Ticket #1: ZooKernel.diff
File ZooKernel.diff, 47.7 KB (added by soeren, 14 years ago) |
---|
-
service.c
1 1 #include "service.h" 2 2 3 map* createMap(char* name,char* value){ 3 /* ************************************************************************* */ 4 5 map* createMap(const char* name, const char* value){ 4 6 map* tmp=(map *)malloc(sizeof(map*)); 5 7 tmp->name=strdup(name); 6 8 tmp->value=strdup(value); … … 8 10 return tmp; 9 11 } 10 12 13 /* ************************************************************************* */ 14 11 15 bool hasKey(map* m,char *key){ 12 16 map* tmp=m; 13 17 while(tmp!=NULL){ … … 16 20 tmp=tmp->next; 17 21 } 18 22 #ifdef DEBUG_MAP 19 printf("NOT FOUND \n");23 fprintf(stderr, "MAP NOT FOUND in service.c line %i\n", __LINE__); 20 24 #endif 21 25 return false; 22 26 } 23 27 28 /* ************************************************************************* */ 29 24 30 map* getMap(map* m,char *key){ 25 31 map* tmp=m; 26 32 while(tmp!=NULL){ … … 31 37 return NULL; 32 38 } 33 39 40 /* ************************************************************************* */ 41 34 42 void* addToMap(map* m,char* n,char* v){ 35 43 if(hasKey(m,n)==false){ 36 44 map* _cursor=m; … … 44 52 } 45 53 } 46 54 55 /* ************************************************************************* */ 56 47 57 void* _dumpMap(map* t){ 48 58 fprintf(stderr,"[%s] => [%s] \n",t->name,t->value); 49 59 fflush(stderr); -
service_internal.h
80 80 81 81 void addDefaultValues(maps**,elements*,maps*,char*); 82 82 83 /*defined in zoo_loader.c*/ 84 int errorException(maps *m, const char *message, const char *errorcode); 83 85 #ifdef __cplusplus 84 86 } 85 87 #endif -
service.h
49 49 #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+sizeof(maps*) 50 50 51 51 52 static char* mtoupper(c har* str){52 static char* mtoupper(const char* str){ 53 53 char* tmp=strdup(str); 54 54 if(tmp){ 55 55 int cnt=strlen(tmp); … … 111 111 } 112 112 } 113 113 114 static map* createMap(c har* name,char* value){114 static map* createMap(const char* name, const char* value){ 115 115 map* tmp=(map *)malloc(MAP_SIZE); 116 116 tmp->name=strdup(name); 117 117 tmp->value=strdup(value); … … 129 129 return c; 130 130 } 131 131 132 static bool hasKey(map* m,c har *key){132 static bool hasKey(map* m,const char *key){ 133 133 map* tmp=m; 134 134 while(tmp!=NULL){ 135 135 if(strcmp(mtoupper(tmp->name),mtoupper(key))==0) … … 152 152 return NULL; 153 153 } 154 154 155 static map* getMap(map* m,c har *key){155 static map* getMap(map* m,const char *key){ 156 156 map* tmp=m; 157 157 while(tmp!=NULL){ 158 158 if(strcmp(mtoupper(tmp->name),mtoupper(key))==0) … … 357 357 return NULL; 358 358 } 359 359 360 static void* addToMap(map* m,c har* n,char* v){360 static void* addToMap(map* m,const char* n,const char* v){ 361 361 if(hasKey(m,n)==false){ 362 362 map* _cursor=m; 363 363 while(_cursor->next!=NULL) -
zoo_service_loader.c
70 70 #include <time.h> 71 71 #include <stdarg.h> 72 72 73 /* ************************************************************************* */ 74 73 75 xmlNodeSet* extractFromDoc(xmlDocPtr doc,char* search){ 74 76 xmlXPathContextPtr xpathCtx; 75 77 xmlXPathObjectPtr xpathObj; … … 79 81 return xpathObj->nodesetval; 80 82 } 81 83 84 /* ************************************************************************* */ 85 82 86 void sigint_handler(int sig){ 83 87 fprintf(stderr,"Not this time!\n"); 84 88 } 85 89 90 /* ************************************************************************* */ 91 86 92 int runRequest(map* request_inputs) 87 93 { 88 94 … … 94 100 /** 95 101 * Parsing service specfic configuration file 96 102 */ 97 m=(maps*)malloc(MAPS_SIZE); 103 m=(maps*)calloc(1, MAPS_SIZE); 104 if(m == NULL){ 105 return errorException(m, "Unable to allocate memory.", "InternalError"); 106 } 98 107 char ntmp[1024]; 99 108 #ifndef WIN32 100 109 getcwd(ntmp,1024); 101 110 #else 102 111 _getcwd(ntmp,1024); 103 112 #endif 104 char conf_file[1024 ];105 s printf(conf_file,"%s/main.cfg",ntmp);113 char conf_file[10240]; 114 snprintf(conf_file, 10240, "%s/main.cfg",ntmp); 106 115 conf_read(conf_file,m); 107 116 117 #ifdef DEBUG 118 fprintf(stderr, "***** BEGIN MAP\n"); 119 dumpMap(request_inputs); 120 fprintf(stderr, "***** END MAP\n"); 121 #endif 108 122 /** 109 123 * Check for minimum inputs 110 124 */ 111 125 r_inputs=getMap(request_inputs,"Request"); 112 126 if(r_inputs==NULLMAP){ 113 tmps=createMap("text","Parameter <request> was not specified");127 tmps=createMap("text","Parameter <request> was not specified"); 114 128 addToMap(tmps,"code","MissingParameterValue"); 115 129 printExceptionReportResponse(m,tmps); 116 130 return 1; 117 131 } 118 132 else 119 133 REQUEST=strdup(r_inputs->value); 134 120 135 r_inputs=NULL; 121 136 r_inputs=getMap(request_inputs,"Service"); 137 122 138 if(r_inputs==NULLMAP){ 123 139 tmps=createMap("text","Parameter <service> was not specified"); 124 140 addToMap(tmps,"code","MissingParameterValue"); 125 141 printExceptionReportResponse(m,tmps); 126 142 return 1; 127 143 } 128 if(strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0){ 144 145 if(strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))!=0){ 129 146 r_inputs=getMap(request_inputs,"Version"); 130 147 if(r_inputs==NULL){ 131 148 tmps=createMap("text","Parameter <version> was not specified"); … … 139 156 * Need to print std exception message here 140 157 */ 141 158 char SP[1024]; 142 if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)){ 159 160 /*if ((argc < 5 && strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))!=0) || (argc < 4 && strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))==0)){*/ 161 if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)) { 143 162 r_inputs=getMap(request_inputs,"ServiceProvider"); 163 164 #ifdef DEBUG 165 fprintf(stderr, "***** BEGIN MAP\n"); 166 dumpMap(r_inputs); 167 fprintf(stderr, "***** END MAP\n"); 168 #endif 169 144 170 if(r_inputs==NULLMAP){ 145 tmps=createMap("text","Parameter <serviceprovider> was not specified"); 146 addToMap(tmps,"code","MissingParameterValue"); 147 printExceptionReportResponse(m,tmps); 171 errorException(m, "Parameter <serviceprovider> was not specified","MissingParameterValue"); 148 172 return 1; 149 173 } 150 174 else 151 sprintf(SP,"%s",r_inputs->value); 175 snprintf(SP, 1024, "%s",r_inputs->value); 176 152 177 r_inputs=getMap(request_inputs,"MetaPath"); 178 179 #ifdef DEBUG 180 fprintf(stderr, "***** BEGIN MAP\n"); 181 dumpMap(r_inputs); 182 fprintf(stderr, "***** END MAP\n"); 183 #endif 184 153 185 if(r_inputs==NULLMAP){ 154 tmps=createMap("text","Parameter <metapath> was not specified"); 155 addToMap(tmps,"code","MissingParameterValue"); 156 printExceptionReportResponse(m,tmps); 186 errorException(m, "Parameter <metapath> was not specified", "MissingParameterValue"); 157 187 return 1; 158 188 } 159 tmps=createMap("text","Parameter <unknown> was not specified"); 160 addToMap(tmps,"code","MissingParameterValue"); 161 printExceptionReportResponse(m,tmps); 189 errorException(m, "Parameter <unknown> was not specified", "MissingParameterValue"); 162 190 return 1; 163 191 } 164 192 … … 175 203 int scount=0; 176 204 177 205 #ifdef DEBUG 206 fprintf(stderr, "***** BEGIN MAP\n"); 178 207 dumpMap(r_inputs); 208 fprintf(stderr, "***** END MAP\n"); 179 209 #endif 180 210 char conf_dir[1024]; 181 211 int t; 182 212 char tmps1[1024]; 183 213 184 if(str cmp(mtoupper(REQUEST),mtoupper("GetCapabilities"))==0){214 if(strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))==0){ 185 215 int i=0; 186 216 struct dirent *dp; 187 217 r_inputs=NULL; 188 r_inputs=getMap(request_inputs,"metapath"); 218 r_inputs=getMap(request_inputs,"MetaPath"); 219 220 snprintf(conf_dir, 1024, "%s/%s",ntmp,r_inputs->value); 189 221 #ifdef DEBUG 222 fprintf(stderr, "***** BEGIN MAP\n"); 190 223 dumpMap(r_inputs); 224 fprintf(stderr, "***** END MAP\n"); 191 225 #endif 192 sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value); 193 DIR *dirp = opendir(conf_dir); 226 DIR *dirp = opendir(conf_dir); 194 227 if(dirp==NULL){ 195 tmps=createMap("text","The specified path doesn't exist."); 196 addToMap(tmps,"code","InvalidParameterValue"); 197 printExceptionReportResponse(m,tmps); 198 return -1; 228 return errorException(m, "The specified meta path doesn't exist.","InvalidParameterValue"); 199 229 } 230 200 231 xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); 201 232 doc->encoding = xmlCharStrdup ("UTF-8"); 202 233 r_inputs=NULL; … … 208 239 */ 209 240 int saved_stdout = dup(fileno(stdout)); 210 241 dup2(fileno(stderr),fileno(stdout)); 242 211 243 while ((dp = readdir(dirp)) != NULL) 212 244 if(strstr(dp->d_name,".zcfg")!=0){ 213 s printf(tmps1,"%s/%s",conf_dir,dp->d_name);245 snprintf(tmps1, 1024, "%s/%s",conf_dir,dp->d_name); 214 246 char *tmps=tmps1; 215 s1=(service*)malloc(sizeof(service*)); 216 s[0]=(service*)malloc(sizeof(service*)); 247 s1=(service*)calloc(1, sizeof(service)); 248 s[0]=(service*)calloc(1, sizeof(service)); 249 if(s1 == NULL || s[0] == NULL){ 250 return errorException(m, "Unable to allocate memory.","InternalError"); 251 } 217 252 #ifdef DEBUG 218 253 fprintf(stderr,"#################\n%s\n#################\n",tmps1); 219 254 #endif … … 232 267 (void)closedir(dirp); 233 268 fflush(stdout); 234 269 dup2(saved_stdout,fileno(stdout)); 235 236 270 printDocument(doc); 237 271 fflush(stdout); 238 272 xmlFree(n); … … 243 277 if(r_inputs==NULL 244 278 || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){ 245 279 if(r_inputs!=NULL && strlen(r_inputs->value)==0) 246 tmps=createMap("text","Mandatory value for <identifier> was not specified");280 errorException(m, "Mandatory value for <identifier> was not specified","MissingParameterValue"); 247 281 else 248 tmps=createMap("text","Mandatory <identifier> was not specified"); 249 addToMap(tmps,"code","MissingParameterValue"); 250 printExceptionReportResponse(m,tmps); 282 errorException(m, "Mandatory <identifier> was not specified","MissingParameterValue"); 251 283 return 1; 252 284 } 253 285 … … 256 288 struct dirent *dp; 257 289 DIR *dirp = opendir(conf_dir); 258 290 if(dirp==NULL){ 259 tmps=createMap("text","The specified metapath path doesn't exist."); 260 addToMap(tmps,"code","InvalidParameterValue"); 261 printExceptionReportResponse(m,tmps); 262 return -1; 291 return errorException(m, "The specified metapath path doesn't exist.","InvalidParameterValue"); 263 292 } 264 if(str cmp(mtoupper(REQUEST),"DESCRIBEPROCESS")==0){293 if(strncmp(mtoupper(REQUEST),"DESCRIBEPROCESS", strlen(mtoupper(REQUEST)))==0){ 265 294 /** 266 295 * Loop over Identifier list 267 296 */ … … 274 303 n = printDescribeProcessHeader(doc,r_inputs->value,m); 275 304 276 305 r_inputs=getMap(request_inputs,"Identifier"); 306 277 307 char *tmps=strtok(r_inputs->value,","); 278 279 308 char buff[256]; 280 309 char buff1[1024]; 281 310 int i=0; … … 285 314 dup2(fileno(stderr),fileno(stdout)); 286 315 while(tmps){ 287 316 memset(buff,0,256); 288 s printf(buff,"%s.zcfg",tmps);317 snprintf(buff, 256, "%s.zcfg",tmps); 289 318 memset(buff1,0,1024); 290 319 #ifdef DEBUG 291 320 fprintf(stderr,"\n#######%s\n########\n",buff1); … … 293 322 while ((dp = readdir(dirp)) != NULL) 294 323 if(strcmp(dp->d_name,buff)==0){ 295 324 memset(buff1,0,1024); 296 sprintf(buff1,"%s/%s",conf_dir,dp->d_name); 297 s1=(service*)malloc(sizeof(service*)); 298 s[scount]=(service*)malloc(sizeof(service*)); 325 snprintf(buff1, 1024, "%s/%s",conf_dir,dp->d_name); 326 s1=(service*)calloc(1, sizeof(service)); 327 s[scount]=(service*)calloc(1, sizeof(service)); 328 if(s1 == NULL || s[scount] == NULL){ 329 return errorException(m, "Unable to allocate memory.","InternalError"); 330 } 299 331 #ifdef DEBUG 300 332 fprintf(stderr,"#################\n%s\n#################\n",tmps1); 301 333 #endif … … 318 350 fflush(stdout); 319 351 //xmlFree(n); 320 352 #ifndef LINUX_FREE_ISSUE 321 free(s1); 353 if(s1) 354 free(s1); 322 355 #endif 323 356 return 0; 324 357 } 325 358 else 326 if(strcmp(mtoupper(REQUEST),"EXECUTE")!=0){ 327 tmps=createMap("text","Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."); 328 addToMap(tmps,"code","InvalidParameterValue"); 329 printExceptionReportResponse(m,tmps); 359 if(strncmp(mtoupper(REQUEST),"EXECUTE", strlen(mtoupper(REQUEST)))!=0){ 360 errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue"); 330 361 #ifdef DEBUG 331 362 fprintf(stderr,"No request found %s",REQUEST); 332 363 #endif … … 336 367 } 337 368 338 369 s1=NULL; 339 s1=(service*)malloc(sizeof(service*)); 340 s[0]=(service*)malloc(sizeof(service*)); 370 s1=(service*)calloc(1, sizeof(service)); 371 s[0]=(service*)calloc(1, sizeof(service)); 372 if(s1 == NULL || s[0] == NULL){ 373 return errorException(m, "Unable to allocate memory.","InternalError"); 374 } 375 341 376 r_inputs=getMap(request_inputs,"MetaPath"); 342 sprintf(tmps1,"%s/%s",ntmp,r_inputs->value); 377 snprintf(tmps1, 1024, "%s/%s",ntmp,r_inputs->value); 378 343 379 r_inputs=getMap(request_inputs,"Identifier"); 380 snprintf(tmps1, 1024, "%s/%s.zcfg",strdup(tmps1),r_inputs->value); 344 381 345 sprintf(tmps1,"%s/%s.zcfg",strdup(tmps1),r_inputs->value);346 347 382 #ifdef DEBUG 348 383 fprintf(stderr,"Trying to load %s\n", tmps1); 349 384 #endif … … 352 387 t=getServiceFromFile(tmps1,&s1); 353 388 fflush(stdout); 354 389 dup2(saved_stdout,fileno(stdout)); 390 /*What is 22 ????*/ 355 391 if(t==22){ 356 tmps=createMap("text","The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request."); 357 addToMap(tmps,"code","InvalidParameterValue"); 358 printExceptionReportResponse(m,tmps); 392 errorException(m, "The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.", "InvalidParameterValue"); 359 393 exit(0); 360 394 } 361 395 s[0]=s1; … … 409 443 #endif 410 444 char current_output_as_string[10240]; 411 445 char cursor_output[10240]; 412 s printf(cursor_output,"%s",strdup(r_inputs->value));446 snprintf(cursor_output, 10240, "%s",strdup(r_inputs->value)); 413 447 j=0; 414 448 map* request_kvp_outputs=NULL; 415 449 … … 422 456 fprintf(stderr,"OUTPUT [%s]\n",cursor_output); 423 457 #endif 424 458 pToken=strtok(cursor_output,";"); 425 char** outputs_as_text=(char**)malloc(128*sizeof(char*)); 459 char** outputs_as_text=(char**)calloc(128, sizeof(char*)); 460 if(outputs_as_text == NULL) { 461 return errorException(m, "Unaböe to allocate memory", "InternalError"); 462 } 426 463 i=0; 427 464 while(pToken!=NULL){ 428 465 #ifdef DEBUG … … 430 467 fflush(stderr); 431 468 fprintf(stderr,"***%s***\n",pToken); 432 469 #endif 433 outputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char)); 434 sprintf(outputs_as_text[i],"%s",pToken); 470 outputs_as_text[i]=(char*)calloc(strlen(pToken), sizeof(char)); 471 if(outputs_as_text[i] == NULL) { 472 return errorException(m, "Unable to allocate memory", "InternalError"); 473 } 474 snprintf(outputs_as_text[i], strlen(pToken), "%s",pToken); 435 475 pToken = strtok(NULL,";"); 436 476 i++; 437 477 } … … 443 483 while(tmpc!=NULL){ 444 484 if(k==0){ 445 485 if(tmp_output==NULL){ 446 tmp_output=(maps*)malloc(MAPS_SIZE); 486 tmp_output=(maps*)calloc(1, MAPS_SIZE); 487 if(tmp_output == NULL){ 488 return errorException(m, "Unable to allocate memory.", "InternalError"); 489 } 447 490 tmp_output->name=strdup(tmpc); 448 491 tmp_output->content=NULL; 449 492 tmp_output->next=NULL; … … 493 536 #endif 494 537 char current_input_as_string[40960]; 495 538 char cursor_input[40960]; 496 s printf(cursor_input,"%s",strdup(r_inputs->value));539 snprintf(cursor_input, 40960, "%s",strdup(r_inputs->value)); 497 540 j=0; 498 541 map* request_kvp_inputs=NULL; 499 542 … … 502 545 */ 503 546 char * pToken; 504 547 pToken=strtok(cursor_input,";"); 505 char** inputs_as_text=(char**)malloc(100*sizeof(char*)); 548 char** inputs_as_text=(char**)calloc(100,sizeof(char*)); 549 if(inputs_as_text == NULL){ 550 return errorException(m, "Unable to allocate memory.", "InternalError"); 551 } 506 552 i=0; 507 553 while(pToken!=NULL){ 508 554 #ifdef DEBUG … … 512 558 #ifdef DEBUG 513 559 fprintf(stderr,"***%s***\n",pToken); 514 560 #endif 515 inputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char)); 516 sprintf(inputs_as_text[i],"%s",pToken); 561 inputs_as_text[i]=(char*)calloc(strlen(pToken),sizeof(char)); 562 if(inputs_as_text[i] == NULL){ 563 return errorException(m, "Unable to allocate memory.", "InternalError"); 564 } 565 snprintf(inputs_as_text[i], strlen(pToken), "%s",pToken); 517 566 pToken = strtok(NULL,";"); 518 567 i++; 519 568 } … … 536 585 fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1); 537 586 #endif 538 587 if(tmpmaps==NULL){ 539 tmpmaps=(maps*)malloc(MAPS_SIZE); 588 tmpmaps=(maps*)calloc(1, MAPS_SIZE); 589 if(tmpmaps == NULL){ 590 return errorException(m, "Unable to allocate memory.", "InternalError"); 591 } 540 592 tmpmaps->name=strdup(tmpn); 541 593 tmpmaps->content=createMap("value",tmpv+1); 542 594 tmpmaps->next=NULL; … … 574 626 fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n", 575 627 tmpv1+1,res.nDataAlloc,res.nDataLen); 576 628 #endif 577 char* tmpContent=(char*)malloc((res.nDataLen+1)*sizeof(char)); 629 char* tmpContent=(char*)calloc((res.nDataLen+1), sizeof(char)); 630 if(tmpContent == NULL){ 631 return errorException(m, "Unable to allocate memory.", "InternalError"); 632 } 578 633 size_t dwRead; 579 634 InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead); 580 635 map* tmpMap=getMap(tmpmaps->content,"value"); … … 646 701 xmlChar *val= 647 702 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 648 703 if(tmpmaps==NULL){ 649 tmpmaps=(maps*)malloc(MAPS_SIZE); 704 tmpmaps=(maps*)calloc(1, MAPS_SIZE); 705 if(tmpmaps == NULL){ 706 return errorException(m, "Unable to allocate memory.", "InternalError"); 707 } 650 708 tmpmaps->name=strdup((char*)val); 651 709 tmpmaps->content=NULL; 652 710 tmpmaps->next=NULL; … … 663 721 xmlChar *val= 664 722 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 665 723 if(tmpmaps==NULL){ 666 tmpmaps=(maps*)malloc(MAPS_SIZE); 724 tmpmaps=(maps*)calloc(1, MAPS_SIZE); 725 if(tmpmaps == NULL){ 726 return errorException(m, "Unable to allocate memory.", "InternalError"); 727 } 667 728 tmpmaps->name="missingIndetifier"; 668 729 tmpmaps->content=createMap((char*)cur2->name,(char*)val); 669 730 tmpmaps->next=NULL; … … 718 779 && CHECK_INET_HANDLE(hInternet)){ 719 780 res=InternetOpenUrl(hInternet,(char*)val,NULL,0, 720 781 INTERNET_FLAG_NO_CACHE_WRITE,0); 721 char* tmpContent= 722 (char*)malloc((res.nDataLen+1)*sizeof(char)); 782 char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char)); 783 if(tmpContent == NULL){ 784 return errorException(m, "Unable to allocate memory.", "InternalError"); 785 } 723 786 size_t dwRead; 724 787 InternetReadFile(res, (LPVOID)tmpContent, 725 788 res.nDataLen, &dwRead); … … 755 818 fprintf(stderr,"%s = %s\n",ha[hai],(char*)val); 756 819 #endif 757 820 if(hai==0){ 758 key=(char*)malloc((1+strlen((char*)val))*sizeof(char)); 759 sprintf(key,"%s",(char*)val); 821 key=(char*)calloc((1+strlen((char*)val)), sizeof(char)); 822 if(key == NULL){ 823 return errorException(m, "Unable to allocate memory.", "InternalError"); 824 } 825 snprintf(key, (1+strlen((char*)val)), "%s",(char*)val); 760 826 }else{ 761 has=(char*)malloc((3+strlen((char*)val)+strlen(key))*sizeof(char)); 762 sprintf(has,"%s: %s",key,(char*)val); 827 has=(char*)calloc((3+strlen((char*)val)+strlen(key)), sizeof(char)); 828 if(has == NULL){ 829 return errorException(m, "Unable to allocate memory.", "InternalError"); 830 } 831 snprintf(has,(3+strlen((char*)val)+strlen(key)), "%s: %s",key,(char*)val); 763 832 #ifdef POST_DEBUG 764 833 fprintf(stderr,"%s\n",has); 765 834 #endif … … 772 841 #ifdef POST_DEBUG 773 842 fprintf(stderr,"Try to fetch the body part of the request ...\n"); 774 843 #endif 775 if(str cmp(mtoupper((char*)cur3->name),mtoupper("Body"))==0 ){844 if(strncmp(mtoupper((char*)cur3->name),mtoupper("Body"), strlen(mtoupper((char*)cur3->name)))==0 ){ 776 845 #ifdef POST_DEBUG 777 846 fprintf(stderr,"Body part found !!!\n",(char*)cur3->content); 778 847 #endif … … 802 871 #endif 803 872 res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp), 804 873 INTERNET_FLAG_NO_CACHE_WRITE,0); 805 char* tmpContent= 806 (char*)malloc((res.nDataLen+1)*sizeof(char)); 874 char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char)); 875 if(tmpContent == NULL){ 876 return errorException(m, "Unable to allocate memory.", "InternalError"); 877 } 807 878 size_t dwRead; 808 879 InternetReadFile(res, (LPVOID)tmpContent, 809 880 res.nDataLen, &dwRead); … … 834 905 #endif 835 906 res1=InternetOpenUrl(bInternet,(char*)val,NULL,0, 836 907 INTERNET_FLAG_NO_CACHE_WRITE,0); 837 char* tmp= 838 (char*)malloc((res1.nDataLen+1)*sizeof(char)); 908 char* tmp= (char*)calloc((res1.nDataLen+1), sizeof(char)); 909 if(tmp == NULL){ 910 return errorException(m, "Unable to allocate memory.", "InternalError"); 911 } 839 912 size_t bRead; 840 913 InternetReadFile(res1, (LPVOID)tmp, 841 914 res1.nDataLen, &bRead); … … 850 923 res=InternetOpenUrl(hInternet,btmp->value,tmp, 851 924 strlen(tmp), 852 925 INTERNET_FLAG_NO_CACHE_WRITE,0); 853 char* tmpContent= 854 (char*)malloc((res.nDataLen+1)*sizeof(char)); 926 char* tmpContent= (char*)calloc((res.nDataLen+1),sizeof(char)); 927 if(tmpContent == NULL){ 928 return errorException(m, "Unable to allocate memory.", "InternalError"); 929 } 855 930 size_t dwRead; 856 931 InternetReadFile(res, (LPVOID)tmpContent, 857 932 res.nDataLen, &dwRead); … … 1020 1095 * A specific responseDocument node. 1021 1096 */ 1022 1097 if(tmpmaps==NULL){ 1023 tmpmaps=(maps*)malloc(MAPS_SIZE); 1098 tmpmaps=(maps*)calloc(1, MAPS_SIZE); 1099 if(tmpmaps == NULL){ 1100 return errorException(m, "Unable to allocate memory.", "InternalError"); 1101 } 1024 1102 tmpmaps->name="unknownIdentifier"; 1025 1103 tmpmaps->next=NULL; 1026 1104 } … … 1091 1169 xmlChar *val= 1092 1170 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 1093 1171 if(tmpmaps==NULL){ 1094 tmpmaps=(maps*)malloc(MAPS_SIZE); 1172 tmpmaps=(maps*)calloc(1, MAPS_SIZE); 1173 if(tmpmaps == NULL){ 1174 return errorException(m, "Unable to allocate memory.", "InternalError"); 1175 } 1095 1176 tmpmaps->name=strdup((char*)val); 1096 1177 tmpmaps->content=NULL; 1097 1178 tmpmaps->next=NULL; … … 1110 1191 xmlChar *val= 1111 1192 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 1112 1193 if(tmpmaps==NULL){ 1113 tmpmaps=(maps*)malloc(MAPS_SIZE); 1194 tmpmaps=(maps*)calloc(1, MAPS_SIZE); 1195 if(tmpmaps == NULL){ 1196 return errorException(m, "Unable to allocate memory.", "InternalError"); 1197 } 1114 1198 tmpmaps->name="missingIndetifier"; 1115 1199 tmpmaps->content=createMap((char*)cur2->name,(char*)val); 1116 1200 tmpmaps->next=NULL; … … 1166 1250 val=xmlGetProp(cur1,BAD_CAST outs[l]); 1167 1251 if(val!=NULL && strlen((char*)val)>0){ 1168 1252 if(tmpmaps==NULL){ 1169 tmpmaps=(maps*)malloc(MAPS_SIZE); 1253 tmpmaps=(maps*)calloc(1, MAPS_SIZE); 1254 if(tmpmaps == NULL){ 1255 return errorException(m, "Unable to allocate memory.", "InternalError"); 1256 } 1170 1257 tmpmaps->name="unknownIdentifier"; 1171 1258 tmpmaps->content=createMap(outs[l],(char*)val); 1172 1259 tmpmaps->next=NULL; … … 1190 1277 val= 1191 1278 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1); 1192 1279 if(tmpmaps==NULL){ 1193 tmpmaps=(maps*)malloc(MAPS_SIZE); 1280 tmpmaps=(maps*)calloc(1, MAPS_SIZE); 1281 if(tmpmaps == NULL){ 1282 return errorException(m, "Unable to allocate memory.", "InternalError"); 1283 } 1194 1284 tmpmaps->name=strdup((char*)val); 1195 1285 tmpmaps->content=NULL; 1196 1286 tmpmaps->next=NULL; … … 1221 1311 fprintf(stderr,"\n%i\n",i); 1222 1312 dumpMaps(request_input_real_format); 1223 1313 dumpMaps(request_output_real_format); 1224 dumpElements();1225 1314 #endif 1226 1315 1227 1316 /** -
service_conf.l
123 123 chardata [^<]* 124 124 /*====================================================*/ 125 125 attname [a-zA-Z0-9_\-]+ 126 attvalue1 [ a-zA-Z0-9_\-.:" "\"\'/\\\(\)]+126 attvalue1 [=,;@a-zA-Z0-9_\-::.:" "\"\'/\\\(\)]+ 127 127 128 128 129 129 -
service_internal.c
24 24 25 25 #include "service_internal.h" 26 26 27 /* ************************************************************************* */ 28 27 29 /* Converts a hex character to its integer value */ 28 30 char from_hex(char ch) { 29 31 return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; 30 32 } 31 33 34 /* ************************************************************************* */ 35 32 36 /* Converts an integer value to its hex character*/ 33 37 char to_hex(char code) { 34 38 static char hex[] = "0123456789abcdef"; 35 39 return hex[code & 15]; 36 40 } 37 41 42 /* ************************************************************************* */ 43 38 44 /* Returns a url-encoded version of str */ 39 45 /* IMPORTANT: be sure to free() the returned string after use */ 40 46 char *url_encode(char *str) { … … 52 58 return buf; 53 59 } 54 60 61 /* ************************************************************************* */ 62 55 63 /* Returns a url-decoded version of str */ 56 64 /* IMPORTANT: be sure to free() the returned string after use */ 57 65 char *url_decode(char *str) { … … 74 82 } 75 83 76 84 85 /* ************************************************************************* */ 86 77 87 void printProcessResponse1(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){ 78 88 if(getpid()==pid) 79 89 printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); … … 253 263 254 264 } 255 265 266 /* ************************************************************************* */ 256 267 257 268 void printProcessResponse(maps* m,int pid,service* serv,char* service,int status,map* inputs,map* outputs){ 258 269 … … 381 392 nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions"); 382 393 mcursor=outputs; 383 394 scursor=serv->outputs; 395 #ifdef DEBUG 384 396 //dumpMap(mcursor); 397 #endif 385 398 while(mcursor!=NULL && scursor!=NULL){ 386 399 //xmlAddChild(nc,xmlNewComment(BAD_CAST "Here we need to check for output format from metadata")); 387 400 printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); … … 422 435 423 436 } 424 437 438 /* ************************************************************************* */ 425 439 426 440 void printGetCapabilitiesResponse(service** serv,int sc,char* service,maps* m){ 427 441 … … 729 743 730 744 } 731 745 746 /* ************************************************************************* */ 747 732 748 xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,char* service,maps* m){ 733 749 734 750 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; … … 969 985 nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings"); 970 986 xmlAddChild(n,nc); 971 987 972 973 974 988 nc1 = xmlNewNode(ns, BAD_CAST "Languages"); 975 989 nc2 = xmlNewNode(ns, BAD_CAST "Default"); 976 990 nc3 = xmlNewNode(ns, BAD_CAST "Supported"); … … 1020 1034 return nc; 1021 1035 } 1022 1036 1037 /* ************************************************************************* */ 1038 1023 1039 void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){ 1024 1040 1025 1041 xmlNsPtr ns,ns_ows; … … 1087 1103 xmlFree(xmlbuff); 1088 1104 1089 1105 } 1090 1091 1106 1107 /* ************************************************************************* */ 1108 1092 1109 void printDescribeProcessResponse(service* serv,char* service){ 1093 1110 1094 1111 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; … … 1363 1380 1364 1381 } 1365 1382 1383 /* ************************************************************************* */ 1384 1366 1385 xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){ 1367 1386 1368 1387 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; … … 1394 1413 return n; 1395 1414 } 1396 1415 1416 /* ************************************************************************* */ 1417 1397 1418 void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service** serv,int sc){ 1398 1419 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; 1399 1420 xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; … … 1672 1693 1673 1694 } 1674 1695 1696 /* ************************************************************************* */ 1697 1675 1698 void printDescribeProcessDocument(xmlDocPtr doc){ 1676 1699 xmlChar *xmlbuff; 1677 1700 int buffersize; … … 1691 1714 } 1692 1715 //printGetCapabilitiesHeader 1693 1716 1717 /* ************************************************************************* */ 1718 1694 1719 void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){ 1695 1720 xmlNodePtr nc1; 1696 1721 nc1=xmlNewNode(ns_wps, BAD_CAST type); … … 1723 1748 1724 1749 } 1725 1750 1751 /* ************************************************************************* */ 1752 1726 1753 void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){ 1727 1754 xmlNodePtr nc1,nc2,nc3; 1728 1755 nc1=xmlNewNode(ns_wps, BAD_CAST type); … … 1751 1778 1752 1779 } 1753 1780 1781 /* ************************************************************************* */ 1782 1754 1783 void printIOType1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){ 1755 1784 xmlNodePtr nc1,nc2,nc3; 1756 1785 nc1=xmlNewNode(ns_wps, BAD_CAST type); … … 1820 1849 1821 1850 } 1822 1851 1852 /* ************************************************************************* */ 1853 1823 1854 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){ 1824 1855 xmlNodePtr nc1,nc2,nc3; 1825 1856 nc1=xmlNewNode(ns_wps, BAD_CAST type); … … 1864 1895 1865 1896 } 1866 1897 1898 /* ************************************************************************* */ 1899 1867 1900 void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,char* identifier,map* amap){ 1868 1901 xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); 1869 1902 xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); … … 1883 1916 } 1884 1917 } 1885 1918 1919 /* ************************************************************************* */ 1920 1886 1921 void printExceptionReportResponse(maps* m,map* s){ 1887 1922 1888 1923 printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); … … 1959 1994 xmlFree(doc); 1960 1995 } 1961 1996 1997 /* ************************************************************************* */ 1962 1998 1963 1999 void outputResponse(service* s,maps* request_inputs,maps* request_outputs, 1964 2000 map* request_inputs1,int cpid,maps* m,int res){ … … 2022 2058 } 2023 2059 } 2024 2060 2061 /* ************************************************************************* */ 2062 2025 2063 char *base64(const unsigned char *input, int length) 2026 2064 { 2027 2065 BIO *bmem, *b64; … … 2044 2082 return buff; 2045 2083 } 2046 2084 2085 /* ************************************************************************* */ 2086 2047 2087 void addDefaultValues(maps** out,elements* in,maps* m,char* type){ 2048 2088 elements* tmpInputs=in; 2049 2089 maps* out1=*out; … … 2073 2113 if(tmpMap==NULL) 2074 2114 addToMap(tmpMaps->content,"value","NULL"); 2075 2115 tmpMaps->next=NULL; 2116 #ifdef DEBUG 2076 2117 dumpMaps(tmpMaps); 2118 #endif 2077 2119 if(out1==NULL){ 2078 2120 out1=(maps*)malloc(MAPS_SIZE); 2079 2121 out1->name=tmpMaps->name; -
service_internal_python.c
24 24 25 25 #include "service_internal_python.h" 26 26 27 /* ************************************************************************* */ 28 27 29 int python_support(maps* m,service* s,int argc,char** argv,map *inputs,map *outputs){ 28 30 Py_Initialize(); 29 31 PyObject *pName, *pModule, *pFunc; … … 135 137 return 2; 136 138 } 137 139 140 /* ************************************************************************* */ 141 138 142 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ 139 143 maps* m=*main_conf; 140 144 maps* inputs=*real_inputs; … … 286 290 return res; 287 291 } 288 292 293 /* ************************************************************************* */ 294 289 295 PyDictObject* PyDict_FromMaps(maps* t){ 290 296 PyObject* res=PyDict_New( ); 291 297 maps* tmp=t; … … 299 305 return (PyDictObject*) res; 300 306 } 301 307 308 /* ************************************************************************* */ 309 302 310 PyDictObject* PyDict_FromMap(map* t){ 303 311 PyObject* res=PyDict_New( ); 304 312 map* tmp=t; … … 312 320 return (PyDictObject*) res; 313 321 } 314 322 323 /* ************************************************************************* */ 324 315 325 maps* mapsFromPyDict(PyDictObject* t){ 316 326 maps* res=NULL; 317 327 maps* cursor=res; … … 350 360 return res; 351 361 } 352 362 363 /* ************************************************************************* */ 364 353 365 map* mapFromPyDict(PyDictObject* t){ 354 366 map* res=NULL; 355 367 PyObject* list=PyDict_Keys((PyObject*)t); -
zoo_loader.c
26 26 * Specific includes 27 27 */ 28 28 #include "fcgio.h" 29 #include "fcgi_config.h" 29 #include "fcgi_config.h" 30 30 #include "fcgi_stdio.h" 31 31 #include <sys/types.h> 32 32 #include <unistd.h> 33 extern "C" { 33 #include "service_internal.h" 34 35 extern "C" 36 { 34 37 #include "cgic.h" 35 }36 37 #include "service_internal.h"38 extern "C" {39 38 #include <libxml/tree.h> 40 39 #include <libxml/xmlmemory.h> 41 40 #include <libxml/parser.h> … … 43 42 #include <libxml/xpathInternals.h> 44 43 } 45 44 45 xmlNodeSet *extractFromDoc (xmlDocPtr, char *); 46 int runRequest (map *); 47 48 using namespace std; 49 50 /* ************************************************************************* */ 51 52 int errorException(maps *m, const char *message, const char *errorcode) 53 { 54 map * errormap = createMap("text", message); 55 addToMap(errormap,"code", errorcode); 56 printExceptionReportResponse(m,errormap); 57 return -1; 58 } 59 60 /* ************************************************************************* */ 61 46 62 #ifndef STRTOK_R 47 63 char * 48 strtok_r (char *s1, const char *s2, char **lasts)64 strtok_r (char *s1, const char *s2, char **lasts) 49 65 { 50 66 char *ret; 51 67 52 68 if (s1 == NULL) 53 69 s1 = *lasts; 54 while (*s1 && strchr(s2, *s1))70 while (*s1 && strchr (s2, *s1)) 55 71 ++s1; 56 if (*s1 == '\0')72 if (*s1 == '\0') 57 73 return NULL; 58 74 ret = s1; 59 while (*s1 && !strchr(s2, *s1))75 while (*s1 && !strchr (s2, *s1)) 60 76 ++s1; 61 if (*s1)77 if (*s1) 62 78 *s1++ = '\0'; 63 79 *lasts = s1; 64 80 return ret; … … 66 82 67 83 #endif 68 84 69 xmlNodeSet* extractFromDoc(xmlDocPtr,char*); 70 int runRequest(map*); 85 /* ************************************************************************* */ 71 86 72 using namespace std; 73 74 char* strtoupper(char* str) 87 char * 88 strtoupper (char *str) 75 89 { 76 int leng =strlen(str);77 for (int i=0; i<leng; i++)78 if (97 <=str[i]&&str[i]<=122)//a-z79 str[i] -=32;90 int leng = strlen (str); 91 for (int i = 0; i < leng; i++) 92 if (97 <= str[i] && str[i] <= 122) //a-z 93 str[i] -= 32; 80 94 return str; 81 95 } 82 96 83 char* strtolower(char* str) 97 /* ************************************************************************* */ 98 99 char * 100 strtolower (char *str) 84 101 { 85 int leng =strlen(str);86 for (int i=0; i<leng; i++)87 if (65 <=str[i]&&str[i]<=90)//A-Z88 str[i] +=32;102 int leng = strlen (str); 103 for (int i = 0; i < leng; i++) 104 if (65 <= str[i] && str[i] <= 90) //A-Z 105 str[i] += 32; 89 106 return str; 90 107 } 91 108 92 char* remplace(char* delim,char* rep,char* source){ 93 if(strcmp(source,"")==0){ 94 #ifdef DEBUG 95 //char *tmp="RETURN NULL !\n"; 96 //printf((void*)tmp); 97 #endif 98 return "NULL"; 99 } 109 /* ************************************************************************* */ 100 110 101 char *_token; 102 char *origin=strdup(source); 103 char result[1024]=""; 104 _token = strtok(source, delim); 111 char * 112 remplace (char *delim, char *rep, char *source) 113 { 114 if (strcmp (source, "") == 0) 115 { 116 return "NULL"; 117 } 118 119 char *_token; 120 char *origin = strdup (source); 121 char result[1024] = ""; 122 _token = strtok (source, delim); 105 123 #ifdef DEBUG 106 fprintf(stderr,"\nREPLACE TOKEN (%s == %s => %d)\n ",_token,origin,strcmp(_token,origin)); 124 fprintf (stderr, "\nREPLACE TOKEN (%s == %s => %d)\n ", _token, origin, 125 strcmp (_token, origin)); 107 126 #endif 108 if(strcmp(_token,origin)!=0) 109 while(_token!=NULL){ 110 sprintf(result,"%s%s%s",result,_token,rep); 111 _token = strtok (NULL, delim); 112 if(_token==NULL) 113 result[strlen(result)-strlen(rep)]=0; 127 if (strcmp (_token, origin) != 0) 128 while (_token != NULL) 129 { 130 snprintf (result, 1024, "%s%s%s", result, _token, rep); 131 _token = strtok (NULL, delim); 132 if (_token == NULL) 133 result[strlen (result) - strlen (rep)] = 0; 114 134 #ifdef DEBUG 115 fprintf(stderr,"\n\nRESULT(%s)\n\n",result);135 fprintf (stderr, "\n\nRESULT(%s)\n\n", result); 116 136 #endif 117 }137 } 118 138 else 119 139 return origin; 120 121 return strdup (result);140 141 return strdup (result); 122 142 } 123 143 124 144 145 /* ************************************************************************* */ 146 125 147 char *colors[] = { 126 148 "red", "green", "blue" 127 149 }; … … 129 151 #define colorsTotal 3 130 152 #define TRUE -1 131 153 #define FALSE -1 132 static bool started =FALSE;133 static bool isStarted =FALSE;154 static bool started = FALSE; 155 static bool isStarted = FALSE; 134 156 135 int cgiMain(){ 157 /* ************************************************************************* */ 158 159 int 160 cgiMain () 161 { 136 162 /** 137 163 * We'll use cgiOut as the default output (stdout) to produce plain text 138 164 * response. 139 165 */ 140 dup2 (fileno(cgiOut),fileno(stdout));166 dup2 (fileno (cgiOut), fileno (stderr)); 141 167 #ifdef DEBUG 142 fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 143 fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n"); 144 fflush(cgiOut); 168 fprintf (cgiOut, 169 "Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 170 fprintf (cgiOut, "Welcome on ZOO verbose debuging mode \r\n\r\n"); 171 fflush (cgiOut); 145 172 #endif 146 147 173 /** 148 174 * Read the main configuration file 149 175 */ 150 if(!isStarted){ 151 maps* m; 152 m=(maps*)malloc(sizeof(maps*)); 153 conf_read("main.cfg",m); 176 #ifdef DEBUG 177 fprintf (stderr, "Read main config file\n"); 178 #endif 179 180 if (!isStarted) 181 { 182 maps *m = NULL; 183 m = (maps *) calloc (1, sizeof (maps)); 184 if (m == NULL) 185 { 186 fprintf (stderr, "Unable to allocate memory for map in zoo_loader.c line %i", __LINE__); 187 return -1; 188 } 189 conf_read ("main.cfg", m); 154 190 #ifdef REAL_FCGI 155 191 #ifdef DEBUG 156 printf("ok passed");157 #endif 158 #endif 159 isStarted=TRUE;160 }192 printf ("ok passed"); 193 #endif 194 #endif 195 isStarted = TRUE; 196 } 161 197 162 198 #ifdef DEBUG 163 char textb[23];164 sprintf(textb,"\n%s\n%s\n",cgiRemoteAddr,cgiRequestMethod);165 fprintf (stderr,"****%s\n%s\n***",textb,cgiQueryString);199 fprintf (stderr, "Addr:%s\n", cgiRemoteAddr); 200 fprintf (stderr, "RequestMethod:%s\n", cgiRequestMethod); 201 fprintf (stderr, "Request: %s\n", cgiQueryString); 166 202 #endif 167 203 168 map* tmp=NULL; 169 170 if(strncmp(cgiContentType,"text/xml",8)==0){ 171 char *buffer=new char[cgiContentLength]; 172 if(fread(buffer,1,cgiContentLength,cgiIn)){ 173 buffer[cgiContentLength]=0; 174 tmp=createMap("request",buffer); 175 }else{ 176 /* Here we have to return an error message ... */ 177 return 1; 178 } 179 } 180 else{ 181 char **array, **arrayStep; 182 if (cgiFormEntries(&array) != cgiFormSuccess) { 183 return 1; 184 } 185 arrayStep = array; 186 while (*arrayStep) { 187 char *value=new char[cgiContentLength]; 188 cgiFormStringNoNewlines(*arrayStep, value, cgiContentLength); 204 map *tmpMap = NULL; 205 206 if (strncmp (cgiContentType, "text/xml", 8) == 0) 207 { 189 208 #ifdef DEBUG 190 fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);209 fprintf (stderr, "XML Request\n"); 191 210 #endif 192 if(tmp!=NULL) 193 addToMap(tmp,*arrayStep,value); 211 char *buffer = new char[cgiContentLength]; 212 if (fread (buffer, 1, cgiContentLength, cgiIn)) 213 { 214 buffer[cgiContentLength] = 0; 215 tmpMap = createMap ("request", buffer); 216 } 194 217 else 195 tmp=createMap(*arrayStep,value); 196 arrayStep++; 218 { 219 fprintf(stderr, "Unable to read cgi content in zoo_loader.c line %i\n", __LINE__); 220 return -1; 221 } 222 delete[]buffer; 197 223 } 198 cgiStringArrayFree(array); 199 } 224 else 225 { 226 #ifdef DEBUG 227 fprintf (stderr, "Key-Value Request\n"); 228 #endif 229 char **array, **arrayStep; 230 if (cgiFormEntries (&array) != cgiFormSuccess) 231 { 232 return 1; 233 } 234 arrayStep = array; 235 while (*arrayStep) 236 { 237 char *value = new char[cgiContentLength]; 238 cgiFormStringNoNewlines (*arrayStep, value, cgiContentLength); 239 #ifdef DEBUG 240 fprintf (stderr, "(( %s = %s ))", *arrayStep, value); 241 #endif 242 if (tmpMap != NULL) 243 addToMap (tmpMap, *arrayStep, value); 244 else 245 tmpMap = createMap (*arrayStep, value); 246 arrayStep++; 247 delete[]value; 248 } 249 cgiStringArrayFree (array); 250 } 200 251 252 #ifdef DEBUG 253 fprintf (stderr, "\nChecking request method: %s", cgiRequestMethod); 254 #endif 255 201 256 /** 202 257 * In case that the POST method was used, then check if params came in XML 203 258 * format (attribute request should be the once). 204 259 */ 205 if(strcmp(cgiRequestMethod,mtoupper("post"))==0 && count(tmp)==1){ 260 if (strncmp (cgiRequestMethod, mtoupper ("post"), 4) == 0 && tmpMap != NULL 261 && count (tmpMap) == 1) 262 { 206 263 /** 207 264 * First include the MetaPath and the ServiceProvider default parameters 208 265 * (which should be always available in GET params so in cgiQueryString) 209 266 */ 210 char *saveptr1, *saveptr2; 211 char *str1, *str2, *token, *subtoken; 212 str1=cgiQueryString; 213 token=strtok_r(str1,"&",&saveptr1); 214 while(token!=NULL){ 267 char *saveptr1, *saveptr2; 268 char *str1, *str2, *token, *subtoken; 269 str1 = cgiQueryString; 270 token = strtok_r (str1, "&", &saveptr1); 271 while (token != NULL) 272 { 215 273 #ifdef DEBUG 216 fprintf(stderr,"%s",token);274 fprintf (stderr, "%s", token); 217 275 #endif 218 str2=token;219 subtoken=strtok_r(str2,"=",&saveptr2);276 str2 = token; 277 subtoken = strtok_r (str2, "=", &saveptr2); 220 278 #ifdef DEBUG 221 fprintf(stderr,"%s\n",subtoken);279 fprintf (stderr, "%s\n", subtoken); 222 280 #endif 223 char* tmp_name; 224 if(subtoken!=NULL){ 225 tmp_name=subtoken; 281 char *tmp_name; 282 if (subtoken != NULL) 283 { 284 tmp_name = subtoken; 226 285 #ifdef DEBUG 227 fprintf(stderr,"%s",subtoken);286 fprintf (stderr, "%s", subtoken); 228 287 #endif 229 subtoken=strtok_r(NULL,"=",&saveptr2);230 if(subtoken!=NULL)231 addToMap(tmp,tmp_name,subtoken);232 else233 addToMap(tmp,tmp_name,"");234 235 token=strtok_r(NULL,"&",&saveptr1);236 288 subtoken = strtok_r (NULL, "=", &saveptr2); 289 if (subtoken != NULL) 290 addToMap (tmpMap, tmp_name, subtoken); 291 else 292 addToMap (tmpMap, tmp_name, ""); 293 } 294 token = strtok_r (NULL, "&", &saveptr1); 295 } 237 296 /** 238 297 * Store the original XML request in xrequest map 239 298 */ 240 map* t1=getMap(tmp,"request"); 241 if(t1!=NULL){ 242 addToMap(tmp,"xrequest",t1->value); 243 xmlInitParser(); 244 xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength); 245 xmlNodePtr cur = xmlDocGetRootElement(doc); 246 char *tval; 247 tval=NULL; 248 tval = (char*) xmlGetProp(cur,BAD_CAST "service"); 249 if(tval!=NULL) 250 addToMap(tmp,"service",tval); 251 tval=NULL; 252 tval = (char*) xmlGetProp(cur,BAD_CAST "language"); 253 if(tval!=NULL) 254 addToMap(tmp,"language",tval); 255 256 char* requests[3]; 257 requests[0]="GetCapabilities"; 258 requests[1]="DescribeProcess"; 259 requests[2]="Execute"; 260 for(int j=0;j<3;j++){ 261 char tt[35]; 262 sprintf(tt,"/*[local-name()='%s']",requests[j]); 263 xmlNodeSet* req=extractFromDoc(doc,tt); 299 map *t1 = getMap (tmpMap, "request"); 300 if (t1 != NULL) 301 { 302 addToMap (tmpMap, "xrequest", t1->value); 303 xmlInitParser (); 304 xmlDocPtr doc = xmlParseMemory (t1->value, cgiContentLength); 305 xmlNodePtr cur = xmlDocGetRootElement (doc); 306 char *tval; 307 tval = NULL; 308 tval = (char *) xmlGetProp (cur, BAD_CAST "service"); 309 if (tval != NULL) 310 addToMap (tmpMap, "service", tval); 311 tval = NULL; 312 tval = (char *) xmlGetProp (cur, BAD_CAST "language"); 313 if (tval != NULL) 314 addToMap (tmpMap, "language", tval); 315 316 char *requests[3]; 317 requests[0] = "GetCapabilities"; 318 requests[1] = "DescribeProcess"; 319 requests[2] = "Execute"; 320 for (int j = 0; j < 3; j++) 321 { 322 char tt[35]; 323 snprintf (tt, 35, "/*[local-name()='%s']", requests[j]); 324 xmlNodeSet *req = extractFromDoc (doc, tt); 264 325 #ifdef DEBUG 265 fprintf(stderr,"%i",req->nodeNr);326 fprintf (stderr, "%i", req->nodeNr); 266 327 #endif 267 if(req->nodeNr==1){ 268 t1->value=requests[j]; 269 j=2; 328 if (req->nodeNr == 1) 329 { 330 t1->value = requests[j]; 331 j = 2; 332 } 333 xmlFree (req); 334 } 335 if (strncmp (mtoupper (t1->value), mtoupper ("GetCapabilities"), strlen(mtoupper (t1->value))) == 336 0) 337 { 338 xmlNodeSet *vers = 339 extractFromDoc (doc, "/*/*/*[local-name()='Version']"); 340 xmlChar *content = 341 xmlNodeListGetString (doc, vers->nodeTab[0]->xmlChildrenNode, 342 1); 343 addToMap (tmpMap, "version", (char *) content); 344 xmlFree (vers); 345 xmlFree (content); 346 } 347 else 348 { 349 tval = NULL; 350 tval = (char *) xmlGetProp (cur, BAD_CAST "version"); 351 if (tval != NULL) 352 addToMap (tmpMap, "version", tval); 353 xmlFree (tval); 354 tval = (char *) xmlGetProp (cur, BAD_CAST "language"); 355 if (tval != NULL) 356 addToMap (tmpMap, "language", tval); 357 xmlNodeSet *id = 358 extractFromDoc (doc, "/*/*[local-name()='Identifier']"); 359 char *identifiers = NULL; 360 identifiers = (char *) malloc (cgiContentLength); 361 if(identifiers == NULL) { 362 fprintf(stderr, "Unable to allocate memory in zoo_loader.c line %i\n", __LINE__); 363 return -1; 364 } 365 identifiers[0] = 0; 366 for (int k = 0; k < id->nodeNr; k++) 367 { 368 xmlChar *content = 369 xmlNodeListGetString (doc, 370 id->nodeTab[k]->xmlChildrenNode, 1); 371 if (strlen (identifiers) > 0) 372 { 373 snprintf (identifiers, cgiContentLength, "%s,%s", identifiers, content); 374 identifiers[strlen (identifiers)] = 0; 375 } 376 else 377 { 378 snprintf (identifiers, cgiContentLength, "%s", content); 379 identifiers[strlen (identifiers)] = 0; 380 } 381 xmlFree (content); 382 } 383 xmlFree (id); 384 addToMap (tmpMap, "Identifier", identifiers); 385 } 386 //xmlCleanupParser(); 387 xmlFree (tval); 270 388 } 271 xmlFree(req);272 }273 if(strcmp(mtoupper(t1->value),mtoupper("GetCapabilities"))==0){274 xmlNodeSet* vers=extractFromDoc(doc,"/*/*/*[local-name()='Version']");275 xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);276 addToMap(tmp,"version",(char*)content);277 xmlFree(vers);278 xmlFree(content);279 }else{280 tval=NULL;281 tval = (char*) xmlGetProp(cur,BAD_CAST "version");282 if(tval!=NULL)283 addToMap(tmp,"version",tval);284 xmlFree(tval);285 tval = (char*) xmlGetProp(cur,BAD_CAST "language");286 if(tval!=NULL)287 addToMap(tmp,"language",tval);288 xmlNodeSet* id=extractFromDoc(doc,"/*/*[local-name()='Identifier']");289 char* identifiers=NULL;290 identifiers=(char*)malloc(cgiContentLength);291 identifiers[0]=0;292 for(int k=0;k<id->nodeNr;k++){293 xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);294 if(strlen(identifiers)>0){295 sprintf(identifiers,"%s,%s",identifiers,content);296 identifiers[strlen(identifiers)]=0;297 }298 else{299 sprintf(identifiers,"%s",content);300 identifiers[strlen(identifiers)]=0;301 }302 xmlFree(content);303 }304 xmlFree(id);305 addToMap(tmp,"Identifier",identifiers);306 }307 //xmlCleanupParser();308 xmlFree(tval);309 389 } 310 } 390 391 #ifdef DEBUG 392 fprintf (stderr, "\nRuning Request\n"); 393 #endif 311 394 //dumpMap(tmp); 312 runRequest (tmp);395 runRequest (tmpMap); 313 396 //dumpMap(tmp); 314 397 315 398 return 0;