Mercurial > hg > orthanc
comparison OrthancServer/Sources/DicomInstanceOrigin.cpp @ 4044:d25f4c0fa160 framework
splitting code into OrthancFramework and OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 20:30:34 +0200 |
parents | OrthancServer/DicomInstanceOrigin.cpp@94f4a18a79cc |
children | 05b8fd21089c |
comparison
equal
deleted
inserted
replaced
4043:6c6239aec462 | 4044:d25f4c0fa160 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "PrecompiledHeadersServer.h" | |
35 #include "DicomInstanceOrigin.h" | |
36 | |
37 #include "../Core/OrthancException.h" | |
38 #include "../Core/SerializationToolbox.h" | |
39 | |
40 namespace Orthanc | |
41 { | |
42 void DicomInstanceOrigin::Format(Json::Value& result) const | |
43 { | |
44 result = Json::objectValue; | |
45 result["RequestOrigin"] = EnumerationToString(origin_); | |
46 | |
47 switch (origin_) | |
48 { | |
49 case RequestOrigin_Unknown: | |
50 { | |
51 // None of the methods "SetDicomProtocolOrigin()", "SetHttpOrigin()", | |
52 // "SetLuaOrigin()" or "SetPluginsOrigin()" was called! | |
53 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
54 } | |
55 | |
56 case RequestOrigin_DicomProtocol: | |
57 { | |
58 result["RemoteIp"] = remoteIp_; | |
59 result["RemoteAet"] = dicomRemoteAet_; | |
60 result["CalledAet"] = dicomCalledAet_; | |
61 break; | |
62 } | |
63 | |
64 case RequestOrigin_RestApi: | |
65 { | |
66 result["RemoteIp"] = remoteIp_; | |
67 result["Username"] = httpUsername_; | |
68 break; | |
69 } | |
70 | |
71 case RequestOrigin_Lua: | |
72 case RequestOrigin_Plugins: | |
73 { | |
74 // No additional information available for these kinds of requests | |
75 break; | |
76 } | |
77 | |
78 default: | |
79 throw OrthancException(ErrorCode_InternalError); | |
80 } | |
81 } | |
82 | |
83 | |
84 DicomInstanceOrigin DicomInstanceOrigin::FromDicomProtocol(const char* remoteIp, | |
85 const char* remoteAet, | |
86 const char* calledAet) | |
87 { | |
88 DicomInstanceOrigin result(RequestOrigin_DicomProtocol); | |
89 result.remoteIp_ = remoteIp; | |
90 result.dicomRemoteAet_ = remoteAet; | |
91 result.dicomCalledAet_ = calledAet; | |
92 return result; | |
93 } | |
94 | |
95 DicomInstanceOrigin DicomInstanceOrigin::FromRest(const RestApiCall& call) | |
96 { | |
97 DicomInstanceOrigin result(call.GetRequestOrigin()); | |
98 | |
99 if (result.origin_ == RequestOrigin_RestApi) | |
100 { | |
101 result.remoteIp_ = call.GetRemoteIp(); | |
102 result.httpUsername_ = call.GetUsername(); | |
103 } | |
104 | |
105 return result; | |
106 } | |
107 | |
108 DicomInstanceOrigin DicomInstanceOrigin::FromHttp(const char* remoteIp, | |
109 const char* username) | |
110 { | |
111 DicomInstanceOrigin result(RequestOrigin_RestApi); | |
112 result.remoteIp_ = remoteIp; | |
113 result.httpUsername_ = username; | |
114 return result; | |
115 } | |
116 | |
117 const char* DicomInstanceOrigin::GetRemoteAetC() const | |
118 { | |
119 if (origin_ == RequestOrigin_DicomProtocol) | |
120 { | |
121 return dicomRemoteAet_.c_str(); | |
122 } | |
123 else | |
124 { | |
125 return ""; | |
126 } | |
127 } | |
128 | |
129 bool DicomInstanceOrigin::LookupRemoteAet(std::string& result) const | |
130 { | |
131 if (origin_ == RequestOrigin_DicomProtocol) | |
132 { | |
133 result = dicomRemoteAet_.c_str(); | |
134 return true; | |
135 } | |
136 else | |
137 { | |
138 return false; | |
139 } | |
140 } | |
141 | |
142 bool DicomInstanceOrigin::LookupRemoteIp(std::string& result) const | |
143 { | |
144 if (origin_ == RequestOrigin_DicomProtocol || | |
145 origin_ == RequestOrigin_RestApi) | |
146 { | |
147 result = remoteIp_; | |
148 return true; | |
149 } | |
150 else | |
151 { | |
152 return false; | |
153 } | |
154 } | |
155 | |
156 bool DicomInstanceOrigin::LookupCalledAet(std::string& result) const | |
157 { | |
158 if (origin_ == RequestOrigin_DicomProtocol) | |
159 { | |
160 result = dicomCalledAet_; | |
161 return true; | |
162 } | |
163 else | |
164 { | |
165 return false; | |
166 } | |
167 } | |
168 | |
169 bool DicomInstanceOrigin::LookupHttpUsername(std::string& result) const | |
170 { | |
171 if (origin_ == RequestOrigin_RestApi) | |
172 { | |
173 result = httpUsername_; | |
174 return true; | |
175 } | |
176 else | |
177 { | |
178 return false; | |
179 } | |
180 } | |
181 | |
182 | |
183 | |
184 static const char* ORIGIN = "Origin"; | |
185 static const char* REMOTE_IP = "RemoteIP"; | |
186 static const char* DICOM_REMOTE_AET = "RemoteAET"; | |
187 static const char* DICOM_CALLED_AET = "CalledAET"; | |
188 static const char* HTTP_USERNAME = "Username"; | |
189 | |
190 | |
191 DicomInstanceOrigin::DicomInstanceOrigin(const Json::Value& serialized) | |
192 { | |
193 origin_ = StringToRequestOrigin(SerializationToolbox::ReadString(serialized, ORIGIN)); | |
194 remoteIp_ = SerializationToolbox::ReadString(serialized, REMOTE_IP); | |
195 dicomRemoteAet_ = SerializationToolbox::ReadString(serialized, DICOM_REMOTE_AET); | |
196 dicomCalledAet_ = SerializationToolbox::ReadString(serialized, DICOM_CALLED_AET); | |
197 httpUsername_ = SerializationToolbox::ReadString(serialized, HTTP_USERNAME); | |
198 } | |
199 | |
200 | |
201 void DicomInstanceOrigin::Serialize(Json::Value& result) const | |
202 { | |
203 result = Json::objectValue; | |
204 result[ORIGIN] = EnumerationToString(origin_); | |
205 result[REMOTE_IP] = remoteIp_; | |
206 result[DICOM_REMOTE_AET] = dicomRemoteAet_; | |
207 result[DICOM_CALLED_AET] = dicomCalledAet_; | |
208 result[HTTP_USERNAME] = httpUsername_; | |
209 } | |
210 } |