Index: branches/branch-1.2/zoo-kernel/Makefile.in
===================================================================
--- branches/branch-1.2/zoo-kernel/Makefile.in	(revision 111)
+++ branches/branch-1.2/zoo-kernel/Makefile.in	(revision 217)
@@ -93,8 +93,8 @@
 
 zoo_service_loader.o: zoo_service_loader.c service.h
-	g++ -g -O2 -Wall ${XML2CFLAGS} ${CFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
+	g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
 
 zoo_loader.cgi: zoo_loader.c zoo_service_loader.o  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${PYTHON_FILE}   ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE}
-	g++ -g -O2 -Wall ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS}   ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
+	g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS}   ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
 	g++  ${JSCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o service_internal.o ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -lcurl -L../thirds/cgic206 -lcgic -lcurl ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MACOS_LD_FLAGS}
 
Index: branches/branch-1.2/zoo-kernel/README
===================================================================
--- branches/branch-1.2/zoo-kernel/README	(revision 217)
+++ branches/branch-1.2/zoo-kernel/README	(revision 217)
@@ -0,0 +1,2 @@
+For information on how to compile and install the ZOO Kernel, please refer to:
+http://zoo-project.org/trac/wiki/ZooDocumentation/ZOOKernel/Installation
Index: branches/branch-1.2/zoo-kernel/configure.ac
===================================================================
--- branches/branch-1.2/zoo-kernel/configure.ac	(revision 111)
+++ branches/branch-1.2/zoo-kernel/configure.ac	(revision 217)
@@ -119,5 +119,5 @@
 
 AC_ARG_WITH([python], 
-	[AS_HELP_STRING([--with-python=PATH], [To enabled python support or specify an alternative directory for python installation,  disabled by default])], 
+	[AS_HELP_STRING([--with-python=PATH], [To enable python support or specify an alternative directory for python installation,  disabled by default])], 
 	[PYTHON_PATH="$withval"; PYTHON_ENABLED="-DUSE_PYTHON"], [PYTHON_ENABLED=""])
 
@@ -164,5 +164,5 @@
 
 AC_ARG_WITH([php], 
-	[AS_HELP_STRING([--with-php=PATH], [To enabled php support or specify an alternative directory for php installation,  disabled by default])], 
+	[AS_HELP_STRING([--with-php=PATH], [To enable php support or specify an alternative directory for php installation,  disabled by default])], 
 	[PHP_PATH="$withval"; PHP_ENABLED="-DUSE_PHP"], [PHP_ENABLED=""])
 
@@ -209,5 +209,5 @@
 
 AC_ARG_WITH([perl], 
-	[AS_HELP_STRING([--with-perl=PATH], [To enabled perl support or specify an alternative directory for perl installation,  disabled by default])], 
+	[AS_HELP_STRING([--with-perl=PATH], [To enable perl support or specify an alternative directory for perl installation,  disabled by default])], 
 	[PERL_PATH="$withval"; PERL_ENABLED="-DUSE_PERL"], [PERL_ENABLED=""])
 
@@ -217,9 +217,8 @@
 	PERL_FILE=""
 else
-	PERLCONFIG="$PERL_PATH/bin/perl"
-	PHP_FILE="service_internal_perl.o"
+	PERL_FILE="service_internal_perl.o"
 	if test  "$PERL_PATH" = "yes"
 	then
-		# PHP was not specified, so search within the current path
+		# Perl was not specified, so search within the current path
 		AC_PATH_PROG([PERLCONFIG], [perl])
 	else
@@ -249,5 +248,5 @@
 
 AC_ARG_WITH([java], 
-	[AS_HELP_STRING([--with-java=PATH], [To enabled java support, specify a JDK_HOME,  disabled by default])], 
+	[AS_HELP_STRING([--with-java=PATH], [To enable java support, specify a JDK_HOME,  disabled by default])], 
 	[JDKHOME="$withval"; JAVA_ENABLED="-DUSE_JAVA"], [JAVA_ENABLED=""])
 
@@ -308,5 +307,5 @@
 
 AC_ARG_WITH([js], 
-	[AS_HELP_STRING([--with-js=PATH], [specify --with-js=path-to-js to enabled js support, specify --with-js on linux debian like, js support is disabled by default ])], 
+	[AS_HELP_STRING([--with-js=PATH], [specify --with-js=path-to-js to enable js support, specify --with-js on linux debian like, js support is disabled by default ])], 
 	[JSHOME="$withval";JS_ENABLED="-DUSE_JS"], [JS_ENABLED=""])
 
Index: branches/branch-1.2/zoo-kernel/main_conf_read.y
===================================================================
--- branches/branch-1.2/zoo-kernel/main_conf_read.y	(revision 111)
+++ branches/branch-1.2/zoo-kernel/main_conf_read.y	(revision 217)
@@ -25,5 +25,5 @@
 using namespace std;
 
-extern void crerror(char *s);
+extern void crerror(const char *s);
 
 void usage(void) ;
@@ -304,5 +304,5 @@
 /* fonction qui affiche l erreur si il y en a une */
 //======================================================
-void crerror(char *s)
+void crerror(const char *s)
 {
   if(debug)
@@ -314,5 +314,5 @@
 /* fonction principale : entrée dans le programme */
 //======================================================
-int conf_read(char* file,maps* my_map){
+int conf_read(const char* file,maps* my_map){
   
   crin = fopen(file,"r");
@@ -335,5 +335,7 @@
 
   fclose(crin);
+#ifndef WIN32
   crlex_destroy();
+#endif
 
   return resultatYYParse;
Index: branches/branch-1.2/zoo-kernel/makefile.vc
===================================================================
--- branches/branch-1.2/zoo-kernel/makefile.vc	(revision 111)
+++ branches/branch-1.2/zoo-kernel/makefile.vc	(revision 217)
@@ -1,14 +1,12 @@
-GEODIR=c:/OSGeo4W
-DESTDIR=c:/OSGeo4W
-TPATH=..\..\..\tools
-TOOLS=$(TPATH)\bin
-CFLAGS=/EHa /nologo /MT /W3 /GX /O2 /D_CRT_SECURE_NO_WARNINGS /DWIN32 $(CJFLAGS) -I./ -I..\thirds\dirent-win32 -IC:\OSGeo4W\apps\Python25\include -I$(GEODIR)/include -I$(TPATH)\include -DLINUX_FREE_ISSUE #-DDEBUG
-CC=cl $(CFLAGS)
-CPP=cl /TP $(CFLAGS)
+# WIN32 Makefile tested using VC-9.0
+# Don't forget to set your PATH using the following command :
+# c:\Progam Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat
+# set PATH=%PATH%;$(TOOLS)
+# using value for TOOLS relative to your local installation
+#
 
-all:  service_loader
+!INCLUDE nmake.opt
 
-service_loader: service.h lex.sr.obj service_conf.tab.obj service_conf.y service_internal_python.obj service_loader.obj main_conf_read.tab.obj lex.cr.obj service_internal.obj
-	cl $(CFLAGS) lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj lex.cr.obj service_internal.obj service_internal_python.obj service_loader.obj -o service_loader -ldl `python-config --libs` `xml2-config --libs` -lfl -lcurl
+all:  zoo_loader.cgi
 
 main_conf_read.tab.c: main_conf_read.y service.h
@@ -54,7 +52,10 @@
 	$(CPP) /EHsc /c $(CFLAGS) zoo_loader.c
 
+dirent.obj:
+	$(CPP) /EHsc /c $(CFLAGS) ..\thirds\dirent-win32\dirent.c
+
 zoo_loader.cgi: zoo_loader.obj zoo_service_loader.obj service_internal.obj service_internal_python.obj ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj dirent.obj
-	link zoo_loader.obj dirent.obj service_internal.obj service_internal_python.obj ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj  zoo_service_loader.obj /out:zoo_loader.cgi  $(GEODIR)/lib/libfcgi.lib $(GEODIR)/lib/libcurl_imp.lib  $(GEODIR)/apps/Python25/libs/python25.lib $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/libcgic.lib $(GEODIR)/lib/gdal_i.lib $(TOOLS)\..\lib\libeay32.dll.a $(TOOLS)\..\lib\libcrypto.a $(TOOLS)\..\lib\libssl32.dll.a /machine:i386 
+	link zoo_loader.obj dirent.obj service_internal.obj service_internal_python.obj ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj  zoo_service_loader.obj /out:zoo_loader.cgi $(LDFLAGS)
 
 clean:
-	erase -f *.obj *.tab.c* *.tab.h *.sr.c* lex.* *.lreg *.sibling
+	erase -f *.cgi *.obj *.tab.c* *.tab.h *.sr.c* lex.* *.lreg *.sibling
Index: branches/branch-1.2/zoo-kernel/nmake.opt
===================================================================
--- branches/branch-1.2/zoo-kernel/nmake.opt	(revision 217)
+++ branches/branch-1.2/zoo-kernel/nmake.opt	(revision 217)
@@ -0,0 +1,14 @@
+LIBINTL_CPATH=..\..\..\
+PYTHON_CPATH=..\..\..\
+TPATH=..\..\..\tools
+GEODIR=c:/OSGeo4W
+DESTDIR=c:/OSGeo4W
+TOOLS=$(TPATH)\bin
+
+CC=cl $(CFLAGS)
+CPP=cl /TP $(CFLAGS)
+
+CFLAGS=-DUSE_PYTHON /EHa /nologo /MT /W3 /EHsc /O2 /D_CRT_SECURE_NO_WARNINGS /DWIN32 $(CJFLAGS) -I./ -I..\thirds\dirent-win32 -I$(PYTHON_CPATH)\include -I$(GEODIR)/include -ILIBINTL_CPATH\include -I$(TPATH)\include -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
+
+LDFLAGS=$(GEODIR)/lib/libfcgi.lib $(GEODIR)/lib/libcurl_im
+p.lib  $(GEODIR)/apps/Python25/libs/python25.lib $(GEODIR)/lib/libxml2.lib ../thirds/cgic206/libcgic.lib $(GEODIR)/lib/gdal_i.lib $(TOOLS)\..\lib\libeay32.dll.a $(TOOLS)\..\lib\libcrypto.a $(TOOLS)\..\lib\libssl32.dll.a $(TOOLS)\..\lib\libintl.lib /machine:i386 
Index: branches/branch-1.2/zoo-kernel/service.h
===================================================================
--- branches/branch-1.2/zoo-kernel/service.h	(revision 111)
+++ branches/branch-1.2/zoo-kernel/service.h	(revision 217)
@@ -28,4 +28,10 @@
 #pragma once
 
+#ifdef WIN32
+#define strncasecmp strnicmp
+#define strcasecmp stricmp
+#define snprintf sprintf_s
+#endif 
+
 #ifdef __cplusplus
 extern "C" {
@@ -55,4 +61,27 @@
 #define SHMSZ     27
 
+
+  /**
+   * \struct map
+   * \brief KVP linked list
+   *
+   * Deal with WPS KVP (name,value).
+   * A map is defined as:
+   *  - name : a key,
+   *  - value: a value,
+   *  - next : a pointer to the next map if any.
+   */
+  typedef struct map{
+    char* name;
+    char* value;
+    struct map* next;
+  } map;
+
+#ifdef WIN32
+#define NULLMAP ((map*) 0)
+#else
+#define NULLMAP NULL
+#endif
+
   /**
    * \struct maps
@@ -60,4 +89,8 @@
    *
    * Small object to store WPS KVP set.
+   * Maps is defined as:
+   *  - a name, 
+   *  - a content map,
+   *  - a pointer to the next maps if any.
    */
   typedef struct maps{
@@ -68,21 +101,6 @@
 
   /**
-   * \struct map
-   * \brief KVP linked list
-   *
-   * Deal with WPS KVP (name,value).
+   * \brief Dump a map on stderr
    */
-  typedef struct map{
-    char* name;       /* The key */
-    char* value;      /* The value */
-    struct map* next; /* Next couple */
-  } map;
-
-#ifdef WIN32
-#define NULLMAP ((map*) 0)
-#else
-#define NULLMAP NULL
-#endif
-
   static void _dumpMap(map* t){
     if(t!=NULL){
@@ -181,5 +199,16 @@
   }
 
-  static map* getMapFromMaps(maps* m,char* key,char* subkey){
+  static map* getLastMap(map* m){
+    map* tmp=m;
+    while(tmp!=NULL){
+      if(tmp->next==NULL){
+	return tmp;
+      }
+      tmp=tmp->next;
+    }
+    return NULL;
+  }
+
+  static map* getMapFromMaps(maps* m,const char* key,const char* subkey){
     maps* _tmpm=getMaps(m,key);
     if(_tmpm!=NULL){
@@ -189,4 +218,52 @@
     else return NULL;
   }
+
+  static char* getMapsAsKVP(maps* m,int length,int type){
+    char *dataInputsKVP=(char*) malloc(length*sizeof(char));
+    maps* curs=m;
+    int i=0;
+    while(curs!=NULL){
+      if(i==0)
+	if(type==0)
+	  sprintf(dataInputsKVP,"%s=",curs->name);
+	else
+	  sprintf(dataInputsKVP,"%s",curs->name);
+      else{
+	char *temp=strdup(dataInputsKVP);
+	if(type==0)
+	  sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
+	else
+	  sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
+	free(temp);
+      }
+      map* icurs=curs->content;
+      if(type==0){
+	map* tmp=getMap(curs->content,"value");
+	char *temp=strdup(dataInputsKVP);
+	if(getMap(m->content,"xlink:href")!=NULL)
+	  sprintf(dataInputsKVP,"%sReference",temp);
+	else
+	  sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
+	free(temp);
+      }
+      int j=0;
+      while(icurs!=NULL){
+	if(strcasecmp(icurs->name,"value")!=0 &&
+	   strcasecmp(icurs->name,"Reference")!=0 &&
+	   strcasecmp(icurs->name,"minOccurs")!=0 &&
+	   strcasecmp(icurs->name,"maxOccurs")!=0 &&
+	   strcasecmp(icurs->name,"inRequest")!=0){
+	  char *itemp=strdup(dataInputsKVP);
+	  sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
+	  free(itemp);
+	}
+	icurs=icurs->next;
+      }
+      curs=curs->next;
+      i++;
+    }
+    return dataInputsKVP;
+  }
+
 
   static void freeMap(map** mo){
@@ -224,4 +301,13 @@
   }
 
+  /**
+   * \brief Not named linked list
+   *
+   * Used to store informations about formats, such as mimeType, encoding ... 
+   *
+   * An iotype is defined as :
+   *  - a content map,
+   *  - a pointer to the next iotype if any.
+   */
   typedef struct iotype{
     struct map* content;
@@ -229,4 +315,18 @@
   } iotype;
 
+  /**
+   * \brief Metadata information about input or output.
+   *
+   * The elements are used to store metadata informations defined in the ZCFG.
+   *
+   * An elements is defined as :
+   *  - a name,
+   *  - a content map,
+   *  - a metadata map,
+   *  - a format (possible values are LiteralData, ComplexData or 
+   * BoundingBoxData),
+   *  - a default iotype,
+   *  - a pointer to the next elements id any.
+   */
   typedef struct elements{
     char* name;
@@ -252,5 +352,5 @@
   } services;
 
-  static bool hasElement(elements* e,char* key){
+  static bool hasElement(elements* e,const char* key){
     elements* tmp=e;
     while(tmp!=NULL){
@@ -476,10 +576,11 @@
 
 
-  static void setMapInMaps(maps* m,char* key,char* subkey,char *value){
+  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
     maps* _tmpm=getMaps(m,key);
     if(_tmpm!=NULL){
       map* _ztmpm=getMap(_tmpm->content,subkey);
       if(_ztmpm!=NULL){
-	free(_ztmpm->value);
+	if(_ztmpm->value!=NULL)
+	  free(_ztmpm->value);
 	_ztmpm->value=strdup(value);
       }else{
Index: branches/branch-1.2/zoo-kernel/service_conf.l
===================================================================
--- branches/branch-1.2/zoo-kernel/service_conf.l	(revision 111)
+++ branches/branch-1.2/zoo-kernel/service_conf.l	(revision 217)
@@ -41,10 +41,10 @@
 
 attname	[a-zA-Z0-9_\-]+
-attvalue1	[\^\*\+,;@a-zA-Z0-9_\-::.:" "\"\'/\\\(\)]+
+attvalue1	[\^\*\+,;@a-zA-Z0-9_\-::.:" "\"\'/\\\(\)\t\|]+
 
 attvalue		\"[^"]*\"|\'[^']*\'\(\)
 
-whitespace                      [ ]{0,}
-whitesp                      [ ]
+whitespace                      [\t]{0,}|[ ]{0,}
+whitesp                      [\t]|[ ]
 newline                 [\r\n]|[\n]
 newlines                 [\r\n]{1,}|[\n]{1,}
Index: branches/branch-1.2/zoo-kernel/service_conf.y
===================================================================
--- branches/branch-1.2/zoo-kernel/service_conf.y	(revision 111)
+++ branches/branch-1.2/zoo-kernel/service_conf.y	(revision 217)
@@ -36,5 +36,4 @@
 static int previous_data=0;
 static int current_data=0;
-static char* myFinalObjectAsJSON="{";
 // namespace
 using namespace std;
@@ -42,5 +41,5 @@
 
 // srerror
-void srerror(char *s);
+void srerror(const char *s);
 //======================================================
 
@@ -713,5 +712,5 @@
 /* fonction qui affiche l erreur si il y en a une */
 //======================================================
-void srerror(char *s)
+void srerror(const char *s)
 {
   if(debug)
@@ -724,5 +723,5 @@
  * definition file.
  */
-int getServiceFromFile(char* file,service** service){
+int getServiceFromFile(const char* file,service** service){
 
   freeMap(&previous_content);
@@ -802,5 +801,7 @@
   *service=my_service;
 
+#ifndef WIN32
   srlex_destroy();
+#endif
   return resultatYYParse;
 }
Index: branches/branch-1.2/zoo-kernel/service_internal.c
===================================================================
--- branches/branch-1.2/zoo-kernel/service_internal.c	(revision 111)
+++ branches/branch-1.2/zoo-kernel/service_internal.c	(revision 217)
@@ -25,5 +25,26 @@
 #include "service_internal.h"
 
-void *addLangAttr(xmlNodePtr n,maps *m){
+#ifdef WIN32
+char *
+strtok_r (char *s1, const char *s2, char **lasts)
+{
+  char *ret;
+  if (s1 == NULL)
+    s1 = *lasts;
+  while (*s1 && strchr(s2, *s1))
+    ++s1;
+  if (*s1 == '\0')
+    return NULL;
+  ret = s1;
+  while (*s1 && !strchr(s2, *s1))
+    ++s1;
+  if (*s1)
+    *s1++ = '\0';
+  *lasts = s1;
+  return ret;
+}
+#endif
+
+void addLangAttr(xmlNodePtr n,maps *m){
   map *tmpLmap=getMapFromMaps(m,"main","language");
   if(tmpLmap!=NULL)
@@ -44,5 +65,113 @@
 }
 
-void* unhandleStatus(maps *conf){
+#ifdef WIN32
+
+#include <windows.h>
+#include <stdio.h>
+#include <conio.h>
+#include <tchar.h>
+
+#define SHMEMSIZE 4096
+
+static LPVOID lpvMemG = NULL;      // pointer to shared memory
+static HANDLE hMapObjectG = NULL;  // handle to file mapping
+
+void updateStatus(maps *conf){
+	fprintf(stderr,"OK Final 1 \n");
+	fflush(stderr);
+	LPWSTR lpszTmp;
+	BOOL fInit;
+	char *s=NULL;
+	map *tmpMap=getMapFromMaps(conf,"lenv","sid");
+	fprintf(stderr,"OK Final 11 \n");
+	fflush(stderr);
+	if(hMapObjectG==NULL)
+	hMapObjectG = CreateFileMapping( 
+		INVALID_HANDLE_VALUE,   // use paging file
+		NULL,                   // default security attributes
+		PAGE_READWRITE,         // read/write access
+		0,                      // size: high 32-bits
+		SHMEMSIZE,              // size: low 32-bits
+		TEXT(tmpMap->value));   // name of map object
+	if (hMapObjectG == NULL){
+		fprintf(stderr,"Unable to create share memory segment %s !! \n",tmpMap->value);
+		return ;
+	}
+	fprintf(stderr,"OK Final 2 \n");
+	fflush(stderr);
+	fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 
+	if(lpvMemG==NULL)
+	lpvMemG = MapViewOfFile( 
+		hMapObjectG,     // object to map view of
+		FILE_MAP_WRITE, // read/write access
+		0,              // high offset:  map from
+		0,              // low offset:   beginning
+		0);             // default: map entire file
+	if (lpvMemG == NULL){
+		fprintf(stderr,"Unable to create or access the shared memory segment %s !! \n",tmpMap->value);
+		return ;
+	} 
+	fprintf(stderr,"OK Final 3 \n");
+	fflush(stderr);
+	if (fInit)
+		memset(lpvMemG, '\0', SHMEMSIZE);
+	fprintf(stderr,"OK Final 4 \n");
+	fflush(stderr);
+	tmpMap=getMapFromMaps(conf,"lenv","status");
+	lpszTmp = (LPWSTR) lpvMemG;
+	for(s=tmpMap->value;*s!=NULL;s++)
+		*lpszTmp++ = *s;
+	*lpszTmp = '\0'; 
+}
+
+char* getStatus(int pid){
+  LPWSTR lpszBuf=NULL;
+  LPWSTR lpszTmp=NULL;
+  LPVOID lpvMem = NULL;
+  HANDLE hMapObject = NULL;
+  BOOL fIgnore,fInit;
+  char tmp[100];
+  sprintf(tmp,"%i",pid);
+  if(hMapObject==NULL)
+    hMapObject = CreateFileMapping( 
+				   INVALID_HANDLE_VALUE,   // use paging file
+				   NULL,                   // default security attributes
+				   PAGE_READWRITE,         // read/write access
+				   0,                      // size: high 32-bits
+				   4096,                   // size: low 32-bits
+				   TEXT(tmp));   // name of map object
+  if (hMapObject == NULL) 
+    return FALSE;
+  if((GetLastError() != ERROR_ALREADY_EXISTS)){
+    fIgnore = UnmapViewOfFile(lpvMem); 
+    fIgnore = CloseHandle(hMapObject);
+    return "-1";
+  }
+  fInit=TRUE;
+  if(lpvMem==NULL)
+    lpvMem = MapViewOfFile( 
+			   hMapObject,     // object to map view of
+			   FILE_MAP_READ,  // read/write access
+			   0,              // high offset:  map from
+			   0,              // low offset:   beginning
+			   0);             // default: map entire file
+  if (lpvMem == NULL) 
+    return "-1"; 
+  lpszTmp = (LPWSTR) lpvMem;
+  while (*lpszTmp!=NULL)
+    *lpszBuf++ = *lpszTmp++;
+  *lpszBuf = '\0';
+  fIgnore = UnmapViewOfFile(lpvMem); 
+  fIgnore = CloseHandle(hMapObject);
+  return (char*)lpszBuf;
+}
+
+void unhandleStatus(maps *conf){
+  BOOL fIgnore;
+  fIgnore = UnmapViewOfFile(lpvMemG); 
+  fIgnore = CloseHandle(hMapObjectG);
+}
+#else
+void unhandleStatus(maps *conf){
   int shmid,i;
   key_t key;
@@ -69,4 +198,57 @@
   }
 }
+
+void updateStatus(maps *conf){
+  int shmid,i;
+  key_t key;
+  char *shm,*s,*s1;
+  map *tmpMap=NULL;
+  tmpMap=getMapFromMaps(conf,"lenv","sid");
+  if(tmpMap!=NULL){
+    key=atoi(tmpMap->value);
+    if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
+#ifdef DEBUG
+      fprintf(stderr,"shmget failed to update value\n");
+#endif
+    }else{
+      if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) {
+#ifdef DEBUG
+	fprintf(stderr,"shmat failed to update value\n");
+#endif
+      }
+      else{
+	tmpMap=getMapFromMaps(conf,"lenv","status");
+	s1=shm;
+	for(s=tmpMap->value;s!=NULL;s++)
+	  *s1++=*s;
+	shmdt((void *)shm);
+      }
+    }
+  }
+}
+
+char* getStatus(int pid){
+  int shmid,i;
+  key_t key;
+  void *shm;
+  char *s;
+  key=pid;
+  if ((shmid = shmget(key, SHMSZ, 0666)) < 0) {
+#ifdef DEBUG
+    fprintf(stderr,"shmget failed in getStatus\n");
+#endif
+  }else{
+    if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
+#ifdef DEBUG
+      fprintf(stderr,"shmat failed in getStatus\n");
+#endif
+    }else{
+      return (char*)shm;
+    }
+  }
+  return "-1";
+}
+
+#endif
 
 #ifdef USE_JS
@@ -109,54 +291,4 @@
 #endif
 
-void* updateStatus(maps *conf){
-  int shmid,i;
-  key_t key;
-  char *shm,*s,*s1;
-  map *tmpMap=NULL;
-  tmpMap=getMapFromMaps(conf,"lenv","sid");
-  if(tmpMap!=NULL){
-    key=atoi(tmpMap->value);
-    if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
-#ifdef DEBUG
-      fprintf(stderr,"shmget failed to update value\n");
-#endif
-    }else{
-      if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) {
-#ifdef DEBUG
-	fprintf(stderr,"shmat failed to update value\n");
-#endif
-      }
-      else{
-	tmpMap=getMapFromMaps(conf,"lenv","status");
-	s1=shm;
-	for(s=tmpMap->value;*s!=NULL;s++)
-	  *s1++=*s;
-	shmdt((void *)shm);
-      }
-    }
-  }
-}
-
-char* getStatus(int pid){
-  int shmid,i;
-  key_t key;
-  void *shm;
-  char *s;
-  key=pid;
-  if ((shmid = shmget(key, SHMSZ, 0666)) < 0) {
-#ifdef DEBUG
-    fprintf(stderr,"shmget failed in getStatus\n");
-#endif
-  }else{
-    if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
-#ifdef DEBUG
-      fprintf(stderr,"shmat failed in getStatus\n");
-#endif
-    }else{
-      return (char*)shm;
-    }
-  }
-  return "-1";
-}
 
 
@@ -216,5 +348,5 @@
 
 
-int zooXmlSearchForNs(char* name){
+int zooXmlSearchForNs(const char* name){
   int i;
   int res=-1;
@@ -227,5 +359,5 @@
 }
 
-int zooXmlAddNs(xmlNodePtr nr,char* url,char* name){
+int zooXmlAddNs(xmlNodePtr nr,const char* url,const char* name){
 #ifdef DEBUG
   fprintf(stderr,"zooXmlAddNs %d \n",nbNs);
@@ -266,5 +398,5 @@
 }
 
-xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,char* service,maps* m){
+xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,const char* service,maps* m){
 
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
@@ -618,5 +750,5 @@
 }
 
-xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){
+xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,const char* service,maps* m){
 
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
@@ -711,5 +843,5 @@
 }
 
-void printFullDescription(elements *elem,char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){
+void printFullDescription(elements *elem,const char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){
   char *orderedFields[7];
   orderedFields[0]="mimeType";
@@ -957,5 +1089,5 @@
 }
 
-void printProcessResponse(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){
+void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
   xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor;
@@ -1192,5 +1324,5 @@
     int buffersize;
     xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1);
-    fwrite(xmlbuff,1,strlen(xmlbuff)*sizeof(char),output);
+    fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output);
     xmlFree(xmlbuff);
     fclose(output);
@@ -1204,5 +1336,4 @@
 
 void printDocument(maps* m, xmlDocPtr doc,int pid){
-  rewind(stdout);
   char *encoding=getEncoding(m);
   if(pid==getpid()){
@@ -1217,6 +1348,6 @@
    */
   xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
-  printf((char *) xmlbuff);
-  //fflush(stdout);
+  printf("%s",xmlbuff);
+  fflush(stdout);
   /*
    * Free associated memory.
@@ -1228,5 +1359,5 @@
 }
 
-void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){
+void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){
   xmlNodePtr nc1;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
@@ -1260,5 +1391,5 @@
 }
 
-void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){
+void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,const char* type){
   xmlNodePtr nc1,nc2,nc3;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
@@ -1288,5 +1419,5 @@
 }
 
-void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,char* type){
+void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){
   xmlNodePtr nc1,nc2,nc3;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
@@ -1443,5 +1574,5 @@
 }
 
-void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,char* identifier,map* amap){
+void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap){
   xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
   xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
@@ -1527,5 +1658,5 @@
   maps* tmpMap=getMaps(m,"main");
 
-  int nsid=zooXmlAddNs(NULL,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
+  int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
   ns=usedNs[nsid];
   n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
@@ -1708,5 +1839,5 @@
 	  freeMap(&errormap);
 	  free(errormap);
-	  return 1;
+	  return;
 	}
 	char mime[1024];
@@ -1757,5 +1888,5 @@
 }
 
-char *base64(const unsigned char *input, int length)
+char *base64(const char *input, int length)
 {
   BIO *bmem, *b64;
@@ -1779,5 +1910,5 @@
 }
 
-char *base64d(unsigned char *input, int length,int* red)
+char *base64d(const char *input, int length,int* red)
 {
   BIO *b64, *bmem;
@@ -1788,5 +1919,5 @@
     b64 = BIO_new(BIO_f_base64());
     if(b64){
-      bmem = BIO_new_mem_buf(input,length);
+      bmem = BIO_new_mem_buf((unsigned char*)input,length);
       bmem = BIO_push(b64, bmem);
       *red=BIO_read(bmem, buffer, length);
@@ -1972,9 +2103,9 @@
  * Note : support only 2D bounding box.
  */
-map* parseBoundingBox(char* value){
+map* parseBoundingBox(const char* value){
   map *res=NULL;
   if(value!=NULL){
     char *cv,*cvp;
-    cv=strtok_r(value,",",&cvp);
+    cv=strtok_r((char*) value,",",&cvp);
     int cnt=0;
     int icnt=0;
@@ -2078,5 +2209,5 @@
   ns_ows=usedNs[owsId];
   n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox");
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1","ows");
+  xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
   int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
   ns_xsi=usedNs[xsiId];
@@ -2089,5 +2220,5 @@
   xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
   if(file==NULL)
-    printf((char *) xmlbuff);
+    printf("%s",xmlbuff);
   else{
     fprintf(file,"%s",xmlbuff);
Index: branches/branch-1.2/zoo-kernel/service_internal.h
===================================================================
--- branches/branch-1.2/zoo-kernel/service_internal.h	(revision 111)
+++ branches/branch-1.2/zoo-kernel/service_internal.h	(revision 217)
@@ -38,6 +38,10 @@
 #include <sys/stat.h>
 #include <sys/types.h>
+#ifndef WIN32
 #include <sys/ipc.h>
 #include <sys/shm.h>
+#else
+#include <direct.h>
+#endif
 #include <stdio.h>
 #include <unistd.h>
@@ -54,6 +58,6 @@
 #include <openssl/buffer.h>
 
-extern   int getServiceFromFile(char*,service**);
-extern   int conf_read(char*,maps*);
+extern   int getServiceFromFile(const char*,service**);
+extern   int conf_read(const char*,maps*);
 
 #ifdef USE_JS
@@ -71,6 +75,6 @@
   static int nbNs=0;
 
-  void* unhandleStatus(maps*);
-  void* updateStatus(maps*);
+  void unhandleStatus(maps*);
+  void updateStatus(maps*);
   char* getStatus(int);
 
@@ -84,28 +88,28 @@
   char* getEncoding(maps*);
 
-  int zooXmlSearchForNs(char*);
-  int zooXmlAddNs(xmlNodePtr,char*,char*);
+  int zooXmlSearchForNs(const char*);
+  int zooXmlAddNs(xmlNodePtr,const char*,const char*);
   void zooXmlCleanupNs();
   
   void printExceptionReportResponse(maps*,map*);
   xmlNodePtr createExceptionReportNode(maps*,map*,int);
-  void printProcessResponse(maps*,map*,int,service*,char*,int,maps*,maps*);
-  xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,char*,maps*);
+  void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*);
+  xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,const char*,maps*);
   void printGetCapabilitiesForProcess(maps*,xmlNodePtr,service*);
-  xmlNodePtr printDescribeProcessHeader(xmlDocPtr,char*,maps*);
+  xmlNodePtr printDescribeProcessHeader(xmlDocPtr,const char*,maps*);
   void printDescribeProcessForProcess(maps*,xmlNodePtr,service*,int);
-  void printFullDescription(elements*,char*,xmlNsPtr,xmlNodePtr);
+  void printFullDescription(elements*,const char*,xmlNsPtr,xmlNodePtr);
   void printDocument(maps*,xmlDocPtr,int);
-  void printDescription(xmlNodePtr,xmlNsPtr,char*,map*);
-  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,char*);
-  map* parseBoundingBox(char*);
+  void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*);
+  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
+  map* parseBoundingBox(const char*);
   void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
   void printBoundingBoxDocument(maps*,maps*,FILE*);
-  void printOutputDefinitions1(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,char*);
+  void printOutputDefinitions1(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
   
   void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
 
-  char *base64(const unsigned char*,int);
-  char *base64d(unsigned char*,int,int*);
+  char *base64(const char*,int);
+  char *base64d(const char*,int,int*);
   void ensureDecodedBase64(maps**);
 
Index: branches/branch-1.2/zoo-kernel/service_internal_java.c
===================================================================
--- branches/branch-1.2/zoo-kernel/service_internal_java.c	(revision 111)
+++ branches/branch-1.2/zoo-kernel/service_internal_java.c	(revision 217)
@@ -2,5 +2,5 @@
  * Author : Gérald FENOY
  *
- * Copyright (c) 2009-2010 GeoLabs SARL
+ * Copyright (c) 2009-2011 GeoLabs SARL
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -118,5 +118,5 @@
 
       pValue=(*env)->CallStaticIntMethod(env,cls,pmid,arg1,arg2,arg3);
-      if (pValue != NULL){
+      if (pValue != (jint)NULL){
 	res=pValue;
 	m=mapsFromHashMap(env,arg1,scHashMapClass);
@@ -233,5 +233,7 @@
   jobject scObject,scObject1;
   if(scHashMapClass==NULL){
+#ifdef DEBUG
     fprintf(stderr,"Unable to load java.util.HashMap\n");
+#endif
     return NULL;
   }
@@ -239,12 +241,21 @@
   containsKey_mid = (*env)->GetMethodID(env, scHashMapClass, "containsKey", "(Ljava/lang/Object;)Z");
   get_mid = (*env)->GetMethodID(env, scHashMapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); 
+
   if(containsKey_mid==0){
+#ifdef DEBUG
     fprintf(stderr,"unable to load containsKey from HashMap object (%d) \n",entrySet_mid);
+#endif
+    return NULL;
   }
   if(get_mid==0){
+#ifdef DEBUG
     fprintf(stderr,"unable to load get from HashMap object (%d) \n",entrySet_mid);
+#endif
+    return NULL;
   }
   if(entrySet_mid==0){
+#ifdef DEBUG
     fprintf(stderr,"unable to load entrySet from HashMap object (%d) \n",entrySet_mid);
+#endif
     return NULL;
   }
@@ -296,7 +307,8 @@
     if((*env)->CallBooleanMethod(env,imap,containsKey_mid,(*env)->NewStringUTF(env,"size"))){
       jobject sizeV=(*env)->CallObjectMethod(env, imap, get_mid,(*env)->NewStringUTF(env,"size"));
-      jstring sizeVS=(*env)->GetStringUTFChars(env, sizeV, NULL);
+      const char* sizeVS=(*env)->GetStringUTFChars(env, sizeV, NULL);
       size=atoi(sizeVS);
       fprintf(stderr,"SIZE : %s\n",sizeVS);
+      (*env)->ReleaseStringUTFChars(env, sizeV, sizeVS);
     }
     
@@ -306,7 +318,6 @@
       jobject jv=(*env)->CallObjectMethod(env,tmp1,getValue_mid);
 
-      jstring jkd=(*env)->GetStringUTFChars(env, jk, NULL);
+      const char* jkd=(*env)->GetStringUTFChars(env, jk, NULL);
       if(size>=0 && strcmp(jkd,"value")==0){
-	fprintf(stderr,"%s\n",jkd);
 	jobject value=(*env)->GetByteArrayElements(env, jv, NULL);
 	if(res==NULL){
@@ -315,5 +326,4 @@
 	  addToMap(res,jkd,"");
 	}
-	fprintf(stderr,"/%s\n",jkd);
 	map* tmpR=getMap(res,"value");
 	free(tmpR->value);
@@ -321,8 +331,10 @@
 	memmove(tmpR->value,value,size*sizeof(char));
 	tmpR->value[size]=0;
-	fprintf(stderr,"/%s\n",jkd);
+	char tmp[128];
+	sprintf(tmp,"%d",size);
+	addToMap(res,"size",tmp);
       }
       else{
-	jstring jvd=(*env)->GetStringUTFChars(env, jv, NULL);
+	const char* jvd=(*env)->GetStringUTFChars(env, jv, NULL);
 	if(res==NULL){
 	  res=createMap(jkd,jvd);
@@ -330,12 +342,8 @@
 	  addToMap(res,jkd,jvd);
 	}
-	(*env)->ReleaseStringChars(env, jv, jvd);
+	(*env)->ReleaseStringUTFChars(env, jv, jvd);
       }
 
-#ifdef DEBUG
-      fprintf(stderr,"%s %s\n",jkd,jvd);
-#endif
-
-      (*env)->ReleaseStringChars(env, jk, jkd);
+      (*env)->ReleaseStringUTFChars(env, jk, jkd);
 
     }
Index: branches/branch-1.2/zoo-kernel/service_internal_python.c
===================================================================
--- branches/branch-1.2/zoo-kernel/service_internal_python.c	(revision 111)
+++ branches/branch-1.2/zoo-kernel/service_internal_python.c	(revision 217)
@@ -86,15 +86,15 @@
   }
   pModule = PyImport_Import(pName);
-  int i;
   int res=SERVICE_FAILED;
-  int cpid=getpid();
   if (pModule != NULL) {
     pFunc=PyObject_GetAttrString(pModule,s->name);
     if (pFunc && PyCallable_Check(pFunc)){
+      PyObject *pValue;
       PyDictObject* arg1=PyDict_FromMaps(m);
       PyDictObject* arg2=PyDict_FromMaps(inputs);
       PyDictObject* arg3=PyDict_FromMaps(outputs);
       PyObject *pArgs=PyTuple_New(3);
-      PyObject *pValue;
+      if (!pArgs)
+	return -1;
       PyTuple_SetItem(pArgs, 0, (PyObject *)arg1);
       PyTuple_SetItem(pArgs, 1, (PyObject *)arg2);
@@ -130,5 +130,4 @@
 	PyErr_Fetch(&ptype, &pvalue, &ptraceback);
 	PyObject *trace=PyObject_Str(pvalue);
-	char tb[1024];
 	char pbt[10240];
 	if(PyString_Check(trace))
@@ -145,5 +144,4 @@
 	else
 	  fprintf(stderr,"EMPTY TRACE ?");
-	PyObject *t;
 	pName = PyString_FromString("traceback");
 	pModule = PyImport_Import(pName);
@@ -302,5 +300,4 @@
   int nb=PyList_Size(list);
   int i;
-  int sizeValue=-1;
   for(i=0;i<nb;i++){
     PyObject* key=PyList_GetItem(list,i);
Index: branches/branch-1.2/zoo-kernel/zoo_loader.c
===================================================================
--- branches/branch-1.2/zoo-kernel/zoo_loader.c	(revision 111)
+++ branches/branch-1.2/zoo-kernel/zoo_loader.c	(revision 217)
@@ -26,4 +26,7 @@
 #define MALLOC_CHECK 0
 
+#ifdef WIN32
+#include "windows.h"
+#endif
 /**
  * Specific includes
@@ -45,5 +48,5 @@
 }
 
-xmlXPathObjectPtr extractFromDoc(xmlDocPtr,char*);
+xmlXPathObjectPtr extractFromDoc(xmlDocPtr,const char*);
 int runRequest(map*);
 
@@ -64,26 +67,4 @@
 /* ************************************************************************* */
 
-#ifndef STRTOK_R
-char *
-strtok_r (char *s1, const char *s2, char **lasts)
-{
-  char *ret;
-
-  if (s1 == NULL)
-    s1 = *lasts;
-  while (*s1 && strchr(s2, *s1))
-    ++s1;
-  if (*s1 == '\0')
-    return NULL;
-  ret = s1;
-  while (*s1 && !strchr(s2, *s1))
-    ++s1;
-  if (*s1)
-    *s1++ = '\0';
-  *lasts = s1;
-  return ret;
-}
-
-#endif
 
 #define TRUE 1
@@ -192,5 +173,5 @@
 	addToMap(tmpMap,"language",tval);
       
-      char* requests[3];
+      const char* requests[3];
       requests[0]="GetCapabilities";
       requests[1]="DescribeProcess";
@@ -206,5 +187,5 @@
 #endif
 	  if(req!=NULL && req->nodeNr==1){
-	    t1->value=requests[j];
+	    t1->value=strdup(requests[j]);
 	    j=2;
 	  }
Index: branches/branch-1.2/zoo-kernel/zoo_service_loader.c
===================================================================
--- branches/branch-1.2/zoo-kernel/zoo_service_loader.c	(revision 111)
+++ branches/branch-1.2/zoo-kernel/zoo_service_loader.c	(revision 217)
@@ -94,5 +94,5 @@
 }
 
-xmlXPathObjectPtr extractFromDoc(xmlDocPtr doc,char* search){
+xmlXPathObjectPtr extractFromDoc(xmlDocPtr doc,const char* search){
   xmlXPathContextPtr xpathCtx;
   xmlXPathObjectPtr xpathObj;
@@ -110,5 +110,5 @@
 void sig_handler(int sig){
   char tmp[100];
-  char *ssig;
+  const char *ssig;
   switch(sig){
   case SIGSEGV:
@@ -153,5 +153,5 @@
   map* r_inputs=NULL;
 #ifndef WIN32
-  getcwd(ntmp,1024);
+  char* pntmp=getcwd(ntmp,1024);
 #else
   _getcwd(ntmp,1024);
@@ -203,8 +203,4 @@
 #endif
       if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){
-#ifdef WIN32
-	//Strange return value needed here !
-	return 1;
-#endif
 	r_inputs=getMap(request_inputs,"Identifier");
 	char fname[1024];
@@ -284,5 +280,10 @@
 #endif
       }
+#ifdef WIN32
+      *ioutputs=dupMaps(&request_output_real_format);
+      FreeLibrary(so);
+#else
       dlclose(so);
+#endif
     } else {
       /**
@@ -345,6 +346,80 @@
 	      }
   *myMap=m;
+#ifndef WIN32
   *ioutputs=request_output_real_format;
+#endif
 }
+
+#ifdef WIN32
+/**
+ * createProcess function: create a new process after setting some env variables
+ */
+void createProcess(maps* m,map* request_inputs,service* s1,char* opts,int cpid, maps* inputs,maps* outputs){
+  STARTUPINFO si;
+  PROCESS_INFORMATION pi;
+  ZeroMemory( &si, sizeof(si) );
+  si.cb = sizeof(si);
+  ZeroMemory( &pi, sizeof(pi) );
+  char *tmp=(char *)malloc((1024+cgiContentLength)*sizeof(char));
+  char *tmpq=(char *)malloc((1024+cgiContentLength)*sizeof(char));
+  map *req=getMap(request_inputs,"request");
+  map *id=getMap(request_inputs,"identifier");
+  map *di=getMap(request_inputs,"DataInputs");
+
+  char *dataInputsKVP=getMapsAsKVP(inputs,cgiContentLength,0);
+  char *dataOutputsKVP=getMapsAsKVP(outputs,cgiContentLength,1);
+  fprintf(stderr,"DATAINPUTSKVP %s\n",dataInputsKVP);
+  fprintf(stderr,"DATAOUTPUTSKVP %s\n",dataOutputsKVP);
+  map *sid=getMapFromMaps(m,"lenv","sid");
+  map* r_inputs=getMapFromMaps(m,"main","tmpPath");
+  map* r_inputs1=getMap(s1->content,"ServiceProvider");
+  map* r_inputs2=getMap(s1->content,"ResponseDocument");
+  if(r_inputs2==NULL)
+    r_inputs2=getMap(s1->content,"RawDataOutput");
+  map *tmpPath=getMapFromMaps(m,"lenv","cwd");
+
+  if(r_inputs2!=NULL){
+    sprintf(tmp,"\"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"",req->value,id->value,dataInputsKVP,r_inputs2->name,r_inputs2->value,sid->value);
+	sprintf(tmpq,"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",req->value,id->value,dataInputsKVP,r_inputs2->name,dataOutputsKVP);
+  }
+  else{
+    sprintf(tmp,"\"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"",req->value,id->value,dataInputsKVP,sid->value);
+    sprintf(tmpq,"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",req->value,id->value,dataInputsKVP,sid->value);
+  }
+
+  char *tmp1=strdup(tmp);
+  sprintf(tmp,"zoo_loader.cgi %s \"%s\"",tmp1,sid->value);
+
+  free(dataInputsKVP);
+  free(dataOutputsKVP);
+  fprintf(stderr,"REQUEST IS : %s \n",tmp);
+  SetEnvironmentVariable("CGISID",TEXT(sid->value));
+  SetEnvironmentVariable("QUERY_STRING",TEXT(tmpq));
+  char clen[1000];
+  sprintf(clen,"%d",strlen(tmpq));
+  SetEnvironmentVariable("CONTENT_LENGTH",TEXT(clen));
+
+  if( !CreateProcess( NULL,             // No module name (use command line)
+		      TEXT(tmp),        // Command line
+		      NULL,             // Process handle not inheritable
+		      NULL,             // Thread handle not inheritable
+		      FALSE,            // Set handle inheritance to FALSE
+		      CREATE_NO_WINDOW, // Apache won't wait until the end
+		      NULL,             // Use parent's environment block
+		      NULL,             // Use parent's starting directory 
+		      &si,              // Pointer to STARTUPINFO struct
+		      &pi )             // Pointer to PROCESS_INFORMATION struct
+      ) 
+    { 
+      fprintf( stderr, "CreateProcess failed (%d).\n", GetLastError() );
+      return ;
+    }else{
+    fprintf( stderr, "CreateProcess successfull (%d).\n\n\n\n", GetLastError() );
+  }
+  CloseHandle( pi.hProcess );
+  CloseHandle( pi.hThread );
+  fprintf(stderr,"CreateProcess finished !\n");
+}
+#endif
 
 int runRequest(map* request_inputs)
@@ -360,7 +435,6 @@
 #endif
 
-  map* r_inputs=NULL,*tmps=NULL;
+  map* r_inputs=NULL;
   maps* m=NULL;
-  int argc=count(request_inputs);
 
   char* REQUEST=NULL;
@@ -374,5 +448,5 @@
   char ntmp[1024];
 #ifndef WIN32
-  getcwd(ntmp,1024);
+  char *pntmp=getcwd(ntmp,1024);
 #else
   _getcwd(ntmp,1024);
@@ -470,5 +544,4 @@
   }
 
-  map* outputs=NULL;
   maps* request_output_real_format=NULL;
   map* tmpm=getMapFromMaps(m,"main","serverAddress");
@@ -478,5 +551,4 @@
     SERVICE_URL=strdup(DEFAULT_SERVICE_URL);
 
-  service* s[100];
   service* s1;
   int scount=0;
@@ -497,5 +569,4 @@
 
   if(strncasecmp(REQUEST,"GetCapabilities",15)==0){
-    int i=0;
     struct dirent *dp;
 #ifdef DEBUG
@@ -510,5 +581,4 @@
     r_inputs=getMap(request_inputs,"ServiceProvider");
     xmlNodePtr n;
-    //dumpMap(request_inputs);
     if(r_inputs!=NULL)
       n = printGetCapabilitiesHeader(doc,r_inputs->value,m);
@@ -516,6 +586,6 @@
       n = printGetCapabilitiesHeader(doc,"",m);
     /**
-     * Strange, here we need to close stdout to ensure that no uneeded 
-     * char will be printed (parser issue ?)
+     * Here we need to close stdout to ensure that not supported chars 
+     * has been found in the zcfg and then printed on stdout
      */
     int saved_stdout = dup(fileno(stdout));
@@ -595,7 +665,4 @@
       char buff[256];
       char buff1[1024];
-      int i=0;
-      int j=0;
-      int end=-1;
       int saved_stdout = dup(fileno(stdout));
       dup2(fileno(stderr),fileno(stdout));
@@ -611,5 +678,4 @@
 	    memset(buff1,0,1024);
 	    snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name);
-	    //s1=(service*)malloc(sizeof(service*));
 	    s1=(service*)calloc(1,SERVICE_SIZE);
 	    if(s1 == NULL){
@@ -640,5 +706,4 @@
       free(SERVICE_URL);
       fflush(stdout);
-      //xmlFree(n);
 #ifndef LINUX_FREE_ISSUE
       if(s1)
@@ -654,5 +719,4 @@
 #endif	
 	closedir(dirp);
-	free(s);
 	return 0;
       }
@@ -682,12 +746,14 @@
 #endif
   int saved_stdout = dup(fileno(stdout));
-  dup2(fileno(stderr),fileno(stdout));
+    dup2(fileno(stderr),fileno(stdout));
   t=getServiceFromFile(tmps1,&s1);
   fflush(stdout);
   dup2(saved_stdout,fileno(stdout));
   if(t<0){
-    char tmpMsg[2048+strlen(r_inputs->value)];
+    char *tmpMsg=(char*)malloc(2048+strlen(r_inputs->value));
+    
     sprintf(tmpMsg,_("The value for <indetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),r_inputs->value);
     errorException(m, tmpMsg, "InvalidParameterValue");
+    free(tmpMsg);
     freeService(&s1);
     free(s1);
@@ -698,11 +764,9 @@
     return 0;
   }
-  close(saved_stdout);
+  //close(saved_stdout);
 
 #ifdef DEBUG
   dumpService(s1);
 #endif
-  map* inputs=NULL;
-  elements* c_inputs=s1->inputs;
   int j;
   
@@ -747,5 +811,4 @@
       fprintf(stderr,"OUTPUT Parsing start now ... \n");
 #endif
-      char current_output_as_string[10240];
       char cursor_output[10240];
       char *cotmp=strdup(r_inputs->value);
@@ -753,5 +816,4 @@
       free(cotmp);
       j=0;
-      map* request_kvp_outputs=NULL;
 	
       /**
@@ -834,5 +896,4 @@
 	fflush(stderr);
 #endif
-	//tmp_output=tmp_output->next;
 	free(tmp);
       }
@@ -848,5 +909,4 @@
     fprintf(stderr,"DATA INPUTS [%s]\n",r_inputs->value);
 #endif
-    char current_input_as_string[40960];
     char cursor_input[40960];
     if(r_inputs!=NULL)
@@ -864,5 +924,4 @@
     }
     j=0;
-    map* request_kvp_inputs=NULL;
   
     /**
@@ -905,7 +964,12 @@
 	char tmpn[256];
 	memset(tmpn,0,256);
-	strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char));
-	tmpn[strlen(tmpc)-strlen(tmpv)]=0;
-	int cnt=0;
+	if(tmpv!=NULL){
+	  strncpy(tmpn,tmpc,(strlen(tmpc)-strlen(tmpv))*sizeof(char));
+	  tmpn[strlen(tmpc)-strlen(tmpv)]=0;
+	}
+	else{
+	  strncpy(tmpn,tmpc,strlen(tmpc)*sizeof(char));
+	  tmpn[strlen(tmpc)]=0;
+	}
 #ifdef DEBUG
 	fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1);
@@ -917,5 +981,8 @@
 	  }
 	  tmpmaps->name=strdup(tmpn);
-	  tmpmaps->content=createMap("value",tmpv+1);
+	  if(tmpv!=NULL)
+	    tmpmaps->content=createMap("value",tmpv+1);
+	  else
+	    tmpmaps->content=createMap("value","Reference");
 	  tmpmaps->next=NULL;
 	}
@@ -931,6 +998,22 @@
 	  char tmpn1[1024];
 	  memset(tmpn1,0,1024);
-	  strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1));
-	  tmpn1[strlen(tmpc)-strlen(tmpv1)]=0;
+	  if(tmpv1!=NULL){
+	    strncpy(tmpn1,tmpc,strlen(tmpc)-strlen(tmpv1));
+	    tmpn1[strlen(tmpc)-strlen(tmpv1)]=0;
+	    addToMap(tmpmaps->content,tmpn1,tmpv1+1);
+	  }
+	  else{
+	    strncpy(tmpn1,tmpc,strlen(tmpc));
+	    tmpn1[strlen(tmpc)]=0;
+	    map* lmap=getLastMap(tmpmaps->content);
+	    char *tmpValue=(char*)calloc((strlen(lmap->value)+strlen(tmpc)+1),sizeof(char));
+	    sprintf(tmpValue,"%s@%s",lmap->value,tmpc);
+	    free(lmap->value);
+	    lmap->value=strdup(tmpValue);
+	    free(tmpValue);
+	    dumpMap(tmpmaps->content);
+	    tmpc=strtok(NULL,"@");
+	    continue;
+	  }
 #ifdef DEBUG
 	  fprintf(stderr,"*** NAME NON URL-ENCODED \n***%s***\n",tmpn1);
@@ -939,41 +1022,59 @@
 	  if(strcmp(tmpn1,"xlink:href")!=0)
 	    addToMap(tmpmaps->content,tmpn1,tmpv1+1);
-	  else{
-#ifdef DEBUG
-	    fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);
+	  else
+	    if(tmpv1!=NULL){
+	      if(strncasecmp(tmpv1+1,"http://",7)!=0 &&
+		 strncasecmp(tmpv1+1,"ftp://",6)!=0){
+		char emsg[1024];
+		sprintf(emsg,_("Unable to find a valid protocol to download the remote file %s"),tmpv1+1);
+		errorException(m,emsg,"InternalError");
+		freeMaps(&m);
+		free(m);
+		free(REQUEST);
+		free(SERVICE_URL);
+		InternetCloseHandle(hInternet);
+		freeService(&s1);
+		free(s1);
+		return 0;
+	      }
+#ifdef DEBUG
+	      fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);
 #endif
 #ifndef WIN32
-	    if(CHECK_INET_HANDLE(hInternet))
-#endif
-	      {
-		res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
-				    INTERNET_FLAG_NO_CACHE_WRITE,0);
-#ifdef DEBUG
-		fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
-			tmpv1+1,res.nDataAlloc,res.nDataLen);
-#endif
-		char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
-		if(tmpContent == NULL){
-		  return errorException(m, _("Unable to allocate memory."), "InternalError");
+	      if(CHECK_INET_HANDLE(hInternet))
+#endif
+		{
+		  res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
+				      INTERNET_FLAG_NO_CACHE_WRITE,0);
+#ifdef DEBUG
+		  fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
+			  tmpv1+1,res.nDataAlloc,res.nDataLen);
+#endif
+		  char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
+		  if(tmpContent == NULL){
+		    return errorException(m, _("Unable to allocate memory."), "InternalError");
+		  }
+		  size_t dwRead;
+		  InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
+		  map* tmpMap=getMap(tmpmaps->content,"value");
+		  if(tmpMap!=NULL){
+		    free(tmpMap->value);
+		    tmpMap->value=(char*)malloc((res.nDataLen+1)*sizeof(char));
+		    memmove(tmpMap->value,tmpContent,(res.nDataLen)*sizeof(char));
+		    tmpMap->value[res.nDataLen]=0;
+		    if(strlen(tmpContent)!=res.nDataLen){
+		      char tmp[256];
+		      sprintf(tmp,"%d",res.nDataLen*sizeof(char));
+		      addToMap(tmpmaps->content,"size",tmp);
+		    }
+		  }
+		  free(tmpContent);
 		}
-		size_t dwRead;
-		InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
-		map* tmpMap=getMap(tmpmaps->content,"value");
-		if(tmpMap!=NULL){
-		  free(tmpMap->value);
-		  tmpMap->value=(char*)malloc((res.nDataLen+1)*sizeof(char));
-		  memmove(tmpMap->value,tmpContent,(res.nDataLen)*sizeof(char));
-		  tmpMap->value[res.nDataLen]=0;
-		  if(strlen(tmpContent)!=res.nDataLen){
-		    char tmp[256];
-		    sprintf(tmp,"%d",res.nDataLen*sizeof(char));
-		    addToMap(tmpmaps->content,"size",tmp);
-		  }
-		}
-		free(tmpContent);
-	      }
-	    addToMap(tmpmaps->content,tmpn1,tmpv1+1);
-	    addToMap(tmpmaps->content,"Reference",tmpv1+1);
-	  }
+	      char *tmpx=url_encode(tmpv1+1);
+	      addToMap(tmpmaps->content,tmpn1,tmpx);
+	      free(tmpx);
+	      addToMap(tmpmaps->content,"Reference",tmpv1+1);
+	      dumpMap(tmpmaps->content);
+	    }
 	  tmpc=strtok(NULL,"@");
 	}
@@ -1010,9 +1111,7 @@
     fflush(stderr);
 #endif
-    xmlNodePtr cur = xmlDocGetRootElement(doc);
     /**
      * Parse every Input in DataInputs node.
      */
-    maps* tempMaps=NULL;
     xmlXPathObjectPtr tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='Input']");
     xmlNodeSet* tmps=tmpsptr->nodesetval;
@@ -1064,5 +1163,5 @@
 		return errorException(m, _("Unable to allocate memory."), "InternalError");
 	      }
-	      tmpmaps->name="missingIndetifier";
+	      tmpmaps->name=strdup("missingIndetifier");
 	      tmpmaps->content=createMap((char*)cur2->name,(char*)val);
 	      tmpmaps->next=NULL;
@@ -1093,6 +1192,5 @@
 	    fprintf(stderr,"REFERENCE\n");
 #endif
-	    map* referenceMap=NULL;
-	    char *refs[5];
+	    const char *refs[5];
 	    refs[0]="mimeType";
 	    refs[1]="encoding";
@@ -1100,5 +1198,4 @@
 	    refs[3]="method";
 	    refs[4]="href";
-	    char*url;
 	    for(int l=0;l<5;l++){
 #ifdef DEBUG
@@ -1141,8 +1238,8 @@
 	    hInternet.header=NULL;
 	    while(cur3){
+	      while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE)
+		cur2=cur3->next;
 	      if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){
-		xmlNodePtr cur4=cur3;
-		char *tmp=new char[cgiContentLength];
-		char *ha[2];
+		const char *ha[2];
 		ha[0]="key";
 		ha[1]="value";
@@ -1170,5 +1267,5 @@
 		}
 		hInternet.header=curl_slist_append(hInternet.header, has);
-		//free(has);
+		free(has);
 	      }
 	      else{
@@ -1184,4 +1281,6 @@
 		  xmlNodePtr cur4=cur3->children;
 		  while(cur4!=NULL){
+		    while(cur4->type!=XML_ELEMENT_NODE)
+		      cur4=cur4->next;
 		    xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0");
 		    bdoc->encoding = xmlCharStrdup ("UTF-8");
@@ -1302,17 +1401,17 @@
 		 * dataType , uom
 		 */
-		char *lits[2];
-		lits[0]="dataType";
-		lits[1]="uom";
+		char *list[2];
+		list[0]=strdup("dataType");
+		list[1]=strdup("uom");
 		for(int l=0;l<2;l++){
 #ifdef DEBUG
-		  fprintf(stderr,"*** LiteralData %s ***",lits[l]);
-#endif
-		  xmlChar *val=xmlGetProp(cur4,BAD_CAST lits[l]);
+		  fprintf(stderr,"*** LiteralData %s ***",list[l]);
+#endif
+		  xmlChar *val=xmlGetProp(cur4,BAD_CAST list[l]);
 		  if(val!=NULL && strlen((char*)val)>0){
 		    if(tmpmaps->content!=NULL)
-		      addToMap(tmpmaps->content,lits[l],(char*)val);
+		      addToMap(tmpmaps->content,list[l],(char*)val);
 		    else
-		      tmpmaps->content=createMap(lits[l],(char*)val);
+		      tmpmaps->content=createMap(list[l],(char*)val);
 		  }
 #ifdef DEBUG
@@ -1320,4 +1419,5 @@
 #endif
 		  xmlFree(val);
+		  free(list[l]);
 		}
 	      }
@@ -1327,5 +1427,5 @@
 		 * mimeType, encoding, schema
 		 */
-		char *coms[3];
+		const char *coms[3];
 		coms[0]="mimeType";
 		coms[1]="encoding";
@@ -1368,5 +1468,4 @@
 		char *res=NULL;
 		char *curs=tmpv->value;
-		int i=0;
 		for(int i=0;i<=strlen(tmpv->value)/64;i++) {
 		  if(res==NULL)
@@ -1421,5 +1520,4 @@
 #endif
     xmlXPathFreeObject(tmpsptr);
-    //xmlFree(tmps);
     
     tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']");
@@ -1439,5 +1537,4 @@
       else
 	addToMap(request_inputs,"ResponseDocument","");
-      request_output_real_format;
       maps *tmpmaps=NULL;
       xmlNodePtr cur=tmps->nodeTab[k];
@@ -1451,5 +1548,5 @@
 	    return errorException(m, _("Unable to allocate memory."), "InternalError");
 	  }
-	  tmpmaps->name="unknownIdentifier";
+	  tmpmaps->name=strdup("unknownIdentifier");
 	  tmpmaps->next=NULL;
 	}
@@ -1458,5 +1555,5 @@
 	 * storeExecuteResponse, lineage, status
 	 */
-	char *ress[3];
+	const char *ress[3];
 	ress[0]="storeExecuteResponse";
 	ress[1]="lineage";
@@ -1487,5 +1584,5 @@
 	     * mimeType, encoding, schema, uom, asReference
 	     */
-	    char *outs[5];
+	    const char *outs[5];
 	    outs[0]="mimeType";
 	    outs[1]="encoding";
@@ -1543,5 +1640,5 @@
 		    return errorException(m, _("Unable to allocate memory."), "InternalError");
 		  }
-		  tmpmaps->name="missingIndetifier";
+		  tmpmaps->name=strdup("missingIndetifier");
 		  tmpmaps->content=createMap((char*)cur2->name,(char*)val);
 		  tmpmaps->next=NULL;
@@ -1563,5 +1660,4 @@
 	}
       }
-      //xmlFree(cur);
       if(request_output_real_format==NULL)
 	request_output_real_format=dupMaps(&tmpmaps);
@@ -1576,5 +1672,4 @@
 
     xmlXPathFreeObject(tmpsptr);
-    //xmlFree(tmps);
     xmlCleanupParser();
   }
@@ -1710,4 +1805,5 @@
   _tmpMaps->next=NULL;
   addToMap(_tmpMaps->content,"status","0");
+  addToMap(_tmpMaps->content,"cwd",ntmp);
   if(cgiCookie!=NULL && strlen(cgiCookie)>0){
     addToMap(_tmpMaps->content,"sessid",strstr(cgiCookie,"=")+1);
@@ -1735,5 +1831,20 @@
   dumpMap(request_inputs);
 #endif
-
+#ifdef WIN32
+  char *cgiSidL=NULL;
+  if(getenv("CGISID")!=NULL)
+	addToMap(request_inputs,"cgiSid",getenv("CGISID"));
+  map* test1=getMap(request_inputs,"cgiSid");
+  if(test1!=NULL){
+    cgiSid=test1->value;
+  }
+  if(cgiSid!=NULL){
+    addToMap(request_inputs,"storeExecuteResponse","true");
+    addToMap(request_inputs,"status","true");
+    status=getMap(request_inputs,"status");
+    dumpMap(request_inputs);
+    fprintf(stderr,"cgiSID : %s",cgiSid);
+  }
+#endif
   if(status!=NULL)
     if(strcasecmp(status->value,"false")==0)
@@ -1751,5 +1862,13 @@
     pid = fork ();
 #else
-    pid = 0;
+    if(cgiSid==NULL){
+      addToMap(request_inputs,"cgSid",cgiSid);
+      createProcess(m,request_inputs,s1,NULL,cpid,request_input_real_format,request_output_real_format);
+      pid = cpid;
+    }else{
+      pid=0;
+      cpid=atoi(cgiSid);
+    }
+    fflush(stderr);
 #endif
     if (pid > 0) {
@@ -1778,7 +1897,7 @@
       fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value);
 #endif
+      freopen(flog,"w+",stderr);
       freopen(fbkp , "w+", stdout);
       fclose(stdin);
-      freopen(flog,"w+",stderr);
       free(fbkp);
       free(flog);
@@ -1791,9 +1910,11 @@
       updateStatus(m);
       printProcessResponse(m,request_inputs,cpid,
-			    s1,r_inputs1->value,SERVICE_STARTED,
-			    request_input_real_format,
-			    request_output_real_format);
+			   s1,r_inputs1->value,SERVICE_STARTED,
+			   request_input_real_format,
+			   request_output_real_format);
+#ifndef WIN32
       fflush(stdout);
       rewind(stdout);
+#endif
 
       loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres);
@@ -1811,5 +1932,5 @@
 #ifdef DEBUG
   dumpMaps(request_output_real_format);
-  fprintf(stderr,"Function loaded and returned %d\n",eres);
+  fprintf(stderr,"Function loaded and returned %d\n",*eres);
   fflush(stderr);
 #endif
@@ -1818,4 +1939,5 @@
 		   request_output_real_format,request_inputs,
 		   cpid,m,eres);
+  fflush(stdout);
   /**
    * Ensure that if error occurs when freeing memory, no signal will return
