Mercurial > hg > orthanc
comparison Core/WebServiceParameters.cpp @ 2823:807169f85ba9
OrthancPluginGetPeerUserProperty()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 18 Sep 2018 15:38:18 +0200 |
parents | dc7330089736 |
children | d924f9bb61cc |
comparison
equal
deleted
inserted
replaced
2822:a0b729ac0549 | 2823:807169f85ba9 |
---|---|
56 static const char* KEY_URL = "Url"; | 56 static const char* KEY_URL = "Url"; |
57 static const char* KEY_URL_2 = "URL"; | 57 static const char* KEY_URL_2 = "URL"; |
58 static const char* KEY_USERNAME = "Username"; | 58 static const char* KEY_USERNAME = "Username"; |
59 | 59 |
60 | 60 |
61 static bool IsReservedKey(const std::string& key) | |
62 { | |
63 return (key == KEY_CERTIFICATE_FILE || | |
64 key == KEY_CERTIFICATE_KEY_FILE || | |
65 key == KEY_CERTIFICATE_KEY_PASSWORD || | |
66 key == KEY_HTTP_HEADERS || | |
67 key == KEY_PASSWORD || | |
68 key == KEY_PKCS11 || | |
69 key == KEY_URL || | |
70 key == KEY_URL_2 || | |
71 key == KEY_USERNAME); | |
72 } | |
73 | |
74 | |
61 WebServiceParameters::WebServiceParameters() : | 75 WebServiceParameters::WebServiceParameters() : |
62 pkcs11Enabled_(false) | 76 pkcs11Enabled_(false) |
63 { | 77 { |
64 SetUrl("http://127.0.0.1:8042/"); | 78 SetUrl("http://127.0.0.1:8042/"); |
65 } | 79 } |
234 } | 248 } |
235 else | 249 else |
236 { | 250 { |
237 pkcs11Enabled_ = false; | 251 pkcs11Enabled_ = false; |
238 } | 252 } |
253 | |
239 | 254 |
240 headers_.clear(); | 255 headers_.clear(); |
241 | 256 |
242 if (peer.isMember(KEY_HTTP_HEADERS)) | 257 if (peer.isMember(KEY_HTTP_HEADERS)) |
243 { | 258 { |
261 headers_[keys[i]] = value.asString(); | 276 headers_[keys[i]] = value.asString(); |
262 } | 277 } |
263 } | 278 } |
264 } | 279 } |
265 } | 280 } |
281 | |
282 | |
283 userProperties_.clear(); | |
284 | |
285 const Json::Value::Members members = peer.getMemberNames(); | |
286 | |
287 for (Json::Value::Members::const_iterator it = members.begin(); | |
288 it != members.end(); ++it) | |
289 { | |
290 if (!IsReservedKey(*it)) | |
291 { | |
292 if (peer[*it].type() != Json::stringValue) | |
293 { | |
294 throw OrthancException(ErrorCode_BadFileFormat); | |
295 } | |
296 else | |
297 { | |
298 userProperties_[*it] = peer[*it].asString(); | |
299 } | |
300 } | |
301 } | |
266 } | 302 } |
267 | 303 |
268 | 304 |
269 void WebServiceParameters::Unserialize(const Json::Value& peer) | 305 void WebServiceParameters::Unserialize(const Json::Value& peer) |
270 { | 306 { |
296 | 332 |
297 void WebServiceParameters::ListHttpHeaders(std::set<std::string>& target) const | 333 void WebServiceParameters::ListHttpHeaders(std::set<std::string>& target) const |
298 { | 334 { |
299 target.clear(); | 335 target.clear(); |
300 | 336 |
301 for (HttpHeaders::const_iterator it = headers_.begin(); | 337 for (Dictionary::const_iterator it = headers_.begin(); |
302 it != headers_.end(); ++it) | 338 it != headers_.end(); ++it) |
303 { | 339 { |
304 target.insert(it->first); | 340 target.insert(it->first); |
305 } | 341 } |
306 } | 342 } |
307 | 343 |
308 | 344 |
309 bool WebServiceParameters::LookupHttpHeader(std::string& value, | 345 bool WebServiceParameters::LookupHttpHeader(std::string& value, |
310 const std::string& key) const | 346 const std::string& key) const |
311 { | 347 { |
312 HttpHeaders::const_iterator found = headers_.find(key); | 348 Dictionary::const_iterator found = headers_.find(key); |
313 | 349 |
314 if (found == headers_.end()) | 350 if (found == headers_.end()) |
351 { | |
352 return false; | |
353 } | |
354 else | |
355 { | |
356 value = found->second; | |
357 return true; | |
358 } | |
359 } | |
360 | |
361 | |
362 void WebServiceParameters::AddUserProperty(const std::string& key, | |
363 const std::string& value) | |
364 { | |
365 if (IsReservedKey(key)) | |
366 { | |
367 LOG(ERROR) << "Cannot use this reserved key to name an user property: " << key; | |
368 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
369 } | |
370 else | |
371 { | |
372 userProperties_[key] = value; | |
373 } | |
374 } | |
375 | |
376 | |
377 void WebServiceParameters::ListUserProperties(std::set<std::string>& target) const | |
378 { | |
379 target.clear(); | |
380 | |
381 for (Dictionary::const_iterator it = userProperties_.begin(); | |
382 it != userProperties_.end(); ++it) | |
383 { | |
384 target.insert(it->first); | |
385 } | |
386 } | |
387 | |
388 | |
389 bool WebServiceParameters::LookupUserProperty(std::string& value, | |
390 const std::string& key) const | |
391 { | |
392 Dictionary::const_iterator found = userProperties_.find(key); | |
393 | |
394 if (found == userProperties_.end()) | |
315 { | 395 { |
316 return false; | 396 return false; |
317 } | 397 } |
318 else | 398 else |
319 { | 399 { |
327 { | 407 { |
328 return (!certificateFile_.empty() || | 408 return (!certificateFile_.empty() || |
329 !certificateKeyFile_.empty() || | 409 !certificateKeyFile_.empty() || |
330 !certificateKeyPassword_.empty() || | 410 !certificateKeyPassword_.empty() || |
331 pkcs11Enabled_ || | 411 pkcs11Enabled_ || |
332 !headers_.empty()); | 412 !headers_.empty() || |
413 !userProperties_.empty()); | |
333 } | 414 } |
334 | 415 |
335 | 416 |
336 void WebServiceParameters::Serialize(Json::Value& value, | 417 void WebServiceParameters::Serialize(Json::Value& value, |
337 bool forceAdvancedFormat, | 418 bool forceAdvancedFormat, |
371 } | 452 } |
372 | 453 |
373 value[KEY_PKCS11] = pkcs11Enabled_; | 454 value[KEY_PKCS11] = pkcs11Enabled_; |
374 | 455 |
375 value[KEY_HTTP_HEADERS] = Json::objectValue; | 456 value[KEY_HTTP_HEADERS] = Json::objectValue; |
376 for (HttpHeaders::const_iterator it = headers_.begin(); | 457 for (Dictionary::const_iterator it = headers_.begin(); |
377 it != headers_.end(); ++it) | 458 it != headers_.end(); ++it) |
378 { | 459 { |
379 value[KEY_HTTP_HEADERS][it->first] = it->second; | 460 value[KEY_HTTP_HEADERS][it->first] = it->second; |
461 } | |
462 | |
463 for (Dictionary::const_iterator it = userProperties_.begin(); | |
464 it != userProperties_.end(); ++it) | |
465 { | |
466 value[it->first] = it->second; | |
380 } | 467 } |
381 } | 468 } |
382 else | 469 else |
383 { | 470 { |
384 value = Json::arrayValue; | 471 value = Json::arrayValue; |