]>
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 ft=cpp
8 #include "include/unordered_map.h"
9 #include "global/global_init.h"
10 #include "rgw_common.h"
11 #include "rgw_client_io.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
18 #include "services/svc_zone_utils.h"
19 #include "include/ceph_assert.h"
21 #define dout_subsys ceph_subsys_rgw
29 class RGWLib
: public DoutPrefixProvider
{
30 RGWFrontendConfig
* fec
;
33 rgw::LDAPHelper
* ldh
{nullptr};
34 RGWREST rest
; // XXX needed for RGWProcessEnv
35 rgw::sal::Store
* store
;
36 boost::intrusive_ptr
<CephContext
> cct
;
39 RGWLib() : fec(nullptr), fe(nullptr), olog(nullptr), store(nullptr)
43 rgw::sal::Store
* get_store() { return store
; }
45 RGWLibFrontend
* get_fe() { return fe
; }
47 rgw::LDAPHelper
* get_ldh() { return ldh
; }
49 CephContext
*get_cct() const override
{ return cct
.get(); }
50 unsigned get_subsys() const { return dout_subsys
; }
51 std::ostream
& gen_prefix(std::ostream
& out
) const { return out
<< "lib rgw: "; }
54 int init(std::vector
<const char *>& args
);
60 /* request interface */
62 class RGWLibIO
: public rgw::io::BasicClient
,
63 public rgw::io::Accounter
65 RGWUserInfo user_info
;
69 get_env().set("HTTP_HOST", "");
71 explicit RGWLibIO(const RGWUserInfo
&_user_info
)
72 : user_info(_user_info
) {}
74 int init_env(CephContext
*cct
) override
{
79 const RGWUserInfo
& get_user() {
83 int set_uid(rgw::sal::Store
* store
, const rgw_user
& uid
);
85 int write_data(const char *buf
, int len
);
86 int read_data(char *buf
, int len
);
87 int send_status(int status
, const char *status_name
);
88 int send_100_continue();
89 int complete_header();
90 int send_content_length(uint64_t len
);
92 RGWEnv
& get_env() noexcept override
{
96 size_t complete_request() override
{ /* XXX */
100 void set_account(bool) override
{
104 uint64_t get_bytes_sent() const override
{
108 uint64_t get_bytes_received() const override
{
115 class RGWRESTMgr_Lib
: public RGWRESTMgr
{
118 ~RGWRESTMgr_Lib() override
{}
119 }; /* RGWRESTMgr_Lib */
122 class RGWHandler_Lib
: public RGWHandler
{
123 friend class RGWRESTMgr_Lib
;
126 int authorize(const DoutPrefixProvider
*dpp
, optional_yield y
) override
;
129 ~RGWHandler_Lib() override
{}
130 static int init_from_header(rgw::sal::Store
* store
,
131 struct req_state
*s
);
132 }; /* RGWHandler_Lib */
134 class RGWLibRequest
: public RGWRequest
,
135 public RGWHandler_Lib
{
137 std::unique_ptr
<rgw::sal::User
> tuser
; // Don't use this. It's empty except during init.
141 /* unambiguiously return req_state */
142 inline struct req_state
* get_state() { return this->RGWRequest::s
; }
144 RGWLibRequest(CephContext
* _cct
, std::unique_ptr
<rgw::sal::User
> _user
)
145 : RGWRequest(rgwlib
.get_store()->get_new_req_id()),
146 tuser(std::move(_user
)), cct(_cct
)
149 int postauth_init(optional_yield
) override
{ return 0; }
151 /* descendant equivalent of *REST*::init_from_header(...):
152 * prepare request for execute()--should mean, fixup URI-alikes
153 * and any other expected stat vars in local req_state, for
155 virtual int header_init() = 0;
157 /* descendant initializer responsible to call RGWOp::init()--which
158 * descendants are required to inherit */
159 virtual int op_init() = 0;
161 using RGWHandler::init
;
163 int init(const RGWEnv
& rgw_env
, RGWObjectCtx
* rados_ctx
,
164 RGWLibIO
* io
, struct req_state
* _s
) {
166 RGWRequest::init_state(_s
);
167 RGWHandler::init(rados_ctx
->get_store(), _s
, io
);
169 get_state()->obj_ctx
= rados_ctx
;
170 get_state()->req_id
= store
->zone_unique_id(id
);
171 get_state()->trans_id
= store
->zone_unique_trans_id(id
);
172 get_state()->bucket_tenant
= tuser
->get_tenant();
173 get_state()->set_user(tuser
);
175 ldpp_dout(_s
, 2) << "initializing for trans_id = "
176 << get_state()->trans_id
.c_str() << dendl
;
178 int ret
= header_init();
180 ret
= init_from_header(rados_ctx
->get_store(), _s
);
185 virtual bool only_bucket() = 0;
187 int read_permissions(RGWOp
*op
, optional_yield y
) override
;
189 }; /* RGWLibRequest */
191 class RGWLibContinuedReq
: public RGWLibRequest
{
193 struct req_state rstate
;
194 RGWObjectCtx rados_ctx
;
197 RGWLibContinuedReq(CephContext
* _cct
,
198 std::unique_ptr
<rgw::sal::User
> _user
)
199 : RGWLibRequest(_cct
, std::move(_user
)), io_ctx(),
200 rstate(_cct
, &io_ctx
.get_env(), id
),
201 rados_ctx(rgwlib
.get_store(), &rstate
)
205 RGWRequest::init_state(&rstate
);
206 RGWHandler::init(rados_ctx
.get_store(), &rstate
, &io_ctx
);
208 get_state()->obj_ctx
= &rados_ctx
;
209 get_state()->req_id
= store
->zone_unique_id(id
);
210 get_state()->trans_id
= store
->zone_unique_trans_id(id
);
212 ldpp_dout(get_state(), 2) << "initializing for trans_id = "
213 << get_state()->trans_id
.c_str() << dendl
;
216 inline rgw::sal::Store
* get_store() { return store
; }
217 inline RGWLibIO
& get_io() { return io_ctx
; }
218 inline RGWObjectCtx
& get_octx() { return rados_ctx
; }
220 virtual int execute() final
{ ceph_abort(); }
221 virtual int exec_start() = 0;
222 virtual int exec_continue() = 0;
223 virtual int exec_finish() = 0;
225 }; /* RGWLibContinuedReq */
227 } /* namespace rgw */
229 #endif /* RGW_LIB_H */