]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_lib.h
ce916a12c7d014ffd9e05c89a950d7eac6d29566
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
7 #include "include/unordered_map.h"
8 #include "global/global_init.h"
9 #include "rgw_common.h"
10 #include "rgw_client_io.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
17 #include "include/assert.h"
26 RGWFrontendConfig
* fec
;
30 RGWREST rest
; // XXX needed for RGWProcessEnv
32 boost::intrusive_ptr
<CephContext
> cct
;
35 RGWLib() : fec(nullptr), fe(nullptr), olog(nullptr), store(nullptr)
39 RGWRados
* get_store() { return store
; }
41 RGWLibFrontend
* get_fe() { return fe
; }
43 rgw::LDAPHelper
* get_ldh() { return ldh
; }
46 int init(vector
<const char *>& args
);
52 /* request interface */
54 class RGWLibIO
: public rgw::io::BasicClient
,
55 public rgw::io::Accounter
57 RGWUserInfo user_info
;
61 get_env().set("HTTP_HOST", "");
63 RGWLibIO(const RGWUserInfo
&_user_info
)
64 : user_info(_user_info
) {}
66 void init_env(CephContext
*cct
) override
{}
68 const RGWUserInfo
& get_user() {
72 int set_uid(RGWRados
* store
, const rgw_user
& uid
);
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
);
81 RGWEnv
& get_env() noexcept override
{
85 size_t complete_request() override
{ /* XXX */
89 void set_account(bool) override
{
93 uint64_t get_bytes_sent() const override
{
97 uint64_t get_bytes_received() const override
{
104 class RGWRESTMgr_Lib
: public RGWRESTMgr
{
107 ~RGWRESTMgr_Lib() override
{}
108 }; /* RGWRESTMgr_Lib */
111 class RGWHandler_Lib
: public RGWHandler
{
112 friend class RGWRESTMgr_Lib
;
115 int authorize() override
;
118 ~RGWHandler_Lib() override
{}
119 static int init_from_header(struct req_state
*s
);
120 }; /* RGWHandler_Lib */
122 class RGWLibRequest
: public RGWRequest
,
123 public RGWHandler_Lib
{
128 /* unambiguiously return req_state */
129 inline struct req_state
* get_state() { return this->RGWRequest::s
; }
131 RGWLibRequest(CephContext
* _cct
, RGWUserInfo
* _user
)
132 : RGWRequest(0), cct(_cct
), user(_user
)
135 RGWUserInfo
* get_user() { return user
; }
137 int postauth_init() override
{ return 0; }
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
143 virtual int header_init() = 0;
145 /* descendant initializer responsible to call RGWOp::init()--which
146 * descendants are required to inherit */
147 virtual int op_init() = 0;
149 using RGWHandler::init
;
151 int init(const RGWEnv
& rgw_env
, RGWObjectCtx
* rados_ctx
,
152 RGWLibIO
* io
, struct req_state
* _s
) {
154 RGWRequest::init_state(_s
);
155 RGWHandler::init(rados_ctx
->store
, _s
, io
);
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
);
166 log_format(_s
, "initializing for trans_id = %s",
167 get_state()->trans_id
.c_str());
169 int ret
= header_init();
171 ret
= init_from_header(_s
);
176 virtual bool only_bucket() = 0;
178 int read_permissions(RGWOp
*op
) override
;
180 }; /* RGWLibRequest */
182 class RGWLibContinuedReq
: public RGWLibRequest
{
184 struct req_state rstate
;
185 RGWObjectCtx rados_ctx
;
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(),
195 RGWRequest::init_state(&rstate
);
196 RGWHandler::init(rados_ctx
.store
, &rstate
, &io_ctx
);
199 get_state()->req
= this;
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
);
207 log_format(get_state(), "initializing for trans_id = %s",
208 get_state()->trans_id
.c_str());
211 inline RGWRados
* get_store() { return store
; }
213 virtual int execute() final
{ abort(); }
214 virtual int exec_start() = 0;
215 virtual int exec_continue() = 0;
216 virtual int exec_finish() = 0;
218 }; /* RGWLibContinuedReq */
220 } /* namespace rgw */
222 #endif /* RGW_LIB_H */