Mercurial > hg > orthanc-python
annotate Sources/IncomingHttpRequestFilter.cpp @ 220:7ecdfdcb49d5
NEWS
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 Jul 2024 08:32:24 +0200 |
parents | 3678a028f1f6 |
children |
rev | line source |
---|---|
219
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
1 /** |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
2 * SPDX-FileCopyrightText: 2020-2023 Osimis S.A., 2024-2024 Orthanc Team SRL, 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
3 * SPDX-License-Identifier: AGPL-3.0-or-later |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
4 */ |
3678a028f1f6
making the project REUSE-compliant
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
203
diff
changeset
|
5 |
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 * Python plugin for Orthanc |
166
6fada29b6759
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
155
diff
changeset
|
8 * 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
|
9 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
155
71d305c29cfa
updated year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
10 * 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
|
11 * |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * 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
|
13 * 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
|
14 * 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
|
15 * the License, or (at your option) any later version. |
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 * 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
|
18 * WITHOUT ANY WARRANTY; without even the implied warranty of |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * 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
|
20 * Affero General Public License for more details. |
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 * 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
|
23 * 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
|
24 **/ |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include "IncomingHttpRequestFilter.h" |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
203
28531e615104
documented orthanc.RegisterIncomingHttpRequestFilter() and orthanc.RegisterOnStoredInstanceCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
29 #include "PythonHeaderWrapper.h" |
28531e615104
documented orthanc.RegisterIncomingHttpRequestFilter() and orthanc.RegisterOnStoredInstanceCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
171
diff
changeset
|
30 |
68
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
31 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 #include "Autogenerated/sdk.h" |
68
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
33 #include "ICallbackRegistration.h" |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
34 #include "PythonString.h" |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 static PyObject* incomingHttpRequestFilter_ = NULL; |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 static int32_t IncomingHttpRequestFilter(OrthancPluginHttpMethod method, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 const char *uri, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 const char *ip, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 uint32_t headersCount, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 const char *const *headersKeys, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 const char *const *headersValues, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 uint32_t getArgumentsCount, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 const char *const *getArgumentsKeys, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 const char *const *getArgumentsValues) |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 try |
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 PythonLock lock; |
52 | 53 |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 PythonObject args(lock, PyTuple_New(1)); |
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 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 PythonString str(lock, uri); |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 PyTuple_SetItem(args.GetPyObject(), 0, str.Release()); |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 PythonObject kw(lock, PyDict_New()); |
127
a862d554753f
fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
126
diff
changeset
|
62 |
a862d554753f
fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
126
diff
changeset
|
63 { |
a862d554753f
fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
126
diff
changeset
|
64 PythonObject tmp(lock, PyLong_FromLong(method)); |
a862d554753f
fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
126
diff
changeset
|
65 PyDict_SetItemString(kw.GetPyObject(), "method", tmp.GetPyObject()); |
a862d554753f
fixing leaks associated with setting integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
126
diff
changeset
|
66 } |
50
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 PythonString str(lock, ip); |
126
9ffe8881f856
fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
70 PyDict_SetItemString(kw.GetPyObject(), "ip", str.GetPyObject()); |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 } |
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 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 PythonObject headers(lock, PyDict_New()); |
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 for (uint32_t i = 0; i < headersCount; i++) |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 PythonString str(lock, headersValues[i]); |
126
9ffe8881f856
fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
79 PyDict_SetItemString(headers.GetPyObject(), headersKeys[i], str.GetPyObject()); |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 |
126
9ffe8881f856
fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
82 PyDict_SetItemString(kw.GetPyObject(), "headers", headers.GetPyObject()); |
50
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 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 if (method == OrthancPluginHttpMethod_Get) |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 PythonObject getArguments(lock, PyDict_New()); |
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 for (uint32_t i = 0; i < getArgumentsCount; i++) |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 PythonString str(lock, getArgumentsValues[i]); |
126
9ffe8881f856
fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
92 PyDict_SetItemString(getArguments.GetPyObject(), getArgumentsKeys[i], str.GetPyObject()); |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
126
9ffe8881f856
fixing more PyDict_SetItemString()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
95 PyDict_SetItemString(kw.GetPyObject(), "get", getArguments.GetPyObject()); |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 PythonObject result(lock, PyObject_Call(incomingHttpRequestFilter_, |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 args.GetPyObject(), kw.GetPyObject())); |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 std::string traceback; |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 if (lock.HasErrorOccurred(traceback)) |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
104 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
|
105 return -1; |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 else |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 if (PyBool_Check(result.GetPyObject())) |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 return (PyObject_IsTrue(result.GetPyObject()) ? 1 /* allowed */ : 0 /* forbidden */); |
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 else |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
115 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
|
116 return -1; |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 catch (OrthancPlugins::PluginException& e) |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 { |
171
c8de83fe7faa
removed deprecation warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
166
diff
changeset
|
122 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
|
123 std::string(e.What(OrthancPlugins::GetGlobalContext()))); |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 return e.GetErrorCode(); |
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 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 PyObject* RegisterIncomingHttpRequestFilter(PyObject* module, PyObject* args) |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 { |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 // 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
|
132 |
68
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
133 class Registration : public ICallbackRegistration |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 { |
68
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
135 public: |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
136 virtual void Register() ORTHANC_OVERRIDE |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
137 { |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
138 OrthancPluginRegisterIncomingHttpRequestFilter2( |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
139 OrthancPlugins::GetGlobalContext(), IncomingHttpRequestFilter); |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
140 } |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
141 }; |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 |
68
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
143 Registration registration; |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
144 return ICallbackRegistration::Apply( |
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
145 registration, args, incomingHttpRequestFilter_, "Python incoming-http-request filter"); |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 } |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 void FinalizeIncomingHttpRequestFilter() |
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 { |
68
0b3ef425db31
refactoring using ICallbackRegistration::Apply()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
56
diff
changeset
|
151 ICallbackRegistration::Unregister(incomingHttpRequestFilter_); |
50
70abe3ebbbfc
New Python function: "orthanc.RegisterIncomingHttpRequestFilter()"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 } |