annotate OrthancServer/Internals/CommandDispatcher.cpp @ 660:f0232774b913

fix warnings
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 04 Nov 2013 15:07:58 +0100
parents 4aa6f0d79947
children d233b5090105
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
399
4d5f0857ec9c copyright update
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 136
diff changeset
3 * Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege,
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Belgium
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 * This program is free software: you can redistribute it and/or
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * License, or (at your option) any later version.
136
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
10 *
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
11 * In addition, as a special exception, the copyright holders of this
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
12 * program give permission to link the code of its release with the
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
15 * the linked executables. You must obey the GNU General Public License
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
19 * you do not wish to do so, delete this exception statement from your
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
20 * version. If you delete this exception statement from all source files
fe180eae201d openssl exception
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 102
diff changeset
21 * in the program, then also delete it here.
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * General Public License for more details.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 *
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 * You should have received a copy of the GNU General Public License
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 **/
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "CommandDispatcher.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "FindScp.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include "StoreScp.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "MoveScp.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../../Core/Toolbox.h"
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <dcmtk/dcmnet/dcasccfg.h> /* for class DcmAssociationConfiguration */
101
428784e59dcd trying to use log4cplus
jodogne
parents: 62
diff changeset
41 #include <boost/lexical_cast.hpp>
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
42 #include <glog/logging.h>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
503
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
44 #define ORTHANC_PROMISCUOUS 1
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
45
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 static OFBool opt_rejectWithoutImplementationUID = OFFalse;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
503
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
49
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
50 #if ORTHANC_PROMISCUOUS == 1
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
51 static
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
52 DUL_PRESENTATIONCONTEXT *
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
53 findPresentationContextID(LST_HEAD * head,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
54 T_ASC_PresentationContextID presentationContextID)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
55 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
56 DUL_PRESENTATIONCONTEXT *pc;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
57 LST_HEAD **l;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
58 OFBool found = OFFalse;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
59
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
60 if (head == NULL)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
61 return NULL;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
62
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
63 l = &head;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
64 if (*l == NULL)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
65 return NULL;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
66
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
67 pc = OFstatic_cast(DUL_PRESENTATIONCONTEXT *, LST_Head(l));
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
68 (void)LST_Position(l, OFstatic_cast(LST_NODE *, pc));
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
69
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
70 while (pc && !found) {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
71 if (pc->presentationContextID == presentationContextID) {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
72 found = OFTrue;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
73 } else {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
74 pc = OFstatic_cast(DUL_PRESENTATIONCONTEXT *, LST_Next(l));
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
75 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
76 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
77 return pc;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
78 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
79
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
80
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
81 /** accept all presenstation contexts for unknown SOP classes,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
82 * i.e. UIDs appearing in the list of abstract syntaxes
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
83 * where no corresponding name is defined in the UID dictionary.
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
84 * @param params pointer to association parameters structure
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
85 * @param transferSyntax transfer syntax to accept
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
86 * @param acceptedRole SCU/SCP role to accept
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
87 */
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
88 static OFCondition acceptUnknownContextsWithTransferSyntax(
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
89 T_ASC_Parameters * params,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
90 const char* transferSyntax,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
91 T_ASC_SC_ROLE acceptedRole)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
92 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
93 OFCondition cond = EC_Normal;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
94 int n, i, k;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
95 DUL_PRESENTATIONCONTEXT *dpc;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
96 T_ASC_PresentationContext pc;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
97 OFBool accepted = OFFalse;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
98 OFBool abstractOK = OFFalse;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
99
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
100 n = ASC_countPresentationContexts(params);
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
101 for (i = 0; i < n; i++)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
102 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
103 cond = ASC_getPresentationContext(params, i, &pc);
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
104 if (cond.bad()) return cond;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
105 abstractOK = OFFalse;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
106 accepted = OFFalse;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
107
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
108 if (dcmFindNameOfUID(pc.abstractSyntax) == NULL)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
109 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
110 abstractOK = OFTrue;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
111
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
112 /* check the transfer syntax */
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
113 for (k = 0; (k < OFstatic_cast(int, pc.transferSyntaxCount)) && !accepted; k++)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
114 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
115 if (strcmp(pc.proposedTransferSyntaxes[k], transferSyntax) == 0)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
116 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
117 accepted = OFTrue;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
118 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
119 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
120 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
121
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
122 if (accepted)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
123 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
124 cond = ASC_acceptPresentationContext(
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
125 params, pc.presentationContextID,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
126 transferSyntax, acceptedRole);
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
127 if (cond.bad()) return cond;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
128 } else {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
129 T_ASC_P_ResultReason reason;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
130
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
131 /* do not refuse if already accepted */
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
132 dpc = findPresentationContextID(params->DULparams.acceptedPresentationContext,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
133 pc.presentationContextID);
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
134 if ((dpc == NULL) || ((dpc != NULL) && (dpc->result != ASC_P_ACCEPTANCE)))
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
135 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
136
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
137 if (abstractOK) {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
138 reason = ASC_P_TRANSFERSYNTAXESNOTSUPPORTED;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
139 } else {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
140 reason = ASC_P_ABSTRACTSYNTAXNOTSUPPORTED;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
141 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
142 /*
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
143 * If previously this presentation context was refused
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
144 * because of bad transfer syntax let it stay that way.
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
145 */
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
146 if ((dpc != NULL) && (dpc->result == ASC_P_TRANSFERSYNTAXESNOTSUPPORTED))
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
147 reason = ASC_P_TRANSFERSYNTAXESNOTSUPPORTED;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
148
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
149 cond = ASC_refusePresentationContext(params, pc.presentationContextID, reason);
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
150 if (cond.bad()) return cond;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
151 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
152 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
153 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
154 return EC_Normal;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
155 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
156
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
157
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
158 /** accept all presenstation contexts for unknown SOP classes,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
159 * i.e. UIDs appearing in the list of abstract syntaxes
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
160 * where no corresponding name is defined in the UID dictionary.
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
161 * This method is passed a list of "preferred" transfer syntaxes.
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
162 * @param params pointer to association parameters structure
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
163 * @param transferSyntax transfer syntax to accept
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
164 * @param acceptedRole SCU/SCP role to accept
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
165 */
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
166 static OFCondition acceptUnknownContextsWithPreferredTransferSyntaxes(
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
167 T_ASC_Parameters * params,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
168 const char* transferSyntaxes[], int transferSyntaxCount,
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
169 T_ASC_SC_ROLE acceptedRole = ASC_SC_ROLE_DEFAULT)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
170 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
171 OFCondition cond = EC_Normal;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
172 /*
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
173 ** Accept in the order "least wanted" to "most wanted" transfer
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
174 ** syntax. Accepting a transfer syntax will override previously
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
175 ** accepted transfer syntaxes.
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
176 */
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
177 for (int i = transferSyntaxCount - 1; i >= 0; i--)
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
178 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
179 cond = acceptUnknownContextsWithTransferSyntax(params, transferSyntaxes[i], acceptedRole);
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
180 if (cond.bad()) return cond;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
181 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
182 return cond;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
183 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
184 #endif
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
185
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
186
62
a70bb32802ae renaming Server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 57
diff changeset
187 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 namespace Internals
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 OFCondition AssociationCleanup(T_ASC_Association *assoc)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 OFString temp_str;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 OFCondition cond = ASC_dropSCPAssociation(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
197 LOG(FATAL) << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 return cond;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 cond = ASC_destroyAssociation(&assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
204 LOG(FATAL) << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 return cond;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 return cond;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 CommandDispatcher* AcceptAssociation(const DicomServer& server, T_ASC_Network *net)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 DcmAssociationConfiguration asccfg;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 char buf[BUFSIZ];
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 T_ASC_Association *assoc;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 OFCondition cond;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 OFString sprofile;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 OFString temp_str;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 std::vector<const char*> knownAbstractSyntaxes;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 // For C-STORE
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 if (server.HasStoreRequestHandlerFactory())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 knownAbstractSyntaxes.push_back(UID_VerificationSOPClass);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 // For C-FIND
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 if (server.HasFindRequestHandlerFactory())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 knownAbstractSyntaxes.push_back(UID_FINDPatientRootQueryRetrieveInformationModel);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 knownAbstractSyntaxes.push_back(UID_FINDStudyRootQueryRetrieveInformationModel);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 // For C-MOVE
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 if (server.HasMoveRequestHandlerFactory())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 knownAbstractSyntaxes.push_back(UID_MOVEStudyRootQueryRetrieveInformationModel);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 const char* transferSyntaxes[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 int numTransferSyntaxes = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 cond = ASC_receiveAssociation(net, &assoc,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 /*opt_maxPDU*/ ASC_DEFAULTMAXPDU,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 NULL, NULL,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 /*opt_secureConnection*/ OFFalse,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 DUL_NOBLOCK, 1);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 if (cond == DUL_NOASSOCIATIONREQUEST)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 // Timeout
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 // if some kind of error occured, take care of it
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
262 LOG(ERROR) << "Receiving Association failed: " << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 // no matter what kind of error occurred, we need to do a cleanup
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
268 LOG(INFO) << "Association Received";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 transferSyntaxes[0] = UID_LittleEndianExplicitTransferSyntax;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 transferSyntaxes[1] = UID_BigEndianExplicitTransferSyntax;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 transferSyntaxes[2] = UID_LittleEndianImplicitTransferSyntax;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 numTransferSyntaxes = 3;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 /* accept the Verification SOP Class if presented */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 cond = ASC_acceptContextsWithPreferredTransferSyntaxes( assoc->params, &knownAbstractSyntaxes[0], knownAbstractSyntaxes.size(), transferSyntaxes, numTransferSyntaxes);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
279 LOG(INFO) << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 /* the array of Storage SOP Class UIDs comes from dcuid.h */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 cond = ASC_acceptContextsWithPreferredTransferSyntaxes( assoc->params, dcmAllStorageSOPClassUIDs, numberOfAllDcmStorageSOPClassUIDs, transferSyntaxes, numTransferSyntaxes);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
288 LOG(INFO) << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292
503
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
293 #if ORTHANC_PROMISCUOUS == 1
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
294 /* accept everything not known not to be a storage SOP class */
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
295 cond = acceptUnknownContextsWithPreferredTransferSyntaxes(
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
296 assoc->params, transferSyntaxes, numTransferSyntaxes);
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
297 if (cond.bad())
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
298 {
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
299 LOG(INFO) << cond.text();
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
300 AssociationCleanup(assoc);
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
301 return NULL;
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
302 }
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
303 #endif
273e7ad98ea9 promiscuous mode
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 399
diff changeset
304
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 /* set our app title */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 ASC_setAPTitles(assoc->params, NULL, NULL, server.GetApplicationEntityTitle().c_str());
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 /* acknowledge or reject this association */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 cond = ASC_getApplicationContextName(assoc->params, buf);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 if ((cond.bad()) || strcmp(buf, UID_StandardApplicationContext) != 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 /* reject: the application context name is not supported */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 T_ASC_RejectParameters rej =
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 ASC_RESULT_REJECTEDPERMANENT,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 ASC_SOURCE_SERVICEUSER,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 ASC_REASON_SU_APPCONTEXTNAMENOTSUPPORTED
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
320 LOG(INFO) << "Association Rejected: Bad Application Context Name: " << buf;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 cond = ASC_rejectAssociation(assoc, &rej);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
324 LOG(INFO) << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 }
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
329
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
330 std::string callingIP;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
331 std::string callingTitle;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 /* check the AETs */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 DIC_AE callingTitle_C;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 DIC_AE calledTitle_C;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 DIC_AE callingIP_C;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 DIC_AE calledIP_C;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 if (ASC_getAPTitles(assoc->params, callingTitle_C, calledTitle_C, NULL).bad() ||
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 ASC_getPresentationAddresses(assoc->params, callingIP_C, calledIP_C).bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 T_ASC_RejectParameters rej =
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 ASC_RESULT_REJECTEDPERMANENT,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 ASC_SOURCE_SERVICEUSER,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 ASC_REASON_SU_NOREASON
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 ASC_rejectAssociation(assoc, &rej);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
353 callingIP = std::string(/*OFSTRING_GUARD*/(callingIP_C));
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
354 callingTitle = std::string(/*OFSTRING_GUARD*/(callingTitle_C));
101
428784e59dcd trying to use log4cplus
jodogne
parents: 62
diff changeset
355 std::string calledTitle(/*OFSTRING_GUARD*/(calledTitle_C));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 Toolbox::ToUpperCase(callingIP);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 Toolbox::ToUpperCase(callingTitle);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 Toolbox::ToUpperCase(calledTitle);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 if (server.HasCalledApplicationEntityTitleCheck() &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 calledTitle != server.GetApplicationEntityTitle())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 T_ASC_RejectParameters rej =
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 ASC_RESULT_REJECTEDPERMANENT,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 ASC_SOURCE_SERVICEUSER,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 ASC_REASON_SU_CALLEDAETITLENOTRECOGNIZED
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 ASC_rejectAssociation(assoc, &rej);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 if (server.HasApplicationEntityFilter() &&
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
375 !server.GetApplicationEntityFilter().IsAllowedConnection(callingIP, callingTitle))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 T_ASC_RejectParameters rej =
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 ASC_RESULT_REJECTEDPERMANENT,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 ASC_SOURCE_SERVICEUSER,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 ASC_REASON_SU_CALLINGAETITLENOTRECOGNIZED
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 ASC_rejectAssociation(assoc, &rej);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 if (opt_rejectWithoutImplementationUID && strlen(assoc->params->theirImplementationClassUID) == 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 /* reject: the no implementation Class UID provided */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 T_ASC_RejectParameters rej =
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 ASC_RESULT_REJECTEDPERMANENT,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 ASC_SOURCE_SERVICEUSER,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 ASC_REASON_SU_NOREASON
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
399 LOG(INFO) << "Association Rejected: No Implementation Class UID provided";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 cond = ASC_rejectAssociation(assoc, &rej);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
403 LOG(INFO) << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 cond = ASC_acknowledgeAssociation(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
413 LOG(ERROR) << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 AssociationCleanup(assoc);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 return NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 }
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
417 LOG(INFO) << "Association Acknowledged (Max Send PDV: " << assoc->sendPDVLength << ")";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 if (ASC_countAcceptedPresentationContexts(assoc->params) == 0)
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
419 LOG(INFO) << " (but no valid presentation contexts)";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
422 IApplicationEntityFilter* filter = server.HasApplicationEntityFilter() ? &server.GetApplicationEntityFilter() : NULL;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
423 return new CommandDispatcher(server, assoc, callingIP, callingTitle, filter);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 bool CommandDispatcher::Step()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 /*
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 * This function receives DIMSE commmands over the network connection
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 * and handles these commands correspondingly. Note that in case of
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 * storscp only C-ECHO-RQ and C-STORE-RQ commands can be processed.
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 bool finished = false;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 // receive a DIMSE command over the network, with a timeout of 1 second
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 DcmDataset *statusDetail = NULL;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 T_ASC_PresentationContextID presID = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 T_DIMSE_Message msg;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 OFCondition cond = DIMSE_receiveCommand(assoc_, DIMSE_NONBLOCKING, 1, &presID, &msg, &statusDetail);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 elapsedTimeSinceLastCommand_++;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 // if the command which was received has extra status
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 // detail information, dump this information
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 if (statusDetail != NULL)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 {
101
428784e59dcd trying to use log4cplus
jodogne
parents: 62
diff changeset
447 //LOG4CPP_WARN(Internals::GetLogger(), "Status Detail:" << OFendl << DcmObject::PrintHelper(*statusDetail));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 delete statusDetail;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 if (cond == DIMSE_OUTOFRESOURCES)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 finished = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 else if (cond == DIMSE_NODATAAVAILABLE)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 // Timeout due to DIMSE_NONBLOCKING
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 if (clientTimeout_ != 0 &&
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 elapsedTimeSinceLastCommand_ >= clientTimeout_)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 // This timeout is actually a client timeout
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 finished = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 else if (cond == EC_Normal)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 // Reset the client timeout counter
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 elapsedTimeSinceLastCommand_ = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
470 // Convert the type of request to Orthanc's internal type
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
471 bool supported = false;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
472 DicomRequestType request;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 switch (msg.CommandField)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
475 case DIMSE_C_ECHO_RQ:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
476 request = DicomRequestType_Echo;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
477 supported = true;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
478 break;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
479
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
480 case DIMSE_C_STORE_RQ:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
481 request = DicomRequestType_Store;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
482 supported = true;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
483 break;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
484
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
485 case DIMSE_C_MOVE_RQ:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
486 request = DicomRequestType_Move;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
487 supported = true;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
488 break;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
489
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
490 case DIMSE_C_FIND_RQ:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
491 request = DicomRequestType_Find;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
492 supported = true;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
493 break;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
495 default:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
496 // we cannot handle this kind of message
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
497 cond = DIMSE_BADCOMMANDTYPE;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
498 LOG(ERROR) << "cannot handle command: 0x" << std::hex << msg.CommandField;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
499 break;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
500 }
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
501
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
503 // Check whether this request is allowed by the security filter
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
504 if (supported &&
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
505 filter_ != NULL &&
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
506 !filter_->IsAllowedRequest(callingIP_, callingAETitle_, request))
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
507 {
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
508 LOG(ERROR) << EnumerationToString(request)
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
509 << " requests are disallowed for the AET \""
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
510 << callingAETitle_ << "\"";
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
511 cond = DIMSE_BADCOMMANDTYPE;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
512 supported = false;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
513 }
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
514
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
515 // in case we received a supported message, process this command
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
516 if (supported)
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
517 {
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
518 // If anything goes wrong, there will be a "BADCOMMANDTYPE" answer
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
519 cond = DIMSE_BADCOMMANDTYPE;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
520
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
521 switch (request)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 {
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
523 case DicomRequestType_Echo:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
524 cond = EchoScp(assoc_, &msg, presID);
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
525 break;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
526
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
527 case DicomRequestType_Store:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
528 if (server_.HasStoreRequestHandlerFactory()) // Should always be true
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
529 {
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
530 std::auto_ptr<IStoreRequestHandler> handler
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
531 (server_.GetStoreRequestHandlerFactory().ConstructStoreRequestHandler());
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
532 cond = Internals::storeScp(assoc_, &msg, presID, *handler);
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
533 }
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
534 break;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535
620
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
536 case DicomRequestType_Move:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
537 if (server_.HasMoveRequestHandlerFactory()) // Should always be true
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
538 {
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
539 std::auto_ptr<IMoveRequestHandler> handler
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
540 (server_.GetMoveRequestHandlerFactory().ConstructMoveRequestHandler());
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
541 cond = Internals::moveScp(assoc_, &msg, presID, *handler);
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
542 }
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
543 break;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
544
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
545 case DicomRequestType_Find:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
546 if (server_.HasFindRequestHandlerFactory()) // Should always be true
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
547 {
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
548 std::auto_ptr<IFindRequestHandler> handler
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
549 (server_.GetFindRequestHandlerFactory().ConstructFindRequestHandler());
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
550 cond = Internals::findScp(assoc_, &msg, presID, *handler);
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
551 }
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
552 break;
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
553
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
554 default:
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
555 // Should never happen
4aa6f0d79947 security filter for dicom requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 503
diff changeset
556 break;
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 // Bad status, which indicates the closing of the connection by
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 // the peer or a network error
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 finished = true;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 if (finished)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 if (cond == DUL_PEERREQUESTEDRELEASE)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
571 LOG(INFO) << "Association Release";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 ASC_acknowledgeRelease(assoc_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 else if (cond == DUL_PEERABORTEDASSOCIATION)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
576 LOG(INFO) << "Association Aborted";
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 else
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 OFString temp_str;
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
581 LOG(ERROR) << "DIMSE failure (aborting association): " << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 /* some kind of error so abort the association */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 ASC_abortAssociation(assoc_);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 return !finished;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 OFCondition EchoScp( T_ASC_Association * assoc, T_DIMSE_Message * msg, T_ASC_PresentationContextID presID)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 OFString temp_str;
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
594 LOG(INFO) << "Received Echo Request";
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
595 //LOG(DEBUG) << DIMSE_dumpMessage(temp_str, msg->msg.CEchoRQ, DIMSE_INCOMING, NULL, presID));
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 /* the echo succeeded !! */
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 OFCondition cond = DIMSE_sendEchoResponse(assoc, presID, &msg->msg.CEchoRQ, STATUS_Success, NULL);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 if (cond.bad())
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 {
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 101
diff changeset
601 LOG(ERROR) << "Echo SCP Failed: " << cond.text();
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 return cond;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 }