Index: trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.c	(revision 485)
+++ trunk/zoo-project/zoo-kernel/service_internal.c	(revision 490)
@@ -181,9 +181,8 @@
 
 void unhandleStatus(maps *conf){
-  int shmid,i;
+  int shmid;
   key_t key;
   void *shm;
   struct shmid_ds shmids;
-  char *s,*s1;
   map *tmpMap=getMapFromMaps(conf,"lenv","sid");
   if(tmpMap!=NULL){
@@ -207,5 +206,5 @@
 
 int _updateStatus(maps *conf){
-  int shmid,i;
+  int shmid;
   key_t key;
   char *shm,*s,*s1;
@@ -247,8 +246,7 @@
 
 char* getStatus(int pid){
-  int shmid,i;
+  int shmid;
   key_t key;
   void *shm;
-  char *s;
   key=pid;
   if ((shmid = shmget(key, SHMSZ, 0666)) < 0) {
@@ -265,5 +263,5 @@
     }
   }
-  return "-1";
+  return (char*)"-1";
 }
 
@@ -277,9 +275,7 @@
   jsval *argv = JS_ARGV(cx,argv1);
   JS_MaybeGC(cx);
-  char *sid;
   int istatus=0;
   char *status=NULL;
   maps *conf;
-  int i=0;
   if(argc>2){
 #ifdef JS_DEBUG
@@ -385,5 +381,4 @@
 #endif
   int currId=-1;
-  int currNode=-1;
   if(nbNs==0){
     nbNs++;
@@ -419,4 +414,22 @@
   nbNs=0;
 }
+
+
+int zooXmlAddDoc(const char* value){
+  int currId=0;
+  nbDocs++;
+  currId=nbDocs-1;
+  iDocs[currId]=xmlParseMemory(value,strlen(value));
+  return currId;
+}
+
+void zooXmlCleanupDocs(){
+  int j;
+  for(j=nbDocs-1;j>=0;j--){
+    xmlFreeDoc(iDocs[j]);
+  }
+  nbDocs=0;
+}
+
 
 xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){
@@ -447,7 +460,5 @@
 
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
-  xmlChar *xmlbuff;
-  int buffersize;
+  xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6;
   /**
    * Create the document and its temporary root.
@@ -486,5 +497,5 @@
   if(tmp4!=NULL){
     map* tmp2=tmp4->content;
-    char *orderedFields[5];
+    const char *orderedFields[5];
     orderedFields[0]="Title";
     orderedFields[1]="Abstract";
@@ -555,5 +566,5 @@
   if(tmp4!=NULL){
     map* tmp2=tmp4->content;
-    char *tmpAddress[6];
+    const char *tmpAddress[6];
     tmpAddress[0]="addressDeliveryPoint";
     tmpAddress[1]="addressCity";
@@ -562,8 +573,8 @@
     tmpAddress[4]="addressCountry";
     tmpAddress[5]="addressElectronicMailAddress";
-    char *tmpPhone[2];
+    const char *tmpPhone[2];
     tmpPhone[0]="phoneVoice";
     tmpPhone[1]="phoneFacsimile";
-    char *orderedFields[12];
+    const char *orderedFields[12];
     orderedFields[0]="providerName";
     orderedFields[1]="providerSite";
@@ -608,8 +619,6 @@
 		  for(j=0;j<2;j++)
 		    if(strcasecmp(tmp2->name,tmpPhone[j])==0){
-		      char *toto=NULL;
-		      char *toto1=tmp2->name;
-		      toto=strstr(toto1,"Phone");
-		      nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+5);
+		      char *tmp4=tmp2->name;
+		      nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+5);
 		      xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
 		      xmlAddChild(nc5,nc1);
@@ -621,8 +630,6 @@
 		    for(j=0;j<6;j++)
 		      if(strcasecmp(tmp2->name,tmpAddress[j])==0){
-			char *toto=NULL;
-			char *toto1=tmp2->name;
-			toto=strstr(toto1,"Address");
-			nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+7);
+			char *tmp4=tmp2->name;
+			nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+7);
 			xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
 			xmlAddChild(nc6,nc1);
@@ -799,5 +806,5 @@
 void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){
   xmlNsPtr ns,ns_ows,ns_xlink;
-  xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
+  xmlNodePtr n=NULL,nc1,nc2;
   /**
    * Initialize or get existing namspaces
@@ -810,5 +817,4 @@
   ns_xlink=usedNs[xlinkId];
 
-  int cursor=0;
   map* tmp1;
   if(serv->content!=NULL){
@@ -833,14 +839,11 @@
 xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,const char* service,maps* m){
 
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr n,nr;
-  xmlChar *xmlbuff;
-  int buffersize;
+  xmlNsPtr ns,ns_xsi;
+  xmlNodePtr n;
 
   int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps");
   ns=usedNs[wpsId];
   n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions");
-  int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
-  ns_ows=usedNs[owsId];
+  zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
   xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
   zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
@@ -860,8 +863,7 @@
 
 void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv){
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
-
-  char tmp[256];
+  xmlNsPtr ns,ns_ows,ns_xlink;
+  xmlNodePtr n,nc1;
+
   n=nc;
   
@@ -874,5 +876,5 @@
 
   nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription");
-  char *tmp4[3];
+  const char *tmp4[3];
   tmp4[0]="processVersion";
   tmp4[1]="storeSupported";
@@ -916,5 +918,5 @@
     nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs");
     elements* e=serv->inputs;
-    printFullDescription(e,"Input",ns_ows,nc1);
+    printFullDescription(1,e,"Input",ns_ows,nc1);
     xmlAddChild(nc,nc1);
   }
@@ -922,5 +924,5 @@
   nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
   elements* e=serv->outputs;
-  printFullDescription(e,"Output",ns_ows,nc1);
+  printFullDescription(0,e,"Output",ns_ows,nc1);
   xmlAddChild(nc,nc1);
 
@@ -929,6 +931,6 @@
 }
 
-void printFullDescription(elements *elem,const char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){
-  char *orderedFields[13];
+void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){
+  const char *orderedFields[13];
   orderedFields[0]="mimeType";
   orderedFields[1]="encoding";
@@ -1001,5 +1003,4 @@
     iotype* _tmp=e->defaults;
     int datatype=0;
-    bool hasDefault=false;
     bool hasUOM=false;
     bool hasUOM1=false;
@@ -1079,5 +1080,5 @@
 	     * RangeClosure: Table 47 OGC Web Services Common Standard
 	     */
-	    char *tmp="closed";
+	    const char *tmp="closed";
 	    if(orig[0]=='[' && orig[strlen(orig)-1]=='[')
 	      tmp="closed-open";
@@ -1146,5 +1147,5 @@
 	    tmp0=getMap(tmp1,"rangeClosure");
 	    if(tmp0!=NULL){
-	      char *tmp="closed";
+	      const char *tmp="closed";
 	      if(strcasecmp(tmp0->value,"co")==0)
 		tmp="closed-open";
@@ -1190,6 +1191,4 @@
     
       
-    int avcnt=0;
-    int dcnt=0;
     int oI=0;
     for(oI=0;oI<13;oI++)
@@ -1247,5 +1246,5 @@
 
       map* metadata=e->metadata;
-      xmlNodePtr n;
+      xmlNodePtr n=NULL;
       int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
       xmlNsPtr ns_xlink=usedNs[xlinkId];
@@ -1353,5 +1352,5 @@
     }
 
-    if(datatype==1 &&
+    if(in>0 && datatype==1 &&
        getMap(_tmp->content,"AllowedValues")==NULL &&
        getMap(_tmp->content,"range")==NULL &&
@@ -1389,9 +1388,7 @@
 
 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
-  xmlNsPtr ns,ns1,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor;
+  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
+  xmlNodePtr nr,n,nc,nc1=NULL,nc3;
   xmlDocPtr doc;
-  xmlChar *xmlbuff;
-  int buffersize;
   time_t time1;  
   time(&time1);
@@ -1574,5 +1571,4 @@
   if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){
     nc = xmlNewNode(ns, BAD_CAST "DataInputs");
-    int i;
     maps* mcursor=inputs;
     elements* scursor=NULL;
@@ -1727,5 +1723,5 @@
 
 void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,const char* type){
-  xmlNodePtr nc1,nc2,nc3;
+  xmlNodePtr nc1;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
   map *tmp=NULL;  
@@ -1774,6 +1770,4 @@
   xmlAddChild(nc1,nc2);
   xmlAddChild(nc,nc1);
-  // Extract Title required to be first element in the ZCFG file !
-  bool isTitle=TRUE;
   if(e!=NULL)
     tmp=getMap(e->content,"Title");
@@ -1836,18 +1830,20 @@
 	 strcasecmp(tmp->name,"schema")==0 ||
 	 strcasecmp(tmp->name,"datatype")==0 ||
-	 strcasecmp(tmp->name,"uom")==0)
+	 strcasecmp(tmp->name,"uom")==0){
 #ifdef USE_MS
 	if(testMap==NULL || (testMap!=NULL && strncasecmp(testMap->value,"text/xml",8)==0)){
 #endif
-	xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
+	  xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
 #ifdef USE_MS
 	}
-      else
-	if(strcasecmp(tmp->name,"mimeType")==0)
-	  if(testMap!=NULL)
-	    xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST testMap->value);
-	  else 
-	    xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
-#endif
+	else
+	  if(strcasecmp(tmp->name,"mimeType")==0){
+	    if(testMap!=NULL)
+	      xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST testMap->value);
+	    else 
+	      xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
+	  }
+#endif
+      }
       tmp=tmp->next;
       xmlAddChild(nc2,nc3);
@@ -1897,8 +1893,8 @@
       if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0)
 	 || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 ||
-			    (strncmp(tmp2->value,"application/",12)==0) &&
-			    strncmp(tmp2->value,"application/json",16)!=0&&
-			    strncmp(tmp2->value,"application/x-javascript",24)!=0&&
-			    strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0)
+			    (strncmp(tmp2->value,"application/",12)==0 &&
+			     strncmp(tmp2->value,"application/json",16)!=0&&
+			     strncmp(tmp2->value,"application/x-javascript",24)!=0&&
+			     strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0))
 	     )) {
 	map* rs=getMap(m->content,"size");
@@ -1906,5 +1902,5 @@
 	if(rs==NULL){
 	  char tmp1[1024];
-	  sprintf(tmp1,"%d",strlen(tmp3->value));
+	  sprintf(tmp1,"%u",strlen(tmp3->value));
 	  rs=createMap("size",tmp1);
 	  isSized=false;
@@ -1924,6 +1920,6 @@
 	  if(strncmp(tmp2->value,"text/xml",8)==0 ||
 	     strncmp(tmp2->value,"application/vnd.google-earth.kml",32)==0){
-	    xmlDocPtr doc =
-	      xmlParseMemory(tmp3->value,strlen(tmp3->value));
+	    int li=zooXmlAddDoc(tmp3->value);
+	    xmlDocPtr doc = iDocs[li];
 	    xmlNodePtr ir = xmlDocGetRootElement(doc);
 	    xmlAddChild(nc3,ir);
@@ -1959,5 +1955,5 @@
 	 strcasecmp(tmp->name,"schema")==0 ||
 	 strcasecmp(tmp->name,"datatype")==0 ||
-	 strcasecmp(tmp->name,"uom")==0)
+	 strcasecmp(tmp->name,"uom")==0){
 #ifdef USE_MS
 	if(testMap!=NULL  && strncasecmp(testMap->value,"text/xml",8)!=0){
@@ -1967,5 +1963,6 @@
 	else
 #endif
-	xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
+	  xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
+      }
       tmp=tmp->next;
       xmlAddChild(nc2,nc3);
@@ -1983,5 +1980,5 @@
   xmlAddChild(root,nc2);
   map* tmp=amap;
-  char *tmp2[2];
+  const char *tmp2[2];
   tmp2[0]="Title";
   tmp2[1]="Abstract";
@@ -2004,8 +2001,8 @@
     }
     else
-      return "UTF-8";
+      return (char*)"UTF-8";
   }
   else
-    return "UTF-8";  
+    return (char*)"UTF-8";  
 }
 
@@ -2017,8 +2014,8 @@
     }
     else
-      return "1.0.0";
+      return (char*)"1.0.0";
   }
   else
-    return "1.0.0";
+    return (char*)"1.0.0";
 }
 
@@ -2035,5 +2032,5 @@
   maps* tmpMap=getMaps(m,"main");
   char *encoding=getEncoding(tmpMap);
-  char *exceptionCode;
+  const char *exceptionCode;
   
   map* tmp=getMap(s,"code");
@@ -2087,10 +2084,6 @@
 xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){
   
-  int buffersize;
-  xmlChar *xmlbuff;
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr n,nc,nc1,nc2;
-
-  maps* tmpMap=getMaps(m,"main");
+  xmlNsPtr ns,ns_xsi;
+  xmlNodePtr n,nc,nc1;
 
   int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows");
@@ -2101,5 +2094,5 @@
   n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
   if(use_ns==1){
-    ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",NULL);
+    xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",NULL);
     int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
     ns_xsi=usedNs[xsiId];
@@ -2126,5 +2119,4 @@
   tmp=getMap(s,"text");
   nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
-  nc2=NULL;
   if(tmp!=NULL){
     xmlNodeSetContent(nc1, BAD_CAST tmp->value);
@@ -2154,5 +2146,5 @@
   if(tmpSess!=NULL){
     map *_tmp=getMapFromMaps(m,"lenv","cookie");
-    char* sessId;
+    char* sessId=NULL;
     if(_tmp!=NULL){
       printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
@@ -2493,5 +2485,5 @@
       if(type==0){
 	map* tmpMapMinO=getMap(tmpInputs->content,"minOccurs");
-	if(tmpMapMinO!=NULL)
+	if(tmpMapMinO!=NULL){
 	  if(atoi(tmpMapMinO->value)>=1){
 	    freeMaps(&tmpMaps2);
@@ -2505,16 +2497,19 @@
 	      addToMap(tmpMaps2->content,"minOccurs",tmpMapMinO->value);
 	  }
+	}
 	map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
-	if(tmpMaxO!=NULL)
+	if(tmpMaxO!=NULL){
 	  if(tmpMaps2->content==NULL)
 	    tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value);
 	  else
 	    addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value);
+	}
 	map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
-	if(tmpMaxMB!=NULL)
+	if(tmpMaxMB!=NULL){
 	  if(tmpMaps2->content==NULL)
 	    tmpMaps2->content=createMap("maximumMegabytes",tmpMaxMB->value);
 	  else
 	    addToMap(tmpMaps2->content,"maximumMegabytes",tmpMaxMB->value);
+	}
       }
 
@@ -2572,9 +2567,10 @@
 	}
 	map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
-	if(tmpMaxMB!=NULL)
+	if(tmpMaxMB!=NULL){
 	  if(tmpMaps->content==NULL)
 	    tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value);
 	  else
 	    addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value);
+	}
 	/**
 	 * Parsing BoundingBoxData, fill the following map and then add it to
@@ -2746,5 +2742,5 @@
 void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){
 
-  xmlNodePtr bb,lw,uc;
+  xmlNodePtr lw=NULL,uc=NULL;
 
   map* tmp=getMap(boundingbox,"value");
@@ -2876,5 +2872,5 @@
     fprintf(stderr,"MIMETYPE: %s\n",mimeType);
 #endif
-    fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
+    fwrite(mimeType,1,strlen(mimeType),fo);
     fclose(fo);
 
@@ -2914,6 +2910,5 @@
   char* cached=isInCache(*m,url);
   char *mimeType=NULL;
-  int fsize;
-  int hasF=-1;
+  int fsize=0;
   if(cached!=NULL){
     struct stat f_status;
@@ -2922,5 +2917,5 @@
       fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
       FILE* f=fopen(cached,"rb");
-      int len=fread(fcontent,f_status.st_size,1,f);
+      fread(fcontent,f_status.st_size,1,f);
       fsize=f_status.st_size;
       fcontent[fsize]=0;
@@ -2932,5 +2927,5 @@
       mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1));
       FILE* f=fopen(cached,"rb");
-      int len=fread(mimeType,f_status.st_size,1,f);
+      fread(mimeType,f_status.st_size,1,f);
       mimeType[f_status.st_size]=0;
       fclose(f);
@@ -2970,9 +2965,7 @@
   if(cached==NULL)
     addToCache(*m,url,fcontent,mimeType,fsize);
-  else{
-    free(fcontent);
-    free(mimeType);
-    free(cached);
-  }
+  free(fcontent);
+  free(mimeType);
+  free(cached);
   return 0;
 }
@@ -2992,4 +2985,5 @@
 }
 
+
 char *readVSIFile(maps* conf,const char* dataSource){
     VSILFILE * fichier=VSIFOpenL(dataSource,"rb");
@@ -3004,5 +2998,6 @@
     }
     char *res1=(char *)malloc(file_status.st_size*sizeof(char));
-    VSIFReadL(res1,1,(file_status.st_size)*sizeof(char),fichier);
+    VSIFReadL(res1,1,file_status.st_size*sizeof(char),fichier);
+    res1[file_status.st_size-1]=0;
     VSIFCloseL(fichier);
     VSIUnlink(dataSource);
@@ -3065,5 +3060,4 @@
 }
 
-
 int updateStatus( maps* conf, const int percentCompleted, const char* message ){
   char tmp[4];
@@ -3098,5 +3092,5 @@
     tmp->value=(char*) malloc((numberOfBytes+1)*sizeof(char));
     memcpy(tmp->value,data,numberOfBytes);
-    sprintf(size,"%d",numberOfBytes);
+    sprintf(size,"%lu",numberOfBytes);
     setMapInMaps(outputs,parameterName,"size",size);
   }
