Index: /trunk/thirds/cgic206/cgic.c
===================================================================
--- /trunk/thirds/cgic206/cgic.c	(revision 378)
+++ /trunk/thirds/cgic206/cgic.c	(revision 379)
@@ -23,4 +23,8 @@
 #define CGICDEBUGEND
 #endif /* CGICDEBUG */
+
+#ifdef WIN32
+#define _INC_STDIO
+#endif
 
 #include <stdio.h>
Index: /trunk/thirds/dirent-win32/dirent.h
===================================================================
--- /trunk/thirds/dirent-win32/dirent.h	(revision 378)
+++ /trunk/thirds/dirent-win32/dirent.h	(revision 379)
@@ -1,4 +1,4 @@
 #ifndef DIRENT_INCLUDED
-#define DIRENT_INCLUDED
+#define DIRENT_INCLUDED 1
 
 /*
Index: /trunk/zoo-project/HISTORY.txt
===================================================================
--- /trunk/zoo-project/HISTORY.txt	(revision 378)
+++ /trunk/zoo-project/HISTORY.txt	(revision 379)
@@ -9,4 +9,7 @@
   * Add importScripts function to JavaScript support (ticket #66)
   * Add multiple inputs values for the same identifier (ticket #72)
+  * Add Python ZOO-API to access ZOO-Kernel internel functions
+  * Add a [headers] section in main.cfg file to add specifics to header returned
+  * Add support for multiple outputs
 
 Version 1.2.0-rc3
Index: /trunk/zoo-project/zoo-kernel/service.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service.h	(revision 378)
+++ /trunk/zoo-project/zoo-kernel/service.h	(revision 379)
@@ -33,4 +33,6 @@
 #ifndef snprintf
 #define snprintf sprintf_s
+#else
+
 #endif
 #endif 
@@ -49,4 +51,6 @@
 #define true 1
 #define false -1
+#else
+  //#include <stdbool.h>
 #endif
 
@@ -614,5 +618,5 @@
       sprintf(tmp,"%s_%d",key,index);
     else
-      sprintf(tmp,key);
+      sprintf(tmp,"%s",key);
 #ifdef DEBUG
     fprintf(stderr,"** KEY %s\n",tmp);
@@ -632,5 +636,5 @@
       sprintf(tmp,"%s_%d",key,index);
     else
-      sprintf(tmp,key);
+      sprintf(tmp,"%s",key);
     map* tmpSize=getMapArray(m,"size",index);
     if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
Index: /trunk/zoo-project/zoo-kernel/service_conf.y
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_conf.y	(revision 378)
+++ /trunk/zoo-project/zoo-kernel/service_conf.y	(revision 379)
@@ -151,4 +151,8 @@
 : INFCAR ID Attributeetoile SUPCAR
 {
+#ifdef DEBUG_SERVICE_CONF
+  fprintf(stderr,"(%s %d) %s\n",__FILE__,__LINE__,$2);
+  fflush(stderr);
+#endif
   if(my_service->content==NULL){
 #ifdef DEBUG_SERVICE_CONF
@@ -226,4 +230,5 @@
 #ifdef DEBUG_SERVICE_CONF
 	fprintf(stderr,"(DATAOUTPUTS - %d) ALLOCATE current_element (%s)\n",__LINE__,$2);
+	fflush(stderr);
 #endif
 	current_element=(elements*)malloc(ELEMENTS_SIZE);
@@ -272,4 +277,8 @@
 	  if(wait_metadata==true){
 	    if(current_content!=NULL){
+#ifdef DEBUG_SERVICE_CONF
+	      fprintf(stderr,"add current_content to current_element->content\n");
+	      fprintf(stderr,"LINE %d",__LINE__);
+#endif
 	      addMapToMap(&current_element->metadata,current_content);
 	      current_element->next=NULL;
@@ -290,5 +299,5 @@
 	    current_element->next=NULL;
 	    if($2!=NULL)
-	    current_element->format=strdup($2);
+	      current_element->format=strdup($2);
 	    current_element->defaults=NULL;
 	    current_element->supported=NULL;
@@ -312,4 +321,5 @@
 #ifdef DEBUG_SERVICE_CONF
   printf("* Identifiant : %s\n",$2);
+  fflush(stdout);
 #endif
 }
@@ -357,4 +367,7 @@
 EmptyElemTag
  : INFCAR ID Attributeetoile SLASH SUPCAR	{
+#ifdef DEBUG_SERVICE_CONF
+  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
+#endif
    if(strncasecmp($2,"Default",7)==0){
      wait_defaults=false;
@@ -386,4 +399,7 @@
  : INFCAR SLASH ID SUPCAR
 {
+#ifdef DEBUG_SERVICE_CONF
+  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
+#endif
   if(strcmp($3,"DataInputs")==0){
     current_data=1;
@@ -495,4 +511,5 @@
 | EPAIR {
 #ifdef DEBUG_SERVICE_CONF
+  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
   fprintf(stderr,"EPAIR FOUND !! \n"); 
   fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
@@ -510,5 +527,4 @@
       fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
 #endif
-      //current_content->next=NULL;
     }
     else{ 
@@ -524,7 +540,7 @@
   }
 #ifdef DEBUG_SERVICE_CONF
-  fprintf(stderr,"EPAIR FOUND !! \n"); 
   fprintf(stderr,"[%s=>%s]\n",curr_key,$1);
   fprintf(stderr,"[ZOO: service_conf.y line %d free(%s)]\n",__LINE__,curr_key);
+  dumpMap(current_content);
   fflush(stderr);
 #endif
@@ -540,4 +556,7 @@
 processid
 : ANID  {
+#ifdef DEBUG_SERVICE_CONF
+  fprintf(stderr,"(%s %d)\n",__FILE__,__LINE__);
+#endif
   if(data==-1){
     data=1;
@@ -690,13 +709,27 @@
 	    free(current_element);
 	    current_element=NULL;
+	    current_element=(elements*)malloc(ELEMENTS_SIZE);
+	    char *cen=strdup($1);
+	    current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char));
+	    cen[strlen(cen)-1]=0;
+	    cen+=1;
+	    sprintf(current_element->name,"%s",cen);
+	    cen-=1;
+	    free(cen);
+	    current_element->content=NULL;
+	    current_element->metadata=NULL;
+	    current_element->format=NULL;
+	    current_element->defaults=NULL;
+	    current_element->supported=NULL;
+	    current_element->next=NULL;
 	  }
 	  else{
 #ifdef DEBUG_SERVICE_CONF
 	    fprintf(stderr,"NAME OUT %s\n",$1);
-	    fprintf(stderr,"(DATAOUTPUTS - 545) SET NAME OF current_element\n");
+	    fprintf(stderr,"(DATAOUTPUTS - %d) SET NAME OF current_element %s\n",__LINE__,$1);
 #endif
 	    if($1!=NULL){ 
 	      char *cen=strdup($1);
-	      current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
+	      current_element->name=(char*)malloc((strlen(cen))*sizeof(char*));
 	      cen[strlen(cen)-1]=0;
 #ifdef DEBUG
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;
 }
Index: /trunk/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal_ms.c	(revision 378)
+++ /trunk/zoo-project/zoo-kernel/service_internal_ms.c	(revision 379)
@@ -1,2 +1,26 @@
+/**
+ * Author : Gérald FENOY
+ *
+ *  Copyright 2010-2011 Fondazione Edmund Mach. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
 #ifdef USE_MS
 #ifndef WIN32
@@ -556,5 +580,5 @@
     else
       msInsertHashTable(&(myLayer->metadata), "ows_title", "Default Title");
-
+    
     if(msGrowLayerClasses(myLayer) == NULL)
       return -1;
@@ -566,5 +590,4 @@
     if(initStyle(myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]) == -1)
       return -1;
-
     /**
      * Apply msStyle else fallback to the default style
@@ -583,5 +606,5 @@
       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.green=80;
       myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->outlinecolor.blue=80;
-
+      
       /**
        * Set specific style depending on type
@@ -597,8 +620,9 @@
 	myLayer->CLASS[myLayer->numclasses]->styles[myLayer->CLASS[myLayer->numclasses]->numstyles]->size=15;
       }
-
+      
     }
     myLayer->CLASS[myLayer->numclasses]->numstyles++;
     myLayer->numclasses++;
+    
     m->layerorder[m->numlayers] = m->numlayers;
     m->numlayers++;
Index: /trunk/zoo-project/zoo-kernel/service_internal_ms.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal_ms.h	(revision 378)
+++ /trunk/zoo-project/zoo-kernel/service_internal_ms.h	(revision 379)
@@ -1,2 +1,25 @@
+/**
+ * Author : Gérald FENOY
+ *
+ *  Copyright 2010  Fondazione Edmund Mach. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
 #ifndef ZOO_SERVICE_INTERNAL_MS_H
 #define ZOO_SERVICE_INTERNAL_MS_H 1
Index: /trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 378)
+++ /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 379)
@@ -775,5 +775,5 @@
 	memset(buff1,0,1024);
 #ifdef DEBUG
-	fprintf(stderr,"\n#######%s\n########\n",buff1);
+	printf("\n#######%s\n########\n",buff1);
 #endif
 	while ((dp = readdir(dirp)) != NULL)
@@ -784,8 +784,9 @@
 	    s1=(service*)calloc(1,SERVICE_SIZE);
 	    if(s1 == NULL){
+	      dup2(saved_stdout,fileno(stdout));
 	      return errorException(m, _("Unable to allocate memory."),"InternalError");
 	    }
 #ifdef DEBUG
-	    fprintf(stderr,"#################\n%s\n#################\n",buff1);
+	    printf("#################\n%s\n#################\n",buff1);
 #endif
 	    t=getServiceFromFile(buff1,&s1);
@@ -1325,5 +1326,5 @@
 		  if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0)
 		     && CHECK_INET_HANDLE(hInternet)){
-		    if(loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val)){
+		    if(loadRemoteFile(m,tmpmaps->content,hInternet,(char*)val)!=0){
 		      freeMaps(&m);
 		      free(m);
