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);
