~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/cadxcore/main/controllers/dcmtk/dicomnetwork.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
}
96
96
 
97
97
GIL::DICOM::DCMTK::Network::~Network() {
98
 
    DropNetwork();
 
98
        DropNetwork();
99
99
}
100
100
 
101
101
CONDITION GIL::DICOM::DCMTK::Network::ConnectAssociation(Association* assoc, int pdu) {
110
110
                                                                  assoc->m_ourAET,
111
111
                                                                  pdu);
112
112
        if (!SUCCESS(cond)) {
113
 
                LOG_ERROR(assoc->ambitolog, "Unable to connect association: " << cond.text());
114
113
                assoc->Drop(cond);
115
114
                return cond;
116
115
        }
132
131
                LOG_WARN("DICOMNetwork", "Shutting down previous initiallized network");
133
132
                DropNetwork();
134
133
        }
135
 
#ifdef _WIN32
136
 
    WORD wVersionRequested;
137
 
    WSADATA wsaData;
138
 
        
139
 
    wVersionRequested = MAKEWORD(1, 1);
140
 
        
141
 
    WSAStartup(wVersionRequested, &wsaData);
142
 
#endif
143
134
 
144
135
        CONDITION cond;
145
136
        
158
149
                        break;
159
150
        }
160
151
        m_Initiallized = cond.good();
161
 
    return cond;
 
152
        return cond;
162
153
}
163
154
 
164
155
CONDITION GIL::DICOM::DCMTK::Network::DropNetwork() {
165
 
        GNC::GCS::ILocker lock(m_sLock);
 
156
        
166
157
        CONDITION cond = ASC_dropNetwork(&m_pDCMTKNetwork);
167
158
        m_pDCMTKNetwork = NULL;
168
159
        
169
 
#if defined(_WINDOWS)
170
 
    WSACleanup();
171
 
#endif
172
 
        
173
 
    return cond;
 
160
        return cond;
174
161
}
175
162
 
176
163
CONDITION GIL::DICOM::DCMTK::Network::ASC_ConnectAssociation(Association* assoc, const std::string& peerTitle, const std::string& peer, int port, const std::string& ouraet, int pdu) {
177
 
    GNC::GCS::ILocker lock(m_sLock);
178
 
    CONDITION cond;
 
164
        CONDITION cond;
179
165
        
180
166
        GTLSTransportLayer *tLayer = NULL;
181
167
        
184
170
                tLayer = new GTLSTransportLayer(DICOM_APPLICATION_REQUESTOR, NULL);
185
171
                if (tLayer == NULL)
186
172
                {
187
 
                        LOG_ERROR(assoc->ambitolog, "unable to create TLS transport layer");
188
 
                        //return 1;
189
 
                        return EC_IllegalParameter;
 
173
                        return makeOFCondition(OFM_dcmtls, DULC_TLSERROR, OF_error, "TLS Error: Unable to create TLS transport layer");
190
174
                }
191
175
                tLayer->setCertificateFromString(assoc->GetCliCert());
192
176
                tLayer->setPrivateKeyFromString(assoc->GetCliKey());
193
177
                
194
178
                if (! tLayer->checkPrivateKeyMatchesCertificate())
195
179
                {
196
 
                        LOG_ERROR(assoc->ambitolog, "private key and certificate do not match");
197
 
                        return EC_IllegalParameter;
 
180
                        return makeOFCondition(OFM_dcmtls, DULC_TLSERROR, OF_error, "TLS Error: Private key and certificate do not match");
198
181
                }
199
182
                
200
183
                tLayer->addSystemTrustedCertificates();
215
198
                cond = ASC_setTransportLayer(m_pDCMTKNetwork, tLayer, 0);
216
199
                if (cond.bad())
217
200
                {
218
 
                        LOG_ERROR(assoc->ambitolog, "Error al insertar capa de transporte segura: " << cond.text());
219
 
                        return EC_IllegalParameter;
 
201
                        return cond;
220
202
                }
221
203
    }   
222
204
        
223
205
    T_ASC_Parameters *params;
224
 
        
225
 
        std::string peerHost;
 
206
         
 
207
         std::string peerHost;
226
208
    char localHost[129];
227
209
        
228
210
    cond = ASC_createAssociationParameters(&params, pdu);
239
221
         }
240
222
 
241
223
    ASC_setAPTitles(params, ouraet.c_str(), peerTitle.c_str(), NULL);
242
 
        
243
 
        
244
 
        cond = ASC_setTransportLayerType(params, assoc->IsSecure());
245
 
    if (cond.bad()) {
246
 
        LOG_ERROR(assoc->ambitolog, "Error al fijar capa de transporte segura: " << cond.text());
247
 
        return cond;
248
 
    }
249
 
        
250
 
    gethostname(localHost, sizeof (localHost) - 1);
 
224
         
 
225
         cond = ASC_setTransportLayerType(params, assoc->IsSecure());
 
226
         if (cond.bad()) {
 
227
                 return cond;
 
228
        }
 
229
        
 
230
        gethostname(localHost, sizeof (localHost) - 1);
251
231
        {
252
232
                std::ostringstream os;
253
233
                os << peer.c_str() << ":" << port;
255
235
        }
256
236
        ASC_setPresentationAddresses(params, localHost, peerHost.c_str());
257
237
 
258
 
        if (assoc) {
259
 
                assoc->OnAddPresentationContext(params);
260
 
        }
 
238
        assoc->OnAddPresentationContext(params);
261
239
 
262
240
        {
263
241
                OFString str;
267
245
        }
268
246
        
269
247
        /* create association */
270
 
    cond = ASC_requestAssociation(m_pDCMTKNetwork, params, &(assoc->assoc));
271
 
    if (cond != ASC_NORMAL) {
 
248
        cond = ASC_requestAssociation(m_pDCMTKNetwork, params, &(assoc->assoc));
 
249
        if (cond != ASC_NORMAL) {
272
250
                if (cond == ASC_ASSOCIATIONREJECTED) {
273
251
                        T_ASC_RejectParameters rej;
274
252
                        
275
253
                        ASC_getRejectParameters(params, &rej);
276
254
                        OFString str;
277
255
                        ASC_printRejectParameters(str, &rej);
278
 
                        LOG_WARN(assoc->ambitolog, "Association Rejected" << std::endl << str.c_str());
279
 
                        return cond;
 
256
                        return makeOFCondition(OFM_dcmnet, DULC_ASSOCIATIONREJECTED, OF_error, str.c_str());
280
257
                }
281
258
                else {
282
259
                        return cond;
298
275
    return ASC_NORMAL;
299
276
}
300
277
 
301
 
bool GIL::DICOM::DCMTK::Network::SendEchoRequest(const std::string& title, const std::string& peer, int port, const std::string& ouraet, int pdu) {
302
 
    EchoAssociation dcmEcho("C-ECHO");
303
 
    dcmEcho.Create(title, peer, port, ouraet, UID_VerificationSOPClass);
 
278
CONDITION GIL::DICOM::DCMTK::Network::SendEchoRequest(const std::string& title, const std::string& peer, int port, const std::string& ouraet, int pdu) {
 
279
        EchoAssociation dcmEcho("C-ECHO");
 
280
        dcmEcho.Create(title, peer, port, ouraet, UID_VerificationSOPClass);
304
281
        
305
282
        ConnectAssociation(&dcmEcho, pdu);
306
283
        
307
 
    return dcmEcho.SendEchoRequest();
 
284
        return dcmEcho.SendEchoRequest();
308
285
}
309
286
 
310
287
T_ASC_Network* GIL::DICOM::DCMTK::Network::GetDcmtkNet() {