]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | #ifndef RGW_LIB_H | |
4 | #define RGW_LIB_H | |
5 | ||
6 | #include <mutex> | |
7 | #include "include/unordered_map.h" | |
8 | #include "global/global_init.h" | |
9 | #include "rgw_common.h" | |
10 | #include "rgw_client_io.h" | |
11 | #include "rgw_rest.h" | |
12 | #include "rgw_request.h" | |
13 | #include "rgw_frontend.h" | |
14 | #include "rgw_process.h" | |
15 | #include "rgw_rest_s3.h" // RGW_Auth_S3 | |
16 | #include "rgw_ldap.h" | |
17 | #include "include/assert.h" | |
18 | ||
19 | class OpsLogSocket; | |
20 | ||
21 | namespace rgw { | |
22 | ||
23 | class RGWLibFrontend; | |
24 | ||
25 | class RGWLib { | |
26 | RGWFrontendConfig* fec; | |
27 | RGWLibFrontend* fe; | |
28 | OpsLogSocket* olog; | |
224ce89b | 29 | rgw::LDAPHelper* ldh{nullptr}; |
7c673cae FG |
30 | RGWREST rest; // XXX needed for RGWProcessEnv |
31 | RGWRados* store; | |
32 | boost::intrusive_ptr<CephContext> cct; | |
33 | ||
34 | public: | |
35 | RGWLib() : fec(nullptr), fe(nullptr), olog(nullptr), store(nullptr) | |
36 | {} | |
37 | ~RGWLib() {} | |
38 | ||
39 | RGWRados* get_store() { return store; } | |
40 | ||
41 | RGWLibFrontend* get_fe() { return fe; } | |
42 | ||
43 | rgw::LDAPHelper* get_ldh() { return ldh; } | |
44 | ||
45 | int init(); | |
46 | int init(vector<const char *>& args); | |
47 | int stop(); | |
48 | }; | |
49 | ||
50 | extern RGWLib rgwlib; | |
51 | ||
52 | /* request interface */ | |
53 | ||
54 | class RGWLibIO : public rgw::io::BasicClient, | |
55 | public rgw::io::Accounter | |
56 | { | |
57 | RGWUserInfo user_info; | |
58 | RGWEnv env; | |
59 | public: | |
60 | RGWLibIO() { | |
61 | get_env().set("HTTP_HOST", ""); | |
62 | } | |
63 | RGWLibIO(const RGWUserInfo &_user_info) | |
64 | : user_info(_user_info) {} | |
65 | ||
3a9019d9 FG |
66 | int init_env(CephContext *cct) override { |
67 | env.init(cct); | |
68 | return 0; | |
69 | } | |
7c673cae FG |
70 | |
71 | const RGWUserInfo& get_user() { | |
72 | return user_info; | |
73 | } | |
74 | ||
75 | int set_uid(RGWRados* store, const rgw_user& uid); | |
76 | ||
77 | int write_data(const char *buf, int len); | |
78 | int read_data(char *buf, int len); | |
79 | int send_status(int status, const char *status_name); | |
80 | int send_100_continue(); | |
81 | int complete_header(); | |
82 | int send_content_length(uint64_t len); | |
83 | ||
84 | RGWEnv& get_env() noexcept override { | |
85 | return env; | |
86 | } | |
87 | ||
88 | size_t complete_request() override { /* XXX */ | |
89 | return 0; | |
90 | }; | |
91 | ||
92 | void set_account(bool) override { | |
93 | return; | |
94 | } | |
95 | ||
96 | uint64_t get_bytes_sent() const override { | |
97 | return 0; | |
98 | } | |
99 | ||
100 | uint64_t get_bytes_received() const override { | |
101 | return 0; | |
102 | } | |
103 | ||
104 | }; /* RGWLibIO */ | |
105 | ||
106 | /* XXX */ | |
107 | class RGWRESTMgr_Lib : public RGWRESTMgr { | |
108 | public: | |
109 | RGWRESTMgr_Lib() {} | |
110 | ~RGWRESTMgr_Lib() override {} | |
111 | }; /* RGWRESTMgr_Lib */ | |
112 | ||
113 | /* XXX */ | |
114 | class RGWHandler_Lib : public RGWHandler { | |
115 | friend class RGWRESTMgr_Lib; | |
116 | public: | |
117 | ||
118 | int authorize() override; | |
119 | ||
120 | RGWHandler_Lib() {} | |
121 | ~RGWHandler_Lib() override {} | |
122 | static int init_from_header(struct req_state *s); | |
123 | }; /* RGWHandler_Lib */ | |
124 | ||
125 | class RGWLibRequest : public RGWRequest, | |
126 | public RGWHandler_Lib { | |
127 | public: | |
128 | CephContext* cct; | |
129 | RGWUserInfo* user; | |
130 | ||
131 | /* unambiguiously return req_state */ | |
132 | inline struct req_state* get_state() { return this->RGWRequest::s; } | |
133 | ||
134 | RGWLibRequest(CephContext* _cct, RGWUserInfo* _user) | |
135 | : RGWRequest(0), cct(_cct), user(_user) | |
136 | {} | |
137 | ||
138 | RGWUserInfo* get_user() { return user; } | |
139 | ||
140 | int postauth_init() override { return 0; } | |
141 | ||
142 | /* descendant equivalent of *REST*::init_from_header(...): | |
143 | * prepare request for execute()--should mean, fixup URI-alikes | |
144 | * and any other expected stat vars in local req_state, for | |
145 | * now */ | |
146 | virtual int header_init() = 0; | |
147 | ||
148 | /* descendant initializer responsible to call RGWOp::init()--which | |
149 | * descendants are required to inherit */ | |
150 | virtual int op_init() = 0; | |
151 | ||
152 | using RGWHandler::init; | |
153 | ||
154 | int init(const RGWEnv& rgw_env, RGWObjectCtx* rados_ctx, | |
155 | RGWLibIO* io, struct req_state* _s) { | |
156 | ||
157 | RGWRequest::init_state(_s); | |
158 | RGWHandler::init(rados_ctx->store, _s, io); | |
159 | ||
160 | /* fixup _s->req */ | |
161 | _s->req = this; | |
162 | ||
163 | log_init(); | |
164 | ||
165 | get_state()->obj_ctx = rados_ctx; | |
166 | get_state()->req_id = store->unique_id(id); | |
167 | get_state()->trans_id = store->unique_trans_id(id); | |
168 | ||
169 | log_format(_s, "initializing for trans_id = %s", | |
170 | get_state()->trans_id.c_str()); | |
171 | ||
172 | int ret = header_init(); | |
173 | if (ret == 0) { | |
174 | ret = init_from_header(_s); | |
175 | } | |
176 | return ret; | |
177 | } | |
178 | ||
179 | virtual bool only_bucket() = 0; | |
180 | ||
181 | int read_permissions(RGWOp *op) override; | |
182 | ||
183 | }; /* RGWLibRequest */ | |
184 | ||
185 | class RGWLibContinuedReq : public RGWLibRequest { | |
186 | RGWLibIO io_ctx; | |
187 | struct req_state rstate; | |
188 | RGWObjectCtx rados_ctx; | |
189 | public: | |
190 | ||
191 | RGWLibContinuedReq(CephContext* _cct, RGWUserInfo* _user) | |
192 | : RGWLibRequest(_cct, _user), io_ctx(), | |
193 | rstate(_cct, &io_ctx.get_env(), _user), rados_ctx(rgwlib.get_store(), | |
194 | &rstate) | |
195 | { | |
196 | io_ctx.init(_cct); | |
197 | ||
198 | RGWRequest::init_state(&rstate); | |
199 | RGWHandler::init(rados_ctx.store, &rstate, &io_ctx); | |
200 | ||
201 | /* fixup _s->req */ | |
202 | get_state()->req = this; | |
203 | ||
204 | log_init(); | |
205 | ||
206 | get_state()->obj_ctx = &rados_ctx; | |
207 | get_state()->req_id = store->unique_id(id); | |
208 | get_state()->trans_id = store->unique_trans_id(id); | |
209 | ||
210 | log_format(get_state(), "initializing for trans_id = %s", | |
211 | get_state()->trans_id.c_str()); | |
212 | } | |
213 | ||
214 | inline RGWRados* get_store() { return store; } | |
215 | ||
216 | virtual int execute() final { abort(); } | |
217 | virtual int exec_start() = 0; | |
218 | virtual int exec_continue() = 0; | |
219 | virtual int exec_finish() = 0; | |
220 | ||
221 | }; /* RGWLibContinuedReq */ | |
222 | ||
223 | } /* namespace rgw */ | |
224 | ||
225 | #endif /* RGW_LIB_H */ |