Index: /trunk/zoo-project/zoo-kernel/makefile.vc
===================================================================
--- /trunk/zoo-project/zoo-kernel/makefile.vc	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/makefile.vc	(revision 680)
@@ -41,6 +41,24 @@
 	$(CPP) $(CFLAGS) /c zcfg2yaml.c
 
-service_internal.obj: service_internal.c mimetypes.h
+service_internal.obj: service_internal.c service_internal.h
 	$(CPP) $(CFLAGS) /c service_internal.c
+
+server_internal.obj: server_internal.c server_internal.h
+	$(CPP) $(CFLAGS) /c server_internal.c
+
+caching.obj: caching.c caching.h
+	$(CPP) $(CFLAGS) /c caching.c
+
+request_parser.obj: request_parser.c request_parser.h
+	$(CPP) $(CFLAGS) /c request_parser.c
+
+response_print.obj: response_print.c response_print.h
+	$(CPP) $(CFLAGS) /c response_print.c
+
+service.obj: service.c service.h
+	$(CPP) $(CFLAGS) /c service.c
+
+sqlapi.obj: sqlapi.c sqlapi.h
+	$(CPP) $(CFLAGS) /c sqlapi.c
 
 service_internal_js.obj: service_internal_js.c service.h
@@ -68,10 +86,14 @@
 	$(CPP) /EHsc /c $(CFLAGS) zoo_loader.c
 
-$(PROGRAMNAME): version.h zoo_loader.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj
-	link zoo_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj  zoo_service_loader.obj /out:$(PROGRAMNAME) $(LDFLAGS) $(LDFLAGSCGI)
+
+$(LIBZOO_SERVICE): service_internal.obj service.obj sqlapi.obj
+	link /dll /out:$(LIBZOO_SERVICE) ./service.obj ./service_internal.obj ./sqlapi.obj $(LDFLAGS) /FORCE:MULTIPLE
+
+$(PROGRAMNAME): version.h $(LIBZOO_SERVICE) zoo_loader.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj request_parser.obj response_print.obj server_internal.obj caching.obj
+	link zoo_loader.obj request_parser.obj response_print.obj server_internal.obj caching.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj  zoo_service_loader.obj ./libzoo_service.lib /out:$(PROGRAMNAME) $(LDFLAGS) $(LDFLAGSCGI) 
 
 zcfg2yaml: version.h zcfg2yaml.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj
-	link zcfg2yaml.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj /out:zcfg2yaml.exe $(LDFLAGS) $(LDFLAGSCGI)
+	link zcfg2yaml.obj server_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj response_print.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj ./libzoo_service.lib /out:zcfg2yaml.exe $(LDFLAGS) $(LDFLAGSCGI)
 
 clean:
-	erase -f *.cgi *.obj *.tab.c* *.tab.h *.sr.c* lex.* *.lreg *.sibling
+	erase -f *.cgi *.obj *.tab.c* *.tab.h *.sr.c* lex.* *.lreg *.sibling *.lib *.dll
Index: /trunk/zoo-project/zoo-kernel/nmake.opt
===================================================================
--- /trunk/zoo-project/zoo-kernel/nmake.opt	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/nmake.opt	(revision 680)
@@ -1,3 +1,4 @@
 PROGRAMNAME=zoo_loader.cgi
+LIBZOO_SERVICE=libzoo_service.dll
 
 CC=cl $(CFLAGS)
@@ -64,5 +65,9 @@
 PYTHON_CPATH=$(PY_DIR)
 
-CFLAGS= $(MS_DEFS) $(INCLUDES) $(CFLAGS1) /nologo /MD /W3 /EHsc /Ox /D_CRT_SECURE_NO_WARNINGS /DWIN32 /DPROGRAMNAME=\"$(PROGRAMNAME)\" $(CJFLAGS) -I$(ZOOK_DIR) $(RUBY_CFLAGS) -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
+!IFDEF DB
+DB_FLAGS=-DRELY_ON_DB
+!ENDIF
+
+CFLAGS= $(DB_FLAGS) $(MS_DEFS) $(INCLUDES) $(CFLAGS1) /nologo /MD /W3 /EHsc /Ox /D_CRT_SECURE_NO_WARNINGS /DWIN32 /DPROGRAMNAME=\"$(PROGRAMNAME)\" $(CJFLAGS) -I$(ZOOK_DIR) $(RUBY_CFLAGS) -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
 
 LDFLAGSCGI=$(TROOT)/../../thirds/cgic206/libcgic.lib 
Index: /trunk/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/request_parser.c	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/request_parser.c	(revision 680)
@@ -1088,4 +1088,5 @@
     }
   }
+  return 0;
 }
 
Index: /trunk/zoo-project/zoo-kernel/response_print.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/response_print.c	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/response_print.c	(revision 680)
@@ -43,6 +43,4 @@
 #include <dlfcn.h>
 #endif
-
-#define ERROR_MSG_MAX_LENGTH 1024
 
 #include "mimetypes.h"
Index: /trunk/zoo-project/zoo-kernel/server_internal.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/server_internal.c	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/server_internal.c	(revision 680)
@@ -29,6 +29,9 @@
 #ifndef WIN32
 #include <dlfcn.h>
-#endif
 #include <uuid/uuid.h>
+#else
+#include <rpc.h>
+#define ERROR_MSG_MAX_LENGTH 1024
+#endif
 #include <signal.h>
 
@@ -57,9 +60,16 @@
 char *get_uuid(){
   char *res=(char*)malloc(37*sizeof(char));
+#ifdef WIN32
+  UUID uuid;
+  UuidCreate(&uuid);
+  RPC_CSTR rest = NULL;
+  UuidToString(&uuid,&rest);
+#else
   uuid_t uuid;
   uuid_generate_time(uuid);
   char rest[128];
   uuid_unparse(uuid,rest);
-  sprintf(res,"%s", rest);
+#endif
+  sprintf(res,"%s",rest);
   return res;
 }
@@ -780,5 +790,5 @@
 #endif	
   LocalFree(lpMsgBuf);
-  
+
   return msg;
 #else
@@ -950,5 +960,11 @@
       fcontent[flen]=0;
       fclose(f0);
+#ifndef WIN32
       kill(atoi(fcontent),SIGKILL);
+#else
+      HANDLE myZooProcess=OpenProcess(PROCESS_ALL_ACCESS,false,atoi(fcontent));
+      TerminateProcess(myZooProcess,1);
+      CloseHandle(myZooProcess);
+#endif
       free(fcontent);
     }
@@ -1089,2 +1105,91 @@
   return 0;
 }
+
+#ifdef WIN32
+/**
+ * Create a KVP request for executing background task.
+ * TODO: use the XML request in case of input POST request.
+ *
+ * @param m the maps containing the parameters from the main.cfg file
+ * @param length the total length of the KVP parameters
+ * @param type
+ */
+char* getMapsAsKVP(maps* m,int length,int type){
+  char *dataInputsKVP=(char*) malloc(length*sizeof(char));
+  char *dataInputsKVPi=NULL;
+  maps* curs=m;
+  int i=0;
+  while(curs!=NULL){
+    map *inRequest=getMap(curs->content,"inRequest");
+    map *hasLength=getMap(curs->content,"length");
+    if((inRequest!=NULL && strncasecmp(inRequest->value,"true",4)==0) ||
+       inRequest==NULL){
+      if(i==0)
+	if(type==0){
+	  sprintf(dataInputsKVP,"%s=",curs->name);
+	  if(hasLength!=NULL){
+	    dataInputsKVPi=(char*)malloc((strlen(curs->name)+2)*sizeof(char));
+	    sprintf(dataInputsKVPi,"%s=",curs->name);
+	  }
+	}
+	else
+	  sprintf(dataInputsKVP,"%s",curs->name);
+      else{
+	char *temp=zStrdup(dataInputsKVP);
+	if(type==0)
+	  sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
+	else
+	  sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
+      }
+      map* icurs=curs->content;
+      if(type==0){
+	char *temp=zStrdup(dataInputsKVP);
+	if(getMap(curs->content,"xlink:href")!=NULL)
+	  sprintf(dataInputsKVP,"%sReference",temp);
+	else{
+	  if(hasLength!=NULL){
+	    int j;
+	    for(j=0;j<atoi(hasLength->value);j++){
+	      map* tmp0=getMapArray(curs->content,"value",j);
+	      if(j==0)
+		free(temp);
+	      temp=zStrdup(dataInputsKVP);
+	      if(j==0)
+		sprintf(dataInputsKVP,"%s%s",temp,tmp0->value);
+	      else
+		sprintf(dataInputsKVP,"%s;%s%s",temp,dataInputsKVPi,tmp0->value);
+	    }
+	  }
+	  else
+	    sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
+	}
+	free(temp);
+      }
+      while(icurs!=NULL){
+	if(strncasecmp(icurs->name,"value",5)!=0 &&
+	   strncasecmp(icurs->name,"mimeType_",9)!=0 &&
+	   strncasecmp(icurs->name,"dataType_",9)!=0 &&
+	   strncasecmp(icurs->name,"size",4)!=0 &&
+	   strncasecmp(icurs->name,"length",4)!=0 &&
+	   strncasecmp(icurs->name,"isArray",7)!=0 &&
+	   strcasecmp(icurs->name,"Reference")!=0 &&
+	   strcasecmp(icurs->name,"minOccurs")!=0 &&
+	   strcasecmp(icurs->name,"maxOccurs")!=0 &&
+	   strncasecmp(icurs->name,"fmimeType",9)!=0 &&
+	   strcasecmp(icurs->name,"inRequest")!=0){
+	  char *itemp=zStrdup(dataInputsKVP);
+	  if(strcasecmp(icurs->name,"xlink:href")!=0)
+	    sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
+	  else
+	    sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,url_encode(icurs->value));
+	  free(itemp);
+	}
+	icurs=icurs->next;
+      }
+    }
+    curs=curs->next;
+    i++;
+  }
+  return dataInputsKVP;
+}
+#endif
Index: /trunk/zoo-project/zoo-kernel/server_internal.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/server_internal.h	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/server_internal.h	(revision 680)
@@ -22,4 +22,8 @@
  * THE SOFTWARE.
  */
+
+#ifdef WIN32
+#pragma comment(lib, "rpcrt4.lib")
+#endif
 
 #include "ulinet.h"
@@ -61,4 +65,8 @@
   int createRegistry (maps*,registry **,char *);
 
+#ifdef WIN32
+  char* getMapsAsKVP(maps*,int,int);
+#endif
+
 #ifdef __cplusplus
 }
Index: /trunk/zoo-project/zoo-kernel/service.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service.c	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/service.c	(revision 680)
@@ -62,7 +62,4 @@
   map* tmp=t;
   while(tmp!=NULL){
-#ifdef DEBUG
-    fprintf(stderr,"%s = %s\n",tmp->name,tmp->value);
-#endif
     fprintf(file,"%s = %s\n",tmp->name,tmp->value);
     tmp=tmp->next;
@@ -91,5 +88,5 @@
  */
 void dumpMapsToFile(maps* m,char* file_path){
-  FILE* file=fopen(file_path,"w");
+  FILE* file=fopen(file_path,"w+");
   maps* tmp=m;
   while(tmp!=NULL){
@@ -99,7 +96,8 @@
     tmp=tmp->next;
   }
+  fflush(file);
   fclose(file);
 }
-  
+
 /**
  * Create a new map
@@ -1429,83 +1427,2 @@
   m=&trorf;
 }
-
-#ifdef WIN32
-char* getMapsAsKVP(maps* m,int length,int type){
-  char *dataInputsKVP=(char*) malloc(length*sizeof(char));
-  char *dataInputsKVPi=NULL;
-  maps* curs=m;
-  int i=0;
-  while(curs!=NULL){
-    map *inRequest=getMap(curs->content,"inRequest");
-    map *hasLength=getMap(curs->content,"length");
-    if((inRequest!=NULL && strncasecmp(inRequest->value,"true",4)==0) ||
-       inRequest==NULL){
-      if(i==0)
-	if(type==0){
-	  sprintf(dataInputsKVP,"%s=",curs->name);
-	  if(hasLength!=NULL){
-	    dataInputsKVPi=(char*)malloc((strlen(curs->name)+2)*sizeof(char));
-	    sprintf(dataInputsKVPi,"%s=",curs->name);
-	  }
-	}
-	else
-	  sprintf(dataInputsKVP,"%s",curs->name);
-      else{
-	char *temp=zStrdup(dataInputsKVP);
-	if(type==0)
-	  sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
-	else
-	  sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
-      }
-      map* icurs=curs->content;
-      if(type==0){
-	char *temp=zStrdup(dataInputsKVP);
-	if(getMap(curs->content,"xlink:href")!=NULL)
-	  sprintf(dataInputsKVP,"%sReference",temp);
-	else{
-	  if(hasLength!=NULL){
-	    int j;
-	    for(j=0;j<atoi(hasLength->value);j++){
-	      map* tmp0=getMapArray(curs->content,"value",j);
-	      if(j==0)
-		free(temp);
-	      temp=zStrdup(dataInputsKVP);
-	      if(j==0)
-		sprintf(dataInputsKVP,"%s%s",temp,tmp0->value);
-	      else
-		sprintf(dataInputsKVP,"%s;%s%s",temp,dataInputsKVPi,tmp0->value);
-	    }
-	  }
-	  else
-	    sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
-	}
-	free(temp);
-      }
-      while(icurs!=NULL){
-	if(strncasecmp(icurs->name,"value",5)!=0 &&
-	   strncasecmp(icurs->name,"mimeType_",9)!=0 &&
-	   strncasecmp(icurs->name,"dataType_",9)!=0 &&
-	   strncasecmp(icurs->name,"size",4)!=0 &&
-	   strncasecmp(icurs->name,"length",4)!=0 &&
-	   strncasecmp(icurs->name,"isArray",7)!=0 &&
-	   strcasecmp(icurs->name,"Reference")!=0 &&
-	   strcasecmp(icurs->name,"minOccurs")!=0 &&
-	   strcasecmp(icurs->name,"maxOccurs")!=0 &&
-	   strncasecmp(icurs->name,"fmimeType",9)!=0 &&
-	   strcasecmp(icurs->name,"inRequest")!=0){
-	  char *itemp=zStrdup(dataInputsKVP);
-	  if(strcasecmp(icurs->name,"xlink:href")!=0)
-	    sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
-	  else
-	    sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,url_encode(icurs->value));
-	  free(itemp);
-	}
-	icurs=icurs->next;
-      }
-    }
-    curs=curs->next;
-    i++;
-  }
-  return dataInputsKVP;
-}
-#endif
Index: /trunk/zoo-project/zoo-kernel/service.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service.h	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/service.h	(revision 680)
@@ -29,9 +29,14 @@
 
 #ifdef WIN32
+#define ZOO_DLL_EXPORT __declspec( dllexport )
+#else
+#define ZOO_DLL_EXPORT 
+#endif
+
+#ifdef WIN32
 #ifndef USE_MS
 #define strncasecmp _strnicmp
 #define strcasecmp _stricmp
-#endif
-#ifndef snprintf
+#else
 #define snprintf sprintf_s
 #endif
@@ -101,5 +106,7 @@
 #include <stdlib.h>
 #include <ctype.h>
+#ifndef WIN32
 #include <stdio.h>
+#endif
 #include <string.h>
 #ifndef WIN32
@@ -261,64 +268,59 @@
   } registry;
 
-
-  void _dumpMap(map*);
-  void dumpMap(map*);
-  void dumpMapToFile(map*,FILE*);
-  void dumpMaps(maps* m);
-  void dumpMapsToFile(maps*,char*);
-  map* createMap(const char*,const char*);
-  int count(map*);
-  bool hasKey(map*,const char*);
-  maps* getMaps(maps*,const char*);
-  map* getMap(map*,const char*);
-  map* getLastMap(map*);
-  map* getMapFromMaps(maps*,const char*,const char*);
-  void freeMap(map**);
-  void freeMaps(maps** mo);
+  ZOO_DLL_EXPORT void _dumpMap(map*);
+  ZOO_DLL_EXPORT void dumpMap(map*);
+  ZOO_DLL_EXPORT void dumpMaps(maps* m);
+  ZOO_DLL_EXPORT void dumpMapToFile(map*,FILE*); // Not required
+  ZOO_DLL_EXPORT void dumpMapsToFile(maps*,char*);
+  ZOO_DLL_EXPORT map* createMap(const char*,const char*);
+  ZOO_DLL_EXPORT int count(map*);
+  ZOO_DLL_EXPORT bool hasKey(map*,const char*);
+  ZOO_DLL_EXPORT maps* getMaps(maps*,const char*);
+  ZOO_DLL_EXPORT map* getMap(map*,const char*);
+  ZOO_DLL_EXPORT map* getLastMap(map*);
+  ZOO_DLL_EXPORT map* getMapFromMaps(maps*,const char*,const char*);
+  ZOO_DLL_EXPORT void freeMap(map**);
+  ZOO_DLL_EXPORT void freeMaps(maps** mo);
   
 
-  bool hasElement(elements*,const char*);
-  elements* getElements(elements*,char*);
-  void freeIOType(iotype**);
-  void freeElements(elements**);
-  void freeService(service**);
-  void addToMap(map*,const char*,const char*);
-  void addIntToMap(map*,const char*,const int);
-  void addToMapWithSize(map*,const char*,const char*,int);
-  void addMapToMap(map**,map*);
-  void addMapToIoType(iotype**,map*);
-  map* getMapOrFill(map**,const char*,const char*);
-  bool contains(map*,map*);
-  iotype* getIoTypeFromElement(elements*,char*, map*);
-  void loadMapBinary(map**,map*,int);
-  void loadMapBinaries(map**,map*);
-  maps* dupMaps(maps**);
-  void addMapsToMaps(maps**,maps*);
-  map* getMapArray(map*,const char*,int);
-  void setMapArray(map*,const char*,int,const char*);
-  map* getMapType(map*);
-  int addMapsArrayToMaps(maps**,maps*,char*);
-  void setMapInMaps(maps*,const char*,const char*,const char*);
-  void dumpElements(elements*);
-  void dumpElementsAsYAML(elements*);
-  elements* dupElements(elements*);
-  void addToElements(elements**,elements*);
-  void dumpService(service*);
-  void dumpServiceAsYAML(service*);
-  service* dupService(service*);
-  void dumpRegistry(registry*);
-  bool addServiceToRegistry(registry**,char*,service*);
-  void freeRegistry(registry**);
-  service* getServiceFromRegistry(registry*,char*,char*);
-  void inheritMap(map**,map*);
-  void inheritIOType(iotype**,iotype*);
-  void inheritElements(elements**,elements*);
-  void inheritance(registry*,service**);
-  void mapsToCharXXX(maps*,char***);
-  void charxxxToMaps(char***,maps**);
-#ifdef WIN32
-  extern char *url_encode(char *);
-  char* getMapsAsKVP(maps*,int,int);
-#endif
+  ZOO_DLL_EXPORT bool hasElement(elements*,const char*);
+  ZOO_DLL_EXPORT elements* getElements(elements*,char*);
+  ZOO_DLL_EXPORT void freeIOType(iotype**);
+  ZOO_DLL_EXPORT void freeElements(elements**);
+  ZOO_DLL_EXPORT void freeService(service**);
+  ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*);
+  ZOO_DLL_EXPORT void addIntToMap(map*,const char*,const int);
+  ZOO_DLL_EXPORT void addToMapWithSize(map*,const char*,const char*,int);
+  ZOO_DLL_EXPORT void addMapToMap(map**,map*);
+  ZOO_DLL_EXPORT void addMapToIoType(iotype**,map*);
+  ZOO_DLL_EXPORT map* getMapOrFill(map**,const char*,const char*);
+  ZOO_DLL_EXPORT bool contains(map*,map*);
+  ZOO_DLL_EXPORT iotype* getIoTypeFromElement(elements*,char*, map*);
+  ZOO_DLL_EXPORT void loadMapBinary(map**,map*,int);
+  ZOO_DLL_EXPORT void loadMapBinaries(map**,map*);
+  ZOO_DLL_EXPORT maps* dupMaps(maps**);
+  ZOO_DLL_EXPORT void addMapsToMaps(maps**,maps*);
+  ZOO_DLL_EXPORT map* getMapArray(map*,const char*,int);
+  ZOO_DLL_EXPORT void setMapArray(map*,const char*,int,const char*);
+  ZOO_DLL_EXPORT map* getMapType(map*);
+  ZOO_DLL_EXPORT int addMapsArrayToMaps(maps**,maps*,char*);
+  ZOO_DLL_EXPORT void setMapInMaps(maps*,const char*,const char*,const char*);
+  ZOO_DLL_EXPORT void dumpElements(elements*);
+  ZOO_DLL_EXPORT void dumpElementsAsYAML(elements*);
+  ZOO_DLL_EXPORT elements* dupElements(elements*);
+  ZOO_DLL_EXPORT void addToElements(elements**,elements*);
+  ZOO_DLL_EXPORT void dumpService(service*);
+  ZOO_DLL_EXPORT void dumpServiceAsYAML(service*);
+  ZOO_DLL_EXPORT service* dupService(service*);
+  ZOO_DLL_EXPORT void dumpRegistry(registry*);
+  ZOO_DLL_EXPORT bool addServiceToRegistry(registry**,char*,service*);
+  ZOO_DLL_EXPORT void freeRegistry(registry**);
+  ZOO_DLL_EXPORT service* getServiceFromRegistry(registry*,char*,char*);
+  ZOO_DLL_EXPORT void inheritMap(map**,map*);
+  ZOO_DLL_EXPORT void inheritIOType(iotype**,iotype*);
+  ZOO_DLL_EXPORT void inheritElements(elements**,elements*);
+  ZOO_DLL_EXPORT void inheritance(registry*,service**);
+  ZOO_DLL_EXPORT void mapsToCharXXX(maps*,char***);
+  ZOO_DLL_EXPORT void charxxxToMaps(char***,maps**);
 
 #ifdef __cplusplus
Index: /trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 680)
@@ -23,5 +23,4 @@
  */
 
-#include "fcgi_stdio.h"
 #include "service_internal.h"
 #ifdef USE_MS
@@ -90,5 +89,5 @@
      ){
 #ifdef WIN32
-    return NULL
+    return NULL;
 #else
     return -1;
@@ -96,12 +95,12 @@
   }
   if(lockShm(lockid)<0){
+#ifdef WIN32
+      return NULL;
+#else
     if(itn<ZOO_LOCK_MAX_RETRY){
       itn++;
       goto toRetry1;
     }else
-#ifdef WIN32
-    return NULL
-#else
-    return -1;
+      return -1;
 #endif
   }else
@@ -211,5 +210,9 @@
       free(fbkpid);
       if(stat!=NULL){
+#ifndef WIN32
 	removeShmLock(conf,1);
+#else
+	unlockShm(lockid);
+#endif
 	free(stat);
       }
@@ -271,6 +274,8 @@
     if(stat!=NULL){
       lockid=acquireLock(conf);
-      if(lockid<0)
+      if(lockid<0){
+	dumpMap(status);
 	return ZOO_LOCK_ACQUIRE_FAILED;
+      }
     }
     FILE* fstatus=fopen(fbkpid,"w");
@@ -292,10 +297,4 @@
 #ifdef WIN32
 
-#include <windows.h>
-#include <fcgi_stdio.h>
-#include <stdio.h>
-#include <conio.h>
-#include <tchar.h>
-
 #define SHMEMSIZE 4096
 
@@ -308,11 +307,11 @@
   map *tmpMap=getMapFromMaps(conf,"lenv","lid");
   if(tmpMap==NULL)
-	tmpMap=getMapFromMaps(conf,"lenv","osid");
+    tmpMap=getMapFromMaps(conf,"lenv","osid");
 
   if(tmpMap!=NULL){
-	snprintf(key, length, "zoo_sem_%s", tmpMap->value);      
+    snprintf(key, length, "zoo_sem_%s", tmpMap->value);      
   }
   else {
-	strncpy(key, "-1", length);  
+    strncpy(key, "-1", length);
   }
   return strlen(key);
@@ -321,20 +320,19 @@
 
 semid getShmLockId(maps* conf, int nsems){
-    semid sem_id;
-    char key[MAX_PATH];
-    getKeyValue(conf, key, MAX_PATH);
-    
-    sem_id = CreateSemaphore( NULL, nsems, nsems+1, key);
-    if(sem_id==NULL){
-#ifdef DEBUG
-      fprintf(stderr,"Semaphore failed to create: %s\n", getLastErrorMessage());
-#endif
-      return NULL;
-    }
-#ifdef DEBUG
-    fprintf(stderr,"%s Accessed !\n",key);
-#endif
-
-    return sem_id;
+  semid sem_id;
+  char key[MAX_PATH];
+  getKeyValue(conf, key, MAX_PATH);
+  
+  sem_id = CreateSemaphore( NULL, nsems, nsems+1, key);
+  if(sem_id==NULL){
+#ifdef DEBUG
+    fprintf(stderr,"Semaphore failed to create: %s\n", getLastErrorMessage());
+#endif
+    return NULL;
+  }
+#ifdef DEBUG
+  fprintf(stderr,"%s Accessed !\n",key);
+#endif
+  return sem_id;
 }
 
Index: /trunk/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal.h	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/service_internal.h	(revision 680)
@@ -98,17 +98,17 @@
 #endif
 
-  char *readVSIFile(maps*,const char*);
-  int  setOutputValue( maps*, const char*, char*, size_t);
-  char* getInputValue( maps*,const char*,size_t*);
+  ZOO_DLL_EXPORT char *readVSIFile(maps*,const char*);
+  ZOO_DLL_EXPORT int  setOutputValue( maps*, const char*, char*, size_t);
+  ZOO_DLL_EXPORT char* getInputValue( maps*,const char*,size_t*);
 
-  void unhandleStatus(maps*);
-  int _updateStatus(maps*);
-  char* _getStatus(maps*,char*);
-  char* _getStatusFile(maps*,char*);
-  char* getStatus(int);
-  char* getStatusId(maps*,char*);
+  ZOO_DLL_EXPORT void unhandleStatus(maps*);
+  ZOO_DLL_EXPORT int _updateStatus(maps*);
+  ZOO_DLL_EXPORT char* _getStatus(maps*,char*);
+  ZOO_DLL_EXPORT char* _getStatusFile(maps*,char*);
+  ZOO_DLL_EXPORT char* getStatus(int);
+  ZOO_DLL_EXPORT char* getStatusId(maps*,char*);
 
-  int updateStatus( maps*,const int,const char*);
-  int removeShmLock(maps*, int);
+  ZOO_DLL_EXPORT int updateStatus( maps*,const int,const char*);
+  ZOO_DLL_EXPORT int removeShmLock(maps*, int);
   /**
    * Cross platform type used for Lock identifier
@@ -117,10 +117,11 @@
 #define semid int
 #else
+#include <windows.h>
 #define semid HANDLE
 #endif
-  semid acquireLock(maps*);
-  semid getShmLockId(maps*,int);
-  int lockShm(semid);
-  int unlockShm(semid);
+  ZOO_DLL_EXPORT semid acquireLock(maps*);
+  ZOO_DLL_EXPORT semid getShmLockId(maps*,int);
+  ZOO_DLL_EXPORT int lockShm(semid);
+  ZOO_DLL_EXPORT int unlockShm(semid);
 
 #ifdef __cplusplus
Index: /trunk/zoo-project/zoo-kernel/sqlapi.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/sqlapi.h	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/sqlapi.h	(revision 680)
@@ -33,14 +33,14 @@
 #include "service.h"
 #include "service_internal.h"
-  void init_sql(maps*);
-  void close_sql(maps*);
-  int execSql(maps*,const char*);
-  void recordStoredFile(maps*,const char*,const char*,const char*);
-  void recordServiceStatus(maps*);
-  void recordResponse(maps*,char*);
-  void readFinalRes(maps*,char*,map*);
-  int isRunning(maps*,char*);
-  char* getStatusId(maps*,char*);
-  void removeService(maps*,char*);
+  ZOO_DLL_EXPORT void init_sql(maps*);
+  ZOO_DLL_EXPORT void close_sql(maps*);
+  ZOO_DLL_EXPORT int execSql(maps*,const char*);
+  ZOO_DLL_EXPORT void recordStoredFile(maps*,const char*,const char*,const char*);
+  ZOO_DLL_EXPORT void recordServiceStatus(maps*);
+  ZOO_DLL_EXPORT void recordResponse(maps*,char*);
+  ZOO_DLL_EXPORT void readFinalRes(maps*,char*,map*);
+  ZOO_DLL_EXPORT int isRunning(maps*,char*);
+  ZOO_DLL_EXPORT char* getStatusId(maps*,char*);
+  ZOO_DLL_EXPORT void removeService(maps*,char*);
 #endif
 
Index: /trunk/zoo-project/zoo-kernel/zoo_loader.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/zoo_loader.c	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/zoo_loader.c	(revision 680)
@@ -56,4 +56,8 @@
 #include "service_internal.h"
 #include "request_parser.h"
+
+#ifdef WIN32
+#include "server_internal.h"
+#endif
 
 int runRequest(map**);
Index: /trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 679)
+++ /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 680)
@@ -56,4 +56,7 @@
 #include "request_parser.h"
 #include "sqlapi.h"
+#ifdef WIN32
+#include "caching.h"
+#endif
 
 #ifdef USE_PYTHON
@@ -707,5 +710,6 @@
   fprintf (stderr, "DATAOUTPUTSKVP %s\n", dataOutputsKVP);
 #endif
-  map *sid = getMapFromMaps (m, "lenv", "sid");
+  map *sid = getMapFromMaps (m, "lenv", "osid");
+  map *usid = getMapFromMaps (m, "lenv", "usid");
   map *r_inputs = getMapFromMaps (m, "main", "tmpPath");
   map *r_inputs1 = getMap (request_inputs, "metapath");
@@ -725,26 +729,26 @@
   
   if(r_inputs2 != NULL && tmpReq != NULL) {
-	const char key[] = "rfile=";
-	char* kvp = (char*) malloc((FILENAME_MAX + strlen(key))*sizeof(char));
-	char* filepath = kvp + strlen(key);
-	strncpy(kvp, key, strlen(key));
-	addToCache(m, tmpReq->value, tmpReq->value, "text/xml", strlen(tmpReq->value), 
-	           filepath, FILENAME_MAX);				   
+    const char key[] = "rfile=";
+    char* kvp = (char*) malloc((FILENAME_MAX + strlen(key))*sizeof(char));
+    char* filepath = kvp + strlen(key);
+    strncpy(kvp, key, strlen(key));
+    addToCache(m, tmpReq->value, tmpReq->value, "text/xml", strlen(tmpReq->value), 
+	       filepath, FILENAME_MAX);				   
     if (filepath == NULL) {
-        errorException( m, _("Unable to cache HTTP POST Execute request."), "InternalError", NULL);  
-		return;
+      errorException( m, _("Unable to cache HTTP POST Execute request."), "InternalError", NULL);  
+      return;
     }	
-	sprintf(tmp,"\"metapath=%s&%s&cgiSid=%s",
-	        r_inputs1->value,kvp,sid->value);
+    sprintf(tmp,"\"metapath=%s&%s&cgiSid=%s&usid=%s\"",
+	    r_inputs1->value,kvp,sid->value,usid->value);
     sprintf(tmpq,"metapath=%s&%s",
-	        r_inputs1->value,kvp);
-	free(kvp);		
+	    r_inputs1->value,kvp);
+    free(kvp);	
   }
   else if (r_inputs2 != NULL)
     {
       sprintf (tmp,
-               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s",
+               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s&usid=%s\"",
                r_inputs1->value, req->value, id->value, dataInputsKVP,
-               r_inputs2->name, dataOutputsKVP, sid->value);
+               r_inputs2->name, dataOutputsKVP, sid->value, usid->value);
       sprintf (tmpq,
                "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",
@@ -755,7 +759,7 @@
     {
       sprintf (tmp,
-               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s",
+               "\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s&usid=%s\"",
                r_inputs1->value, req->value, id->value, dataInputsKVP,
-               sid->value);
+               sid->value, usid->value);
       sprintf (tmpq,
                "metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",
@@ -777,9 +781,8 @@
 #endif
 
-  map* usid = getMapFromMaps (m, "lenv", "usid");
+  usid = getMapFromMaps (m, "lenv", "usid");
   if (usid != NULL && usid->value != NULL) {
     SetEnvironmentVariable("USID", TEXT (usid->value));
   }
-
   SetEnvironmentVariable ("CGISID", TEXT (sid->value));
   SetEnvironmentVariable ("QUERY_STRING", TEXT (tmpq));
@@ -911,5 +914,4 @@
     }
 
-
   /**
    * Manage our own error log file (usefull to separate standard apache debug
@@ -991,5 +993,6 @@
       char tmpUrl[1024];
 	
-      if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"?		
+      if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) {
+	// Knut: check if non-empty instead of "on"?		
 	if ( strncmp(cgiServerPort, "443", 3) == 0 ) { 
 	  sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
@@ -1927,6 +1930,5 @@
 
   map *test1 = getMap (request_inputs, "cgiSid");
-  if (test1 != NULL)
-    {
+  if (test1 != NULL){
       cgiSid = test1->value;
       addToMap (request_inputs, "storeExecuteResponse", "true");
@@ -1935,4 +1937,9 @@
       status = getMap (request_inputs, "status");
     }
+  test1 = getMap (request_inputs, "usid");
+  if (test1 != NULL){
+    setMapInMaps (m, "lenv", "usid", test1->value);
+    setMapInMaps (m, "lenv", "uusid", test1->value);
+  }
 #endif
   char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog;
@@ -1983,4 +1990,5 @@
           pid = 0;
           cpid = atoi (cgiSid);
+	  updateStatus(m,0,_("Initializing"));
         }
 #endif
@@ -2029,6 +2037,6 @@
           sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value);
 
-          f0 = freopen (fbkpid, "w+", stdout);
-	  fprintf(stdout,"%d",getpid());
+          f0 = freopen (fbkpid, "w+",stdout);
+	  printf("%d",getpid());
 	  fflush(stdout);
 
@@ -2039,9 +2047,7 @@
                      strlen (usid->value) + 7) * sizeof (char));
           sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value);
-
-          FILE* f2 = fopen (fbkp, "w+");
-	  fprintf(f2,"%s",tmpm->value);
+          FILE* f2 = freopen (fbkp, "w+",stdout);
+	  printf("%s",tmpm->value);
 	  fflush(f2);
-	  fclose(f2);
 	  free(fbkp);
 
@@ -2071,5 +2077,4 @@
 	  fclose (stdin);
 #endif
-	  fprintf(stderr,"DEBUG START %s %d \n",__FILE__,__LINE__);
 #ifdef RELY_ON_DB
 	  init_sql(m);
@@ -2163,5 +2168,5 @@
     {
       fclose (stdout);
-      //fclose (stderr);
+      fclose (stderr);
       /**
        * Dump back the final file fbkp1 to fbkp
Index: /trunk/zoo-project/zoo-services/utils/status/makefile.vc
===================================================================
--- /trunk/zoo-project/zoo-services/utils/status/makefile.vc	(revision 679)
+++ /trunk/zoo-project/zoo-services/utils/status/makefile.vc	(revision 680)
@@ -2,21 +2,7 @@
 !INCLUDE $(ZOOK_DIR)/nmake.opt
 
-FILES=$(ZOOK_DIR)/service_internal.obj $(ZOOK_DIR)/ulinet.obj
-!IFDEF JS_DIR
-FILES=$(FILES) $(ZOOK_DIR)$(JS_FILE)
-!ENDIF
-!IFDEF JDK_DIR
-FILES=$(FILES) $(ZOOK_DIR)$(JAVA_FILE)
-!ENDIF
-!IFDEF PY_DIR
-FILES=$(FILES) $(ZOOK_DIR)$(PY_FILE)
-!ENDIF
-!IFDEF MS_DIR
-FILES=$(FILES) $(ZOOK_DIR)$(MS_FILE)
-!ENDIF
-
 cgi-env/wps_status.zo: service.c
 	$(CPP) /D_CRT_NONSTDC_NO_DEPRECATE -DWIN32 -DZOO_SERVICE $(CFLAGS) /c service.c
-	link /dll /out:cgi-env/wps_status.zo $(FILES) ./service.obj $(LDFLAGS) $(XSLT_DIR)\win32\bin.msvc\libxslt.lib /FORCE:MULTIPLE
+	link /dll /out:cgi-env/wps_status.zo $(FILES) ./service.obj $(LDFLAGS) $(XSLT_DIR)\win32\bin.msvc\libxslt.lib $(ZOOK_DIR)\libzoo_service.lib /FORCE:MULTIPLE
 
 clean:
Index: /trunk/zoo-project/zoo-services/utils/status/service.c
===================================================================
--- /trunk/zoo-project/zoo-services/utils/status/service.c	(revision 679)
+++ /trunk/zoo-project/zoo-services/utils/status/service.c	(revision 680)
@@ -51,8 +51,5 @@
    * return the final ExecuteResponse stored on the Server file system.
    */
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int GetStatus(maps*& conf,maps*& inputs,maps*& outputs){
+  ZOO_DLL_EXPORT int GetStatus(maps*& conf,maps*& inputs,maps*& outputs){
     const char *params[4 + 1];
     int xmlLoadExtDtdDefaultValue;
