Changeset 854 for branches


Ignore:
Timestamp:
Nov 21, 2017, 10:24:14 AM (6 years ago)
Author:
djay
Message:

HPC support update. Add inputs for create options in Gdal_Dem.

Location:
branches/prototype-v0/zoo-project
Files:
1 added
31 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in

    r839 r854  
    4545
    4646service_callback.o: service_callback.c
    47         g++ -fPIC ${JSON_CFLAGS} ${CFLAGS} -c service_callback.c
     47        g++ -fPIC ${XML2CFLAGS} ${JSON_CFLAGS} ${CFLAGS} -c service_callback.c
    4848
    4949request_parser.o: request_parser.c request_parser.h
     
    6060
    6161server_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.c
     62        g++ ${JSON_CFLAGS} ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c server_internal.c
    6363
    6464service_internal.o: service_internal.c service_internal.h service.h
    65         gcc ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c
     65        gcc ${JSON_CFLAGS} ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c
    6666
    6767service_yaml.o: service_yaml.c service.h
     
    126126zcfg2yaml: 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}
    127127        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}
    129129
    130130install: zoo_loader.cgi
  • branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in

    r839 r854  
    115115
    116116CFLAGS=@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@
     117LDFLAGS=-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@
    118118
    119119DATAROOTDIR=@datarootdir@/zoo-project
  • branches/prototype-v0/zoo-project/zoo-kernel/caching.c

    r839 r854  
    6464
    6565/**
     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 */
     76char* 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/**
    66132 * Cache a file for a given request.
    67133 * For each cached file, the are two files stored, a .zca and a .zcm containing
     
    80146  map* tmp=getMapFromMaps(conf,"main","cacheDir");
    81147  if(tmp!=NULL){
    82     char* md5str=getMd5(request);
     148    char* myRequest=getFilenameForRequest(conf,request);
     149    char* md5str=getMd5(myRequest);
     150    free(myRequest);
    83151    char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
    84152    sprintf(fname,"%s/%s.zca",tmp->value,md5str);
     153    zooLock* lck=lockFile(conf,fname,'w');
     154    if(lck!=NULL){
    85155#ifdef DEBUG
    86     fprintf(stderr,"Cache list : %s\n",fname);
    87     fflush(stderr);
     156      fprintf(stderr,"Cache list : %s\n",fname);
     157      fflush(stderr);
    88158#endif
    89     FILE* fo=fopen(fname,"w+");
    90     if(fo==NULL){
     159      FILE* fo=fopen(fname,"w+");
     160      if(fo==NULL){
    91161#ifdef DEBUG
    92       fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno));
     162        fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno));
    93163#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);
    99171       
    100         if (filepath != NULL) {
    101                 strncpy(filepath, fname, max_path);
    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+");
    106178#ifdef DEBUG
    107     fprintf(stderr,"MIMETYPE: %s\n",mimeType);
     179      fprintf(stderr,"MIMETYPE: %s\n",mimeType);
    108180#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    }
    114196  }
    115197  else {
    116           filepath = NULL;
     198    filepath = NULL;
    117199  }       
    118200}
     
    129211  map* tmpM=getMapFromMaps(conf,"main","cacheDir");
    130212  if(tmpM!=NULL){
    131     char* md5str=getMd5(request);
     213    char* myRequest=getFilenameForRequest(conf,request);
     214    char* md5str=getMd5(myRequest);
     215    free(myRequest);
    132216#ifdef DEBUG
    133217    fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
     
    206290      sprintf(xname,"Reference");
    207291      sprintf(bname,"body");
    208       sprintf(hname,"headers",i);
     292      sprintf(hname,"headers");
    209293      sprintf(oname,"Order");
    210294    }
     
    280364            free(tmpStr);
    281365          }else{
    282             md5str=getMd5(tmp1->value);
     366            char *myRequest=getFilenameForRequest(*m,tmp1->value);
     367            md5str=getMd5(myRequest);
    283368            request=zStrdup(tmp1->value);
     369            free(myRequest);
    284370          }
    285371          char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
     
    387473
    388474  if(cached!=NULL){
    389 
    390475    struct stat f_status;
    391476    int s=stat(cached, &f_status);
    392477    if(s==0){
     478      zooLock* lck=lockFile(*m,cached,'r');
     479      if(lck==NULL)
     480        return -1;
    393481      fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
    394482      FILE* f=fopen(cached,"rb");
     
    398486      fclose(f);
    399487      addToMap(*content,"cache_file",cached);
     488      unlockFile(*m,lck);
    400489    }
    401490    cached[strlen(cached)-1]='m';
    402491    s=stat(cached, &f_status);
    403492    if(s==0){
     493      zooLock* lck=lockFile(*m,cached,'r');
     494      if(lck==NULL)
     495        return -1;
    404496      mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1));
    405497      FILE* f=fopen(cached,"rb");
     
    407499      mimeType[f_status.st_size]=0;
    408500      fclose(f);
    409     }
    410 
     501      unlockFile(*m,lck);
     502    }
    411503  }else{   
    412504    addRequestToQueue(m,hInternet,url,true);
     
    439531    if(tmp!=NULL){
    440532      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);
    442536      char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
    443537      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
  • branches/prototype-v0/zoo-project/zoo-kernel/meta_sql.c

    r850 r854  
    297297 */
    298298elements* 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__);
    301299  elements* res=createElements(input->GetFieldAsString( 1 ));
    302300  res->content=createMap("title",input->GetFieldAsString( 2 ));
     
    348346  fillMetadata(conf,&res->metadata,output->GetFieldAsString( 0 ));
    349347  fillAdditionalParameters(conf,&res->additional_parameters,output->GetFieldAsString( 0 ));
    350   res->defaults=NULL;
    351   res->supported=NULL;
    352   res->child=NULL;
    353   res->next=NULL;
    354348  int ioCnt=fillLiteralData(conf,res,output,"Output");
    355349  if(ioCnt==0)
     
    361355  free(nestedOutputsQuery);
    362356  while( (noutput = noutputs->GetNextFeature()) != NULL ){
    363     elements* nout=extractInput(conf,noutput);
     357    elements* nout=extractOutput(conf,noutput);
    364358    addToElements(&res->child,nout);
    365359    freeElements(&nout);
     
    413407        elements* in=extractInput(conf,input);
    414408        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);
    419410          freeElements(&in);
    420411          free(in);
     
    431422      while( (output = outputs->GetNextFeature()) != NULL ){
    432423        elements* in=extractOutput(conf,output);
    433         if(s->outputs==NULL)
    434           s->outputs=dupElements(in);
    435         else
     424        if(in!=NULL){
    436425          addToElements(&s->outputs,in);
    437         freeElements(&in);
    438         free(in);
     426          freeElements(&in);
     427          free(in);
     428        }
    439429        OGRFeature::DestroyFeature( output );
    440430      }
     
    463453                                     service *), int minimal ){
    464454  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)
    467457    return -1;
    468458  // Fetch every services
  • branches/prototype-v0/zoo-project/zoo-kernel/mimetypes.h

    r839 r854  
    818818*/
    819819static 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;
    823822       
    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;
    837838}
    838839
  • branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c

    r839 r854  
    18491849  }
    18501850}
     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 */
     1858void 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  
    4949  void checkValidValue(map*,map**,const char*,const char**,int);
    5050  int validateRequest(maps**,service*,map*,maps**,maps**,HINTERNET*);
    51 
     51  void parseCookie(maps**,const char*);
     52 
    5253#ifdef __cplusplus
    5354}
  • branches/prototype-v0/zoo-project/zoo-kernel/response_print.c

    r851 r854  
    743743}
    744744
    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 */
     753void addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){
    746754    int hasTitle=-1;
    747755    int hasValue=-1;
     
    817825}
    818826
    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 */
     837void addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){
    821838    int hasTitle=-1;
    822839    int hasValue=-1;
     840    int toAddAtEnd=-1;
     841    int cnt=0;
     842    xmlNodePtr* ncr=NULL;
    823843    xmlNodePtr nc1;
    824844    map* oMeta=meta;
    825845    int isAdditionalParameters=-1;
    826     //if(count(oMeta)>=2){
    827846    int level=0;
    828847    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   
    829853    if(test!=NULL)
    830854      level+=1;
     
    837861    if(count(oMeta)>level+1)
    838862      isAdditionalParameters=1;
    839     //}
    840     char *ctitle=NULL;
     863
    841864    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      }
    845868      if(strncasecmp(meta->name,"title",5)==0 ||
    846869         strcasecmp(meta->name,"href")==0 ||
     
    851874          hasTitle=1;
    852875          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;
    857884          }
    858885          if(ctitle==NULL){
     
    865892            free(ctitle);
    866893          ctitle=zStrdup(meta->value);
     894        }else{
     895          xmlNewNsProp(nc1,ns_xlink,BAD_CAST meta->name,BAD_CAST meta->value);
    867896        }
    868897      }else{
     
    892921      meta=meta->next;
    893922      if(hasTitle<0){
    894         xmlAddChild(nc,nc1);
     923        //xmlAddChild(nc,nc1);
    895924        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){
    900934      xmlAddChild(nc,nc1);
     935      free(ctitle);
    901936    }
    902937}
     
    14061441                  }
    14071442                }
    1408                 else
     1443                else{
    14091444                  xmlFreeNode(nc9);
     1445                }
    14101446                if(strcasecmp(tmp1->name,"uom")==0)
    14111447                  hasUOM1=true;
     
    14281464            if(hasUOM1==false && vid==0){
    14291465              xmlFreeNode(nc5);
    1430               if(datatype==1)
     1466              if(datatype==1){
    14311467                xmlFreeNode(nc4);
     1468              }
    14321469            }
    14331470            else
     
    14401477        if(datatype!=1 && default1<0){
    14411478          xmlFreeNode(nc5);
    1442           if(datatype!=2)
     1479          if(datatype!=2){
    14431480            xmlFreeNode(nc4);
     1481          }
    14441482        }
    14451483
     
    16031641                if(vid==0 || oI!=4)
    16041642                  xmlAddChild(nc5,nc6);
    1605                 else
     1643                else{
    16061644                  xmlFreeNode(nc6);
     1645                }
    16071646              }
    1608               else
     1647              else{
    16091648                xmlFreeNode(nc6);
     1649              }
    16101650            }
    16111651            tmp1=tmp1->next;
     
    16341674            }
    16351675            else{
    1636               xmlFreeNode(nc4);
    16371676              xmlAddChild(nc3,nc5);
    16381677            }
     
    16481687
    16491688      if(hasSupported==0){
    1650         if(datatype==0 && vid!=0)
     1689        if(datatype==0 && vid!=0){
    16511690          xmlFreeNode(nc4);
     1691        }
    16521692        xmlFreeNode(nc5);
    16531693      }
     
    26782718      toto=getMap(tmpI->content,"asReference");
    26792719#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) ) )
    26812727#else
    26822728      if(toto!=NULL && strcasecmp(toto->value,"true")==0)
     
    26992745          }
    27002746
     2747          char *file_path=NULL;
    27012748          if(gfile==NULL) {
    27022749            map *ext=getMap(tmpI->content,"extension");
    2703             char *file_path;
    27042750            char file_ext[32];
    27052751
     
    27162762              free(file_name);
    27172763            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);
    27192765            itn++;
    27202766            file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
     
    27302776              return;
    27312777            }
    2732             free(file_path);
    27332778
    27342779            toto=getMap(tmpI->content,"value");
     
    27442789            }
    27452790            fclose(ofile);
    2746 
    27472791          }
    27482792
    27492793          map *tmp2=getMapFromMaps(m,"main","tmpUrl");
    27502794          map *tmp3=getMapFromMaps(m,"main","serverAddress");
    2751           char *file_url;
     2795          char *file_url=NULL;
    27522796          if(strncasecmp(tmp2->value,"http://",7)==0 ||
    27532797             strncasecmp(tmp2->value,"https://",8)==0){
     
    27592803          }
    27602804          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);
    27632819          file_name=NULL;
    27642820        }
     
    27662822      else{
    27672823        if(testMap!=NULL){
     2824          setMapInMaps(m,"lenv","state","out");
    27682825          setReferenceUrl(m,tmpI);
     2826          geodatatype=getMap(tmpI->content,"geodatatype");
     2827          if(geodatatype!=NULL && strcasecmp(geodatatype->value,"other")==0)
     2828            goto restartNoMS;
    27692829        }
    27702830      }
  • branches/prototype-v0/zoo-project/zoo-kernel/response_print.h

    r839 r854  
    220220  void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
    221221  void printStatusInfo(maps*,map*,char*);
    222   int addAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
    223   int addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr);
     222  void addAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
     223  void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr);
    224224
    225225  void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
  • branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c

    r850 r854  
    2626#include "service_internal.h"
    2727#include "response_print.h"
     28#include "service_callback.h"
    2829#include "mimetypes.h"
    2930#ifndef WIN32
     
    444445          if(cSize!=NULL){
    445446            length=atoi(cSize->value);
    446           }
     447          }else
     448            length=strlen(cValue->value);
    447449          writeFile(val,cValue->value,length);
    448450          setMapArray(cMap,"cache_file",k,val);
     
    466468        free(val);
    467469      }
     470      addToMap(inputs->content,"byValue","true");
    468471    }
    469472    inputs=inputs->next;
     
    980983    if(isRunning(conf,pid)>0){
    981984      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."),
    983986                        "ResultNotReady", pid);
    984987        return;
     
    10081011          printf("%s",result);
    10091012          fflush(stdout);
     1013          free(sid);
    10101014          freeMap(&statusInfo);
    10111015          free(statusInfo);
     1016          free(result);
    10121017          return;
    10131018        }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."),
    10151020                          "ResultNotReady", pid);
    10161021          freeMap(&statusInfo);
     
    11041109    removeService(conf,pid);
    11051110#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    */
    11061116    map* statusInfo=createMap("JobID",pid);
    11071117    addToMap(statusInfo,"Status","Dismissed");
  • branches/prototype-v0/zoo-project/zoo-kernel/service.c

    r850 r854  
    11721172    tmp->name=zStrdup(cursor->name);
    11731173    tmp->content=NULL;
    1174     addMapToMap(&tmp->content,e->content);
     1174    addMapToMap(&tmp->content,cursor->content);
    11751175    tmp->metadata=NULL;
    1176     addMapToMap(&tmp->metadata,e->metadata);
     1176    addMapToMap(&tmp->metadata,cursor->metadata);
    11771177    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);
    11811181    else
    11821182      tmp->format=NULL;
    1183     if(e->defaults!=NULL){
     1183    if(cursor->defaults!=NULL){
    11841184      tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
    11851185      tmp->defaults->content=NULL;
    1186       addMapToMap(&tmp->defaults->content,e->defaults->content);
     1186      addMapToMap(&tmp->defaults->content,cursor->defaults->content);
    11871187      tmp->defaults->next=NULL;
    11881188#ifdef DEBUG
     
    11921192    }else
    11931193      tmp->defaults=NULL;
    1194     if(e->supported!=NULL){
     1194    if(cursor->supported!=NULL && cursor->supported->content!=NULL){
    11951195      tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
    11961196      tmp->supported->content=NULL;
    1197       addMapToMap(&tmp->supported->content,e->supported->content);
     1197      addMapToMap(&tmp->supported->content,cursor->supported->content);
    11981198      tmp->supported->next=NULL;
    1199       iotype *tmp2=e->supported->next;
     1199      iotype *tmp2=cursor->supported->next;
    12001200      while(tmp2!=NULL){
    12011201        addMapToIoType(&tmp->supported,tmp2->content);
  • branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c

    r851 r854  
    3030#include "service_json.h"
    3131#include "service_internal_ms.h"
     32#include "sqlapi.h"
    3233#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>
    3343
    3444#ifdef __cplusplus
     
    3646#endif
    3747
     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   */
    3862  int nbThreads=0;
     63  /**
     64   * Current step
     65   */
    3966  int cStep=0;
     67  /**
     68   * Is there any ongoing HTTP request
     69   */
     70  int isOngoing=0;
     71  /**
     72   * Threads array
     73   */
    4074  pthread_t* myThreads=NULL;
     75  /**
     76   * Steps array
     77   */
    4178  bool steps[7][2]={
    4279    {false,false},
     
    4885    {false,false}
    4986  };
     87  /**
     88   * Arguments array to give to the _invokeCallback thread's function
     89   */
     90  local_params** local_arguments;
    5091 
    5192  /**
     
    71112  }
    72113
    73   /**
    74    * Parameter definition to be used for sending parameters to a thread.
    75    */
    76   typedef struct {
    77     maps *conf;      //!< the main configuration file
    78     map *url;        //!< the callback url maps
    79     json_object *res;//!< the JSON object to post
    80     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 the
    88    * domain listed in the shared key are contained in the url given as parameter
    89    * then it return "SHARED" in other cases, it returns "OTHER".
    90    *
    91    * @param conf the main configuration file maps
    92    * @param url the URL to evaluate
    93    * @return a string "SHARED" in case the host is in a domain listed in the
    94    * 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   }
    114114
    115115  /**
     
    133133    hInternet.waitingRequests[0] = zStrdup(URL);
    134134    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);
    136137    fprintf(stderr," * JSON: [%s] \n",jsonStr);
    137138    fprintf(stderr," * URL: %s/ \n\n",hInternet.waitingRequests[0]);
    138139    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) &&
    140142           ( cStep!=arg->step || (arg->state!=0 && steps[arg->step][0]==false) )
    141143           ){
    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
    144152    fprintf(stderr,"************************* From thread %d %s %d: REQUEST START\n\n",pthread_self(),__FILE__,__LINE__);
    145153    int i=0;
    146154    for(i=0;i<7;i++){
    147155      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);
    151172    fflush(stderr);
     173#endif   
     174    free(tmp1);
    152175    res1 = InternetOpenUrl (&hInternet,
    153176                            hInternet.waitingRequests[0],
     
    158181    //curl_easy_setopt(hInternet.ihandle[hInternet.nb].handle, CURLOPT_VERBOSE, 1);x
    159182    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);
    162192    char *tmp = (char *) malloc ((hInternet.ihandle[0].nDataLen + 1)
    163193                                 * sizeof (char));
     
    177207    json_object_put(arg->res);
    178208    InternetCloseHandle(&hInternet);
     209    isOngoing=0;
    179210    if(cStep==0 || cStep==6 || arg->state==1)
    180211      cStep=arg->step+1;
    181     steps[arg->step][arg->state]=true;
     212#ifdef CALLBACK_DEBUG   
    182213    fprintf(stderr,"************************* From thread %d %s %d: RESPONSE CONTENT\n",pthread_self(),__FILE__,__LINE__);
    183214    for(i=0;i<7;i++){
     
    187218    fprintf(stderr,"************************* From thread %d %s %d\n\n",pthread_self(),__FILE__,__LINE__);
    188219    fflush(stderr);
     220#endif
     221    steps[arg->step][arg->state]=true;
    189222    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);
    191226    pthread_exit(NULL);
    192227  }
     
    237272
    238273    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 );
    241275    json_object *jsStr0=json_object_new_string(tmp1);
    242276    json_object_object_add(res,"datetime",jsStr0);
    243 
     277    free(tmp1);
     278   
    244279    switch(step){
    245280    case 0: {
    246281      // Create a new analyze
    247282      maps* lenv=getMaps(conf,"lenv");
    248       sid=getMapFromMaps(conf,"lenv","xrequest");
     283      sid=getMapFromMaps(conf,"renv","xrequest");
    249284      if(sid!=NULL){
    250285        json_object *jsStr=json_object_new_string(sid->value);
     
    256291        json_object_object_add(res,"process_identifier",jsStr);
    257292      }
     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);
    258305      break;
    259306    }
     307     
    260308    case 1: {
    261309      // Fetching data inputs
    262310      maps* curs=inputs;
    263       char *keys[8][2]={
     311      dumpMaps(curs);
     312      char *keys[10][2]={
    264313        {
    265314          "href",
     
    287336        },
    288337        {
    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"
    291344        },
    292345        {
    293346          "geodatatype",
    294347          "datatype"
     348        },
     349        {
     350          "wcs_extent",
     351          "boundingbox"
    295352        }       
    296353      };
     
    300357        sid=getMap(curs->content,"ref_wms_link");
    301358        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);
    304366          struct stat buf;
    305367          char timeStr[ 100 ] = "";
     
    314376          }
    315377          setReferenceUrl(conf,curs);
    316           //outputMapfile(conf,curs);
    317           dumpMaps(curs);
    318378        }
    319379        int i=0;
    320380        int hasRef=-1;
    321         for(;i<8;i++){
     381        for(;i<10;i++){
    322382          sid=getMap(curs->content,keys[i][0]);
    323383          if(sid!=NULL){
     
    340400      break;
    341401    }
     402     
    342403    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
    343540      // Uploading data input to cluster
    344541      maps* in=getMaps(conf,"uploadQueue");
     
    371568      break;
    372569    }
     570     
    373571    case 3: {
    374572      // Generating job script
     
    380578      break;
    381579    }
     580     
    382581    case 4: {
    383582      // Submitting job to cluster
     
    389588      break;
    390589    }
     590     
    391591    case 5: {
    392592      // Downloading process outputs from cluster
    393593      //json_object* in=mapsToJson(outputs);
    394       dumpMaps(outputs);
    395594      maps* curs=outputs;
    396       char *keys[8][2]={
     595      dumpMaps(curs);
     596      char *keys[10][2]={
    397597        {
    398598          "Reference",
     
    400600        },
    401601        {
    402           "storage",
     602          "generated_file",
    403603          "cachefile"
    404604        },
    405605        {
    406           "fmimeType",
     606          "mimeType",
    407607          "mimetype"
    408608        },
     
    412612        },
    413613        {
     614          "geodatatype",
     615          "datatype"
     616        },
     617        {
     618          "wms_extent",
     619          "boundingbox"
     620        },
     621        {
    414622          "ref_wms_link",
    415623          "ref_wms_link"
     
    420628        },
    421629        {
     630          "ref_wcs_link",
     631          "ref_wcs_preview_link"
     632        },
     633        {
    422634          "ref_wfs_link",
    423635          "ref_wfs_link"
    424         },
    425         {
    426           "geodatatype",
    427           "datatype"
    428636        }       
     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        }
    429659      };
    430660      json_object *res1=json_object_new_object();
    431661      while(curs!=NULL){       
    432         map* tmpMap=getMap(curs->content,"cache_file");
    433         sid=getMap(curs->content,"ref_wms_link");
    434662        json_object *res2=json_object_new_object();
    435663        int i=0;
    436664        int hasRef=-1;
    437         for(;i<8;i++){
     665        for(;i<10;i++){
    438666          sid=getMap(curs->content,keys[i][0]);
    439667          if(sid!=NULL){
     
    448676        else{
    449677          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                }
    461722              }
     723              if(hasRef0<0)
     724                json_object_put(res3);
     725              else
     726                json_object_object_add(res2,curs0->name,res3);
     727              curs0=curs0->next;
    462728            }
    463             if(hasRef0<0)
    464               json_object_put(res3);
    465             else
    466               json_object_object_add(res2,curs0->name,res3);
    467             curs0=curs0->next;
    468           }       
    469729          json_object_object_add(res1,curs->name,res2);
    470730        }
     
    474734      break;
    475735    }
     736     
    476737    case 6: {
    477738      // 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);
    483784      break;
    484785    }
     786     
    485787    case 7: {
    486788      // Error or Dismiss
     
    490792        json_object_object_add(res,"message",jsStr);
    491793      }
    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");
    493799      json_object_object_add(res,"wps_status",jsStr);
    494800      break;
     
    498804      }
    499805    }
    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;
    507817    //pthread_t p1;
    508818    if(myThreads==NULL)
     
    510820    else
    511821      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){
    513823      setMapInMaps(conf,"lenv","message",_("Unable to create a new thread"));
    514824      return false;
     
    519829  }
    520830
     831  /**
     832   * Wait for the threads to end then, clean used memory.
     833   */
    521834  void cleanupCallbackThreads(){
    522835    int i=0;
    523836    for(i=0;i<nbThreads;i++){
     837      fprintf(stderr,"%s %d %d \n",__FILE__,__LINE__,i);
     838      fflush(stderr);
    524839      pthread_join(myThreads[i],NULL);
    525     }
     840      free(local_arguments[i]);
     841    }
     842    free(local_arguments);
    526843    free(myThreads);
    527844  }
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c

    r839 r854  
    3939
    4040#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 */
     49struct 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 */
     143int 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
    41162#ifndef RELY_ON_DB
    42163#include <dirent.h>
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h

    r680 r854  
    6363 * Number of time the ZOO-Kernel will try to acquire lock
    6464 */
    65 #define ZOO_LOCK_MAX_RETRY 10
     65#define ZOO_LOCK_MAX_RETRY 180
    6666
    6767#include <sys/stat.h>
     
    8585#endif
    8686
     87#include <fcntl.h>
     88 
    8789#include "service.h"
    8890
     
    9496#endif
    9597
     98/**
     99 * The lock structure used by the ZOO-Kernel to ensure atomicity of operations
     100 *
     101 */
     102typedef 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
     108static zooLock** zoo_file_locks=NULL;
     109static int zoo_file_locks_cnt=0;
     110
    96111#ifdef __cplusplus
    97112extern "C" {
    98113#endif
    99114
     115 
    100116  ZOO_DLL_EXPORT char *readVSIFile(maps*,const char*);
    101117  ZOO_DLL_EXPORT int  setOutputValue( maps*, const char*, char*, size_t);
    102118  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*);
    103122
    104123  ZOO_DLL_EXPORT void unhandleStatus(maps*);
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c

    r851 r854  
    144144        if(cur->defaults!=NULL){
    145145          freeIOType(&cur->defaults);
     146          free(cur->defaults);
    146147          cur->defaults=NULL;
    147148        }
    148149        if(cur->supported!=NULL){
    149150          freeIOType(&cur->supported);
     151          free(cur->supported);
    150152          cur->supported=NULL;
    151153        }
     
    162164  }
    163165  //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 */
     173int 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 */
     213int 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 */
     252char* 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";
    164277}
    165278
     
    181294  map* tmp=NULL;
    182295  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
    183298  char *serviceType;
    184299  map* mServiceType=getMap(s->content,"serviceType");
     
    187302  else
    188303    serviceType="HPC";
    189   map* targetPathMap=getMapFromMaps(*main_conf,serviceType,"storagePath");
    190304  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
    191305  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 
    192321  pthread_t threads_pool[50];
    193322  // Force the HPC services to be called asynchronously
     
    215344          dumpMapsValuesToFiles(main_conf,&input);
    216345          addToMap(input->content,"toPublish","true");
     346          addToMap(input->content,"useMapserver","true");
    217347        }
    218348        if(getMap(input->content,"cache_file")!=NULL){
     
    264394  invokeCallback(m,inputs,NULL,2,0);
    265395  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  }
    266401
    267402  // 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  }
    270411  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    271412  invokeCallback(m,inputs,NULL,2,1);
    272413  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    273414
    274   // Add the filename to generate for every output to the parameters
     415  // Add the filename to generate for every output to parameters
    275416  input=*real_outputs;
    276417  // TODO: fix appendOutputParameters
    277418  //appendOutputParameters(input,parameters,&parameters_cnt,s,uuid,targetPathMap);
     419  dumpMaps(input);
    278420  while(input!=NULL){
    279421    // TODO: parse all outputs including inner outputs if required.
    280422    if(input->child==NULL){
    281       parameters_cnt+=1;
    282       if(parameters_cnt==1)
    283         parameters=(char**)malloc(parameters_cnt*sizeof(char*));
    284       else
    285         parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));
    286423      // Name every files that should be produced by the service execution
    287424      map* mime=getMap(input->content,"mimeType");
     
    302439      free(targetName);
    303440      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        }
    314460      }
    315461      free(targetPath);
    316462    }// In other case it means we need to return the cache_file as generated_file
    317463    else{
    318       parameters_cnt+=1;
    319       if(parameters_cnt==1)
    320         parameters=(char**)malloc(parameters_cnt*sizeof(char*));
    321       else
    322         parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));
    323464      // Name every files that should be produced by the service execution
    324465      map* mime=getMap(input->child->content,"mimeType");
     
    339480      free(targetName);
    340481      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        }
    351502      }
    352503      free(targetPath);
     
    354505    input=input->next;
    355506  }
    356  
    357507  // Produce the SBATCH File locally
    358508  char *scriptPath=(char*)malloc((strlen(s->name)+strlen(tmpPath->value)+strlen(uuid->value)+10)*sizeof(char));
     
    365515  fflush(stderr);
    366516  FILE* scriptFile=fopen(scriptPath,"w+");
    367   map* headerMap=getMapFromMaps(*main_conf,serviceType,"header");
     517  map* headerMap=getMapFromMaps(*main_conf,configurationId,"jobscript_header");
    368518  if(headerMap!=NULL){
    369519    // Use the header file if defined in the HPC section of the main.cfg file
     
    383533  }else
    384534    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);
    386536  if(hpc_opts!=NULL){
    387537    map* hpc_opts_content=hpc_opts->content;
    388538    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);
    390541      hpc_opts_content=hpc_opts_content->next;
    391542    }
     
    396547    fprintf(scriptFile,"#SBATCH --export=MODULES=%s\n",mods->value);
    397548
    398   map* bodyMap=getMapFromMaps(*main_conf,serviceType,"body");
     549  map* bodyMap=getMapFromMaps(*main_conf,configurationId,"jobscript_body");
    399550  if(bodyMap!=NULL){
    400551    // Use the header file if defined in the HPC section of the main.cfg file
     
    415566    fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service BODY *** ###\n\n");
    416567
    417  
    418568  map* sp=getMap(s->content,"serviceProvider");
    419569 
     
    433583  fflush(scriptFile);
    434584  fclose(scriptFile);
    435  
    436585  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    437586  invokeCallback(m,inputs,NULL,3,1);
     
    442591  invokeCallback(m,inputs,NULL,4,0);
    443592  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    444   targetPathMap=getMapFromMaps(*main_conf,serviceType,"executePath");
     593  targetPathMap=getMapFromMaps(*main_conf,configurationId,"remote_work_path");
    445594  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);
    447604    return SERVICE_FAILED;
    448605  }
     
    453610  SSHCON *test=ssh_connect(*main_conf);
    454611  ssh_copy(*main_conf,scriptPath,targetPath,ssh_get_cnt(*main_conf));
    455  
     612  unlink(scriptPath);
     613  free(scriptPath);
    456614  // 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");
    458617  char *command=(char*)malloc((strlen(targetPath)+strlen(targetPathMap->value)+strlen(subStr->value)+strlen(uuid->value)+137)*sizeof(char));
    459618  sprintf(command,"sbatch %s 2> %s/error_%s.log | sed \"s:%s::g\"",targetPath,targetPathMap->value,uuid->value,subStr->value);
     
    489648    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    490649    fflush(stderr);
    491     invokeCallback(m,NULL,NULL,7,1);
     650    invokeCallback(m,NULL,NULL,7,0);
    492651    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    493652    fflush(stderr);
     
    497656    free(targetPath);
    498657    ssh_close(*main_conf);
    499     sleep(120);
     658    sleep(1);
    500659    return -1;
    501660  }
     
    507666  fflush(stderr);
    508667  free(command);
     668  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     669  fflush(stderr);
    509670
    510671  struct sockaddr_un addr;
     672  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     673  fflush(stderr);
    511674  memset(&addr, 0, sizeof(addr));
     675  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     676  fflush(stderr);
    512677  addr.sun_family = AF_UNIX;
     678  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     679  fflush(stderr);
    513680  int rc, cl, fd = socket(AF_UNIX, SOCK_STREAM, 0);
     681  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     682  fflush(stderr);
    514683  char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+20));
     684  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     685  fflush(stderr);
    515686  sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,uuid->value);
     687  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     688  fflush(stderr);
    516689  strncpy(addr.sun_path, sname, sizeof(addr.sun_path)-1);
     690  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     691  fflush(stderr);
    517692 
    518693  if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
    519694    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);
    520703    sleep(120);
    521704    return -1;
    522705  }
     706  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     707  fflush(stderr);
    523708  if (listen(fd, 5) == -1) {
    524709    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);
    525717    return -1;
    526718  }
     719  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     720  fflush(stderr);
    527721  if ( (cl = accept(fd, NULL, NULL)) == -1) {
    528722    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);
    529730    return -1;
    530731  }else{
     732    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     733    fflush(stderr);
    531734    int hasPassed=-1;
    532735    char buf[11];
     
    536739        sleep(1);
    537740        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);
    539748        return -1;
    540749      }else{
    541750        if(rc<0){
    542751          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);
    544759          return -1;
    545760        }
    546761      }
    547762      hasPassed=1;
     763      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     764      fflush(stderr);
    548765      res=atoi(buf);
     766      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     767      fflush(stderr);
    549768      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 
    552778      if(res==3){
    553779        fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     
    573799                setMapInMaps(*main_conf,"lenv","message",tmpStr);
    574800                free(tmpStr);
     801                invokeCallback(m,NULL,NULL,7,0);
    575802                return SERVICE_FAILED;
    576803              }
     
    587814              if(ssh_fetch(*main_conf,targetPath,generatedFile->value,ssh_get_cnt(m))==0){
    588815                maps* tmp=getMaps(*real_outputs,input->name);
     816                char serviceName[9];
    589817                freeMap(&tmp->content);
    590818                free(tmp->content);
     
    592820                maps* output=getMaps(*real_outputs,input->name);
    593821                setMapInMaps(output->child,"download_link","generated_file",targetPath);
     822                setMapInMaps(output->child,"download_link","storage",targetPath);
    594823                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");
    595827                setMapInMaps(output->child,"wms_link","generated_file",targetPath);
     828                setMapInMaps(output->child,"wms_link","storage",targetPath);
    596829                setMapInMaps(output->child,"wms_link","useMapserver","true");
    597830                setMapInMaps(output->child,"wms_link","msOgc","WMS");
    598831                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;
    601852              }
    602853              free(targetPath);
     
    605856          input=input->next;
    606857        }
     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);
    607889      }
    608890      //free(buf);
     
    611893      perror("Failed to read");
    612894      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);
    613902      sleep(120);
    614903      return SERVICE_FAILED;
     
    622911  return res;
    623912}
    624 
    625    
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c

    r851 r854  
    138138    exit(-1);
    139139  }
     140  int finalProto=-1;
    140141  map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion");
    141142  map *dataPath=getMapFromMaps(m,"main","dataPath");
     
    147148  map* protoMap=getMap(tmpI->content,"msOgc");
    148149  map* versionMap=getMap(tmpI->content,"msOgcVersion");
    149   char options[3][5][25]={
     150  char options[4][5][25]={
    150151    {"WMS","1.3.0","GetMap","layers=%s","wms_extent"},
    151152    {"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"}
    154155  };
     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  }
    155165  int proto=0;
    156166  if(rformat==NULL){
     
    194204
    195205  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");
    197206 
    198207  if(proto>0){
     208    if(proto==2)
     209      finalProto=1;
    199210    sprintf(webService_url,
    200211            "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
     
    248259  }
    249260  addToMap(tmpI->content,"Reference",webService_url);
    250 
     261  memset(layers,0,128);
     262  sprintf(layers,options[proto][3],tmpI->name);
    251263  protoVersion=options[proto][1];
    252264  extent=getMap(tmpI->content,options[proto][4]);
    253265  memset(webService_url,0,strlen(webService_url));
    254266  if(proto>0){
     267    if(proto==2)
     268      finalProto=1;
    255269    sprintf(webService_url,
    256270            "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
     
    292306    addToMap(tmpI->content,"ref_wms_link",webService_url);
    293307  }
     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  }
    294331  if(hasCRS==0){
    295332    freeMap(&crs);
     
    299336  free(rformat);
    300337  free(webService_url);
    301   dumpMaps(tmpI);
    302338}
    303339
     
    492528  /**
    493529   * Try to load the file as ZIP
    494    */
    495 
     530   *
    496531  OGRDataSourceH poDS1 = NULL;
    497532  OGRSFDriverH *poDriver1 = NULL;
     
    534569    fprintf(stderr,"Unable to access the DataSource as ZIP File\n");
    535570    setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
     571    fprintf(stderr,"Remove ZIP File!\n");
     572    unlink(odsName);
    536573    //OGR_DS_Destroy(poDS1);
    537574  }else{
     
    594631    }
    595632    OGR_DS_Destroy(poDS1);
    596   }
     633    }
    597634  free(sdsName);
    598   free(dsName);
     635  free(dsName);*/
    599636 
    600637  OGRDataSourceH poDS = NULL;
     
    649686    myLayer->status = MS_ON;
    650687    msConnectLayer(myLayer,MS_OGR,pszDataSource);
     688
     689    addIntToMap(output->content,"nb_features",OGR_L_GetFeatureCount(poLayer,1));
    651690
    652691    /**
     
    811850   */
    812851  GDALAllRegister();
    813   hDataset = GDALOpen( pszFilename, GA_ReadOnly );
     852  hDataset = GDALOpen( pszFilename, GA_Update );
    814853  if( hDataset == NULL ){
    815854#ifdef DEBUGMS
     
    866905  m->width=GDALGetRasterXSize( hDataset );
    867906  m->height=GDALGetRasterYSize( hDataset );
     907  addIntToMap(output->content,"nb_pixels",GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset ));
    868908 
    869909  /**
     
    880920    setSrsInformations(output,m,myLayer,pszProjection);
    881921  }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    }
    883927  }
    884928
     
    905949      addToMap(output->content,"boundingbox",extent);
    906950    }
     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);
    907959  }
    908960
     
    919971  }
    920972  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");
    922977  else if(nBandsI>=2)
    923978    msLayerAddProcessing(myLayer,"BANDS=1,2");
    924979  else
    925980    msLayerAddProcessing(myLayer,"BANDS=1");
     981 
    926982
    927983  /**
     
    929985   */
    930986  char lBands[7];
    931   memset(&nBands,0,7);
    932987  char *nameBands=NULL;
    933988  for( iBand = 0; iBand < nBandsI; iBand++ ){
     989    memset(&lBands,0,7);
    934990    sprintf(lBands,"Band%d",iBand+1);   
    935991    if(nameBands==NULL){
     
    937993      sprintf(nameBands,"%s",lBands);
    938994    }else{
    939       if(iBand<4){
     995      /*if(iBand<4)*/{
    940996        char *tmpS=zStrdup(nameBands);
    941997        nameBands=(char*)realloc(nameBands,(strlen(tmpS)+strlen(lBands)+2)*sizeof(char));
     
    9541010   */
    9551011  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;
    9601013    hBand = GDALGetRasterBand( hDataset, iBand+1 );
    9611014
    9621015    CPLErrorReset();
    963     GDALComputeRasterMinMax( hBand, FALSE, adfCMinMax );
     1016    GDALComputeRasterStatistics( hBand, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev, NULL,NULL);
    9641017    char tmpN[21];
    9651018    sprintf(tmpN,"Band%d",iBand+1);
    9661019    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));
    9691023      char tmpI[31];     
    9701024      sprintf(tmpI,"%s_interval",tmpN);
    9711025      msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm);
    972 
     1026      if(pdfMax>255)
     1027        msLayerAddProcessing(myLayer,tmpMp);
    9731028      map* test=getMap(output->content,"msClassify");
    9741029      if(test!=NULL && strncasecmp(test->value,"true",4)==0){
     
    9901045         
    9911046        if(nBandsI==1){
    992           double delta=adfCMinMax[1]-adfCMinMax[0];
     1047          double delta=pdfMax-pdfMin;
    9931048          double interval=delta/10;
    994           double cstep=adfCMinMax[0];
     1049          double cstep=pdfMin;
    9951050          for(i=0;i<10;i++){
    9961051            /**
     
    10361091         
    10371092          char tmpMm[100];
    1038           sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
     1093          sprintf(tmpMm,"%.3f %.3f",pdfMin,pdfMax);
    10391094         
    10401095        }
     
    10461101          myLayer->offsite.blue=0;
    10471102        }
    1048         msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");
    10491103      }
    10501104    }
     
    10561110
    10571111  }
     1112  msLayerAddProcessing(myLayer,"RESAMPLE=BILINEAR");
    10581113
    10591114  m->layerorder[m->numlayers] = m->numlayers;
     
    10811136      ext="json";
    10821137
    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  }
    11031161
    11041162  /*
     
    11741232#endif
    11751233
     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
    11761245  /*
    11771246   * Set default projection to EPSG:4326
     
    12621331  msSaveMap(myMap,mapPath);
    12631332  free(mapPath);
     1333  //msFreeSymbolSet(&myMap->symbolset);
     1334  msFreeMap(myMap);
     1335  //msFree(myMap);
    12641336  msGDALCleanup();
    1265   msFreeMap(myMap);
    12661337}
    12671338
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal_python.c

    r790 r854  
    5757 * from the ZOO-Kernel Python environment:
    5858 *  - "_" corresponding to the PythonTranslate function
    59  *  - "updte_status" corresponding to the PythonUpdateStatus function
     59 *  - "update_status" corresponding to the PythonUpdateStatus function
    6060 * @see PythonTranslate, PythonUpdateStatus
    6161 */
     
    163163    fprintf(stderr,"PYTHON SUPPORT (%i)\n",strlen(tmp->value));
    164164#endif
    165     python_path=(char*)malloc((strlen(tmp->value))*sizeof(char));
     165    python_path=(char*)malloc((strlen(tmp->value)+1)*sizeof(char));
    166166    sprintf(python_path,"%s",tmp->value);
    167167    hasToClean=1;
     
    281281        dumpMaps(*real_outputs);
    282282#endif
    283       }else{     
     283      }else{
    284284        PythonZooReport(m,tmp->value,0);
    285285        res=-1;
     
    323323  char *pbt=NULL;
    324324  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));
    326326    sprintf(pbt,"TRACE: %s",PyString_AsString(trace));
    327327  }
    328328  else
    329329    fprintf(stderr,"EMPTY TRACE ?");
    330  
     330
    331331  trace=NULL;
    332332 
  • branches/prototype-v0/zoo-project/zoo-kernel/sql/schema.sql

    r839 r854  
    3131-- Create a dedicated schema to store all tables
    3232-- 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;
    3535--------------------------------------------------------------------------------
    3636-- Services table
     
    4545       creation_time timestamp with time zone default now(),
    4646       end_time timestamp with time zone default NULL,
    47        -- queue_duration ,
    48        -- run_duration ,
    4947       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
    5349);
    5450--------------------------------------------------------------------------------
     
    5652-- Used to store the response provided by a services running asynchronously
    5753create table responses (
    58        uuid text references process(uuid) ON DELETE CASCADE,
     54       uuid text references services(uuid) ON DELETE CASCADE,
    5955       content text,
    6056       creation_time timestamp with time zone default now()
  • branches/prototype-v0/zoo-project/zoo-kernel/sql/zoo_collectiondb.sql

    r839 r854  
    314314        abstract,
    315315        (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)))  as service_provider,
     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,
    317317        availability
    318318        FROM CollectionDB.ows_Process
  • branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c

    r851 r854  
    7070  int i=0;
    7171  maps* cconf=getMaps(conf,key);
    72   if(cconf==NULL)
     72  if(cconf==NULL){
     73    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    7374    return "-1";
     75  }
    7476  int len=0;
    7577  for(i=0;i<6;i++){
     
    119121int _init_sql(maps* conf,const char* key){
    120122  char* sqlInitString=_createInitString(conf,key);
     123  fprintf(stderr,"Try to connect to: %s %s !\n",key,sqlInitString);
     124  fflush(stderr); 
    121125  if(strncmp(sqlInitString,"-1",2)==0)
    122126    return -1;
     127  fprintf(stderr,"Try to connect to: %s !\n",key);
     128  fflush(stderr); 
    123129  OGRSFDriver *poDriver = NULL;
    124130  OGRRegisterAll();
     
    195201 */
    196202void close_sql(maps* conf,int cid){
    197   if( zoo_ResultSet != NULL )
     203  if( zoo_ResultSet != NULL ){
    198204    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){
    200208#if GDAL_VERSION_MAJOR >= 2
    201209    GDALClose(zoo_DS[cid]);
     
    223231 */
    224232OGRLayer *fetchSql(maps* conf,int cid,const char* sqlQuery){
    225   if(zoo_DS[cid]==NULL)
     233  if(zoo_DS==NULL || zoo_DS[cid]==NULL)
    226234    return NULL;
    227235  OGRLayer *res=NULL;
     
    250258int execSql(maps* conf,int cid,const char* sqlQuery){
    251259  int res=-1;
     260  if(zoo_DS == NULL || zoo_DS[cid]==NULL)
     261    return -1;
    252262  zoo_ResultSet = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL);
    253263  if( zoo_ResultSet != NULL ){
     
    371381  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char));
    372382  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){
    380384    init_sql(conf);
    381385    zoo_ds_nb++;
    382386  }
    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");
    386392  return 0;
    387393}
     
    439445  int zoo_ds_nb=getCurrentId(conf);
    440446  map *schema=getMapFromMaps(conf,"database","schema");
     447  OGRFeature  *poFeature = NULL;
     448  const char *tmp1=NULL;
     449  int hasRes=-1;
    441450  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char));
    442451  sprintf(sqlQuery,
     
    454463  }
    455464  execSql(conf,zoo_ds_nb-1,sqlQuery);
    456   OGRFeature  *poFeature = NULL;
    457   const char *tmp1;
    458   int hasRes=-1;
    459465  if(zoo_ResultSet!=NULL){
    460466      while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
     
    472478  if(hasRes<0)
    473479    tmp1=NULL;
    474   else
    475     cleanUpResultSet(conf,zoo_ds_nb-1);
     480  cleanUpResultSet(conf,zoo_ds_nb-1);
    476481  free(sqlQuery);
    477482  return (char*)tmp1;
     
    534539  //close_sql(conf,zoo_ds_nb-1);
    535540  free(sqlQuery);
    536   end_sql();
     541  //end_sql();
    537542}
    538543
     
    555560    zoo_ds_nb++;
    556561  }
    557   execSql(conf,zoo_ds_nb-1,sqlQuery);
     562  if(execSql(conf,zoo_ds_nb-1,sqlQuery)<0)
     563    return NULL;
    558564  OGRFeature  *poFeature = NULL;
    559565  const char *tmp1;
  • branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c

    r851 r854  
    2929
    3030#include "sshapi.h"
     31#include "service_internal.h"
    3132
    3233SSHCON *sessions[MAX_PARALLEL_SSH_CON];
     
    9495  int port=22;
    9596
    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  }
    107124
    108125#ifdef WIN32
     
    117134#endif
    118135
    119   // TODO: fetch ip address for the hostname
    120136  if (hpc_host != NULL) {
    121     hostaddr = inet_addr(hpc_host->value);
     137    hostaddr = inet_addr(ip);
    122138  } else {
    123139    setMapInMaps(conf,"lenv","message","No host parameter found in your main.cfg file!\n");
     
    235251int ssh_get_cnt(maps* conf){
    236252  int result=0;
    237   map* myMap=getMapFromMaps(conf,"lenv","cnt_session");
     253  map* myMap=getMapFromMaps(conf,"lenv","nb_sessions");
    238254  if(myMap!=NULL){
    239255    result=atoi(myMap->value);
     
    323339    return false;
    324340  }
    325 
     341 
    326342  do {
    327343    sessions[cnt]->sftp_session = libssh2_sftp_init(sessions[cnt]->session);
     
    391407 * @param targetPath const char* defining the path for accessing the file on the
    392408 * remote host
    393  * @return true in case of success, false if failure occured
     409 * @return 0 in case of success, -1 if failure occured
    394410 */
    395411int ssh_fetch(maps* conf,const char* localPath,const char* targetPath,int cnt){
     
    414430     
    415431      fprintf(stderr, "Unable to init SFTP session\n");
    416       return false;
     432      return -1;
    417433    }
    418434  } 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 {
    419452    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);
    473486  duration = (int)(time(NULL)-start);
    474487  fclose(local);
    475488  libssh2_sftp_close_handle(sftp_handle);
    476 
    477489  libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
    478490  return 0;
     
    491503  int exitcode;
    492504  char *exitsignal=(char *)"none";
     505  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     506  fflush(stderr);
    493507  while( (channel = libssh2_channel_open_session(sessions[cnt]->session)) == NULL &&
    494508         libssh2_session_last_error(sessions[cnt]->session,NULL,NULL,0) == LIBSSH2_ERROR_EAGAIN ) {
     509    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     510    fflush(stderr);
    495511      waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
    496512  }
     513  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     514  fflush(stderr);
    497515  if( channel == NULL ){
    498516    fprintf(stderr,"Error\n");
    499     return 1;
    500   }
     517    return -1;
     518  }
     519  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     520  fflush(stderr);
    501521  while( (rc = libssh2_channel_exec(channel, command)) == LIBSSH2_ERROR_EAGAIN ) {
     522    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     523    fflush(stderr);
    502524    waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
    503525  }
     526  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     527  fflush(stderr);
    504528  if( rc != 0 ) {
    505529    fprintf(stderr,"Error\n");
    506530    return -1;
    507531  }
     532  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     533  fflush(stderr);
    508534
    509535  map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
     
    513539  FILE* logFile=fopen(logPath,"wb");
    514540  free(logPath);
     541  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     542  fflush(stderr);
    515543  while(true){
    516544    int rc;
     
    535563      break;
    536564  }
     565  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     566  fflush(stderr);
    537567  fclose(logFile);
     568  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     569  fflush(stderr);
    538570  exitcode = 127;
     571  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     572  fflush(stderr);
    539573  while( (rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN )
    540574    waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
     575  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     576  fflush(stderr);
    541577 
    542578  if( rc == 0 ) {
     
    545581                                    NULL, NULL, NULL, NULL, NULL);
    546582  }
     583  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     584  fflush(stderr);
    547585 
    548586  if (exitsignal)
     
    550588  else
    551589    fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
     590  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     591  fflush(stderr);
    552592 
    553593  libssh2_channel_free(channel);
     
    643683  }
    644684#ifdef DEBUG
    645   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     685  fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__);
    646686  fflush(stderr);
    647687  dumpMaps(getMaps(*conf,"uploadQueue"));
    648   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     688  fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__);
    649689  fflush(stderr);
    650690#endif
     
    660700        getMapArray(queueMaps->content,"targetPath",i)
    661701      };
    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      }/**/
    664719    }   
    665720  }
  • branches/prototype-v0/zoo-project/zoo-kernel/sshapi.h

    r839 r854  
    5757#include <sys/time.h>
    5858#endif
    59  
     59
     60#include <netdb.h>
    6061#include <arpa/inet.h>
    6162#include <sys/types.h>
  • branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c

    r851 r854  
    211211  ret.agent=strdup(lpszAgent);
    212212  ret.nb=0;
     213  ret.waitingRequests[ret.nb] = NULL;
    213214  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;
    214225  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 */
     240char* 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";
    215262}
    216263
     
    282329    int i;
    283330    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){
    285332        while (token != NULL){
    286333          int length=strlen(token)+6;
     
    297344          }
    298345          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);
    303352          }
    304353          free(tmp1);
     
    321370void InternetCloseHandle(HINTERNET* handle0){
    322371  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    }
    361414  }
    362415}
     
    377430  struct MemoryStruct header;
    378431
     432  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     433  fflush(stderr);
    379434  hInternet->ihandle[hInternet->nb].handle=curl_easy_init( );
     435  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     436  fflush(stderr);
    380437  hInternet->ihandle[hInternet->nb].hasCacheFile=0;
     438  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     439  fflush(stderr);
    381440  hInternet->ihandle[hInternet->nb].nDataAlloc = 0;
     441  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     442  fflush(stderr);
    382443  hInternet->ihandle[hInternet->nb].url = NULL;
     444  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     445  fflush(stderr);
    383446  hInternet->ihandle[hInternet->nb].mimeType = NULL;
     447  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     448  fflush(stderr);
    384449  hInternet->ihandle[hInternet->nb].cookie = NULL;
     450  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     451  fflush(stderr);
    385452  hInternet->ihandle[hInternet->nb].nDataLen = 0;
     453  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     454  fflush(stderr);
    386455  hInternet->ihandle[hInternet->nb].id = hInternet->nb;
     456  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     457  fflush(stderr);
    387458  hInternet->ihandle[hInternet->nb].nDataAlloc = 0;
     459  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     460  fflush(stderr);
    388461  hInternet->ihandle[hInternet->nb].pabyData = NULL;
     462  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     463  fflush(stderr);
    389464  hInternet->ihandle[hInternet->nb].post = NULL;
     465  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     466  fflush(stderr);
    390467 
    391468  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIEFILE, "ALL");
     469  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     470  fflush(stderr);
    392471#ifndef TIGER
    393472  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_COOKIELIST, "ALL");
    394473#endif
    395474  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_USERAGENT, hInternet->agent);
     475  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     476  fflush(stderr);
    396477 
    397478  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_FOLLOWLOCATION,1);
     479  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     480  fflush(stderr);
    398481  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_MAXREDIRS,3);
     482  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     483  fflush(stderr);
    399484 
    400485  header.memory=NULL;
     
    402487
    403488  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_HEADERFUNCTION, header_write_data);
     489  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     490  fflush(stderr);
    404491  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle, CURLOPT_WRITEHEADER, (void *)&header);
     492  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     493  fflush(stderr);
    405494
    406495#ifdef MSG_LAF_VERBOSE
     
    431520      break;
    432521    }
     522  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     523  fflush(stderr);
    433524#ifdef ULINET_DEBUG
    434525  fprintf(stderr,"URL (%s)\nBODY (%s)\n",lpszUrl,lpszHeaders);
     
    448539    curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_POSTFIELDSIZE,(long)dwHeadersLength);
    449540  }
     541  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     542  fflush(stderr);
    450543  if(hInternet->ihandle[hInternet->nb].header!=NULL)
    451544    curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_HTTPHEADER,hInternet->ihandle[hInternet->nb].header);
    452545
     546  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     547  fflush(stderr);
    453548  curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_URL,lpszUrl);
    454549  hInternet->ihandle[hInternet->nb].url = zStrdup(lpszUrl);
     550  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     551  fflush(stderr);
    455552
    456553  curl_multi_add_handle(hInternet->handle,hInternet->ihandle[hInternet->nb].handle);
     554  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     555  fflush(stderr);
    457556 
    458557  hInternet->ihandle[hInternet->nb].header=NULL;
     558  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     559  fflush(stderr);
    459560  ++hInternet->nb;
     561  hInternet->ihandle[hInternet->nb].header=NULL;
    460562
    461563#ifdef ULINET_DEBUG
     
    481583  for(i=0;i<hInternet->nb;i++){
    482584    char *tmp;
     585    fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i);
    483586    curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_CONTENT_TYPE,&tmp);
     587    fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i);
    484588    if(tmp!=NULL)
    485589      hInternet->ihandle[i].mimeType=strdup(tmp);
     590    fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i);
    486591    curl_easy_getinfo(hInternet->ihandle[i].handle,CURLINFO_RESPONSE_CODE,&hInternet->ihandle[i].code);
     592    fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i);
    487593    curl_multi_remove_handle(hInternet->handle, hInternet->ihandle[i].handle);
     594    fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i);
    488595    curl_easy_cleanup(hInternet->ihandle[i].handle);
     596    fprintf(stderr," *** %s %d %d \n",__FILE__,__LINE__,i);
    489597    //fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,hInternet->ihandle[i].mimeType);
    490598    //fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,hInternet->ihandle[i].pabyData);
  • branches/prototype-v0/zoo-project/zoo-kernel/ulinet.h

    r839 r854  
    128128  HINTERNET InternetOpen(char*,int,char*,char*,int);
    129129
     130  char* getProvenance(maps*,const char*);
    130131  int isProtectedHost(const char*,const char*);
    131132  int AddMissingHeaderEntry(_HINTERNET*,const char*,const char*);
  • branches/prototype-v0/zoo-project/zoo-kernel/zoo_loader.c

    r790 r854  
    8686  fflush(stderr);
    8787#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);
    8894 
    8995  char *strQuery=NULL;
  • branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c

    r851 r854  
    107107#include <dirent.h>
    108108#include <signal.h>
     109#include <execinfo.h>
    109110#include <unistd.h>
    110111#ifndef WIN32
     
    122123#include <time.h>
    123124#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>
    124135
    125136#ifndef WIN32
     
    385396sig_handler (int sig)
    386397{
     398 
    387399  char tmp[100];
    388400  const char *ssig;
     
    413425  sprintf (tmp,
    414426           _
    415            ("ZOO Kernel failed to process your request, receiving signal %d = %s"),
     427           ("ZOO Kernel failed to process your request, receiving signal %d = %s "),
    416428           sig, ssig);
    417429  errorException (NULL, tmp, "InternalError", NULL);
     
    9901002#ifdef ETC_DIR
    9911003#ifndef WIN32
    992     getcwd (ntmp, 1024);
     1004  getcwd (ntmp, 1024);
    9931005#else
    994     _getcwd (ntmp, 1024);
     1006  _getcwd (ntmp, 1024);
    9951007#endif
    9961008#endif
     
    11841196  fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
    11851197  fflush(stderr);
    1186   dumpMap(r_inputs);
     1198  //dumpMap(r_inputs);
    11871199  fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
    11881200  fflush(stderr);
     
    12941306  }
    12951307
     1308  dumpMap(request_inputs);
     1309
    12961310  if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0)
    12971311    {
     
    13481362#ifdef META_DB
    13491363      fetchServicesFromDb(zooRegistry,m,doc,n,printGetCapabilitiesForProcess,1);
    1350       fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
    13511364      close_sql(m,0);
    13521365#endif     
     
    14301443            r_inputs = NULL;
    14311444            r_inputs = getMap (request_inputs, "version");
     1445            fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
     1446            fflush(stderr);
    14321447            xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
    14331448                                          root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1);
     
    15191534                              free (REQUEST);
    15201535                              closedir (dirp);
    1521                               xmlFreeDoc (doc);
     1536                              //xmlFreeDoc (doc);
    15221537                              xmlCleanupParser ();
    15231538                              zooXmlCleanupNs ();
     
    15501565                          addToMap (request_inputs, "metapath", tmpMap->value);
    15511566                        map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
     1567                        /**
     1568                         * No support for dot in service name stored in metadb!?
    15521569#ifdef META_DB
    1553                         service* s2=extractServiceFromDb(m,tmpMapI->name,0);
     1570                        service* s2=extractServiceFromDb(m,tmpMapI->value,0);
    15541571                        if(s2==NULL){
    15551572#endif
     1573                        */
    15561574                          s1 = (service *) malloc (SERVICE_SIZE);
    15571575                          t = readServiceFile (m, buff1, &s1, tmpMapI->value);
     
    15851603                              free (s1);
    15861604                              closedir (dirp);
    1587                               xmlFreeDoc (doc);
     1605                              //xmlFreeDoc (doc);
    15881606                              xmlCleanupParser ();
    15891607                              zooXmlCleanupNs ();
     
    16041622                          hasVal = 1;
    16051623                          setMapInMaps (m, "lenv", "level", "0");
     1624                          /*
    16061625#ifdef META_DB
    16071626                        }
    16081627#endif
     1628                          */
    16091629                      }
    16101630                    else
     
    16881708                                      free (REQUEST);
    16891709                                      closedir (dirp);
    1690                                       xmlFreeDoc (doc);
     1710                                      //xmlFreeDoc (doc);
    16911711                                      xmlCleanupParser ();
    16921712                                      zooXmlCleanupNs ();
     
    17361756                        free (REQUEST);
    17371757                        closedir (dirp);
    1738                         xmlFreeDoc (doc);
     1758                        //xmlFreeDoc (doc);
    17391759                        xmlCleanupParser ();
    17401760                        zooXmlCleanupNs ();
     
    18431863  }
    18441864  s1 = NULL;
    1845   if(postRequest!=NULL)
    1846     setMapInMaps (m, "lenv", "xrequest", postRequest->value);
    1847  
     1865 
    18481866  r_inputs = getMap (request_inputs, "Identifier");
    18491867  map* import = getMapFromMaps (m, IMPORTSERVICE, r_inputs->value);
     
    18801898  fprintf(stderr,"CONNECTING METADB!\n");
    18811899  //FAILED CONNECTING DB
    1882   if(getMapFromMaps(m,"lenv","dbIssue")!=NULL){
     1900  if(getMapFromMaps(m,"lenv","dbIssue")!=NULL || metadb_id<0){
    18831901    fprintf(stderr,"ERROR CONNECTING METADB\n");
    18841902  }
    1885   s1=extractServiceFromDb(m,r_inputs->value,0);
     1903  if(metadb_id>=0)
     1904    s1=extractServiceFromDb(m,r_inputs->value,0);
    18861905  //close_sql(m,0);
    18871906  if(s1!=NULL){
     
    21812200    {
    21822201      int hasValidCookie = -1;
    2183       char *tcook = zStrdup (cgiCookie);
     2202      char *tcook = originalCookie = zStrdup (cgiCookie);
     2203      //fprintf(stderr,">>>>> %s %d %s\n",__FILE__,__LINE__,tcook );
    21842204      char *tmp = NULL;
    21852205      map *testing = getMapFromMaps (m, "main", "cookiePrefix");
     2206      parseCookie(&m,originalCookie);
    21862207      if (testing == NULL)
    21872208        {
     
    21972218        {
    21982219          char *token, *saveptr;
    2199           token = strtok_r (cgiCookie, ";", &saveptr);
     2220          token = strtok_r (tcook, ";", &saveptr);
    22002221          while (token != NULL)
    22012222            {
     
    22442265          if (istat == 0 && file_status.st_size > 0)
    22452266            {
     2267              int saved_stdout = dup (fileno (stdout));
     2268              dup2 (fileno (stderr), fileno (stdout));
    22462269              conf_read (session_file_path, tmpSess);
    22472270              addMapsToMaps (&m, tmpSess);
    22482271              freeMaps (&tmpSess);
     2272              fflush(stdout);
     2273              dup2 (saved_stdout, fileno (stdout));
     2274              close(saved_stdout);
    22492275            }
    22502276          free (tmpSess);
     
    22732299      char* tmpName=zStrdup(s);
    22742300      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);
    22772303      if(_tmpMaps->content == NULL)
    22782304        _tmpMaps->content = createMap (tmpName1,tmpValue);
     
    22852311  }
    22862312  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);
    22912313    addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]);
    2292     dumpMap(_tmpMaps->content);
    22932314  }
    22942315  addMapsToMaps (&m, _tmpMaps);
    22952316  freeMaps (&_tmpMaps);
    22962317  free (_tmpMaps);
    2297 
     2318  if(postRequest!=NULL)
     2319    setMapInMaps (m, "renv", "xrequest", postRequest->value);
     2320  //dumpMaps(m);
    22982321#ifdef WIN32
    22992322  char *cgiSidL = NULL;
     
    23342357                                  "ZooWPSClient\0",
    23352358                                  INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);*/
    2336 
    23372359      if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
    23382360        freeService (&s1);
     
    23502372        return -1;
    23512373      }
    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");
    23552374      loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
    23562375                         &request_output_real_format, &eres);
    2357 #ifdef RELY_ON_DB
     2376
    23582377#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);
    23602383      //end_sql();
    2361 #endif
    2362       close_sql(m,0);
    2363 #endif     
     2384      #endif*/
    23642385    }
    23652386  else
     
    23872408        }
    23882409#endif
     2410      //InternetCloseHandle (&hInternet);
    23892411      if (pid > 0)
    23902412        {
     
    24112433          setMapInMaps (m, "lenv", "async","true");
    24122434          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*/
    24132446
    24142447          // Create the filename for the result file (.res)
     
    25252558          invokeCallback(m,request_input_real_format,NULL,1,0);
    25262559          fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     2560          dumpMaps(request_output_real_format);
    25272561          if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
    25282562            freeService (&s1);
    25292563            free (s1);
     2564            fflush (stdout);
     2565            fflush (stderr);
    25302566            fclose (f0);
    25312567            fclose (f1);
    25322568            if(dumpBackFinalFile(m,fbkp,fbkp1)<0)
    25332569              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
    25342580            unlink (fbkpid);
    25352581            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
    25362590            freeMaps (&m);
    25372591            free (m);
     
    25442598            freeMaps (&tmpmaps);
    25452599            free (tmpmaps);
    2546             fflush (stdout);
    2547             fflush (stderr);
    25482600            return -1;
    25492601          }
     2602          dumpMaps(request_output_real_format);
    25502603          fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
    25512604          invokeCallback(m,request_input_real_format,NULL,1,1);
    25522605          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          }
    25572618        }
    25582619      else
     
    25732634  fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
    25742635#endif
     2636fflush(stdout);
     2637rewind(stdout);
    25752638  if (eres != -1)
    25762639    outputResponse (s1, request_input_real_format,
     
    25952658  if (((int) getpid ()) != cpid || cgiSid != NULL)
    25962659    {
    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
    25982663      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);
    26022665
    26032666      fclose (stdout);
     
    26192682        setMapInMaps(m,"lenv","fstate",wpsStatus[0]);
    26202683        break;
    2621       }     
     2684      }
    26222685#ifndef RELY_ON_DB
    26232686      dumpMapsToFile(bmap,fbkpres,1);
     
    26252688#else
    26262689      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);
    26302692#endif
    26312693      freeMaps(&bmap);
     
    26372699      cleanupCallbackThreads();
    26382700      close_sql(m,1);
    2639       //end_sql();
    26402701#endif
    26412702      close_sql(m,0);
    2642 #endif
    2643       unlink (flog);
     2703      end_sql();
     2704#endif
    26442705      free(fbkpid);
    26452706      free(fbkpres);
    2646       free (flog);           
    26472707      free (fbkp1);
    26482708      // free (tmps1); // tmps1 is stack memory and should not be freed
     
    26532713      fflush(stderr);
    26542714      fclose (stderr);
     2715      unlink (flog);
     2716      free (flog);
    26552717    }
    26562718  else{
  • branches/prototype-v0/zoo-project/zoo-services/gdal/dem/cgi-env/Gdal_Dem.zcfg

    r412 r854  
    4444    <Default />
    4545   </LiteralData>
     46  [co]
     47   Title = Creation Option
     48   Abstract = string representing options (NAME=VALUE)
     49   minOccurs = 0
     50   maxOccurs = 1
     51   <LiteralData>
     52    DataType = string
     53    <Default />
     54   </LiteralData>
    4655 </DataInputs>
    4756 <DataOutputs>
  • branches/prototype-v0/zoo-project/zoo-services/gdal/dem/service.c

    r444 r854  
    24862486      setMapInMaps(outputs,"Result","value",tmpMap->value);
    24872487    }
     2488   
     2489    tmpMap=getMapFromMaps(inputs,"co","value");
     2490    if(tmpMap!=NULL){
     2491      papszCreateOptions = CSLAddString( papszCreateOptions, tmpMap->value ); 
     2492      map* tmpMap1;
     2493      maps* tmpMaps=getMaps(inputs,"co");
     2494      if((tmpMap1=getMapFromMaps(inputs,"co","length"))!=NULL){
     2495        int i=1;
     2496        int length=atoi(tmpMap1->value);
     2497        for(;i<length;i++){
     2498          tmpMap=getMapArray(tmpMaps->content,"value",i);
     2499          papszCreateOptions = CSLAddString( papszCreateOptions, tmpMap->value );
     2500        }
     2501      }
     2502    }   
    24882503
    24892504    tmpMap=NULL;
  • branches/prototype-v0/zoo-project/zoo-services/utils/hpc/Makefile

    r839 r854  
    44
    55cgi-env/wps_hpc.zo: service.c
    6         g++ ${CFLAGS} -shared -fpic -o cgi-env/wps_hpc.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service ${ZRPATH}/zoo-kernel/sshapi.o ${HPCLDFLAGS}
     6        g++ ${CFLAGS} -shared -fpic -o cgi-env/wps_hpc.zo service.c service2.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service ${ZRPATH}/zoo-kernel/sshapi.o ${HPCLDFLAGS}
    77
    88install:
  • branches/prototype-v0/zoo-project/zoo-services/utils/hpc/service.c

    r839 r854  
    33 *
    44 * Copyright 2008-2009 GeoLabs SARL. All rights reserved.
     5 *
     6 * This work was supported by public funds received in the framework of GEOSUD,
     7 * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
     8 * by the French National Research Agency
    59 *
    610 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    2731#include "service_internal.h"
    2832#include "sshapi.h"
     33#include "server_internal.h"
    2934
    3035#include <sys/socket.h>
     
    5762    int fd,rc=NULL;
    5863    int i=0;
     64    map* usid=getMapFromMaps(conf,"lenv","usid");
     65    map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
     66
     67    char *flenv =
     68      (char *) malloc ((strlen (tmpPath->value) +
     69                        strlen (jobid->value) + 12) * sizeof (char));
     70    sprintf (flenv, "%s/%s_lenv.cfg", tmpPath->value, jobid->value);
     71    maps* m = (maps *) malloc (MAPS_SIZE);
     72    m->child=NULL;
     73    m->next=NULL;
     74    map* configId=NULL;
     75
     76   
     77    if(conf_read(flenv, m) != 2){
     78      configId=getMapFromMaps(m,"lenv","configId");
     79      setMapInMaps(conf,"lenv","configId",configId->value);
     80    }else{
     81      setMapInMaps(conf,"lenv","message",_("Unable to read the lenv section file of the requested jobid"));
     82      return SERVICE_FAILED;
     83    }
     84    unlink(flenv);
     85    free(flenv);
     86
    5987    SSHCON *test=ssh_connect(conf);
    6088    if(test==NULL){
    61       return SERVICE_FAILED;
    62     }
    63     map* usid=getMapFromMaps(conf,"lenv","usid");
    64     map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
     89      setMapInMaps(conf,"lenv","message",_("Unable to connect using through ssh."));
     90      return SERVICE_FAILED;
     91    }
     92
    6593    char *logPath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+12)*sizeof(char));
    6694    sprintf(logPath,"%s/exec_out_%s",tmpPath->value,jobid->value);
     
    80108    }
    81109    free(logPath);
    82     // Run scontrol to see if the service execution ends
     110    // Run scontrol to check if the service execution ended.
    83111    // Store all the informations returned by scontrol command as a cfg file to
    84112    // be parsed back by the ZOO-Kernel waiting for the execution of the remote
     
    86114    maps* tmpMaps=createMaps("henv");
    87115    char* command=(char*)malloc((126)*sizeof(char));
    88     //memset(&command,0,34);
    89     sprintf(command,"scontrol show jobid | grep -A24 %s",fcontent);   
     116    sprintf(command,"scontrol show jobid | grep -A24 JobId=%s",fcontent);   
    90117    if(ssh_exec(conf,command,ssh_get_cnt(conf))==0){
    91118      free(command);
    92119      setMapInMaps(conf,"lenv","message",_("Failed to run scontrol remotely"));
     120      // TODO: check status in db and if available continue in other case return SERVICE_FAILED
    93121      return SERVICE_FAILED;
    94122    }else{
     
    98126      int ts=stat(logPath, &f_status);
    99127      if(ts==0) {
    100         fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
    101         FILE* f=fopen(logPath,"rb");
    102         fread(fcontent,f_status.st_size,1,f);
    103         int fsize=f_status.st_size;
    104         fcontent[fsize]=0;
    105         fclose(f);
    106         free(logPath);
    107         fprintf(stderr,"%s \n",fcontent);
    108         char *token, *saveptr;
    109         token = strtok_r (fcontent, " ", &saveptr);
    110         while (token != NULL)
    111           {
    112             //fprintf(stderr,"%s %d\n",token,__LINE__);
    113             char *token1, *saveptr1;
    114             char *tmpToken=strdup(token);
    115             token1 = strtok_r (tmpToken, "=", &saveptr1);
    116             int isNext=-1;
    117             int hasTwoElements=0;
    118             char *name=NULL;
    119             while (token1 != NULL)
    120               {
    121                 if(hasTwoElements==0)
    122                   name=strdup(token1);
    123                 if(hasTwoElements<1)
    124                   hasTwoElements+=1;
    125                 else{
    126                   char *value=strdup(token1);
    127                   if(value[strlen(value)-1]=='\n')
    128                     value[strlen(value)-1]=0;
    129                   if(strlen(name)>0 && strlen(value)>0){
    130                     if(tmpMaps->content==NULL)
    131                       tmpMaps->content=createMap(name,value);
    132                     else
    133                       addToMap(tmpMaps->content,name,value);
    134                     free(value);
    135                   }
    136                   free(name);
    137                   hasTwoElements=0;
    138                 }
    139                 token1 = strtok_r (NULL, "=", &saveptr1);
    140               }
    141             free(tmpToken);
    142             token = strtok_r (NULL, " ", &saveptr);
    143           }
     128        fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
     129        FILE* f=fopen(logPath,"rb");
     130        fread(fcontent,f_status.st_size,1,f);
     131        int fsize=f_status.st_size;
     132        fcontent[fsize]=0;
     133        fclose(f);
     134        free(logPath);
     135        char *token, *saveptr;
     136        token = strtok_r (fcontent, " ", &saveptr);
     137        while (token != NULL)
     138          {
     139            char *token1, *saveptr1;
     140            char *tmpToken=strdup(token);
     141            token1 = strtok_r (tmpToken, "=", &saveptr1);
     142            int isNext=-1;
     143            int hasTwoElements=0;
     144            char *name=NULL;
     145            while (token1 != NULL)
     146              {
     147                if(hasTwoElements==0)
     148                  name=strdup(token1);
     149                if(hasTwoElements<1)
     150                  hasTwoElements+=1;
     151                else{
     152                  char *value=strdup(token1);
     153                  if(value[strlen(value)-1]=='\n')
     154                    value[strlen(value)-1]=0;
     155                  if(strlen(name)>0 && strlen(value)>0){
     156                    if(tmpMaps->content==NULL)
     157                      tmpMaps->content=createMap(name,value);
     158                    else
     159                      addToMap(tmpMaps->content,name,value);
     160                    free(value);
     161                  }
     162                  free(name);
     163                  hasTwoElements=0;
     164                }
     165                token1 = strtok_r (NULL, "=", &saveptr1);
     166              }
     167            free(tmpToken);
     168            token = strtok_r (NULL, " ", &saveptr);
     169          }
    144170      }else{
    145         setMapInMaps(conf,"lenv","message",_("Unable to access the downloaded execution log file"));
    146         return SERVICE_FAILED;
     171        setMapInMaps(conf,"lenv","message",_("Unable to access the downloaded execution log file"));
     172        return SERVICE_FAILED;
    147173      }
    148174    }
    149     logPath=(char*)malloc((strlen(tmpPath->value)+strlen(usid->value)+15)*sizeof(char));
    150     sprintf(logPath,"%s/exec_status_%s",tmpPath->value,usid->value);
    151     dumpMapsToFile(tmpMaps,logPath,0);
    152 
    153     char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+21));
    154     sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,jobid->value);
    155     if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    156       perror("socket error");
    157       setMapInMaps(conf,"lenv","message",_("Socket error"));
    158       return SERVICE_FAILED;
    159       }
    160     }
    161     logPath=(char*)malloc((strlen(tmpPath->value)+strlen(usid->value)+15)*sizeof(char));
    162     sprintf(logPath,"%s/exec_status_%s",tmpPath->value,usid->value);
     175    logPath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+15)*sizeof(char));
     176    sprintf(logPath,"%s/exec_status_%s",tmpPath->value,jobid->value);
    163177    dumpMapsToFile(tmpMaps,logPath,0);
    164178    char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+21));
     
    179193    if (write(fd, "3", 1) != rc) {
    180194      if (rc < 0) {
    181         perror("write error");
    182         setMapInMaps(conf,"lenv","message",_("Unable to announce the successful execution of the HPC service"));
    183         close(fd);
    184         return SERVICE_FAILED;
     195        perror("write error");
     196        setMapInMaps(conf,"lenv","message",_("Unable to announce the successful execution of the HPC service"));
     197        close(fd);
     198        return SERVICE_FAILED;
    185199      }
    186200    }
  • branches/prototype-v0/zoo-project/zoo-services/utils/status/Makefile

    r811 r854  
    44
    55cgi-env/wps_status.zo: service.c
    6         g++ ${CFLAGS} -shared -fpic -o cgi-env/wps_status.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service
     6        g++ -rdynamic ${CFLAGS} -shared -fpic -o cgi-env/wps_status.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service
    77
    88install:
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png