Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 676)
+++ 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
