]>
Commit | Line | Data |
---|---|---|
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 | #include <algorithm> | |
5 | #include <sstream> | |
6 | #include <string.h> | |
7 | ||
8 | #include "rgw_loadgen.h" | |
9 | #include "rgw_auth_s3.h" | |
10 | ||
11 | ||
12 | #define dout_subsys ceph_subsys_rgw | |
13 | ||
14 | void RGWLoadGenRequestEnv::set_date(utime_t& tm) | |
15 | { | |
16 | stringstream s; | |
17 | tm.asctime(s); | |
18 | date_str = s.str(); | |
19 | } | |
20 | ||
21 | int RGWLoadGenRequestEnv::sign(RGWAccessKey& access_key) | |
22 | { | |
23 | map<string, string> meta_map; | |
24 | map<string, string> sub_resources; | |
25 | ||
26 | string canonical_header; | |
27 | string digest; | |
28 | ||
29 | rgw_create_s3_canonical_header(request_method.c_str(), | |
30 | nullptr, /* const char *content_md5 */ | |
31 | content_type.c_str(), | |
32 | date_str.c_str(), | |
33 | meta_map, | |
34 | uri.c_str(), | |
35 | sub_resources, | |
36 | canonical_header); | |
37 | ||
38 | int ret = rgw_get_s3_header_digest(canonical_header, access_key.key, digest); | |
39 | if (ret < 0) { | |
40 | return ret; | |
41 | } | |
42 | ||
43 | headers["HTTP_DATE"] = date_str; | |
44 | headers["HTTP_AUTHORIZATION"] = string("AWS ") + access_key.id + ":" + digest; | |
45 | ||
46 | return 0; | |
47 | } | |
48 | ||
49 | size_t RGWLoadGenIO::write_data(const char* const buf, | |
50 | const size_t len) | |
51 | { | |
52 | return len; | |
53 | } | |
54 | ||
55 | size_t RGWLoadGenIO::read_data(char* const buf, const size_t len) | |
56 | { | |
57 | const size_t read_len = std::min(left_to_read, | |
58 | static_cast<uint64_t>(len)); | |
59 | left_to_read -= read_len; | |
60 | return read_len; | |
61 | } | |
62 | ||
63 | void RGWLoadGenIO::flush() | |
64 | { | |
65 | } | |
66 | ||
67 | size_t RGWLoadGenIO::complete_request() | |
68 | { | |
69 | return 0; | |
70 | } | |
71 | ||
72 | void RGWLoadGenIO::init_env(CephContext *cct) | |
73 | { | |
74 | env.init(cct); | |
75 | ||
76 | left_to_read = req->content_length; | |
77 | ||
78 | char buf[32]; | |
79 | snprintf(buf, sizeof(buf), "%lld", (long long)req->content_length); | |
80 | env.set("CONTENT_LENGTH", buf); | |
81 | ||
82 | env.set("CONTENT_TYPE", req->content_type.c_str()); | |
83 | env.set("HTTP_DATE", req->date_str.c_str()); | |
84 | ||
85 | for (map<string, string>::iterator iter = req->headers.begin(); iter != req->headers.end(); ++iter) { | |
86 | env.set(iter->first.c_str(), iter->second.c_str()); | |
87 | } | |
88 | ||
89 | env.set("REQUEST_METHOD", req->request_method.c_str()); | |
90 | env.set("REQUEST_URI", req->uri.c_str()); | |
91 | env.set("QUERY_STRING", req->query_string.c_str()); | |
92 | env.set("SCRIPT_URI", req->uri.c_str()); | |
93 | ||
94 | char port_buf[16]; | |
95 | snprintf(port_buf, sizeof(port_buf), "%d", req->port); | |
96 | env.set("SERVER_PORT", port_buf); | |
97 | } | |
98 | ||
99 | size_t RGWLoadGenIO::send_status(const int status, | |
100 | const char* const status_name) | |
101 | { | |
102 | return 0; | |
103 | } | |
104 | ||
105 | size_t RGWLoadGenIO::send_100_continue() | |
106 | { | |
107 | return 0; | |
108 | } | |
109 | ||
110 | size_t RGWLoadGenIO::send_header(const boost::string_ref& name, | |
111 | const boost::string_ref& value) | |
112 | { | |
113 | return 0; | |
114 | } | |
115 | ||
116 | size_t RGWLoadGenIO::complete_header() | |
117 | { | |
118 | return 0; | |
119 | } | |
120 | ||
121 | size_t RGWLoadGenIO::send_content_length(const uint64_t len) | |
122 | { | |
123 | return 0; | |
124 | } |