]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_rest_client.h
update sources to v12.1.0
[ceph.git] / ceph / src / rgw / rgw_rest_client.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_RGW_REST_CLIENT_H
5#define CEPH_RGW_REST_CLIENT_H
6
7#include "rgw_http_client.h"
8
9class RGWGetDataCB;
10
11class RGWRESTSimpleRequest : public RGWHTTPClient {
12protected:
13 int http_status;
14 int status;
15
16 string url;
17
18 map<string, string> out_headers;
19 param_vec_t params;
20
21 bufferlist::iterator *send_iter;
22
23 size_t max_response; /* we need this as we don't stream out response */
24 bufferlist response;
25
26 virtual int handle_header(const string& name, const string& val);
27 void append_param(string& dest, const string& name, const string& val);
28 void get_params_str(map<string, string>& extra_args, string& dest);
29
30 int sign_request(RGWAccessKey& key, RGWEnv& env, req_info& info);
31public:
32 RGWRESTSimpleRequest(CephContext *_cct, const string& _url, param_vec_t *_headers,
33 param_vec_t *_params) : RGWHTTPClient(_cct), http_status(0), status(0),
34 url(_url), send_iter(NULL),
35 max_response(0) {
36 set_headers(_headers);
37 set_params(_params);
38 }
39
40 void set_headers(param_vec_t *_headers) {
41 if (_headers)
42 headers = *_headers;
43 }
44
45 void set_params(param_vec_t *_params) {
46 if (_params)
47 params = *_params;
48 }
49
50 int receive_header(void *ptr, size_t len) override;
51 int receive_data(void *ptr, size_t len) override;
52 int send_data(void *ptr, size_t len) override;
53
54 bufferlist& get_response() { return response; }
55
56 int execute(RGWAccessKey& key, const char *method, const char *resource);
57 int forward_request(RGWAccessKey& key, req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl);
58
59 map<string, string>& get_out_headers() { return out_headers; }
60
61 int get_http_status() { return http_status; }
62 int get_status();
63};
64
65
66class RGWRESTStreamWriteRequest : public RGWRESTSimpleRequest {
67 Mutex lock;
68 list<bufferlist> pending_send;
69 RGWGetDataCB *cb;
70 RGWHTTPManager http_manager;
71public:
72 int add_output_data(bufferlist& bl);
73 int send_data(void *ptr, size_t len) override;
74
75 RGWRESTStreamWriteRequest(CephContext *_cct, const string& _url, param_vec_t *_headers,
76 param_vec_t *_params) : RGWRESTSimpleRequest(_cct, _url, _headers, _params),
77 lock("RGWRESTStreamWriteRequest"), cb(NULL), http_manager(_cct) {}
78 ~RGWRESTStreamWriteRequest() override;
79 int put_obj_init(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size, map<string, bufferlist>& attrs);
80 int complete(string& etag, real_time *mtime);
81
82 RGWGetDataCB *get_out_cb() { return cb; }
83};
84
85class RGWRESTStreamRWRequest : public RGWRESTSimpleRequest {
86 Mutex lock;
87 RGWGetDataCB *cb;
88 bufferlist outbl;
89 bufferlist in_data;
90 size_t chunk_ofs;
91 size_t ofs;
92 RGWHTTPManager http_manager;
93 const char *method;
94 uint64_t write_ofs;
95protected:
96 int handle_header(const string& name, const string& val) override;
97public:
98 int send_data(void *ptr, size_t len) override;
99 int receive_data(void *ptr, size_t len) override;
100
101 RGWRESTStreamRWRequest(CephContext *_cct, const char *_method, const string& _url, RGWGetDataCB *_cb,
102 param_vec_t *_headers, param_vec_t *_params) : RGWRESTSimpleRequest(_cct, _url, _headers, _params),
103 lock("RGWRESTStreamReadRequest"), cb(_cb),
104 chunk_ofs(0), ofs(0), http_manager(_cct), method(_method), write_ofs(0) {
105 }
31f18b77
FG
106 virtual ~RGWRESTStreamRWRequest() override {}
107 int send_request(RGWAccessKey& key, map<string, string>& extra_headers, rgw_obj& obj, RGWHTTPManager *mgr = NULL);
108 int send_request(RGWAccessKey *key, map<string, string>& extra_headers, const string& resource, bufferlist *send_data = NULL /* optional input data */, RGWHTTPManager *mgr = NULL);
109 int complete_request(string& etag, real_time *mtime, uint64_t *psize, map<string, string>& attrs);
7c673cae
FG
110
111 void set_outbl(bufferlist& _outbl) {
112 outbl.swap(_outbl);
113 }
114
115 void set_in_cb(RGWGetDataCB *_cb) { cb = _cb; }
116};
117
118class RGWRESTStreamReadRequest : public RGWRESTStreamRWRequest {
119public:
120 RGWRESTStreamReadRequest(CephContext *_cct, const string& _url, RGWGetDataCB *_cb, param_vec_t *_headers,
121 param_vec_t *_params) : RGWRESTStreamRWRequest(_cct, "GET", _url, _cb, _headers, _params) {}
122};
123
124class RGWRESTStreamHeadRequest : public RGWRESTStreamRWRequest {
125public:
126 RGWRESTStreamHeadRequest(CephContext *_cct, const string& _url, RGWGetDataCB *_cb, param_vec_t *_headers,
127 param_vec_t *_params) : RGWRESTStreamRWRequest(_cct, "HEAD", _url, _cb, _headers, _params) {}
128};
129
130#endif
131