0
|
1 /**
|
|
2 * Palantir - A Lightweight, RESTful DICOM Store
|
|
3 * Copyright (C) 2012 Medical Physics Department, CHU of Liege,
|
|
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.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful, but
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 **/
|
|
19
|
|
20
|
|
21 #include "HttpHandler.h"
|
|
22
|
|
23 #include <string.h>
|
|
24
|
|
25 namespace Palantir
|
|
26 {
|
|
27 static void SplitGETNameValue(HttpHandler::Arguments& result,
|
|
28 const char* start,
|
|
29 const char* end)
|
|
30 {
|
|
31 const char* equal = strchr(start, '=');
|
|
32 if (equal == NULL || equal >= end)
|
|
33 {
|
|
34 result.insert(std::make_pair(std::string(start, end - start), ""));
|
|
35 }
|
|
36 else
|
|
37 {
|
|
38 result.insert(std::make_pair(std::string(start, equal - start),
|
|
39 std::string(equal + 1, end)));
|
|
40 }
|
|
41 }
|
|
42
|
|
43
|
|
44 void HttpHandler::ParseGetQuery(HttpHandler::Arguments& result, const char* query)
|
|
45 {
|
|
46 const char* pos = query;
|
|
47
|
|
48 while (pos != NULL)
|
|
49 {
|
|
50 const char* ampersand = strchr(pos, '&');
|
|
51 if (ampersand)
|
|
52 {
|
|
53 SplitGETNameValue(result, pos, ampersand);
|
|
54 pos = ampersand + 1;
|
|
55 }
|
|
56 else
|
|
57 {
|
|
58 // No more ampersand, this is the last argument
|
|
59 SplitGETNameValue(result, pos, pos + strlen(pos));
|
|
60 pos = NULL;
|
|
61 }
|
|
62 }
|
|
63 }
|
|
64
|
|
65
|
|
66
|
|
67 std::string HttpHandler::GetArgument(const Arguments& arguments,
|
|
68 const std::string& name,
|
|
69 const std::string& defaultValue)
|
|
70 {
|
|
71 Arguments::const_iterator it = arguments.find(name);
|
|
72 if (it == arguments.end())
|
|
73 {
|
|
74 return defaultValue;
|
|
75 }
|
|
76 else
|
|
77 {
|
|
78 return it->second;
|
|
79 }
|
|
80 }
|
|
81 }
|