Changeset 469 for trunk/zoo-project/zoo-kernel/zoo_service_loader.c
- Timestamp:
- May 1, 2014, 1:28:14 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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");
Note: See TracChangeset
for help on using the changeset viewer.