Changeset 652
- Timestamp:
- Jun 11, 2015, 3:07:11 PM (10 years ago)
- Location:
- trunk/zoo-project
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/HISTORY.txt
r634 r652 1 1 Version 1.5.0-dev 2 * Fix concurrency access to status informations 3 * Use simple file rather than shared memory for storing status informations 4 * Add support for db backend to store status informations 5 * Add the lib_zoo_service shared library to be linked against C services 2 6 * Add ZOO-API for the PHP language (with documentation) 3 7 * Add doxygen comments in source code -
trunk/zoo-project/zoo-kernel/Makefile.in
r649 r652 93 93 g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c -fno-common -DPIC -o zoo_service_loader.o 94 94 95 libzoo_service.${EXT}: version.h service_internal.o service.o 96 gcc -shared ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS} service_internal.o service.o -lfcgi ${GDAL_LIBS}95 libzoo_service.${EXT}: version.h service_internal.o service.o sqlapi.o 96 gcc -shared ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS} service_internal.o service.o sqlapi.o -lfcgi ${GDAL_LIBS} 97 97 98 zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o sqlapi.oresponse_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}98 zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} 99 99 g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${RUBYCFLAGS} ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c -fno-common -DPIC -o zoo_loader.o 100 g++ ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE} ${PERL_FILE} ${PHP_FILE} ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} sqlapi.o response_print.o server_internal.o caching.o request_parser.oulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}100 g++ ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE} ${PERL_FILE} ${PHP_FILE} ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS} 101 101 102 102 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} -
trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in
r651 r652 90 90 SAGA_FILE=@SAGA_FILE@ 91 91 92 CFLAGS=@ DEB_DEF@ -fpic ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF92 CFLAGS=@RELY_ON_DB@ @DEB_DEF@ -fpic ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF 93 93 LDFLAGS=-lzoo_service -lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto -luuid ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} 94 94 -
trunk/zoo-project/zoo-kernel/configure.ac
r640 r652 47 47 48 48 AC_ARG_WITH([cgi-dir], 49 [AS_HELP_STRING([--with-cgi-dir=PATH], [ specifyan alternative cgi directory path ( default: /usr/lib/cgi-bin) ])],49 [AS_HELP_STRING([--with-cgi-dir=PATH], [Specifies an alternative cgi directory path ( default: /usr/lib/cgi-bin) ])], 50 50 [CGI_DIR="$withval"], [CGI_DIR="/usr/lib/cgi-bin"]) 51 51 AC_SUBST([CGI_DIR]) 52 52 53 AC_ARG_WITH([db-backend], 54 [AS_HELP_STRING([--with-db-backend], [Relies on a database for storing status messages and response files ])], 55 [RELY_ON_DB="-DRELY_ON_DB"], [RELY_ON_DB=""]) 56 AC_SUBST([RELY_ON_DB]) 57 53 58 54 59 # =========================================================================== … … 57 62 58 63 AC_ARG_WITH([yaml], 59 [AS_HELP_STRING([--with-yaml=PATH], [ specifyan alternative location for the yaml library])],64 [AS_HELP_STRING([--with-yaml=PATH], [Specifies an alternative location for the yaml library])], 60 65 [YAMLPATH="$withval"], [YAMLPATH=""]) 61 66 … … 94 99 95 100 AC_ARG_WITH([fastcgi], 96 [AS_HELP_STRING([--with-fastcgi=PATH], [ specifyan alternative location for the fastcgi library])],101 [AS_HELP_STRING([--with-fastcgi=PATH], [Specifies an alternative location for the fastcgi library])], 97 102 [FCGIPATH="$withval"], [FCGIPATH="/usr"]) 98 103 … … 118 123 119 124 AC_ARG_WITH([xml2config], 120 [AS_HELP_STRING([--with-xml2config=FILE], [ specifyan alternative xml2-config file])],125 [AS_HELP_STRING([--with-xml2config=FILE], [Specifies an alternative xml2-config file])], 121 126 [XML2CONFIG="$withval"], [XML2CONFIG=""]) 122 127 … … 132 137 # XML2CONFIG was specified; display a message to the user 133 138 if test "x$XML2CONFIG" = "xyes"; then 134 AC_MSG_ERROR([you must specifya parameter to --with-xml2config, e.g. --with-xml2config=/path/to/xml2-config])139 AC_MSG_ERROR([you must Specifies a parameter to --with-xml2config, e.g. --with-xml2config=/path/to/xml2-config]) 135 140 else 136 141 if test -f $XML2CONFIG; then … … 167 172 168 173 AC_ARG_WITH([xsltconfig], 169 [AS_HELP_STRING([--with-xsltconfig=FILE], [ specifyan alternative xslt-config file])],174 [AS_HELP_STRING([--with-xsltconfig=FILE], [Specifies an alternative xslt-config file])], 170 175 [XSLTCONFIG="$withval"], [XSLTCONFIG=""]) 171 176 … … 181 186 # XSLTCONFIG was specified; display a message to the user 182 187 if test "x$XSLTCONFIG" = "xyes"; then 183 AC_MSG_ERROR([you must specifya parameter to --with-xsltconfig, e.g. --with-xsltconfig=/path/to/xslt-config])188 AC_MSG_ERROR([you must Specifies a parameter to --with-xsltconfig, e.g. --with-xsltconfig=/path/to/xslt-config]) 184 189 else 185 190 if test -f $XSLTCONFIG; then … … 209 214 210 215 AC_ARG_WITH([gdal-config], 211 [AS_HELP_STRING([--with-gdal-config=FILE], [ specifyan alternative gdal-config file])],216 [AS_HELP_STRING([--with-gdal-config=FILE], [Specifies an alternative gdal-config file])], 212 217 [GDAL_CONFIG="$withval"], [GDAL_CONFIG=""]) 213 218 if test -z $GDAL_CONFIG; … … 238 243 239 244 AC_ARG_WITH([proj], 240 [AS_HELP_STRING([--with-proj=PATH], [ specifyan alternative location for PROJ4 setup])],245 [AS_HELP_STRING([--with-proj=PATH], [Specifies an alternative location for PROJ4 setup])], 241 246 [PROJPATH="$withval"], [PROJPATH=""]) 242 247 … … 259 264 260 265 AC_ARG_WITH([geosconfig], 261 [AS_HELP_STRING([--with-geosconfig=FILE], [ specifyan alternative geos-config file])],266 [AS_HELP_STRING([--with-geosconfig=FILE], [Specifies an alternative geos-config file])], 262 267 [GEOSCONFIG="$withval"], [GEOSCONFIG=""]) 263 268 … … 273 278 # GEOSCONFIG was specified; display a message to the user 274 279 if test "x$GEOSCONFIG" = "xyes"; then 275 AC_MSG_WARN([you must specifya parameter to --with-geosconfig, e.g. --with-geosconfig=/path/to/geos-config])280 AC_MSG_WARN([you must Specifies a parameter to --with-geosconfig, e.g. --with-geosconfig=/path/to/geos-config]) 276 281 else 277 282 if test -f $GEOSCONFIG; then … … 301 306 302 307 AC_ARG_WITH([cgal], 303 [AS_HELP_STRING([--with-cgal=PATH], [ specifyan alternative location for CGAL setup])],308 [AS_HELP_STRING([--with-cgal=PATH], [Specifies an alternative location for CGAL setup])], 304 309 [CGALPATH="$withval"], [CGALPATH="/usr"]) 305 310 … … 323 328 324 329 AC_ARG_WITH([mapserver], 325 [AS_HELP_STRING([--with-mapserver=PATH], [ specifythe path for MapServer compiled source tree])],330 [AS_HELP_STRING([--with-mapserver=PATH], [Specifies the path for MapServer compiled source tree])], 326 331 [MS_SRC_PATH="$withval"], [MS_SRC_PATH=""]) 327 332 … … 362 367 363 368 AC_ARG_WITH([python], 364 [AS_HELP_STRING([--with-python=PATH], [To enable python support or specifyan alternative directory for python installation, disabled by default])],369 [AS_HELP_STRING([--with-python=PATH], [To enable python support or Specifies an alternative directory for python installation, disabled by default])], 365 370 [PYTHON_PATH="$withval"; PYTHON_ENABLED="-DUSE_PYTHON"], [PYTHON_ENABLED=""]) 366 371 … … 417 422 418 423 AC_ARG_WITH([js], 419 [AS_HELP_STRING([--with-js=PATH], [ specify--with-js=path-to-js to enable js support, specify --with-js on linux debian like, js support is disabled by default ])],424 [AS_HELP_STRING([--with-js=PATH], [Specifies --with-js=path-to-js to enable js support, specify --with-js on linux debian like, js support is disabled by default ])], 420 425 [JSHOME="$withval";JS_ENABLED="-DUSE_JS"], [JS_ENABLED=""]) 421 426 … … 666 671 667 672 AC_ARG_WITH([itk], 668 [AS_HELP_STRING([--with-itk=PATH], [ specifyan alternative location for the itk library])],673 [AS_HELP_STRING([--with-itk=PATH], [Specifies an alternative location for the itk library])], 669 674 [ITKPATH="$withval"], [ITKPATH=""]) 670 675 671 676 AC_ARG_WITH([itk-version], 672 [AS_HELP_STRING([--with-itk-version=VERSION], [ specifyan alternative version for the itk library])],677 [AS_HELP_STRING([--with-itk-version=VERSION], [Specifies an alternative version for the itk library])], 673 678 [ITKVERS="$withval"], [ITKVERS=""]) 674 679 675 680 AC_ARG_WITH([otb], 676 [AS_HELP_STRING([--with-otb=PATH], [ specifyan alternative location for the otb library])],681 [AS_HELP_STRING([--with-otb=PATH], [Specifies an alternative location for the otb library])], 677 682 [OTBPATH="$withval"], [OTBPATH=""]) 678 683 … … 720 725 721 726 AC_ARG_WITH([wx-config], 722 [AS_HELP_STRING([--with-wx-config=PATH], [ specifyan alternative path for the wx-config tool])],727 [AS_HELP_STRING([--with-wx-config=PATH], [Specifies an alternative path for the wx-config tool])], 723 728 [WXCFG="$withval"], [WXCFG=""]) 724 729 725 730 AC_ARG_WITH([saga], 726 [AS_HELP_STRING([--with-saga=PATH], [ specifyan alternative location for the SAGA-GIS library])],731 [AS_HELP_STRING([--with-saga=PATH], [Specifies an alternative location for the SAGA-GIS library])], 727 732 [SAGAPATH="$withval"], [SAGAPATH=""]) 728 733 -
trunk/zoo-project/zoo-kernel/response_print.c
r651 r652 1515 1515 int lpid; 1516 1516 map* tmpm2=getMapFromMaps(m,"lenv","usid"); 1517 lpid=atoi(tmpm2->value); 1518 tmpm2=getMap(tmp_maps->content,"tmpUrl"); 1519 if(tmpm1!=NULL && tmpm2!=NULL){ 1520 if( strncasecmp( tmpm2->value, "http://", 7) == 0 || 1521 strncasecmp( tmpm2->value, "https://", 8 ) == 0 ){ 1522 sprintf(url,"%s/%s_%i.xml",tmpm2->value,service,lpid); 1517 map* tmpm3=getMap(tmp_maps->content,"tmpUrl"); 1518 if(tmpm1!=NULL && tmpm3!=NULL){ 1519 if( strncasecmp( tmpm3->value, "http://", 7) == 0 || 1520 strncasecmp( tmpm3->value, "https://", 8 ) == 0 ){ 1521 sprintf(url,"%s/%s_%s.xml",tmpm3->value,service,tmpm2->value); 1523 1522 }else 1524 sprintf(url,"%s/%s /%s_%i.xml",tmpm1->value,tmpm2->value,service,lpid);1523 sprintf(url,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value); 1525 1524 } 1526 1525 } … … 1529 1528 } 1530 1529 int lpid; 1531 tmpm1=getMapFromMaps(m,"lenv","usid"); 1532 lpid=atoi(tmpm1->value); 1530 map* tmpm2=getMapFromMaps(m,"lenv","usid"); 1533 1531 tmpm1=getMapFromMaps(m,"main","TmpPath"); 1534 sprintf(stored_path,"%s/%s_% i.xml",tmpm1->value,service,lpid);1532 sprintf(stored_path,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value); 1535 1533 } 1536 1534 … … 1683 1681 } 1684 1682 1685 if(hasStoredExecuteResponse==true && status!=SERVICE_STARTED){ 1686 semid lid=getShmLockId(m,1); 1683 if(hasStoredExecuteResponse==true && status!=SERVICE_STARTED && status!=SERVICE_ACCEPTED){ 1684 #ifndef RELY_ON_DB 1685 semid lid=acquireLock(m);//,1); 1687 1686 if(lid<0){ 1688 1687 /* If the lock failed */ … … 1694 1693 } 1695 1694 else{ 1696 #ifdef DEBUG1697 fprintf(stderr,"LOCK %s %d !\n",__FILE__,__LINE__);1698 1695 #endif 1699 lockShm(lid);1700 1696 /* We need to write the ExecuteResponse Document somewhere */ 1701 1697 FILE* output=fopen(stored_path,"w"); … … 1709 1705 xmlCleanupParser(); 1710 1706 zooXmlCleanupNs(); 1707 #ifndef RELY_ON_DB 1711 1708 unlockShm(lid); 1709 #endif 1712 1710 return; 1713 1711 } … … 1718 1716 xmlFree(xmlbuff); 1719 1717 fclose(output); 1718 #ifndef RELY_ON_DB 1720 1719 #ifdef DEBUG 1721 1720 fprintf(stderr,"UNLOCK %s %d !\n",__FILE__,__LINE__); 1722 1721 #endif 1723 1722 unlockShm(lid); 1724 map* test1=getMap(request,"status"); 1725 if(test1==NULL || strcasecmp(test1->value,"true")!=0){ 1726 removeShmLock(m,1); 1727 } 1728 } 1723 map* v=getMapFromMaps(m,"lenv","sid"); 1724 // Remove the lock when running as a normal task 1725 if(getpid()==atoi(v->value)){ 1726 removeShmLock (m, 1); 1727 } 1728 } 1729 #endif 1729 1730 } 1730 1731 printDocument(m,doc,pid); … … 2316 2317 #endif 2317 2318 maps* tmpI=request_outputs; 2318 2319 map* usid=getMapFromMaps(m,"lenv","usid"); 2320 int itn=0; 2319 2321 while(tmpI!=NULL){ 2320 2322 #ifdef USE_MS … … 2354 2356 } 2355 2357 2356 if(gfile==NULL) {2358 if(gfile==NULL) { 2357 2359 map *ext=getMap(tmpI->content,"extension"); 2358 2360 char *file_path; … … 2369 2371 } 2370 2372 2371 file_name=(char*)malloc((strlen(s->name)+strlen( file_ext)+strlen(tmpI->name)+1024)*sizeof(char));2372 int cpid0=cpid+time(NULL);2373 sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,file_ext);2373 file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char)); 2374 sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext); 2375 itn++; 2374 2376 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2375 2377 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2376 2378 2377 2379 FILE *ofile=fopen(file_path,"wb"); 2378 2380 if(ofile==NULL){ 2379 2381 char tmpMsg[1024]; -
trunk/zoo-project/zoo-kernel/server_internal.c
r649 r652 29 29 #include <dlfcn.h> 30 30 #endif 31 #include <uuid/uuid.h> 31 32 32 33 int getVersionId(const char* version){ … … 37 38 } 38 39 return 0; 40 } 41 42 /** 43 * Generate a UUID. 44 * ref: https://www.ietf.org/rfc/rfc4122.txt / 4.2 45 * 46 * @return a new char* containing the UUID, make sure to free the returned 47 * ressource once used. 48 */ 49 char *get_uuid(){ 50 char *res=(char*)malloc(37*sizeof(char)); 51 uuid_t uuid; 52 uuid_generate_time(uuid); 53 char * rest; 54 uuid_unparse(uuid,rest); 55 sprintf(res,"%s", rest); 56 return res; 39 57 } 40 58 … … 325 343 void dumpMapsValuesToFiles(maps** main_conf,maps** in){ 326 344 map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath"); 327 map* tmpSid=getMapFromMaps(*main_conf,"lenv"," sid");345 map* tmpSid=getMapFromMaps(*main_conf,"lenv","usid"); 328 346 maps* inputs=*in; 329 347 int length=0; -
trunk/zoo-project/zoo-kernel/server_internal.h
r649 r652 39 39 #include <libxml/parser.h> 40 40 #include <libxml/xpath.h> 41 41 42 char *get_uuid(); 42 43 char *base64(const char*,int); 43 44 char *base64d(const char*,int,int*); -
trunk/zoo-project/zoo-kernel/service.c
r645 r652 93 93 FILE* file=fopen(file_path,"w"); 94 94 maps* tmp=m; 95 if(tmp!=NULL){95 while(tmp!=NULL){ 96 96 fprintf(file,"[%s]\n",tmp->name); 97 dumpMapToFile(tmp->content,file); 98 fflush(file); 99 } 100 fclose(file); 101 } 97 dumpMapToFile(tmp->content,file); 98 fflush(file); 99 tmp=tmp->next; 100 } 101 fclose(file); 102 } 102 103 103 104 /** -
trunk/zoo-project/zoo-kernel/service_internal.c
r651 r652 39 39 40 40 #define ERROR_MSG_MAX_LENGTH 1024 41 42 /** 43 * Get the ongoing status of a running service 41 #ifndef RELY_ON_DB 42 #include <dirent.h> 43 44 /** 45 * Read the sid file attached of a service if any 44 46 * 45 47 * @param conf the maps containing the setting of the main.cfg file 46 48 * @param pid the service identifier (usid key from the [lenv] section) 47 * @return the reported status char* (MESSAGE|POURCENTAGE) 48 */ 49 char* _getStatus(maps* conf,int pid){ 50 char lid[1024]; 51 sprintf(lid,"%d",pid); 52 setMapInMaps(conf,"lenv","lid",lid); 53 semid lockid=getShmLockId(conf,1); 49 * @return the reported status char* (temporary/final result) 50 */ 51 char* getStatusId(maps* conf,char* pid){ 52 map* r_inputs = getMapFromMaps (conf, "main", "tmpPath"); 53 char* fbkpid = 54 (char *) 55 malloc ((strlen (r_inputs->value) + strlen (pid) + 7) * sizeof (char)); 56 sprintf (fbkpid, "%s/%s.sid", r_inputs->value, pid); 57 FILE* f0 = fopen (fbkpid, "r"); 58 if(f0!=NULL){ 59 fseek (f0, 0, SEEK_END); 60 long flen = ftell (f0); 61 fseek (f0, 0, SEEK_SET); 62 char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char)); 63 fread(tmps1,flen,1,f0); 64 tmps1[flen]=0; 65 fclose(f0); 66 return tmps1; 67 }else 68 return NULL; 69 } 70 71 /** 72 * Acquire the global lock 73 * 74 * @param conf the maps containing the setting of the main.cfg file 75 * @return a semid 76 */ 77 semid acquireLock(maps* conf){ 78 semid lockid; 79 int itn=0; 80 toRetry1: 81 lockid=getShmLockId(conf,1); 54 82 if( 55 83 #ifdef WIN32 … … 59 87 #endif 60 88 ){ 61 char* tmp = (char*) malloc(3*sizeof(char)); 62 sprintf(tmp,"%d",ZOO_LOCK_CREATE_FAILED); 63 return tmp; 89 #ifdef WIN32 90 return NULL 91 #else 92 return -1; 93 #endif 64 94 } 65 95 if(lockShm(lockid)<0){ 66 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 67 fflush(stderr); 68 char* tmp = (char*) malloc(3*sizeof(char)); 69 sprintf(tmp,"%d",ZOO_LOCK_ACQUIRE_FAILED); 70 return tmp; 71 } 72 char *tmp=getStatus(pid); 73 unlockShm(lockid); 74 if(tmp==NULL || strncmp(tmp,"-1",2)==0){ 96 if(itn<ZOO_LOCK_MAX_RETRY){ 97 itn++; 98 goto toRetry1; 99 }else 100 #ifdef WIN32 101 return NULL 102 #else 103 return -1; 104 #endif 105 }else 106 return lockid; 107 } 108 109 /** 110 * Read the cache file of a running service 111 * 112 * @param conf the maps containing the setting of the main.cfg file 113 * @param pid the service identifier (usid key from the [lenv] section) 114 * @return the reported status char* (temporary/final result) 115 */ 116 char* _getStatusFile(maps* conf,char* pid){ 117 map* tmpTmap = getMapFromMaps (conf, "main", "tmpPath"); 118 119 struct dirent *dp; 120 DIR *dirp = opendir(tmpTmap->value); 121 char fileName[1024]; 122 int hasFile=-1; 123 if(dirp!=NULL){ 124 char tmp[128]; 125 sprintf(tmp,"_%s.xml",pid); 126 while ((dp = readdir(dirp)) != NULL){ 127 #ifdef DEBUG 128 fprintf(stderr,"File : %s searched : %s\n",dp->d_name,tmp); 129 #endif 130 if(strstr(dp->d_name,"final_")==0 && strstr(dp->d_name,tmp)!=0){ 131 sprintf(fileName,"%s/%s",tmpTmap->value,dp->d_name); 132 hasFile=1; 133 break; 134 } 135 } 136 } 137 if(hasFile>0){ 138 semid lockid; 139 char* stat=getStatusId(conf,pid); 140 if(stat!=NULL){ 141 setMapInMaps(conf,"lenv","lid",stat); 142 lockid=acquireLock(conf); 143 if(lockid<0) 144 return NULL; 145 } 146 147 FILE* f0 = fopen (fileName, "r"); 148 if(f0!=NULL){ 149 fseek (f0, 0, SEEK_END); 150 long flen = ftell (f0); 151 fseek (f0, 0, SEEK_SET); 152 char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char)); 153 fread(tmps1,flen,1,f0); 154 tmps1[flen]=0; 155 fclose(f0); 156 if(stat!=NULL){ 157 unlockShm(lockid); 158 free(stat); 159 } 160 161 return tmps1; 162 } 163 else{ 164 if(stat!=NULL){ 165 unlockShm(lockid); 166 free(stat); 167 } 168 return NULL; 169 } 170 } 171 else 172 return NULL; 173 } 174 175 /** 176 * Get the ongoing status of a running service 177 * 178 * @param conf the maps containing the setting of the main.cfg file 179 * @param pid the service identifier (usid key from the [lenv] section) 180 * @return the reported status char* (MESSAGE|POURCENTAGE) 181 */ 182 char* _getStatus(maps* conf,char* lid){ 183 map* r_inputs = getMapFromMaps (conf, "main", "tmpPath"); 184 char* fbkpid = 185 (char *) 186 malloc ((strlen (r_inputs->value) + strlen (lid) + 9) * sizeof (char)); 187 sprintf (fbkpid, "%s/%s.status", r_inputs->value, lid); 188 FILE* f0 = fopen (fbkpid, "r"); 189 if(f0!=NULL){ 190 char* stat=getStatusId(conf,lid); 191 if(stat!=NULL){ 192 setMapInMaps(conf,"lenv","lid",stat); 193 semid lockid=acquireLock(conf); 194 if(lockid<0) 195 return NULL; 196 } 197 fseek (f0, 0, SEEK_END); 198 long flen = ftell (f0); 199 if(flen>0){ 200 fseek (f0, 0, SEEK_SET); 201 char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char)); 202 fread(tmps1,flen,1,f0); 203 tmps1[flen]=0; 204 fclose(f0); 205 free(fbkpid); 206 if(stat!=NULL){ 207 removeShmLock(conf,1); 208 free(stat); 209 } 210 return tmps1; 211 } 212 fclose(f0); 213 free(fbkpid); 214 if(stat!=NULL){ 215 removeShmLock(conf,1); 216 free(stat); 217 } 218 return NULL; 219 }else{ 220 free(fbkpid); 221 char* stat=getStatusId(conf,lid); 222 setMapInMaps(conf,"lenv","lid",stat); 75 223 removeShmLock(conf,1); 76 } 77 return tmp; 78 } 224 return NULL; 225 } 226 } 227 228 /** 229 * Stop handling status repport. 230 * 231 * @param conf the map containing the setting of the main.cfg file 232 */ 233 void unhandleStatus(maps *conf){ 234 map* r_inputs = getMapFromMaps (conf, "main", "tmpPath"); 235 map* usid = getMapFromMaps (conf, "lenv", "usid"); 236 char* fbkpid = 237 (char *) malloc ((strlen (r_inputs->value) + strlen (usid->value) + 9) 238 * sizeof (char)); 239 sprintf (fbkpid, "%s/%s.status", r_inputs->value, usid->value); 240 unlink(fbkpid); 241 free(fbkpid); 242 } 243 244 /** 245 * Update the current status of the running service. 246 * 247 * @see acquireLock, lockShm 248 * @param conf the map containing the setting of the main.cfg file 249 * @return 0 on success, -2 if shmget failed, -1 if shmat failed 250 */ 251 int _updateStatus(maps *conf){ 252 map* r_inputs = getMapFromMaps (conf, "main", "tmpPath"); 253 map* sid = getMapFromMaps (conf, "lenv", "usid"); 254 char* fbkpid = 255 (char *) 256 malloc ((strlen (r_inputs->value) + strlen (sid->value) + 9) * sizeof (char)); 257 sprintf (fbkpid, "%s/%s.status", r_inputs->value, sid->value); 258 map* status=getMapFromMaps(conf,"lenv","status"); 259 map* msg=getMapFromMaps(conf,"lenv","message"); 260 if(status!=NULL && msg!=NULL && 261 status->value!=NULL && msg->value!=NULL && 262 strlen(status->value)>0 && strlen(msg->value)>1){ 263 semid lockid; 264 char* stat=getStatusId(conf,sid->value); 265 if(stat!=NULL){ 266 lockid=acquireLock(conf); 267 if(lockid<0) 268 return ZOO_LOCK_ACQUIRE_FAILED; 269 } 270 FILE* fstatus=fopen(fbkpid,"w"); 271 if(fstatus!=NULL){ 272 fprintf(fstatus,"%s|%s\n",status->value,msg->value); 273 fflush(fstatus); 274 fclose(fstatus); 275 } 276 if(stat!=NULL){ 277 unlockShm(lockid); 278 free(stat); 279 } 280 } 281 return 0; 282 } 283 284 #endif 79 285 80 286 #ifdef WIN32 … … 96 302 map *tmpMap=getMapFromMaps(conf,"lenv","lid"); 97 303 if(tmpMap==NULL) 98 tmpMap=getMapFromMaps(conf,"lenv"," usid");304 tmpMap=getMapFromMaps(conf,"lenv","osid"); 99 305 100 306 if(tmpMap!=NULL){ … … 130 336 semid sem_id=getShmLockId(conf,1); 131 337 if (CloseHandle(sem_id) == 0) { 338 #ifdef DEBUG 132 339 fprintf(stderr,"Unable to remove semaphore: %s\n", getLastErrorMessage()); 340 #endif 133 341 return -1; 134 342 } … … 165 373 static HANDLE hMapObjectG = NULL; // handle to file mapping 166 374 167 int _updateStatus(maps *conf){168 LPWSTR lpszTmp;169 BOOL fInit;170 char *final_string=NULL;171 char *s=NULL;172 map *tmpMap1;173 map *tmpMap=getMapFromMaps(conf,"lenv","usid");174 semid lockid=getShmLockId(conf,1);175 if(lockid==NULL){176 #ifdef DEBUG177 fprintf(stderr,"Unable to create semaphore on line %d!! \n",__LINE__);178 #endif179 return ZOO_LOCK_CREATE_FAILED;180 }181 if(lockShm(lockid)<0){182 #ifdef DEBUG183 fprintf(stderr,"Unable to create semaphore on line %d!! \n",__LINE__);184 #endif185 return ZOO_LOCK_ACQUIRE_FAILED;186 }187 188 if(hMapObjectG==NULL)189 hMapObjectG = CreateFileMapping(190 INVALID_HANDLE_VALUE, // use paging file191 NULL, // default security attributes192 PAGE_READWRITE, // read/write access193 0, // size: high 32-bits194 SHMEMSIZE, // size: low 32-bits195 TEXT(tmpMap->value)); // name of map object196 if (hMapObjectG == NULL){197 #ifdef DEBUG198 fprintf(stderr,"Unable to create shared memory segment: %s\n", getLastErrorMessage());199 #endif200 return -2;201 }202 fInit = (GetLastError() != ERROR_ALREADY_EXISTS);203 if(lpvMemG==NULL)204 lpvMemG = MapViewOfFile(205 hMapObjectG, // object to map view of206 FILE_MAP_WRITE, // read/write access207 0, // high offset: map from208 0, // low offset: beginning209 0); // default: map entire file210 if (lpvMemG == NULL){211 #ifdef DEBUG212 fprintf(stderr,"Unable to create or access the shared memory segment %s !! \n",tmpMap->value);213 #endif214 return -1;215 }216 memset(lpvMemG, '\0', SHMEMSIZE);217 tmpMap=getMapFromMaps(conf,"lenv","status");218 tmpMap1=NULL;219 tmpMap1=getMapFromMaps(conf,"lenv","message");220 lpszTmp = (LPWSTR) lpvMemG;221 final_string=(char*)malloc((strlen(tmpMap1->value)+strlen(tmpMap->value)+2)*sizeof(char));222 sprintf(final_string,"%s|%s",tmpMap->value,tmpMap1->value);223 for(s=final_string;*s!='\0';*s++){224 *lpszTmp++ = *s;225 }226 *lpszTmp++ = '\0';227 free(final_string);228 unlockShm(lockid);229 return 0;230 }231 375 232 376 char* getStatus(int pid){ … … 287 431 } 288 432 289 void unhandleStatus(maps *conf){290 BOOL fIgnore;291 fIgnore = UnmapViewOfFile(lpvMemG);292 fIgnore = CloseHandle(hMapObjectG);293 }294 295 433 #else 296 434 /** … … 312 450 313 451 /** 314 * Set in the pre-allocated key the zoo_sem_[ SID] string315 * where [ SID] is the lid (if any) or usid value from the [lenv] section.452 * Set in the pre-allocated key the zoo_sem_[OSID] string 453 * where [OSID] is the lid (if any) or osid value from the [lenv] section. 316 454 * 317 455 * @param conf the map containing the setting of the main.cfg file … … 322 460 map *tmpMap=getMapFromMaps(conf,"lenv","lid"); 323 461 if(tmpMap==NULL) 324 tmpMap=getMapFromMaps(conf,"lenv"," usid");462 tmpMap=getMapFromMaps(conf,"lenv","osid"); 325 463 int key=-1; 326 464 if(tmpMap!=NULL) … … 380 518 fprintf(stderr,"Retry to access the semaphore later ...\n"); 381 519 #endif 382 sleep(1);520 zSleep(1); 383 521 } 384 522 } … … 411 549 int sem_id=getShmLockId(conf,nsems); 412 550 if (semctl(sem_id, 0, IPC_RMID, arg) == -1) { 413 perror("semctl"); 551 #ifdef DEBUG 552 perror("semctl remove"); 553 #endif 414 554 return -1; 415 555 } 556 #ifdef DEBUG 557 fprintf(stderr,"Semaphore removed!\n"); 558 #endif 416 559 return 0; 417 560 } … … 429 572 sb.sem_flg = SEM_UNDO; 430 573 if (semop(id, &sb, 1) == -1){ 431 perror("semop"); 574 #ifdef DEBUG 575 perror("semop lock"); 576 #endif 432 577 return -1; 433 578 } … … 447 592 sb.sem_flg = SEM_UNDO; 448 593 if (semop(id, &sb, 1) == -1) { 449 perror("semop"); 594 #ifdef DEBUG 595 perror("semop unlock"); 596 #endif 450 597 return -1; 451 598 } … … 454 601 455 602 /** 456 * Stop handling status repport. 457 * 458 * @param conf the map containing the setting of the main.cfg file 459 */ 460 void unhandleStatus(maps *conf){ 461 int shmid; 462 key_t key; 463 void *shm; 464 struct shmid_ds shmids; 465 map *tmpMap=getMapFromMaps(conf,"lenv","usid"); 466 if(tmpMap!=NULL){ 467 key=atoi(tmpMap->value); 468 if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { 469 #ifdef DEBUG 470 fprintf(stderr,"shmget failed to update value\n"); 471 #endif 472 }else{ 473 if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { 474 #ifdef DEBUG 475 fprintf(stderr,"shmat failed to update value\n"); 476 #endif 477 }else{ 478 shmdt(shm); 479 shmctl(shmid,IPC_RMID,&shmids); 480 } 481 } 482 } 483 } 484 485 /** 486 * Update the current of the running service. 487 * 488 * @see getKeyValue, getShmLockId, lockShm 489 * @param conf the map containing the setting of the main.cfg file 490 * @return 0 on success, -2 if shmget failed, -1 if shmat failed 491 */ 492 int _updateStatus(maps *conf){ 493 int shmid; 494 char *shm,*s,*s1; 495 map *tmpMap=NULL; 496 key_t key=getKeyValue(conf); 497 if(key!=-1){ 498 semid lockid=getShmLockId(conf,1); 499 if(lockid<0) 500 return ZOO_LOCK_CREATE_FAILED; 501 if(lockShm(lockid)<0){ 502 return ZOO_LOCK_ACQUIRE_FAILED; 503 } 504 if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { 505 #ifdef DEBUG 506 fprintf(stderr,"shmget failed to create new Shared memory segment\n"); 507 #endif 508 unlockShm(lockid); 509 return -2; 510 }else{ 511 if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) { 512 #ifdef DEBUG 513 fprintf(stderr,"shmat failed to update value\n"); 514 #endif 515 unlockShm(lockid); 516 return -1; 517 } 518 else{ 519 tmpMap=getMapFromMaps(conf,"lenv","status"); 520 s1=shm; 521 for(s=tmpMap->value;*s!=NULL && *s!=0;s++){ 522 *s1++=*s; 523 } 524 *s1++='|'; 525 tmpMap=getMapFromMaps(conf,"lenv","message"); 526 if(tmpMap!=NULL) 527 for(s=tmpMap->value;*s!=NULL && *s!=0;s++){ 528 *s1++=*s; 529 } 530 *s1=NULL; 531 shmdt((void *)shm); 532 unlockShm(lockid); 533 } 534 } 535 } 536 return 0; 537 } 538 539 /** 540 * Update the current of the running service. 603 * Get the current status of the running service. 541 604 * 542 605 * @see getKeyValue, getShmLockId, lockShm -
trunk/zoo-project/zoo-kernel/service_internal.h
r649 r652 60 60 */ 61 61 #define ZOO_LOCK_RELEASE_FAILED -6 62 /** 63 * Number of time the ZOO-Kernel will try to acquire lock 64 */ 65 #define ZOO_LOCK_MAX_RETRY 10 62 66 63 67 #include <sys/stat.h> … … 100 104 void unhandleStatus(maps*); 101 105 int _updateStatus(maps*); 102 char* _getStatus(maps*,int); 106 char* _getStatus(maps*,char*); 107 char* _getStatusFile(maps*,char*); 103 108 char* getStatus(int); 109 104 110 int updateStatus( maps*,const int,const char*); 105 111 int removeShmLock(maps*, int); … … 112 118 #define semid HANDLE 113 119 #endif 120 semid acquireLock(maps*); 114 121 semid getShmLockId(maps*,int); 115 122 int lockShm(semid); 116 123 int unlockShm(semid); 117 124 118 #ifdef USE_JS119 #endif120 121 125 #ifdef __cplusplus 122 126 } -
trunk/zoo-project/zoo-kernel/service_internal_saga.c
r640 r652 102 102 103 103 maps* SagaWatcher::m_conf; 104 char* SagaWatcher::message=zStrdup(" ");104 char* SagaWatcher::message=zStrdup("No message left"); 105 105 int SagaWatcher::status=1; 106 106 … … 121 121 { 122 122 default: 123 re s =0;123 return 0; 124 124 break; 125 125 126 case CALLBACK_PROCESS_GET_OKAY: 126 case CALLBACK_DLG_ERROR: 127 return 1; 127 128 break; 128 129 130 case CALLBACK_DLG_PARAMETERS: 129 131 case CALLBACK_PROCESS_SET_OKAY: 132 case CALLBACK_DATAOBJECT_COLORS_GET: 133 case CALLBACK_DATAOBJECT_COLORS_SET: 134 case CALLBACK_DATAOBJECT_PARAMS_GET: 135 case CALLBACK_DATAOBJECT_PARAMS_SET: 136 case CALLBACK_DATAOBJECT_UPDATE: 137 case CALLBACK_DATAOBJECT_SHOW: 138 case CALLBACK_DLG_CONTINUE: 139 case CALLBACK_PROCESS_SET_READY: 130 140 break; 131 141 … … 139 149 break; 140 150 141 case CALLBACK_PROCESS_ SET_READY:151 case CALLBACK_PROCESS_GET_OKAY: 142 152 status=1; 143 153 break; … … 161 171 case CALLBACK_DLG_MESSAGE: 162 172 SetMessage((param2.String + ": " + param1.String).b_str()); 163 break;164 165 case CALLBACK_DLG_CONTINUE:166 break;167 168 case CALLBACK_DLG_ERROR:169 173 break; 170 174 … … 174 178 else 175 179 res = 0; 176 break;177 178 case CALLBACK_DATAOBJECT_UPDATE:179 break;180 181 case CALLBACK_DATAOBJECT_SHOW:182 break;183 184 case CALLBACK_DATAOBJECT_COLORS_GET:185 break;186 187 case CALLBACK_DATAOBJECT_COLORS_SET:188 break;189 190 case CALLBACK_DATAOBJECT_PARAMS_GET:191 break;192 193 case CALLBACK_DATAOBJECT_PARAMS_SET:194 break;195 196 case CALLBACK_DLG_PARAMETERS:197 180 break; 198 181 -
trunk/zoo-project/zoo-kernel/sqlapi.c
r651 r652 1 1 /* 2 2 * Author : David Saggiorato 3 * 4 * Copyright 20 08-2009GeoLabs SARL. All rights reserved.3 * Gérald Fenoy 4 * Copyright 2015 GeoLabs SARL. All rights reserved. 5 5 * 6 6 * Permission is hereby granted, free of charge, to any person obtaining a copy … … 23 23 */ 24 24 25 #ifdef RELY_ON_DB 26 #include "ogr_api.h" 27 #include "ogrsf_frmts.h" 28 #include "ogr_p.h" 29 25 30 #include "sqlapi.h" 26 31 #include <fcgi_stdio.h> 27 #include <uuid/uuid.h>28 32 #include <stdlib.h> 29 33 30 34 /** 31 * Generate a UUID. 32 * ref: https://www.ietf.org/rfc/rfc4122.txt / 4.2 33 * 34 * @return a new char* containing the UUID, make sure to free the returned ressource 35 * once used. 36 */ 37 char *get_uuid(){ 38 char *res=(char*)malloc(37*sizeof(char)); 39 uuid_t uuid; 40 uuid_generate_time(uuid); 41 char * rest; 42 uuid_unparse(uuid,rest); 43 sprintf(res,"%s", rest); 35 * Global GDALDataset pointer 36 */ 37 OGRDataSource *zoo_DS = NULL; 38 39 /** 40 * Global OGRLayer pointer pointing to the lastest result set 41 */ 42 OGRLayer *zoo_ResultSet = NULL; 43 44 /** 45 * Create a GDAL / OGR string for connecting to the db backend 46 * (do not support active_schema) 47 * 48 * @param conf the maps containing the setting of the main.cfg file 49 */ 50 char* createInitString(maps* conf){ 51 char* res=NULL; 52 char keywords[5][9]={ 53 "dbname", 54 "host", 55 "port", 56 "user", 57 "password" 58 }; 59 int i=0; 60 maps* cconf=getMaps(conf,"database"); 61 int len=0; 62 for(i=0;i<5;i++){ 63 map* tmp=getMap(cconf->content,keywords[i]); 64 if(tmp!=NULL){ 65 if(res==NULL){ 66 res=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+4)*sizeof(char)); 67 sprintf(res,"%s='%s'",keywords[i],tmp->value); 68 len+=strlen(res); 69 }else{ 70 char* res1=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char)); 71 sprintf(res1," %s='%s'",keywords[i],tmp->value); 72 res=(char*)realloc(res,(len+strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char)); 73 memcpy(res+len,res1,(strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char)); 74 len+=strlen(res1); 75 res[len]=0; 76 free(res1); 77 } 78 } 79 } 80 map* tmp=getMap(cconf->content,"type"); 81 if(tmp!=NULL){ 82 char* fres=(char*)malloc((strlen(res)+strlen(tmp->value)+2)*sizeof(char)); 83 sprintf(fres,"%s:%s",tmp->value,res); 84 free(res); 85 return fres; 86 } 44 87 return res; 45 88 } 89 90 /** 91 * Connect to the db backend. 92 * 93 * @param conf the maps containing the setting of the main.cfg file 94 * @see createInitString 95 */ 96 void init_sql(maps* conf){ 97 char* sqlInitString=createInitString(conf); 98 OGRSFDriver *poDriver = NULL; 99 OGRRegisterAll(); 100 zoo_DS = OGRSFDriverRegistrar::Open(sqlInitString,false,&poDriver); 101 if( zoo_DS == NULL ){ 102 #ifdef DEBUG 103 fprintf(stderr,"sqlInitString: %s FAILED !\n",sqlInitString); 104 fflush(stderr); 105 #endif 106 free(sqlInitString); 107 setMapInMaps(conf,"lenv","message","Failed to connect to the database backend"); 108 return; 109 } 110 #ifdef DEBUG 111 fprintf(stderr,"sqlInitString: %s SUCEED !\n",sqlInitString); 112 fflush(stderr); 113 #endif 114 free(sqlInitString); 115 } 116 117 /** 118 * Close any connection to the db backend. 119 * 120 * @param conf the maps containing the setting of the main.cfg file 121 */ 122 void close_sql(maps* conf){ 123 if( zoo_ResultSet != NULL ) 124 zoo_DS->ReleaseResultSet( zoo_ResultSet ); 125 if(zoo_DS!=NULL){ 126 OGRDataSource::DestroyDataSource( zoo_DS ); 127 zoo_DS=NULL; 128 } 129 } 130 131 /** 132 * Call OGRCleanupAll. 133 * 134 */ 135 void end_sql(){ 136 OGRCleanupAll(); 137 } 138 139 /** 140 * Execute a SQL query to the SQL Database Backend. 141 * 142 * @param conf the maps containing the setting of the main.cfg file 143 * @param sqlQuery the SQL query to run 144 * @return -1 in case of failure and 1 if the query succeed. 145 */ 146 int execSql(maps* conf,const char* sqlQuery){ 147 zoo_ResultSet = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL); 148 if( zoo_ResultSet != NULL ){ 149 return 1; 150 } 151 return -1; 152 } 153 154 /** 155 * Clean any memory allocated by executing a request 156 * 157 * @param conf the maps containing the setting of the main.cfg file 158 * @param sqlQuery the SQL query to run 159 * @return -1 in case of failure and 1 if the query succeed. 160 */ 161 void cleanUpResultSet(const maps* conf){ 162 if( zoo_ResultSet != NULL ){ 163 zoo_DS->ReleaseResultSet( zoo_ResultSet ); 164 zoo_ResultSet=NULL; 165 } 166 } 167 168 /** 169 * Record a file stored during ZOO-Kernel execution 170 * 171 * @param conf the maps containing the setting of the main.cfg file 172 * @param filename the file's name 173 * @param type the type (Intput,Output,Response) 174 * @param name the maps containing the setting of the main.cfg file 175 */ 176 void recordStoredFile(maps* conf,const char* filename,const char* type,const char* name){ 177 map *uusid=getMapFromMaps(conf,"lenv","usid"); 178 map *schema=getMapFromMaps(conf,"database","schema"); 179 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(uusid->value)+strlen(filename)+strlen(type)+(name!=NULL?strlen(name):2)+68+1)*sizeof(char)); 180 if(name!=NULL) 181 sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s','%s');",schema->value,uusid->value,filename,type,name); 182 else 183 sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s',NULL);",schema->value,uusid->value,filename,type); 184 execSql(conf,sqlQuery); 185 cleanUpResultSet(conf); 186 } 187 188 /** 189 * Insert the reference tuple corresponding to the running service 190 * 191 * @param conf the maps containing the setting of the main.cfg file 192 */ 193 void recordServiceStatus(maps* conf){ 194 map *sid=getMapFromMaps(conf,"lenv","sid"); 195 map *osid=getMapFromMaps(conf,"lenv","osid"); 196 map *uusid=getMapFromMaps(conf,"lenv","usid"); 197 map *schema=getMapFromMaps(conf,"database","schema"); 198 char *sqlQuery=(char*)malloc((strlen(schema->value)+ 199 strlen(uusid->value)+ 200 strlen(osid->value)+ 201 strlen(sid->value)+56+1)*sizeof(char)); 202 sprintf(sqlQuery, 203 "INSERT INTO %s.services (uuid,sid,osid)" 204 "VALUES ('%s','%s','%s');", 205 schema->value, 206 uusid->value,sid->value,osid->value); 207 execSql(conf,sqlQuery); 208 cleanUpResultSet(conf); 209 } 210 211 /** 212 * Store the content of the result file 213 * 214 * @param conf the maps containing the setting of the main.cfg file 215 * @param filename the file's name 216 */ 217 void recordResponse(maps* conf,char* filename){ 218 FILE *file = fopen (filename, "rb"); 219 fseek (file, 0, SEEK_END); 220 long flen = ftell (file); 221 fseek (file, 0, SEEK_SET); 222 char *tmps = (char *) malloc ((flen + 1) * sizeof (char)); 223 fread (tmps, flen, 1, file); 224 tmps[flen]=0; 225 fclose(file); 226 map *sid=getMapFromMaps(conf,"lenv","usid"); 227 map *schema=getMapFromMaps(conf,"database","schema"); 228 char *sqlQuery=(char*)malloc((strlen(schema->value)+flen+strlen(sid->value)+51+1)*sizeof(char)); 229 sprintf(sqlQuery,"UPDATE %s.services set response=$$%s$$ where uuid=$$%s$$;",schema->value,tmps,sid->value); 230 execSql(conf,sqlQuery); 231 cleanUpResultSet(conf); 232 } 233 234 /** 235 * Update the current status of the running service. 236 * 237 * @param conf the map containing the setting of the main.cfg file 238 * @return 0 on success, -2 if shmget failed, -1 if shmat failed 239 */ 240 int _updateStatus(maps* conf){ 241 map *sid=getMapFromMaps(conf,"lenv","usid"); 242 map *p=getMapFromMaps(conf,"lenv","status"); 243 map *msg=getMapFromMaps(conf,"lenv","message"); 244 map *schema=getMapFromMaps(conf,"database","schema"); 245 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char)); 246 sprintf(sqlQuery,"UPDATE %s.services set status=$$%s$$,message=$$%s$$ where uuid=$$%s$$;",schema->value,p->value,msg->value,sid->value); 247 fflush(stderr); 248 if( zoo_DS == NULL ) 249 init_sql(conf); 250 execSql(conf,sqlQuery); 251 cleanUpResultSet(conf); 252 return 0; 253 } 254 255 /** 256 * Get the ongoing status of a running service 257 * 258 * @param conf the maps containing the setting of the main.cfg file 259 * @param pid the service identifier (usid key from the [lenv] section) 260 * @return the reported status char* (MESSAGE|POURCENTAGE) 261 */ 262 char* _getStatus(maps* conf,char* pid){ 263 map *schema=getMapFromMaps(conf,"database","schema"); 264 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char)); 265 sprintf(sqlQuery,"select status||'|'||message from %s.services where uuid=$$%s$$;",schema->value,pid); 266 if( zoo_DS == NULL ) 267 init_sql(conf); 268 execSql(conf,sqlQuery); 269 OGRFeature *poFeature = NULL; 270 const char *tmp1; 271 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ 272 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 273 if( poFeature->IsFieldSet( iField ) ){ 274 tmp1=strdup(poFeature->GetFieldAsString( iField )); 275 } 276 else 277 tmp1=NULL; 278 } 279 OGRFeature::DestroyFeature( poFeature ); 280 } 281 cleanUpResultSet(conf); 282 return (char*)tmp1; 283 } 284 285 /** 286 * Read the cache file of a running service 287 * 288 * @param conf the maps containing the setting of the main.cfg file 289 * @param pid the service identifier (usid key from the [lenv] section) 290 * @return the reported status char* (temporary/final result) 291 */ 292 char* _getStatusFile(maps* conf,char* pid){ 293 map *schema=getMapFromMaps(conf,"database","schema"); 294 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char)); 295 sprintf(sqlQuery,"select response from %s.services where uuid=$$%s$$;",schema->value,pid); 296 if( zoo_DS == NULL ) 297 init_sql(conf); 298 execSql(conf,sqlQuery); 299 OGRFeature *poFeature = NULL; 300 const char *tmp1; 301 int hasRes=-1; 302 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ 303 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 304 if( poFeature->IsFieldSet( iField ) ){ 305 tmp1=strdup(poFeature->GetFieldAsString( iField )); 306 hasRes=1; 307 } 308 else 309 tmp1=NULL; 310 } 311 OGRFeature::DestroyFeature( poFeature ); 312 } 313 if(hasRes<0) 314 tmp1=NULL; 315 cleanUpResultSet(conf); 316 return (char*)tmp1; 317 } 318 319 /** 320 * Stop handling status repport. 321 * 322 * @param conf the map containing the setting of the main.cfg file 323 */ 324 void unhandleStatus(maps* conf){ 325 map *sid=getMapFromMaps(conf,"lenv","usid"); 326 char *sqlQuery=(char*)malloc((strlen(sid->value)+52+1)*sizeof(char)); 327 sprintf(sqlQuery,"UPDATE services set end_time=now() where uuid=$$%s$$;",sid->value); 328 execSql(conf,sqlQuery); 329 cleanUpResultSet(conf); 330 close_sql(conf); 331 end_sql(); 332 } 333 334 #endif -
trunk/zoo-project/zoo-kernel/sqlapi.h
r644 r652 30 30 #endif 31 31 32 char *get_uuid(); 33 void init_sql(const char* host,const char *user, const char *passwd, const char * bdd,int port); 34 int add_job(const char * uuid); 35 int start_job(const char *uuid); 32 #ifdef RELY_ON_DB 33 #include "service.h" 34 #include "service_internal.h" 35 void init_sql(maps*); 36 void close_sql(maps*); 37 int execSql(maps*,const char*); 38 void recordStoredFile(maps*,const char*,const char*,const char*); 39 void recordServiceStatus(maps*); 40 void recordResponse(maps*,char*,bool); 41 #endif 36 42 37 43 #ifdef __cplusplus -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r640 r652 1669 1669 } 1670 1670 1671 1672 // Define each env variable in runing environment 1671 1673 maps *curs = getMaps (m, "env"); 1672 1674 if (curs != NULL) … … 1728 1730 #endif 1729 1731 1730 /** 1731 * Need to check if we need to fork to load a status enabled 1732 */ 1732 // Need to check if we need to fork to load a status enabled 1733 1733 r_inputs = NULL; 1734 1734 map *store = getMap (request_inputs, "storeExecuteResponse"); … … 1787 1787 _tmpMaps->name = zStrdup ("lenv"); 1788 1788 char tmpBuff[100]; 1789 semid lid = getShmLockId (NULL, 1);1790 lockShm (lid);1791 1789 struct ztimeval tp; 1792 1790 if (zGettimeofday (&tp, NULL) == 0) … … 1794 1792 else 1795 1793 sprintf (tmpBuff, "%i", (cpid + (int) time (NULL))); 1796 unlockShm (lid); 1797 removeShmLock (NULL, 1); 1798 _tmpMaps->content = createMap ("usid", tmpBuff); 1794 _tmpMaps->content = createMap ("osid", tmpBuff); 1799 1795 _tmpMaps->next = NULL; 1800 1796 sprintf (tmpBuff, "%i", cpid); … … 1802 1798 char* tmpUuid=get_uuid(); 1803 1799 addToMap (_tmpMaps->content, "uusid", tmpUuid); 1800 addToMap (_tmpMaps->content, "usid", tmpUuid); 1804 1801 free(tmpUuid); 1805 1802 addToMap (_tmpMaps->content, "status", "0"); … … 1910 1907 } 1911 1908 #endif 1912 char *fbkp, *fbkp 1;1909 char *fbkp, *fbkpid, *fbkp1, *flog; 1913 1910 FILE *f0, *f1; 1914 1911 if (status != NULL) … … 1977 1974 * process answer to http client. 1978 1975 */ 1979 #ifndef WIN32 1980 zSleep (1); 1981 #endif 1982 r_inputs = getMapFromMaps (m, "lenv", "usid"); 1976 map* usid = getMapFromMaps (m, "lenv", "uusid"); 1977 r_inputs = getMapFromMaps (m, "lenv", "osid"); 1983 1978 int cpid = atoi (r_inputs->value); 1984 1979 r_inputs = getMapFromMaps (m, "main", "tmpPath"); 1985 //map *r_inputs1 = getMap (s1->content, "ServiceProvider"); 1986 map* r_inputs1 = createMap("ServiceName", s1->name); 1987 1980 map* r_inputs1 = createMap("ServiceName", s1->name); 1981 1982 // Create PID file referencing the OS process identifier 1983 fbkpid = 1984 (char *) 1985 malloc ((strlen (r_inputs->value) + 1986 strlen (usid->value) + 7) * sizeof (char)); 1987 sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value); 1988 1989 f0 = freopen (fbkpid, "w+", stdout); 1990 fprintf(stdout,"%d",getpid()); 1991 fflush(stdout); 1992 1993 // Create SID file referencing the semaphore name 1988 1994 fbkp = 1989 1995 (char *) 1990 1996 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 1991 1024) * sizeof (char)); 1992 sprintf (fbkp, "%s/%s_%d.xml", r_inputs->value, r_inputs1->value, 1993 cpid); 1994 char *flog = 1997 strlen (usid->value) + 7) * sizeof (char)); 1998 sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value); 1999 2000 FILE* f2 = fopen (fbkp, "w+"); 2001 map* tmpm=getMapFromMaps (m, "lenv", "osid"); 2002 fprintf(f2,"%s",tmpm->value); 2003 fflush(f2); 2004 fclose(f2); 2005 free(fbkp); 2006 2007 fbkp = 1995 2008 (char *) 1996 2009 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 1997 1024) * sizeof (char)); 1998 sprintf (flog, "%s/%s_%d_error.log", r_inputs->value, 1999 r_inputs1->value, cpid); 2010 strlen (usid->value) + 7) * sizeof (char)); 2011 sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value, 2012 usid->value); 2013 flog = 2014 (char *) 2015 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2016 strlen (usid->value) + 13) * sizeof (char)); 2017 sprintf (flog, "%s/%s_%s_error.log", r_inputs->value, 2018 r_inputs1->value, usid->value); 2000 2019 #ifdef DEBUG 2001 2020 fprintf (stderr, "RUN IN BACKGROUND MODE \n"); … … 2005 2024 #endif 2006 2025 freopen (flog, "w+", stderr); 2007 semid lid = getShmLockId (m, 1);2008 2026 fflush (stderr); 2009 if (lid < 0)2010 {2011 return errorException (m, _("Lock failed"),2012 "InternalError", NULL);2013 }2014 else2015 {2016 if (lockShm (lid) < 0)2017 {2018 return errorException (m, _("Lock failed"),2019 "InternalError", NULL);2020 }2021 }2022 2027 f0 = freopen (fbkp, "w+", stdout); 2023 2028 rewind (stdout); … … 2036 2041 request_output_real_format); 2037 2042 fflush (stdout); 2038 unlockShm (lid); 2043 #ifdef RELY_ON_DB 2044 init_sql(m); 2045 recordServiceStatus(m); 2046 recordResponse(m,fbkp); 2047 #endif 2039 2048 fflush (stderr); 2040 2049 fbkp1 = 2041 2050 (char *) 2042 2051 malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) + 2043 1024) * sizeof (char));2044 sprintf (fbkp1, "%s/%s_final_% d.xml", r_inputs->value,2045 r_inputs1->value, cpid);2052 strlen (usid->value) + 13) * sizeof (char)); 2053 sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value, 2054 r_inputs1->value, usid->value); 2046 2055 2047 2056 f1 = freopen (fbkp1, "w+", stdout); 2048 free (flog);2049 2057 2050 2058 if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){ … … 2062 2070 free (tmpmaps); 2063 2071 fflush (stdout); 2064 unlockShm (lid);2065 2072 fflush (stderr); 2073 unhandleStatus (m); 2066 2074 return -1; 2067 2075 } … … 2073 2081 else 2074 2082 { 2075 2076 2077 2078 2083 /** 2084 * error server don't accept the process need to output a valid 2085 * error response here !!! 2086 */ 2079 2087 eres = -1; 2080 2088 errorException (m, _("Unable to run the child process properly"), … … 2109 2117 fclose (stdout); 2110 2118 fclose (stderr); 2111 /**2112 * Dump back the final file fbkp1 to fbkp2113 */2119 /** 2120 * Dump back the final file fbkp1 to fbkp 2121 */ 2114 2122 fclose (f0); 2115 2123 fclose (f1); 2116 2124 FILE *f2 = fopen (fbkp1, "rb"); 2125 #ifndef RELY_ON_DB 2117 2126 semid lid = getShmLockId (m, 1); 2118 2127 if (lid < 0) 2119 2128 return -1; 2120 2129 lockShm (lid); 2130 #endif 2121 2131 FILE *f3 = fopen (fbkp, "wb+"); 2122 2132 free (fbkp); … … 2129 2139 fclose (f2); 2130 2140 fclose (f3); 2131 unlockShm (lid); 2141 unlink (fbkpid); 2142 #ifndef RELY_ON_DB 2143 removeShmLock (m, 1); 2144 #else 2145 recordResponse(m,fbkp1); 2146 #endif 2132 2147 unlink (fbkp1); 2148 unlink (flog); 2149 unhandleStatus (m); 2150 free(fbkpid); 2151 free (flog); 2133 2152 free (fbkp1); 2134 2153 free (tmps1); 2135 unhandleStatus (m);2136 2154 } 2137 2155 -
trunk/zoo-project/zoo-services/utils/status/service.c
r643 r652 65 65 tmpMmap=tmpTmap; 66 66 xmlInitParser(); 67 struct dirent *dp;68 DIR *dirp = opendir(tmpTmap->value);69 char fileName[1024],xslFileName[1024];70 67 int hasFile=-1; 71 if(dirp!=NULL){ 72 char tmp[128]; 73 sprintf(tmp,"_%s.xml",tmpMap->value); 74 while ((dp = readdir(dirp)) != NULL){ 75 #ifdef DEBUG 76 fprintf(stderr,"File : %s searched : %s\n",dp->d_name,tmp); 77 #endif 78 if(strstr(dp->d_name,"final_")==0 && strstr(dp->d_name,tmp)!=0){ 79 sprintf(fileName,"%s/%s",tmpTmap->value,dp->d_name); 80 hasFile=1; 81 break; 82 } 83 } 84 }else{ 85 char tmp[1024]; 86 snprintf(tmp,1024,_ss("GetStatus was unable to use the tmpPath value set in main.cfg file as directory %s."),tmpTmap->value); 87 setMapInMaps(conf,"lenv","message",tmp); 88 return SERVICE_FAILED; 89 } 90 if(hasFile<0){ 68 char xslFileName[1024]; 69 char* mem=_getStatusFile(conf,tmpMap->value); 70 if(mem==NULL){ 91 71 char tmp[1024]; 92 72 snprintf(tmp,1024,_ss("GetStatus was unable to find any cache file for Service ID %s."),tmpMap->value); … … 100 80 xmlDocPtr doc, res; 101 81 cur = xsltParseStylesheetFile(BAD_CAST xslFileName); 102 doc = xmlParseFile(fileName); 82 doc = xmlParseMemory(mem,strlen(mem)); 83 //doc = xmlParseFile(fileName); 103 84 if(cur!=NULL && doc!=NULL){ 104 85 /** 105 86 * Parse Status to extract Status / Message 106 87 */ 107 char *tmpStr=_getStatus(conf, atoi(tmpMap->value));88 char *tmpStr=_getStatus(conf,tmpMap->value); 108 89 #ifdef DEBUG 109 90 fprintf(stderr,"DEBUG: %s \n",tmpStr);
Note: See TracChangeset
for help on using the changeset viewer.