Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 1961:ef1e9856c26f
New callback to filter incoming HTTP requests: OrthancPluginRegisterIncomingHttpRequestFilter()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Apr 2016 17:26:13 +0200 |
parents | e8c2f993f6b3 |
children | 22ddb22fce83 |
comparison
equal
deleted
inserted
replaced
1960:239e50b3792f | 1961:ef1e9856c26f |
---|---|
281 | 281 |
282 typedef std::pair<std::string, _OrthancPluginProperty> Property; | 282 typedef std::pair<std::string, _OrthancPluginProperty> Property; |
283 typedef std::list<RestCallback*> RestCallbacks; | 283 typedef std::list<RestCallback*> RestCallbacks; |
284 typedef std::list<OrthancPluginOnStoredInstanceCallback> OnStoredCallbacks; | 284 typedef std::list<OrthancPluginOnStoredInstanceCallback> OnStoredCallbacks; |
285 typedef std::list<OrthancPluginOnChangeCallback> OnChangeCallbacks; | 285 typedef std::list<OrthancPluginOnChangeCallback> OnChangeCallbacks; |
286 typedef std::list<OrthancPluginIncomingHttpRequestFilter> IncomingHttpRequestFilters; | |
286 typedef std::map<Property, std::string> Properties; | 287 typedef std::map<Property, std::string> Properties; |
287 | 288 |
288 PluginsManager manager_; | 289 PluginsManager manager_; |
289 ServerContext* context_; | 290 ServerContext* context_; |
290 RestCallbacks restCallbacks_; | 291 RestCallbacks restCallbacks_; |
291 OnStoredCallbacks onStoredCallbacks_; | 292 OnStoredCallbacks onStoredCallbacks_; |
292 OnChangeCallbacks onChangeCallbacks_; | 293 OnChangeCallbacks onChangeCallbacks_; |
293 OrthancPluginWorklistCallback worklistCallback_; | 294 OrthancPluginWorklistCallback worklistCallback_; |
294 OrthancPluginDecodeImageCallback decodeImageCallback_; | 295 OrthancPluginDecodeImageCallback decodeImageCallback_; |
296 IncomingHttpRequestFilters incomingHttpRequestFilters_; | |
295 std::auto_ptr<StorageAreaFactory> storageArea_; | 297 std::auto_ptr<StorageAreaFactory> storageArea_; |
296 boost::recursive_mutex restCallbackMutex_; | 298 boost::recursive_mutex restCallbackMutex_; |
297 boost::recursive_mutex storedCallbackMutex_; | 299 boost::recursive_mutex storedCallbackMutex_; |
298 boost::recursive_mutex changeCallbackMutex_; | 300 boost::recursive_mutex changeCallbackMutex_; |
299 boost::mutex worklistCallbackMutex_; | 301 boost::mutex worklistCallbackMutex_; |
757 pimpl_->decodeImageCallback_ = p.callback; | 759 pimpl_->decodeImageCallback_ = p.callback; |
758 } | 760 } |
759 } | 761 } |
760 | 762 |
761 | 763 |
764 void OrthancPlugins::RegisterIncomingHttpRequestFilter(const void* parameters) | |
765 { | |
766 const _OrthancPluginIncomingHttpRequestFilter& p = | |
767 *reinterpret_cast<const _OrthancPluginIncomingHttpRequestFilter*>(parameters); | |
768 | |
769 LOG(INFO) << "Plugin has registered a callback to filter incoming HTTP requests"; | |
770 pimpl_->incomingHttpRequestFilters_.push_back(p.callback); | |
771 } | |
762 | 772 |
763 | 773 |
764 void OrthancPlugins::AnswerBuffer(const void* parameters) | 774 void OrthancPlugins::AnswerBuffer(const void* parameters) |
765 { | 775 { |
766 const _OrthancPluginAnswerBuffer& p = | 776 const _OrthancPluginAnswerBuffer& p = |
1760 | 1770 |
1761 case _OrthancPluginService_RegisterDecodeImageCallback: | 1771 case _OrthancPluginService_RegisterDecodeImageCallback: |
1762 RegisterDecodeImageCallback(parameters); | 1772 RegisterDecodeImageCallback(parameters); |
1763 return true; | 1773 return true; |
1764 | 1774 |
1775 case _OrthancPluginService_RegisterIncomingHttpRequestFilter: | |
1776 RegisterIncomingHttpRequestFilter(parameters); | |
1777 return true; | |
1778 | |
1765 case _OrthancPluginService_AnswerBuffer: | 1779 case _OrthancPluginService_AnswerBuffer: |
1766 AnswerBuffer(parameters); | 1780 AnswerBuffer(parameters); |
1767 return true; | 1781 return true; |
1768 | 1782 |
1769 case _OrthancPluginService_CompressAndAnswerPngImage: | 1783 case _OrthancPluginService_CompressAndAnswerPngImage: |
2407 } | 2421 } |
2408 | 2422 |
2409 DefaultDicomImageDecoder defaultDecoder; | 2423 DefaultDicomImageDecoder defaultDecoder; |
2410 return defaultDecoder.Decode(dicom, size, frame); // TODO RETURN NULL ??? | 2424 return defaultDecoder.Decode(dicom, size, frame); // TODO RETURN NULL ??? |
2411 } | 2425 } |
2426 | |
2427 | |
2428 bool OrthancPlugins::IsAllowed(HttpMethod method, | |
2429 const char* uri, | |
2430 const char* ip, | |
2431 const char* username, | |
2432 const IHttpHandler::Arguments& httpHeaders) const | |
2433 { | |
2434 std::vector<const char*> httpKeys; | |
2435 std::vector<const char*> httpValues; | |
2436 | |
2437 httpKeys.reserve(httpHeaders.size()); | |
2438 httpValues.reserve(httpHeaders.size()); | |
2439 | |
2440 size_t pos = 0; | |
2441 for (IHttpHandler::Arguments::const_iterator | |
2442 it = httpHeaders.begin(); it != httpHeaders.end(); ++it, pos++) | |
2443 { | |
2444 httpKeys[pos] = it->first.c_str(); | |
2445 httpValues[pos] = it->first.c_str(); | |
2446 } | |
2447 | |
2448 OrthancPluginHttpMethod cMethod = Plugins::Convert(method); | |
2449 const char** cHttpKeys = (httpKeys.size() == 0 ? NULL : &httpKeys[0]); | |
2450 const char** cHttpValues = (httpValues.size() == 0 ? NULL : &httpValues[0]); | |
2451 | |
2452 for (PImpl::IncomingHttpRequestFilters::const_iterator | |
2453 filter = pimpl_->incomingHttpRequestFilters_.begin(); | |
2454 filter != pimpl_->incomingHttpRequestFilters_.end(); ++filter) | |
2455 { | |
2456 int32_t allowed = (*filter) (cMethod, uri, ip, httpKeys.size(), cHttpKeys, cHttpValues); | |
2457 | |
2458 if (allowed != 0 && | |
2459 allowed != 1) | |
2460 { | |
2461 throw OrthancException(ErrorCode_Plugin); | |
2462 } | |
2463 | |
2464 if (allowed == 0) | |
2465 { | |
2466 return false; | |
2467 } | |
2468 } | |
2469 | |
2470 return true; | |
2471 } | |
2412 } | 2472 } |