]>
git.proxmox.com Git - ceph.git/blob - 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
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
;
29 rgw::LDAPHelper
* ldh
{nullptr};
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 int init_env(CephContext
*cct
) override
{
71 const RGWUserInfo
& get_user() {
75 int set_uid(RGWRados
* store
, const rgw_user
& uid
);
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
);
84 RGWEnv
& get_env() noexcept override
{
88 size_t complete_request() override
{ /* XXX */
92 void set_account(bool) override
{
96 uint64_t get_bytes_sent() const override
{
100 uint64_t get_bytes_received() const override
{
107 class RGWRESTMgr_Lib
: public RGWRESTMgr
{
110 ~RGWRESTMgr_Lib() override
{}
111 }; /* RGWRESTMgr_Lib */
114 class RGWHandler_Lib
: public RGWHandler
{
115 friend class RGWRESTMgr_Lib
;
118 int authorize() override
;
121 ~RGWHandler_Lib() override
{}
122 static int init_from_header(struct req_state
*s
);
123 }; /* RGWHandler_Lib */
125 class RGWLibRequest
: public RGWRequest
,
126 public RGWHandler_Lib
{
131 /* unambiguiously return req_state */
132 inline struct req_state
* get_state() { return this->RGWRequest::s
; }
134 RGWLibRequest(CephContext
* _cct
, RGWUserInfo
* _user
)
135 : RGWRequest(0), cct(_cct
), user(_user
)
138 RGWUserInfo
* get_user() { return user
; }
140 int postauth_init() override
{ return 0; }
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
146 virtual int header_init() = 0;
148 /* descendant initializer responsible to call RGWOp::init()--which
149 * descendants are required to inherit */
150 virtual int op_init() = 0;
152 using RGWHandler::init
;
154 int init(const RGWEnv
& rgw_env
, RGWObjectCtx
* rados_ctx
,
155 RGWLibIO
* io
, struct req_state
* _s
) {
157 RGWRequest::init_state(_s
);
158 RGWHandler::init(rados_ctx
->store
, _s
, io
);
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
);
169 log_format(_s
, "initializing for trans_id = %s",
170 get_state()->trans_id
.c_str());
172 int ret
= header_init();
174 ret
= init_from_header(_s
);
179 virtual bool only_bucket() = 0;
181 int read_permissions(RGWOp
*op
) override
;
183 }; /* RGWLibRequest */
185 class RGWLibContinuedReq
: public RGWLibRequest
{
187 struct req_state rstate
;
188 RGWObjectCtx rados_ctx
;
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(),
198 RGWRequest::init_state(&rstate
);
199 RGWHandler::init(rados_ctx
.store
, &rstate
, &io_ctx
);
202 get_state()->req
= this;
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
);
210 log_format(get_state(), "initializing for trans_id = %s",
211 get_state()->trans_id
.c_str());
214 inline RGWRados
* get_store() { return store
; }
216 virtual int execute() final
{ abort(); }
217 virtual int exec_start() = 0;
218 virtual int exec_continue() = 0;
219 virtual int exec_finish() = 0;
221 }; /* RGWLibContinuedReq */
223 } /* namespace rgw */
225 #endif /* RGW_LIB_H */