00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef restcgi_resource_h
00023 #define restcgi_resource_h
00024 #include "apidefs.h"
00025 #include "method_e.h"
00026 #include "content.h"
00027 #include "status_code_e.h"
00028 #include "version.h"
00029 #include <uripp/path.h>
00030 #include <uripp/query.h>
00031 #include <utility>
00032 #include <boost/shared_ptr.hpp>
00033 #include <boost/weak_ptr.hpp>
00034 namespace restcgi {
00035 class method;
00036 class version;
00037 class version_tag;
00038 class request_hdr;
00039 class response_hdr;
00040 class content_hdr;
00042 class RESTCGI_API uri_info {
00043 public:
00044 typedef restcgi::method method_type;
00045 typedef boost::shared_ptr<method_type> method_pointer;
00046 uri_info();
00047 uri_info(method_pointer m);
00048 const uripp::path& path() const;
00049 const uripp::query& query() const;
00050 void method(method_pointer m);
00051 private:
00052 method_pointer method_;
00053 };
00083 class RESTCGI_API resource {
00084 public:
00085 typedef boost::shared_ptr<resource> pointer;
00086 typedef boost::shared_ptr<const resource> const_pointer;
00087 typedef restcgi::method method_type;
00088 typedef boost::shared_ptr<method_type> method_pointer;
00089 typedef uripp::path uri_path_type;
00090 typedef restcgi::uri_info uri_info_type;
00091 typedef restcgi::version version_type;
00092 typedef restcgi::version_tag version_tag_type;
00093 typedef restcgi::version_constraint version_constraint_type;
00094 virtual ~resource();
00095 void method(method_pointer m);
00096 method_pointer method() const {return method_;}
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 virtual pointer locate(uri_path_type& path);
00137 virtual void get_method();
00157 virtual void put_method();
00179 virtual void post_method();
00199 virtual void del_method();
00220 virtual void options_method();
00236 virtual void head_method();
00237 int methods_allowed_mask() const {return methods_allowed_mask_;}
00238 pointer child() const {return child_;}
00239 pointer parent() const {return parent_.lock();}
00240 bool chain_children() const {return chain_children_;}
00241 void child(pointer rthis, pointer cr);
00242 protected:
00243 typedef uripp::query uri_query_type;
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 resource(int methods_allowed_mask, bool chain_children = false);
00259 const method_e& me() const;
00260 const uri_info_type& uri_info() const {return uri_info_;}
00261
00262 version_constraint_type version_constraint() const {return version_constraint_;}
00267 void default_response(bool v);
00280 virtual version_type read(bool veronly);
00288 virtual version_type update(icontent::pointer ic);
00293 virtual pointer create_child();
00294 typedef std::pair<uri_path_type, version_type> id_version_type;
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 virtual id_version_type create(icontent::pointer ic);
00309 virtual void del();
00331 virtual void on_responding(status_code_e& sc, response_hdr& rh, content_hdr& ch);
00343 virtual void write(ocontent::pointer oc);
00344 private:
00345 void setup();
00346 void respond(const version_type& v = version_type());
00347 int methods_allowed_mask_;
00348 bool chain_children_;
00349 bool default_response_;
00350 method_pointer method_;
00351 uri_info_type uri_info_;
00352 version_constraint_type version_constraint_;
00353 pointer child_;
00354 boost::weak_ptr<resource> parent_;
00355 };
00375 void RESTCGI_API copy(const request_hdr& rh, version_constraint& vc);
00377 void RESTCGI_API copy(const version& v, response_hdr& rh);
00378 }
00379 #endif