comparison OrthancFramework/Sources/HttpServer/HttpToolbox.cpp @ 4330:a01b1c9cbef4

moving generic type definitions from IHttpHandler to HttpToolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Nov 2020 14:39:10 +0100
parents 9dc0e42f868b
children 17d209a3f397
comparison
equal deleted inserted replaced
4329:9dc0e42f868b 4330:a01b1c9cbef4
23 #include "../PrecompiledHeaders.h" 23 #include "../PrecompiledHeaders.h"
24 #include "HttpToolbox.h" 24 #include "HttpToolbox.h"
25 25
26 #include <string.h> 26 #include <string.h>
27 27
28 #if ORTHANC_SANDBOXED != 1
29 # include "IHttpHandler.h"
30 #endif
31
28 32
29 namespace Orthanc 33 namespace Orthanc
30 { 34 {
31 static void SplitGETNameValue(IHttpHandler::GetArguments& result, 35 static void SplitGETNameValue(HttpToolbox::GetArguments& result,
32 const char* start, 36 const char* start,
33 const char* end) 37 const char* end)
34 { 38 {
35 std::string name, value; 39 std::string name, value;
36 40
51 55
52 result.push_back(std::make_pair(name, value)); 56 result.push_back(std::make_pair(name, value));
53 } 57 }
54 58
55 59
56 void HttpToolbox::ParseGetArguments(IHttpHandler::GetArguments& result, 60 void HttpToolbox::ParseGetArguments(GetArguments& result,
57 const char* query) 61 const char* query)
58 { 62 {
59 const char* pos = query; 63 const char* pos = query;
60 64
61 while (pos != NULL) 65 while (pos != NULL)
75 } 79 }
76 } 80 }
77 81
78 82
79 void HttpToolbox::ParseGetQuery(UriComponents& uri, 83 void HttpToolbox::ParseGetQuery(UriComponents& uri,
80 IHttpHandler::GetArguments& getArguments, 84 GetArguments& getArguments,
81 const char* query) 85 const char* query)
82 { 86 {
83 const char *questionMark = ::strchr(query, '?'); 87 const char *questionMark = ::strchr(query, '?');
84 if (questionMark == NULL) 88 if (questionMark == NULL)
85 { 89 {
93 HttpToolbox::ParseGetArguments(getArguments, questionMark + 1); 97 HttpToolbox::ParseGetArguments(getArguments, questionMark + 1);
94 } 98 }
95 } 99 }
96 100
97 101
98 std::string HttpToolbox::GetArgument(const IHttpHandler::Arguments& getArguments, 102 std::string HttpToolbox::GetArgument(const Arguments& getArguments,
99 const std::string& name, 103 const std::string& name,
100 const std::string& defaultValue) 104 const std::string& defaultValue)
101 { 105 {
102 IHttpHandler::Arguments::const_iterator it = getArguments.find(name); 106 Arguments::const_iterator it = getArguments.find(name);
103 if (it == getArguments.end()) 107 if (it == getArguments.end())
104 { 108 {
105 return defaultValue; 109 return defaultValue;
106 } 110 }
107 else 111 else
109 return it->second; 113 return it->second;
110 } 114 }
111 } 115 }
112 116
113 117
114 std::string HttpToolbox::GetArgument(const IHttpHandler::GetArguments& getArguments, 118 std::string HttpToolbox::GetArgument(const GetArguments& getArguments,
115 const std::string& name, 119 const std::string& name,
116 const std::string& defaultValue) 120 const std::string& defaultValue)
117 { 121 {
118 for (size_t i = 0; i < getArguments.size(); i++) 122 for (size_t i = 0; i < getArguments.size(); i++)
119 { 123 {
126 return defaultValue; 130 return defaultValue;
127 } 131 }
128 132
129 133
130 134
131 void HttpToolbox::ParseCookies(IHttpHandler::Arguments& result, 135 void HttpToolbox::ParseCookies(Arguments& result,
132 const IHttpHandler::Arguments& httpHeaders) 136 const Arguments& httpHeaders)
133 { 137 {
134 result.clear(); 138 result.clear();
135 139
136 IHttpHandler::Arguments::const_iterator it = httpHeaders.find("cookie"); 140 Arguments::const_iterator it = httpHeaders.find("cookie");
137 if (it != httpHeaders.end()) 141 if (it != httpHeaders.end())
138 { 142 {
139 const std::string& cookies = it->second; 143 const std::string& cookies = it->second;
140 144
141 size_t pos = 0; 145 size_t pos = 0;
165 } 169 }
166 } 170 }
167 } 171 }
168 172
169 173
170 void HttpToolbox::CompileGetArguments(IHttpHandler::Arguments& compiled, 174 void HttpToolbox::CompileGetArguments(Arguments& compiled,
171 const IHttpHandler::GetArguments& source) 175 const GetArguments& source)
172 { 176 {
173 compiled.clear(); 177 compiled.clear();
174 178
175 for (size_t i = 0; i < source.size(); i++) 179 for (size_t i = 0; i < source.size(); i++)
176 { 180 {
177 compiled[source[i].first] = source[i].second; 181 compiled[source[i].first] = source[i].second;
178 } 182 }
179 } 183 }
184
185
186
187 #if ORTHANC_SANDBOXED != 1
188 bool HttpToolbox::SimpleGet(std::string& result,
189 IHttpHandler& handler,
190 RequestOrigin origin,
191 const std::string& uri,
192 const Arguments& httpHeaders)
193 {
194 return IHttpHandler::SimpleGet(result, handler, origin, uri, httpHeaders);
195 }
196
197 bool HttpToolbox::SimplePost(std::string& result,
198 IHttpHandler& handler,
199 RequestOrigin origin,
200 const std::string& uri,
201 const void* bodyData,
202 size_t bodySize,
203 const Arguments& httpHeaders)
204 {
205 return IHttpHandler::SimplePost(result, handler, origin, uri, bodyData, bodySize, httpHeaders);
206 }
207
208 bool HttpToolbox::SimplePut(std::string& result,
209 IHttpHandler& handler,
210 RequestOrigin origin,
211 const std::string& uri,
212 const void* bodyData,
213 size_t bodySize,
214 const Arguments& httpHeaders)
215 {
216 return IHttpHandler::SimplePut(result, handler, origin, uri, bodyData, bodySize, httpHeaders);
217 }
218
219 bool HttpToolbox::SimpleDelete(IHttpHandler& handler,
220 RequestOrigin origin,
221 const std::string& uri,
222 const Arguments& httpHeaders)
223 {
224 return IHttpHandler::SimpleDelete(handler, origin, uri, httpHeaders);
225 }
226 #endif
180 } 227 }