Changeset 541


Ignore:
Timestamp:
Nov 17, 2014, 4:38:34 PM (9 years ago)
Author:
david
Message:
  • fix indent
File:
1 edited

Legend:

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

    r539 r541  
    2525#define length(x) (sizeof(x) / sizeof(x[0]))
    2626
    27 extern "C" int yylex();
    28 extern "C" int crlex();
     27extern "C" int yylex ();
     28extern "C" int crlex ();
    2929
    3030#include "cgic.h"
    3131
    32 extern "C" {
     32extern "C"
     33{
    3334#include <libxml/tree.h>
    3435#include <libxml/xmlmemory.h>
     
    9192
    9293#ifdef WIN32
    93 extern "C" {
    94   __declspec(dllexport) char *strcasestr(char const *a, char const *b)
     94extern "C"
     95{
     96  __declspec (dllexport) char *strcasestr (char const *a, char const *b)
    9597#ifndef USE_MS
    96  {
    97   char *x=zStrdup(a);
    98   char *y=zStrdup(b);
    99  
    100   x=_strlwr(x);
    101   y=_strlwr(y);
    102   char *pos = strstr(x, y);
    103   char *ret = pos == NULL ? NULL : (char *)(a + (pos-x));
    104   free(x);
    105   free(y);
    106   return ret;
    107  };
     98  {
     99    char *x = zStrdup (a);
     100    char *y = zStrdup (b);
     101
     102      x = _strlwr (x);
     103      y = _strlwr (y);
     104    char *pos = strstr (x, y);
     105    char *ret = pos == NULL ? NULL : (char *) (a + (pos - x));
     106      free (x);
     107      free (y);
     108      return ret;
     109  };
    108110#else
    109   ;
     111   ;
    110112#endif
    111113}
     
    115117#define __(String) dgettext ("zoo-service",String)
    116118
    117 extern   int getServiceFromFile(maps*,const char*,service**);
    118 
    119 int readServiceFile(maps* conf, char* file,service** service,char *name){
    120   int t=getServiceFromFile(conf,file,service);
     119extern int getServiceFromFile (maps *, const char *, service **);
     120
     121int
     122readServiceFile (maps * conf, char *file, service ** service, char *name)
     123{
     124  int t = getServiceFromFile (conf, file, service);
    121125#ifdef YAML
    122   if(t<0){
    123     t=getServiceFromYAML(conf,file,service,name);
    124   }
     126  if (t < 0)
     127    {
     128      t = getServiceFromYAML (conf, file, service, name);
     129    }
    125130#endif
    126131  return t;
    127132}
    128133
    129 void translateChar(char* str,char toReplace,char toReplaceBy){
    130   int i=0,len=strlen(str);
    131   for(i=0;i<len;i++){
    132     if(str[i]==toReplace)
    133       str[i]=toReplaceBy;
    134   }
     134void
     135translateChar (char *str, char toReplace, char toReplaceBy)
     136{
     137  int i = 0, len = strlen (str);
     138  for (i = 0; i < len; i++)
     139    {
     140      if (str[i] == toReplace)
     141        str[i] = toReplaceBy;
     142    }
    135143}
    136144
     
    139147 * value = "["",""]"
    140148 */
    141 int appendMapsToMaps(maps* m,maps* mo,maps* mi,elements* elem){
    142   maps* tmpMaps=getMaps(mo,mi->name);
    143   map* tmap=getMapType(tmpMaps->content);
    144   elements* el=getElements(elem,mi->name);
    145   int hasEl=1;
    146   if(el==NULL)
    147     hasEl=-1;
    148   if(tmap==NULL){
    149     if(hasEl>0)
    150       tmap=getMapType(el->defaults->content);     
    151   }
    152 
    153   map* testMap=NULL;
    154   if(hasEl>0){
    155     testMap=getMap(el->content,"maxOccurs");
    156   }else{
    157     testMap=createMap("maxOccurs","unbounded");
    158   }
    159 
    160   if(testMap!=NULL){
    161     if(strncasecmp(testMap->value,"unbounded",9)!=0 && atoi(testMap->value)>1){
    162       if(addMapsArrayToMaps(&mo,mi,tmap->name)<0){
    163         char emsg[1024];
    164         sprintf(emsg,_("You set maximum occurences for <%s> as %i but you tried to use it more than the limit you set. Please correct your ZCFG file or your request."),mi->name,atoi(testMap->value));
    165         errorException(m,emsg,"InternalError",NULL);
    166         return -1;
    167       }
    168     }else{
    169       if(strncasecmp(testMap->value,"unbounded",9)==0){
    170         if(hasEl<0){
    171           freeMap(&testMap);
    172           free(testMap);
    173         }
    174         if(addMapsArrayToMaps(&mo,mi,tmap->name)<0){
    175           char emsg[1024];
    176           map* tmpMap=getMap(mi->content,"length");
    177           sprintf(emsg,_("ZOO-Kernel was unable to load your data for %s position %s."),mi->name,tmpMap->value);
    178           errorException(m,emsg,"InternalError",NULL);
    179           return -1;
    180         }
    181       }
    182       else{
    183         char emsg[1024];
    184         sprintf(emsg,_("You set maximum occurences for <%s> to one but you tried to use it more than once. Please correct your ZCFG file or your request."),mi->name);
    185         errorException(m,emsg,"InternalError",NULL);
    186         return -1;
    187       }
    188     }
    189   }
     149int
     150appendMapsToMaps (maps * m, maps * mo, maps * mi, elements * elem)
     151{
     152  maps *tmpMaps = getMaps (mo, mi->name);
     153  map *tmap = getMapType (tmpMaps->content);
     154  elements *el = getElements (elem, mi->name);
     155  int hasEl = 1;
     156  if (el == NULL)
     157    hasEl = -1;
     158  if (tmap == NULL)
     159    {
     160      if (hasEl > 0)
     161        tmap = getMapType (el->defaults->content);
     162    }
     163
     164  map *testMap = NULL;
     165  if (hasEl > 0)
     166    {
     167      testMap = getMap (el->content, "maxOccurs");
     168    }
     169  else
     170    {
     171      testMap = createMap ("maxOccurs", "unbounded");
     172    }
     173
     174  if (testMap != NULL)
     175    {
     176      if (strncasecmp (testMap->value, "unbounded", 9) != 0
     177          && atoi (testMap->value) > 1)
     178        {
     179          if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0)
     180            {
     181              char emsg[1024];
     182              sprintf (emsg,
     183                       _
     184                       ("You set maximum occurences for <%s> as %i but you tried to use it more than the limit you set. Please correct your ZCFG file or your request."),
     185                       mi->name, atoi (testMap->value));
     186              errorException (m, emsg, "InternalError", NULL);
     187              return -1;
     188            }
     189        }
     190      else
     191        {
     192          if (strncasecmp (testMap->value, "unbounded", 9) == 0)
     193            {
     194              if (hasEl < 0)
     195                {
     196                  freeMap (&testMap);
     197                  free (testMap);
     198                }
     199              if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0)
     200                {
     201                  char emsg[1024];
     202                  map *tmpMap = getMap (mi->content, "length");
     203                  sprintf (emsg,
     204                           _
     205                           ("ZOO-Kernel was unable to load your data for %s position %s."),
     206                           mi->name, tmpMap->value);
     207                  errorException (m, emsg, "InternalError", NULL);
     208                  return -1;
     209                }
     210            }
     211          else
     212            {
     213              char emsg[1024];
     214              sprintf (emsg,
     215                       _
     216                       ("You set maximum occurences for <%s> to one but you tried to use it more than once. Please correct your ZCFG file or your request."),
     217                       mi->name);
     218              errorException (m, emsg, "InternalError", NULL);
     219              return -1;
     220            }
     221        }
     222    }
    190223  return 0;
    191224}
    192225
    193 int recursReaddirF(maps* m,xmlNodePtr n,char *conf_dir,char *prefix,int saved_stdout,int level,void (func) (maps*,xmlNodePtr,service*)){
     226int
     227recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix,
     228                int saved_stdout, int level, void (func) (maps *, xmlNodePtr,
     229                                                          service *))
     230{
    194231  struct dirent *dp;
    195   int scount=0;
    196 
    197   if(conf_dir==NULL)
     232  int scount = 0;
     233
     234  if (conf_dir == NULL)
    198235    return 1;
    199   DIR *dirp = opendir(conf_dir);
    200   if(dirp==NULL){
    201     if(level>0)
    202       return 1;
     236  DIR *dirp = opendir (conf_dir);
     237  if (dirp == NULL)
     238    {
     239      if (level > 0)
     240        return 1;
     241      else
     242        return -1;
     243    }
     244  char tmp1[25];
     245  sprintf (tmp1, "sprefix_%d", level);
     246  char levels[17];
     247  sprintf (levels, "%d", level);
     248  setMapInMaps (m, "lenv", "level", levels);
     249  while ((dp = readdir (dirp)) != NULL)
     250    if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.'
     251        && strstr (dp->d_name, ".") == NULL)
     252      {
     253
     254        char *tmp =
     255          (char *) malloc ((strlen (conf_dir) + strlen (dp->d_name) + 2) *
     256                           sizeof (char));
     257        sprintf (tmp, "%s/%s", conf_dir, dp->d_name);
     258
     259        if (prefix != NULL)
     260          {
     261            prefix = NULL;
     262          }
     263        prefix = (char *) malloc ((strlen (dp->d_name) + 2) * sizeof (char));
     264        sprintf (prefix, "%s.", dp->d_name);
     265
     266        //map* tmpMap=getMapFromMaps(m,"lenv",tmp1);
     267
     268        int res;
     269        if (prefix != NULL)
     270          {
     271            setMapInMaps (m, "lenv", tmp1, prefix);
     272            char levels1[17];
     273            sprintf (levels1, "%d", level + 1);
     274            setMapInMaps (m, "lenv", "level", levels1);
     275            res =
     276              recursReaddirF (m, n, tmp, prefix, saved_stdout, level + 1,
     277                              func);
     278            sprintf (levels1, "%d", level);
     279            setMapInMaps (m, "lenv", "level", levels1);
     280            free (prefix);
     281            prefix = NULL;
     282          }
     283        else
     284          res = -1;
     285        free (tmp);
     286        if (res < 0)
     287          {
     288            return res;
     289          }
     290      }
    203291    else
    204       return -1;
    205   }
    206   char tmp1[25];
    207   sprintf(tmp1,"sprefix_%d",level);
    208   char levels[17];
    209   sprintf(levels,"%d",level);
    210   setMapInMaps(m,"lenv","level",levels);
    211   while ((dp = readdir(dirp)) != NULL)
    212     if((dp->d_type==DT_DIR || dp->d_type==DT_LNK) && dp->d_name[0]!='.' && strstr(dp->d_name,".")==NULL){
    213 
    214       char *tmp=(char*)malloc((strlen(conf_dir)+strlen(dp->d_name)+2)*sizeof(char));
    215       sprintf(tmp,"%s/%s",conf_dir,dp->d_name);
    216 
    217       if(prefix!=NULL){
    218         prefix=NULL;
     292      {
     293        if (dp->d_name[0] != '.' && strstr (dp->d_name, ".zcfg") != 0)
     294          {
     295            int t;
     296            char tmps1[1024];
     297            memset (tmps1, 0, 1024);
     298            snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name);
     299            service *s1 = (service *) malloc (SERVICE_SIZE);
     300            if (s1 == NULL)
     301              {
     302                dup2 (saved_stdout, fileno (stdout));
     303                errorException (m, _("Unable to allocate memory."),
     304                                "InternalError", NULL);
     305                return -1;
     306              }
     307#ifdef DEBUG
     308            fprintf (stderr, "#################\n%s\n#################\n",
     309                     tmps1);
     310#endif
     311            char *tmpsn = zStrdup (dp->d_name);
     312            tmpsn[strlen (tmpsn) - 5] = 0;
     313            t = readServiceFile (m, tmps1, &s1, tmpsn);
     314            free (tmpsn);
     315            if (t < 0)
     316              {
     317                map *tmp00 = getMapFromMaps (m, "lenv", "message");
     318                char tmp01[1024];
     319                if (tmp00 != NULL)
     320                  sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"),
     321                           dp->d_name, tmp00->value);
     322                else
     323                  sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
     324                           dp->d_name);
     325                dup2 (saved_stdout, fileno (stdout));
     326                errorException (m, tmp01, "InternalError", NULL);
     327                return -1;
     328              }
     329#ifdef DEBUG
     330            dumpService (s1);
     331            fflush (stdout);
     332            fflush (stderr);
     333#endif
     334            func (m, n, s1);
     335            freeService (&s1);
     336            free (s1);
     337            scount++;
     338          }
    219339      }
    220       prefix=(char*)malloc((strlen(dp->d_name)+2)*sizeof(char));
    221       sprintf(prefix,"%s.",dp->d_name);
    222      
    223       //map* tmpMap=getMapFromMaps(m,"lenv",tmp1);
    224      
    225       int res;
    226       if(prefix!=NULL){
    227         setMapInMaps(m,"lenv",tmp1,prefix);
    228         char levels1[17];
    229         sprintf(levels1,"%d",level+1);
    230         setMapInMaps(m,"lenv","level",levels1);
    231         res=recursReaddirF(m,n,tmp,prefix,saved_stdout,level+1,func);
    232         sprintf(levels1,"%d",level);
    233         setMapInMaps(m,"lenv","level",levels1);
    234         free(prefix);
    235         prefix=NULL;
    236       }else
    237         res=-1;
    238       free(tmp);
    239       if(res<0){
    240         return res;
    241       }
    242     }
    243     else{
    244       if(dp->d_name[0]!='.' && strstr(dp->d_name,".zcfg")!=0){
    245         int t;
    246         char tmps1[1024];
    247         memset(tmps1,0,1024);
    248         snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name);
    249         service* s1=(service*)malloc(SERVICE_SIZE);
    250         if(s1 == NULL){
    251           dup2(saved_stdout,fileno(stdout));
    252           errorException(m, _("Unable to allocate memory."),"InternalError",NULL);
    253           return -1;
    254         }
    255 #ifdef DEBUG
    256         fprintf(stderr,"#################\n%s\n#################\n",tmps1);
    257 #endif
    258         char *tmpsn=zStrdup(dp->d_name);
    259         tmpsn[strlen(tmpsn)-5]=0;
    260         t=readServiceFile(m,tmps1,&s1,tmpsn);
    261         free(tmpsn);
    262         if(t<0){
    263           map* tmp00=getMapFromMaps(m,"lenv","message");
    264           char tmp01[1024];
    265           if(tmp00!=NULL)
    266             sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value);
    267           else
    268             sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),dp->d_name);
    269           dup2(saved_stdout,fileno(stdout));
    270           errorException(m, tmp01,"InternalError",NULL);
    271           return -1;
    272         }
    273 #ifdef DEBUG
    274         dumpService(s1);
    275         fflush(stdout);
    276         fflush(stderr);
    277 #endif
    278         func(m,n,s1);
    279         freeService(&s1);
    280         free(s1);
    281         scount++;
    282       }
    283     }
    284   (void)closedir(dirp);
     340  (void) closedir (dirp);
    285341  return 1;
    286342}
    287343
    288 xmlXPathObjectPtr extractFromDoc(xmlDocPtr doc,const char* search){
     344xmlXPathObjectPtr
     345extractFromDoc (xmlDocPtr doc, const char *search)
     346{
    289347  xmlXPathContextPtr xpathCtx;
    290348  xmlXPathObjectPtr xpathObj;
    291   xpathCtx = xmlXPathNewContext(doc);
    292   xpathObj = xmlXPathEvalExpression(BAD_CAST search,xpathCtx);
    293   xmlXPathFreeContext(xpathCtx);
     349  xpathCtx = xmlXPathNewContext (doc);
     350  xpathObj = xmlXPathEvalExpression (BAD_CAST search, xpathCtx);
     351  xmlXPathFreeContext (xpathCtx);
    294352  return xpathObj;
    295353}
    296354
    297 void donothing(int sig){
    298 #ifdef DEBUG
    299   fprintf(stderr,"Signal %d after the ZOO-Kernel returned result !\n",sig);
    300 #endif
    301   exit(0);
     355void
     356donothing (int sig)
     357{
     358#ifdef DEBUG
     359  fprintf (stderr, "Signal %d after the ZOO-Kernel returned result !\n", sig);
     360#endif
     361  exit (0);
    302362}
    303363
    304 void sig_handler(int sig){
     364void
     365sig_handler (int sig)
     366{
    305367  char tmp[100];
    306368  const char *ssig;
    307   switch(sig){
    308   case SIGSEGV:
    309     ssig="SIGSEGV";
    310     break;
    311   case SIGTERM:
    312     ssig="SIGTERM";
    313     break;
    314   case SIGINT:
    315     ssig="SIGINT";
    316     break;
    317   case SIGILL:
    318     ssig="SIGILL";
    319     break;
    320   case SIGFPE:
    321     ssig="SIGFPE";
    322     break;
    323   case SIGABRT:
    324     ssig="SIGABRT";
    325     break;
    326   default:
    327     ssig="UNKNOWN";
    328     break;
    329   }
    330   sprintf(tmp,_("ZOO Kernel failed to process your request receiving signal %d = %s"),sig,ssig);
    331   errorException(NULL, tmp, "InternalError",NULL);
    332 #ifdef DEBUG
    333   fprintf(stderr,"Not this time!\n");
    334 #endif
    335   exit(0);
     369  switch (sig)
     370    {
     371    case SIGSEGV:
     372      ssig = "SIGSEGV";
     373      break;
     374    case SIGTERM:
     375      ssig = "SIGTERM";
     376      break;
     377    case SIGINT:
     378      ssig = "SIGINT";
     379      break;
     380    case SIGILL:
     381      ssig = "SIGILL";
     382      break;
     383    case SIGFPE:
     384      ssig = "SIGFPE";
     385      break;
     386    case SIGABRT:
     387      ssig = "SIGABRT";
     388      break;
     389    default:
     390      ssig = "UNKNOWN";
     391      break;
     392    }
     393  sprintf (tmp,
     394           _
     395           ("ZOO Kernel failed to process your request receiving signal %d = %s"),
     396           sig, ssig);
     397  errorException (NULL, tmp, "InternalError", NULL);
     398#ifdef DEBUG
     399  fprintf (stderr, "Not this time!\n");
     400#endif
     401  exit (0);
    336402}
    337403
    338 void loadServiceAndRun(maps **myMap,service* s1,map* request_inputs,maps **inputs,maps** ioutputs,int* eres){
     404void
     405loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
     406                   maps ** inputs, maps ** ioutputs, int *eres)
     407{
    339408  char tmps1[1024];
    340409  char ntmp[1024];
    341   maps *m=*myMap;
    342   maps *request_output_real_format=*ioutputs;
    343   maps *request_input_real_format=*inputs;
     410  maps *m = *myMap;
     411  maps *request_output_real_format = *ioutputs;
     412  maps *request_input_real_format = *inputs;
    344413  /**
    345414   * Extract serviceType to know what kind of service should be loaded
    346415   */
    347   map* r_inputs=NULL;
     416  map *r_inputs = NULL;
    348417#ifndef WIN32
    349   getcwd(ntmp,1024);
     418  getcwd (ntmp, 1024);
    350419#else
    351   _getcwd(ntmp,1024);
    352 #endif
    353   r_inputs=getMap(s1->content,"serviceType");
    354 #ifdef DEBUG
    355   fprintf(stderr,"LOAD A %s SERVICE PROVIDER \n",r_inputs->value);
    356   fflush(stderr);
    357 #endif
    358   if(strlen(r_inputs->value)==1 && strncasecmp(r_inputs->value,"C",1)==0){
    359     r_inputs=getMap(request_inputs,"metapath");
    360     if(r_inputs!=NULL)
    361       sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
    362     else
    363       sprintf(tmps1,"%s/",ntmp);
    364     char *altPath=zStrdup(tmps1);
    365     r_inputs=getMap(s1->content,"ServiceProvider");
    366     sprintf(tmps1,"%s/%s",altPath,r_inputs->value);
    367     free(altPath);
    368 #ifdef DEBUG
    369     fprintf(stderr,"Trying to load %s\n",tmps1);
     420  _getcwd (ntmp, 1024);
     421#endif
     422  r_inputs = getMap (s1->content, "serviceType");
     423#ifdef DEBUG
     424  fprintf (stderr, "LOAD A %s SERVICE PROVIDER \n", r_inputs->value);
     425  fflush (stderr);
     426#endif
     427  if (strlen (r_inputs->value) == 1
     428      && strncasecmp (r_inputs->value, "C", 1) == 0)
     429    {
     430      r_inputs = getMap (request_inputs, "metapath");
     431      if (r_inputs != NULL)
     432        sprintf (tmps1, "%s/%s", ntmp, r_inputs->value);
     433      else
     434        sprintf (tmps1, "%s/", ntmp);
     435      char *altPath = zStrdup (tmps1);
     436      r_inputs = getMap (s1->content, "ServiceProvider");
     437      sprintf (tmps1, "%s/%s", altPath, r_inputs->value);
     438      free (altPath);
     439#ifdef DEBUG
     440      fprintf (stderr, "Trying to load %s\n", tmps1);
    370441#endif
    371442#ifdef WIN32
    372     HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
     443      HINSTANCE so =
     444        LoadLibraryEx (tmps1, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
    373445#else
    374     void* so = dlopen(tmps1, RTLD_LAZY);
     446      void *so = dlopen (tmps1, RTLD_LAZY);
    375447#endif
    376448#ifdef WIN32
    377     DWORD errstr;
    378     errstr = GetLastError();
     449      DWORD errstr;
     450      errstr = GetLastError ();
    379451#else
    380     char *errstr;
    381     errstr = dlerror();
    382 #endif
    383 #ifdef DEBUG
    384     fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr);
    385 #endif
    386     if( so != NULL ) {
    387 #ifdef DEBUG
    388       fprintf(stderr,"Library loaded %s \n",errstr);
    389       fprintf(stderr,"Service Shared Object = %s\n",r_inputs->value);
    390 #endif
    391       r_inputs=getMap(s1->content,"serviceType");
    392 #ifdef DEBUG
    393       dumpMap(r_inputs);
    394       fprintf(stderr,"%s\n",r_inputs->value);
    395       fflush(stderr);
    396 #endif
    397       if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){
    398         r_inputs=getMap(request_inputs,"Identifier");
    399         char fname[1024];
    400         sprintf(fname,"%s_",r_inputs->value);
    401 #ifdef DEBUG
    402         fprintf(stderr,"Try to load function %s\n",fname);
     452      char *errstr;
     453      errstr = dlerror ();
     454#endif
     455#ifdef DEBUG
     456      fprintf (stderr, "%s loaded (%d) \n", tmps1, errstr);
     457#endif
     458      if (so != NULL)
     459        {
     460#ifdef DEBUG
     461          fprintf (stderr, "Library loaded %s \n", errstr);
     462          fprintf (stderr, "Service Shared Object = %s\n", r_inputs->value);
     463#endif
     464          r_inputs = getMap (s1->content, "serviceType");
     465#ifdef DEBUG
     466          dumpMap (r_inputs);
     467          fprintf (stderr, "%s\n", r_inputs->value);
     468          fflush (stderr);
     469#endif
     470          if (strncasecmp (r_inputs->value, "C-FORTRAN", 9) == 0)
     471            {
     472              r_inputs = getMap (request_inputs, "Identifier");
     473              char fname[1024];
     474              sprintf (fname, "%s_", r_inputs->value);
     475#ifdef DEBUG
     476              fprintf (stderr, "Try to load function %s\n", fname);
    403477#endif
    404478#ifdef WIN32
    405         typedef int (CALLBACK* execute_t)(char***,char***,char***);
    406         execute_t execute=(execute_t)GetProcAddress(so,fname);
     479              typedef int (CALLBACK * execute_t) (char ***, char ***,
     480                                                  char ***);
     481              execute_t execute = (execute_t) GetProcAddress (so, fname);
    407482#else
    408         typedef int (*execute_t)(char***,char***,char***);
    409         execute_t execute=(execute_t)dlsym(so,fname);
     483              typedef int (*execute_t) (char ***, char ***, char ***);
     484              execute_t execute = (execute_t) dlsym (so, fname);
    410485#endif
    411486#ifdef DEBUG
    412487#ifdef WIN32
    413         errstr = GetLastError();
     488              errstr = GetLastError ();
    414489#else
    415         errstr = dlerror();
    416 #endif
    417         fprintf(stderr,"Function loaded %s\n",errstr);
    418 #endif 
    419 
    420         char main_conf[10][30][1024];
    421         char inputs[10][30][1024];
    422         char outputs[10][30][1024];
    423         for(int i=0;i<10;i++){
    424           for(int j=0;j<30;j++){
    425             memset(main_conf[i][j],0,1024);
    426             memset(inputs[i][j],0,1024);
    427             memset(outputs[i][j],0,1024);
    428           }
    429         }
    430         mapsToCharXXX(m,(char***)main_conf);
    431         mapsToCharXXX(request_input_real_format,(char***)inputs);
    432         mapsToCharXXX(request_output_real_format,(char***)outputs);
    433         *eres=execute((char***)&main_conf[0],(char***)&inputs[0],(char***)&outputs[0]);
    434 #ifdef DEBUG
    435         fprintf(stderr,"Function run successfully \n");
    436 #endif
    437         charxxxToMaps((char***)&outputs[0],&request_output_real_format);
    438       }else{
     490              errstr = dlerror ();
     491#endif
     492              fprintf (stderr, "Function loaded %s\n", errstr);
     493#endif
     494
     495              char main_conf[10][30][1024];
     496              char inputs[10][30][1024];
     497              char outputs[10][30][1024];
     498              for (int i = 0; i < 10; i++)
     499                {
     500                  for (int j = 0; j < 30; j++)
     501                    {
     502                      memset (main_conf[i][j], 0, 1024);
     503                      memset (inputs[i][j], 0, 1024);
     504                      memset (outputs[i][j], 0, 1024);
     505                    }
     506                }
     507              mapsToCharXXX (m, (char ***) main_conf);
     508              mapsToCharXXX (request_input_real_format, (char ***) inputs);
     509              mapsToCharXXX (request_output_real_format, (char ***) outputs);
     510              *eres =
     511                execute ((char ***) &main_conf[0], (char ***) &inputs[0],
     512                         (char ***) &outputs[0]);
     513#ifdef DEBUG
     514              fprintf (stderr, "Function run successfully \n");
     515#endif
     516              charxxxToMaps ((char ***) &outputs[0],
     517                             &request_output_real_format);
     518            }
     519          else
     520            {
    439521#ifdef DEBUG
    440522#ifdef WIN32
    441         errstr = GetLastError();
    442         fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr);
    443 #endif
    444 #endif
    445         r_inputs=getMapFromMaps(m,"lenv","Identifier");
    446 #ifdef DEBUG
    447         fprintf(stderr,"Try to load function %s\n",r_inputs->value);
    448 #endif
    449         typedef int (*execute_t)(maps**,maps**,maps**);
     523              errstr = GetLastError ();
     524              fprintf (stderr, "Function %s failed to load because of %d\n",
     525                       r_inputs->value, errstr);
     526#endif
     527#endif
     528              r_inputs = getMapFromMaps (m, "lenv", "Identifier");
     529#ifdef DEBUG
     530              fprintf (stderr, "Try to load function %s\n", r_inputs->value);
     531#endif
     532              typedef int (*execute_t) (maps **, maps **, maps **);
    450533#ifdef WIN32
    451         execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value);
     534              execute_t execute =
     535                (execute_t) GetProcAddress (so, r_inputs->value);
    452536#else
    453         execute_t execute=(execute_t)dlsym(so,r_inputs->value);
    454 #endif
    455 
    456         if(execute==NULL){
     537              execute_t execute = (execute_t) dlsym (so, r_inputs->value);
     538#endif
     539
     540              if (execute == NULL)
     541                {
    457542#ifdef WIN32
    458           errstr = GetLastError();
     543                  errstr = GetLastError ();
    459544#else
    460           errstr = dlerror();
    461 #endif
    462           char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value));
    463           sprintf(tmpMsg,_("Error occured while running the %s function: %s"),r_inputs->value,errstr);
    464           errorException(m, tmpMsg, "InternalError",NULL);
    465           free(tmpMsg);
    466 #ifdef DEBUG
    467           fprintf(stderr,"Function %s error %s\n",r_inputs->value,errstr);
    468 #endif
    469           *eres=-1;
    470           return;
    471         }
     545                  errstr = dlerror ();
     546#endif
     547                  char *tmpMsg =
     548                    (char *) malloc (2048 + strlen (r_inputs->value));
     549                  sprintf (tmpMsg,
     550                           _
     551                           ("Error occured while running the %s function: %s"),
     552                           r_inputs->value, errstr);
     553                  errorException (m, tmpMsg, "InternalError", NULL);
     554                  free (tmpMsg);
     555#ifdef DEBUG
     556                  fprintf (stderr, "Function %s error %s\n", r_inputs->value,
     557                           errstr);
     558#endif
     559                  *eres = -1;
     560                  return;
     561                }
    472562
    473563#ifdef DEBUG
    474564#ifdef WIN32
    475         errstr = GetLastError();
     565              errstr = GetLastError ();
    476566#else
    477         errstr = dlerror();
    478 #endif
    479         fprintf(stderr,"Function loaded %s\n",errstr);
    480 #endif 
    481 
    482 #ifdef DEBUG
    483         fprintf(stderr,"Now run the function \n");
    484         fflush(stderr);
    485 #endif
    486         *eres=execute(&m,&request_input_real_format,&request_output_real_format);
    487 #ifdef DEBUG
    488         fprintf(stderr,"Function loaded and returned %d\n",eres);
    489         fflush(stderr);
    490 #endif
    491       }
     567              errstr = dlerror ();
     568#endif
     569              fprintf (stderr, "Function loaded %s\n", errstr);
     570#endif
     571
     572#ifdef DEBUG
     573              fprintf (stderr, "Now run the function \n");
     574              fflush (stderr);
     575#endif
     576              *eres =
     577                execute (&m, &request_input_real_format,
     578                         &request_output_real_format);
     579#ifdef DEBUG
     580              fprintf (stderr, "Function loaded and returned %d\n", eres);
     581              fflush (stderr);
     582#endif
     583            }
    492584#ifdef WIN32
    493       *ioutputs=dupMaps(&request_output_real_format);
    494       FreeLibrary(so);
     585          *ioutputs = dupMaps (&request_output_real_format);
     586          FreeLibrary (so);
    495587#else
    496       dlclose(so);
    497 #endif
    498     } else {
     588          dlclose (so);
     589#endif
     590        }
     591      else
     592        {
    499593      /**
    500594       * Unable to load the specified shared library
    501595       */
    502       char tmps[1024];
     596          char tmps[1024];
    503597#ifdef WIN32
    504       DWORD errstr = GetLastError();
     598          DWORD errstr = GetLastError ();
    505599#else
    506       char* errstr = dlerror();
    507 #endif
    508       sprintf(tmps,_("C Library can't be loaded %s"),errstr);
    509       map* tmps1=createMap("text",tmps);
    510       printExceptionReportResponse(m,tmps1);
    511       *eres=-1;
    512       freeMap(&tmps1);
    513       free(tmps1);
    514     }
    515   }
     600          char *errstr = dlerror ();
     601#endif
     602          sprintf (tmps, _("C Library can't be loaded %s"), errstr);
     603          map *tmps1 = createMap ("text", tmps);
     604          printExceptionReportResponse (m, tmps1);
     605          *eres = -1;
     606          freeMap (&tmps1);
     607          free (tmps1);
     608        }
     609    }
    516610  else
    517611#ifdef USE_PYTHON
    518     if(strncasecmp(r_inputs->value,"PYTHON",6)==0){
    519       *eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    520     }
    521     else
    522 #endif
    523        
     612  if (strncasecmp (r_inputs->value, "PYTHON", 6) == 0)
     613    {
     614      *eres =
     615        zoo_python_support (&m, request_inputs, s1,
     616                            &request_input_real_format,
     617                            &request_output_real_format);
     618    }
     619  else
     620#endif
     621
    524622#ifdef USE_JAVA
    525       if(strncasecmp(r_inputs->value,"JAVA",4)==0){
    526         *eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    527       }
    528       else
     623  if (strncasecmp (r_inputs->value, "JAVA", 4) == 0)
     624    {
     625      *eres =
     626        zoo_java_support (&m, request_inputs, s1, &request_input_real_format,
     627                          &request_output_real_format);
     628    }
     629  else
    529630#endif
    530631
    531632#ifdef USE_PHP
    532         if(strncasecmp(r_inputs->value,"PHP",3)==0){
    533           *eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    534         }
    535         else
    536 #endif
    537            
    538            
     633  if (strncasecmp (r_inputs->value, "PHP", 3) == 0)
     634    {
     635      *eres =
     636        zoo_php_support (&m, request_inputs, s1, &request_input_real_format,
     637                         &request_output_real_format);
     638    }
     639  else
     640#endif
     641
     642
    539643#ifdef USE_PERL
    540           if(strncasecmp(r_inputs->value,"PERL",4)==0){
    541             *eres=zoo_perl_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    542           }
    543           else
     644  if (strncasecmp (r_inputs->value, "PERL", 4) == 0)
     645    {
     646      *eres =
     647        zoo_perl_support (&m, request_inputs, s1, &request_input_real_format,
     648                          &request_output_real_format);
     649    }
     650  else
    544651#endif
    545652
    546653#ifdef USE_JS
    547             if(strncasecmp(r_inputs->value,"JS",2)==0){
    548               *eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    549             }
    550             else
     654  if (strncasecmp (r_inputs->value, "JS", 2) == 0)
     655    {
     656      *eres =
     657        zoo_js_support (&m, request_inputs, s1, &request_input_real_format,
     658                        &request_output_real_format);
     659    }
     660  else
    551661#endif
    552662
    553663#ifdef USE_RUBY
    554           if(strncasecmp(r_inputs->value,"Ruby",4)==0){
    555             *eres=zoo_ruby_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
    556           }
    557           else
    558 #endif
    559 
    560               {
    561                 char tmpv[1024];
    562                 sprintf(tmpv,_("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),r_inputs->value);
    563                 map* tmps=createMap("text",tmpv);
    564                 printExceptionReportResponse(m,tmps);
    565                 *eres=-1;
    566               }
    567   *myMap=m;
    568   *ioutputs=request_output_real_format;
     664  if (strncasecmp (r_inputs->value, "Ruby", 4) == 0)
     665    {
     666      *eres =
     667        zoo_ruby_support (&m, request_inputs, s1, &request_input_real_format,
     668                          &request_output_real_format);
     669    }
     670  else
     671#endif
     672
     673    {
     674      char tmpv[1024];
     675      sprintf (tmpv,
     676               _
     677               ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),
     678               r_inputs->value);
     679      map *tmps = createMap ("text", tmpv);
     680      printExceptionReportResponse (m, tmps);
     681      *eres = -1;
     682    }
     683  *myMap = m;
     684  *ioutputs = request_output_real_format;
    569685}
    570686
     
    574690 * createProcess function: create a new process after setting some env variables
    575691 */
    576 void createProcess(maps* m,map* request_inputs,service* s1,char* opts,int cpid, maps* inputs,maps* outputs){
     692void
     693createProcess (maps * m, map * request_inputs, service * s1, char *opts,
     694               int cpid, maps * inputs, maps * outputs)
     695{
    577696  STARTUPINFO si;
    578697  PROCESS_INFORMATION pi;
    579   ZeroMemory( &si, sizeof(si) );
    580   si.cb = sizeof(si);
    581   ZeroMemory( &pi, sizeof(pi) );
    582   char *tmp=(char *)malloc((1024+cgiContentLength)*sizeof(char));
    583   char *tmpq=(char *)malloc((1024+cgiContentLength)*sizeof(char));
    584   map *req=getMap(request_inputs,"request");
    585   map *id=getMap(request_inputs,"identifier");
    586   map *di=getMap(request_inputs,"DataInputs");
    587 
    588   char *dataInputsKVP=getMapsAsKVP(inputs,cgiContentLength,0);
    589   char *dataOutputsKVP=getMapsAsKVP(outputs,cgiContentLength,1);
    590 #ifdef DEBUG
    591   fprintf(stderr,"DATAINPUTSKVP %s\n",dataInputsKVP);
    592   fprintf(stderr,"DATAOUTPUTSKVP %s\n",dataOutputsKVP);
    593 #endif
    594   map *sid=getMapFromMaps(m,"lenv","sid");
    595   map* r_inputs=getMapFromMaps(m,"main","tmpPath");
    596   map* r_inputs1=getMap(request_inputs,"metapath");
    597   int hasIn=-1;
    598   if(r_inputs1==NULL){
    599     r_inputs1=createMap("metapath","");
    600     hasIn=1;
    601   }
    602   map* r_inputs2=getMap(request_inputs,"ResponseDocument");
    603   if(r_inputs2==NULL)
    604     r_inputs2=getMap(request_inputs,"RawDataOutput");
    605   map *tmpPath=getMapFromMaps(m,"lenv","cwd");
    606 
    607   map *tmpReq=getMap(request_inputs,"xrequest");
    608   if(r_inputs2!=NULL){
    609     sprintf(tmp,"\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"",r_inputs1->value,req->value,id->value,dataInputsKVP,r_inputs2->name,dataOutputsKVP,sid->value);
    610     sprintf(tmpq,"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",r_inputs1->value,req->value,id->value,dataInputsKVP,r_inputs2->name,dataOutputsKVP);
    611   }
    612   else{
    613     sprintf(tmp,"\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"",r_inputs1->value,req->value,id->value,dataInputsKVP,sid->value);
    614     sprintf(tmpq,"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",r_inputs1->value,req->value,id->value,dataInputsKVP,sid->value);
    615   }
    616  
    617   if(hasIn>0){
    618     freeMap(&r_inputs1);
    619     free(r_inputs1);
    620   }
    621   char *tmp1=zStrdup(tmp);
    622   sprintf(tmp,"\"zoo_loader.cgi\" %s \"%s\"",tmp1,sid->value);
    623  
    624   free(dataInputsKVP);
    625   free(dataOutputsKVP);
    626 #ifdef DEBUG
    627   fprintf(stderr,"REQUEST IS : %s \n",tmp);
    628 #endif
    629   SetEnvironmentVariable("CGISID",TEXT(sid->value));
    630   SetEnvironmentVariable("QUERY_STRING",TEXT(tmpq));
     698  ZeroMemory (&si, sizeof (si));
     699  si.cb = sizeof (si);
     700  ZeroMemory (&pi, sizeof (pi));
     701  char *tmp = (char *) malloc ((1024 + cgiContentLength) * sizeof (char));
     702  char *tmpq = (char *) malloc ((1024 + cgiContentLength) * sizeof (char));
     703  map *req = getMap (request_inputs, "request");
     704  map *id = getMap (request_inputs, "identifier");
     705  map *di = getMap (request_inputs, "DataInputs");
     706
     707  char *dataInputsKVP = getMapsAsKVP (inputs, cgiContentLength, 0);
     708  char *dataOutputsKVP = getMapsAsKVP (outputs, cgiContentLength, 1);
     709#ifdef DEBUG
     710  fprintf (stderr, "DATAINPUTSKVP %s\n", dataInputsKVP);
     711  fprintf (stderr, "DATAOUTPUTSKVP %s\n", dataOutputsKVP);
     712#endif
     713  map *sid = getMapFromMaps (m, "lenv", "sid");
     714  map *r_inputs = getMapFromMaps (m, "main", "tmpPath");
     715  map *r_inputs1 = getMap (request_inputs, "metapath");
     716  int hasIn = -1;
     717  if (r_inputs1 == NULL)
     718    {
     719      r_inputs1 = createMap ("metapath", "");
     720      hasIn = 1;
     721    }
     722  map *r_inputs2 = getMap (request_inputs, "ResponseDocument");
     723  if (r_inputs2 == NULL)
     724    r_inputs2 = getMap (request_inputs, "RawDataOutput");
     725  map *tmpPath = getMapFromMaps (m, "lenv", "cwd");
     726
     727  map *tmpReq = getMap (request_inputs, "xrequest");
     728  if (r_inputs2 != NULL)
     729    {
     730      sprintf (tmp,
     731               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"",
     732               r_inputs1->value, req->value, id->value, dataInputsKVP,
     733               r_inputs2->name, dataOutputsKVP, sid->value);
     734      sprintf (tmpq,
     735               "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",
     736               r_inputs1->value, req->value, id->value, dataInputsKVP,
     737               r_inputs2->name, dataOutputsKVP);
     738    }
     739  else
     740    {
     741      sprintf (tmp,
     742               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"",
     743               r_inputs1->value, req->value, id->value, dataInputsKVP,
     744               sid->value);
     745      sprintf (tmpq,
     746               "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",
     747               r_inputs1->value, req->value, id->value, dataInputsKVP,
     748               sid->value);
     749    }
     750
     751  if (hasIn > 0)
     752    {
     753      freeMap (&r_inputs1);
     754      free (r_inputs1);
     755    }
     756  char *tmp1 = zStrdup (tmp);
     757  sprintf (tmp, "\"zoo_loader.cgi\" %s \"%s\"", tmp1, sid->value);
     758
     759  free (dataInputsKVP);
     760  free (dataOutputsKVP);
     761#ifdef DEBUG
     762  fprintf (stderr, "REQUEST IS : %s \n", tmp);
     763#endif
     764  SetEnvironmentVariable ("CGISID", TEXT (sid->value));
     765  SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq));
    631766  char clen[1000];
    632   sprintf(clen,"%d",strlen(tmpq));
    633   SetEnvironmentVariable("CONTENT_LENGTH",TEXT(clen));
    634  
    635   if( !CreateProcess( NULL,             // No module name (use command line)
    636                       TEXT(tmp),        // Command line
    637                       NULL,             // Process handle not inheritable
    638                       NULL,             // Thread handle not inheritable
    639                       FALSE,            // Set handle inheritance to FALSE
    640                       CREATE_NO_WINDOW, // Apache won't wait until the end
    641                       NULL,             // Use parent's environment block
    642                       NULL,             // Use parent's starting directory
    643                       &si,              // Pointer to STARTUPINFO struct
    644                       &pi )             // Pointer to PROCESS_INFORMATION struct
    645       )
    646     {
    647 #ifdef DEBUG
    648       fprintf( stderr, "CreateProcess failed (%d).\n", GetLastError() );
    649 #endif
    650       return ;
    651     }else{
    652 #ifdef DEBUG
    653     fprintf( stderr, "CreateProcess successfull (%d).\n\n\n\n", GetLastError() );
    654 #endif
    655   }
    656   CloseHandle( pi.hProcess );
    657   CloseHandle( pi.hThread );
    658 #ifdef DEBUG
    659   fprintf(stderr,"CreateProcess finished !\n");
     767  sprintf (clen, "%d", strlen (tmpq));
     768  SetEnvironmentVariable ("CONTENT_LENGTH", TEXT (clen));
     769
     770  if (!CreateProcess (NULL,     // No module name (use command line)
     771                      TEXT (tmp),       // Command line
     772                      NULL,     // Process handle not inheritable
     773                      NULL,     // Thread handle not inheritable
     774                      FALSE,    // Set handle inheritance to FALSE
     775                      CREATE_NO_WINDOW, // Apache won't wait until the end
     776                      NULL,     // Use parent's environment block
     777                      NULL,     // Use parent's starting directory
     778                      &si,      // Pointer to STARTUPINFO struct
     779                      &pi)      // Pointer to PROCESS_INFORMATION struct
     780    )
     781    {
     782#ifdef DEBUG
     783      fprintf (stderr, "CreateProcess failed (%d).\n", GetLastError ());
     784#endif
     785      return;
     786    }
     787  else
     788    {
     789#ifdef DEBUG
     790      fprintf (stderr, "CreateProcess successfull (%d).\n\n\n\n",
     791               GetLastError ());
     792#endif
     793    }
     794  CloseHandle (pi.hProcess);
     795  CloseHandle (pi.hThread);
     796#ifdef DEBUG
     797  fprintf (stderr, "CreateProcess finished !\n");
    660798#endif
    661799}
    662800#endif
    663801
    664 int runRequest(map** inputs)
     802int
     803runRequest (map ** inputs)
    665804{
    666  
     805
    667806#ifndef USE_GDB
    668   signal(SIGCHLD, SIG_IGN);
    669   signal(SIGSEGV,sig_handler);
    670   signal(SIGTERM,sig_handler);
    671   signal(SIGINT,sig_handler);
    672   signal(SIGILL,sig_handler);
    673   signal(SIGFPE,sig_handler);
    674   signal(SIGABRT,sig_handler);
    675 #endif
    676 
    677   map* r_inputs=NULL;
    678   map* request_inputs=*inputs;
    679   maps* m=NULL;
    680   char* REQUEST=NULL;
     807  signal (SIGCHLD, SIG_IGN);
     808  signal (SIGSEGV, sig_handler);
     809  signal (SIGTERM, sig_handler);
     810  signal (SIGINT, sig_handler);
     811  signal (SIGILL, sig_handler);
     812  signal (SIGFPE, sig_handler);
     813  signal (SIGABRT, sig_handler);
     814#endif
     815
     816  map *r_inputs = NULL;
     817  map *request_inputs = *inputs;
     818  maps *m = NULL;
     819  char *REQUEST = NULL;
    681820  /**
    682821   * Parsing service specfic configuration file
    683822   */
    684   m=(maps*)malloc(MAPS_SIZE);
    685   if(m == NULL){
    686     return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    687   }
     823  m = (maps *) malloc (MAPS_SIZE);
     824  if (m == NULL)
     825    {
     826      return errorException (m, _("Unable to allocate memory."),
     827                             "InternalError", NULL);
     828    }
    688829  char ntmp[1024];
    689830#ifndef WIN32
    690   getcwd(ntmp,1024);
     831  getcwd (ntmp, 1024);
    691832#else
    692   _getcwd(ntmp,1024);
    693 #endif
    694   r_inputs=getMapOrFill(&request_inputs,"metapath","");
     833  _getcwd (ntmp, 1024);
     834#endif
     835  r_inputs = getMapOrFill (&request_inputs, "metapath", "");
    695836
    696837
    697838  char conf_file[10240];
    698   snprintf(conf_file,10240,"%s/%s/main.cfg",ntmp,r_inputs->value);
    699   if(conf_read(conf_file,m)==2){
    700     errorException(NULL, _("Unable to load the main.cfg file."),"InternalError",NULL);
    701     free(m);
    702     return 1;
    703   }
    704 #ifdef DEBUG
    705   fprintf(stderr, "***** BEGIN MAPS\n");
    706   dumpMaps(m);
    707   fprintf(stderr, "***** END MAPS\n");
    708 #endif
    709 
    710   map *getPath=getMapFromMaps(m,"main","gettextPath");
    711   if(getPath!=NULL){
    712     bindtextdomain ("zoo-kernel",getPath->value);
    713     bindtextdomain ("zoo-services",getPath->value);   
    714   }else{
    715     bindtextdomain ("zoo-kernel","/usr/share/locale/");
    716     bindtextdomain ("zoo-services","/usr/share/locale/");
    717   }
     839  snprintf (conf_file, 10240, "%s/%s/main.cfg", ntmp, r_inputs->value);
     840  if (conf_read (conf_file, m) == 2)
     841    {
     842      errorException (NULL, _("Unable to load the main.cfg file."),
     843                      "InternalError", NULL);
     844      free (m);
     845      return 1;
     846    }
     847#ifdef DEBUG
     848  fprintf (stderr, "***** BEGIN MAPS\n");
     849  dumpMaps (m);
     850  fprintf (stderr, "***** END MAPS\n");
     851#endif
     852
     853  map *getPath = getMapFromMaps (m, "main", "gettextPath");
     854  if (getPath != NULL)
     855    {
     856      bindtextdomain ("zoo-kernel", getPath->value);
     857      bindtextdomain ("zoo-services", getPath->value);
     858    }
     859  else
     860    {
     861      bindtextdomain ("zoo-kernel", "/usr/share/locale/");
     862      bindtextdomain ("zoo-services", "/usr/share/locale/");
     863    }
    718864
    719865
     
    723869   * headers messages returned by the CGI due to wrong redirection of stderr)
    724870   */
    725   FILE * fstde=NULL;
    726   map* fstdem=getMapFromMaps(m,"main","logPath");
    727   if(fstdem!=NULL)
    728     fstde = freopen(fstdem->value, "a+", stderr) ;
    729 
    730   r_inputs=getMap(request_inputs,"language");
    731   if(r_inputs==NULL)
    732     r_inputs=getMapFromMaps(m,"main","language");
    733   if(r_inputs!=NULL){
    734     if(isValidLang(m,r_inputs->value)<0){
    735       char tmp[1024];
    736       sprintf(tmp,_("The value %s is not supported for the <language> parameter"),
    737               r_inputs->value);
    738       errorException(m, tmp,"InvalidParameterValue","language");
    739       freeMaps(&m);
    740       free(m);
    741       free(REQUEST);
    742       return 1;
    743 
    744     }
    745     char *tmp=zStrdup(r_inputs->value);
    746     setMapInMaps(m,"main","language",tmp);
     871  FILE *fstde = NULL;
     872  map *fstdem = getMapFromMaps (m, "main", "logPath");
     873  if (fstdem != NULL)
     874    fstde = freopen (fstdem->value, "a+", stderr);
     875
     876  r_inputs = getMap (request_inputs, "language");
     877  if (r_inputs == NULL)
     878    r_inputs = getMapFromMaps (m, "main", "language");
     879  if (r_inputs != NULL)
     880    {
     881      if (isValidLang (m, r_inputs->value) < 0)
     882        {
     883          char tmp[1024];
     884          sprintf (tmp,
     885                   _
     886                   ("The value %s is not supported for the <language> parameter"),
     887                   r_inputs->value);
     888          errorException (m, tmp, "InvalidParameterValue", "language");
     889          freeMaps (&m);
     890          free (m);
     891          free (REQUEST);
     892          return 1;
     893
     894        }
     895      char *tmp = zStrdup (r_inputs->value);
     896      setMapInMaps (m, "main", "language", tmp);
    747897#ifdef DEB
    748     char tmp2[12];
    749     sprintf(tmp2,"%s.utf-8",tmp);
    750     translateChar(tmp2,'-','_');
    751     setlocale (LC_ALL, tmp2);
     898      char tmp2[12];
     899      sprintf (tmp2, "%s.utf-8", tmp);
     900      translateChar (tmp2, '-', '_');
     901      setlocale (LC_ALL, tmp2);
    752902#else
    753     translateChar(tmp,'-','_');
    754     setlocale (LC_ALL, tmp);
     903      translateChar (tmp, '-', '_');
     904      setlocale (LC_ALL, tmp);
    755905#endif
    756906#ifndef WIN32
    757     setenv("LC_ALL",tmp,1);
     907      setenv ("LC_ALL", tmp, 1);
    758908#else
    759     char tmp1[12];
    760     sprintf(tmp1,"LC_ALL=%s",tmp);
    761     putenv(tmp1);
    762 #endif
    763     free(tmp);
    764   }
    765   else{
    766     setlocale (LC_ALL, "en_US");
     909      char tmp1[12];
     910      sprintf (tmp1, "LC_ALL=%s", tmp);
     911      putenv (tmp1);
     912#endif
     913      free (tmp);
     914    }
     915  else
     916    {
     917      setlocale (LC_ALL, "en_US");
    767918#ifndef WIN32
    768     setenv("LC_ALL","en_US",1);
     919      setenv ("LC_ALL", "en_US", 1);
    769920#else
    770     char tmp1[12];
    771     sprintf(tmp1,"LC_ALL=en_US");
    772     putenv(tmp1);
    773 #endif
    774     setMapInMaps(m,"main","language","en-US");
    775   }
     921      char tmp1[12];
     922      sprintf (tmp1, "LC_ALL=en_US");
     923      putenv (tmp1);
     924#endif
     925      setMapInMaps (m, "main", "language", "en-US");
     926    }
    776927  setlocale (LC_NUMERIC, "en_US");
    777   bind_textdomain_codeset("zoo-kernel","UTF-8");
    778   textdomain("zoo-kernel");
    779   bind_textdomain_codeset("zoo-services","UTF-8");
    780   textdomain("zoo-services");
    781 
    782   map* lsoap=getMap(request_inputs,"soap");
    783   if(lsoap!=NULL && strcasecmp(lsoap->value,"true")==0)
    784     setMapInMaps(m,"main","isSoap","true");
     928  bind_textdomain_codeset ("zoo-kernel", "UTF-8");
     929  textdomain ("zoo-kernel");
     930  bind_textdomain_codeset ("zoo-services", "UTF-8");
     931  textdomain ("zoo-services");
     932
     933  map *lsoap = getMap (request_inputs, "soap");
     934  if (lsoap != NULL && strcasecmp (lsoap->value, "true") == 0)
     935    setMapInMaps (m, "main", "isSoap", "true");
    785936  else
    786     setMapInMaps(m,"main","isSoap","false");
    787 
    788   if(strlen(cgiServerName)>0){
    789     char tmpUrl[1024];
    790     if(strncmp(cgiServerPort,"80",2)==0){
    791       sprintf(tmpUrl,"http://%s%s",cgiServerName,cgiScriptName);
    792     }else{
    793       sprintf(tmpUrl,"http://%s:%s%s",cgiServerName,cgiServerPort,cgiScriptName);
    794     }
    795 #ifdef DEBUG
    796     fprintf(stderr,"*** %s ***\n",tmpUrl);
    797 #endif
    798     setMapInMaps(m,"main","serverAddress",tmpUrl);
    799   }
     937    setMapInMaps (m, "main", "isSoap", "false");
     938
     939  if (strlen (cgiServerName) > 0)
     940    {
     941      char tmpUrl[1024];
     942      if (strncmp (cgiServerPort, "80", 2) == 0)
     943        {
     944          sprintf (tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
     945        }
     946      else
     947        {
     948          sprintf (tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort,
     949                   cgiScriptName);
     950        }
     951#ifdef DEBUG
     952      fprintf (stderr, "*** %s ***\n", tmpUrl);
     953#endif
     954      setMapInMaps (m, "main", "serverAddress", tmpUrl);
     955    }
    800956
    801957  /**
    802958   * Check for minimum inputs
    803959   */
    804   r_inputs=getMap(request_inputs,"Request");
    805   if(request_inputs==NULL || r_inputs==NULL){
    806     errorException(m, _("Parameter <request> was not specified"),"MissingParameterValue","request");
    807     if(count(request_inputs)==1){
    808       freeMap(&request_inputs);
    809       free(request_inputs);
    810     }
    811     freeMaps(&m);
    812     free(m);
    813     return 1;
    814   }
    815   else{
    816     REQUEST=zStrdup(r_inputs->value);
    817     if(strncasecmp(r_inputs->value,"GetCapabilities",15)!=0
    818        && strncasecmp(r_inputs->value,"DescribeProcess",15)!=0
    819        && strncasecmp(r_inputs->value,"Execute",7)!=0){
    820       errorException(m, _("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), "OperationNotSupported",r_inputs->value);
    821       freeMaps(&m);
    822       free(m);
    823       free(REQUEST);
     960  r_inputs = getMap (request_inputs, "Request");
     961  if (request_inputs == NULL || r_inputs == NULL)
     962    {
     963      errorException (m, _("Parameter <request> was not specified"),
     964                      "MissingParameterValue", "request");
     965      if (count (request_inputs) == 1)
     966        {
     967          freeMap (&request_inputs);
     968          free (request_inputs);
     969        }
     970      freeMaps (&m);
     971      free (m);
    824972      return 1;
    825973    }
    826   }
    827   r_inputs=NULL;
    828   r_inputs=getMap(request_inputs,"Service");
    829   if(r_inputs==NULLMAP){
    830     errorException(m, _("Parameter <service> was not specified"),"MissingParameterValue","service");
    831     freeMaps(&m);
    832     free(m);
    833     free(REQUEST);
    834     return 1;
    835   }else{
    836     if(strcasecmp(r_inputs->value,"WPS")!=0){
    837       errorException(m, _("Unenderstood <service> value, WPS is the only acceptable value."), "InvalidParameterValue","service");
    838       freeMaps(&m);
    839       free(m);
    840       free(REQUEST);
     974  else
     975    {
     976      REQUEST = zStrdup (r_inputs->value);
     977      if (strncasecmp (r_inputs->value, "GetCapabilities", 15) != 0
     978          && strncasecmp (r_inputs->value, "DescribeProcess", 15) != 0
     979          && strncasecmp (r_inputs->value, "Execute", 7) != 0)
     980        {
     981          errorException (m,
     982                          _
     983                          ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."),
     984                          "OperationNotSupported", r_inputs->value);
     985          freeMaps (&m);
     986          free (m);
     987          free (REQUEST);
     988          return 1;
     989        }
     990    }
     991  r_inputs = NULL;
     992  r_inputs = getMap (request_inputs, "Service");
     993  if (r_inputs == NULLMAP)
     994    {
     995      errorException (m, _("Parameter <service> was not specified"),
     996                      "MissingParameterValue", "service");
     997      freeMaps (&m);
     998      free (m);
     999      free (REQUEST);
    8411000      return 1;
    8421001    }
    843   }
    844   if(strncasecmp(REQUEST,"GetCapabilities",15)!=0){
    845     r_inputs=getMap(request_inputs,"Version");
    846     if(r_inputs==NULL){
    847       errorException(m, _("Parameter <version> was not specified"),"MissingParameterValue","version");
    848       freeMaps(&m);
    849       free(m);
    850       free(REQUEST);
    851       return 1;
    852     }else{
    853       if(strcasecmp(r_inputs->value,"1.0.0")!=0){
    854         errorException(m, _("Unenderstood <version> value, 1.0.0 is the only acceptable value."), "InvalidParameterValue","service");
    855         freeMaps(&m);
    856         free(m);
    857         free(REQUEST);
    858         return 1;
    859       }
    860     }
    861   }else{
    862     r_inputs=getMap(request_inputs,"AcceptVersions");
    863     if(r_inputs!=NULL){
    864       if(strncmp(r_inputs->value,"1.0.0",5)!=0){
    865         errorException(m, _("Unenderstood <AcceptVersions> value, 1.0.0 is the only acceptable value."), "VersionNegotiationFailed",NULL);
    866         freeMaps(&m);
    867         free(m);
    868         free(REQUEST);
    869         return 1;
    870       }
    871     }
    872   }
    873 
    874   r_inputs=getMap(request_inputs,"serviceprovider");
    875   if(r_inputs==NULL){
    876     addToMap(request_inputs,"serviceprovider","");
    877   }
    878 
    879   maps* request_output_real_format=NULL;
    880   map* tmpm=getMapFromMaps(m,"main","serverAddress");
    881   if(tmpm!=NULL)
    882     SERVICE_URL=zStrdup(tmpm->value);
    8831002  else
    884     SERVICE_URL=zStrdup(DEFAULT_SERVICE_URL);
    885 
    886   service* s1;
    887   int scount=0;
    888 #ifdef DEBUG
    889   dumpMap(r_inputs);
     1003    {
     1004      if (strcasecmp (r_inputs->value, "WPS") != 0)
     1005        {
     1006          errorException (m,
     1007                          _
     1008                          ("Unenderstood <service> value, WPS is the only acceptable value."),
     1009                          "InvalidParameterValue", "service");
     1010          freeMaps (&m);
     1011          free (m);
     1012          free (REQUEST);
     1013          return 1;
     1014        }
     1015    }
     1016  if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0)
     1017    {
     1018      r_inputs = getMap (request_inputs, "Version");
     1019      if (r_inputs == NULL)
     1020        {
     1021          errorException (m, _("Parameter <version> was not specified"),
     1022                          "MissingParameterValue", "version");
     1023          freeMaps (&m);
     1024          free (m);
     1025          free (REQUEST);
     1026          return 1;
     1027        }
     1028      else
     1029        {
     1030          if (strcasecmp (r_inputs->value, "1.0.0") != 0)
     1031            {
     1032              errorException (m,
     1033                              _
     1034                              ("Unenderstood <version> value, 1.0.0 is the only acceptable value."),
     1035                              "InvalidParameterValue", "service");
     1036              freeMaps (&m);
     1037              free (m);
     1038              free (REQUEST);
     1039              return 1;
     1040            }
     1041        }
     1042    }
     1043  else
     1044    {
     1045      r_inputs = getMap (request_inputs, "AcceptVersions");
     1046      if (r_inputs != NULL)
     1047        {
     1048          if (strncmp (r_inputs->value, "1.0.0", 5) != 0)
     1049            {
     1050              errorException (m,
     1051                              _
     1052                              ("Unenderstood <AcceptVersions> value, 1.0.0 is the only acceptable value."),
     1053                              "VersionNegotiationFailed", NULL);
     1054              freeMaps (&m);
     1055              free (m);
     1056              free (REQUEST);
     1057              return 1;
     1058            }
     1059        }
     1060    }
     1061
     1062  r_inputs = getMap (request_inputs, "serviceprovider");
     1063  if (r_inputs == NULL)
     1064    {
     1065      addToMap (request_inputs, "serviceprovider", "");
     1066    }
     1067
     1068  maps *request_output_real_format = NULL;
     1069  map *tmpm = getMapFromMaps (m, "main", "serverAddress");
     1070  if (tmpm != NULL)
     1071    SERVICE_URL = zStrdup (tmpm->value);
     1072  else
     1073    SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL);
     1074
     1075  service *s1;
     1076  int scount = 0;
     1077#ifdef DEBUG
     1078  dumpMap (r_inputs);
    8901079#endif
    8911080  char conf_dir[1024];
     
    8931082  char tmps1[1024];
    8941083
    895   r_inputs=NULL;
    896   r_inputs=getMap(request_inputs,"metapath");
    897   if(r_inputs!=NULL)
    898     snprintf(conf_dir,1024,"%s/%s",ntmp,r_inputs->value);
     1084  r_inputs = NULL;
     1085  r_inputs = getMap (request_inputs, "metapath");
     1086  if (r_inputs != NULL)
     1087    snprintf (conf_dir, 1024, "%s/%s", ntmp, r_inputs->value);
    8991088  else
    900     snprintf(conf_dir,1024,"%s",ntmp);
    901 
    902   if(strncasecmp(REQUEST,"GetCapabilities",15)==0){
    903 #ifdef DEBUG
    904     dumpMap(r_inputs);
    905 #endif
    906     xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
    907     r_inputs=NULL;
    908     r_inputs=getMap(request_inputs,"ServiceProvider");
    909     xmlNodePtr n;
    910     if(r_inputs!=NULL)
    911       n = printGetCapabilitiesHeader(doc,r_inputs->value,m);
    912     else
    913       n = printGetCapabilitiesHeader(doc,"",m);
     1089    snprintf (conf_dir, 1024, "%s", ntmp);
     1090
     1091  if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0)
     1092    {
     1093#ifdef DEBUG
     1094      dumpMap (r_inputs);
     1095#endif
     1096      xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
     1097      r_inputs = NULL;
     1098      r_inputs = getMap (request_inputs, "ServiceProvider");
     1099      xmlNodePtr n;
     1100      if (r_inputs != NULL)
     1101        n = printGetCapabilitiesHeader (doc, r_inputs->value, m);
     1102      else
     1103        n = printGetCapabilitiesHeader (doc, "", m);
    9141104    /**
    9151105     * Here we need to close stdout to ensure that not supported chars
    9161106     * has been found in the zcfg and then printed on stdout
    9171107     */
    918     int saved_stdout = dup(fileno(stdout));
    919     dup2(fileno(stderr),fileno(stdout));
    920     if(int res=recursReaddirF(m,n,conf_dir,NULL,saved_stdout,0,printGetCapabilitiesForProcess)<0){
    921       freeMaps(&m);
    922       free(m);
    923       free(REQUEST);
    924       free(SERVICE_URL);
    925       fflush(stdout);
    926       return res;
    927     }
    928     dup2(saved_stdout,fileno(stdout));
    929     printDocument(m,doc,getpid());
    930     freeMaps(&m);
    931     free(m);
    932     free(REQUEST);
    933     free(SERVICE_URL);
    934     fflush(stdout);
    935     return 0;
    936   }
    937   else{
    938     r_inputs=getMap(request_inputs,"Identifier");
    939     if(r_inputs==NULL
    940        || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){
    941       errorException(m, _("Mandatory <identifier> was not specified"),"MissingParameterValue","identifier");
    942       freeMaps(&m);
    943       free(m);
    944       free(REQUEST);
    945       free(SERVICE_URL);
     1108      int saved_stdout = dup (fileno (stdout));
     1109      dup2 (fileno (stderr), fileno (stdout));
     1110      if (int res =
     1111          recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,
     1112                          printGetCapabilitiesForProcess) < 0)
     1113        {
     1114          freeMaps (&m);
     1115          free (m);
     1116          free (REQUEST);
     1117          free (SERVICE_URL);
     1118          fflush (stdout);
     1119          return res;
     1120        }
     1121      dup2 (saved_stdout, fileno (stdout));
     1122      printDocument (m, doc, getpid ());
     1123      freeMaps (&m);
     1124      free (m);
     1125      free (REQUEST);
     1126      free (SERVICE_URL);
     1127      fflush (stdout);
    9461128      return 0;
    9471129    }
    948 
    949     struct dirent *dp;
    950     DIR *dirp = opendir(conf_dir);
    951     if(dirp==NULL){
    952       errorException(m, _("The specified path path doesn't exist."),"InvalidParameterValue",conf_dir);
    953       freeMaps(&m);
    954       free(m);
    955       free(REQUEST);
    956       free(SERVICE_URL);
    957       return 0;
    958     }
    959     if(strncasecmp(REQUEST,"DescribeProcess",15)==0){
     1130  else
     1131    {
     1132      r_inputs = getMap (request_inputs, "Identifier");
     1133      if (r_inputs == NULL
     1134          || strlen (r_inputs->name) == 0 || strlen (r_inputs->value) == 0)
     1135        {
     1136          errorException (m, _("Mandatory <identifier> was not specified"),
     1137                          "MissingParameterValue", "identifier");
     1138          freeMaps (&m);
     1139          free (m);
     1140          free (REQUEST);
     1141          free (SERVICE_URL);
     1142          return 0;
     1143        }
     1144
     1145      struct dirent *dp;
     1146      DIR *dirp = opendir (conf_dir);
     1147      if (dirp == NULL)
     1148        {
     1149          errorException (m, _("The specified path path doesn't exist."),
     1150                          "InvalidParameterValue", conf_dir);
     1151          freeMaps (&m);
     1152          free (m);
     1153          free (REQUEST);
     1154          free (SERVICE_URL);
     1155          return 0;
     1156        }
     1157      if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
     1158        {
    9601159      /**
    9611160       * Loop over Identifier list
    9621161       */
    963       xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
    964       r_inputs=NULL;
    965       r_inputs=getMap(request_inputs,"ServiceProvider");
    966 
    967       xmlNodePtr n;
    968       if(r_inputs!=NULL)
    969         n = printDescribeProcessHeader(doc,r_inputs->value,m);
    970       else
    971         n = printDescribeProcessHeader(doc,"",m);
    972 
    973       r_inputs=getMap(request_inputs,"Identifier");
    974      
    975       char *orig=zStrdup(r_inputs->value);
    976 
    977       int saved_stdout = dup(fileno(stdout));
    978       dup2(fileno(stderr),fileno(stdout));
    979       if(strcasecmp("all",orig)==0){
    980         if(int res=recursReaddirF(m,n,conf_dir,NULL,saved_stdout,0,printDescribeProcessForProcess)<0)
    981           return res;
    982       }
    983       else{
    984         char *saveptr;
    985         char *tmps=strtok_r(orig,",",&saveptr);
    986        
    987         char buff[256];
    988         char buff1[1024];
    989         while(tmps!=NULL){
    990           int hasVal=-1;
    991           char *corig=zStrdup(tmps);
    992           if(strstr(corig,".")!=NULL){
    993            
    994             parseIdentifier(m,conf_dir,corig,buff1);
    995             map* tmpMap=getMapFromMaps(m,"lenv","metapath");
    996             if(tmpMap!=NULL)
    997               addToMap(request_inputs,"metapath",tmpMap->value);
    998             map* tmpMapI=getMapFromMaps(m,"lenv","Identifier");
    999 
    1000             s1=(service*)malloc(SERVICE_SIZE);
    1001             t=readServiceFile(m,buff1,&s1,tmpMapI->value);
    1002             if(t<0){
    1003               map* tmp00=getMapFromMaps(m,"lenv","message");
    1004               char tmp01[1024];
    1005               if(tmp00!=NULL)
    1006                 sprintf(tmp01,_("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),tmps,tmp00->value);
    1007               else
    1008                 sprintf(tmp01,_("Unable to parse the ZCFG file for the following ZOO-Service: %s."),tmps);
    1009               dup2(saved_stdout,fileno(stdout));
    1010               errorException(m, tmp01,"InvalidParameterValue","identifier");
    1011               freeMaps(&m);
    1012               free(m);
    1013               free(REQUEST);
    1014               free(corig);
    1015               free(orig);
    1016               free(SERVICE_URL);
    1017               free(s1);
    1018               closedir(dirp);
    1019               xmlFreeDoc(doc);
    1020               xmlCleanupParser();
    1021               zooXmlCleanupNs();
    1022               return 1;
    1023             }
    1024 #ifdef DEBUG
    1025             dumpService(s1);
    1026 #endif
    1027             printDescribeProcessForProcess(m,n,s1);
    1028             freeService(&s1);
    1029             free(s1);
    1030             s1=NULL;
    1031             scount++;
    1032             hasVal=1;
    1033             setMapInMaps(m,"lenv","level","0");
    1034           }else{
    1035             memset(buff,0,256);
    1036             snprintf(buff,256,"%s.zcfg",corig);
    1037             memset(buff1,0,1024);
    1038 #ifdef DEBUG
    1039             printf("\n#######%s\n########\n",buff);
    1040 #endif
    1041             while ((dp = readdir(dirp)) != NULL){
    1042               if( strcasecmp(dp->d_name,buff)==0 ){
    1043                 memset(buff1,0,1024);
    1044                 snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name);
    1045                 s1=(service*)malloc(SERVICE_SIZE);
    1046                 if(s1 == NULL){
    1047                   dup2(saved_stdout,fileno(stdout));
    1048                   return errorException(m, _("Unable to allocate memory."),"InternalError",NULL);
    1049                 }
    1050 #ifdef DEBUG
    1051                 printf("#################\n(%s) %s\n#################\n",r_inputs->value,buff1);
    1052 #endif
    1053                 char *tmp0=zStrdup(dp->d_name);
    1054                 tmp0[strlen(tmp0)-5]=0;
    1055                 t=readServiceFile(m,buff1,&s1,tmp0);
    1056                 free(tmp0);
    1057                 if(t<0){
    1058                   map* tmp00=getMapFromMaps(m,"lenv","message");
    1059                   char tmp01[1024];
    1060                   if(tmp00!=NULL)
    1061                     sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),dp->d_name,tmp00->value);
    1062                   else
    1063                     sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),dp->d_name);
    1064                   dup2(saved_stdout,fileno(stdout));
    1065                   errorException(m, tmp01,"InternalError",NULL);
    1066                   freeMaps(&m);
    1067                   free(m);
    1068                   free(orig);
    1069                   free(REQUEST);
    1070                   closedir(dirp);
    1071                   xmlFreeDoc(doc);
    1072                   xmlCleanupParser();
    1073                   zooXmlCleanupNs();
    1074                   return 1;
    1075                 }
    1076 #ifdef DEBUG
    1077                 dumpService(s1);
    1078 #endif
    1079                 printDescribeProcessForProcess(m,n,s1);
    1080                 freeService(&s1);
    1081                 free(s1);
    1082                 s1=NULL;
    1083                 scount++;
    1084                 hasVal=1;
    1085               }
    1086             }
    1087           }
    1088           if(hasVal<0){
    1089             map* tmp00=getMapFromMaps(m,"lenv","message");
    1090             char tmp01[1024];
    1091             if(tmp00!=NULL)
    1092               sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),buff,tmp00->value);
    1093             else
    1094               sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),buff);
    1095             dup2(saved_stdout,fileno(stdout));
    1096             errorException(m, tmp01,"InvalidParameterValue","Identifier");
    1097             freeMaps(&m);
    1098             free(m);
    1099             free(orig);
    1100             free(REQUEST);
    1101             closedir(dirp);
    1102             xmlFreeDoc(doc);
    1103             xmlCleanupParser();
    1104             zooXmlCleanupNs();
    1105             return 1;
    1106           }
    1107           rewinddir(dirp);
    1108           tmps=strtok_r(NULL,",",&saveptr);
    1109           if(corig!=NULL)
    1110             free(corig);
    1111         }
    1112       }
    1113       closedir(dirp);
    1114       fflush(stdout);
    1115       dup2(saved_stdout,fileno(stdout));
    1116       free(orig);
    1117       printDocument(m,doc,getpid());
    1118       freeMaps(&m);
    1119       free(m);
    1120       free(REQUEST);
    1121       free(SERVICE_URL);
    1122       fflush(stdout);
     1162          xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
     1163          r_inputs = NULL;
     1164          r_inputs = getMap (request_inputs, "ServiceProvider");
     1165
     1166          xmlNodePtr n;
     1167          if (r_inputs != NULL)
     1168            n = printDescribeProcessHeader (doc, r_inputs->value, m);
     1169          else
     1170            n = printDescribeProcessHeader (doc, "", m);
     1171
     1172          r_inputs = getMap (request_inputs, "Identifier");
     1173
     1174          char *orig = zStrdup (r_inputs->value);
     1175
     1176          int saved_stdout = dup (fileno (stdout));
     1177          dup2 (fileno (stderr), fileno (stdout));
     1178          if (strcasecmp ("all", orig) == 0)
     1179            {
     1180              if (int res =
     1181                  recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,
     1182                                  printDescribeProcessForProcess) < 0)
     1183                return res;
     1184            }
     1185          else
     1186            {
     1187              char *saveptr;
     1188              char *tmps = strtok_r (orig, ",", &saveptr);
     1189
     1190              char buff[256];
     1191              char buff1[1024];
     1192              while (tmps != NULL)
     1193                {
     1194                  int hasVal = -1;
     1195                  char *corig = zStrdup (tmps);
     1196                  if (strstr (corig, ".") != NULL)
     1197                    {
     1198
     1199                      parseIdentifier (m, conf_dir, corig, buff1);
     1200                      map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
     1201                      if (tmpMap != NULL)
     1202                        addToMap (request_inputs, "metapath", tmpMap->value);
     1203                      map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
     1204
     1205                      s1 = (service *) malloc (SERVICE_SIZE);
     1206                      t = readServiceFile (m, buff1, &s1, tmpMapI->value);
     1207                      if (t < 0)
     1208                        {
     1209                          map *tmp00 = getMapFromMaps (m, "lenv", "message");
     1210                          char tmp01[1024];
     1211                          if (tmp00 != NULL)
     1212                            sprintf (tmp01,
     1213                                     _
     1214                                     ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
     1215                                     tmps, tmp00->value);
     1216                          else
     1217                            sprintf (tmp01,
     1218                                     _
     1219                                     ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
     1220                                     tmps);
     1221                          dup2 (saved_stdout, fileno (stdout));
     1222                          errorException (m, tmp01, "InvalidParameterValue",
     1223                                          "identifier");
     1224                          freeMaps (&m);
     1225                          free (m);
     1226                          free (REQUEST);
     1227                          free (corig);
     1228                          free (orig);
     1229                          free (SERVICE_URL);
     1230                          free (s1);
     1231                          closedir (dirp);
     1232                          xmlFreeDoc (doc);
     1233                          xmlCleanupParser ();
     1234                          zooXmlCleanupNs ();
     1235                          return 1;
     1236                        }
     1237#ifdef DEBUG
     1238                      dumpService (s1);
     1239#endif
     1240                      printDescribeProcessForProcess (m, n, s1);
     1241                      freeService (&s1);
     1242                      free (s1);
     1243                      s1 = NULL;
     1244                      scount++;
     1245                      hasVal = 1;
     1246                      setMapInMaps (m, "lenv", "level", "0");
     1247                    }
     1248                  else
     1249                    {
     1250                      memset (buff, 0, 256);
     1251                      snprintf (buff, 256, "%s.zcfg", corig);
     1252                      memset (buff1, 0, 1024);
     1253#ifdef DEBUG
     1254                      printf ("\n#######%s\n########\n", buff);
     1255#endif
     1256                      while ((dp = readdir (dirp)) != NULL)
     1257                        {
     1258                          if (strcasecmp (dp->d_name, buff) == 0)
     1259                            {
     1260                              memset (buff1, 0, 1024);
     1261                              snprintf (buff1, 1024, "%s/%s", conf_dir,
     1262                                        dp->d_name);
     1263                              s1 = (service *) malloc (SERVICE_SIZE);
     1264                              if (s1 == NULL)
     1265                                {
     1266                                  dup2 (saved_stdout, fileno (stdout));
     1267                                  return errorException (m,
     1268                                                         _
     1269                                                         ("Unable to allocate memory."),
     1270                                                         "InternalError",
     1271                                                         NULL);
     1272                                }
     1273#ifdef DEBUG
     1274                              printf
     1275                                ("#################\n(%s) %s\n#################\n",
     1276                                 r_inputs->value, buff1);
     1277#endif
     1278                              char *tmp0 = zStrdup (dp->d_name);
     1279                              tmp0[strlen (tmp0) - 5] = 0;
     1280                              t = readServiceFile (m, buff1, &s1, tmp0);
     1281                              free (tmp0);
     1282                              if (t < 0)
     1283                                {
     1284                                  map *tmp00 =
     1285                                    getMapFromMaps (m, "lenv", "message");
     1286                                  char tmp01[1024];
     1287                                  if (tmp00 != NULL)
     1288                                    sprintf (tmp01,
     1289                                             _
     1290                                             ("Unable to parse the ZCFG file: %s (%s)"),
     1291                                             dp->d_name, tmp00->value);
     1292                                  else
     1293                                    sprintf (tmp01,
     1294                                             _
     1295                                             ("Unable to parse the ZCFG file: %s."),
     1296                                             dp->d_name);
     1297                                  dup2 (saved_stdout, fileno (stdout));
     1298                                  errorException (m, tmp01, "InternalError",
     1299                                                  NULL);
     1300                                  freeMaps (&m);
     1301                                  free (m);
     1302                                  free (orig);
     1303                                  free (REQUEST);
     1304                                  closedir (dirp);
     1305                                  xmlFreeDoc (doc);
     1306                                  xmlCleanupParser ();
     1307                                  zooXmlCleanupNs ();
     1308                                  return 1;
     1309                                }
     1310#ifdef DEBUG
     1311                              dumpService (s1);
     1312#endif
     1313                              printDescribeProcessForProcess (m, n, s1);
     1314                              freeService (&s1);
     1315                              free (s1);
     1316                              s1 = NULL;
     1317                              scount++;
     1318                              hasVal = 1;
     1319                            }
     1320                        }
     1321                    }
     1322                  if (hasVal < 0)
     1323                    {
     1324                      map *tmp00 = getMapFromMaps (m, "lenv", "message");
     1325                      char tmp01[1024];
     1326                      if (tmp00 != NULL)
     1327                        sprintf (tmp01,
     1328                                 _("Unable to parse the ZCFG file: %s (%s)"),
     1329                                 buff, tmp00->value);
     1330                      else
     1331                        sprintf (tmp01,
     1332                                 _("Unable to parse the ZCFG file: %s."),
     1333                                 buff);
     1334                      dup2 (saved_stdout, fileno (stdout));
     1335                      errorException (m, tmp01, "InvalidParameterValue",
     1336                                      "Identifier");
     1337                      freeMaps (&m);
     1338                      free (m);
     1339                      free (orig);
     1340                      free (REQUEST);
     1341                      closedir (dirp);
     1342                      xmlFreeDoc (doc);
     1343                      xmlCleanupParser ();
     1344                      zooXmlCleanupNs ();
     1345                      return 1;
     1346                    }
     1347                  rewinddir (dirp);
     1348                  tmps = strtok_r (NULL, ",", &saveptr);
     1349                  if (corig != NULL)
     1350                    free (corig);
     1351                }
     1352            }
     1353          closedir (dirp);
     1354          fflush (stdout);
     1355          dup2 (saved_stdout, fileno (stdout));
     1356          free (orig);
     1357          printDocument (m, doc, getpid ());
     1358          freeMaps (&m);
     1359          free (m);
     1360          free (REQUEST);
     1361          free (SERVICE_URL);
     1362          fflush (stdout);
     1363          return 0;
     1364        }
     1365      else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
     1366        {
     1367          errorException (m,
     1368                          _
     1369                          ("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."),
     1370                          "InvalidParameterValue", "request");
     1371#ifdef DEBUG
     1372          fprintf (stderr, "No request found %s", REQUEST);
     1373#endif
     1374          closedir (dirp);
     1375          freeMaps (&m);
     1376          free (m);
     1377          free (REQUEST);
     1378          free (SERVICE_URL);
     1379          fflush (stdout);
     1380          return 0;
     1381        }
     1382      closedir (dirp);
     1383    }
     1384
     1385  s1 = NULL;
     1386  s1 = (service *) malloc (SERVICE_SIZE);
     1387  if (s1 == NULL)
     1388    {
     1389      freeMaps (&m);
     1390      free (m);
     1391      free (REQUEST);
     1392      free (SERVICE_URL);
     1393      return errorException (m, _("Unable to allocate memory."),
     1394                             "InternalError", NULL);
     1395    }
     1396  r_inputs = getMap (request_inputs, "MetaPath");
     1397  if (r_inputs != NULL)
     1398    snprintf (tmps1, 1024, "%s/%s", ntmp, r_inputs->value);
     1399  else
     1400    snprintf (tmps1, 1024, "%s/", ntmp);
     1401  r_inputs = getMap (request_inputs, "Identifier");
     1402  char *ttmp = zStrdup (tmps1);
     1403  snprintf (tmps1, 1024, "%s/%s.zcfg", ttmp, r_inputs->value);
     1404  free (ttmp);
     1405#ifdef DEBUG
     1406  fprintf (stderr, "Trying to load %s\n", tmps1);
     1407#endif
     1408  if (strstr (r_inputs->value, ".") != NULL)
     1409    {
     1410      char *identifier = zStrdup (r_inputs->value);
     1411      parseIdentifier (m, conf_dir, identifier, tmps1);
     1412      map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
     1413      if (tmpMap != NULL)
     1414        addToMap (request_inputs, "metapath", tmpMap->value);
     1415      free (identifier);
     1416    }
     1417  else
     1418    {
     1419      setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
     1420      setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
     1421    }
     1422
     1423  r_inputs = getMapFromMaps (m, "lenv", "Identifier");
     1424  int saved_stdout = dup (fileno (stdout));
     1425  dup2 (fileno (stderr), fileno (stdout));
     1426  t = readServiceFile (m, tmps1, &s1, r_inputs->value);
     1427  fflush (stdout);
     1428  dup2 (saved_stdout, fileno (stdout));
     1429  if (t < 0)
     1430    {
     1431      char *tmpMsg = (char *) malloc (2048 + strlen (r_inputs->value));
     1432      sprintf (tmpMsg,
     1433               _
     1434               ("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),
     1435               r_inputs->value);
     1436      errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
     1437      free (tmpMsg);
     1438      free (s1);
     1439      freeMaps (&m);
     1440      free (m);
     1441      free (REQUEST);
     1442      free (SERVICE_URL);
    11231443      return 0;
    11241444    }
    1125     else
    1126       if(strncasecmp(REQUEST,"Execute",strlen(REQUEST))!=0){
    1127         errorException(m, _("Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute."), "InvalidParameterValue","request");
    1128 #ifdef DEBUG
    1129         fprintf(stderr,"No request found %s",REQUEST);
    1130 #endif 
    1131         closedir(dirp);
    1132         freeMaps(&m);
    1133         free(m);
    1134         free(REQUEST);
    1135         free(SERVICE_URL);
    1136         fflush(stdout);
    1137         return 0;
    1138       }
    1139     closedir(dirp);
    1140   }
    1141  
    1142   s1=NULL;
    1143   s1=(service*)malloc(SERVICE_SIZE);
    1144   if(s1 == NULL){
    1145     freeMaps(&m);
    1146     free(m);
    1147     free(REQUEST);
    1148     free(SERVICE_URL);
    1149     return errorException(m, _("Unable to allocate memory."),"InternalError",NULL);
    1150   }
    1151   r_inputs=getMap(request_inputs,"MetaPath");
    1152   if(r_inputs!=NULL)
    1153     snprintf(tmps1,1024,"%s/%s",ntmp,r_inputs->value);
    1154   else
    1155     snprintf(tmps1,1024,"%s/",ntmp);
    1156   r_inputs=getMap(request_inputs,"Identifier");
    1157   char *ttmp=zStrdup(tmps1);
    1158   snprintf(tmps1,1024,"%s/%s.zcfg",ttmp,r_inputs->value);
    1159   free(ttmp);
    1160 #ifdef DEBUG
    1161   fprintf(stderr,"Trying to load %s\n", tmps1);
    1162 #endif
    1163   if(strstr(r_inputs->value,".")!=NULL){
    1164     char *identifier=zStrdup(r_inputs->value);
    1165     parseIdentifier(m,conf_dir,identifier,tmps1);
    1166     map* tmpMap=getMapFromMaps(m,"lenv","metapath");
    1167     if(tmpMap!=NULL)
    1168       addToMap(request_inputs,"metapath",tmpMap->value);
    1169     free(identifier);
    1170   }else{
    1171     setMapInMaps(m,"lenv","Identifier",r_inputs->value);
    1172     setMapInMaps(m,"lenv","oIdentifier",r_inputs->value);
    1173   }
    1174 
    1175   r_inputs=getMapFromMaps(m,"lenv","Identifier");
    1176   int saved_stdout = dup(fileno(stdout));
    1177   dup2(fileno(stderr),fileno(stdout));
    1178   t=readServiceFile(m,tmps1,&s1,r_inputs->value);
    1179   fflush(stdout);
    1180   dup2(saved_stdout,fileno(stdout));
    1181   if(t<0){
    1182     char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value));
    1183     sprintf(tmpMsg,_("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),r_inputs->value);
    1184     errorException(m, tmpMsg, "InvalidParameterValue","identifier");
    1185     free(tmpMsg);
    1186     free(s1);
    1187     freeMaps(&m);
    1188     free(m);
    1189     free(REQUEST);
    1190     free(SERVICE_URL);
    1191     return 0;
    1192   }
    1193   close(saved_stdout);
    1194 
    1195 #ifdef DEBUG
    1196   dumpService(s1);
     1445  close (saved_stdout);
     1446
     1447#ifdef DEBUG
     1448  dumpService (s1);
    11971449#endif
    11981450  int j;
    1199  
     1451
    12001452
    12011453  /**
    12021454   * Create the input and output maps data structure
    12031455   */
    1204   int i=0;
     1456  int i = 0;
    12051457  HINTERNET hInternet;
    12061458  HINTERNET res;
    1207   hInternet=InternetOpen(
     1459  hInternet = InternetOpen (
    12081460#ifndef WIN32
    1209                          (LPCTSTR)
    1210 #endif
    1211                          "ZooWPSClient\0",
    1212                          INTERNET_OPEN_TYPE_PRECONFIG,
    1213                          NULL,NULL, 0);
     1461                             (LPCTSTR)
     1462#endif
     1463                             "ZooWPSClient\0",
     1464                             INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    12141465
    12151466#ifndef WIN32
    1216   if(!CHECK_INET_HANDLE(hInternet))
    1217     fprintf(stderr,"WARNING : hInternet handle failed to initialize");
    1218 #endif
    1219   maps* request_input_real_format=NULL;
    1220   maps* tmpmaps = request_input_real_format;
    1221   map* postRequest=NULL;
    1222   postRequest=getMap(request_inputs,"xrequest");
    1223   if(postRequest==NULLMAP){
     1467  if (!CHECK_INET_HANDLE (hInternet))
     1468    fprintf (stderr, "WARNING : hInternet handle failed to initialize");
     1469#endif
     1470  maps *request_input_real_format = NULL;
     1471  maps *tmpmaps = request_input_real_format;
     1472  map *postRequest = NULL;
     1473  postRequest = getMap (request_inputs, "xrequest");
     1474  if (postRequest == NULLMAP)
     1475    {
    12241476    /**
    12251477     * Parsing outputs provided as KVP
    12261478     */
    1227     r_inputs=NULL;
    1228 #ifdef DEBUG
    1229     fprintf(stderr,"OUTPUT Parsing ... \n");
    1230 #endif
    1231     r_inputs=getMap(request_inputs,"ResponseDocument");
    1232     if(r_inputs==NULL) r_inputs=getMap(request_inputs,"RawDataOutput");
    1233    
    1234 #ifdef DEBUG
    1235     fprintf(stderr,"OUTPUT Parsing ... \n");
    1236 #endif
    1237     if(r_inputs!=NULL){
    1238 #ifdef DEBUG
    1239       fprintf(stderr,"OUTPUT Parsing start now ... \n");
    1240 #endif
    1241       char cursor_output[10240];
    1242       char *cotmp=zStrdup(r_inputs->value);
    1243       snprintf(cursor_output,10240,"%s",cotmp);
    1244       free(cotmp);
    1245       j=0;
    1246        
     1479      r_inputs = NULL;
     1480#ifdef DEBUG
     1481      fprintf (stderr, "OUTPUT Parsing ... \n");
     1482#endif
     1483      r_inputs = getMap (request_inputs, "ResponseDocument");
     1484      if (r_inputs == NULL)
     1485        r_inputs = getMap (request_inputs, "RawDataOutput");
     1486
     1487#ifdef DEBUG
     1488      fprintf (stderr, "OUTPUT Parsing ... \n");
     1489#endif
     1490      if (r_inputs != NULL)
     1491        {
     1492#ifdef DEBUG
     1493          fprintf (stderr, "OUTPUT Parsing start now ... \n");
     1494#endif
     1495          char cursor_output[10240];
     1496          char *cotmp = zStrdup (r_inputs->value);
     1497          snprintf (cursor_output, 10240, "%s", cotmp);
     1498          free (cotmp);
     1499          j = 0;
     1500
    12471501      /**
    12481502       * Put each Output into the outputs_as_text array
    12491503       */
    1250       char * pToken;
    1251       maps* tmp_output=NULL;
    1252 #ifdef DEBUG
    1253       fprintf(stderr,"OUTPUT [%s]\n",cursor_output);
    1254 #endif
    1255       pToken=strtok(cursor_output,";");
    1256       char** outputs_as_text=(char**)malloc(128*sizeof(char*));
    1257       if(outputs_as_text == NULL) {
    1258         return errorException(m, _("Unable to allocate memory"), "InternalError",NULL);
    1259       }
    1260       i=0;
    1261       while(pToken!=NULL){
    1262 #ifdef DEBUG
    1263         fprintf(stderr,"***%s***\n",pToken);
    1264         fflush(stderr);
    1265         fprintf(stderr,"***%s***\n",pToken);
    1266 #endif
    1267         outputs_as_text[i]=(char*)malloc((strlen(pToken)+1)*sizeof(char));
    1268         if(outputs_as_text[i] == NULL) {
    1269           return errorException(m, _("Unable to allocate memory"), "InternalError",NULL);
    1270         }
    1271         snprintf(outputs_as_text[i],strlen(pToken)+1,"%s",pToken);
    1272         pToken = strtok(NULL,";");
    1273         i++;
    1274       }
    1275       for(j=0;j<i;j++){
    1276         char *tmp=zStrdup(outputs_as_text[j]);
    1277         free(outputs_as_text[j]);
    1278         char *tmpc;
    1279         tmpc=strtok(tmp,"@");
    1280         int k=0;
    1281         while(tmpc!=NULL){
    1282           if(k==0){
    1283             if(tmp_output==NULL){
    1284               tmp_output=(maps*)malloc(MAPS_SIZE);
    1285               if(tmp_output == NULL){
    1286                 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1287               }
    1288               tmp_output->name=zStrdup(tmpc);
    1289               tmp_output->content=NULL;
    1290               tmp_output->next=NULL;
    1291             }
    1292           }
    1293           else{
    1294             char *tmpv=strstr(tmpc,"=");
    1295             char tmpn[256];
    1296             memset(tmpn,0,256);
    1297             strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char));
    1298             tmpn[strlen(tmpc)-strlen(tmpv)]=0;
    1299 #ifdef DEBUG
    1300             fprintf(stderr,"OUTPUT DEF [%s]=[%s]\n",tmpn,tmpv+1);
    1301 #endif
    1302             if(tmp_output->content==NULL){
    1303               tmp_output->content=createMap(tmpn,tmpv+1);
    1304               tmp_output->content->next=NULL;
    1305             }
    1306             else
    1307               addToMap(tmp_output->content,tmpn,tmpv+1);
    1308           }
    1309           k++;
    1310 #ifdef DEBUG
    1311           fprintf(stderr,"***%s***\n",tmpc);
    1312 #endif
    1313           tmpc=strtok(NULL,"@");
    1314         }
    1315         if(request_output_real_format==NULL)
    1316           request_output_real_format=dupMaps(&tmp_output);
    1317         else
    1318           addMapsToMaps(&request_output_real_format,tmp_output);
    1319         freeMaps(&tmp_output);
    1320         free(tmp_output);
    1321         tmp_output=NULL;
    1322 #ifdef DEBUG
    1323         dumpMaps(tmp_output);
    1324         fflush(stderr);
    1325 #endif
    1326         free(tmp);
    1327       }
    1328       free(outputs_as_text);
    1329     }
     1504          char *pToken;
     1505          maps *tmp_output = NULL;
     1506#ifdef DEBUG
     1507          fprintf (stderr, "OUTPUT [%s]\n", cursor_output);
     1508#endif
     1509          pToken = strtok (cursor_output, ";");
     1510          char **outputs_as_text = (char **) malloc (128 * sizeof (char *));
     1511          if (outputs_as_text == NULL)
     1512            {
     1513              return errorException (m, _("Unable to allocate memory"),
     1514                                     "InternalError", NULL);
     1515            }
     1516          i = 0;
     1517          while (pToken != NULL)
     1518            {
     1519#ifdef DEBUG
     1520              fprintf (stderr, "***%s***\n", pToken);
     1521              fflush (stderr);
     1522              fprintf (stderr, "***%s***\n", pToken);
     1523#endif
     1524              outputs_as_text[i] =
     1525                (char *) malloc ((strlen (pToken) + 1) * sizeof (char));
     1526              if (outputs_as_text[i] == NULL)
     1527                {
     1528                  return errorException (m, _("Unable to allocate memory"),
     1529                                         "InternalError", NULL);
     1530                }
     1531              snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s",
     1532                        pToken);
     1533              pToken = strtok (NULL, ";");
     1534              i++;
     1535            }
     1536          for (j = 0; j < i; j++)
     1537            {
     1538              char *tmp = zStrdup (outputs_as_text[j]);
     1539              free (outputs_as_text[j]);
     1540              char *tmpc;
     1541              tmpc = strtok (tmp, "@");
     1542              int k = 0;
     1543              while (tmpc != NULL)
     1544                {
     1545                  if (k == 0)
     1546                    {
     1547                      if (tmp_output == NULL)
     1548                        {
     1549                          tmp_output = (maps *) malloc (MAPS_SIZE);
     1550                          if (tmp_output == NULL)
     1551                            {
     1552                              return errorException (m,
     1553                                                     _
     1554                                                     ("Unable to allocate memory."),
     1555                                                     "InternalError", NULL);
     1556                            }
     1557                          tmp_output->name = zStrdup (tmpc);
     1558                          tmp_output->content = NULL;
     1559                          tmp_output->next = NULL;
     1560                        }
     1561                    }
     1562                  else
     1563                    {
     1564                      char *tmpv = strstr (tmpc, "=");
     1565                      char tmpn[256];
     1566                      memset (tmpn, 0, 256);
     1567                      strncpy (tmpn, tmpc,
     1568                               (strlen (tmpc) -
     1569                                strlen (tmpv)) * sizeof (char));
     1570                      tmpn[strlen (tmpc) - strlen (tmpv)] = 0;
     1571#ifdef DEBUG
     1572                      fprintf (stderr, "OUTPUT DEF [%s]=[%s]\n", tmpn,
     1573                               tmpv + 1);
     1574#endif
     1575                      if (tmp_output->content == NULL)
     1576                        {
     1577                          tmp_output->content = createMap (tmpn, tmpv + 1);
     1578                          tmp_output->content->next = NULL;
     1579                        }
     1580                      else
     1581                        addToMap (tmp_output->content, tmpn, tmpv + 1);
     1582                    }
     1583                  k++;
     1584#ifdef DEBUG
     1585                  fprintf (stderr, "***%s***\n", tmpc);
     1586#endif
     1587                  tmpc = strtok (NULL, "@");
     1588                }
     1589              if (request_output_real_format == NULL)
     1590                request_output_real_format = dupMaps (&tmp_output);
     1591              else
     1592                addMapsToMaps (&request_output_real_format, tmp_output);
     1593              freeMaps (&tmp_output);
     1594              free (tmp_output);
     1595              tmp_output = NULL;
     1596#ifdef DEBUG
     1597              dumpMaps (tmp_output);
     1598              fflush (stderr);
     1599#endif
     1600              free (tmp);
     1601            }
     1602          free (outputs_as_text);
     1603        }
    13301604
    13311605
     
    13331607     * Parsing inputs provided as KVP
    13341608     */
    1335     r_inputs=getMap(request_inputs,"DataInputs");
    1336 #ifdef DEBUG
    1337     fprintf(stderr,"DATA INPUTS [%s]\n",r_inputs->value);
    1338 #endif
    1339     char cursor_input[40960];
    1340     if(r_inputs!=NULL)
    1341       snprintf(cursor_input,40960,"%s",r_inputs->value);
    1342     else{
    1343       errorException(m, _("Parameter <DataInputs> was not specified"),"MissingParameterValue","DataInputs");
    1344       freeMaps(&m);
    1345       free(m);
    1346       free(REQUEST);
    1347       free(SERVICE_URL);
    1348       InternetCloseHandle(&hInternet);
    1349       freeService(&s1);
    1350       free(s1);
    1351       return 0;
    1352     }
    1353     j=0;
    1354  
     1609      r_inputs = getMap (request_inputs, "DataInputs");
     1610#ifdef DEBUG
     1611      fprintf (stderr, "DATA INPUTS [%s]\n", r_inputs->value);
     1612#endif
     1613      char cursor_input[40960];
     1614      if (r_inputs != NULL)
     1615        snprintf (cursor_input, 40960, "%s", r_inputs->value);
     1616      else
     1617        {
     1618          errorException (m, _("Parameter <DataInputs> was not specified"),
     1619                          "MissingParameterValue", "DataInputs");
     1620          freeMaps (&m);
     1621          free (m);
     1622          free (REQUEST);
     1623          free (SERVICE_URL);
     1624          InternetCloseHandle (&hInternet);
     1625          freeService (&s1);
     1626          free (s1);
     1627          return 0;
     1628        }
     1629      j = 0;
     1630
    13551631    /**
    13561632     * Put each DataInputs into the inputs_as_text array
    13571633     */
    1358     char *tmp1=zStrdup(cursor_input);
    1359     char * pToken;
    1360     pToken=strtok(cursor_input,";");
    1361     if(pToken!=NULL && strncasecmp(pToken,tmp1,strlen(tmp1))==0){
    1362       char* tmp2=url_decode(tmp1);
    1363       snprintf(cursor_input,(strlen(tmp2)+1)*sizeof(char),"%s",tmp2);
    1364       free(tmp2);
    1365       pToken=strtok(cursor_input,";");
    1366     }
    1367     free(tmp1);
    1368 
    1369     char** inputs_as_text=(char**)malloc(100*sizeof(char*));
    1370     if(inputs_as_text == NULL){
    1371       return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1372     }
    1373     i=0;
    1374     while(pToken!=NULL){
    1375 #ifdef DEBUG
    1376       fprintf(stderr,"***%s***\n",pToken);
    1377 #endif
    1378       fflush(stderr);
    1379 #ifdef DEBUG
    1380       fprintf(stderr,"***%s***\n",pToken);
    1381 #endif
    1382       inputs_as_text[i]=(char*)malloc((strlen(pToken)+1)*sizeof(char));
    1383       snprintf(inputs_as_text[i],strlen(pToken)+1,"%s",pToken);
    1384       if(inputs_as_text[i] == NULL){
    1385         return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1386       }
    1387       pToken = strtok(NULL,";");
    1388       i++;
    1389     }
    1390 
    1391     for(j=0;j<i;j++){
    1392       char *tmp=zStrdup(inputs_as_text[j]);
    1393       free(inputs_as_text[j]);
    1394       char *tmpc;
    1395       tmpc=strtok(tmp,"@");
    1396       while(tmpc!=NULL){
    1397 #ifdef DEBUG
    1398         fprintf(stderr,"***\n***%s***\n",tmpc);
    1399 #endif
    1400         char *tmpv=strstr(tmpc,"=");
    1401         char tmpn[256];
    1402         memset(tmpn,0,256);
    1403         if(tmpv!=NULL){
    1404           strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char));
    1405           tmpn[strlen(tmpc)-strlen(tmpv)]=0;
    1406         }
    1407         else{
    1408           strncpy(tmpn,tmpc,strlen(tmpc)*sizeof(char));
    1409           tmpn[strlen(tmpc)]=0;
    1410         }
    1411 #ifdef DEBUG
    1412         fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1);
    1413 #endif
    1414         if(tmpmaps==NULL){
    1415           tmpmaps=(maps*)malloc(MAPS_SIZE);
    1416           if(tmpmaps == NULL){
    1417             return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1418           }
    1419           tmpmaps->name=zStrdup(tmpn);
    1420           if(tmpv!=NULL){
    1421             char *tmpvf=url_decode(tmpv+1);
    1422             tmpmaps->content=createMap("value",tmpvf);
    1423             free(tmpvf);
    1424           }
    1425           else
    1426             tmpmaps->content=createMap("value","Reference");
    1427           tmpmaps->next=NULL;
    1428         }
    1429         tmpc=strtok(NULL,"@");
    1430         while(tmpc!=NULL){
    1431 #ifdef DEBUG
    1432           fprintf(stderr,"*** KVP NON URL-ENCODED \n***%s***\n",tmpc);
    1433 #endif
    1434           char *tmpv1=strstr(tmpc,"=");
    1435 #ifdef DEBUG
    1436           fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1);
    1437 #endif
    1438           char tmpn1[1024];
    1439           memset(tmpn1,0,1024);
    1440           if(tmpv1!=NULL){
    1441             strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1));
    1442             tmpn1[strlen(tmpc)-strlen(tmpv1)]=0;
    1443             addToMap(tmpmaps->content,tmpn1,tmpv1+1);
    1444           }
    1445           else{
    1446             strncpy(tmpn1,tmpc,strlen(tmpc));
    1447             tmpn1[strlen(tmpc)]=0;
    1448             map* lmap=getLastMap(tmpmaps->content);
    1449             char *tmpValue=(char*)malloc((strlen(tmpv)+strlen(tmpc)+1)*sizeof(char));
    1450             sprintf(tmpValue,"%s@%s",tmpv+1,tmpc);
    1451             free(lmap->value);
    1452             lmap->value=zStrdup(tmpValue);
    1453             free(tmpValue);
    1454             tmpc=strtok(NULL,"@");
    1455             continue;
    1456           }
    1457 #ifdef DEBUG
    1458           fprintf(stderr,"*** NAME NON URL-ENCODED \n***%s***\n",tmpn1);
    1459           fprintf(stderr,"*** VALUE NON URL-ENCODED \n***%s***\n",tmpv1+1);
    1460 #endif
    1461           if(strcmp(tmpn1,"xlink:href")!=0)
    1462             addToMap(tmpmaps->content,tmpn1,tmpv1+1);
    1463           else
    1464             if(tmpv1!=NULL){
    1465               char *tmpx2=url_decode(tmpv1+1);
    1466               if(strncasecmp(tmpx2,"http://",7)!=0 &&
    1467                  strncasecmp(tmpx2,"ftp://",6)!=0 &&
    1468                  strncasecmp(tmpx2,"https://",8)!=0){
    1469                 char emsg[1024];
    1470                 sprintf(emsg,_("Unable to find a valid protocol to download the remote file %s"),tmpv1+1);
    1471                 errorException(m,emsg,"InternalError",NULL);
    1472                 freeMaps(&m);
    1473                 free(m);
    1474                 free(REQUEST);
    1475                 free(SERVICE_URL);
    1476                 InternetCloseHandle(&hInternet);
    1477                 freeService(&s1);
    1478                 free(s1);
    1479                 return 0;
    1480               }
    1481 #ifdef DEBUG
    1482               fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);
    1483 #endif
    1484               addToMap(tmpmaps->content,tmpn1,tmpx2);         
     1634      char *tmp1 = zStrdup (cursor_input);
     1635      char *pToken;
     1636      pToken = strtok (cursor_input, ";");
     1637      if (pToken != NULL && strncasecmp (pToken, tmp1, strlen (tmp1)) == 0)
     1638        {
     1639          char *tmp2 = url_decode (tmp1);
     1640          snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s",
     1641                    tmp2);
     1642          free (tmp2);
     1643          pToken = strtok (cursor_input, ";");
     1644        }
     1645      free (tmp1);
     1646
     1647      char **inputs_as_text = (char **) malloc (100 * sizeof (char *));
     1648      if (inputs_as_text == NULL)
     1649        {
     1650          return errorException (m, _("Unable to allocate memory."),
     1651                                 "InternalError", NULL);
     1652        }
     1653      i = 0;
     1654      while (pToken != NULL)
     1655        {
     1656#ifdef DEBUG
     1657          fprintf (stderr, "***%s***\n", pToken);
     1658#endif
     1659          fflush (stderr);
     1660#ifdef DEBUG
     1661          fprintf (stderr, "***%s***\n", pToken);
     1662#endif
     1663          inputs_as_text[i] =
     1664            (char *) malloc ((strlen (pToken) + 1) * sizeof (char));
     1665          snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken);
     1666          if (inputs_as_text[i] == NULL)
     1667            {
     1668              return errorException (m, _("Unable to allocate memory."),
     1669                                     "InternalError", NULL);
     1670            }
     1671          pToken = strtok (NULL, ";");
     1672          i++;
     1673        }
     1674
     1675      for (j = 0; j < i; j++)
     1676        {
     1677          char *tmp = zStrdup (inputs_as_text[j]);
     1678          free (inputs_as_text[j]);
     1679          char *tmpc;
     1680          tmpc = strtok (tmp, "@");
     1681          while (tmpc != NULL)
     1682            {
     1683#ifdef DEBUG
     1684              fprintf (stderr, "***\n***%s***\n", tmpc);
     1685#endif
     1686              char *tmpv = strstr (tmpc, "=");
     1687              char tmpn[256];
     1688              memset (tmpn, 0, 256);
     1689              if (tmpv != NULL)
     1690                {
     1691                  strncpy (tmpn, tmpc,
     1692                           (strlen (tmpc) - strlen (tmpv)) * sizeof (char));
     1693                  tmpn[strlen (tmpc) - strlen (tmpv)] = 0;
     1694                }
     1695              else
     1696                {
     1697                  strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char));
     1698                  tmpn[strlen (tmpc)] = 0;
     1699                }
     1700#ifdef DEBUG
     1701              fprintf (stderr, "***\n*** %s = %s ***\n", tmpn, tmpv + 1);
     1702#endif
     1703              if (tmpmaps == NULL)
     1704                {
     1705                  tmpmaps = (maps *) malloc (MAPS_SIZE);
     1706                  if (tmpmaps == NULL)
     1707                    {
     1708                      return errorException (m,
     1709                                             _("Unable to allocate memory."),
     1710                                             "InternalError", NULL);
     1711                    }
     1712                  tmpmaps->name = zStrdup (tmpn);
     1713                  if (tmpv != NULL)
     1714                    {
     1715                      char *tmpvf = url_decode (tmpv + 1);
     1716                      tmpmaps->content = createMap ("value", tmpvf);
     1717                      free (tmpvf);
     1718                    }
     1719                  else
     1720                    tmpmaps->content = createMap ("value", "Reference");
     1721                  tmpmaps->next = NULL;
     1722                }
     1723              tmpc = strtok (NULL, "@");
     1724              while (tmpc != NULL)
     1725                {
     1726#ifdef DEBUG
     1727                  fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n",
     1728                           tmpc);
     1729#endif
     1730                  char *tmpv1 = strstr (tmpc, "=");
     1731#ifdef DEBUG
     1732                  fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
     1733                           tmpv1 + 1);
     1734#endif
     1735                  char tmpn1[1024];
     1736                  memset (tmpn1, 0, 1024);
     1737                  if (tmpv1 != NULL)
     1738                    {
     1739                      strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1));
     1740                      tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0;
     1741                      addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
     1742                    }
     1743                  else
     1744                    {
     1745                      strncpy (tmpn1, tmpc, strlen (tmpc));
     1746                      tmpn1[strlen (tmpc)] = 0;
     1747                      map *lmap = getLastMap (tmpmaps->content);
     1748                      char *tmpValue =
     1749                        (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) *
     1750                                         sizeof (char));
     1751                      sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc);
     1752                      free (lmap->value);
     1753                      lmap->value = zStrdup (tmpValue);
     1754                      free (tmpValue);
     1755                      tmpc = strtok (NULL, "@");
     1756                      continue;
     1757                    }
     1758#ifdef DEBUG
     1759                  fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n",
     1760                           tmpn1);
     1761                  fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
     1762                           tmpv1 + 1);
     1763#endif
     1764                  if (strcmp (tmpn1, "xlink:href") != 0)
     1765                    addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
     1766                  else if (tmpv1 != NULL)
     1767                    {
     1768                      char *tmpx2 = url_decode (tmpv1 + 1);
     1769                      if (strncasecmp (tmpx2, "http://", 7) != 0 &&
     1770                          strncasecmp (tmpx2, "ftp://", 6) != 0 &&
     1771                          strncasecmp (tmpx2, "https://", 8) != 0)
     1772                        {
     1773                          char emsg[1024];
     1774                          sprintf (emsg,
     1775                                   _
     1776                                   ("Unable to find a valid protocol to download the remote file %s"),
     1777                                   tmpv1 + 1);
     1778                          errorException (m, emsg, "InternalError", NULL);
     1779                          freeMaps (&m);
     1780                          free (m);
     1781                          free (REQUEST);
     1782                          free (SERVICE_URL);
     1783                          InternetCloseHandle (&hInternet);
     1784                          freeService (&s1);
     1785                          free (s1);
     1786                          return 0;
     1787                        }
     1788#ifdef DEBUG
     1789                      fprintf (stderr,
     1790                               "REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",
     1791                               tmpv1 + 1);
     1792#endif
     1793                      addToMap (tmpmaps->content, tmpn1, tmpx2);
    14851794#ifndef WIN32
    1486               if(CHECK_INET_HANDLE(hInternet))
    1487 #endif
    1488                 {
    1489                   if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,tmpx2)<0){
    1490                     freeMaps(&m);
    1491                     free(m);
    1492                     free(REQUEST);
    1493                     free(SERVICE_URL);
    1494                     InternetCloseHandle(&hInternet);
    1495                     freeService(&s1);
    1496                     free(s1);
    1497                     return 0;
    1498                   }
    1499                 }
    1500               free(tmpx2);
    1501               addToMap(tmpmaps->content,"Reference",tmpv1+1);
    1502             }
    1503           tmpc=strtok(NULL,"@");
    1504         }
    1505 #ifdef DEBUG
    1506         dumpMaps(tmpmaps);
    1507         fflush(stderr);
    1508 #endif
    1509         if(request_input_real_format==NULL)
    1510           request_input_real_format=dupMaps(&tmpmaps);
    1511         else{
    1512           maps* testPresence=getMaps(request_input_real_format,tmpmaps->name);
    1513           if(testPresence!=NULL){
    1514             elements* elem=getElements(s1->inputs,tmpmaps->name);
    1515             if(elem!=NULL){
    1516               if(appendMapsToMaps(m,request_input_real_format,tmpmaps,elem)<0){
    1517                 freeMaps(&m);
    1518                 free(m);
    1519                 free(REQUEST);
    1520                 free(SERVICE_URL);
    1521                 InternetCloseHandle(&hInternet);
    1522                 freeService(&s1);
    1523                 free(s1);
    1524                 return 0;
    1525               }
    1526             }
    1527           }
    1528           else
    1529             addMapsToMaps(&request_input_real_format,tmpmaps);
    1530         }
    1531         freeMaps(&tmpmaps);
    1532         free(tmpmaps);
    1533         tmpmaps=NULL;
    1534         free(tmp);
    1535       }
    1536     }
    1537     free(inputs_as_text);
    1538   }
    1539   else {
     1795                      if (CHECK_INET_HANDLE (hInternet))
     1796#endif
     1797                        {
     1798                          if (loadRemoteFile
     1799                              (&m, &tmpmaps->content, &hInternet, tmpx2) < 0)
     1800                            {
     1801                              freeMaps (&m);
     1802                              free (m);
     1803                              free (REQUEST);
     1804                              free (SERVICE_URL);
     1805                              InternetCloseHandle (&hInternet);
     1806                              freeService (&s1);
     1807                              free (s1);
     1808                              return 0;
     1809                            }
     1810                        }
     1811                      free (tmpx2);
     1812                      addToMap (tmpmaps->content, "Reference", tmpv1 + 1);
     1813                    }
     1814                  tmpc = strtok (NULL, "@");
     1815                }
     1816#ifdef DEBUG
     1817              dumpMaps (tmpmaps);
     1818              fflush (stderr);
     1819#endif
     1820              if (request_input_real_format == NULL)
     1821                request_input_real_format = dupMaps (&tmpmaps);
     1822              else
     1823                {
     1824                  maps *testPresence =
     1825                    getMaps (request_input_real_format, tmpmaps->name);
     1826                  if (testPresence != NULL)
     1827                    {
     1828                      elements *elem =
     1829                        getElements (s1->inputs, tmpmaps->name);
     1830                      if (elem != NULL)
     1831                        {
     1832                          if (appendMapsToMaps
     1833                              (m, request_input_real_format, tmpmaps,
     1834                               elem) < 0)
     1835                            {
     1836                              freeMaps (&m);
     1837                              free (m);
     1838                              free (REQUEST);
     1839                              free (SERVICE_URL);
     1840                              InternetCloseHandle (&hInternet);
     1841                              freeService (&s1);
     1842                              free (s1);
     1843                              return 0;
     1844                            }
     1845                        }
     1846                    }
     1847                  else
     1848                    addMapsToMaps (&request_input_real_format, tmpmaps);
     1849                }
     1850              freeMaps (&tmpmaps);
     1851              free (tmpmaps);
     1852              tmpmaps = NULL;
     1853              free (tmp);
     1854            }
     1855        }
     1856      free (inputs_as_text);
     1857    }
     1858  else
     1859    {
    15401860    /**
    15411861     * Parse XML request
    1542      */
    1543     xmlInitParser();
    1544 #ifdef DEBUG
    1545     fflush(stderr);
    1546     fprintf(stderr,"BEFORE %s\n",postRequest->value);
    1547     fflush(stderr);
    1548 #endif
    1549     xmlDocPtr doc =
    1550       xmlParseMemory(postRequest->value,cgiContentLength);
    1551 #ifdef DEBUG
    1552     fprintf(stderr,"AFTER\n");
    1553     fflush(stderr);
     1862     */
     1863      xmlInitParser ();
     1864#ifdef DEBUG
     1865      fflush (stderr);
     1866      fprintf (stderr, "BEFORE %s\n", postRequest->value);
     1867      fflush (stderr);
     1868#endif
     1869      xmlDocPtr doc = xmlParseMemory (postRequest->value, cgiContentLength);
     1870#ifdef DEBUG
     1871      fprintf (stderr, "AFTER\n");
     1872      fflush (stderr);
    15541873#endif
    15551874    /**
    15561875     * Parse every Input in DataInputs node.
    15571876     */
    1558     xmlXPathObjectPtr tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='Input']");
    1559     xmlNodeSet* tmps=tmpsptr->nodesetval;
    1560 #ifdef DEBUG
    1561     fprintf(stderr,"*****%d*****\n",tmps->nodeNr);
    1562 #endif
    1563     for(int k=0;k<tmps->nodeNr;k++){
    1564       maps *tmpmaps=NULL;
    1565       xmlNodePtr cur=tmps->nodeTab[k];
    1566       if(tmps->nodeTab[k]->type == XML_ELEMENT_NODE) {
    1567         /**
     1877      xmlXPathObjectPtr tmpsptr =
     1878        extractFromDoc (doc, "/*/*/*[local-name()='Input']");
     1879      xmlNodeSet *tmps = tmpsptr->nodesetval;
     1880#ifdef DEBUG
     1881      fprintf (stderr, "*****%d*****\n", tmps->nodeNr);
     1882#endif
     1883      for (int k = 0; k < tmps->nodeNr; k++)
     1884        {
     1885          maps *tmpmaps = NULL;
     1886          xmlNodePtr cur = tmps->nodeTab[k];
     1887          if (tmps->nodeTab[k]->type == XML_ELEMENT_NODE)
     1888            {
     1889        /**
    15681890         * A specific Input node.
    15691891         */
    15701892#ifdef DEBUG
    1571         fprintf(stderr, "= element 0 node \"%s\"\n", cur->name);
    1572 #endif
    1573         xmlNodePtr cur2=cur->children;
    1574         while(cur2!=NULL){
    1575           while(cur2!=NULL && cur2->type!=XML_ELEMENT_NODE)
    1576             cur2=cur2->next;
    1577           if(cur2==NULL)
    1578             break;
    1579           /**
     1893              fprintf (stderr, "= element 0 node \"%s\"\n", cur->name);
     1894#endif
     1895              xmlNodePtr cur2 = cur->children;
     1896              while (cur2 != NULL)
     1897                {
     1898                  while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
     1899                    cur2 = cur2->next;
     1900                  if (cur2 == NULL)
     1901                    break;
     1902          /**
    15801903           * Indentifier
    15811904           */
    1582           if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
    1583             xmlChar *val= xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    1584             if(tmpmaps==NULL){
    1585               tmpmaps=(maps*)malloc(MAPS_SIZE);
    1586               if(tmpmaps == NULL){
    1587                 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1588               }
    1589               tmpmaps->name=zStrdup((char*)val);
    1590               tmpmaps->content=NULL;
    1591               tmpmaps->next=NULL;
    1592             }
    1593             xmlFree(val);
    1594           }
    1595           /**
     1905                  if (xmlStrncasecmp
     1906                      (cur2->name, BAD_CAST "Identifier",
     1907                       xmlStrlen (cur2->name)) == 0)
     1908                    {
     1909                      xmlChar *val =
     1910                        xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1);
     1911                      if (tmpmaps == NULL)
     1912                        {
     1913                          tmpmaps = (maps *) malloc (MAPS_SIZE);
     1914                          if (tmpmaps == NULL)
     1915                            {
     1916                              return errorException (m,
     1917                                                     _
     1918                                                     ("Unable to allocate memory."),
     1919                                                     "InternalError", NULL);
     1920                            }
     1921                          tmpmaps->name = zStrdup ((char *) val);
     1922                          tmpmaps->content = NULL;
     1923                          tmpmaps->next = NULL;
     1924                        }
     1925                      xmlFree (val);
     1926                    }
     1927          /**
    15961928           * Title, Asbtract
    15971929           */
    1598           if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
    1599              xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
    1600             xmlChar *val=
    1601               xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    1602             if(tmpmaps==NULL){
    1603               tmpmaps=(maps*)malloc(MAPS_SIZE);
    1604               if(tmpmaps == NULL){
    1605                 return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1606               }
    1607               tmpmaps->name=zStrdup("missingIndetifier");
    1608               tmpmaps->content=createMap((char*)cur2->name,(char*)val);
    1609               tmpmaps->next=NULL;
    1610             }
    1611             else{
    1612               if(tmpmaps->content!=NULL)
    1613                 addToMap(tmpmaps->content,
    1614                          (char*)cur2->name,(char*)val);
    1615               else
    1616                 tmpmaps->content=
    1617                   createMap((char*)cur2->name,(char*)val);
    1618             }
    1619 #ifdef DEBUG
    1620             dumpMaps(tmpmaps);
    1621 #endif
    1622             xmlFree(val);
    1623           }
    1624           /**
     1930                  if (xmlStrncasecmp
     1931                      (cur2->name, BAD_CAST "Title",
     1932                       xmlStrlen (cur2->name)) == 0
     1933                      || xmlStrncasecmp (cur2->name, BAD_CAST "Abstract",
     1934                                         xmlStrlen (cur2->name)) == 0)
     1935                    {
     1936                      xmlChar *val =
     1937                        xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1);
     1938                      if (tmpmaps == NULL)
     1939                        {
     1940                          tmpmaps = (maps *) malloc (MAPS_SIZE);
     1941                          if (tmpmaps == NULL)
     1942                            {
     1943                              return errorException (m,
     1944                                                     _
     1945                                                     ("Unable to allocate memory."),
     1946                                                     "InternalError", NULL);
     1947                            }
     1948                          tmpmaps->name = zStrdup ("missingIndetifier");
     1949                          tmpmaps->content =
     1950                            createMap ((char *) cur2->name, (char *) val);
     1951                          tmpmaps->next = NULL;
     1952                        }
     1953                      else
     1954                        {
     1955                          if (tmpmaps->content != NULL)
     1956                            addToMap (tmpmaps->content,
     1957                                      (char *) cur2->name, (char *) val);
     1958                          else
     1959                            tmpmaps->content =
     1960                              createMap ((char *) cur2->name, (char *) val);
     1961                        }
     1962#ifdef DEBUG
     1963                      dumpMaps (tmpmaps);
     1964#endif
     1965                      xmlFree (val);
     1966                    }
     1967          /**
    16251968           * InputDataFormChoice (Reference or Data ?)
    16261969           */
    1627           if(xmlStrcasecmp(cur2->name,BAD_CAST "Reference")==0){
    1628             /**
     1970                  if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0)
     1971                    {
     1972            /**
    16291973             * Get every attribute from a Reference node
    16301974             * mimeType, encoding, schema, href, method
     
    16321976             */
    16331977#ifdef DEBUG
    1634             fprintf(stderr,"REFERENCE\n");
    1635 #endif
    1636             const char *refs[5]={"mimeType","encoding","schema","method","href"};
    1637             for(int l=0;l<5;l++){
    1638 #ifdef DEBUG
    1639               fprintf(stderr,"*** %s ***",refs[l]);
    1640 #endif
    1641               xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]);
    1642               if(val!=NULL && xmlStrlen(val)>0){
    1643                 if(tmpmaps->content!=NULL)
    1644                   addToMap(tmpmaps->content,refs[l],(char*)val);
    1645                 else
    1646                   tmpmaps->content=createMap(refs[l],(char*)val);
    1647                 map* ltmp=getMap(tmpmaps->content,"method");
    1648                 if(l==4){
    1649                   if(!(ltmp!=NULL && strncmp(ltmp->value,"POST",4)==0)
    1650                      && CHECK_INET_HANDLE(hInternet)){
    1651                     if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,(char*)val)!=0){
    1652                       freeMaps(&m);
    1653                       free(m);
    1654                       free(REQUEST);
    1655                       free(SERVICE_URL);
    1656                       InternetCloseHandle(&hInternet);
    1657                       freeService(&s1);
    1658                       free(s1);
    1659                       return 0;
    1660                     }
    1661                   }
    1662                 }
    1663               }
    1664 #ifdef DEBUG
    1665               fprintf(stderr,"%s\n",val);
    1666 #endif
    1667               xmlFree(val);
    1668             }
     1978                      fprintf (stderr, "REFERENCE\n");
     1979#endif
     1980                      const char *refs[5] =
     1981                        { "mimeType", "encoding", "schema", "method",
     1982                        "href"
     1983                      };
     1984                      for (int l = 0; l < 5; l++)
     1985                        {
     1986#ifdef DEBUG
     1987                          fprintf (stderr, "*** %s ***", refs[l]);
     1988#endif
     1989                          xmlChar *val = xmlGetProp (cur2, BAD_CAST refs[l]);
     1990                          if (val != NULL && xmlStrlen (val) > 0)
     1991                            {
     1992                              if (tmpmaps->content != NULL)
     1993                                addToMap (tmpmaps->content, refs[l],
     1994                                          (char *) val);
     1995                              else
     1996                                tmpmaps->content =
     1997                                  createMap (refs[l], (char *) val);
     1998                              map *ltmp = getMap (tmpmaps->content, "method");
     1999                              if (l == 4)
     2000                                {
     2001                                  if (!
     2002                                      (ltmp != NULL
     2003                                       && strncmp (ltmp->value, "POST",
     2004                                                   4) == 0)
     2005                                      && CHECK_INET_HANDLE (hInternet))
     2006                                    {
     2007                                      if (loadRemoteFile
     2008                                          (&m, &tmpmaps->content, &hInternet,
     2009                                           (char *) val) != 0)
     2010                                        {
     2011                                          freeMaps (&m);
     2012                                          free (m);
     2013                                          free (REQUEST);
     2014                                          free (SERVICE_URL);
     2015                                          InternetCloseHandle (&hInternet);
     2016                                          freeService (&s1);
     2017                                          free (s1);
     2018                                          return 0;
     2019                                        }
     2020                                    }
     2021                                }
     2022                            }
     2023#ifdef DEBUG
     2024                          fprintf (stderr, "%s\n", val);
     2025#endif
     2026                          xmlFree (val);
     2027                        }
    16692028#ifdef POST_DEBUG
    1670             fprintf(stderr,"Parse Header and Body from Reference \n");
    1671 #endif
    1672             xmlNodePtr cur3=cur2->children;
    1673             /*      HINTERNET hInternetP;
    1674                     hInternetP=InternetOpen(
    1675                     #ifndef WIN32
    1676                     (LPCTSTR)
    1677                     #endif
    1678                     "ZooWPSClient\0",
    1679                     INTERNET_OPEN_TYPE_PRECONFIG,
    1680                     NULL,NULL, 0);*/
    1681             //hInternet.ihandle[hInternet.nb].header=NULL;
    1682             while(cur3!=NULL){
    1683               while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE)
    1684                 cur3=cur3->next;
    1685               if(cur3==NULL)
    1686                 break;
    1687               if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){
    1688                 const char *ha[2];
    1689                 ha[0]="key";
    1690                 ha[1]="value";
    1691                 int hai;
    1692                 char *has;
    1693                 char *key;
    1694                 for(hai=0;hai<2;hai++){
    1695                   xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]);
     2029                      fprintf (stderr,
     2030                               "Parse Header and Body from Reference \n");
     2031#endif
     2032                      xmlNodePtr cur3 = cur2->children;
     2033                      /*      HINTERNET hInternetP;
     2034                         hInternetP=InternetOpen(
     2035                         #ifndef WIN32
     2036                         (LPCTSTR)
     2037                         #endif
     2038                         "ZooWPSClient\0",
     2039                         INTERNET_OPEN_TYPE_PRECONFIG,
     2040                         NULL,NULL, 0); */
     2041                      //hInternet.ihandle[hInternet.nb].header=NULL;
     2042                      while (cur3 != NULL)
     2043                        {
     2044                          while (cur3 != NULL
     2045                                 && cur3->type != XML_ELEMENT_NODE)
     2046                            cur3 = cur3->next;
     2047                          if (cur3 == NULL)
     2048                            break;
     2049                          if (xmlStrcasecmp (cur3->name, BAD_CAST "Header") ==
     2050                              0)
     2051                            {
     2052                              const char *ha[2];
     2053                              ha[0] = "key";
     2054                              ha[1] = "value";
     2055                              int hai;
     2056                              char *has;
     2057                              char *key;
     2058                              for (hai = 0; hai < 2; hai++)
     2059                                {
     2060                                  xmlChar *val =
     2061                                    xmlGetProp (cur3, BAD_CAST ha[hai]);
    16962062#ifdef POST_DEBUG
    1697                   fprintf(stderr,"%s = %s\n",ha[hai],(char*)val);
    1698 #endif
    1699                   if(hai==0){
    1700                     key=zStrdup((char*)val);
    1701                   }else{
    1702                     has=(char*)malloc((4+xmlStrlen(val)+strlen(key))*sizeof(char));
    1703                     if(has == NULL){
    1704                       return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1705                     }
    1706                     snprintf(has,(3+xmlStrlen(val)+strlen(key)),"%s: %s",key,(char*)val);
    1707                     free(key);
     2063                                  fprintf (stderr, "%s = %s\n", ha[hai],
     2064                                           (char *) val);
     2065#endif
     2066                                  if (hai == 0)
     2067                                    {
     2068                                      key = zStrdup ((char *) val);
     2069                                    }
     2070                                  else
     2071                                    {
     2072                                      has =
     2073                                        (char *)
     2074                                        malloc ((4 + xmlStrlen (val) +
     2075                                                 strlen (key)) *
     2076                                                sizeof (char));
     2077                                      if (has == NULL)
     2078                                        {
     2079                                          return errorException (m,
     2080                                                                 _
     2081                                                                 ("Unable to allocate memory."),
     2082                                                                 "InternalError",
     2083                                                                 NULL);
     2084                                        }
     2085                                      snprintf (has,
     2086                                                (3 + xmlStrlen (val) +
     2087                                                 strlen (key)), "%s: %s", key,
     2088                                                (char *) val);
     2089                                      free (key);
    17082090#ifdef POST_DEBUG
    1709                     fprintf(stderr,"%s\n",has);
    1710 #endif
    1711                   }
    1712                   xmlFree(val);
    1713                 }
    1714                 hInternet.ihandle[hInternet.nb].header=curl_slist_append(hInternet.ihandle[hInternet.nb].header, has);
    1715                 if(has!=NULL)
    1716                   free(has);
    1717               }
    1718               else{
     2091                                      fprintf (stderr, "%s\n", has);
     2092#endif
     2093                                    }
     2094                                  xmlFree (val);
     2095                                }
     2096                              hInternet.ihandle[hInternet.nb].header =
     2097                                curl_slist_append (hInternet.ihandle
     2098                                                   [hInternet.nb].header,
     2099                                                   has);
     2100                              if (has != NULL)
     2101                                free (has);
     2102                            }
     2103                          else
     2104                            {
    17192105#ifdef POST_DEBUG
    1720                 fprintf(stderr,"Try to fetch the body part of the request ...\n");
    1721 #endif
    1722                 if(xmlStrcasecmp(cur3->name,BAD_CAST "Body")==0 ){
     2106                              fprintf (stderr,
     2107                                       "Try to fetch the body part of the request ...\n");
     2108#endif
     2109                              if (xmlStrcasecmp (cur3->name, BAD_CAST "Body")
     2110                                  == 0)
     2111                                {
    17232112#ifdef POST_DEBUG
    1724                   fprintf(stderr,"Body part found !!!\n",(char*)cur3->content);
    1725 #endif
    1726                   char *tmp=(char*)malloc(cgiContentLength+1*sizeof(char));
    1727                   memset(tmp,0,cgiContentLength);
    1728                   xmlNodePtr cur4=cur3->children;
    1729                   while(cur4!=NULL){
    1730                     while(cur4->type!=XML_ELEMENT_NODE)
    1731                       cur4=cur4->next;
    1732                     xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0");
    1733                     bdoc->encoding = xmlCharStrdup ("UTF-8");
    1734                     xmlDocSetRootElement(bdoc,cur4);
    1735                     xmlChar* btmps;
    1736                     int bsize;
    1737                     xmlDocDumpMemory(bdoc,&btmps,&bsize);
     2113                                  fprintf (stderr, "Body part found !!!\n",
     2114                                           (char *) cur3->content);
     2115#endif
     2116                                  char *tmp =
     2117                                    (char *) malloc (cgiContentLength +
     2118                                                     1 * sizeof (char));
     2119                                  memset (tmp, 0, cgiContentLength);
     2120                                  xmlNodePtr cur4 = cur3->children;
     2121                                  while (cur4 != NULL)
     2122                                    {
     2123                                      while (cur4->type != XML_ELEMENT_NODE)
     2124                                        cur4 = cur4->next;
     2125                                      xmlDocPtr bdoc =
     2126                                        xmlNewDoc (BAD_CAST "1.0");
     2127                                      bdoc->encoding =
     2128                                        xmlCharStrdup ("UTF-8");
     2129                                      xmlDocSetRootElement (bdoc, cur4);
     2130                                      xmlChar *btmps;
     2131                                      int bsize;
     2132                                      xmlDocDumpMemory (bdoc, &btmps, &bsize);
    17382133#ifdef POST_DEBUG
    1739                     fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps);
    1740 #endif
    1741                     if(btmps!=NULL)
    1742                       sprintf(tmp,"%s",(char*)btmps);
    1743                     xmlFree(btmps);
    1744                     cur4=cur4->next;
    1745                     xmlFreeDoc(bdoc);
    1746                   }
    1747                   map *btmp=getMap(tmpmaps->content,"href");
    1748                   if(btmp!=NULL){
     2134                                      fprintf (stderr,
     2135                                               "Body part found !!! %s %s\n",
     2136                                               tmp, (char *) btmps);
     2137#endif
     2138                                      if (btmps != NULL)
     2139                                        sprintf (tmp, "%s", (char *) btmps);
     2140                                      xmlFree (btmps);
     2141                                      cur4 = cur4->next;
     2142                                      xmlFreeDoc (bdoc);
     2143                                    }
     2144                                  map *btmp =
     2145                                    getMap (tmpmaps->content, "href");
     2146                                  if (btmp != NULL)
     2147                                    {
    17492148#ifdef POST_DEBUG
    1750                     fprintf(stderr,"%s %s\n",btmp->value,tmp);
    1751                     curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
    1752 #endif
    1753                     hInternet.waitingRequests[hInternet.nb]=strdup(tmp);
    1754                     InternetOpenUrl(&hInternet,btmp->value,hInternet.waitingRequests[hInternet.nb],strlen(hInternet.waitingRequests[hInternet.nb]),
    1755                                     INTERNET_FLAG_NO_CACHE_WRITE,0);
    1756                   }
    1757                   free(tmp);
    1758                 }
    1759                 else
    1760                   if(xmlStrcasecmp(cur3->name,BAD_CAST "BodyReference")==0 ){
    1761                     xmlChar *val=xmlGetProp(cur3,BAD_CAST "href");
    1762                     HINTERNET bInternet,res1;
    1763                     bInternet=InternetOpen(
     2149                                      fprintf (stderr, "%s %s\n", btmp->value,
     2150                                               tmp);
     2151                                      curl_easy_setopt (hInternet.handle,
     2152                                                        CURLOPT_VERBOSE, 1);
     2153#endif
     2154                                      hInternet.
     2155                                        waitingRequests[hInternet.nb] =
     2156                                        strdup (tmp);
     2157                                      InternetOpenUrl (&hInternet,
     2158                                                       btmp->value,
     2159                                                       hInternet.waitingRequests
     2160                                                       [hInternet.nb],
     2161                                                       strlen
     2162                                                       (hInternet.waitingRequests
     2163                                                        [hInternet.nb]),
     2164                                                       INTERNET_FLAG_NO_CACHE_WRITE,
     2165                                                       0);
     2166                                    }
     2167                                  free (tmp);
     2168                                }
     2169                              else
     2170                                if (xmlStrcasecmp
     2171                                    (cur3->name,
     2172                                     BAD_CAST "BodyReference") == 0)
     2173                                {
     2174                                  xmlChar *val =
     2175                                    xmlGetProp (cur3, BAD_CAST "href");
     2176                                  HINTERNET bInternet, res1;
     2177                                  bInternet = InternetOpen (
    17642178#ifndef WIN32
    1765                                            (LPCTSTR)
    1766 #endif
    1767                                            "ZooWPSClient\0",
    1768                                            INTERNET_OPEN_TYPE_PRECONFIG,
    1769                                            NULL,NULL, 0);
    1770                     if(!CHECK_INET_HANDLE(hInternet))
    1771                       fprintf(stderr,"WARNING : hInternet handle failed to initialize");
     2179                                                             (LPCTSTR)
     2180#endif
     2181                                                             "ZooWPSClient\0",
     2182                                                             INTERNET_OPEN_TYPE_PRECONFIG,
     2183                                                             NULL, NULL, 0);
     2184                                  if (!CHECK_INET_HANDLE (hInternet))
     2185                                    fprintf (stderr,
     2186                                             "WARNING : hInternet handle failed to initialize");
    17722187#ifdef POST_DEBUG
    1773                     curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1);
    1774 #endif
    1775                     bInternet.waitingRequests[0]=strdup((char*)val);
    1776                     res1=InternetOpenUrl(&bInternet,bInternet.waitingRequests[0],NULL,0,
    1777                                          INTERNET_FLAG_NO_CACHE_WRITE,0);
    1778                     processDownloads(&bInternet);
    1779                     char* tmp=
    1780                       (char*)malloc((bInternet.ihandle[0].nDataLen+1)*sizeof(char));
    1781                     if(tmp == NULL){
    1782                       return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    1783                     }
    1784                     size_t bRead;
    1785                     InternetReadFile(bInternet.ihandle[0], (LPVOID)tmp,
    1786                                      bInternet.ihandle[0].nDataLen, &bRead);
    1787                     tmp[bInternet.ihandle[0].nDataLen]=0;
    1788                     InternetCloseHandle(&bInternet);
    1789                     map *btmp=getMap(tmpmaps->content,"href");
    1790                     if(btmp!=NULL){
     2188                                  curl_easy_setopt (bInternet.handle,
     2189                                                    CURLOPT_VERBOSE, 1);
     2190#endif
     2191                                  bInternet.waitingRequests[0] =
     2192                                    strdup ((char *) val);
     2193                                  res1 =
     2194                                    InternetOpenUrl (&bInternet,
     2195                                                     bInternet.waitingRequests
     2196                                                     [0], NULL, 0,
     2197                                                     INTERNET_FLAG_NO_CACHE_WRITE,
     2198                                                     0);
     2199                                  processDownloads (&bInternet);
     2200                                  char *tmp =
     2201                                    (char *)
     2202                                    malloc ((bInternet.ihandle[0].nDataLen +
     2203                                             1) * sizeof (char));
     2204                                  if (tmp == NULL)
     2205                                    {
     2206                                      return errorException (m,
     2207                                                             _
     2208                                                             ("Unable to allocate memory."),
     2209                                                             "InternalError",
     2210                                                             NULL);
     2211                                    }
     2212                                  size_t bRead;
     2213                                  InternetReadFile (bInternet.ihandle[0],
     2214                                                    (LPVOID) tmp,
     2215                                                    bInternet.
     2216                                                    ihandle[0].nDataLen,
     2217                                                    &bRead);
     2218                                  tmp[bInternet.ihandle[0].nDataLen] = 0;
     2219                                  InternetCloseHandle (&bInternet);
     2220                                  map *btmp =
     2221                                    getMap (tmpmaps->content, "href");
     2222                                  if (btmp != NULL)
     2223                                    {
    17912224#ifdef POST_DEBUG
    1792                       fprintf(stderr,"%s %s\n",btmp->value,tmp);
    1793 #endif
    1794                       hInternet.waitingRequests[hInternet.nb]=strdup(tmp);
    1795                       res=InternetOpenUrl(&hInternet,btmp->value,hInternet.waitingRequests[hInternet.nb],
    1796                                           strlen(hInternet.waitingRequests[hInternet.nb]),
    1797                                           INTERNET_FLAG_NO_CACHE_WRITE,0);
    1798                     }
    1799                     free(tmp);
    1800                   }
    1801               }
    1802               cur3=cur3->next;
    1803             }
     2225                                      fprintf (stderr, "%s %s\n", btmp->value,
     2226                                               tmp);
     2227#endif
     2228                                      hInternet.
     2229                                        waitingRequests[hInternet.nb] =
     2230                                        strdup (tmp);
     2231                                      res =
     2232                                        InternetOpenUrl (&hInternet,
     2233                                                         btmp->value,
     2234                                                         hInternet.waitingRequests
     2235                                                         [hInternet.nb],
     2236                                                         strlen
     2237                                                         (hInternet.waitingRequests
     2238                                                          [hInternet.nb]),
     2239                                                         INTERNET_FLAG_NO_CACHE_WRITE,
     2240                                                         0);
     2241                                    }
     2242                                  free (tmp);
     2243                                }
     2244                            }
     2245                          cur3 = cur3->next;
     2246                        }
    18042247#ifdef POST_DEBUG
    1805             fprintf(stderr,"Header and Body was parsed from Reference \n");
    1806 #endif
    1807 #ifdef DEBUG
    1808             dumpMap(tmpmaps->content);
    1809             fprintf(stderr, "= element 2 node \"%s\" = (%s)\n",
    1810                     cur2->name,cur2->content);
    1811 #endif
    1812           }
    1813           else if(xmlStrcasecmp(cur2->name,BAD_CAST "Data")==0){
    1814 #ifdef DEBUG
    1815             fprintf(stderr,"DATA\n");
    1816 #endif
    1817             xmlNodePtr cur4=cur2->children;
    1818             while(cur4!=NULL){
    1819               while(cur4!=NULL &&cur4->type!=XML_ELEMENT_NODE)
    1820                 cur4=cur4->next;
    1821               if(cur4==NULL)
    1822                 break;
    1823               if(xmlStrcasecmp(cur4->name, BAD_CAST "LiteralData")==0){
    1824                 /**
     2248                      fprintf (stderr,
     2249                               "Header and Body was parsed from Reference \n");
     2250#endif
     2251#ifdef DEBUG
     2252                      dumpMap (tmpmaps->content);
     2253                      fprintf (stderr, "= element 2 node \"%s\" = (%s)\n",
     2254                               cur2->name, cur2->content);
     2255#endif
     2256                    }
     2257                  else if (xmlStrcasecmp (cur2->name, BAD_CAST "Data") == 0)
     2258                    {
     2259#ifdef DEBUG
     2260                      fprintf (stderr, "DATA\n");
     2261#endif
     2262                      xmlNodePtr cur4 = cur2->children;
     2263                      while (cur4 != NULL)
     2264                        {
     2265                          while (cur4 != NULL
     2266                                 && cur4->type != XML_ELEMENT_NODE)
     2267                            cur4 = cur4->next;
     2268                          if (cur4 == NULL)
     2269                            break;
     2270                          if (xmlStrcasecmp
     2271                              (cur4->name, BAD_CAST "LiteralData") == 0)
     2272                            {
     2273                /**
    18252274                 * Get every attribute from a LiteralData node
    18262275                 * dataType , uom
    18272276                 */
    1828                 char *list[2];
    1829                 list[0]=zStrdup("dataType");
    1830                 list[1]=zStrdup("uom");
    1831                 for(int l=0;l<2;l++){
    1832 #ifdef DEBUG
    1833                   fprintf(stderr,"*** LiteralData %s ***",list[l]);
    1834 #endif
    1835                   xmlChar *val=xmlGetProp(cur4,BAD_CAST list[l]);
    1836                   if(val!=NULL && strlen((char*)val)>0){
    1837                     if(tmpmaps->content!=NULL)
    1838                       addToMap(tmpmaps->content,list[l],(char*)val);
    1839                     else
    1840                       tmpmaps->content=createMap(list[l],(char*)val);
    1841 #ifdef DEBUG
    1842                     fprintf(stderr,"%s\n",val);
    1843 #endif
    1844                   }
    1845                   xmlFree(val);
    1846                   free(list[l]);                 
    1847                 }
    1848               }
    1849               else if(xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0){
    1850                 /**
     2277                              char *list[2];
     2278                              list[0] = zStrdup ("dataType");
     2279                              list[1] = zStrdup ("uom");
     2280                              for (int l = 0; l < 2; l++)
     2281                                {
     2282#ifdef DEBUG
     2283                                  fprintf (stderr, "*** LiteralData %s ***",
     2284                                           list[l]);
     2285#endif
     2286                                  xmlChar *val =
     2287                                    xmlGetProp (cur4, BAD_CAST list[l]);
     2288                                  if (val != NULL
     2289                                      && strlen ((char *) val) > 0)
     2290                                    {
     2291                                      if (tmpmaps->content != NULL)
     2292                                        addToMap (tmpmaps->content, list[l],
     2293                                                  (char *) val);
     2294                                      else
     2295                                        tmpmaps->content =
     2296                                          createMap (list[l], (char *) val);
     2297#ifdef DEBUG
     2298                                      fprintf (stderr, "%s\n", val);
     2299#endif
     2300                                    }
     2301                                  xmlFree (val);
     2302                                  free (list[l]);
     2303                                }
     2304                            }
     2305                          else
     2306                            if (xmlStrcasecmp
     2307                                (cur4->name, BAD_CAST "ComplexData") == 0)
     2308                            {
     2309                /**
    18512310                 * Get every attribute from a Reference node
    18522311                 * mimeType, encoding, schema
    18532312                 */
    1854                 const char *coms[3]={"mimeType","encoding","schema"};
    1855                 for(int l=0;l<3;l++){
    1856 #ifdef DEBUG
    1857                   fprintf(stderr,"*** ComplexData %s ***\n",coms[l]);
    1858 #endif
    1859                   xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]);
    1860                   if(val!=NULL && strlen((char*)val)>0){
    1861                     if(tmpmaps->content!=NULL)
    1862                       addToMap(tmpmaps->content,coms[l],(char*)val);
    1863                     else
    1864                       tmpmaps->content=createMap(coms[l],(char*)val);
    1865 #ifdef DEBUG
    1866                     fprintf(stderr,"%s\n",val);
    1867 #endif
    1868                   }
    1869                   xmlFree(val);
    1870                 }
    1871               }
    1872 
    1873               map* test=getMap(tmpmaps->content,"encoding");
    1874               if(test==NULL){
    1875                 if(tmpmaps->content!=NULL)
    1876                   addToMap(tmpmaps->content,"encoding","utf-8");
    1877                 else
    1878                   tmpmaps->content=createMap("encoding","utf-8");
    1879                 test=getMap(tmpmaps->content,"encoding");
    1880               }
    1881 
    1882               if(strcasecmp(test->value,"base64")!=0){
    1883                 xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1);
    1884                 map* ltmp=getMap(tmpmaps->content,"mimeType");
    1885                 if(mv==NULL ||
    1886                    (xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0 &&
    1887                     (ltmp==NULL || strncasecmp(ltmp->value,"text/xml",8)==0) )){
    1888                   xmlDocPtr doc1=xmlNewDoc(BAD_CAST "1.0");
    1889                   int buffersize;
    1890                   xmlNodePtr cur5=cur4->children;
    1891                   while(cur5!=NULL && cur5->type!=XML_ELEMENT_NODE && cur5->type!=XML_CDATA_SECTION_NODE)
    1892                     cur5=cur5->next;
    1893                   if(cur5!=NULL && cur5->type!=XML_CDATA_SECTION_NODE){
    1894                     xmlDocSetRootElement(doc1,cur5);
    1895                     xmlDocDumpFormatMemoryEnc(doc1, &mv, &buffersize, "utf-8", 1);
    1896                     char size[1024];
    1897                     sprintf(size,"%d",buffersize);
    1898                     addToMap(tmpmaps->content,"size",size);
    1899                     xmlFreeDoc(doc1);
    1900                   }
    1901                 }
    1902                 if(mv!=NULL){
    1903                   addToMap(tmpmaps->content,"value",(char*)mv);
    1904                   xmlFree(mv);
    1905                 }
    1906               }else{
    1907                 xmlChar* tmp=xmlNodeListGetRawString(doc,cur4->xmlChildrenNode,0);
    1908                 addToMap(tmpmaps->content,"value",(char*)tmp);
    1909                 map* tmpv=getMap(tmpmaps->content,"value");
    1910                 char *res=NULL;
    1911                 char *curs=tmpv->value;
    1912                 for(int i=0;i<=strlen(tmpv->value)/64;i++) {
    1913                   if(res==NULL)
    1914                     res=(char*)malloc(67*sizeof(char));
    1915                   else
    1916                     res=(char*)realloc(res,(((i+1)*65)+i)*sizeof(char));
    1917                   int csize=i*65;
    1918                   strncpy(res + csize,curs,64);
    1919                   if(i==xmlStrlen(tmp)/64)
    1920                     strcat(res,"\n\0");
    1921                   else{
    1922                     strncpy(res + (((i+1)*64)+i),"\n\0",2);
    1923                     curs+=64;
    1924                   }
    1925                 }
    1926                 free(tmpv->value);
    1927                 tmpv->value=zStrdup(res);
    1928                 free(res);
    1929                 xmlFree(tmp);
    1930               }
    1931               cur4=cur4->next;
    1932             }
    1933           }
    1934 #ifdef DEBUG
    1935           fprintf(stderr,"cur2 next \n");
    1936           fflush(stderr);
    1937 #endif
    1938           cur2=cur2->next;
    1939         }
    1940 #ifdef DEBUG
    1941         fprintf(stderr,"ADD MAPS TO REQUEST MAPS !\n");
    1942         fflush(stderr);
    1943 #endif
    1944 
    1945         {
    1946           maps* testPresence=getMaps(request_input_real_format,tmpmaps->name);
    1947           if(testPresence!=NULL){
    1948             elements* elem=getElements(s1->inputs,tmpmaps->name);
    1949             if(elem!=NULL){
    1950               if(appendMapsToMaps(m,request_input_real_format,tmpmaps,elem)<0){
    1951                 freeMaps(&m);
    1952                 free(m);
    1953                 free(REQUEST);
    1954                 free(SERVICE_URL);
    1955                 InternetCloseHandle(&hInternet);
    1956                 freeService(&s1);
    1957                 free(s1);
    1958                 return 0;
    1959               }
    1960             }
    1961           }
    1962           else
    1963             addMapsToMaps(&request_input_real_format,tmpmaps);
    1964         }
    1965 
    1966 #ifdef DEBUG
    1967         fprintf(stderr,"******TMPMAPS*****\n");
    1968         dumpMaps(tmpmaps);
    1969         fprintf(stderr,"******REQUESTMAPS*****\n");
    1970         dumpMaps(request_input_real_format);
    1971 #endif
    1972         freeMaps(&tmpmaps);
    1973         free(tmpmaps);
    1974         tmpmaps=NULL;         
    1975       }
    1976 #ifdef DEBUG
    1977       dumpMaps(tmpmaps);
    1978 #endif
    1979     }
    1980 #ifdef DEBUG
    1981     fprintf(stderr,"Search for response document node\n");
    1982 #endif
    1983     xmlXPathFreeObject(tmpsptr);
    1984    
    1985     tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']");
    1986     bool asRaw=false;
    1987     tmps=tmpsptr->nodesetval;
    1988     if(tmps->nodeNr==0){
    1989       xmlXPathFreeObject(tmpsptr);
    1990       tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']");
    1991       tmps=tmpsptr->nodesetval;
    1992       asRaw=true;
    1993     }
    1994 #ifdef DEBUG
    1995     fprintf(stderr,"*****%d*****\n",tmps->nodeNr);
    1996 #endif
    1997     if(asRaw==true){
    1998       addToMap(request_inputs,"RawDataOutput","");
    1999       xmlNodePtr cur0=tmps->nodeTab[0];
    2000       if(cur0->type == XML_ELEMENT_NODE) {
    2001        
    2002         maps* tmpmaps=(maps*)malloc(MAPS_SIZE);
    2003         if(tmpmaps == NULL){
    2004           return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    2005         }
    2006         tmpmaps->name=zStrdup("unknownIdentifier");
    2007         tmpmaps->content=NULL;
    2008         tmpmaps->next=NULL;
    2009        
    2010         /**
     2313                              const char *coms[3] =
     2314                                { "mimeType", "encoding", "schema" };
     2315                              for (int l = 0; l < 3; l++)
     2316                                {
     2317#ifdef DEBUG
     2318                                  fprintf (stderr, "*** ComplexData %s ***\n",
     2319                                           coms[l]);
     2320#endif
     2321                                  xmlChar *val =
     2322                                    xmlGetProp (cur4, BAD_CAST coms[l]);
     2323                                  if (val != NULL
     2324                                      && strlen ((char *) val) > 0)
     2325                                    {
     2326                                      if (tmpmaps->content != NULL)
     2327                                        addToMap (tmpmaps->content, coms[l],
     2328                                                  (char *) val);
     2329                                      else
     2330                                        tmpmaps->content =
     2331                                          createMap (coms[l], (char *) val);
     2332#ifdef DEBUG
     2333                                      fprintf (stderr, "%s\n", val);
     2334#endif
     2335                                    }
     2336                                  xmlFree (val);
     2337                                }
     2338                            }
     2339
     2340                          map *test = getMap (tmpmaps->content, "encoding");
     2341                          if (test == NULL)
     2342                            {
     2343                              if (tmpmaps->content != NULL)
     2344                                addToMap (tmpmaps->content, "encoding",
     2345                                          "utf-8");
     2346                              else
     2347                                tmpmaps->content =
     2348                                  createMap ("encoding", "utf-8");
     2349                              test = getMap (tmpmaps->content, "encoding");
     2350                            }
     2351
     2352                          if (strcasecmp (test->value, "base64") != 0)
     2353                            {
     2354                              xmlChar *mv = xmlNodeListGetString (doc,
     2355                                                                  cur4->
     2356                                                                  xmlChildrenNode,
     2357                                                                  1);
     2358                              map *ltmp =
     2359                                getMap (tmpmaps->content, "mimeType");
     2360                              if (mv == NULL
     2361                                  ||
     2362                                  (xmlStrcasecmp
     2363                                   (cur4->name, BAD_CAST "ComplexData") == 0
     2364                                   && (ltmp == NULL
     2365                                       || strncasecmp (ltmp->value,
     2366                                                       "text/xml", 8) == 0)))
     2367                                {
     2368                                  xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0");
     2369                                  int buffersize;
     2370                                  xmlNodePtr cur5 = cur4->children;
     2371                                  while (cur5 != NULL
     2372                                         && cur5->type != XML_ELEMENT_NODE
     2373                                         && cur5->type !=
     2374                                         XML_CDATA_SECTION_NODE)
     2375                                    cur5 = cur5->next;
     2376                                  if (cur5 != NULL
     2377                                      && cur5->type != XML_CDATA_SECTION_NODE)
     2378                                    {
     2379                                      xmlDocSetRootElement (doc1, cur5);
     2380                                      xmlDocDumpFormatMemoryEnc (doc1, &mv,
     2381                                                                 &buffersize,
     2382                                                                 "utf-8", 1);
     2383                                      char size[1024];
     2384                                      sprintf (size, "%d", buffersize);
     2385                                      addToMap (tmpmaps->content, "size",
     2386                                                size);
     2387                                      xmlFreeDoc (doc1);
     2388                                    }
     2389                                }
     2390                              if (mv != NULL)
     2391                                {
     2392                                  addToMap (tmpmaps->content, "value",
     2393                                            (char *) mv);
     2394                                  xmlFree (mv);
     2395                                }
     2396                            }
     2397                          else
     2398                            {
     2399                              xmlChar *tmp = xmlNodeListGetRawString (doc,
     2400                                                                      cur4->xmlChildrenNode,
     2401                                                                      0);
     2402                              addToMap (tmpmaps->content, "value",
     2403                                        (char *) tmp);
     2404                              map *tmpv = getMap (tmpmaps->content, "value");
     2405                              char *res = NULL;
     2406                              char *curs = tmpv->value;
     2407                              for (int i = 0; i <= strlen (tmpv->value) / 64;
     2408                                   i++)
     2409                                {
     2410                                  if (res == NULL)
     2411                                    res =
     2412                                      (char *) malloc (67 * sizeof (char));
     2413                                  else
     2414                                    res =
     2415                                      (char *) realloc (res,
     2416                                                        (((i + 1) * 65) +
     2417                                                         i) * sizeof (char));
     2418                                  int csize = i * 65;
     2419                                  strncpy (res + csize, curs, 64);
     2420                                  if (i == xmlStrlen (tmp) / 64)
     2421                                    strcat (res, "\n\0");
     2422                                  else
     2423                                    {
     2424                                      strncpy (res + (((i + 1) * 64) + i),
     2425                                               "\n\0", 2);
     2426                                      curs += 64;
     2427                                    }
     2428                                }
     2429                              free (tmpv->value);
     2430                              tmpv->value = zStrdup (res);
     2431                              free (res);
     2432                              xmlFree (tmp);
     2433                            }
     2434                          cur4 = cur4->next;
     2435                        }
     2436                    }
     2437#ifdef DEBUG
     2438                  fprintf (stderr, "cur2 next \n");
     2439                  fflush (stderr);
     2440#endif
     2441                  cur2 = cur2->next;
     2442                }
     2443#ifdef DEBUG
     2444              fprintf (stderr, "ADD MAPS TO REQUEST MAPS !\n");
     2445              fflush (stderr);
     2446#endif
     2447
     2448              {
     2449                maps *testPresence =
     2450                  getMaps (request_input_real_format, tmpmaps->name);
     2451                if (testPresence != NULL)
     2452                  {
     2453                    elements *elem = getElements (s1->inputs, tmpmaps->name);
     2454                    if (elem != NULL)
     2455                      {
     2456                        if (appendMapsToMaps
     2457                            (m, request_input_real_format, tmpmaps, elem) < 0)
     2458                          {
     2459                            freeMaps (&m);
     2460                            free (m);
     2461                            free (REQUEST);
     2462                            free (SERVICE_URL);
     2463                            InternetCloseHandle (&hInternet);
     2464                            freeService (&s1);
     2465                            free (s1);
     2466                            return 0;
     2467                          }
     2468                      }
     2469                  }
     2470                else
     2471                  addMapsToMaps (&request_input_real_format, tmpmaps);
     2472              }
     2473
     2474#ifdef DEBUG
     2475              fprintf (stderr, "******TMPMAPS*****\n");
     2476              dumpMaps (tmpmaps);
     2477              fprintf (stderr, "******REQUESTMAPS*****\n");
     2478              dumpMaps (request_input_real_format);
     2479#endif
     2480              freeMaps (&tmpmaps);
     2481              free (tmpmaps);
     2482              tmpmaps = NULL;
     2483            }
     2484#ifdef DEBUG
     2485          dumpMaps (tmpmaps);
     2486#endif
     2487        }
     2488#ifdef DEBUG
     2489      fprintf (stderr, "Search for response document node\n");
     2490#endif
     2491      xmlXPathFreeObject (tmpsptr);
     2492
     2493      tmpsptr =
     2494        extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']");
     2495      bool asRaw = false;
     2496      tmps = tmpsptr->nodesetval;
     2497      if (tmps->nodeNr == 0)
     2498        {
     2499          xmlXPathFreeObject (tmpsptr);
     2500          tmpsptr =
     2501            extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']");
     2502          tmps = tmpsptr->nodesetval;
     2503          asRaw = true;
     2504        }
     2505#ifdef DEBUG
     2506      fprintf (stderr, "*****%d*****\n", tmps->nodeNr);
     2507#endif
     2508      if (asRaw == true)
     2509        {
     2510          addToMap (request_inputs, "RawDataOutput", "");
     2511          xmlNodePtr cur0 = tmps->nodeTab[0];
     2512          if (cur0->type == XML_ELEMENT_NODE)
     2513            {
     2514
     2515              maps *tmpmaps = (maps *) malloc (MAPS_SIZE);
     2516              if (tmpmaps == NULL)
     2517                {
     2518                  return errorException (m, _("Unable to allocate memory."),
     2519                                         "InternalError", NULL);
     2520                }
     2521              tmpmaps->name = zStrdup ("unknownIdentifier");
     2522              tmpmaps->content = NULL;
     2523              tmpmaps->next = NULL;
     2524
     2525        /**
    20112526         * Get every attribute from a RawDataOutput node
    20122527         * mimeType, encoding, schema, uom
    20132528         */
    2014         const char *outs[4]={"mimeType","encoding","schema","uom"};
    2015         for(int l=0;l<4;l++){
    2016 #ifdef DEBUG
    2017           fprintf(stderr,"*** %s ***\t",outs[l]);
    2018 #endif
    2019           xmlChar *val=xmlGetProp(cur0,BAD_CAST outs[l]);
    2020           if(val!=NULL){
    2021             if(strlen((char*)val)>0){
    2022               if(tmpmaps->content!=NULL)
    2023                 addToMap(tmpmaps->content,outs[l],(char*)val);
    2024               else
    2025                 tmpmaps->content=createMap(outs[l],(char*)val);
    2026             }
    2027             xmlFree(val);
    2028           }
    2029         }
    2030         xmlNodePtr cur2=cur0->children;
    2031         while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE)
    2032           cur2=cur2->next;
    2033         int cur1cnt=0;
    2034         while(cur2!=NULL){
    2035           if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
    2036             xmlChar *val=
    2037               xmlNodeListGetString(NULL,cur2->xmlChildrenNode,1);
    2038             free(tmpmaps->name);
    2039             tmpmaps->name=zStrdup((char*)val);
    2040             xmlFree(val);
    2041           }
    2042           cur2=cur2->next;
    2043           while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE)
    2044             cur2=cur2->next;
    2045         }
    2046         if(request_output_real_format==NULL)
    2047           request_output_real_format=dupMaps(&tmpmaps);
    2048         else
    2049           addMapsToMaps(&request_output_real_format,tmpmaps);
    2050         if(tmpmaps!=NULL){
    2051           freeMaps(&tmpmaps);
    2052           free(tmpmaps);
    2053           tmpmaps=NULL;
    2054         }
    2055       }
    2056     }
    2057     else
    2058       for(int k=0;k<tmps->nodeNr;k++){
    2059         //else
    2060         addToMap(request_inputs,"ResponseDocument","");
    2061         maps *tmpmaps=NULL;
    2062         xmlNodePtr cur=tmps->nodeTab[k];
    2063         if(cur->type == XML_ELEMENT_NODE) {
    2064           /**
     2529              const char *outs[4] =
     2530                { "mimeType", "encoding", "schema", "uom" };
     2531              for (int l = 0; l < 4; l++)
     2532                {
     2533#ifdef DEBUG
     2534                  fprintf (stderr, "*** %s ***\t", outs[l]);
     2535#endif
     2536                  xmlChar *val = xmlGetProp (cur0, BAD_CAST outs[l]);
     2537                  if (val != NULL)
     2538                    {
     2539                      if (strlen ((char *) val) > 0)
     2540                        {
     2541                          if (tmpmaps->content != NULL)
     2542                            addToMap (tmpmaps->content, outs[l],
     2543                                      (char *) val);
     2544                          else
     2545                            tmpmaps->content =
     2546                              createMap (outs[l], (char *) val);
     2547                        }
     2548                      xmlFree (val);
     2549                    }
     2550                }
     2551              xmlNodePtr cur2 = cur0->children;
     2552              while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
     2553                cur2 = cur2->next;
     2554              int cur1cnt = 0;
     2555              while (cur2 != NULL)
     2556                {
     2557                  if (xmlStrncasecmp
     2558                      (cur2->name, BAD_CAST "Identifier",
     2559                       xmlStrlen (cur2->name)) == 0)
     2560                    {
     2561                      xmlChar *val =
     2562                        xmlNodeListGetString (NULL, cur2->xmlChildrenNode, 1);
     2563                      free (tmpmaps->name);
     2564                      tmpmaps->name = zStrdup ((char *) val);
     2565                      xmlFree (val);
     2566                    }
     2567                  cur2 = cur2->next;
     2568                  while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
     2569                    cur2 = cur2->next;
     2570                }
     2571              if (request_output_real_format == NULL)
     2572                request_output_real_format = dupMaps (&tmpmaps);
     2573              else
     2574                addMapsToMaps (&request_output_real_format, tmpmaps);
     2575              if (tmpmaps != NULL)
     2576                {
     2577                  freeMaps (&tmpmaps);
     2578                  free (tmpmaps);
     2579                  tmpmaps = NULL;
     2580                }
     2581            }
     2582        }
     2583      else
     2584        for (int k = 0; k < tmps->nodeNr; k++)
     2585          {
     2586            //else
     2587            addToMap (request_inputs, "ResponseDocument", "");
     2588            maps *tmpmaps = NULL;
     2589            xmlNodePtr cur = tmps->nodeTab[k];
     2590            if (cur->type == XML_ELEMENT_NODE)
     2591              {
     2592          /**
    20652593           * A specific responseDocument node.
    20662594           */
    2067           if(tmpmaps==NULL){
    2068             tmpmaps=(maps*)malloc(MAPS_SIZE);
    2069             if(tmpmaps == NULL){
    2070               return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    2071             }
    2072             tmpmaps->name=zStrdup("unknownIdentifier");
    2073             tmpmaps->content=NULL;
    2074             tmpmaps->next=NULL;
    2075           }
    2076           /**
     2595                if (tmpmaps == NULL)
     2596                  {
     2597                    tmpmaps = (maps *) malloc (MAPS_SIZE);
     2598                    if (tmpmaps == NULL)
     2599                      {
     2600                        return errorException (m,
     2601                                               _
     2602                                               ("Unable to allocate memory."),
     2603                                               "InternalError", NULL);
     2604                      }
     2605                    tmpmaps->name = zStrdup ("unknownIdentifier");
     2606                    tmpmaps->content = NULL;
     2607                    tmpmaps->next = NULL;
     2608                  }
     2609          /**
    20772610           * Get every attribute: storeExecuteResponse, lineage, status
    20782611           */
    2079           const char *ress[3]={"storeExecuteResponse","lineage","status"};
    2080           xmlChar *val;
    2081           for(int l=0;l<3;l++){
    2082 #ifdef DEBUG
    2083             fprintf(stderr,"*** %s ***\t",ress[l]);
    2084 #endif
    2085             val=xmlGetProp(cur,BAD_CAST ress[l]);
    2086             if(val!=NULL && strlen((char*)val)>0){
    2087               if(tmpmaps->content!=NULL)
    2088                 addToMap(tmpmaps->content,ress[l],(char*)val);
    2089               else
    2090                 tmpmaps->content=createMap(ress[l],(char*)val);
    2091               addToMap(request_inputs,ress[l],(char*)val);
    2092             }
    2093 #ifdef DEBUG
    2094             fprintf(stderr,"%s\n",val);
    2095 #endif
    2096             xmlFree(val);
    2097           }
    2098           xmlNodePtr cur1=cur->children;
    2099           while(cur1!=NULL && cur1->type != XML_ELEMENT_NODE)
    2100             cur1=cur1->next;
    2101           int cur1cnt=0;
    2102           while(cur1){
    2103             /**
     2612                const char *ress[3] =
     2613                  { "storeExecuteResponse", "lineage", "status" };
     2614                xmlChar *val;
     2615                for (int l = 0; l < 3; l++)
     2616                  {
     2617#ifdef DEBUG
     2618                    fprintf (stderr, "*** %s ***\t", ress[l]);
     2619#endif
     2620                    val = xmlGetProp (cur, BAD_CAST ress[l]);
     2621                    if (val != NULL && strlen ((char *) val) > 0)
     2622                      {
     2623                        if (tmpmaps->content != NULL)
     2624                          addToMap (tmpmaps->content, ress[l], (char *) val);
     2625                        else
     2626                          tmpmaps->content =
     2627                            createMap (ress[l], (char *) val);
     2628                        addToMap (request_inputs, ress[l], (char *) val);
     2629                      }
     2630#ifdef DEBUG
     2631                    fprintf (stderr, "%s\n", val);
     2632#endif
     2633                    xmlFree (val);
     2634                  }
     2635                xmlNodePtr cur1 = cur->children;
     2636                while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE)
     2637                  cur1 = cur1->next;
     2638                int cur1cnt = 0;
     2639                while (cur1)
     2640                  {
     2641            /**
    21042642             * Indentifier
    21052643             */
    2106             if(xmlStrncasecmp(cur1->name,BAD_CAST "Identifier",xmlStrlen(cur1->name))==0){
    2107               xmlChar *val=
    2108                 xmlNodeListGetString(doc,cur1->xmlChildrenNode,1);
    2109               if(tmpmaps==NULL){
    2110                 tmpmaps=(maps*)malloc(MAPS_SIZE);
    2111                 if(tmpmaps == NULL){
    2112                   return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    2113                 }
    2114                 tmpmaps->name=zStrdup((char*)val);
    2115                 tmpmaps->content=NULL;
    2116                 tmpmaps->next=NULL;
    2117               }
    2118               else{
    2119                 free(tmpmaps->name);
    2120                 tmpmaps->name=zStrdup((char*)val);
    2121               }
    2122               if(asRaw==true)
    2123                 addToMap(request_inputs,"RawDataOutput",(char*)val);
    2124               else{
    2125                 if(cur1cnt==0)
    2126                   addToMap(request_inputs,"ResponseDocument",(char*)val);
    2127                 else{
    2128                   map* tt=getMap(request_inputs,"ResponseDocument");
    2129                   char* tmp=zStrdup(tt->value);
    2130                   free(tt->value);
    2131                   tt->value=(char*)malloc((strlen(tmp)+strlen((char*)val)+1)*sizeof(char));
    2132                   sprintf(tt->value,"%s;%s",tmp,(char*)val);
    2133                   free(tmp);
    2134                 }
    2135               }
    2136               cur1cnt+=1;
    2137               xmlFree(val);
    2138             }
    2139             /**
     2644                    if (xmlStrncasecmp
     2645                        (cur1->name, BAD_CAST "Identifier",
     2646                         xmlStrlen (cur1->name)) == 0)
     2647                      {
     2648                        xmlChar *val =
     2649                          xmlNodeListGetString (doc, cur1->xmlChildrenNode,
     2650                                                1);
     2651                        if (tmpmaps == NULL)
     2652                          {
     2653                            tmpmaps = (maps *) malloc (MAPS_SIZE);
     2654                            if (tmpmaps == NULL)
     2655                              {
     2656                                return errorException (m,
     2657                                                       _
     2658                                                       ("Unable to allocate memory."),
     2659                                                       "InternalError", NULL);
     2660                              }
     2661                            tmpmaps->name = zStrdup ((char *) val);
     2662                            tmpmaps->content = NULL;
     2663                            tmpmaps->next = NULL;
     2664                          }
     2665                        else
     2666                          {
     2667                            free (tmpmaps->name);
     2668                            tmpmaps->name = zStrdup ((char *) val);
     2669                          }
     2670                        if (asRaw == true)
     2671                          addToMap (request_inputs, "RawDataOutput",
     2672                                    (char *) val);
     2673                        else
     2674                          {
     2675                            if (cur1cnt == 0)
     2676                              addToMap (request_inputs, "ResponseDocument",
     2677                                        (char *) val);
     2678                            else
     2679                              {
     2680                                map *tt =
     2681                                  getMap (request_inputs, "ResponseDocument");
     2682                                char *tmp = zStrdup (tt->value);
     2683                                free (tt->value);
     2684                                tt->value =
     2685                                  (char *)
     2686                                  malloc ((strlen (tmp) +
     2687                                           strlen ((char *) val) +
     2688                                           1) * sizeof (char));
     2689                                sprintf (tt->value, "%s;%s", tmp,
     2690                                         (char *) val);
     2691                                free (tmp);
     2692                              }
     2693                          }
     2694                        cur1cnt += 1;
     2695                        xmlFree (val);
     2696                      }
     2697            /**
    21402698             * Title, Asbtract
    21412699             */
    2142             else if(xmlStrncasecmp(cur1->name,BAD_CAST "Title",xmlStrlen(cur1->name))==0 ||
    2143                     xmlStrncasecmp(cur1->name,BAD_CAST "Abstract",xmlStrlen(cur1->name))==0){
    2144               xmlChar *val=
    2145                 xmlNodeListGetString(doc,cur1->xmlChildrenNode,1);
    2146               if(tmpmaps==NULL){
    2147                 tmpmaps=(maps*)malloc(MAPS_SIZE);
    2148                 if(tmpmaps == NULL){
    2149                   return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    2150                 }
    2151                 tmpmaps->name=zStrdup("missingIndetifier");
    2152                 tmpmaps->content=createMap((char*)cur1->name,(char*)val);
    2153                 tmpmaps->next=NULL;
    2154               }
    2155               else{
    2156                 if(tmpmaps->content!=NULL)
    2157                   addToMap(tmpmaps->content,(char*)cur1->name,(char*)val);
    2158                 else
    2159                   tmpmaps->content=createMap((char*)cur1->name,(char*)val);
    2160               }
    2161               xmlFree(val);
    2162             }
    2163             else if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){
    2164               /**
     2700                    else
     2701                      if (xmlStrncasecmp
     2702                          (cur1->name, BAD_CAST "Title",
     2703                           xmlStrlen (cur1->name)) == 0
     2704                          || xmlStrncasecmp (cur1->name, BAD_CAST "Abstract",
     2705                                             xmlStrlen (cur1->name)) == 0)
     2706                      {
     2707                        xmlChar *val =
     2708                          xmlNodeListGetString (doc, cur1->xmlChildrenNode,
     2709                                                1);
     2710                        if (tmpmaps == NULL)
     2711                          {
     2712                            tmpmaps = (maps *) malloc (MAPS_SIZE);
     2713                            if (tmpmaps == NULL)
     2714                              {
     2715                                return errorException (m,
     2716                                                       _
     2717                                                       ("Unable to allocate memory."),
     2718                                                       "InternalError", NULL);
     2719                              }
     2720                            tmpmaps->name = zStrdup ("missingIndetifier");
     2721                            tmpmaps->content =
     2722                              createMap ((char *) cur1->name, (char *) val);
     2723                            tmpmaps->next = NULL;
     2724                          }
     2725                        else
     2726                          {
     2727                            if (tmpmaps->content != NULL)
     2728                              addToMap (tmpmaps->content, (char *) cur1->name,
     2729                                        (char *) val);
     2730                            else
     2731                              tmpmaps->content =
     2732                                createMap ((char *) cur1->name, (char *) val);
     2733                          }
     2734                        xmlFree (val);
     2735                      }
     2736                    else
     2737                      if (xmlStrncasecmp
     2738                          (cur1->name, BAD_CAST "Output",
     2739                           xmlStrlen (cur1->name)) == 0)
     2740                      {
     2741              /**
    21652742               * Get every attribute from a Output node
    21662743               * mimeType, encoding, schema, uom, asReference
    21672744               */
    2168               const char *outs[5]={"mimeType","encoding","schema","uom","asReference"};
    2169               for(int l=0;l<5;l++){
    2170 #ifdef DEBUG
    2171                 fprintf(stderr,"*** %s ***\t",outs[l]);
    2172 #endif
    2173                 xmlChar *val=xmlGetProp(cur1,BAD_CAST outs[l]);
    2174                 if(val!=NULL && strlen((char*)val)>0){
    2175                   if(tmpmaps->content!=NULL)
    2176                     addToMap(tmpmaps->content,outs[l],(char*)val);
    2177                   else
    2178                     tmpmaps->content=createMap(outs[l],(char*)val);
    2179                 }
    2180 #ifdef DEBUG
    2181                 fprintf(stderr,"%s\n",val);
    2182 #endif
    2183                 xmlFree(val);
    2184               }
    2185               xmlNodePtr cur2=cur1->children;
    2186               while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE)
    2187                 cur2=cur2->next;
    2188               while(cur2){
    2189                 /**
     2745                        const char *outs[5] =
     2746                          { "mimeType", "encoding", "schema", "uom",
     2747                          "asReference"
     2748                        };
     2749                        for (int l = 0; l < 5; l++)
     2750                          {
     2751#ifdef DEBUG
     2752                            fprintf (stderr, "*** %s ***\t", outs[l]);
     2753#endif
     2754                            xmlChar *val =
     2755                              xmlGetProp (cur1, BAD_CAST outs[l]);
     2756                            if (val != NULL && strlen ((char *) val) > 0)
     2757                              {
     2758                                if (tmpmaps->content != NULL)
     2759                                  addToMap (tmpmaps->content, outs[l],
     2760                                            (char *) val);
     2761                                else
     2762                                  tmpmaps->content =
     2763                                    createMap (outs[l], (char *) val);
     2764                              }
     2765#ifdef DEBUG
     2766                            fprintf (stderr, "%s\n", val);
     2767#endif
     2768                            xmlFree (val);
     2769                          }
     2770                        xmlNodePtr cur2 = cur1->children;
     2771                        while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
     2772                          cur2 = cur2->next;
     2773                        while (cur2)
     2774                          {
     2775                /**
    21902776                 * Indentifier
    21912777                 */
    2192                 if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
    2193                   xmlChar *val=
    2194                     xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    2195                   if(tmpmaps==NULL){
    2196                     tmpmaps=(maps*)malloc(MAPS_SIZE);
    2197                     if(tmpmaps == NULL){
    2198                       return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    2199                     }
    2200                     tmpmaps->name=zStrdup((char*)val);
    2201                     tmpmaps->content=NULL;
    2202                     tmpmaps->next=NULL;
    2203                   }
    2204                   else{
    2205                     if(tmpmaps->name!=NULL)
    2206                       free(tmpmaps->name);
    2207                     tmpmaps->name=zStrdup((char*)val);;
    2208                   }
    2209                   xmlFree(val);
    2210                 }
    2211                 /**
     2778                            if (xmlStrncasecmp
     2779                                (cur2->name, BAD_CAST "Identifier",
     2780                                 xmlStrlen (cur2->name)) == 0)
     2781                              {
     2782                                xmlChar *val = xmlNodeListGetString (doc,
     2783                                                                     cur2->
     2784                                                                     xmlChildrenNode,
     2785                                                                     1);
     2786                                if (tmpmaps == NULL)
     2787                                  {
     2788                                    tmpmaps = (maps *) malloc (MAPS_SIZE);
     2789                                    if (tmpmaps == NULL)
     2790                                      {
     2791                                        return errorException (m,
     2792                                                               _
     2793                                                               ("Unable to allocate memory."),
     2794                                                               "InternalError",
     2795                                                               NULL);
     2796                                      }
     2797                                    tmpmaps->name = zStrdup ((char *) val);
     2798                                    tmpmaps->content = NULL;
     2799                                    tmpmaps->next = NULL;
     2800                                  }
     2801                                else
     2802                                  {
     2803                                    if (tmpmaps->name != NULL)
     2804                                      free (tmpmaps->name);
     2805                                    tmpmaps->name = zStrdup ((char *) val);;
     2806                                  }
     2807                                xmlFree (val);
     2808                              }
     2809                /**
    22122810                 * Title, Asbtract
    22132811                 */
    2214                 else if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
    2215                         xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
    2216                   xmlChar *val=
    2217                     xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    2218                   if(tmpmaps==NULL){
    2219                     tmpmaps=(maps*)malloc(MAPS_SIZE);
    2220                     if(tmpmaps == NULL){
    2221                       return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
    2222                     }
    2223                     tmpmaps->name=zStrdup("missingIndetifier");
    2224                     tmpmaps->content=createMap((char*)cur2->name,(char*)val);
    2225                     tmpmaps->next=NULL;
    2226                   }
    2227                   else{
    2228                     if(tmpmaps->content!=NULL)
    2229                       addToMap(tmpmaps->content,
    2230                                (char*)cur2->name,(char*)val);
    2231                     else
    2232                       tmpmaps->content=
    2233                         createMap((char*)cur2->name,(char*)val);
    2234                   }
    2235                   xmlFree(val);
    2236                 }
    2237                 cur2=cur2->next;
    2238                 while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE)
    2239                   cur2=cur2->next;
    2240               }
    2241             }
    2242             cur1=cur1->next;
    2243             while(cur1!=NULL && cur1->type != XML_ELEMENT_NODE)
    2244               cur1=cur1->next;
    2245           }
    2246         }
    2247         if(request_output_real_format==NULL)
    2248           request_output_real_format=dupMaps(&tmpmaps);
    2249         else
    2250           addMapsToMaps(&request_output_real_format,tmpmaps);
    2251         if(tmpmaps!=NULL){
    2252           freeMaps(&tmpmaps);
    2253           free(tmpmaps);
    2254           tmpmaps=NULL;
    2255         }
    2256       }
    2257     xmlXPathFreeObject(tmpsptr);
    2258     xmlFreeDoc(doc);
    2259     xmlCleanupParser();
    2260   }
    2261  
    2262   runHttpRequests(&m,&request_input_real_format,&hInternet);
     2812                            else
     2813                              if (xmlStrncasecmp
     2814                                  (cur2->name, BAD_CAST "Title",
     2815                                   xmlStrlen (cur2->name)) == 0
     2816                                  || xmlStrncasecmp (cur2->name,
     2817                                                     BAD_CAST "Abstract",
     2818                                                     xmlStrlen (cur2->name))
     2819                                  == 0)
     2820                              {
     2821                                xmlChar *val = xmlNodeListGetString (doc,
     2822                                                                     cur2->
     2823                                                                     xmlChildrenNode,
     2824                                                                     1);
     2825                                if (tmpmaps == NULL)
     2826                                  {
     2827                                    tmpmaps = (maps *) malloc (MAPS_SIZE);
     2828                                    if (tmpmaps == NULL)
     2829                                      {
     2830                                        return errorException (m,
     2831                                                               _
     2832                                                               ("Unable to allocate memory."),
     2833                                                               "InternalError",
     2834                                                               NULL);
     2835                                      }
     2836                                    tmpmaps->name =
     2837                                      zStrdup ("missingIndetifier");
     2838                                    tmpmaps->content =
     2839                                      createMap ((char *) cur2->name,
     2840                                                 (char *) val);
     2841                                    tmpmaps->next = NULL;
     2842                                  }
     2843                                else
     2844                                  {
     2845                                    if (tmpmaps->content != NULL)
     2846                                      addToMap (tmpmaps->content,
     2847                                                (char *) cur2->name,
     2848                                                (char *) val);
     2849                                    else
     2850                                      tmpmaps->content =
     2851                                        createMap ((char *) cur2->name,
     2852                                                   (char *) val);
     2853                                  }
     2854                                xmlFree (val);
     2855                              }
     2856                            cur2 = cur2->next;
     2857                            while (cur2 != NULL
     2858                                   && cur2->type != XML_ELEMENT_NODE)
     2859                              cur2 = cur2->next;
     2860                          }
     2861                      }
     2862                    cur1 = cur1->next;
     2863                    while (cur1 != NULL && cur1->type != XML_ELEMENT_NODE)
     2864                      cur1 = cur1->next;
     2865                  }
     2866              }
     2867            if (request_output_real_format == NULL)
     2868              request_output_real_format = dupMaps (&tmpmaps);
     2869            else
     2870              addMapsToMaps (&request_output_real_format, tmpmaps);
     2871            if (tmpmaps != NULL)
     2872              {
     2873                freeMaps (&tmpmaps);
     2874                free (tmpmaps);
     2875                tmpmaps = NULL;
     2876              }
     2877          }
     2878      xmlXPathFreeObject (tmpsptr);
     2879      xmlFreeDoc (doc);
     2880      xmlCleanupParser ();
     2881    }
     2882
     2883  runHttpRequests (&m, &request_input_real_format, &hInternet);
    22632884
    22642885  //  if(CHECK_INET_HANDLE(hInternet))
    2265   InternetCloseHandle(&hInternet);
    2266 
    2267 #ifdef DEBUG
    2268   fprintf(stderr,"\n%d\n",__LINE__);
    2269   fflush(stderr);
    2270   dumpMaps(request_input_real_format);
    2271   dumpMaps(request_output_real_format);
    2272   dumpMap(request_inputs);
    2273   fprintf(stderr,"\n%d\n",__LINE__);
    2274   fflush(stderr);
     2886  InternetCloseHandle (&hInternet);
     2887
     2888#ifdef DEBUG
     2889  fprintf (stderr, "\n%d\n", __LINE__);
     2890  fflush (stderr);
     2891  dumpMaps (request_input_real_format);
     2892  dumpMaps (request_output_real_format);
     2893  dumpMap (request_inputs);
     2894  fprintf (stderr, "\n%d\n", __LINE__);
     2895  fflush (stderr);
    22752896#endif
    22762897
     
    22792900   * DataInputs and ResponseDocument / RawDataOutput
    22802901   */
    2281   char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,0);
    2282   maps *ptr=request_input_real_format;
    2283   while(ptr!=NULL){
    2284     map *tmp0=getMap(ptr->content,"size");
    2285     map *tmp1=getMap(ptr->content,"maximumMegabytes");
    2286     if(tmp1!=NULL && tmp0!=NULL){
    2287       float i=atof(tmp0->value)/1048576.0;
    2288       if(i>=atoi(tmp1->value)){
    2289         char tmps[1024];
    2290         map* tmpe=createMap("code","FileSizeExceeded");
    2291         snprintf(tmps,1024,_("The <%s> parameter has a limited size (%sMB) defined in ZOO ServicesProvider configuration file but the reference you provided exceed this limitation (%fMB), please correct your query or the ZOO Configuration file."),ptr->name,tmp1->value,i);
    2292         addToMap(tmpe,"locator",ptr->name);
    2293         addToMap(tmpe,"text",tmps);
    2294         printExceptionReportResponse(m,tmpe);
    2295         freeService(&s1);
    2296         free(s1);
    2297         freeMap(&tmpe);
    2298         free(tmpe);
    2299         freeMaps(&m);
    2300         free(m);
    2301         free(REQUEST);
    2302         free(SERVICE_URL);
    2303         freeMaps(&request_input_real_format);
    2304         free(request_input_real_format);
    2305         freeMaps(&request_output_real_format);
    2306         free(request_output_real_format);
    2307         freeMaps(&tmpmaps);
    2308         free(tmpmaps);
    2309         return 1;
    2310       }
    2311     }
    2312     ptr=ptr->next;
    2313   }
    2314 
    2315   char *dfv1=addDefaultValues(&request_output_real_format,s1->outputs,m,1);
    2316   if(strcmp(dfv1,"")!=0 || strcmp(dfv,"")!=0){
    2317     char tmps[1024];
    2318     map* tmpe=createMap("code","MissingParameterValue");
    2319     if(strcmp(dfv,"")!=0){
    2320       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);
    2321       addToMap(tmpe,"locator",dfv);
    2322     }
    2323     else if(strcmp(dfv1,"")!=0){
    2324       snprintf(tmps,1024,_("The <%s> argument was specified as Output identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."),dfv1);
    2325       addToMap(tmpe,"locator",dfv1);
    2326     }
    2327     addToMap(tmpe,"text",tmps);
    2328     printExceptionReportResponse(m,tmpe);
    2329     freeService(&s1);
    2330     free(s1);
    2331     freeMap(&tmpe);
    2332     free(tmpe);
    2333     freeMaps(&m);
    2334     free(m);
    2335     free(REQUEST);
    2336     free(SERVICE_URL);
    2337     freeMaps(&request_input_real_format);
    2338     free(request_input_real_format);
    2339     freeMaps(&request_output_real_format);
    2340     free(request_output_real_format);
    2341     freeMaps(&tmpmaps);
    2342     free(tmpmaps);
    2343     return 1;
    2344   }
    2345   maps* tmpReqI=request_input_real_format;
    2346   while(tmpReqI!=NULL){
    2347     char name[1024];
    2348     if(getMap(tmpReqI->content,"isFile")!=NULL){
    2349       if (cgiFormFileName(tmpReqI->name, name, sizeof(name)) == cgiFormSuccess) {
    2350         int BufferLen=1024;
    2351         cgiFilePtr file;
    2352         int targetFile;
    2353         char storageNameOnServer[2048];
    2354         char fileNameOnServer[64];
    2355         char contentType[1024];
    2356         char buffer[1024];
    2357         char *tmpStr=NULL;
    2358         int size;
    2359         int got,t;
    2360         map *path=getMapFromMaps(m,"main","tmpPath");
    2361         cgiFormFileSize(tmpReqI->name, &size);
    2362         cgiFormFileContentType(tmpReqI->name, contentType, sizeof(contentType));
    2363         if (cgiFormFileOpen(tmpReqI->name, &file) == cgiFormSuccess) {
    2364           t=-1;
    2365           while(1){
    2366             tmpStr=strstr(name+t+1,"\\");
    2367             if(NULL==tmpStr)
    2368               tmpStr=strstr(name+t+1,"/");
    2369             if(NULL!=tmpStr)
    2370               t=(int)(tmpStr-name);
    2371             else
    2372               break;
    2373           }
    2374           strcpy(fileNameOnServer,name+t+1);
    2375          
    2376           sprintf(storageNameOnServer,"%s/%s",path->value,fileNameOnServer);
    2377 #ifdef DEBUG
    2378           fprintf(stderr,"Name on server %s\n",storageNameOnServer);
    2379           fprintf(stderr,"fileNameOnServer: %s\n",fileNameOnServer);
    2380 #endif
    2381           targetFile = open (storageNameOnServer,O_RDWR|O_CREAT|O_TRUNC,S_IRWXU|S_IRGRP|S_IROTH);
    2382           if(targetFile<0){
    2383 #ifdef DEBUG
    2384             fprintf(stderr,"could not create the new file,%s\n",fileNameOnServer);         
    2385 #endif
    2386           }else{
    2387             while (cgiFormFileRead(file, buffer, BufferLen, &got) ==cgiFormSuccess){
    2388               if(got>0)
    2389                 write(targetFile,buffer,got);
    2390             }
    2391           }
    2392           addToMap(tmpReqI->content,"lref",storageNameOnServer);
    2393           cgiFormFileClose(file);
    2394           close(targetFile);
    2395 #ifdef DEBUG
    2396           fprintf(stderr,"File \"%s\" has been uploaded",fileNameOnServer);
    2397 #endif
    2398         }
    2399       }
    2400     }
    2401     tmpReqI=tmpReqI->next;
    2402   }
    2403 
    2404   ensureDecodedBase64(&request_input_real_format);
    2405 
    2406 #ifdef DEBUG
    2407   fprintf(stderr,"REQUEST_INPUTS\n");
    2408   dumpMaps(request_input_real_format);
    2409   fprintf(stderr,"REQUEST_OUTPUTS\n");
    2410   dumpMaps(request_output_real_format);
    2411 #endif
    2412 
    2413   maps* curs=getMaps(m,"env");
    2414   if(curs!=NULL){
    2415     map* mapcs=curs->content;
    2416     while(mapcs!=NULLMAP){
     2902  char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0);
     2903  maps *ptr = request_input_real_format;
     2904  while (ptr != NULL)
     2905    {
     2906      map *tmp0 = getMap (ptr->content, "size");
     2907      map *tmp1 = getMap (ptr->content, "maximumMegabytes");
     2908      if (tmp1 != NULL && tmp0 != NULL)
     2909        {
     2910          float i = atof (tmp0->value) / 1048576.0;
     2911          if (i >= atoi (tmp1->value))
     2912            {
     2913              char tmps[1024];
     2914              map *tmpe = createMap ("code", "FileSizeExceeded");
     2915              snprintf (tmps, 1024,
     2916                        _
     2917                        ("The <%s> parameter has a limited size (%sMB) defined in ZOO ServicesProvider configuration file but the reference you provided exceed this limitation (%fMB), please correct your query or the ZOO Configuration file."),
     2918                        ptr->name, tmp1->value, i);
     2919              addToMap (tmpe, "locator", ptr->name);
     2920              addToMap (tmpe, "text", tmps);
     2921              printExceptionReportResponse (m, tmpe);
     2922              freeService (&s1);
     2923              free (s1);
     2924              freeMap (&tmpe);
     2925              free (tmpe);
     2926              freeMaps (&m);
     2927              free (m);
     2928              free (REQUEST);
     2929              free (SERVICE_URL);
     2930              freeMaps (&request_input_real_format);
     2931              free (request_input_real_format);
     2932              freeMaps (&request_output_real_format);
     2933              free (request_output_real_format);
     2934              freeMaps (&tmpmaps);
     2935              free (tmpmaps);
     2936              return 1;
     2937            }
     2938        }
     2939      ptr = ptr->next;
     2940    }
     2941
     2942  char *dfv1 =
     2943    addDefaultValues (&request_output_real_format, s1->outputs, m, 1);
     2944  if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0)
     2945    {
     2946      char tmps[1024];
     2947      map *tmpe = createMap ("code", "MissingParameterValue");
     2948      if (strcmp (dfv, "") != 0)
     2949        {
     2950          snprintf (tmps, 1024,
     2951                    _
     2952                    ("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."),
     2953                    dfv);
     2954          addToMap (tmpe, "locator", dfv);
     2955        }
     2956      else if (strcmp (dfv1, "") != 0)
     2957        {
     2958          snprintf (tmps, 1024,
     2959                    _
     2960                    ("The <%s> argument was specified as Output identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."),
     2961                    dfv1);
     2962          addToMap (tmpe, "locator", dfv1);
     2963        }
     2964      addToMap (tmpe, "text", tmps);
     2965      printExceptionReportResponse (m, tmpe);
     2966      freeService (&s1);
     2967      free (s1);
     2968      freeMap (&tmpe);
     2969      free (tmpe);
     2970      freeMaps (&m);
     2971      free (m);
     2972      free (REQUEST);
     2973      free (SERVICE_URL);
     2974      freeMaps (&request_input_real_format);
     2975      free (request_input_real_format);
     2976      freeMaps (&request_output_real_format);
     2977      free (request_output_real_format);
     2978      freeMaps (&tmpmaps);
     2979      free (tmpmaps);
     2980      return 1;
     2981    }
     2982  maps *tmpReqI = request_input_real_format;
     2983  while (tmpReqI != NULL)
     2984    {
     2985      char name[1024];
     2986      if (getMap (tmpReqI->content, "isFile") != NULL)
     2987        {
     2988          if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) ==
     2989              cgiFormSuccess)
     2990            {
     2991              int BufferLen = 1024;
     2992              cgiFilePtr file;
     2993              int targetFile;
     2994              char storageNameOnServer[2048];
     2995              char fileNameOnServer[64];
     2996              char contentType[1024];
     2997              char buffer[1024];
     2998              char *tmpStr = NULL;
     2999              int size;
     3000              int got, t;
     3001              map *path = getMapFromMaps (m, "main", "tmpPath");
     3002              cgiFormFileSize (tmpReqI->name, &size);
     3003              cgiFormFileContentType (tmpReqI->name, contentType,
     3004                                      sizeof (contentType));
     3005              if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess)
     3006                {
     3007                  t = -1;
     3008                  while (1)
     3009                    {
     3010                      tmpStr = strstr (name + t + 1, "\\");
     3011                      if (NULL == tmpStr)
     3012                        tmpStr = strstr (name + t + 1, "/");
     3013                      if (NULL != tmpStr)
     3014                        t = (int) (tmpStr - name);
     3015                      else
     3016                        break;
     3017                    }
     3018                  strcpy (fileNameOnServer, name + t + 1);
     3019
     3020                  sprintf (storageNameOnServer, "%s/%s", path->value,
     3021                           fileNameOnServer);
     3022#ifdef DEBUG
     3023                  fprintf (stderr, "Name on server %s\n",
     3024                           storageNameOnServer);
     3025                  fprintf (stderr, "fileNameOnServer: %s\n",
     3026                           fileNameOnServer);
     3027#endif
     3028                  targetFile =
     3029                    open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,
     3030                          S_IRWXU | S_IRGRP | S_IROTH);
     3031                  if (targetFile < 0)
     3032                    {
     3033#ifdef DEBUG
     3034                      fprintf (stderr, "could not create the new file,%s\n",
     3035                               fileNameOnServer);
     3036#endif
     3037                    }
     3038                  else
     3039                    {
     3040                      while (cgiFormFileRead (file, buffer, BufferLen, &got)
     3041                             == cgiFormSuccess)
     3042                        {
     3043                          if (got > 0)
     3044                            write (targetFile, buffer, got);
     3045                        }
     3046                    }
     3047                  addToMap (tmpReqI->content, "lref", storageNameOnServer);
     3048                  cgiFormFileClose (file);
     3049                  close (targetFile);
     3050#ifdef DEBUG
     3051                  fprintf (stderr, "File \"%s\" has been uploaded",
     3052                           fileNameOnServer);
     3053#endif
     3054                }
     3055            }
     3056        }
     3057      tmpReqI = tmpReqI->next;
     3058    }
     3059
     3060  ensureDecodedBase64 (&request_input_real_format);
     3061
     3062#ifdef DEBUG
     3063  fprintf (stderr, "REQUEST_INPUTS\n");
     3064  dumpMaps (request_input_real_format);
     3065  fprintf (stderr, "REQUEST_OUTPUTS\n");
     3066  dumpMaps (request_output_real_format);
     3067#endif
     3068
     3069  maps *curs = getMaps (m, "env");
     3070  if (curs != NULL)
     3071    {
     3072      map *mapcs = curs->content;
     3073      while (mapcs != NULLMAP)
     3074        {
    24173075#ifndef WIN32
    2418       setenv(mapcs->name,mapcs->value,1);
     3076          setenv (mapcs->name, mapcs->value, 1);
    24193077#else
    24203078#ifdef DEBUG
    2421       fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value);
    2422 #endif
    2423       if(mapcs->value[strlen(mapcs->value)-2]=='\r'){
    2424 #ifdef DEBUG
    2425         fprintf(stderr,"[ZOO: Env var finish with \r]\n");
    2426 #endif
    2427         mapcs->value[strlen(mapcs->value)-1]=0;
    2428       }
    2429 #ifdef DEBUG
    2430       fflush(stderr);
    2431       fprintf(stderr,"setting variable... %s\n",(
    2432 #endif
    2433                                                  SetEnvironmentVariable(mapcs->name,mapcs->value)
    2434 #ifdef DEBUG
    2435                                                  ==0)? "OK" : "FAILED");
     3079          fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name,
     3080                   mapcs->value);
     3081#endif
     3082          if (mapcs->value[strlen (mapcs->value) - 2] == '\r')
     3083            {
     3084#ifdef DEBUG
     3085              fprintf (stderr, "[ZOO: Env var finish with \r]\n");
     3086#endif
     3087              mapcs->value[strlen (mapcs->value) - 1] = 0;
     3088            }
     3089#ifdef DEBUG
     3090          if (SetEnvironmentVariable (mapcs->name, mapcs->value) == 0)
     3091            {
     3092              fflush (stderr);
     3093              fprintf (stderr, "setting variable... %s\n", "OK");
     3094            }
     3095          else
     3096            {
     3097              fflush (stderr);
     3098              fprintf (stderr, "setting variable... %s\n", "OK");
     3099            }
    24363100#else
    2437       ;
    2438 #endif
    2439       char* toto=(char*)malloc((strlen(mapcs->name)+strlen(mapcs->value)+2)*sizeof(char));
    2440       sprintf(toto,"%s=%s",mapcs->name,mapcs->value);
    2441       putenv(toto);
    2442 #ifdef DEBUG
    2443       fflush(stderr);
    2444 #endif
    2445 #endif
    2446 #ifdef DEBUG
    2447       fprintf(stderr,"[ZOO: setenv (%s=%s)]\n",mapcs->name,mapcs->value);
    2448       fflush(stderr);
    2449 #endif
    2450       mapcs=mapcs->next;
    2451     }
    2452   }
    2453  
    2454 #ifdef DEBUG
    2455   dumpMap(request_inputs);
     3101
     3102
     3103          SetEnvironmentVariable (mapcs->name, mapcs->value);
     3104#endif
     3105          char *toto =
     3106            (char *)
     3107            malloc ((strlen (mapcs->name) + strlen (mapcs->value) +
     3108                     2) * sizeof (char));
     3109          sprintf (toto, "%s=%s", mapcs->name, mapcs->value);
     3110          putenv (toto);
     3111#ifdef DEBUG
     3112          fflush (stderr);
     3113#endif
     3114#endif
     3115#ifdef DEBUG
     3116          fprintf (stderr, "[ZOO: setenv (%s=%s)]\n", mapcs->name,
     3117                   mapcs->value);
     3118          fflush (stderr);
     3119#endif
     3120          mapcs = mapcs->next;
     3121        }
     3122    }
     3123
     3124#ifdef DEBUG
     3125  dumpMap (request_inputs);
    24563126#endif
    24573127
     
    24593129   * Need to check if we need to fork to load a status enabled
    24603130   */
    2461   r_inputs=NULL;
    2462   map* store=getMap(request_inputs,"storeExecuteResponse");
    2463   map* status=getMap(request_inputs,"status");
     3131  r_inputs = NULL;
     3132  map *store = getMap (request_inputs, "storeExecuteResponse");
     3133  map *status = getMap (request_inputs, "status");
    24643134  /**
    24653135   * 05-007r7 WPS 1.0.0 page 57 :
     
    24673137   * shall raise an exception.'
    24683138   */
    2469   if(status!=NULL && strcmp(status->value,"true")==0 &&
    2470      store!=NULL && strcmp(store->value,"false")==0){
    2471     errorException(m, _("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."), "InvalidParameterValue","storeExecuteResponse");
    2472     freeService(&s1);
    2473     free(s1);
    2474     freeMaps(&m);
    2475     free(m);
    2476    
    2477     freeMaps(&request_input_real_format);
    2478     free(request_input_real_format);
    2479    
    2480     freeMaps(&request_output_real_format);
    2481     free(request_output_real_format);
    2482    
    2483     free(REQUEST);
    2484     free(SERVICE_URL);
    2485     return 1;
    2486   }
    2487   r_inputs=getMap(request_inputs,"storeExecuteResponse");
    2488   int eres=SERVICE_STARTED;
    2489   int cpid=getpid();
     3139  if (status != NULL && strcmp (status->value, "true") == 0 &&
     3140      store != NULL && strcmp (store->value, "false") == 0)
     3141    {
     3142      errorException (m,
     3143                      _
     3144                      ("Status cannot be set to true with storeExecuteResponse to false. Please, modify your request parameters."),
     3145                      "InvalidParameterValue", "storeExecuteResponse");
     3146      freeService (&s1);
     3147      free (s1);
     3148      freeMaps (&m);
     3149      free (m);
     3150
     3151      freeMaps (&request_input_real_format);
     3152      free (request_input_real_format);
     3153
     3154      freeMaps (&request_output_real_format);
     3155      free (request_output_real_format);
     3156
     3157      free (REQUEST);
     3158      free (SERVICE_URL);
     3159      return 1;
     3160    }
     3161  r_inputs = getMap (request_inputs, "storeExecuteResponse");
     3162  int eres = SERVICE_STARTED;
     3163  int cpid = getpid ();
    24903164
    24913165  /**
     
    25073181   *
    25083182   */
    2509   maps *_tmpMaps=(maps*)malloc(MAPS_SIZE);
    2510   _tmpMaps->name=zStrdup("lenv");
     3183  maps *_tmpMaps = (maps *) malloc (MAPS_SIZE);
     3184  _tmpMaps->name = zStrdup ("lenv");
    25113185  char tmpBuff[100];
    2512   int lid=getShmLockId(NULL,1);
    2513   lockShm(lid);
     3186  int lid = getShmLockId (NULL, 1);
     3187  lockShm (lid);
    25143188  struct ztimeval tp;
    2515   if(zGettimeofday(&tp,NULL)==0)
    2516     sprintf(tmpBuff,"%i",(cpid+((int)tp.tv_sec+(int)tp.tv_usec)));
     3189  if (zGettimeofday (&tp, NULL) == 0)
     3190    sprintf (tmpBuff, "%i", (cpid + ((int) tp.tv_sec + (int) tp.tv_usec)));
    25173191  else
    2518     sprintf(tmpBuff,"%i",(cpid+(int)time(NULL)));
    2519   unlockShm(lid);
    2520   removeShmLock(NULL,1);
    2521   _tmpMaps->content=createMap("usid",tmpBuff);
    2522   _tmpMaps->next=NULL;
    2523   sprintf(tmpBuff,"%i",cpid);
    2524   addToMap(_tmpMaps->content,"sid",tmpBuff);
    2525   addToMap(_tmpMaps->content,"status","0");
    2526   addToMap(_tmpMaps->content,"cwd",ntmp);
    2527   addToMap(_tmpMaps->content,"message",_("No message provided"));
    2528   map* ltmp=getMap(request_inputs,"soap");
    2529   if(ltmp!=NULL)
    2530     addToMap(_tmpMaps->content,"soap",ltmp->value);
     3192    sprintf (tmpBuff, "%i", (cpid + (int) time (NULL)));
     3193  unlockShm (lid);
     3194  removeShmLock (NULL, 1);
     3195  _tmpMaps->content = createMap ("usid", tmpBuff);
     3196  _tmpMaps->next = NULL;
     3197  sprintf (tmpBuff, "%i", cpid);
     3198  addToMap (_tmpMaps->content, "sid", tmpBuff);
     3199  addToMap (_tmpMaps->content, "status", "0");
     3200  addToMap (_tmpMaps->content, "cwd", ntmp);
     3201  addToMap (_tmpMaps->content, "message", _("No message provided"));
     3202  map *ltmp = getMap (request_inputs, "soap");
     3203  if (ltmp != NULL)
     3204    addToMap (_tmpMaps->content, "soap", ltmp->value);
    25313205  else
    2532     addToMap(_tmpMaps->content,"soap","false");
    2533   if(cgiCookie!=NULL && strlen(cgiCookie)>0){
    2534     int hasValidCookie=-1;
    2535     char *tcook=zStrdup(cgiCookie);
    2536     char *tmp=NULL;
    2537     map* testing=getMapFromMaps(m,"main","cookiePrefix");
    2538     if(testing==NULL){
    2539       tmp=zStrdup("ID=");
    2540     }else{
    2541       tmp=(char*)malloc((strlen(testing->value)+2)*sizeof(char));
    2542       sprintf(tmp,"%s=",testing->value);
    2543     }
    2544     if(strstr(cgiCookie,";")!=NULL){
    2545       char *token,*saveptr;
    2546       token=strtok_r(cgiCookie,";",&saveptr);
    2547       while(token!=NULL){
    2548         if(strcasestr(token,tmp)!=NULL){
    2549           if(tcook!=NULL)
    2550             free(tcook);
    2551           tcook=zStrdup(token);
    2552           hasValidCookie=1;
    2553         }
    2554         token=strtok_r(NULL,";",&saveptr);
    2555       }
    2556     }else{
    2557       if(strstr(cgiCookie,"=")!=NULL && strcasestr(cgiCookie,tmp)!=NULL){
    2558         tcook=zStrdup(cgiCookie);
    2559         hasValidCookie=1;
    2560       }
    2561       if(tmp!=NULL){
    2562         free(tmp);
    2563       }
    2564     }
    2565     if(hasValidCookie>0){
    2566       addToMap(_tmpMaps->content,"sessid",strstr(tcook,"=")+1);
    2567       char session_file_path[1024];
    2568       map *tmpPath=getMapFromMaps(m,"main","sessPath");
    2569       if(tmpPath==NULL)
    2570         tmpPath=getMapFromMaps(m,"main","tmpPath");
    2571       char *tmp1=strtok(tcook,";");
    2572       if(tmp1!=NULL)
    2573         sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(tmp1,"=")+1);
     3206    addToMap (_tmpMaps->content, "soap", "false");
     3207  if (cgiCookie != NULL && strlen (cgiCookie) > 0)
     3208    {
     3209      int hasValidCookie = -1;
     3210      char *tcook = zStrdup (cgiCookie);
     3211      char *tmp = NULL;
     3212      map *testing = getMapFromMaps (m, "main", "cookiePrefix");
     3213      if (testing == NULL)
     3214        {
     3215          tmp = zStrdup ("ID=");
     3216        }
    25743217      else
    2575         sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(cgiCookie,"=")+1);
    2576       free(tcook);
    2577       maps *tmpSess=(maps*)malloc(MAPS_SIZE);
    2578       struct stat file_status;
    2579       int istat = stat(session_file_path, &file_status);
    2580       if(istat==0 && file_status.st_size>0){
    2581         conf_read(session_file_path,tmpSess);
    2582         addMapsToMaps(&m,tmpSess);
    2583         freeMaps(&tmpSess);
    2584         free(tmpSess);
    2585       }
    2586     }
    2587   }
    2588   addMapsToMaps(&m,_tmpMaps);
    2589   freeMaps(&_tmpMaps);
    2590   free(_tmpMaps);
    2591 
    2592 #ifdef DEBUG
    2593   dumpMap(request_inputs);
     3218        {
     3219          tmp =
     3220            (char *) malloc ((strlen (testing->value) + 2) * sizeof (char));
     3221          sprintf (tmp, "%s=", testing->value);
     3222        }
     3223      if (strstr (cgiCookie, ";") != NULL)
     3224        {
     3225          char *token, *saveptr;
     3226          token = strtok_r (cgiCookie, ";", &saveptr);
     3227          while (token != NULL)
     3228            {
     3229              if (strcasestr (token, tmp) != NULL)
     3230                {
     3231                  if (tcook != NULL)
     3232                    free (tcook);
     3233                  tcook = zStrdup (token);
     3234                  hasValidCookie = 1;
     3235                }
     3236              token = strtok_r (NULL, ";", &saveptr);
     3237            }
     3238        }
     3239      else
     3240        {
     3241          if (strstr (cgiCookie, "=") != NULL
     3242              && strcasestr (cgiCookie, tmp) != NULL)
     3243            {
     3244              tcook = zStrdup (cgiCookie);
     3245              hasValidCookie = 1;
     3246            }
     3247          if (tmp != NULL)
     3248            {
     3249              free (tmp);
     3250            }
     3251        }
     3252      if (hasValidCookie > 0)
     3253        {
     3254          addToMap (_tmpMaps->content, "sessid", strstr (tcook, "=") + 1);
     3255          char session_file_path[1024];
     3256          map *tmpPath = getMapFromMaps (m, "main", "sessPath");
     3257          if (tmpPath == NULL)
     3258            tmpPath = getMapFromMaps (m, "main", "tmpPath");
     3259          char *tmp1 = strtok (tcook, ";");
     3260          if (tmp1 != NULL)
     3261            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
     3262                     strstr (tmp1, "=") + 1);
     3263          else
     3264            sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
     3265                     strstr (cgiCookie, "=") + 1);
     3266          free (tcook);
     3267          maps *tmpSess = (maps *) malloc (MAPS_SIZE);
     3268          struct stat file_status;
     3269          int istat = stat (session_file_path, &file_status);
     3270          if (istat == 0 && file_status.st_size > 0)
     3271            {
     3272              conf_read (session_file_path, tmpSess);
     3273              addMapsToMaps (&m, tmpSess);
     3274              freeMaps (&tmpSess);
     3275              free (tmpSess);
     3276            }
     3277        }
     3278    }
     3279  addMapsToMaps (&m, _tmpMaps);
     3280  freeMaps (&_tmpMaps);
     3281  free (_tmpMaps);
     3282
     3283#ifdef DEBUG
     3284  dumpMap (request_inputs);
    25943285#endif
    25953286#ifdef WIN32
    2596   char *cgiSidL=NULL;
    2597   if(getenv("CGISID")!=NULL)
    2598     addToMap(request_inputs,"cgiSid",getenv("CGISID"));
    2599   map* test1=getMap(request_inputs,"cgiSid");
    2600   if(test1!=NULL){
    2601     cgiSid=test1->value;
    2602     addToMap(request_inputs,"storeExecuteResponse","true");
    2603     addToMap(request_inputs,"status","true");
    2604     setMapInMaps(m,"lenv","sid",test1->value);
    2605     status=getMap(request_inputs,"status");
    2606   }
    2607 #endif
    2608   char *fbkp,*fbkp1;
    2609   FILE *f0,*f1;
    2610   if(status!=NULL)
    2611     if(strcasecmp(status->value,"false")==0)
    2612       status=NULLMAP;
    2613   if(status==NULLMAP){
    2614     loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres);
    2615   }
    2616   else{
    2617     int   pid;
    2618 #ifdef DEBUG
    2619     fprintf(stderr,"\nPID : %d\n",cpid);
     3287  char *cgiSidL = NULL;
     3288  if (getenv ("CGISID") != NULL)
     3289    addToMap (request_inputs, "cgiSid", getenv ("CGISID"));
     3290  map *test1 = getMap (request_inputs, "cgiSid");
     3291  if (test1 != NULL)
     3292    {
     3293      cgiSid = test1->value;
     3294      addToMap (request_inputs, "storeExecuteResponse", "true");
     3295      addToMap (request_inputs, "status", "true");
     3296      setMapInMaps (m, "lenv", "sid", test1->value);
     3297      status = getMap (request_inputs, "status");
     3298    }
     3299#endif
     3300  char *fbkp, *fbkp1;
     3301  FILE *f0, *f1;
     3302  if (status != NULL)
     3303    if (strcasecmp (status->value, "false") == 0)
     3304      status = NULLMAP;
     3305  if (status == NULLMAP)
     3306    {
     3307      loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
     3308                         &request_output_real_format, &eres);
     3309    }
     3310  else
     3311    {
     3312      int pid;
     3313#ifdef DEBUG
     3314      fprintf (stderr, "\nPID : %d\n", cpid);
    26203315#endif
    26213316
    26223317#ifndef WIN32
    2623     pid = fork ();
     3318      pid = fork ();
    26243319#else
    2625     if(cgiSid==NULL){
    2626       createProcess(m,request_inputs,s1,NULL,cpid,request_input_real_format,request_output_real_format);
    2627       pid = cpid;
    2628     }else{
    2629       pid=0;
    2630       cpid=atoi(cgiSid);
    2631     }
    2632 #endif
    2633     if (pid > 0) {
     3320      if (cgiSid == NULL)
     3321        {
     3322          createProcess (m, request_inputs, s1, NULL, cpid,
     3323                         request_input_real_format,
     3324                         request_output_real_format);
     3325          pid = cpid;
     3326        }
     3327      else
     3328        {
     3329          pid = 0;
     3330          cpid = atoi (cgiSid);
     3331        }
     3332#endif
     3333      if (pid > 0)
     3334        {
    26343335      /**
    26353336       * dady :
     
    26373338       */
    26383339#ifdef DEBUG
    2639       fprintf(stderr,"father pid continue (origin %d) %d ...\n",cpid,getpid());
    2640 #endif
    2641       eres=SERVICE_ACCEPTED;
    2642     }else if (pid == 0) {
     3340          fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
     3341                   getpid ());
     3342#endif
     3343          eres = SERVICE_ACCEPTED;
     3344        }
     3345      else if (pid == 0)
     3346        {
    26433347      /**
    26443348       * son : have to close the stdout, stdin and stderr to let the parent
     
    26463350       */
    26473351#ifndef WIN32
    2648       zSleep(1);
    2649 #endif
    2650       r_inputs=getMapFromMaps(m,"lenv","usid");
    2651       int cpid=atoi(r_inputs->value);
    2652       r_inputs=getMapFromMaps(m,"main","tmpPath");
    2653       map* r_inputs1=getMap(s1->content,"ServiceProvider");
    2654       fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char));
    2655       sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid);
    2656       char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char));
    2657       sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid);
    2658 #ifdef DEBUG
    2659       fprintf(stderr,"RUN IN BACKGROUND MODE \n");
    2660       fprintf(stderr,"son pid continue (origin %d) %d ...\n",cpid,getpid());
    2661       fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value);
    2662 #endif
    2663       freopen(flog, "w+", stderr);
    2664       semid lid=getShmLockId(m,1);
    2665       fflush(stderr);
    2666       if(lid<0){
    2667         fprintf(stderr,"ERROR %s %d\n",__FILE__,__LINE__);
    2668         fflush(stderr);
    2669         return -1;
    2670       }
    2671       else{
    2672         if(lockShm(lid)<0){
    2673           fprintf(stderr,"ERROR %s %d\n",__FILE__,__LINE__);
    2674           fflush(stderr);
    2675           return -1;
    2676         }
    2677         fflush(stderr);
    2678       }
    2679       f0=freopen(fbkp , "w+", stdout);
    2680       rewind(stdout);
     3352          zSleep (1);
     3353#endif
     3354          r_inputs = getMapFromMaps (m, "lenv", "usid");
     3355          int cpid = atoi (r_inputs->value);
     3356          r_inputs = getMapFromMaps (m, "main", "tmpPath");
     3357          map *r_inputs1 = getMap (s1->content, "ServiceProvider");
     3358          fbkp =
     3359            (char *)
     3360            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
     3361                     1024) * sizeof (char));
     3362          sprintf (fbkp, "%s/%s_%d.xml", r_inputs->value, r_inputs1->value,
     3363                   cpid);
     3364          char *flog =
     3365            (char *)
     3366            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
     3367                     1024) * sizeof (char));
     3368          sprintf (flog, "%s/%s_%d_error.log", r_inputs->value,
     3369                   r_inputs1->value, cpid);
     3370#ifdef DEBUG
     3371          fprintf (stderr, "RUN IN BACKGROUND MODE \n");
     3372          fprintf (stderr, "son pid continue (origin %d) %d ...\n", cpid,
     3373                   getpid ());
     3374          fprintf (stderr, "\nFILE TO STORE DATA %s\n", r_inputs->value);
     3375#endif
     3376          freopen (flog, "w+", stderr);
     3377          semid lid = getShmLockId (m, 1);
     3378          fflush (stderr);
     3379          if (lid < 0)
     3380            {
     3381              fprintf (stderr, "ERROR %s %d\n", __FILE__, __LINE__);
     3382              fflush (stderr);
     3383              return -1;
     3384            }
     3385          else
     3386            {
     3387              if (lockShm (lid) < 0)
     3388                {
     3389                  fprintf (stderr, "ERROR %s %d\n", __FILE__, __LINE__);
     3390                  fflush (stderr);
     3391                  return -1;
     3392                }
     3393              fflush (stderr);
     3394            }
     3395          f0 = freopen (fbkp, "w+", stdout);
     3396          rewind (stdout);
    26813397#ifndef WIN32
    2682       fclose(stdin);
    2683 #endif
    2684       free(flog);
     3398          fclose (stdin);
     3399#endif
     3400          free (flog);
    26853401      /**
    26863402       * set status to SERVICE_STARTED and flush stdout to ensure full
     
    26893405       * this way the data will be updated at the end of the process run.
    26903406       */
    2691       printProcessResponse(m,request_inputs,cpid,s1,r_inputs1->value,SERVICE_STARTED,
    2692                            request_input_real_format,request_output_real_format);
    2693       fflush(stdout);
    2694       unlockShm(lid);
    2695       fflush(stderr);
    2696       fbkp1=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char));
    2697       sprintf(fbkp1,"%s/%s_final_%d.xml",r_inputs->value,r_inputs1->value,cpid);
    2698       f1=freopen(fbkp1 , "w+", stdout);
    2699       loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres);
    2700     } else {
     3407          printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
     3408                                SERVICE_STARTED, request_input_real_format,
     3409                                request_output_real_format);
     3410          fflush (stdout);
     3411          unlockShm (lid);
     3412          fflush (stderr);
     3413          fbkp1 =
     3414            (char *)
     3415            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
     3416                     1024) * sizeof (char));
     3417          sprintf (fbkp1, "%s/%s_final_%d.xml", r_inputs->value,
     3418                   r_inputs1->value, cpid);
     3419          f1 = freopen (fbkp1, "w+", stdout);
     3420          loadServiceAndRun (&m, s1, request_inputs,
     3421                             &request_input_real_format,
     3422                             &request_output_real_format, &eres);
     3423        }
     3424      else
     3425        {
    27013426      /**
    27023427       * error server don't accept the process need to output a valid
    27033428       * error response here !!!
    27043429       */
    2705       eres=-1;
    2706       errorException(m, _("Unable to run the child process properly"), "InternalError",NULL);
    2707     }
    2708   }
    2709 
    2710 #ifdef DEBUG
    2711   dumpMaps(request_output_real_format);
    2712 #endif
    2713   if(eres!=-1)
    2714     outputResponse(s1,request_input_real_format,
    2715                    request_output_real_format,request_inputs,
    2716                    cpid,m,eres);
    2717   fflush(stdout);
     3430          eres = -1;
     3431          errorException (m, _("Unable to run the child process properly"),
     3432                          "InternalError", NULL);
     3433        }
     3434    }
     3435
     3436#ifdef DEBUG
     3437  dumpMaps (request_output_real_format);
     3438#endif
     3439  if (eres != -1)
     3440    outputResponse (s1, request_input_real_format,
     3441                    request_output_real_format, request_inputs,
     3442                    cpid, m, eres);
     3443  fflush (stdout);
    27183444  /**
    27193445   * Ensure that if error occurs when freeing memory, no signal will return
     
    27223448   */
    27233449#ifndef USE_GDB
    2724   signal(SIGSEGV,donothing);
    2725   signal(SIGTERM,donothing);
    2726   signal(SIGINT,donothing);
    2727   signal(SIGILL,donothing);
    2728   signal(SIGFPE,donothing);
    2729   signal(SIGABRT,donothing);
    2730 #endif
    2731   if(((int)getpid())!=cpid || cgiSid!=NULL){
    2732     fclose(stdout);
    2733     fclose(stderr);
     3450  signal (SIGSEGV, donothing);
     3451  signal (SIGTERM, donothing);
     3452  signal (SIGINT, donothing);
     3453  signal (SIGILL, donothing);
     3454  signal (SIGFPE, donothing);
     3455  signal (SIGABRT, donothing);
     3456#endif
     3457  if (((int) getpid ()) != cpid || cgiSid != NULL)
     3458    {
     3459      fclose (stdout);
     3460      fclose (stderr);
    27343461    /**
    27353462     * Dump back the final file fbkp1 to fbkp
    27363463     */
    2737     fclose(f0);
    2738     fclose(f1);
    2739     FILE* f2=fopen(fbkp1,"rb");
    2740     semid lid=getShmLockId(m,1);
    2741     if(lid<0)
    2742       return -1;
    2743     lockShm(lid);
    2744     FILE* f3=fopen(fbkp,"wb+");
    2745     free(fbkp);
    2746     fseek(f2,0,SEEK_END);
    2747     long flen=ftell(f2);
    2748     fseek(f2,0,SEEK_SET);
    2749     char *tmps1=(char*)malloc((flen+1)*sizeof(char));
    2750     fread(tmps1,flen,1,f2);
    2751     fwrite(tmps1,1,flen,f3);
    2752     fclose(f2);
    2753     fclose(f3);
    2754     unlockShm(lid);
    2755     unlink(fbkp1);
    2756     free(fbkp1);
    2757     free(tmps1);
    2758     unhandleStatus(m);
    2759   }
    2760 
    2761   freeService(&s1);
    2762   free(s1);
    2763   freeMaps(&m);
    2764   free(m);
    2765  
    2766   freeMaps(&request_input_real_format);
    2767   free(request_input_real_format);
    2768  
    2769   freeMaps(&request_output_real_format);
    2770   free(request_output_real_format);
    2771  
    2772   free(REQUEST);
    2773   free(SERVICE_URL);
    2774 #ifdef DEBUG
    2775   fprintf(stderr,"Processed response \n");
    2776   fflush(stdout);
    2777   fflush(stderr);
    2778 #endif
    2779 
    2780   if(((int)getpid())!=cpid || cgiSid!=NULL){
    2781     exit(0);
    2782   }
     3464      fclose (f0);
     3465      fclose (f1);
     3466      FILE *f2 = fopen (fbkp1, "rb");
     3467      semid lid = getShmLockId (m, 1);
     3468      if (lid < 0)
     3469        return -1;
     3470      lockShm (lid);
     3471      FILE *f3 = fopen (fbkp, "wb+");
     3472      free (fbkp);
     3473      fseek (f2, 0, SEEK_END);
     3474      long flen = ftell (f2);
     3475      fseek (f2, 0, SEEK_SET);
     3476      char *tmps1 = (char *) malloc ((flen + 1) * sizeof (char));
     3477      fread (tmps1, flen, 1, f2);
     3478      fwrite (tmps1, 1, flen, f3);
     3479      fclose (f2);
     3480      fclose (f3);
     3481      unlockShm (lid);
     3482      unlink (fbkp1);
     3483      free (fbkp1);
     3484      free (tmps1);
     3485      unhandleStatus (m);
     3486    }
     3487
     3488  freeService (&s1);
     3489  free (s1);
     3490  freeMaps (&m);
     3491  free (m);
     3492
     3493  freeMaps (&request_input_real_format);
     3494  free (request_input_real_format);
     3495
     3496  freeMaps (&request_output_real_format);
     3497  free (request_output_real_format);
     3498
     3499  free (REQUEST);
     3500  free (SERVICE_URL);
     3501#ifdef DEBUG
     3502  fprintf (stderr, "Processed response \n");
     3503  fflush (stdout);
     3504  fflush (stderr);
     3505#endif
     3506
     3507  if (((int) getpid ()) != cpid || cgiSid != NULL)
     3508    {
     3509      exit (0);
     3510    }
    27833511
    27843512  return 0;
    27853513}
    2786 
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