static CONDITION selectCallback(IDB_Query * queryResponse, long count, LST_HEAD * lst) { QUERY_LIST_ITEM * item; IDB_InstanceListElement * e1, *e2; item = malloc(sizeof(*item)); if (item == NULL) return 0; item->query = *queryResponse; if (queryResponse->image.InstanceList != NULL) { item->query.image.InstanceList = LST_Create(); if (item->query.image.InstanceList == NULL) return 0; e1 = LST_Head(&queryResponse->image.InstanceList); (void) LST_Position(&queryResponse->image.InstanceList, e1); while (e1 != NULL) { e2 = malloc(sizeof(*e2)); *e2 = *e1; (void) LST_Enqueue(&item->query.image.InstanceList, e2); e1 = LST_Next(&queryResponse->image.InstanceList); } } (void) LST_Enqueue(&lst, item); return IDB_NORMAL; }
CONDITION DUL_AddSinglePresentationCtx(DUL_ASSOCIATESERVICEPARAMETERS* params, DUL_SC_ROLE proposedRole, DUL_SC_ROLE acceptedRole, DUL_PRESENTATIONCONTEXTID contextID, unsigned char result, const char* abstractSyntax, const char** xferSyntaxes, int xferSyntaxCount) { LST_HEAD* lst; DUL_TRANSFERSYNTAX* transfer; DUL_PRESENTATIONCONTEXT* ctx; CONDITION cond; ctx = (DUL_PRESENTATIONCONTEXT *) CTN_MALLOC(sizeof(*ctx)); if (ctx == NULL) return COND_PushCondition(DUL_MALLOCERROR, DUL_Message(DUL_MALLOCERROR), "DUL_AddSinglePresentationCtx", sizeof(*ctx)); (void) memset(ctx, 0, sizeof(*ctx)); lst = LST_Create(); if (lst == NULL) return COND_PushCondition(DUL_LISTCREATEFAILED, DUL_Message(DUL_LISTCREATEFAILED), "DUL_AddSinglePresentationCtx"); (ctx)->presentationContextID = contextID; (ctx)->result = result; (ctx)->proposedSCRole = proposedRole; (ctx)->acceptedSCRole = acceptedRole; strcpy((ctx)->abstractSyntax, abstractSyntax); strcpy((ctx)->acceptedTransferSyntax, ""); for (; xferSyntaxCount-- > 0; xferSyntaxes++) { if (strlen(*xferSyntaxes) != 0) { transfer = CTN_MALLOC(sizeof(*transfer)); if (transfer == NULL) return COND_PushCondition(DUL_MALLOCERROR, DUL_Message(DUL_MALLOCERROR), "DUL_AddSinglePresentationCtx", sizeof(*transfer)); strcpy(transfer->transferSyntax, *xferSyntaxes); if (LST_Enqueue(&lst, transfer) != LST_NORMAL) return COND_PushCondition(DUL_LISTERROR, DUL_Message(DUL_LISTERROR), "DUL_AddSinglePresentationCtx"); } } (ctx)->proposedTransferSyntax = lst; cond = LST_Enqueue(¶ms->requestedPresentationContext,ctx); if (cond != LST_NORMAL) { return COND_PushCondition(DUL_LISTERROR, DUL_Message(DUL_LISTERROR), "DUL_AddSinglePresentationCtx"); /* Memory Leak here */ } return DUL_NORMAL; }
CONDITION SRV_RegisterSOPClassXfer(const char *SOPClass, const char* xferSyntax, DUL_SC_ROLE role, DUL_ASSOCIATESERVICEPARAMETERS * params) { DUL_PRESENTATIONCONTEXTID contextID = 1; CONDITION cond; DUL_PRESENTATIONCONTEXT* ctx; if (params->requestedPresentationContext == NULL){ params->requestedPresentationContext = LST_Create(); if (params->requestedPresentationContext == NULL) return COND_PushCondition(SRV_LISTFAILURE, SRV_Message(SRV_LISTFAILURE), "SRV_RegisterSOPClassXfer"); } ctx = LST_Head(¶ms->requestedPresentationContext); if (ctx != NULL) (void) LST_Position(¶ms->requestedPresentationContext, ctx); while (ctx != NULL) { DUL_TRANSFERSYNTAX* xferItem; contextID += 2; xferItem = (DUL_TRANSFERSYNTAX*) LST_Head(&ctx->proposedTransferSyntax); if ((strcmp(SOPClass, ctx->abstractSyntax) == 0) && (strcmp(xferSyntax, xferItem->transferSyntax) == 0) && (role == ctx->proposedSCRole)) return SRV_NORMAL; ctx = LST_Next(¶ms->requestedPresentationContext); } cond = DUL_MakePresentationCtx(&ctx, role, DUL_SC_ROLE_DEFAULT, contextID, 0, SOPClass, "", xferSyntax, NULL); if (cond != DUL_NORMAL) return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR, SRV_Message(SRV_PRESENTATIONCONTEXTERROR), "SRV_RegisterSOPClassXfer"); cond = LST_Enqueue(¶ms->requestedPresentationContext, ctx); if (cond != LST_NORMAL) return COND_PushCondition(SRV_LISTFAILURE, SRV_Message(SRV_LISTFAILURE), "SRV_RegisterSOPClassXfer"); return SRV_NORMAL; }
CONDITION SRV_RegisterSOPClass(const char *SOPClass, DUL_SC_ROLE role, DUL_ASSOCIATESERVICEPARAMETERS * params) { DUL_PRESENTATIONCONTEXTID contextID = 1; CONDITION cond; DUL_PRESENTATIONCONTEXT* ctx; if (params->requestedPresentationContext == NULL) { params->requestedPresentationContext = LST_Create(); if (params->requestedPresentationContext == NULL) return COND_PushCondition(SRV_LISTFAILURE, SRV_Message(SRV_LISTFAILURE), "SRV_RegisterSOPClass"); } ctx = LST_Head(¶ms->requestedPresentationContext); if (ctx != NULL) (void) LST_Position(¶ms->requestedPresentationContext, ctx); while (ctx != NULL) { contextID += 2; if (strcmp(SOPClass, ctx->abstractSyntax) == 0) return SRV_NORMAL; ctx = LST_Next(¶ms->requestedPresentationContext); } cond = DUL_MakePresentationCtx(&ctx, role, DUL_SC_ROLE_DEFAULT, contextID, 0, SOPClass, "", DICOM_TRANSFERLITTLEENDIAN, NULL); if (cond != DUL_NORMAL) return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR, SRV_Message(SRV_PRESENTATIONCONTEXTERROR), "SRV_RegisterSOPClass"); cond = LST_Enqueue(¶ms->requestedPresentationContext, ctx); if (cond != LST_NORMAL) return COND_PushCondition(SRV_LISTFAILURE, SRV_Message(SRV_LISTFAILURE), "SRV_RegisterSOPClass"); return SRV_NORMAL; }
void expandPatientStudy(LST_HEAD * patientList, LST_HEAD * patientStudyList) { FIS_PATIENTRECORD * p; FIS_STUDYRECORD * s; RSA_PATIENTSTUDY * ps; clearPatientStudy(patientStudyList); p = LST_Head(&patientList); if (p != NULL) (void) LST_Position(&patientList, p); while (p != NULL) { s = LST_Head(&p->StudyList); if (s != NULL) (void) LST_Position(&p->StudyList, s); while (s != NULL) { ps = malloc(sizeof(*ps)); ps->Patient = *p; ps->Study = *s; (void) LST_Enqueue(&patientStudyList, ps); s = LST_Next(&p->StudyList); } p = LST_Next(&patientList); } }
CONDITION MSG_BuildReferencedItemSequence(MSG_REFERENCED_ITEM * item, LST_HEAD ** list) { CONDITION cond; DCM_SEQUENCE_ITEM * sq; if (*list == NULL) { *list = LST_Create(); if (*list == NULL) return COND_PushCondition(MSG_LISTFAILURE, MSG_Message(MSG_LISTFAILURE), "MSG_BuildReferencedItemSequence"); } sq = CTN_MALLOC(sizeof(*sq)); if (sq == NULL) return COND_PushCondition(MSG_MALLOCFAILURE, MSG_Message(MSG_MALLOCFAILURE), sizeof(*sq), "MSG_BuildReferencedItemSequence"); cond = MSG_BuildCommand(item, &sq->object); if (cond != MSG_NORMAL) return cond; cond = LST_Enqueue(list, item); if (cond != LST_NORMAL) return COND_PushCondition(MSG_LISTFAILURE, MSG_Message(MSG_LISTFAILURE), "MSG_BuildReferencedItemSequence"); return MSG_NORMAL; }
static CONDITION commitSOPRefCallback(TBL_FIELD * field, int count, LST_HEAD * l) { FIS_COMMITSOPREFRECORD *r; CONDITION cond; int i; static FLAG_MAP map[] = { {"TraUID", FIS_K_COMMITSOP_TRAUID}, {"SOPClaUID", FIS_K_COMMITSOP_SOPCLAUID}, {"SOPInsUID", FIS_K_COMMITSOP_SOPINSUID} }; commitSOPRef.Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) commitSOPRef.Flag |= map[i].Flag; break; } } field++; } if (l != NULL) { r = malloc(sizeof(*r)); if (r == NULL) return TBL_EARLYEXIT; *r = commitSOPRef; if (LST_Enqueue(&l, r) != LST_NORMAL) return TBL_EARLYEXIT; } return TBL_NORMAL; }
static CONDITION queryCallback(MSG_C_FIND_REQ * request, MSG_C_FIND_RESP * response, int responseCount, char *SOPClass, char *queryLevel, void *p) { ITEM* item; LST_HEAD* l; if (response->status == MSG_K_SUCCESS) return SRV_NORMAL; MSG_DumpMessage(response, stdout); if (p == 0) return SRV_NORMAL; item = calloc(1, sizeof(*item)); if (item == 0) { fprintf(stderr, "Could not allocate %d bytes\n", sizeof(*item)); exit(1); } DCM_CopyObject(&response->identifier, &item->obj); l = (LST_HEAD*)p; LST_Enqueue(&l, item); return SRV_NORMAL; }
static CONDITION addSeriesRecord(DCM_OBJECT ** seriesObject, LST_HEAD ** lst) { CONDITION cond; DDR_SERIES record, *seriesPtr; DCM_ELEMENT required[] = { {DCM_IDMODALITY, DCM_CS, "", 1, sizeof(record.Modality), NULL}, {DCM_RELSERIESINSTANCEUID, DCM_UI, "", 1, sizeof(record.SeriesInstanceUID), NULL}, {DCM_RELSERIESNUMBER, DCM_IS, "", 1, sizeof(record.SeriesNumber), NULL}, {DCM_DIRLOWERLEVELOFFSET, DCM_UL, "", 1, sizeof(record.LeafLinkOffset), NULL} }; required[0].d.string = record.Modality; required[1].d.string = record.SeriesInstanceUID; required[2].d.string = record.SeriesNumber; required[3].d.ul = &record.LeafLinkOffset; memset(&record, 0, sizeof(record)); cond = DCM_ParseObject(seriesObject, required, (int) DIM_OF(required), NULL, 0, NULL); if (cond != DCM_NORMAL) { return 0; /* repair */ } seriesPtr = malloc(sizeof(*seriesPtr)); if (seriesPtr == NULL) { return 0; /* repair */ } memcpy(seriesPtr, &record, sizeof(record)); LST_Enqueue(lst, seriesPtr); return DDR_NORMAL; }
static CONDITION workQueueCallback(TBL_FIELD * field, int count, LST_HEAD * l) { FIS_WORKQUEUERECORD *r; CONDITION cond; int i; static FLAG_MAP map[] = { {"TasNam", FIS_K_WORKQUEUE_TASNAM}, {"TasID", FIS_K_WORKQUEUE_TASID} }; workQueue.Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) workQueue.Flag |= map[i].Flag; break; } } field++; } if (l != NULL) { r = malloc(sizeof(*r)); if (r == NULL) return TBL_EARLYEXIT; *r = workQueue; if (LST_Enqueue(&l, r) != LST_NORMAL) return TBL_EARLYEXIT; } return TBL_NORMAL; }
CONDITION extractGroups(LST_HEAD * src, LST_HEAD * dst) { DMAN_GROUPNAMES * s, *p; s = LST_Head(&src); if (s != NULL) (void) LST_Position(&src, s); while (s != NULL) { p = LST_Head(&dst); if (p != NULL) (void) LST_Position(&dst, p); while (p != NULL) { if (strcmp(s->GroupName, p->GroupName) == 0) break; else p = LST_Next(&dst); } if (p == NULL) { p = malloc(sizeof(*p)); if (p == NULL) return 0; *p = *s; (void) LST_Enqueue(&dst, p); } s = LST_Next(&src); } return 1; }
CONDITION UTL_ScanDirectory(const char* path, LST_HEAD** lst) { UTL_FILEITEM* item = 0; #ifdef _WIN32 long hFile = 0; struct _finddata_t fileInfo; char directoryText[1024]; *lst = LST_Create(); strcpy(directoryText, path); strcat(directoryText, "/*"); if( (hFile = _findfirst(directoryText, &fileInfo)) == -1L) return 0; item = malloc(sizeof(*item)); strcpy(item->path, fileInfo.name); LST_Enqueue(lst, item); while(_findnext(hFile, &fileInfo) == 0) { item = malloc(sizeof(*item)); strcpy(item->path, fileInfo.name); LST_Enqueue(lst, item); } _findclose(hFile); #else DIR* dirp; struct dirent* dp; *lst = LST_Create(); dirp = opendir(path); if (dirp == 0) return 0; while ((dp = readdir(dirp)) != NULL) { item = malloc(sizeof(*item)); strcpy(item->path, dp->d_name); LST_Enqueue(lst, item); } closedir(dirp); #endif return UTL_NORMAL; }
static int requestAssociation(DUL_NETWORKKEY ** network, DUL_ASSOCIATIONKEY ** association, DUL_ASSOCIATESERVICEPARAMETERS * params, char **SOPClasses, int classCount) { CONDITION cond; DUL_PRESENTATIONCONTEXT * ctx; static DUL_PRESENTATIONCONTEXTID contextID = 1; if (params->requestedPresentationContext == NULL) { params->requestedPresentationContext = LST_Create(); if (params->requestedPresentationContext == NULL) { return 0; } } while (classCount-- > 0) { ctx = malloc(sizeof(*ctx)); if (ctx == NULL) return 0; cond = DUL_MakePresentationCtx(&ctx, DUL_SC_ROLE_DEFAULT, DUL_SC_ROLE_DEFAULT, contextID, 0, *SOPClasses++, "", DICOM_TRANSFERLITTLEENDIAN, DICOM_TRANSFERLITTLEENDIANEXPLICIT, DICOM_TRANSFERBIGENDIANEXPLICIT, NULL); if (cond != DUL_NORMAL) return 0; else { cond = LST_Enqueue(¶ms->requestedPresentationContext, ctx); if (cond != LST_NORMAL) return 0; contextID += 2; } } cond = DUL_RequestAssociation(network, params, association); if (cond != DUL_NORMAL) { if (cond == DUL_ASSOCIATIONREJECTED) { fprintf(stderr, "Association Rejected\n"); fprintf(stderr, " Result: %2x Source %2x Reason %2x\n", params->result, params->resultSource, params->diagnostic); } return 0; } (void) printf("Association accepted, parameters:\n"); DUL_DumpParams(params); return 1; }
static CONDITION storageCommitCallback(TBL_FIELD * field, int count, LST_HEAD * l) { FIS_STORAGECOMMITREQRECORD *r; CONDITION cond; int i; static FLAG_MAP map[] = { {"TraUID", FIS_K_SCOMMIT_TRAUID}, {"ReqAE", FIS_K_SCOMMIT_REQAE}, {"ResAE", FIS_K_SCOMMIT_RESAE}, {"ReqDat", FIS_K_SCOMMIT_REQDAT}, {"ReqTim", FIS_K_SCOMMIT_REQTIM}, {"ResDat", FIS_K_SCOMMIT_RESDAT}, {"ResTim", FIS_K_SCOMMIT_RESTIM} }; storageCommitRequest.Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) storageCommitRequest.Flag |= map[i].Flag; break; } } field++; } if (storageCommitRequest.Flag & FIS_K_SCOMMIT_REQDAT) UTL_ConvertLongtoDate((long) commitRequestDate, storageCommitRequest.ReqDat); if (storageCommitRequest.Flag & FIS_K_SCOMMIT_REQDAT) UTL_ConvertLongtoDate((long) commitResponseDate, storageCommitRequest.ResDat); if (storageCommitRequest.Flag & FIS_K_SCOMMIT_REQTIM) UTL_ConvertFloattoTime(commitRequestTime, storageCommitRequest.ReqTim); if (storageCommitRequest.Flag & FIS_K_SCOMMIT_RESTIM) UTL_ConvertFloattoTime(commitResponseTime, storageCommitRequest.ResTim); if (l != NULL) { r = malloc(sizeof(*r)); if (r == NULL) return TBL_EARLYEXIT; *r = storageCommitRequest; if (LST_Enqueue(&l, r) != LST_NORMAL) return TBL_EARLYEXIT; } return TBL_NORMAL; }
CONDITION DUL_MakePresentationCtx(DUL_PRESENTATIONCONTEXT ** ctx, DUL_SC_ROLE proposedSCRole, DUL_SC_ROLE acceptedSCRole, DUL_PRESENTATIONCONTEXTID ctxID, unsigned char result, const char *abstractSyntax, const char *transferSyntax,...) { va_list args; LST_HEAD * lst; DUL_TRANSFERSYNTAX * transfer; #ifdef lint char __builtin_va_alist; #endif *ctx = (DUL_PRESENTATIONCONTEXT *) CTN_MALLOC(sizeof(**ctx)); if (*ctx == NULL) return COND_PushCondition(DUL_MALLOCERROR, DUL_Message(DUL_MALLOCERROR), "DUL_MakePresentationCtx", sizeof(**ctx)); (void) memset(*ctx, 0, sizeof(**ctx)); lst = LST_Create(); if (lst == NULL) return COND_PushCondition(DUL_LISTCREATEFAILED, DUL_Message(DUL_LISTCREATEFAILED), "DUL_MakePresentationCtx"); (*ctx)->presentationContextID = ctxID; (*ctx)->result = result; (*ctx)->proposedSCRole = proposedSCRole; (*ctx)->acceptedSCRole = acceptedSCRole; strcpy((*ctx)->abstractSyntax, abstractSyntax); va_start(args, transferSyntax); strcpy((*ctx)->acceptedTransferSyntax, transferSyntax); while ((transferSyntax = va_arg(args, char *)) != NULL) { if (strlen(transferSyntax) != 0) { transfer = CTN_MALLOC(sizeof(*transfer)); if (transfer == NULL) return COND_PushCondition(DUL_MALLOCERROR, DUL_Message(DUL_MALLOCERROR), "DUL_MakePresentationCtx", sizeof(*transfer)); strcpy(transfer->transferSyntax, transferSyntax); if (LST_Enqueue(&lst, transfer) != LST_NORMAL) return COND_PushCondition(DUL_LISTERROR, DUL_Message(DUL_LISTERROR), "DUL_MakePresentationCtx"); } } va_end(args); (*ctx)->proposedTransferSyntax = lst; return DUL_NORMAL; }
CONDITION IAP_InstanceArraytoElement(char *SOPArray, size_t SOPSpacing, char *UIDArray, size_t UIDSpacing, int count, DCM_ELEMENT * e) { CONDITION cond; DCM_ELEMENT classElement = { DCM_IDREFERENCEDSOPCLASSUID, DCM_UI, "", 1, 0, NULL }, uidElement = { DCM_IDREFERENCEDSOPINSTUID, DCM_UI, "", 1, 0, NULL }; DCM_OBJECT * object; DCM_SEQUENCE_ITEM * item; e->d.sq = LST_Create(); if (e->d.sq == NULL) return 0; /* repair */ while (count-- > 0) { item = malloc(sizeof(*item)); if (item == NULL) return 0; /* repair */ cond = DCM_CreateObject(&item->object); if (cond != DCM_NORMAL) return 0; /* repair */ classElement.d.string = SOPArray; classElement.length = strlen(SOPArray); cond = DCM_AddElement(&item->object, &classElement); if (cond != DCM_NORMAL) return 0; /* repair */ uidElement.d.string = UIDArray; uidElement.length = strlen(UIDArray); cond = DCM_AddElement(&item->object, &uidElement); if (cond != DCM_NORMAL) return 0; /* repair */ cond = LST_Enqueue(&e->d.sq, item); if (cond != LST_NORMAL) return 0; /* repair */ SOPArray += SOPSpacing; UIDArray += UIDSpacing; } return HAP_NORMAL; }
static CONDITION studyCallback(TBL_FIELD * field, int count, LST_HEAD * l) { FIS_STUDYRECORD * s; int i; static FLAG_MAP map[] = { {"PatUID", FIS_K_STU_PATUID}, {"StuInsUID", FIS_K_STU_STUINSUID}, {"VisUID", FIS_K_STU_VISUID}, {"AccNum", FIS_K_STU_ACCNUM}, {"StuID", FIS_K_STU_STUID}, {"SchStuStaDat", FIS_K_STU_SCHSTUSTADAT}, {"SchStuStaTim", FIS_K_STU_SCHSTUSTATIM}, {"SchStuLoc", FIS_K_STU_SCHSTULOC}, {"ProDes", FIS_K_STU_PRODES}, {"StuStaID", FIS_K_STU_STUSTAID} }; study.Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) study.Flag |= map[i].Flag; break; } } field++; } if (study.Flag & FIS_K_STU_SCHSTUSTADAT) UTL_ConvertLongtoDate((long) studyDate, study.SchStuStaDat); if (study.Flag & FIS_K_STU_SCHSTUSTATIM) UTL_ConvertFloattoTime(studyTime, study.SchStuStaTim); if (l != NULL) { s = malloc(sizeof(*s)); if (s == NULL) return TBL_EARLYEXIT; *s = study; if (LST_Enqueue(&l, s) != LST_NORMAL) return TBL_EARLYEXIT; } return TBL_NORMAL; }
static CONDITION callbackAE(TBL_FIELD * field, int count, void *ctxArg) { DMAN_APPLICATIONENTITY * ae, *localAE; CONDITION cond; int i; static FLAG_MAP map[] = { {"Title", DMAN_K_APPLICATION_TITLE}, {"Node", DMAN_K_APPLICATION_NODE}, {"Port", DMAN_K_APPLICATION_PORT}, {"Comment", DMAN_K_APPLICATION_COMMENT}, {"Organization", DMAN_K_APPLICATION_ORGANIZATION}, }; CONTEXT *ctx; ctx = (CONTEXT *) ctxArg; ae = (DMAN_APPLICATIONENTITY *) ctx->record; ae->Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) ae->Flag |= map[i].Flag; break; } } field++; } if (*ctx->lst != NULL) { localAE = malloc(sizeof(*localAE)); if (localAE == NULL) return 0; *localAE = *ae; cond = LST_Enqueue(ctx->lst, localAE); if (cond != LST_NORMAL) return 0; } return TBL_NORMAL; }
static void groupCallback(unsigned short group, char *description, void *ctx) { DCM_ELEMENT_NODE *n; LST_HEAD **l; l = (LST_HEAD **) ctx; n = calloc(1, sizeof(*n)); if (n == NULL) return; n->e.tag = DCM_MAKETAG(group, 0); strcpy(n->e.description, description); (void) LST_Enqueue(l, n); }
static CONDITION callbackFA(TBL_FIELD * field, int count, void *ctxArg) { DMAN_FISACCESS * sa, *localSA; CONDITION cond; int i; static FLAG_MAP map[] = { {"Title", DMAN_K_FISACCESS_TITLE}, {"DbKey", DMAN_K_FISACCESS_DBKEY}, {"Owner", DMAN_K_FISACCESS_OWNER}, {"GroupName", DMAN_K_FISACCESS_GROUPNAME}, {"Comment", DMAN_K_FISACCESS_COMMENT} }; CONTEXT *ctx; ctx = (CONTEXT *) ctxArg; sa = (DMAN_FISACCESS *) ctx->record; sa->Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) sa->Flag |= map[i].Flag; break; } } field++; } if (*ctx->lst != NULL) { localSA = malloc(sizeof(*localSA)); if (localSA == NULL) return 0; *localSA = *sa; cond = LST_Enqueue(ctx->lst, localSA); if (cond != LST_NORMAL) return 0; } return TBL_NORMAL; }
static CONDITION callbackStorageControl(TBL_FIELD * field, int count, void *ctxArg) { DMAN_STORAGECONTROL * s, *localStorage; CONDITION cond; int i; static FLAG_MAP map[] = { {"RequestingTitle", DMAN_K_STORAGECONTROL_REQUESTING}, {"RespondingTitle", DMAN_K_STORAGECONTROL_RESPONDING}, {"Medium", DMAN_K_STORAGECONTROL_MEDIUM}, {"Root", DMAN_K_STORAGECONTROL_ROOT} }; CONTEXT *ctx; ctx = (CONTEXT *) ctxArg; s = (DMAN_STORAGECONTROL *) ctx->record; s->Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) s->Flag |= map[i].Flag; break; } } field++; } if (*ctx->lst != NULL) { localStorage = malloc(sizeof(*localStorage)); if (localStorage == NULL) return 0; *localStorage = *s; cond = LST_Enqueue(ctx->lst, localStorage); if (cond != LST_NORMAL) return 0; } return TBL_NORMAL; }
CONDITION UTL_ReadConfigFile( ) { FILE* f; char buf[1024]; if (UTL_configList != 0) return UTL_NORMAL; UTL_configList = LST_Create(); if (UTL_configList == NULL) return 0; if (UTL_configFile == 0) return UTL_NORMAL; if (UTL_configFile[0] == '\0') return UTL_NORMAL; f = fopen(UTL_configFile, "r"); if (f == NULL) return 0; while (fgets(buf, sizeof(buf), f) != NULL) { char* token1; char* token2; CONFIG_ITEM* item; if (buf[0] == '#') continue; if (buf[0] == '\n') continue; token1 = strtok(buf, " \t\n"); token2 = strtok(0, " \t\n"); if (token2 == NULL) continue; item = (CONFIG_ITEM*)malloc(sizeof(*item) + strlen(token1) + strlen(token2) + 2); item->pName = ((char*)item) + sizeof(*item); strcpy(item->pName, token1); item->pValue = item->pName + strlen(token1) + 1; strcpy(item->pValue, token2); LST_Enqueue(&UTL_configList, item); } fclose(f); return UTL_NORMAL; }
static CONDITION interpretationCallback(TBL_FIELD * field, int count, LST_HEAD * l) { FIS_INTERPRETATIONRECORD *r; CONDITION cond; int i; static FLAG_MAP map[] = { {"IntUID", FIS_K_INTERP_INTUID}, {"ResUID", FIS_K_INTERP_RESUID}, {"IntID", FIS_K_INTERP_INTID}, {"IntTex", FIS_K_INTERP_INTTEX}, {"IntDiaDes", FIS_K_INTERP_INTDIADES}, {"IntTypID", FIS_K_INTERP_INTTYPID}, {"IntStaID", FIS_K_INTERP_INTSTAID}, {"InsCreDat", FIS_K_INTERP_INSCREDAT}, {"InsCreTim", FIS_K_INTERP_INSCRETIM}, {"InsCreUID", FIS_K_INTERP_INSCREUID}, {"PhyAppInt", FIS_K_INTERP_PHYAPPINT}, {"IntAppDat", FIS_K_INTERP_INTAPPDAT}, {"IntAppTim", FIS_K_INTERP_INTAPPTIM} }; interpretation.Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) interpretation.Flag |= map[i].Flag; break; } } field++; } if (l != NULL) { r = malloc(sizeof(*r)); if (r == NULL) return TBL_EARLYEXIT; *r = interpretation; if (LST_Enqueue(&l, r) != LST_NORMAL) return TBL_EARLYEXIT; } return TBL_NORMAL; }
static void elementCallback(DCM_TAG tag, char *description, DCM_VALUEREPRESENTATION representation, void *ctx) { DCM_ELEMENT_NODE *n; LST_HEAD **l; l = (LST_HEAD **) ctx; n = calloc(1, sizeof(*n)); if (n == NULL) return; n->e.tag = tag; strcpy(n->e.description, description); n->e.representation = representation; (void) LST_Enqueue(l, n); }
/* ICON_GetStudyIconLst ** ** Purpose: ** Reads the file and returns a list of STUDYICON records corresponding ** to a study identified by an accession number. ** ** Parameter Dictionary: ** file Pathname of the file. ** studyiconlist List of STUDYICON records. ** ** Return Values: ** ICON_NORMAL Sucess ** ICON_FILEOPENFAILED Failed to open file. ** ICON_LISTFAILURE Failed to create/enqueue list. ** ICON_OFFSETERROR Failed to search file. ** ICON_MALLOCFAILURE Failed to malloc memory space. ** ICON_INCORRECTFILESIZE Failed to parse file properly. ** ** Notes: ** ** Algorithm: ** Description of the algorithm (optional) and any other notes. */ CONDITION ICON_GetStudyIconLst(char *file, ICON_STUDYOFFSET * studyoffset, LST_HEAD ** studyiconlist) { int fd, fdcond; LIST_ICON_STUDYICON * listitem; ICON_STUDYICON temp; CONDITION cond; fd = open(file, O_RDONLY); if (fd < 0) return COND_PushCondition(ICON_FILEOPENFAILED, ICON_Message(ICON_FILEOPENFAILED), file, "ICON_GetStudyIconLst"); *studyiconlist = LST_Create(); if (*studyiconlist == NULL) return COND_PushCondition(ICON_LISTFAILURE, ICON_Message(ICON_LISTFAILURE), "ICON_GetStudyIconLst"); if (lseek(fd, studyoffset->Offset, SEEK_SET) < 0) return COND_PushCondition(ICON_OFFSETERROR, ICON_Message(ICON_OFFSETERROR), "ICON_GetStudyIconLst"); while (((fdcond = read(fd, (char *) &temp, sizeof(ICON_STUDYICON))) == sizeof(ICON_STUDYICON)) && (!strcmp(temp.accessionNumber, studyoffset->accessionNumber))) { listitem = (LIST_ICON_STUDYICON *) malloc(sizeof(LIST_ICON_STUDYICON)); if (listitem == NULL) return COND_PushCondition(ICON_MALLOCFAILURE, ICON_Message(ICON_MALLOCFAILURE), "ICON_GetStudyIconLst"); listitem->studyicon = temp; cond = LST_Enqueue(studyiconlist, listitem); if (cond != LST_NORMAL) return COND_PushCondition(ICON_LISTFAILURE, ICON_Message(ICON_LISTFAILURE), "ICON_GetStudyIconLst"); } if ((fdcond != sizeof(ICON_STUDYICON)) && (fdcond != 0)) return COND_PushCondition(ICON_INCORRECTFILESIZE, ICON_Message(ICON_INCORRECTFILESIZE), "ICON_GetStudyIconLst"); close(fd); return (ICON_NORMAL); }
static CONDITION callbackGroup(TBL_FIELD * field, int count, void *ctxArg) { DMAN_GROUPNAMES * g, *localGroup; CONDITION cond; int i; static FLAG_MAP map[] = { {"Title", DMAN_K_GROUP_TITLE}, {"GroupName", DMAN_K_GROUP_GROUP}, }; CONTEXT *ctx; ctx = (CONTEXT *) ctxArg; g = (DMAN_GROUPNAMES *) ctx->record; g->Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) g->Flag |= map[i].Flag; break; } } field++; } if (*ctx->lst != NULL) { localGroup = malloc(sizeof(*localGroup)); if (localGroup == NULL) return 0; *localGroup = *g; cond = LST_Enqueue(ctx->lst, localGroup); if (cond != LST_NORMAL) return 0; } return TBL_NORMAL; }
static CONDITION studyComponentCallback(TBL_FIELD * field, int count, LST_HEAD * l) { FIS_STUDYCOMPONENTRECORD * s; int i; static FLAG_MAP map[] = { {"StuComUID", FIS_K_STUDYCOMP_STUCOMUID}, {"StuInsUID", FIS_K_STUDYCOMP_STUINSUID}, {"Mod", FIS_K_STUDYCOMP_MOD}, {"StuDes", FIS_K_STUDYCOMP_STUDES}, {"ProCodVal", FIS_K_STUDYCOMP_PROCODVAL}, {"ProCodSch", FIS_K_STUDYCOMP_PROCODSCHDES}, {"ProCodMea", FIS_K_STUDYCOMP_PROCODMEA}, {"StuComStaID", FIS_K_STUDYCOMP_STUCOMSTAID}, {"StuID", FIS_K_STUDYCOMP_STUID}, }; studyComponent.Flag = 0; while (field->FieldName != NULL) { for (i = 0; i < (int) DIM_OF(map); i++) { if (strcmp(field->FieldName, map[i].FieldName) == 0) { if (!field->Value.IsNull) studyComponent.Flag |= map[i].Flag; break; } } field++; } if (l != NULL) { s = malloc(sizeof(*s)); if (s == NULL) return TBL_EARLYEXIT; *s = studyComponent; if (LST_Enqueue(&l, s) != LST_NORMAL) return TBL_EARLYEXIT; } return TBL_NORMAL; }
static CONDITION addStudyRecord(DCM_OBJECT ** studyObject, LST_HEAD ** lst) { CONDITION cond; DDR_STUDY record, *studyPtr; DCM_ELEMENT required[] = { {DCM_IDSTUDYDATE, DCM_DA, "", 1, sizeof(record.StudyDate), NULL}, {DCM_IDSTUDYTIME, DCM_TM, "", 1, sizeof(record.StudyTime), NULL}, {DCM_IDSTUDYDESCRIPTION, DCM_LO, "", 1, sizeof(record.StudyDescription), NULL}, {DCM_RELSTUDYINSTANCEUID, DCM_UI, "", 1, sizeof(record.StudyInstanceUID), NULL}, {DCM_RELSTUDYID, DCM_SH, "", 1, sizeof(record.StudyID), NULL}, {DCM_IDACCESSIONNUMBER, DCM_SH, "", 1, sizeof(record.AccessionNumber), NULL}, {DCM_DIRLOWERLEVELOFFSET, DCM_UL, "", 1, sizeof(record.SeriesLinkOffset), NULL} }; required[0].d.string = record.StudyDate; required[1].d.string = record.StudyTime; required[2].d.string = record.StudyDescription; required[3].d.string = record.StudyInstanceUID; required[4].d.string = record.StudyID; required[5].d.string = record.AccessionNumber; required[6].d.ul = &record.SeriesLinkOffset; memset(&record, 0, sizeof(record)); cond = DCM_ParseObject(studyObject, required, (int) DIM_OF(required), NULL, 0, NULL); if (cond != DCM_NORMAL) { return 0; /* repair */ } studyPtr = malloc(sizeof(*studyPtr)); if (studyPtr == NULL) { return 0; /* repair */ } memcpy(studyPtr, &record, sizeof(record)); LST_Enqueue(lst, studyPtr); return DDR_NORMAL; }
static CONDITION addLeafRecord(DCM_OBJECT ** leafObject, LST_HEAD ** lst) { CONDITION cond; DDR_SERIES_LEAF record, *leafPtr; DCM_ELEMENT required[] = { {DCM_DIRRECORDTYPE, DCM_CS, "", 1, sizeof(record.RecordType), NULL}, {DCM_DIRREFERENCEDFILEID, DCM_CS, "", 1, sizeof(record.FileID), NULL}, {DCM_DIRREFSOPCLASSUID, DCM_UI, "", 1, sizeof(record.SOPClassUID), NULL}, {DCM_DIRREFSOPINSTANCEUID, DCM_UI, "", 1, sizeof(record.SOPInstanceUID), NULL}, {DCM_DIRREFTRANSFERSYNTAXUID, DCM_UI, "", 1, sizeof(record.TransferSyntaxUID), NULL} }; required[0].d.string = record.RecordType; required[1].d.string = record.FileID; required[2].d.string = record.SOPClassUID; required[3].d.string = record.SOPInstanceUID; required[4].d.string = record.TransferSyntaxUID; memset(&record, 0, sizeof(record)); cond = DCM_ParseObject(leafObject, required, (int) DIM_OF(required), NULL, 0, NULL); if (cond != DCM_NORMAL) { return 0; /* repair */ } if (strcmp(record.RecordType, "IMAGE") == 0) addImageLeafAttributes(leafObject, &record); leafPtr = malloc(sizeof(*leafPtr)); if (leafPtr == NULL) { return 0; /* repair */ } memcpy(leafPtr, &record, sizeof(record)); LST_Enqueue(lst, leafPtr); return DDR_NORMAL; }
CONDITION SRV_RejectServiceClass(DUL_PRESENTATIONCONTEXT * requestedCtx, unsigned short result, DUL_ASSOCIATESERVICEPARAMETERS * params) { CONDITION cond; DUL_PRESENTATIONCONTEXT * ctx; if (params->acceptedPresentationContext == NULL) { params->acceptedPresentationContext = LST_Create(); if (params->acceptedPresentationContext == NULL) return COND_PushCondition(SRV_LISTFAILURE, SRV_Message(SRV_LISTFAILURE), "SRV_RejectServiceClass"); } cond = DUL_MakePresentationCtx(&ctx, requestedCtx->proposedSCRole, DUL_SC_ROLE_DEFAULT, requestedCtx->presentationContextID, (unsigned char)result, requestedCtx->abstractSyntax, DICOM_TRANSFERLITTLEENDIAN, DICOM_TRANSFERLITTLEENDIAN, NULL); if (cond != DUL_NORMAL) return COND_PushCondition(SRV_PRESENTATIONCONTEXTERROR, SRV_Message(SRV_PRESENTATIONCONTEXTERROR), "SRV_RejectServiceClass"); cond = LST_Enqueue(¶ms->acceptedPresentationContext, ctx); if (cond != LST_NORMAL) return COND_PushCondition(SRV_LISTFAILURE, SRV_Message(SRV_LISTFAILURE), "SRV_RejectServiceClass"); return SRV_NORMAL; }