Mercurial > hg > orthanc
comparison OrthancServer/main.cpp @ 409:63f707278fc8 lua-scripting
lua filtering of incoming http requests
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 03 May 2013 12:23:02 +0200 |
parents | 2d269089078f |
children | 53d79c963e4a |
comparison
equal
deleted
inserted
replaced
408:5a3a4a25e568 | 409:63f707278fc8 |
---|---|
146 { | 146 { |
147 } | 147 } |
148 }; | 148 }; |
149 | 149 |
150 | 150 |
151 class MyIncomingHttpRequestFilter : public IIncomingHttpRequestFilter | |
152 { | |
153 private: | |
154 ServerContext& context_; | |
155 | |
156 public: | |
157 MyIncomingHttpRequestFilter(ServerContext& context) : context_(context) | |
158 { | |
159 } | |
160 | |
161 virtual bool IsAllowed(Orthanc_HttpMethod method, | |
162 const char* uri, | |
163 const char* ip, | |
164 const char* username) const | |
165 { | |
166 static const char* HTTP_FILTER = "IncomingHttpRequestFilter"; | |
167 | |
168 // Test if the instance must be filtered out | |
169 if (context_.GetLuaContext().IsExistingFunction(HTTP_FILTER)) | |
170 { | |
171 LuaFunctionCall call(context_.GetLuaContext(), HTTP_FILTER); | |
172 | |
173 switch (method) | |
174 { | |
175 case Orthanc_HttpMethod_Get: | |
176 call.PushString("GET"); | |
177 break; | |
178 | |
179 case Orthanc_HttpMethod_Put: | |
180 call.PushString("PUT"); | |
181 break; | |
182 | |
183 case Orthanc_HttpMethod_Post: | |
184 call.PushString("POST"); | |
185 break; | |
186 | |
187 case Orthanc_HttpMethod_Delete: | |
188 call.PushString("DELETE"); | |
189 break; | |
190 | |
191 default: | |
192 return true; | |
193 } | |
194 | |
195 call.PushString(uri); | |
196 call.PushString(ip); | |
197 call.PushString(username); | |
198 | |
199 if (!call.ExecutePredicate()) | |
200 { | |
201 LOG(INFO) << "An incoming HTTP request has been discarded by the filter"; | |
202 return false; | |
203 } | |
204 } | |
205 | |
206 return true; | |
207 } | |
208 }; | |
209 | |
210 | |
151 void PrintHelp(char* path) | 211 void PrintHelp(char* path) |
152 { | 212 { |
153 std::cout | 213 std::cout |
154 << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl | 214 << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl |
155 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl | 215 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl |
319 //dicomServer.SetFindRequestHandlerFactory(serverFactory); | 379 //dicomServer.SetFindRequestHandlerFactory(serverFactory); |
320 dicomServer.SetPortNumber(GetGlobalIntegerParameter("DicomPort", 4242)); | 380 dicomServer.SetPortNumber(GetGlobalIntegerParameter("DicomPort", 4242)); |
321 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); | 381 dicomServer.SetApplicationEntityTitle(GetGlobalStringParameter("DicomAet", "ORTHANC")); |
322 | 382 |
323 // HTTP server | 383 // HTTP server |
384 MyIncomingHttpRequestFilter httpFilter(context); | |
324 MongooseServer httpServer; | 385 MongooseServer httpServer; |
325 httpServer.SetPortNumber(GetGlobalIntegerParameter("HttpPort", 8042)); | 386 httpServer.SetPortNumber(GetGlobalIntegerParameter("HttpPort", 8042)); |
326 httpServer.SetRemoteAccessAllowed(GetGlobalBoolParameter("RemoteAccessAllowed", false)); | 387 httpServer.SetRemoteAccessAllowed(GetGlobalBoolParameter("RemoteAccessAllowed", false)); |
388 httpServer.SetIncomingHttpRequestFilter(httpFilter); | |
327 | 389 |
328 httpServer.SetAuthenticationEnabled(GetGlobalBoolParameter("AuthenticationEnabled", false)); | 390 httpServer.SetAuthenticationEnabled(GetGlobalBoolParameter("AuthenticationEnabled", false)); |
329 SetupRegisteredUsers(httpServer); | 391 SetupRegisteredUsers(httpServer); |
330 | 392 |
331 if (GetGlobalBoolParameter("SslEnabled", false)) | 393 if (GetGlobalBoolParameter("SslEnabled", false)) |