Ignore:
Timestamp:
Oct 22, 2014, 7:46:23 PM (10 years ago)
Author:
david
Message:

-loading files configuration on startup
-devel version with probably a lot of leak
-using temporarily glib to store services

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_loader.c

    r490 r512  
    3131#ifndef WIN32
    3232#include "fcgio.h"
    33 #include "fcgi_config.h" 
     33#include "fcgi_config.h"
    3434#include "fcgi_stdio.h"
    3535#endif
     
    4242#endif
    4343
    44 extern "C" {
     44extern "C"
     45{
    4546#include "cgic.h"
    4647#include <libxml/tree.h>
     
    4950#include <libxml/xpath.h>
    5051#include <libxml/xpathInternals.h>
     52
     53#include <string.h>
     54#include <stdio.h>
     55#include <stdlib.h>
     56#include <glib.h>
     57#include <sys/stat.h>
     58#include "service_zcfg.h"
    5159}
    5260
    5361#include "service_internal.h"
    5462
    55 xmlXPathObjectPtr extractFromDoc(xmlDocPtr,const char*);
    56 int runRequest(map**);
     63xmlXPathObjectPtr extractFromDoc (xmlDocPtr, const char *);
     64int runRequest (map **);
    5765
    5866using namespace std;
     
    6573#endif
    6674
    67 int cgiMain(){
    68   /**
     75
     76int
     77main (int argc, char *argv[])
     78{
     79  maps *m;
     80  m = (maps *) malloc (MAP_SIZE);
     81  conf_read ("main.cfg", m);
     82  char ntmp[1024];
     83#ifndef WIN32
     84  getcwd (ntmp, 1024);
     85#else
     86  _getcwd (ntmp, 1024);
     87#endif
     88  char *rootDir = "/var/www/zoo-wps/cgi-bin";
     89  init_services_conf (rootDir);
     90
     91
     92  while (FCGI_Accept () >= 0)
     93    {
     94      cgiMain_init (argc, argv);
     95/**
    6996   * We'll use cgiOut as the default output (stdout) to produce plain text
    7097   * response.
    7198   */
    72   dup2(fileno(cgiOut),fileno(stdout));
     99      dup2 (fileno (cgiOut), fileno (stdout));
     100
    73101#ifdef DEBUG
    74   fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
    75   fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n");
    76   fflush(cgiOut);
    77   fprintf (stderr, "Addr:%s\n", cgiRemoteAddr);
    78   fprintf (stderr, "RequestMethod: (%s) %d %d\n", cgiRequestMethod,strncasecmp(cgiRequestMethod,"post",4),strncmp(cgiContentType,"text/xml",8)==0 || strncasecmp(cgiRequestMethod,"post",4)==0);
    79   fprintf (stderr, "Request: %s\n", cgiQueryString);
    80   fprintf (stderr, "ContentType: %s\n", cgiContentType);
    81   fprintf (stderr, "ContentLength: %d\n", cgiContentLength);
    82   fflush(stderr);
    83 #endif
    84 
    85  
    86   char *strQuery=NULL;
    87   if(cgiQueryString!=NULL)
    88     strQuery=zStrdup(cgiQueryString);
    89   map* tmpMap=NULL;
    90 
    91   if(strncmp(cgiContentType,"text/xml",8)==0 ||
    92      strncasecmp(cgiRequestMethod,"post",4)==0){
    93     if(cgiContentLength==0){
    94        char *buffer=new char[2];
    95        char *res=NULL;
    96        int r=0;
    97        while((r=fread(buffer,sizeof(char),1,cgiIn))){
    98          buffer[1]=0;
    99          cgiContentLength+=r;
    100          if(res==NULL){
    101            res=(char*)malloc(2*sizeof(char));
    102            sprintf(res,"%s",buffer);
    103          }
    104          else{
    105            char *tmp=zStrdup(res);
    106            res=(char*)realloc(res,(strlen(tmp)+2)*sizeof(char));
    107            sprintf(res,"%s%s",tmp,buffer);
    108            free(tmp);
    109          }
    110        }
    111        delete[] buffer;
    112        if(res==NULL && (strQuery==NULL || strlen(strQuery)==0)){
    113          return errorException(NULL,"ZOO-Kernel failed to process your request cause the request was emtpty.","InternalError",NULL);
    114        }else{
    115          if(strQuery==NULL || strlen(strQuery)==0)
    116            tmpMap=createMap("request",res);
    117        }
    118        if(res!=NULL)
    119          free(res);
    120     }else{
    121       char *buffer=new char[cgiContentLength+1];
    122       if(fread(buffer,sizeof(char),cgiContentLength,cgiIn)>0){
    123         buffer[cgiContentLength]=0;
    124         tmpMap=createMap("request",buffer);
    125       }else{
    126         buffer[0]=0;
    127         char **array, **arrayStep;
    128         if (cgiFormEntries(&array) != cgiFormSuccess) {
    129           return 1;
    130         }
    131         arrayStep = array;
    132         while (*arrayStep) {
    133           char *ivalue=new char[cgiContentLength];
    134           cgiFormStringNoNewlines(*arrayStep, ivalue, cgiContentLength);
    135           char* tmpValueFinal=(char*) malloc((strlen(*arrayStep)+strlen(ivalue)+1)*sizeof(char));
    136           sprintf(tmpValueFinal,"%s=%s",*arrayStep,ivalue);
    137           if(strlen(buffer)==0){
    138             sprintf(buffer,"%s",tmpValueFinal);
    139           }else{
    140             char *tmp=zStrdup(buffer);
    141             sprintf(buffer,"%s&%s",tmp,tmpValueFinal);
    142             free(tmp);
    143           }
    144           free(tmpValueFinal);
     102      fprintf (cgiOut,
     103               "Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
     104      fprintf (cgiOut, "Welcome on ZOO verbose debuging mode \r\n\r\n");
     105      fflush (cgiOut);
     106      fprintf (stderr, "Addr:%s\n", cgiRemoteAddr);
     107      fprintf (stderr, "RequestMethod: (%s) %d %d\n", cgiRequestMethod,
     108               strncasecmp (cgiRequestMethod, "post", 4),
     109               strncmp (cgiContentType, "text/xml", 8) == 0
     110               || strncasecmp (cgiRequestMethod, "post", 4) == 0);
     111      fprintf (stderr, "Request: %s\n", cgiQueryString);
     112      fprintf (stderr, "ContentType: %s\n", cgiContentType);
     113      fprintf (stderr, "ContentLength: %d\n", cgiContentLength);
     114      fflush (stderr);
     115#endif
     116
     117
     118      char *strQuery = NULL;
     119      if (cgiQueryString != NULL)
     120        strQuery = zStrdup (cgiQueryString);
     121      map *tmpMap = NULL;
     122
     123      if (strncmp (cgiContentType, "text/xml", 8) == 0 ||
     124          strncasecmp (cgiRequestMethod, "post", 4) == 0)
     125        {
     126          if (cgiContentLength == 0)
     127            {
     128              char *buffer = new char[2];
     129              char *res = NULL;
     130              int r = 0;
     131              while ((r = fread (buffer, sizeof (char), 1, cgiIn)))
     132                {
     133                  buffer[1] = 0;
     134                  cgiContentLength += r;
     135                  if (res == NULL)
     136                    {
     137                      res = (char *) malloc (2 * sizeof (char));
     138                      sprintf (res, "%s", buffer);
     139                    }
     140                  else
     141                    {
     142                      char *tmp = zStrdup (res);
     143                      res =
     144                        (char *) realloc (res,
     145                                          (strlen (tmp) + 2) * sizeof (char));
     146                      sprintf (res, "%s%s", tmp, buffer);
     147                      free (tmp);
     148                    }
     149                }
     150              delete[]buffer;
     151              if (res == NULL && (strQuery == NULL || strlen (strQuery) == 0))
     152                {
     153                  return errorException (NULL,
     154                                         "ZOO-Kernel failed to process your request cause the request was emtpty.",
     155                                         "InternalError", NULL);
     156                }
     157              else
     158                {
     159                  if (strQuery == NULL || strlen (strQuery) == 0)
     160                    tmpMap = createMap ("request", res);
     161                }
     162              if (res != NULL)
     163                free (res);
     164            }
     165          else
     166            {
     167              char *buffer = new char[cgiContentLength + 1];
     168              if (fread (buffer, sizeof (char), cgiContentLength, cgiIn) > 0)
     169                {
     170                  buffer[cgiContentLength] = 0;
     171                  tmpMap = createMap ("request", buffer);
     172                }
     173              else
     174                {
     175                  buffer[0] = 0;
     176                  char **array, **arrayStep;
     177                  if (cgiFormEntries (&array) != cgiFormSuccess)
     178                    {
     179                      return 1;
     180                    }
     181                  arrayStep = array;
     182                  while (*arrayStep)
     183                    {
     184                      char *ivalue = new char[cgiContentLength];
     185                      cgiFormStringNoNewlines (*arrayStep, ivalue,
     186                                               cgiContentLength);
     187                      char *tmpValueFinal =
     188                        (char *)
     189                        malloc ((strlen (*arrayStep) + strlen (ivalue) +
     190                                 1) * sizeof (char));
     191                      sprintf (tmpValueFinal, "%s=%s", *arrayStep, ivalue);
     192                      if (strlen (buffer) == 0)
     193                        {
     194                          sprintf (buffer, "%s", tmpValueFinal);
     195                        }
     196                      else
     197                        {
     198                          char *tmp = zStrdup (buffer);
     199                          sprintf (buffer, "%s&%s", tmp, tmpValueFinal);
     200                          free (tmp);
     201                        }
     202                      free (tmpValueFinal);
    145203#ifdef DEBUG
    146           fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,ivalue);
    147 #endif
    148           delete[]ivalue;
    149           arrayStep++;
    150         }
    151         if(tmpMap!=NULL)
    152           addToMap(tmpMap,"request",buffer);
    153         else
    154           tmpMap=createMap("request",buffer);
    155       }
    156       delete[]buffer;
    157     }
    158   }
    159   else{
     204                      fprintf (stderr, "(( \n %s \n %s \n ))", *arrayStep,
     205                               ivalue);
     206#endif
     207                      delete[]ivalue;
     208                      arrayStep++;
     209                    }
     210                  if (tmpMap != NULL)
     211                    addToMap (tmpMap, "request", buffer);
     212                  else
     213                    tmpMap = createMap ("request", buffer);
     214                }
     215              delete[]buffer;
     216            }
     217        }
     218      else
     219        {
    160220#ifdef DEBUG
    161     dumpMap(tmpMap);
    162 #endif
    163     char **array, **arrayStep;
    164     if (cgiFormEntries(&array) != cgiFormSuccess) {
    165       return 1;
    166     }
    167     arrayStep = array;
    168     while (*arrayStep) {
    169       char *value=new char[cgiContentLength];
    170       cgiFormStringNoNewlines(*arrayStep, value, cgiContentLength);
     221          dumpMap (tmpMap);
     222#endif
     223          char **array, **arrayStep;
     224          if (cgiFormEntries (&array) != cgiFormSuccess)
     225            {
     226              return 1;
     227            }
     228          arrayStep = array;
     229          while (*arrayStep)
     230            {
     231              char *value = new char[cgiContentLength];
     232              cgiFormStringNoNewlines (*arrayStep, value, cgiContentLength);
    171233#ifdef DEBUG
    172       fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
    173 #endif
    174       if(tmpMap!=NULL)
    175         addToMap(tmpMap,*arrayStep,value);
    176       else
    177         tmpMap=createMap(*arrayStep,value);
    178       arrayStep++;
    179       delete[]value;
    180     }
    181     cgiStringArrayFree(array);
    182   }
     234              fprintf (stderr, "(( \n %s \n %s \n ))", *arrayStep, value);
     235#endif
     236              if (tmpMap != NULL)
     237                addToMap (tmpMap, *arrayStep, value);
     238              else
     239                tmpMap = createMap (*arrayStep, value);
     240              arrayStep++;
     241              delete[]value;
     242            }
     243          cgiStringArrayFree (array);
     244        }
    183245
    184246#ifdef WIN32
    185   map *tmpReq=getMap(tmpMap,"rfile");
    186   if(tmpReq!=NULL){
    187     FILE *lf=fopen(tmpReq->value,"r");
    188     fseek(lf,0,SEEK_END);
    189     long flen=ftell(lf);
    190     fseek(lf,0,SEEK_SET);
    191     char *buffer=(char*)malloc((flen+1)*sizeof(char));
    192     fread(buffer,flen,1,lf);
    193     fclose(lf);
    194     addToMap(tmpMap,"request",buffer);
    195     free(buffer);
    196     cgiContentLength=flen+9;
    197   }
     247      map *tmpReq = getMap (tmpMap, "rfile");
     248      if (tmpReq != NULL)
     249        {
     250          FILE *lf = fopen (tmpReq->value, "r");
     251          fseek (lf, 0, SEEK_END);
     252          long flen = ftell (lf);
     253          fseek (lf, 0, SEEK_SET);
     254          char *buffer = (char *) malloc ((flen + 1) * sizeof (char));
     255          fread (buffer, flen, 1, lf);
     256          fclose (lf);
     257          addToMap (tmpMap, "request", buffer);
     258          free (buffer);
     259          cgiContentLength = flen + 9;
     260        }
    198261#endif
    199262  /**
     
    202265   * one.
    203266   */
    204   if(strncasecmp(cgiRequestMethod,"post",4)==0 ||
    205      (count(tmpMap)==1 && strncmp(tmpMap->value,"<",1)==0)
     267      if (strncasecmp (cgiRequestMethod, "post", 4) == 0 ||
     268          (count (tmpMap) == 1 && strncmp (tmpMap->value, "<", 1) == 0)
    206269#ifdef WIN32
    207      ||tmpReq!=NULL
    208 #endif
    209      ){
     270          || tmpReq != NULL
     271#endif
     272        )
     273        {
    210274    /**
    211275     * Store the original XML request in xrequest map
    212276     */
    213     map* t1=getMap(tmpMap,"request");
    214     if(t1!=NULL && strncasecmp(t1->value,"<",1)==0){
    215       addToMap(tmpMap,"xrequest",t1->value);
    216       xmlInitParser();
    217       xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);
    218       {
    219         xmlXPathObjectPtr reqptr=extractFromDoc(doc,"/*[local-name()='Envelope']/*[local-name()='Body']/*");
    220         if(reqptr!=NULL){
    221           xmlNodeSet* req=reqptr->nodesetval;
    222           if(req!=NULL && req->nodeNr==1){
    223             addToMap(tmpMap,"soap","true");
    224             for(int k=0;k < req->nodeNr;k++){
    225               //xmlNsPtr ns=xmlNewNs(req->nodeTab[k],BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
    226               xmlDocSetRootElement(doc, req->nodeTab[k]);
    227               xmlChar *xmlbuff;
    228               int buffersize;
    229               xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "utf-8", 1);
    230               addToMap(tmpMap,"xrequest",(char*)xmlbuff);
    231               xmlFree(xmlbuff);
    232             }
    233           }
    234           xmlXPathFreeObject(reqptr);
    235         }
    236       }
    237 
    238       xmlNodePtr cur = xmlDocGetRootElement(doc);
    239       char *tval;
    240       tval=NULL;
    241       tval = (char*) xmlGetProp(cur,BAD_CAST "service");
    242       if(tval!=NULL){
    243         addToMap(tmpMap,"service",tval);
    244         xmlFree(tval);
    245       }
    246       tval=NULL;
    247       tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    248       if(tval!=NULL){
    249         addToMap(tmpMap,"language",tval);
    250         xmlFree(tval);
    251       }
    252       const char* requests[3]={"GetCapabilities","DescribeProcess","Execute"};
    253       for(int j=0;j<3;j++){
    254         char tt[128];
    255         sprintf(tt,"/*[local-name()='%s']",requests[j]);
    256         xmlXPathObjectPtr reqptr=extractFromDoc(doc,tt);
    257         if(reqptr!=NULL){
    258           xmlNodeSet* req=reqptr->nodesetval;
     277          map *t1 = getMap (tmpMap, "request");
     278          if (t1 != NULL && strncasecmp (t1->value, "<", 1) == 0)
     279            {
     280              addToMap (tmpMap, "xrequest", t1->value);
     281              xmlInitParser ();
     282              xmlDocPtr doc = xmlParseMemory (t1->value, cgiContentLength);
     283              {
     284                xmlXPathObjectPtr reqptr = extractFromDoc (doc,
     285                                                           "/*[local-name()='Envelope']/*[local-name()='Body']/*");
     286                if (reqptr != NULL)
     287                  {
     288                    xmlNodeSet *req = reqptr->nodesetval;
     289                    if (req != NULL && req->nodeNr == 1)
     290                      {
     291                        addToMap (tmpMap, "soap", "true");
     292                        for (int k = 0; k < req->nodeNr; k++)
     293                          {
     294                            //xmlNsPtr ns=xmlNewNs(req->nodeTab[k],BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
     295                            xmlDocSetRootElement (doc, req->nodeTab[k]);
     296                            xmlChar *xmlbuff;
     297                            int buffersize;
     298                            xmlDocDumpFormatMemoryEnc (doc, &xmlbuff,
     299                                                       &buffersize, "utf-8",
     300                                                       1);
     301                            addToMap (tmpMap, "xrequest", (char *) xmlbuff);
     302                            xmlFree (xmlbuff);
     303                          }
     304                      }
     305                    xmlXPathFreeObject (reqptr);
     306                  }
     307              }
     308
     309              xmlNodePtr cur = xmlDocGetRootElement (doc);
     310              char *tval;
     311              tval = NULL;
     312              tval = (char *) xmlGetProp (cur, BAD_CAST "service");
     313              if (tval != NULL)
     314                {
     315                  addToMap (tmpMap, "service", tval);
     316                  xmlFree (tval);
     317                }
     318              tval = NULL;
     319              tval = (char *) xmlGetProp (cur, BAD_CAST "language");
     320              if (tval != NULL)
     321                {
     322                  addToMap (tmpMap, "language", tval);
     323                  xmlFree (tval);
     324                }
     325              const char *requests[3] =
     326                { "GetCapabilities", "DescribeProcess", "Execute" };
     327              for (int j = 0; j < 3; j++)
     328                {
     329                  char tt[128];
     330                  sprintf (tt, "/*[local-name()='%s']", requests[j]);
     331                  xmlXPathObjectPtr reqptr = extractFromDoc (doc, tt);
     332                  if (reqptr != NULL)
     333                    {
     334                      xmlNodeSet *req = reqptr->nodesetval;
    259335#ifdef DEBUG
    260           fprintf(stderr,"%i",req->nodeNr);
    261 #endif
    262           if(req!=NULL && req->nodeNr==1){
    263             if(t1->value!=NULL)
    264               free(t1->value);
    265             t1->value=zStrdup(requests[j]);
    266             j=2;
    267           }
    268           xmlXPathFreeObject(reqptr);
    269         }
    270       }
    271       if(strncasecmp(t1->value,"GetCapabilities",15)==0){
    272         xmlXPathObjectPtr versptr=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
    273         xmlNodeSet* vers=versptr->nodesetval;
    274         xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);
    275         addToMap(tmpMap,"version",(char*)content);
    276         xmlXPathFreeObject(versptr);
    277         xmlFree(content);
    278       }else{
    279         tval=NULL;
    280         tval = (char*) xmlGetProp(cur,BAD_CAST "version");
    281         if(tval!=NULL){
    282           addToMap(tmpMap,"version",tval);
    283           xmlFree(tval);
    284         }
    285         tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    286         if(tval!=NULL){
    287           addToMap(tmpMap,"language",tval);
    288           xmlFree(tval);
    289         }
    290         xmlXPathObjectPtr idptr=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
    291         if(idptr!=NULL){
    292           xmlNodeSet* id=idptr->nodesetval;
    293           if(id!=NULL){
    294             char* identifiers=NULL;
    295             identifiers=(char*)calloc(cgiContentLength,sizeof(char));
    296             identifiers[0]=0;
    297             for(int k=0;k<id->nodeNr;k++){
    298               xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
    299               if(strlen(identifiers)>0){
    300                 char *tmp=zStrdup(identifiers);
    301                 snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content);
    302                 free(tmp);
    303               }
    304               else{
    305                 snprintf(identifiers,xmlStrlen(content)+1,"%s",content);
    306               }
    307               xmlFree(content);
    308             }
    309             xmlXPathFreeObject(idptr);
    310             addToMap(tmpMap,"Identifier",identifiers);
    311             free(identifiers);
    312           }
    313         }
    314       }
    315       xmlFreeDoc(doc);
    316       xmlCleanupParser();
    317     }else{
    318       freeMap(&tmpMap);
    319       free(tmpMap);
    320       tmpMap=createMap("not_valid","true");
    321     }
    322 
    323     char *token,*saveptr;
    324     token=strtok_r(cgiQueryString,"&",&saveptr);
    325     while(token!=NULL){
    326       char *token1,*saveptr1;
    327       char *name=NULL;
    328       char *value=NULL;
    329       token1=strtok_r(token,"=",&saveptr1);
    330       while(token1!=NULL){
    331         if(name==NULL)
    332           name=zStrdup(token1);
    333         else
    334           value=zStrdup(token1);
    335         token1=strtok_r(NULL,"=",&saveptr1);
    336       }
    337       addToMap(tmpMap,name,value);
    338       free(name);
    339       free(value);
    340       name=NULL;
    341       value=NULL;
    342       token=strtok_r(NULL,"&",&saveptr);
    343     }
    344    
    345   }
    346 
    347   if(strncasecmp(cgiContentType,"multipart/form-data",19)==0){
    348     map* tmp=getMap(tmpMap,"dataInputs");
    349     if(tmp!=NULL){
    350       addToMap(tmpMap,"dataInputs",strstr(strQuery,"dataInputs=")+11);
    351     }
    352   }
    353 
    354   if(strQuery!=NULL)
    355     free(strQuery);
    356 
    357   runRequest(&tmpMap);
     336                      fprintf (stderr, "%i", req->nodeNr);
     337#endif
     338                      if (req != NULL && req->nodeNr == 1)
     339                        {
     340                          if (t1->value != NULL)
     341                            free (t1->value);
     342                          t1->value = zStrdup (requests[j]);
     343                          j = 2;
     344                        }
     345                      xmlXPathFreeObject (reqptr);
     346                    }
     347                }
     348              if (strncasecmp (t1->value, "GetCapabilities", 15) == 0)
     349                {
     350                  xmlXPathObjectPtr versptr =
     351                    extractFromDoc (doc, "/*/*/*[local-name()='Version']");
     352                  xmlNodeSet *vers = versptr->nodesetval;
     353                  xmlChar *content = xmlNodeListGetString (doc,
     354                                                           vers->
     355                                                           nodeTab
     356                                                           [0]->xmlChildrenNode,
     357                                                           1);
     358                  addToMap (tmpMap, "version", (char *) content);
     359                  xmlXPathFreeObject (versptr);
     360                  xmlFree (content);
     361                }
     362              else
     363                {
     364                  tval = NULL;
     365                  tval = (char *) xmlGetProp (cur, BAD_CAST "version");
     366                  if (tval != NULL)
     367                    {
     368                      addToMap (tmpMap, "version", tval);
     369                      xmlFree (tval);
     370                    }
     371                  tval = (char *) xmlGetProp (cur, BAD_CAST "language");
     372                  if (tval != NULL)
     373                    {
     374                      addToMap (tmpMap, "language", tval);
     375                      xmlFree (tval);
     376                    }
     377                  xmlXPathObjectPtr idptr =
     378                    extractFromDoc (doc, "/*/*[local-name()='Identifier']");
     379                  if (idptr != NULL)
     380                    {
     381                      xmlNodeSet *id = idptr->nodesetval;
     382                      if (id != NULL)
     383                        {
     384                          char *identifiers = NULL;
     385                          identifiers =
     386                            (char *) calloc (cgiContentLength, sizeof (char));
     387                          identifiers[0] = 0;
     388                          for (int k = 0; k < id->nodeNr; k++)
     389                            {
     390                              xmlChar *content = xmlNodeListGetString (doc,
     391                                                                       id->nodeTab
     392                                                                       [k]->
     393                                                                       xmlChildrenNode,
     394                                                                       1);
     395                              if (strlen (identifiers) > 0)
     396                                {
     397                                  char *tmp = zStrdup (identifiers);
     398                                  snprintf (identifiers,
     399                                            strlen (tmp) +
     400                                            xmlStrlen (content) + 2, "%s,%s",
     401                                            tmp, content);
     402                                  free (tmp);
     403                                }
     404                              else
     405                                {
     406                                  snprintf (identifiers,
     407                                            xmlStrlen (content) + 1, "%s",
     408                                            content);
     409                                }
     410                              xmlFree (content);
     411                            }
     412                          xmlXPathFreeObject (idptr);
     413                          addToMap (tmpMap, "Identifier", identifiers);
     414                          free (identifiers);
     415                        }
     416                    }
     417                }
     418              xmlFreeDoc (doc);
     419              xmlCleanupParser ();
     420            }
     421          else
     422            {
     423              freeMap (&tmpMap);
     424              free (tmpMap);
     425              tmpMap = createMap ("not_valid", "true");
     426            }
     427
     428          char *token, *saveptr;
     429          token = strtok_r (cgiQueryString, "&", &saveptr);
     430          while (token != NULL)
     431            {
     432              char *token1, *saveptr1;
     433              char *name = NULL;
     434              char *value = NULL;
     435              token1 = strtok_r (token, "=", &saveptr1);
     436              while (token1 != NULL)
     437                {
     438                  if (name == NULL)
     439                    name = zStrdup (token1);
     440                  else
     441                    value = zStrdup (token1);
     442                  token1 = strtok_r (NULL, "=", &saveptr1);
     443                }
     444              addToMap (tmpMap, name, value);
     445              free (name);
     446              free (value);
     447              name = NULL;
     448              value = NULL;
     449              token = strtok_r (NULL, "&", &saveptr);
     450            }
     451
     452        }
     453
     454      if (strncasecmp (cgiContentType, "multipart/form-data", 19) == 0)
     455        {
     456          map *tmp = getMap (tmpMap, "dataInputs");
     457          if (tmp != NULL)
     458            {
     459              addToMap (tmpMap, "dataInputs",
     460                        strstr (strQuery, "dataInputs=") + 11);
     461            }
     462        }
     463
     464      if (strQuery != NULL)
     465        free (strQuery);
     466
     467      runRequest (&tmpMap);
    358468
    359469  /**
    360470   * Required but can't be made after executing a process using POST requests.
    361471   */
    362   if(/*strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && */tmpMap!=NULL){
    363     freeMap(&tmpMap);
    364     free(tmpMap);
    365   }
     472      if ( /*strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && */ tmpMap != NULL)
     473        {
     474          freeMap (&tmpMap);
     475          free (tmpMap);
     476        }
     477      cgiFreeResources ();
     478    }
     479  FCGI_Finish ();
    366480  return 0;
    367481
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