comparison OrthancServer/DicomInstanceOrigin.cpp @ 2640:c691fcf66071 jobs

ResourceModificationJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 28 May 2018 16:30:17 +0200
parents
children a21b244efb37
comparison
equal deleted inserted replaced
2639:75a404e40323 2640:c691fcf66071
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-2018 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
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 void DicomInstanceOrigin::SetDicomProtocolOrigin(const char* remoteIp,
85 const char* remoteAet,
86 const char* calledAet)
87 {
88 origin_ = RequestOrigin_DicomProtocol;
89 remoteIp_ = remoteIp;
90 dicomRemoteAet_ = remoteAet;
91 dicomCalledAet_ = calledAet;
92 }
93
94 void DicomInstanceOrigin::SetRestOrigin(const RestApiCall& call)
95 {
96 origin_ = call.GetRequestOrigin();
97
98 if (origin_ == RequestOrigin_RestApi)
99 {
100 remoteIp_ = call.GetRemoteIp();
101 httpUsername_ = call.GetUsername();
102 }
103 }
104
105 void DicomInstanceOrigin::SetHttpOrigin(const char* remoteIp,
106 const char* username)
107 {
108 origin_ = RequestOrigin_RestApi;
109 remoteIp_ = remoteIp;
110 httpUsername_ = username;
111 }
112
113 void DicomInstanceOrigin::SetLuaOrigin()
114 {
115 origin_ = RequestOrigin_Lua;
116 }
117
118 void DicomInstanceOrigin::SetPluginsOrigin()
119 {
120 origin_ = RequestOrigin_Plugins;
121 }
122
123 const char* DicomInstanceOrigin::GetRemoteAet() const
124 {
125 if (origin_ == RequestOrigin_DicomProtocol)
126 {
127 return dicomRemoteAet_.c_str();
128 }
129 else
130 {
131 return "";
132 }
133 }
134 }