Changeset 469 for trunk/zoo-project
- Timestamp:
- May 1, 2014, 1:28:14 AM (11 years ago)
- Location:
- trunk/zoo-project
- Files:
-
- 3 added
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service.h
r466 r469 430 430 map *tmp=getMap(m,n); 431 431 if(tmp->value!=NULL) 432 432 free(tmp->value); 433 433 tmp->value=zStrdup(v); 434 434 } … … 450 450 while(_cursor->next!=NULL) 451 451 _cursor=_cursor->next; 452 map* tmp1=getMap( _cursor,tmp->name);453 if(tmp1==NULL) 452 map* tmp1=getMap(*mo,tmp->name); 453 if(tmp1==NULL){ 454 454 _cursor->next=createMap(tmp->name,tmp->value); 455 } 455 456 else{ 456 free(tmp1->value); 457 if(tmp1->value!=NULL) 458 free(tmp1->value); 457 459 tmp1->value=zStrdup(tmp->value); 458 460 } … … 567 569 } 568 570 else{ 569 maps* tmp1=getMaps(*mo,tmp->name);570 571 while(_cursor->next!=NULL) 571 572 _cursor=_cursor->next; 573 maps* tmp1=getMaps(*mo,tmp->name); 572 574 if(tmp1==NULL) 573 575 _cursor->next=dupMaps(&tmp); … … 687 689 _ztmpm->value=zStrdup(value); 688 690 }else{ 689 addToMap(_tmpm->content,subkey,value); 691 maps *tmp=(maps*)malloc(MAPS_SIZE); 692 tmp->name=zStrdup(key); 693 tmp->content=createMap(subkey,value); 694 tmp->next=NULL; 695 addMapsToMaps(&_tmpm,tmp); 696 freeMaps(&tmp); 697 free(tmp); 690 698 } 691 699 }else{ -
trunk/zoo-project/zoo-kernel/service_conf.y
r465 r469 204 204 dumpService(my_service); 205 205 #endif 206 if(my_service->inputs==NULL ){206 if(my_service->inputs==NULL && current_element!=NULL && current_element->name!=NULL){ 207 207 my_service->inputs=dupElements(current_element); 208 208 my_service->inputs->next=NULL; 209 freeElements(¤t_element); 209 210 } 210 211 else if(current_element!=NULL && current_element->name!=NULL){ 211 212 addToElements(&my_service->inputs,current_element); 213 freeElements(¤t_element); 212 214 } 213 215 #ifdef DEBUG_SERVICE_CONF … … 218 220 fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n"); 219 221 #endif 220 freeElements(¤t_element);221 222 free(current_element); 222 223 current_element=NULL; … … 848 849 dumpService(my_service); 849 850 #endif 850 if(wait_outputs<0 || my_service==NULL || my_service->name==NULL || my_service->content==NULL || my_service-> inputs==NULL || my_service->outputs==NULL){851 if(wait_outputs<0 || my_service==NULL || my_service->name==NULL || my_service->content==NULL || my_service->outputs==NULL){ 851 852 setMapInMaps(conf,"lenv","message",srlval.chaine); 852 853 #ifndef WIN32 -
trunk/zoo-project/zoo-kernel/service_internal.c
r467 r469 756 756 } 757 757 758 void addPrefix(maps* conf,map* level,service* serv){ 759 if(level!=NULL){ 760 char key[25]; 761 char* prefix=NULL; 762 int clevel=atoi(level->value); 763 int cl=0; 764 for(cl=0;cl<clevel;cl++){ 765 sprintf(key,"sprefix_%d",cl); 766 map* tmp2=getMapFromMaps(conf,"lenv",key); 767 if(tmp2!=NULL){ 768 if(prefix==NULL) 769 prefix=zStrdup(tmp2->value); 770 else{ 771 int plen=strlen(prefix); 772 prefix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char)); 773 memcpy(prefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char)); 774 prefix[plen+strlen(tmp2->value)]=0; 775 } 776 } 777 } 778 if(prefix!=NULL){ 779 char* tmp0=strdup(serv->name); 780 free(serv->name); 781 serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char)); 782 sprintf(serv->name,"%s%s",prefix,tmp0); 783 free(tmp0); 784 free(prefix); 785 prefix=NULL; 786 } 787 } 788 } 789 758 790 void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){ 759 791 xmlNsPtr ns,ns_ows,ns_xlink; … … 776 808 if(tmp1!=NULL) 777 809 xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); 810 map* tmp3=getMapFromMaps(m,"lenv","level"); 811 addPrefix(m,tmp3,serv); 778 812 printDescription(nc1,ns_ows,serv->name,serv->content); 779 813 tmp1=serv->metadata; … … 816 850 } 817 851 818 void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv ,int sc){852 void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv){ 819 853 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; 820 854 xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; … … 851 885 } 852 886 887 tmp1=getMapFromMaps(m,"lenv","level"); 888 addPrefix(m,tmp1,serv); 853 889 printDescription(nc,ns_ows,serv->name,serv->content); 854 890 … … 1860 1896 void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap){ 1861 1897 xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); 1898 1862 1899 xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); 1863 1900 xmlAddChild(root,nc2); … … 1904 1941 1905 1942 void printExceptionReportResponse(maps* m,map* s){ 1943 if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL) 1944 return; 1906 1945 int buffersize; 1907 1946 xmlDocPtr doc; … … 1958 1997 xmlCleanupParser(); 1959 1998 zooXmlCleanupNs(); 1999 setMapInMaps(m,"lenv","hasPrinted","true"); 1960 2000 } 1961 2001 … … 1969 2009 maps* tmpMap=getMaps(m,"main"); 1970 2010 1971 int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows /1.1","ows");2011 int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows"); 1972 2012 ns=usedNs[nsid]; 1973 2013 n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); 1974 2014 1975 2015 if(use_ns==1){ 1976 ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1 ",BAD_CAST "ows");2016 ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1.0",BAD_CAST "ows"); 1977 2017 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 1978 2018 ns_xsi=usedNs[xsiId]; 2019 ns_xsi=xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 2020 xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"); 1979 2021 int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); 1980 2022 ns_xlink=usedNs[xlinkId]; 1981 xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd");1982 2023 } 1983 2024 addLangAttr(n,m); … … 2848 2889 return -1; 2849 2890 } 2891 2892 #ifdef USE_MS 2893 char *readVSIFile(maps* conf,const char* dataSource){ 2894 VSILFILE * fichier=VSIFOpenL(dataSource,"rb"); 2895 VSIStatBufL file_status; 2896 VSIStatL(dataSource, &file_status); 2897 if(fichier==NULL){ 2898 char tmp[1024]; 2899 sprintf(tmp,"Failed to open file %s for reading purpose. File seems empty %d.", 2900 dataSource,file_status.st_size); 2901 setMapInMaps(conf,"lenv","message",tmp); 2902 return NULL; 2903 } 2904 char *res1=(char *)malloc(file_status.st_size*sizeof(char)); 2905 VSIFReadL(res1,1,(file_status.st_size)*sizeof(char),fichier); 2906 VSIFCloseL(fichier); 2907 VSIUnlink(dataSource); 2908 return res1; 2909 } 2910 #endif 2911 2912 void parseIdentifier(maps* conf,char* conf_dir,char *identifier,char* buffer){ 2913 char *saveptr1; 2914 char *tmps1=strtok_r(identifier,".",&saveptr1); 2915 int level=0; 2916 char key[25]; 2917 char levels[18]; 2918 while(tmps1!=NULL){ 2919 char *test=zStrdup(tmps1); 2920 char* tmps2=(char*)malloc((strlen(test)+2)*sizeof(char)); 2921 sprintf(key,"sprefix_%d",level); 2922 sprintf(tmps2,"%s.",test); 2923 sprintf(levels,"%d",level); 2924 setMapInMaps(conf,"lenv","level",levels); 2925 setMapInMaps(conf,"lenv",key,tmps2); 2926 free(tmps2); 2927 level++; 2928 tmps1=strtok_r(NULL,".",&saveptr1); 2929 } 2930 int i=0; 2931 sprintf(buffer,"%s",conf_dir); 2932 for(i=0;i<level;i++){ 2933 char *tmp0=zStrdup(buffer); 2934 sprintf(key,"sprefix_%d",i); 2935 map* tmp00=getMapFromMaps(conf,"lenv",key); 2936 sprintf(buffer,"%s/%s",tmp0,tmp00->value); 2937 free(tmp0); 2938 buffer[strlen(buffer)-1]=0; 2939 if(i+1<level){ 2940 map* tmpMap=getMapFromMaps(conf,"lenv","metapath"); 2941 if(tmpMap==NULL || strlen(tmpMap->value)==0){ 2942 char *tmp01=zStrdup(tmp00->value); 2943 tmp01[strlen(tmp01)-1]=0; 2944 setMapInMaps(conf,"lenv","metapath",tmp01); 2945 free(tmp01); 2946 } 2947 else{ 2948 char *value=(char*)malloc((strlen(tmp00->value)+strlen(tmpMap->value)+2)*sizeof(char)); 2949 sprintf(value,"%s/%s",tmpMap->value,tmp00->value); 2950 value[strlen(value)-1]=0; 2951 setMapInMaps(conf,"lenv","metapath",value); 2952 free(value); 2953 } 2954 }else{ 2955 char *tmp0=zStrdup(tmp00->value); 2956 tmp0[strlen(tmp0)-1]=0; 2957 setMapInMaps(conf,"lenv","Identifier",tmp0); 2958 free(tmp0); 2959 } 2960 } 2961 char *tmp0=zStrdup(buffer); 2962 sprintf(buffer,"%s.zcfg",tmp0); 2963 free(tmp0); 2964 } 2965 -
trunk/zoo-project/zoo-kernel/service_internal.h
r467 r469 38 38 #include <sys/stat.h> 39 39 #include <sys/types.h> 40 #include "cgic.h" 40 41 #ifndef WIN32 41 42 #include <sys/ipc.h> 42 43 #include <sys/shm.h> 43 44 #else 44 #include "cgic.h"45 45 #include <direct.h> 46 46 #endif … … 56 56 #include <xlocale.h> 57 57 #endif 58 #include <dirent.h> 58 59 #include "service.h" 59 60 #include <openssl/sha.h> … … 118 119 void printGetCapabilitiesForProcess(maps*,xmlNodePtr,service*); 119 120 xmlNodePtr printDescribeProcessHeader(xmlDocPtr,const char*,maps*); 120 void printDescribeProcessForProcess(maps*,xmlNodePtr,service* ,int);121 void printDescribeProcessForProcess(maps*,xmlNodePtr,service*); 121 122 void printFullDescription(elements*,const char*,xmlNsPtr,xmlNodePtr); 122 123 void printDocument(maps*,xmlDocPtr,int); … … 144 145 int loadRemoteFile(maps*,map*,HINTERNET,char*); 145 146 147 #ifdef USE_MS 148 char *readVSIFile(maps*,const char*); 149 #endif 150 void parseIdentifier(maps*,char*,char*,char*); 151 146 152 #ifdef __cplusplus 147 153 } -
trunk/zoo-project/zoo-kernel/service_internal_python.c
r465 r469 289 289 #if PY_MAJOR_VERSION < 3 290 290 PyGILState_Release(gstate); 291 PyEval_ AcquireLock();291 PyEval_ReleaseLock(); 292 292 #endif 293 293 PyThreadState_Swap(mainstate); -
trunk/zoo-project/zoo-kernel/service_internal_python.h
r376 r469 28 28 #pragma once 29 29 30 #include "service.h"31 30 #include "service_internal.h" 32 31 #include <Python.h> 32 #include "cgic.h" 33 33 #ifdef WIN32 34 34 #include <windows.h> -
trunk/zoo-project/zoo-kernel/zcfg2yaml.c
r467 r469 30 30 int main(int argc, char** argv){ 31 31 service* s1=NULL; 32 maps *m ;32 maps *m=NULL; 33 33 char conf_file[1024]; 34 34 snprintf(conf_file,1024,"%s",argv[1]); … … 37 37 return errorException(m, _("Unable to allocate memory."),"InternalError",NULL); 38 38 } 39 int t=getServiceFromFile( conf,file,service);39 int t=getServiceFromFile(m,conf_file,&s1); 40 40 if(t>=0) 41 41 dumpServiceAsYAML(s1); -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r467 r469 189 189 } 190 190 return 0; 191 } 192 193 int recursReaddirF(maps* m,xmlNodePtr n,char *conf_dir,char *prefix,int saved_stdout,int level,void (func) (maps*,xmlNodePtr,service*)){ 194 struct dirent *dp; 195 int scount=0; 196 197 if(conf_dir==NULL) 198 return 1; 199 DIR *dirp = opendir(conf_dir); 200 if(dirp==NULL){ 201 dup2(saved_stdout,fileno(stdout)); 202 errorException(m, _("The specified path doesn't exist."),"InvalidParameterValue","metapath"); 203 return -1; 204 } 205 char tmp1[25]; 206 sprintf(tmp1,"sprefix_%d",level); 207 char levels[17]; 208 sprintf(levels,"%d",level); 209 setMapInMaps(m,"lenv","level",levels); 210 while ((dp = readdir(dirp)) != NULL) 211 if((dp->d_type==DT_DIR || dp->d_type==DT_LNK) && dp->d_name[0]!='.' && strstr(dp->d_name,".")==NULL){ 212 213 char *tmp=(char*)malloc((strlen(conf_dir)+strlen(dp->d_name)+2)*sizeof(char)); 214 sprintf(tmp,"%s/%s",conf_dir,dp->d_name); 215 216 if(prefix!=NULL){ 217 free(prefix); 218 prefix=NULL; 219 } 220 prefix=(char*)malloc((strlen(dp->d_name)+2)*sizeof(char)); 221 sprintf(prefix,"%s.",dp->d_name); 222 223 map* tmpMap=getMapFromMaps(m,"lenv",tmp1); 224 225 int res; 226 if(prefix!=NULL){ 227 setMapInMaps(m,"lenv",tmp1,prefix); 228 char *cprefix=zStrdup(prefix); 229 char levels1[17]; 230 sprintf(levels1,"%d",level+1); 231 setMapInMaps(m,"lenv","level",levels1); 232 res=recursReaddirF(m,n,tmp,cprefix,saved_stdout,level+1,func); 233 sprintf(levels1,"%d",level); 234 setMapInMaps(m,"lenv","level",levels1); 235 free(prefix); 236 prefix=NULL; 237 } 238 free(tmp); 239 if(res<0){ 240 return res; 241 } 242 } 243 else{ 244 char* tmp0=strdup(dp->d_name); 245 if(dp->d_name[0]!='.' && strstr(dp->d_name,".zcfg")!=0){ 246 int t; 247 char tmps1[1024]; 248 memset(tmps1,0,1024); 249 snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name); 250 service* s1=(service*)malloc(SERVICE_SIZE); 251 if(s1 == NULL){ 252 dup2(saved_stdout,fileno(stdout)); 253 errorException(m, _("Unable to allocate memory."),"InternalError",NULL); 254 return -1; 255 } 256 #ifdef DEBUG 257 fprintf(stderr,"#################\n%s\n#################\n",tmps1); 258 #endif 259 t=readServiceFile(m,tmps1,&s1,dp->d_name); 260 if(t<0){ 261 dumpMaps(m); 262 map* tmp00=getMapFromMaps(m,"lenv","message"); 263 char tmp01[1024]; 264 if(tmp00!=NULL) 265 sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value); 266 else 267 sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),dp->d_name); 268 dup2(saved_stdout,fileno(stdout)); 269 errorException(m, tmp01,"InternalError",NULL); 270 freeMaps(&m); 271 free(m); 272 return -1; 273 } 274 #ifdef DEBUG 275 dumpService(s1); 276 fflush(stdout); 277 fflush(stderr); 278 #endif 279 func(m,n,s1); 280 freeService(&s1); 281 free(s1); 282 scount++; 283 } 284 } 285 (void)closedir(dirp); 286 return 1; 191 287 } 192 288 … … 277 373 void* so = dlopen(tmps1, RTLD_LAZY); 278 374 #endif 279 #ifdef DEBUG280 375 #ifdef WIN32 281 376 DWORD errstr; … … 285 380 char *errstr; 286 381 errstr = dlerror(); 287 #endif288 382 #endif 289 383 if( so != NULL ) { … … 346 440 #endif 347 441 #endif 348 r_inputs=getMap (request_inputs,"Identifier");442 r_inputs=getMapFromMaps(m,"lenv","Identifier"); 349 443 #ifdef DEBUG 350 444 fprintf(stderr,"Try to load function %s\n",r_inputs->value); … … 356 450 execute_t execute=(execute_t)dlsym(so,r_inputs->value); 357 451 #endif 452 453 if(execute==NULL){ 454 #ifdef WIN32 455 errstr = GetLastError(); 456 #else 457 errstr = dlerror(); 458 #endif 459 char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value)); 460 sprintf(tmpMsg,_("Error occured while running the %s function: %s"),r_inputs->value,errstr); 461 errorException(m, tmpMsg, "InternalError",NULL); 462 free(tmpMsg); 463 fprintf(stderr,"Function %s error %s\n",r_inputs->value,errstr); 464 return; 465 } 358 466 359 467 #ifdef DEBUG … … 758 866 dumpMap(r_inputs); 759 867 #endif 760 DIR *dirp = opendir(conf_dir);761 if(dirp==NULL){762 return errorException(m, _("The specified path doesn't exist."),"InvalidParameterValue","metapath");763 }764 868 xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); 765 869 r_inputs=NULL; … … 776 880 int saved_stdout = dup(fileno(stdout)); 777 881 dup2(fileno(stderr),fileno(stdout)); 778 while ((dp = readdir(dirp)) != NULL) 779 if(strstr(dp->d_name,".zcfg")!=0){ 780 int t; 781 memset(tmps1,0,1024); 782 snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name); 783 s1=(service*)malloc(SERVICE_SIZE); 784 if(s1 == NULL){ 785 return errorException(m, _("Unable to allocate memory."),"InternalError",NULL); 786 } 787 #ifdef DEBUG 788 fprintf(stderr,"#################\n%s\n#################\n",tmps1); 789 #endif 790 t=readServiceFile(m,tmps1,&s1,dp->d_name); 791 if(t<0){ 792 dumpMaps(m); 793 map* tmp00=getMapFromMaps(m,"lenv","message"); 794 char tmp01[1024]; 795 sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value); 796 dup2(saved_stdout,fileno(stdout)); 797 errorException(m, tmp01,"InternalError",NULL); 798 freeMaps(&m); 799 free(m); 800 return 1; 801 } 802 803 #ifdef DEBUG 804 dumpService(s1); 805 fflush(stdout); 806 fflush(stderr); 807 #endif 808 printGetCapabilitiesForProcess(m,n,s1); 809 freeService(&s1); 810 free(s1); 811 scount++; 812 } 813 (void)closedir(dirp); 814 fflush(stdout); 882 if(int res=recursReaddirF(m,n,conf_dir,NULL,saved_stdout,0,printGetCapabilitiesForProcess)<0) 883 return res; 815 884 dup2(saved_stdout,fileno(stdout)); 816 885 printDocument(m,doc,getpid()); … … 860 929 r_inputs=getMap(request_inputs,"Identifier"); 861 930 862 char *saveptr;863 931 char *orig=zStrdup(r_inputs->value); 864 char *tmps=strtok_r(orig,",",&saveptr); 865 866 char buff[256]; 867 char buff1[1024]; 932 868 933 int saved_stdout = dup(fileno(stdout)); 869 934 dup2(fileno(stderr),fileno(stdout)); 870 while(tmps){ 871 memset(buff,0,256); 872 snprintf(buff,256,"%s.zcfg",tmps); 873 memset(buff1,0,1024); 874 #ifdef DEBUG 875 printf("\n#######%s\n########\n",buff); 876 #endif 877 while ((dp = readdir(dirp)) != NULL) 878 if((strcasecmp("all.zcfg",buff)==0 && strstr(dp->d_name,".zcfg")>0) 879 || strcasecmp(dp->d_name,buff)==0){ 880 memset(buff1,0,1024); 881 snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name); 935 if(strcasecmp("all",orig)==0){ 936 if(int res=recursReaddirF(m,n,conf_dir,NULL,saved_stdout,0,printDescribeProcessForProcess)<0) 937 return res; 938 } 939 else{ 940 char *saveptr; 941 char *tmps=strtok_r(orig,",",&saveptr); 942 943 char buff[256]; 944 char buff1[1024]; 945 while(tmps!=NULL){ 946 char *corig=strdup(tmps); 947 if(strstr(corig,".")!=NULL){ 948 parseIdentifier(m,conf_dir,corig,buff1); 882 949 s1=(service*)malloc(SERVICE_SIZE); 883 if(s1 == NULL){ 884 dup2(saved_stdout,fileno(stdout)); 885 return errorException(m, _("Unable to allocate memory."),"InternalError",NULL); 886 } 887 #ifdef DEBUG 888 printf("#################\n(%s) %s\n#################\n",r_inputs->value,buff1); 889 #endif 890 char *tmp0=zStrdup(dp->d_name); 891 tmp0[strlen(tmp0)-5]=0; 892 t=readServiceFile(m,buff1,&s1,tmp0); 893 free(tmp0); 950 t=readServiceFile(m,buff1,&s1,corig); 894 951 if(t<0){ 895 952 map* tmp00=getMapFromMaps(m,"lenv","message"); … … 908 965 dumpService(s1); 909 966 #endif 910 printDescribeProcessForProcess(m,n,s1 ,1);967 printDescribeProcessForProcess(m,n,s1); 911 968 freeService(&s1); 912 969 free(s1); 913 970 s1=NULL; 914 971 scount++; 972 setMapInMaps(m,"lenv","level","0"); 915 973 } 916 rewinddir(dirp); 917 tmps=strtok_r(NULL,",",&saveptr); 974 975 memset(buff,0,256); 976 snprintf(buff,256,"%s.zcfg",tmps); 977 memset(buff1,0,1024); 978 #ifdef DEBUG 979 printf("\n#######%s\n########\n",buff); 980 #endif 981 while ((dp = readdir(dirp)) != NULL) 982 if( (strcasecmp("all.zcfg",buff)==0 && strstr(dp->d_name,".zcfg")>0) 983 || strcasecmp(dp->d_name,buff)==0 ){ 984 memset(buff1,0,1024); 985 snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name); 986 s1=(service*)malloc(SERVICE_SIZE); 987 if(s1 == NULL){ 988 dup2(saved_stdout,fileno(stdout)); 989 return errorException(m, _("Unable to allocate memory."),"InternalError",NULL); 990 } 991 #ifdef DEBUG 992 printf("#################\n(%s) %s\n#################\n",r_inputs->value,buff1); 993 #endif 994 char *tmp0=zStrdup(dp->d_name); 995 tmp0[strlen(tmp0)-5]=0; 996 t=readServiceFile(m,buff1,&s1,tmp0); 997 free(tmp0); 998 if(t<0){ 999 map* tmp00=getMapFromMaps(m,"lenv","message"); 1000 char tmp01[1024]; 1001 if(tmp00!=NULL) 1002 sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value); 1003 else 1004 sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),dp->d_name); 1005 dup2(saved_stdout,fileno(stdout)); 1006 errorException(m, tmp01,"InternalError",NULL); 1007 freeMaps(&m); 1008 free(m); 1009 return 1; 1010 } 1011 #ifdef DEBUG 1012 dumpService(s1); 1013 #endif 1014 printDescribeProcessForProcess(m,n,s1); 1015 freeService(&s1); 1016 free(s1); 1017 s1=NULL; 1018 scount++; 1019 } 1020 rewinddir(dirp); 1021 tmps=strtok_r(NULL,",",&saveptr); 1022 } 918 1023 } 919 1024 closedir(dirp); … … 967 1072 fprintf(stderr,"Trying to load %s\n", tmps1); 968 1073 #endif 1074 if(strstr(r_inputs->value,".")!=NULL){ 1075 char *identifier=zStrdup(r_inputs->value); 1076 parseIdentifier(m,conf_dir,identifier,tmps1); 1077 map* tmpMap=getMapFromMaps(m,"lenv","metapath"); 1078 if(tmpMap!=NULL) 1079 addToMap(request_inputs,"metapath",tmpMap->value); 1080 free(identifier); 1081 }else 1082 setMapInMaps(m,"lenv","Identifier",r_inputs->value); 969 1083 int saved_stdout = dup(fileno(stdout)); 970 1084 dup2(fileno(stderr),fileno(stdout)); … … 974 1088 if(t<0){ 975 1089 char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value)); 976 977 1090 sprintf(tmpMsg,_("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),r_inputs->value); 978 1091 errorException(m, tmpMsg, "InvalidParameterValue","identifier"); -
trunk/zoo-project/zoo-services/cgal/Makefile
r284 r469 1 ZRPATH=../.. /..1 ZRPATH=../.. 2 2 include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts 3 3 CFLAGS=${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG 4 4 CC=gcc 5 5 6 cgi-env/cgal_service.zo: service.c 7 g++ ${CFLAGS} -shared -fpic -o cgi-env/cgal_service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS} -lCGAL 6 cgi-env/cgal_service.zo: delaunay.c voronoi.c cgal_service.o 7 g++ ${CFLAGS} -c ./delaunay.c 8 g++ ${CFLAGS} -c ./voronoi.c 9 g++ ${CFLAGS} -shared -fpic -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${MACOS_LD_FLAGS} -lCGAL -lgmp 10 11 cgal_service.o: cgal_service.c cgal_service.h 12 g++ ${CFLAGS} -c ./cgal_service.c 13 8 14 9 15 clean: 10 rm -f cgi-env/*.zo 16 rm -f cgi-env/*.zo *.o -
trunk/zoo-project/zoo-services/cgal/voronoi.c
r468 r469 36 36 #include "ogrsf_frmts.h" 37 37 #include "service.h" 38 39 typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 40 41 typedef CGAL::Delaunay_triangulation_2<K> Triangulation; 38 #include "cgal_service.h" 39 40 typedef CGAL::Delaunay_triangulation_2<Kernel> Triangulation; 42 41 typedef Triangulation::Edge_iterator Edge_iterator; 43 typedef Triangulation::Point Point;44 45 typedef CGAL::Constrained_Delaunay_triangulation_2<K> CDT;46 typedef CDT::Point Point;47 typedef CDT::Vertex_handle Vertex_handle;48 49 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;50 typedef CGAL::Triangulation_euclidean_traits_xy_3<K> Gt;51 typedef CGAL::Delaunay_triangulation_2<Gt> DelaunayTriangulation;52 53 42 typedef Triangulation::Vertex_circulator Vertex_circulator; 54 43 55 typedef K::Point_3 Point1;56 57 44 extern "C" { 58 #include <libxml/tree.h>59 #include <libxml/parser.h>60 #include <libxml/xpath.h>61 #include <libxml/xpathInternals.h>62 63 #include <openssl/sha.h>64 #include <openssl/hmac.h>65 #include <openssl/evp.h>66 #include <openssl/bio.h>67 #include <openssl/buffer.h>68 69 xmlNodeSet* extractFromDoc(xmlDocPtr,char*);70 void printExceptionReportResponse(maps*,map*);71 45 72 46 int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){ … … 77 51 OGRGeometryH geometry,res; 78 52 int bufferDistance; 79 xmlInitParser();80 53 map* tmpm=NULL; 81 54 tmpm=getMapFromMaps(inputs,"InputPoints","value"); 82 83 xmlInitParser(); 84 xmlDocPtr doc = 85 xmlParseMemory(tmpm->value,strlen(tmpm->value)); 86 xmlNodePtr cur = xmlDocGetRootElement(doc); 87 /** 88 * Parse every Input in DataInputs node. 89 */ 90 maps* tempMaps=NULL; 91 xmlXPathContextPtr xpathCtx; 92 xmlXPathObjectPtr xpathObj; 93 xpathCtx = xmlXPathNewContext(doc); 94 xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx); 95 xmlXPathFreeContext(xpathCtx); 96 xmlNodeSet* nSet=xpathObj->nodesetval; 97 98 if(nSet==NULL){ 99 setMapInMaps(conf,"lenv","message","Unable to continue !!!"); 100 return SERVICE_FAILED; 101 } 102 char filepath[2048]; 103 map* tmpMap=getMapFromMaps(conf,"main","tmpPath"); 104 if(tmpMap!=NULL){ 105 sprintf(filepath,"%s/varonoi_%d.tmp",tmpMap->value,getpid()); 106 } 107 FILE *fo=fopen(filepath,"w"); 108 #ifdef DEBUG 109 fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,nSet->nodeNr); 110 #endif 111 for(int k=0;k<nSet->nodeNr;k++){ 112 xmlNodePtr cur=nSet->nodeTab[k]; 113 char *val= 114 (char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1); 115 char *tmp=strstr(val,","); 116 char tmp1[1024]; 117 strncpy(tmp1,val,strlen(val)-strlen(tmp)); 118 tmp1[strlen(val)-strlen(tmp)]=0; 119 char buff[1024]; 120 sprintf(buff,"%s %s\n",tmp1,tmp+1); 121 fwrite(buff,1,strlen(buff)*sizeof(char),fo); 122 } 123 fclose(fo); 124 #ifdef DEBUG 125 fprintf(stderr,"File Close (%s) OK\n",filepath); 126 #endif 127 128 std::ifstream in(filepath); 129 std::istream_iterator<Point> begin(in); 130 std::istream_iterator<Point> end; 55 56 OGRRegisterAll(); 57 58 std::vector<Point> points; 59 if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED) 60 return res; 61 131 62 Triangulation T; 132 T.insert( begin, end);63 T.insert(points.begin(), points.end()); 133 64 134 65 OGRRegisterAll(); … … 142 73 int iDriver; 143 74 144 tmpMap=getMapFromMaps(outputs,"Result","mimeType");75 map* tmpMap=getMapFromMaps(outputs,"Result","mimeType"); 145 76 const char *oDriver; 146 77 oDriver="GeoJSON"; … … 192 123 /* -------------------------------------------------------------------- */ 193 124 map* tpath=getMapFromMaps(conf,"main","tmpPath"); 194 char *pszDestDataSource=(char*)malloc( strlen(tpath->value)+20);125 char *pszDestDataSource=(char*)malloc(100); 195 126 char **papszDSCO=NULL; 196 sprintf(pszDestDataSource," %s/result_%d.json",tpath->value,getpid());127 sprintf(pszDestDataSource,"/vsimem/result_%d.json",tpath->value,getpid()); 197 128 poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO ); 198 129 if( poODS == NULL ){ … … 231 162 for ( ; eit !=T.edges_end(); ++eit) { 232 163 CGAL::Object o = T.dual(eit); 233 if (const K ::Segment_2 *tmp=CGAL::object_cast<K::Segment_2>(&o)) {234 const K::Point_2p1=tmp->source();235 const K::Point_2p2=tmp->target();164 if (const Kernel::Segment_2 *tmp=CGAL::object_cast<Kernel::Segment_2>(&o)) { 165 const Point p1=tmp->source(); 166 const Point p2=tmp->target(); 236 167 #ifdef DEBUG 237 168 fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y()); … … 250 181 ++ns ; 251 182 } 252 else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;} 183 else if (const Kernel::Ray_2 *tmp=CGAL::object_cast<Kernel::Ray_2>(&o)) { 184 const Point p1=tmp->source(); 185 const Point p2=tmp->point(2); 186 OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) ); 187 OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString); 188 OGR_G_AddPoint_2D(currLine,p1.x(),p1.y()); 189 OGR_G_AddPoint_2D(currLine,p2.x(),p2.y()); 190 OGR_F_SetGeometry( hFeature, currLine ); 191 OGR_G_DestroyGeometry(currLine); 192 if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){ 193 setMapInMaps(conf,"lenv","message","Failed to create feature in file.\n"); 194 return SERVICE_FAILED; 195 } 196 OGR_F_Destroy( hFeature ); 197 ++nr; 198 } 253 199 } 254 200 OGR_DS_Destroy( poODS ); 255 OGRCleanupAll();256 201 257 202 #ifdef DEBUG … … 261 206 #endif 262 207 263 char tmp1[1024]; 264 265 FILE * fichier=fopen(pszDestDataSource,"r"); 266 struct stat file_status; 267 stat(pszDestDataSource, &file_status); 268 char *res1=(char *)malloc(file_status.st_size*sizeof(char)); 269 if(fichier==NULL){ 270 char tmp[1024]; 271 sprintf(tmp,"Failed to open file %s for reading purpose.\n", 272 pszDestDataSource); 273 setMapInMaps(conf,"lenv","message",tmp); 274 return SERVICE_FAILED; 275 } 276 fread(res1,1,(file_status.st_size)*sizeof(char),fichier); 277 res1[strlen(res1)]=0; 278 fclose(fichier); 279 unlink(pszDestDataSource); 208 209 char *res1=readVSIFile(conf,pszDestDataSource); 210 if(res1==NULL) 211 return SERVICE_FAILED; 280 212 281 213 setMapInMaps(outputs,"Result","value",res1); … … 290 222 fprintf(stderr,"\nService internal print\n===\n"); 291 223 #endif 292 xmlCleanupParser();224 OGRCleanupAll(); 293 225 return SERVICE_SUCCEEDED; 294 226 }
Note: See TracChangeset
for help on using the changeset viewer.