Changeset 368
- Timestamp:
- Oct 4, 2012, 5:04:31 PM (12 years ago)
- Location:
- trunk/zoo-project/zoo-kernel
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/nmake.opt
r364 r368 1 LIBINTL_CPATH=..\..\..\2 PYTHON_CPATH=..\..\..\Python-2.7.33 TPATH=..\..\..\tools4 #GEODIR=c:/OSGeo4W5 #DESTDIR=c:/OSGeo4W6 TOOLS=$(TPATH)\bin7 1 8 2 CC=cl $(CFLAGS) … … 37 31 !ENDIF 38 32 39 CFLAGS=-SPOST_DEBUG $(CFLAGS1) /nologo /MD /W3 /EHsc /O2 /D_CRT_SECURE_NO_WARNINGS /DWIN32 $(CJFLAGS) -I$(ZOOK_DIR) -I./ $(JAVA_CFLAGS) -I$(TROOT)..\..\thirds\dirent-win32 -I$(INTL_DIR) -I$(CURL_DIR)\include -I$(XML2_DIR)\include -I$(GDAL_DIR)\port $(JS_CFLAGS) -I$(GDAL_DIR)\ogr -I$(GDAL_DIR)\gcore -I$(GD_DIR) -I$(ICONV_DIR) -I$(TROOT)..\..\thirds\include -I$(TROOT)..\..\thirds\cgic206 -I$(PYTHON_CPATH)\include -I$(SSL_DIR)/inc32 -I$(FCGI_DIR)\include $(PY_CFLAGS) -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF 33 TROOT=$(ZOOK_DIR) 34 TPATH=$(ZOOK_DIR)\..\..\..\tools 35 LIBINTL_CPATH=$(ZOOK_DIR)\..\..\..\ 36 PYTHON_CPATH=$(ZOOK_DIR)\..\..\..\Python-2.7.3 40 37 41 LDFLAGS=$(FCGI_LIBRARY) $(CURL_LIBRARY) $(PY_LDFLAGS) $(XML2_LIBRARY) $(TROOT)../../thirds/cgic206/libcgic.lib $(SSL_DIR)/out32dll/libeay32.lib $(JAVA_LDFLAGS) $(SSL_DIR)/out32dll/ssleay32.lib $(MS_LDFLAGS) $(INTL_DIR)/intl.lib $(XML2_DIR)/win32/bin.msvc/libxml2.lib $(GDAL_DIR)/gdal_i.lib $(CURL_DIR)/lib/libcurl.lib $(JS_LDFLAGS) /machine:i386 38 CFLAGS=$(CFLAGS1) /nologo /MD /W3 /EHsc /O2 /D_CRT_SECURE_NO_WARNINGS /DWIN32 $(CJFLAGS) -I$(ZOOK_DIR) -I./ $(JAVA_CFLAGS) $(MS_CFLAGS) -I$(TROOT)\..\..\thirds\dirent-win32 -I$(INTL_DIR) -I$(CURL_DIR)\include -I$(XML2_DIR)\include -I$(GDAL_DIR)\port $(JS_CFLAGS) -I$(GDAL_DIR)\ogr -I$(GDAL_DIR)\gcore -I$(GD_DIR) -I$(ICONV_DIR) -I$(TROOT)\..\..\thirds\include -I$(TROOT)\..\..\thirds\cgic206 -I$(PYTHON_CPATH)\include -I$(SSL_DIR)/inc32 -I$(FCGI_DIR)\include $(PY_CFLAGS) -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF 39 40 LDFLAGS=$(FCGI_LIBRARY) $(CURL_LIBRARY) $(PY_LDFLAGS) $(XML2_LIBRARY) $(TROOT)/../../thirds/cgic206/libcgic.lib $(SSL_DIR)/out32dll/libeay32.lib $(JAVA_LDFLAGS) $(SSL_DIR)/out32dll/ssleay32.lib $(MS_LDFLAGS) $(INTL_DIR)/intl.lib $(XML2_DIR)/win32/bin.msvc/libxml2.lib $(GDAL_DIR)/gdal_i.lib $(CURL_DIR)/lib/libcurl.lib $(JS_LDFLAGS) /machine:i386 -
trunk/zoo-project/zoo-kernel/service_internal_js.c
r364 r368 120 120 } 121 121 122 jsval tmp=INT_TO_JSVAL(3); 123 if (!JS_SetProperty(cx, global, "SERVICE_SUCCEEDED", &tmp)) 124 return 1; 125 tmp=INT_TO_JSVAL(4); 126 if (!JS_SetProperty(cx, global, "SERVICE_FAILED", &tmp)) 127 return 1; 122 128 if (!JS_DefineFunction(cx, global, "ZOORequest", JSRequest, 4, 0)) 123 129 return 1; … … 638 644 } 639 645 646 char* JSValToChar(JSContext* context, jsval* arg) { 647 char *c; 648 char *tmp; 649 JSString *jsmsg; 650 size_t len; 651 int i; 652 if(!JSVAL_IS_STRING(*arg)) { 653 return NULL; 654 } 655 jsmsg = JS_ValueToString(context,*arg); 656 len = JS_GetStringLength(jsmsg); 657 tmp = JS_EncodeString(context,jsmsg); 658 c = (char*)malloc((len+1)*sizeof(char)); 659 c[len] = '\0'; 660 #ifdef ULINET_DEBUG 661 fprintf(stderr,"%d \n",len); 662 #endif 663 for(i = 0;i < len;i++) { 664 c[i] = tmp[i]; 665 c[i+1] = 0; 666 } 667 #ifdef ULINET_DEBUG 668 fprintf(stderr,"%s \n",c); 669 #endif 670 return c; 671 } 672 673 HINTERNET setHeader(HINTERNET handle,JSContext *cx,JSObject *header){ 674 jsuint length=0; 675 jsint i=0; 676 char *tmp1; 677 #ifdef ULINET_DEBUG 678 fprintf(stderr,"setHeader\n"); 679 #endif 680 if(JS_IsArrayObject(cx,header)){ 681 #ifdef ULINET_DEBUG 682 fprintf(stderr,"header is an array\n"); 683 #endif 684 JS_GetArrayLength(cx,header,&length); 685 #ifdef ULINET_DEBUG 686 fprintf(stderr,"header is an array of %d elements\n",length); 687 #endif 688 handle.header=NULL; 689 for(i=0;i<length;i++){ 690 jsval tmp; 691 JS_GetElement(cx,header,i,&tmp); 692 tmp1=JSValToChar(cx,&tmp); 693 #ifdef ULINET_DEBUG 694 fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1); 695 #endif 696 handle.header=curl_slist_append(handle.header, tmp1); 697 free(tmp1); 698 } 699 } 700 else{ 701 fprintf(stderr,"not an array !!!!!!!\n"); 702 } 703 return handle; 704 } 705 706 JSBool 707 JSRequest(JSContext *cx, uintN argc, jsval *argv1) 708 { 709 jsval *argv = JS_ARGV(cx,argv1); 710 HINTERNET hInternet; 711 HINTERNET res; 712 HINTERNET res1; 713 JSObject *header; 714 char *url; 715 char *method; 716 char* tmpValue; 717 size_t dwRead; 718 int i=0; 719 JS_MaybeGC(cx); 720 hInternet=InternetOpen("ZooWPSClient\0", 721 INTERNET_OPEN_TYPE_PRECONFIG, 722 NULL,NULL, 0); 723 if(!CHECK_INET_HANDLE(hInternet)) 724 return JS_FALSE; 725 if(argc>=2){ 726 method=JSValToChar(cx,&argv[0]); 727 url=JSValToChar(cx,&argv[1]); 728 } 729 else{ 730 method=strdup("GET"); 731 url=JSValToChar(cx,argv); 732 } 733 if(argc==4){ 734 char *body; 735 body=JSValToChar(cx,&argv[2]); 736 header=JSVAL_TO_OBJECT(argv[3]); 737 #ifdef ULINET_DEBUG 738 fprintf(stderr,"URL (%s) \nBODY (%s)\n",url,body); 739 #endif 740 if(JS_IsArrayObject(cx,header)) 741 res1=setHeader(hInternet,cx,header); 742 #ifdef ULINET_DEBUG 743 fprintf(stderr,"BODY (%s)\n",body); 744 #endif 745 res=InternetOpenUrl(res1,url,body,strlen(body), 746 INTERNET_FLAG_NO_CACHE_WRITE,0); 747 free(body); 748 }else{ 749 if(argc==3){ 750 char *body=JSValToChar(cx,&argv[2]); 751 res=InternetOpenUrl(hInternet,url,body,strlen(body), 752 INTERNET_FLAG_NO_CACHE_WRITE,0); 753 free(body); 754 } 755 res=InternetOpenUrl(hInternet,url,NULL,0, 756 INTERNET_FLAG_NO_CACHE_WRITE,0); 757 } 758 tmpValue=(char*)malloc((res.nDataLen+1)*sizeof(char)); 759 InternetReadFile(res,(LPVOID)tmpValue,res.nDataLen,&dwRead); 760 #ifdef ULINET_DEBUG 761 fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue); 762 #endif 763 if(dwRead==0){ 764 JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,"Unable to access the file.",strlen("Unable to access the file.")))); 765 return JS_TRUE; 766 } 767 768 #ifdef ULINET_DEBUG 769 fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue); 770 #endif 771 JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue)))); 772 free(url); 773 if(argc>=2) 774 free(method); 775 if(argc==4 && res.header!=NULL){ 776 curl_slist_free_all(res.header); 777 } 778 InternetCloseHandle(hInternet); 779 JS_MaybeGC(cx); 780 return JS_TRUE; 781 } -
trunk/zoo-project/zoo-kernel/service_internal_js.h
r364 r368 44 44 maps* mapsFromJSObject(JSContext *,jsval); 45 45 map* mapFromJSObject(JSContext *,jsval); 46 JSBool JSRequest(JSContext*, uintN, jsval*); 46 47 47 48 void reportError(JSContext *cx, const char *message, JSErrorReport *report); -
trunk/zoo-project/zoo-kernel/service_internal_python.c
r364 r368 25 25 #include "service_internal_python.h" 26 26 27 static PyObject* ZooError; 28 29 PyMethodDef zooMethods[] = { 30 {"update_status", PythonUpdateStatus, METH_VARARGS, "Update status percentage of a running process."}, 31 {NULL, NULL, 0, NULL} /* tempt not the blade, all fear the sentinel */ 32 }; 33 34 PyMODINIT_FUNC init_zoo(){ 35 PyObject *tmp,*d; 36 PyObject* module = Py_InitModule("zoo", zooMethods); 37 if (module == NULL) 38 return; 39 40 d = PyModule_GetDict(module); 41 tmp = PyInt_FromLong(3); 42 PyDict_SetItemString(d, "SERVICE_SUCCEEDED", tmp); 43 Py_DECREF(tmp); 44 45 tmp = PyInt_FromLong(4); 46 PyDict_SetItemString(d, "SERVICE_FAILED", tmp); 47 Py_DECREF(tmp); 48 49 ZooError = PyErr_NewException("zoo.error", NULL, NULL); 50 Py_INCREF(ZooError); 51 PyModule_AddObject(module, "error", ZooError); 52 } 53 27 54 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ 28 55 maps* m=*main_conf; … … 80 107 PyEval_InitThreads(); 81 108 Py_Initialize(); 109 init_zoo(); 82 110 mainstate = PyThreadState_Swap(NULL); 83 111 PyEval_ReleaseLock(); … … 388 416 return res; 389 417 } 418 419 PyObject* 420 PythonUpdateStatus(PyObject* self, PyObject* args) 421 { 422 maps* conf; 423 PyObject* confdict; 424 int istatus; 425 char* status; 426 if (!PyArg_ParseTuple(args, "O!i", &PyDict_Type, &confdict, &istatus)){ 427 #ifdef DEBUG 428 fprintf(stderr,"Incorrect arguments to update status function"); 429 #endif 430 return NULL; 431 } 432 if (istatus < 0 || istatus > 100){ 433 PyErr_SetString(ZooError, "Status must be a percentage."); 434 return NULL; 435 }else{ 436 char tmpStatus[4]; 437 snprintf(tmpStatus, 4, "%i", istatus); 438 status = strdup(tmpStatus); 439 } 440 /* now update the map */ 441 { 442 PyObject* lenv = PyMapping_GetItemString(confdict, "lenv"); 443 if (lenv && PyMapping_Check(lenv)){ 444 PyObject* valobj = PyString_FromString(status); 445 PyMapping_SetItemString(lenv, "status", valobj); 446 Py_DECREF(valobj); 447 } 448 Py_DECREF(lenv); 449 } 450 conf = mapsFromPyDict((PyDictObject*)confdict); 451 if (getMapFromMaps(conf,"lenv","status") != NULL){ 452 fprintf(stderr,"STATUS RETURNED : %s\n",status); 453 if(status!=NULL){ 454 setMapInMaps(conf,"lenv","status",status); 455 free(status); 456 } 457 else 458 setMapInMaps(conf,"lenv","status","15"); 459 updateStatus(conf); 460 } 461 freeMaps(&conf); 462 free(conf); 463 Py_RETURN_NONE; 464 } -
trunk/zoo-project/zoo-kernel/service_internal_python.h
r348 r368 45 45 int zoo_python_support(maps**,map*,service*,maps**,maps**); 46 46 47 PyObject* PythonUpdateStatus(PyObject*, PyObject*); 48 47 49 #endif -
trunk/zoo-project/zoo-kernel/ulinet.c
r364 r368 374 374 } 375 375 376 #ifdef USE_JS377 #define XP_WIN 1378 #include "jsapi.h"379 380 char* JSValToChar(JSContext* context, jsval* arg) {381 char *c;382 char *tmp;383 JSString *jsmsg;384 size_t len;385 int i;386 if(!JSVAL_IS_STRING(*arg)) {387 return NULL;388 }389 jsmsg = JS_ValueToString(context,*arg);390 len = JS_GetStringLength(jsmsg);391 tmp = JS_EncodeString(context,jsmsg);392 c = (char*)malloc((len+1)*sizeof(char));393 c[len] = '\0';394 #ifdef ULINET_DEBUG395 fprintf(stderr,"%d \n",len);396 #endif397 for(i = 0;i < len;i++) {398 c[i] = tmp[i];399 c[i+1] = 0;400 }401 #ifdef ULINET_DEBUG402 fprintf(stderr,"%s \n",c);403 #endif404 return c;405 }406 407 HINTERNET setHeader(HINTERNET handle,JSContext *cx,JSObject *header){408 jsuint length=0;409 jsint i=0;410 char *tmp1;411 #ifdef ULINET_DEBUG412 fprintf(stderr,"setHeader\n");413 #endif414 if(JS_IsArrayObject(cx,header)){415 #ifdef ULINET_DEBUG416 fprintf(stderr,"header is an array\n");417 #endif418 JS_GetArrayLength(cx,header,&length);419 #ifdef ULINET_DEBUG420 fprintf(stderr,"header is an array of %d elements\n",length);421 #endif422 handle.header=NULL;423 for(i=0;i<length;i++){424 jsval tmp;425 JS_GetElement(cx,header,i,&tmp);426 tmp1=JSValToChar(cx,&tmp);427 #ifdef ULINET_DEBUG428 fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1);429 #endif430 handle.header=curl_slist_append(handle.header, tmp1);431 free(tmp1);432 }433 }434 else{435 fprintf(stderr,"not an array !!!!!!!\n");436 }437 return handle;438 }439 440 JSBool441 JSRequest(JSContext *cx, uintN argc, jsval *argv1)442 {443 jsval *argv = JS_ARGV(cx,argv1);444 HINTERNET hInternet;445 HINTERNET res;446 HINTERNET res1;447 JSObject *header;448 char *url;449 char *method;450 char* tmpValue;451 size_t dwRead;452 int i=0;453 JS_MaybeGC(cx);454 hInternet=InternetOpen((LPCTSTR)"ZooWPSClient\0",455 INTERNET_OPEN_TYPE_PRECONFIG,456 NULL,NULL, 0);457 if(!CHECK_INET_HANDLE(hInternet))458 return JS_FALSE;459 if(argc>=2){460 method=JSValToChar(cx,&argv[0]);461 url=JSValToChar(cx,&argv[1]);462 }463 else{464 method=strdup("GET");465 url=JSValToChar(cx,argv);466 }467 if(argc==4){468 char *body;469 body=JSValToChar(cx,&argv[2]);470 header=JSVAL_TO_OBJECT(argv[3]);471 #ifdef ULINET_DEBUG472 fprintf(stderr,"URL (%s) \nBODY (%s)\n",url,body);473 #endif474 if(JS_IsArrayObject(cx,header))475 res1=setHeader(hInternet,cx,header);476 #ifdef ULINET_DEBUG477 fprintf(stderr,"BODY (%s)\n",body);478 #endif479 res=InternetOpenUrl(res1,url,body,strlen(body),480 INTERNET_FLAG_NO_CACHE_WRITE,0);481 free(body);482 }else{483 if(argc==3){484 char *body=JSValToChar(cx,&argv[2]);485 res=InternetOpenUrl(hInternet,url,body,strlen(body),486 INTERNET_FLAG_NO_CACHE_WRITE,0);487 free(body);488 }489 res=InternetOpenUrl(hInternet,url,NULL,0,490 INTERNET_FLAG_NO_CACHE_WRITE,0);491 }492 tmpValue=(char*)malloc((res.nDataLen+1)*sizeof(char));493 InternetReadFile(res,(LPVOID)tmpValue,res.nDataLen,&dwRead);494 fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);495 if(dwRead==0){496 JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,"Unable to access the file.",strlen("Unable to access the file."))));497 return JS_TRUE;498 }499 500 #ifdef ULINET_DEBUG501 fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);502 #endif503 JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue))));504 free(url);505 if(argc>=2)506 free(method);507 if(argc==4 && res.header!=NULL){508 curl_slist_free_all(res.header);509 }510 InternetCloseHandle(hInternet);511 JS_MaybeGC(cx);512 return JS_TRUE;513 }514 #endif -
trunk/zoo-project/zoo-kernel/ulinet.h
r364 r368 141 141 bool InternetGetCookie(LPCTSTR lpszUrl,LPCTSTR lpszCookieName,LPTSTR lpszCookieData,LPDWORD lpdwSize); 142 142 143 #ifdef USE_JS144 JSBool JSRequest(JSContext*, uintN, jsval*);145 #endif146 147 143 #ifdef __cplusplus 148 144 } -
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r365 r368 66 66 #include "service_internal_perl.h" 67 67 #endif 68 69 70 68 71 69 #include <dirent.h> … … 633 631 service* s1; 634 632 int scount=0; 635 636 633 #ifdef DEBUG 637 634 dumpMap(r_inputs); … … 1140 1137 #endif 1141 1138 { 1142 loadRemoteFile(m,tmpmaps->content,hInternet,tmpx2); 1139 if(loadRemoteFile(m,tmpmaps->content,hInternet,tmpx2)<0){ 1140 freeMaps(&m); 1141 free(m); 1142 free(REQUEST); 1143 free(SERVICE_URL); 1144 InternetCloseHandle(hInternet); 1145 freeService(&s1); 1146 free(s1); 1147 return 0; 1148 } 1143 1149 } 1144 1150 free(tmpx2); … … 1293 1299 if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0) 1294 1300 && CHECK_INET_HANDLE(hInternet)){ 1295 loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val); 1301 if(loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val)){ 1302 freeMaps(&m); 1303 free(m); 1304 free(REQUEST); 1305 free(SERVICE_URL); 1306 InternetCloseHandle(hInternet); 1307 freeService(&s1); 1308 free(s1); 1309 return 0; 1310 } 1296 1311 } 1297 1312 }
Note: See TracChangeset
for help on using the changeset viewer.