Changeset 579 for trunk/zoo-project/zoo-kernel/service_internal.c
- Timestamp:
- Feb 12, 2015, 5:01:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal.c
r578 r579 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * … … 43 43 #define ERROR_MSG_MAX_LENGTH 1024 44 44 45 /** 46 * Verify if a given language is listed in the lang list defined in the [main] 47 * section of the main.cfg file. 48 * 49 * @param conf the map containing the settings from the main.cfg file 50 * @param str the specific language 51 * @return 1 if the specific language is listed, -1 in other case. 52 */ 45 53 int isValidLang(maps* conf,const char *str){ 46 54 map *tmpMap=getMapFromMaps(conf,"main","lang"); … … 59 67 } 60 68 69 /** 70 * Print the HTTP headers based on a map. 71 * 72 * @param m the map containing the headers informations 73 */ 61 74 void printHeaders(maps* m){ 62 75 maps *_tmp=getMaps(m,"headers"); … … 70 83 } 71 84 85 /** 86 * Add a land attribute to a XML node 87 * 88 * @param n the XML node to add the attribute 89 * @param m the map containing the language key to add as xml:lang 90 */ 72 91 void addLangAttr(xmlNodePtr n,maps *m){ 73 92 map *tmpLmap=getMapFromMaps(m,"main","language"); … … 78 97 } 79 98 80 /* Converts a hex character to its integer value */ 99 /** 100 * Converts a hex character to its integer value 101 * 102 * @param ch the char to convert 103 * @return the converted char 104 */ 81 105 char from_hex(char ch) { 82 106 return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; 83 107 } 84 108 85 /* Converts an integer value to its hex character*/ 109 /** 110 * Converts an integer value to its hec character 111 * 112 * @param code the char to convert 113 * @return the converted char 114 */ 86 115 char to_hex(char code) { 87 116 static char hex[] = "0123456789abcdef"; … … 89 118 } 90 119 120 /** 121 * Get the ongoing status of a running service 122 * 123 * @param conf the maps containing the setting of the main.cfg file 124 * @param pid the service identifier (usid key from the [lenv] section) 125 * @return the reported status char* (MESSAGE|POURCENTAGE) 126 */ 91 127 char* _getStatus(maps* conf,int pid){ 92 128 char lid[1024]; … … 131 167 132 168 size_t getKeyValue(maps* conf, char* key, size_t length){ 133 134 169 if(conf==NULL) { 135 136 170 strncpy(key, "700666", length); 171 return strlen(key); 137 172 } 138 173 … … 148 183 } 149 184 return strlen(key); 150 } 185 } 186 187 151 188 semid getShmLockId(maps* conf, int nsems){ 152 189 semid sem_id; … … 336 373 337 374 #else 338 375 /** 376 * Number of time to try to access a semaphores set 377 * @see getShmLockId 378 */ 339 379 #define MAX_RETRIES 10 340 380 … … 347 387 #endif 348 388 389 /** 390 * Set in the pre-allocated key the zoo_sem_[SID] string 391 * where [SID] is the lid (if any) or usid value from the [lenv] section. 392 * 393 * @param conf the map containing the setting of the main.cfg file 394 */ 349 395 int getKeyValue(maps* conf){ 350 396 if(conf==NULL) … … 359 405 } 360 406 407 /** 408 * Try to create or access a semaphore set. 409 * 410 * @see getKeyValue 411 * @param conf the map containing the setting of the main.cfg file 412 * @param nsems number of semaphores 413 * @return a semaphores set indentifier on success, -1 in other case 414 */ 361 415 int getShmLockId(maps* conf, int nsems){ 362 416 int i; … … 422 476 } 423 477 478 /** 479 * Try to remove a semaphore set. 480 * 481 * @param conf the map containing the setting of the main.cfg file 482 * @param nsems number of semaphores 483 * @return 0 if the semaphore can be removed, -1 in other case. 484 */ 424 485 int removeShmLock(maps* conf, int nsems){ 425 486 union semun arg; … … 432 493 } 433 494 495 /** 496 * Lock a semaphore set. 497 * 498 * @param id the semaphores set indetifier 499 * @return 0 if the semaphore can be locked, -1 in other case. 500 */ 434 501 int lockShm(int id){ 435 502 struct sembuf sb; … … 444 511 } 445 512 513 /** 514 * unLock a semaphore set. 515 * 516 * @param id the semaphores set indetifier 517 * @return 0 if the semaphore can be locked, -1 in other case. 518 */ 446 519 int unlockShm(int id){ 447 520 struct sembuf sb; … … 456 529 } 457 530 531 /** 532 * Stop handling status repport. 533 * 534 * @param conf the map containing the setting of the main.cfg file 535 */ 458 536 void unhandleStatus(maps *conf){ 459 537 int shmid; … … 481 559 } 482 560 561 /** 562 * Update the current of the running service. 563 * 564 * @see getKeyValue, getShmLockId, lockShm 565 * @param conf the map containing the setting of the main.cfg file 566 * @return 0 on success, -2 if shmget failed, -1 if shmat failed 567 */ 483 568 int _updateStatus(maps *conf){ 484 569 int shmid; … … 528 613 } 529 614 615 /** 616 * Update the current of the running service. 617 * 618 * @see getKeyValue, getShmLockId, lockShm 619 * @param pid the semaphores 620 * @return 0 on success, -2 if shmget failed, -1 if shmat failed 621 */ 530 622 char* getStatus(int pid){ 531 623 int shmid; … … 594 686 595 687 596 597 /* Returns a url-encoded version of str */ 598 /* IMPORTANT: be sure to free() the returned string after use */ 688 /** 689 * URLEncode an url 690 * 691 * @param str the url to encode 692 * @return a url-encoded version of str 693 * @warning be sure to free() the returned string after use 694 */ 599 695 char *url_encode(char *str) { 600 696 char *pstr = str, *buf = (char*) malloc(strlen(str) * 3 + 1), *pbuf = buf; … … 612 708 } 613 709 614 /* Returns a url-decoded version of str */ 615 /* IMPORTANT: be sure to free() the returned string after use */ 710 /** 711 * Decode an URLEncoded url 712 * 713 * @param str the URLEncoded url to decode 714 * @return a url-decoded version of str 715 * @warning be sure to free() the returned string after use 716 */ 616 717 char *url_decode(char *str) { 617 718 char *pstr = str, *buf = (char*) malloc(strlen(str) + 1), *pbuf = buf; … … 633 734 } 634 735 736 /** 737 * Replace the first letter by its upper case version in a new char array 738 * 739 * @param tmp the char* 740 * @return a new char* with first letter in upper case 741 * @warning be sure to free() the returned string after use 742 */ 635 743 char *zCapitalize1(char *tmp){ 636 744 char *res=zStrdup(tmp); … … 640 748 } 641 749 750 /** 751 * Replace all letters by their upper case version in a new char array 752 * 753 * @param tmp the char* 754 * @return a new char* with first letter in upper case 755 * @warning be sure to free() the returned string after use 756 */ 642 757 char *zCapitalize(char *tmp){ 643 758 int i=0; … … 649 764 } 650 765 651 766 /** 767 * Search for an existing XML namespace in usedNS. 768 * 769 * @param name the name of the XML namespace to search 770 * @return the index of the XML namespace found or -1 if not found. 771 */ 652 772 int zooXmlSearchForNs(const char* name){ 653 773 int i; … … 661 781 } 662 782 783 /** 784 * Add an XML namespace to the usedNS if it was not already used. 785 * 786 * @param nr the xmlNodePtr to attach the XML namspace (can be NULL) 787 * @param url the url of the XML namespace to add 788 * @param name the name of the XML namespace to add 789 * @return the index of the XML namespace added. 790 */ 663 791 int zooXmlAddNs(xmlNodePtr nr,const char* url,const char* name){ 664 792 #ifdef DEBUG … … 683 811 } 684 812 813 /** 814 * Free allocated memory to store used XML namespace. 815 */ 685 816 void zooXmlCleanupNs(){ 686 817 int j; … … 700 831 } 701 832 702 833 /** 834 * Add a XML document to the iDocs. 835 * 836 * @param value the string containing the XML document 837 * @return the index of the XML document added. 838 */ 703 839 int zooXmlAddDoc(const char* value){ 704 840 int currId=0; … … 709 845 } 710 846 847 /** 848 * Free allocated memort to store XML documents 849 */ 711 850 void zooXmlCleanupDocs(){ 712 851 int j; … … 716 855 nbDocs=0; 717 856 } 718 719 720 /************************************************************************/721 /* soapEnvelope() */722 /************************************************************************/723 857 724 858 /** … … 755 889 } 756 890 757 /************************************************************************/758 /* printWPSHeader() */759 /************************************************************************/760 761 891 /** 762 892 * Generate a WPS header. … … 794 924 return n; 795 925 } 796 797 /************************************************************************/798 /* printGetCapabilitiesHeader() */799 /************************************************************************/800 926 801 927 /** … … 1095 1221 } 1096 1222 1097 1223 /** 1224 * Add prefix to the service name. 1225 * 1226 * @param conf the conf maps containing the main.cfg settings 1227 * @param level the map containing the level information 1228 * @param serv the service structure created from the zcfg file 1229 */ 1098 1230 void addPrefix(maps* conf,map* level,service* serv){ 1099 1231 if(level!=NULL){ … … 1128 1260 } 1129 1261 1262 /** 1263 * Generate a wps:Process node for a servie and add it to a given node. 1264 * 1265 * @param m the conf maps containing the main.cfg settings 1266 * @param nc the XML node to add the Process node 1267 * @param serv the service structure created from the zcfg file 1268 * @return the generated wps:ProcessOfferings xmlNodePtr 1269 */ 1130 1270 void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){ 1131 1271 xmlNsPtr ns,ns_ows,ns_xlink; … … 1161 1301 } 1162 1302 1303 /** 1304 * Generate a ProcessDescription node for a servie and add it to a given node. 1305 * 1306 * @param m the conf maps containing the main.cfg settings 1307 * @param nc the XML node to add the Process node 1308 * @param serv the servive structure created from the zcfg file 1309 * @return the generated wps:ProcessOfferings xmlNodePtr 1310 */ 1163 1311 void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv){ 1164 1312 xmlNsPtr ns,ns_ows,ns_xlink; … … 1230 1378 } 1231 1379 1380 /** 1381 * Generate the required XML tree for the detailled metadata informations of 1382 * inputs or outputs 1383 * 1384 * @param in 1 in case of inputs, 0 for outputs 1385 * @param elem the elements structure containing the metadata informations 1386 * @param type the name ("Input" or "Output") of the XML node to create 1387 * @param ns_ows the ows XML namespace 1388 * @param nc1 the XML node to use to add the created tree 1389 */ 1232 1390 void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){ 1233 1391 const char *orderedFields[13]; … … 1686 1844 } 1687 1845 1846 /** 1847 * Generate a wps:Execute XML document. 1848 * 1849 * @param m the conf maps containing the main.cfg settings 1850 * @param request the map representing the HTTP request 1851 * @param pid the process identifier linked to a service 1852 * @param serv the serv structure created from the zcfg file 1853 * @param service the service name 1854 * @param status the status returned by the service 1855 * @param inputs the inputs provided 1856 * @param outputs the outputs generated by the service 1857 */ 1688 1858 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ 1689 1859 xmlNsPtr ns,ns_ows,ns_xlink; … … 1966 2136 } 1967 2137 1968 2138 /** 2139 * Print a XML document. 2140 * 2141 * @param m the conf maps containing the main.cfg settings 2142 * @param doc the XML document 2143 * @param pid the process identifier linked to a service 2144 */ 1969 2145 void printDocument(maps* m, xmlDocPtr doc,int pid){ 1970 2146 char *encoding=getEncoding(m); … … 1992 2168 } 1993 2169 2170 /** 2171 * Print a XML document. 2172 * 2173 * @param doc the XML document (unused) 2174 * @param nc the XML node to add the output definition 2175 * @param ns_wps the wps XML namespace 2176 * @param ns_ows the ows XML namespace 2177 * @param e the output elements 2178 * @param m the conf maps containing the main.cfg settings 2179 * @param type the type (unused) 2180 */ 1994 2181 void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){ 1995 2182 xmlNodePtr nc1; … … 2024 2211 } 2025 2212 2213 /** 2214 * Generate XML nodes describing inputs or outputs metadata. 2215 * 2216 * @param doc the XML document 2217 * @param nc the XML node to add the definition 2218 * @param ns_wps the wps namespace 2219 * @param ns_ows the ows namespace 2220 * @param ns_xlink the xlink namespace 2221 * @param e the output elements 2222 * @param m the conf maps containing the main.cfg settings 2223 * @param type the type 2224 */ 2026 2225 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){ 2027 2226 xmlNodePtr nc1,nc2,nc3; … … 2258 2457 } 2259 2458 2459 /** 2460 * Create XML node with basic ows metadata informations (Identifier,Title,Abstract) 2461 * 2462 * @param root the root XML node to add the description 2463 * @param ns_ows the ows XML namespace 2464 * @param identifier the identifier to use 2465 * @param amap the map containing the ows metadata informations 2466 */ 2260 2467 void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap){ 2261 2468 xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); … … 2278 2485 } 2279 2486 2487 /** 2488 * Access the value of the encoding key in a maps 2489 * 2490 * @param m the maps to search for the encoding key 2491 * @return the value of the encoding key in a maps if encoding key exists, 2492 * "UTF-8" in other case. 2493 */ 2280 2494 char* getEncoding(maps* m){ 2281 2495 if(m!=NULL){ … … 2291 2505 } 2292 2506 2507 /** 2508 * Access the value of the version key in a maps 2509 * 2510 * @param m the maps to search for the version key 2511 * @return the value of the version key in a maps if encoding key exists, 2512 * "1.0.0" in other case. 2513 */ 2293 2514 char* getVersion(maps* m){ 2294 2515 if(m!=NULL){ … … 2304 2525 } 2305 2526 2306 /************************************************************************/2307 /* printExceptionReportResponse() */2308 /************************************************************************/2309 2310 2527 /** 2311 2528 * Print an OWS ExceptionReport Document and HTTP headers (when required) … … 2313 2530 * Set hasPrinted value to true in the [lenv] section. 2314 2531 * 2315 * @param m the conf maps2532 * @param m the maps containing the settings of the main.cfg file 2316 2533 * @param s the map containing the text,code,locator keys 2317 2534 */ … … 2375 2592 setMapInMaps(m,"lenv","hasPrinted","true"); 2376 2593 } 2377 2378 /************************************************************************/2379 /* createExceptionReportNode() */2380 /************************************************************************/2381 2594 2382 2595 /** … … 2448 2661 } 2449 2662 2450 /************************************************************************/2451 /* errorException() */2452 /************************************************************************/2453 2454 2663 /** 2455 2664 * Print an OWS ExceptionReport. … … 2474 2683 } 2475 2684 2476 /************************************************************************/2477 /* readGeneratedFile() */2478 /************************************************************************/2479 2480 2685 /** 2481 2686 * Read a file generated by a service. … … 2511 2716 } 2512 2717 2718 /** 2719 * Generate the output response (RawDataOutput or ResponseDocument) 2720 * 2721 * @param s the service structure containing the metadata informations 2722 * @param request_inputs the inputs provided to the service for execution 2723 * @param request_outputs the outputs updated by the service execution 2724 * @param request_inputs1 the map containing the HTTP request 2725 * @param cpid the process identifier attached to a service execution 2726 * @param m the conf maps containing the main.cfg settings 2727 * @param res the value returned by the service execution 2728 */ 2513 2729 void outputResponse(service* s,maps* request_inputs,maps* request_outputs, 2514 2730 map* request_inputs1,int cpid,maps* m,int res){ … … 2795 3011 } 2796 3012 3013 3014 /** 3015 * Base64 encoding of a char* 3016 * 3017 * @param input the value to encode 3018 * @param length the value length 3019 * @return the buffer containing the base64 value 3020 * @warning make sure to free the returned value 3021 */ 2797 3022 char *base64(const char *input, int length) 2798 3023 { … … 2817 3042 } 2818 3043 3044 /** 3045 * Base64 decoding of a char* 3046 * 3047 * @param input the value to decode 3048 * @param length the value length 3049 * @param red the value length 3050 * @return the buffer containing the base64 value 3051 * @warning make sure to free the returned value 3052 */ 2819 3053 char *base64d(const char *input, int length,int* red) 2820 3054 { … … 2836 3070 } 2837 3071 3072 /** 3073 * Make sure that each value encoded in base64 in a maps is decoded. 3074 * 3075 * @param in the maps containing the values 3076 */ 2838 3077 void ensureDecodedBase64(maps **in){ 2839 3078 maps* cursor=*in; … … 2856 3095 } 2857 3096 3097 /** 3098 * Add the default values defined in the zcfg to a maps. 3099 * 3100 * @param out the maps containing the inputs or outputs given in the initial 3101 * HTTP request 3102 * @param in the description of all inputs or outputs available for a service 3103 * @param m the maps containing the settings of the main.cfg file 3104 * @param type 0 for inputs and 1 for outputs 3105 * @param err the map to store potential missing mandatory input parameters or 3106 * wrong output names depending on the type. 3107 * @return "" if no error was detected, the name of last input or output causing 3108 * an error. 3109 */ 2858 3110 char* addDefaultValues(maps** out,elements* in,maps* m,int type,map** err){ 2859 3111 map *res=*err; … … 3095 3347 3096 3348 /** 3097 * parseBoundingBox : parse a BoundingBox string 3098 * 3099 * OGC 06-121r3 : 10.2 Bounding box 3100 * 3101 * value is provided as : lowerCorner,upperCorner,crs,dimension 3102 * exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84 3103 * 3104 * Need to create a map to store boundingbox informations : 3349 * Parse a BoundingBox string 3350 * 3351 * [OGC 06-121r3](http://portal.opengeospatial.org/files/?artifact_id=20040): 3352 * 10.2 Bounding box 3353 * 3354 * 3355 * Value is provided as : lowerCorner,upperCorner,crs,dimension 3356 * Exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84 3357 * 3358 * A map to store boundingbox informations should contain: 3105 3359 * - lowerCorner : double,double (minimum within this bounding box) 3106 3360 * - upperCorner : double,double (maximum within this bounding box) … … 3109 3363 * 3110 3364 * Note : support only 2D bounding box. 3365 * 3366 * @param value the char* containing the KVP bouding box 3367 * @return a map containing all the bounding box keys 3111 3368 */ 3112 3369 map* parseBoundingBox(const char* value){ … … 3156 3413 3157 3414 /** 3158 * printBoundingBox : fill a BoundingBox node (ows:BoundingBox or 3159 * wps:BoundingBoxData). Set crs and dimensions attributes, add 3160 * Lower/UpperCorner nodes to a pre-existing XML node. 3415 * Create required XML nodes for boundingbox and update the current XML node 3416 * 3417 * @param ns_ows the ows XML namespace 3418 * @param n the XML node to update 3419 * @param boundingbox the map containing the boundingbox definition 3161 3420 */ 3162 3421 void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){ … … 3191 3450 } 3192 3451 3452 /** 3453 * Print an ows:BoundingBox XML document 3454 * 3455 * @param m the maps containing the settings of the main.cfg file 3456 * @param boundingbox the maps containing the boundingbox definition 3457 * @param file the file to print the BoundingBox (if NULL then print on stdout) 3458 * @see parseBoundingBox, printBoundingBox 3459 */ 3193 3460 void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){ 3194 3461 if(file==NULL) … … 3243 3510 } 3244 3511 3245 3512 /** 3513 * Compute md5 3514 * 3515 * @param url the char* 3516 * @return a char* representing the md5 of the url 3517 * @warning make sure to free ressources returned by this function 3518 */ 3246 3519 char* getMd5(char* url){ 3247 3520 EVP_MD_CTX md5ctx; … … 3267 3540 3268 3541 /** 3269 * Cache a file for a given request 3542 * Cache a file for a given request. 3543 * For each cached file, the are two files stored, a .zca and a .zcm containing 3544 * the downloaded content and the mimeType respectively. 3545 * 3546 * @param conf the maps containing the settings of the main.cfg file 3547 * @param request the url used too fetch the content 3548 * @param content the downloaded content 3549 * @param mimeType the content mimeType 3550 * @param length the content size 3270 3551 */ 3271 3552 void addToCache(maps* conf,char* request,char* content,char* mimeType,int length){ … … 3300 3581 } 3301 3582 3583 /** 3584 * Verify if a url is available in the cache 3585 * 3586 * @param conf the maps containing the settings of the main.cfg file 3587 * @param request the url 3588 * @return the full name of the cached file if any, NULL in other case 3589 * @warning make sure to free ressources returned by this function (if not NULL) 3590 */ 3302 3591 char* isInCache(maps* conf,char* request){ 3303 3592 map* tmpM=getMapFromMaps(conf,"main","cacheDir"); … … 3321 3610 } 3322 3611 3612 /** 3613 * Effectively run all the HTTP requests in the queue 3614 * 3615 * @param m the maps containing the settings of the main.cfg file 3616 * @param inputs the maps containing the inputs (defined in the requests+added 3617 * per default based on the zcfg file) 3618 * @param hInternet the HINTERNET pointer 3619 * @return 0 on success 3620 */ 3323 3621 int runHttpRequests(maps** m,maps** inputs,HINTERNET* hInternet){ 3324 3622 if(hInternet->nb>0){ … … 3427 3725 3428 3726 /** 3429 * loadRemoteFile:3430 3727 * Try to load file from cache or download a remote file if not in cache 3728 * 3729 * @param m the maps containing the settings of the main.cfg file 3730 * @param content the map to update 3731 * @param hInternet the HINTERNET pointer 3732 * @param url the url to fetch 3733 * @return 0 3431 3734 */ 3432 3735 int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){ … … 3523 3826 } 3524 3827 3828 /** 3829 * Read a file using the GDAL VSI API 3830 * 3831 * @param conf the maps containing the settings of the main.cfg file 3832 * @param dataSource the datasource name to read 3833 * @warning make sure to free ressources returned by this function 3834 */ 3525 3835 char *readVSIFile(maps* conf,const char* dataSource){ 3526 3836 VSILFILE * fichier=VSIFOpenL(dataSource,"rb"); … … 3542 3852 } 3543 3853 3854 /** 3855 * Extract the service identifier from the full service identifier 3856 * ie: 3857 * - Full service name: OTB.BandMath 3858 * - Service name: BandMath 3859 * 3860 * @param conf the maps containing the settings of the main.cfg file 3861 * @param conf_dir the full path to the ZOO-Kernel directory 3862 * @param identifier the full service name (potentialy including a prefix, ie: 3863 * Prefix.MyService) 3864 * @param buffer the resulting service identifier (without any prefix) 3865 */ 3544 3866 void parseIdentifier(maps* conf,char* conf_dir,char *identifier,char* buffer){ 3545 3867 setMapInMaps(conf,"lenv","oIdentifier",identifier); … … 3607 3929 } 3608 3930 3931 /** 3932 * Update the status of an ongoing service 3933 * 3934 * @param conf the maps containing the settings of the main.cfg file 3935 * @param percentCompleted percentage of completude of execution of the service 3936 * @param message information about the current step executed 3937 * @return the value of _updateStatus 3938 * @see _updateStatus 3939 */ 3609 3940 int updateStatus( maps* conf, const int percentCompleted, const char* message ){ 3610 3941 char tmp[4]; … … 3615 3946 } 3616 3947 3948 /** 3949 * Access an input value 3950 * 3951 * @param inputs the maps to search for the input value 3952 * @param parameterName the input name to fetch the value 3953 * @param numberOfBytes the resulting size of the value to add (for binary 3954 * values), -1 for basic char* data 3955 * @return a pointer to the input value if found, NULL in other case. 3956 */ 3617 3957 char* getInputValue( maps* inputs, const char* parameterName, size_t* numberOfBytes){ 3618 3958 map* res=getMapFromMaps(inputs,parameterName,"value"); … … 3630 3970 } 3631 3971 3972 /** 3973 * Set an output value 3974 * 3975 * @param outputs the maps to define the output value 3976 * @param parameterName the output name to set the value 3977 * @param data the value to set 3978 * @param numberOfBytes size of the value to add (for binary values), -1 for 3979 * basic char* data 3980 * @return 0 3981 */ 3632 3982 int setOutputValue( maps* outputs, const char* parameterName, char* data, size_t numberOfBytes ){ 3633 3983 if(numberOfBytes==-1){ … … 3649 3999 } 3650 4000 3651 /************************************************************************/3652 /* checkValidValue() */3653 /************************************************************************/3654 3655 4001 /** 3656 4002 * Verify if a parameter value is valid. … … 3658 4004 * @param request the request map 3659 4005 * @param res the error map potentially generated 4006 * @param toCheck the parameter to use 3660 4007 * @param avalues the acceptable values (or null if testing only for presence) 3661 4008 * @param mandatory verify the presence of the parameter if mandatory > 0 … … 3740 4087 } 3741 4088 3742 /* 3743 * The character string returned from getLastErrorMessage resides 4089 /** 4090 * Access the last error message returned by the OS when trying to dynamically 4091 * load a shared library. 4092 * 4093 * @return the last error message 4094 * @warning The character string returned from getLastErrorMessage resides 3744 4095 * in a static buffer. The application should not write to this 3745 4096 * buffer or attempt to free() it. 3746 4097 */ 3747 char* getLastErrorMessage() { 3748 #ifdef WIN32 3749 LPVOID lpMsgBuf; 3750 DWORD errCode = GetLastError(); 3751 static char msg[ERROR_MSG_MAX_LENGTH]; 3752 size_t i; 3753 3754 DWORD length = FormatMessage( 3755 FORMAT_MESSAGE_ALLOCATE_BUFFER | 3756 FORMAT_MESSAGE_FROM_SYSTEM | 3757 FORMAT_MESSAGE_IGNORE_INSERTS, 3758 NULL, 3759 errCode, 3760 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 3761 (LPTSTR) &lpMsgBuf, 3762 0, NULL ); 3763 3764 #ifdef UNICODE 3765 wcstombs_s( &i, msg, ERROR_MSG_MAX_LENGTH, 3766 (wchar_t*) lpMsgBuf, _TRUNCATE ); 3767 #else 3768 strcpy_s( msg, ERROR_MSG_MAX_LENGTH, 3769 (char *) lpMsgBuf ); 3770 #endif 3771 LocalFree(lpMsgBuf); 3772 3773 return msg; 4098 char* getLastErrorMessage() { 4099 #ifdef WIN32 4100 LPVOID lpMsgBuf; 4101 DWORD errCode = GetLastError(); 4102 static char msg[ERROR_MSG_MAX_LENGTH]; 4103 size_t i; 4104 4105 DWORD length = FormatMessage( 4106 FORMAT_MESSAGE_ALLOCATE_BUFFER | 4107 FORMAT_MESSAGE_FROM_SYSTEM | 4108 FORMAT_MESSAGE_IGNORE_INSERTS, 4109 NULL, 4110 errCode, 4111 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 4112 (LPTSTR) &lpMsgBuf, 4113 0, NULL ); 4114 4115 #ifdef UNICODE 4116 wcstombs_s( &i, msg, ERROR_MSG_MAX_LENGTH, 4117 (wchar_t*) lpMsgBuf, _TRUNCATE ); 3774 4118 #else 3775 return dlerror(); 3776 #endif 3777 } 4119 strcpy_s( msg, ERROR_MSG_MAX_LENGTH, 4120 (char *) lpMsgBuf ); 4121 #endif 4122 LocalFree(lpMsgBuf); 4123 4124 return msg; 4125 #else 4126 return dlerror(); 4127 #endif 4128 }
Note: See TracChangeset
for help on using the changeset viewer.