Changeset 383 for trunk/zoo-project/zoo-kernel
- Timestamp:
- Jan 8, 2013, 3:54:57 PM (12 years ago)
- Location:
- trunk/zoo-project/zoo-kernel
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal.c
r379 r383 1745 1745 xmlNodePtr n; 1746 1746 1747 printHeaders(m); 1747 1748 doc = xmlNewDoc(BAD_CAST "1.0"); 1748 1749 maps* tmpMap=getMaps(m,"main"); … … 1899 1900 // mimeType information if present here. Maybe we can add more formats 1900 1901 // here. 1901 // If mimeType was not found, we then set txt as the default extension .1902 // If mimeType was not found, we then set txt as the default extension 1902 1903 map* mtype=getMap(tmpI->content,"mimeType"); 1903 1904 if(mtype!=NULL){ … … 1919 1920 file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+13)*sizeof(char)); 1920 1921 sprintf(file_name,"%s/%s_%s_%i.%s",tmp1->value,s->name,tmpI->name,cpid+100000,ext->value); 1921 FILE *ofile=fopen(file_name,"w ");1922 FILE *ofile=fopen(file_name,"wb"); 1922 1923 if(ofile==NULL) 1923 1924 fprintf(stderr,"Unable to create file on disk implying segfault ! \n"); … … 2000 2001 return; 2001 2002 } 2003 map* fname=getMapFromMaps(tmpI,tmpI->name,"filename"); 2004 if(fname!=NULL) 2005 printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); 2006 map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); 2007 if(rs!=NULL) 2008 printf("Content-Length: %s\r\n",rs->value); 2009 2002 2010 char mime[1024]; 2003 2011 map* mi=getMap(tmpI->content,"mimeType"); … … 2020 2028 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 2021 2029 printf("%s",mime); 2022 if(mi!=NULL && strncmp(mi->value,"image",5)==0){ 2023 map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); 2030 if(rs!=NULL) 2024 2031 fwrite(toto->value,atoi(rs->value),1,stdout); 2025 }2026 2032 else 2027 printf("%s",toto->value);2033 fwrite(toto->value,strlen(toto->value),1,stdout); 2028 2034 #ifdef DEBUG 2029 2035 dumpMap(toto); -
trunk/zoo-project/zoo-kernel/service_internal_js.c
r377 r383 25 25 #include "service_internal.h" 26 26 27 #ifndef JSCLASS_GLOBAL_FLAGS 28 #define JSCLSAS_GLOBAL_FLAGS 0 29 #endif 30 27 31 static char dbg[1024]; 28 32 … … 81 85 82 86 /* The class of the global object. */ 83 JSClass global_class 87 JSClass global_class= { 84 88 "global", JSCLASS_GLOBAL_FLAGS, 85 89 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, … … 99 103 100 104 /* Create a context. */ 101 cx = JS_NewContext(rt,8192 );105 cx = JS_NewContext(rt,81920); 102 106 if (cx == NULL){ 103 107 return 1; 104 108 } 105 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT );//| JSOPTION_METHODJIT);109 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); 106 110 JS_SetVersion(cx, JSVERSION_LATEST); 107 111 JS_SetErrorReporter(cx, reportError); … … 111 115 global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); 112 116 //#else 113 //global = JS_NewObject(cx, &global_class, NULL,NULL);117 //global = JS_NewObject(cx, &global_class, 0,0); 114 118 //#endif 115 119 … … 150 154 * Load the first part of the ZOO-API 151 155 */ 152 char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+1 6);156 char *api0=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+17); 153 157 sprintf(api0,"%s/%s/ZOO-proj4js.js",ntmp,tmpm1->value); 154 158 #ifdef JS_DEBUG … … 158 162 fflush(stderr); 159 163 160 char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+1 1);164 char *api1=(char*)malloc(strlen(tmpm1->value)+strlen(ntmp)+13); 161 165 sprintf(api1,"%s/%s/ZOO-api.js",ntmp,tmpm1->value); 162 166 #ifdef JS_DEBUG … … 200 204 exit(-1); 201 205 } 206 202 207 /* Call a function in obj's scope. */ 203 208 jsval argv[3]; … … 264 269 fprintf(stderr," * %d * \n",res); 265 270 #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 273 289 } 274 290 else{ 275 291 #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 */ 278 297 jsval tmp1; 279 298 JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1); … … 283 302 fprintf(stderr," * %d * \n",res); 284 303 #endif 304 /** 305 * Extract outputs when available. 306 */ 285 307 jsval tmp2; 286 308 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)) 289 317 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 296 339 #ifdef JS_DEBUG 297 340 dumpMaps(*outputs); … … 299 342 } 300 343 /* Cleanup. */ 344 JS_MaybeGC(cx); 301 345 JS_DestroyContext(cx); 302 346 JS_DestroyRuntime(rt); … … 479 523 jsuint len; 480 524 JSBool hasLen=JS_GetArrayLength(cx, tt, &len); 525 #ifdef JS_DEBUG 481 526 if(hasLen==JS_FALSE){ 482 #ifdef JS_DEBUG483 527 fprintf(stderr,"outputs array is empty\n"); 484 #endif 485 } 486 #ifdef JS_DEBUG 528 } 487 529 fprintf(stderr,"outputs array length : %d\n",len); 488 530 #endif … … 694 736 tmp1=JSValToChar(cx,&tmp); 695 737 #ifdef ULINET_DEBUG 738 curl_easy_setopt(handle.handle,CURLOPT_VERBOSE,1); 696 739 fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1); 697 740 #endif -
trunk/zoo-project/zoo-kernel/service_internal_js.h
r377 r383 27 27 28 28 #pragma once 29 29 #ifdef WIN32 30 #include <wchar.h> 31 #endif 30 32 #include "service.h" 31 33 #include "service_internal.h"
Note: See TracChangeset
for help on using the changeset viewer.