annotate Sources/IncomingHttpRequestFilter.cpp @ 213:f8dc8dd2da76

documented orthanc.RegisterIncomingCStoreInstanceFilter() and orthanc.RegisterReceivedInstanceCallback()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Jul 2024 14:56:51 +0200
parents 28531e615104
children 3678a028f1f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Python plugin for Orthanc
166
6fada29b6759 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
3 * Copyright (C) 2020-2023 Osimis S.A., Belgium
6fada29b6759 updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 155
diff changeset
4 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
155
71d305c29cfa updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
5 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "IncomingHttpRequestFilter.h"
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
203
28531e615104 documented orthanc.RegisterIncomingHttpRequestFilter() and orthanc.RegisterOnStoredInstanceCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
24 #include "PythonHeaderWrapper.h"
28531e615104 documented orthanc.RegisterIncomingHttpRequestFilter() and orthanc.RegisterOnStoredInstanceCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 171
diff changeset
25
68
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
26 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "Autogenerated/sdk.h"
68
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
28 #include "ICallbackRegistration.h"
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
29 #include "PythonString.h"
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 static PyObject* incomingHttpRequestFilter_ = NULL;
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 static int32_t IncomingHttpRequestFilter(OrthancPluginHttpMethod method,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 const char *uri,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 const char *ip,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 uint32_t headersCount,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 const char *const *headersKeys,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 const char *const *headersValues,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 uint32_t getArgumentsCount,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 const char *const *getArgumentsKeys,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 const char *const *getArgumentsValues)
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 try
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 PythonLock lock;
52
13eb87c58b0a removed bad comment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 50
diff changeset
48
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 PythonObject args(lock, PyTuple_New(1));
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 PythonString str(lock, uri);
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 PyTuple_SetItem(args.GetPyObject(), 0, str.Release());
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 PythonObject kw(lock, PyDict_New());
127
a862d554753f fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
57
a862d554753f fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
58 {
a862d554753f fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
59 PythonObject tmp(lock, PyLong_FromLong(method));
a862d554753f fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
60 PyDict_SetItemString(kw.GetPyObject(), "method", tmp.GetPyObject());
a862d554753f fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
61 }
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 PythonString str(lock, ip);
126
9ffe8881f856 fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
65 PyDict_SetItemString(kw.GetPyObject(), "ip", str.GetPyObject());
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 PythonObject headers(lock, PyDict_New());
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 for (uint32_t i = 0; i < headersCount; i++)
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 PythonString str(lock, headersValues[i]);
126
9ffe8881f856 fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
74 PyDict_SetItemString(headers.GetPyObject(), headersKeys[i], str.GetPyObject());
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
126
9ffe8881f856 fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
77 PyDict_SetItemString(kw.GetPyObject(), "headers", headers.GetPyObject());
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 if (method == OrthancPluginHttpMethod_Get)
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 PythonObject getArguments(lock, PyDict_New());
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 for (uint32_t i = 0; i < getArgumentsCount; i++)
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 PythonString str(lock, getArgumentsValues[i]);
126
9ffe8881f856 fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
87 PyDict_SetItemString(getArguments.GetPyObject(), getArgumentsKeys[i], str.GetPyObject());
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
126
9ffe8881f856 fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
90 PyDict_SetItemString(kw.GetPyObject(), "get", getArguments.GetPyObject());
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 PythonObject result(lock, PyObject_Call(incomingHttpRequestFilter_,
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 args.GetPyObject(), kw.GetPyObject()));
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 std::string traceback;
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 if (lock.HasErrorOccurred(traceback))
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
99 ORTHANC_PLUGINS_LOG_ERROR("Error in the Python incoming-http-request filter, traceback:\n" + traceback);
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 return -1;
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 else
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 if (PyBool_Check(result.GetPyObject()))
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 return (PyObject_IsTrue(result.GetPyObject()) ? 1 /* allowed */ : 0 /* forbidden */);
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 else
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
110 ORTHANC_PLUGINS_LOG_ERROR("The Python incoming-http-request filter has not returned a Boolean");
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return -1;
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 catch (OrthancPlugins::PluginException& e)
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
171
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
117 ORTHANC_PLUGINS_LOG_ERROR("Exception in the Python incoming-http-request filter: " +
c8de83fe7faa removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 166
diff changeset
118 std::string(e.What(OrthancPlugins::GetGlobalContext())));
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 return e.GetErrorCode();
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 PyObject* RegisterIncomingHttpRequestFilter(PyObject* module, PyObject* args)
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 // The GIL is locked at this point (no need to create "PythonLock")
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
68
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
128 class Registration : public ICallbackRegistration
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
68
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
130 public:
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
131 virtual void Register() ORTHANC_OVERRIDE
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
132 {
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
133 OrthancPluginRegisterIncomingHttpRequestFilter2(
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
134 OrthancPlugins::GetGlobalContext(), IncomingHttpRequestFilter);
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
135 }
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
136 };
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
68
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
138 Registration registration;
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
139 return ICallbackRegistration::Apply(
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
140 registration, args, incomingHttpRequestFilter_, "Python incoming-http-request filter");
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 void FinalizeIncomingHttpRequestFilter()
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
68
0b3ef425db31 refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 56
diff changeset
146 ICallbackRegistration::Unregister(incomingHttpRequestFilter_);
50
70abe3ebbbfc New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }