Index: trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.c	(revision 378)
+++ trunk/zoo-project/zoo-kernel/service_internal.c	(revision 379)
@@ -1347,8 +1347,16 @@
     maps* mcursor=outputs;
     elements* scursor=serv->outputs;
+    map* testResponse=getMap(request,"RawDataOutput");
+    if(testResponse==NULL)
+      testResponse=getMap(request,"ResponseDocument");
     while(mcursor!=NULL){
+      map* tmp0=getMap(mcursor->content,"inRequest");
       scursor=getElements(serv->outputs,mcursor->name);
       if(scursor!=NULL){
-	printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
+	if(testResponse==NULL)
+	  printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
+	else
+	  if(strncmp(tmp0->value,"true",4)==0)
+	    printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
       }
       mcursor=mcursor->next;
@@ -1599,5 +1607,10 @@
       map* tmp1=getMap(m->content,"encoding");
       map* tmp2=getMap(m->content,"mimeType");
-      map* toto=getMap(m->content,"value");
+      map* tmp3=getMap(m->content,"value");
+      int hasValue=1;
+      if(tmp3==NULL){
+	tmp3=createMap("value","");
+	hasValue=-1;
+      }
       if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0)
 	 || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 ||
@@ -1610,10 +1623,10 @@
 	if(rs==NULL){
 	  char tmp1[1024];
-	  sprintf(tmp1,"%d",strlen(toto->value));
+	  sprintf(tmp1,"%d",strlen(tmp3->value));
 	  rs=createMap("size",tmp1);
 	  isSized=false;
 	}
 
-	xmlAddChild(nc3,xmlNewText(BAD_CAST base64(toto->value, atoi(rs->value))));
+	xmlAddChild(nc3,xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));
 	if(!isSized){
 	  freeMap(&rs);
@@ -1624,21 +1637,25 @@
 	if(strncmp(tmp2->value,"text/js",7)==0 ||
 	   strncmp(tmp2->value,"application/json",16)==0)
-	  xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value)));
+	  xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
 	else{
 	  if(strncmp(tmp2->value,"text/xml",8)==0 ||
 	     strncmp(tmp2->value,"application/vnd.google-earth.kml",32)==0){
 	    xmlDocPtr doc =
-	      xmlParseMemory(toto->value,strlen(toto->value));
+	      xmlParseMemory(tmp3->value,strlen(tmp3->value));
 	    xmlNodePtr ir = xmlDocGetRootElement(doc);
 	    xmlAddChild(nc3,ir);
 	  }
 	  else
-	    xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value));
+	    xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value));
 	}
 	xmlAddChild(nc2,nc3);
       }
       else{
-		  xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value));
-	  }
+	xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value));
+      }
+      if(hasValue<0){
+	freeMap(&tmp3);
+	free(tmp3);
+      }
     }
   }
@@ -1811,24 +1828,37 @@
     asRaw=1;
   
-  map *_tmp=getMapFromMaps(m,"lenv","cookie");
-  map *_tmp1=getMapFromMaps(m,"lenv","sessid");
-  if(_tmp!=NULL){
-    printf("Set-Cookie: %s\r\n",_tmp->value);
-    printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
-    maps *tmpSess=getMaps(m,"senv");
-    if(tmpSess!=NULL){
-      char session_file_path[1024];
-      map *tmpPath=getMapFromMaps(m,"main","sessPath");
-      if(tmpPath==NULL)
-	tmpPath=getMapFromMaps(m,"main","tmpPath");
+  maps* tmpSess=getMaps(m,"senv");
+  if(tmpSess!=NULL){
+    map *_tmp=getMapFromMaps(m,"lenv","cookie");
+    char* sessId;
+    if(_tmp!=NULL){
+      printf("Set-Cookie: %s\r\n",_tmp->value);
+      printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
+      char session_file_path[100];
       char *tmp1=strtok(_tmp->value,";");
       if(tmp1!=NULL)
-	sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(tmp1,"=")+1);
+	sprintf(session_file_path,"%s",strstr(tmp1,"=")+1);
       else
-	sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(_tmp->value,"=")+1);
-      dumpMapsToFile(tmpSess,session_file_path);
-    }
-  }
-
+	sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1);
+      sessId=strdup(session_file_path);
+    }else{
+      maps* t=getMaps(m,"senv");
+      map*p=t->content;
+      while(p!=NULL){
+	if(strstr(p->name,"ID")!=NULL){
+	  sessId=strdup(p->value);
+	  break;
+	}
+	p=p->next;
+      }
+    }
+    char session_file_path[1024];
+    map *tmpPath=getMapFromMaps(m,"main","sessPath");
+    if(tmpPath==NULL)
+      tmpPath=getMapFromMaps(m,"main","tmpPath");
+    sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId);
+    dumpMapsToFile(tmpSess,session_file_path);
+  }
+  
   printHeaders(m);
 
@@ -2472,5 +2502,5 @@
     fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
 #endif
-    char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+38));
+    char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+50));
     sprintf(fname,"%s/%s.zca",tmpM->value,md5str);
     struct stat f_status;
@@ -2495,20 +2525,22 @@
   char* cached=isInCache(m,url);
   int fsize;
+  int hasF=-1;
   if(cached!=NULL){
     struct stat f_status;
     int s=stat(cached, &f_status);
     if(s==0){
-      fprintf(stderr,"FILE SIZE (%d)\n",f_status.st_size/1024);
       fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
       FILE* f=fopen(cached,"rb");
       fread(fcontent,sizeof(char),f_status.st_size,f);
       fsize=f_status.st_size;
+      hasF=1;
     }
   }else{
     res=InternetOpenUrl(hInternet,url,NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
-    fcontent=(char*)calloc((res.nDataLen+1),sizeof(char));
+    fcontent=(char*)malloc((res.nDataLen+1)*sizeof(char));
     if(fcontent == NULL){
       return errorException(m, _("Unable to allocate memory."), "InternalError");
     }
+    hasF=1;
     size_t dwRead;
     InternetReadFile(res, (LPVOID)fcontent, res.nDataLen, &dwRead);
@@ -2524,6 +2556,8 @@
   free(tmpMap->value);
   tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
+  if(tmpMap->value==NULL)
+    fprintf(stderr,"Unable to allocate memory!\n");
   memcpy(tmpMap->value,fcontent,(fsize)*sizeof(char));
-
+  
   char ltmp1[256];
   sprintf(ltmp1,"%d",fsize);
@@ -2531,7 +2565,9 @@
   if(cached==NULL)
     addToCache(m,url,fcontent,fsize);
-  free(fcontent);
-  if(cached!=NULL)
+  else{
+    if(hasF)
+      free(fcontent);
     free(cached);
+  }
   return 0;
 }
