Mercurial > hg > orthanc
annotate Core/HttpServer/HttpHandler.cpp @ 1048:648bf1457113
fix build
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 18 Jul 2014 17:18:33 +0200 |
parents | dcb2469f00f4 |
children | 6e7e5ed91c2d |
rev | line source |
---|---|
0 | 1 /** |
59 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
689 | 3 * Copyright (C) 2012-2014 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 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
33 #include "../PrecompiledHeaders.h" |
0 | 34 #include "HttpHandler.h" |
35 | |
36 #include <string.h> | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
37 #include <iostream> |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
38 |
0 | 39 |
59 | 40 namespace Orthanc |
0 | 41 { |
42 static void SplitGETNameValue(HttpHandler::Arguments& result, | |
43 const char* start, | |
44 const char* end) | |
45 { | |
334 | 46 std::string name, value; |
47 | |
0 | 48 const char* equal = strchr(start, '='); |
49 if (equal == NULL || equal >= end) | |
50 { | |
334 | 51 name = std::string(start, end - start); |
52 //value = ""; | |
0 | 53 } |
54 else | |
55 { | |
334 | 56 name = std::string(start, equal - start); |
57 value = std::string(equal + 1, end); | |
0 | 58 } |
334 | 59 |
336 | 60 Toolbox::UrlDecode(name); |
61 Toolbox::UrlDecode(value); | |
62 | |
334 | 63 result.insert(std::make_pair(name, value)); |
0 | 64 } |
65 | |
66 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
67 void HttpHandler::ParseGetArguments(HttpHandler::Arguments& result, const char* query) |
0 | 68 { |
69 const char* pos = query; | |
70 | |
71 while (pos != NULL) | |
72 { | |
73 const char* ampersand = strchr(pos, '&'); | |
74 if (ampersand) | |
75 { | |
76 SplitGETNameValue(result, pos, ampersand); | |
77 pos = ampersand + 1; | |
78 } | |
79 else | |
80 { | |
81 // No more ampersand, this is the last argument | |
82 SplitGETNameValue(result, pos, pos + strlen(pos)); | |
83 pos = NULL; | |
84 } | |
85 } | |
86 } | |
87 | |
88 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
89 void HttpHandler::ParseGetQuery(UriComponents& uri, |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
90 HttpHandler::Arguments& getArguments, |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
91 const char* query) |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
92 { |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
93 const char *questionMark = ::strchr(query, '?'); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
94 if (questionMark == NULL) |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
95 { |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
96 // No question mark in the string |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
97 Toolbox::SplitUriComponents(uri, query); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
98 getArguments.clear(); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
99 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
100 else |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
101 { |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
102 Toolbox::SplitUriComponents(uri, std::string(query, questionMark)); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
103 HttpHandler::ParseGetArguments(getArguments, questionMark + 1); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
104 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
105 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
106 |
0 | 107 |
207 | 108 std::string HttpHandler::GetArgument(const Arguments& getArguments, |
0 | 109 const std::string& name, |
110 const std::string& defaultValue) | |
111 { | |
207 | 112 Arguments::const_iterator it = getArguments.find(name); |
113 if (it == getArguments.end()) | |
0 | 114 { |
115 return defaultValue; | |
116 } | |
117 else | |
118 { | |
119 return it->second; | |
120 } | |
121 } | |
330 | 122 |
123 | |
124 | |
125 void HttpHandler::ParseCookies(HttpHandler::Arguments& result, | |
126 const HttpHandler::Arguments& httpHeaders) | |
127 { | |
128 result.clear(); | |
129 | |
332 | 130 HttpHandler::Arguments::const_iterator it = httpHeaders.find("cookie"); |
330 | 131 if (it != httpHeaders.end()) |
132 { | |
133 const std::string& cookies = it->second; | |
134 | |
135 size_t pos = 0; | |
136 while (pos != std::string::npos) | |
137 { | |
138 size_t nextSemicolon = cookies.find(";", pos); | |
139 std::string cookie; | |
140 | |
141 if (nextSemicolon == std::string::npos) | |
142 { | |
143 cookie = cookies.substr(pos); | |
144 pos = std::string::npos; | |
145 } | |
146 else | |
147 { | |
148 cookie = cookies.substr(pos, nextSemicolon - pos); | |
149 pos = nextSemicolon + 1; | |
150 } | |
151 | |
152 size_t equal = cookie.find("="); | |
153 if (equal != std::string::npos) | |
154 { | |
155 std::string name = Toolbox::StripSpaces(cookie.substr(0, equal)); | |
156 std::string value = Toolbox::StripSpaces(cookie.substr(equal + 1)); | |
157 result[name] = value; | |
158 } | |
159 } | |
160 } | |
161 } | |
0 | 162 } |