comparison Plugin/Plugin.cpp @ 29:bc0431cb6b8f

fix for compatibility with simplified OrthancPluginCppWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 04 Dec 2018 21:16:54 +0100
parents c44013681a51
children c304ffca5d80
comparison
equal deleted inserted replaced
28:ae19947abf68 29:bc0431cb6b8f
24 24
25 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> 25 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
26 #include <Core/Logging.h> 26 #include <Core/Logging.h>
27 #include <Core/Toolbox.h> 27 #include <Core/Toolbox.h>
28 28
29 static OrthancPluginContext* context_ = NULL;
30
31 29
32 // Configuration of the authorization plugin 30 // Configuration of the authorization plugin
33 static std::auto_ptr<OrthancPlugins::IAuthorizationParser> authorizationParser_; 31 static std::auto_ptr<OrthancPlugins::IAuthorizationParser> authorizationParser_;
34 static std::auto_ptr<OrthancPlugins::IAuthorizationService> authorizationService_; 32 static std::auto_ptr<OrthancPlugins::IAuthorizationService> authorizationService_;
35 static std::set<std::string> uncheckedResources_; 33 static std::set<std::string> uncheckedResources_;
244 242
245 extern "C" 243 extern "C"
246 { 244 {
247 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) 245 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
248 { 246 {
249 context_ = context; 247 OrthancPlugins::SetGlobalContext(context);
250 OrthancPluginLogWarning(context_, "Initializing the authorization plugin"); 248 OrthancPluginLogWarning(context, "Initializing the authorization plugin");
251 249
252 /* Check the version of the Orthanc core */ 250 /* Check the version of the Orthanc core */
253 if (OrthancPluginCheckVersion(context_) == 0) 251 if (OrthancPluginCheckVersion(context) == 0)
254 { 252 {
255 OrthancPlugins::ReportMinimalOrthancVersion(context_, 253 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
256 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
257 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, 254 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
258 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); 255 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
259 return -1; 256 return -1;
260 } 257 }
261 258
262 Orthanc::Logging::Initialize(context_); 259 Orthanc::Logging::Initialize(context);
263 OrthancPluginSetDescription(context_, "Advanced authorization plugin for Orthanc."); 260 OrthancPluginSetDescription(context, "Advanced authorization plugin for Orthanc.");
264 261
265 try 262 try
266 { 263 {
267 OrthancPlugins::OrthancConfiguration general(context_); 264 OrthancPlugins::OrthancConfiguration general;
268 265
269 static const char* SECTION = "Authorization"; 266 static const char* SECTION = "Authorization";
270 if (general.IsSection(SECTION)) 267 if (general.IsSection(SECTION))
271 { 268 {
272 OrthancPlugins::OrthancConfiguration configuration; 269 OrthancPlugins::OrthancConfiguration configuration;
289 { 286 {
290 root = "/dicom-web/"; 287 root = "/dicom-web/";
291 } 288 }
292 289
293 authorizationParser_.reset 290 authorizationParser_.reset
294 (new OrthancPlugins::DefaultAuthorizationParser(context_, factory, root)); 291 (new OrthancPlugins::DefaultAuthorizationParser(factory, root));
295 } 292 }
296 293
297 std::list<std::string> tmp; 294 std::list<std::string> tmp;
298 295
299 configuration.LookupListOfStrings(tmp, "TokenHttpHeaders", true); 296 configuration.LookupListOfStrings(tmp, "TokenHttpHeaders", true);
312 tokens_.push_back(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, *it)); 309 tokens_.push_back(OrthancPlugins::Token(OrthancPlugins::TokenType_GetArgument, *it));
313 } 310 }
314 #else 311 #else
315 if (!tmp.empty()) 312 if (!tmp.empty())
316 { 313 {
317 LOG(ERROR) << "The option \"TokenGetArguments\" of the authorization plugin " 314 throw Orthanc::OrthancException(
318 << "is only valid if compiled against Orthanc >= 1.3.0"; 315 Orthanc::ErrorCode_Plugin,
319 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); 316 "The option \"TokenGetArguments\" of the authorization plugin "
317 "is only valid if compiled against Orthanc >= 1.3.0"
320 } 318 }
321 #endif 319 #endif
322 320
323 configuration.LookupSetOfStrings(uncheckedResources_, "UncheckedResources", false); 321 configuration.LookupSetOfStrings(uncheckedResources_, "UncheckedResources", false);
324 configuration.LookupListOfStrings(uncheckedFolders_, "UncheckedFolders", false); 322 configuration.LookupListOfStrings(uncheckedFolders_, "UncheckedFolders", false);
326 std::string url; 324 std::string url;
327 325
328 static const char* WEB_SERVICE = "WebService"; 326 static const char* WEB_SERVICE = "WebService";
329 if (!configuration.LookupStringValue(url, WEB_SERVICE)) 327 if (!configuration.LookupStringValue(url, WEB_SERVICE))
330 { 328 {
331 LOG(ERROR) << "Missing mandatory option \"" << WEB_SERVICE 329 throw Orthanc::OrthancException(
332 << "\" for the authorization plugin"; 330 Orthanc::ErrorCode_BadFileFormat,
333 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 331 "Missing mandatory option \"" + std::string(WEB_SERVICE) +
332 "\" for the authorization plugin");
334 } 333 }
335 334
336 if (configuration.LookupListOfStrings(tmp, "UncheckedLevels", false)) 335 if (configuration.LookupListOfStrings(tmp, "UncheckedLevels", false))
337 { 336 {
338 for (std::list<std::string>::const_iterator 337 for (std::list<std::string>::const_iterator
342 } 341 }
343 } 342 }
344 343
345 authorizationService_.reset 344 authorizationService_.reset
346 (new OrthancPlugins::CachedAuthorizationService 345 (new OrthancPlugins::CachedAuthorizationService
347 (new OrthancPlugins::AuthorizationWebService(context_, url), factory)); 346 (new OrthancPlugins::AuthorizationWebService(url), factory));
348 347
349 OrthancPluginRegisterOnChangeCallback(context_, OnChangeCallback); 348 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback);
350 349
351 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1) 350 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 2, 1)
352 OrthancPluginRegisterIncomingHttpRequestFilter2(context_, FilterHttpRequests); 351 OrthancPluginRegisterIncomingHttpRequestFilter2(context, FilterHttpRequests);
353 #else 352 #else
354 OrthancPluginRegisterIncomingHttpRequestFilter(context_, FilterHttpRequestsFallback); 353 OrthancPluginRegisterIncomingHttpRequestFilter(context, FilterHttpRequestsFallback);
355 #endif 354 #endif
356 } 355 }
357 else 356 else
358 { 357 {
359 LOG(WARNING) << "No section \"" << SECTION << "\" in the configuration file, " 358 LOG(WARNING) << "No section \"" << SECTION << "\" in the configuration file, "