Ticket #1: ZooKernel.diff

File ZooKernel.diff, 47.7 KB (added by soeren, 14 years ago)
  • service.c

     
    11#include "service.h"
    22
    3 map* createMap(char* name,char* value){
     3/* ************************************************************************* */
     4
     5map* createMap(const char* name, const char* value){
    46  map* tmp=(map *)malloc(sizeof(map*));
    57  tmp->name=strdup(name);
    68  tmp->value=strdup(value);
     
    810  return tmp;
    911}
    1012
     13/* ************************************************************************* */
     14
    1115bool hasKey(map* m,char *key){
    1216  map* tmp=m;
    1317  while(tmp!=NULL){
     
    1620    tmp=tmp->next;
    1721  }
    1822#ifdef DEBUG_MAP
    19   printf("NOT FOUND \n");
     23  fprintf(stderr, "MAP NOT FOUND in service.c line %i\n", __LINE__);
    2024#endif
    2125  return false;
    2226}
    2327
     28/* ************************************************************************* */
     29
    2430map* getMap(map* m,char *key){
    2531  map* tmp=m;
    2632  while(tmp!=NULL){
     
    3137  return NULL;
    3238}
    3339
     40/* ************************************************************************* */
     41
    3442void* addToMap(map* m,char* n,char* v){
    3543  if(hasKey(m,n)==false){
    3644    map* _cursor=m;
     
    4452  }
    4553}
    4654
     55/* ************************************************************************* */
     56
    4757void* _dumpMap(map* t){
    4858  fprintf(stderr,"[%s] => [%s] \n",t->name,t->value);
    4959  fflush(stderr);
  • service_internal.h

     
    8080
    8181  void addDefaultValues(maps**,elements*,maps*,char*);
    8282
     83   /*defined in zoo_loader.c*/
     84  int errorException(maps *m, const char *message, const char *errorcode);
    8385#ifdef __cplusplus
    8486}
    8587#endif
  • service.h

     
    4949#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+sizeof(maps*)
    5050
    5151
    52   static char* mtoupper(char* str){
     52  static char* mtoupper(const char* str){
    5353    char* tmp=strdup(str);
    5454    if(tmp){
    5555      int cnt=strlen(tmp);
     
    111111    }
    112112  }
    113113
    114   static map* createMap(char* name,char* value){
     114  static map* createMap(const char* name, const char* value){
    115115    map* tmp=(map *)malloc(MAP_SIZE);
    116116    tmp->name=strdup(name);
    117117    tmp->value=strdup(value);
     
    129129    return c;
    130130  }
    131131   
    132   static bool hasKey(map* m,char *key){
     132  static bool hasKey(map* m,const char *key){
    133133    map* tmp=m;
    134134    while(tmp!=NULL){
    135135      if(strcmp(mtoupper(tmp->name),mtoupper(key))==0)
     
    152152    return NULL;
    153153  }
    154154
    155   static map* getMap(map* m,char *key){
     155  static map* getMap(map* m,const char *key){
    156156    map* tmp=m;
    157157    while(tmp!=NULL){
    158158      if(strcmp(mtoupper(tmp->name),mtoupper(key))==0)
     
    357357    return NULL;
    358358  }
    359359
    360   static void* addToMap(map* m,char* n,char* v){
     360  static void* addToMap(map* m,const char* n,const char* v){
    361361    if(hasKey(m,n)==false){
    362362      map* _cursor=m;
    363363      while(_cursor->next!=NULL)
  • zoo_service_loader.c

     
    7070#include <time.h>
    7171#include <stdarg.h>
    7272
     73/* ************************************************************************* */
     74
    7375xmlNodeSet* extractFromDoc(xmlDocPtr doc,char* search){
    7476  xmlXPathContextPtr xpathCtx;
    7577  xmlXPathObjectPtr xpathObj;
     
    7981  return xpathObj->nodesetval;
    8082}
    8183
     84/* ************************************************************************* */
     85
    8286void sigint_handler(int sig){
    8387  fprintf(stderr,"Not this time!\n");
    8488}
    8589
     90/* ************************************************************************* */
     91
    8692int runRequest(map* request_inputs)
    8793{
    8894
     
    94100  /**
    95101   * Parsing service specfic configuration file
    96102   */
    97   m=(maps*)malloc(MAPS_SIZE);
     103  m=(maps*)calloc(1, MAPS_SIZE);
     104  if(m == NULL){
     105    return errorException(m, "Unable to allocate memory.", "InternalError");
     106  }
    98107  char ntmp[1024];
    99108#ifndef WIN32
    100109  getcwd(ntmp,1024);
    101110#else
    102111  _getcwd(ntmp,1024);
    103112#endif
    104   char conf_file[1024];
    105   sprintf(conf_file,"%s/main.cfg",ntmp); 
     113  char conf_file[10240];
     114  snprintf(conf_file, 10240, "%s/main.cfg",ntmp); 
    106115  conf_read(conf_file,m);
    107  
     116
     117#ifdef DEBUG
     118  fprintf(stderr, "***** BEGIN MAP\n");
     119  dumpMap(request_inputs);
     120  fprintf(stderr, "***** END MAP\n");
     121#endif
    108122  /**
    109123   * Check for minimum inputs
    110124   */
    111125  r_inputs=getMap(request_inputs,"Request");
    112126  if(r_inputs==NULLMAP){
    113   tmps=createMap("text","Parameter <request> was not specified");
     127    tmps=createMap("text","Parameter <request> was not specified");
    114128    addToMap(tmps,"code","MissingParameterValue");
    115129    printExceptionReportResponse(m,tmps);
    116130    return 1;
    117131  }
    118132  else
    119133    REQUEST=strdup(r_inputs->value);
     134 
    120135  r_inputs=NULL;
    121136  r_inputs=getMap(request_inputs,"Service");
     137
    122138  if(r_inputs==NULLMAP){
    123139    tmps=createMap("text","Parameter <service> was not specified");
    124140    addToMap(tmps,"code","MissingParameterValue");
    125141    printExceptionReportResponse(m,tmps);
    126142    return 1;
    127143  }
    128   if(strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0){
     144
     145  if(strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))!=0){
    129146    r_inputs=getMap(request_inputs,"Version");
    130147    if(r_inputs==NULL){
    131148      tmps=createMap("text","Parameter <version> was not specified");
     
    139156   * Need to print std exception message here
    140157   */
    141158  char SP[1024];
    142   if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)){
     159
     160  /*if ((argc < 5 && strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))!=0) || (argc < 4 && strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))==0)){*/
     161  if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)) {
    143162    r_inputs=getMap(request_inputs,"ServiceProvider");
     163
     164#ifdef DEBUG
     165    fprintf(stderr, "***** BEGIN MAP\n");
     166    dumpMap(r_inputs);
     167    fprintf(stderr, "***** END MAP\n");
     168#endif
     169
    144170    if(r_inputs==NULLMAP){
    145       tmps=createMap("text","Parameter <serviceprovider> was not specified");
    146       addToMap(tmps,"code","MissingParameterValue");
    147       printExceptionReportResponse(m,tmps);   
     171      errorException(m, "Parameter <serviceprovider> was not specified","MissingParameterValue");
    148172      return 1;
    149173    }
    150174    else
    151       sprintf(SP,"%s",r_inputs->value);
     175      snprintf(SP, 1024, "%s",r_inputs->value);
     176
    152177    r_inputs=getMap(request_inputs,"MetaPath");
     178
     179#ifdef DEBUG
     180    fprintf(stderr, "***** BEGIN MAP\n");
     181    dumpMap(r_inputs);
     182    fprintf(stderr, "***** END MAP\n");
     183#endif
     184
    153185    if(r_inputs==NULLMAP){
    154       tmps=createMap("text","Parameter <metapath> was not specified");
    155       addToMap(tmps,"code","MissingParameterValue");
    156       printExceptionReportResponse(m,tmps);   
     186      errorException(m, "Parameter <metapath> was not specified", "MissingParameterValue");
    157187      return 1;
    158188    }
    159     tmps=createMap("text","Parameter <unknown> was not specified");
    160     addToMap(tmps,"code","MissingParameterValue");
    161     printExceptionReportResponse(m,tmps);   
     189    errorException(m, "Parameter <unknown> was not specified", "MissingParameterValue");
    162190    return 1;
    163191  }
    164192
     
    175203  int scount=0;
    176204
    177205#ifdef DEBUG
     206  fprintf(stderr, "***** BEGIN MAP\n");
    178207  dumpMap(r_inputs);
     208  fprintf(stderr, "***** END MAP\n");
    179209#endif
    180210  char conf_dir[1024];
    181211  int t;
    182212  char tmps1[1024];
    183213
    184   if(strcmp(mtoupper(REQUEST),mtoupper("GetCapabilities"))==0){
     214  if(strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))==0){
    185215    int i=0;
    186216    struct dirent *dp;
    187217    r_inputs=NULL;
    188     r_inputs=getMap(request_inputs,"metapath");
     218    r_inputs=getMap(request_inputs,"MetaPath");
     219
     220    snprintf(conf_dir, 1024, "%s/%s",ntmp,r_inputs->value);
    189221#ifdef DEBUG
     222    fprintf(stderr, "***** BEGIN MAP\n");
    190223    dumpMap(r_inputs);
     224    fprintf(stderr, "***** END MAP\n");
    191225#endif
    192     sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value);
    193         DIR *dirp = opendir(conf_dir);
     226    DIR *dirp = opendir(conf_dir);
    194227    if(dirp==NULL){
    195       tmps=createMap("text","The specified path doesn't exist.");
    196       addToMap(tmps,"code","InvalidParameterValue");
    197       printExceptionReportResponse(m,tmps);   
    198       return -1;
     228      return errorException(m, "The specified meta path doesn't exist.","InvalidParameterValue");
    199229    }
     230
    200231    xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
    201232    doc->encoding = xmlCharStrdup ("UTF-8");
    202233    r_inputs=NULL;
     
    208239     */
    209240    int saved_stdout = dup(fileno(stdout));
    210241    dup2(fileno(stderr),fileno(stdout));
     242
    211243    while ((dp = readdir(dirp)) != NULL)
    212244      if(strstr(dp->d_name,".zcfg")!=0){
    213         sprintf(tmps1,"%s/%s",conf_dir,dp->d_name);
     245        snprintf(tmps1, 1024, "%s/%s",conf_dir,dp->d_name);
    214246        char *tmps=tmps1;
    215         s1=(service*)malloc(sizeof(service*));
    216         s[0]=(service*)malloc(sizeof(service*));
     247        s1=(service*)calloc(1, sizeof(service));
     248        s[0]=(service*)calloc(1, sizeof(service));
     249        if(s1 == NULL || s[0] == NULL){
     250          return errorException(m, "Unable to allocate memory.","InternalError");
     251        }
    217252#ifdef DEBUG
    218253        fprintf(stderr,"#################\n%s\n#################\n",tmps1);
    219254#endif
     
    232267    (void)closedir(dirp);
    233268    fflush(stdout);
    234269    dup2(saved_stdout,fileno(stdout));
    235    
    236270    printDocument(doc);
    237271    fflush(stdout);
    238272    xmlFree(n);
     
    243277    if(r_inputs==NULL
    244278       || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){
    245279      if(r_inputs!=NULL && strlen(r_inputs->value)==0)
    246         tmps=createMap("text","Mandatory value for <identifier> was not specified");
     280        errorException(m, "Mandatory value for <identifier> was not specified","MissingParameterValue");
    247281      else
    248         tmps=createMap("text","Mandatory <identifier> was not specified");
    249       addToMap(tmps,"code","MissingParameterValue");
    250       printExceptionReportResponse(m,tmps);
     282        errorException(m, "Mandatory <identifier> was not specified","MissingParameterValue");
    251283      return 1;
    252284    }
    253285
     
    256288    struct dirent *dp;
    257289    DIR *dirp = opendir(conf_dir);
    258290    if(dirp==NULL){
    259       tmps=createMap("text","The specified metapath path doesn't exist.");
    260       addToMap(tmps,"code","InvalidParameterValue");
    261       printExceptionReportResponse(m,tmps);   
    262       return -1;
     291      return errorException(m, "The specified metapath path doesn't exist.","InvalidParameterValue");
    263292    }
    264     if(strcmp(mtoupper(REQUEST),"DESCRIBEPROCESS")==0){
     293    if(strncmp(mtoupper(REQUEST),"DESCRIBEPROCESS", strlen(mtoupper(REQUEST)))==0){
    265294      /**
    266295       * Loop over Identifier list
    267296       */
     
    274303        n = printDescribeProcessHeader(doc,r_inputs->value,m);
    275304
    276305      r_inputs=getMap(request_inputs,"Identifier");
     306
    277307      char *tmps=strtok(r_inputs->value,",");
    278      
    279308      char buff[256];
    280309      char buff1[1024];
    281310      int i=0;
     
    285314      dup2(fileno(stderr),fileno(stdout));
    286315      while(tmps){
    287316        memset(buff,0,256);
    288         sprintf(buff,"%s.zcfg",tmps);
     317        snprintf(buff, 256, "%s.zcfg",tmps);
    289318        memset(buff1,0,1024);
    290319#ifdef DEBUG
    291320        fprintf(stderr,"\n#######%s\n########\n",buff1);
     
    293322        while ((dp = readdir(dirp)) != NULL)
    294323          if(strcmp(dp->d_name,buff)==0){
    295324            memset(buff1,0,1024);
    296             sprintf(buff1,"%s/%s",conf_dir,dp->d_name);
    297             s1=(service*)malloc(sizeof(service*));
    298             s[scount]=(service*)malloc(sizeof(service*));
     325            snprintf(buff1, 1024, "%s/%s",conf_dir,dp->d_name);
     326            s1=(service*)calloc(1, sizeof(service));
     327            s[scount]=(service*)calloc(1, sizeof(service));
     328          if(s1 == NULL || s[scount] == NULL){
     329            return errorException(m, "Unable to allocate memory.","InternalError");
     330          }
    299331#ifdef DEBUG
    300332            fprintf(stderr,"#################\n%s\n#################\n",tmps1);
    301333#endif
     
    318350      fflush(stdout);
    319351      //xmlFree(n);
    320352#ifndef LINUX_FREE_ISSUE
    321       free(s1);
     353      if(s1)
     354        free(s1);
    322355#endif
    323356      return 0;
    324357    }
    325358    else
    326       if(strcmp(mtoupper(REQUEST),"EXECUTE")!=0){
    327         tmps=createMap("text","Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.");
    328         addToMap(tmps,"code","InvalidParameterValue");
    329         printExceptionReportResponse(m,tmps);
     359      if(strncmp(mtoupper(REQUEST),"EXECUTE", strlen(mtoupper(REQUEST)))!=0){
     360        errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue");
    330361#ifdef DEBUG
    331362        fprintf(stderr,"No request found %s",REQUEST);
    332363#endif 
     
    336367  }
    337368 
    338369  s1=NULL;
    339   s1=(service*)malloc(sizeof(service*));
    340   s[0]=(service*)malloc(sizeof(service*));
     370  s1=(service*)calloc(1, sizeof(service));
     371  s[0]=(service*)calloc(1, sizeof(service));
     372  if(s1 == NULL || s[0] == NULL){
     373    return errorException(m, "Unable to allocate memory.","InternalError");
     374  }
     375
    341376  r_inputs=getMap(request_inputs,"MetaPath");
    342   sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
     377  snprintf(tmps1, 1024, "%s/%s",ntmp,r_inputs->value);
     378
    343379  r_inputs=getMap(request_inputs,"Identifier");
     380  snprintf(tmps1, 1024, "%s/%s.zcfg",strdup(tmps1),r_inputs->value);
    344381
    345   sprintf(tmps1,"%s/%s.zcfg",strdup(tmps1),r_inputs->value);
    346 
    347382#ifdef DEBUG
    348383  fprintf(stderr,"Trying to load %s\n", tmps1);
    349384#endif
     
    352387  t=getServiceFromFile(tmps1,&s1);
    353388  fflush(stdout);
    354389  dup2(saved_stdout,fileno(stdout));
     390  /*What is 22 ????*/
    355391  if(t==22){
    356     tmps=createMap("text","The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.");
    357     addToMap(tmps,"code","InvalidParameterValue");
    358     printExceptionReportResponse(m,tmps);
     392    errorException(m, "The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.", "InvalidParameterValue");
    359393    exit(0);
    360394  }
    361395  s[0]=s1;
     
    409443#endif
    410444      char current_output_as_string[10240];
    411445      char cursor_output[10240];
    412       sprintf(cursor_output,"%s",strdup(r_inputs->value));
     446      snprintf(cursor_output, 10240, "%s",strdup(r_inputs->value));
    413447      j=0;
    414448      map* request_kvp_outputs=NULL;
    415449       
     
    422456      fprintf(stderr,"OUTPUT [%s]\n",cursor_output);
    423457#endif
    424458      pToken=strtok(cursor_output,";");
    425       char** outputs_as_text=(char**)malloc(128*sizeof(char*));
     459      char** outputs_as_text=(char**)calloc(128, sizeof(char*));
     460      if(outputs_as_text == NULL) {
     461        return errorException(m, "Unaböe to allocate memory", "InternalError");
     462      }
    426463      i=0;
    427464      while(pToken!=NULL){
    428465#ifdef DEBUG
     
    430467        fflush(stderr);
    431468        fprintf(stderr,"***%s***\n",pToken);
    432469#endif
    433         outputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char));
    434         sprintf(outputs_as_text[i],"%s",pToken);
     470        outputs_as_text[i]=(char*)calloc(strlen(pToken), sizeof(char));
     471        if(outputs_as_text[i] == NULL) {
     472          return errorException(m, "Unable to allocate memory", "InternalError");
     473        }
     474        snprintf(outputs_as_text[i], strlen(pToken), "%s",pToken);
    435475        pToken = strtok(NULL,";");
    436476        i++;
    437477      }
     
    443483        while(tmpc!=NULL){
    444484          if(k==0){
    445485            if(tmp_output==NULL){
    446               tmp_output=(maps*)malloc(MAPS_SIZE);
     486              tmp_output=(maps*)calloc(1, MAPS_SIZE);
     487              if(tmp_output == NULL){
     488                return errorException(m, "Unable to allocate memory.", "InternalError");
     489              }
    447490              tmp_output->name=strdup(tmpc);
    448491              tmp_output->content=NULL;
    449492              tmp_output->next=NULL;
     
    493536#endif
    494537    char current_input_as_string[40960];
    495538    char cursor_input[40960];
    496     sprintf(cursor_input,"%s",strdup(r_inputs->value));
     539    snprintf(cursor_input, 40960, "%s",strdup(r_inputs->value));
    497540    j=0;
    498541    map* request_kvp_inputs=NULL;
    499542 
     
    502545     */
    503546    char * pToken;
    504547    pToken=strtok(cursor_input,";");
    505     char** inputs_as_text=(char**)malloc(100*sizeof(char*));
     548    char** inputs_as_text=(char**)calloc(100,sizeof(char*));
     549    if(inputs_as_text == NULL){
     550      return errorException(m, "Unable to allocate memory.", "InternalError");
     551    }
    506552    i=0;
    507553    while(pToken!=NULL){
    508554#ifdef DEBUG
     
    512558#ifdef DEBUG
    513559      fprintf(stderr,"***%s***\n",pToken);
    514560#endif
    515       inputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char));
    516       sprintf(inputs_as_text[i],"%s",pToken);
     561      inputs_as_text[i]=(char*)calloc(strlen(pToken),sizeof(char));
     562      if(inputs_as_text[i] == NULL){
     563        return errorException(m, "Unable to allocate memory.", "InternalError");
     564      }
     565      snprintf(inputs_as_text[i], strlen(pToken), "%s",pToken);
    517566      pToken = strtok(NULL,";");
    518567      i++;
    519568    }
     
    536585        fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1);
    537586#endif
    538587        if(tmpmaps==NULL){
    539           tmpmaps=(maps*)malloc(MAPS_SIZE);
     588          tmpmaps=(maps*)calloc(1, MAPS_SIZE);
     589          if(tmpmaps == NULL){
     590            return errorException(m, "Unable to allocate memory.", "InternalError");
     591          }
    540592          tmpmaps->name=strdup(tmpn);
    541593          tmpmaps->content=createMap("value",tmpv+1);
    542594          tmpmaps->next=NULL;
     
    574626              fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
    575627                      tmpv1+1,res.nDataAlloc,res.nDataLen);
    576628#endif
    577               char* tmpContent=(char*)malloc((res.nDataLen+1)*sizeof(char));
     629              char* tmpContent=(char*)calloc((res.nDataLen+1), sizeof(char));
     630              if(tmpContent == NULL){
     631                return errorException(m, "Unable to allocate memory.", "InternalError");
     632              }
    578633              size_t dwRead;
    579634              InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
    580635              map* tmpMap=getMap(tmpmaps->content,"value");
     
    646701              xmlChar *val=
    647702                xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    648703              if(tmpmaps==NULL){
    649                 tmpmaps=(maps*)malloc(MAPS_SIZE);
     704                tmpmaps=(maps*)calloc(1, MAPS_SIZE);
     705                if(tmpmaps == NULL){
     706                  return errorException(m, "Unable to allocate memory.", "InternalError");
     707                }
    650708                tmpmaps->name=strdup((char*)val);
    651709                tmpmaps->content=NULL;
    652710                tmpmaps->next=NULL;
     
    663721              xmlChar *val=
    664722                xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    665723              if(tmpmaps==NULL){
    666                 tmpmaps=(maps*)malloc(MAPS_SIZE);
     724                tmpmaps=(maps*)calloc(1, MAPS_SIZE);
     725                if(tmpmaps == NULL){
     726                  return errorException(m, "Unable to allocate memory.", "InternalError");
     727                }
    667728                tmpmaps->name="missingIndetifier";
    668729                tmpmaps->content=createMap((char*)cur2->name,(char*)val);
    669730                tmpmaps->next=NULL;
     
    718779                       && CHECK_INET_HANDLE(hInternet)){
    719780                        res=InternetOpenUrl(hInternet,(char*)val,NULL,0,
    720781                                            INTERNET_FLAG_NO_CACHE_WRITE,0);
    721                         char* tmpContent=
    722                           (char*)malloc((res.nDataLen+1)*sizeof(char));
     782                        char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char));
     783                        if(tmpContent == NULL){
     784                          return errorException(m, "Unable to allocate memory.", "InternalError");
     785                        }
    723786                        size_t dwRead;
    724787                        InternetReadFile(res, (LPVOID)tmpContent,
    725788                                         res.nDataLen, &dwRead);
     
    755818                    fprintf(stderr,"%s = %s\n",ha[hai],(char*)val);
    756819#endif
    757820                    if(hai==0){
    758                       key=(char*)malloc((1+strlen((char*)val))*sizeof(char));
    759                       sprintf(key,"%s",(char*)val);
     821                      key=(char*)calloc((1+strlen((char*)val)), sizeof(char));
     822                      if(key == NULL){
     823                        return errorException(m, "Unable to allocate memory.", "InternalError");
     824                      }
     825                      snprintf(key, (1+strlen((char*)val)), "%s",(char*)val);
    760826                    }else{
    761                       has=(char*)malloc((3+strlen((char*)val)+strlen(key))*sizeof(char));
    762                       sprintf(has,"%s: %s",key,(char*)val);
     827                      has=(char*)calloc((3+strlen((char*)val)+strlen(key)), sizeof(char));
     828                      if(has == NULL){
     829                        return errorException(m, "Unable to allocate memory.", "InternalError");
     830                      }
     831                      snprintf(has,(3+strlen((char*)val)+strlen(key)), "%s: %s",key,(char*)val);
    763832#ifdef POST_DEBUG
    764833                      fprintf(stderr,"%s\n",has);
    765834#endif
     
    772841#ifdef POST_DEBUG
    773842                  fprintf(stderr,"Try to fetch the body part of the request ...\n");
    774843#endif
    775                   if(strcmp(mtoupper((char*)cur3->name),mtoupper("Body"))==0 ){
     844                  if(strncmp(mtoupper((char*)cur3->name),mtoupper("Body"), strlen(mtoupper((char*)cur3->name)))==0 ){
    776845#ifdef POST_DEBUG
    777846                    fprintf(stderr,"Body part found !!!\n",(char*)cur3->content);
    778847#endif
     
    802871#endif
    803872                      res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp),
    804873                                          INTERNET_FLAG_NO_CACHE_WRITE,0);
    805                       char* tmpContent=
    806                         (char*)malloc((res.nDataLen+1)*sizeof(char));
     874                      char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
     875                      if(tmpContent == NULL){
     876                        return errorException(m, "Unable to allocate memory.", "InternalError");
     877                      }
    807878                      size_t dwRead;
    808879                      InternetReadFile(res, (LPVOID)tmpContent,
    809880                                       res.nDataLen, &dwRead);
     
    834905#endif
    835906                      res1=InternetOpenUrl(bInternet,(char*)val,NULL,0,
    836907                                           INTERNET_FLAG_NO_CACHE_WRITE,0);
    837                       char* tmp=
    838                         (char*)malloc((res1.nDataLen+1)*sizeof(char));
     908                      char* tmp= (char*)calloc((res1.nDataLen+1), sizeof(char));
     909                      if(tmp == NULL){
     910                        return errorException(m, "Unable to allocate memory.", "InternalError");
     911                      }
    839912                      size_t bRead;
    840913                      InternetReadFile(res1, (LPVOID)tmp,
    841914                                       res1.nDataLen, &bRead);
     
    850923                        res=InternetOpenUrl(hInternet,btmp->value,tmp,
    851924                                            strlen(tmp),
    852925                                            INTERNET_FLAG_NO_CACHE_WRITE,0);
    853                         char* tmpContent=
    854                           (char*)malloc((res.nDataLen+1)*sizeof(char));
     926                        char* tmpContent= (char*)calloc((res.nDataLen+1),sizeof(char));
     927                        if(tmpContent == NULL){
     928                          return errorException(m, "Unable to allocate memory.", "InternalError");
     929                        }
    855930                        size_t dwRead;
    856931                        InternetReadFile(res, (LPVOID)tmpContent,
    857932                                         res.nDataLen, &dwRead);
     
    10201095         * A specific responseDocument node.
    10211096         */
    10221097        if(tmpmaps==NULL){
    1023           tmpmaps=(maps*)malloc(MAPS_SIZE);
     1098          tmpmaps=(maps*)calloc(1, MAPS_SIZE);                     
     1099          if(tmpmaps == NULL){
     1100            return errorException(m, "Unable to allocate memory.", "InternalError");
     1101          }
    10241102          tmpmaps->name="unknownIdentifier";
    10251103          tmpmaps->next=NULL;
    10261104        }
     
    10911169                xmlChar *val=
    10921170                  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    10931171                if(tmpmaps==NULL){
    1094                   tmpmaps=(maps*)malloc(MAPS_SIZE);
     1172                  tmpmaps=(maps*)calloc(1, MAPS_SIZE);
     1173                  if(tmpmaps == NULL){
     1174                    return errorException(m, "Unable to allocate memory.", "InternalError");
     1175                  }
    10951176                  tmpmaps->name=strdup((char*)val);
    10961177                  tmpmaps->content=NULL;
    10971178                  tmpmaps->next=NULL;
     
    11101191                xmlChar *val=
    11111192                  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    11121193                if(tmpmaps==NULL){
    1113                   tmpmaps=(maps*)malloc(MAPS_SIZE);
     1194                  tmpmaps=(maps*)calloc(1, MAPS_SIZE);
     1195                  if(tmpmaps == NULL){
     1196                    return errorException(m, "Unable to allocate memory.", "InternalError");
     1197                  }
    11141198                  tmpmaps->name="missingIndetifier";
    11151199                  tmpmaps->content=createMap((char*)cur2->name,(char*)val);
    11161200                  tmpmaps->next=NULL;
     
    11661250        val=xmlGetProp(cur1,BAD_CAST outs[l]);
    11671251        if(val!=NULL && strlen((char*)val)>0){
    11681252          if(tmpmaps==NULL){
    1169             tmpmaps=(maps*)malloc(MAPS_SIZE);
     1253            tmpmaps=(maps*)calloc(1, MAPS_SIZE);
     1254            if(tmpmaps == NULL){
     1255              return errorException(m, "Unable to allocate memory.", "InternalError");
     1256            }
    11701257            tmpmaps->name="unknownIdentifier";
    11711258            tmpmaps->content=createMap(outs[l],(char*)val);
    11721259            tmpmaps->next=NULL;
     
    11901277          val=
    11911278            xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
    11921279          if(tmpmaps==NULL){
    1193             tmpmaps=(maps*)malloc(MAPS_SIZE);
     1280            tmpmaps=(maps*)calloc(1, MAPS_SIZE);
     1281            if(tmpmaps == NULL){
     1282              return errorException(m, "Unable to allocate memory.", "InternalError");
     1283            }
    11941284            tmpmaps->name=strdup((char*)val);
    11951285            tmpmaps->content=NULL;
    11961286            tmpmaps->next=NULL;
     
    12211311  fprintf(stderr,"\n%i\n",i);
    12221312  dumpMaps(request_input_real_format);
    12231313  dumpMaps(request_output_real_format);
    1224   dumpElements();
    12251314#endif
    12261315
    12271316  /**
  • service_conf.l

     
    123123chardata        [^<]*
    124124/*====================================================*/
    125125attname [a-zA-Z0-9_\-]+
    126 attvalue1       [a-zA-Z0-9_\-.:" "\"\'/\\\(\)]+
     126attvalue1       [=,;@a-zA-Z0-9_\-::.:" "\"\'/\\\(\)]+
    127127
    128128
    129129
  • service_internal.c

     
    2424
    2525#include "service_internal.h"
    2626
     27/* ************************************************************************* */
     28
    2729/* Converts a hex character to its integer value */
    2830char from_hex(char ch) {
    2931  return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
    3032}
    3133
     34/* ************************************************************************* */
     35
    3236/* Converts an integer value to its hex character*/
    3337char to_hex(char code) {
    3438  static char hex[] = "0123456789abcdef";
    3539  return hex[code & 15];
    3640}
    3741
     42/* ************************************************************************* */
     43
    3844/* Returns a url-encoded version of str */
    3945/* IMPORTANT: be sure to free() the returned string after use */
    4046char *url_encode(char *str) {
     
    5258  return buf;
    5359}
    5460
     61/* ************************************************************************* */
     62
    5563/* Returns a url-decoded version of str */
    5664/* IMPORTANT: be sure to free() the returned string after use */
    5765char *url_decode(char *str) {
     
    7482}
    7583
    7684
     85/* ************************************************************************* */
     86
    7787void printProcessResponse1(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){
    7888  if(getpid()==pid)
    7989    printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 
     
    253263
    254264}
    255265
     266/* ************************************************************************* */
    256267
    257268void printProcessResponse(maps* m,int pid,service* serv,char* service,int status,map* inputs,map* outputs){
    258269 
     
    381392  nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
    382393  mcursor=outputs;
    383394  scursor=serv->outputs;
     395#ifdef DEBUG
    384396  //dumpMap(mcursor);
     397#endif
    385398  while(mcursor!=NULL && scursor!=NULL){
    386399    //xmlAddChild(nc,xmlNewComment(BAD_CAST "Here we need to check for output format from metadata"));
    387400    printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
     
    422435
    423436}
    424437
     438/* ************************************************************************* */
    425439
    426440void printGetCapabilitiesResponse(service** serv,int sc,char* service,maps* m){
    427441
     
    729743
    730744}
    731745
     746/* ************************************************************************* */
     747
    732748xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,char* service,maps* m){
    733749
    734750  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
     
    969985  nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings");
    970986  xmlAddChild(n,nc);
    971987
    972 
    973 
    974988  nc1 = xmlNewNode(ns, BAD_CAST "Languages");
    975989  nc2 = xmlNewNode(ns, BAD_CAST "Default");
    976990  nc3 = xmlNewNode(ns, BAD_CAST "Supported");
     
    10201034  return nc;
    10211035}
    10221036
     1037/* ************************************************************************* */
     1038
    10231039void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){
    10241040
    10251041  xmlNsPtr ns,ns_ows;
     
    10871103  xmlFree(xmlbuff);
    10881104
    10891105}
    1090  
    10911106
     1107/* ************************************************************************* */
     1108
    10921109void printDescribeProcessResponse(service* serv,char* service){
    10931110
    10941111  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
     
    13631380
    13641381}
    13651382
     1383/* ************************************************************************* */
     1384
    13661385xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){
    13671386
    13681387  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
     
    13941413  return n;
    13951414}
    13961415
     1416/* ************************************************************************* */
     1417
    13971418void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service** serv,int sc){
    13981419  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
    13991420  xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
     
    16721693
    16731694}
    16741695
     1696/* ************************************************************************* */
     1697
    16751698void printDescribeProcessDocument(xmlDocPtr doc){
    16761699  xmlChar *xmlbuff;
    16771700  int buffersize;
     
    16911714}
    16921715//printGetCapabilitiesHeader
    16931716
     1717/* ************************************************************************* */
     1718
    16941719void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){
    16951720  xmlNodePtr nc1;
    16961721  nc1=xmlNewNode(ns_wps, BAD_CAST type);
     
    17231748
    17241749}
    17251750
     1751/* ************************************************************************* */
     1752
    17261753void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){
    17271754  xmlNodePtr nc1,nc2,nc3;
    17281755  nc1=xmlNewNode(ns_wps, BAD_CAST type);
     
    17511778
    17521779}
    17531780
     1781/* ************************************************************************* */
     1782
    17541783void printIOType1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){
    17551784  xmlNodePtr nc1,nc2,nc3;
    17561785  nc1=xmlNewNode(ns_wps, BAD_CAST type);
     
    18201849
    18211850}
    18221851
     1852/* ************************************************************************* */
     1853
    18231854void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){
    18241855  xmlNodePtr nc1,nc2,nc3;
    18251856  nc1=xmlNewNode(ns_wps, BAD_CAST type);
     
    18641895
    18651896}
    18661897
     1898/* ************************************************************************* */
     1899
    18671900void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,char* identifier,map* amap){
    18681901  xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
    18691902  xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
     
    18831916  }
    18841917}
    18851918
     1919/* ************************************************************************* */
     1920
    18861921void printExceptionReportResponse(maps* m,map* s){
    18871922 
    18881923  printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 
     
    19591994  xmlFree(doc);
    19601995}
    19611996
     1997/* ************************************************************************* */
    19621998
    19631999void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
    19642000                    map* request_inputs1,int cpid,maps* m,int res){
     
    20222058  }
    20232059}
    20242060
     2061/* ************************************************************************* */
     2062
    20252063char *base64(const unsigned char *input, int length)
    20262064{
    20272065  BIO *bmem, *b64;
     
    20442082  return buff;
    20452083}
    20462084
     2085/* ************************************************************************* */
     2086
    20472087void addDefaultValues(maps** out,elements* in,maps* m,char* type){
    20482088  elements* tmpInputs=in;
    20492089  maps* out1=*out;
     
    20732113      if(tmpMap==NULL)
    20742114        addToMap(tmpMaps->content,"value","NULL");
    20752115      tmpMaps->next=NULL;
     2116#ifdef DEBUG
    20762117      dumpMaps(tmpMaps);
     2118#endif
    20772119      if(out1==NULL){
    20782120        out1=(maps*)malloc(MAPS_SIZE);
    20792121        out1->name=tmpMaps->name;
  • service_internal_python.c

     
    2424
    2525#include "service_internal_python.h"
    2626
     27/* ************************************************************************* */
     28
    2729int python_support(maps* m,service* s,int argc,char** argv,map *inputs,map *outputs){
    2830  Py_Initialize();
    2931  PyObject *pName, *pModule, *pFunc;
     
    135137  return 2;
    136138}
    137139
     140/* ************************************************************************* */
     141
    138142int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
    139143  maps* m=*main_conf;
    140144  maps* inputs=*real_inputs;
     
    286290  return res;
    287291}
    288292
     293/* ************************************************************************* */
     294
    289295PyDictObject* PyDict_FromMaps(maps* t){
    290296  PyObject* res=PyDict_New( );
    291297  maps* tmp=t;
     
    299305  return (PyDictObject*) res;
    300306}
    301307
     308/* ************************************************************************* */
     309
    302310PyDictObject* PyDict_FromMap(map* t){
    303311  PyObject* res=PyDict_New( );
    304312  map* tmp=t;
     
    312320  return (PyDictObject*) res;
    313321}
    314322
     323/* ************************************************************************* */
     324
    315325maps* mapsFromPyDict(PyDictObject* t){
    316326  maps* res=NULL;
    317327  maps* cursor=res;
     
    350360  return res;
    351361}
    352362
     363/* ************************************************************************* */
     364
    353365map* mapFromPyDict(PyDictObject* t){
    354366  map* res=NULL;
    355367  PyObject* list=PyDict_Keys((PyObject*)t);
  • zoo_loader.c

     
    2626 * Specific includes
    2727 */
    2828#include "fcgio.h"
    29 #include "fcgi_config.h" 
     29#include "fcgi_config.h"
    3030#include "fcgi_stdio.h"
    3131#include <sys/types.h>
    3232#include <unistd.h>
    33 extern "C" {
     33#include "service_internal.h"
     34
     35extern "C"
     36{
    3437#include "cgic.h"
    35 }
    36 
    37 #include "service_internal.h"
    38 extern "C" {
    3938#include <libxml/tree.h>
    4039#include <libxml/xmlmemory.h>
    4140#include <libxml/parser.h>
     
    4342#include <libxml/xpathInternals.h>
    4443}
    4544
     45xmlNodeSet *extractFromDoc (xmlDocPtr, char *);
     46int runRequest (map *);
     47
     48using namespace std;
     49
     50/* ************************************************************************* */
     51
     52int errorException(maps *m, const char *message, const char *errorcode)
     53{
     54  map * errormap = createMap("text", message);
     55  addToMap(errormap,"code", errorcode);
     56  printExceptionReportResponse(m,errormap);   
     57  return -1;
     58}
     59
     60/* ************************************************************************* */
     61
    4662#ifndef STRTOK_R
    4763char *
    48 strtok_r(char *s1, const char *s2, char **lasts)
     64strtok_r (char *s1, const char *s2, char **lasts)
    4965{
    5066  char *ret;
    5167
    5268  if (s1 == NULL)
    5369    s1 = *lasts;
    54   while(*s1 && strchr(s2, *s1))
     70  while (*s1 && strchr (s2, *s1))
    5571    ++s1;
    56   if(*s1 == '\0')
     72  if (*s1 == '\0')
    5773    return NULL;
    5874  ret = s1;
    59   while(*s1 && !strchr(s2, *s1))
     75  while (*s1 && !strchr (s2, *s1))
    6076    ++s1;
    61   if(*s1)
     77  if (*s1)
    6278    *s1++ = '\0';
    6379  *lasts = s1;
    6480  return ret;
     
    6682
    6783#endif
    6884
    69 xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
    70 int runRequest(map*);
     85/* ************************************************************************* */
    7186
    72 using namespace std;
    73 
    74 char* strtoupper(char* str)
     87char *
     88strtoupper (char *str)
    7589{
    76   int leng=strlen(str);
    77   for(int i=0; i<leng; i++)
    78     if (97<=str[i]&&str[i]<=122)//a-z
    79       str[i]-=32;
     90  int leng = strlen (str);
     91  for (int i = 0; i < leng; i++)
     92    if (97 <= str[i] && str[i] <= 122)  //a-z
     93      str[i] -= 32;
    8094  return str;
    8195}
    8296
    83 char* strtolower(char* str)
     97/* ************************************************************************* */
     98
     99char *
     100strtolower (char *str)
    84101{
    85   int leng=strlen(str);
    86   for(int i=0; i<leng; i++)
    87     if (65<=str[i]&&str[i]<=90)//A-Z
    88       str[i]+=32;
     102  int leng = strlen (str);
     103  for (int i = 0; i < leng; i++)
     104    if (65 <= str[i] && str[i] <= 90)   //A-Z
     105      str[i] += 32;
    89106  return str;
    90107}
    91108
    92 char* remplace(char* delim,char* rep,char* source){
    93   if(strcmp(source,"")==0){
    94 #ifdef DEBUG
    95     //char *tmp="RETURN NULL !\n";
    96     //printf((void*)tmp);
    97 #endif
    98     return "NULL";
    99   }
     109/* ************************************************************************* */
    100110
    101   char *_token;
    102   char *origin=strdup(source);
    103   char result[1024]="";
    104   _token = strtok(source, delim);
     111char *
     112remplace (char *delim, char *rep, char *source)
     113{
     114  if (strcmp (source, "") == 0)
     115    {
     116      return "NULL";
     117    }
     118
     119  char *_token;
     120  char *origin = strdup (source);
     121  char result[1024] = "";
     122  _token = strtok (source, delim);
    105123#ifdef DEBUG
    106   fprintf(stderr,"\nREPLACE TOKEN (%s == %s => %d)\n ",_token,origin,strcmp(_token,origin));
     124  fprintf (stderr, "\nREPLACE TOKEN (%s == %s => %d)\n ", _token, origin,
     125           strcmp (_token, origin));
    107126#endif
    108   if(strcmp(_token,origin)!=0)
    109     while(_token!=NULL){
    110       sprintf(result,"%s%s%s",result,_token,rep);
    111       _token = strtok (NULL, delim);
    112       if(_token==NULL)
    113         result[strlen(result)-strlen(rep)]=0;
     127  if (strcmp (_token, origin) != 0)
     128    while (_token != NULL)
     129      {
     130        snprintf (result, 1024, "%s%s%s", result, _token, rep);
     131        _token = strtok (NULL, delim);
     132        if (_token == NULL)
     133          result[strlen (result) - strlen (rep)] = 0;
    114134#ifdef DEBUG
    115       fprintf(stderr,"\n\nRESULT(%s)\n\n",result);
     135        fprintf (stderr, "\n\nRESULT(%s)\n\n", result);
    116136#endif
    117     }
     137      }
    118138  else
    119139    return origin;
    120  
    121   return strdup(result);
     140
     141  return strdup (result);
    122142}
    123143
    124144
     145/* ************************************************************************* */
     146
    125147char *colors[] = {
    126148  "red", "green", "blue"
    127149};
     
    129151#define colorsTotal 3
    130152#define TRUE -1
    131153#define FALSE -1
    132 static bool started=FALSE;
    133 static bool isStarted=FALSE;
     154static bool started = FALSE;
     155static bool isStarted = FALSE;
    134156
    135 int cgiMain(){
     157/* ************************************************************************* */
     158
     159int
     160cgiMain ()
     161{
    136162  /**
    137163   * We'll use cgiOut as the default output (stdout) to produce plain text
    138164   * response.
    139165   */
    140   dup2(fileno(cgiOut),fileno(stdout));
     166  dup2 (fileno (cgiOut), fileno (stderr));
    141167#ifdef DEBUG
    142     fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
    143     fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n");
    144     fflush(cgiOut);
     168  fprintf (cgiOut,
     169           "Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
     170  fprintf (cgiOut, "Welcome on ZOO verbose debuging mode \r\n\r\n");
     171  fflush (cgiOut);
    145172#endif
    146  
    147173  /**
    148174   * Read the main configuration file
    149175   */
    150   if(!isStarted){
    151     maps* m;
    152     m=(maps*)malloc(sizeof(maps*)); 
    153     conf_read("main.cfg",m);
     176#ifdef DEBUG
     177  fprintf (stderr, "Read main config file\n");
     178#endif
     179
     180  if (!isStarted)
     181    {
     182      maps *m = NULL;
     183      m = (maps *) calloc (1, sizeof (maps));
     184      if (m == NULL)
     185        {
     186          fprintf (stderr, "Unable to allocate memory for map in zoo_loader.c line %i", __LINE__);
     187          return -1;
     188        }
     189      conf_read ("main.cfg", m);
    154190#ifdef REAL_FCGI
    155191#ifdef DEBUG
    156     printf("ok passed");
    157 #endif   
    158 #endif   
    159     isStarted=TRUE;
    160   }
     192      printf ("ok passed");
     193#endif
     194#endif
     195      isStarted = TRUE;
     196    }
    161197
    162198#ifdef DEBUG
    163   char textb[23];
    164   sprintf(textb,"\n%s\n%s\n",cgiRemoteAddr,cgiRequestMethod);
    165   fprintf(stderr,"****%s\n%s\n***",textb,cgiQueryString);
     199  fprintf (stderr, "Addr:%s\n", cgiRemoteAddr);
     200  fprintf (stderr, "RequestMethod:%s\n", cgiRequestMethod);
     201  fprintf (stderr, "Request: %s\n", cgiQueryString);
    166202#endif
    167203
    168   map* tmp=NULL;
    169    
    170   if(strncmp(cgiContentType,"text/xml",8)==0){
    171     char *buffer=new char[cgiContentLength];
    172     if(fread(buffer,1,cgiContentLength,cgiIn)){
    173       buffer[cgiContentLength]=0;
    174       tmp=createMap("request",buffer);
    175     }else{
    176       /* Here we have to return an error message ... */
    177       return 1;
    178     }
    179   }
    180   else{
    181     char **array, **arrayStep;
    182     if (cgiFormEntries(&array) != cgiFormSuccess) {
    183       return 1;
    184     }
    185     arrayStep = array;
    186     while (*arrayStep) {
    187       char *value=new char[cgiContentLength];
    188       cgiFormStringNoNewlines(*arrayStep, value, cgiContentLength);
     204  map *tmpMap = NULL;
     205
     206  if (strncmp (cgiContentType, "text/xml", 8) == 0)
     207    {
    189208#ifdef DEBUG
    190       fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
     209  fprintf (stderr, "XML Request\n");
    191210#endif
    192       if(tmp!=NULL)
    193         addToMap(tmp,*arrayStep,value);
     211      char *buffer = new char[cgiContentLength];
     212      if (fread (buffer, 1, cgiContentLength, cgiIn))
     213        {
     214          buffer[cgiContentLength] = 0;
     215          tmpMap = createMap ("request", buffer);
     216        }
    194217      else
    195         tmp=createMap(*arrayStep,value);
    196       arrayStep++;
     218        {
     219          fprintf(stderr, "Unable to read cgi content in zoo_loader.c line %i\n", __LINE__);
     220          return -1;
     221        }
     222      delete[]buffer;
    197223    }
    198     cgiStringArrayFree(array);
    199   }
     224  else
     225    {
     226#ifdef DEBUG
     227  fprintf (stderr, "Key-Value Request\n");
     228#endif
     229      char **array, **arrayStep;
     230      if (cgiFormEntries (&array) != cgiFormSuccess)
     231        {
     232          return 1;
     233        }
     234      arrayStep = array;
     235      while (*arrayStep)
     236        {
     237          char *value = new char[cgiContentLength];
     238          cgiFormStringNoNewlines (*arrayStep, value, cgiContentLength);
     239#ifdef DEBUG
     240          fprintf (stderr, "(( %s = %s ))", *arrayStep, value);
     241#endif
     242          if (tmpMap != NULL)
     243            addToMap (tmpMap, *arrayStep, value);
     244          else
     245            tmpMap = createMap (*arrayStep, value);
     246          arrayStep++;
     247          delete[]value;
     248        }
     249      cgiStringArrayFree (array);
     250    }
    200251
     252#ifdef DEBUG
     253  fprintf (stderr, "\nChecking request method: %s", cgiRequestMethod);
     254#endif
     255
    201256  /**
    202257   * In case that the POST method was used, then check if params came in XML
    203258   * format (attribute request should be the once).
    204259   */
    205   if(strcmp(cgiRequestMethod,mtoupper("post"))==0 && count(tmp)==1){
     260  if (strncmp (cgiRequestMethod, mtoupper ("post"), 4) == 0 && tmpMap != NULL
     261      && count (tmpMap) == 1)
     262    {
    206263    /**
    207264     * First include the MetaPath and the ServiceProvider default parameters
    208265     * (which should be always available in GET params so in cgiQueryString)
    209266     */
    210     char *saveptr1, *saveptr2;
    211     char *str1, *str2, *token, *subtoken;
    212     str1=cgiQueryString;
    213     token=strtok_r(str1,"&",&saveptr1);
    214     while(token!=NULL){
     267      char *saveptr1, *saveptr2;
     268      char *str1, *str2, *token, *subtoken;
     269      str1 = cgiQueryString;
     270      token = strtok_r (str1, "&", &saveptr1);
     271      while (token != NULL)
     272        {
    215273#ifdef DEBUG
    216       fprintf(stderr,"%s",token);
     274          fprintf (stderr, "%s", token);
    217275#endif
    218       str2=token;
    219       subtoken=strtok_r(str2,"=",&saveptr2);
     276          str2 = token;
     277          subtoken = strtok_r (str2, "=", &saveptr2);
    220278#ifdef DEBUG
    221       fprintf(stderr,"%s\n",subtoken);
     279          fprintf (stderr, "%s\n", subtoken);
    222280#endif
    223       char* tmp_name;
    224       if(subtoken!=NULL){
    225         tmp_name=subtoken;
     281          char *tmp_name;
     282          if (subtoken != NULL)
     283            {
     284              tmp_name = subtoken;
    226285#ifdef DEBUG
    227         fprintf(stderr,"%s",subtoken);
     286              fprintf (stderr, "%s", subtoken);
    228287#endif
    229         subtoken=strtok_r(NULL,"=",&saveptr2);
    230         if(subtoken!=NULL)
    231           addToMap(tmp,tmp_name,subtoken);
    232         else
    233           addToMap(tmp,tmp_name,"");
    234       }
    235       token=strtok_r(NULL,"&",&saveptr1);
    236     }
     288              subtoken = strtok_r (NULL, "=", &saveptr2);
     289              if (subtoken != NULL)
     290                addToMap (tmpMap, tmp_name, subtoken);
     291              else
     292                addToMap (tmpMap, tmp_name, "");
     293            }
     294          token = strtok_r (NULL, "&", &saveptr1);
     295        }
    237296    /**
    238297     * Store the original XML request in xrequest map
    239298     */
    240     map* t1=getMap(tmp,"request");
    241     if(t1!=NULL){
    242       addToMap(tmp,"xrequest",t1->value);
    243       xmlInitParser();
    244       xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);     
    245       xmlNodePtr cur = xmlDocGetRootElement(doc);
    246       char *tval;
    247       tval=NULL;
    248       tval = (char*) xmlGetProp(cur,BAD_CAST "service");
    249       if(tval!=NULL)
    250         addToMap(tmp,"service",tval);
    251       tval=NULL;
    252       tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    253       if(tval!=NULL)
    254         addToMap(tmp,"language",tval);
    255      
    256       char* requests[3];
    257       requests[0]="GetCapabilities";
    258       requests[1]="DescribeProcess";
    259       requests[2]="Execute";
    260       for(int j=0;j<3;j++){
    261         char tt[35];
    262         sprintf(tt,"/*[local-name()='%s']",requests[j]);
    263         xmlNodeSet* req=extractFromDoc(doc,tt);
     299      map *t1 = getMap (tmpMap, "request");
     300      if (t1 != NULL)
     301        {
     302          addToMap (tmpMap, "xrequest", t1->value);
     303          xmlInitParser ();
     304          xmlDocPtr doc = xmlParseMemory (t1->value, cgiContentLength);
     305          xmlNodePtr cur = xmlDocGetRootElement (doc);
     306          char *tval;
     307          tval = NULL;
     308          tval = (char *) xmlGetProp (cur, BAD_CAST "service");
     309          if (tval != NULL)
     310            addToMap (tmpMap, "service", tval);
     311          tval = NULL;
     312          tval = (char *) xmlGetProp (cur, BAD_CAST "language");
     313          if (tval != NULL)
     314            addToMap (tmpMap, "language", tval);
     315
     316          char *requests[3];
     317          requests[0] = "GetCapabilities";
     318          requests[1] = "DescribeProcess";
     319          requests[2] = "Execute";
     320          for (int j = 0; j < 3; j++)
     321            {
     322              char tt[35];
     323              snprintf (tt, 35, "/*[local-name()='%s']", requests[j]);
     324              xmlNodeSet *req = extractFromDoc (doc, tt);
    264325#ifdef DEBUG
    265         fprintf(stderr,"%i",req->nodeNr);
     326              fprintf (stderr, "%i", req->nodeNr);
    266327#endif
    267         if(req->nodeNr==1){
    268           t1->value=requests[j];
    269           j=2;
     328              if (req->nodeNr == 1)
     329                {
     330                  t1->value = requests[j];
     331                  j = 2;
     332                }
     333              xmlFree (req);
     334            }
     335          if (strncmp (mtoupper (t1->value), mtoupper ("GetCapabilities"), strlen(mtoupper (t1->value))) ==
     336              0)
     337            {
     338              xmlNodeSet *vers =
     339                extractFromDoc (doc, "/*/*/*[local-name()='Version']");
     340              xmlChar *content =
     341                xmlNodeListGetString (doc, vers->nodeTab[0]->xmlChildrenNode,
     342                                      1);
     343              addToMap (tmpMap, "version", (char *) content);
     344              xmlFree (vers);
     345              xmlFree (content);
     346            }
     347          else
     348            {
     349              tval = NULL;
     350              tval = (char *) xmlGetProp (cur, BAD_CAST "version");
     351              if (tval != NULL)
     352                addToMap (tmpMap, "version", tval);
     353              xmlFree (tval);
     354              tval = (char *) xmlGetProp (cur, BAD_CAST "language");
     355              if (tval != NULL)
     356                addToMap (tmpMap, "language", tval);
     357              xmlNodeSet *id =
     358                extractFromDoc (doc, "/*/*[local-name()='Identifier']");
     359              char *identifiers = NULL;
     360              identifiers = (char *) malloc (cgiContentLength);
     361              if(identifiers == NULL) {
     362                fprintf(stderr, "Unable to allocate memory in zoo_loader.c line %i\n", __LINE__);
     363                return -1;
     364              }
     365              identifiers[0] = 0;
     366              for (int k = 0; k < id->nodeNr; k++)
     367                {
     368                  xmlChar *content =
     369                    xmlNodeListGetString (doc,
     370                                          id->nodeTab[k]->xmlChildrenNode, 1);
     371                  if (strlen (identifiers) > 0)
     372                    {
     373                      snprintf (identifiers, cgiContentLength, "%s,%s", identifiers, content);
     374                      identifiers[strlen (identifiers)] = 0;
     375                    }
     376                  else
     377                    {
     378                      snprintf (identifiers, cgiContentLength, "%s", content);
     379                      identifiers[strlen (identifiers)] = 0;
     380                    }
     381                  xmlFree (content);
     382                }
     383              xmlFree (id);
     384              addToMap (tmpMap, "Identifier", identifiers);
     385            }
     386          //xmlCleanupParser();
     387          xmlFree (tval);
    270388        }
    271         xmlFree(req);
    272       }
    273       if(strcmp(mtoupper(t1->value),mtoupper("GetCapabilities"))==0){   
    274         xmlNodeSet* vers=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
    275         xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);
    276         addToMap(tmp,"version",(char*)content);
    277         xmlFree(vers);
    278         xmlFree(content);
    279       }else{
    280         tval=NULL;
    281         tval = (char*) xmlGetProp(cur,BAD_CAST "version");
    282         if(tval!=NULL)
    283           addToMap(tmp,"version",tval);
    284         xmlFree(tval);
    285         tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    286         if(tval!=NULL)
    287           addToMap(tmp,"language",tval);
    288         xmlNodeSet* id=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
    289         char* identifiers=NULL;
    290         identifiers=(char*)malloc(cgiContentLength);
    291         identifiers[0]=0;
    292         for(int k=0;k<id->nodeNr;k++){
    293           xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
    294           if(strlen(identifiers)>0){
    295             sprintf(identifiers,"%s,%s",identifiers,content);
    296             identifiers[strlen(identifiers)]=0;
    297           }
    298           else{
    299             sprintf(identifiers,"%s",content);
    300             identifiers[strlen(identifiers)]=0;
    301           }
    302           xmlFree(content);
    303         }
    304         xmlFree(id);
    305         addToMap(tmp,"Identifier",identifiers);
    306       }
    307       //xmlCleanupParser();
    308       xmlFree(tval);
    309389    }
    310   }
     390
     391#ifdef DEBUG
     392  fprintf (stderr, "\nRuning Request\n");
     393#endif
    311394  //dumpMap(tmp);
    312   runRequest(tmp);
     395  runRequest (tmpMap);
    313396  //dumpMap(tmp);
    314397
    315398  return 0;

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