Index: trunk/zoo-project/zoo-kernel/nmake.opt
===================================================================
--- trunk/zoo-project/zoo-kernel/nmake.opt	(revision 366)
+++ trunk/zoo-project/zoo-kernel/nmake.opt	(revision 368)
@@ -1,8 +1,2 @@
-LIBINTL_CPATH=..\..\..\
-PYTHON_CPATH=..\..\..\Python-2.7.3
-TPATH=..\..\..\tools
-#GEODIR=c:/OSGeo4W
-#DESTDIR=c:/OSGeo4W
-TOOLS=$(TPATH)\bin
 
 CC=cl $(CFLAGS)
@@ -37,5 +31,10 @@
 !ENDIF
 
-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
+TROOT=$(ZOOK_DIR)
+TPATH=$(ZOOK_DIR)\..\..\..\tools
+LIBINTL_CPATH=$(ZOOK_DIR)\..\..\..\
+PYTHON_CPATH=$(ZOOK_DIR)\..\..\..\Python-2.7.3
 
-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
+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
+
+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
Index: trunk/zoo-project/zoo-kernel/service_internal_js.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 366)
+++ trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 368)
@@ -120,4 +120,10 @@
   }
 
+  jsval tmp=INT_TO_JSVAL(3);
+  if (!JS_SetProperty(cx, global, "SERVICE_SUCCEEDED", &tmp))
+    return 1;
+  tmp=INT_TO_JSVAL(4);
+  if (!JS_SetProperty(cx, global, "SERVICE_FAILED", &tmp))
+    return 1;
   if (!JS_DefineFunction(cx, global, "ZOORequest", JSRequest, 4, 0))
     return 1;
@@ -638,2 +644,138 @@
 }
 
+char* JSValToChar(JSContext* context, jsval* arg) {
+  char *c;
+  char *tmp;
+  JSString *jsmsg;
+  size_t len;
+  int i;
+  if(!JSVAL_IS_STRING(*arg)) {
+    return NULL;
+  }
+  jsmsg = JS_ValueToString(context,*arg);
+  len = JS_GetStringLength(jsmsg);
+  tmp = JS_EncodeString(context,jsmsg);
+  c = (char*)malloc((len+1)*sizeof(char));
+  c[len] = '\0';
+#ifdef ULINET_DEBUG
+  fprintf(stderr,"%d \n",len);
+#endif
+  for(i = 0;i < len;i++) {
+    c[i] = tmp[i];
+    c[i+1] = 0;
+  }
+#ifdef ULINET_DEBUG
+  fprintf(stderr,"%s \n",c);
+#endif
+  return c;
+}
+
+HINTERNET setHeader(HINTERNET handle,JSContext *cx,JSObject *header){
+  jsuint length=0;
+  jsint i=0;
+  char *tmp1;
+#ifdef ULINET_DEBUG
+  fprintf(stderr,"setHeader\n");
+#endif
+  if(JS_IsArrayObject(cx,header)){
+#ifdef ULINET_DEBUG
+    fprintf(stderr,"header is an array\n");
+#endif
+    JS_GetArrayLength(cx,header,&length);
+#ifdef ULINET_DEBUG
+    fprintf(stderr,"header is an array of %d elements\n",length);
+#endif
+    handle.header=NULL;
+    for(i=0;i<length;i++){
+      jsval tmp;
+      JS_GetElement(cx,header,i,&tmp);
+      tmp1=JSValToChar(cx,&tmp);
+#ifdef ULINET_DEBUG
+      fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1);
+#endif
+      handle.header=curl_slist_append(handle.header, tmp1);
+      free(tmp1);
+    }
+  }
+  else{
+    fprintf(stderr,"not an array !!!!!!!\n");
+  }
+  return handle;
+}
+
+JSBool
+JSRequest(JSContext *cx, uintN argc, jsval *argv1)
+{
+  jsval *argv = JS_ARGV(cx,argv1);
+  HINTERNET hInternet;
+  HINTERNET res;
+  HINTERNET res1;
+  JSObject *header;
+  char *url;
+  char *method;
+  char* tmpValue;
+  size_t dwRead;
+  int i=0;
+  JS_MaybeGC(cx);
+  hInternet=InternetOpen("ZooWPSClient\0",
+			 INTERNET_OPEN_TYPE_PRECONFIG,
+			 NULL,NULL, 0);
+  if(!CHECK_INET_HANDLE(hInternet))
+    return JS_FALSE;
+  if(argc>=2){
+    method=JSValToChar(cx,&argv[0]);
+    url=JSValToChar(cx,&argv[1]);
+  }
+  else{
+    method=strdup("GET");
+    url=JSValToChar(cx,argv);
+  }
+  if(argc==4){
+    char *body;
+    body=JSValToChar(cx,&argv[2]);
+    header=JSVAL_TO_OBJECT(argv[3]);
+#ifdef ULINET_DEBUG
+    fprintf(stderr,"URL (%s) \nBODY (%s)\n",url,body);
+#endif
+    if(JS_IsArrayObject(cx,header))
+      res1=setHeader(hInternet,cx,header);
+#ifdef ULINET_DEBUG
+    fprintf(stderr,"BODY (%s)\n",body);
+#endif
+    res=InternetOpenUrl(res1,url,body,strlen(body),
+			INTERNET_FLAG_NO_CACHE_WRITE,0);    
+    free(body);
+  }else{
+    if(argc==3){
+      char *body=JSValToChar(cx,&argv[2]);
+      res=InternetOpenUrl(hInternet,url,body,strlen(body),
+			  INTERNET_FLAG_NO_CACHE_WRITE,0);
+      free(body);
+    }
+    res=InternetOpenUrl(hInternet,url,NULL,0,
+			INTERNET_FLAG_NO_CACHE_WRITE,0);
+  }
+  tmpValue=(char*)malloc((res.nDataLen+1)*sizeof(char));
+  InternetReadFile(res,(LPVOID)tmpValue,res.nDataLen,&dwRead);
+#ifdef ULINET_DEBUG
+  fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);
+#endif
+  if(dwRead==0){
+    JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,"Unable to access the file.",strlen("Unable to access the file."))));
+    return JS_TRUE;
+  }
+
+#ifdef ULINET_DEBUG
+  fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);
+#endif
+  JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue))));
+  free(url);
+  if(argc>=2)
+    free(method);
+  if(argc==4 && res.header!=NULL){
+    curl_slist_free_all(res.header);
+  }
+  InternetCloseHandle(hInternet);
+  JS_MaybeGC(cx);
+  return JS_TRUE;
+}
Index: trunk/zoo-project/zoo-kernel/service_internal_js.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_js.h	(revision 366)
+++ trunk/zoo-project/zoo-kernel/service_internal_js.h	(revision 368)
@@ -44,4 +44,5 @@
   maps* mapsFromJSObject(JSContext *,jsval);
   map* mapFromJSObject(JSContext *,jsval);
+  JSBool JSRequest(JSContext*, uintN, jsval*);
 
   void reportError(JSContext *cx, const char *message, JSErrorReport *report);
Index: trunk/zoo-project/zoo-kernel/service_internal_python.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_python.c	(revision 366)
+++ trunk/zoo-project/zoo-kernel/service_internal_python.c	(revision 368)
@@ -25,4 +25,31 @@
 #include "service_internal_python.h"
 
+static PyObject* ZooError;
+
+PyMethodDef zooMethods[] = {
+  {"update_status", PythonUpdateStatus, METH_VARARGS, "Update status percentage of a running process."},
+  {NULL, NULL, 0, NULL} /* tempt not the blade, all fear the sentinel */
+};
+
+PyMODINIT_FUNC init_zoo(){
+  PyObject *tmp,*d;
+  PyObject* module = Py_InitModule("zoo", zooMethods);
+  if (module == NULL)
+    return;
+  
+  d = PyModule_GetDict(module);
+  tmp = PyInt_FromLong(3);
+  PyDict_SetItemString(d, "SERVICE_SUCCEEDED", tmp);
+  Py_DECREF(tmp);
+
+  tmp = PyInt_FromLong(4);
+  PyDict_SetItemString(d, "SERVICE_FAILED", tmp);
+  Py_DECREF(tmp);
+
+  ZooError = PyErr_NewException("zoo.error", NULL, NULL);
+  Py_INCREF(ZooError);
+  PyModule_AddObject(module, "error", ZooError);
+}
+
 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
   maps* m=*main_conf;
@@ -80,4 +107,5 @@
   PyEval_InitThreads();
   Py_Initialize();
+  init_zoo();
   mainstate = PyThreadState_Swap(NULL);
   PyEval_ReleaseLock();
@@ -388,2 +416,49 @@
   return res;
 }
+
+PyObject*
+PythonUpdateStatus(PyObject* self, PyObject* args)
+{
+  maps* conf;
+  PyObject* confdict;
+  int istatus;
+  char* status;
+  if (!PyArg_ParseTuple(args, "O!i", &PyDict_Type, &confdict, &istatus)){
+#ifdef DEBUG
+    fprintf(stderr,"Incorrect arguments to update status function");
+#endif
+    return NULL;
+  }
+  if (istatus < 0 || istatus > 100){
+     PyErr_SetString(ZooError, "Status must be a percentage.");
+     return NULL;
+  }else{
+     char tmpStatus[4];
+     snprintf(tmpStatus, 4, "%i", istatus);
+     status = strdup(tmpStatus);
+  }
+  /* now update the map */
+  {
+    PyObject* lenv = PyMapping_GetItemString(confdict, "lenv");
+    if (lenv && PyMapping_Check(lenv)){
+      PyObject* valobj = PyString_FromString(status);
+      PyMapping_SetItemString(lenv, "status", valobj);
+      Py_DECREF(valobj);
+    }
+    Py_DECREF(lenv);
+  }
+  conf = mapsFromPyDict((PyDictObject*)confdict);
+  if (getMapFromMaps(conf,"lenv","status") != NULL){
+    fprintf(stderr,"STATUS RETURNED : %s\n",status);
+    if(status!=NULL){
+      setMapInMaps(conf,"lenv","status",status);
+      free(status);
+    }
+    else
+      setMapInMaps(conf,"lenv","status","15");
+    updateStatus(conf);
+  }
+  freeMaps(&conf);
+  free(conf);
+  Py_RETURN_NONE;
+}
Index: trunk/zoo-project/zoo-kernel/service_internal_python.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_python.h	(revision 366)
+++ trunk/zoo-project/zoo-kernel/service_internal_python.h	(revision 368)
@@ -45,3 +45,5 @@
 int zoo_python_support(maps**,map*,service*,maps**,maps**);
 
+PyObject* PythonUpdateStatus(PyObject*, PyObject*);
+
 #endif
Index: trunk/zoo-project/zoo-kernel/ulinet.c
===================================================================
--- trunk/zoo-project/zoo-kernel/ulinet.c	(revision 366)
+++ trunk/zoo-project/zoo-kernel/ulinet.c	(revision 368)
@@ -374,141 +374,2 @@
 }
 
-#ifdef USE_JS
-#define XP_WIN 1
-#include "jsapi.h"
-
-char* JSValToChar(JSContext* context, jsval* arg) {
-  char *c;
-  char *tmp;
-  JSString *jsmsg;
-  size_t len;
-  int i;
-  if(!JSVAL_IS_STRING(*arg)) {
-    return NULL;
-  }
-  jsmsg = JS_ValueToString(context,*arg);
-  len = JS_GetStringLength(jsmsg);
-  tmp = JS_EncodeString(context,jsmsg);
-  c = (char*)malloc((len+1)*sizeof(char));
-  c[len] = '\0';
-#ifdef ULINET_DEBUG
-  fprintf(stderr,"%d \n",len);
-#endif
-  for(i = 0;i < len;i++) {
-    c[i] = tmp[i];
-    c[i+1] = 0;
-  }
-#ifdef ULINET_DEBUG
-  fprintf(stderr,"%s \n",c);
-#endif
-  return c;
-}
-
-HINTERNET setHeader(HINTERNET handle,JSContext *cx,JSObject *header){
-  jsuint length=0;
-  jsint i=0;
-  char *tmp1;
-#ifdef ULINET_DEBUG
-  fprintf(stderr,"setHeader\n");
-#endif
-  if(JS_IsArrayObject(cx,header)){
-#ifdef ULINET_DEBUG
-    fprintf(stderr,"header is an array\n");
-#endif
-    JS_GetArrayLength(cx,header,&length);
-#ifdef ULINET_DEBUG
-    fprintf(stderr,"header is an array of %d elements\n",length);
-#endif
-    handle.header=NULL;
-    for(i=0;i<length;i++){
-      jsval tmp;
-      JS_GetElement(cx,header,i,&tmp);
-      tmp1=JSValToChar(cx,&tmp);
-#ifdef ULINET_DEBUG
-      fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1);
-#endif
-      handle.header=curl_slist_append(handle.header, tmp1);
-      free(tmp1);
-    }
-  }
-  else{
-    fprintf(stderr,"not an array !!!!!!!\n");
-  }
-  return handle;
-}
-
-JSBool
-JSRequest(JSContext *cx, uintN argc, jsval *argv1)
-{
-  jsval *argv = JS_ARGV(cx,argv1);
-  HINTERNET hInternet;
-  HINTERNET res;
-  HINTERNET res1;
-  JSObject *header;
-  char *url;
-  char *method;
-  char* tmpValue;
-  size_t dwRead;
-  int i=0;
-  JS_MaybeGC(cx);
-  hInternet=InternetOpen((LPCTSTR)"ZooWPSClient\0",
-			 INTERNET_OPEN_TYPE_PRECONFIG,
-			 NULL,NULL, 0);
-  if(!CHECK_INET_HANDLE(hInternet))
-    return JS_FALSE;
-  if(argc>=2){
-    method=JSValToChar(cx,&argv[0]);
-    url=JSValToChar(cx,&argv[1]);
-  }
-  else{
-    method=strdup("GET");
-    url=JSValToChar(cx,argv);
-  }
-  if(argc==4){
-    char *body;
-    body=JSValToChar(cx,&argv[2]);
-    header=JSVAL_TO_OBJECT(argv[3]);
-#ifdef ULINET_DEBUG
-    fprintf(stderr,"URL (%s) \nBODY (%s)\n",url,body);
-#endif
-    if(JS_IsArrayObject(cx,header))
-      res1=setHeader(hInternet,cx,header);
-#ifdef ULINET_DEBUG
-    fprintf(stderr,"BODY (%s)\n",body);
-#endif
-    res=InternetOpenUrl(res1,url,body,strlen(body),
-			INTERNET_FLAG_NO_CACHE_WRITE,0);    
-    free(body);
-  }else{
-    if(argc==3){
-      char *body=JSValToChar(cx,&argv[2]);
-      res=InternetOpenUrl(hInternet,url,body,strlen(body),
-			  INTERNET_FLAG_NO_CACHE_WRITE,0);
-      free(body);
-    }
-    res=InternetOpenUrl(hInternet,url,NULL,0,
-			INTERNET_FLAG_NO_CACHE_WRITE,0);
-  }
-  tmpValue=(char*)malloc((res.nDataLen+1)*sizeof(char));
-  InternetReadFile(res,(LPVOID)tmpValue,res.nDataLen,&dwRead);
-  fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);
-  if(dwRead==0){
-    JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,"Unable to access the file.",strlen("Unable to access the file."))));
-    return JS_TRUE;
-  }
-
-#ifdef ULINET_DEBUG
-  fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue);
-#endif
-  JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue))));
-  free(url);
-  if(argc>=2)
-    free(method);
-  if(argc==4 && res.header!=NULL){
-    curl_slist_free_all(res.header);
-  }
-  InternetCloseHandle(hInternet);
-  JS_MaybeGC(cx);
-  return JS_TRUE;
-}
-#endif
Index: trunk/zoo-project/zoo-kernel/ulinet.h
===================================================================
--- trunk/zoo-project/zoo-kernel/ulinet.h	(revision 366)
+++ trunk/zoo-project/zoo-kernel/ulinet.h	(revision 368)
@@ -141,8 +141,4 @@
 bool InternetGetCookie(LPCTSTR lpszUrl,LPCTSTR lpszCookieName,LPTSTR lpszCookieData,LPDWORD lpdwSize);
 
-#ifdef USE_JS
-JSBool JSRequest(JSContext*, uintN, jsval*);
-#endif
-
 #ifdef __cplusplus
 }
Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 366)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 368)
@@ -66,6 +66,4 @@
 #include "service_internal_perl.h"
 #endif
-
-
 
 #include <dirent.h>
@@ -633,5 +631,4 @@
   service* s1;
   int scount=0;
-
 #ifdef DEBUG
   dumpMap(r_inputs);
@@ -1140,5 +1137,14 @@
 #endif
 		{
-		  loadRemoteFile(m,tmpmaps->content,hInternet,tmpx2);
+		  if(loadRemoteFile(m,tmpmaps->content,hInternet,tmpx2)<0){
+		    freeMaps(&m);
+		    free(m);
+		    free(REQUEST);
+		    free(SERVICE_URL);
+		    InternetCloseHandle(hInternet);
+		    freeService(&s1);
+		    free(s1);
+		    return 0;
+		  }
 		}
 	      free(tmpx2);
@@ -1293,5 +1299,14 @@
 		  if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0)
 		     && CHECK_INET_HANDLE(hInternet)){
-		    loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val);
+		    if(loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val)){
+		      freeMaps(&m);
+		      free(m);
+		      free(REQUEST);
+		      free(SERVICE_URL);
+		      InternetCloseHandle(hInternet);
+		      freeService(&s1);
+		      free(s1);
+		      return 0;
+		    }
 		  }
 		}
