comparison Core/HttpServer/HttpHandler.cpp @ 1363:feaf2840917c

Plugins now receive duplicated GET arguments in their REST callbacks
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 May 2015 15:21:26 +0200
parents 6e7e5ed91c2d
children 02f5a3f5c0a0
comparison
equal deleted inserted replaced
1362:bf6db7d2f8b1 1363:feaf2840917c
37 #include <iostream> 37 #include <iostream>
38 38
39 39
40 namespace Orthanc 40 namespace Orthanc
41 { 41 {
42 static void SplitGETNameValue(HttpHandler::Arguments& result, 42 static void SplitGETNameValue(HttpHandler::GetArguments& result,
43 const char* start, 43 const char* start,
44 const char* end) 44 const char* end)
45 { 45 {
46 std::string name, value; 46 std::string name, value;
47 47
58 } 58 }
59 59
60 Toolbox::UrlDecode(name); 60 Toolbox::UrlDecode(name);
61 Toolbox::UrlDecode(value); 61 Toolbox::UrlDecode(value);
62 62
63 result.insert(std::make_pair(name, value)); 63 result.push_back(std::make_pair(name, value));
64 } 64 }
65 65
66 66
67 void HttpHandler::ParseGetArguments(HttpHandler::Arguments& result, const char* query) 67 void HttpHandler::ParseGetArguments(HttpHandler::GetArguments& result,
68 const char* query)
68 { 69 {
69 const char* pos = query; 70 const char* pos = query;
70 71
71 while (pos != NULL) 72 while (pos != NULL)
72 { 73 {
85 } 86 }
86 } 87 }
87 88
88 89
89 void HttpHandler::ParseGetQuery(UriComponents& uri, 90 void HttpHandler::ParseGetQuery(UriComponents& uri,
90 HttpHandler::Arguments& getArguments, 91 HttpHandler::GetArguments& getArguments,
91 const char* query) 92 const char* query)
92 { 93 {
93 const char *questionMark = ::strchr(query, '?'); 94 const char *questionMark = ::strchr(query, '?');
94 if (questionMark == NULL) 95 if (questionMark == NULL)
95 { 96 {
102 Toolbox::SplitUriComponents(uri, std::string(query, questionMark)); 103 Toolbox::SplitUriComponents(uri, std::string(query, questionMark));
103 HttpHandler::ParseGetArguments(getArguments, questionMark + 1); 104 HttpHandler::ParseGetArguments(getArguments, questionMark + 1);
104 } 105 }
105 } 106 }
106 107
107 108
108 std::string HttpHandler::GetArgument(const Arguments& getArguments, 109 std::string HttpHandler::GetArgument(const Arguments& getArguments,
109 const std::string& name, 110 const std::string& name,
110 const std::string& defaultValue) 111 const std::string& defaultValue)
111 { 112 {
112 Arguments::const_iterator it = getArguments.find(name); 113 Arguments::const_iterator it = getArguments.find(name);
116 } 117 }
117 else 118 else
118 { 119 {
119 return it->second; 120 return it->second;
120 } 121 }
122 }
123
124
125 std::string HttpHandler::GetArgument(const GetArguments& getArguments,
126 const std::string& name,
127 const std::string& defaultValue)
128 {
129 for (size_t i = 0; i < getArguments.size(); i++)
130 {
131 if (getArguments[i].first == name)
132 {
133 return getArguments[i].second;
134 }
135 }
136
137 return defaultValue;
121 } 138 }
122 139
123 140
124 141
125 void HttpHandler::ParseCookies(HttpHandler::Arguments& result, 142 void HttpHandler::ParseCookies(HttpHandler::Arguments& result,
157 result[name] = value; 174 result[name] = value;
158 } 175 }
159 } 176 }
160 } 177 }
161 } 178 }
179
180
181 void HttpHandler::CompileGetArguments(Arguments& compiled,
182 const GetArguments& source)
183 {
184 compiled.clear();
185
186 for (size_t i = 0; i < source.size(); i++)
187 {
188 compiled[source[i].first] = source[i].second;
189 }
190 }
162 } 191 }