Ignore:
Timestamp:
Jan 8, 2013, 3:54:57 PM (12 years ago)
Author:
djay
Message:

Fix issue in JS support and for binary RawDataOutput?. Add Content-Length and Content-Disposition (optional) to response header. Add support to JS ZOO-API for sending headers and handling multi-valued inputs.

File:
1 edited

Legend:

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

    r377 r383  
    2525#include "service_internal.h"
    2626
     27#ifndef JSCLASS_GLOBAL_FLAGS
     28#define JSCLSAS_GLOBAL_FLAGS 0
     29#endif
     30
    2731static char dbg[1024];
    2832
     
    8185
    8286  /* The class of the global object. */
    83   JSClass global_class = {
     87  JSClass global_class= {
    8488    "global", JSCLASS_GLOBAL_FLAGS,
    8589    JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
     
    99103 
    100104  /* Create a context. */
    101   cx = JS_NewContext(rt,8192);
     105  cx = JS_NewContext(rt,81920);
    102106  if (cx == NULL){
    103107    return 1;
    104108  }
    105   JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );//| JSOPTION_METHODJIT);
     109  JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT);
    106110  JS_SetVersion(cx, JSVERSION_LATEST);
    107111  JS_SetErrorReporter(cx, reportError);
     
    111115  global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
    112116  //#else
    113   //global = JS_NewObject(cx, &global_class, NULL,NULL);
     117  //global = JS_NewObject(cx, &global_class, 0,0);
    114118  //#endif
    115119
     
    150154   * Load the first part of the ZOO-API
    151155   */
    152   char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+16);
     156  char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+17);
    153157  sprintf(api0,"%s/%s/ZOO-proj4js.js",ntmp,tmpm1->value);
    154158#ifdef JS_DEBUG
     
    158162  fflush(stderr);
    159163
    160   char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+11);
     164  char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+13);
    161165  sprintf(api1,"%s/%s/ZOO-api.js",ntmp,tmpm1->value);
    162166#ifdef JS_DEBUG
     
    200204    exit(-1);
    201205  }
     206
    202207  /* Call a function in obj's scope. */
    203208  jsval argv[3];
     
    264269    fprintf(stderr," * %d * \n",res);
    265270#endif
    266     jsval tmp2;
    267     JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
    268     if(hasElement==JS_TRUE){
    269           freeMaps(outputs);
    270           free(*outputs);
    271       *outputs=mapsFromJSObject(cx,tmp2);
    272     }
     271    if(res==SERVICE_SUCCEEDED){
     272      jsval tmp2;
     273      JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
     274      if(hasElement==JS_TRUE){
     275        freeMaps(outputs);
     276        free(*outputs);
     277        *outputs=mapsFromJSObject(cx,tmp2);
     278      }
     279    }else{
     280      jsval tmp3;
     281      JSBool hasConf=JS_GetElement(cx,d,1,&tmp3);
     282      if(hasConf==JS_TRUE){
     283        freeMaps(main_conf);
     284        free(*main_conf);
     285        *main_conf=mapsFromJSObject(cx,tmp3);
     286      }
     287    }
     288
    273289  }
    274290  else{
    275291#ifdef JS_DEBUG
    276     fprintf(stderr,"The serice didn't return an array !\n");
    277 #endif
     292    fprintf(stderr,"The service didn't return an array !\n");
     293#endif
     294    /**
     295     * Extract result
     296     */
    278297    jsval tmp1;
    279298    JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1);
     
    283302    fprintf(stderr," * %d * \n",res);
    284303#endif
     304    /**
     305     * Extract outputs when available.
     306     */
    285307    jsval tmp2;
    286308    JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2);
    287 #ifdef JS_DEBUG
    288     if(!hasElement)
     309    if(!JSVAL_IS_VOID(tmp2) && hasElement==JS_TRUE){
     310      freeMaps(outputs);
     311      free(*outputs);   
     312      *outputs=mapsFromJSObject(cx,tmp2);
     313    }
     314    JS_MaybeGC(cx);
     315#ifdef JS_DEBUG
     316    if(JSVAL_IS_VOID(tmp2))
    289317      fprintf(stderr,"No outputs property returned\n");
    290     if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
    291       fprintf(stderr,"outputs is array an as expected\n");
    292     else
    293       fprintf(stderr,"outputs is not an array as expected\n");
    294 #endif
    295     *outputs=mapsFromJSObject(cx,tmp2);
     318    else{
     319      if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
     320        fprintf(stderr,"outputs is an array as expected\n");
     321      else
     322        fprintf(stderr,"outputs is not an array as expected\n");
     323    }
     324    JS_MaybeGC(cx);
     325#endif
     326
     327    /**
     328     * Extract conf when available.
     329     */
     330    jsval tmp3;
     331    JSBool hasConf=JS_GetProperty(cx,d,"conf",&tmp3);
     332    if(!JSVAL_IS_VOID(tmp3) && hasConf==JS_TRUE){
     333      freeMaps(main_conf);
     334      free(*main_conf);
     335      *main_conf=mapsFromJSObject(cx,tmp3);
     336    }
     337    JS_MaybeGC(cx);
     338
    296339#ifdef JS_DEBUG
    297340    dumpMaps(*outputs);
     
    299342  }
    300343  /* Cleanup. */
     344  JS_MaybeGC(cx);
    301345  JS_DestroyContext(cx);
    302346  JS_DestroyRuntime(rt);
     
    479523  jsuint len;
    480524  JSBool hasLen=JS_GetArrayLength(cx, tt, &len);
     525#ifdef JS_DEBUG
    481526  if(hasLen==JS_FALSE){
    482 #ifdef JS_DEBUG
    483527    fprintf(stderr,"outputs array is empty\n");
    484 #endif
    485   }
    486 #ifdef JS_DEBUG
     528  }
    487529  fprintf(stderr,"outputs array length : %d\n",len);
    488530#endif
     
    694736      tmp1=JSValToChar(cx,&tmp);
    695737#ifdef ULINET_DEBUG
     738      curl_easy_setopt(handle.handle,CURLOPT_VERBOSE,1);
    696739      fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1);
    697740#endif
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