Index: trunk/zoo-kernel/service_conf.y
===================================================================
--- trunk/zoo-kernel/service_conf.y	(revision 1)
+++ trunk/zoo-kernel/service_conf.y	(revision 9)
@@ -13,5 +13,5 @@
 #include <ctype.h>
 #include <service.h>
-#include <vector>
+  //#include <vector>
 
 static int tmp_count=1;
@@ -65,6 +65,7 @@
 // srlex
 extern int srlex(void);
-
-vector<char*> lattribute;
+extern int srlex_destroy(void);
+
+//vector<char*> lattribute;
 
 %}
@@ -132,11 +133,11 @@
  : STag contentetoile ETag	
 {
-  if (strcmp($1,$3) != 0)
+  /*if (strcasecmp($1,$3) != 0)
     {
-      //srerror("Opening and ending tag mismatch");
       fprintf(stderr,"Opening and ending tag mismatch\n  ::details : tag '%s' et '%s' \n",$1,$3);
-      lattribute.clear();
+      //lattribute.clear();
       //return 1;
-    }
+      }*/
+  free($3);
 }
 // pour neutre
@@ -159,13 +160,13 @@
   /* parce que cet element est reconnu AVANT la balise fermante */
   /* et APRES l'analyse des eventuelles balises internes ou successeur */
-  lattribute.clear();
-	
+  //lattribute.clear();
+
   if(my_service->content==NULL){
 #ifdef DEBUG_SERVICE_CONF
     fprintf(stderr,"NO CONTENT\n");
 #endif
-    //addMapToMap(&my_service->content,current_content);
-    //freeMap(&current_content);
-    my_service->content=current_content;
+    addMapToMap(&my_service->content,current_content);
+    freeMap(&current_content);
+    free(current_content);
     current_content=NULL;
     my_service->metadata=NULL;
@@ -173,12 +174,9 @@
   }
 
-  if(strcmp($2,"DataInputs")==0){
+  if(strncasecmp($2,"DataInputs",10)==0){
     if(wait_mainmetadata==true){
-      if(my_service->metadata==NULL)
-	my_service->metadata=current_content;
-      else{
-	addMapToMap(&my_service->metadata,current_content);
-	freeMap(&current_content);
-      }
+      addMapToMap(&my_service->metadata,current_content);
+      freeMap(&current_content);
+      free(current_content);
       current_content=NULL;
     }
@@ -208,15 +206,24 @@
   }
   else
-    if(strcmp($2,"DataOutputs")==0){
+    if(strncasecmp($2,"DataOutputs",11)==0){
       if(wait_inputs==true){
 #ifdef DEBUG_SERVICE_CONF
 	fprintf(stderr,"(DATAOUTPUTS) DUP INPUTS current_element\n");
-#endif
-	if(my_service->inputs==NULL)
+	fprintf(stderr,"CURRENT_ELEMENT\n");
+	dumpElements(current_element);
+	fprintf(stderr,"SERVICE INPUTS\n");
+	dumpElements(my_service->inputs);
+	dumpService(my_service);
+#endif
+	if(my_service->inputs==NULL){
 	  my_service->inputs=dupElements(current_element);
+	  my_service->inputs->next=NULL;
+	}
 	else
-	  addToElements(my_service->inputs,current_element);
-#ifdef DEBUG_SERVICE_CONF
+	  addToElements(&my_service->inputs,current_element);
+#ifdef DEBUG_SERVICE_CONF
+	fprintf(stderr,"CURRENT_ELEMENT\n");
 	dumpElements(current_element);
+	fprintf(stderr,"SERVICE INPUTS\n");
 	dumpElements(my_service->inputs);
 	fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n");
@@ -245,5 +252,5 @@
     }
     else
-      if(strcmp($2,"MetaData")==0){
+      if(strncasecmp($2,"MetaData",8)==0){
 	current_data=3;
 	if(current_element!=NULL){
@@ -263,23 +270,27 @@
       }
       else
-	if(strcmp($2,"ComplexData")==0 || strcmp($2,"LiteralData")==0
-	|| strcmp($2,"ComplexOutput")==0 || strcmp($2,"LiteralOutput")==0){
+	if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
+	   || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0){
 	  current_data=4;
 	  if(wait_metadata==true){
 	    if(current_content!=NULL){
-	      current_element->metadata=current_content;
+	      addMapToMap(&current_element->metadata,current_content);
 	      current_element->next=NULL;
 	      current_element->format=$2;
 	      current_element->defaults=NULL;
+	      current_element->supported=NULL;
+	      freeMap(&current_content);
+	      free(current_content);
 	    }
-	  }else{ // No MainMetaData
-	    //addMapToMap(&current_element->content,current_content);
-	    //freeMap(&current_content);
-	    //free(current_content);
-	    current_element->content=current_content;
+	  }else{ 
+	    // No MainMetaData
+	    addMapToMap(&current_element->content,current_content);
+	    freeMap(&current_content);
+	    free(current_content);
 	    current_element->metadata=NULL;
 	    current_element->next=NULL;
 	    current_element->format=$2;
 	    current_element->defaults=NULL;
+	    current_element->supported=NULL;
 	  }
 	  current_content=NULL;
@@ -287,10 +298,10 @@
 	}
 	else
-	  if(strcmp($2,"Default")==0){
+	  if(strncasecmp($2,"Default",7)==0){
 	    wait_defaults=true;
 	    current_data=5;
 	  }
 	  else
-	    if(strcmp($2,"Supported")==0){
+	    if(strncasecmp($2,"Supported",9)==0){
 	      wait_supporteds=true;
 	      if(wait_defaults==true){
@@ -304,8 +315,9 @@
   printf("* Identifiant : %s\n",$2);
 #endif
-		
   /* et on renvoie l'identifiant de balise afin de pouvoir le comparer */
   /* avec la balise jumelle fermante ! */
   $$ = $2 ;
+  /*if($2!=NULL)
+    free($2);*/
 }
  ;
@@ -338,13 +350,13 @@
   printf ("attribute : %s\n",$1) ;
 #endif
-  for(int i=0;i < lattribute.size(); i++)
+  /*for(int i=0;i < lattribute.size(); i++)
     {
       if (strcmp($1,lattribute.at(i)) == 0)
 	{
 	  fprintf (stderr,"attributs identiques : %d -- %s , %s",i,lattribute.at(i),$1) ;
-	  //srerror("attribut redondant !:");
 	}
     }
-  lattribute.push_back($1);
+    lattribute.push_back($1);*/
+  free($1);
 }
  ;
@@ -359,5 +371,5 @@
 //======================================================
 EmptyElemTag
- : INFCAR ID Attributeetoile SLASH SUPCAR	{lattribute.clear();/* voir Stag */}
+ : INFCAR ID Attributeetoile SLASH SUPCAR	{/*lattribute.clear();/* voir Stag */}
  ;
 //======================================================
@@ -387,7 +399,10 @@
     current_data=previous_data;
     if(current_element->defaults==NULL){
-      current_element->defaults=(iotype*)malloc(MAP_SIZE);
-    }
-    current_element->defaults->content=current_content;
+      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
+      current_element->defaults->content=NULL;
+    }
+    addMapToMap(&current_element->defaults->content,current_content);
+    freeMap(&current_content);
+    free(current_content);
     current_element->defaults->next=NULL;
     wait_defaults=false;
@@ -398,27 +413,42 @@
     current_data=previous_data;
     if(current_element->supported==NULL){
-      current_element->supported=(iotype*)malloc(MAP_SIZE);
-      current_element->supported->content=current_content;
+      //addMapToIoType(&current_element->supported,current_content);
+      current_element->supported=(iotype*)malloc(IOTYPE_SIZE);
+      current_element->supported->content=NULL;
+      addMapToMap(&current_element->supported->content,current_content);
+      freeMap(&current_content);
+      free(current_content);
       current_element->supported->next=NULL;
-      /**
-       * Need to free this ressource (HERE ?)
+      current_content=NULL;
+    }
+    else{
+#ifdef DEBUG
+      // Currently we support only one supported format
+      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
+#endif
+      //addMapToIoType(&current_element->supported,current_content);
+      /*iotype* iotmp=*(&current_element->supported);
+      while(iotmp!=NULL){
+	dumpMap(iotmp->content);
+	iotmp=iotmp->next;
+      }
+      iotmp=(iotype*)malloc(IOTYPE_SIZE);
+      iotmp->content=NULL;
+      addMapToMap(&iotmp->content,current_content);
+      iotmp->next=NULL;
+      dumpElements(current_element);
+      fprintf(stderr,"SECOND SUPPORTED FORMAT MAP START !!!!\n");
+      dumpMap(current_content);
+      fprintf(stderr,"SECOND SUPPORTED FORMAT MAP END !!!!\n");*/
+      freeMap(&current_content);
       free(current_content);
-      */
-    }
-    else{ 
-      /*current_element->supported->next=(iotype*)malloc(sizeof(iotype*));
-      current_element->supported->next->content=NULL;
-      current_element->supported->next->next=NULL;
-      iotype* tmp1=current_element->supported;
-      while(tmp1!=NULL){
-	addMapToMap(&current_element->supported->next->content,current_content);
-	freeMap(&current_content);
-#ifdef DEBUG_SERVICE_CONF
-	fprintf(stderr,"LINE 409");
-#endif
-	free(current_content);
-	current_content=NULL;
-	tmp1=tmp1->next;
-	}*/
+      current_content=NULL;
+      /*freeMap(&iotmp->content);
+      free(&iotmp->content);
+      free(iotype);*/
+#ifdef DEBUG
+      // Currently we support only one supported format
+      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
+#endif
     }
     current_content=NULL;
@@ -472,5 +502,5 @@
 //======================================================
 
-pair: PAIR {  if(debug) fprintf(stderr,"PAIR FOUND !!\n"); }
+pair: PAIR {  if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
 | EPAIR {
 #ifdef DEBUG_SERVICE_CONF
@@ -495,16 +525,10 @@
     dumpMap(current_content);
     fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1); 
-    
-#endif
-    //map* tmp1=createMap(curr_key,$1);
+#endif
     addToMap(current_content,curr_key,$1);
-    //freeMap(&tmp1);
-    //free(tmp1);
 #ifdef DEBUG_SERVICE_CONF
     fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1); 
 #endif    
   }
-  //free(curr_key);
-  curr_key=NULL;
 #ifdef DEBUG_SERVICE_CONF
   fprintf(stderr,"EPAIR FOUND !! \n"); 
@@ -513,6 +537,10 @@
   fflush(stderr);
 #endif
-  }
-| SPAIR  { curr_key=$1; if(debug) fprintf(stderr,"SPAIR FOUND !!\n"); }
+  if(curr_key!=NULL){
+    free(curr_key);
+    curr_key=NULL;
+  }
+  }
+| SPAIR  { curr_key=strdup($1);/*free($1);*/if(debug) fprintf(stderr,"SPAIR FOUND !!\n"); }
  ;
 
@@ -522,5 +550,11 @@
   if(data==-1){
     data=1;
-    my_service->name=$1;
+    char *cen=strdup($1);
+    my_service->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
+    cen[strlen(cen)-1]=0;
+    cen+=1;
+    sprintf(my_service->name,"%s",cen);
+    cen-=1;
+    free(cen);
     my_service->content=NULL;
     my_service->metadata=NULL;
@@ -530,33 +564,19 @@
     if(current_data==1){
       if(my_service->content!=NULL && current_element->name!=NULL){
-	//fprintf(stderr,"ELEMENT (%s)",current_element->name);
 	if(my_service->inputs==NULL){
-#ifdef DEBUG_SERVICE_CONF
-	  fprintf(stderr,"count (%i) (%s)\n",tmp_count%2,$1);
-	  fflush(stderr);
-#endif
-	  //if(tmp_count==1){
-#ifdef DEBUG_SERVICE_CONF
-	  fprintf(stderr,"(DATAINPUTS - 464)DUP current_element\n");
-	  dumpElements(current_element);
-#endif
 	  my_service->inputs=dupElements(current_element);
-#ifdef DEBUG_SERVICE_CONF
-	  fprintf(stderr,"(DATAINPUTS - 466)FREE current_element\n");
-#endif
-	  freeElements(&current_element);
-	  current_element=NULL;
+	  my_service->inputs->next=NULL;
 	  tmp_count++;
 	}
 	else{
-	  addToElements(my_service->inputs,current_element);
-#ifdef DEBUG_SERVICE_CONF
-	  fprintf(stderr,"(DATAINPUTS - 6)FREE current_element (after adding to allread existing inputs)");
-#endif
-	  freeElements(&current_element);
+	  addToElements(&my_service->inputs,current_element);
 	}
 #ifdef DEBUG_SERVICE_CONF
+	fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
+	dumpElements(current_element);
+	fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
 	dumpElements(my_service->inputs);
 #endif
+	freeElements(&current_element);
 	free(current_element);
 	current_element=NULL;
@@ -582,5 +602,11 @@
 	fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n");
 #endif
-	current_element->name=strdup($1);
+	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);
 #ifdef DEBUG_SERVICE_CONF
 	fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
@@ -604,4 +630,5 @@
 	    if(my_service->inputs==NULL){
 	      my_service->inputs=dupElements(current_element);
+	      my_service->inputs->next=NULL;
 	    }
 	    else{
@@ -609,18 +636,15 @@
 	      fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
 #endif
-	      addToElements(my_service->inputs,current_element);
+	      addToElements(&my_service->inputs,current_element);
 	    }
 #ifdef DEBUG_SERVICE_CONF
 	    dumpElements(current_element);
-	    fprintf(stderr,"(DATAOUTPUTS - 531) FREE current_element\n");
+	    fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
 #endif
 	    freeElements(&current_element);
-	    free(&current_element);
-#ifdef DEBUG_SERVICE_CONF
-	    fprintf(stderr,"free OUTPUTS\n");
-#endif
+	    free(current_element);
 	    current_element=NULL;
 #ifdef DEBUG_SERVICE_CONF
-	    fprintf(stderr,"(DATAOUTPUTS - 536) ALLOCATE current_element\n");
+	    fprintf(stderr,"(DATAOUTPUTS) ALLOCATE current_element %s %i\n",__FILE__,__LINE__);
 #endif
 	    current_element=(elements*)malloc(ELEMENTS_SIZE);
@@ -638,5 +662,11 @@
 	    fprintf(stderr,"(DATAOUTPUTS - 545) SET NAME OF current_element\n");
 #endif
-	    current_element->name=strdup($1);
+	    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;
@@ -647,4 +677,5 @@
 	  }
 	  wait_inputs=false;
+	  dumpMap(current_content);
 	  current_content=NULL;
 	}
@@ -655,5 +686,14 @@
 	    fprintf(stderr,"(DATAOUTPUTS - 545) SET NAME OF current_element\n");
 #endif
-	    current_element->name=strdup($1);
+	    char *cen=strdup($1);
+	    current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
+	    cen[strlen(cen)-1]=0;
+#ifdef DEBUG
+	    fprintf(stderr,"tmp %s\n",cen);
+#endif
+	    cen+=1;
+	    sprintf(current_element->name,"%s",cen);
+	    cen-=1;
+	    free(cen);
 	    current_element->content=NULL;
 	    current_element->metadata=NULL;
@@ -726,8 +766,7 @@
   if (srin==NULL){
     fprintf(stderr,"error : le fichier specifie n'existe pas ou n'est pas accessible en lecture\n") ;
-    return 22;
-  }
-
-  //printf(" ");
+    return -1;
+  }
+
   int resultatYYParse = srparse() ;
   
@@ -738,4 +777,7 @@
 #endif
       my_service->outputs=dupElements(current_element);
+      my_service->outputs->next=NULL;
+      freeElements(&current_element);
+      free(current_element);
       current_element=NULL;
     }
@@ -744,5 +786,5 @@
       fprintf(stderr,"(DATAOUTPUTS - 628) COPY current_element\n");
 #endif
-      addToElements(my_service->outputs,current_element);
+      addToElements(&my_service->outputs,current_element);
     }
 #ifdef DEBUG_SERVICE_CONF
@@ -750,9 +792,11 @@
 #endif
     freeElements(&current_element);
+    free(current_element);
+    current_element=NULL;
   }
   if(current_element!=NULL){
     freeElements(&current_element);
     fprintf(stderr,"LINE 709");
-    //free(current_element);
+    free(current_element);
     current_element=NULL;
   }
@@ -760,5 +804,5 @@
     freeMap(&current_content);
     fprintf(stderr,"LINE 715");
-    //free(current_content);
+    free(current_content);
     current_content=NULL;
   }
@@ -769,4 +813,5 @@
   *service=my_service;
 
+  srlex_destroy();
   return resultatYYParse;
 }
