Index: /branches/prototype-v0/zoo-project/zoo-kernel/main_conf_read.y
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/main_conf_read.y	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/main_conf_read.y	(revision 850)
@@ -87,5 +87,5 @@
  ;
 
-pair: PAIR {curr_key=zStrdup($1);}
+pair: PAIR {if(curr_key!=NULL) free(curr_key);curr_key=zStrdup($1);}
 | EPAIR {
   if(current_content==NULL) 
@@ -101,5 +101,5 @@
   curr_key=NULL;
   }
-| SPAIR  {curr_key=zStrdup($1);if(debug) printf("SPAIR FOUND !!\n"); }
+| SPAIR  {if(curr_key!=NULL) free(curr_key);curr_key=zStrdup($1);if(debug) printf("SPAIR FOUND !!\n"); }
  ;
 
Index: /branches/prototype-v0/zoo-project/zoo-kernel/meta_sql.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/meta_sql.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/meta_sql.c	(revision 850)
@@ -144,5 +144,5 @@
       if(strlen(tmp)>0)
 	if(*ap==NULL){
-	  *ap=createMap(fields[i],tmp);
+	  (*ap)=createMap(fields[i],tmp);
 	  addToMap(*ap,"fromDb","true");
 	}
@@ -306,4 +306,5 @@
   // Extract metadata
   fillMetadata(conf,&res->metadata,input->GetFieldAsString( 0 ));
+  res->additional_parameters=NULL;
   fillAdditionalParameters(conf,&res->additional_parameters,input->GetFieldAsString( 0 ));
   res->defaults=NULL;
@@ -401,4 +402,5 @@
       if(minimal==1){
 	OGRFeature::DestroyFeature( poFeature );
+	cleanFetchSql(conf,0,res);
 	return s;
       }
@@ -410,7 +412,12 @@
       while( (input = inputs->GetNextFeature()) != NULL ){
 	elements* in=extractInput(conf,input);
-	addToElements(&s->inputs,in);
-	freeElements(&in);
-	free(in);	
+	if(in!=NULL){
+	  if(s->inputs==NULL)
+	    s->inputs=dupElements(in);
+	  else
+	    addToElements(&s->inputs,in);
+	  freeElements(&in);
+	  free(in);
+	}
 	OGRFeature::DestroyFeature( input );
       }
@@ -424,5 +431,8 @@
       while( (output = outputs->GetNextFeature()) != NULL ){
 	elements* in=extractOutput(conf,output);
-	addToElements(&s->outputs,in);
+	if(s->outputs==NULL)
+	  s->outputs=dupElements(in);
+	else
+	  addToElements(&s->outputs,in);
 	freeElements(&in);
 	free(in);
@@ -463,31 +473,17 @@
     poFeature = res->GetNextFeature();
     while( poFeature != NULL ){
-      fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
-      fflush(stderr);
       service* s=extractServiceFromDb(conf,poFeature->GetFieldAsString( 1 ),minimal);
 #ifdef USE_HPC
       addNestedOutputs(&s);
 #endif
-      fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
-      fflush(stderr);
-      dumpMap(s->content);
-      fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
-      fflush(stderr);
       func(reg,conf,doc,n,s);
-      fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
-      fflush(stderr);
       freeService(&s);
-      fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
-      fflush(stderr);
       free(s);
       OGRFeature::DestroyFeature( poFeature );
       poFeature = res->GetNextFeature();
       result++;
-      fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
-      fflush(stderr);
-    }
-  }
-  fprintf(stderr,"************************* %s %d\n\n",__FILE__,__LINE__);
-  fflush(stderr);
+    }
+    cleanFetchSql(conf,0,res);
+  }
   return result;
 }
Index: /branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 850)
@@ -339,8 +339,8 @@
       }
       else{
-	nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
-	xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
 	if(dcount==0){
 	  if(vid==0){
+	    nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
+	    xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
 	    xmlAddChild(nc2,nc4);
 	    xmlAddChild(nc1,nc2);
@@ -867,23 +867,25 @@
 	}
       }else{
-	xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
-	xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
-	xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
-	xmlAddChild(nc2,nc3);
-	if(fromDb<0){
-	  char *mptr;
-	  char* meta_values=strtok_r(meta->value,",",&mptr);
-	  while(meta_values!=NULL){
+	if(strncasecmp(meta->name,"length",6)!=0 && strncasecmp(meta->name,"fromDb",6)!=0){
+	  xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
+	  xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
+	  xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
+	  xmlAddChild(nc2,nc3);
+	  if(fromDb<0){
+	    char *mptr;
+	    char* meta_values=strtok_r(meta->value,",",&mptr);
+	    while(meta_values!=NULL){
+	      xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
+	      xmlAddChild(nc4,xmlNewText(BAD_CAST meta_values));
+	      xmlAddChild(nc2,nc4);
+	      meta_values=strtok_r(NULL,",",&mptr);
+	    }
+	  }else{
 	    xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	    xmlAddChild(nc4,xmlNewText(BAD_CAST meta_values));
+	    xmlAddChild(nc4,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value)));
 	    xmlAddChild(nc2,nc4);
-	    meta_values=strtok_r(NULL,",",&mptr);
-	  }
-	}else{
-	  xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	  xmlAddChild(nc4,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value)));
-	  xmlAddChild(nc2,nc4);
-	}
-	xmlAddChild(nc1,nc2);
+	  }
+	  xmlAddChild(nc1,nc2);
+	}
 	hasTitle=-1;
       }
@@ -892,5 +894,6 @@
 	xmlAddChild(nc,nc1);
 	hasValue=1;
-      }
+      }else
+	free(ctitle);
     }
     if(oMeta!=NULL && hasValue<0 && nc1!=NULL){
@@ -1404,5 +1407,5 @@
 		}
 		else
-		  xmlFree(nc9);
+		  xmlFreeNode(nc9);
 		if(strcasecmp(tmp1->name,"uom")==0)
 		  hasUOM1=true;
@@ -1601,8 +1604,8 @@
 		  xmlAddChild(nc5,nc6);
 		else
-		  xmlFree(nc6);
+		  xmlFreeNode(nc6);
 	      }
 	      else
-		xmlFree(nc6);
+		xmlFreeNode(nc6);
 	    }
 	    tmp1=tmp1->next;
@@ -1631,10 +1634,13 @@
 	    }
 	    else{
+	      xmlFreeNode(nc4);
 	      xmlAddChild(nc3,nc5);
 	    }
 	  }
 	  else
-	    if(datatype!=1)
+	    if(datatype!=1){
+	      xmlFreeNode(nc4);
 	      xmlAddChild(nc3,nc5);
+	    }
 
 	_tmp=_tmp->next;
@@ -1654,4 +1660,5 @@
 	}
 	else{
+	  xmlFreeNode(nc4);
 	  xmlAddChild(nc3,nc5);
 	}
@@ -1673,4 +1680,5 @@
     }
     if(e->child!=NULL && vid==0){
+      xmlFreeNode(nc3);
       elements* children=dupElements(e->child);
       elements* cursor=children;
@@ -1678,5 +1686,5 @@
 	char* tmp=strdup(cursor->name);
 	free(cursor->name);
-	cursor->name=(char*)malloc((strlen(cursor->name)+strlen(e->name)+2)*sizeof(char));
+	cursor->name=(char*)malloc((strlen(tmp)+strlen(e->name)+2)*sizeof(char));
 	sprintf(cursor->name,"%s.%s",e->name,tmp);
 	cursor=cursor->next;
Index: /branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c	(revision 850)
@@ -460,5 +460,6 @@
 	if(cSize!=NULL){
 	  length=atoi(cSize->value);
-	}
+	}else
+	  length=strlen(cValue->value);
 	writeFile(val,cValue->value,length);
 	addToMap(cMap,"cache_file",val);
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 850)
@@ -417,6 +417,6 @@
     if(tmp->format!=NULL)
       free(tmp->format);
+    freeElements(&tmp->child);
     if(tmp->child!=NULL){
-      freeElements(&tmp->child);
       free(tmp->child);
     }
@@ -453,4 +453,7 @@
     if(tmp->metadata!=NULL)
       free(tmp->metadata);
+    freeMap(&tmp->additional_parameters);
+    if(tmp->additional_parameters!=NULL)
+      free(tmp->additional_parameters);
     freeElements(&tmp->inputs);
     if(tmp->inputs!=NULL)
@@ -1160,5 +1163,5 @@
   elements* cursor=e;
   elements* tmp=NULL;
-  if(cursor!=NULL && e->name!=NULL){
+  if(cursor!=NULL && cursor->name!=NULL){
 #ifdef DEBUG
     fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
@@ -1167,5 +1170,5 @@
 #endif
     tmp=(elements*)malloc(ELEMENTS_SIZE);
-    tmp->name=zStrdup(e->name);
+    tmp->name=zStrdup(cursor->name);
     tmp->content=NULL;
     addMapToMap(&tmp->content,e->content);
@@ -1228,5 +1231,5 @@
   elements* tmp=e;
   if(*m==NULL){
-    *m=dupElements(tmp);
+    (*m)=dupElements(tmp);
   }else{
     addToElements(&(*m)->next,tmp);
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service.h
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 850)
@@ -139,5 +139,5 @@
  * The memory size to create an elements
  */
-#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*3)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*)))
+#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*3)+sizeof(char*)+((sizeof(map*) + sizeof(iotype*))*2)+(2*sizeof(elements*)))
 /**
  * The memory size to create a map
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c	(revision 850)
@@ -35,4 +35,23 @@
 #endif
 
+  /**
+   * Check if a service name is prohibited, meaning that we don't have to invoke
+   * the callback for this specific service.
+   *
+   */
+  bool isProhibited(maps* conf,const char* serviceName){
+    map* plist=getMapFromMaps(conf,"callback","prohibited");
+    if(plist!=NULL){
+      char *tmp=plist->value;
+      char *tmpS=strtok(tmp,",");
+      while(tmpS!=NULL){
+	if(strcmp(serviceName,tmpS)==0)
+	  return true;
+	tmpS=strtok(NULL,",");
+      }
+    }
+    return false;
+  }
+  
   /**
    * Invoke the callback in case there is a [callback] section containing a url parameter
@@ -57,7 +76,10 @@
     if(url==NULL)
       return false;
-
+      
     maps* lenv=getMaps(m,"lenv");
-
+    map* sname=getMap(lenv->content,"identifier");
+    if(sname!=NULL && isProhibited(m,sname->value))
+      return false;
+      
     json_object *res=json_object_new_object();
 
@@ -87,5 +109,5 @@
       maps* curs=inputs;
       
-      char *keys[4][2]={
+      char *keys[8][2]={
 	{
 	  "href",
@@ -103,10 +125,27 @@
 	  "size",
 	  "size"
-	}
+	},
+	{
+	  "ref_wms_link",
+	  "ref_wms_link"
+	},
+	{
+	  "ref_wcs_link",
+	  "ref_wcs_link"
+	},
+	{
+	  "ref_wfs_link",
+	  "ref_wfs_link"
+	},
+	{
+	  "datatype",
+	  "datatype"
+	}	
       };
       json_object *res1=json_object_new_object();
       while(curs!=NULL){
 	map* tmpMap=getMap(curs->content,"cache_file");
-	if(tmpMap!=NULL){
+	sid=getMap(curs->content,"ref_wms_link");
+	if(tmpMap!=NULL && sid==NULL){
 	  addToMap(curs->content,"generated_file",tmpMap->value);
 	  tmpMap=getMap(curs->content,"fmimeType");
@@ -121,5 +160,5 @@
 	int i=0;
 	int hasRef=-1;
-	for(;i<4;i++){
+	for(;i<8;i++){
 	  sid=getMap(curs->content,keys[i][0]);
 	  if(sid!=NULL){
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 850)
@@ -80,4 +80,6 @@
 	  }
 	  free(tmp[i]->name);
+	  if(tmp[i]->format!=NULL)
+	    free(tmp[i]->format);
 	  tmp[i]->format=zStrdup("ComplexData");
 	  freeMap(&tmp[i]->content);
@@ -160,4 +162,5 @@
     cur=cur->next;
   }
+  //dumpElements((*s)->outputs);
 }
 
@@ -351,10 +354,4 @@
   }
   
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
-  invokeCallback(m,inputs,NULL,3,0);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
-
   // Produce the SBATCH File locally
   char *scriptPath=(char*)malloc((strlen(s->name)+strlen(tmpPath->value)+strlen(uuid->value)+10)*sizeof(char));
@@ -489,5 +486,9 @@
       setMapInMaps(*main_conf,"lenv","message",_("Unable to fetch the remote error log file"));
     tmpPath=getMapFromMaps(*main_conf,"lenv","message");
+    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+    fflush(stderr);
     invokeCallback(m,NULL,NULL,7,1);
+    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+    fflush(stderr);
     sprintf(tmpS, "Cannot execute the HPC ZOO-Service %s: %s", s->name, tmpPath->value);
     errorException(m,tmpS,"NoApplicableCode",NULL);
@@ -533,8 +534,10 @@
 	sleep(1);
 	setMapInMaps(*main_conf,"lenv","message",_("Read closed"));
+	invokeCallback(m,NULL,NULL,7,1);
 	return -1;
       }else{
 	if(rc<0){
 	  setMapInMaps(*main_conf,"lenv","message",_("Read error"));
+	  invokeCallback(m,NULL,NULL,7,1);
 	  return -1;
 	}
@@ -543,5 +546,5 @@
       res=atoi(buf);
       unlink(sname);
-      //free(sname);  
+      //free(sname);
 
       if(res==3){
@@ -597,4 +600,9 @@
 	  input=input->next;
 	}
+	fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+	fflush(stderr);
+	invokeCallback(m,NULL,outputs,5,1);
+	fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+	fflush(stderr);
       }
       //free(buf);
@@ -607,5 +615,9 @@
     }
   }
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+  fflush(stderr);
   ssh_close(*main_conf);
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+  fflush(stderr);
   return res;
 }
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 850)
@@ -194,44 +194,68 @@
 
   char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(format->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char));
-
+  map* datatype=getMap(tmpI->content,"datatype");
+  
+  sprintf(webService_url,
+	  "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
+	  msUrl->value,
+	  dataPath->value,
+	  tmpI->name,
+	  sid->value,
+	  options[proto][2],
+	  options[proto][0],
+	  protoVersion,
+	  layers,
+	  rformat->value,
+	  extent->value,
+	  crs->value
+	  );
   if(proto>0){
-    sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
-	    msUrl->value,
-	    dataPath->value,
-	    tmpI->name,
-	    sid->value,
-	    options[proto][2],
-	    options[proto][0],
-	    protoVersion,
-	    layers,
-	    rformat->value,
-	    extent->value,
-	    crs->value
-	    );
+    addToMap(tmpI->content,"Reference",webService_url);
+    proto=0;
+    rformat=createMap("mimeType","image/png");
   }
   else{
-    sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
-	    msUrl->value,
-	    dataPath->value,
-	    tmpI->name,
-	    sid->value,
-	    options[proto][2],
-	    options[proto][0],
-	    protoVersion,
-	    layers,
-	    width->value,
-	    height->value,
-	    rformat->value,
-	    extent->value,
-	    crs->value
-	    );
-  }
+    if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
+      proto=2;
+      rformat=createMap("mimeType","image/tiff");
+    }
+    else{
+      proto=1;
+      rformat=createMap("mimeType","text/xml");
+    }
+  }
+  if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
+    addToMap(tmpI->content,"ref_wcs_link",webService_url);
+  }
+  else{
+    addToMap(tmpI->content,"ref_wfs_link",webService_url);
+  }
+  protoVersion=options[proto][1];
+  extent=getMap(tmpI->content,options[proto][4]);
+  memset(webService_url,0,strlen(webService_url));
+  sprintf(webService_url,
+	  "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
+	  msUrl->value,
+	  dataPath->value,
+	  tmpI->name,
+	  sid->value,
+	  options[proto][2],
+	  options[proto][0],
+	  protoVersion,
+	  layers,
+	  width->value,
+	  height->value,
+	  rformat->value,
+	  extent->value,
+	  crs->value
+	  );
+  if(proto>0){
+    addToMap(tmpI->content,"Reference",webService_url);
+  }
+  addToMap(tmpI->content,"ref_wms_link",webService_url);
   if(hasCRS==0){
     freeMap(&crs);
     free(crs);
   }
-  addToMap(tmpI->content,"Reference",webService_url);
   free(webService_url);
 }
@@ -531,5 +555,5 @@
   free(sdsName);
   free(dsName);
-
+  
   OGRDataSourceH poDS = NULL;
   OGRSFDriverH *poDriver = NULL;
@@ -548,4 +572,5 @@
   }
 
+  addToMap(output->content,"datatype","vector");
   int iLayer = 0;
   for( iLayer=0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++ ){
@@ -757,4 +782,5 @@
 #endif
 
+  addToMap(output->content,"datatype","raster");
   /**
    * Add a new layer set name, data
Index: /branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c	(revision 850)
@@ -396,4 +396,5 @@
 char* _getStatus(maps* conf,char* pid){
   int zoo_ds_nb=getCurrentId(conf);
+  int created=-1;
   map *schema=getMapFromMaps(conf,"database","schema");
   char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
@@ -408,4 +409,5 @@
     init_sql(conf);
     zoo_ds_nb++;
+    created=1;
   }
   execSql(conf,zoo_ds_nb-1,sqlQuery);
Index: /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c	(revision 850)
@@ -286,4 +286,5 @@
 	  int length=strlen(token)+6;
 	  char* tmp1=(char*)malloc(length*sizeof(char));
+	  map* tmpMap;
 	  snprintf(tmp1,6,"HTTP_");
 	  int j;
@@ -296,7 +297,9 @@
 	  }
 	  fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,tmp1);
-	  map* tmpMap = getMapFromMaps(conf,"renv",tmp1);
-	  if(tmpMap!=NULL)	    
-	    AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value);
+	  if(strncmp(tmp1,"HTTP_COOKIE",11)!=0){	    
+	    tmpMap = getMapFromMaps(conf,"renv",tmp1);
+	    if(tmpMap!=NULL)
+	      AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value);
+	  }
 	  free(tmp1);
 	  if(handle->ihandle[i].header!=NULL)
Index: /branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 849)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 850)
@@ -304,5 +304,5 @@
       {
         char* extn = strstr(dp->d_name, ".zcfg");
-        if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5)
+        if(dp->d_name[0] != '.' && extn != NULL && strlen(extn) == 5 && strlen(dp->d_name)>6)
           {
             int t;
@@ -311,6 +311,7 @@
             snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name);
 
-            char *tmpsn = zStrdup (dp->d_name);
-            tmpsn[strlen (tmpsn) - 5] = 0;
+	    char *tmpsn = (char*)malloc((strlen(dp->d_name)-4)*sizeof(char));//zStrdup (dp->d_name);
+	    memset (tmpsn, 0, strlen(dp->d_name)-4);
+	    snprintf(tmpsn,strlen(dp->d_name)-4,"%s",dp->d_name);
             
             map* import = getMapFromMaps (m, IMPORTSERVICE, tmpsn);
@@ -1181,5 +1182,13 @@
   };
   r_inputs = getMap (request_inputs, "Request");
-  REQUEST = zStrdup (r_inputs->value);
+  fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
+  fflush(stderr);
+  dumpMap(r_inputs);
+  fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
+  fflush(stderr);
+  if(r_inputs!=NULL)
+    REQUEST = zStrdup (r_inputs->value);
+  fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
+  fflush(stderr);
   int reqId=-1;
   if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){
@@ -1188,5 +1197,5 @@
     for(j=0;j<nbSupportedRequests;j++){
       if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){
-	if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(REQUEST))==0){
+	if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){
 	  checkValidValue(request_inputs,&err,"identifier",NULL,1);
 	  reqId=j+1;
@@ -1195,5 +1204,5 @@
 	else
 	  if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob && 
-	     strncasecmp(REQUEST,requests[vid][j+1],strlen(REQUEST))==0){
+	     strncasecmp(REQUEST,requests[vid][j+1],strlen(requests[vid][j+1]))==0){
 	    checkValidValue(request_inputs,&err,"jobid",NULL,1);
 	    reqId=j+1;
@@ -1358,7 +1367,14 @@
       r_inputs = getMap (request_inputs, "JobId");
       if(reqId>nbReqIdentifier){
-	if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 ||
-	    strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){
+	if (strncasecmp (REQUEST, "GetStatus", 9) == 0 ||
+	    strncasecmp (REQUEST, "GetResult", 9) == 0){
 	  runGetStatus(m,r_inputs->value,REQUEST);
+#ifdef RELY_ON_DB
+	  map* dsNb=getMapFromMaps(m,"lenv","ds_nb");
+	  if(dsNb!=NULL && atoi(dsNb->value)>1)
+	    close_sql(m,1);
+	  close_sql(m,0);
+#endif
+	  
 	  freeMaps (&m);
 	  free(m);
@@ -2160,5 +2176,6 @@
     addToMap (_tmpMaps->content, "soap", "false");
 
-  // Parse the session file and add it to the main maps 
+  // Parse the session file and add it to the main maps
+  char* originalCookie=NULL;
   if (cgiCookie != NULL && strlen (cgiCookie) > 0)
     {
@@ -2252,8 +2269,9 @@
   _tmpMaps = createMaps("renv");
   for (; s; ei++) {
+    int len=strlen(s);
     char* tmpName=zStrdup(s);
     char* tmpValue=strstr(s,"=")+1;
-    char* tmpName1=(char*)malloc((1+(strlen(tmpName)-strlen(tmpValue)))*sizeof(char));
-    snprintf(tmpName1,(strlen(tmpName)-strlen(tmpValue)),"%s",tmpName);
+    char* tmpName1=(char*)malloc((1+(len-strlen(tmpValue)))*sizeof(char));
+    snprintf(tmpName1,(len-strlen(tmpValue))+1,"%s",tmpName);
     if(_tmpMaps->content == NULL)
       _tmpMaps->content = createMap (tmpName1,tmpValue);
@@ -2263,4 +2281,12 @@
     free(tmpName1);
     s = *(orig+ei);
+  }
+  if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){
+    /*map* tmpMap1=getMap(_tmpMaps->content,"HTTP_COOKIE");
+    free(tmpMap1->value);
+    tmpMap1->value=zStrdup(cgiCookie);*/
+    fprintf(stderr,"[%s]\n",cgiCookie);
+    addToMap(_tmpMaps->content,"HTTP_COOKIE1",&cgiCookie[0]);
+    dumpMap(_tmpMaps->content);
   }
   addMapsToMaps (&m, _tmpMaps);
@@ -2292,7 +2318,4 @@
   }
 #endif
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  invokeCallback(m,NULL,NULL,0,0);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 
   char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog;
@@ -2446,4 +2469,7 @@
 	  recordServiceStatus(m);
 #endif
+	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+	  invokeCallback(m,NULL,NULL,0,0);
+	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	  if(vid==0){
 	    /**
@@ -2513,4 +2539,7 @@
 	    return -1;
 	  }
+	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+	  invokeCallback(m,request_input_real_format,NULL,1,1);
+	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	  setMapInMaps(m,"lenv","ds_nb","1");
           loadServiceAndRun (&m, s1, request_inputs,
