Changeset 854 for branches/prototype-v0/zoo-project/zoo-kernel
- Timestamp:
- Nov 21, 2017, 10:24:14 AM (7 years ago)
- Location:
- branches/prototype-v0/zoo-project/zoo-kernel
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in
r839 r854 45 45 46 46 service_callback.o: service_callback.c 47 g++ -fPIC ${ JSON_CFLAGS} ${CFLAGS} -c service_callback.c47 g++ -fPIC ${XML2CFLAGS} ${JSON_CFLAGS} ${CFLAGS} -c service_callback.c 48 48 49 49 request_parser.o: request_parser.c request_parser.h … … 60 60 61 61 server_internal.o: server_internal.c server_internal.h service.h mimetypes.h 62 g++ ${ GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c server_internal.c62 g++ ${JSON_CFLAGS} ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c server_internal.c 63 63 64 64 service_internal.o: service_internal.c service_internal.h service.h 65 gcc ${ GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c65 gcc ${JSON_CFLAGS} ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c 66 66 67 67 service_yaml.o: service_yaml.c service.h … … 126 126 zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE} 127 127 g++ -g -O2 ${JSCFLAGS} ${RUBYCFLAGS} ${XML2CFLAGS} ${CFLAGS} -c zcfg2yaml.c -fno-common -DPIC -o zcfg2yaml.o 128 g++ ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o server_internal.o service_internal.o ${MS_FILE} response_print.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o ${YAML_FILE} -o zcfg2yaml -L. ${LDFLAGS}128 g++ ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o ulinet.o service_callback.o server_internal.o service_internal.o ${MS_FILE} response_print.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o ${YAML_FILE} -o zcfg2yaml -L. ${LDFLAGS} 129 129 130 130 install: zoo_loader.cgi -
branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in
r839 r854 115 115 116 116 CFLAGS=@SSH2_CPPFLAGS@ @GETTEXT_CFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF 117 LDFLAGS=-lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} @GETTEXT_LDFLAGS@ @JSON_LDFLAGS@ 117 LDFLAGS=-lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} @GETTEXT_LDFLAGS@ @JSON_LDFLAGS@ @XSLT_LDFLAGS@ 118 118 119 119 DATAROOTDIR=@datarootdir@/zoo-project -
branches/prototype-v0/zoo-project/zoo-kernel/caching.c
r839 r854 64 64 65 65 /** 66 * Create a URL by appending every request header listed in the security 67 * section.This imply that the URL will contain any authentication 68 * informations that should be fowarded to the server from which de input 69 * was download. 70 * @param conf the main configuration maps 71 * @param request the URL to transform. 72 * @return a char* that contain the original URL plus potential header (only for 73 * hosts that are not shared). 74 * @warning Be sure to free the memory returned by this function. 75 */ 76 char* getFilenameForRequest(maps* conf, const char* request){ 77 map* passThrough=getMapFromMaps(conf,"security","attributes"); 78 map* targetHosts=getMapFromMaps(conf,"security","hosts"); 79 char* passedHeader[10]; 80 int cnt=0; 81 char *res=zStrdup(request); 82 char *toAppend=NULL; 83 if(passThrough!=NULL && targetHosts!=NULL){ 84 char *tmp=zStrdup(passThrough->value); 85 char *token, *saveptr; 86 token = strtok_r (tmp, ",", &saveptr); 87 int i; 88 if((strstr(targetHosts->value,"*")!=NULL || isProtectedHost(targetHosts->value,request)==1) && strncasecmp(getProvenance(conf,request),"SHARED",6)!=0){ 89 while (token != NULL){ 90 int length=strlen(token)+6; 91 char* tmp1=(char*)malloc(length*sizeof(char)); 92 map* tmpMap; 93 snprintf(tmp1,6,"HTTP_"); 94 int j; 95 for(j=0;token[j]!='\0';j++){ 96 if(token[j]!='-') 97 tmp1[5+j]=toupper(token[j]); 98 else 99 tmp1[5+j]='_'; 100 tmp1[5+j+1]='\0'; 101 } 102 tmpMap = getMapFromMaps(conf,"renv",tmp1); 103 if(tmpMap!=NULL){ 104 if(toAppend==NULL){ 105 toAppend=(char*)malloc((strlen(tmpMap->value)+1)*sizeof(char)); 106 sprintf(toAppend,"%s",tmpMap->value); 107 }else{ 108 char *tmp3=zStrdup(toAppend); 109 toAppend=(char*)realloc(toAppend,(strlen(tmpMap->value)+strlen(tmp3)+2)*sizeof(char)); 110 sprintf(toAppend,"%s,%s",tmp3,tmpMap->value); 111 free(tmp3); 112 } 113 } 114 free(tmp1); 115 cnt+=1; 116 token = strtok_r (NULL, ",", &saveptr); 117 } 118 } 119 free(tmp); 120 } 121 if(toAppend!=NULL){ 122 char *tmp3=zStrdup(res); 123 res=(char*)realloc(res,(strlen(tmp3)+strlen(toAppend)+1)*sizeof(char)); 124 sprintf(res,"%s%s",tmp3,toAppend); 125 free(tmp3); 126 free(toAppend); 127 } 128 return res; 129 } 130 131 /** 66 132 * Cache a file for a given request. 67 133 * For each cached file, the are two files stored, a .zca and a .zcm containing … … 80 146 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 81 147 if(tmp!=NULL){ 82 char* md5str=getMd5(request); 148 char* myRequest=getFilenameForRequest(conf,request); 149 char* md5str=getMd5(myRequest); 150 free(myRequest); 83 151 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 84 152 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 153 zooLock* lck=lockFile(conf,fname,'w'); 154 if(lck!=NULL){ 85 155 #ifdef DEBUG 86 fprintf(stderr,"Cache list : %s\n",fname);87 fflush(stderr);156 fprintf(stderr,"Cache list : %s\n",fname); 157 fflush(stderr); 88 158 #endif 89 FILE* fo=fopen(fname,"w+");90 if(fo==NULL){159 FILE* fo=fopen(fname,"w+"); 160 if(fo==NULL){ 91 161 #ifdef DEBUG 92 162 fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno)); 93 163 #endif 94 filepath = NULL; 95 return; 96 } 97 fwrite(content,sizeof(char),length,fo); 98 fclose(fo); 164 filepath = NULL; 165 unlockFile(conf,lck); 166 return; 167 } 168 fwrite(content,sizeof(char),length,fo); 169 unlockFile(conf,lck); 170 fclose(fo); 99 171 100 101 102 } 103 104 sprintf(fname,"%s/%s.zcm",tmp->value,md5str);105 fo=fopen(fname,"w+");172 if (filepath != NULL) { 173 strncpy(filepath, fname, max_path); 174 } 175 176 sprintf(fname,"%s/%s.zcm",tmp->value,md5str); 177 fo=fopen(fname,"w+"); 106 178 #ifdef DEBUG 107 fprintf(stderr,"MIMETYPE: %s\n",mimeType);179 fprintf(stderr,"MIMETYPE: %s\n",mimeType); 108 180 #endif 109 fwrite(mimeType,sizeof(char),strlen(mimeType),fo); 110 fclose(fo); 111 112 free(md5str); 113 free(fname); 181 fwrite(mimeType,sizeof(char),strlen(mimeType),fo); 182 fclose(fo); 183 184 sprintf(fname,"%s/%s.zcp",tmp->value,md5str); 185 fo=fopen(fname,"w+"); 186 char* origin=getProvenance(conf,request); 187 #ifdef DEBUG 188 fprintf(stderr,"ORIGIN: %s\n",mimeType); 189 #endif 190 fwrite(origin,sizeof(char),strlen(origin),fo); 191 fclose(fo); 192 193 free(md5str); 194 free(fname); 195 } 114 196 } 115 197 else { 116 198 filepath = NULL; 117 199 } 118 200 } … … 129 211 map* tmpM=getMapFromMaps(conf,"main","cacheDir"); 130 212 if(tmpM!=NULL){ 131 char* md5str=getMd5(request); 213 char* myRequest=getFilenameForRequest(conf,request); 214 char* md5str=getMd5(myRequest); 215 free(myRequest); 132 216 #ifdef DEBUG 133 217 fprintf(stderr,"MD5STR : (%s)\n\n",md5str); … … 206 290 sprintf(xname,"Reference"); 207 291 sprintf(bname,"body"); 208 sprintf(hname,"headers" ,i);292 sprintf(hname,"headers"); 209 293 sprintf(oname,"Order"); 210 294 } … … 280 364 free(tmpStr); 281 365 }else{ 282 md5str=getMd5(tmp1->value); 366 char *myRequest=getFilenameForRequest(*m,tmp1->value); 367 md5str=getMd5(myRequest); 283 368 request=zStrdup(tmp1->value); 369 free(myRequest); 284 370 } 285 371 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); … … 387 473 388 474 if(cached!=NULL){ 389 390 475 struct stat f_status; 391 476 int s=stat(cached, &f_status); 392 477 if(s==0){ 478 zooLock* lck=lockFile(*m,cached,'r'); 479 if(lck==NULL) 480 return -1; 393 481 fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 394 482 FILE* f=fopen(cached,"rb"); … … 398 486 fclose(f); 399 487 addToMap(*content,"cache_file",cached); 488 unlockFile(*m,lck); 400 489 } 401 490 cached[strlen(cached)-1]='m'; 402 491 s=stat(cached, &f_status); 403 492 if(s==0){ 493 zooLock* lck=lockFile(*m,cached,'r'); 494 if(lck==NULL) 495 return -1; 404 496 mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 405 497 FILE* f=fopen(cached,"rb"); … … 407 499 mimeType[f_status.st_size]=0; 408 500 fclose(f); 409 }410 501 unlockFile(*m,lck); 502 } 411 503 }else{ 412 504 addRequestToQueue(m,hInternet,url,true); … … 439 531 if(tmp!=NULL){ 440 532 map *c=getMap((*content),"xlink:href"); 441 char* md5str=getMd5(c->value); 533 char *myRequest=getFilenameForRequest(*m,c->value); 534 char* md5str=getMd5(myRequest); 535 free(myRequest); 442 536 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 443 537 sprintf(fname,"%s/%s.zca",tmp->value,md5str); -
branches/prototype-v0/zoo-project/zoo-kernel/meta_sql.c
r850 r854 297 297 */ 298 298 elements* extractInput(maps* conf,OGRFeature *input){ 299 fprintf(stderr,"************************* %s %s %d\n\n",input->GetFieldAsString( 0 ),__FILE__,__LINE__);300 fprintf(stderr,"************************* %s %s %d\n\n",input->GetFieldAsString( 1 ),__FILE__,__LINE__);301 299 elements* res=createElements(input->GetFieldAsString( 1 )); 302 300 res->content=createMap("title",input->GetFieldAsString( 2 )); … … 348 346 fillMetadata(conf,&res->metadata,output->GetFieldAsString( 0 )); 349 347 fillAdditionalParameters(conf,&res->additional_parameters,output->GetFieldAsString( 0 )); 350 res->defaults=NULL;351 res->supported=NULL;352 res->child=NULL;353 res->next=NULL;354 348 int ioCnt=fillLiteralData(conf,res,output,"Output"); 355 349 if(ioCnt==0) … … 361 355 free(nestedOutputsQuery); 362 356 while( (noutput = noutputs->GetNextFeature()) != NULL ){ 363 elements* nout=extract Input(conf,noutput);357 elements* nout=extractOutput(conf,noutput); 364 358 addToElements(&res->child,nout); 365 359 freeElements(&nout); … … 413 407 elements* in=extractInput(conf,input); 414 408 if(in!=NULL){ 415 if(s->inputs==NULL) 416 s->inputs=dupElements(in); 417 else 418 addToElements(&s->inputs,in); 409 addToElements(&s->inputs,in); 419 410 freeElements(&in); 420 411 free(in); … … 431 422 while( (output = outputs->GetNextFeature()) != NULL ){ 432 423 elements* in=extractOutput(conf,output); 433 if(s->outputs==NULL) 434 s->outputs=dupElements(in); 435 else 424 if(in!=NULL){ 436 425 addToElements(&s->outputs,in); 437 freeElements(&in); 438 free(in); 426 freeElements(&in); 427 free(in); 428 } 439 429 OGRFeature::DestroyFeature( output ); 440 430 } … … 463 453 service *), int minimal ){ 464 454 int result=0; 465 _init_sql(conf,"metadb");466 if(getMapFromMaps(conf,"lenv","dbIssue")!=NULL )455 result=_init_sql(conf,"metadb"); 456 if(getMapFromMaps(conf,"lenv","dbIssue")!=NULL || result < 0) 467 457 return -1; 468 458 // Fetch every services -
branches/prototype-v0/zoo-project/zoo-kernel/mimetypes.h
r839 r854 818 818 */ 819 819 static map* getFileExtensionMap(const char* mimeType, bool* hasExt) { 820 821 map* ext = createMap("extension", "txt"); 822 *hasExt = false; 820 map* ext = createMap("extension", "txt"); 821 *hasExt = false; 823 822 824 if (mimeType != NULL) { 825 for (int i = 0; i < NUM_MIME_TYPES; i++) { 826 if (strncmp(mimeType, MIME[i][M_Type], strlen(MIME[i][M_Type])) == 0) { 827 ext->value = zStrdup(MIME[i][M_Extension]); 828 *hasExt = true; 829 break; 830 } 831 } 832 if (*hasExt == false && strncmp(mimeType, "image/", 6) == 0) { 833 ext->value = zStrdup(strstr(mimeType, "/") + 1); 834 } 835 } 836 return ext; 823 if (mimeType != NULL) { 824 for (int i = 0; i < NUM_MIME_TYPES; i++) { 825 if(strncmp(mimeType, MIME[i][M_Type], strlen(MIME[i][M_Type])) == 0) { 826 free(ext->value); 827 ext->value = zStrdup(MIME[i][M_Extension]); 828 *hasExt = true; 829 break; 830 } 831 } 832 if (*hasExt == false && strncmp(mimeType, "image/", 6) == 0) { 833 free(ext->value); 834 ext->value = zStrdup(strstr(mimeType, "/") + 1); 835 } 836 } 837 return ext; 837 838 } 838 839 -
branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c
r839 r854 1849 1849 } 1850 1850 } 1851 1852 /** 1853 * Parse cookie contained in request headers. 1854 * 1855 * @param conf the conf maps containinfg the main.cfg 1856 * @param cookie the 1857 */ 1858 void parseCookie(maps** conf,const char* cookie){ 1859 char* tcook=zStrdup(cookie); 1860 char *token, *saveptr; 1861 token = strtok_r (tcook, "; ", &saveptr); 1862 maps* res=createMaps("cookies"); 1863 while (token != NULL){ 1864 char *token1, *saveptr1, *name; 1865 int i=0; 1866 token1 = strtok_r (token, "=", &saveptr1); 1867 while (token1 != NULL){ 1868 if(i==0){ 1869 name=zStrdup(token1); 1870 i++; 1871 } 1872 else{ 1873 if(res->content==NULL) 1874 res->content=createMap(name,token1); 1875 else 1876 addToMap(res->content,name,token1); 1877 free(name); 1878 i=0; 1879 } 1880 token1 = strtok_r (NULL, "=", &saveptr1); 1881 } 1882 token = strtok_r (NULL, "; ", &saveptr); 1883 } 1884 addMapsToMaps(conf,res); 1885 freeMaps(&res); 1886 free(res); 1887 free(tcook); 1888 } -
branches/prototype-v0/zoo-project/zoo-kernel/request_parser.h
r767 r854 49 49 void checkValidValue(map*,map**,const char*,const char**,int); 50 50 int validateRequest(maps**,service*,map*,maps**,maps**,HINTERNET*); 51 51 void parseCookie(maps**,const char*); 52 52 53 #ifdef __cplusplus 53 54 } -
branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
r851 r854 743 743 } 744 744 745 int addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){ 745 /** 746 * Add a Metadata node to any existing node. 747 * @param meta the map defining the additional parameters 748 * @param doc the XML document used 749 * @param nb the node to add the additional parameters 750 * @param ns_ows the OWS namespace 751 * @param ns_xlink the xlink namespace 752 */ 753 void addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){ 746 754 int hasTitle=-1; 747 755 int hasValue=-1; … … 817 825 } 818 826 819 820 int addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){ 827 /** 828 * Add AdditionalParameters nodes to any existing node. 829 * @param meta the map defining the additional parameters 830 * @param doc the XML document used 831 * @param nb the node to add the additional parameters 832 * @param ns_ows the OWS namespace 833 * @param ns_xlink the xlink namespace 834 * @param fromDb 1 if the metadata has been extracted from the metadb, 835 * 0 otherwise 836 */ 837 void addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){ 821 838 int hasTitle=-1; 822 839 int hasValue=-1; 840 int toAddAtEnd=-1; 841 int cnt=0; 842 xmlNodePtr* ncr=NULL; 823 843 xmlNodePtr nc1; 824 844 map* oMeta=meta; 825 845 int isAdditionalParameters=-1; 826 //if(count(oMeta)>=2){827 846 int level=0; 828 847 map* test=getMap(meta,"title"); 848 map* otitle=getMap(meta,"title"); 849 map* length=getMap(meta,"length"); 850 int len=0; 851 char *ctitle=NULL; 852 829 853 if(test!=NULL) 830 854 level+=1; … … 837 861 if(count(oMeta)>level+1) 838 862 isAdditionalParameters=1; 839 //} 840 char *ctitle=NULL; 863 841 864 while(meta!=NULL){ 842 if(hasTitle<0 )843 if(hasValue<0)844 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 865 if(hasTitle<0 && hasValue<0){ 866 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 867 } 845 868 if(strncasecmp(meta->name,"title",5)==0 || 846 869 strcasecmp(meta->name,"href")==0 || … … 851 874 hasTitle=1; 852 875 if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){ 853 xmlAddChild(nc,nc1); 854 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 855 free(ctitle); 856 ctitle=NULL; 876 xmlNodePtr ncTmp = xmlDocCopyNodeList(doc,nc1); 877 xmlAddChild(nc,ncTmp); 878 xmlFreeNode(nc1); 879 toAddAtEnd=1; 880 cnt++; 881 nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters"); 882 free(ctitle); 883 ctitle=NULL; 857 884 } 858 885 if(ctitle==NULL){ … … 865 892 free(ctitle); 866 893 ctitle=zStrdup(meta->value); 894 }else{ 895 xmlNewNsProp(nc1,ns_xlink,BAD_CAST meta->name,BAD_CAST meta->value); 867 896 } 868 897 }else{ … … 892 921 meta=meta->next; 893 922 if(hasTitle<0){ 894 xmlAddChild(nc,nc1);923 //xmlAddChild(nc,nc1); 895 924 hasValue=1; 896 }else 897 free(ctitle); 898 } 899 if(oMeta!=NULL && hasValue<0 && nc1!=NULL){ 925 }/*else 926 if(ctitle!=NULL) 927 free(ctitle);*/ 928 } 929 if(length!=NULL) 930 len=atoi(length->value); 931 if(otitle!=NULL) 932 len=1; 933 if(cnt<len){ 900 934 xmlAddChild(nc,nc1); 935 free(ctitle); 901 936 } 902 937 } … … 1406 1441 } 1407 1442 } 1408 else 1443 else{ 1409 1444 xmlFreeNode(nc9); 1445 } 1410 1446 if(strcasecmp(tmp1->name,"uom")==0) 1411 1447 hasUOM1=true; … … 1428 1464 if(hasUOM1==false && vid==0){ 1429 1465 xmlFreeNode(nc5); 1430 if(datatype==1) 1466 if(datatype==1){ 1431 1467 xmlFreeNode(nc4); 1468 } 1432 1469 } 1433 1470 else … … 1440 1477 if(datatype!=1 && default1<0){ 1441 1478 xmlFreeNode(nc5); 1442 if(datatype!=2) 1479 if(datatype!=2){ 1443 1480 xmlFreeNode(nc4); 1481 } 1444 1482 } 1445 1483 … … 1603 1641 if(vid==0 || oI!=4) 1604 1642 xmlAddChild(nc5,nc6); 1605 else 1643 else{ 1606 1644 xmlFreeNode(nc6); 1645 } 1607 1646 } 1608 else 1647 else{ 1609 1648 xmlFreeNode(nc6); 1649 } 1610 1650 } 1611 1651 tmp1=tmp1->next; … … 1634 1674 } 1635 1675 else{ 1636 xmlFreeNode(nc4);1637 1676 xmlAddChild(nc3,nc5); 1638 1677 } … … 1648 1687 1649 1688 if(hasSupported==0){ 1650 if(datatype==0 && vid!=0) 1689 if(datatype==0 && vid!=0){ 1651 1690 xmlFreeNode(nc4); 1691 } 1652 1692 xmlFreeNode(nc5); 1653 1693 } … … 2678 2718 toto=getMap(tmpI->content,"asReference"); 2679 2719 #ifdef USE_MS 2680 if(toto!=NULL && strcasecmp(toto->value,"true")==0 && (testMap==NULL || strncasecmp(testMap->value,"true",4)!=0) ) 2720 restartNoMS: 2721 map* geodatatype=getMap(tmpI->content,"geodatatype"); 2722 2723 if(toto!=NULL && strcasecmp(toto->value,"true")==0 && 2724 (testMap==NULL || 2725 strncasecmp(testMap->value,"true",4)!=0 || 2726 (geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) ) ) 2681 2727 #else 2682 2728 if(toto!=NULL && strcasecmp(toto->value,"true")==0) … … 2699 2745 } 2700 2746 2747 char *file_path=NULL; 2701 2748 if(gfile==NULL) { 2702 2749 map *ext=getMap(tmpI->content,"extension"); 2703 char *file_path;2704 2750 char file_ext[32]; 2705 2751 … … 2716 2762 free(file_name); 2717 2763 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char)); 2718 sprintf(file_name," %s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);2764 sprintf(file_name,"ZOO_DATA_%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext); 2719 2765 itn++; 2720 2766 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); … … 2730 2776 return; 2731 2777 } 2732 free(file_path);2733 2778 2734 2779 toto=getMap(tmpI->content,"value"); … … 2744 2789 } 2745 2790 fclose(ofile); 2746 2747 2791 } 2748 2792 2749 2793 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2750 2794 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2751 char *file_url ;2795 char *file_url=NULL; 2752 2796 if(strncasecmp(tmp2->value,"http://",7)==0 || 2753 2797 strncasecmp(tmp2->value,"https://",8)==0){ … … 2759 2803 } 2760 2804 addToMap(tmpI->content,"Reference",file_url); 2761 free(file_name); 2762 free(file_url); 2805 /*maps* curs=tmpI; 2806 curs=curs->next; 2807 map* test=getMap(tmpI->content,"replicateStorageNext"); 2808 if(test!=NULL && strncasecmp(test->value,"true",4)==0) 2809 while(curs!=NULL){ 2810 addToMap(curs->content,"storage",file_path); 2811 curs=curs->next; 2812 } 2813 if(file_path!=NULL) 2814 free(file_path);*/ 2815 if(file_name!=NULL) 2816 free(file_name); 2817 if(file_url!=NULL) 2818 free(file_url); 2763 2819 file_name=NULL; 2764 2820 } … … 2766 2822 else{ 2767 2823 if(testMap!=NULL){ 2824 setMapInMaps(m,"lenv","state","out"); 2768 2825 setReferenceUrl(m,tmpI); 2826 geodatatype=getMap(tmpI->content,"geodatatype"); 2827 if(geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0) 2828 goto restartNoMS; 2769 2829 } 2770 2830 } -
branches/prototype-v0/zoo-project/zoo-kernel/response_print.h
r839 r854 220 220 void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*); 221 221 void printStatusInfo(maps*,map*,char*); 222 intaddAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);223 intaddMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr);222 void addAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int); 223 void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr); 224 224 225 225 void outputResponse(service*,maps*,maps*,map*,int,maps*,int); -
branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c
r850 r854 26 26 #include "service_internal.h" 27 27 #include "response_print.h" 28 #include "service_callback.h" 28 29 #include "mimetypes.h" 29 30 #ifndef WIN32 … … 444 445 if(cSize!=NULL){ 445 446 length=atoi(cSize->value); 446 } 447 }else 448 length=strlen(cValue->value); 447 449 writeFile(val,cValue->value,length); 448 450 setMapArray(cMap,"cache_file",k,val); … … 466 468 free(val); 467 469 } 470 addToMap(inputs->content,"byValue","true"); 468 471 } 469 472 inputs=inputs->next; … … 980 983 if(isRunning(conf,pid)>0){ 981 984 if(strncasecmp(req,"GetResult",strlen(req))==0){ 982 errorException (conf, _("The result for the requested JobID has not yet been generated. (1)"),985 errorException (conf, _("The result for the requested JobID has not yet been generated. The service is currently running."), 983 986 "ResultNotReady", pid); 984 987 return; … … 1008 1011 printf("%s",result); 1009 1012 fflush(stdout); 1013 free(sid); 1010 1014 freeMap(&statusInfo); 1011 1015 free(statusInfo); 1016 free(result); 1012 1017 return; 1013 1018 }else{ 1014 errorException (conf, _("The result for the requested JobID has not yet been generated. (2)"),1019 errorException (conf, _("The result for the requested JobID has not yet been generated. The service ends but it still needs to produce the outputs."), 1015 1020 "ResultNotReady", pid); 1016 1021 freeMap(&statusInfo); … … 1104 1109 removeService(conf,pid); 1105 1110 #endif 1111 /* 1112 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 1113 invokeCallback(conf,NULL,NULL,7,1); 1114 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 1115 */ 1106 1116 map* statusInfo=createMap("JobID",pid); 1107 1117 addToMap(statusInfo,"Status","Dismissed"); -
branches/prototype-v0/zoo-project/zoo-kernel/service.c
r850 r854 1172 1172 tmp->name=zStrdup(cursor->name); 1173 1173 tmp->content=NULL; 1174 addMapToMap(&tmp->content, e->content);1174 addMapToMap(&tmp->content,cursor->content); 1175 1175 tmp->metadata=NULL; 1176 addMapToMap(&tmp->metadata, e->metadata);1176 addMapToMap(&tmp->metadata,cursor->metadata); 1177 1177 tmp->additional_parameters=NULL; 1178 addMapToMap(&tmp->additional_parameters, e->additional_parameters);1179 if( e->format!=NULL)1180 tmp->format=zStrdup( e->format);1178 addMapToMap(&tmp->additional_parameters,cursor->additional_parameters); 1179 if(cursor->format!=NULL) 1180 tmp->format=zStrdup(cursor->format); 1181 1181 else 1182 1182 tmp->format=NULL; 1183 if( e->defaults!=NULL){1183 if(cursor->defaults!=NULL){ 1184 1184 tmp->defaults=(iotype*)malloc(IOTYPE_SIZE); 1185 1185 tmp->defaults->content=NULL; 1186 addMapToMap(&tmp->defaults->content, e->defaults->content);1186 addMapToMap(&tmp->defaults->content,cursor->defaults->content); 1187 1187 tmp->defaults->next=NULL; 1188 1188 #ifdef DEBUG … … 1192 1192 }else 1193 1193 tmp->defaults=NULL; 1194 if( e->supported!=NULL){1194 if(cursor->supported!=NULL && cursor->supported->content!=NULL){ 1195 1195 tmp->supported=(iotype*)malloc(IOTYPE_SIZE); 1196 1196 tmp->supported->content=NULL; 1197 addMapToMap(&tmp->supported->content, e->supported->content);1197 addMapToMap(&tmp->supported->content,cursor->supported->content); 1198 1198 tmp->supported->next=NULL; 1199 iotype *tmp2= e->supported->next;1199 iotype *tmp2=cursor->supported->next; 1200 1200 while(tmp2!=NULL){ 1201 1201 addMapToIoType(&tmp->supported,tmp2->content); -
branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c
r851 r854 30 30 #include "service_json.h" 31 31 #include "service_internal_ms.h" 32 #include "sqlapi.h" 32 33 #include <pthread.h> 34 #include <libxml/tree.h> 35 #include <libxml/parser.h> 36 #include <libxml/xpath.h> 37 #include <libxml/xpathInternals.h> 38 39 #include <libxslt/xslt.h> 40 #include <libxslt/xsltInternals.h> 41 #include <libxslt/transform.h> 42 #include <libxslt/xsltutils.h> 33 43 34 44 #ifdef __cplusplus … … 36 46 #endif 37 47 48 /** 49 * Parameter definition to be used for sending parameters to a thread. 50 */ 51 typedef struct { 52 maps *conf; //!< the main configuration file 53 map *url; //!< the callback url maps 54 json_object *res;//!< the JSON object to post 55 int step; //!< the current step [0,6] 56 int state; //!< the current state [0,1] 57 } local_params; 58 59 /** 60 * Number of threads 61 */ 38 62 int nbThreads=0; 63 /** 64 * Current step 65 */ 39 66 int cStep=0; 67 /** 68 * Is there any ongoing HTTP request 69 */ 70 int isOngoing=0; 71 /** 72 * Threads array 73 */ 40 74 pthread_t* myThreads=NULL; 75 /** 76 * Steps array 77 */ 41 78 bool steps[7][2]={ 42 79 {false,false}, … … 48 85 {false,false} 49 86 }; 87 /** 88 * Arguments array to give to the _invokeCallback thread's function 89 */ 90 local_params** local_arguments; 50 91 51 92 /** … … 71 112 } 72 113 73 /**74 * Parameter definition to be used for sending parameters to a thread.75 */76 typedef struct {77 maps *conf; //!< the main configuration file78 map *url; //!< the callback url maps79 json_object *res;//!< the JSON object to post80 int step; //!< the current step [0,6]81 int state; //!< the current state [0,1]82 } local_params;83 84 /**85 * Verify if the URL should use a shared cache or not.86 *87 * In case the security section contains a key named "shared", then if the88 * domain listed in the shared key are contained in the url given as parameter89 * then it return "SHARED" in other cases, it returns "OTHER".90 *91 * @param conf the main configuration file maps92 * @param url the URL to evaluate93 * @return a string "SHARED" in case the host is in a domain listed in the94 * shared key, "OTHER" in other cases.95 */96 char* getProvenance(maps* conf,const char* url){97 map* sharedCache=getMapFromMaps(conf,"security","shared");98 if(sharedCache!=NULL){99 char *res=NULL;100 char *hosts=sharedCache->value;101 char *curs=strtok(hosts,",");102 while(curs!=NULL){103 if(strstr(url,curs)==NULL)104 res="OTHER";105 else{106 res="SHARED";107 return res;108 }109 }110 return res;111 }112 return "OTHER";113 }114 114 115 115 /** … … 133 133 hInternet.waitingRequests[0] = zStrdup(URL); 134 134 free(URL); 135 fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS\n",pthread_self(),__FILE__,__LINE__); 135 #ifdef CALLBACK_DEBUG 136 fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS cStep %d %d\n",pthread_self(),__FILE__,__LINE__,cStep,isOngoing); 136 137 fprintf(stderr," * JSON: [%s] \n",jsonStr); 137 138 fprintf(stderr," * URL: %s/ \n\n",hInternet.waitingRequests[0]); 138 139 fprintf(stderr,"************************* From thread %d %s %d: REQUEST PARAMETERS\n",pthread_self(),__FILE__,__LINE__); 139 while( cStep!=7 && 140 #endif 141 while( (arg->step!=7 || isOngoing>0) && 140 142 ( cStep!=arg->step || (arg->state!=0 && steps[arg->step][0]==false) ) 141 143 ){ 142 sleep(1); 143 } 144 struct timespec tv; 145 tv.tv_sec = 0; 146 tv.tv_nsec = (long) 5*1e+9; 147 nanosleep(&tv, &tv); 148 //sleep(1); 149 } 150 isOngoing=1; 151 #ifdef CALLBACK_DEBUG 144 152 fprintf(stderr,"************************* From thread %d %s %d: REQUEST START\n\n",pthread_self(),__FILE__,__LINE__); 145 153 int i=0; 146 154 for(i=0;i<7;i++){ 147 155 fprintf(stderr,"%d) %d %d\n",i,steps[i][0],steps[i][1]); 148 fflush(stderr); 149 } 150 fprintf(stderr,"************************* From thread %d %s %d: REQUEST START\n",pthread_self(),__FILE__,__LINE__); 156 } 157 #endif 158 const struct tm *tm; 159 size_t len; 160 time_t now; 161 char *tmp1; 162 map *tmpStatus; 163 164 now = time ( NULL ); 165 tm = localtime ( &now ); 166 167 tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); 168 len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); 169 170 #ifdef CALLBACK_DEBUG 171 fprintf(stderr,"************************* From thread %d %s %d: REQUEST START (%s)\n",pthread_self(),__FILE__,__LINE__,tmp1); 151 172 fflush(stderr); 173 #endif 174 free(tmp1); 152 175 res1 = InternetOpenUrl (&hInternet, 153 176 hInternet.waitingRequests[0], … … 158 181 //curl_easy_setopt(hInternet.ihandle[hInternet.nb].handle, CURLOPT_VERBOSE, 1);x 159 182 processDownloads(&hInternet); 160 fprintf(stderr,"************************* From thread %d %s %d: REQUEST END\n\n",pthread_self(),__FILE__,__LINE__); 161 fflush(stderr); 183 now = time ( NULL ); 184 tm = localtime ( &now ); 185 tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); 186 len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); 187 188 #ifdef CALLBACK_DEBUG 189 fprintf(stderr,"************************* From thread %d %s %d: REQUEST END (%s)\n\n",pthread_self(),__FILE__,__LINE__,tmp1); 190 #endif 191 free(tmp1); 162 192 char *tmp = (char *) malloc ((hInternet.ihandle[0].nDataLen + 1) 163 193 * sizeof (char)); … … 177 207 json_object_put(arg->res); 178 208 InternetCloseHandle(&hInternet); 209 isOngoing=0; 179 210 if(cStep==0 || cStep==6 || arg->state==1) 180 211 cStep=arg->step+1; 181 steps[arg->step][arg->state]=true; 212 #ifdef CALLBACK_DEBUG 182 213 fprintf(stderr,"************************* From thread %d %s %d: RESPONSE CONTENT\n",pthread_self(),__FILE__,__LINE__); 183 214 for(i=0;i<7;i++){ … … 187 218 fprintf(stderr,"************************* From thread %d %s %d\n\n",pthread_self(),__FILE__,__LINE__); 188 219 fflush(stderr); 220 #endif 221 steps[arg->step][arg->state]=true; 189 222 free(tmp); 190 free(args); 223 //free(args); 224 fprintf(stderr,"************************* From thread %d %s %d: EXIT\n\n",pthread_self(),__FILE__,__LINE__); 225 fflush(stderr); 191 226 pthread_exit(NULL); 192 227 } … … 237 272 238 273 tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); 239 240 len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); 274 len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%H:%M:%SZ", tm ); 241 275 json_object *jsStr0=json_object_new_string(tmp1); 242 276 json_object_object_add(res,"datetime",jsStr0); 243 277 free(tmp1); 278 244 279 switch(step){ 245 280 case 0: { 246 281 // Create a new analyze 247 282 maps* lenv=getMaps(conf,"lenv"); 248 sid=getMapFromMaps(conf," lenv","xrequest");283 sid=getMapFromMaps(conf,"renv","xrequest"); 249 284 if(sid!=NULL){ 250 285 json_object *jsStr=json_object_new_string(sid->value); … … 256 291 json_object_object_add(res,"process_identifier",jsStr); 257 292 } 293 // Save the Execute request on disk 294 map* tmpPath=getMapFromMaps(conf,"main","tmpPath"); 295 map* req=getMapFromMaps(conf,"renv","xrequest"); 296 sid=getMapFromMaps(conf,"lenv","usid"); 297 char* executePath=(char*)malloc((strlen(tmpPath->value)+strlen(sid->value)+14)*sizeof(char)); 298 sprintf(executePath,"%s/execute_%s.xml",tmpPath->value,sid->value); 299 FILE* saveExecute=fopen(executePath,"wb"); 300 fwrite(req->value,1,strlen(req->value)*sizeof(char),saveExecute); 301 fflush(saveExecute); 302 fclose(saveExecute); 303 setMapInMaps(conf,"lenv","execute_file",executePath); 304 free(executePath); 258 305 break; 259 306 } 307 260 308 case 1: { 261 309 // Fetching data inputs 262 310 maps* curs=inputs; 263 char *keys[8][2]={ 311 dumpMaps(curs); 312 char *keys[10][2]={ 264 313 { 265 314 "href", … … 287 336 }, 288 337 { 289 "ref_wfs_link", 290 "ref_wfs_link" 338 "ref_wcs_link", 339 "ref_wcs_link" 340 }, 341 { 342 "ref_wcs_preview_link", 343 "ref_wcs_preview_link" 291 344 }, 292 345 { 293 346 "geodatatype", 294 347 "datatype" 348 }, 349 { 350 "wcs_extent", 351 "boundingbox" 295 352 } 296 353 }; … … 300 357 sid=getMap(curs->content,"ref_wms_link"); 301 358 json_object *res2=json_object_new_object(); 302 if(tmpMap!=NULL && sid==NULL){ 303 addToMap(curs->content,"generated_file",tmpMap->value); 359 if(tmpMap!=NULL){ 360 if(sid==NULL){ 361 addToMap(curs->content,"generated_file",tmpMap->value); 362 addToMap(curs->content,"storage",tmpMap->value); 363 } 364 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 365 dumpMap(curs->content); 304 366 struct stat buf; 305 367 char timeStr[ 100 ] = ""; … … 314 376 } 315 377 setReferenceUrl(conf,curs); 316 //outputMapfile(conf,curs);317 dumpMaps(curs);318 378 } 319 379 int i=0; 320 380 int hasRef=-1; 321 for(;i< 8;i++){381 for(;i<10;i++){ 322 382 sid=getMap(curs->content,keys[i][0]); 323 383 if(sid!=NULL){ … … 340 400 break; 341 401 } 402 342 403 case 2: { 404 // Update the execute request stored on disk at step 1,1 to modify the references used. 405 if(state==0){ 406 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 407 fflush(stderr); 408 maps* curs=inputs; 409 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 410 fflush(stderr); 411 xmlInitParser(); 412 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 413 fflush(stderr); 414 map* xmlPath=getMapFromMaps(conf,"lenv","execute_file"); 415 dumpMap(xmlPath); 416 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 417 fflush(stderr); 418 while(curs!=NULL){ 419 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 420 fflush(stderr); 421 dumpMap(curs->content); 422 //map* bvMap=getMap(curs->content,"byValue"); 423 // TODO handle mapArray 424 //if(bvMap!=NULL && strncasecmp(bvMap->value,"true",4)==0){ 425 if(getMap(curs->content,"href")==NULL && getMap(curs->content,"mimeType")!=NULL){ 426 map* tmpMap=getMap(curs->content,"cache_file"); 427 addToMap(curs->content,"generated_file",tmpMap->value); 428 addToMap(curs->content,"storage",tmpMap->value); 429 setReferenceUrl(conf,curs); 430 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 431 fflush(stderr); 432 dumpMap(curs->content); 433 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 434 fflush(stderr); 435 const char *params[5]; 436 int xmlLoadExtDtdDefaultValue; 437 int hasFile=-1; 438 map* xslPath=getMapFromMaps(conf,"callback","template"); 439 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 440 fflush(stderr); 441 dumpMap(xslPath); 442 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 443 fflush(stderr); 444 map* filePath=getMap(curs->content,"ref_wfs_link"); 445 if(filePath==NULL) 446 filePath=getMap(curs->content,"ref_wcs_link"); 447 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 448 fflush(stderr); 449 dumpMap(filePath); 450 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 451 fflush(stderr); 452 char* inputName=curs->name; 453 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 454 fflush(stderr); 455 if(xslPath==NULL || xmlPath==NULL || filePath==NULL) 456 break; 457 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 458 fflush(stderr); 459 char *tmpParam=(char*)malloc((strlen(curs->name)+11)*sizeof(char)); 460 char *tmpParam1=(char*)malloc((strlen(filePath->value)+11)*sizeof(char)); 461 sprintf(tmpParam,"string(\"%s\")",curs->name); 462 sprintf(tmpParam1,"string(\"%s\")",filePath->value); 463 params[0]="attr"; 464 params[1]=tmpParam; 465 params[2]="value"; 466 params[3]=tmpParam1;//filePath->value; 467 params[4]=NULL; 468 fprintf(stderr, "## XSLT PARAMETERS ATTR: %s VALUE: %s \n", 469 tmpParam,tmpParam1); 470 xmlSubstituteEntitiesDefault(1); 471 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 472 fflush(stderr); 473 xmlLoadExtDtdDefaultValue = 0; 474 xsltStylesheetPtr cur = NULL; 475 xmlDocPtr doc, res; 476 cur = xsltParseStylesheetFile(BAD_CAST xslPath->value); 477 doc = xmlParseFile(xmlPath->value); 478 fflush(stderr); 479 res = xsltApplyStylesheet(cur, doc, params); 480 xmlChar *xmlbuff; 481 int buffersize; 482 xmlDocDumpFormatMemory(res, &xmlbuff, &buffersize, 1); 483 // Store the executeRequest in file again 484 free(tmpParam); 485 free(tmpParam1); 486 fprintf(stderr," # Request / XSLT: %s\n",xmlbuff); 487 fflush(stderr); 488 FILE* saveExecute=fopen(xmlPath->value,"wb"); 489 fwrite(xmlbuff,1,buffersize,saveExecute); 490 fflush(saveExecute); 491 fclose(saveExecute); 492 xmlFree(xmlbuff); 493 xmlFreeDoc(doc); 494 xsltFreeStylesheet(cur); 495 } 496 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 497 fflush(stderr); 498 curs=curs->next; 499 } 500 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 501 fflush(stderr); 502 xmlCleanupParser(); 503 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 504 fflush(stderr); 505 FILE* f0=fopen(xmlPath->value,"rb"); 506 if(f0!=NULL){ 507 long flen; 508 char *fcontent; 509 fseek (f0, 0, SEEK_END); 510 flen = ftell (f0); 511 fseek (f0, 0, SEEK_SET); 512 fcontent = (char *) malloc ((flen + 1) * sizeof (char)); 513 fread(fcontent,flen,1,f0); 514 fcontent[flen]=0; 515 fclose(f0); 516 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 517 fflush(stderr); 518 map *schema=getMapFromMaps(conf,"database","schema"); 519 map* sid=getMapFromMaps(conf,"lenv","usid"); 520 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 521 fflush(stderr); 522 char *req=(char*)malloc((flen+strlen(schema->value)+strlen(sid->value)+66)*sizeof(char)); 523 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 524 fflush(stderr); 525 sprintf(req,"UPDATE %s.services set request_execute_content=$$%s$$ WHERE uuid=$$%s$$",schema->value,fcontent,sid->value); 526 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 527 fflush(stderr); 528 execSql(conf,1,req); 529 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 530 fflush(stderr); 531 free(fcontent); 532 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 533 fflush(stderr); 534 free(req); 535 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 536 fflush(stderr); 537 } 538 } 539 343 540 // Uploading data input to cluster 344 541 maps* in=getMaps(conf,"uploadQueue"); … … 371 568 break; 372 569 } 570 373 571 case 3: { 374 572 // Generating job script … … 380 578 break; 381 579 } 580 382 581 case 4: { 383 582 // Submitting job to cluster … … 389 588 break; 390 589 } 590 391 591 case 5: { 392 592 // Downloading process outputs from cluster 393 593 //json_object* in=mapsToJson(outputs); 394 dumpMaps(outputs);395 594 maps* curs=outputs; 396 char *keys[8][2]={ 595 dumpMaps(curs); 596 char *keys[10][2]={ 397 597 { 398 598 "Reference", … … 400 600 }, 401 601 { 402 " storage",602 "generated_file", 403 603 "cachefile" 404 604 }, 405 605 { 406 " fmimeType",606 "mimeType", 407 607 "mimetype" 408 608 }, … … 412 612 }, 413 613 { 614 "geodatatype", 615 "datatype" 616 }, 617 { 618 "wms_extent", 619 "boundingbox" 620 }, 621 { 414 622 "ref_wms_link", 415 623 "ref_wms_link" … … 420 628 }, 421 629 { 630 "ref_wcs_link", 631 "ref_wcs_preview_link" 632 }, 633 { 422 634 "ref_wfs_link", 423 635 "ref_wfs_link" 424 },425 {426 "geodatatype",427 "datatype"428 636 } 637 }; 638 char* specifics[5][2]={ 639 { 640 "download_link", 641 "ref_download_link" 642 }, 643 { 644 "wms_link", 645 "ref_wms_link" 646 }, 647 { 648 "wfs_link", 649 "ref_wfs_link" 650 }, 651 { 652 "wcs_link", 653 "ref_wcs_link" 654 }, 655 { 656 "wcs_link", 657 "ref_wcs_preview_link" 658 } 429 659 }; 430 660 json_object *res1=json_object_new_object(); 431 661 while(curs!=NULL){ 432 map* tmpMap=getMap(curs->content,"cache_file");433 sid=getMap(curs->content,"ref_wms_link");434 662 json_object *res2=json_object_new_object(); 435 663 int i=0; 436 664 int hasRef=-1; 437 for(;i< 8;i++){665 for(;i<10;i++){ 438 666 sid=getMap(curs->content,keys[i][0]); 439 667 if(sid!=NULL){ … … 448 676 else{ 449 677 maps* curs0=curs->child; 450 while(curs0!=NULL){ 451 json_object *res3=json_object_new_object(); 452 int i0=0; 453 int hasRef0=-1; 454 for(;i0<8;i0++){ 455 sid=getMap(curs0->content,keys[i0][0]); 456 if(sid!=NULL){ 457 json_object *jsStr=json_object_new_string(sid->value); 458 json_object_object_add(res3,keys[i0][1],jsStr); 459 //if(i0==0) 460 hasRef0=1; 678 int i=0; 679 int bypass=-1; 680 for(i=0;i<5;i++){ 681 maps* specificMaps; 682 if((specificMaps=getMaps(curs0,specifics[i][0]))!=NULL){ 683 int hasRef0=-1; 684 int i0=0; 685 for(;i0<6;i0++){ 686 sid=getMap(specificMaps->content,keys[i0][0]); 687 if(sid!=NULL){ 688 json_object *jsStr=json_object_new_string(sid->value); 689 if(i0==0){ 690 json_object_object_add(res2,specifics[i][1],jsStr); 691 } 692 else 693 json_object_object_add(res2,keys[i0][1],jsStr); 694 hasRef0=1; 695 bypass=1; 696 if(i==1){ 697 struct stat buf; 698 char timeStr[ 100 ] = ""; 699 if (stat(sid->value, &buf)==0){ 700 strftime(timeStr, 100, "%d-%m-%Y %H:%M:%S", localtime( &buf.st_mtime)); 701 json_object *jsStr=json_object_new_string(timeStr); 702 json_object_object_add(res2,"creation_date",jsStr); 703 } 704 } 705 } 706 } 707 } 708 } 709 if(bypass<0) 710 while(curs0!=NULL){ 711 json_object *res3=json_object_new_object(); 712 int i0=0; 713 int hasRef0=-1; 714 for(;i0<10;i0++){ 715 sid=getMap(curs0->content,keys[i0][0]); 716 if(sid!=NULL){ 717 json_object *jsStr=json_object_new_string(sid->value); 718 json_object_object_add(res3,keys[i0][1],jsStr); 719 //if(i0==0) 720 hasRef0=1; 721 } 461 722 } 723 if(hasRef0<0) 724 json_object_put(res3); 725 else 726 json_object_object_add(res2,curs0->name,res3); 727 curs0=curs0->next; 462 728 } 463 if(hasRef0<0)464 json_object_put(res3);465 else466 json_object_object_add(res2,curs0->name,res3);467 curs0=curs0->next;468 }469 729 json_object_object_add(res1,curs->name,res2); 470 730 } … … 474 734 break; 475 735 } 736 476 737 case 6: { 477 738 // Finalize HPC 478 sid=getMapFromMaps(conf,"lenv","local_script"); 479 if(sid!=NULL){ 480 json_object *jsStr=json_object_new_string(sid->value); 481 json_object_object_add(res,"inputs",jsStr); 482 } 739 char *keys[6][2]={ 740 { 741 "SubmitTime", 742 "hpc_submission_date" 743 }, 744 { 745 "JobId", 746 "hpc_job_identifier" 747 }, 748 { 749 "JobName", 750 "hpc_job_name" 751 }, 752 { 753 "StartTime", 754 "hpc_start_date" 755 }, 756 { 757 "EndTime", 758 "hpc_end_date" 759 }, 760 { 761 "JobState", 762 "hpc_status" 763 } 764 }; 765 int i=0; 766 if(getMaps(conf,"henv")!=NULL){ 767 for(i=0;i<6;i++){ 768 sid=getMapFromMaps(conf,"henv",keys[i][0]); 769 if(sid!=NULL){ 770 json_object *jsStr=json_object_new_string(sid->value); 771 json_object_object_add(res,keys[i][1],jsStr); 772 } 773 } 774 } 775 if((sid=getMapFromMaps(conf,"henv","billing_nb_cpu"))!=NULL){ 776 json_object *jsStr=json_object_new_string(sid->value); 777 json_object_object_add(res,"hpc_cpu_usage",jsStr); 778 }else{ 779 json_object *jsStr=json_object_new_string("1"); 780 json_object_object_add(res,"hpc_cpu_usage",jsStr); 781 } 782 json_object *jsStr=json_object_new_string("succeeded"); 783 json_object_object_add(res,"wps_status",jsStr); 483 784 break; 484 785 } 786 485 787 case 7: { 486 788 // Error or Dismiss … … 490 792 json_object_object_add(res,"message",jsStr); 491 793 } 492 json_object *jsStr=json_object_new_string("failed"); 794 json_object *jsStr; 795 if(state==1) 796 jsStr=json_object_new_string("dismissed"); 797 else 798 jsStr=json_object_new_string("failed"); 493 799 json_object_object_add(res,"wps_status",jsStr); 494 800 break; … … 498 804 } 499 805 } 500 501 local_params* argumentsA=(local_params*)malloc(MAPS_SIZE+MAP_SIZE+sizeof(json_object*)+(2*sizeof(int))); 502 argumentsA->conf=conf; 503 argumentsA->url=url; 504 argumentsA->res=res; 505 argumentsA->step=step; 506 argumentsA->state=state; 806 807 if(local_arguments==NULL) 808 local_arguments=(local_params**)malloc(sizeof(local_params*)); 809 else 810 local_arguments=(local_params**)realloc(local_arguments,(nbThreads+1)*sizeof(local_params*)); 811 local_arguments[nbThreads]=(local_params*)malloc(MAPS_SIZE+MAP_SIZE+sizeof(json_object*)+(2*sizeof(int))); 812 local_arguments[nbThreads]->conf=conf; 813 local_arguments[nbThreads]->url=url; 814 local_arguments[nbThreads]->res=res; 815 local_arguments[nbThreads]->step=step; 816 local_arguments[nbThreads]->state=state; 507 817 //pthread_t p1; 508 818 if(myThreads==NULL) … … 510 820 else 511 821 myThreads=(pthread_t*)realloc(myThreads,(nbThreads+1)*sizeof(pthread_t)); 512 if(pthread_create(&myThreads[nbThreads], NULL, _invokeCallback, (void*) argumentsA)==-1){822 if(pthread_create(&myThreads[nbThreads], NULL, _invokeCallback, (void*)local_arguments[nbThreads])==-1){ 513 823 setMapInMaps(conf,"lenv","message",_("Unable to create a new thread")); 514 824 return false; … … 519 829 } 520 830 831 /** 832 * Wait for the threads to end then, clean used memory. 833 */ 521 834 void cleanupCallbackThreads(){ 522 835 int i=0; 523 836 for(i=0;i<nbThreads;i++){ 837 fprintf(stderr,"%s %d %d \n",__FILE__,__LINE__,i); 838 fflush(stderr); 524 839 pthread_join(myThreads[i],NULL); 525 } 840 free(local_arguments[i]); 841 } 842 free(local_arguments); 526 843 free(myThreads); 527 844 } -
branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c
r839 r854 39 39 40 40 #define ERROR_MSG_MAX_LENGTH 1024 41 42 /** 43 * Lock a file for read, write and upload. 44 * @param conf the main configuration maps 45 * @param filename the file to lock 46 * @param mode define access: 'r' for read, 'w' for write 47 * @return a new zooLock structure on sucess, NULL on failure 48 */ 49 struct zooLock* lockFile(maps* conf,const char* filename,const char mode){ 50 struct stat f_status; 51 int itn=0; 52 int s; 53 struct zooLock* myLock=(struct zooLock*)malloc(sizeof(struct flock)+sizeof(FILE*)+sizeof(char*)); 54 int len=6; 55 char *template="%s.lock"; 56 int res=-1; 57 retryLockFile: 58 myLock->filename=(char*)malloc((strlen(filename)+len)*sizeof(char)); 59 sprintf(myLock->filename,"%s.lock",filename); 60 s=stat(myLock->filename, &f_status); 61 if(s==0 && mode!='r'){ 62 if(itn<ZOO_LOCK_MAX_RETRY){ 63 itn++; 64 sleep(5); 65 free(myLock->filename); 66 goto retryLockFile; 67 }else{ 68 free(myLock->filename); 69 free(myLock); 70 return NULL; 71 } 72 }else{ 73 char local_mode[3]; 74 memset(local_mode,0,3); 75 if(mode=='w') 76 sprintf(local_mode,"%c+",mode); 77 else 78 sprintf(local_mode,"%c",mode); 79 myLock->lockfile=fopen(myLock->filename,local_mode); 80 char tmp[512]; 81 sprintf(tmp,"%d",getpid()); 82 if(myLock->lockfile==NULL){ 83 myLock->lockfile=fopen(myLock->filename,"w+"); 84 fwrite(tmp,sizeof(char),strlen(tmp),myLock->lockfile); 85 fflush(myLock->lockfile); 86 fclose(myLock->lockfile); 87 myLock->lockfile=fopen(myLock->filename,local_mode); 88 }/*else 89 fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,(myLock->lockfile==NULL));*/ 90 if(mode!='r'){ 91 fwrite(tmp,sizeof(char),strlen(tmp),myLock->lockfile); 92 fflush(myLock->lockfile); 93 } 94 int cnt=0; 95 if(mode=='r'){ 96 myLock->lock.l_type = F_RDLCK; 97 }else 98 myLock->lock.l_type = F_WRLCK; 99 myLock->lock.l_whence = 0; 100 myLock->lock.l_start = 0; 101 myLock->lock.l_len = strlen(tmp)*sizeof(char); 102 while (true) { 103 if((res=fcntl(fileno(myLock->lockfile), F_SETLK, &(myLock->lock)))==-1 && 104 (errno==EAGAIN || errno==EACCES)){ 105 if(cnt >= ZOO_LOCK_MAX_RETRY){ 106 char message[51]; 107 sprintf(message,"Unable to get the lock after %d attempts.\n",cnt); 108 setMapInMaps(conf,"lenv","message",message); 109 fclose(myLock->lockfile); 110 free(myLock->filename); 111 free(myLock); 112 return NULL; 113 } 114 fprintf(stderr,"(%d) Wait for lock on %s, tried %d times ... \n",getpid(),myLock->filename,cnt); 115 fflush(stderr); 116 sleep(1); 117 cnt++; 118 }else 119 break; 120 } 121 if(res<0){ 122 char *tmp; 123 if(errno==EBADF) 124 tmp="Either: the filedes argument is invalid; you requested a read lock but the filedes is not open for read access; or, you requested a write lock but the filedes is not open for write access."; 125 else 126 if(errno==EINVAL) 127 tmp="Either the lockp argument doesn’t specify valid lock information, or the file associated with filedes doesn’t support locks."; 128 else 129 tmp="The system has run out of file lock resources; there are already too many file locks in place."; 130 fprintf(stderr,"Unable to get the lock on %s due to the following error: %s\n",myLock->filename,tmp); 131 return NULL; 132 } 133 return myLock; 134 } 135 } 136 137 /** 138 * Remove a lock. 139 * @param conf the main configuration maps 140 * @param s the zooLock structure 141 * @return 0 on success, -1 on failure. 142 */ 143 int unlockFile(maps* conf,struct zooLock* s){ 144 int res=-1; 145 if(s!=NULL){ 146 s->lock.l_type = F_UNLCK; 147 res=fcntl(fileno(s->lockfile), F_SETLK, &s->lock); 148 if(res==-1) 149 return res; 150 // Check if there is any process locking a file and delete the lock if not. 151 s->lock.l_type = F_WRLCK; 152 if(fcntl(fileno(s->lockfile), F_GETLK, &s->lock)!=-1 && s->lock.l_type == F_UNLCK){ 153 unlink(s->filename); 154 } 155 fclose(s->lockfile); 156 free(s->filename); 157 free(s); 158 } 159 return res; 160 } 161 41 162 #ifndef RELY_ON_DB 42 163 #include <dirent.h> -
branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h
r680 r854 63 63 * Number of time the ZOO-Kernel will try to acquire lock 64 64 */ 65 #define ZOO_LOCK_MAX_RETRY 1 065 #define ZOO_LOCK_MAX_RETRY 180 66 66 67 67 #include <sys/stat.h> … … 85 85 #endif 86 86 87 #include <fcntl.h> 88 87 89 #include "service.h" 88 90 … … 94 96 #endif 95 97 98 /** 99 * The lock structure used by the ZOO-Kernel to ensure atomicity of operations 100 * 101 */ 102 typedef struct zooLock{ 103 struct flock lock; //!< The lock 104 FILE* lockfile; //!< The pointer to the lock file 105 char* filename; //!< The filename to lock 106 } zooLock; 107 108 static zooLock** zoo_file_locks=NULL; 109 static int zoo_file_locks_cnt=0; 110 96 111 #ifdef __cplusplus 97 112 extern "C" { 98 113 #endif 99 114 115 100 116 ZOO_DLL_EXPORT char *readVSIFile(maps*,const char*); 101 117 ZOO_DLL_EXPORT int setOutputValue( maps*, const char*, char*, size_t); 102 118 ZOO_DLL_EXPORT char* getInputValue( maps*,const char*,size_t*); 119 120 ZOO_DLL_EXPORT struct zooLock* lockFile(maps*,const char*,const char); 121 ZOO_DLL_EXPORT int unlockFile(maps*,struct zooLock*); 103 122 104 123 ZOO_DLL_EXPORT void unhandleStatus(maps*); -
branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c
r851 r854 144 144 if(cur->defaults!=NULL){ 145 145 freeIOType(&cur->defaults); 146 free(cur->defaults); 146 147 cur->defaults=NULL; 147 148 } 148 149 if(cur->supported!=NULL){ 149 150 freeIOType(&cur->supported); 151 free(cur->supported); 150 152 cur->supported=NULL; 151 153 } … … 162 164 } 163 165 //dumpElements((*s)->outputs); 166 } 167 168 /** 169 * Acquire a read lock on every files used as input for executing a service. 170 * @param conf the main configuration file map 171 * @return 0 if every file can be locked, -1 if one lock has failed. 172 */ 173 int addReadLocks(maps** conf){ 174 map* queueLengthMap=getMapFromMaps(*conf,"uploadQueue","length"); 175 maps* queueMaps=getMaps(*conf,"uploadQueue"); 176 if(queueLengthMap!=NULL){ 177 int cnt=atoi(queueLengthMap->value); 178 int i=0; 179 for(i=0;i<cnt;i++){ 180 map* argv[2]={ 181 getMapArray(queueMaps->content,"input",i), 182 getMapArray(queueMaps->content,"localPath",i) 183 }; 184 zooLock* lck; 185 if((lck=lockFile(*conf,argv[1]->value,'r'))==NULL){ 186 char* templateStr=_("Unable to lock the file for %s in read mode."); 187 char *tmpMessage=(char*)malloc((strlen(templateStr)+strlen(argv[0]->value)+1)*sizeof(char)); 188 sprintf(tmpMessage,templateStr,argv[0]->value); 189 setMapInMaps(*conf,"lenv","message",tmpMessage); 190 free(tmpMessage); 191 return -1; 192 }else{ 193 if(zoo_file_locks_cnt==0){ 194 zoo_file_locks=(zooLock**)malloc(sizeof(zooLock*)); 195 } 196 else{ 197 zoo_file_locks=(zooLock**)realloc(zoo_file_locks,(zoo_file_locks_cnt+1)*sizeof(zooLock*)); 198 } 199 zoo_file_locks[zoo_file_locks_cnt]=lck; 200 zoo_file_locks_cnt++; 201 } 202 } 203 } 204 return 0; 205 } 206 207 /** 208 * Remove all read locks set for files used as input for executing the service. 209 * @param conf the main configuration maps pointer 210 * @return 0 in case of success, -1 if any error occured. In case of error, one 211 * can refer to the message map array from the lenv section. 212 */ 213 int removeReadLocks(maps** conf){ 214 int res=0; 215 int nberr=0; 216 map* queueLengthMap=getMapFromMaps(*conf,"uploadQueue","length"); 217 maps* queueMaps=getMaps(*conf,"uploadQueue"); 218 if(queueLengthMap!=NULL){ 219 int cnt=atoi(queueLengthMap->value); 220 int i=0; 221 for(i=0;i<cnt;i++){ 222 if(unlockFile(*conf,zoo_file_locks[i])<1){ 223 map* argv=getMapArray(queueMaps->content,"input",i); 224 char* templateStr=_("Unable to unlock the file for %s after execution."); 225 char *tmpMessage=(char*)malloc((strlen(templateStr)+strlen(argv->value)+1)*sizeof(char)); 226 sprintf(tmpMessage,templateStr,argv->value); 227 maps* lenv=getMaps(*conf,"lenv"); 228 setMapArray(lenv->content,"message",nberr,tmpMessage); 229 free(tmpMessage); 230 res=-1; 231 nberr++; 232 } 233 } 234 } 235 free(zoo_file_locks); 236 return res; 237 } 238 239 /** 240 * Get the section name depending on number of features and/or pixels of each 241 * inputs and the threshold defined in a section. 242 * It supposes that your inputs has been published using MapServer support, 243 * implying that the number of features (nb_features), respectively pixels 244 * (nb_pixels), are defined. The section, identified by confId, should contain 245 * preview_max_features and preview_max_pixels defining the threshold values. 246 * @param conf the main configuration file maps pointer 247 * @param inputs the inputs maps pointer 248 * @param confId the section identifier 249 * @return "preview_conf" in case the numbers are lower than the threshold, 250 * "fullres_conf" in other cases. 251 */ 252 char* getConfiguration(maps** conf,maps** inputs,const char* confId){ 253 maps* input=*inputs; 254 map* max_pixels=getMapFromMaps(*conf,confId,"preview_max_pixels"); 255 map* max_features=getMapFromMaps(*conf,confId,"preview_max_features"); 256 int i_max_pixels=atoi(max_pixels->value); 257 int i_max_features=atoi(max_features->value); 258 while(input!=NULL && input->content!=NULL){ 259 map* tmpMap=getMap(input->content,"geodatatype"); 260 if(tmpMap!=NULL){ 261 map* currentNb; 262 if(strcasecmp(tmpMap->value,"raster")==0 ){ 263 currentNb=getMap(input->content,"nb_pixels"); 264 if(atoi(currentNb->value)>i_max_pixels) 265 return "fullres_conf"; 266 }else{ 267 if(strcasecmp(tmpMap->value,"vector")==0 ){ 268 currentNb=getMap(input->content,"nb_features"); 269 if(atoi(currentNb->value)>i_max_features) 270 return "fullres_conf"; 271 } 272 } 273 } 274 input=input->next; 275 } 276 return "preview_conf"; 164 277 } 165 278 … … 181 294 map* tmp=NULL; 182 295 int res=-1; 296 // Get the configuration id depending on service type and defined thresholds 297 // then, set the configId key in the lenv section 183 298 char *serviceType; 184 299 map* mServiceType=getMap(s->content,"serviceType"); … … 187 302 else 188 303 serviceType="HPC"; 189 map* targetPathMap=getMapFromMaps(*main_conf,serviceType,"storagePath");190 304 map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath"); 191 305 map* uuid=getMapFromMaps(*main_conf,"lenv","usid"); 306 map* confMap=getMapFromMaps(*main_conf,serviceType,getConfiguration(main_conf,real_inputs,serviceType)); 307 char * configurationId=confMap->value; 308 setMapInMaps(*main_conf,"lenv","configId",configurationId); 309 // Dump lenv maps again after having set the configId ... 310 char *flenv = 311 (char *) 312 malloc ((strlen (tmpPath->value) + 313 strlen (uuid->value) + 12) * sizeof (char)); 314 sprintf (flenv, "%s/%s_lenv.cfg", tmpPath->value, uuid->value); 315 maps* lenvMaps=getMaps(m,"lenv"); 316 dumpMapsToFile(lenvMaps,flenv,0); 317 free(flenv); 318 319 map* targetPathMap=getMapFromMaps(*main_conf,configurationId,"remote_data_path"); 320 192 321 pthread_t threads_pool[50]; 193 322 // Force the HPC services to be called asynchronously … … 215 344 dumpMapsValuesToFiles(main_conf,&input); 216 345 addToMap(input->content,"toPublish","true"); 346 addToMap(input->content,"useMapserver","true"); 217 347 } 218 348 if(getMap(input->content,"cache_file")!=NULL){ … … 264 394 invokeCallback(m,inputs,NULL,2,0); 265 395 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 396 dumpMaps(inputs); 397 if(getMapFromMaps(m,"lenv","mapError")!=NULL){ 398 invokeCallback(m,inputs,NULL,7,0); 399 return -1; 400 } 266 401 267 402 // Upload data on HPC 268 runUpload(main_conf); 269 403 if(runUpload(main_conf)==false){ 404 errorException (m, _("Unable to lock the file for upload!"), 405 "InternalError", NULL); 406 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 407 invokeCallback(m,inputs,NULL,7,0); 408 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 409 return -1; 410 } 270 411 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 271 412 invokeCallback(m,inputs,NULL,2,1); 272 413 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 273 414 274 // Add the filename to generate for every output to theparameters415 // Add the filename to generate for every output to parameters 275 416 input=*real_outputs; 276 417 // TODO: fix appendOutputParameters 277 418 //appendOutputParameters(input,parameters,¶meters_cnt,s,uuid,targetPathMap); 419 dumpMaps(input); 278 420 while(input!=NULL){ 279 421 // TODO: parse all outputs including inner outputs if required. 280 422 if(input->child==NULL){ 281 parameters_cnt+=1;282 if(parameters_cnt==1)283 parameters=(char**)malloc(parameters_cnt*sizeof(char*));284 else285 parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));286 423 // Name every files that should be produced by the service execution 287 424 map* mime=getMap(input->content,"mimeType"); … … 302 439 free(targetName); 303 440 setMapInMaps(*real_outputs,input->name,"generated_file",targetPath); 304 // We should verify if any optional tag for output is required 305 // (i.e. -out output.tiff *int8*), meaning that we should search 306 // for a corresponding inputs name. 307 map* inValue=getMapFromMaps(*real_inputs,input->name,"value"); 308 if(inValue!=NULL){ 309 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+strlen(inValue->value)+4)*sizeof(char)); 310 sprintf(parameters[parameters_cnt-1],"-%s %s %s",input->name,targetPath,inValue->value); 311 }else{ 312 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char)); 313 sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath); 441 if(strcasecmp(input->name,"wms_link")!=0&& 442 strcasecmp(input->name,"wcs_link")!=0 && 443 strcasecmp(input->name,"wfs_link")!=0){ 444 parameters_cnt+=1; 445 if(parameters_cnt==1) 446 parameters=(char**)malloc(parameters_cnt*sizeof(char*)); 447 else 448 parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*)); 449 // We should verify if any optional tag for output is required 450 // (i.e. -out output.tiff *int8*), meaning that we should search 451 // for a corresponding inputs name. 452 map* inValue=getMapFromMaps(*real_inputs,input->name,"value"); 453 if(inValue!=NULL){ 454 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+strlen(inValue->value)+4)*sizeof(char)); 455 sprintf(parameters[parameters_cnt-1],"-%s %s %s",input->name,targetPath,inValue->value); 456 }else{ 457 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char)); 458 sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath); 459 } 314 460 } 315 461 free(targetPath); 316 462 }// In other case it means we need to return the cache_file as generated_file 317 463 else{ 318 parameters_cnt+=1;319 if(parameters_cnt==1)320 parameters=(char**)malloc(parameters_cnt*sizeof(char*));321 else322 parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));323 464 // Name every files that should be produced by the service execution 324 465 map* mime=getMap(input->child->content,"mimeType"); … … 339 480 free(targetName); 340 481 addToMap(input->content,"generated_file",targetPath); 341 // We should verify if any optional tag for output is required 342 // (i.e. -out output.tiff *int8*), meaning that we should search 343 // for a corresponding inputs name. 344 map* inValue=getMapFromMaps(*real_inputs,input->name,"value"); 345 if(inValue!=NULL){ 346 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+strlen(inValue->value)+4)*sizeof(char)); 347 sprintf(parameters[parameters_cnt-1],"-%s %s %s",input->name,targetPath,inValue->value); 348 }else{ 349 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char)); 350 sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath); 482 addToMap(input->content,"storage",targetPath); 483 if(strcasecmp(input->name,"wms_link")!=0&& 484 strcasecmp(input->name,"wcs_link")!=0 && 485 strcasecmp(input->name,"wfs_link")!=0){ 486 parameters_cnt+=1; 487 if(parameters_cnt==1) 488 parameters=(char**)malloc(parameters_cnt*sizeof(char*)); 489 else 490 parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*)); 491 // We should verify if any optional tag for output is required 492 // (i.e. -out output.tiff *int8*), meaning that we should search 493 // for a corresponding inputs name. 494 map* inValue=getMapFromMaps(*real_inputs,input->name,"value"); 495 if(inValue!=NULL){ 496 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+strlen(inValue->value)+4)*sizeof(char)); 497 sprintf(parameters[parameters_cnt-1],"-%s %s %s",input->name,targetPath,inValue->value); 498 }else{ 499 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char)); 500 sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath); 501 } 351 502 } 352 503 free(targetPath); … … 354 505 input=input->next; 355 506 } 356 357 507 // Produce the SBATCH File locally 358 508 char *scriptPath=(char*)malloc((strlen(s->name)+strlen(tmpPath->value)+strlen(uuid->value)+10)*sizeof(char)); … … 365 515 fflush(stderr); 366 516 FILE* scriptFile=fopen(scriptPath,"w+"); 367 map* headerMap=getMapFromMaps(*main_conf, serviceType,"header");517 map* headerMap=getMapFromMaps(*main_conf,configurationId,"jobscript_header"); 368 518 if(headerMap!=NULL){ 369 519 // Use the header file if defined in the HPC section of the main.cfg file … … 383 533 }else 384 534 fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service HEADER *** ###\n\n"); 385 maps* hpc_opts=getMaps(*main_conf, "sbatch_options");535 maps* hpc_opts=getMaps(*main_conf,configurationId); 386 536 if(hpc_opts!=NULL){ 387 537 map* hpc_opts_content=hpc_opts->content; 388 538 while(hpc_opts_content!=NULL){ 389 fprintf(scriptFile,"#SBATCH --%s=%s\n",hpc_opts_content->name,hpc_opts_content->value); 539 if(strncasecmp(hpc_opts_content->name,"sbatch_options_",15)==0) 540 fprintf(scriptFile,"#SBATCH --%s=%s\n",strstr(hpc_opts_content->name,"sbatch_options_")+15,hpc_opts_content->value); 390 541 hpc_opts_content=hpc_opts_content->next; 391 542 } … … 396 547 fprintf(scriptFile,"#SBATCH --export=MODULES=%s\n",mods->value); 397 548 398 map* bodyMap=getMapFromMaps(*main_conf, serviceType,"body");549 map* bodyMap=getMapFromMaps(*main_conf,configurationId,"jobscript_body"); 399 550 if(bodyMap!=NULL){ 400 551 // Use the header file if defined in the HPC section of the main.cfg file … … 415 566 fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service BODY *** ###\n\n"); 416 567 417 418 568 map* sp=getMap(s->content,"serviceProvider"); 419 569 … … 433 583 fflush(scriptFile); 434 584 fclose(scriptFile); 435 436 585 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 437 586 invokeCallback(m,inputs,NULL,3,1); … … 442 591 invokeCallback(m,inputs,NULL,4,0); 443 592 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 444 targetPathMap=getMapFromMaps(*main_conf, serviceType,"executePath");593 targetPathMap=getMapFromMaps(*main_conf,configurationId,"remote_work_path"); 445 594 if(targetPathMap==NULL){ 446 setMapInMaps(*main_conf,"lenv","message",_("There is no executePath defined in you HPC section!")); 595 setMapInMaps(*main_conf,"lenv","message",_("There is no remote_work_path defined in your section!")); 596 setMapInMaps(*main_conf,"lenv","status","failed"); 597 errorException (m, _("There is no remote_work_path defined in your section!"), 598 "InternalError", NULL); 599 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 600 fflush(stderr); 601 invokeCallback(m,NULL,NULL,7,0); 602 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 603 fflush(stderr); 447 604 return SERVICE_FAILED; 448 605 } … … 453 610 SSHCON *test=ssh_connect(*main_conf); 454 611 ssh_copy(*main_conf,scriptPath,targetPath,ssh_get_cnt(*main_conf)); 455 612 unlink(scriptPath); 613 free(scriptPath); 456 614 // Execute the SBATCH script remotely 457 map* subStr=getMapFromMaps(*main_conf,"HPC","subStr"); 615 addReadLocks(main_conf); 616 map* subStr=getMapFromMaps(*main_conf,configurationId,"sbatch_substr"); 458 617 char *command=(char*)malloc((strlen(targetPath)+strlen(targetPathMap->value)+strlen(subStr->value)+strlen(uuid->value)+137)*sizeof(char)); 459 618 sprintf(command,"sbatch %s 2> %s/error_%s.log | sed \"s:%s::g\"",targetPath,targetPathMap->value,uuid->value,subStr->value); … … 489 648 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 490 649 fflush(stderr); 491 invokeCallback(m,NULL,NULL,7, 1);650 invokeCallback(m,NULL,NULL,7,0); 492 651 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 493 652 fflush(stderr); … … 497 656 free(targetPath); 498 657 ssh_close(*main_conf); 499 sleep(1 20);658 sleep(1); 500 659 return -1; 501 660 } … … 507 666 fflush(stderr); 508 667 free(command); 668 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 669 fflush(stderr); 509 670 510 671 struct sockaddr_un addr; 672 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 673 fflush(stderr); 511 674 memset(&addr, 0, sizeof(addr)); 675 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 676 fflush(stderr); 512 677 addr.sun_family = AF_UNIX; 678 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 679 fflush(stderr); 513 680 int rc, cl, fd = socket(AF_UNIX, SOCK_STREAM, 0); 681 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 682 fflush(stderr); 514 683 char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+20)); 684 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 685 fflush(stderr); 515 686 sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,uuid->value); 687 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 688 fflush(stderr); 516 689 strncpy(addr.sun_path, sname, sizeof(addr.sun_path)-1); 690 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 691 fflush(stderr); 517 692 518 693 if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { 519 694 perror("bind error"); 695 setMapInMaps(m,"lenv","message",_("Unable to bind socket!")); 696 errorException (m, _("Unable to bind socket!"), 697 "InternalError", NULL); 698 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 699 fflush(stderr); 700 invokeCallback(m,NULL,NULL,7,0); 701 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 702 fflush(stderr); 520 703 sleep(120); 521 704 return -1; 522 705 } 706 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 707 fflush(stderr); 523 708 if (listen(fd, 5) == -1) { 524 709 setMapInMaps(*main_conf,"lenv","message",_("Listen error")); 710 errorException (m, _("Listen error"), 711 "InternalError", NULL); 712 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 713 fflush(stderr); 714 invokeCallback(m,NULL,NULL,7,0); 715 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 716 fflush(stderr); 525 717 return -1; 526 718 } 719 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 720 fflush(stderr); 527 721 if ( (cl = accept(fd, NULL, NULL)) == -1) { 528 722 setMapInMaps(*main_conf,"lenv","message",_("Accept error")); 723 errorException (m, _("Accept error"), 724 "InternalError", NULL); 725 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 726 fflush(stderr); 727 invokeCallback(m,NULL,NULL,7,0); 728 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 729 fflush(stderr); 529 730 return -1; 530 731 }else{ 732 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 733 fflush(stderr); 531 734 int hasPassed=-1; 532 735 char buf[11]; … … 536 739 sleep(1); 537 740 setMapInMaps(*main_conf,"lenv","message",_("Read closed")); 538 invokeCallback(m,NULL,NULL,7,1); 741 errorException (m, _("Read closed"), 742 "InternalError", NULL); 743 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 744 fflush(stderr); 745 invokeCallback(m,NULL,NULL,7,0); 746 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 747 fflush(stderr); 539 748 return -1; 540 749 }else{ 541 750 if(rc<0){ 542 751 setMapInMaps(*main_conf,"lenv","message",_("Read error")); 543 invokeCallback(m,NULL,NULL,7,1); 752 errorException (m, _("Read error"), 753 "InternalError", NULL); 754 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 755 fflush(stderr); 756 invokeCallback(m,NULL,NULL,7,0); 757 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 758 fflush(stderr); 544 759 return -1; 545 760 } 546 761 } 547 762 hasPassed=1; 763 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 764 fflush(stderr); 548 765 res=atoi(buf); 766 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 767 fflush(stderr); 549 768 unlink(sname); 550 //free(sname); 551 769 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 770 fflush(stderr); 771 free(sname); 772 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 773 fflush(stderr); 774 removeReadLocks(main_conf); 775 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 776 fflush(stderr); 777 552 778 if(res==3){ 553 779 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); … … 573 799 setMapInMaps(*main_conf,"lenv","message",tmpStr); 574 800 free(tmpStr); 801 invokeCallback(m,NULL,NULL,7,0); 575 802 return SERVICE_FAILED; 576 803 } … … 587 814 if(ssh_fetch(*main_conf,targetPath,generatedFile->value,ssh_get_cnt(m))==0){ 588 815 maps* tmp=getMaps(*real_outputs,input->name); 816 char serviceName[9]; 589 817 freeMap(&tmp->content); 590 818 free(tmp->content); … … 592 820 maps* output=getMaps(*real_outputs,input->name); 593 821 setMapInMaps(output->child,"download_link","generated_file",targetPath); 822 setMapInMaps(output->child,"download_link","storage",targetPath); 594 823 setMapInMaps(output->child,"download_link","useMapserver","false"); 824 setMapInMaps(output->child,"download_link","replicateStorageNext","true"); 825 setMapInMaps(output->child,"download_link","asReference","true"); 826 setMapInMaps(output->child,"download_link","inRequest","true"); 595 827 setMapInMaps(output->child,"wms_link","generated_file",targetPath); 828 setMapInMaps(output->child,"wms_link","storage",targetPath); 596 829 setMapInMaps(output->child,"wms_link","useMapserver","true"); 597 830 setMapInMaps(output->child,"wms_link","msOgc","WMS"); 598 831 setMapInMaps(output->child,"wms_link","requestedMimeType","image/png"); 599 setMapInMaps(output->child,"wcs_link","generated_file",targetPath); 600 setMapInMaps(output->child,"wcs_link","useMapserver","true"); 832 setMapInMaps(output->child,"wms_link","asReference","true"); 833 if(getMaps(output->child,"wcs_link")!=NULL){ 834 sprintf(serviceName,"wcs_link"); 835 setMapInMaps(output->child,serviceName,"msOgc","WCS"); 836 } 837 else{ 838 sprintf(serviceName,"wfs_link"); 839 setMapInMaps(output->child,serviceName,"msOgc","WFS"); 840 } 841 setMapInMaps(output->child,serviceName,"storage",targetPath); 842 setMapInMaps(output->child,serviceName,"generated_file",targetPath); 843 setMapInMaps(output->child,serviceName,"useMapserver","true"); 844 setMapInMaps(output->child,serviceName,"asReference","true"); 845 }else{ 846 char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char)); 847 sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename); 848 setMapInMaps(*main_conf,"lenv","message",tmpStr); 849 free(tmpStr); 850 invokeCallback(m,NULL,NULL,7,0); 851 return SERVICE_FAILED; 601 852 } 602 853 free(targetPath); … … 605 856 input=input->next; 606 857 } 858 859 // Read informations provided by FinalizeHPC as a configuration file 860 // then, remove the file. 861 map* jobid=getMapFromMaps(*main_conf,"lenv","usid"); 862 map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath"); 863 char *filePath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+15)*sizeof(char)); 864 sprintf(filePath,"%s/exec_status_%s",tmpPath->value,jobid->value); 865 maps* m = (maps *) malloc (MAPS_SIZE); 866 m->child=NULL; 867 m->next=NULL; 868 int saved_stdout = dup (fileno (stdout)); 869 dup2 (fileno (stderr), fileno (stdout)); 870 conf_read(filePath,m); 871 fflush(stdout); 872 dup2 (saved_stdout, fileno (stdout)); 873 close(saved_stdout); 874 unlink(filePath); 875 free(filePath); 876 addMapsToMaps(main_conf,m); 877 freeMaps(&m); 878 free(m); 879 }else{ 880 // Try to access remotely to the log file and return a more relevant error message 881 setMapInMaps(m,"lenv","message",_("HPC Execution failed!")); 882 errorException (m, _("HPC Execution failed!"), 883 "InternalError", NULL); 884 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 885 fflush(stderr); 886 invokeCallback(m,NULL,NULL,7,0); 887 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 888 fflush(stderr); 607 889 } 608 890 //free(buf); … … 611 893 perror("Failed to read"); 612 894 setMapInMaps(*main_conf,"lenv","message",_("Unable to parse the value returned by remote execution")); 895 errorException (m, _("Unable to parse the value returned by remote execution"), 896 "InternalError", NULL); 897 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 898 fflush(stderr); 899 invokeCallback(m,NULL,NULL,7,0); 900 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 901 fflush(stderr); 613 902 sleep(120); 614 903 return SERVICE_FAILED; … … 622 911 return res; 623 912 } 624 625 -
branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
r851 r854 138 138 exit(-1); 139 139 } 140 int finalProto=-1; 140 141 map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion"); 141 142 map *dataPath=getMapFromMaps(m,"main","dataPath"); … … 147 148 map* protoMap=getMap(tmpI->content,"msOgc"); 148 149 map* versionMap=getMap(tmpI->content,"msOgcVersion"); 149 char options[ 3][5][25]={150 char options[4][5][25]={ 150 151 {"WMS","1.3.0","GetMap","layers=%s","wms_extent"}, 151 152 {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"}, 152 //{"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}153 {"WCS"," 2.0.0","GetCoverage","coverageid=%s","wcs_extent"}153 {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"}, 154 {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"} 154 155 }; 156 map* datatype=getMap(tmpI->content,"geodatatype"); 157 if(datatype==NULL || strncmp(datatype->value,"other",5)==0){ 158 setMapInMaps(m,"lenv","mapError","true"); 159 setMapInMaps(m,"lenv","locator",tmpI->name); 160 setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data.")); 161 if(getMapFromMaps(m,"lenv","state")==NULL) 162 errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name); 163 return; 164 } 155 165 int proto=0; 156 166 if(rformat==NULL){ … … 194 204 195 205 char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(format->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char)); 196 map* datatype=getMap(tmpI->content,"geodatatype");197 206 198 207 if(proto>0){ 208 if(proto==2) 209 finalProto=1; 199 210 sprintf(webService_url, 200 211 "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", … … 248 259 } 249 260 addToMap(tmpI->content,"Reference",webService_url); 250 261 memset(layers,0,128); 262 sprintf(layers,options[proto][3],tmpI->name); 251 263 protoVersion=options[proto][1]; 252 264 extent=getMap(tmpI->content,options[proto][4]); 253 265 memset(webService_url,0,strlen(webService_url)); 254 266 if(proto>0){ 267 if(proto==2) 268 finalProto=1; 255 269 sprintf(webService_url, 256 270 "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", … … 292 306 addToMap(tmpI->content,"ref_wms_link",webService_url); 293 307 } 308 if(finalProto>0){ 309 proto=3; 310 memset(layers,0,128); 311 sprintf(layers,options[proto][3],tmpI->name); 312 protoVersion=options[proto][1]; 313 extent=getMap(tmpI->content,options[proto][4]); 314 memset(webService_url,0,strlen(webService_url)); 315 sprintf(webService_url, 316 "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s", 317 msUrl->value, 318 dataPath->value, 319 tmpI->name, 320 sid->value, 321 options[proto][2], 322 options[proto][0], 323 protoVersion, 324 layers, 325 rformat->value, 326 extent->value, 327 crs->value 328 ); 329 addToMap(tmpI->content,"ref_wcs_preview_link",webService_url); 330 } 294 331 if(hasCRS==0){ 295 332 freeMap(&crs); … … 299 336 free(rformat); 300 337 free(webService_url); 301 dumpMaps(tmpI);302 338 } 303 339 … … 492 528 /** 493 529 * Try to load the file as ZIP 494 */ 495 530 * 496 531 OGRDataSourceH poDS1 = NULL; 497 532 OGRSFDriverH *poDriver1 = NULL; … … 534 569 fprintf(stderr,"Unable to access the DataSource as ZIP File\n"); 535 570 setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode"); 571 fprintf(stderr,"Remove ZIP File!\n"); 572 unlink(odsName); 536 573 //OGR_DS_Destroy(poDS1); 537 574 }else{ … … 594 631 } 595 632 OGR_DS_Destroy(poDS1); 596 }633 } 597 634 free(sdsName); 598 free(dsName); 635 free(dsName);*/ 599 636 600 637 OGRDataSourceH poDS = NULL; … … 649 686 myLayer->status = MS_ON; 650 687 msConnectLayer(myLayer,MS_OGR,pszDataSource); 688 689 addIntToMap(output->content,"nb_features",OGR_L_GetFeatureCount(poLayer,1)); 651 690 652 691 /** … … 811 850 */ 812 851 GDALAllRegister(); 813 hDataset = GDALOpen( pszFilename, GA_ ReadOnly);852 hDataset = GDALOpen( pszFilename, GA_Update ); 814 853 if( hDataset == NULL ){ 815 854 #ifdef DEBUGMS … … 866 905 m->width=GDALGetRasterXSize( hDataset ); 867 906 m->height=GDALGetRasterYSize( hDataset ); 907 addIntToMap(output->content,"nb_pixels",GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset )); 868 908 869 909 /** … … 880 920 setSrsInformations(output,m,myLayer,pszProjection); 881 921 }else{ 882 fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset )); 922 fprintf(stderr,"NO SRS FOUND ! %s\n",GDALGetProjectionRef( hDataset )); 923 CPLErr sp=GDALSetProjection( hDataset , "+init=epsg:4326" ); 924 if(sp!=CE_None){ 925 fprintf(stderr,"NO SRS FOUND ! %s\n",CPLGetLastErrorMsg()); 926 } 883 927 } 884 928 … … 905 949 addToMap(output->content,"boundingbox",extent); 906 950 } 951 }else{ 952 int scale=1; 953 if(m->width>2048){ 954 addIntToMap(output->content,"width",2048); 955 scale=2048/m->width; 956 }else 957 addIntToMap(output->content,"width",m->width); 958 addIntToMap(output->content,"height",m->height*scale); 907 959 } 908 960 … … 919 971 } 920 972 if(nBandsI>=3) 921 msLayerAddProcessing(myLayer,"BANDS=1,2,3"); 973 if(nBandsI==4) 974 msLayerAddProcessing(myLayer,"BANDS=1,2,3,4"); 975 else 976 msLayerAddProcessing(myLayer,"BANDS=1,2,3"); 922 977 else if(nBandsI>=2) 923 978 msLayerAddProcessing(myLayer,"BANDS=1,2"); 924 979 else 925 980 msLayerAddProcessing(myLayer,"BANDS=1"); 981 926 982 927 983 /** … … 929 985 */ 930 986 char lBands[7]; 931 memset(&nBands,0,7);932 987 char *nameBands=NULL; 933 988 for( iBand = 0; iBand < nBandsI; iBand++ ){ 989 memset(&lBands,0,7); 934 990 sprintf(lBands,"Band%d",iBand+1); 935 991 if(nameBands==NULL){ … … 937 993 sprintf(nameBands,"%s",lBands); 938 994 }else{ 939 if(iBand<4){995 /*if(iBand<4)*/{ 940 996 char *tmpS=zStrdup(nameBands); 941 997 nameBands=(char*)realloc(nameBands,(strlen(tmpS)+strlen(lBands)+2)*sizeof(char)); … … 954 1010 */ 955 1011 for( iBand = 0; iBand < nBandsI; iBand++ ){ 956 //int bGotNodata;//, bSuccess; 957 double adfCMinMax[2]/*, dfNoData*/; 958 //int nBlockXSize, nBlockYSize, nMaskFlags; 959 //double /*dfMean, dfStdDev*/; 1012 double pdfMin, pdfMax, pdfMean, pdfStdDev; 960 1013 hBand = GDALGetRasterBand( hDataset, iBand+1 ); 961 1014 962 1015 CPLErrorReset(); 963 GDALComputeRaster MinMax( hBand, FALSE, adfCMinMax);1016 GDALComputeRasterStatistics( hBand, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev, NULL,NULL); 964 1017 char tmpN[21]; 965 1018 sprintf(tmpN,"Band%d",iBand+1); 966 1019 if (CPLGetLastErrorType() == CE_None){ 967 char tmpMm[100]; 968 sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]); 1020 char tmpMm[100],tmpMp[100]; 1021 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 1022 sprintf(tmpMp,"SCALE_%d=%.3f,%.3f",iBand+1,pdfMean-(2*pdfStdDev),pdfMean+(2*pdfStdDev)); 969 1023 char tmpI[31]; 970 1024 sprintf(tmpI,"%s_interval",tmpN); 971 1025 msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm); 972 1026 if(pdfMax>255) 1027 msLayerAddProcessing(myLayer,tmpMp); 973 1028 map* test=getMap(output->content,"msClassify"); 974 1029 if(test!=NULL && strncasecmp(test->value,"true",4)==0){ … … 990 1045 991 1046 if(nBandsI==1){ 992 double delta= adfCMinMax[1]-adfCMinMax[0];1047 double delta=pdfMax-pdfMin; 993 1048 double interval=delta/10; 994 double cstep= adfCMinMax[0];1049 double cstep=pdfMin; 995 1050 for(i=0;i<10;i++){ 996 1051 /** … … 1036 1091 1037 1092 char tmpMm[100]; 1038 sprintf(tmpMm,"%.3f %.3f", adfCMinMax[0],adfCMinMax[1]);1093 sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax); 1039 1094 1040 1095 } … … 1046 1101 myLayer->offsite.blue=0; 1047 1102 } 1048 msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");1049 1103 } 1050 1104 } … … 1056 1110 1057 1111 } 1112 msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR"); 1058 1113 1059 1114 m->layerorder[m->numlayers] = m->numlayers; … … 1081 1136 ext="json"; 1082 1137 1083 map* tmpMap=getMapFromMaps(conf,"main","dataPath"); 1084 map* sidMap=getMapFromMaps(conf,"lenv","usid"); 1085 char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); 1086 sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 1087 int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); 1088 map *gfile=getMap(outputs->content,"generated_file"); 1089 if(gfile!=NULL){ 1090 readGeneratedFile(conf,outputs->content,gfile->value); 1091 } 1092 map* sizeMap=getMap(outputs->content,"size"); 1093 map* vData=getMap(outputs->content,"value"); 1094 if(sizeMap!=NULL){ 1095 zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); 1096 } 1097 else{ 1098 zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); 1099 } 1100 close(f); 1101 addToMap(outputs->content,"storage",pszDataSource); 1102 free(pszDataSource); 1138 map* storage=getMap(outputs->content,"storage"); 1139 if(storage==NULL){ 1140 map* tmpMap=getMapFromMaps(conf,"main","dataPath"); 1141 map* sidMap=getMapFromMaps(conf,"lenv","usid"); 1142 char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char)); 1143 sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 1144 int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); 1145 map *gfile=getMap(outputs->content,"generated_file"); 1146 if(gfile!=NULL){ 1147 readGeneratedFile(conf,outputs->content,gfile->value); 1148 } 1149 map* sizeMap=getMap(outputs->content,"size"); 1150 map* vData=getMap(outputs->content,"value"); 1151 if(sizeMap!=NULL){ 1152 zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char)); 1153 } 1154 else{ 1155 zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char)); 1156 } 1157 close(f); 1158 addToMap(outputs->content,"storage",pszDataSource); 1159 free(pszDataSource); 1160 } 1103 1161 1104 1162 /* … … 1174 1232 #endif 1175 1233 1234 outputFormatObj *o6=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","geotiff"); 1235 if(!o6) 1236 fprintf(stderr,"Unable to initialize GDAL driver !\n"); 1237 else{ 1238 o6->imagemode=MS_IMAGEMODE_BYTE; 1239 o6->mimetype=strdup("image/geotiff"); 1240 o6->inmapfile=MS_TRUE; 1241 msAppendOutputFormat(myMap,msCloneOutputFormat(o6)); 1242 msFreeOutputFormat(o6); 1243 } 1244 1176 1245 /* 1177 1246 * Set default projection to EPSG:4326 … … 1262 1331 msSaveMap(myMap,mapPath); 1263 1332 free(mapPath); 1333 //msFreeSymbolSet(&myMap->symbolset); 1334 msFreeMap(myMap); 1335 //msFree(myMap); 1264 1336 msGDALCleanup(); 1265 msFreeMap(myMap);1266 1337 } 1267 1338 -
branches/prototype-v0/zoo-project/zoo-kernel/service_internal_python.c
r790 r854 57 57 * from the ZOO-Kernel Python environment: 58 58 * - "_" corresponding to the PythonTranslate function 59 * - "upd te_status" corresponding to the PythonUpdateStatus function59 * - "update_status" corresponding to the PythonUpdateStatus function 60 60 * @see PythonTranslate, PythonUpdateStatus 61 61 */ … … 163 163 fprintf(stderr,"PYTHON SUPPORT (%i)\n",strlen(tmp->value)); 164 164 #endif 165 python_path=(char*)malloc((strlen(tmp->value) )*sizeof(char));165 python_path=(char*)malloc((strlen(tmp->value)+1)*sizeof(char)); 166 166 sprintf(python_path,"%s",tmp->value); 167 167 hasToClean=1; … … 281 281 dumpMaps(*real_outputs); 282 282 #endif 283 }else{ 283 }else{ 284 284 PythonZooReport(m,tmp->value,0); 285 285 res=-1; … … 323 323 char *pbt=NULL; 324 324 if(PyString_Check(trace)){ 325 pbt=(char*)malloc(( 7+strlen(PyString_AsString(trace))+1)*sizeof(char));325 pbt=(char*)malloc((8+strlen(PyString_AsString(trace)))*sizeof(char)); 326 326 sprintf(pbt,"TRACE: %s",PyString_AsString(trace)); 327 327 } 328 328 else 329 329 fprintf(stderr,"EMPTY TRACE ?"); 330 330 331 331 trace=NULL; 332 332 -
branches/prototype-v0/zoo-project/zoo-kernel/sql/schema.sql
r839 r854 31 31 -- Create a dedicated schema to store all tables 32 32 -- Uncomment the following 2 lines to activate the schema use 33 -- CREATE SCHEMA zoo;34 -- SET search_path TO zoo;33 -- CREATE SCHEMA process; 34 -- SET search_path TO process; 35 35 -------------------------------------------------------------------------------- 36 36 -- Services table … … 45 45 creation_time timestamp with time zone default now(), 46 46 end_time timestamp with time zone default NULL, 47 -- queue_duration ,48 -- run_duration ,49 47 progress int, 50 message TEXT, 51 -- data_lifetime timestamp with time zone default now() + interval '48 hours', 52 rps_step int4 default 0 48 message TEXT 53 49 ); 54 50 -------------------------------------------------------------------------------- … … 56 52 -- Used to store the response provided by a services running asynchronously 57 53 create table responses ( 58 uuid text references process(uuid) ON DELETE CASCADE,54 uuid text references services(uuid) ON DELETE CASCADE, 59 55 content text, 60 56 creation_time timestamp with time zone default now() -
branches/prototype-v0/zoo-project/zoo-kernel/sql/zoo_collectiondb.sql
r839 r854 314 314 abstract, 315 315 (SELECT service_type FROM CollectionDB.zoo_ServiceTypes WHERE id = (SELECT service_type_id FROM CollectionDB.zoo_DeploymentMetadata WHERE id = (SELECT deployment_metadata_id FROM CollectionDB.PrivateMetadataDeploymentmetadataAssignment WHERE private_metadata_id=(SELECT id FROM CollectionDB.zoo_PrivateMetadata WHERE id = CollectionDB.ows_Process.private_metadata_id)))) as service_type, 316 (SELECT executable_name as service_provider FROM CollectionDB.zoo_DeploymentMetadata WHERE id = (SELECT deployment_metadata_id FROM CollectionDB.PrivateMetadataDeploymentmetadataAssignment WHERE private_metadata_id=(SELECT id FROM CollectionDB.zoo_PrivateMetadata WHERE id = CollectionDB.ows_Process.private_metadata_id))) 316 (SELECT executable_name as service_provider FROM CollectionDB.zoo_DeploymentMetadata WHERE id = (SELECT deployment_metadata_id FROM CollectionDB.PrivateMetadataDeploymentmetadataAssignment WHERE private_metadata_id=(SELECT id FROM CollectionDB.zoo_PrivateMetadata WHERE id = CollectionDB.ows_Process.private_metadata_id))) as service_provider, 317 317 availability 318 318 FROM CollectionDB.ows_Process -
branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
r851 r854 70 70 int i=0; 71 71 maps* cconf=getMaps(conf,key); 72 if(cconf==NULL) 72 if(cconf==NULL){ 73 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 73 74 return "-1"; 75 } 74 76 int len=0; 75 77 for(i=0;i<6;i++){ … … 119 121 int _init_sql(maps* conf,const char* key){ 120 122 char* sqlInitString=_createInitString(conf,key); 123 fprintf(stderr,"Try to connect to: %s %s !\n",key,sqlInitString); 124 fflush(stderr); 121 125 if(strncmp(sqlInitString,"-1",2)==0) 122 126 return -1; 127 fprintf(stderr,"Try to connect to: %s !\n",key); 128 fflush(stderr); 123 129 OGRSFDriver *poDriver = NULL; 124 130 OGRRegisterAll(); … … 195 201 */ 196 202 void close_sql(maps* conf,int cid){ 197 if( zoo_ResultSet != NULL ) 203 if( zoo_ResultSet != NULL ){ 198 204 zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet ); 199 if(zoo_DS!=NULL){ 205 zoo_ResultSet=NULL; 206 } 207 if(zoo_DS!=NULL && zoo_DS[cid]!=NULL){ 200 208 #if GDAL_VERSION_MAJOR >= 2 201 209 GDALClose(zoo_DS[cid]); … … 223 231 */ 224 232 OGRLayer *fetchSql(maps* conf,int cid,const char* sqlQuery){ 225 if(zoo_DS [cid]==NULL)233 if(zoo_DS==NULL || zoo_DS[cid]==NULL) 226 234 return NULL; 227 235 OGRLayer *res=NULL; … … 250 258 int execSql(maps* conf,int cid,const char* sqlQuery){ 251 259 int res=-1; 260 if(zoo_DS == NULL || zoo_DS[cid]==NULL) 261 return -1; 252 262 zoo_ResultSet = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL); 253 263 if( zoo_ResultSet != NULL ){ … … 371 381 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char)); 372 382 sprintf(sqlQuery,"UPDATE %s.services set status=$$%s$$,message=$$%s$$ where uuid=$$%s$$;",schema->value,p->value,msg->value,sid->value); 373 if( zoo_ds_nb== 374 #ifdef META_DB 375 1 376 #else 377 0 378 #endif 379 ){ 383 if(zoo_ds_nb==0){ 380 384 init_sql(conf); 381 385 zoo_ds_nb++; 382 386 } 383 execSql(conf,zoo_ds_nb-1,sqlQuery); 384 cleanUpResultSet(conf,zoo_ds_nb-1); 385 free(sqlQuery); 387 execSql(conf,0,sqlQuery); 388 cleanUpResultSet(conf,0); 389 close_sql(conf,0); 390 free(sqlQuery); 391 setMapInMaps(conf,"lenv","ds_nb","0"); 386 392 return 0; 387 393 } … … 439 445 int zoo_ds_nb=getCurrentId(conf); 440 446 map *schema=getMapFromMaps(conf,"database","schema"); 447 OGRFeature *poFeature = NULL; 448 const char *tmp1=NULL; 449 int hasRes=-1; 441 450 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char)); 442 451 sprintf(sqlQuery, … … 454 463 } 455 464 execSql(conf,zoo_ds_nb-1,sqlQuery); 456 OGRFeature *poFeature = NULL;457 const char *tmp1;458 int hasRes=-1;459 465 if(zoo_ResultSet!=NULL){ 460 466 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ … … 472 478 if(hasRes<0) 473 479 tmp1=NULL; 474 else 475 cleanUpResultSet(conf,zoo_ds_nb-1); 480 cleanUpResultSet(conf,zoo_ds_nb-1); 476 481 free(sqlQuery); 477 482 return (char*)tmp1; … … 534 539 //close_sql(conf,zoo_ds_nb-1); 535 540 free(sqlQuery); 536 end_sql();541 //end_sql(); 537 542 } 538 543 … … 555 560 zoo_ds_nb++; 556 561 } 557 execSql(conf,zoo_ds_nb-1,sqlQuery); 562 if(execSql(conf,zoo_ds_nb-1,sqlQuery)<0) 563 return NULL; 558 564 OGRFeature *poFeature = NULL; 559 565 const char *tmp1; -
branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
r851 r854 29 29 30 30 #include "sshapi.h" 31 #include "service_internal.h" 31 32 32 33 SSHCON *sessions[MAX_PARALLEL_SSH_CON]; … … 94 95 int port=22; 95 96 96 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 97 fflush(stderr); 98 99 map* hpc_host=getMapFromMaps(conf,"HPC","host"); 100 map* hpc_port=getMapFromMaps(conf,"HPC","port"); 101 map* hpc_user=getMapFromMaps(conf,"HPC","user"); 102 map* hpc_password=getMapFromMaps(conf,"HPC","password"); 103 map* hpc_public_key=getMapFromMaps(conf,"HPC","key"); 104 105 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 106 fflush(stderr); 97 map* hpc_config=getMapFromMaps(conf,"lenv","configId"); 98 99 map* hpc_host=getMapFromMaps(conf,hpc_config->value,"ssh_host"); 100 map* hpc_port=getMapFromMaps(conf,hpc_config->value,"ssh_port"); 101 map* hpc_user=getMapFromMaps(conf,hpc_config->value,"ssh_user"); 102 map* hpc_password=getMapFromMaps(conf,hpc_config->value,"ssh_password"); 103 map* hpc_public_key=getMapFromMaps(conf,hpc_config->value,"ssh_key"); 104 105 char ip[100]; 106 struct hostent *my_hostent; 107 struct in_addr **addrs; 108 109 if (hpc_host != NULL) { 110 // Fetch ip address for the hostname 111 if ( (my_hostent = gethostbyname( hpc_host->value ) ) == NULL){ 112 herror("gethostbyname"); 113 setMapInMaps(conf,"lenv","message",_("Issue when invoking gethostbyname!")); 114 return NULL; 115 } 116 117 addrs = (struct in_addr **) my_hostent->h_addr_list; 118 119 for(i = 0; addrs[i] != NULL; i++) { 120 strcpy(ip , inet_ntoa(*addrs[i]) ); 121 break; 122 } 123 } 107 124 108 125 #ifdef WIN32 … … 117 134 #endif 118 135 119 // TODO: fetch ip address for the hostname120 136 if (hpc_host != NULL) { 121 hostaddr = inet_addr( hpc_host->value);137 hostaddr = inet_addr(ip); 122 138 } else { 123 139 setMapInMaps(conf,"lenv","message","No host parameter found in your main.cfg file!\n"); … … 235 251 int ssh_get_cnt(maps* conf){ 236 252 int result=0; 237 map* myMap=getMapFromMaps(conf,"lenv"," cnt_session");253 map* myMap=getMapFromMaps(conf,"lenv","nb_sessions"); 238 254 if(myMap!=NULL){ 239 255 result=atoi(myMap->value); … … 323 339 return false; 324 340 } 325 341 326 342 do { 327 343 sessions[cnt]->sftp_session = libssh2_sftp_init(sessions[cnt]->session); … … 391 407 * @param targetPath const char* defining the path for accessing the file on the 392 408 * remote host 393 * @return true in case of success, falseif failure occured409 * @return 0 in case of success, -1 if failure occured 394 410 */ 395 411 int ssh_fetch(maps* conf,const char* localPath,const char* targetPath,int cnt){ … … 414 430 415 431 fprintf(stderr, "Unable to init SFTP session\n"); 416 return false;432 return -1; 417 433 } 418 434 } while (!sessions[cnt]->sftp_session); 435 do { 436 sftp_handle = libssh2_sftp_open(sessions[cnt]->sftp_session, targetPath, 437 LIBSSH2_FXF_READ, 0); 438 if (!sftp_handle) { 439 if (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN) { 440 fprintf(stderr, " ** Unable to open file with SFTP\n"); 441 return -1; 442 } 443 else { 444 //non-blocking open 445 waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session); 446 } 447 } 448 } while (!sftp_handle); 449 450 int result=0; 451 do { 419 452 do { 420 sftp_handle = libssh2_sftp_open(sessions[cnt]->sftp_session, targetPath, 421 422 LIBSSH2_FXF_READ, 0); 423 424 if (!sftp_handle) { 425 if (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN) { 426 fprintf(stderr, "Unable to open file with SFTP\n"); 427 return -1; 428 } 429 else { 430 fprintf(stderr, "non-blocking open\n"); 431 waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session); 432 } 433 } 434 } while (!sftp_handle); 435 436 int result=1; 437 do { 438 do { 439 rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem)); 440 /*fprintf(stderr, "libssh2_sftp_read returned %d\n", 441 rc);*/ 442 if(rc > 0) { 443 //write(2, mem, rc); 444 fwrite(mem, rc, 1, local); 445 } 446 } while (rc > 0); 447 448 if(rc != LIBSSH2_ERROR_EAGAIN) { 449 result=-1; 450 break; 451 } 452 453 struct timeval timeout; 454 fd_set fd; 455 timeout.tv_sec = 10; 456 timeout.tv_usec = 0; 457 458 FD_ZERO(&fd); 459 460 FD_SET(sessions[cnt]->sock_id, &fd); 461 462 rc = select(sessions[cnt]->sock_id+1, &fd, &fd, NULL, &timeout); 463 if(rc <= 0) { 464 if(rc==0) 465 fprintf(stderr, "SFTP download timed out: %d\n", rc); 466 else 467 fprintf(stderr, "SFTP download error: %d\n", rc); 468 result=-1; 469 break; 470 } 471 472 } while (1); 453 rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem)); 454 /*fprintf(stderr, "libssh2_sftp_read returned %d\n", 455 rc);*/ 456 if(rc > 0) { 457 //write(2, mem, rc); 458 fwrite(mem, rc, 1, local); 459 } 460 } while (rc > 0); 461 462 if(rc != LIBSSH2_ERROR_EAGAIN) { 463 result=-1; 464 break; 465 } 466 467 struct timeval timeout; 468 fd_set fd; 469 timeout.tv_sec = 10; 470 timeout.tv_usec = 0; 471 472 FD_ZERO(&fd); 473 474 FD_SET(sessions[cnt]->sock_id, &fd); 475 476 rc = select(sessions[cnt]->sock_id+1, &fd, &fd, NULL, &timeout); 477 if(rc <= 0) { 478 if(rc==0) 479 fprintf(stderr, "SFTP download timed out: %d\n", rc); 480 else 481 fprintf(stderr, "SFTP download error: %d\n", rc); 482 return -1; 483 } 484 485 } while (1); 473 486 duration = (int)(time(NULL)-start); 474 487 fclose(local); 475 488 libssh2_sftp_close_handle(sftp_handle); 476 477 489 libssh2_sftp_shutdown(sessions[cnt]->sftp_session); 478 490 return 0; … … 491 503 int exitcode; 492 504 char *exitsignal=(char *)"none"; 505 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 506 fflush(stderr); 493 507 while( (channel = libssh2_channel_open_session(sessions[cnt]->session)) == NULL && 494 508 libssh2_session_last_error(sessions[cnt]->session,NULL,NULL,0) == LIBSSH2_ERROR_EAGAIN ) { 509 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 510 fflush(stderr); 495 511 waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session); 496 512 } 513 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 514 fflush(stderr); 497 515 if( channel == NULL ){ 498 516 fprintf(stderr,"Error\n"); 499 return 1; 500 } 517 return -1; 518 } 519 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 520 fflush(stderr); 501 521 while( (rc = libssh2_channel_exec(channel, command)) == LIBSSH2_ERROR_EAGAIN ) { 522 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 523 fflush(stderr); 502 524 waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session); 503 525 } 526 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 527 fflush(stderr); 504 528 if( rc != 0 ) { 505 529 fprintf(stderr,"Error\n"); 506 530 return -1; 507 531 } 532 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 533 fflush(stderr); 508 534 509 535 map* tmpPath=getMapFromMaps(conf,"main","tmpPath"); … … 513 539 FILE* logFile=fopen(logPath,"wb"); 514 540 free(logPath); 541 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 542 fflush(stderr); 515 543 while(true){ 516 544 int rc; … … 535 563 break; 536 564 } 565 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 566 fflush(stderr); 537 567 fclose(logFile); 568 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 569 fflush(stderr); 538 570 exitcode = 127; 571 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 572 fflush(stderr); 539 573 while( (rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN ) 540 574 waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session); 575 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 576 fflush(stderr); 541 577 542 578 if( rc == 0 ) { … … 545 581 NULL, NULL, NULL, NULL, NULL); 546 582 } 583 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 584 fflush(stderr); 547 585 548 586 if (exitsignal) … … 550 588 else 551 589 fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount); 590 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 591 fflush(stderr); 552 592 553 593 libssh2_channel_free(channel); … … 643 683 } 644 684 #ifdef DEBUG 645 fprintf(stderr," %s %d\n",__FILE__,__LINE__);685 fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__); 646 686 fflush(stderr); 647 687 dumpMaps(getMaps(*conf,"uploadQueue")); 648 fprintf(stderr," %s %d\n",__FILE__,__LINE__);688 fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__); 649 689 fflush(stderr); 650 690 #endif … … 660 700 getMapArray(queueMaps->content,"targetPath",i) 661 701 }; 662 fprintf(stderr,"%s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value); 663 ssh_copy(*conf,argv[1]->value,argv[2]->value,ssh_get_cnt(*conf)); 702 fprintf(stderr,"*** %s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value); 703 /**/zooLock* lck; 704 if((lck=lockFile(*conf,argv[1]->value,'w'))!=NULL){/**/ 705 if(ssh_copy(*conf,argv[1]->value,argv[2]->value,ssh_get_cnt(*conf))!=true){ 706 char* templateStr=_("Unable to copy over SSH the file requested for setting the value of %s."); 707 char *tmpMessage=(char*)malloc((strlen(templateStr)+strlen(argv[0]->value)+1)*sizeof(char)); 708 sprintf(tmpMessage,templateStr,argv[0]->value); 709 setMapInMaps(*conf,"lenv","message",tmpMessage); 710 free(tmpMessage); 711 unlockFile(*conf,lck); 712 return false; 713 } 714 /**/unlockFile(*conf,lck); 715 }else{ 716 setMapInMaps(*conf,"lenv","message",_("Unable to lock the file for upload!")); 717 return false; 718 }/**/ 664 719 } 665 720 } -
branches/prototype-v0/zoo-project/zoo-kernel/sshapi.h
r839 r854 57 57 #include <sys/time.h> 58 58 #endif 59 59 60 #include <netdb.h> 60 61 #include <arpa/inet.h> 61 62 #include <sys/types.h> -
branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c
r851 r854 211 211 ret.agent=strdup(lpszAgent); 212 212 ret.nb=0; 213 ret.waitingRequests[ret.nb] = NULL; 213 214 ret.ihandle[ret.nb].header=NULL; 215 ret.ihandle[ret.nb].handle=NULL; 216 ret.ihandle[ret.nb].hasCacheFile=0; 217 ret.ihandle[ret.nb].nDataAlloc = 0; 218 ret.ihandle[ret.nb].url = NULL; 219 ret.ihandle[ret.nb].mimeType = NULL; 220 ret.ihandle[ret.nb].cookie = NULL; 221 ret.ihandle[ret.nb].nDataLen = 0; 222 ret.ihandle[ret.nb].nDataAlloc = 0; 223 ret.ihandle[ret.nb].pabyData = NULL; 224 ret.ihandle[ret.nb].post = NULL; 214 225 return ret; 226 } 227 228 /** 229 * Verify if the URL should use a shared cache or not. 230 * 231 * In case the security section contains a key named "shared", then if the 232 * domain listed in the shared key are contained in the url given as parameter 233 * then it return "SHARED" in other cases, it returns "OTHER". 234 * 235 * @param conf the main configuration file maps 236 * @param url the URL to evaluate 237 * @return a string "SHARED" in case the host is in a domain listed in the 238 * shared key, "OTHER" in other cases. 239 */ 240 char* getProvenance(maps* conf,const char* url){ 241 map* sharedCache=getMapFromMaps(conf,"security","shared"); 242 if(sharedCache!=NULL){ 243 char *res=NULL; 244 char *hosts=sharedCache->value; 245 char *curs=strtok(hosts,","); 246 while(curs!=NULL){ 247 fprintf(stderr,"### %s %d %s \n",__FILE__,__LINE__,strstr(url,curs)); 248 fflush(stderr); 249 if(strstr(url,curs)==NULL) 250 res="OTHER"; 251 else{ 252 res="SHARED"; 253 fprintf(stderr,"### %s %d %s \n",__FILE__,__LINE__,"SHARED"); 254 fflush(stderr); 255 return res; 256 } 257 curs=strtok(NULL,","); 258 } 259 return res; 260 } 261 return "OTHER"; 215 262 } 216 263 … … 282 329 int i; 283 330 for(i=0;i<handle->nb;i++){ 284 if( targetHosts->value[0]=='*'|| isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){331 if(strstr(targetHosts->value,"*")!=NULL || isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){ 285 332 while (token != NULL){ 286 333 int length=strlen(token)+6; … … 297 344 } 298 345 fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,tmp1); 299 if(strncmp(tmp1,"HTTP_COOKIE",11)!=0){ 300 tmpMap = getMapFromMaps(conf,"renv",tmp1); 301 if(tmpMap!=NULL) 302 AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value); 346 //dumpMaps(conf); 347 tmpMap = getMapFromMaps(conf,"renv",tmp1); 348 if(tmpMap!=NULL){ 349 fprintf(stderr,"add header %s %s\n",token,tmpMap->value); 350 fflush(stderr); 351 AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value); 303 352 } 304 353 free(tmp1); … … 321 370 void InternetCloseHandle(HINTERNET* handle0){ 322 371 int i=0; 323 for(i=0;i<handle0->nb;i++){ 324 _HINTERNET handle=handle0->ihandle[i]; 325 if(handle.hasCacheFile>0){ 326 fclose(handle.file); 327 unlink(handle.filename); 328 } 329 else{ 330 handle.pabyData = NULL; 331 handle.nDataAlloc = handle.nDataLen = 0; 332 } 333 if(handle0->ihandle[i].header!=NULL){ 334 curl_slist_free_all(handle0->ihandle[i].header); 335 handle0->ihandle[i].header=NULL; 336 } 337 if(handle.post!=NULL) 338 free(handle.post); 339 if(handle.url!=NULL) 340 free(handle.url); 341 if(handle.mimeType!=NULL) 342 free(handle.mimeType); 343 if(handle.cookie!=NULL) 344 free(handle.cookie); 345 } 346 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 347 fflush(stderr); 348 if(handle0->handle) 349 curl_multi_cleanup(handle0->handle); 350 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 351 fflush(stderr); 352 free(handle0->agent); 353 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 354 fflush(stderr); 355 for(i=handle0->nb-1;i>=0;i--){ 356 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 357 fflush(stderr); 358 free(handle0->waitingRequests[i]); 359 fprintf(stderr,"%s%d\n",__FILE__,__LINE__); 360 fflush(stderr); 372 if(handle0!=NULL){ 373 for(i=0;i<handle0->nb;i++){ 374 _HINTERNET handle=handle0->ihandle[i]; 375 if(handle.hasCacheFile>0){ 376 fclose(handle.file); 377 unlink(handle.filename); 378 } 379 else{ 380 handle.pabyData = NULL; 381 handle.nDataAlloc = handle.nDataLen = 0; 382 } 383 if(handle.header!=NULL){ 384 curl_slist_free_all(handle.header); 385 handle.header=NULL; 386 } 387 if(handle.post!=NULL){ 388 free(handle.post); 389 handle.post=NULL; 390 } 391 if(handle.url!=NULL){ 392 free(handle.url); 393 handle.url=NULL; 394 } 395 if(handle.mimeType!=NULL){ 396 free(handle.mimeType); 397 handle.mimeType=NULL; 398 } 399 if(handle.cookie!=NULL){ 400 free(handle.cookie); 401 handle.cookie=NULL; 402 } 403 if(handle0->waitingRequests[i]!=NULL){ 404 free(handle0->waitingRequests[i]); 405 handle0->waitingRequests[i]=NULL; 406 } 407 } 408 if(handle0->handle) 409 curl_multi_cleanup(handle0->handle); 410 if(handle0->agent!=NULL){ 411 free(handle0->agent); 412 handle0->agent=NULL; 413 } 361 414 } 362 415 } … … 377 430 struct MemoryStruct header; 378 431 432 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 433 fflush(stderr); 379 434 hInternet->ihandle[hInternet->nb].handle=curl_easy_init( ); 435 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 436 fflush(stderr); 380 437 hInternet->ihandle[hInternet->nb].hasCacheFile=0; 438 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 439 fflush(stderr); 381 440 hInternet->ihandle[hInternet->nb].nDataAlloc = 0; 441 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 442 fflush(stderr); 382 443 hInternet->ihandle[hInternet->nb].url = NULL; 444 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 445 fflush(stderr); 383 446 hInternet->ihandle[hInternet->nb].mimeType = NULL; 447 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 448 fflush(stderr); 384 449 hInternet->ihandle[hInternet->nb].cookie = NULL; 450 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 451 fflush(stderr); 385 452 hInternet->ihandle[hInternet->nb].nDataLen = 0; 453 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 454 fflush(stderr); 386 455 hInternet->ihandle[hInternet->nb].id = hInternet->nb; 456 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 457 fflush(stderr); 387 458 hInternet->ihandle[hInternet->nb].nDataAlloc = 0; 459 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 460 fflush(stderr); 388 461 hInternet->ihandle[hInternet->nb].pabyData = NULL; 462 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 463 fflush(stderr); 389 464 hInternet->ihandle[hInternet->nb].post = NULL; 465 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 466 fflush(stderr); 390 467 391 468 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIEFILE, "ALL"); 469 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 470 fflush(stderr); 392 471 #ifndef TIGER 393 472 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIELIST, "ALL"); 394 473 #endif 395 474 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_USERAGENT, hInternet->agent); 475 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 476 fflush(stderr); 396 477 397 478 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_FOLLOWLOCATION,1); 479 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 480 fflush(stderr); 398 481 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_MAXREDIRS,3); 482 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 483 fflush(stderr); 399 484 400 485 header.memory=NULL; … … 402 487 403 488 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_HEADERFUNCTION, header_write_data); 489 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 490 fflush(stderr); 404 491 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEHEADER, (void *)&header); 492 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 493 fflush(stderr); 405 494 406 495 #ifdef MSG_LAF_VERBOSE … … 431 520 break; 432 521 } 522 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 523 fflush(stderr); 433 524 #ifdef ULINET_DEBUG 434 525 fprintf(stderr,"URL (%s)\nBODY (%s)\n",lpszUrl,lpszHeaders); … … 448 539 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDSIZE,(long)dwHeadersLength); 449 540 } 541 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 542 fflush(stderr); 450 543 if(hInternet->ihandle[hInternet->nb].header!=NULL) 451 544 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_HTTPHEADER,hInternet->ihandle[hInternet->nb].header); 452 545 546 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 547 fflush(stderr); 453 548 curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_URL,lpszUrl); 454 549 hInternet->ihandle[hInternet->nb].url = zStrdup(lpszUrl); 550 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 551 fflush(stderr); 455 552 456 553 curl_multi_add_handle(hInternet->handle,hInternet->ihandle[hInternet->nb].handle); 554 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 555 fflush(stderr); 457 556 458 557 hInternet->ihandle[hInternet->nb].header=NULL; 558 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 559 fflush(stderr); 459 560 ++hInternet->nb; 561 hInternet->ihandle[hInternet->nb].header=NULL; 460 562 461 563 #ifdef ULINET_DEBUG … … 481 583 for(i=0;i<hInternet->nb;i++){ 482 584 char *tmp; 585 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 483 586 curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_CONTENT_TYPE,&tmp); 587 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 484 588 if(tmp!=NULL) 485 589 hInternet->ihandle[i].mimeType=strdup(tmp); 590 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 486 591 curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_RESPONSE_CODE,&hInternet->ihandle[i].code); 592 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 487 593 curl_multi_remove_handle(hInternet->handle, hInternet->ihandle[i].handle); 594 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 488 595 curl_easy_cleanup(hInternet->ihandle[i].handle); 596 fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i); 489 597 //fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,hInternet->ihandle[i].mimeType); 490 598 //fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,hInternet->ihandle[i].pabyData); -
branches/prototype-v0/zoo-project/zoo-kernel/ulinet.h
r839 r854 128 128 HINTERNET InternetOpen(char*,int,char*,char*,int); 129 129 130 char* getProvenance(maps*,const char*); 130 131 int isProtectedHost(const char*,const char*); 131 132 int AddMissingHeaderEntry(_HINTERNET*,const char*,const char*); -
branches/prototype-v0/zoo-project/zoo-kernel/zoo_loader.c
r790 r854 86 86 fflush(stderr); 87 87 #endif 88 fprintf (stderr, "Addr:%s\n", cgiRemoteAddr); 89 fprintf (stderr, "RequestMethod: (%s) %d %d\n", cgiRequestMethod,strncasecmp(cgiRequestMethod,"post",4),strncmp(cgiContentType,"text/xml",8)==0 || strncasecmp(cgiRequestMethod,"post",4)==0); 90 fprintf (stderr, "Request: %s\n", cgiQueryString); 91 fprintf (stderr, "ContentType: %s\n", cgiContentType); 92 fprintf (stderr, "ContentLength: %d\n", cgiContentLength); 93 fflush(stderr); 88 94 89 95 char *strQuery=NULL; -
branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
r851 r854 107 107 #include <dirent.h> 108 108 #include <signal.h> 109 #include <execinfo.h> 109 110 #include <unistd.h> 110 111 #ifndef WIN32 … … 122 123 #include <time.h> 123 124 #include <stdarg.h> 125 126 #include <libxml/tree.h> 127 #include <libxml/parser.h> 128 #include <libxml/xpath.h> 129 #include <libxml/xpathInternals.h> 130 131 #include <libxslt/xslt.h> 132 #include <libxslt/xsltInternals.h> 133 #include <libxslt/transform.h> 134 #include <libxslt/xsltutils.h> 124 135 125 136 #ifndef WIN32 … … 385 396 sig_handler (int sig) 386 397 { 398 387 399 char tmp[100]; 388 400 const char *ssig; … … 413 425 sprintf (tmp, 414 426 _ 415 ("ZOO Kernel failed to process your request, receiving signal %d = %s "),427 ("ZOO Kernel failed to process your request, receiving signal %d = %s "), 416 428 sig, ssig); 417 429 errorException (NULL, tmp, "InternalError", NULL); … … 990 1002 #ifdef ETC_DIR 991 1003 #ifndef WIN32 992 1004 getcwd (ntmp, 1024); 993 1005 #else 994 1006 _getcwd (ntmp, 1024); 995 1007 #endif 996 1008 #endif … … 1184 1196 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 1185 1197 fflush(stderr); 1186 dumpMap(r_inputs);1198 //dumpMap(r_inputs); 1187 1199 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 1188 1200 fflush(stderr); … … 1294 1306 } 1295 1307 1308 dumpMap(request_inputs); 1309 1296 1310 if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0) 1297 1311 { … … 1348 1362 #ifdef META_DB 1349 1363 fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1); 1350 fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);1351 1364 close_sql(m,0); 1352 1365 #endif … … 1430 1443 r_inputs = NULL; 1431 1444 r_inputs = getMap (request_inputs, "version"); 1445 fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__); 1446 fflush(stderr); 1432 1447 xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess", 1433 1448 root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1); … … 1519 1534 free (REQUEST); 1520 1535 closedir (dirp); 1521 xmlFreeDoc (doc);1536 //xmlFreeDoc (doc); 1522 1537 xmlCleanupParser (); 1523 1538 zooXmlCleanupNs (); … … 1550 1565 addToMap (request_inputs, "metapath", tmpMap->value); 1551 1566 map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier"); 1567 /** 1568 * No support for dot in service name stored in metadb!? 1552 1569 #ifdef META_DB 1553 service* s2=extractServiceFromDb(m,tmpMapI-> name,0);1570 service* s2=extractServiceFromDb(m,tmpMapI->value,0); 1554 1571 if(s2==NULL){ 1555 1572 #endif 1573 */ 1556 1574 s1 = (service *) malloc (SERVICE_SIZE); 1557 1575 t = readServiceFile (m, buff1, &s1, tmpMapI->value); … … 1585 1603 free (s1); 1586 1604 closedir (dirp); 1587 xmlFreeDoc (doc);1605 //xmlFreeDoc (doc); 1588 1606 xmlCleanupParser (); 1589 1607 zooXmlCleanupNs (); … … 1604 1622 hasVal = 1; 1605 1623 setMapInMaps (m, "lenv", "level", "0"); 1624 /* 1606 1625 #ifdef META_DB 1607 1626 } 1608 1627 #endif 1628 */ 1609 1629 } 1610 1630 else … … 1688 1708 free (REQUEST); 1689 1709 closedir (dirp); 1690 xmlFreeDoc (doc);1710 //xmlFreeDoc (doc); 1691 1711 xmlCleanupParser (); 1692 1712 zooXmlCleanupNs (); … … 1736 1756 free (REQUEST); 1737 1757 closedir (dirp); 1738 xmlFreeDoc (doc);1758 //xmlFreeDoc (doc); 1739 1759 xmlCleanupParser (); 1740 1760 zooXmlCleanupNs (); … … 1843 1863 } 1844 1864 s1 = NULL; 1845 if(postRequest!=NULL) 1846 setMapInMaps (m, "lenv", "xrequest", postRequest->value); 1847 1865 1848 1866 r_inputs = getMap (request_inputs, "Identifier"); 1849 1867 map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value); … … 1880 1898 fprintf(stderr,"CONNECTING METADB!\n"); 1881 1899 //FAILED CONNECTING DB 1882 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL ){1900 if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){ 1883 1901 fprintf(stderr,"ERROR CONNECTING METADB\n"); 1884 1902 } 1885 s1=extractServiceFromDb(m,r_inputs->value,0); 1903 if(metadb_id>=0) 1904 s1=extractServiceFromDb(m,r_inputs->value,0); 1886 1905 //close_sql(m,0); 1887 1906 if(s1!=NULL){ … … 2181 2200 { 2182 2201 int hasValidCookie = -1; 2183 char *tcook = zStrdup (cgiCookie); 2202 char *tcook = originalCookie = zStrdup (cgiCookie); 2203 //fprintf(stderr,">>>>> %s %d %s\n",__FILE__,__LINE__,tcook ); 2184 2204 char *tmp = NULL; 2185 2205 map *testing = getMapFromMaps (m, "main", "cookiePrefix"); 2206 parseCookie(&m,originalCookie); 2186 2207 if (testing == NULL) 2187 2208 { … … 2197 2218 { 2198 2219 char *token, *saveptr; 2199 token = strtok_r ( cgiCookie, ";", &saveptr);2220 token = strtok_r (tcook, ";", &saveptr); 2200 2221 while (token != NULL) 2201 2222 { … … 2244 2265 if (istat == 0 && file_status.st_size > 0) 2245 2266 { 2267 int saved_stdout = dup (fileno (stdout)); 2268 dup2 (fileno (stderr), fileno (stdout)); 2246 2269 conf_read (session_file_path, tmpSess); 2247 2270 addMapsToMaps (&m, tmpSess); 2248 2271 freeMaps (&tmpSess); 2272 fflush(stdout); 2273 dup2 (saved_stdout, fileno (stdout)); 2274 close(saved_stdout); 2249 2275 } 2250 2276 free (tmpSess); … … 2273 2299 char* tmpName=zStrdup(s); 2274 2300 char* tmpValue=strstr(s,"=")+1; 2275 char* tmpName1=(char*)malloc((1+(len- strlen(tmpValue)))*sizeof(char));2276 snprintf(tmpName1,(len-strlen(tmpValue)) +1,"%s",tmpName);2301 char* tmpName1=(char*)malloc((1+(len-(strlen(tmpValue)+1)))*sizeof(char)); 2302 snprintf(tmpName1,(len-strlen(tmpValue)),"%s",tmpName); 2277 2303 if(_tmpMaps->content == NULL) 2278 2304 _tmpMaps->content = createMap (tmpName1,tmpValue); … … 2285 2311 } 2286 2312 if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){ 2287 /*map* tmpMap1=getMap(_tmpMaps->content,"HTTP_COOKIE");2288 free(tmpMap1->value);2289 tmpMap1->value=zStrdup(cgiCookie);*/2290 fprintf(stderr,"[%s]\n",cgiCookie);2291 2313 addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]); 2292 dumpMap(_tmpMaps->content);2293 2314 } 2294 2315 addMapsToMaps (&m, _tmpMaps); 2295 2316 freeMaps (&_tmpMaps); 2296 2317 free (_tmpMaps); 2297 2318 if(postRequest!=NULL) 2319 setMapInMaps (m, "renv", "xrequest", postRequest->value); 2320 //dumpMaps(m); 2298 2321 #ifdef WIN32 2299 2322 char *cgiSidL = NULL; … … 2334 2357 "ZooWPSClient\0", 2335 2358 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);*/ 2336 2337 2359 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2338 2360 freeService (&s1); … … 2350 2372 return -1; 2351 2373 } 2352 fprintf(stderr,"*************************\n\n");2353 //fprintf(stderr,"%s \n",json_object_to_json_string_ext(mapsToJson(request_input_real_format),JSON_C_TO_STRING_PLAIN));2354 fprintf(stderr,"*************************\n\n");2355 2374 loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format, 2356 2375 &request_output_real_format, &eres); 2357 #ifdef RELY_ON_DB 2376 2358 2377 #ifdef META_DB 2359 close_sql(m,1); 2378 close_sql(m,0); 2379 #endif 2380 2381 /*#ifdef RELY_ON_DB 2382 //close_sql(m,1); 2360 2383 //end_sql(); 2361 #endif 2362 close_sql(m,0); 2363 #endif 2384 #endif*/ 2364 2385 } 2365 2386 else … … 2387 2408 } 2388 2409 #endif 2410 //InternetCloseHandle (&hInternet); 2389 2411 if (pid > 0) 2390 2412 { … … 2411 2433 setMapInMaps (m, "lenv", "async","true"); 2412 2434 map* r_inputs1 = createMap("ServiceName", s1->name); 2435 2436 /*hInternet = InternetOpen ( 2437 #ifndef WIN32 2438 (LPCTSTR) 2439 #endif 2440 "ZooWPSClient\0", 2441 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 2442 #ifndef WIN32 2443 if (!CHECK_INET_HANDLE (hInternet)) 2444 fprintf (stderr, "WARNING : hInternet handle failed to initialize"); 2445 #endif*/ 2413 2446 2414 2447 // Create the filename for the result file (.res) … … 2525 2558 invokeCallback(m,request_input_real_format,NULL,1,0); 2526 2559 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2560 dumpMaps(request_output_real_format); 2527 2561 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ 2528 2562 freeService (&s1); 2529 2563 free (s1); 2564 fflush (stdout); 2565 fflush (stderr); 2530 2566 fclose (f0); 2531 2567 fclose (f1); 2532 2568 if(dumpBackFinalFile(m,fbkp,fbkp1)<0) 2533 2569 return -1; 2570 //dumpBackFinalFile(m,fbkp,fbkp1); 2571 #ifndef RELY_ON_DB 2572 dumpMapsToFile(bmap,fbkpres,1); 2573 removeShmLock (m, 1); 2574 #else 2575 recordResponse(m,fbkp1); 2576 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2577 invokeCallback(m,NULL,NULL,7,0); 2578 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2579 #endif 2534 2580 unlink (fbkpid); 2535 2581 unhandleStatus (m); 2582 #ifdef RELY_ON_DB 2583 #ifdef META_DB 2584 cleanupCallbackThreads(); 2585 close_sql(m,1); 2586 //end_sql(); 2587 #endif 2588 close_sql(m,0); 2589 #endif 2536 2590 freeMaps (&m); 2537 2591 free (m); … … 2544 2598 freeMaps (&tmpmaps); 2545 2599 free (tmpmaps); 2546 fflush (stdout);2547 fflush (stderr);2548 2600 return -1; 2549 2601 } 2602 dumpMaps(request_output_real_format); 2550 2603 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2551 2604 invokeCallback(m,request_input_real_format,NULL,1,1); 2552 2605 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2553 setMapInMaps(m,"lenv","ds_nb","1"); 2554 loadServiceAndRun (&m, s1, request_inputs, 2555 &request_input_real_format, 2556 &request_output_real_format, &eres); 2606 if(getMapFromMaps(m,"lenv","mapError")!=NULL){ 2607 setMapInMaps(m,"lenv","message",_("Issue with geographic data")); 2608 invokeCallback(m,NULL,NULL,7,0); 2609 eres=-1;//SERVICE_FAILED; 2610 }else{ 2611 setMapInMaps(m,"lenv","ds_nb","0"); 2612 close_sql(m,0); 2613 loadServiceAndRun (&m, s1, request_inputs, 2614 &request_input_real_format, 2615 &request_output_real_format, &eres); 2616 setMapInMaps(m,"lenv","ds_nb","2"); 2617 } 2557 2618 } 2558 2619 else … … 2573 2634 fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__); 2574 2635 #endif 2636 fflush(stdout); 2637 rewind(stdout); 2575 2638 if (eres != -1) 2576 2639 outputResponse (s1, request_input_real_format, … … 2595 2658 if (((int) getpid ()) != cpid || cgiSid != NULL) 2596 2659 { 2597 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2660 if (eres == SERVICE_SUCCEEDED) 2661 invokeCallback(m,NULL,request_output_real_format,5,1); 2662 2598 2663 fflush(stderr); 2599 invokeCallback(m,NULL,request_output_real_format,5,1); 2600 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2601 fflush(stderr); 2664 fflush(stdout); 2602 2665 2603 2666 fclose (stdout); … … 2619 2682 setMapInMaps(m,"lenv","fstate",wpsStatus[0]); 2620 2683 break; 2621 } 2684 } 2622 2685 #ifndef RELY_ON_DB 2623 2686 dumpMapsToFile(bmap,fbkpres,1); … … 2625 2688 #else 2626 2689 recordResponse(m,fbkp1); 2627 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2628 invokeCallback(m,NULL,request_output_real_format,6,0); 2629 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 2690 if (eres == SERVICE_SUCCEEDED) 2691 invokeCallback(m,NULL,request_output_real_format,6,0); 2630 2692 #endif 2631 2693 freeMaps(&bmap); … … 2637 2699 cleanupCallbackThreads(); 2638 2700 close_sql(m,1); 2639 //end_sql();2640 2701 #endif 2641 2702 close_sql(m,0); 2642 #endif 2643 unlink (flog); 2703 end_sql(); 2704 #endif 2644 2705 free(fbkpid); 2645 2706 free(fbkpres); 2646 free (flog);2647 2707 free (fbkp1); 2648 2708 // free (tmps1); // tmps1 is stack memory and should not be freed … … 2653 2713 fflush(stderr); 2654 2714 fclose (stderr); 2715 unlink (flog); 2716 free (flog); 2655 2717 } 2656 2718 else{
Note: See TracChangeset
for help on using the changeset viewer.