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