static DUL_TRANSFERSYNTAX* matchProposedXferSyntax(DUL_PRESENTATIONCONTEXT* requestedCtx, const char* prefix, char** xferSyntaxes, int xferSyntaxCount) { char** xferSyntaxesLocal = 0; DUL_TRANSFERSYNTAX* transfer; int found = 0; int idx; if (xferSyntaxCount == 0) { char* paramValue; char paramName[1024] = ""; strcpy(paramName, prefix); strcat(paramName, "/"); strcat(paramName, requestedCtx->abstractSyntax); paramValue = UTL_GetConfigParameter(paramName); if (paramValue == NULL) paramValue = DICOM_TRANSFERLITTLEENDIAN; xferSyntaxesLocal = UTL_ExpandToPointerArray(paramValue, ";", &xferSyntaxCount); }else{ xferSyntaxesLocal = xferSyntaxes; } for (idx = 0; (idx < xferSyntaxCount) && !found; idx++) { transfer = (DUL_TRANSFERSYNTAX*)LST_Head(&requestedCtx->proposedTransferSyntax); (void) LST_Position(&requestedCtx->proposedTransferSyntax, transfer); while (transfer != NULL) { if (strcmp(transfer->transferSyntax, xferSyntaxesLocal[idx]) == 0) { found = 1; break; }else{ transfer = LST_Next(&requestedCtx->proposedTransferSyntax); } } } if (xferSyntaxesLocal != xferSyntaxes) CTN_FREE(xferSyntaxesLocal); return transfer; }
char* UTL_GetConfigParameter(const char* paramName) { CONDITION cond; char nameCopy[256]; CONFIG_ITEM* item; int idx; cond = UTL_ReadConfigFile( ); if (cond != UTL_NORMAL) return NULL; item = LST_Head(&UTL_configList); if (item == NULL) return NULL; (void) LST_Position(&UTL_configList, item); while(item != NULL) { if (strcmp(item->pName, paramName) == 0) return item->pValue; item = LST_Next(&UTL_configList); } strcpy(nameCopy, paramName); idx = strlen(nameCopy) - 1; while (idx > 0) { if (nameCopy[idx] == '/') { nameCopy[idx] = '\0'; idx = -1; break; } else { idx--; } } if (idx < 0) { return UTL_GetConfigParameter(nameCopy); } else { return NULL; } }
static DUL_TRANSFERSYNTAX* matchProposedXferSyntax(DUL_PRESENTATIONCONTEXT* requestedCtx, const char* prefix, char** xferSyntaxes, int xferSyntaxCount) { char** xferSyntaxesLocal = 0; int singleMode = 0; DUL_TRANSFERSYNTAX* transfer; int found = 0; int idx; if (xferSyntaxCount == 0) { char* paramValue; char paramName[1024] = ""; strcpy(paramName, prefix); strcat(paramName, "/"); strcat(paramName, requestedCtx->abstractSyntax); paramValue = UTL_GetConfigParameter(paramName); if (paramValue == NULL) paramValue = DICOM_TRANSFERLITTLEENDIAN; xferSyntaxesLocal = UTL_ExpandToPointerArray(paramValue, ";", &xferSyntaxCount); } else { xferSyntaxesLocal = xferSyntaxes; } for (idx = 0; (idx < xferSyntaxCount) && !found; idx++) { transfer = (DUL_TRANSFERSYNTAX*)LST_Head(&requestedCtx->proposedTransferSyntax); (void) LST_Position(&requestedCtx->proposedTransferSyntax, transfer); while (transfer != NULL) { // COND_PushCondition(0, "%s %s", transfer->transferSyntax, xferSyntaxesLocal[idx]); /*repair*/ if (strcmp(transfer->transferSyntax, xferSyntaxesLocal[idx]) == 0) { found = 1; break; } else transfer = LST_Next(&requestedCtx->proposedTransferSyntax); } } if (!found) { DUL_TRANSFERSYNTAX* x; x = (DUL_TRANSFERSYNTAX*)LST_Head(&requestedCtx->proposedTransferSyntax); (void)LST_Position(&requestedCtx->proposedTransferSyntax, x); while (x != NULL) { COND_PushCondition(SRV_REQUESTEDXFER, "SRV REQUESTED transfer syntax: %s", x->transferSyntax); x = (DUL_TRANSFERSYNTAX*)LST_Next(&requestedCtx->proposedTransferSyntax); } for (idx = 0; (idx < xferSyntaxCount) && !found; idx++) { COND_PushCondition(SRV_SUPPORTEDXFER, "SRV Supported transfer syntax: %s", xferSyntaxesLocal[idx]); } transfer = 0; } if (xferSyntaxesLocal != xferSyntaxes) { CTN_FREE(xferSyntaxesLocal); } return transfer; }
CONDITION SRV_CStoreResponse(DUL_ASSOCIATIONKEY ** association, DUL_PRESENTATIONCONTEXT * ctx, MSG_C_STORE_REQ ** storeRequest, MSG_C_STORE_RESP * storeReply, char *fileName, SRV_C_STORE_RESP_CALLBACK * callback, void *callbackCtx, char *dirName) { int fd, done; unsigned long total, estimatedSize, nextCallback; unsigned short sendStatus = 0x0000; DUL_PDV pdv; CONDITION cond; DCM_OBJECT * object; DCM_FILE_META fileMeta; int storeAsPart10 = 0; char* paramValue; storeReply->messageIDRespondedTo = (*storeRequest)->messageID; storeReply->type = MSG_K_C_STORE_RESP; (void) strcpy(storeReply->classUID, (*storeRequest)->classUID); (void) strcpy(storeReply->instanceUID, (*storeRequest)->instanceUID); storeReply->conditionalFields = MSG_K_C_STORERESP_CLASSUID | MSG_K_C_STORERESP_INSTANCEUID; storeReply->dataSetType = DCM_CMDDATANULL; if (strlen(fileName) == 0 || fileName == NULL) { fd = -1; }else{ #ifdef _MSC_VER fd = _open(fileName, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, _S_IREAD | _S_IWRITE); #else fd = open(fileName, O_CREAT | O_WRONLY | O_TRUNC, 0666); #endif if (fd < 0) (void) COND_PushCondition(SRV_FILECREATEFAILED, SRV_Message(SRV_FILECREATEFAILED), fileName, "SRV_CStoreResponse"); } if (strcmp(ctx->acceptedTransferSyntax, DICOM_TRANSFERLITTLEENDIAN) != 0){ storeAsPart10 = 1; }else{ paramValue = UTL_GetConfigParameter("STORAGE/PART10FLAG"); if (paramValue != NULL) { if (strcmp(paramValue, "1") == 0) storeAsPart10 = 1; } } if ((storeAsPart10 == 1) && (fd > 0)){ int localStatus = 0; memset(&fileMeta, 0, sizeof(fileMeta)); setFileMeta(&fileMeta, *storeRequest, ctx->acceptedTransferSyntax); localStatus = writePart10MetaHeader(fd, &fileMeta); if (localStatus != 0) fd = -1; } if (fd < 0) { sendStatus = MSG_K_C_STORE_OUTOFRESOURCES; storeReply->conditionalFields |= MSG_K_C_STORERESP_ERRORCOMMENT; strcpy(storeReply->errorComment, "Storage Service unable to create local file"); fprintf(stderr,"Storage Service unable to create local file\n"); } done = 0; total = 0; estimatedSize = genericImageSize((*storeRequest)->classUID); nextCallback = estimatedSize / 10; while (!done) { cond = SRVPRV_ReadNextPDV(association, DUL_BLOCK, 0, &pdv); if (cond != SRV_NORMAL) { (void) MSG_Free((void **) storeRequest); return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CStoreResponse"); } if (pdv.pdvType != DUL_DATASETPDV) { (void) MSG_Free((void **) storeRequest); return COND_PushCondition(SRV_UNEXPECTEDPDVTYPE, SRV_Message(SRV_UNEXPECTEDPDVTYPE), (int) pdv.pdvType, "SRV_CStoreResponse"); } if (sendStatus == 0) if (write(fd, pdv.data, pdv.fragmentLength) != (int) pdv.fragmentLength) sendStatus = MSG_K_C_STORE_OUTOFRESOURCES; total += pdv.fragmentLength; if (pdv.lastPDV) done++; if (total > nextCallback){ cond = callback(*storeRequest, NULL, total, estimatedSize, NULL, callbackCtx, ctx); if (cond != SRV_NORMAL){ (void) MSG_Free((void **) storeRequest); return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CStoreResponse"); } nextCallback += estimatedSize / 10; } } if (fd >= 0) (void) close(fd); storeReply->status = sendStatus; if (sendStatus == 0x0000) { unsigned long options = DCM_ORDERLITTLEENDIAN; if (storeAsPart10 == 1) options = DCM_PART10FILE; cond = DCM_OpenFile(fileName, options, &object); if (cond != DCM_NORMAL) { (void) MSG_Free((void **) storeRequest); return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CStoreResponse"); } cond = callback(*storeRequest, storeReply, total, estimatedSize, &object, callbackCtx, ctx); if (cond != SRV_NORMAL) { (void) DCM_CloseObject(&object); return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CStoreResponse"); } (void) DCM_CloseObject(&object); } (void) MSG_Free((void **) storeRequest); cond = MSG_BuildCommand(storeReply, &object); if (cond != MSG_NORMAL) return COND_PushCondition(SRV_OBJECTBUILDFAILED, SRV_Message(SRV_OBJECTBUILDFAILED), "STORE Request", "SRV_CStoreResponse"); cond = SRV_SendCommand(association, ctx, &object); (void) DCM_CloseObject(&object); if (cond != SRV_NORMAL) return COND_PushCondition(SRV_RESPONSEFAILED, SRV_Message(SRV_RESPONSEFAILED), "SRV_CStoreResponse"); return SRV_NORMAL; }