Mercurial > hg > orthanc
annotate Core/HttpServer/MongooseServer.cpp @ 562:f64e3838d6e1 find-move-scp
refactoring enumerations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Sep 2013 16:49:48 +0200 |
parents | 6f8ae46ed90e |
children | 08eca5d86aad |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
398 | 3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege, |
0 | 4 * Belgium |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 // http://en.highscore.de/cpp/boost/stringhandling.html | |
34 | |
35 #include "MongooseServer.h" | |
36 | |
37 #include <algorithm> | |
38 #include <string.h> | |
39 #include <boost/lexical_cast.hpp> | |
40 #include <boost/algorithm/string.hpp> | |
41 #include <iostream> | |
42 #include <string.h> | |
43 #include <stdio.h> | |
44 #include <boost/thread.hpp> | |
108 | 45 #include <glog/logging.h> |
0 | 46 |
59 | 47 #include "../OrthancException.h" |
0 | 48 #include "../ChunkedBuffer.h" |
324 | 49 #include "HttpOutput.h" |
0 | 50 #include "mongoose.h" |
51 | |
52 | |
59 | 53 #define ORTHANC_REALM "Orthanc Secure Area" |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
54 |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
55 static const long LOCALHOST = (127ll << 24) + 1ll; |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
56 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
57 |
59 | 58 namespace Orthanc |
0 | 59 { |
60 static const char multipart[] = "multipart/form-data; boundary="; | |
61 static unsigned int multipartLength = sizeof(multipart) / sizeof(char) - 1; | |
62 | |
63 | |
64 namespace | |
65 { | |
66 // Anonymous namespace to avoid clashes between compilation modules | |
67 class MongooseOutput : public HttpOutput | |
68 { | |
69 private: | |
70 struct mg_connection* connection_; | |
71 | |
72 public: | |
73 MongooseOutput(struct mg_connection* connection) : connection_(connection) | |
74 { | |
75 } | |
76 | |
77 virtual void Send(const void* buffer, size_t length) | |
78 { | |
217 | 79 if (length > 0) |
80 { | |
81 mg_write(connection_, buffer, length); | |
82 } | |
0 | 83 } |
84 }; | |
85 | |
86 | |
87 enum PostDataStatus | |
88 { | |
89 PostDataStatus_Success, | |
90 PostDataStatus_NoLength, | |
91 PostDataStatus_Pending, | |
92 PostDataStatus_Failure | |
93 }; | |
94 } | |
95 | |
96 | |
97 // TODO Move this to external file | |
98 | |
99 | |
100 class ChunkedFile : public ChunkedBuffer | |
101 { | |
102 private: | |
103 std::string filename_; | |
104 | |
105 public: | |
106 ChunkedFile(const std::string& filename) : | |
107 filename_(filename) | |
108 { | |
109 } | |
110 | |
111 const std::string& GetFilename() const | |
112 { | |
113 return filename_; | |
114 } | |
115 }; | |
116 | |
117 | |
118 | |
119 class ChunkStore | |
120 { | |
121 private: | |
122 typedef std::list<ChunkedFile*> Content; | |
123 Content content_; | |
124 unsigned int numPlaces_; | |
125 | |
126 boost::mutex mutex_; | |
127 std::set<std::string> discardedFiles_; | |
128 | |
129 void Clear() | |
130 { | |
131 for (Content::iterator it = content_.begin(); | |
132 it != content_.end(); it++) | |
133 { | |
134 delete *it; | |
135 } | |
136 } | |
137 | |
138 Content::iterator Find(const std::string& filename) | |
139 { | |
140 for (Content::iterator it = content_.begin(); | |
141 it != content_.end(); it++) | |
142 { | |
143 if ((*it)->GetFilename() == filename) | |
144 { | |
145 return it; | |
146 } | |
147 } | |
148 | |
149 return content_.end(); | |
150 } | |
151 | |
152 void Remove(const std::string& filename) | |
153 { | |
154 Content::iterator it = Find(filename); | |
155 if (it != content_.end()) | |
156 { | |
157 delete *it; | |
158 content_.erase(it); | |
159 } | |
160 } | |
161 | |
162 public: | |
163 ChunkStore() | |
164 { | |
165 numPlaces_ = 10; | |
166 } | |
167 | |
168 ~ChunkStore() | |
169 { | |
170 Clear(); | |
171 } | |
172 | |
173 PostDataStatus Store(std::string& completed, | |
174 const char* chunkData, | |
175 size_t chunkSize, | |
176 const std::string& filename, | |
177 size_t filesize) | |
178 { | |
179 boost::mutex::scoped_lock lock(mutex_); | |
180 | |
181 std::set<std::string>::iterator wasDiscarded = discardedFiles_.find(filename); | |
182 if (wasDiscarded != discardedFiles_.end()) | |
183 { | |
184 discardedFiles_.erase(wasDiscarded); | |
185 return PostDataStatus_Failure; | |
186 } | |
187 | |
188 ChunkedFile* f; | |
189 Content::iterator it = Find(filename); | |
190 if (it == content_.end()) | |
191 { | |
192 f = new ChunkedFile(filename); | |
193 | |
194 // Make some room | |
195 if (content_.size() >= numPlaces_) | |
196 { | |
197 discardedFiles_.insert(content_.front()->GetFilename()); | |
198 delete content_.front(); | |
199 content_.pop_front(); | |
200 } | |
201 | |
202 content_.push_back(f); | |
203 } | |
204 else | |
205 { | |
206 f = *it; | |
207 } | |
208 | |
209 f->AddChunk(chunkData, chunkSize); | |
210 | |
211 if (f->GetNumBytes() > filesize) | |
212 { | |
213 Remove(filename); | |
214 } | |
215 else if (f->GetNumBytes() == filesize) | |
216 { | |
217 f->Flatten(completed); | |
218 Remove(filename); | |
219 return PostDataStatus_Success; | |
220 } | |
221 | |
222 return PostDataStatus_Pending; | |
223 } | |
224 | |
225 /*void Print() | |
226 { | |
227 boost::mutex::scoped_lock lock(mutex_); | |
228 | |
229 printf("ChunkStore status:\n"); | |
230 for (Content::const_iterator i = content_.begin(); | |
231 i != content_.end(); i++) | |
232 { | |
233 printf(" [%s]: %d\n", (*i)->GetFilename().c_str(), (*i)->GetNumBytes()); | |
234 } | |
235 printf("-----\n"); | |
236 }*/ | |
237 }; | |
238 | |
239 | |
240 struct MongooseServer::PImpl | |
241 { | |
242 struct mg_context *context_; | |
243 ChunkStore chunkStore_; | |
244 }; | |
245 | |
246 | |
247 ChunkStore& MongooseServer::GetChunkStore() | |
248 { | |
249 return pimpl_->chunkStore_; | |
250 } | |
251 | |
252 | |
253 | |
254 HttpHandler* MongooseServer::FindHandler(const UriComponents& forUri) const | |
255 { | |
256 for (Handlers::const_iterator it = | |
257 handlers_.begin(); it != handlers_.end(); it++) | |
258 { | |
259 if ((*it)->IsServedUri(forUri)) | |
260 { | |
261 return *it; | |
262 } | |
263 } | |
264 | |
265 return NULL; | |
266 } | |
267 | |
268 | |
269 | |
270 | |
416 | 271 static PostDataStatus ReadBody(std::string& postData, |
272 struct mg_connection *connection, | |
273 const HttpHandler::Arguments& headers) | |
0 | 274 { |
275 HttpHandler::Arguments::const_iterator cs = headers.find("content-length"); | |
276 if (cs == headers.end()) | |
277 { | |
278 return PostDataStatus_NoLength; | |
279 } | |
280 | |
281 int length; | |
282 try | |
283 { | |
284 length = boost::lexical_cast<int>(cs->second); | |
285 } | |
286 catch (boost::bad_lexical_cast) | |
287 { | |
288 return PostDataStatus_NoLength; | |
289 } | |
290 | |
291 if (length < 0) | |
292 { | |
293 length = 0; | |
294 } | |
295 | |
296 postData.resize(length); | |
297 | |
298 size_t pos = 0; | |
299 while (length > 0) | |
300 { | |
301 int r = mg_read(connection, &postData[pos], length); | |
302 if (r <= 0) | |
303 { | |
304 return PostDataStatus_Failure; | |
305 } | |
418
b79bf2f4ab2e
execution of lua through REST
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
417
diff
changeset
|
306 |
8 | 307 assert(r <= length); |
0 | 308 length -= r; |
309 pos += r; | |
310 } | |
311 | |
312 return PostDataStatus_Success; | |
313 } | |
314 | |
315 | |
316 | |
317 static PostDataStatus ParseMultipartPost(std::string &completedFile, | |
318 struct mg_connection *connection, | |
319 const HttpHandler::Arguments& headers, | |
320 const std::string& contentType, | |
321 ChunkStore& chunkStore) | |
322 { | |
323 std::string boundary = "--" + contentType.substr(multipartLength); | |
324 | |
325 std::string postData; | |
416 | 326 PostDataStatus status = ReadBody(postData, connection, headers); |
0 | 327 |
328 if (status != PostDataStatus_Success) | |
329 { | |
330 return status; | |
331 } | |
332 | |
333 /*for (HttpHandler::Arguments::const_iterator i = headers.begin(); i != headers.end(); i++) | |
334 { | |
335 std::cout << "Header [" << i->first << "] = " << i->second << "\n"; | |
336 } | |
337 printf("CHUNK\n");*/ | |
338 | |
339 typedef HttpHandler::Arguments::const_iterator ArgumentIterator; | |
340 | |
341 ArgumentIterator requestedWith = headers.find("x-requested-with"); | |
342 ArgumentIterator fileName = headers.find("x-file-name"); | |
343 ArgumentIterator fileSizeStr = headers.find("x-file-size"); | |
344 | |
338
3a3b3ba8c1e0
fix for uploads through internet explorer 7
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
333
diff
changeset
|
345 if (requestedWith != headers.end() && |
0 | 346 requestedWith->second != "XMLHttpRequest") |
347 { | |
348 return PostDataStatus_Failure; | |
349 } | |
350 | |
351 size_t fileSize = 0; | |
352 if (fileSizeStr != headers.end()) | |
353 { | |
354 try | |
355 { | |
356 fileSize = boost::lexical_cast<size_t>(fileSizeStr->second); | |
357 } | |
358 catch (boost::bad_lexical_cast) | |
359 { | |
360 return PostDataStatus_Failure; | |
361 } | |
362 } | |
363 | |
364 typedef boost::find_iterator<std::string::iterator> FindIterator; | |
10 | 365 typedef boost::iterator_range<char*> Range; |
0 | 366 |
367 //chunkStore.Print(); | |
368 | |
369 try | |
370 { | |
371 FindIterator last; | |
372 for (FindIterator it = | |
373 make_find_iterator(postData, boost::first_finder(boundary)); | |
374 it!=FindIterator(); | |
375 ++it) | |
376 { | |
377 if (last != FindIterator()) | |
378 { | |
10 | 379 Range part(&last->back(), &it->front()); |
0 | 380 Range content = boost::find_first(part, "\r\n\r\n"); |
345 | 381 if (/*content != Range()*/!content.empty()) |
0 | 382 { |
383 Range c(&content.back() + 1, &it->front() - 2); | |
384 size_t chunkSize = c.size(); | |
385 | |
386 if (chunkSize > 0) | |
387 { | |
388 const char* chunkData = &c.front(); | |
389 | |
390 if (fileName == headers.end()) | |
391 { | |
392 // This file is stored in a single chunk | |
393 completedFile.resize(chunkSize); | |
394 if (chunkSize > 0) | |
395 { | |
396 memcpy(&completedFile[0], chunkData, chunkSize); | |
397 } | |
398 return PostDataStatus_Success; | |
399 } | |
400 else | |
401 { | |
402 return chunkStore.Store(completedFile, chunkData, chunkSize, fileName->second, fileSize); | |
403 } | |
404 } | |
10 | 405 } |
0 | 406 } |
407 | |
408 last = it; | |
409 } | |
410 } | |
411 catch (std::length_error) | |
412 { | |
413 return PostDataStatus_Failure; | |
414 } | |
415 | |
416 return PostDataStatus_Pending; | |
417 } | |
418 | |
419 | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
420 static void SendUnauthorized(HttpOutput& output) |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
421 { |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
422 std::string s = "HTTP/1.1 401 Unauthorized\r\n" |
59 | 423 "WWW-Authenticate: Basic realm=\"" ORTHANC_REALM "\"" |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
424 "\r\n\r\n"; |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
425 output.Send(&s[0], s.size()); |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
426 } |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
427 |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
428 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
429 static bool Authorize(const MongooseServer& that, |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
430 const HttpHandler::Arguments& headers, |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
431 HttpOutput& output) |
23 | 432 { |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
433 bool granted = false; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
434 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
435 HttpHandler::Arguments::const_iterator auth = headers.find("authorization"); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
436 if (auth != headers.end()) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
437 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
438 std::string s = auth->second; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
439 if (s.substr(0, 6) == "Basic ") |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
440 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
441 std::string b64 = s.substr(6); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
442 granted = that.IsValidBasicHttpAuthentication(b64); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
443 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
444 } |
23 | 445 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
446 if (!granted) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
447 { |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
448 SendUnauthorized(output); |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
449 return false; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
450 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
451 else |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
452 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
453 return true; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
454 } |
23 | 455 } |
456 | |
457 | |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
458 static std::string GetAuthenticatedUsername(const HttpHandler::Arguments& headers) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
459 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
460 HttpHandler::Arguments::const_iterator auth = headers.find("authorization"); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
461 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
462 if (auth == headers.end()) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
463 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
464 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
465 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
466 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
467 std::string s = auth->second; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
468 if (s.substr(0, 6) != "Basic ") |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
469 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
470 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
471 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
472 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
473 std::string b64 = s.substr(6); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
474 std::string decoded = Toolbox::DecodeBase64(b64); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
475 size_t semicolons = decoded.find(':'); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
476 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
477 if (semicolons == std::string::npos) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
478 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
479 // Bad-formatted request |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
480 return ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
481 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
482 else |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
483 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
484 return decoded.substr(0, semicolons); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
485 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
486 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
487 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
488 |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
489 static bool ExtractMethod(HttpMethod& method, |
414 | 490 const struct mg_request_info *request, |
491 const HttpHandler::Arguments& headers, | |
492 const HttpHandler::Arguments& argumentsGET) | |
493 { | |
494 std::string overriden; | |
495 | |
496 // Check whether some PUT/DELETE faking is done | |
497 | |
498 // 1. Faking with Google's approach | |
499 HttpHandler::Arguments::const_iterator methodOverride = | |
500 headers.find("x-http-method-override"); | |
501 | |
502 if (methodOverride != headers.end()) | |
503 { | |
504 overriden = methodOverride->second; | |
505 } | |
506 else if (!strcmp(request->request_method, "GET")) | |
507 { | |
508 // 2. Faking with Ruby on Rail's approach | |
509 // GET /my/resource?_method=delete <=> DELETE /my/resource | |
510 methodOverride = argumentsGET.find("_method"); | |
511 if (methodOverride != argumentsGET.end()) | |
512 { | |
513 overriden = methodOverride->second; | |
514 } | |
515 } | |
516 | |
517 if (overriden.size() > 0) | |
518 { | |
519 // A faking has been done within this request | |
520 Toolbox::ToUpperCase(overriden); | |
521 | |
416 | 522 LOG(INFO) << "HTTP method faking has been detected for " << overriden; |
523 | |
414 | 524 if (overriden == "PUT") |
525 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
526 method = HttpMethod_Put; |
416 | 527 return true; |
414 | 528 } |
529 else if (overriden == "DELETE") | |
530 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
531 method = HttpMethod_Delete; |
416 | 532 return true; |
414 | 533 } |
534 else | |
535 { | |
536 return false; | |
537 } | |
538 } | |
539 | |
540 // No PUT/DELETE faking was present | |
541 if (!strcmp(request->request_method, "GET")) | |
542 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
543 method = HttpMethod_Get; |
414 | 544 } |
545 else if (!strcmp(request->request_method, "POST")) | |
546 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
547 method = HttpMethod_Post; |
414 | 548 } |
549 else if (!strcmp(request->request_method, "DELETE")) | |
550 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
551 method = HttpMethod_Delete; |
414 | 552 } |
553 else if (!strcmp(request->request_method, "PUT")) | |
554 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
555 method = HttpMethod_Put; |
414 | 556 } |
557 else | |
558 { | |
559 return false; | |
560 } | |
561 | |
562 return true; | |
563 } | |
564 | |
565 | |
0 | 566 |
567 static void* Callback(enum mg_event event, | |
568 struct mg_connection *connection, | |
569 const struct mg_request_info *request) | |
570 { | |
571 if (event == MG_NEW_REQUEST) | |
572 { | |
573 MongooseServer* that = (MongooseServer*) (request->user_data); | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
574 MongooseOutput output(connection); |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
575 |
414 | 576 // Check remote calls |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
577 if (!that->IsRemoteAccessAllowed() && |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
578 request->remote_ip != LOCALHOST) |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
579 { |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
580 SendUnauthorized(output); |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
581 return (void*) ""; |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
582 } |
0 | 583 |
584 | |
414 | 585 // Extract the HTTP headers |
586 HttpHandler::Arguments headers; | |
0 | 587 for (int i = 0; i < request->num_headers; i++) |
588 { | |
589 std::string name = request->http_headers[i].name; | |
590 std::transform(name.begin(), name.end(), name.begin(), ::tolower); | |
591 headers.insert(std::make_pair(name, request->http_headers[i].value)); | |
592 } | |
593 | |
414 | 594 |
595 // Extract the GET arguments | |
596 HttpHandler::Arguments argumentsGET; | |
597 if (!strcmp(request->request_method, "GET")) | |
598 { | |
599 HttpHandler::ParseGetQuery(argumentsGET, request->query_string); | |
600 } | |
601 | |
602 | |
603 // Compute the HTTP method, taking method faking into consideration | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
604 HttpMethod method; |
414 | 605 if (!ExtractMethod(method, request, headers, argumentsGET)) |
606 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
607 output.SendHeader(HttpStatus_400_BadRequest); |
414 | 608 return (void*) ""; |
609 } | |
610 | |
611 | |
23 | 612 // Authenticate this connection |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
613 if (that->IsAuthenticationEnabled() && |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
614 !Authorize(*that, headers, output)) |
23 | 615 { |
616 return (void*) ""; | |
617 } | |
618 | |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
619 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
620 // Apply the filter, if it is installed |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
621 const IIncomingHttpRequestFilter *filter = that->GetIncomingHttpRequestFilter(); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
622 if (filter != NULL) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
623 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
624 std::string username = GetAuthenticatedUsername(headers); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
625 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
626 char remoteIp[24]; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
627 sprintf(remoteIp, "%d.%d.%d.%d", |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
628 reinterpret_cast<const uint8_t*>(&request->remote_ip) [3], |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
629 reinterpret_cast<const uint8_t*>(&request->remote_ip) [2], |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
630 reinterpret_cast<const uint8_t*>(&request->remote_ip) [1], |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
631 reinterpret_cast<const uint8_t*>(&request->remote_ip) [0]); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
632 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
633 if (!filter->IsAllowed(method, request->uri, remoteIp, username.c_str())) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
634 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
635 SendUnauthorized(output); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
636 return (void*) ""; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
637 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
638 } |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
639 |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
640 |
414 | 641 // Extract the body of the request for PUT and POST |
642 std::string body; | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
643 if (method == HttpMethod_Post || |
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
644 method == HttpMethod_Put) |
0 | 645 { |
416 | 646 PostDataStatus status; |
647 | |
0 | 648 HttpHandler::Arguments::const_iterator ct = headers.find("content-type"); |
649 if (ct == headers.end()) | |
650 { | |
416 | 651 // No content-type specified. Assume no multi-part content occurs at this point. |
652 status = ReadBody(body, connection, headers); | |
0 | 653 } |
654 else | |
655 { | |
416 | 656 std::string contentType = ct->second; |
657 if (contentType.size() >= multipartLength && | |
658 !memcmp(contentType.c_str(), multipart, multipartLength)) | |
659 { | |
660 status = ParseMultipartPost(body, connection, headers, contentType, that->GetChunkStore()); | |
661 } | |
662 else | |
663 { | |
664 status = ReadBody(body, connection, headers); | |
665 } | |
0 | 666 } |
667 | |
668 switch (status) | |
669 { | |
416 | 670 case PostDataStatus_NoLength: |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
671 output.SendHeader(HttpStatus_411_LengthRequired); |
416 | 672 return (void*) ""; |
0 | 673 |
416 | 674 case PostDataStatus_Failure: |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
675 output.SendHeader(HttpStatus_400_BadRequest); |
416 | 676 return (void*) ""; |
0 | 677 |
416 | 678 case PostDataStatus_Pending: |
679 output.AnswerBufferWithContentType(NULL, 0, ""); | |
680 return (void*) ""; | |
0 | 681 |
416 | 682 default: |
683 break; | |
0 | 684 } |
685 } | |
686 | |
414 | 687 |
688 // Call the proper handler for this URI | |
0 | 689 UriComponents uri; |
415 | 690 try |
691 { | |
692 Toolbox::SplitUriComponents(uri, request->uri); | |
693 } | |
694 catch (OrthancException) | |
695 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
696 output.SendHeader(HttpStatus_400_BadRequest); |
415 | 697 return (void*) ""; |
698 } | |
699 | |
0 | 700 |
701 HttpHandler* handler = that->FindHandler(uri); | |
702 if (handler) | |
703 { | |
704 try | |
705 { | |
477 | 706 LOG(INFO) << EnumerationToString(method) << " " << Toolbox::FlattenUri(uri); |
414 | 707 handler->Handle(output, method, uri, headers, argumentsGET, body); |
0 | 708 } |
59 | 709 catch (OrthancException& e) |
0 | 710 { |
108 | 711 LOG(ERROR) << "MongooseServer Exception [" << e.What() << "]"; |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
712 output.SendHeader(HttpStatus_500_InternalServerError); |
0 | 713 } |
327
4564e908bba9
handling of bad lexical casts in http server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
324
diff
changeset
|
714 catch (boost::bad_lexical_cast&) |
4564e908bba9
handling of bad lexical casts in http server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
324
diff
changeset
|
715 { |
4564e908bba9
handling of bad lexical casts in http server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
324
diff
changeset
|
716 LOG(ERROR) << "MongooseServer Exception: Bad lexical cast"; |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
717 output.SendHeader(HttpStatus_400_BadRequest); |
333 | 718 } |
719 catch (std::runtime_error&) | |
720 { | |
721 LOG(ERROR) << "MongooseServer Exception: Presumably a bad JSON request"; | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
722 output.SendHeader(HttpStatus_400_BadRequest); |
327
4564e908bba9
handling of bad lexical casts in http server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
324
diff
changeset
|
723 } |
0 | 724 } |
725 else | |
726 { | |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
418
diff
changeset
|
727 output.SendHeader(HttpStatus_404_NotFound); |
0 | 728 } |
729 | |
730 // Mark as processed | |
731 return (void*) ""; | |
732 } | |
733 else | |
734 { | |
735 return NULL; | |
736 } | |
737 } | |
738 | |
739 | |
740 bool MongooseServer::IsRunning() const | |
741 { | |
742 return (pimpl_->context_ != NULL); | |
743 } | |
744 | |
745 | |
746 MongooseServer::MongooseServer() : pimpl_(new PImpl) | |
747 { | |
748 pimpl_->context_ = NULL; | |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
749 remoteAllowed_ = false; |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
750 authentication_ = false; |
23 | 751 ssl_ = false; |
0 | 752 port_ = 8000; |
417 | 753 filter_ = NULL; |
0 | 754 } |
755 | |
756 | |
757 MongooseServer::~MongooseServer() | |
758 { | |
759 Stop(); | |
760 ClearHandlers(); | |
761 } | |
762 | |
763 | |
128 | 764 void MongooseServer::SetPortNumber(uint16_t port) |
0 | 765 { |
766 Stop(); | |
767 port_ = port; | |
768 } | |
769 | |
770 void MongooseServer::Start() | |
771 { | |
772 if (!IsRunning()) | |
773 { | |
774 std::string port = boost::lexical_cast<std::string>(port_); | |
775 | |
23 | 776 if (ssl_) |
777 { | |
778 port += "s"; | |
779 } | |
780 | |
0 | 781 const char *options[] = { |
782 "listening_ports", port.c_str(), | |
23 | 783 ssl_ ? "ssl_certificate" : NULL, |
784 certificate_.c_str(), | |
0 | 785 NULL |
786 }; | |
787 | |
788 pimpl_->context_ = mg_start(&Callback, this, options); | |
789 if (!pimpl_->context_) | |
790 { | |
59 | 791 throw OrthancException("Unable to launch the Mongoose server"); |
0 | 792 } |
793 } | |
794 } | |
795 | |
796 void MongooseServer::Stop() | |
797 { | |
798 if (IsRunning()) | |
799 { | |
800 mg_stop(pimpl_->context_); | |
801 pimpl_->context_ = NULL; | |
802 } | |
803 } | |
804 | |
805 | |
806 void MongooseServer::RegisterHandler(HttpHandler* handler) | |
807 { | |
808 Stop(); | |
809 | |
810 handlers_.push_back(handler); | |
811 } | |
812 | |
813 | |
814 void MongooseServer::ClearHandlers() | |
815 { | |
816 Stop(); | |
817 | |
818 for (Handlers::iterator it = | |
819 handlers_.begin(); it != handlers_.end(); it++) | |
820 { | |
821 delete *it; | |
822 } | |
823 } | |
824 | |
23 | 825 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
826 void MongooseServer::ClearUsers() |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
827 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
828 Stop(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
829 registeredUsers_.clear(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
830 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
831 |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
832 |
23 | 833 void MongooseServer::RegisterUser(const char* username, |
834 const char* password) | |
835 { | |
836 Stop(); | |
24 | 837 |
838 std::string tag = std::string(username) + ":" + std::string(password); | |
839 registeredUsers_.insert(Toolbox::EncodeBase64(tag)); | |
23 | 840 } |
841 | |
842 void MongooseServer::SetSslEnabled(bool enabled) | |
843 { | |
844 Stop(); | |
845 | |
59 | 846 #if ORTHANC_SSL_ENABLED == 0 |
23 | 847 if (enabled) |
848 { | |
59 | 849 throw OrthancException("Orthanc has been built without SSL support"); |
23 | 850 } |
851 else | |
852 { | |
853 ssl_ = false; | |
854 } | |
855 #else | |
856 ssl_ = enabled; | |
857 #endif | |
858 } | |
859 | |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
860 void MongooseServer::SetAuthenticationEnabled(bool enabled) |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
861 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
862 Stop(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
863 authentication_ = enabled; |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
864 } |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
865 |
23 | 866 void MongooseServer::SetSslCertificate(const char* path) |
867 { | |
868 Stop(); | |
869 certificate_ = path; | |
870 } | |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
871 |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
872 void MongooseServer::SetRemoteAccessAllowed(bool allowed) |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
873 { |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
874 Stop(); |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
875 remoteAllowed_ = allowed; |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
876 } |
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
877 |
409
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
878 void MongooseServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter) |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
879 { |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
880 Stop(); |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
881 filter_ = &filter; |
63f707278fc8
lua filtering of incoming http requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
398
diff
changeset
|
882 } |
34
96e57b863dd9
option to disallow remote access
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
25
diff
changeset
|
883 |
25
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
884 bool MongooseServer::IsValidBasicHttpAuthentication(const std::string& basic) const |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
885 { |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
886 return registeredUsers_.find(basic) != registeredUsers_.end(); |
dd1489098265
basic http authentication
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
887 } |
0 | 888 } |