00001 /* 00002 * 00003 * Copyright (C) 1994-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: network conditions and helper class 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:17:21 $ 00022 * CVS/RCS Revision: $Revision: 1.16 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 #ifndef COND_H 00030 #define COND_H 00031 00032 #include "dcmtk/config/osconfig.h" 00033 #include "dcmtk/ofstd/ofconsol.h" 00034 #include "dcmtk/dcmdata/dcerror.h" 00035 00036 /* NOTES ON THE CONVERSION OF THE DCMNET MODULE FROM CONDITION TO OFCONDITION 00037 * 00038 * All functions in this module have been adapted to the new OFCondition 00039 * class which - unlike the CONDITION functions - does not create problems 00040 * in multi-threaded code. The following notes explain the major differences 00041 * and modifications needed in client code. 00042 * 00043 * - OFCondition is a class (CONDITION was just a typedef for long). This 00044 * means that switch statements on conditions are not possible anymore. 00045 * Use if/else if/else constructs instead. 00046 * 00047 * - The condition ASC_RELEASECONFIRMED has been removed. 00048 * ASC_releaseAssociation() now returns EC_Normal upon successful completion. 00049 * 00050 * - No translation of error codes that are passed from the DUL module to the 00051 * ASC or DIMSE module is performed anymore. That means that error codes 00052 * such as DUL_PEERABORTEDASSOCIATION or DUL_PEERREQUESTEDRELEASE are now 00053 * passed back to client code instead of their "aliases" with ASC_ or 00054 * DIMSE_ prefix. Macros have been defined to catch most of these cases. 00055 * 00056 * - All normal status codes (DUL_NORMAL, DIMSE_NORMAL, ASC_NORMAL) have been 00057 * mapped to EC_Normal. Macros have also been defined for these identifiers. 00058 * 00059 * - DUL_PEERREQUESTEDRELEASE is now an error code, i.e. unlike prior releases 00060 * SUCCESS(DUL_PEERREQUESTEDRELEASE) is false. 00061 * 00062 * - In strict mode (compiled with OFCONDITION_STRICT_MODE), additional 00063 * restrictions apply. OFCondition requires explicit copy construction 00064 * (not default constructor), and all compatibility aliases/typedefs 00065 * are disabled. SUCCESS(cond) is undefined, use cond.good() instead. 00066 * 00067 */ 00068 00069 // condition code constants used in the association module 00070 const unsigned short ASCC_BADPRESENTATIONCONTEXTID = 0x101; 00071 const unsigned short ASCC_BADPRESENTATIONCONTEXTPOSITION = 0x102; 00072 const unsigned short ASCC_CODINGERROR = 0x103; 00073 const unsigned short ASCC_DUPLICATEPRESENTATIONCONTEXTID = 0x104; 00074 const unsigned short ASCC_MISSINGTRANSFERSYNTAX = 0x105; 00075 const unsigned short ASCC_NULLKEY = 0x106; 00076 const unsigned short ASCC_SHUTDOWNAPPLICATION = 0x107; 00077 const unsigned short ASCC_USERIDENTIFICATIONFAILED = 0x108; 00078 const unsigned short ASCC_SCPSCUROLESELECTIONFAILED = 0x109; 00079 00080 // condition constants used in the association module 00081 extern const OFCondition ASC_BADPRESENTATIONCONTEXTID; /* Bad presentation context ID */ 00082 extern const OFCondition ASC_MISSINGTRANSFERSYNTAX; /* Missing transfer syntax */ 00083 extern const OFCondition ASC_NULLKEY; /* Caller passed in a NULL key */ 00084 extern const OFCondition ASC_SHUTDOWNAPPLICATION; /* Peer requested application shutdown */ 00085 extern const OFCondition ASC_USERIDENTIFICATIONFAILED; /* User Identity Negotiation failed */ 00086 extern const OFCondition ASC_SCPSCUROLESELECTIONFAILED; /* SCP/SCU role selection failed */ 00087 00088 // condition code constants used in the DIMSE module 00089 const unsigned short DIMSEC_BADCOMMANDTYPE = 0x201; 00090 const unsigned short DIMSEC_BADDATA = 0x202; 00091 const unsigned short DIMSEC_BADMESSAGE = 0x203; 00092 const unsigned short DIMSEC_BUILDFAILED = 0x204; 00093 const unsigned short DIMSEC_ILLEGALASSOCIATION = 0x205; 00094 const unsigned short DIMSEC_INVALIDPRESENTATIONCONTEXTID = 0x206; 00095 const unsigned short DIMSEC_NODATAAVAILABLE = 0x207; 00096 const unsigned short DIMSEC_NOVALIDPRESENTATIONCONTEXTID = 0x208; 00097 const unsigned short DIMSEC_NULLKEY = 0x209; 00098 const unsigned short DIMSEC_OUTOFRESOURCES = 0x20a; 00099 const unsigned short DIMSEC_PARSEFAILED = 0x20b; 00100 const unsigned short DIMSEC_READPDVFAILED = 0x20c; 00101 const unsigned short DIMSEC_RECEIVEFAILED = 0x20d; 00102 const unsigned short DIMSEC_SENDFAILED = 0x20e; 00103 const unsigned short DIMSEC_UNEXPECTEDPDVTYPE = 0x20f; 00104 const unsigned short DIMSEC_UNEXPECTEDREQUEST = 0x210; 00105 const unsigned short DIMSEC_UNEXPECTEDRESPONSE = 0x211; 00106 const unsigned short DIMSEC_UNSUPPORTEDTRANSFERSYNTAX = 0x212; 00107 const unsigned short DIMSEC_NODATADICT = 0x213; 00108 00109 // condition constants used in the DIMSE module 00110 extern const OFCondition DIMSE_BADCOMMANDTYPE; /* Bad command type */ 00111 extern const OFCondition DIMSE_BADDATA; /* Inappropriate data for message (send) */ 00112 extern const OFCondition DIMSE_BADMESSAGE; /* Badly formed message (send) */ 00113 extern const OFCondition DIMSE_ILLEGALASSOCIATION; /* Caller passed in an illegal association */ 00114 extern const OFCondition DIMSE_NODATAAVAILABLE; /* no data (timeout in non-blocking mode) */ 00115 extern const OFCondition DIMSE_NOVALIDPRESENTATIONCONTEXTID; /* no valid presentation context ID */ 00116 extern const OFCondition DIMSE_NULLKEY; /* Caller passed in a NULL key */ 00117 extern const OFCondition DIMSE_OUTOFRESOURCES; /* out of resources */ 00118 extern const OFCondition DIMSE_PARSEFAILED; /* Failed to parse received message*/ 00119 extern const OFCondition DIMSE_READPDVFAILED; /* Read PDV failed */ 00120 extern const OFCondition DIMSE_RECEIVEFAILED; /* Failed to receive message */ 00121 extern const OFCondition DIMSE_SENDFAILED; /* Failed to send message */ 00122 extern const OFCondition DIMSE_UNEXPECTEDPDVTYPE; /* Unexpected PDV type */ 00123 extern const OFCondition DIMSE_NODATADICT; /* Data dictionary missing */ 00124 00125 // condition code constants used in the DUL module 00126 const unsigned short DULC_ASSOCIATIONREJECTED = 0x301; 00127 const unsigned short DULC_CODINGERROR = 0x302; 00128 const unsigned short DULC_FSMERROR = 0x303; 00129 const unsigned short DULC_ILLEGALACCEPT = 0x304; 00130 const unsigned short DULC_ILLEGALKEY = 0x305; 00131 const unsigned short DULC_ILLEGALPARAMETER = 0x306; 00132 const unsigned short DULC_ILLEGALPDU = 0x307; 00133 const unsigned short DULC_ILLEGALPDULENGTH = 0x308; 00134 const unsigned short DULC_ILLEGALREJECTREASON = 0x309; 00135 const unsigned short DULC_ILLEGALREJECTRESULT = 0x30a; 00136 const unsigned short DULC_ILLEGALREQUEST = 0x30b; 00137 const unsigned short DULC_ILLEGALSERVICEPARAMETER = 0x30c; 00138 const unsigned short DULC_INCORRECTBUFFERLENGTH = 0x30d; 00139 const unsigned short DULC_INSUFFICIENTBUFFERLENGTH = 0x30e; 00140 const unsigned short DULC_LISTERROR = 0x30f; 00141 const unsigned short DULC_NETWORKCLOSED = 0x310; 00142 // 0x311 was NETWORKINITIALIZED (Network already initialized) in previous releases 00143 const unsigned short DULC_NOASSOCIATIONREQUEST = 0x312; 00144 const unsigned short DULC_NOPDVS = 0x313; 00145 const unsigned short DULC_NULLKEY = 0x314; 00146 const unsigned short DULC_PCTRANSLATIONFAILURE = 0x315; 00147 const unsigned short DULC_PDATAPDUARRIVED = 0x316; 00148 const unsigned short DULC_PEERABORTEDASSOCIATION = 0x317; 00149 const unsigned short DULC_PEERILLEGALXFERSYNTAXCOUNT = 0x318; 00150 const unsigned short DULC_PEERREQUESTEDRELEASE = 0x319; 00151 const unsigned short DULC_READTIMEOUT = 0x31a; 00152 const unsigned short DULC_REQUESTASSOCIATIONFAILED = 0x31b; 00153 const unsigned short DULC_TCPINITERROR = 0x31c; 00154 const unsigned short DULC_TCPIOERROR = 0x31d; 00155 const unsigned short DULC_TLSERROR = 0x31e; 00156 const unsigned short DULC_UNEXPECTEDPDU = 0x31f; 00157 const unsigned short DULC_UNKNOWNHOST = 0x320; 00158 const unsigned short DULC_UNRECOGNIZEDPDUTYPE = 0x321; 00159 const unsigned short DULC_UNSUPPORTEDPEERPROTOCOL = 0x322; 00160 const unsigned short DULC_WRONGDATATYPE = 0x323; 00161 const unsigned short DULC_TCPWRAPPER = 0x324; 00162 const unsigned short DULC_FORKEDCHILD = 0x325; 00163 const unsigned short DULC_CANNOTFORK = 0x326; 00164 00165 // condition constants used in the DUL module 00166 extern const OFCondition DUL_ASSOCIATIONREJECTED; /* DUL Association Rejected */ 00167 extern const OFCondition DUL_ILLEGALACCEPT; /* Attempt to accept by requestor */ 00168 extern const OFCondition DUL_ILLEGALKEY; /* Illegal key */ 00169 extern const OFCondition DUL_ILLEGALPDU; /* DUL Illegal or ill-formed PDU */ 00170 extern const OFCondition DUL_ILLEGALPDULENGTH; /* DUL Illegal PDU Length */ 00171 extern const OFCondition DUL_ILLEGALREQUEST; /* Attempt to request by acceptor */ 00172 extern const OFCondition DUL_INCORRECTBUFFERLENGTH; /* DUL Incorrect buffer space allocated for data */ 00173 extern const OFCondition DUL_INSUFFICIENTBUFFERLENGTH; /* DUL Insufficient buffer space allocated for data */ 00174 extern const OFCondition DUL_LISTERROR; /* DUL List error */ 00175 extern const OFCondition DUL_NETWORKCLOSED; /* DUL network closed */ 00176 extern const OFCondition DUL_NOASSOCIATIONREQUEST; /* No requests for associations for this server */ 00177 extern const OFCondition DUL_NOPDVS; /* DUL No PDVs available in current buffer */ 00178 extern const OFCondition DUL_NULLKEY; /* NULL key passed to routine */ 00179 extern const OFCondition DUL_PCTRANSLATIONFAILURE; /* DUL Presentation Context translation failure */ 00180 extern const OFCondition DUL_PDATAPDUARRIVED; /* DUL P-Data PDU arrived */ 00181 extern const OFCondition DUL_PEERABORTEDASSOCIATION; /* Peer aborted Association (or never connected) */ 00182 extern const OFCondition DUL_PEERREQUESTEDRELEASE; /* DUL Peer Requested Release */ 00183 extern const OFCondition DUL_READTIMEOUT; /* DUL network read timeout */ 00184 extern const OFCondition DUL_REQUESTASSOCIATIONFAILED; /* Failed to establish association */ 00185 extern const OFCondition DUL_UNEXPECTEDPDU; /* Received unexpected PDU */ 00186 extern const OFCondition DUL_UNSUPPORTEDPEERPROTOCOL; /* DUL Unsupported peer protocol */ 00187 extern const OFCondition DUL_WRONGDATATYPE; /* DUL Wrong Data Type Specified for Request */ 00188 00189 00190 // This macro creates a condition with given code, severity and text. 00191 // Making this a macro instead of a function saves the creation of a temporary. 00192 #define makeDcmnetCondition(A, B, C) makeOFCondition(OFM_dcmnet, (A), (B), (C)) 00193 00194 // This macro creates a condition with given code, severity, text, and subcondition. 00195 // This method is intended as a replacement for COND_PushCondition(). 00196 // Instead of maintaining a global condition stack (which is difficult 00197 // in multi-threaded applications), the error text of the sub-condition 00198 // is appended to the newly created condition. 00199 // Making this a macro instead of a function saves the creation of a temporary. 00200 #define makeDcmnetSubCondition(A, B, C, D) DimseCondition::push(OFM_dcmnet, (A), (B), (C), (D)) 00201 00202 00207 class DimseCondition 00208 { 00209 public: 00210 00219 static OFString& dump(OFString& str, OFCondition cond); 00220 00229 static void dump(OFCondition cond, OFConsole& console = ofConsole); 00230 00237 static OFCondition push( 00238 unsigned short aModule, 00239 unsigned short aCode, 00240 OFStatus aStatus, 00241 const char *aText, 00242 OFCondition subCondition); 00243 00250 static OFCondition push( 00251 OFCondition newCondition, 00252 OFCondition subCondition); 00253 00254 }; 00255 00256 00257 // if not in strict mode, we define a couple of things 00258 // to improve compatibility with existing code. 00259 #ifndef OFCONDITION_STRICT_MODE 00260 00261 // CONDITION is now identical to OFCondition 00262 typedef OFCondition CONDITION; 00263 00264 // the success macro was defined in dicom.h in earlier releases 00265 #define SUCCESS(cond) ((cond).good()) 00266 00267 // aliases for condition codes 00268 #define ASC_ASSOCIATIONREJECTED DUL_ASSOCIATIONREJECTED 00269 #define ASC_NORMAL EC_Normal 00270 #define ASC_PEERABORTEDASSOCIATION DUL_PEERABORTEDASSOCIATION 00271 #define ASC_PEERREQUESTEDRELEASE DUL_PEERREQUESTEDRELEASE 00272 #define ASC_READTIMEOUT DUL_READTIMEOUT 00273 #define DIMSE_NORMAL EC_Normal 00274 #define DIMSE_PEERABORTEDASSOCIATION DUL_PEERABORTEDASSOCIATION 00275 #define DIMSE_PEERREQUESTEDRELEASE DUL_PEERREQUESTEDRELEASE 00276 00277 #endif /* !OFCONDITION_STRICT_MODE */ 00278 00279 #endif 00280 00281 /* 00282 * CVS Log 00283 * $Log: cond.h,v $ 00284 * Revision 1.16 2010-10-14 13:17:21 joergr 00285 * Updated copyright header. Added reference to COPYRIGHT file. 00286 * 00287 * Revision 1.15 2010-09-09 08:32:13 joergr 00288 * Fixed typo in OFCondition constants for SCP/SCU role selection failures. 00289 * 00290 * Revision 1.14 2010-08-26 09:27:21 joergr 00291 * Fixed incorrect behavior of association acceptors during SCP/SCU role 00292 * selection negotiation. 00293 * 00294 * Revision 1.13 2009-11-18 11:53:58 uli 00295 * Switched to logging mechanism provided by the "new" oflog module. 00296 * 00297 * Revision 1.12 2008-09-08 13:16:11 joergr 00298 * Fixed typo in OFCondition text string. 00299 * 00300 * Revision 1.11 2008-04-17 15:28:33 onken 00301 * Reworked and extended User Identity Negotiation code. 00302 * 00303 * Revision 1.10 2005-12-08 16:02:07 meichel 00304 * Changed include path schema for all DCMTK header files 00305 * 00306 * Revision 1.9 2005/11/25 11:31:11 meichel 00307 * StoreSCP now supports multi-process mode both on Posix and Win32 platforms 00308 * where a separate client process is forked for each incoming association. 00309 * 00310 * Revision 1.8 2003/06/10 13:37:36 meichel 00311 * Added support for TCP wrappers in DICOM network layer 00312 * 00313 * Revision 1.7 2002/12/10 11:00:57 meichel 00314 * Removed error code DUL_NETWORKINITIALIZED which is not used anymore 00315 * 00316 * Revision 1.6 2001/10/12 10:18:25 meichel 00317 * Replaced the CONDITION types, constants and functions in the dcmnet module 00318 * by an OFCondition based implementation which eliminates the global condition 00319 * stack. This is a major change, caveat emptor! 00320 * 00321 * 00322 */