int main(int argc, char *argv[]) { int iconfilesize; char *iconindex, *iconfile, *imagefile; char *accessionNumber; CONDITION cond; ICON_STUDYOFFSET studyoffset; while (--argc > 0 && (*++argv)[0] == '-') { switch (*(argv[0] + 1)) { case 'v': verbose = TRUE; break; default: break; } } DCM_Debug(verbose); if (argc != 3) { printf("Usage: append_icon_index ICONCindex ICONfile imagefilei\n"); return (0); } THR_Init(); iconindex = strdup(argv[0]); iconfile = strdup(argv[1]); imagefile = strdup(argv[2]); iconfilesize = getFileSize(iconfile); if (iconfilesize < 0) { THR_Shutdown(); return (1); } printf("Size of %s is %d\n", iconfile, iconfilesize); accessionNumber = extractAccessionNumber(imagefile); if (accessionNumber == NULL) { THR_Shutdown(); return (1); } printf("Accession Number = %s\n", accessionNumber); strcpy(studyoffset.accessionNumber, accessionNumber); studyoffset.Offset = iconfilesize; cond = ICON_AppendStudyOffset(iconindex, &studyoffset); if (cond != ICON_NORMAL) { printf("ICON_AppendStudyOffset failed\n"); if (verbose == TRUE) COND_DumpConditions(); THR_Shutdown(); return (1); } (void) ICON_DumpStudyOffset(iconindex); THR_Shutdown(); return 0; }
main(int argc, char **argv) { DCM_OBJECT * object; CONDITION cond; char * fileInput; CTNBOOLEAN verbose = FALSE, exitFlag = FALSE, formatFlag = FALSE; unsigned long options = DCM_ORDERLITTLEENDIAN; long vmLimit = 0; LST_HEAD* fileNames = 0; UTL_FILEITEM* p = NULL; if (argc < 2) usageerror(); else { argv++; fileInput = *argv; } THR_Init(); DCM_Debug(verbose); cond = DCM_OpenFile(fileInput, options, &object); if (cond != DCM_NORMAL && ((options & DCM_PART10FILE) == 0)) { COND_DumpConditions(); (void) DCM_CloseObject(&object); (void) COND_PopCondition(TRUE); fprintf(stderr, "Could not open %s as expected. Trying Part 10 format.\n", p->path); cond = DCM_OpenFile(p->path, options | DCM_PART10FILE, &object); } if (cond == DCM_NORMAL) { printf("<?xml version=\"1.0\" ?>\n"); printf("<Structured_Report>\n"); iterateThroughElements(&object, 1); printf("</Structured_Report>\n"); } COND_DumpConditions(); (void) DCM_CloseObject(&object); (void) COND_PopCondition(TRUE); if (cond != DCM_NORMAL && exitFlag) { THR_Shutdown(); exit(1); } #ifdef MALLOC_DEBUG malloc_verify(0); malloc_shutdown(); #endif THR_Shutdown(); return 0; }
int main(int argc, char **argv) { CONDITION cond; /* Return value from DUL and ACR routines */ DCM_OBJECT * object; /* Handle to the information object */ DCM_ELEMENT element; /* Handle to the DCM_ELEMENT */ IE_OBJECT * ieObject; /* Handle to the IE_OBJECT object */ IE_INFORMATIONENTITY * ieIE, *ie_node; /* Handle to IE_INFORMATIONENTITY */ LST_HEAD * ie_head, *mod_head, *attr_head; /* Handle to the LST_HEAD */ IE_MODULE * ieModule, *mod_node; /* Handle to IE_MODULE */ IE_ATTRIBUTE * attr_node; /* Handle to IE_ATTRIBUTE */ CTNBOOLEAN verbose = FALSE; /* For debugging purpose */ CTNBOOLEAN flag; /* Return value from findElement routine */ unsigned long options = DCM_ORDERLITTLEENDIAN; /* Byte order in data streams */ char *file; /* The image file name */ char UID[90]; /* The SOP Class UID of the image file */ U32 length; /* Length of the data field of DCM_ELEMENT */ int ie_loop, mod_loop, attr_loop, j, k, i;/* Iteration variables */ while (--argc > 0 && (*++argv)[0] == '-') { switch (*(argv[0] + 1)) { case 'v': verbose = TRUE; break; case 'b': options &= ~DCM_ORDERMASK; options |= DCM_ORDERBIGENDIAN; break; case 't': options &= ~DCM_FILEFORMATMASK; options |= DCM_PART10FILE; break; default: break; } } if (argc < 1) usageerror(); file = *argv; THR_Init(); DCM_Debug(verbose); /* Open a DICOM object file and put the contents into the memory represented by the information object. */ cond = DCM_OpenFile(file, options, &object); if (cond != DCM_NORMAL && ((options & DCM_PART10FILE) == 0)) { COND_DumpConditions(); (void) DCM_CloseObject(&object); (void) COND_PopCondition(TRUE); fprintf(stderr, "Could not open %s as expected. Trying Part 10 format.\n", file); cond = DCM_OpenFile(file, options | DCM_PART10FILE, &object); } if (cond != DCM_NORMAL) { COND_DumpConditions(); THR_Shutdown(); return 1; }else{ printf("file is successfully opened!\n"); /* Call IE_ExamineObject to examine this DCM object. */ cond = IE_ExamineObject(&object, &ieObject); if (cond == IE_ILLEGALDCMOBJECT || cond == IE_LISTFAILURE || cond == IE_MALLOCFAILURE){ COND_DumpConditions(); }else{ /* Print the IE_OBJECT object. */ strcpy(UID, ieObject->classUID); printObject(ieObject); /* Examine each IE on the list. */ ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { ie_node = LST_Pop(&ie_head); cond = IE_ExamineInformationEntity(&object, ie_node->ieType, &ieIE); /* Print each IE_IE. */ printIE(ieIE); /* Examine each module on the list. */ mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); cond = IE_ExamineModule(&object, ieIE->ieType, mod_node->moduleType, &ieModule); printModule(ieModule); /* Print each IE_ATTRIBUTE. */ attr_head = ieModule->attributeList; attr_loop = LST_Count(&attr_head); for (j = 0; j < attr_loop; j++) { attr_node = LST_Pop(&attr_head); printIEAttribute(attr_node); free(attr_node); } free(mod_node); cond = IE_Free((void **) &ieModule); } free(ie_node); cond = IE_Free((void **) &ieIE); } cond = IE_Free((void **) &ieObject); /* Check to see the status of the Information Entities. */ cond = IE_ExamineObject(&object, &ieObject); printf("\n%s requirements:\n", ieObject->objectDescription); ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { ie_node = LST_Pop(&ie_head); if (ie_node->requirement == IE_K_REQUIRED) printIE(ie_node); free(ie_node); } cond = IE_Free((void **) &ieObject); /* Check to see the status of the Information Entity and status of the Modules within them. */ cond = IE_ExamineObject(&object, &ieObject); printf("\n%s requirements:\n", ieObject->objectDescription); ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { ie_node = LST_Pop(&ie_head); cond = IE_ExamineInformationEntity(&object, ie_node->ieType, &ieIE); if (ie_node->requirement == IE_K_REQUIRED) { printf("\n"); printIE(ieIE); mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); if (mod_node->requirement == IE_K_REQUIRED) printModule(mod_node); free(mod_node); } } free(ie_node); cond = IE_Free((void **) &ieIE); } cond = IE_Free((void **) &ieObject); /* Check to see the missing attributes if there is any. */ cond = IE_ObjectRequirements(UID, &ieObject); printf("\n Missing required(type1 and type2) attributes: \n"); ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { ie_node = LST_Pop(&ie_head); cond = IE_IERequirements(UID, ie_node->ieType, &ieIE); mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); cond = IE_ModuleRequirements(UID, ie_node->ieType, mod_node->moduleType, &ieModule); printf(" %s\n", ieModule->moduleDescription); attr_head = ieModule->attributeList; attr_loop = LST_Count(&attr_head); for (j = 0; j < attr_loop; j++) { attr_node = LST_Pop(&attr_head); flag = findElement(object, attr_node->element.tag, &element); cond = DCM_LookupElement(&element); if (cond != DCM_NORMAL) cond = COND_PopCondition(FALSE); if (!flag) { if (attr_node->requirement == IE_K_TYPE1){ printf(" %08x, %s\n", element.tag, element.description); }else if (attr_node->requirement == IE_K_TYPE2){ cond = DCM_GetElementSize(&object, attr_node->element.tag, &length); if (cond != DCM_NORMAL){ cond = COND_PopCondition(FALSE); printf(" %08x, %s\n", element.tag, element.description); } } } } /* finish one module */ free(mod_node); cond = IE_Free((void **) &ieModule); } free(ie_node); cond = IE_Free((void **) &ieIE); } cond = IE_Free((void **) &ieObject); } } /* Free the memory and remove the object handle. */ cond = DCM_CloseObject(&object); if (cond != DCM_NORMAL){ COND_DumpConditions(); }else{ printf("The object is closed successfully.\n"); } THR_Shutdown(); return 0; }
int main(int argc, char **argv) { CONDITION /* Return value from DUL and ACR routines */ cond; IE_OBJECT /* Handle to the IE_OBJECT object */ * ieObject; IE_INFORMATIONENTITY /* Handle to IE_INFORMATIONENTITY */ * ieIE, *ie_node; LST_HEAD /* Handle to the LST_HEAD */ * ie_head, *mod_head, *attr_head; IE_MODULE /* Handle to IE_MODULE */ * ieModule, *mod_node; IE_ATTRIBUTE /* Handle to IE_ATTRIBUTE */ * attr_node; CTNBOOLEAN /* For debugging purpose */ verbose = FALSE; char /* The UID of the image file */ *UID, *SOPClassName; int /* Iteration variables */ ie_loop, mod_loop, attr_loop, i, k, j; if (argc < 1) usageerror(); THR_Init(); DCM_Debug(verbose); while (--argc > 0 && (*++argv)[0] == '-') { switch (*(argv[0] + 1)) { case 'v': verbose = TRUE; break; default: break; } } while (argc-- > 0) { SOPClassName = *argv; (void) *argv++; /* * Find the SOP Class UID according to the SOP Class name. */ UID = lookupUID(SOPClassName); if (UID != NULL) { /* The SOP Class name is legal */ printf("\nRequired IEs and Modules for %s image file:\n", SOPClassName); /* * Find the required IEs. */ cond = IE_ObjectRequirements(UID, &ieObject); if (cond == IE_LISTFAILURE || cond == IE_MALLOCFAILURE || cond == IE_ILLEGALDCMOBJECT) { COND_DumpConditions(); THR_Shutdown(); return (2); } ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { /* * Find all the required Modules. */ ie_node = LST_Pop(&ie_head); printf("%s\n", ie_node->ieDescription); cond = IE_IERequirements(UID, ie_node->ieType, &ieIE); mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); printf(" %s\n", mod_node->moduleDescription); } cond = IE_Free((void **) &ieIE); } cond = IE_Free((void **) &ieObject); printf("\n"); printf("Required Modules and Attributes for %s image file:\n", SOPClassName); /* * Find all the required IEs. */ cond = IE_ObjectRequirements(UID, &ieObject); if (cond == IE_LISTFAILURE || cond == IE_MALLOCFAILURE || cond == IE_ILLEGALDCMOBJECT) { COND_DumpConditions(); THR_Shutdown(); return (2); } ie_head = ieObject->ieList; ie_loop = LST_Count(&ie_head); for (i = 0; i < ie_loop; i++) { /* * Find all the required Modules. */ ie_node = LST_Pop(&ie_head); cond = IE_IERequirements(UID, ie_node->ieType, &ieIE); mod_head = ieIE->moduleList; mod_loop = LST_Count(&mod_head); for (k = 0; k < mod_loop; k++) { mod_node = LST_Pop(&mod_head); cond = IE_ModuleRequirements(UID, ie_node->ieType, mod_node->moduleType, &ieModule); printf("%s\n", mod_node->moduleDescription); attr_head = ieModule->attributeList; attr_loop = LST_Count(&attr_head); for (j = 0; j < attr_loop; j++) { /* * Find all the mandatory attributes. */ attr_node = LST_Pop(&attr_head); cond = DCM_LookupElement (&(attr_node->element)); printf(" %s\n", attr_node->element.description); } } } } else /* Illegal SOP Class entered by the user */ printf("Illegal SOP Class.\n"); } THR_Shutdown(); return (0); }
main(int argc, char **argv) { CONDITION /* Return values from facilities */ cond; DUL_NETWORKKEY /* Used to initialize our network */ * network = NULL; DUL_ASSOCIATESERVICEPARAMETERS /* The items which describe this * Association */ params = { DICOM_STDAPPLICATIONCONTEXT, "DEMO_SENDER_93", "RSNA_STORAGE_93", "", 16384, 0, 0, 0, "calling addr", "called addr", NULL, NULL, 0, 0, MIR_IMPLEMENTATIONCLASSUID, MIR_IMPLEMENTATIONVERSIONNAME, "", "" }; char *calledAPTitle = "RSNA_STORAGE_93", *callingAPTitle = "DEMO_SENDER_93", localHost[40], *node, /* The node we are calling */ *port; /* ASCIIZ representation of TCP port */ int scratch; /* Used to check syntax of port number */ unsigned long maxPDU = 16384; CTNBOOLEAN verboseDCM = FALSE, verboseDUL = FALSE, verboseSRV = FALSE; while (--argc > 0 && (*++argv)[0] == '-') { switch (*(argv[0] + 1)) { case 'c': argc--; argv++; if (argc <= 0) usageerror(); callingAPTitle = *argv; break; case 'd': argc--; argv++; if (argc <= 0) usageerror(); if (strcmp(*argv, "DCM") == 0) verboseDCM = TRUE; else if (strcmp(*argv, "DUL") == 0) verboseDUL = TRUE; else if (strcmp(*argv, "SRV") == 0) verboseSRV = TRUE; else usageerror(); break; case 'm': argc--; argv++; if (argc <= 0) usageerror(); if (sscanf(*argv, "%lu", &maxPDU) != 1) usageerror(); break; case 't': argc--; argv++; if (argc <= 0) usageerror(); calledAPTitle = *argv; break; case 'v': verboseDUL = TRUE; verboseSRV = TRUE; break; default: break; } } if (argc < 2) usageerror(); THR_Init(); DCM_Debug(verboseDCM); DUL_Debug(verboseDUL); SRV_Debug(verboseSRV); node = *argv++; argc--; port = *argv++; argc--; if (sscanf(port, "%d", &scratch) != 1) usageerror(); cond = DUL_InitializeNetwork(DUL_NETWORK_TCP, DUL_AEREQUESTOR, NULL, DUL_TIMEOUT, DUL_ORDERBIGENDIAN, &network); if (cond != DUL_NORMAL) myExit(NULL); (void) gethostname(localHost, sizeof(localHost)); sprintf(params.calledPresentationAddress, "%s:%s", node, port); strcpy(params.callingPresentationAddress, localHost); strcpy(params.calledAPTitle, calledAPTitle); strcpy(params.callingAPTitle, callingAPTitle); params.maxPDU = maxPDU; reqReleaseAssociation(&network, ¶ms); THR_Shutdown(); exit(0); }
int main(int argc, char **argv) { CONDITION cond = APP_NORMAL; /* condition code returned by various * facilities */ DUL_NETWORKKEY * network; /* The handle to the network */ DUL_ASSOCIATIONKEY * association = NULL; /* The handle to the Association */ DUL_ASSOCIATESERVICEPARAMETERS service; /* Presentation parameters */ int pid, /* process id */ port; /* port number on which the server listens */ char node[MAXHOSTNAMELEN + 1] = ""; /* name of node */ CTNBOOLEAN singleUserMode = FALSE; /* indicates if the server will run in single * user mode i.e. iterative */ LST_HEAD * processList = NULL; /* maintains a list of children processes */ CTNBOOLEAN paramsFlag = FALSE; /* Dump association parameters? */ (void) gethostname(node, MAXHOSTNAMELEN); /* Parse the command line arguments. First process all the switches */ while (--argc > 0 && *(++argv)[0] == '-') { switch ((*argv)[1]) { case 'd': /* option to put a specific facility in debug * mode */ argc--; argv++; if (!argc) usageError(); if (strcmp(*argv, "DCM") == 0) verboseDCM = TRUE; else if (strcmp(*argv, "DUL") == 0) verboseDUL = TRUE; else if (strcmp(*argv, "SRV") == 0) verboseSRV = TRUE; else usageError(); break; case 'f': /* database selection option */ argc--; argv++; if (!argc) usageError(); controlDatabase = *argv; break; case 'i': /* set the forgive option */ forgiveFlag = TRUE; break; case 'n': /* use node as name rather than hostname */ if (argc < 1) usageError(); argc--; argv++; strcpy(node, *argv); break; case 'p': paramsFlag = TRUE; /* Dump the association parameters to stdout */ break; case 'r': sendBack = TRUE; /* send optional attributes back in the * response messages */ break; case 's': /* set single user mode. Useful for debugging */ singleUserMode = TRUE; break; case 't': traceFlag = TRUE; /* tracing ON (non silent operation) */ break; case 'v': /* set verbose mode ON */ verboseDUL = TRUE; verboseSRV = TRUE; verboseDCM = TRUE; break; case 'x': /* for maintaining a Generalized Queue. This * option is useful for terminals having X * capability */ gqueueFlag = TRUE; #ifdef ASG argc--; argv++; if (sscanf(*argv, "%d", &gqID) != 1) usageError(); #endif break; default: printf("Unrecognized option: %s\n", *argv); break; } } if (argc < 1) usageError(); if (sscanf(*argv++, "%d", &port) != 1) usageError(); #ifdef _MSC_VER singleUserMode = TRUE; #endif THR_Init(); DCM_Debug(verboseDCM); DUL_Debug(verboseDUL); SRV_Debug(verboseSRV); /* Handle interrupts */ (void) signal(SIGINT, signalHandler); /* Initialize a network connection and listen on the specified port */ cond = DUL_InitializeNetwork(DUL_NETWORK_TCP, DUL_AEBOTH, (void *) &port, DUL_TIMEOUT, DUL_ORDERBIGENDIAN, &network); if (cond != DUL_NORMAL) { exitApplication(cond); } appHandles.network = network; /* set the network key field */ if (!singleUserMode) { /* * initialize a list that will hold information about all the * children processes that are active */ if ((processList = LST_Create()) == NULL) { cond = COND_PushCondition(APP_ERROR(APP_FAILURE), "LST_Create", "main"); exitApplication(cond); } appHandles.processList = processList; /* set the process list field */ } /* The server loops forever accepting new requests */ while (1) { /* get the next Association request */ cond = nextAssociationRequest(node, &network, &service, maxPDU, forgiveFlag, &gqID, &association); if (cond == APP_NORMAL) { appHandles.association = association; appHandles.service = &service; if (!singleUserMode) { /* * remove all those child processes that have exited so that * zombie processes are not created */ (void) harvestChildrenProcesses(&processList); /* * server continues to accept new requests, whereas the child * services the requests on that association. To create a * child process, we fork */ pid = fork(); } else pid = 0; /* setting pid to 0 in this else clause is * essential due to the manner in which the * following if condition is coded */ if (pid < 0) { /* fork failed */ printf("Cannot spawn child process. Request rejected\n"); clearAssociationKeyAndServiceParameters(APP_FAILURE); continue; } else if (pid == 0) { /* This is the child process unless * the single user mode is ON in * which case this is the parent * process itself. For this part of * the code to be activated when the * singleUserMode is TRUE, we need to * set pid = 0 as done above */ if (!singleUserMode) printf("Forked child\n"); cond = DUL_AcknowledgeAssociationRQ(&association, &service); if (cond != DUL_NORMAL) { if (!singleUserMode) { /* child process exits with a status of -1 */ exitApplication(cond); } else { /* * In the single user mode, the parent just discards * the current association and service parameters and * continues to listen to new requests */ clearAssociationKeyAndServiceParameters(cond); continue; /* go to next iteration of main loop */ } } /* * open a GQ queue, if the GQ facility is to be used */ if (gqueueFlag) { if (gqID == -1) { /* we were unsuccessful retrieving * the GQ ID info from the database. * Hence we decide to ignore the * display */ fprintf(stderr, "Failure to retrieve GQ ID information\n"); fprintf(stderr, "GQ facility ignored\n"); gqueueFlag = FALSE; } else { /* open a GQ */ cond = openGQ(gqID); if (cond != APP_NORMAL) { if (!singleUserMode) { /* child process exits with a status of -1 */ exitApplication(cond); } else { clearAssociationKeyAndServiceParameters(cond); continue; /* go to next iteration of * main loop */ } } } } if (paramsFlag) DUL_DumpParams(&service); cond = serviceRequests(&network, &association, &service); if (cond == SRV_PEERREQUESTEDRELEASE) cond = SRV_NORMAL; if (CTN_ERROR(cond)) { if (!singleUserMode) { fprintf(stderr, "child failed to service request\n"); COND_DumpConditions(); exitApplication(cond); } else { /* * In the single user mode, the parent just discards * the current association and service parameters and * continues to listen to new requests */ fprintf(stderr, "Iterative server failed to serve request\n"); clearAssociationKeyAndServiceParameters(cond); continue; /* go to next iteration of main loop */ } } if (!singleUserMode) { /* graceful exit by the child process (return status 0) */ exitApplication(SRV_NORMAL); } } else { /* * Parent has to drop the Association that was created for * the child when an Association request arrived from the * client. If this is not done, both the parent and the child * are capable of receiving on the same association */ cond = DUL_DropAssociation(&association); if (cond != DUL_NORMAL) { exitApplication(cond); } /* * Add information of the process to the list maintained by * the parent */ (void) addChildProcess(&service, pid, &processList); /* * Now clear the service parameters so as to accept a new set * of parameters on the association */ (void) DUL_ClearServiceParameters(&service); printf("Parent ready to accept new request\n"); } } else { /* * something went wrong accepting the next Association request * Parent server issues an error message and continues to serve * the next request */ fprintf(stderr, "!!!! Error getting next Request.\n"); fprintf(stderr, "Discarding this request\n"); COND_DumpConditions(); } } #ifdef MALLOC_DEBUG malloc_verify(0); malloc_shutdown(); #endif return 0; }