comparison Core/DicomNetworking/DicomAssociationParameters.cpp @ 3825:4570c57668a8

refactoring DicomUserConnection as Dicom[Control|Store]UserConnection
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 10 Apr 2020 16:04:54 +0200
parents
children 3d1bb2193832
comparison
equal deleted inserted replaced
3817:37e20bbf25f5 3825:4570c57668a8
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 "../PrecompiledHeaders.h"
35 #include "DicomAssociationParameters.h"
36
37
38 #ifdef _WIN32
39 /**
40 * "The maximum length, in bytes, of the string returned in the buffer
41 * pointed to by the name parameter is dependent on the namespace provider,
42 * but this string must be 256 bytes or less.
43 * http://msdn.microsoft.com/en-us/library/windows/desktop/ms738527(v=vs.85).aspx
44 **/
45 # define HOST_NAME_MAX 256
46 # include <winsock.h>
47 #endif
48
49
50 #if !defined(HOST_NAME_MAX) && defined(_POSIX_HOST_NAME_MAX)
51 /**
52 * TO IMPROVE: "_POSIX_HOST_NAME_MAX is only the minimum value that
53 * HOST_NAME_MAX can ever have [...] Therefore you cannot allocate an
54 * array of size _POSIX_HOST_NAME_MAX, invoke gethostname() and expect
55 * that the result will fit."
56 * http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00128.html
57 **/
58 #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
59 #endif
60
61
62 #include "../Logging.h"
63 #include "../OrthancException.h"
64
65 #include <boost/thread/mutex.hpp>
66
67 // By default, the timeout for client DICOM connections is set to 10 seconds
68 static boost::mutex defaultTimeoutMutex_;
69 static uint32_t defaultTimeout_ = 10;
70
71
72 namespace Orthanc
73 {
74 void DicomAssociationParameters::ReadDefaultTimeout()
75 {
76 boost::mutex::scoped_lock lock(defaultTimeoutMutex_);
77 timeout_ = defaultTimeout_;
78 }
79
80
81 DicomAssociationParameters::DicomAssociationParameters() :
82 localAet_("STORESCU"),
83 remoteAet_("ANY-SCP"),
84 remoteHost_("127.0.0.1"),
85 remotePort_(104),
86 manufacturer_(ModalityManufacturer_Generic)
87 {
88 ReadDefaultTimeout();
89 }
90
91
92 DicomAssociationParameters::DicomAssociationParameters(const std::string& localAet,
93 const RemoteModalityParameters& remote) :
94 localAet_(localAet),
95 remoteAet_(remote.GetApplicationEntityTitle()),
96 remoteHost_(remote.GetHost()),
97 remotePort_(remote.GetPortNumber()),
98 manufacturer_(remote.GetManufacturer()),
99 timeout_(defaultTimeout_)
100 {
101 ReadDefaultTimeout();
102 }
103
104
105 void DicomAssociationParameters::SetRemoteHost(const std::string& host)
106 {
107 if (host.size() > HOST_NAME_MAX - 10)
108 {
109 throw OrthancException(ErrorCode_ParameterOutOfRange,
110 "Invalid host name (too long): " + host);
111 }
112
113 remoteHost_ = host;
114 }
115
116
117 void DicomAssociationParameters::SetRemoteModality(const RemoteModalityParameters& parameters)
118 {
119 SetRemoteApplicationEntityTitle(parameters.GetApplicationEntityTitle());
120 SetRemoteHost(parameters.GetHost());
121 SetRemotePort(parameters.GetPortNumber());
122 SetRemoteManufacturer(parameters.GetManufacturer());
123 }
124
125
126 bool DicomAssociationParameters::IsEqual(const DicomAssociationParameters& other) const
127 {
128 return (localAet_ == other.localAet_ &&
129 remoteAet_ == other.remoteAet_ &&
130 remoteHost_ == other.remoteHost_ &&
131 remotePort_ == other.remotePort_ &&
132 manufacturer_ == other.manufacturer_);
133 }
134
135
136 void DicomAssociationParameters::SetDefaultTimeout(uint32_t seconds)
137 {
138 LOG(INFO) << "Default timeout for DICOM connections if Orthanc acts as SCU (client): "
139 << seconds << " seconds (0 = no timeout)";
140
141 {
142 boost::mutex::scoped_lock lock(defaultTimeoutMutex_);
143 defaultTimeout_ = seconds;
144 }
145 }
146
147
148 size_t DicomAssociationParameters::GetMaxHostNameSize()
149 {
150 return HOST_NAME_MAX;
151 }
152 }