Ignore:
Timestamp:
Sep 14, 2010, 2:04:55 PM (14 years ago)
Author:
djay
Message:

Update of both ZOO Kernel and ZOO Services (ogr base-vect-ops ServicesProvider?).
All the ZCFG files have been corrected to remove all references to wrong metadata (Test = Demo) to avoid validation issues.
Main Memory leaks has been removed from this version.
Addition of the Simplify Service in the C ogr base-vect-ops ServicesProvider? and addition of the Python version (without Simplify).
Update of the configure.ac and Makefile.in to follow dicussions on the mailing list and ensure to use our cgic206 and not another one, path to our cgic library is now directly in the Makefile.in file.
Accept the "-" character to name inputs, to solve issue on GRASS 7 integration.
Addition of the extension keyword for ZCFG file to be able to store resulting outputs in a file name using the extension suffix.
This version after a testing period shall be considerate as 1.0.1 version of the ZOO Project.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/zoo_service_loader.c

    r5 r9  
    2727extern "C" int yylex();
    2828extern "C" int crlex();
     29
     30
    2931extern "C" {
    3032#include <libxml/tree.h>
     
    7173#include <stdarg.h>
    7274
    73 xmlNodeSet* extractFromDoc(xmlDocPtr doc,char* search){
     75xmlXPathObjectPtr extractFromDoc(xmlDocPtr doc,char* search){
    7476  xmlXPathContextPtr xpathCtx;
    7577  xmlXPathObjectPtr xpathObj;
    7678  xpathCtx = xmlXPathNewContext(doc);
    7779  xpathObj = xmlXPathEvalExpression(BAD_CAST search,xpathCtx);
    78   xmlXPathFreeContext(xpathCtx); 
    79   return xpathObj->nodesetval;
     80  xmlXPathFreeContext(xpathCtx);
     81  return xpathObj;
    8082}
    8183
    82 void sigint_handler(int sig){
     84void sig_handler(int sig){
     85  char tmp[100];
     86  char *ssig;
     87  switch(sig){
     88  case SIGSEGV:
     89    ssig="SIGSEGV";
     90    break;
     91  case SIGTERM:
     92    ssig="SIGTERM";
     93    break;
     94  case SIGINT:
     95    ssig="SIGINT";
     96    break;
     97  case SIGILL:
     98    ssig="SIGILL";
     99    break;
     100  case SIGFPE:
     101    ssig="SIGFPE";
     102    break;
     103  case SIGABRT:
     104    ssig="SIGABRT";
     105    break;
     106  default:
     107    ssig="UNKNOWN";
     108    break;
     109  }
     110  sprintf(tmp,"ZOO Kernel failed to process your request receiving signal %d = %s",sig,ssig);
     111  errorException(NULL, tmp, "InternalError");
    83112  fprintf(stderr,"Not this time!\n");
     113  exit(0);
    84114}
    85115
    86116int runRequest(map* request_inputs)
    87117{
     118
     119  (void) signal(SIGSEGV,sig_handler);
     120  (void) signal(SIGTERM,sig_handler);
     121  (void) signal(SIGINT,sig_handler);
     122  (void) signal(SIGILL,sig_handler);
     123  (void) signal(SIGFPE,sig_handler);
     124  (void) signal(SIGABRT,sig_handler);
    88125
    89126  map* r_inputs=NULL,*tmps=NULL;
     
    95132   * Parsing service specfic configuration file
    96133   */
    97   m=(maps*)malloc(MAPS_SIZE);
     134  m=(maps*)calloc(1,MAPS_SIZE);
     135  if(m == NULL){
     136    return errorException(m, "Unable to allocate memory.", "InternalError");
     137  }
    98138  char ntmp[1024];
    99139#ifndef WIN32
     
    102142  _getcwd(ntmp,1024);
    103143#endif
    104   char conf_file[1024];
    105   sprintf(conf_file,"%s/main.cfg",ntmp); 
     144  r_inputs=getMap(request_inputs,"metapath");
     145  if(r_inputs==NULL){
     146    if(request_inputs==NULL)
     147      request_inputs=createMap("metapath","");
     148    else
     149      addToMap(request_inputs,"metapath","");
     150#ifdef DEBUG
     151    fprintf(stderr,"ADD METAPATH\n");
     152    dumpMap(request_inputs);
     153#endif
     154    r_inputs=getMap(request_inputs,"metapath");
     155  }
     156  char conf_file[10240];
     157  snprintf(conf_file,10240,"%s/%s/main.cfg",ntmp,r_inputs->value);
    106158  conf_read(conf_file,m);
    107  
     159#ifdef DEBUG
     160  fprintf(stderr, "***** BEGIN MAPS\n");
     161  dumpMaps(m);
     162  fprintf(stderr, "***** END MAPS\n");
     163#endif
     164
    108165  /**
    109166   * Check for minimum inputs
    110167   */
    111168  r_inputs=getMap(request_inputs,"Request");
    112   if(r_inputs==NULLMAP){
    113   tmps=createMap("text","Parameter <request> was not specified");
    114     addToMap(tmps,"code","MissingParameterValue");
    115     printExceptionReportResponse(m,tmps);
     169  if(request_inputs==NULL || r_inputs==NULL){
     170    errorException(m, "Parameter <request> was not specified","MissingParameterValue");
     171    freeMaps(&m);
     172    free(m);
     173    freeMap(&request_inputs);
     174    free(request_inputs);
    116175    return 1;
    117176  }
    118   else
     177  else{
    119178    REQUEST=strdup(r_inputs->value);
    120   r_inputs=NULL;
    121   r_inputs=getMap(request_inputs,"Service");
    122   if(r_inputs==NULLMAP){
    123     tmps=createMap("text","Parameter <service> was not specified");
    124     addToMap(tmps,"code","MissingParameterValue");
    125     printExceptionReportResponse(m,tmps);
    126     return 1;
    127   }
    128   if(strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0){
    129     r_inputs=getMap(request_inputs,"Version");
    130     if(r_inputs==NULL){
    131       tmps=createMap("text","Parameter <version> was not specified");
    132       addToMap(tmps,"code","MissingParameterValue");
    133       printExceptionReportResponse(m,tmps);
     179    if(strncasecmp(r_inputs->value,"GetCapabilities",15)!=0
     180       && strncasecmp(r_inputs->value,"DescribeProcess",15)!=0
     181       && strncasecmp(r_inputs->value,"Execute",7)!=0){
     182      errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue");
     183      freeMaps(&m);
     184      free(m);
     185      freeMap(&request_inputs);
     186      free(request_inputs);
     187      free(REQUEST);
    134188      return 1;
    135189    }
    136190  }
    137 
    138   /**
    139    * Need to print std exception message here
    140    */
    141   char SP[1024];
    142   if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)){
    143     r_inputs=getMap(request_inputs,"ServiceProvider");
    144     if(r_inputs==NULLMAP){
    145       tmps=createMap("text","Parameter <serviceprovider> was not specified");
    146       addToMap(tmps,"code","MissingParameterValue");
    147       printExceptionReportResponse(m,tmps);   
     191  r_inputs=NULL;
     192  r_inputs=getMap(request_inputs,"Service");
     193  if(r_inputs==NULLMAP){
     194    errorException(m, "Parameter <service> was not specified","MissingParameterValue");
     195    freeMaps(&m);
     196    free(m);
     197    free(REQUEST);
     198    return 1;
     199  }
     200  if(strncasecmp(REQUEST,"GetCapabilities",15)!=0){
     201    r_inputs=getMap(request_inputs,"Version");
     202    if(r_inputs==NULL){
     203      errorException(m, "Parameter <version> was not specified","MissingParameterValue");
     204      freeMaps(&m);
     205      free(m);
     206      free(REQUEST);
    148207      return 1;
    149208    }
    150     else
    151       sprintf(SP,"%s",r_inputs->value);
    152     r_inputs=getMap(request_inputs,"MetaPath");
    153     if(r_inputs==NULLMAP){
    154       tmps=createMap("text","Parameter <metapath> was not specified");
    155       addToMap(tmps,"code","MissingParameterValue");
    156       printExceptionReportResponse(m,tmps);   
    157       return 1;
    158     }
    159     tmps=createMap("text","Parameter <unknown> was not specified");
    160     addToMap(tmps,"code","MissingParameterValue");
    161     printExceptionReportResponse(m,tmps);   
    162     return 1;
     209  }
     210
     211  r_inputs=getMap(request_inputs,"serviceprovider");
     212  if(r_inputs==NULL){
     213    addToMap(request_inputs,"serviceprovider","");
    163214  }
    164215
     
    182233  char tmps1[1024];
    183234
    184   if(strcmp(mtoupper(REQUEST),mtoupper("GetCapabilities"))==0){
     235  r_inputs=NULL;
     236  r_inputs=getMap(request_inputs,"metapath");
     237  if(r_inputs!=NULL)
     238    snprintf(conf_dir,1024,"%s/%s",ntmp,r_inputs->value);
     239  else
     240    snprintf(conf_dir,1024,"%s",ntmp);
     241
     242  if(strncasecmp(REQUEST,"GetCapabilities",15)==0){
    185243    int i=0;
    186244    struct dirent *dp;
    187     r_inputs=NULL;
    188     r_inputs=getMap(request_inputs,"metapath");
    189245#ifdef DEBUG
    190246    dumpMap(r_inputs);
    191247#endif
    192     sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value);
    193         DIR *dirp = opendir(conf_dir);
     248    DIR *dirp = opendir(conf_dir);
    194249    if(dirp==NULL){
    195       tmps=createMap("text","The specified path doesn't exist.");
    196       addToMap(tmps,"code","InvalidParameterValue");
    197       printExceptionReportResponse(m,tmps);   
    198       return -1;
     250      return errorException(m, "The specified path doesn't exist.","InvalidParameterValue");
    199251    }
    200252    xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
    201     doc->encoding = xmlCharStrdup ("UTF-8");
    202253    r_inputs=NULL;
    203254    r_inputs=getMap(request_inputs,"ServiceProvider");
    204     xmlNodePtr n = printGetCapabilitiesHeader(doc,r_inputs->value,m);
     255    xmlNodePtr n;
     256    //dumpMap(request_inputs);
     257    if(r_inputs!=NULL)
     258      n = printGetCapabilitiesHeader(doc,r_inputs->value,m);
     259    else
     260      n = printGetCapabilitiesHeader(doc,"",m);
    205261    /**
    206262     * Strange, here we need to close stdout to ensure that no uneeded
     
    211267    while ((dp = readdir(dirp)) != NULL)
    212268      if(strstr(dp->d_name,".zcfg")!=0){
    213         sprintf(tmps1,"%s/%s",conf_dir,dp->d_name);
    214         char *tmps=tmps1;
    215         s1=(service*)malloc(sizeof(service*));
    216         s[0]=(service*)malloc(sizeof(service*));
     269        memset(tmps1,0,1024);
     270        snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name);
     271        s1=(service*)calloc(1,SERVICE_SIZE);
     272        if(s1 == NULL){
     273          return errorException(m, "Unable to allocate memory.","InternalError");
     274        }
    217275#ifdef DEBUG
    218276        fprintf(stderr,"#################\n%s\n#################\n",tmps1);
     
    224282        fflush(stderr);
    225283#endif
    226         s[0]=s1;
    227284        printGetCapabilitiesForProcess(m,n,s1);
    228         //freeService(&s1);
    229         //s1=NULL;
     285        freeService(&s1);
     286        free(s1);
    230287        scount++;
    231288      }
     
    233290    fflush(stdout);
    234291    dup2(saved_stdout,fileno(stdout));
    235    
    236     printDocument(doc);
     292    printDocument(m,doc,getpid());
     293    freeMaps(&m);
     294    free(m);
     295    free(REQUEST);
     296    free(SERVICE_URL);
    237297    fflush(stdout);
    238     xmlFree(n);
    239298    return 0;
    240299  }
     
    243302    if(r_inputs==NULL
    244303       || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){
    245       if(r_inputs!=NULL && strlen(r_inputs->value)==0)
    246         tmps=createMap("text","Mandatory value for <identifier> was not specified");
    247       else
    248         tmps=createMap("text","Mandatory <identifier> was not specified");
    249       addToMap(tmps,"code","MissingParameterValue");
    250       printExceptionReportResponse(m,tmps);
    251       return 1;
     304      errorException(m, "Mandatory <identifier> was not specified","MissingParameterValue");
     305      freeMaps(&m);
     306      free(m);
     307      free(REQUEST);
     308      free(SERVICE_URL);
     309      return 0;
    252310    }
    253311
    254     r_inputs=getMap(request_inputs,"metapath");
    255     sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value);
    256312    struct dirent *dp;
    257313    DIR *dirp = opendir(conf_dir);
    258314    if(dirp==NULL){
    259       tmps=createMap("text","The specified metapath path doesn't exist.");
    260       addToMap(tmps,"code","InvalidParameterValue");
    261       printExceptionReportResponse(m,tmps);   
    262       return -1;
     315      errorException(m, "The specified path path doesn't exist.","InvalidParameterValue");
     316      freeMaps(&m);
     317      free(m);
     318      free(REQUEST);
     319      free(SERVICE_URL);
     320      return 0;
    263321    }
    264     if(strcmp(mtoupper(REQUEST),"DESCRIBEPROCESS")==0){
     322    if(strncasecmp(REQUEST,"DescribeProcess",15)==0){
    265323      /**
    266324       * Loop over Identifier list
    267325       */
    268326      xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
    269       doc->encoding = xmlCharStrdup ("UTF-8");
    270327      r_inputs=NULL;
    271328      r_inputs=getMap(request_inputs,"ServiceProvider");
     329
    272330      xmlNodePtr n;
    273331      if(r_inputs!=NULL)
    274332        n = printDescribeProcessHeader(doc,r_inputs->value,m);
     333      else
     334        n = printDescribeProcessHeader(doc,"",m);
    275335
    276336      r_inputs=getMap(request_inputs,"Identifier");
     
    286346      while(tmps){
    287347        memset(buff,0,256);
    288         sprintf(buff,"%s.zcfg",tmps);
     348        snprintf(buff,256,"%s.zcfg",tmps);
    289349        memset(buff1,0,1024);
    290350#ifdef DEBUG
     
    294354          if(strcmp(dp->d_name,buff)==0){
    295355            memset(buff1,0,1024);
    296             sprintf(buff1,"%s/%s",conf_dir,dp->d_name);
    297             s1=(service*)malloc(sizeof(service*));
    298             s[scount]=(service*)malloc(sizeof(service*));
    299 #ifdef DEBUG
    300             fprintf(stderr,"#################\n%s\n#################\n",tmps1);
     356            snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name);
     357            //s1=(service*)malloc(sizeof(service*));
     358            s1=(service*)calloc(1,SERVICE_SIZE);
     359            if(s1 == NULL){
     360              return errorException(m, "Unable to allocate memory.","InternalError");
     361            }
     362#ifdef DEBUG
     363            fprintf(stderr,"#################\n%s\n#################\n",buff1);
    301364#endif
    302365            t=getServiceFromFile(buff1,&s1);
    303             /*dumpService(s1);
    304               fflush(stdout);
    305               fflush(stderr);*/
    306             s[0]=s1;
    307             printDescribeProcessForProcess(m,n,s,1);
     366#ifdef DEBUG
     367            dumpService(s1);
     368#endif
     369            printDescribeProcessForProcess(m,n,s1,1);
     370            freeService(&s1);
     371            free(s1);
    308372            scount++;
    309373          }
     
    311375        tmps=strtok(NULL,",");
    312376      }
    313       (void)closedir(dirp);
     377      closedir(dirp);
    314378      fflush(stdout);
    315379      dup2(saved_stdout,fileno(stdout));
    316 
    317       printDocument(doc);
     380      printDocument(m,doc,getpid());
     381      freeMaps(&m);
     382      free(m);
     383      free(REQUEST);
     384      free(SERVICE_URL);
    318385      fflush(stdout);
    319386      //xmlFree(n);
    320387#ifndef LINUX_FREE_ISSUE
    321       free(s1);
     388      if(s1)
     389        free(s1);
    322390#endif
    323391      return 0;
    324392    }
    325393    else
    326       if(strcmp(mtoupper(REQUEST),"EXECUTE")!=0){
    327         tmps=createMap("text","Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.");
    328         addToMap(tmps,"code","InvalidParameterValue");
    329         printExceptionReportResponse(m,tmps);
     394      if(strncasecmp(REQUEST,"Execute",strlen(REQUEST))!=0){
     395        errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue");
    330396#ifdef DEBUG
    331397        fprintf(stderr,"No request found %s",REQUEST);
    332398#endif 
     399        closedir(dirp);
    333400        free(s);
    334401        return 0;
    335402      }
     403    closedir(dirp);
    336404  }
    337405 
    338406  s1=NULL;
    339   s1=(service*)malloc(sizeof(service*));
    340   s[0]=(service*)malloc(sizeof(service*));
     407  s1=(service*)calloc(1,SERVICE_SIZE);
     408  if(s1 == NULL){
     409    return errorException(m, "Unable to allocate memory.","InternalError");
     410  }
    341411  r_inputs=getMap(request_inputs,"MetaPath");
    342   sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
     412  if(r_inputs!=NULL)
     413    snprintf(tmps1,1024,"%s/%s",ntmp,r_inputs->value);
     414  else
     415    snprintf(tmps1,1024,"%s/",ntmp);
    343416  r_inputs=getMap(request_inputs,"Identifier");
    344 
    345   sprintf(tmps1,"%s/%s.zcfg",strdup(tmps1),r_inputs->value);
    346 
     417  char *ttmp=strdup(tmps1);
     418  snprintf(tmps1,1024,"%s/%s.zcfg",ttmp,r_inputs->value);
     419  free(ttmp);
    347420#ifdef DEBUG
    348421  fprintf(stderr,"Trying to load %s\n", tmps1);
     
    354427  dup2(saved_stdout,fileno(stdout));
    355428  if(t==22){
    356     tmps=createMap("text","The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.");
    357     addToMap(tmps,"code","InvalidParameterValue");
    358     printExceptionReportResponse(m,tmps);
     429    errorException(m, "The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.", "InvalidParameterValue");
    359430    exit(0);
    360431  }
    361   s[0]=s1;
     432  //s[0]=s1;
    362433
    363434#ifdef DEBUG
     
    399470#endif
    400471    r_inputs=getMap(request_inputs,"ResponseDocument");
    401     if(r_inputs==NULLMAP)
    402       r_inputs=getMap(request_inputs,"RawDataOutput");
    403 #ifdef DEBUG
     472    if(r_inputs==NULL) r_inputs=getMap(request_inputs,"RawDataOutput");
     473   
     474    //#ifdef DEBUG
    404475    fprintf(stderr,"OUTPUT Parsing ... \n");
    405 #endif
    406     if(r_inputs!=NULLMAP){
    407 #ifdef DEBUG
     476    //#endif
     477    if(r_inputs!=NULL){
     478      //#ifdef DEBUG
    408479      fprintf(stderr,"OUTPUT Parsing start now ... \n");
    409 #endif
     480      //#endif
    410481      char current_output_as_string[10240];
    411482      char cursor_output[10240];
    412       sprintf(cursor_output,"%s",strdup(r_inputs->value));
     483      char *cotmp=strdup(r_inputs->value);
     484      snprintf(cursor_output,10240,"%s",cotmp);
     485      free(cotmp);
    413486      j=0;
    414487      map* request_kvp_outputs=NULL;
     
    423496#endif
    424497      pToken=strtok(cursor_output,";");
    425       char** outputs_as_text=(char**)malloc(128*sizeof(char*));
     498      char** outputs_as_text=(char**)calloc(128,sizeof(char*));
     499      if(outputs_as_text == NULL) {
     500        return errorException(m, "Unable to allocate memory", "InternalError");
     501      }
    426502      i=0;
    427503      while(pToken!=NULL){
     
    431507        fprintf(stderr,"***%s***\n",pToken);
    432508#endif
    433         outputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char));
    434         sprintf(outputs_as_text[i],"%s",pToken);
     509        outputs_as_text[i]=(char*)calloc(strlen(pToken)+1,sizeof(char));
     510        if(outputs_as_text[i] == NULL) {
     511          return errorException(m, "Unable to allocate memory", "InternalError");
     512        }
     513        snprintf(outputs_as_text[i],strlen(pToken)+1,"%s",pToken);
    435514        pToken = strtok(NULL,";");
    436515        i++;
     
    438517      for(j=0;j<i;j++){
    439518        char *tmp=strdup(outputs_as_text[j]);
     519        free(outputs_as_text[j]);
    440520        char *tmpc;
    441521        tmpc=strtok(tmp,"@");
     
    444524          if(k==0){
    445525            if(tmp_output==NULL){
    446               tmp_output=(maps*)malloc(MAPS_SIZE);
     526              tmp_output=(maps*)calloc(1,MAPS_SIZE);
     527              if(tmp_output == NULL){
     528                return errorException(m, "Unable to allocate memory.", "InternalError");
     529              }
    447530              tmp_output->name=strdup(tmpc);
    448531              tmp_output->content=NULL;
     
    473556        }
    474557        if(request_output_real_format==NULL)
    475           request_output_real_format=tmp_output;
     558          request_output_real_format=dupMaps(&tmp_output);
    476559        else
    477560          addMapsToMaps(&request_output_real_format,tmp_output);
     561        freeMaps(&tmp_output);
     562        free(tmp_output);
     563        tmp_output=NULL;
    478564#ifdef DEBUG
    479565        dumpMaps(tmp_output);
    480566        fflush(stderr);
    481567#endif
    482         tmp_output=tmp_output->next;
     568        //tmp_output=tmp_output->next;
     569        free(tmp);
    483570      }
     571      free(outputs_as_text);
    484572    }
    485573
     
    494582    char current_input_as_string[40960];
    495583    char cursor_input[40960];
    496     sprintf(cursor_input,"%s",strdup(r_inputs->value));
     584    if(r_inputs!=NULL)
     585      snprintf(cursor_input,40960,"%s",r_inputs->value);
     586    else{
     587      errorException(m, "Parameter <DataInputs> was not specified","MissingParameterValue");
     588      freeMaps(&m);
     589      free(m);
     590      free(REQUEST);
     591      free(SERVICE_URL);
     592      return 0;
     593    }
    497594    j=0;
    498595    map* request_kvp_inputs=NULL;
     
    503600    char * pToken;
    504601    pToken=strtok(cursor_input,";");
    505     char** inputs_as_text=(char**)malloc(100*sizeof(char*));
     602    char** inputs_as_text=(char**)calloc(100,sizeof(char*));
     603    if(inputs_as_text == NULL){
     604      return errorException(m, "Unable to allocate memory.", "InternalError");
     605    }
    506606    i=0;
    507607    while(pToken!=NULL){
     
    513613      fprintf(stderr,"***%s***\n",pToken);
    514614#endif
    515       inputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char));
    516       sprintf(inputs_as_text[i],"%s",pToken);
     615      inputs_as_text[i]=(char*)calloc(strlen(pToken)+1,sizeof(char));
     616      snprintf(inputs_as_text[i],strlen(pToken)+1,"%s",pToken);
     617      if(inputs_as_text[i] == NULL){
     618        return errorException(m, "Unable to allocate memory.", "InternalError");
     619      }
    517620      pToken = strtok(NULL,";");
    518621      i++;
     
    521624    for(j=0;j<i;j++){
    522625      char *tmp=strdup(inputs_as_text[j]);
     626      free(inputs_as_text[j]);
    523627      char *tmpc;
    524628      tmpc=strtok(tmp,"@");
     
    537641#endif
    538642        if(tmpmaps==NULL){
    539           tmpmaps=(maps*)malloc(MAPS_SIZE);
     643          tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     644          if(tmpmaps == NULL){
     645            return errorException(m, "Unable to allocate memory.", "InternalError");
     646          }
    540647          tmpmaps->name=strdup(tmpn);
    541648          tmpmaps->content=createMap("value",tmpv+1);
     
    566673#endif
    567674#ifndef WIN32
    568                 if(CHECK_INET_HANDLE(hInternet))
    569 #endif
    570                 {
    571               res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
    572                                             INTERNET_FLAG_NO_CACHE_WRITE,0);
    573 #ifdef DEBUG
    574               fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
    575                       tmpv1+1,res.nDataAlloc,res.nDataLen);
    576 #endif
    577               char* tmpContent=(char*)malloc((res.nDataLen+1)*sizeof(char));
    578               size_t dwRead;
    579               InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
    580               map* tmpMap=getMap(tmpmaps->content,"value");
    581               if(tmpMap!=NULL)
    582                 tmpMap->value=tmpContent;
    583             }
     675            if(CHECK_INET_HANDLE(hInternet))
     676#endif
     677              {
     678                res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
     679                                    INTERNET_FLAG_NO_CACHE_WRITE,0);
     680#ifdef DEBUG
     681                fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
     682                        tmpv1+1,res.nDataAlloc,res.nDataLen);
     683#endif
     684                char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
     685                if(tmpContent == NULL){
     686                  return errorException(m, "Unable to allocate memory.", "InternalError");
     687                }
     688                size_t dwRead;
     689                InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
     690                map* tmpMap=getMap(tmpmaps->content,"value");
     691                if(tmpMap!=NULL)
     692                  tmpMap->value=strdup(tmpContent);
     693                free(tmpContent);
     694              }
    584695            addToMap(tmpmaps->content,tmpn1,tmpv1+1);
    585696          }
    586697          tmpc=strtok(NULL,"@");
    587698        }
     699#ifdef DEBUG
     700        dumpMaps(tmpmaps);
     701        fflush(stderr);
     702#endif
    588703        if(request_input_real_format==NULL)
    589           request_input_real_format=tmpmaps;
     704          request_input_real_format=dupMaps(&tmpmaps);
    590705        else
    591706          addMapsToMaps(&request_input_real_format,tmpmaps);
    592 #ifdef DEBUG
    593         dumpMaps(tmpmaps);
    594         fflush(stderr);
    595 #endif
    596         tmpmaps=tmpmaps->next;
     707        /*freeMap(&tmpmaps->content);
     708        free(tmpmaps->content);
     709        tmpmaps->content=NULL;*/
     710        freeMaps(&tmpmaps);
     711        free(tmpmaps);
     712          //}
     713        tmpmaps=NULL;
     714        free(tmp);
    597715      }
    598716    }
    599   }
     717    free(inputs_as_text);
     718  }
    600719  else {
     720    /**
     721     * Parse XML request
     722     */
    601723    xmlInitParser();
    602724#ifdef DEBUG
     
    616738     */
    617739    maps* tempMaps=NULL;
    618     xmlNodeSet* tmps=extractFromDoc(doc,
    619                                     "/*/*/*[local-name()='Input']");
     740    xmlXPathObjectPtr tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='Input']");
     741    xmlNodeSet* tmps=tmpsptr->nodesetval;
    620742#ifdef DEBUG
    621743    fprintf(stderr,"*****%d*****\n",tmps->nodeNr);
     
    631753        fprintf(stderr, "= element 0 node \"%s\"\n", cur->name);
    632754#endif
    633         xmlNodePtr cur1=cur->children;
    634         while(cur1){
    635 #ifdef DEBUG
    636           fprintf(stderr, "= element 1 node \"%s\" = (%s)\n",
    637                   cur1->name,xmlNodeListGetString(doc,cur1,1));
    638 #endif
    639           xmlNodePtr cur2=cur1/*->next*/;
    640           while(cur2){
     755        xmlNodePtr cur2=cur->children;
     756        while(cur2){
     757          while(cur2->type!=XML_ELEMENT_NODE)
     758            cur2=cur2->next;
     759          /**
     760           * Indentifier
     761           */
     762          if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
     763            xmlChar *val= xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
     764            if(tmpmaps==NULL){
     765              tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     766              if(tmpmaps == NULL){
     767                return errorException(m, "Unable to allocate memory.", "InternalError");
     768              }
     769              tmpmaps->name=strdup((char*)val);
     770              tmpmaps->content=NULL;
     771              tmpmaps->next=NULL;
     772            }
     773            xmlFree(val);
     774          }
     775          /**
     776           * Title, Asbtract
     777           */
     778          if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
     779             xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
     780            xmlChar *val=
     781              xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
     782            if(tmpmaps==NULL){
     783              tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     784              if(tmpmaps == NULL){
     785                return errorException(m, "Unable to allocate memory.", "InternalError");
     786              }
     787              tmpmaps->name="missingIndetifier";
     788              tmpmaps->content=createMap((char*)cur2->name,(char*)val);
     789              tmpmaps->next=NULL;
     790            }
     791            else{
     792              if(tmpmaps->content!=NULL)
     793                addToMap(tmpmaps->content,
     794                         (char*)cur2->name,(char*)val);
     795              else
     796                tmpmaps->content=
     797                  createMap((char*)cur2->name,(char*)val);
     798            }
     799#ifdef DEBUG
     800            dumpMaps(tmpmaps);
     801#endif
     802            xmlFree(val);
     803          }
     804          /**
     805           * InputDataFormChoice (Reference or Data ?)
     806           */
     807          if(xmlStrcasecmp(cur2->name,BAD_CAST "Reference")==0){
    641808            /**
    642              * Indentifier
     809             * Get every attribute from a Reference node
     810             * mimeType, encoding, schema, href, method
     811             * Header and Body gesture should be added here
    643812             */
    644             if(strcmp(mtoupper((char*)cur2->name),
    645                       mtoupper("Identifier"))==0){
    646               xmlChar *val=
    647                 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    648               if(tmpmaps==NULL){
    649                 tmpmaps=(maps*)malloc(MAPS_SIZE);
    650                 tmpmaps->name=strdup((char*)val);
    651                 tmpmaps->content=NULL;
    652                 tmpmaps->next=NULL;
     813#ifdef DEBUG
     814            fprintf(stderr,"REFERENCE\n");
     815#endif
     816            map* referenceMap=NULL;
     817            char *refs[5];
     818            refs[0]="mimeType";
     819            refs[1]="encoding";
     820            refs[2]="schema";
     821            refs[3]="method";
     822            refs[4]="href";
     823            char*url;
     824            for(int l=0;l<5;l++){
     825#ifdef DEBUG
     826              fprintf(stderr,"*** %s ***",refs[l]);
     827#endif
     828              xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]);
     829              if(val!=NULL && xmlStrlen(val)>0){
     830                if(tmpmaps->content!=NULL)
     831                  addToMap(tmpmaps->content,refs[l],(char*)val);
     832                else
     833                  tmpmaps->content=createMap(refs[l],(char*)val);
     834                map* ltmp=getMap(tmpmaps->content,"method");
     835                if(l==4){
     836                  if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0)
     837                     && CHECK_INET_HANDLE(hInternet)){
     838                    res=InternetOpenUrl(hInternet,(char*)val,NULL,0,
     839                                        INTERNET_FLAG_NO_CACHE_WRITE,0);
     840                    char* tmpContent=
     841                      (char*)calloc((res.nDataLen+1),sizeof(char));
     842                    if(tmpContent == NULL){
     843                      return errorException(m, "Unable to allocate memory.", "InternalError");
     844                    }
     845                    size_t dwRead;
     846                    InternetReadFile(res, (LPVOID)tmpContent,
     847                                     res.nDataLen, &dwRead);
     848                    tmpContent[res.nDataLen]=0;
     849                    addToMap(tmpmaps->content,"value",tmpContent);
     850                  }
     851                }
    653852              }
     853#ifdef DEBUG
     854              fprintf(stderr,"%s\n",val);
     855#endif
    654856              xmlFree(val);
    655857            }
    656             /**
    657              * Title, Asbtract
    658              */
    659             if(strcmp(mtoupper((char*)cur2->name),
    660                       mtoupper("Title"))==0 ||
    661                strcmp(mtoupper((char*)cur2->name),
    662                       mtoupper("Abstract"))==0){
    663               xmlChar *val=
    664                 xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    665               if(tmpmaps==NULL){
    666                 tmpmaps=(maps*)malloc(MAPS_SIZE);
    667                 tmpmaps->name="missingIndetifier";
    668                 tmpmaps->content=createMap((char*)cur2->name,(char*)val);
    669                 tmpmaps->next=NULL;
     858#ifdef POST_DEBUG
     859            fprintf(stderr,"Parse Header and Body from Reference \n");
     860#endif
     861            xmlNodePtr cur3=cur2->children;
     862            hInternet.header=NULL;
     863            while(cur3){
     864              if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){
     865                xmlNodePtr cur4=cur3;
     866                char *tmp=new char[cgiContentLength];
     867                char *ha[2];
     868                ha[0]="key";
     869                ha[1]="value";
     870                int hai;
     871                char *has;
     872                char *key;
     873                for(hai=0;hai<2;hai++){
     874                  xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]);
     875#ifdef POST_DEBUG
     876                  fprintf(stderr,"%s = %s\n",ha[hai],(char*)val);
     877#endif
     878                  if(hai==0){
     879                    key=(char*)calloc((1+strlen((char*)val)),sizeof(char));
     880                    snprintf(key,1+strlen((char*)val),"%s",(char*)val);
     881                  }else{
     882                    has=(char*)calloc((3+strlen((char*)val)+strlen(key)),sizeof(char));
     883                    if(has == NULL){
     884                      return errorException(m, "Unable to allocate memory.", "InternalError");
     885                    }
     886                    snprintf(has,(3+strlen((char*)val)+strlen(key)),"%s: %s",key,(char*)val);
     887#ifdef POST_DEBUG
     888                    fprintf(stderr,"%s\n",has);
     889#endif
     890                  }
     891                }
     892                hInternet.header=curl_slist_append(hInternet.header, has);
     893                //free(has);
    670894              }
    671895              else{
    672                 if(tmpmaps->content!=NULL)
    673                   addToMap(tmpmaps->content,
    674                            (char*)cur2->name,(char*)val);
     896#ifdef POST_DEBUG
     897                fprintf(stderr,"Try to fetch the body part of the request ...\n");
     898#endif
     899                if(xmlStrcasecmp(cur3->name,BAD_CAST "Body")==0 ){
     900#ifdef POST_DEBUG
     901                  fprintf(stderr,"Body part found !!!\n",(char*)cur3->content);
     902#endif
     903                  char *tmp=new char[cgiContentLength];
     904                  memset(tmp,0,cgiContentLength);
     905                  xmlNodePtr cur4=cur3->children;
     906                  while(cur4!=NULL){
     907                    xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0");
     908                    bdoc->encoding = xmlCharStrdup ("UTF-8");
     909                    xmlDocSetRootElement(bdoc,cur4);
     910                    xmlChar* btmps;
     911                    int bsize;
     912                    xmlDocDumpMemory(bdoc,&btmps,&bsize);
     913#ifdef POST_DEBUG
     914                    fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps);
     915#endif
     916                    if(btmps!=NULL)
     917                      sprintf(tmp,"%s",(char*)btmps);
     918                    xmlFreeDoc(bdoc);
     919                    cur4=cur4->next;
     920                  }
     921                  map *btmp=getMap(tmpmaps->content,"href");
     922                  if(btmp!=NULL){
     923#ifdef POST_DEBUG
     924                    fprintf(stderr,"%s %s\n",btmp->value,tmp);
     925                    curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
     926#endif
     927                    res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp),
     928                                        INTERNET_FLAG_NO_CACHE_WRITE,0);
     929                    char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char));
     930                    if(tmpContent == NULL){
     931                      return errorException(m, "Unable to allocate memory.", "InternalError");
     932                    }
     933                    size_t dwRead;
     934                    InternetReadFile(res, (LPVOID)tmpContent,
     935                                     res.nDataLen, &dwRead);
     936                    tmpContent[res.nDataLen]=0;
     937                    if(hInternet.header!=NULL)
     938                      curl_slist_free_all(hInternet.header);
     939                    addToMap(tmpmaps->content,"value",tmpContent);
     940#ifdef POST_DEBUG
     941                    fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);
     942#endif
     943                  }
     944                }
    675945                else
    676                   tmpmaps->content=
    677                     createMap((char*)cur2->name,(char*)val);
    678               }
    679 #ifdef DEBUG
    680               dumpMaps(tmpmaps);
    681 #endif
    682               xmlFree(val);
    683             }
    684             /**
    685              * InputDataFormChoice (Reference or Data ?)
    686              */
    687             if(strcmp(mtoupper((char*)cur2->name),
    688                       mtoupper("Reference"))==0){
    689               /**
    690                * Get every attribute from a Reference node
    691                * mimeType, encoding, schema, href, method
    692                * Header and Body gesture should be added here
    693                */
    694 #ifdef DEBUG
    695               fprintf(stderr,"REFERENCE\n");
    696 #endif
    697               map* referenceMap=NULL;
    698               char *refs[5];
    699               refs[0]="mimeType";
    700               refs[1]="encoding";
    701               refs[2]="schema";
    702               refs[3]="method";
    703               refs[4]="href";
    704               char*url;
    705               for(int l=0;l<5;l++){
    706 #ifdef DEBUG
    707                 fprintf(stderr,"*** %s ***\t",refs[l]);
    708 #endif
    709                 xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]);
    710                 if(val!=NULL && strlen((char*)val)>0){
    711                   if(tmpmaps->content!=NULL)
    712                     addToMap(tmpmaps->content,refs[l],(char*)val);
    713                   else
    714                     tmpmaps->content=createMap(refs[l],(char*)val);
    715                   map* ltmp=getMap(tmpmaps->content,"method");
    716                   if(l==4){
    717                     if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0)
    718                        && CHECK_INET_HANDLE(hInternet)){
    719                         res=InternetOpenUrl(hInternet,(char*)val,NULL,0,
    720                                             INTERNET_FLAG_NO_CACHE_WRITE,0);
    721                         char* tmpContent=
    722                           (char*)malloc((res.nDataLen+1)*sizeof(char));
    723                         size_t dwRead;
    724                         InternetReadFile(res, (LPVOID)tmpContent,
    725                                          res.nDataLen, &dwRead);
    726                         tmpContent[res.nDataLen]=0;
    727                         addToMap(tmpmaps->content,"value",tmpContent);
     946                  if(xmlStrcasecmp(cur3->name,BAD_CAST "BodyReference")==0 ){
     947                    xmlChar *val=xmlGetProp(cur3,BAD_CAST "href");
     948                    HINTERNET bInternet,res1;
     949                    bInternet=InternetOpen(
     950#ifndef WIN32
     951                                           (LPCTSTR)
     952#endif
     953                                           "ZooWPSClient\0",
     954                                           INTERNET_OPEN_TYPE_PRECONFIG,
     955                                           NULL,NULL, 0);
     956                    if(!CHECK_INET_HANDLE(bInternet))
     957                      fprintf(stderr,"WARNING : hInternet handle failed to initialize");
     958#ifdef POST_DEBUG
     959                    curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1);
     960#endif
     961                    res1=InternetOpenUrl(bInternet,(char*)val,NULL,0,
     962                                         INTERNET_FLAG_NO_CACHE_WRITE,0);
     963                    char* tmp=
     964                      (char*)calloc((res1.nDataLen+1),sizeof(char));
     965                    if(tmp == NULL){
     966                      return errorException(m, "Unable to allocate memory.", "InternalError");
    728967                    }
    729                   }
    730                  
    731                 }
    732 #ifdef DEBUG
    733                 fprintf(stderr,"%s\n",val);
    734 #endif
    735                 xmlFree(val);
    736               }
    737 #ifdef POST_DEBUG
    738               fprintf(stderr,"Parse Header and Body from Reference \n");
    739 #endif
    740               xmlNodePtr cur3=cur2->children;
    741               hInternet.header=NULL;
    742               while(cur3){
    743                 if(strcmp(mtoupper((char*)cur3->name), mtoupper("Header"))==0 ){
    744                   xmlNodePtr cur4=cur3;
    745                   char *tmp=new char[cgiContentLength];
    746                   char *ha[2];
    747                   ha[0]="key";
    748                   ha[1]="value";
    749                   int hai;
    750                   char *has;
    751                   char *key;
    752                   for(hai=0;hai<2;hai++){
    753                     xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]);
    754 #ifdef POST_DEBUG
    755                     fprintf(stderr,"%s = %s\n",ha[hai],(char*)val);
    756 #endif
    757                     if(hai==0){
    758                       key=(char*)malloc((1+strlen((char*)val))*sizeof(char));
    759                       sprintf(key,"%s",(char*)val);
    760                     }else{
    761                       has=(char*)malloc((3+strlen((char*)val)+strlen(key))*sizeof(char));
    762                       sprintf(has,"%s: %s",key,(char*)val);
    763 #ifdef POST_DEBUG
    764                       fprintf(stderr,"%s\n",has);
    765 #endif
    766                     }
    767                   }
    768                   hInternet.header=curl_slist_append(hInternet.header, has);
    769                   //free(has);
    770                 }
    771                 else{
    772 #ifdef POST_DEBUG
    773                   fprintf(stderr,"Try to fetch the body part of the request ...\n");
    774 #endif
    775                   if(strcmp(mtoupper((char*)cur3->name),mtoupper("Body"))==0 ){
    776 #ifdef POST_DEBUG
    777                     fprintf(stderr,"Body part found !!!\n",(char*)cur3->content);
    778 #endif
    779                     char *tmp=new char[cgiContentLength];
    780                     memset(tmp,cgiContentLength,0);
    781                     xmlNodePtr cur4=cur3->children;
    782                     while(cur4!=NULL){
    783                       xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0");
    784                       bdoc->encoding = xmlCharStrdup ("UTF-8");
    785                       xmlDocSetRootElement(bdoc,cur4);
    786                       xmlChar* btmps;
    787                       int bsize;
    788                       xmlDocDumpMemory(bdoc,&btmps,&bsize);
    789 #ifdef POST_DEBUG
    790                       fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps);
    791 #endif
    792                       if(btmps!=NULL)
    793                         sprintf(tmp,"%s",(char*)btmps);
    794                       xmlFreeDoc(bdoc);
    795                       cur4=cur4->next;
    796                     }
     968                    size_t bRead;
     969                    InternetReadFile(res1, (LPVOID)tmp,
     970                                     res1.nDataLen, &bRead);
     971                    tmp[res1.nDataLen]=0;
     972                    InternetCloseHandle(bInternet);
    797973                    map *btmp=getMap(tmpmaps->content,"href");
    798974                    if(btmp!=NULL){
     
    801977                      curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
    802978#endif
    803                       res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp),
     979                      res=InternetOpenUrl(hInternet,btmp->value,tmp,
     980                                          strlen(tmp),
    804981                                          INTERNET_FLAG_NO_CACHE_WRITE,0);
    805                       char* tmpContent=
    806                         (char*)malloc((res.nDataLen+1)*sizeof(char));
     982                      char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char));
     983                      if(tmpContent == NULL){
     984                        return errorException(m, "Unable to allocate memory.", "InternalError");
     985                      }
    807986                      size_t dwRead;
    808987                      InternetReadFile(res, (LPVOID)tmpContent,
     
    817996                    }
    818997                  }
    819                   else
    820                     if(strcmp(mtoupper((char*)cur3->name),mtoupper("BodyReference"))==0 ){
    821                       xmlChar *val=xmlGetProp(cur3,BAD_CAST "href");
    822                       HINTERNET bInternet,res1;
    823                       bInternet=InternetOpen(
    824 #ifndef WIN32
    825                                   (LPCTSTR)
    826 #endif
    827                                   "ZooWPSClient\0",
    828                                              INTERNET_OPEN_TYPE_PRECONFIG,
    829                                              NULL,NULL, 0);
    830                       if(!CHECK_INET_HANDLE(bInternet))
    831                         fprintf(stderr,"WARNING : hInternet handle failed to initialize");
     998              }
     999              cur3=cur3->next;
     1000            }
    8321001#ifdef POST_DEBUG
    833                       curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1);
    834 #endif
    835                       res1=InternetOpenUrl(bInternet,(char*)val,NULL,0,
    836                                            INTERNET_FLAG_NO_CACHE_WRITE,0);
    837                       char* tmp=
    838                         (char*)malloc((res1.nDataLen+1)*sizeof(char));
    839                       size_t bRead;
    840                       InternetReadFile(res1, (LPVOID)tmp,
    841                                        res1.nDataLen, &bRead);
    842                       tmp[res1.nDataLen]=0;
    843                       InternetCloseHandle(bInternet);
    844                       map *btmp=getMap(tmpmaps->content,"href");
    845                       if(btmp!=NULL){
    846 #ifdef POST_DEBUG
    847                         fprintf(stderr,"%s %s\n",btmp->value,tmp);
    848                         curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
    849 #endif
    850                         res=InternetOpenUrl(hInternet,btmp->value,tmp,
    851                                             strlen(tmp),
    852                                             INTERNET_FLAG_NO_CACHE_WRITE,0);
    853                         char* tmpContent=
    854                           (char*)malloc((res.nDataLen+1)*sizeof(char));
    855                         size_t dwRead;
    856                         InternetReadFile(res, (LPVOID)tmpContent,
    857                                          res.nDataLen, &dwRead);
    858                         tmpContent[res.nDataLen]=0;
    859                         if(hInternet.header!=NULL)
    860                           curl_slist_free_all(hInternet.header);
    861                         addToMap(tmpmaps->content,"value",tmpContent);
    862 #ifdef POST_DEBUG
    863                         fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);
    864 #endif
    865                       }
    866                     }
    867                 }
    868                 cur3=cur3->next;
    869               }
    870 #ifdef POST_DEBUG
    871               fprintf(stderr,"Header and Body was parsed from Reference \n");
    872 #endif
    873 #ifdef DEBUG
    874               dumpMap(tmpmaps->content);
    875               fprintf(stderr, "= element 2 node \"%s\" = (%s)\n",
    876                       cur2->name,cur2->content);
    877 #endif
    878             }
    879             else if(strcmp(mtoupper((char*)cur2->name),
    880                            mtoupper("Data"))==0){
    881 #ifdef DEBUG
    882               fprintf(stderr,"DATA\n");
    883 #endif
    884               xmlNodePtr cur4=cur2->children;
    885               while(cur4){
    886                 if(strcmp(mtoupper((char*)cur4->name),
    887                           mtoupper("LiteralData"))==0){
    888                   /**
    889                    * Get every attribute from a LiteralData node
    890                    * dataType , uom
    891                    */
    892                   char *lits[2];
    893                   lits[0]="dataType";
    894                   lits[1]="uom";
    895                   for(int l=0;l<2;l++){
    896 #ifdef DEBUG
    897                     fprintf(stderr,"*** %s ***\t",lits[l]);
    898 #endif
    899                     xmlChar *val=xmlGetProp(cur4,BAD_CAST lits[l]);
    900                     if(val!=NULL && strlen((char*)val)>0){
    901                       if(tmpmaps->content!=NULL)
    902                         addToMap(tmpmaps->content,lits[l],(char*)val);
    903                       else
    904                         tmpmaps->content=createMap(lits[l],(char*)val);
    905                     }
    906 #ifdef DEBUG
    907                     fprintf(stderr,"%s\n",val);
    908 #endif
    909                     xmlFree(val);
    910                   }
    911                   xmlChar* mv=xmlNodeListGetString(doc,
    912                                                    cur4->xmlChildrenNode,1);
    913                   if(tmpmaps->content!=NULL)
    914                     addToMap(tmpmaps->content,
    915                              "value",
    916                              (char*)mv);
    917                   else
    918                     tmpmaps->content=
    919                       createMap("value",
    920                                 (char*)mv);
    921                   xmlFree(mv);
    922                 }
    923                 else if(strcmp(mtoupper((char*)cur4->name),
    924                                mtoupper("ComplexData"))==0){
    925                   /**
    926                    * Get every attribute from a Reference node
    927                    * mimeType, encoding, schema
    928                    */
    929                   char *coms[2];
    930                   coms[0]="mimeType";
    931                   coms[1]="encoding";
    932                   coms[2]="schema";
    933                   for(int l=0;l<2;l++){
    934 #ifdef DEBUG
    935                     fprintf(stderr,"*** %s ***\t",coms[l]);
    936 #endif
    937                     xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]);
    938                     if(val!=NULL && strlen((char*)val)>0){
    939                       if(tmpmaps->content!=NULL)
    940                         addToMap(tmpmaps->content,coms[l],(char*)val);
    941                       else
    942                         tmpmaps->content=createMap(coms[l],(char*)val);
    943                     }
    944 #ifdef DEBUG
    945                     fprintf(stderr,"%s\n",val);
    946 #endif
    947                     xmlFree(val);
    948                   }
    949                   xmlChar* mv=xmlNodeListGetString(doc,
    950                                                    cur4->xmlChildrenNode,1);
    951                   if(tmpmaps->content!=NULL)
    952                     addToMap(tmpmaps->content,
    953                              "value",
    954                              (char*)mv);
    955                   else
    956                     tmpmaps->content=
    957                       createMap("value",
    958                                 (char*)mv);
    959                   xmlFree(mv);
    960                 }
    961                 cur4=cur4->next;
    962               }
    963             }
     1002            fprintf(stderr,"Header and Body was parsed from Reference \n");
     1003#endif
    9641004#ifdef DEBUG
    9651005            dumpMap(tmpmaps->content);
    9661006            fprintf(stderr, "= element 2 node \"%s\" = (%s)\n",
    967                     cur2->name,cur2->content); 
    968 #endif
    969             xmlNodePtr cur3=cur->children;
    970             while(cur3){
    971 #ifdef DEBUG
    972               fprintf(stderr, "= element 3 node \"%s\" = (%s)\n",cur3->name,
    973                       xmlNodeListGetString(doc,cur3->xmlChildrenNode,1));
    974 #endif
    975               if(strcmp(mtoupper((char*)cur3->name),
    976                         mtoupper("Title"))==0){
    977 #ifdef DEBUG
    978                 fprintf(stderr, "= element 3 node \"%s\" = (%s)\n",
    979                         cur3->name,xmlNodeListGetString(doc,cur3,1));
    980 #endif
     1007                    cur2->name,cur2->content);
     1008#endif
     1009          }
     1010          else if(xmlStrcasecmp(cur2->name,BAD_CAST "Data")==0){
     1011#ifdef DEBUG
     1012            fprintf(stderr,"DATA\n");
     1013#endif
     1014            xmlNodePtr cur4=cur2->children;
     1015            while(cur4){
     1016              while(cur4->type!=XML_ELEMENT_NODE)
     1017                cur4=cur4->next;
     1018
     1019              if(xmlStrcasecmp(cur4->name, BAD_CAST "LiteralData")==0){
     1020                /**
     1021                 * Get every attribute from a LiteralData node
     1022                 * dataType , uom
     1023                 */
     1024                char *lits[2];
     1025                lits[0]="dataType";
     1026                lits[1]="uom";
     1027                for(int l=0;l<2;l++){
     1028#ifdef DEBUG
     1029                  fprintf(stderr,"*** LiteralData %s ***",lits[l]);
     1030#endif
     1031                  xmlChar *val=xmlGetProp(cur4,BAD_CAST lits[l]);
     1032                  if(val!=NULL && strlen((char*)val)>0){
     1033                    if(tmpmaps->content!=NULL)
     1034                      addToMap(tmpmaps->content,lits[l],(char*)val);
     1035                    else
     1036                      tmpmaps->content=createMap(lits[l],(char*)val);
     1037                  }
     1038#ifdef DEBUG
     1039                  fprintf(stderr,"%s\n",val);
     1040#endif
     1041                  xmlFree(val);
     1042                }
    9811043              }
    982               cur3=cur3->children;
     1044              else if(xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0){
     1045                /**
     1046                 * Get every attribute from a Reference node
     1047                 * mimeType, encoding, schema
     1048                 */
     1049                char *coms[3];
     1050                coms[0]="mimeType";
     1051                coms[1]="encoding";
     1052                coms[2]="schema";
     1053                for(int l=0;l<3;l++){
     1054#ifdef DEBUG
     1055                  fprintf(stderr,"*** ComplexData %s ***",coms[l]);
     1056#endif
     1057                  xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]);
     1058                  if(val!=NULL && strlen((char*)val)>0){
     1059                    if(tmpmaps->content!=NULL)
     1060                      addToMap(tmpmaps->content,coms[l],(char*)val);
     1061                    else
     1062                      tmpmaps->content=createMap(coms[l],(char*)val);
     1063                  }
     1064#ifdef DEBUG
     1065                  fprintf(stderr,"%s\n",val);
     1066#endif
     1067                  xmlFree(val);
     1068                }
     1069              }
     1070              xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1);
     1071              addToMap(tmpmaps->content,"value",(char*)mv);
     1072              xmlFree(mv);
     1073              cur4=cur4->next;
    9831074            }
    984             cur2=cur2->next;
    9851075          }
    986           cur1=cur1->children;
     1076#ifdef DEBUG
     1077          fprintf(stderr,"cur2 next \n");
     1078          fflush(stderr);
     1079#endif
     1080          cur2=cur2->next;
    9871081        }
    988         if(request_input_real_format==NULL)
    989           request_input_real_format=tmpmaps;
    990         else
    991           addMapsToMaps(&request_input_real_format,tmpmaps);
    992 #ifdef DEBUG
     1082#ifdef DEBUG
     1083        fprintf(stderr,"ADD MAPS TO REQUEST MAPS !\n");
     1084        fflush(stderr);
     1085#endif
     1086        addMapsToMaps(&request_input_real_format,tmpmaps);
     1087       
     1088#ifdef DEBUG
     1089        fprintf(stderr,"******TMPMAPS*****\n");
    9931090        dumpMaps(tmpmaps);
    994 #endif
    995         fflush(stderr);
     1091        fprintf(stderr,"******REQUESTMAPS*****\n");
     1092        dumpMaps(request_input_real_format);
     1093#endif
    9961094        tmpmaps=tmpmaps->next;
    9971095             
    998       } else {
    999 #ifdef DEBUG
    1000         fprintf(stderr, "= node \"%s\": type %d\n", cur->name, cur->type);
    1001 #endif
    10021096      }
    10031097#ifdef DEBUG
     
    10051099#endif
    10061100    }
    1007    
    1008     xmlFree(tmps);
    1009     tmps=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']");
     1101#ifdef DEBUG
     1102    fprintf(stderr,"Search for response document node\n");
     1103#endif
     1104    xmlXPathFreeObject(tmpsptr);
     1105    //xmlFree(tmps);
     1106    tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']");
     1107    tmps=tmpsptr->nodesetval;
    10101108#ifdef DEBUG
    10111109    fprintf(stderr,"*****%d*****\n",tmps->nodeNr);
     
    10211119         */
    10221120        if(tmpmaps==NULL){
    1023           tmpmaps=(maps*)malloc(MAPS_SIZE);
     1121          tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1122          if(tmpmaps == NULL){
     1123            return errorException(m, "Unable to allocate memory.", "InternalError");
     1124          }
    10241125          tmpmaps->name="unknownIdentifier";
    10251126          tmpmaps->next=NULL;
     
    10531154        xmlNodePtr cur1=cur->children;
    10541155        while(cur1){
    1055           if(strcmp(mtoupper((char*)cur1->name),
    1056                     mtoupper("Output"))==0){
     1156          if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){
    10571157            /**
    10581158             * Get every attribute from a Output node
     
    10871187               * Indentifier
    10881188               */
    1089               if(strcmp(mtoupper((char*)cur2->name),
    1090                         mtoupper("Identifier"))==0){
     1189              if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
    10911190                xmlChar *val=
    10921191                  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    10931192                if(tmpmaps==NULL){
    1094                   tmpmaps=(maps*)malloc(MAPS_SIZE);
     1193                  tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1194                  if(tmpmaps == NULL){
     1195                    return errorException(m, "Unable to allocate memory.", "InternalError");
     1196                  }
    10951197                  tmpmaps->name=strdup((char*)val);
    10961198                  tmpmaps->content=NULL;
     
    11041206               * Title, Asbtract
    11051207               */
    1106               if(strcmp(mtoupper((char*)cur2->name),
    1107                         mtoupper("Title"))==0 ||
    1108                  strcmp(mtoupper((char*)cur2->name),
    1109                         mtoupper("Abstract"))==0){
     1208              if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
     1209                 xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
    11101210                xmlChar *val=
    11111211                  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    11121212                if(tmpmaps==NULL){
    1113                   tmpmaps=(maps*)malloc(MAPS_SIZE);
     1213                  tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1214                  if(tmpmaps == NULL){
     1215                    return errorException(m, "Unable to allocate memory.", "InternalError");
     1216                  }
    11141217                  tmpmaps->name="missingIndetifier";
    11151218                  tmpmaps->content=createMap((char*)cur2->name,(char*)val);
     
    11411244#endif
    11421245    }
    1143 
    1144     xmlFree(tmps);
    1145     tmps=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']");
     1246    xmlXPathFreeObject(tmpsptr);
     1247    //xmlFree(tmps);
     1248    tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']");
     1249    tmps=tmpsptr->nodesetval;
    11461250#ifdef DEBUG
    11471251    fprintf(stderr,"*****%d*****\n",tmps->nodeNr);
     
    11671271        if(val!=NULL && strlen((char*)val)>0){
    11681272          if(tmpmaps==NULL){
    1169             tmpmaps=(maps*)malloc(MAPS_SIZE);
     1273            tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1274            if(tmpmaps == NULL){
     1275              return errorException(m, "Unable to allocate memory.", "InternalError");
     1276            }
    11701277            tmpmaps->name="unknownIdentifier";
    11711278            tmpmaps->content=createMap(outs[l],(char*)val);
     
    11861293         * Indentifier
    11871294         */
    1188         if(strcmp(mtoupper((char*)cur2->name),
    1189                   mtoupper("Identifier"))==0){
     1295        if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
    11901296          val=
    11911297            xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    11921298          if(tmpmaps==NULL){
    1193             tmpmaps=(maps*)malloc(MAPS_SIZE);
     1299            tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1300            if(tmpmaps == NULL){
     1301              return errorException(m, "Unable to allocate memory.", "InternalError");
     1302            }
    11941303            tmpmaps->name=strdup((char*)val);
    11951304            tmpmaps->content=NULL;
     
    12101319#endif
    12111320    }
    1212    
    1213     xmlFree(tmps);
     1321    xmlXPathFreeObject(tmpsptr);
     1322    //xmlFree(tmps);
    12141323    xmlCleanupParser();
    12151324  }
    12161325
    1217   if(CHECK_INET_HANDLE(hInternet))
    1218     InternetCloseHandle(hInternet);
     1326  //if(CHECK_INET_HANDLE(hInternet))
     1327  InternetCloseHandle(hInternet);
    12191328
    12201329#ifdef DEBUG
     
    12221331  dumpMaps(request_input_real_format);
    12231332  dumpMaps(request_output_real_format);
    1224   dumpElements();
     1333  dumpMap(request_inputs);
    12251334#endif
    12261335
     
    12281337   * Ensure that each requested arguments are present in the request
    12291338   * DataInputs and ResponseDocument / RawDataOutput
    1230    */
    1231   addDefaultValues(&request_input_real_format,s1->inputs,m,"inputs");
     1339   */ 
     1340  char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,"inputs");
     1341  if(strcmp(dfv,"")!=0){
     1342    char tmps[1024];
     1343    snprintf(tmps,1024,"The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file.",dfv);
     1344    map* tmpe=createMap("text",tmps);
     1345    addToMap(tmpe,"code","MissingParameterValue");
     1346    printExceptionReportResponse(m,tmpe);
     1347    freeMap(&tmpe);
     1348    free(tmpe);
     1349    freeMaps(&m);
     1350    free(m);
     1351    free(REQUEST);
     1352    freeMaps(&request_input_real_format);
     1353    free(request_input_real_format);
     1354    freeMaps(&request_output_real_format);
     1355    free(request_output_real_format);
     1356    freeMaps(&tmpmaps);
     1357    free(tmpmaps);
     1358    return 1;
     1359  }
    12321360  addDefaultValues(&request_output_real_format,s1->outputs,m,"outputs");
    12331361
    1234   const struct tm *tm;
    1235   size_t len;
    1236   time_t now;
    1237   char *sDate;
    1238  
    1239   now = time ( NULL );
    1240   tm = localtime ( &now );
    1241 
    1242   sDate = new char[TIME_SIZE];
     1362#ifdef DEBUG
     1363  fprintf(stderr,"REQUEST_INPUTS\n");
     1364  dumpMaps(request_input_real_format);
     1365  fprintf(stderr,"REQUEST_OUTPUTS\n");
     1366  dumpMaps(request_output_real_format);
     1367#endif
    12431368
    12441369  maps* curs=getMaps(m,"env");
     
    12801405  }
    12811406 
    1282   len = strftime ( sDate, TIME_SIZE, "%d-%B-%YT%I:%M:%SZ", tm );
    1283 
    12841407#ifdef DEBUG
    12851408  dumpMap(request_inputs);
     
    12971420#endif
    12981421
     1422  if(r_inputs!=NULL)
     1423    if(strcasecmp(r_inputs->value,"false")==0)
     1424      r_inputs=NULL;
    12991425  if(r_inputs==NULLMAP){
    13001426    /**
     
    13071433    fflush(stderr);
    13081434#endif
    1309 
    1310         if(strncmp(mtoupper(r_inputs->value),"C",1)==0){
     1435    if(strncasecmp(r_inputs->value,"C",1)==0){
    13111436      r_inputs=getMap(request_inputs,"metapath");
    1312       sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
    1313           char *altPath=strdup(tmps1);
     1437      if(r_inputs!=NULL)
     1438        sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
     1439      else
     1440        sprintf(tmps1,"%s/",ntmp);
     1441      char *altPath=strdup(tmps1);
    13141442      r_inputs=getMap(s1->content,"ServiceProvider");
    13151443      sprintf(tmps1,"%s/%s",altPath,r_inputs->value);
    1316           free(altPath);
     1444      free(altPath);
    13171445#ifdef DEBUG
    13181446      fprintf(stderr,"Trying to load %s\n",tmps1);
    13191447#endif
    13201448#ifdef WIN32
    1321           HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
     1449      HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
    13221450#else
    13231451      void* so = dlopen(tmps1, RTLD_LAZY);
    13241452#endif
     1453#ifdef DEBUG
    13251454#ifdef WIN32
    13261455      DWORD errstr;
    1327           errstr = GetLastError();
    1328 #ifdef DEBUG
    1329           fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr);
    1330 #endif
     1456      errstr = GetLastError();
     1457      fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr);
    13311458#else
    13321459      char *errstr;
    1333           errstr = dlerror();
     1460      errstr = dlerror();
     1461#endif
    13341462#endif
    13351463
     
    13421470#ifdef DEBUG
    13431471        dumpMap(r_inputs);
    1344         fprintf(stderr,"%s %s",r_inputs->value,mtoupper(r_inputs->value));
     1472        fprintf(stderr,"%s\n",r_inputs->value);
    13451473        fflush(stderr);
    13461474#endif
    1347         if(strcmp(mtoupper(r_inputs->value),"C-FORTRAN")==0){
     1475        if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){
    13481476#ifdef WIN32
    13491477          //Strange return value needed here !
     
    13521480          r_inputs=getMap(request_inputs,"Identifier");
    13531481          char fname[1024];
    1354           sprintf(fname,"%s",r_inputs->value);
     1482          sprintf(fname,"%s_",r_inputs->value);
    13551483#ifdef DEBUG
    13561484          fprintf(stderr,"Try to load function %s\n",fname);
     
    13711499          fprintf(stderr,"Function loaded %s\n",errstr);
    13721500#endif 
     1501
    13731502          char main_conf[10][30][1024];
    13741503          char inputs[10][30][1024];
     
    13901519          charxxxToMaps((char***)&outputs[0],&request_output_real_format);
    13911520        }else{
     1521#ifdef DEBUG
    13921522#ifdef WIN32
    13931523          errstr = GetLastError();
    1394 #ifdef DEBUG
    13951524          fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr);
    13961525#endif
     
    14041533          execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value);
    14051534#ifdef DEBUG
    1406           /*if(!execute)*/
    14071535          errstr = GetLastError();
    14081536          fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr);
    1409           /*else
    1410           fprintf(stderr,"Function %s loaded\n",r_inputs->value);*/
    14111537#endif
    14121538#else
     
    14331559#endif
    14341560        }
    1435 
    14361561        dlclose(so);
    14371562      } else {
     
    14401565         */
    14411566        char tmps[1024];
     1567#ifdef WIN32
     1568        DWORD errstr = GetLastError();
     1569#else
     1570        char* errstr = dlerror();
     1571#endif
    14421572        sprintf(tmps,"C Library can't be loaded %s \n",errstr);
    14431573        map* tmps1=createMap("text",tmps);
     
    14471577    }
    14481578    else{
    1449         if(strcmp(mtoupper(r_inputs->value),"PYTHON")==0){
    1450                 eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    1451         }
    1452         else
    1453 
    1454         #ifdef USE_JAVA
    1455         if(strcmp(mtoupper(r_inputs->value),"JAVA")==0){
     1579      if(strncasecmp(r_inputs->value,"PYTHON",6)==0){
     1580        eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
     1581      }
     1582      else
     1583       
     1584#ifdef USE_JAVA
     1585        if(strncasecmp(r_inputs->value,"JAVA",4)==0){
    14561586          eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    14571587        }
    14581588        else
    1459         #endif
    1460 
    1461         #ifdef USE_PHP
    1462           if(strcmp(mtoupper(r_inputs->value),"PHP")==0){
     1589#endif
     1590
     1591#ifdef USE_PHP
     1592          if(strncasecmp(r_inputs->value,"PHP",3)==0){
    14631593            eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    14641594          }
    1465         else
    1466         #endif
    1467        
    1468         #ifdef USE_JS
    1469             if(strcmp(mtoupper(r_inputs->value),"JS")==0){
     1595          else
     1596#endif
     1597         
     1598#ifdef USE_JS
     1599            if(strncasecmp(r_inputs->value,"JS",2)==0){
    14701600              eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    14711601            }
    14721602            else
    1473          #endif
    1474                 {
    1475               char tmpv[1024];
    1476               sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value);
    1477               map* tmps=createMap("text",tmpv);
    1478               printExceptionReportResponse(m,tmps);
    1479               return(-1);
    1480             }
     1603#endif
     1604              {
     1605                char tmpv[1024];
     1606                sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value);
     1607                map* tmps=createMap("text",tmpv);
     1608                printExceptionReportResponse(m,tmps);
     1609                return(-1);
     1610              }
    14811611    }
    14821612  }
     
    14871617    fprintf(stderr,"\nPID : %d\n",cpid);
    14881618#endif
     1619
    14891620#ifndef WIN32
    1490         pid = fork ();
     1621    pid = fork ();
    14911622#else
    1492         pid = 0;
     1623    pid = 0;
    14931624#endif
    14941625    if (pid > 0) {
     
    15061637       * process answer to http client.
    15071638       */
    1508       char tmp1[256];
    15091639      r_inputs=getMapFromMaps(m,"main","tmpPath");
    1510       sprintf(tmp1,"%s",r_inputs->value);
    1511       r_inputs=getMap(s1->content,"ServiceProvider");
    1512       sprintf(tmp1,"%s/%s",strdup(tmp1),r_inputs->value);
    1513       sprintf(tmp1,"%s_%d.xml",strdup(tmp1),cpid);
     1640      map* r_inputs1=getMap(s1->content,"ServiceProvider");
     1641      char* fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+16)*sizeof(char));
     1642      sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid);
     1643      char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+22)*sizeof(char));
     1644      sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid);
     1645      fprintf(stderr,"File to use as backup %s\n",fbkp);
    15141646#ifdef DEBUG
    15151647      fprintf(stderr,"RUN IN BACKGROUND MODE \n");
    15161648      fprintf(stderr,"son pid continue (origin %d) %d ...\n",cpid,getpid());
    1517       fprintf(stderr,"\nFILE TO STORE DATA %s\n",tmp1);
    1518 #endif
    1519       freopen(tmp1 , "w+", stdout);
     1649      fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value);
     1650#endif
     1651      freopen(fbkp , "w+", stdout);
    15201652      fclose(stdin);
    1521       r_inputs=getMapFromMaps(m,"main","tmpPath");
    1522       sprintf(tmp1,"%s",r_inputs->value);
    1523       r_inputs=getMap(s1->content,"ServiceProvider");
    1524       sprintf(tmp1,"%s/%s",strdup(tmp1),r_inputs->value);
    1525       sprintf(tmp1,"%s_%d_error.log",strdup(tmp1),cpid);
    1526       freopen(tmp1,"w+",stderr);
     1653      freopen(flog,"w+",stderr);
     1654      free(fbkp);
     1655      free(flog);
    15271656      /**
    15281657       * set status to SERVICE_STARTED and flush stdout to ensure full
     
    15311660       * this way the data will be updated at the end of the process run.
    15321661       */
    1533       printProcessResponse1(m,request_inputs,cpid,
    1534                             s[0],r_inputs->value,SERVICE_STARTED,
     1662      printProcessResponse(m,request_inputs,cpid,
     1663                            s1,r_inputs->value,SERVICE_STARTED,
    15351664                            request_input_real_format,
    15361665                            request_output_real_format);
     
    15461675#endif
    15471676
    1548       if(strncmp(mtoupper(r_inputs->value),"C",1)==0){
     1677      if(strncasecmp(r_inputs->value,"C",1)==0){
     1678
    15491679        r_inputs=getMap(request_inputs,"metapath");
    1550         sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
    1551         r_inputs=getMap(s1->content,"ServiceProvider");
    1552         sprintf(tmps1,"%s/%s",strdup(tmps1),r_inputs->value);
     1680        if(r_inputs!=NULL){
     1681          sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
     1682          r_inputs=getMap(s1->content,"ServiceProvider");
     1683          if(r_inputs!=NULL)
     1684            sprintf(tmps1,"%s/%s",strdup(tmps1),r_inputs->value);
     1685        }else{
     1686          sprintf(tmps1,"%s/",ntmp);
     1687        }
     1688         
    15531689 
    15541690#ifdef DEBUG
     
    15561692#endif
    15571693#ifdef WIN32
    1558           HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
     1694        HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
    15591695#else
    1560       void* so = dlopen(tmps1, RTLD_LAZY);
     1696        void* so = dlopen(tmps1, RTLD_LAZY);
    15611697#endif
    15621698#ifdef WIN32
    1563           DWORD errstr;
    1564           errstr = GetLastError();
     1699        DWORD errstr;
     1700        errstr = GetLastError();
    15651701#else
    1566           char *errstr;
    1567           errstr = dlerror();
     1702        char *errstr;
     1703        errstr = dlerror();
    15681704#endif
    15691705        if( so != NULL ) {
     
    15721708          fprintf(stderr,"r_inputs->value = %s\n",r_inputs->value);
    15731709#endif
    1574           if(strcmp(mtoupper(r_inputs->value),"C-FORTRAN")==0){
     1710          if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){
    15751711            r_inputs=getMap(request_inputs,"Identifier");
    15761712#ifdef DEBUG
     
    15841720#endif
    15851721#ifdef WIN32
    1586           execute_t execute=(execute_t)GetProcAddress(so,fname);
     1722            execute_t execute=(execute_t)GetProcAddress(so,fname);
    15871723#else
    1588           execute_t execute=(execute_t)dlsym(so,fname);
     1724            execute_t execute=(execute_t)dlsym(so,fname);
    15891725#endif
    15901726#ifdef DEBUG
    15911727#ifdef WIN32
    1592           errstr = GetLastError();
     1728            errstr = GetLastError();
    15931729#else
    1594           errstr = dlerror();
     1730            errstr = dlerror();
    15951731#endif
    15961732#endif 
     
    16221758#endif
    16231759#ifdef WIN32
    1624           execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value);
     1760            execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value);
    16251761#else
    1626           execute_t execute=(execute_t)dlsym(so,r_inputs->value);
     1762            execute_t execute=(execute_t)dlsym(so,r_inputs->value);
    16271763#endif
    16281764#ifdef DEBUG
    16291765#ifdef WIN32
    1630           errstr = GetLastError();
     1766            errstr = GetLastError();
    16311767#else
    1632           errstr = dlerror();
     1768            errstr = dlerror();
    16331769#endif
    16341770            fprintf(stderr,"Function loaded %s\n",errstr);
     
    16381774             */
    16391775            eres=execute(&m,&request_input_real_format,&request_output_real_format);
    1640             dlclose(so);
    16411776          }
     1777          dlclose(so);
    16421778        } else {
    16431779          /**
     
    16481784          map* tmps=createMap("text",tmps1);
    16491785          printExceptionReportResponse(m,tmps);
     1786          freeMap(&tmps);
     1787          free(tmps);
    16501788          exit(1);
    16511789        }
    16521790      } else{
    1653         if(strcmp(mtoupper(r_inputs->value),"PYTHON")==0){
     1791        if(strncasecmp(r_inputs->value,"PYTHON",6)==0){
    16541792          eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    16551793        }
    16561794        else
    16571795
    1658         #ifdef USE_JAVA
    1659           if(strcmp(mtoupper(r_inputs->value),"JAVA")==0){
     1796#ifdef USE_JAVA
     1797          if(strncasecmp(r_inputs->value,"JAVA",4)==0){
    16601798            eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    16611799          }
    16621800          else
    1663         #endif
    1664        
    1665         #ifdef USE_PHP
    1666             if(strcmp(mtoupper(r_inputs->value),"PHP")==0){
     1801#endif
     1802           
     1803#ifdef USE_PHP
     1804            if(strncasecmp(r_inputs->value,"PHP",3)==0){
    16671805              eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    16681806            }
    16691807            else
    1670         #endif
    1671 
    1672         #ifdef USE_JS
    1673             if(strcmp(mtoupper(r_inputs->value),"JS")==0){
     1808#endif
     1809             
     1810#ifdef USE_JS
     1811              if(strncasecmp(r_inputs->value,"JS",2)==0){
    16741812                eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    16751813              }
    1676             else
    1677         #endif
    1678         {
    1679               char tmpv[1024];
    1680               sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value);
    1681               map* tmps=createMap("text",tmpv);
    1682               printExceptionReportResponse(m,tmps);
    1683               return -1;
    1684             }
     1814              else
     1815#endif
     1816                {
     1817                  char tmpv[1024];
     1818                  sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value);
     1819                  map* tmps=createMap("text",tmpv);
     1820                  printExceptionReportResponse(m,tmps);
     1821                  return -1;
     1822                }
    16851823      }
    16861824 
     
    16971835#ifdef DEBUG
    16981836  dumpMaps(request_output_real_format);
    1699 #endif
    1700   outputResponse(s1,request_input_real_format,
    1701                  request_output_real_format,request_inputs,
    1702                  cpid,m,eres);
    1703 
     1837  fprintf(stderr,"Function loaded and returned %d\n",eres);
     1838  fflush(stderr);
     1839#endif
     1840  if(eres!=-1)
     1841    outputResponse(s1,request_input_real_format,
     1842                   request_output_real_format,request_inputs,
     1843                   cpid,m,eres);
     1844
     1845  //if(getpid()==cpid){
     1846  freeService(&s1);
     1847  free(s1);
     1848  freeMaps(&m);
     1849  free(m);
     1850  freeMaps(&tmpmaps);
     1851  free(tmpmaps);
     1852 
     1853  freeMaps(&request_input_real_format);
     1854  free(request_input_real_format);
     1855 
     1856  //freeMap(&request_inputs);
     1857  //free(request_inputs);
     1858   
     1859  /* The following is requested but get issue using with Python support :/ */
     1860  freeMaps(&request_output_real_format);
     1861  free(request_output_real_format);
     1862 
     1863  free(REQUEST);
     1864  free(SERVICE_URL);
    17041865#ifdef DEBUG
    17051866  fprintf(stderr,"Processed response \n");
     
    17071868  fflush(stderr);
    17081869#endif
     1870    //}
    17091871
    17101872  return 0;
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