1 /* 2 * 3 * Copyright (C) 1993-2017, OFFIS e.V. 4 * All rights reserved. See COPYRIGHT file for details. 5 * 6 * This software and supporting documentation were developed by 7 * 8 * OFFIS e.V. 9 * R&D Division Health 10 * Escherweg 2 11 * D-26121 Oldenburg, Germany 12 * 13 * 14 * Module: dcmqrdb 15 * 16 * Author: Marco Eichelberg 17 * 18 * Purpose: class DcmQueryRetrieveSCP 19 * 20 */ 21 22 #ifndef DCMQRSRV_H 23 #define DCMQRSRV_H 24 25 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 26 #include "dcmtk/ofstd/oftypes.h" 27 #include "dcmtk/dcmnet/assoc.h" 28 #include "dcmtk/dcmnet/dimse.h" 29 #include "dcmtk/dcmnet/dcasccfg.h" 30 #include "dcmtk/dcmqrdb/dcmqrptb.h" 31 32 class DcmQueryRetrieveConfig; 33 class DcmQueryRetrieveOptions; 34 class DcmQueryRetrieveDatabaseHandle; 35 class DcmQueryRetrieveDatabaseHandleFactory; 36 37 /// enumeration describing reasons for refusing an association request 38 enum CTN_RefuseReason 39 { 40 /// too many concurrent associations 41 CTN_TooManyAssociations, 42 /// fork system function failed 43 CTN_CannotFork, 44 /// bad application context (not DICOM) 45 CTN_BadAppContext, 46 /// unknown peer application entity title (access not authorised) 47 CTN_BadAEPeer, 48 /// unknown peer application entity title (access not authorised) 49 CTN_BadAEService, 50 /// other non-specific reason 51 CTN_NoReason 52 }; 53 54 /** main class for Query/Retrieve Service Class Provider 55 */ 56 class DCMTK_DCMQRDB_EXPORT DcmQueryRetrieveSCP 57 { 58 public: 59 60 /** constructor 61 * @param config SCP configuration facility 62 * @param options SCP configuration options 63 * @param factory factory object used to create database handles 64 */ 65 DcmQueryRetrieveSCP( 66 const DcmQueryRetrieveConfig& config, 67 const DcmQueryRetrieveOptions& options, 68 const DcmQueryRetrieveDatabaseHandleFactory& factory, 69 const DcmAssociationConfiguration& associationConfiguration); 70 71 /// destructor ~DcmQueryRetrieveSCP()72 virtual ~DcmQueryRetrieveSCP() { } 73 74 /** wait for incoming A-ASSOCIATE requests, perform association negotiation 75 * and serve the requests. May fork child processes depending on availability 76 * of the fork() system function and configuration options. 77 * @param theNet network structure for listen socket 78 * @return EC_Normal if successful, an error code otherwise 79 */ 80 OFCondition waitForAssociation(T_ASC_Network *theNet); 81 82 /** set database flags 83 * @param dbCheckFindIdentifier flag indicating that a check should be performed for C-FIND requests 84 * @param dbCheckMoveIdentifier flag indicating that a check should be performed for C-MOVE requests 85 */ 86 void setDatabaseFlags( 87 OFBool dbCheckFindIdentifier, 88 OFBool dbCheckMoveIdentifier); 89 90 /** clean up terminated child processes. 91 */ 92 void cleanChildren(); 93 94 private: 95 96 /// private undefined copy constructor 97 DcmQueryRetrieveSCP(const DcmQueryRetrieveSCP& other); 98 99 /// private undefined assignment operator 100 DcmQueryRetrieveSCP& operator=(const DcmQueryRetrieveSCP& other); 101 102 /** perform association negotiation for an incoming A-ASSOCIATE request based 103 * on the SCP configuration and option flags. No A-ASSOCIATE response is generated, 104 * this is left to the caller. 105 * @param assoc incoming association 106 * @return EC_Normal if successful, an error code otherwise 107 */ 108 OFCondition negotiateAssociation(T_ASC_Association * assoc); 109 110 OFCondition refuseAssociation(T_ASC_Association ** assoc, CTN_RefuseReason reason); 111 112 OFCondition handleAssociation( 113 T_ASC_Association * assoc, 114 OFBool correctUIDPadding); 115 116 OFCondition echoSCP( 117 T_ASC_Association * assoc, 118 T_DIMSE_C_EchoRQ * req, 119 T_ASC_PresentationContextID presId); 120 121 OFCondition findSCP( 122 T_ASC_Association * assoc, 123 T_DIMSE_C_FindRQ * request, 124 T_ASC_PresentationContextID presID, 125 DcmQueryRetrieveDatabaseHandle& dbHandle); 126 127 OFCondition getSCP( 128 T_ASC_Association * assoc, 129 T_DIMSE_C_GetRQ * request, 130 T_ASC_PresentationContextID presID, 131 DcmQueryRetrieveDatabaseHandle& dbHandle); 132 133 OFCondition moveSCP( 134 T_ASC_Association * assoc, 135 T_DIMSE_C_MoveRQ * request, 136 T_ASC_PresentationContextID presID, 137 DcmQueryRetrieveDatabaseHandle& dbHandle); 138 139 OFCondition storeSCP( 140 T_ASC_Association * assoc, 141 T_DIMSE_C_StoreRQ * req, 142 T_ASC_PresentationContextID presId, 143 DcmQueryRetrieveDatabaseHandle& dbHandle, 144 OFBool correctUIDPadding); 145 146 OFCondition dispatch( 147 T_ASC_Association *assoc, 148 OFBool correctUIDPadding); 149 150 static void refuseAnyStorageContexts(T_ASC_Association *assoc); 151 152 /// configuration facility 153 const DcmQueryRetrieveConfig *config_; 154 155 /// child process table, only used in multi-processing mode 156 DcmQueryRetrieveProcessTable processtable_; 157 158 /// flag for database interface: check C-FIND identifier 159 OFBool dbCheckFindIdentifier_; 160 161 /// flag for database interface: check C-MOVE identifier 162 OFBool dbCheckMoveIdentifier_; 163 164 /// factory object used to create database handles 165 const DcmQueryRetrieveDatabaseHandleFactory& factory_; 166 167 /// SCP configuration options 168 const DcmQueryRetrieveOptions& options_; 169 170 /// Association configuration profiles read from configuration file 171 const DcmAssociationConfiguration& associationConfiguration_; 172 }; 173 174 #endif 175