Mercurial > hg > orthanc
annotate Plugins/Engine/PluginsHttpHandler.cpp @ 899:bb0a51561016 plugins
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 18 Jun 2014 13:29:09 +0200 |
parents | bafc9d592632 |
children | 1b92ce45cc8d |
rev | line source |
---|---|
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Belgium |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * License, or (at your option) any later version. |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * program give permission to link the code of its release with the |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * in the program, then also delete it here. |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * General Public License for more details. |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 **/ |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 #include "PluginsHttpHandler.h" |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "../../Core/OrthancException.h" |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include "../../Core/Toolbox.h" |
899 | 37 #include "../../Core/HttpServer/HttpOutput.h" |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #include <boost/regex.hpp> |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 #include <glog/logging.h> |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 namespace Orthanc |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 struct PluginsHttpHandler::PImpl |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 typedef std::pair<boost::regex*, OrthancPluginRestCallback> Callback; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 typedef std::list<Callback> Callbacks; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 Callbacks callbacks_; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 OrthancPluginRestCallback currentCallback_; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 PImpl() : currentCallback_(NULL) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 }; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
899 | 58 PluginsHttpHandler::PluginsHttpHandler() |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 pimpl_.reset(new PImpl); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 PluginsHttpHandler::~PluginsHttpHandler() |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 for (PImpl::Callbacks::iterator it = pimpl_->callbacks_.begin(); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 it != pimpl_->callbacks_.end(); it++) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 delete it->first; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 bool PluginsHttpHandler::IsServedUri(const UriComponents& uri) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 pimpl_->currentCallback_ = NULL; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 std::string tmp = Toolbox::FlattenUri(uri); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 for (PImpl::Callbacks::const_iterator it = pimpl_->callbacks_.begin(); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 it != pimpl_->callbacks_.end(); it++) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 if (boost::regex_match(tmp, *(it->first))) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 pimpl_->currentCallback_ = it->second; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 return true; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 return false; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 bool PluginsHttpHandler::Handle(HttpOutput& output, |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 HttpMethod method, |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 const UriComponents& uri, |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 const Arguments& headers, |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 const Arguments& getArguments, |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 const std::string& postData) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 std::string flatUri = Toolbox::FlattenUri(uri); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 LOG(INFO) << "Delegating HTTP request to plugin for URI: " << flatUri; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 std::vector<const char*> getKeys(getArguments.size()); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 std::vector<const char*> getValues(getArguments.size()); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 |
899 | 106 OrthancPluginHttpRequest request; |
107 memset(&request, 0, sizeof(OrthancPluginHttpRequest)); | |
108 | |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 switch (method) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 case HttpMethod_Get: |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 { |
899 | 113 request.method = OrthancPluginHttpMethod_Get; |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 size_t i = 0; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 for (Arguments::const_iterator it = getArguments.begin(); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 it != getArguments.end(); it++, i++) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 getKeys[i] = it->first.c_str(); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 getValues[i] = it->second.c_str(); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 break; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 case HttpMethod_Post: |
899 | 127 request.method = OrthancPluginHttpMethod_Post; |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 break; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 case HttpMethod_Delete: |
899 | 131 request.method = OrthancPluginHttpMethod_Delete; |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 break; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 case HttpMethod_Put: |
899 | 135 request.method = OrthancPluginHttpMethod_Put; |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 break; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 default: |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 throw OrthancException(ErrorCode_InternalError); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
899 | 142 |
143 request.getCount = getArguments.size(); | |
144 request.body = (postData.size() ? &postData[0] : NULL); | |
145 request.bodySize = postData.size(); | |
146 | |
147 if (getArguments.size() > 0) | |
148 { | |
149 request.getKeys = &getKeys[0]; | |
150 request.getValues = &getValues[0]; | |
151 } | |
152 | |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 assert(pimpl_->currentCallback_ != NULL); |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 int32_t error = (*pimpl_->currentCallback_) (reinterpret_cast<OrthancPluginRestOutput*>(&output), |
899 | 155 flatUri.c_str(), |
156 &request); | |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 if (error < 0) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 LOG(ERROR) << "Plugin failed with error code " << error; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 return false; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 else |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 if (error > 0) |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 { |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 LOG(WARNING) << "Plugin finished with warning code " << error; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 return true; |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 } |
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 } |
899 | 173 |
174 | |
175 bool PluginsHttpHandler::InvokeService(OrthancPluginService service, | |
176 const void* parameters) | |
177 { | |
178 | |
179 | |
180 /*void PluginsManager::RegisterRestCallback(const OrthancPluginContext* context, | |
181 const char* pathRegularExpression, | |
182 OrthancPluginRestCallback callback) | |
183 { | |
184 LOG(INFO) << "Plugin has registered a REST callback on: " << pathRegularExpression; | |
185 PluginsManager* manager = reinterpret_cast<PluginsManager*>(context->pluginsManager); | |
186 manager->restCallbacks_.push_back(std::make_pair(pathRegularExpression, callback)); | |
187 }*/ | |
188 | |
189 | |
190 /*static void AnswerBuffer(OrthancPluginRestOutput* output, | |
191 const char* answer, | |
192 uint32_t answerSize, | |
193 const char* mimeType) | |
194 { | |
195 HttpOutput* translatedOutput = reinterpret_cast<HttpOutput*>(output); | |
196 translatedOutput->AnswerBufferWithContentType(answer, answerSize, mimeType); | |
197 }*/ | |
198 | |
199 | |
200 | |
201 /*for (PluginsManager::RestCallbacks::const_iterator | |
202 it = manager.GetRestCallbacks().begin(); it != manager.GetRestCallbacks().end(); ++it) | |
203 { | |
204 pimpl_->callbacks_.push_back(std::make_pair(new boost::regex(it->first), it->second)); | |
205 }*/ | |
206 | |
207 | |
208 switch (service) | |
209 { | |
210 case OrthancPluginService_RegisterRestCallback: | |
211 { | |
212 const OrthancPluginRestCallbackParams& p = | |
213 *reinterpret_cast<const OrthancPluginRestCallbackParams*>(parameters); | |
214 | |
215 LOG(INFO) << "Plugin has registered a REST callback on: " << p.pathRegularExpression; | |
216 pimpl_->callbacks_.push_back(std::make_pair(new boost::regex(p.pathRegularExpression), p.callback)); | |
217 | |
218 return true; | |
219 } | |
220 | |
221 case OrthancPluginService_AnswerBuffer: | |
222 { | |
223 const OrthancPluginAnswerBufferParams& p = | |
224 *reinterpret_cast<const OrthancPluginAnswerBufferParams*>(parameters); | |
225 | |
226 HttpOutput* translatedOutput = reinterpret_cast<HttpOutput*>(p.output); | |
227 translatedOutput->AnswerBufferWithContentType(p.answer, p.answerSize, p.mimeType); | |
228 | |
229 return true; | |
230 } | |
231 | |
232 default: | |
233 return false; | |
234 } | |
235 } | |
236 | |
897
bafc9d592632
REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 } |