]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_lib.h
ce916a12c7d014ffd9e05c89a950d7eac6d29566
[ceph.git] / ceph / src / rgw / rgw_lib.h
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;
29 rgw::LDAPHelper* ldh;
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
66 void init_env(CephContext *cct) override {}
67
68 const RGWUserInfo& get_user() {
69 return user_info;
70 }
71
72 int set_uid(RGWRados* store, const rgw_user& uid);
73
74 int write_data(const char *buf, int len);
75 int read_data(char *buf, int len);
76 int send_status(int status, const char *status_name);
77 int send_100_continue();
78 int complete_header();
79 int send_content_length(uint64_t len);
80
81 RGWEnv& get_env() noexcept override {
82 return env;
83 }
84
85 size_t complete_request() override { /* XXX */
86 return 0;
87 };
88
89 void set_account(bool) override {
90 return;
91 }
92
93 uint64_t get_bytes_sent() const override {
94 return 0;
95 }
96
97 uint64_t get_bytes_received() const override {
98 return 0;
99 }
100
101 }; /* RGWLibIO */
102
103 /* XXX */
104 class RGWRESTMgr_Lib : public RGWRESTMgr {
105 public:
106 RGWRESTMgr_Lib() {}
107 ~RGWRESTMgr_Lib() override {}
108 }; /* RGWRESTMgr_Lib */
109
110 /* XXX */
111 class RGWHandler_Lib : public RGWHandler {
112 friend class RGWRESTMgr_Lib;
113 public:
114
115 int authorize() override;
116
117 RGWHandler_Lib() {}
118 ~RGWHandler_Lib() override {}
119 static int init_from_header(struct req_state *s);
120 }; /* RGWHandler_Lib */
121
122 class RGWLibRequest : public RGWRequest,
123 public RGWHandler_Lib {
124 public:
125 CephContext* cct;
126 RGWUserInfo* user;
127
128 /* unambiguiously return req_state */
129 inline struct req_state* get_state() { return this->RGWRequest::s; }
130
131 RGWLibRequest(CephContext* _cct, RGWUserInfo* _user)
132 : RGWRequest(0), cct(_cct), user(_user)
133 {}
134
135 RGWUserInfo* get_user() { return user; }
136
137 int postauth_init() override { return 0; }
138
139 /* descendant equivalent of *REST*::init_from_header(...):
140 * prepare request for execute()--should mean, fixup URI-alikes
141 * and any other expected stat vars in local req_state, for
142 * now */
143 virtual int header_init() = 0;
144
145 /* descendant initializer responsible to call RGWOp::init()--which
146 * descendants are required to inherit */
147 virtual int op_init() = 0;
148
149 using RGWHandler::init;
150
151 int init(const RGWEnv& rgw_env, RGWObjectCtx* rados_ctx,
152 RGWLibIO* io, struct req_state* _s) {
153
154 RGWRequest::init_state(_s);
155 RGWHandler::init(rados_ctx->store, _s, io);
156
157 /* fixup _s->req */
158 _s->req = this;
159
160 log_init();
161
162 get_state()->obj_ctx = rados_ctx;
163 get_state()->req_id = store->unique_id(id);
164 get_state()->trans_id = store->unique_trans_id(id);
165
166 log_format(_s, "initializing for trans_id = %s",
167 get_state()->trans_id.c_str());
168
169 int ret = header_init();
170 if (ret == 0) {
171 ret = init_from_header(_s);
172 }
173 return ret;
174 }
175
176 virtual bool only_bucket() = 0;
177
178 int read_permissions(RGWOp *op) override;
179
180 }; /* RGWLibRequest */
181
182 class RGWLibContinuedReq : public RGWLibRequest {
183 RGWLibIO io_ctx;
184 struct req_state rstate;
185 RGWObjectCtx rados_ctx;
186 public:
187
188 RGWLibContinuedReq(CephContext* _cct, RGWUserInfo* _user)
189 : RGWLibRequest(_cct, _user), io_ctx(),
190 rstate(_cct, &io_ctx.get_env(), _user), rados_ctx(rgwlib.get_store(),
191 &rstate)
192 {
193 io_ctx.init(_cct);
194
195 RGWRequest::init_state(&rstate);
196 RGWHandler::init(rados_ctx.store, &rstate, &io_ctx);
197
198 /* fixup _s->req */
199 get_state()->req = this;
200
201 log_init();
202
203 get_state()->obj_ctx = &rados_ctx;
204 get_state()->req_id = store->unique_id(id);
205 get_state()->trans_id = store->unique_trans_id(id);
206
207 log_format(get_state(), "initializing for trans_id = %s",
208 get_state()->trans_id.c_str());
209 }
210
211 inline RGWRados* get_store() { return store; }
212
213 virtual int execute() final { abort(); }
214 virtual int exec_start() = 0;
215 virtual int exec_continue() = 0;
216 virtual int exec_finish() = 0;
217
218 }; /* RGWLibContinuedReq */
219
220 } /* namespace rgw */
221
222 #endif /* RGW_LIB_H */