Mercurial > hg > orthanc
comparison OrthancServer/OrthancInitialization.cpp @ 752:45715eadc2e0
port number as a string
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 14 Apr 2014 17:17:38 +0200 |
parents | ef4569ae7952 |
children | 537837f50fbb |
comparison
equal
deleted
inserted
replaced
751:5197fd35333c | 752:45715eadc2e0 |
---|---|
250 { | 250 { |
251 boost::mutex::scoped_lock lock(globalMutex_); | 251 boost::mutex::scoped_lock lock(globalMutex_); |
252 | 252 |
253 if (!configuration_->isMember("DicomModalities")) | 253 if (!configuration_->isMember("DicomModalities")) |
254 { | 254 { |
255 throw OrthancException(""); | 255 throw OrthancException(ErrorCode_BadFileFormat); |
256 } | 256 } |
257 | 257 |
258 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; | 258 const Json::Value& modalities = (*configuration_) ["DicomModalities"]; |
259 if (modalities.type() != Json::objectValue || | 259 if (modalities.type() != Json::objectValue || |
260 !modalities.isMember(name) || | 260 !modalities.isMember(name) || |
261 (modalities[name].size() != 3 && modalities[name].size() != 4)) | 261 (modalities[name].size() != 3 && modalities[name].size() != 4)) |
262 { | 262 { |
263 throw OrthancException(""); | 263 throw OrthancException(ErrorCode_BadFileFormat); |
264 } | 264 } |
265 | 265 |
266 try | 266 try |
267 { | 267 { |
268 aet = modalities[name].get(0u, "").asString(); | 268 aet = modalities[name].get(0u, "").asString(); |
269 address = modalities[name].get(1u, "").asString(); | 269 address = modalities[name].get(1u, "").asString(); |
270 port = modalities[name].get(2u, "").asInt(); | 270 |
271 const Json::Value& portValue = modalities[name].get(2u, ""); | |
272 try | |
273 { | |
274 port = portValue.asInt(); | |
275 } | |
276 catch (std::runtime_error /* error inside JsonCpp */) | |
277 { | |
278 try | |
279 { | |
280 port = boost::lexical_cast<int>(portValue.asString()); | |
281 } | |
282 catch (boost::bad_lexical_cast) | |
283 { | |
284 throw OrthancException(ErrorCode_BadFileFormat); | |
285 } | |
286 } | |
271 | 287 |
272 if (modalities[name].size() == 4) | 288 if (modalities[name].size() == 4) |
273 { | 289 { |
274 manufacturer = StringToModalityManufacturer(modalities[name].get(3u, "").asString()); | 290 manufacturer = StringToModalityManufacturer(modalities[name].get(3u, "").asString()); |
275 } | 291 } |
276 else | 292 else |
277 { | 293 { |
278 manufacturer = ModalityManufacturer_Generic; | 294 manufacturer = ModalityManufacturer_Generic; |
279 } | 295 } |
280 } | 296 } |
281 catch (...) | 297 catch (OrthancException& e) |
282 { | 298 { |
283 throw OrthancException("Badly formatted DICOM modality"); | 299 LOG(ERROR) << "Syntax error in the definition of modality \"" << name |
300 << "\". Please check your configuration file."; | |
301 throw e; | |
284 } | 302 } |
285 } | 303 } |
286 | 304 |
287 | 305 |
288 | 306 |
293 { | 311 { |
294 boost::mutex::scoped_lock lock(globalMutex_); | 312 boost::mutex::scoped_lock lock(globalMutex_); |
295 | 313 |
296 if (!configuration_->isMember("OrthancPeers")) | 314 if (!configuration_->isMember("OrthancPeers")) |
297 { | 315 { |
298 throw OrthancException(""); | 316 throw OrthancException(ErrorCode_BadFileFormat); |
299 } | |
300 | |
301 const Json::Value& modalities = (*configuration_) ["OrthancPeers"]; | |
302 if (modalities.type() != Json::objectValue || | |
303 !modalities.isMember(name)) | |
304 { | |
305 throw OrthancException(""); | |
306 } | 317 } |
307 | 318 |
308 try | 319 try |
309 { | 320 { |
310 url = modalities[name].get(0u, "").asString(); | 321 const Json::Value& modalities = (*configuration_) ["OrthancPeers"]; |
311 | 322 if (modalities.type() != Json::objectValue || |
312 if (modalities[name].size() == 1) | 323 !modalities.isMember(name)) |
313 { | |
314 username = ""; | |
315 password = ""; | |
316 } | |
317 else if (modalities[name].size() == 3) | |
318 { | |
319 username = modalities[name].get(1u, "").asString(); | |
320 password = modalities[name].get(2u, "").asString(); | |
321 } | |
322 else | |
323 { | 324 { |
324 throw OrthancException(ErrorCode_BadFileFormat); | 325 throw OrthancException(ErrorCode_BadFileFormat); |
325 } | 326 } |
326 } | 327 |
327 catch (...) | 328 try |
328 { | 329 { |
329 throw OrthancException(ErrorCode_BadFileFormat); | 330 url = modalities[name].get(0u, "").asString(); |
330 } | 331 |
331 | 332 if (modalities[name].size() == 1) |
332 if (url.size() != 0 && url[url.size() - 1] != '/') | 333 { |
333 { | 334 username = ""; |
334 url += '/'; | 335 password = ""; |
336 } | |
337 else if (modalities[name].size() == 3) | |
338 { | |
339 username = modalities[name].get(1u, "").asString(); | |
340 password = modalities[name].get(2u, "").asString(); | |
341 } | |
342 else | |
343 { | |
344 throw OrthancException(ErrorCode_BadFileFormat); | |
345 } | |
346 } | |
347 catch (...) | |
348 { | |
349 throw OrthancException(ErrorCode_BadFileFormat); | |
350 } | |
351 | |
352 if (url.size() != 0 && url[url.size() - 1] != '/') | |
353 { | |
354 url += '/'; | |
355 } | |
356 } | |
357 catch (OrthancException& e) | |
358 { | |
359 LOG(ERROR) << "Syntax error in the definition of peer \"" << name | |
360 << "\". Please check your configuration file."; | |
361 throw e; | |
335 } | 362 } |
336 } | 363 } |
337 | 364 |
338 | 365 |
339 static bool ReadKeys(std::set<std::string>& target, | 366 static bool ReadKeys(std::set<std::string>& target, |
434 return (base / relative).string(); | 461 return (base / relative).string(); |
435 | 462 |
436 However, for some unknown reason, some versions of Boost do not | 463 However, for some unknown reason, some versions of Boost do not |
437 make the proper path resolution when "baseDirectory" is an | 464 make the proper path resolution when "baseDirectory" is an |
438 absolute path. So, a hack is used below. | 465 absolute path. So, a hack is used below. |
439 **/ | 466 **/ |
440 | 467 |
441 if (relative.is_absolute()) | 468 if (relative.is_absolute()) |
442 { | 469 { |
443 return relative.string(); | 470 return relative.string(); |
444 } | 471 } |