Ignore:
Timestamp:
Aug 5, 2011, 3:02:43 PM (13 years ago)
Author:
djay
Message:

Merge branch-1.2 r268:r296.

Location:
branches/branch-1.2
Files:
13 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/branch-1.2

  • branches/branch-1.2/zoo-kernel/Makefile.in

    r217 r301  
    22ifeq ($(OS),Darwin)
    33        MACOS_LD_FLAGS=-lintl -framework SystemConfiguration -framework CoreFoundation
    4         MACOS_CFLAGS=-arch i386 -arch ppc -arch x86_64
     4        MACOS_CFLAGS=-arch $(shell uname -m)
    55endif
    66
  • branches/branch-1.2/zoo-kernel/configure.ac

    r217 r301  
    122122        [PYTHON_PATH="$withval"; PYTHON_ENABLED="-DUSE_PYTHON"], [PYTHON_ENABLED=""])
    123123
     124AC_ARG_WITH([pyvers],
     125        [AS_HELP_STRING([--with-pyvers=NUM], [To use a specific python version])],
     126        [PYTHON_VERS="$withval"], [PYTHON_VERS=""])
     127
    124128
    125129if test -z "$PYTHON_ENABLED"
     
    127131        PYTHON_FILE=""
    128132else
    129         PYTHONCONFIG="$PYTHON_PATH/bin/python-config"
     133        PYTHONCONFIG="$PYTHON_PATH/bin/python${PYTHON_VERS}-config"
    130134        PYTHON_FILE="service_internal_python.o"
    131135        if test  "$PYTHON_PATH" = "yes"
    132136        then
    133137                # PHP was not specified, so search within the current path
    134                 AC_PATH_PROG([PYTHONCONFIG], [python-config])
    135         else
    136                 PYTHONCONFIG="$PYTHON_PATH/bin/python-config"
     138                AC_PATH_PROG([PYTHONCONFIG], [python${PYTHON_VERS}-config])
     139        else
     140                PYTHONCONFIG="$PYTHON_PATH/bin/python${PYTHON_VERS}-config"
    137141        fi
    138142
     
    314318        JS_FILE=""
    315319else
     320        JS_FILE="service_internal_js.o"
    316321        if test "$JSHOME" = "yes"
    317322        then
    318                 JS_FILE="service_internal_js.o"
    319323
    320324                #on teste si on est sous debian like
    321325                if test -f "/usr/bin/dpkg"
    322326                then
    323                         if test -n "`dpkg -l | grep libmozjs-dev`"
     327                        if test -n "`dpkg -l | grep libmozjs185-dev`"
    324328                        then
    325                                 JS_CPPFLAGS="-I/usr/include/mozjs/"
    326                                 JS_LDFLAGS="-L/usr/lib -lmozjs -lm"
    327                                 JS_LIB="mozjs"
     329                                JS_CPPFLAGS="-I/usr/include/js/"
     330                                JS_LDFLAGS="-L/usr/lib -lmozjs185 -lm"
     331                                JS_LIB="mozjs185"
    328332                        else
    329                                 XUL_VERSION="`dpkg -l | grep xulrunner | grep dev | awk '{print $3;}' | sed -e 's/\([[0-9]]\{1,2\}\.[[0-9]]\{1,2\}\.[[0-9]]\{1,2\}\.[[0-9]]\{1,2\}\).*/\1/'`"
     333                                XUL_VERSION="`dpkg -l | grep xulrunner | grep dev | head -1| awk '{print $3;}' | cut -d'+' -f1`"
    330334                                if test -n "$XUL_VERSION"
    331335                                then
     
    334338                                        JS_LIB="mozjs"
    335339                                else
    336                                         AC_MSG_ERROR([You must install libmozjs-dev or xulrunner-dev ])
     340                                        AC_MSG_ERROR([You must install libmozjs185-dev or xulrunner-dev ])
    337341                                fi
    338342                        fi
    339343                else
    340                         AC_MSG_ERROR([You must  specify your custom install of libjs])
     344                        AC_MSG_ERROR([You must  specify your custom install of libmozjs185])
    341345                fi
    342346        else
    343                 JS_CPPFLAGS="-I$JSHOME/include/"
    344                 JS_LDFLAGS="-L$JSHOME/lib -lmozjs -lm"
    345                 JS_LIB="mozjs"
     347                JS_CPPFLAGS="-I$JSHOME/include/js/"
     348                JS_LDFLAGS="-L$JSHOME/lib -lmozjs185 -lm"
     349                JS_LIB="mozjs185"
    346350
    347351        fi
     
    356360        LIBS="$JS_LDFLAGS"
    357361
    358         AC_CHECK_LIB([$JS_LIB], [JS_CallFunctionName], [], [AC_MSG_ERROR([could not find $JS_LIB])], [])
     362        AC_CHECK_LIB([$JS_LIB], [JS_CompileFile,JS_CallFunctionName], [], [AC_MSG_ERROR([could not find $JS_LIB])], [])
    359363                       
    360364        AC_SUBST([JS_CPPFLAGS])
     
    366370
    367371AC_CONFIG_FILES([Makefile])
     372AC_CONFIG_FILES([ZOOMakefile.opts])
    368373AC_OUTPUT
  • branches/branch-1.2/zoo-kernel/service.h

    r268 r301  
    203203  }
    204204
     205
    205206  static map* getLastMap(map* m){
    206207    map* tmp=m;
     
    497498  }
    498499
     500  static map* getMapOrFill(map* m,const char *key,char* value){
     501    map* tmp=m;
     502    map* tmpMap=getMap(tmp,key);
     503    if(tmpMap==NULL){
     504      if(tmp!=NULL)
     505        addToMap(tmp,key,value);
     506      else
     507        tmp=createMap(key,value);
     508      tmpMap=getMap(tmp,key);
     509    }
     510    return tmpMap;
     511  }
     512
    499513  static bool contains(map* m,map* i){
    500514    while(i!=NULL){     
  • branches/branch-1.2/zoo-kernel/service_internal.c

    r268 r301  
    258258
    259259JSBool
    260 JSUpdateStatus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
     260JSUpdateStatus(JSContext *cx, uintN argc, jsval *argv1)
    261261{
     262  jsval *argv = JS_ARGV(cx,argv1);
    262263  JS_MaybeGC(cx);
    263264  char *sid;
     
    280281  }
    281282  if(getMapFromMaps(conf,"lenv","status")!=NULL){
    282     if(status!=NULL)
     283    fprintf(stderr,"STATUS RETURNED : %s\n",status);
     284    if(status!=NULL){
    283285      setMapInMaps(conf,"lenv","status",status);
     286      free(status);
     287    }
    284288    else
    285289      setMapInMaps(conf,"lenv","status","15");
     
    367371#endif
    368372  int currId=-1;
     373  int currNode=-1;
    369374  if(nbNs==0){
    370375    nbNs++;
     
    399404  }
    400405  nbNs=0;
     406}
     407
     408xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){
     409  map* soap=getMapFromMaps(conf,"main","isSoap");
     410  if(soap!=NULL && strcasecmp(soap->value,"true")==0){
     411    int lNbNs=nbNs;
     412    nsName[lNbNs]=strdup("soap");
     413    usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
     414    nbNs++;
     415    xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope");
     416    nsName[nbNs]=strdup("soap");
     417    usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
     418    nbNs++;
     419    nsName[nbNs]=strdup("xsi");
     420    usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
     421    nbNs++;
     422    xmlNsPtr ns_xsi=usedNs[nbNs-1];
     423    xmlNewNsProp(nr,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope");
     424    xmlNodePtr nr1 = xmlNewNode(usedNs[lNbNs], BAD_CAST "Body");
     425    xmlAddChild(nr1,n);
     426    xmlAddChild(nr,nr1);
     427    return nr;
     428  }else
     429    return n;
    401430}
    402431
     
    715744  xmlAddChild(n,nc1);
    716745 
    717   xmlDocSetRootElement(doc, n);
     746  xmlNodePtr fn=soapEnvelope(m,n);
     747  xmlDocSetRootElement(doc, fn);
    718748  //xmlFreeNs(ns);
    719749  free(SERVICE_URL);
     
    775805  addLangAttr(n,m);
    776806
    777   xmlDocSetRootElement(doc, n);
     807  xmlNodePtr fn=soapEnvelope(m,n);
     808  xmlDocSetRootElement(doc, fn);
    778809
    779810  return n;
     
    10031034        }
    10041035    }
     1036
    10051037    _tmp=e->supported;
     1038    if(_tmp==NULL && (getMap(e->defaults->content,"uom")!=NULL || datatype!=1))
     1039      _tmp=e->defaults;
     1040
    10061041    int hasSupported=-1;
    10071042    while(_tmp!=NULL){
     
    10821117      if(hasDefault!=true && strncmp(type,"Input",5)==0)
    10831118        xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
    1084       xmlFreeNodeList(nc5);
    1085       xmlFreeNodeList(nc4);
    10861119    }
    10871120   
     
    10931126
    10941127void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
    1095   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
     1128  xmlNsPtr ns,ns1,ns_ows,ns_xlink,ns_xsi;
    10961129  xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor;
    10971130  xmlDocPtr doc;
     
    11001133  time_t time1; 
    11011134  time(&time1);
     1135  nr=NULL;
    11021136  /**
    11031137   * Create the document and its temporary root.
     
    11061140  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
    11071141  ns=usedNs[wpsId];
    1108  
     1142
    11091143  n = xmlNewNode(ns, BAD_CAST "ExecuteResponse");
     1144  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
    11101145  int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
    11111146  ns_ows=usedNs[owsId];
     
    11141149  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
    11151150  ns_xsi=usedNs[xsiId];
    1116   xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
    1117 
     1151 
    11181152  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd");
    11191153 
     
    11591193        sprintf(currentSid,"%s",tmp_lenv->value);
    11601194      if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){
    1161         sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
     1195        sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
    11621196      }else{
    11631197        if(strlen(tmpm->value)>0)
     
    11761210    }
    11771211    if(tmpm1!=NULL)
    1178       sprintf(tmp,"%s/",tmpm1->value);
     1212      sprintf(tmp,"%s",tmpm1->value);
    11791213    tmpm1=getMapFromMaps(m,"main","TmpPath");
    11801214    sprintf(stored_path,"%s/%s_%i.xml",tmpm1->value,service,pid);
     
    13121346    while(mcursor!=NULL){
    13131347      scursor=getElements(serv->outputs,mcursor->name);
    1314       printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
     1348      if(scursor!=NULL){
     1349        printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
     1350      }
    13151351      mcursor=mcursor->next;
    13161352    }
     
    13201356  fprintf(stderr,"printProcessResponse 1 202\n");
    13211357#endif
    1322   xmlDocSetRootElement(doc, n);
     1358  nr=soapEnvelope(m,n);
     1359  xmlDocSetRootElement(doc, nr);
     1360
    13231361  if(hasStoredExecuteResponse==true){
    13241362    /* We need to write the ExecuteResponse Document somewhere */
     
    15251563         || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 ||
    15261564                            (strncmp(tmp2->value,"application/",12)==0) &&
    1527                             strncmp(tmp2->value,"application/json",16)!=0))) {
     1565                            strncmp(tmp2->value,"application/json",16)!=0&&
     1566                            strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0)
     1567             )) {
    15281568        map* rs=getMap(m->content,"size");
    15291569        bool isSized=true;
     
    15311571          char tmp1[1024];
    15321572          sprintf(tmp1,"%d",strlen(toto->value));
    1533           rs=createMap("z",tmp1);
     1573          rs=createMap("size",tmp1);
    15341574          isSized=false;
    15351575        }
     
    15411581        }
    15421582      }
    1543       else if(tmp!=NULL){
    1544         if(strncmp(tmp->value,"text/js",4)==0 ||
    1545            strncmp(tmp->value,"application/js",14)==0)
     1583      else if(tmp2!=NULL){
     1584        if(strncmp(tmp2->value,"text/js",7)==0 ||
     1585           strncmp(tmp2->value,"application/json",16)==0)
    15461586          xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value)));
    1547         else
    1548           xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value));
     1587        else{
     1588          if(strncmp(tmp2->value,"text/xml",8)==0 ||
     1589             strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0){
     1590            xmlDocPtr doc =
     1591              xmlParseMemory(BAD_CAST toto->value,strlen(BAD_CAST toto->value));
     1592            xmlNodePtr ir = xmlDocGetRootElement(doc);
     1593            xmlAddChild(nc3,ir);
     1594          }
     1595          else
     1596            xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value));
     1597        }
    15491598        xmlAddChild(nc2,nc3);
    15501599      }
     
    17641813            else if(strcasecmp(mtype->value,"application/json")==0)
    17651814              ext=createMap("extension","js");
     1815            else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)!=0)
     1816              ext=createMap("extension","kml");
    17661817            else
    17671818              ext=createMap("extension","txt");
     
    19532004  elements* tmpInputs=in;
    19542005  maps* out1=*out;
     2006  if(type==1){
     2007    while(out1!=NULL){
     2008      if(getElements(in,out1->name)==NULL)
     2009        return out1->name;
     2010      out1=out1->next;
     2011    }
     2012    out1=*out;
     2013  }
    19552014  while(tmpInputs!=NULL){
    19562015    maps *tmpMaps=getMaps(out1,tmpInputs->name);
     
    20822141      else
    20832142        addToMap(tmpMaps->content,"inRequest","true");
     2143
    20842144    }
    20852145    tmpInputs=tmpInputs->next;
     
    22362296 
    22372297}
     2298
     2299
     2300unsigned char* getMd5(char* url){
     2301  EVP_MD_CTX md5ctx;
     2302  unsigned char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char));
     2303  unsigned char result[EVP_MAX_MD_SIZE];
     2304  unsigned int len;
     2305  EVP_DigestInit(&md5ctx, EVP_md5());
     2306  EVP_DigestUpdate(&md5ctx, url, strlen(url));
     2307  EVP_DigestFinal_ex(&md5ctx,result,&len);
     2308  EVP_MD_CTX_cleanup(&md5ctx);
     2309  int i;
     2310  for(i = 0; i < len; i++){
     2311    if(i>0){
     2312      char *tmp=strdup(fresult);
     2313      sprintf(fresult,"%s%02x", tmp,result[i]);
     2314      free(tmp);
     2315    }
     2316    else
     2317      sprintf(fresult,"%02x",result[i]);
     2318  }
     2319  return fresult;
     2320}
     2321
     2322/**
     2323 * Cache a file for a given request
     2324 */
     2325void addToCache(maps* conf,char* request,char* content,int length){
     2326  map* tmp=getMapFromMaps(conf,"main","cacheDir");
     2327  if(tmp!=NULL){
     2328    unsigned char* md5str=getMd5(request);
     2329    char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
     2330    sprintf(fname,"%s/%s.zca",tmp->value,md5str);
     2331#ifdef DEBUG
     2332    fprintf(stderr,"Cache list : %s\n",fname);
     2333    fflush(stderr);
     2334#endif
     2335    FILE* fo=fopen(fname,"w+");
     2336    fwrite(content,sizeof(char),length,fo);
     2337    fclose(fo);
     2338    free(md5str);
     2339    free(fname);
     2340  }
     2341}
     2342
     2343char* isInCache(maps* conf,char* request){
     2344  map* tmpM=getMapFromMaps(conf,"main","cacheDir");
     2345  if(tmpM!=NULL){
     2346    unsigned char* md5str=getMd5(request);
     2347#ifdef DEBUG
     2348    fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
     2349#endif
     2350    char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+38));
     2351    sprintf(fname,"%s/%s.zca",tmpM->value,md5str);
     2352    struct stat f_status;
     2353    int s=stat(fname, &f_status);
     2354    if(s==0 && f_status.st_size>0){
     2355      free(md5str);
     2356      return fname;
     2357    }
     2358    free(md5str);
     2359    free(fname);
     2360  }
     2361  return NULL;
     2362}
     2363
     2364/**
     2365 * loadRemoteFile:
     2366 * Try to load file from cache or download a remote file if not in cache
     2367 */
     2368void loadRemoteFile(maps* m,map* content,HINTERNET hInternet,char *url){
     2369  HINTERNET res;
     2370  char* fcontent;
     2371  char* cached=isInCache(m,url);
     2372  int fsize;
     2373  if(cached!=NULL){
     2374    struct stat f_status;
     2375    int s=stat(cached, &f_status);
     2376    if(s==0){
     2377      fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
     2378      FILE* f=fopen(cached,"r");
     2379      fread(fcontent,sizeof(char),f_status.st_size,f);
     2380      fsize=f_status.st_size;
     2381    }
     2382  }else{
     2383    res=InternetOpenUrl(hInternet,url,NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
     2384    fcontent=(char*)calloc((res.nDataLen+1),sizeof(char));
     2385    if(fcontent == NULL){
     2386      return errorException(m, _("Unable to allocate memory."), "InternalError");
     2387    }
     2388    size_t dwRead;
     2389    InternetReadFile(res, (LPVOID)fcontent, res.nDataLen, &dwRead);
     2390    fcontent[res.nDataLen]=0;
     2391    fsize=res.nDataLen;
     2392  }
     2393  map* tmpMap=getMapOrFill(content,"value","");
     2394  free(tmpMap->value);
     2395  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
     2396  memcpy(tmpMap->value,fcontent,(fsize)*sizeof(char));
     2397  char ltmp1[256];
     2398  sprintf(ltmp1,"%d",fsize);
     2399  addToMap(content,"size",ltmp1);
     2400  if(cached==NULL)
     2401    addToCache(m,url,fcontent,fsize);
     2402  free(fcontent);
     2403  free(cached);
     2404}
     2405
     2406int errorException(maps *m, const char *message, const char *errorcode)
     2407{
     2408  map* errormap = createMap("text", message);
     2409  addToMap(errormap,"code", errorcode);
     2410  printExceptionReportResponse(m,errormap);
     2411  freeMap(&errormap);
     2412  free(errormap);
     2413  return -1;
     2414}
  • branches/branch-1.2/zoo-kernel/service_internal.h

    r268 r301  
    5353#include "service.h"
    5454#include <openssl/sha.h>
     55#include <openssl/md5.h>
    5556#include <openssl/hmac.h>
    5657#include <openssl/evp.h>
     
    5960
    6061#include "cgic.h"
     62#include "ulinet.h"
    6163
    6264extern   int getServiceFromFile(const char*,service**);
     
    7274#endif
    7375#include <libxml/parser.h>
     76#include <libxml/xpath.h>
     77
    7478  static char* SERVICE_URL;
    75   static xmlNsPtr usedNs[5];
    76   static char* nsName[5];
     79  static xmlNsPtr usedNs[10];
     80  static char* nsName[10];
    7781  static int nbNs=0;
    7882
     
    8387#ifdef USE_JS
    8488  char* JSValToChar(JSContext*,jsval*);
    85   JSBool JSUpdateStatus(JSContext*,JSObject*,uintN,jsval *,jsval *);
     89  JSBool JSUpdateStatus(JSContext*,uintN,jsval *);
    8690#endif
    8791 
     
    118122  char* addDefaultValues(maps**,elements*,maps*,int);
    119123
    120   /*defined in zoo_loader.c*/
    121124  int errorException(maps *m, const char *message, const char *errorcode);
    122125
     126  int checkForSoapEnvelope(xmlDocPtr);
     127
     128  void addToCache(maps*,char*,char*,int);
     129  char* isInCache(maps*,char*);
     130  void loadRemoteFile(maps*,map*,HINTERNET,char*);
     131 
    123132#ifdef __cplusplus
    124133}
  • branches/branch-1.2/zoo-kernel/service_internal_js.c

    r42 r301  
    2727static char dbg[1024];
    2828
     29JSBool
     30JSAlert(JSContext *cx, uintN argc, jsval *argv1)
     31{
     32  jsval *argv = JS_ARGV(cx,argv1);
     33  int i=0;
     34  JS_MaybeGC(cx);
     35  for(i=0;i<argc;i++){
     36    JSString* jsmsg = JS_ValueToString(cx,argv[i]);
     37    fprintf(stderr,"[ZOO-API:JS] %s\n",JS_EncodeString(cx,jsmsg));
     38  }
     39  JS_MaybeGC(cx);
     40 
     41  return JS_TRUE;
     42}
     43
    2944int zoo_js_support(maps** main_conf,map* request,service* s,
    3045                   maps **inputs,maps **outputs)
     
    5772    return 1;
    5873  }
    59   JS_SetOptions(cx, JSOPTION_VAROBJFIX);
     74  JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );//| JSOPTION_METHODJIT);
    6075  JS_SetVersion(cx, JSVERSION_LATEST);
    6176  JS_SetErrorReporter(cx, reportError);
    6277
    6378  /* Create the global object. */
    64   global = JS_NewObject(cx, &global_class, NULL, NULL);
    65   if (global == NULL){
    66     return 1;
    67   }
     79  //global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
     80  global = JS_NewObject(cx, &global_class, NULL,NULL);
    6881
    6982  /* Populate the global object with the standard globals,
     
    7285    return 1;
    7386  }
     87
    7488  if (!JS_DefineFunction(cx, global, "ZOORequest", JSRequest, 4, 0))
    7589    return 1;
    7690  if (!JS_DefineFunction(cx, global, "ZOOUpdateStatus", JSUpdateStatus, 2, 0))
     91    return 1;
     92  if (!JS_DefineFunction(cx, global, "alert", JSAlert, 2, 0))
    7793    return 1;
    7894
     
    86102  char api0[strlen(tmpm1->value)+strlen(ntmp)+15];
    87103  sprintf(api0,"%s/%sZOO-proj4js.js",ntmp,tmpm1->value);
     104#ifdef JS_DEBUG
    88105  fprintf(stderr,"Trying to load %s\n",api0);
    89   JSScript *api_script1=loadZooApiFile(cx,global,api0);
     106#endif
     107  JSObject *api_script1=loadZooApiFile(cx,global,api0);
    90108  fflush(stderr);
    91109
    92110  char api1[strlen(tmpm1->value)+strlen(ntmp)+11];
    93111  sprintf(api1,"%s/%sZOO-api.js",ntmp,tmpm1->value);
     112#ifdef JS_DEBUG
    94113  fprintf(stderr,"Trying to load %s\n",api1);
    95   JSScript *api_script2=loadZooApiFile(cx,global,api1);
     114#endif
     115  JSObject *api_script2=loadZooApiFile(cx,global,api1);
    96116  fflush(stderr);
    97117
     
    106126  sprintf(filename,"%s/%s%s",ntmp,tmpm1->value,tmpm2->value);
    107127  filename[strlen(tmpm1->value)+strlen(tmpm2->value)+strlen(ntmp)+1]=0;
     128#ifdef JS_DEBUG
    108129  fprintf(stderr,"FILENAME %s\n",filename);
     130#endif
    109131  struct stat file_status;
    110132  stat(filename, &file_status);
     
    112134  uint16 lineno;
    113135  jsval rval;
    114   FILE *jsfile=fopen(filename,"r");
    115136  JSBool ok ;
    116   JSScript *script = JS_CompileFileHandle(cx, global, filename,jsfile);
     137  JSObject *script = JS_CompileFile(cx, global, filename);
    117138  if(script!=NULL){
    118139    (void)JS_ExecuteScript(cx, global, script, &rval);
     
    127148    JS_DestroyRuntime(rt);
    128149    JS_ShutDown();
    129     fclose(jsfile);
    130150    exit(-1);
    131151  }
     
    161181    if(strlen(dbg)==0)
    162182      sprintf(dbg,"No result was found after the function call");
    163     sprintf(tmp1,"Unable to run %s from the JavScript file %s : \n %s",s->name,filename,dbg);
     183    sprintf(tmp1,"Unable to run %s from the JavaScript file %s : \n %s",s->name,filename,dbg);
     184#ifdef JS_DEBUG
    164185    fprintf(stderr,"%s",tmp1);
     186#endif
    165187    map* err=createMap("text",tmp1);
    166188    addToMap(err,"code","NoApplicableCode");
     
    211233    jsval tmp2;
    212234    JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2);
     235#ifdef JS_DEBUG
    213236    if(!hasElement)
    214237      fprintf(stderr,"No outputs property returned\n");
     
    217240    else
    218241      fprintf(stderr,"outputs is not an array as expected\n");
     242#endif
    219243    *outputs=mapsFromJSObject(cx,tmp2);
    220244#ifdef JS_DEBUG
    221     dumpMaps(out);
     245    dumpMaps(outputs);
    222246#endif
    223247  }
    224248
    225249  /* Cleanup. */
    226   JS_DestroyScript(cx, script);
    227   JS_DestroyScript(cx, api_script1);
    228   JS_DestroyScript(cx, api_script2);
    229   //JS_MaybeGC(cx);
    230   // If we use the DestroyContext as requested to release memory then we get
    231   // issue getting back the main configuration maps after coming back to the
    232   // runRequest function ...
    233   //JS_DestroyContext(cx);
     250  JS_DestroyContext(cx);
    234251  JS_DestroyRuntime(rt);
    235252  JS_ShutDown();
     
    240257}
    241258
    242 JSScript * loadZooApiFile(JSContext *cx,JSObject  *global, char* filename){
     259JSObject * loadZooApiFile(JSContext *cx,JSObject  *global, char* filename){
    243260  struct stat api_status;
    244261  int s=stat(filename, &api_status);
    245262  if(s==0){
    246263    jsval rval;
    247     FILE *jsfile=fopen(filename,"r");
    248264    JSBool ok ;
    249     JSScript *script = JS_CompileFileHandle(cx, global, filename,jsfile);
     265    JSObject *script = JS_CompileFile(cx, JS_GetGlobalObject(cx), filename);
    250266    if(script!=NULL){
    251       (void)JS_ExecuteScript(cx, global, script, &rval);
     267      (void)JS_ExecuteScript(cx, JS_GetGlobalObject(cx), script, &rval);
     268#ifdef JS_DEBUG
    252269      fprintf(stderr,"**************\n%s correctly loaded\n**************\n",filename);
     270#endif
    253271      return script;
    254272    }
     273#ifdef JS_DEBUG
    255274    else
    256275      fprintf(stderr,"\n**************\nUnable to run %s\n**************\n",filename);
    257   }
     276#endif
     277  }
     278#ifdef JS_DEBUG
    258279  else
    259280    fprintf(stderr,"\n**************\nUnable to load %s\n**************\n",filename);
     281#endif
    260282  return NULL;
    261283}
     
    288310  map* tmpm=t;
    289311  while(tmpm!=NULL){
    290     jsval jsstr = STRING_TO_JSVAL(JS_NewString(cx,tmpm->value,strlen(tmpm->value)));
     312    jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm->value,strlen(tmpm->value)));
    291313    JS_SetProperty(cx, res, tmpm->name,&jsstr);
    292314#ifdef JS_DEBUG
     
    335357      fprintf(stderr,"Properties length :  %d \n",idp->length);
    336358#endif
     359      tres=(maps*)malloc(MAPS_SIZE);
     360      tres->name=NULL;
     361      tres->content=NULL;
     362      tres->next=NULL;
     363
    337364      for (index=0,argNum=idp->length;index<argNum;index++) {
    338365        jsval id = idp->vector[index];
     
    346373        len1 = JS_GetStringLength(jsmsg);
    347374#ifdef JS_DEBUG
    348         fprintf(stderr,"Enumerate id : %d => %s\n",oi,JS_GetStringBytes(jsmsg));
     375        fprintf(stderr,"Enumerate id : %d => %s\n",oi,JS_EncodeString(cx,jsmsg));
    349376#endif
    350377        jsval nvp=JSVAL_NULL;
    351         if((JS_GetProperty(cx, JSVAL_TO_OBJECT(tmp1), JS_GetStringBytes(jsmsg), &nvp)==JS_FALSE))
    352 #ifdef JS_DEBUG
    353         fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,JS_GetStringBytes(jsmsg));
    354 #endif
     378        if((JS_GetProperty(cx, JSVAL_TO_OBJECT(tmp1), JS_EncodeString(cx,jsmsg), &nvp)==JS_FALSE)){
     379#ifdef JS_DEBUG
     380          fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,JS_EncodeString(cx,jsmsg));
     381#endif
     382        }
     383       
    355384        if(JSVAL_IS_OBJECT(nvp)){
    356385#ifdef JS_DEBUG
     
    358387#endif
    359388        }
    360 #ifdef JS_DEBUG
    361         else
    362           fprintf(stderr,"JSVAL NVP IS NOT OBJECT !!\n");
    363 #endif
    364         JSObject *nvp1;
     389
     390        JSObject *nvp1=JSVAL_NULL;
    365391        JS_ValueToObject(cx,nvp,&nvp1);
    366392        jsval nvp1j=OBJECT_TO_JSVAL(nvp1);
    367393        if(JSVAL_IS_OBJECT(nvp1j)){
    368 #ifdef JS_DEBUG
    369           fprintf(stderr,"JSVAL NVP1J IS OBJECT\n");
    370 #endif
    371           tres=(maps*)malloc(MAPS_SIZE);
    372           tres->name=strdup(JS_GetStringBytes(jsmsg));
    373           tres->content=mapFromJSObject(cx,nvp1j);
    374           tres->next=NULL;
    375 #ifdef JS_DEBUG
    376           dumpMaps(res);
    377 #endif
    378           if(res==NULL)
    379             res=dupMaps(&tres);
     394          JSString *jsmsg1;
     395          JSObject *nvp2=JSVAL_NULL;
     396          jsmsg1 = JS_ValueToString(cx,nvp1j);
     397          len1 = JS_GetStringLength(jsmsg1);
     398#ifdef JS_DEBUG
     399          fprintf(stderr,"JSVAL NVP1J IS OBJECT %s = %s\n",JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
     400#endif
     401          if(strcasecmp(JS_EncodeString(cx,jsmsg1),"[object Object]")==0){
     402            tres->name=strdup(JS_EncodeString(cx,jsmsg));
     403            tres->content=mapFromJSObject(cx,nvp1j);
     404          }
    380405          else
    381             addMapsToMaps(&res,tres);
    382           freeMaps(&tres);
    383           free(tres);
    384           tres=NULL;
    385 #ifdef JS_DEBUG
    386           dumpMaps(res);
    387 #endif
     406            if(strcasecmp(JS_EncodeString(cx,jsmsg),"name")==0){
     407              tres->name=strdup(JS_EncodeString(cx,jsmsg1));
     408            }
     409            else{
     410              if(tres->content==NULL)
     411                tres->content=createMap(JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
     412              else
     413                addToMap(tres->content,JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
     414            }
    388415        }
    389416#ifdef JS_DEBUG
     
    391418          fprintf(stderr,"JSVAL NVP1J IS NOT OBJECT !!\n");
    392419#endif
     420
    393421      }
     422#ifdef JS_DEBUG
     423      dumpMaps(tres);
     424#endif
     425      if(res==NULL)
     426        res=dupMaps(&tres);
     427      else
     428        addMapsToMaps(&res,tres);
     429      freeMaps(&tres);
     430      free(tres);
     431      tres=NULL;
     432
    394433    }
    395434  }
     
    423462      len = JS_GetStringLength(jsmsg);
    424463      jsval nvp;
    425       JS_GetProperty(cx, JSVAL_TO_OBJECT(t), JS_GetStringBytes(jsmsg), &nvp);
     464      JS_GetProperty(cx, JSVAL_TO_OBJECT(t), JS_EncodeString(cx,jsmsg), &nvp);
    426465      jsmsg1 = JS_ValueToString(cx,nvp);
    427466      len1 = JS_GetStringLength(jsmsg1);
    428467#ifdef JS_DEBUG
    429       fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
     468      fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
    430469#endif
    431470      if(res!=NULL){
    432471#ifdef JS_DEBUG
    433         fprintf(stderr,"%s - %s\n",JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
    434 #endif
    435         addToMap(res,JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
     472        fprintf(stderr,"%s - %s\n",JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
     473#endif
     474        addToMap(res,JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
    436475      }
    437476      else{
    438         res=createMap(JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
     477        res=createMap(JS_EncodeString(cx,jsmsg),JS_EncodeString(cx,jsmsg1));
    439478        res->next=NULL;
    440479      }
  • branches/branch-1.2/zoo-kernel/service_internal_js.h

    r42 r301  
    5252  int zoo_js_support(maps**,map*,service*,maps **,maps **);
    5353
    54   JSScript *loadZooApiFile(JSContext*,JSObject*,char*);
     54  JSObject *loadZooApiFile(JSContext*,JSObject*,char*);
    5555
    5656#ifdef __cplusplus
  • branches/branch-1.2/zoo-kernel/service_internal_python.c

    r217 r301  
    7474  free(pythonpath);
    7575
     76  PyThreadState *mainstate;
     77  PyEval_InitThreads();
    7678  Py_Initialize();
     79  mainstate = PyThreadState_Swap(NULL);
     80  PyEval_ReleaseLock();
     81  PyGILState_STATE gstate;
     82  gstate = PyGILState_Ensure();
    7783  PyObject *pName, *pModule, *pFunc;
    7884  tmp=getMap(s->content,"serviceProvider");
     
    119125        dumpMaps(outputs);
    120126#endif
    121         Py_DECREF(arg1);
    122         Py_DECREF(arg2);
    123         Py_DECREF(arg3);
    124         Py_DECREF(pArgs);
    125         Py_DECREF(pValue);
    126         Py_XDECREF(pFunc);
    127         Py_DECREF(pModule);
    128127      }else{     
    129128        PyObject *ptype,*pvalue, *ptraceback;
     
    159158        addToMap(err,"code","NoApplicableCode");
    160159        printExceptionReportResponse(m,err);
    161         Py_DECREF(arg1);
    162         Py_DECREF(arg2);
    163         Py_DECREF(arg3);
    164         Py_XDECREF(pFunc);
    165         Py_DECREF(pArgs);
    166         Py_DECREF(pModule);
    167         Py_DECREF(ptraceback);
    168         Py_DECREF(ptype);
    169         Py_DECREF(pValue);
    170 #if not(defined(macintosh)) && not(defined(__MACH__) && defined(__APPLE__))
    171         Py_Finalize();
    172 #endif
    173         exit(-1);
     160        res=-1;
    174161      }
    175162    }
    176163    else{
    177164      char tmpS[1024];
    178       sprintf(tmpS, "Cannot find the %s function int the %s file.\n", s->name, tmp->value);
     165      sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value);
    179166      map* tmps=createMap("text",tmpS);
    180167      printExceptionReportResponse(m,tmps);
    181       Py_XDECREF(pFunc);
    182       Py_DECREF(pModule);
    183       exit(-1);
     168      res=-1;
    184169    }
    185170  } else{
     
    190175    if (PyErr_Occurred())
    191176      PyErr_Print();
    192     exit(-1);
     177    PyErr_Clear();
     178    res=-1;
     179    //exit(-1);
    193180  }
    194 #if not(defined(macintosh)) && not(defined(__MACH__) && defined(__APPLE__))
     181  PyGILState_Release(gstate);
     182  PyEval_AcquireLock();
     183  PyThreadState_Swap(mainstate);
    195184  Py_Finalize();
    196 #endif
    197185  return res;
    198186}
     
    202190  maps* tmp=t;
    203191  while(tmp!=NULL){
    204     PyObject* subc=(PyObject*)PyDict_FromMap(tmp->content);
    205     if(PyDict_SetItem(res,PyString_FromString(tmp->name),subc)<0){
    206       fprintf(stderr,"Unable to parse params...");
    207       exit(1);
    208     }
    209     Py_DECREF(subc);
     192    PyObject* value=(PyObject*)PyDict_FromMap(tmp->content);
     193    PyObject* name=PyString_FromString(tmp->name);
     194    if(PyDict_SetItem(res,name,value)<0){
     195      fprintf(stderr,"Unable to set map value ...");
     196      return NULL;
     197    }
     198    Py_DECREF(name);
    210199    tmp=tmp->next;
    211200  } 
     
    223212        PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value));
    224213        if(PyDict_SetItem(res,name,value)<0){
    225           fprintf(stderr,"Unable to parse params...");
    226           Py_DECREF(value);
    227           exit(1);
     214          fprintf(stderr,"Unable to set key value pair...");
     215          return NULL;
    228216        }
    229         Py_DECREF(value);
    230217      }
    231218      else{
    232219        PyObject* value=PyString_FromString(tmp->value);
    233220        if(PyDict_SetItem(res,name,value)<0){
    234           fprintf(stderr,"Unable to parse params...");
    235           Py_DECREF(value);
    236           exit(1);
     221          fprintf(stderr,"Unable to set key value pair...");
     222          return NULL;
    237223        }
    238         Py_DECREF(value);
    239224      }
    240225    }
     
    242227      PyObject* value=PyString_FromString(tmp->value);
    243228      if(PyDict_SetItem(res,name,value)<0){
    244         fprintf(stderr,"Unable to parse params...");
    245         Py_DECREF(value);
    246         exit(1);
    247       }
    248       Py_DECREF(value);
     229        fprintf(stderr,"Unable to set key value pair...");
     230        return NULL;
     231      }
    249232    }
    250233    Py_DECREF(name);
     
    272255    cursor=(maps*)malloc(MAPS_SIZE);
    273256    cursor->name=PyString_AsString(key);
    274 #ifdef DEBUG
    275     dumpMap(mapFromPyDict((PyDictObject*)value));
    276 #endif
    277257    cursor->content=mapFromPyDict((PyDictObject*)value);
     258#ifdef DEBUG
     259    dumpMap(cursor->content);
     260#endif
    278261    cursor->next=NULL;
    279262    if(res==NULL)
     
    284267    free(cursor->content);
    285268    free(cursor);
    286     Py_DECREF(value);
    287     Py_DECREF(key);
    288269#ifdef DEBUG
    289270    dumpMaps(res);
     
    291272#endif
    292273  }
    293   Py_DECREF(list);
    294274  return res;
    295275}
     
    330310        res=createMap(PyString_AsString(key),PyString_AsString(value));
    331311    }
    332     Py_DECREF(key);
    333   }
    334   Py_DECREF(list);
     312  }
    335313  return res;
    336314}
  • branches/branch-1.2/zoo-kernel/ulinet.c

    r93 r301  
    385385  jsmsg = JS_ValueToString(context,*arg);
    386386  len = JS_GetStringLength(jsmsg);
    387   tmp = JS_GetStringBytes(jsmsg);
     387  tmp = JS_EncodeString(context,jsmsg);
    388388  c = (char*)malloc((len+1)*sizeof(char));
    389389  c[len] = '\0';
     
    435435
    436436JSBool
    437 JSRequest(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
     437JSRequest(JSContext *cx, uintN argc, jsval *argv1)
    438438{
     439  jsval *argv = JS_ARGV(cx,argv1);
    439440  HINTERNET hInternet;
    440441  char *url;
     
    488489  fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);
    489490#endif
    490   *rval=STRING_TO_JSVAL(JS_NewString(cx,tmpValue,strlen(tmpValue)));
     491  JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue))));
    491492  free(url);
    492493  if(argc>=2)
  • branches/branch-1.2/zoo-kernel/ulinet.h

    r1 r301  
    138138
    139139#ifdef USE_JS
    140 JSBool JSRequest(JSContext*, JSObject*, uintN, jsval*, jsval*);
     140JSBool JSRequest(JSContext*, uintN, jsval*);
    141141#endif
    142142
  • branches/branch-1.2/zoo-kernel/zoo_loader.c

    r217 r301  
    4848}
    4949
     50#include "service_internal.h"
     51
    5052xmlXPathObjectPtr extractFromDoc(xmlDocPtr,const char*);
    5153int runRequest(map*);
    5254
    5355using namespace std;
    54 
    55 /* ************************************************************************* */
    56 
    57 int errorException(maps *m, const char *message, const char *errorcode)
    58 {
    59   map* errormap = createMap("text", message);
    60   addToMap(errormap,"code", errorcode);
    61   printExceptionReportResponse(m,errormap);
    62   freeMap(&errormap);
    63   free(errormap);
    64   return -1;
    65 }
    66 
    67 /* ************************************************************************* */
    68 
    6956
    7057#define TRUE 1
     
    8572#ifdef DEBUG
    8673  fprintf (stderr, "Addr:%s\n", cgiRemoteAddr);
    87   fprintf (stderr, "RequestMethod:%s\n", cgiRequestMethod);
     74  fprintf (stderr, "RequestMethod: (%s) %d %d\n", cgiRequestMethod,strncasecmp(cgiRequestMethod,"post",4),strncmp(cgiContentType,"text/xml",8)==0 || strncasecmp(cgiRequestMethod,"post",4)==0);
    8875  fprintf (stderr, "Request: %s\n", cgiQueryString);
    8976#endif
     
    9380  if(strncmp(cgiContentType,"text/xml",8)==0 ||
    9481     strncasecmp(cgiRequestMethod,"post",4)==0){
    95     char *buffer=new char[cgiContentLength+1];
    96     if(fread(buffer,1,cgiContentLength,cgiIn)){
    97       buffer[cgiContentLength]=0;
    98       tmpMap=createMap("request",buffer);
     82    if(cgiContentLength==NULL){
     83       cgiContentLength=0;
     84       char *buffer=new char[2];
     85       char *res=NULL;
     86       int r=0;
     87       while(r=fread(buffer,sizeof(char),1,cgiIn)){
     88         cgiContentLength+=r;
     89         if(res==NULL){
     90           res=(char*)malloc(1*sizeof(char));
     91           sprintf(res,"%s",buffer);
     92         }
     93         else{
     94           res=(char*)realloc(res,(cgiContentLength+1)*sizeof(char));
     95           char *tmp=strdup(res);
     96           sprintf(res,"%s%s",tmp,buffer);
     97           free(tmp);
     98         }
     99       }
     100       if(res==NULL){
     101         return errorException(NULL,"ZOO-Kernel failed to process your request cause the request was emtpty.","InternalError");
     102       }else
     103         tmpMap=createMap("request",res);
    99104    }else{
    100       char **array, **arrayStep;
    101       if (cgiFormEntries(&array) != cgiFormSuccess) {
    102         return 1;
    103       }
    104       arrayStep = array;
    105       while (*arrayStep) {
    106         char *value=new char[cgiContentLength];
    107         cgiFormStringNoNewlines(*arrayStep, value, cgiContentLength);
    108         char* tmpValueFinal=(char*) malloc((strlen(*arrayStep)+strlen(value)+1)*sizeof(char));
    109         sprintf(tmpValueFinal,"%s=%s",*arrayStep,value);
    110         tmpMap=createMap("request",tmpValueFinal);
    111         free(tmpValueFinal);
    112 #ifdef DEBUG
    113         fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
    114 #endif
    115         delete[]value;
    116         arrayStep++;
    117       }
    118     }
    119     delete[]buffer;
     105      char *buffer=new char[cgiContentLength+1];
     106      if(fread(buffer,sizeof(char),cgiContentLength,cgiIn)){
     107        buffer[cgiContentLength]=0;
     108        tmpMap=createMap("request",buffer);
     109      }else{
     110        buffer[0]=0;
     111        char **array, **arrayStep;
     112        if (cgiFormEntries(&array) != cgiFormSuccess) {
     113          return 1;
     114        }
     115        arrayStep = array;
     116        while (*arrayStep) {
     117          char *ivalue=new char[cgiContentLength];
     118          cgiFormStringNoNewlines(*arrayStep, ivalue, cgiContentLength);
     119          char* tmpValueFinal=(char*) malloc((strlen(*arrayStep)+strlen(ivalue)+1)*sizeof(char));
     120          sprintf(tmpValueFinal,"%s=%s",*arrayStep,ivalue);
     121          if(strlen(buffer)==0){
     122            sprintf(buffer,"%s",tmpValueFinal);
     123          }else{
     124            char *tmp=strdup(buffer);
     125            sprintf(buffer,"%s&%s",tmp,tmpValueFinal);
     126            free(tmp);
     127          }
     128         
     129          sprintf(tmpValueFinal,"%s=%s",*arrayStep,ivalue);
     130          free(tmpValueFinal);
     131#ifdef DEBUG
     132          fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,ivalue);
     133#endif
     134          delete[]ivalue;
     135          arrayStep++;
     136        }
     137        tmpMap=createMap("request",buffer);
     138      }
     139      delete[]buffer;
     140    }
    120141  }
    121142  else{
     
    162183      xmlInitParser();
    163184      xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);
     185
     186
     187      {
     188        xmlXPathObjectPtr reqptr=extractFromDoc(doc,"/*[local-name()='Envelope']/*[local-name()='Body']/*");
     189        if(reqptr!=NULL){
     190          xmlNodeSet* req=reqptr->nodesetval;
     191          if(req!=NULL && req->nodeNr==1){
     192            addToMap(tmpMap,"soap","true");
     193            int k=0;
     194            for(k;k < req->nodeNr;k++){
     195              xmlNsPtr ns=xmlNewNs(req->nodeTab[k],BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
     196              xmlDocSetRootElement(doc, req->nodeTab[k]);
     197              xmlChar *xmlbuff;
     198              int buffersize;
     199              xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "utf-8", 1);
     200              addToMap(tmpMap,"xrequest",(char*)xmlbuff);
     201              char *tmp=(char*)xmlbuff;
     202              fprintf(stderr,"%s\n",tmp);
     203              xmlFree(xmlbuff);
     204            }
     205          }
     206        }
     207      }
     208
    164209      xmlNodePtr cur = xmlDocGetRootElement(doc);
    165210      char *tval;
     
    172217      if(tval!=NULL)
    173218        addToMap(tmpMap,"language",tval);
    174      
    175       const char* requests[3];
    176       requests[0]="GetCapabilities";
    177       requests[1]="DescribeProcess";
    178       requests[2]="Execute";
     219      const char* requests[3]={"GetCapabilities","DescribeProcess","Execute"};
    179220      for(int j=0;j<3;j++){
    180         char tt[35];
     221        char tt[128];
    181222        sprintf(tt,"/*[local-name()='%s']",requests[j]);
    182223        xmlXPathObjectPtr reqptr=extractFromDoc(doc,tt);
  • branches/branch-1.2/zoo-kernel/zoo_service_loader.c

    r268 r301  
    452452  _getcwd(ntmp,1024);
    453453#endif
    454   r_inputs=getMap(request_inputs,"metapath");
    455   if(r_inputs==NULL){
    456     if(request_inputs==NULL)
    457       request_inputs=createMap("metapath","");
    458     else
    459       addToMap(request_inputs,"metapath","");
    460 #ifdef DEBUG
    461     fprintf(stderr,"ADD METAPATH\n");
    462     dumpMap(request_inputs);
    463 #endif
    464     r_inputs=getMap(request_inputs,"metapath");
    465   }
     454  r_inputs=getMapOrFill(request_inputs,"metapath","");
     455
    466456  char conf_file[10240];
    467457  snprintf(conf_file,10240,"%s/%s/main.cfg",ntmp,r_inputs->value);
     
    493483  textdomain("zoo-services");
    494484
     485  map* lsoap=getMap(request_inputs,"soap");
     486  if(lsoap!=NULL && strcasecmp(lsoap->value,"true")==0)
     487    setMapInMaps(m,"main","isSoap","true");
     488  else
     489    setMapInMaps(m,"main","isSoap","false");
    495490
    496491  /**
     
    10131008            lmap->value=strdup(tmpValue);
    10141009            free(tmpValue);
    1015             dumpMap(tmpmaps->content);
    10161010            tmpc=strtok(NULL,"@");
    10171011            continue;
     
    10421036              fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);
    10431037#endif
     1038              char *tmpx=url_encode(tmpv1+1);
     1039              addToMap(tmpmaps->content,tmpn1,tmpx);
     1040             
    10441041#ifndef WIN32
    10451042              if(CHECK_INET_HANDLE(hInternet))
    10461043#endif
    10471044                {
    1048                   res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
    1049                                       INTERNET_FLAG_NO_CACHE_WRITE,0);
    1050 #ifdef DEBUG
    1051                   fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
    1052                           tmpv1+1,res.nDataAlloc,res.nDataLen);
    1053 #endif
    1054                   char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
    1055                   if(tmpContent == NULL){
    1056                     return errorException(m, _("Unable to allocate memory."), "InternalError");
    1057                   }
    1058                   size_t dwRead;
    1059                   InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
    1060                   map* tmpMap=getMap(tmpmaps->content,"value");
    1061                   if(tmpMap!=NULL){
    1062                     free(tmpMap->value);
    1063                     tmpMap->value=(char*)malloc((res.nDataLen+1)*sizeof(char));
    1064                     memmove(tmpMap->value,tmpContent,(res.nDataLen)*sizeof(char));
    1065                     tmpMap->value[res.nDataLen]=0;
    1066                     if(strlen(tmpContent)!=res.nDataLen){
    1067                       char tmp[256];
    1068                       sprintf(tmp,"%d",res.nDataLen*sizeof(char));
    1069                       addToMap(tmpmaps->content,"size",tmp);
    1070                     }
    1071                   }
    1072                   free(tmpContent);
     1045                  loadRemoteFile(m,tmpmaps->content,hInternet,tmpv1+1);
    10731046                }
    1074               char *tmpx=url_encode(tmpv1+1);
    1075               addToMap(tmpmaps->content,tmpn1,tmpx);
    1076               free(tmpx);
     1047              char *tmpx1=url_encode(tmpv1+1);
     1048              addToMap(tmpmaps->content,tmpn1,tmpx1);
     1049              free(tmpx1);
    10771050              addToMap(tmpmaps->content,"Reference",tmpv1+1);
    1078               dumpMap(tmpmaps->content);
    10791051            }
    10801052          tmpc=strtok(NULL,"@");
     
    11931165            fprintf(stderr,"REFERENCE\n");
    11941166#endif
    1195             const char *refs[5];
    1196             refs[0]="mimeType";
    1197             refs[1]="encoding";
    1198             refs[2]="schema";
    1199             refs[3]="method";
    1200             refs[4]="href";
     1167            const char *refs[5]={"mimeType","encoding","schema","method","href"};
    12011168            for(int l=0;l<5;l++){
    12021169#ifdef DEBUG
     
    12131180                  if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0)
    12141181                     && CHECK_INET_HANDLE(hInternet)){
    1215                     res=InternetOpenUrl(hInternet,(char*)val,NULL,0,
    1216                                         INTERNET_FLAG_NO_CACHE_WRITE,0);
    1217                     char* tmpContent=
    1218                       (char*)calloc((res.nDataLen+1),sizeof(char));
    1219                     if(tmpContent == NULL){
    1220                       return errorException(m, _("Unable to allocate memory."), "InternalError");
    1221                     }
    1222                     size_t dwRead;
    1223                     InternetReadFile(res, (LPVOID)tmpContent,
    1224                                      res.nDataLen, &dwRead);
    1225                     tmpContent[res.nDataLen]=0;
    1226                     addToMap(tmpmaps->content,"value",tmpContent);
     1182                    loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val);
    12271183                  }
    12281184                }
     
    14151371                    else
    14161372                      tmpmaps->content=createMap(list[l],(char*)val);
     1373#ifdef DEBUG
     1374                    fprintf(stderr,"%s\n",val);
     1375#endif
    14171376                  }
    1418 #ifdef DEBUG
    1419                   fprintf(stderr,"%s\n",val);
    1420 #endif
    14211377                  xmlFree(val);
    1422                   free(list[l]);
     1378                  free(list[l]);                 
    14231379                }
    14241380              }
     
    14281384                 * mimeType, encoding, schema
    14291385                 */
    1430                 const char *coms[3];
    1431                 coms[0]="mimeType";
    1432                 coms[1]="encoding";
    1433                 coms[2]="schema";
     1386                const char *coms[3]={"mimeType","encoding","schema"};
    14341387                for(int l=0;l<3;l++){
    14351388#ifdef DEBUG
    1436                   fprintf(stderr,"*** ComplexData %s ***",coms[l]);
     1389                  fprintf(stderr,"*** ComplexData %s ***\n",coms[l]);
    14371390#endif
    14381391                  xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]);
     
    14421395                    else
    14431396                      tmpmaps->content=createMap(coms[l],(char*)val);
     1397#ifdef DEBUG
     1398                    fprintf(stderr,"%s\n",val);
     1399#endif
    14441400                  }
    1445 #ifdef DEBUG
    1446                   fprintf(stderr,"%s\n",val);
    1447 #endif
    14481401                  xmlFree(val);
    14491402                }
    14501403              }
     1404
    14511405              map* test=getMap(tmpmaps->content,"encoding");
    1452               if(test==NULL || strcasecmp(test->value,"base64")!=0){
     1406              if(test==NULL){
     1407                if(tmpmaps->content!=NULL)
     1408                  addToMap(tmpmaps->content,"encoding","utf-8");
     1409                else
     1410                  tmpmaps->content=createMap("encoding","utf-8");
     1411                test=getMap(tmpmaps->content,"encoding");
     1412              }
     1413
     1414              if(strcasecmp(test->value,"base64")!=0){
    14531415                xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1);
    1454                 if(mv==NULL){
     1416                map* ltmp=getMap(tmpmaps->content,"mimeType");
     1417                if(mv==NULL ||
     1418                   (xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0 &&
     1419                    (ltmp==NULL || strncasecmp(ltmp->value,"text/xml",8)==0) )){
    14551420                  xmlDocPtr doc1=xmlNewDoc(BAD_CAST "1.0");
    14561421                  int buffersize;
    1457                   xmlDocSetRootElement(doc1,cur4->xmlChildrenNode);
     1422                  xmlNodePtr cur5=cur4->children;
     1423                  while(cur5!=NULL &&cur5->type!=XML_ELEMENT_NODE)
     1424                    cur5=cur5->next;
     1425                  xmlDocSetRootElement(doc1,cur5);
    14581426                  xmlDocDumpFormatMemoryEnc(doc1, &mv, &buffersize, "utf-8", 1);
    14591427                  char size[1024];
     
    15561524         * storeExecuteResponse, lineage, status
    15571525         */
    1558         const char *ress[3];
    1559         ress[0]="storeExecuteResponse";
    1560         ress[1]="lineage";
    1561         ress[2]="status";
     1526        const char *ress[3]={"storeExecuteResponse","lineage","status"};
    15621527        xmlChar *val;
    15631528        for(int l=0;l<3;l++){
     
    15801545        xmlNodePtr cur1=cur->children;
    15811546        while(cur1){
    1582           if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){
     1547          /**
     1548           * Indentifier
     1549           */
     1550          if(xmlStrncasecmp(cur1->name,BAD_CAST "Identifier",xmlStrlen(cur1->name))==0){
     1551            xmlChar *val=
     1552              xmlNodeListGetString(doc,cur1->xmlChildrenNode,1);
     1553            if(tmpmaps==NULL){
     1554              tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1555              if(tmpmaps == NULL){
     1556                return errorException(m, _("Unable to allocate memory."), "InternalError");
     1557              }
     1558              tmpmaps->name=strdup((char*)val);
     1559              tmpmaps->content=NULL;
     1560              tmpmaps->next=NULL;
     1561            }
     1562            else
     1563              tmpmaps->name=strdup((char*)val);;
     1564            xmlFree(val);
     1565          }
     1566          /**
     1567           * Title, Asbtract
     1568           */
     1569          else if(xmlStrncasecmp(cur1->name,BAD_CAST "Title",xmlStrlen(cur1->name))==0 ||
     1570                  xmlStrncasecmp(cur1->name,BAD_CAST "Abstract",xmlStrlen(cur1->name))==0){
     1571            xmlChar *val=
     1572              xmlNodeListGetString(doc,cur1->xmlChildrenNode,1);
     1573            if(tmpmaps==NULL){
     1574              tmpmaps=(maps*)calloc(1,MAPS_SIZE);
     1575              if(tmpmaps == NULL){
     1576                return errorException(m, _("Unable to allocate memory."), "InternalError");
     1577              }
     1578              tmpmaps->name=strdup("missingIndetifier");
     1579              tmpmaps->content=createMap((char*)cur1->name,(char*)val);
     1580              tmpmaps->next=NULL;
     1581            }
     1582            else{
     1583              if(tmpmaps->content!=NULL)
     1584                addToMap(tmpmaps->content,
     1585                         (char*)cur1->name,(char*)val);
     1586              else
     1587                tmpmaps->content=
     1588                  createMap((char*)cur1->name,(char*)val);
     1589            }
     1590            xmlFree(val);
     1591          }
     1592          else if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){
    15831593            /**
    15841594             * Get every attribute from a Output node
    15851595             * mimeType, encoding, schema, uom, asReference
    15861596             */
    1587             const char *outs[5];
    1588             outs[0]="mimeType";
    1589             outs[1]="encoding";
    1590             outs[2]="schema";
    1591             outs[3]="uom";
    1592             outs[4]="asReference";
     1597            const char *outs[5]={"mimeType","encoding","schema","uom","asReference"};
    15931598            for(int l=0;l<5;l++){
    15941599#ifdef DEBUG
     
    16321637               * Title, Asbtract
    16331638               */
    1634               if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
     1639              else if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
    16351640                 xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
    16361641                xmlChar *val=
     
    16841689  dumpMaps(request_output_real_format);
    16851690  dumpMap(request_inputs);
     1691  fprintf(stderr,"\n%i\n",i);
    16861692#endif
    16871693
     
    16911697   */
    16921698  char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,0);
    1693   if(strcmp(dfv,"")!=0){
     1699  char *dfv1=addDefaultValues(&request_output_real_format,s1->outputs,m,1);
     1700  if(strcmp(dfv1,"")!=0 || strcmp(dfv,"")!=0){
    16941701    char tmps[1024];
    1695     snprintf(tmps,1024,_("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."),dfv);
     1702    if(strcmp(dfv,"")!=0){
     1703      snprintf(tmps,1024,_("The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file."),dfv);
     1704    }
     1705    else if(strcmp(dfv1,"")!=0){
     1706      snprintf(tmps,1024,_("The <%s> argument was specified as Output identifier but not defined in the ZOO Configuration File. Please, correct your query or the ZOO Configuration File."),dfv1);
     1707    }
    16961708    map* tmpe=createMap("text",tmps);
    16971709    addToMap(tmpe,"code","MissingParameterValue");
     
    17131725    return 1;
    17141726  }
    1715   addDefaultValues(&request_output_real_format,s1->outputs,m,1);
    17161727
    17171728  ensureDecodedBase64(&request_input_real_format);
     
    18071818  addToMap(_tmpMaps->content,"status","0");
    18081819  addToMap(_tmpMaps->content,"cwd",ntmp);
     1820  map* ltmp=getMap(request_inputs,"soap");
     1821  if(ltmp!=NULL)
     1822    addToMap(_tmpMaps->content,"soap",ltmp->value);
     1823  else
     1824    addToMap(_tmpMaps->content,"soap","false");
    18091825  if(cgiCookie!=NULL && strlen(cgiCookie)>0){
    18101826    addToMap(_tmpMaps->content,"sessid",strstr(cgiCookie,"=")+1);
     
    18241840    if(istat==0 && file_status.st_size>0){
    18251841      conf_read(session_file_path,tmpSess);
    1826       dumpMaps(tmpSess);
    18271842      addMapsToMaps(&m,tmpSess);
    18281843      freeMaps(&tmpSess);
     
    18491864    addToMap(request_inputs,"status","true");
    18501865    status=getMap(request_inputs,"status");
    1851     dumpMap(request_inputs);
    18521866    fprintf(stderr,"cgiSID : %s",cgiSid);
    18531867  }
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