00001 /* 00002 * 00003 * Copyright (C) 1998-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: dcmnet 00015 * 00016 * Author: Marco Eichelberg 00017 * 00018 * Purpose: 00019 * classes: DcmTransportConnection, DcmTCPConnection 00020 * 00021 * Last Update: $Author: joergr $ 00022 * Update Date: $Date: 2010-10-14 13:17:22 $ 00023 * CVS/RCS Revision: $Revision: 1.11 $ 00024 * Status: $State: Exp $ 00025 * 00026 * CVS/RCS Log at end of file 00027 * 00028 */ 00029 00030 #ifndef DCMTRANS_H 00031 #define DCMTRANS_H 00032 00033 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00034 #include "dcmtk/ofstd/oftypes.h" /* for OFBool */ 00035 #include "dcmtk/dcmnet/dcmlayer.h" /* for DcmTransportLayerStatus */ 00036 #include "dcmtk/ofstd/ofstream.h" /* for ostream */ 00037 00038 #define INCLUDE_UNISTD 00039 #include "dcmtk/ofstd/ofstdinc.h" 00040 00045 class DcmTransportConnection 00046 { 00047 public: 00048 00054 DcmTransportConnection(int openSocket); 00055 00058 virtual ~DcmTransportConnection(); 00059 00065 virtual DcmTransportLayerStatus serverSideHandshake() = 0; 00066 00072 virtual DcmTransportLayerStatus clientSideHandshake() = 0; 00073 00080 virtual DcmTransportLayerStatus renegotiate(const char *newSuite) = 0; 00081 00088 virtual ssize_t read(void *buf, size_t nbyte) = 0; 00089 00096 virtual ssize_t write(void *buf, size_t nbyte) = 0; 00097 00102 virtual void close() = 0; 00103 00108 virtual unsigned long getPeerCertificateLength() = 0; 00109 00110 /* copies the peer certificate of a secure connection into a buffer 00111 * specified by the caller. If the buffer is too small to hold the 00112 * certificate, nothing is copied and zero is returned. 00113 * @param buf buffer into which the certificate is written 00114 * @param bufLen size of the buffer in bytes 00115 * @return number of bytes written, always less or equal bufLen. 00116 */ 00117 virtual unsigned long getPeerCertificate(void *buf, unsigned long bufLen) = 0; 00118 00125 virtual OFBool networkDataAvailable(int timeout) = 0; 00126 00130 virtual OFBool isTransparentConnection() = 0; 00131 00136 virtual OFString& dumpConnectionParameters(OFString& str) = 0; 00137 00143 void dumpConnectionParameters(STD_NAMESPACE ostream& out); 00144 00149 virtual const char *errorString(DcmTransportLayerStatus code) = 0; 00150 00165 static OFBool selectReadableAssociation(DcmTransportConnection *connections[], int connCount, int timeout); 00166 00167 protected: 00168 00172 int getSocket() { return theSocket; } 00173 00177 void setSocket(int socket) { theSocket = socket; } 00178 00179 private: 00180 00182 DcmTransportConnection(const DcmTransportConnection&); 00183 00185 DcmTransportConnection& operator=(const DcmTransportConnection&); 00186 00203 static OFBool safeSelectReadableAssociation(DcmTransportConnection *connections[], int connCount, int timeout); 00204 00221 static OFBool fastSelectReadableAssociation(DcmTransportConnection *connections[], int connCount, int timeout); 00222 00224 int theSocket; 00225 }; 00226 00227 00230 class DcmTCPConnection: public DcmTransportConnection 00231 { 00232 public: 00233 00239 DcmTCPConnection(int openSocket); 00240 00243 virtual ~DcmTCPConnection(); 00244 00250 virtual DcmTransportLayerStatus serverSideHandshake(); 00251 00257 virtual DcmTransportLayerStatus clientSideHandshake(); 00258 00265 virtual DcmTransportLayerStatus renegotiate(const char *newSuite); 00266 00273 virtual ssize_t read(void *buf, size_t nbyte); 00274 00281 virtual ssize_t write(void *buf, size_t nbyte); 00282 00287 virtual void close(); 00288 00293 virtual unsigned long getPeerCertificateLength(); 00294 00295 /* copies the peer certificate of a secure connection into a buffer 00296 * specified by the caller. If the buffer is too small to hold the 00297 * certificate, nothing is copied and zero is returned. 00298 * @param buf buffer into which the certificate is written 00299 * @param bufLen size of the buffer in bytes 00300 * @return number of bytes written, always less or equal bufLen. 00301 */ 00302 virtual unsigned long getPeerCertificate(void *buf, unsigned long bufLen); 00303 00309 virtual OFBool networkDataAvailable(int timeout); 00310 00314 virtual OFBool isTransparentConnection(); 00315 00320 virtual OFString& dumpConnectionParameters(OFString& str); 00321 00326 virtual const char *errorString(DcmTransportLayerStatus code); 00327 00328 private: 00329 00331 DcmTCPConnection(const DcmTCPConnection&); 00332 00334 DcmTCPConnection& operator=(const DcmTCPConnection&); 00335 00336 }; 00337 00338 #endif 00339 00340 /* 00341 * $Log: dcmtrans.h,v $ 00342 * Revision 1.11 2010-10-14 13:17:22 joergr 00343 * Updated copyright header. Added reference to COPYRIGHT file. 00344 * 00345 * Revision 1.10 2009-11-18 11:53:58 uli 00346 * Switched to logging mechanism provided by the "new" oflog module. 00347 * 00348 * Revision 1.9 2009-01-29 11:39:44 joergr 00349 * Fixed issue with missing invalidation of socket variable during close method. 00350 * Please note that this is only required if the connection objects exists after 00351 * the TCP/IP connection has been closed (which is currently not the case). 00352 * 00353 * Revision 1.8 2006/08/15 16:04:29 meichel 00354 * Updated the code in module dcmnet to correctly compile when 00355 * all standard C++ classes remain in namespace std. 00356 * 00357 * Revision 1.7 2005/12/08 16:02:18 meichel 00358 * Changed include path schema for all DCMTK header files 00359 * 00360 * Revision 1.6 2004/08/03 11:42:43 meichel 00361 * Headers libc.h and unistd.h are now included via ofstdinc.h 00362 * 00363 * Revision 1.5 2003/12/05 10:39:45 joergr 00364 * Removed leading underscore characters from preprocessor symbols (reserved 00365 * symbols). 00366 * 00367 * Revision 1.4 2003/07/04 13:27:15 meichel 00368 * Added include for ofstream.h, to make sure ofstream is correctly defined 00369 * 00370 * Revision 1.3 2001/06/01 15:50:04 meichel 00371 * Updated copyright header 00372 * 00373 * Revision 1.2 2000/10/10 12:06:53 meichel 00374 * Updated transport layer error codes and routines for printing 00375 * connection parameters. 00376 * 00377 * Revision 1.1 2000/08/10 14:50:53 meichel 00378 * Added initial OpenSSL support. 00379 * 00380 * 00381 */