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

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

File:
1 edited

Legend:

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

    r1 r9  
    2323 */
    2424
     25#define MALLOC_CHECK_ 0
     26#define MALLOC_CHECK 0
     27
    2528/**
    2629 * Specific includes
     
    3134#include <sys/types.h>
    3235#include <unistd.h>
     36#include "service_internal.h"
     37
    3338extern "C" {
    3439#include "cgic.h"
    35 }
    36 
    37 #include "service_internal.h"
    38 extern "C" {
    3940#include <libxml/tree.h>
    4041#include <libxml/xmlmemory.h>
     
    4445}
    4546
     47xmlXPathObjectPtr extractFromDoc(xmlDocPtr,char*);
     48int runRequest(map*);
     49
     50using namespace std;
     51
     52/* ************************************************************************* */
     53
     54int errorException(maps *m, const char *message, const char *errorcode)
     55{
     56  map * errormap = createMap("text", message);
     57  addToMap(errormap,"code", errorcode);
     58  printExceptionReportResponse(m,errormap);
     59  freeMap(&errormap);
     60  free(errormap);
     61  return -1;
     62}
     63
     64/* ************************************************************************* */
     65
    4666#ifndef STRTOK_R
    4767char *
    48 strtok_r(char *s1, const char *s2, char **lasts)
     68strtok_r (char *s1, const char *s2, char **lasts)
    4969{
    5070  char *ret;
     
    5272  if (s1 == NULL)
    5373    s1 = *lasts;
    54   while(*s1 && strchr(s2, *s1))
     74  while (*s1 && strchr(s2, *s1))
    5575    ++s1;
    56   if(*s1 == '\0')
     76  if (*s1 == '\0')
    5777    return NULL;
    5878  ret = s1;
    59   while(*s1 && !strchr(s2, *s1))
     79  while (*s1 && !strchr(s2, *s1))
    6080    ++s1;
    61   if(*s1)
     81  if (*s1)
    6282    *s1++ = '\0';
    6383  *lasts = s1;
     
    6787#endif
    6888
    69 xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
    70 int runRequest(map*);
    71 
    72 using namespace std;
    73 
    74 char* strtoupper(char* str)
    75 {
    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;
    80   return str;
    81 }
    82 
    83 char* strtolower(char* str)
    84 {
    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;
    89   return str;
    90 }
    91 
    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   }
    100 
    101   char *_token;
    102   char *origin=strdup(source);
    103   char result[1024]="";
    104   _token = strtok(source, delim);
    105 #ifdef DEBUG
    106   fprintf(stderr,"\nREPLACE TOKEN (%s == %s => %d)\n ",_token,origin,strcmp(_token,origin));
    107 #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;
    114 #ifdef DEBUG
    115       fprintf(stderr,"\n\nRESULT(%s)\n\n",result);
    116 #endif
    117     }
    118   else
    119     return origin;
    120  
    121   return strdup(result);
    122 }
    123 
    124 
    125 char *colors[] = {
    126   "red", "green", "blue"
    127 };
    128 
    129 #define colorsTotal 3
    130 #define TRUE -1
     89#define TRUE 1
    13190#define FALSE -1
    132 static bool started=FALSE;
    133 static bool isStarted=FALSE;
    13491
    13592int cgiMain(){
     
    14097  dup2(fileno(cgiOut),fileno(stdout));
    14198#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);
     99  fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
     100  fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n");
     101  fflush(cgiOut);
    145102#endif
    146103 
    147104  /**
    148105   * Read the main configuration file
    149    */
    150106  if(!isStarted){
    151107    maps* m;
     
    159115    isStarted=TRUE;
    160116  }
    161 
    162 #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);
    166 #endif
    167 
    168   map* tmp=NULL;
     117   */
     118
     119#ifdef DEBUG
     120  fprintf (stderr, "Addr:%s\n", cgiRemoteAddr);
     121  fprintf (stderr, "RequestMethod:%s\n", cgiRequestMethod);
     122  fprintf (stderr, "Request: %s\n", cgiQueryString);
     123#endif
     124
     125  map* tmpMap=NULL;
    169126   
    170127  if(strncmp(cgiContentType,"text/xml",8)==0){
    171     char *buffer=new char[cgiContentLength];
     128    char *buffer=new char[cgiContentLength+1];
    172129    if(fread(buffer,1,cgiContentLength,cgiIn)){
    173130      buffer[cgiContentLength]=0;
    174       tmp=createMap("request",buffer);
     131      tmpMap=createMap("request",buffer);
    175132    }else{
    176133      /* Here we have to return an error message ... */
     134      fprintf(stderr, "Unable to read cgi content in zoo_loader.c line %i\n", __LINE__);     
    177135      return 1;
    178136    }
     137    delete[]buffer;
    179138  }
    180139  else{
     
    190149      fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
    191150#endif
    192       if(tmp!=NULL)
    193         addToMap(tmp,*arrayStep,value);
     151      if(tmpMap!=NULL)
     152        addToMap(tmpMap,*arrayStep,value);
    194153      else
    195         tmp=createMap(*arrayStep,value);
     154        tmpMap=createMap(*arrayStep,value);
    196155      arrayStep++;
     156      delete[]value;
    197157    }
    198158    cgiStringArrayFree(array);
     
    201161  /**
    202162   * In case that the POST method was used, then check if params came in XML
    203    * format (attribute request should be the once).
    204    */
    205   if(strcmp(cgiRequestMethod,mtoupper("post"))==0 && count(tmp)==1){
     163   * format else try to use the attribute "request" which should be the only
     164   * one.
     165   */
     166  if(strncasecmp(cgiRequestMethod,"post",4)==0 || count(tmpMap)==1){
    206167    /**
    207168     * First include the MetaPath and the ServiceProvider default parameters
    208169     * (which should be always available in GET params so in cgiQueryString)
    209170     */
    210     char *saveptr1, *saveptr2;
    211     char *str1, *str2, *token, *subtoken;
     171    //char *saveptr1, *saveptr2;
     172    char *str1/*, str2, *token, *subtoken*/;
    212173    str1=cgiQueryString;
    213     token=strtok_r(str1,"&",&saveptr1);
    214     while(token!=NULL){
    215 #ifdef DEBUG
    216       fprintf(stderr,"%s",token);
    217 #endif
    218       str2=token;
    219       subtoken=strtok_r(str2,"=",&saveptr2);
    220 #ifdef DEBUG
    221       fprintf(stderr,"%s\n",subtoken);
    222 #endif
    223       char* tmp_name;
    224       if(subtoken!=NULL){
    225         tmp_name=subtoken;
    226 #ifdef DEBUG
    227         fprintf(stderr,"%s",subtoken);
    228 #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     }
    237174    /**
    238175     * Store the original XML request in xrequest map
    239176     */
    240     map* t1=getMap(tmp,"request");
     177    map* t1=getMap(tmpMap,"request");
    241178    if(t1!=NULL){
    242       addToMap(tmp,"xrequest",t1->value);
     179      addToMap(tmpMap,"xrequest",t1->value);
    243180      xmlInitParser();
    244       xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);     
     181      xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);
    245182      xmlNodePtr cur = xmlDocGetRootElement(doc);
    246183      char *tval;
     
    248185      tval = (char*) xmlGetProp(cur,BAD_CAST "service");
    249186      if(tval!=NULL)
    250         addToMap(tmp,"service",tval);
     187        addToMap(tmpMap,"service",tval);
    251188      tval=NULL;
    252189      tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    253190      if(tval!=NULL)
    254         addToMap(tmp,"language",tval);
     191        addToMap(tmpMap,"language",tval);
    255192     
    256193      char* requests[3];
     
    261198        char tt[35];
    262199        sprintf(tt,"/*[local-name()='%s']",requests[j]);
    263         xmlNodeSet* req=extractFromDoc(doc,tt);
    264 #ifdef DEBUG
    265         fprintf(stderr,"%i",req->nodeNr);
    266 #endif
    267         if(req->nodeNr==1){
    268           t1->value=requests[j];
    269           j=2;
     200        xmlXPathObjectPtr reqptr=extractFromDoc(doc,tt);
     201        if(reqptr!=NULL){
     202          xmlNodeSet* req=reqptr->nodesetval;
     203#ifdef DEBUG
     204          fprintf(stderr,"%i",req->nodeNr);
     205#endif
     206          if(req!=NULL && req->nodeNr==1){
     207            t1->value=requests[j];
     208            j=2;
     209          }
     210          xmlXPathFreeObject(reqptr);
    270211        }
    271         xmlFree(req);
     212        //xmlFree(req);
    272213      }
    273       if(strcmp(mtoupper(t1->value),mtoupper("GetCapabilities"))==0){   
    274         xmlNodeSet* vers=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
     214      if(strncasecmp(t1->value,"GetCapabilities",15)==0){
     215        xmlXPathObjectPtr versptr=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
     216        xmlNodeSet* vers=versptr->nodesetval;
    275217        xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);
    276         addToMap(tmp,"version",(char*)content);
    277         xmlFree(vers);
     218        addToMap(tmpMap,"version",(char*)content);
     219        xmlXPathFreeObject(versptr);
     220        //xmlFree(vers);
    278221        xmlFree(content);
    279222      }else{
     
    281224        tval = (char*) xmlGetProp(cur,BAD_CAST "version");
    282225        if(tval!=NULL)
    283           addToMap(tmp,"version",tval);
     226          addToMap(tmpMap,"version",tval);
    284227        xmlFree(tval);
    285228        tval = (char*) xmlGetProp(cur,BAD_CAST "language");
    286229        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;
     230          addToMap(tmpMap,"language",tval);
     231        xmlXPathObjectPtr idptr=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
     232        if(idptr!=NULL){
     233          xmlNodeSet* id=idptr->nodesetval;
     234          if(id!=NULL){
     235            char* identifiers=NULL;
     236            identifiers=(char*)calloc(cgiContentLength,sizeof(char));
     237            identifiers[0]=0;
     238            for(int k=0;k<id->nodeNr;k++){
     239              xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
     240              if(strlen(identifiers)>0){
     241                char *tmp=strdup(identifiers);
     242                snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content);
     243                free(tmp);
     244              }
     245              else{
     246                snprintf(identifiers,xmlStrlen(content)+1,"%s",content);
     247              }
     248              xmlFree(content);
     249            }
     250            xmlXPathFreeObject(idptr);
     251            addToMap(tmpMap,"Identifier",identifiers);
     252            free(identifiers);
    297253          }
    298           else{
    299             sprintf(identifiers,"%s",content);
    300             identifiers[strlen(identifiers)]=0;
    301           }
    302           xmlFree(content);
    303254        }
    304         xmlFree(id);
    305         addToMap(tmp,"Identifier",identifiers);
     255        //xmlFree(id);
    306256      }
    307       //xmlCleanupParser();
    308257      xmlFree(tval);
    309     }
    310   }
    311   //dumpMap(tmp);
    312   runRequest(tmp);
    313   //dumpMap(tmp);
    314 
     258      xmlFreeDoc(doc);
     259      xmlCleanupParser();
     260    }
     261  }
     262
     263  runRequest(tmpMap);
     264
     265  /**
     266   * Required but can't be made after executing a process using POST requests.
     267   */
     268  if(strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && tmpMap!=NULL){
     269    freeMap(&tmpMap);
     270    free(tmpMap);
     271  }
    315272  return 0;
    316273
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