]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_lib.h
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / rgw / rgw_lib.h
CommitLineData
7c673cae 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
11fdf7f2 3
1e59de90 4#pragma once
7c673cae
FG
5
6#include <mutex>
7c673cae
FG
7#include "rgw_common.h"
8#include "rgw_client_io.h"
9#include "rgw_rest.h"
10#include "rgw_request.h"
7c673cae 11#include "rgw_ldap.h"
11fdf7f2 12#include "include/ceph_assert.h"
1e59de90 13#include "rgw_main.h"
b3b6e05e 14
a4b75251 15class OpsLogSink;
7c673cae
FG
16
17namespace rgw {
18
19 class RGWLibFrontend;
20
b3b6e05e 21 class RGWLib : public DoutPrefixProvider {
7c673cae 22 boost::intrusive_ptr<CephContext> cct;
1e59de90
TL
23 AppMain main;
24 RGWLibFrontend* fe;
7c673cae
FG
25
26 public:
1e59de90 27 RGWLib() : main(this), fe(nullptr)
7c673cae
FG
28 {}
29 ~RGWLib() {}
30
1e59de90 31 rgw::sal::Driver* get_driver() { return main.get_driver(); }
7c673cae
FG
32
33 RGWLibFrontend* get_fe() { return fe; }
34
1e59de90 35 rgw::LDAPHelper* get_ldh() { return main.get_ldh(); }
b3b6e05e 36 CephContext *get_cct() const override { return cct.get(); }
1e59de90 37 unsigned get_subsys() const { return ceph_subsys_rgw; }
b3b6e05e
TL
38 std::ostream& gen_prefix(std::ostream& out) const { return out << "lib rgw: "; }
39
1e59de90
TL
40 void set_fe(RGWLibFrontend* fe);
41
7c673cae 42 int init();
20effc67 43 int init(std::vector<const char *>& args);
7c673cae
FG
44 int stop();
45 };
46
1e59de90 47 extern RGWLib* g_rgwlib;
7c673cae
FG
48
49/* request interface */
50
51 class RGWLibIO : public rgw::io::BasicClient,
52 public rgw::io::Accounter
53 {
54 RGWUserInfo user_info;
55 RGWEnv env;
56 public:
57 RGWLibIO() {
58 get_env().set("HTTP_HOST", "");
59 }
11fdf7f2 60 explicit RGWLibIO(const RGWUserInfo &_user_info)
7c673cae
FG
61 : user_info(_user_info) {}
62
3a9019d9
FG
63 int init_env(CephContext *cct) override {
64 env.init(cct);
65 return 0;
66 }
7c673cae
FG
67
68 const RGWUserInfo& get_user() {
69 return user_info;
70 }
71
1e59de90 72 int set_uid(rgw::sal::Driver* driver, const rgw_user& uid);
7c673cae
FG
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
7c673cae
FG
103 class RGWRESTMgr_Lib : public RGWRESTMgr {
104 public:
105 RGWRESTMgr_Lib() {}
106 ~RGWRESTMgr_Lib() override {}
107 }; /* RGWRESTMgr_Lib */
108
7c673cae
FG
109 class RGWHandler_Lib : public RGWHandler {
110 friend class RGWRESTMgr_Lib;
111 public:
112
f67539c2 113 int authorize(const DoutPrefixProvider *dpp, optional_yield y) override;
7c673cae
FG
114
115 RGWHandler_Lib() {}
116 ~RGWHandler_Lib() override {}
1e59de90
TL
117 static int init_from_header(rgw::sal::Driver* driver,
118 req_state *s);
7c673cae
FG
119 }; /* RGWHandler_Lib */
120
121 class RGWLibRequest : public RGWRequest,
122 public RGWHandler_Lib {
f67539c2 123 private:
20effc67 124 std::unique_ptr<rgw::sal::User> tuser; // Don't use this. It's empty except during init.
7c673cae
FG
125 public:
126 CephContext* cct;
7c673cae
FG
127
128 /* unambiguiously return req_state */
1e59de90 129 inline req_state* get_state() { return this->RGWRequest::s; }
7c673cae 130
20effc67 131 RGWLibRequest(CephContext* _cct, std::unique_ptr<rgw::sal::User> _user)
1e59de90 132 : RGWRequest(g_rgwlib->get_driver()->get_new_req_id()),
f67539c2 133 tuser(std::move(_user)), cct(_cct)
7c673cae
FG
134 {}
135
f67539c2 136 int postauth_init(optional_yield) override { return 0; }
7c673cae
FG
137
138 /* descendant equivalent of *REST*::init_from_header(...):
139 * prepare request for execute()--should mean, fixup URI-alikes
140 * and any other expected stat vars in local req_state, for
141 * now */
142 virtual int header_init() = 0;
143
144 /* descendant initializer responsible to call RGWOp::init()--which
145 * descendants are required to inherit */
146 virtual int op_init() = 0;
147
148 using RGWHandler::init;
149
1e59de90
TL
150 int init(const RGWEnv& rgw_env, rgw::sal::Driver* _driver,
151 RGWLibIO* io, req_state* _s) {
7c673cae
FG
152
153 RGWRequest::init_state(_s);
1e59de90 154 RGWHandler::init(_driver, _s, io);
7c673cae 155
1e59de90
TL
156 get_state()->req_id = driver->zone_unique_id(id);
157 get_state()->trans_id = driver->zone_unique_trans_id(id);
f67539c2
TL
158 get_state()->bucket_tenant = tuser->get_tenant();
159 get_state()->set_user(tuser);
7c673cae 160
11fdf7f2
TL
161 ldpp_dout(_s, 2) << "initializing for trans_id = "
162 << get_state()->trans_id.c_str() << dendl;
7c673cae
FG
163
164 int ret = header_init();
165 if (ret == 0) {
1e59de90 166 ret = init_from_header(driver, _s);
7c673cae
FG
167 }
168 return ret;
169 }
170
171 virtual bool only_bucket() = 0;
172
f67539c2 173 int read_permissions(RGWOp *op, optional_yield y) override;
7c673cae
FG
174
175 }; /* RGWLibRequest */
176
177 class RGWLibContinuedReq : public RGWLibRequest {
178 RGWLibIO io_ctx;
1e59de90 179 req_state rstate;
7c673cae
FG
180 public:
181
1e59de90 182 RGWLibContinuedReq(CephContext* _cct, const RGWProcessEnv& penv,
20effc67 183 std::unique_ptr<rgw::sal::User> _user)
f67539c2 184 : RGWLibRequest(_cct, std::move(_user)), io_ctx(),
1e59de90 185 rstate(_cct, penv, &io_ctx.get_env(), id)
7c673cae
FG
186 {
187 io_ctx.init(_cct);
188
189 RGWRequest::init_state(&rstate);
1e59de90 190 RGWHandler::init(g_rgwlib->get_driver(), &rstate, &io_ctx);
7c673cae 191
1e59de90
TL
192 get_state()->req_id = driver->zone_unique_id(id);
193 get_state()->trans_id = driver->zone_unique_trans_id(id);
7c673cae 194
11fdf7f2
TL
195 ldpp_dout(get_state(), 2) << "initializing for trans_id = "
196 << get_state()->trans_id.c_str() << dendl;
7c673cae
FG
197 }
198
1e59de90 199 inline rgw::sal::Driver* get_driver() { return driver; }
f67539c2 200 inline RGWLibIO& get_io() { return io_ctx; }
7c673cae 201
11fdf7f2 202 virtual int execute() final { ceph_abort(); }
7c673cae
FG
203 virtual int exec_start() = 0;
204 virtual int exec_continue() = 0;
205 virtual int exec_finish() = 0;
206
207 }; /* RGWLibContinuedReq */
208
209} /* namespace rgw */