Ejemplo n.º 1
0
CONDITION
MSG_ParseCFindResponse(DCM_OBJECT ** object, MSG_C_FIND_RESP * findResponse)
{
    static MSG_C_FIND_RESP       response;
    static unsigned short        command, type;

    static DCM_ELEMENT elementList[] = {
    		{DCM_GROUPCOMMAND, DCM_CMDCOMMANDFIELD, DCM_US, "", 1, sizeof(command), (void *) &command},
    		{DCM_GROUPCOMMAND, DCM_CMDCLASSUID, DCM_UI, "", 1, sizeof(response.classUID), (void *) response.classUID},
    		{DCM_GROUPCOMMAND, DCM_CMDMSGIDRESPOND, DCM_US, "", 1, sizeof(response.messageIDRespondedTo), (void *) &response.messageIDRespondedTo},
    		{DCM_GROUPCOMMAND, DCM_CMDDATASETTYPE, DCM_US, "", 1, sizeof(type), (void *) &type},
    		{DCM_GROUPCOMMAND, DCM_CMDSTATUS, DCM_US, "", 1, sizeof(response.status), (void *) &response.status},
    };

    void		    *ctx;
    int		        index;
    unsigned long   rtnLength;
    CONDITION 		cond;

    for (index = 0; index < (int) DIM_OF(elementList); index++) {
    	ctx = NULL;
    	cond = DCM_GetElementValue(object, &elementList[index], &rtnLength, &ctx);
    	if (cond != DCM_NORMAL) return COND_PushCondition(MSG_PARSEFAILED, MSG_Message(MSG_PARSEFAILED));
    }
    response.type = MSG_K_C_FIND_RESP;
    *findResponse = response;
    return MSG_NORMAL;
}
Ejemplo n.º 2
0
CONDITION
MSG_ParseCEchoRequest(DCM_OBJECT ** object, MSG_C_ECHO_REQ * echoRequest)
{
    static MSG_C_ECHO_REQ        request;
    static unsigned short        command, type;

    static DCM_ELEMENT elementList[] = {
    		{DCM_GROUPCOMMAND, DCM_CMDCOMMANDFIELD, DCM_US, "", 1, sizeof(command), (void *) &command},
    		{DCM_GROUPCOMMAND, DCM_CMDDATASETTYPE, DCM_US, "", 1, sizeof(type), (void *) &type},
    		{DCM_GROUPCOMMAND, DCM_CMDMSGID, DCM_US, "", 1,	sizeof(request.messageID), (void *) &request.messageID},
    		{DCM_GROUPCOMMAND, DCM_CMDCLASSUID, DCM_UI, "", 1, sizeof(request.UID), (void *) request.UID}
    };
    void	        *ctx;
    int		        index;
    unsigned long   rtnLength;
    CONDITION		cond;

    for (index = 0; index < (int) DIM_OF(elementList); index++) {
    	ctx = NULL;
    	cond = DCM_GetElementValue(object, &elementList[index], &rtnLength, &ctx);
    	if (cond != DCM_NORMAL) return COND_PushCondition(MSG_PARSEFAILED, MSG_Message(MSG_PARSEFAILED));
    }
    request.type = MSG_K_C_ECHO_REQ;
    *echoRequest = request;
    return MSG_NORMAL;
}
Ejemplo n.º 3
0
Archivo: iap.c Proyecto: bhavik86/Dicom
CONDITION
IAP_ObjectToQuery(DCM_OBJECT ** object, char *SOPClass, Query * query, int *elementCount)
{
    CONDITION		cond, returnCondition;
    int         	index;
    void        	*ctx;
    U32				l;
    long        	flag;
    static char     queryLevelString[48] = "";	/* Initialize for AIX compiler bug */
    DCM_ELEMENT		queryLevelElement = {DCM_IDQUERYLEVEL, DCM_CS, "", 1, sizeof(queryLevelString), (void *) &queryLevelString[0]};

    *elementCount = 0;
    q.QueryState = 0;
    q.Patient.Query_Flag = 0;
    q.Study.Query_Flag = 0;
    q.Series.Query_Flag = 0;
    q.Image.Query_Flag = 0;

    ctx = NULL;
    returnCondition = IAP_NORMAL;

    cond = DCM_GetElementValue(object, &queryLevelElement, &l, &ctx);
    if (cond != DCM_NORMAL) {
    	if (cond == DCM_ILLEGALOBJECT){
    		return COND_PushCondition(IAP_ILLEGALOBJECT, "IAP_ObjectToQuery");
    	}else{
    		(void) COND_PopCondition(FALSE);
    		(void) COND_PushCondition(IAP_QUERYLEVELMISSING, "IAP_ObjectToQuery");
    		returnCondition = IAP_INCOMPLETEOBJECT;
    	}
    }else{
    	queryLevelString[l] = '\0';
    	if (queryLevelString[l - 1] == ' ') queryLevelString[l - 1] = '\0';

    	for (index = 0; index < DIM_OF(levelMap); index++) {
    		if (strcmp(levelMap[index].queryLevel, queryLevelString) == 0) q.QueryState |= levelMap[index].flag;
    	}
    }

    flag = 0;
    for (index = 0; index < DIM_OF(classMap); index++) {
    	if (strcmp(classMap[index].SOPClass, SOPClass) == 0) flag |= classMap[index].flag;
    }
    if (flag == 0) {
    	(void) COND_PushCondition(IAP_SOPCLASSMISSING, "");
    	returnCondition = IAP_INCOMPLETEOBJECT;
    }
    q.QueryState |= flag;

    cond = DCM_ParseObject(object, NULL, 0, list, (int) DIM_OF(list), elementCount);
    if (cond != DCM_NORMAL)	return COND_PushCondition(IAP_OBJECTACCESSFAILED, IAP_Message(IAP_OBJECTACCESSFAILED), "IAP_ObjectToQuery");

    cond = parseImageInstanceUID(object, elementCount);
    if (cond != IAP_NORMAL)	return cond;

    *query = q;
    return returnCondition;
}
Ejemplo n.º 4
0
CONDITION
MSG_ParseCStoreRequest(DCM_OBJECT ** object, MSG_C_STORE_REQ * storeRequest)
{
    static MSG_C_STORE_REQ	   request;
    static unsigned short      command;

    static DCM_ELEMENT elementList[] = {
    		{DCM_GROUPCOMMAND, DCM_CMDCOMMANDFIELD, DCM_US, "", 1, sizeof(command), (void *) &command},
    		{DCM_GROUPCOMMAND, DCM_CMDCLASSUID, DCM_UI, "", 1, sizeof(request.classUID), (void *) request.classUID},
    		{DCM_GROUPCOMMAND, DCM_CMDMSGID, DCM_US, "", 1, sizeof(request.messageID), (void *) &request.messageID},
    		{DCM_GROUPCOMMAND, DCM_CMDPRIORITY, DCM_US, "", 1, sizeof(request.priority), (void *) &request.priority},
    		{DCM_GROUPCOMMAND, DCM_CMDDATASETTYPE, DCM_US, "", 1, sizeof(request.dataSetType), (void *) &request.dataSetType},
    		{DCM_GROUPCOMMAND, DCM_CMDREQUESTEDINSTANCEUID, DCM_UI, "", 1, sizeof(request.instanceUID), (void *) request.instanceUID}
    };

    static MSGPRV_CONDITIONAL conditional[] = {
    		{DCM_GROUPCOMMAND, DCM_CMDMOVEAETITLE, DCM_AE, "", 1, sizeof(request.moveAETitle), (void *) request.moveAETitle, &request.conditionalFields, MSG_K_C_STORE_MOVEAETITLE},
    		{DCM_GROUPCOMMAND, DCM_CMDMOVEMESSAGEID, DCM_US, "", 1, sizeof(request.moveMessageID), (void *) &request.moveMessageID,	&request.conditionalFields, MSG_K_C_STORE_MOVEMESSAGEID},
    };
    void	        *ctx;
    int		        index;
    unsigned long   rtnLength;
    CONDITION		cond;

    request.conditionalFields = 0;
    for (index = 0; index < (int) DIM_OF(elementList); index++) {
    	ctx = NULL;
    	cond = DCM_GetElementValue(object, &elementList[index], &rtnLength, &ctx);
    	if (cond != DCM_NORMAL) return COND_PushCondition(MSG_PARSEFAILED, MSG_Message(MSG_PARSEFAILED));
    }

    for (index = 0; index < (int) DIM_OF(conditional); index++) {
    	ctx = NULL;
    	cond = DCM_GetElementValue(object, &conditional[index].e, &rtnLength, &ctx);
    	if (cond == DCM_NORMAL) {
    		if (DCM_IsString(conditional[index].e.representation)) conditional[index].e.d.string[rtnLength] = '\0';
    		*conditional[index].flag |= conditional[index].flagBit;
    	}else{
    		(void) COND_PopCondition(FALSE);
    	}
    }
    request.type = MSG_K_C_STORE_REQ;
    *storeRequest = request;
    return MSG_NORMAL;
}
Ejemplo n.º 5
0
Archivo: iap.c Proyecto: bhavik86/Dicom
CONDITION
IAP_SendInfoObject(DUL_ASSOCIATIONKEY ** association, DUL_ASSOCIATESERVICEPARAMETERS * params, const char *fileName, const char *fileXferSyntax,
				   const char *moveAETitle, unsigned short moveMessageID, CONDITION(*sendCallback) (), void *callbackCtx)
{
    static MSG_C_STORE_REQ      request;
    CONDITION					cond;
    DCM_OBJECT					* object;
    static DCM_ELEMENT 			list[] = {
									{DCM_IDSOPCLASSUID, DCM_UI, "", 1, sizeof(request.classUID), (void *) &request.classUID[0]},
									{DCM_IDSOPINSTANCEUID, DCM_UI, "", 1, sizeof(request.instanceUID), (void *) &request.instanceUID[0]},
								};
    U32 						l;
    void 						*ctx;
    int 						index;

    if (fileName == NULL) return IAP_NORMAL;
    if (fileName[0] == '\0') return IAP_NORMAL;

    cond = DCM_OpenFile(fileName, DCM_PART10FILE, &object);
    if (cond != DCM_NORMAL)	return COND_PushCondition(IAP_OBJECTACCESSFAILED, IAP_Message(IAP_OBJECTACCESSFAILED), "IAP_SendInfoObject");

    for (index = 0; index < (int) DIM_OF(list); index++) {
    	ctx = NULL;
    	cond = DCM_GetElementValue(&object, &list[index], &l, &ctx);
    	if (cond != DCM_NORMAL) {
    		(void) DCM_CloseObject(&object);
    		return COND_PushCondition(IAP_OBJECTACCESSFAILED, IAP_Message(IAP_OBJECTACCESSFAILED), "IAP_SendInfoObject");
    	}
    	list[index].d.string[l] = '\0';
    }
    (void) DCM_RemoveGroup(&object, DCM_GROUPFILEMETA);

    request.type = MSG_K_C_STORE_REQ;
    request.messageID = SRV_MessageIDOut();
    request.priority = DCM_PRIORITYMEDIUM;
    request.dataSetType = DCM_CMDDATAIMAGE;
    request.dataSet = object;
    request.fileName = NULL;
    request.conditionalFields = 0;

    if (moveAETitle != NULL) {
    	strcpy(request.moveAETitle, moveAETitle);
    	request.moveMessageID = moveMessageID;
    	request.conditionalFields |= MSG_K_C_STORE_MOVEMESSAGEID | MSG_K_C_STORE_MOVEAETITLE;
    }else{
    	request.moveAETitle[0] = '\0';
    }
    cond = SRV_CStoreRequest(association, params, &request, NULL, sendCallback, callbackCtx, "");

    (void) DCM_CloseObject(&object);
    if (cond != SRV_NORMAL)	return COND_PushCondition(IAP_SENDFAILED, IAP_Message(IAP_SENDFAILED), "IAP_SendInfoObject");

    return IAP_NORMAL;
}
Ejemplo n.º 6
0
static CTNBOOLEAN
findElement(DCM_OBJECT * object, DCM_TAG tag, DCM_ELEMENT * element)
{
    CONDITION		cond;				/* Return value from DUL and ACR routines */
    DCM_ELEMENT		dcm_element;		/* Handle to the dicom data element */
    void			*ctx;				/* Context variable used by DCM_GetElementValue */
    CTNBOOLEAN		flag = TRUE;		/* See Return Values in the header */
    CTNBOOLEAN		isString = FALSE;	/* Flag indicates if value is of string type */


    /* Find the group and element fields in the tag. */
    dcm_element.tag = tag;
    element->tag = dcm_element.tag;

    /* Find the representation of the data in the element. */
    cond = DCM_LookupElement(&dcm_element);
    if (cond != DCM_NORMAL) {
    	cond = COND_PopCondition(FALSE);
    	return FALSE;
    }

    /* Fill the length field and assign the memory for the data. */
    switch (dcm_element.representation) {
		case DCM_LO:		/* Long string */
		case DCM_UI:		/* UID */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char));
								isString = TRUE;
							}
							break;
		case DCM_DA:		/* Date */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char));
								isString = TRUE;
							}
							break;
		case DCM_CS:		/* Control string */
		case DCM_TM:		/* Time */
		case DCM_SH:		/* Short string */
		case DCM_DS:		/* Decimal string */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char));
								isString = TRUE;
							}
							break;
		case DCM_IS:		/* Integer string */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char));
								isString = TRUE;
							}
							break;
		case DCM_ST:		/* Short text */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char));
								isString = TRUE;
							}
							break;
		case DCM_LT:		/* Long text */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char));
								isString = TRUE;
							}
							break;
		case DCM_PN:		/* Person name */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char));
								isString = TRUE;
							}
							break;
		case DCM_AS:		/* Age string */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.string = malloc((dcm_element.length + 1) * sizeof(char));
								isString = TRUE;
							}
							break;
		case DCM_SS:		/* Signed short */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.ss = malloc((dcm_element.length + 1) * sizeof(char));
							}
							break;
		case DCM_SL:		/* signed long */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.sl = malloc((dcm_element.length + 1) * sizeof(char));
							}
							break;
		case DCM_US:		/* unsigned short */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.us = malloc((dcm_element.length + 1) * sizeof(char));
							}
							break;
		case DCM_UL:		/* unsigned long */
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond != DCM_NORMAL){
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}else{
								dcm_element.d.ul = malloc((dcm_element.length + 1) * sizeof(char));
							}
							break;
		case DCM_SQ:		/* Sequence of items */
							break;
		default:
							cond = DCM_GetElementSize(&object, tag, &(dcm_element.length));
							if (cond == DCM_NORMAL){
								return flag;
							}else{
								cond = COND_PopCondition(FALSE);
								return FALSE;
							}
    }

    /* The following is necessary when made the first call to DCM_GetElementValue(). */
    ctx = NULL;
    cond = DCM_GetElementValue(&object, &dcm_element, &(dcm_element.length), &ctx);
    if (cond != DCM_NORMAL) {	/* check for error */
    	/* the attribute is not found */
    	flag = FALSE;
    	cond = COND_PopCondition(FALSE);
    }else{
    	if (isString) dcm_element.d.string[dcm_element.length] = '\0';
    	*element = dcm_element;
    }
    return flag;
}
Ejemplo n.º 7
0
Archivo: get.c Proyecto: bhavik86/Dicom
CONDITION
SRV_CGetResponse(DUL_ASSOCIATIONKEY ** association, DUL_ASSOCIATESERVICEPARAMETERS * params, DUL_PRESENTATIONCONTEXT * getPresentationCtx,
				 MSG_C_GET_REQ ** getRequest, MSG_C_GET_RESP * getResponse, SRV_C_GET_RESP_CALLBACK * getCallback, void *getCtx, char *dirName)
{
    int      		flag, responseCount = 0;
    U32				l;
    char        	queryLevelString[48] = "";	/* Initialization for AIX compiler */
    CONDITION		cond, rtnCond = SRV_NORMAL;
    DCM_OBJECT		* responseObject;	/* get response object */
    void       		*ctx;
    DCM_ELEMENT		queryLevelElement = {DCM_IDQUERYLEVEL, DCM_CS, "", 1, sizeof(queryLevelString), NULL};
    static char 	*allowedQueryLevels[] = {
							DCM_QUERYLEVELPATIENT,
							DCM_QUERYLEVELSTUDY,
							DCM_QUERYLEVELSERIES,
							DCM_QUERYLEVELIMAGE};
    MSG_STATUS_DESCRIPTION	statusDescription;
    char pendingMsg[] = "\
In SRV_CGetResponse, the response message returned by your callback has \n\
a status of pending and data set that is not null.\n";
    MSG_TYPE		messageType;
    void	       *message;
    DUL_PRESENTATIONCONTEXTID	ctxID;
    MSG_C_STORE_REQ				storeRequest;
    char				        classUID[DICOM_UI_LENGTH + 1];

    queryLevelElement.d.string = queryLevelString;

    if (getCallback == NULL) {
    	(void) MSG_Free((void **) getRequest);
    	return COND_PushCondition(SRV_NOCALLBACK, SRV_Message(SRV_NOCALLBACK), "SRV_CGetResponse");
    }
    if (getResponse->type != MSG_K_C_GET_RESP) {
    	(void) MSG_Free((void **) getRequest);
    	return COND_PushCondition(SRV_ILLEGALPARAMETER, SRV_Message(SRV_ILLEGALPARAMETER), "type", "GET Request", "SRV_CGetResponse");
    }
    (void) strcpy(classUID, (*getRequest)->classUID);

    cond = DCM_CreateObject(&getResponse->identifier, 0);
    if (cond != DCM_NORMAL)	return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CGetResponse");

    cond = SRV_ReceiveDataSet(association, getPresentationCtx, DUL_BLOCK, 0, dirName, &(*getRequest)->identifier);
    if (PRVSRV_debug && (cond == SRV_NORMAL)) (void) DCM_DumpElements(&(*getRequest)->identifier, 0);

    if (cond != SRV_NORMAL) {
    	(void) MSG_Free((void **) getRequest);
    	return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CGetResponse");
    }
    ctx = NULL;

    cond = DCM_GetElementValue(&(*getRequest)->identifier, &queryLevelElement, &l, &ctx);
    if (cond != DCM_NORMAL) {
    	(void) MSG_Free((void **) getRequest);
    	(void) COND_PushCondition(SRV_QUERYLEVELATTRIBUTEMISSING, SRV_Message(SRV_QUERYLEVELATTRIBUTEMISSING), "SRV_CGetResponse");
    	return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CGetResponse");
    }
    queryLevelString[l] = '\0';
    if (queryLevelString[l - 1] == ' ')	queryLevelString[l - 1] = '\0';

    for (flag = 0, l = 0; l < DIM_OF(allowedQueryLevels) && !flag; l++){
    	if (strcmp(queryLevelString, allowedQueryLevels[l]) == 0) flag = 1;
    }
    if (!flag) {
    	(void) MSG_Free((void **) getRequest);
    	(void) COND_PushCondition(SRV_ILLEGALQUERYLEVELATTRIBUTE, SRV_Message(SRV_ILLEGALQUERYLEVELATTRIBUTE), queryLevelString, "SRV_CGetResponse");
    	return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CGetResponse");
    }
    getResponse->messageIDRespondedTo = (*getRequest)->messageID;
    getResponse->conditionalFields = 0;
    getResponse->remainingSubOperations = 0;
    getResponse->completedSubOperations = 0;
    getResponse->failedSubOperations = 0;
    getResponse->warningSubOperations = 0;

    /*
     * Fill up the Store request and let the callback routine do the matching
     * and fill the rest of the fields
     */
    storeRequest.type = MSG_K_C_STORE_REQ;
    storeRequest.conditionalFields = 0;
    storeRequest.messageID = SRV_MessageIDOut();
    storeRequest.priority = 0;
    storeRequest.moveMessageID = (*getRequest)->messageID;

    /*
     * We invoke the callback for the first time without any StoreResponse so
     * that the callback can deal with the query and fill the Store Request
     * message and the GET response message. We also pass responseCount as 0
     * when we invoke the callback for the first time
     */
    cond = getCallback(*getRequest, getResponse, &storeRequest, NULL, 0, getPresentationCtx->abstractSyntax, queryLevelString, getCtx);
    if (cond != SRV_NORMAL) return COND_PushCondition(SRV_CALLBACKABORTEDSERVICE, SRV_Message(SRV_CALLBACKABORTEDSERVICE), "SRV_CGetRespose");

    if (storeRequest.dataSetType != DCM_CMDDATANULL) {
    	/* Send a Store Request */
    	cond = sendStoreRequest(association, params, &storeRequest);
    	if (cond != SRV_NORMAL) return COND_PushCondition(SRV_SENDFAILED, SRV_Message(SRV_SENDFAILED),"sendStoreRequest", "SRV_CGetResponse");
	}else{
		/*
		 * No images are to be transferred as the query may have been
		 * unsuccessful in the call back routine. We expect the callback
		 * routine to have supplied the appropriate values for the various
		 * fields of the getResponse message.
		 *
		 * Send the CGetResponse Message and return from the routine
		 */
		cond = MSG_BuildCommand(getResponse, &responseObject);
		if (cond != MSG_NORMAL) return COND_PushCondition(SRV_OBJECTBUILDFAILED, SRV_Message(SRV_OBJECTBUILDFAILED), "getResponse", "SRV_CGetResponse");

		cond = SRV_SendCommand(association, getPresentationCtx, &responseObject);
		if (cond != SRV_NORMAL) return COND_PushCondition(SRV_SENDFAILED, SRV_Message(SRV_SENDFAILED),"SRV_SendCommand", "SRV_CGetResponse");

		if (getResponse->dataSetType != DCM_CMDDATANULL) {
			cond = SRV_SendDataSet(association, getPresentationCtx, &getResponse->identifier, NULL, NULL, 0);
			if (cond != SRV_NORMAL) return COND_PushCondition(SRV_SENDFAILED, SRV_Message(SRV_SENDFAILED), "SRV_SendDataSet", "SRV_CGetResponse");
		}
		return SRV_NORMAL;
    }
    flag = 0;
    while (!flag) {
    	/*
    	 * Now wait for incoming Store Responses or a Cancel Request. If it
    	 * is a Store Response, invoke the callback routine, with the Store
    	 * Response. The callback will update the Get Response message
    	 * accordingly and also fill the Store Request message if any more
    	 * requests are to be made
    	 */
    	cond = SRV_ReceiveCommand(association, params, DUL_BLOCK, 0, &ctxID, NULL, &messageType, (void **) &message);
    	if (cond != SRV_NORMAL) return COND_PushCondition(SRV_RECEIVEFAILED, SRV_Message(SRV_RECEIVEFAILED), "SRV_CGetResponse");

    	switch (messageType) {
			case MSG_K_C_CANCEL_REQ:
											rtnCond = SRV_OPERATIONCANCELLED;
											getResponse->status = MSG_K_CANCEL;
											(void) MSG_Free(&message);

											cond = getCallback(*getRequest, getResponse, NULL, NULL, responseCount, getPresentationCtx->abstractSyntax, queryLevelString, getCtx);
											if (cond != SRV_NORMAL) return COND_PushCondition(SRV_CALLBACKABORTEDSERVICE, SRV_Message(SRV_CALLBACKABORTEDSERVICE), "SRV_CGetRespose");

											getResponse->messageIDRespondedTo = (*getRequest)->messageID;
											break;
			case MSG_K_C_STORE_RESP:
											responseCount++;
											getResponse->dataSetType = DCM_CMDDATANULL;
											getResponse->status = 0xffff;

											/*
											 * Fill up the Store request and let the callback routine do the
											 * matching and fill the rest of the fields
											 */
											storeRequest.type = MSG_K_C_STORE_REQ;
											storeRequest.conditionalFields = 0;
											storeRequest.messageID = SRV_MessageIDOut();
											storeRequest.priority = 0;
											storeRequest.moveMessageID = (*getRequest)->messageID;
											cond = getCallback(*getRequest, getResponse, &storeRequest, (MSG_C_STORE_RESP *) message, responseCount,
															   getPresentationCtx->abstractSyntax, queryLevelString, getCtx);
											if (cond != SRV_NORMAL)
												return COND_PushCondition(SRV_CALLBACKABORTEDSERVICE, SRV_Message(SRV_CALLBACKABORTEDSERVICE), "SRV_CGetRespose");

											if (storeRequest.dataSetType != DCM_CMDDATANULL) {
												/* make the next store request */
												cond = sendStoreRequest(association, params, &storeRequest);
												if (cond != SRV_NORMAL)
													return COND_PushCondition(SRV_SENDFAILED, SRV_Message(SRV_SENDFAILED), "sendStoreRequest", "SRV_CGetResponse");
											}
											break;
			default:
											break;
    	}

    	if (cond == SRV_NORMAL) {
    		cond = MSG_StatusLookup(getResponse->status, MSG_K_C_GET_RESP, &statusDescription);
    		if (cond != MSG_NORMAL)	return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CGetResponse");

    		if (statusDescription.statusClass != MSG_K_CLASS_PENDING) flag = 1;

    		/* Consistency check */
    		if ((statusDescription.statusClass == MSG_K_CLASS_PENDING) && (getResponse->dataSetType != DCM_CMDDATANULL)) {

    			if (PRVSRV_debug) fprintf(DEBUG_DEVICE, pendingMsg);
    			rtnCond = COND_PushCondition(SRV_SUSPICIOUSRESPONSE, SRV_Message(SRV_SUSPICIOUSRESPONSE), "C-GET", "pending", "not null", "SRV_CGetResponse");
    		}
    	}else{
    		flag = 1;
    	}

    	strcpy(getResponse->classUID, classUID);
    	getResponse->conditionalFields |= MSG_K_C_GETRESP_CLASSUID;

    	cond = MSG_BuildCommand(getResponse, &responseObject);
    	if (cond != MSG_NORMAL) {
    		(void) MSG_Free((void **) getRequest);
    		return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CGetResponse");
    	}

    	cond = SRV_SendCommand(association, getPresentationCtx, &responseObject);
    	if (cond != SRV_NORMAL) {
    		(void) MSG_Free((void **) getRequest);
    		return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CGetResponse");
    	}

    	if (getResponse->dataSetType != DCM_CMDDATANULL) {
    		cond = SRV_SendDataSet(association, getPresentationCtx, &getResponse->identifier, NULL, NULL, 0);
    		if (cond != SRV_NORMAL) {
    			(void) MSG_Free((void **) getRequest);
    			return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CGetResponse");
    		}
    	}
    }
    (void) MSG_Free((void **) getRequest);
    return rtnCond;
}
Ejemplo n.º 8
0
Archivo: get.c Proyecto: bhavik86/Dicom
CONDITION
SRV_CGetRequest(DUL_ASSOCIATIONKEY ** association, DUL_ASSOCIATESERVICEPARAMETERS * params,	MSG_C_GET_REQ * getRequest, MSG_C_GET_RESP * getResponse,
				SRV_C_GET_REQ_CALLBACK * getCallback, void *getCallbackCtx, CONDITION(*storageCallback) (), void *storageCallbackCtx, char *dirName)
{
    DCM_OBJECT					* commandObject;	/* Handle for a command object */
    CONDITION					cond;			/* Return value from function calls */
    DUL_PRESENTATIONCONTEXT		* presentationCtx,	/* Presentation context for GET service */	*storePresentationCtx;	/* for the arriving store request */
    DUL_PRESENTATIONCONTEXTID	ctxID;
    void      					*message;
    MSG_TYPE					messageType;
    CTNBOOLEAN					done = FALSE;
    U32							l;
    unsigned long        		responseCount = 0;
    MSG_C_STORE_REQ				* storeRequest;
    void       					*ctx;
    char        				queryLevelString[48] = "";	/* Initialization for AIX compiler */
    DCM_ELEMENT					queryLevelElement = {DCM_IDQUERYLEVEL, DCM_CS, "", 1, sizeof(queryLevelString), NULL};
    unsigned short		        command;
    CTNBOOLEAN					cancelled = FALSE;
    MSG_C_CANCEL_REQ			cancelRequest = {MSG_K_C_CANCEL_REQ, 0, 0, DCM_CMDDATANULL};

    queryLevelElement.d.string = queryLevelString;

    if ((getCallback == NULL) || (storageCallback == NULL))	return COND_PushCondition(SRV_NOCALLBACK, SRV_Message(SRV_NOCALLBACK), "SRV_CGetRequest");
    if (getRequest->type != MSG_K_C_GET_REQ) return COND_PushCondition(SRV_ILLEGALPARAMETER, SRV_Message(SRV_ILLEGALPARAMETER), "type", "GET Request", "SRV_CGetRequest");
    if (getRequest->dataSetType == DCM_CMDDATANULL)	return COND_PushCondition(SRV_ILLEGALPARAMETER, SRV_Message(SRV_ILLEGALPARAMETER), "dataSetType", "GET Request", "SRV_CGetRequest");

    ctx = NULL;
    cond = DCM_GetElementValue(&getRequest->identifier, &queryLevelElement, &l, &ctx);
    if (cond != DCM_NORMAL)	return COND_PushCondition(SRV_OBJECTACCESSFAILED, SRV_Message(SRV_OBJECTACCESSFAILED), "Query Identifier", "SRV_CGetRequest");

    queryLevelString[l] = '\0';
    if (queryLevelString[l - 1] == ' ')	queryLevelString[l - 1] = '\0';

    presentationCtx = SRVPRV_PresentationContext(params, getRequest->classUID);
    if (presentationCtx == NULL) return COND_PushCondition(SRV_NOSERVICEINASSOCIATION, SRV_Message(SRV_NOSERVICEINASSOCIATION), getRequest->classUID, "SRV_CGetRequest");

    cond = MSG_BuildCommand(getRequest, &commandObject);
    if (cond != MSG_NORMAL) return COND_PushCondition(SRV_OBJECTBUILDFAILED, SRV_Message(SRV_OBJECTBUILDFAILED), "GET Request", "SRV_CGetRequest");

    cond = SRV_SendCommand(association, presentationCtx, &commandObject);
    (void) DCM_CloseObject(&commandObject);
    if (cond != SRV_NORMAL) return COND_PushCondition(SRV_REQUESTFAILED, SRV_Message(SRV_REQUESTFAILED), "SRV_CGetRequest");

    cond = SRV_SendDataSet(association, presentationCtx, &getRequest->identifier, NULL, NULL, 0);
    if (cond != SRV_NORMAL)	return COND_PushCondition(SRV_REQUESTFAILED, SRV_Message(SRV_REQUESTFAILED), "SRV_CGetRequest");

    while (!done) {		/* do until there are no more pending requests */
    	cond = SRV_ReceiveCommand(association, params, DUL_BLOCK, 0, &ctxID, &command, &messageType, &message);
    	if (cond != SRV_NORMAL) return COND_PushCondition(SRV_REQUESTFAILED, SRV_Message(SRV_REQUESTFAILED), "SRV_CGetRequest");

    	switch (messageType) {
			case MSG_K_C_GET_RESP:
											cond = processGetResponse(association, presentationCtx, dirName, getRequest, (MSG_C_GET_RESP *) message,
																	  queryLevelString, getCallback, getCallbackCtx, &done, &cancelled, getResponse, &responseCount);
											(void) MSG_Free(&message);
											if ((CTN_FATAL(cond)) || (CTN_ERROR(cond)))	return cond;
											break;
			case MSG_K_C_STORE_REQ:
											storeRequest = (MSG_C_STORE_REQ *) message;
											storePresentationCtx = SRVPRV_PresentationContext(params, storeRequest->classUID);
											if (storePresentationCtx == NULL)
												return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR, SRV_Message(SRV_PRESENTATIONCONTEXTERROR), "SRV_CGetRequest");

											cond = processStoreRequest(association, storePresentationCtx, storeRequest, storageCallback, storageCallbackCtx);
											if ((CTN_FATAL(cond)) || (CTN_ERROR(cond)))	return cond;
											break;
			default:
											(void) MSG_Free(&message);
											return COND_PushCondition(SRV_UNEXPECTEDCOMMAND, SRV_Message(SRV_UNEXPECTEDCOMMAND), (int) command, "SRV_CGetRequest");
    	}
    }
    if (cancelled){
    	return SRV_OPERATIONCANCELLED;
    }else{
    	return SRV_NORMAL;
    }
}
Ejemplo n.º 9
0
CONDITION
MSG_ParseCMoveResponse(DCM_OBJECT ** object, MSG_C_MOVE_RESP * moveResponse)
{
    static MSG_C_MOVE_RESP	    response;
    static unsigned short       command, type;

    static DCM_ELEMENT elementList[] = {
    		{DCM_GROUPCOMMAND, DCM_CMDCOMMANDFIELD, DCM_US, "", 1, sizeof(command), (void *) &command},
    		{DCM_GROUPCOMMAND, DCM_CMDCLASSUID, DCM_UI, "", 1, sizeof(response.classUID), (void *) response.classUID},
    		{DCM_GROUPCOMMAND, DCM_CMDMSGIDRESPOND, DCM_US, "", 1, sizeof(response.messageIDRespondedTo), (void *) &response.messageIDRespondedTo},
    		{DCM_GROUPCOMMAND, DCM_CMDDATASETTYPE, DCM_US, "", 1, sizeof(type), (void *) &type},
    		{DCM_GROUPCOMMAND, DCM_CMDSTATUS, DCM_US, "", 1, sizeof(response.status), (void *) &response.status},
    };

    DCM_ELEMENT		e;			/* Used for conditional elements */

    static MSGPRV_CONDITIONAL conditionalList[] = {
    		{DCM_GROUPCOMMAND, DCM_CMDSUCCESSINSTANCEUIDLIST, DCM_UI, "", 1, 0, (void *) &response.successUIDs, &response.conditionalFields, MSG_K_C_MOVE_SUCCESSUID},
    		{DCM_GROUPCOMMAND, DCM_CMDFAILEDINSTANCEUIDLIST, DCM_UI, "", 1, 0, (void *) &response.failedUIDs, &response.conditionalFields, MSG_K_C_MOVE_FAILEDUID},
    		{DCM_GROUPCOMMAND, DCM_CMDWARNINGINSTANCEUIDLIST, DCM_UI, "", 1, 0, (void *) &response.warningUIDs, &response.conditionalFields, MSG_K_C_MOVE_WARNINGUID},
    		{DCM_GROUPCOMMAND, DCM_CMDREMAININGSUBOPERATIONS, DCM_US, "", 1, sizeof(response.remainingSubOperations), (void *) &response.remainingSubOperations, &response.conditionalFields, MSG_K_C_MOVE_REMAINING},
    		{DCM_GROUPCOMMAND, DCM_CMDCOMPLETEDSUBOPERATIONS, DCM_US, "", 1, sizeof(response.completedSubOperations), (void *) &response.completedSubOperations, &response.conditionalFields, MSG_K_C_MOVE_COMPLETED},
    		{DCM_GROUPCOMMAND, DCM_CMDFAILEDSUBOPERATIONS, DCM_US, "", 1, sizeof(response.failedSubOperations), (void *) &response.failedSubOperations, &response.conditionalFields, MSG_K_C_MOVE_FAILED},
    		{DCM_GROUPCOMMAND, DCM_CMDWARNINGSUBOPERATIONS, DCM_US, "", 1, sizeof(response.warningSubOperations), (void *) &response.warningSubOperations, &response.conditionalFields, MSG_K_C_MOVE_WARNING},
    };

    void		       *ctx;
    int			       index;
    unsigned long	   rtnLength;
    CONDITION		   cond;

    for (index = 0; index < (int) DIM_OF(elementList); index++) {
    	ctx = NULL;
    	cond = DCM_GetElementValue(object, &elementList[index], &rtnLength, &ctx);
    	if (cond != DCM_NORMAL) return COND_PushCondition(MSG_PARSEFAILED, MSG_Message(MSG_PARSEFAILED));
    }
    response.type = MSG_K_C_MOVE_RESP;

    for (index = 0; index < (int) DIM_OF(conditionalList); index++) {
    	cond = DCM_NORMAL;
    	e = conditionalList[index].e;
    	if (e.length == 0) {
    		cond = DCM_GetElementSize(object, DCM_MAKETAG(e.group, e.element), &rtnLength);
    		if (cond == DCM_NORMAL) {
    			e.length = rtnLength;
    			e.d.string = malloc(rtnLength + 1);
    			if (e.d.string == NULL) return 0;	/* repair */
    			*conditionalList[index].e.d.stringArray = e.d.string;
    		}else{
    			(void) COND_PopCondition(FALSE);
    		}
    	}
    	if (cond == DCM_NORMAL) {
    		ctx = NULL;
    		cond = DCM_GetElementValue(object, &e, &rtnLength, &ctx);
    		if (cond == DCM_NORMAL) {
    			*conditionalList[index].flag |= conditionalList[index].flagBit;
    			e.d.string[rtnLength] = '\0';
    		}
    	}
    }

    *moveResponse = response;
    return MSG_NORMAL;
}
Ejemplo n.º 10
0
CONDITION
HAP_ObjectToQuery(DCM_OBJECT ** object, char *SOPClass, Query * query,
		  int *elementCount)
{
    CONDITION
	cond,
	returnCondition;
    int
        index;
    void
       *ctx;
    unsigned long
        l;
    long
        flag;
    static char
        queryLevelString[48];
    DCM_ELEMENT
	queryLevelElement =
    {
	DCM_IDQUERYLEVEL, DCM_CS, "", 1,
	    sizeof(queryLevelString), (void *) queryLevelString
    };

    *elementCount = 0;
    q.QueryState = 0;
    q.Patient.Query_Flag = 0;
    q.Study.Query_Flag = 0;
    q.Series.Query_Flag = 0;
    q.Image.Query_Flag = 0;

    ctx = NULL;
    returnCondition = HAP_NORMAL;

    cond = DCM_GetElementValue(object, &queryLevelElement, &l, &ctx);
    if (cond != DCM_NORMAL) {
	if (cond == DCM_ILLEGALOBJECT)
	    return COND_PushCondition(HAP_ILLEGALOBJECT, "");
	else {
	    (void) COND_PopCondition(FALSE);
	    (void) COND_PushCondition(HAP_QUERYLEVELMISSING, "");
	    returnCondition = HAP_INCOMPLETEOBJECT;
	}
    } else {
	queryLevelString[l] = '\0';
	if (queryLevelString[l - 1] == ' ')
	    queryLevelString[l - 1] = '\0';

	for (index = 0; index < DIM_OF(levelMap); index++) {
	    if (strcmp(levelMap[index].queryLevel, queryLevelString) == 0)
		q.QueryState |= levelMap[index].flag;
	}
    }

    flag = 0;
    for (index = 0; index < DIM_OF(classMap); index++) {
	if (strcmp(classMap[index].SOPClass, SOPClass) == 0)
	    flag |= classMap[index].flag;
    }
    if (flag == 0)
	return HAP_ILLEGALSOPCLASS;

    q.QueryState |= flag;

    for (index = 0; index < (int) DIM_OF(list); index++) {
	ctx = NULL;
	cond = DCM_GetElementValue(object, &list[index].e, &l, &ctx);
	if (cond == DCM_NORMAL) {
	    (*elementCount)++;
	    list[index].e.d.string[l] = '\0';
	    *list[index].flagAddress |= list[index].flag;
	} else
	    (void) COND_PopCondition(FALSE);
    }
    *query = q;
    return returnCondition;
}