Changeset 579 for trunk/zoo-project
- Timestamp:
- Feb 12, 2015, 5:01:11 PM (10 years ago)
- Location:
- trunk/zoo-project/zoo-kernel
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/otbZooWatcher.h
r558 r579 21 21 #include "service.h" 22 22 23 /** 24 * Observer used to access the ongoing status of a running OTB Application 25 */ 23 26 class /*ITK_EXPORT*/ ZooWatcher : public otb::FilterWatcherBase 24 27 { 25 28 public: 26 29 27 /** Constructor. Takes a ProcessObject to monitor and an optional 28 * comment string that is prepended to each event message. */ 30 /** 31 * Constructor 32 * @param process the itk::ProcessObject to monitor 33 * @param comment comment string that is prepended to each event message 34 */ 29 35 ZooWatcher(itk::ProcessObject* process, 30 36 const char *comment = ""); 31 37 38 /** 39 * Constructor 40 * @param process the itk::ProcessObject to monitor 41 * @param comment comment string that is prepended to each event message 42 */ 32 43 ZooWatcher(itk::ProcessObject* process, 33 44 const std::string& comment = ""); … … 36 47 ZooWatcher(); 37 48 38 /** Get/Set/Free Configuration maps */ 49 /** 50 * Copy the original conf in the m_Conf property 51 * 52 * @param conf the maps pointer to copy 53 */ 39 54 void SetConf(maps **conf) 40 55 { 41 56 m_Conf=dupMaps(conf); 42 57 } 58 /** 59 * Get Configuration maps (m_Conf) 60 * @return the m_Conf property 61 */ 43 62 const maps& GetConf() const 44 63 { 45 64 return *m_Conf; 46 65 } 66 /** 67 * Free Configuration maps (m_Conf) 68 */ 47 69 void FreeConf(){ 48 70 freeMaps(&m_Conf); -
trunk/zoo-project/zoo-kernel/service.h
r576 r579 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * … … 60 60 } 61 61 #else 62 /** 63 * The crossplatform strdup alias 64 */ 62 65 #define zStrdup strdup 66 /** 67 * The crossplatform mkdir alias 68 */ 63 69 #define zMkdir mkdir 70 /** 71 * The crossplatform open alias 72 */ 64 73 #define zOpen open 74 /** 75 * The crossplatform write alias 76 */ 65 77 #define zWrite write 78 /** 79 * The crossplatform sleep alias 80 */ 66 81 #define zSleep sleep 82 /** 83 * The crossplatform gettimeofday alias 84 */ 67 85 #define zGettimeofday gettimeofday 86 /** 87 * The crossplatform timeval alias 88 */ 68 89 #define ztimeval timeval 69 90 #endif … … 87 108 #endif 88 109 #ifndef true 110 /** 111 * Local true definition 112 */ 89 113 #define true 1 114 /** 115 * Local false definition 116 */ 90 117 #define false -1 91 118 #endif 92 119 #endif 93 120 121 /** 122 * The global accepted status for a service 123 */ 94 124 #define SERVICE_ACCEPTED 0 125 /** 126 * The global started status for a service 127 */ 95 128 #define SERVICE_STARTED 1 129 /** 130 * The global paused status for a service 131 */ 96 132 #define SERVICE_PAUSED 2 133 /** 134 * The global succeeded status for a service 135 */ 97 136 #define SERVICE_SUCCEEDED 3 137 /** 138 * The global failed status for a service 139 */ 98 140 #define SERVICE_FAILED 4 99 141 142 /** 143 * The memory size to create an elements 144 */ 100 145 #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*)) 146 /** 147 * The memory size to create a map 148 */ 101 149 #define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) 150 /** 151 * The memory size to create an iotype 152 */ 102 153 #define IOTYPE_SIZE MAP_SIZE+sizeof(NULL) 154 /** 155 * The memory size to create a maps 156 */ 103 157 #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE 158 /** 159 * The memory size to create a service 160 */ 104 161 #define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*) 105 162 … … 116 173 117 174 /** 118 * \struct map 119 * \brief KVP linked list 175 * KVP linked list 120 176 * 121 177 * Deal with WPS KVP (name,value). … … 138 194 139 195 /** 140 * \struct maps 141 * \brief linked list of map pointer 196 * linked list of map pointer 142 197 * 143 198 * Small object to store WPS KVP set. … … 154 209 155 210 /** 156 * \brief Dump a map on stderr 211 * Dump a map on stderr 212 * 213 * @param t the map to dump 157 214 */ 158 215 static void _dumpMap(map* t){ … … 166 223 } 167 224 225 /** 226 * Dump a map on stderr, see _dumpMap() 227 * 228 * @param t the map to dump 229 */ 168 230 static void dumpMap(map* t){ 169 231 map* tmp=t; … … 174 236 } 175 237 238 /** 239 * Dump a map to a file 240 * 241 * @param t the map to dump to file 242 * @param file the file to store the map 243 */ 176 244 static void dumpMapToFile(map* t,FILE* file){ 177 245 map* tmp=t; … … 185 253 } 186 254 255 /** 256 * Dump a maps on stderr, see dumpMap(). 257 * 258 * @param m the map to dump 259 */ 187 260 static void dumpMaps(maps* m){ 188 261 maps* tmp=m; … … 194 267 } 195 268 269 /** 270 * Dump a maps to a file, see dumpMapToFile(). 271 * 272 * @param m the map to dump 273 * @param file_path the full path to the file name to store the map 274 */ 196 275 static void dumpMapsToFile(maps* m,char* file_path){ 197 276 FILE* file=fopen(file_path,"w"); … … 205 284 } 206 285 286 /** 287 * Create a new map 288 * 289 * @param name the key to add to the map 290 * @param value the corresponding value to add to the map 291 * @return the allocated map 292 */ 207 293 static map* createMap(const char* name,const char* value){ 208 294 map* tmp=(map *)malloc(MAP_SIZE); … … 213 299 } 214 300 301 /** 302 * Count number of map in a map 303 * 304 * @param m the maps to count 305 * @return number of map in a map 306 */ 215 307 static int count(map* m){ 216 308 map* tmp=m; … … 223 315 } 224 316 317 /** 318 * Verify if a key exist in a map 319 * 320 * @param m the map to search for the key 321 * @param key the key to search in the map 322 * @return true if the key wwas found, false in other case 323 */ 225 324 static bool hasKey(map* m,const char *key){ 226 325 map* tmp=m; … … 236 335 } 237 336 337 /** 338 * Access a specific maps 339 * 340 * @param m the maps to search for the key 341 * @param key the key to search in the maps 342 * @return a pointer on the maps found or NULL if not found 343 */ 238 344 static maps* getMaps(maps* m,const char *key){ 239 345 maps* tmp=m; … … 247 353 } 248 354 355 /** 356 * Access a specific map 357 * 358 * @param m the map to search for the key 359 * @param key the key to search in the map 360 * @return a pointer on the map found or NULL if not found 361 */ 249 362 static map* getMap(map* m,const char *key){ 250 363 map* tmp=m; … … 259 372 260 373 374 /** 375 * Access the last map 376 * 377 * @param m the map to search for the lastest map 378 * @return a pointer on the lastest map found or NULL if not found 379 */ 261 380 static map* getLastMap(map* m){ 262 381 map* tmp=m; … … 270 389 } 271 390 391 /** 392 * Access a specific map from a maps 393 * 394 * @param m the maps to search for the key 395 * @param key the key to search in the maps 396 * @param subkey the key to search in the map (found for the key, if any) 397 * @return a pointer on the map found or NULL if not found 398 */ 272 399 static map* getMapFromMaps(maps* m,const char* key,const char* subkey){ 273 400 maps* _tmpm=getMaps(m,key); … … 279 406 } 280 407 281 408 /** 409 * Free allocated memory of a map. 410 * Require to call free on mo after calling this function. 411 * 412 * @param mo the map to free 413 */ 282 414 static void freeMap(map** mo){ 283 415 map* _cursor=*mo; … … 295 427 } 296 428 429 /** 430 * Free allocated memory of a maps. 431 * Require to call free on mo after calling this function. 432 * 433 * @param mo the maps to free 434 */ 297 435 static void freeMaps(maps** mo){ 298 436 maps* _cursor=*mo; … … 314 452 315 453 /** 316 * \briefNot named linked list454 * Not named linked list 317 455 * 318 456 * Used to store informations about formats, such as mimeType, encoding ... … … 328 466 329 467 /** 330 * \briefMetadata information about input or output.468 * Metadata information about input or output. 331 469 * 332 470 * The elements are used to store metadata informations defined in the ZCFG. 333 471 * 334 * An elements is defined as 472 * An elements is defined as: 335 473 * - a name, 336 474 * - a content map, … … 351 489 } elements; 352 490 491 /** 492 * Metadata informations about a full Service. 493 * 494 * An element is defined as: 495 * - a name, 496 * - a content map, 497 * - a metadata map, 498 * - an inputs elements 499 * - an outputs elements 500 */ 353 501 typedef struct service{ 354 502 char* name; … … 359 507 } service; 360 508 509 /** 510 * Multiple services chained list. 511 */ 361 512 typedef struct services{ 362 513 struct service* content; … … 364 515 } services; 365 516 517 /** 518 * Verify if an elements contains a name equal to the given key. 519 * 520 * @param e the elements to search for the key 521 * @param key the elements name to search 522 * @return true if the elements contains the name, false in other cases. 523 */ 366 524 static bool hasElement(elements* e,const char* key){ 367 525 elements* tmp=e; … … 374 532 } 375 533 534 /** 535 * Access a specific elements named key. 536 * 537 * @param m the elements to search 538 * @param key the elements name to search 539 * @return a pointer to the specific element if found, NULL in other case. 540 */ 376 541 static elements* getElements(elements* m,char *key){ 377 542 elements* tmp=m; … … 384 549 } 385 550 386 551 /** 552 * Free allocated memory of an iotype. 553 * Require to call free on i after calling this function. 554 * 555 * @param i the iotype to free 556 */ 387 557 static void freeIOType(iotype** i){ 388 558 iotype* _cursor=*i; … … 397 567 } 398 568 569 /** 570 * Free allocated memory of an elements. 571 * Require to call free on e after calling this function. 572 * 573 * @param e the iotype to free 574 */ 399 575 static void freeElements(elements** e){ 400 576 elements* tmp=*e; … … 423 599 } 424 600 601 /** 602 * Free allocated memory of a service. 603 * Require to call free on e after calling this function. 604 * 605 * @param s the service to free 606 */ 425 607 static void freeService(service** s){ 426 608 service* tmp=*s; … … 443 625 } 444 626 627 /** 628 * Add key value pair to an existing map. 629 * 630 * @param m the map to add the KVP 631 * @param n the key to add 632 * @param v the corresponding value to add 633 */ 445 634 static void addToMap(map* m,const char* n,const char* v){ 446 635 if(hasKey(m,n)==false){ … … 459 648 } 460 649 650 /** 651 * Add a key and a binary value to an existing map. 652 * 653 * @param m the map to add the KVP 654 * @param n the key to add 655 * @param v the corresponding value to add 656 * @param size the size of the given value 657 */ 461 658 static void addToMapWithSize(map* m,const char* n,const char* v,int size){ 462 659 if(hasKey(m,n)==false){ … … 479 676 } 480 677 678 /** 679 * Add a map at the end of another map. 680 * 681 * @param mo the map to add mi 682 * @param mi the map to add to mo 683 */ 481 684 static void addMapToMap(map** mo,map* mi){ 482 685 map* tmp=mi; … … 511 714 } 512 715 716 /** 717 * Add a map to iotype. 718 * 719 * @param io the iotype to add the map 720 * @param mi the map to add to io 721 */ 513 722 static void addMapToIoType(iotype** io,map* mi){ 514 723 iotype* tmp=*io; … … 522 731 } 523 732 733 /** 734 * Access a specific map or set its value. 735 * 736 * @param m the map to search for the key 737 * @param key the key to search/add in the map 738 * @param value the value to add if the key does not exist 739 * @return a pointer on the map found or NULL if not found 740 */ 524 741 static map* getMapOrFill(map** m,const char *key,const char* value){ 525 742 map* tmp=*m; … … 536 753 } 537 754 755 /** 756 * Verify if a map is contained in another map. 757 * 758 * @param m the map to search for i 759 * @param i the map to search in m 760 * @return true if i was found in m, false in other case 761 */ 538 762 static bool contains(map* m,map* i){ 539 763 while(i!=NULL){ … … 552 776 } 553 777 778 /** 779 * Access a specific iotype from an elements. 780 * 781 * @param e the elements to search for the name 782 * @param name the name to search in the elements e 783 * @param values the map to verify it was contained in the defaults or 784 * supported content of the elements e 785 * @return a pointer on the iotype found or NULL if not found 786 */ 554 787 static iotype* getIoTypeFromElement(elements* e,char *name, map* values){ 555 788 elements* cursor=e; … … 572 805 } 573 806 807 /** 808 * Load binary values from a map (in) and add them to another map (out) 809 * 810 * @param out the map to add binaries values 811 * @param in the map containing the binary values to add ti out 812 * @param pos index of the binary in an array (in case of "MapArray") 813 */ 574 814 static void loadMapBinary(map** out,map* in,int pos){ 575 815 map* size=getMap(in,"size"); … … 598 838 } 599 839 840 /** 841 * Load binary values from a map (in) and add them to another map (out). 842 * This function will take care of MapArray. 843 * @see loadMapBinary 844 * 845 * @param out the map to add binaries values 846 * @param in the map containing the binary values to add ti out 847 */ 600 848 static void loadMapBinaries(map** out,map* in){ 601 849 map* size=getMap(in,"size"); … … 613 861 } 614 862 863 /** 864 * Duplicate a Maps 865 * 866 * @param mo the maps to clone 867 * @return the allocated maps containing a copy of the mo maps 868 */ 615 869 static maps* dupMaps(maps** mo){ 616 870 maps* _cursor=*mo; … … 631 885 } 632 886 887 /** 888 * Add a maps at the end of another maps. 889 * 890 * @see addMapToMap, dupMaps, getMaps 891 * @param mo the maps to add mi 892 * @param mi the maps to add to mo 893 */ 633 894 static void addMapsToMaps(maps** mo,maps* mi){ 634 895 maps* tmp=mi; … … 652 913 } 653 914 915 /** 916 * Access a specific map array element 917 * 918 * @param m the map to search for the key 919 * @param key the key to search in the map 920 * @param index of the MapArray 921 * @return a pointer on the map found or NULL if not found 922 */ 654 923 static map* getMapArray(map* m,const char* key,int index){ 655 924 char tmp[1024]; … … 670 939 671 940 941 /** 942 * Add a key value in a MapArray for a specific index 943 * 944 * @param m the map to search for the key 945 * @param key the key to search in the map 946 * @param index the index of the MapArray 947 * @param value the value to set in the MapArray 948 * @return a pointer on the map found or NULL if not found 949 */ 672 950 static void setMapArray(map* m,const char* key,int index,const char* value){ 673 951 char tmp[1024]; … … 697 975 } 698 976 977 /** 978 * Access the map "type" 979 * 980 * @param mt the map 981 * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in 982 * other case 983 */ 699 984 static map* getMapType(map* mt){ 700 985 map* tmap=getMap(mt,(char *)"mimeType"); … … 711 996 } 712 997 998 /** 999 * Add a Maps containing a MapArray to a Maps 1000 * 1001 * @see getMapType 1002 * @param mo the maps 1003 * @param mi the maps 1004 * @param typ the map "type" 1005 * @return 1006 */ 713 1007 static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){ 714 1008 maps* tmp=mi; … … 759 1053 } 760 1054 1055 /** 1056 * Set a key value pair to a map contained in a Maps 1057 * 1058 * @param m the maps 1059 * @param key the maps name 1060 * @param subkey the map name included in the maps corresponding to key 1061 * @param value the corresponding value to add in the map 1062 */ 761 1063 static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){ 762 1064 maps* _tmpm=getMaps(m,key); … … 787 1089 } 788 1090 789 1091 /** 1092 * Dump an elements on stderr 1093 * 1094 * @param e the elements to dump 1095 */ 790 1096 static void dumpElements(elements* e){ 791 1097 elements* tmp=e; … … 818 1124 } 819 1125 1126 /** 1127 * Dump an elements on stderr using the YAML syntaxe 1128 * 1129 * @param e the elements to dump 1130 */ 820 1131 static void dumpElementsAsYAML(elements* e){ 821 1132 elements* tmp=e; … … 889 1200 } 890 1201 891 1202 /** 1203 * Duplicate an elements 1204 * 1205 * @param e the elements to clone 1206 * @return the allocated elements containing a copy of the elements e 1207 */ 892 1208 static elements* dupElements(elements* e){ 893 1209 elements* cursor=e; … … 939 1255 } 940 1256 1257 /** 1258 * Add an elements to another elements. 1259 * 1260 * @see dupElements 1261 * @param m the elements to add the e 1262 * @param e the elements to be added to m 1263 */ 941 1264 static void addToElements(elements** m,elements* e){ 942 1265 elements* tmp=e; … … 948 1271 } 949 1272 1273 /** 1274 * Dump a service on stderr 1275 * 1276 * @param s the service to dump 1277 */ 950 1278 static void dumpService(service* s){ 951 1279 fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name); … … 967 1295 } 968 1296 1297 /** 1298 * Dump a service on stderr using the YAML syntaxe 1299 * 1300 * @param s the service to dump 1301 */ 969 1302 static void dumpServiceAsYAML(service* s){ 970 1303 int i; … … 994 1327 } 995 1328 1329 /** 1330 * Convert a maps to a char*** (only used for Fortran support) 1331 * 1332 * @param m the maps to convert 1333 * @param c the resulting array 1334 */ 996 1335 static void mapsToCharXXX(maps* m,char*** c){ 997 1336 maps* tm=m; … … 1024 1363 } 1025 1364 1365 /** 1366 * Convert a char*** to a maps (only used for Fortran support) 1367 * 1368 * @param c the array to convert 1369 * @param m the resulting maps 1370 */ 1026 1371 static void charxxxToMaps(char*** c,maps**m){ 1027 1372 maps* trorf=*m; -
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 } -
trunk/zoo-project/zoo-kernel/service_internal.h
r578 r579 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * … … 28 28 #pragma once 29 29 30 /** 31 * The default service url (overriden by serverAddress) 32 */ 30 33 #define DEFAULT_SERVICE_URL "http://www.zoo-project.org/" 34 /** 35 * The time size 36 */ 31 37 #define TIME_SIZE 40 32 38 33 39 #include <libintl.h> 34 40 #include <locale.h> 41 /** 42 * ZOO-Kernel internal messages translation function 43 */ 35 44 #define _(String) dgettext ("zoo-kernel",String) 45 /** 46 * ZOO-Services messages translation function 47 */ 36 48 #define _ss(String) dgettext ("zoo-services",String) 37 49 50 /** 51 * ZOO-Kernel was unable to create a lock 52 */ 38 53 #define ZOO_LOCK_CREATE_FAILED -4 54 /** 55 * ZOO-Kernel was unable to acquire a lock 56 */ 39 57 #define ZOO_LOCK_ACQUIRE_FAILED -5 58 /** 59 * ZOO-Kernel was unable to release a lock 60 */ 40 61 #define ZOO_LOCK_RELEASE_FAILED -6 41 62 … … 89 110 #include <libxml/xpath.h> 90 111 112 /** 113 * Maximum number of XML namespaces 114 */ 115 #define ZOO_NS_MAX 10 116 /** 117 * Maximum number of XML docs 118 */ 119 #define ZOO_DOC_MAX 20 120 121 /** 122 * Global char* to store the serverAddress value of the mmmmmain section 123 */ 91 124 static char* SERVICE_URL; 92 static xmlNsPtr usedNs[10]; 93 static char* nsName[10]; 94 static xmlDocPtr iDocs[10]; 125 /** 126 * Array of xmlNsPtr storing all used XML namespace 127 */ 128 static xmlNsPtr usedNs[ZOO_NS_MAX]; 129 /** 130 * Array storing names of the used XML namespace 131 */ 132 static char* nsName[ZOO_NS_MAX]; 133 /** 134 * Number of XML namespaces 135 */ 95 136 static int nbNs=0; 137 /** 138 * Array of xmlDocPtr storing XML docs 139 */ 140 static xmlDocPtr iDocs[ZOO_DOC_MAX]; 141 /** 142 * Number of XML docs 143 */ 96 144 static int nbDocs=0; 97 145 … … 107 155 char* getStatus(int); 108 156 int removeShmLock(maps*, int); 157 /** 158 * Cross platform type used for Lock identifier 159 */ 109 160 #ifndef WIN32 110 161 #define semid int -
trunk/zoo-project/zoo-kernel/service_internal_ms.c
r550 r579 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * -
trunk/zoo-project/zoo-kernel/service_internal_ms.h
r379 r579 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * -
trunk/zoo-project/zoo-kernel/service_internal_python.c
r576 r579 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * … … 25 25 #include "service_internal_python.h" 26 26 27 /** 28 * The state for the zoo Python module 29 */ 27 30 struct module_state { 28 31 PyObject *error; 29 32 }; 30 33 … … 43 46 #endif 44 47 48 /** 49 * The exception for the zoo Python module 50 */ 45 51 static PyObject* ZooError; 46 52 53 /** 54 * Function definitions for the zoo Python Module 55 * 56 * Define the following functions available from a service loaded and running 57 * from the ZOO-Kernel Python environment: 58 * - "_" corresponding to the PythonTranslate function 59 * - "updte_status" corresponding to the PythonUpdateStatus function 60 * @see PythonTranslate, PythonUpdateStatus 61 */ 47 62 PyMethodDef zooMethods[] = { 48 63 {"_", PythonTranslate, METH_VARARGS, "Translate a string using the zoo-services textdomain."}, … … 76 91 #endif 77 92 93 /** 94 * Function to create and initialize the zoo Python module 95 * 96 * @return the Python module (for Python versions < 3, nothing for version >=3) 97 */ 78 98 PyMODINIT_FUNC init_zoo(){ 79 99 PyObject *tmp,*d; … … 115 135 } 116 136 137 /** 138 * Loading a Python module then run the function corresponding to the service 139 * by passing the conf, inputs and outputs parameters by reference. 140 * 141 * @param main_conf the conf maps containing the main.cfg settings 142 * @param request the map containing the HTTP request 143 * @param s the service structure 144 * @param real_inputs the maps containing the inputs 145 * @param real_outputs the maps containing the outputs 146 */ 117 147 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ 118 148 char *pythonpath; … … 271 301 } 272 302 303 /** 304 * Repport Python error which may occur on loading the Python module or at 305 * runtime. 306 * 307 * @param m the conf maps containing the main.cfg settings 308 * @param module the service name 309 * @param load 1 if the Python module was not loaded yet 310 */ 273 311 void PythonZooReport(maps* m,const char* module,int load){ 274 312 PyObject *pName, *pModule, *pFunc; … … 335 373 } 336 374 375 /** 376 * Convert a maps to a Python dictionary 377 * 378 * @param t the maps to convert 379 * @return a new PyDictObject containing the converted maps 380 * @see PyDict_FromMap 381 * @warning make sure to free ressources returned by this function 382 */ 337 383 PyDictObject* PyDict_FromMaps(maps* t){ 338 384 PyObject* res=PyDict_New( ); … … 351 397 } 352 398 399 /** 400 * Convert a map to a Python dictionary 401 * 402 * @param t the map to convert 403 * @return a new PyDictObject containing the converted maps 404 * @warning make sure to free ressources returned by this function 405 */ 353 406 PyDictObject* PyDict_FromMap(map* t){ 354 407 PyObject* res=PyDict_New( ); … … 461 514 } 462 515 516 /** 517 * Convert a Python dictionary to a maps 518 * 519 * @param t the PyDictObject to convert 520 * @return a new maps containing the converted PyDictObject 521 * @warning make sure to free ressources returned by this function 522 */ 463 523 maps* mapsFromPyDict(PyDictObject* t){ 464 524 maps* res=NULL; … … 501 561 } 502 562 563 /** 564 * Convert a Python dictionary to a map 565 * 566 * @param t the PyDictObject to convert 567 * @return a new map containing the converted PyDictObject 568 * @warning make sure to free ressources returned by this function 569 */ 503 570 map* mapFromPyDict(PyDictObject* t){ 504 571 map* res=NULL; … … 540 607 } 541 608 609 /** 610 * Use the ZOO-Services messages translation function from the Python 611 * environment 612 * 613 * @param self the Python object on which we can run the method 614 * @param args the Python arguments given from the Python environment 615 * @return a new Python string containing the translated value to the Python 616 * environment 617 * @see _ss 618 */ 542 619 PyObject* 543 620 PythonTranslate(PyObject* self, PyObject* args) … … 553 630 } 554 631 632 /** 633 * Update the ongoing status of a running service from the Python environment 634 * 635 * @param self the Python object on which we can run the method 636 * @param args the Python arguments given from the Python environment 637 * @return None to the Python environment 638 * @see _updateStatus 639 */ 555 640 PyObject* 556 641 PythonUpdateStatus(PyObject* self, PyObject* args) -
trunk/zoo-project/zoo-kernel/service_internal_python.h
r576 r579 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * … … 40 40 41 41 maps* mapsFromPyDict(PyDictObject* t); 42 void createMapsFromPyDict(maps**,PyDictObject*);43 42 map* mapFromPyDict(PyDictObject* t); 44 43 -
trunk/zoo-project/zoo-kernel/ulinet.c
r539 r579 1 /* *1 /* 2 2 * ulinet.c 3 3 * 4 4 * Author : Gérald FENOY 5 5 * 6 * Copyright (c) 2008-201 0GeoLabs SARL6 * Copyright (c) 2008-2015 GeoLabs SARL 7 7 * 8 8 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 30 30 #include "ulinet.h" 31 31 #include <assert.h> 32 32 33 /** 34 * Write the downloaded content to a _HINTERNET structure 35 * 36 * @param buffer the buffer to read 37 * @param size size of each member 38 * @param nmemb number of element to read 39 * @param data the _HINTERNET structure to write in 40 * @return the size red, -1 if buffer is NULL 41 */ 33 42 size_t write_data_into(void *buffer, size_t size, size_t nmemb, void *data){ 34 43 size_t realsize = size * nmemb; … … 58 67 } 59 68 69 /** 70 * In case of presence of "Set-Cookie" in the headers red, store the cookie 71 * identifier in CCookie 72 * 73 * @param buffer the buffer to read 74 * @param size size of each member 75 * @param nmemb number of element to read 76 * @param data the _HINTERNET structure to write in 77 * @return the size red, -1 if buffer is NULL 78 * @see CCookie 79 */ 60 80 size_t header_write_data(void *buffer, size_t size, size_t nmemb, void *data){ 61 81 if(strncmp("Set-Cookie: ",(char*)buffer,12)==0){ … … 82 102 }; 83 103 84 104 /** 105 * Define the proxy to use for a CURL handler 106 * 107 * @param handle the CURL handler 108 * @param host the proxy host (including http://) 109 * @param port the proxy port 110 */ 85 111 void setProxy(CURL* handle,char* host,long port){ 112 char* proxyDef=(char*)malloc((strlen(host)+10+2)*sizeof(char)); 113 sprintf(proxyDef,"%s:%ld",host,port); 114 curl_easy_setopt(handle,CURLOPT_PROXY,proxyDef); 115 free(proxyDef); 86 116 } 87 117 … … 154 184 #else 155 185 /** 156 * Linux (Gnome) 186 * Should autodetect the proxy configuration (do nothing on linux) 187 * 188 * @param handle a CURL handle 189 * @param proto the protocol requiring the use of a proxy 157 190 */ 158 191 bool setProxiesForProtcol(CURL* handle,const char *proto){ … … 164 197 #endif 165 198 199 /** 200 * Create a HINTERNET 201 * 202 * @param lpszAgent the HTPP User-Agent to use to send requests 203 * @param dwAccessType type of access required 204 * @param lpszProxyName the name of the proxy server(s) to use 205 * @param lpszProxyBypass ip address or host names which should not be routed 206 * through the proxy 207 * @param dwFlags Options (INTERNET_FLAG_ASYNC,INTERNET_FLAG_FROM_CACHE,INTERNET_FLAG_OFFLINE) 208 * @return the created HINTERNET 209 */ 166 210 HINTERNET InternetOpen(char* lpszAgent,int dwAccessType,char* lpszProxyName,char* lpszProxyBypass,int dwFlags){ 167 211 HINTERNET ret; … … 173 217 } 174 218 219 /** 220 * Close a HINTERNET connection and free allocated ressources 221 * 222 * @param handle0 the HINTERNET connection to close 223 */ 175 224 void InternetCloseHandle(HINTERNET* handle0){ 176 225 int i=0; … … 200 249 } 201 250 251 /** 252 * Create a new element in the download queue 253 * 254 * @param hInternet the HINTERNET connection to add the download link 255 * @param lpszUrl the url to download 256 * @param lpszHeaders the additional headers to be sent to the HTTP server 257 * @param dwHeadersLength the size of the additional headers 258 * @param dwFlags desired download mode (INTERNET_FLAG_NO_CACHE_WRITE for not using cache file) 259 * @param dwContext not used 260 */ 202 261 HINTERNET InternetOpenUrl(HINTERNET* hInternet,LPCTSTR lpszUrl,LPCTSTR lpszHeaders,size_t dwHeadersLength,size_t dwFlags,size_t dwContext){ 203 262 … … 289 348 }; 290 349 350 /** 351 * Download all opened urls in the queue 352 * 353 * @param hInternet the HINTERNET structure containing the queue 354 * @return 0 355 */ 291 356 int processDownloads(HINTERNET* hInternet){ 292 357 int still_running=0; … … 307 372 } 308 373 374 /** 375 * Initialize the CCookie for a specific index (hInternet.nb) 376 * 377 * @param hInternet the HINTERNET structure to know the CCookie index to reset 378 * @return 1 379 * @see HINTERNET 380 */ 309 381 int freeCookieList(HINTERNET hInternet){ 310 382 memset(&CCookie[hInternet.nb][0],0,1024); … … 315 387 } 316 388 389 /** 390 * Copy a downloaded content 391 * 392 * @param hInternet the _HINTERNET structure 393 * @param lpBuffer the memory space to copy the downloaded content 394 * @param dwNumberOfBytesToRead the size of lpBuffer 395 * @param lpdwNumberOfBytesRead number of bytes red 396 * @return 1 on success, 0 if failure 397 */ 317 398 int InternetReadFile(_HINTERNET hInternet,LPVOID lpBuffer,int dwNumberOfBytesToRead, size_t *lpdwNumberOfBytesRead){ 318 399 int dwDataSize; -
trunk/zoo-project/zoo-kernel/ulinet.h
r554 r579 1 /* *1 /* 2 2 * Author : Gérald FENOY 3 3 * … … 56 56 static char CCookie[MAX_REQ][1024]; 57 57 #else 58 extern char HEADER[MAX_REQ][3072]; 58 /** 59 * The cookies found 60 */ 59 61 extern char CCookie[MAX_REQ][1024]; 60 62 #endif … … 64 66 #endif 65 67 66 //static pthread_mutex_t hMutexConnect = PTHREAD_MUTEX_INITIALIZER;67 68 static char* waitingRequests[MAX_REQ];69 70 68 struct MemoryStruct { 71 char *memory; 72 size_t size; 69 char *memory; //!< the memory space to store data 70 size_t size; //!< side of the memory space 73 71 }; 74 72 73 /** 74 * Individual CURL handler 75 */ 75 76 typedef struct { 76 CURL *handle; 77 struct curl_slist *header; 78 char* filename; 79 FILE* file; 80 size_t size; 81 unsigned char *pabyData; 82 char *mimeType; 83 int hasCacheFile; 84 int nDataLen; 85 int nDataAlloc; 86 int id; 77 CURL *handle; //!< the CURL handler 78 struct curl_slist *header; //!< the headers to send 79 char* filename; //!< the cached file name 80 FILE* file; //!< the file pointer 81 unsigned char *pabyData; //!< the downloaded content 82 char *mimeType; //!< the mimeType returned by the server 83 int hasCacheFile; //!< 1 if we used a cache file 84 int nDataLen; //!< the length of the downloaded content 85 int nDataAlloc; //!< 86 int id; //!< The position of the element in the queue 87 87 } _HINTERNET; 88 88 89 /** 90 * Multiple CURL handlers 91 */ 89 92 typedef struct { 90 CURLM *handle; 91 _HINTERNET ihandle[MAX_REQ]; 92 char *waitingRequests[MAX_REQ]; 93 char *agent; 94 int nb; 93 CURLM *handle; //!< the CURLM handler 94 _HINTERNET ihandle[MAX_REQ]; //!< individual handlers in the queue 95 char *waitingRequests[MAX_REQ]; //!< request in the queue 96 char *agent; //!< The User-Agent to use for HTTP request 97 int nb; //!< number of element in the queue 95 98 } HINTERNET; 96 99 97 100 size_t write_data_into(void *buffer, size_t size, size_t nmemb, void *data); 98 101 99 size_t content_write_data(void *buffer, size_t size, size_t nmemb, void *data);100 101 102 size_t header_write_data(void *buffer, size_t size, size_t nmemb, void *data); 102 103 103 104 104 void setProxy(CURL* handle,char* host,long port); 105 106 105 107 106 #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r578 r579 2681 2681 { 2682 2682 /** 2683 * Get every attribute from a Output node2683 * Get every attribute from an Output node 2684 2684 * mimeType, encoding, schema, uom, asReference 2685 2685 */
Note: See TracChangeset
for help on using the changeset viewer.