Index: branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 822)
+++ branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 839)
@@ -23,4 +23,5 @@
  */
 
+#include "service.h"
 #include "response_print.h"
 #include "request_parser.h"
@@ -644,5 +645,5 @@
  * @return the generated wps:ProcessOfferings xmlNodePtr 
  */
-void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
+void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){
   xmlNsPtr ns,ns_ows,ns_xml,ns_xlink;
   xmlNodePtr n=NULL,nc1,nc2,nc3;
@@ -692,26 +693,12 @@
     tmp1=serv->metadata;
 
-    addMetadata(tmp1,nc1,ns_ows,ns_xlink);
-
-    /*while(tmp1!=NULL){
-      nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-      if(strcmp(tmp1->name,"title")==0 ||
-	 strcmp(tmp1->name,"href")==0 ||
-	 strcmp(tmp1->name,"role")==0 ||
-	 strcmp(tmp1->name,"link_type")==0){
-	xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-	xmlAddChild(nc1,nc2);
-      }else{
-	if(nc3==NULL)
-	  nc3 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
-	xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Name");
-	xmlAddChild(nc4,xmlNewText(BAD_CAST tmp1->name));
-	xmlNodePtr nc5 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	xmlAddChild(nc5,xmlNewText(BAD_CAST tmp1->value));
-	xmlAddChild(nc3,nc4);
-	xmlAddChild(nc3,nc5);
-      }
-      tmp1=tmp1->next;
-      }*/
+    addMetadata(tmp1,doc,nc1,ns_ows,ns_xlink);
+    tmp1=serv->additional_parameters;
+    int fromDb=-1;
+    map* test=getMap(serv->content,"fromDb");
+    if(test!=NULL && strncasecmp(test->value,"true",4)==0)
+      fromDb=1;
+    addAdditionalParameters(tmp1,doc,nc1,ns_ows,ns_xlink,fromDb);
+
     if(nc3!=NULL)
       xmlAddChild(nc1,nc3);
@@ -756,5 +743,5 @@
 }
 
-int addMetadata(map* meta,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){
+int addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){
     int hasTitle=-1;
     int hasValue=-1;
@@ -830,4 +817,86 @@
 }
 
+
+int addAdditionalParameters(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int fromDb){
+    int hasTitle=-1;
+    int hasValue=-1;
+    xmlNodePtr nc1;
+    map* oMeta=meta;
+    int isAdditionalParameters=-1;
+    //if(count(oMeta)>=2){
+    int level=0;
+    map* test=getMap(meta,"title");
+    if(test!=NULL)
+      level+=1;
+    test=getMap(meta,"href");
+    if(test!=NULL)
+      level+=1;
+    test=getMap(meta,"role");
+    if(test!=NULL)
+      level+=1;
+    if(count(oMeta)>level+1)
+      isAdditionalParameters=1;
+    //}
+    char *ctitle=NULL;
+    while(meta!=NULL){
+      if(hasTitle<0)
+	if(hasValue<0)
+	  nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
+      if(strncasecmp(meta->name,"title",5)==0 ||
+	 strcasecmp(meta->name,"href")==0 ||
+	 strcasecmp(meta->name,"role")==0 ){
+	int index=5;
+	if(strncasecmp(meta->name,"title",5)==0){
+	  index=6;
+	  hasTitle=1;
+	  if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
+	      xmlAddChild(nc,nc1);
+	      nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
+	      free(ctitle);
+	      ctitle=NULL;
+	  }
+	  if(ctitle==NULL){
+	    char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
+	    snprintf(tmp,index,"%s",meta->name);
+	    xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
+	    free(tmp);
+	  }	  
+	  if(ctitle!=NULL)
+	    free(ctitle);
+	  ctitle=zStrdup(meta->value);
+	}
+      }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){
+	    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,xmlNewCDataBlock(doc,BAD_CAST meta->value,strlen(meta->value)));
+	  xmlAddChild(nc2,nc4);
+	}
+	xmlAddChild(nc1,nc2);
+	hasTitle=-1;
+      }
+      meta=meta->next;
+      if(hasTitle<0){
+	xmlAddChild(nc,nc1);
+	hasValue=1;
+      }
+    }
+    if(oMeta!=NULL && hasValue<0 && nc1!=NULL){
+      xmlAddChild(nc,nc1);
+    }
+}
+
 /**
  * Add the ows:Metadata nodes relative to the profile registry
@@ -886,5 +955,5 @@
  * @return the generated wps:ProcessOfferings xmlNodePtr 
  */
-void printDescribeProcessForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
+void printDescribeProcessForProcess(registry *reg, maps* m,xmlDocPtr doc,xmlNodePtr nc,service* serv){
   xmlNsPtr ns,ns_ows,ns_xlink;
   xmlNodePtr n,nc1;
@@ -892,4 +961,9 @@
   map* version=getMapFromMaps(m,"main","rversion");
   int vid=getVersionId(version->value);
+  int fromDb=-1;
+  map* serviceType=getMap(serv->content,"serviceType");
+  map* test=getMap(serv->content,"fromDb");
+  if(test!=NULL && strncasecmp(test->value,"true",4)==0)
+    fromDb=1;
 
   n=nc;
@@ -937,5 +1011,5 @@
     tmp1=serv->metadata;
     while(tmp1!=NULL){
-      addMetadata(tmp1,nc,ns_ows,ns_xlink);
+      addMetadata(tmp1,doc,nc,ns_ows,ns_xlink);
       /*nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
       xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
@@ -951,6 +1025,8 @@
   }else{
     tmp1=serv->metadata;
-    addMetadata(tmp1,nc,ns_ows,ns_xlink);
+    addMetadata(tmp1,doc,nc,ns_ows,ns_xlink);
     addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv);
+    tmp1=serv->additional_parameters;
+    addAdditionalParameters(tmp1,doc,nc,ns_ows,ns_xlink,fromDb);
   }
 
@@ -959,9 +1035,9 @@
     if(vid==0){
       nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs");
-      printFullDescription(1,e,"Input",ns,ns_ows,nc1,vid);
+      printFullDescription(doc,1,e,"Input",ns,ns_ows,nc1,vid,fromDb,NULL);
       xmlAddChild(nc,nc1);
     }
     else{
-      printFullDescription(1,e,"wps:Input",ns,ns_ows,nc,vid);
+      printFullDescription(doc,1,e,"wps:Input",ns,ns_ows,nc,vid,fromDb,NULL);
     }
   }
@@ -970,9 +1046,9 @@
   if(vid==0){
     nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
-    printFullDescription(0,e,"Output",ns,ns_ows,nc1,vid);
+    printFullDescription(doc,0,e,"Output",ns,ns_ows,nc1,vid,fromDb,NULL);
     xmlAddChild(nc,nc1);
   }
   else{
-    printFullDescription(0,e,"wps:Output",ns,ns_ows,nc,vid);
+    printFullDescription(doc,0,e,"wps:Output",ns,ns_ows,nc,vid,fromDb,serviceType);
   }
   if(vid==0)
@@ -996,6 +1072,8 @@
  * @param nc1 the XML node to use to add the created tree
  * @param vid the WPS version id (0 for 1.0.0, 1 for 2.0.0)
- */
-void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid){
+ * @param fromDb 1 in case the metadata comes from the DB, -1 in other cases
+ * @param serviceType the serviceType found in the ZCFG file or the DB
+ */
+void printFullDescription(xmlDocPtr doc,int in,elements *elem,const char* type,xmlNsPtr ns,xmlNsPtr ns_ows,xmlNodePtr nc1,int vid,int fromDb,const map* serviceType){
   xmlNsPtr ns1=NULL;
   if(vid==1)
@@ -1032,4 +1110,7 @@
 
     if(e->format!=NULL){
+#ifdef USE_HPC	    
+    DEFAULT_OUT:
+#endif
       const char orderedFields[13][14]={
 	"mimeType",
@@ -1138,5 +1219,6 @@
 	      char *tmps=strdup(token);
 	      tmps[strlen(tmps)]=0;
-	      xmlAddChild(nc7,xmlNewText(BAD_CAST tmps));
+	      nc8 = xmlNewText(BAD_CAST tmps);
+	      xmlAddChild(nc7,nc8);
 	      free(tmps);
 	      xmlAddChild(nc6,nc7);
@@ -1437,6 +1519,7 @@
 	xmlNsPtr ns_xlink=usedNs[xlinkId];
 
-	dumpMap(metadata);
-	addMetadata(metadata,nc2,ns_ows,ns_xlink);
+	//dumpMap(metadata);
+	addMetadata(metadata,doc,nc2,ns_ows,ns_xlink);
+	addAdditionalParameters(e->additional_parameters,doc,nc2,ns_ows,ns_xlink,fromDb);
 
       }
@@ -1583,9 +1666,10 @@
       xmlAddChild(nc2,nc3);
     }else{
-      if(e->child!=NULL && vid!=0){
-	printFullDescription(in,e->child,type,ns,ns_ows,nc2,vid);
-      }
-    }
-    
+      if(e->child!=NULL){
+	if(e->child!=NULL && vid!=0){
+	  printFullDescription(doc,in,e->child,type,ns,ns_ows,nc2,vid,fromDb,NULL);
+	}
+      }
+    }
     if(e->child!=NULL && vid==0){
       elements* children=dupElements(e->child);
@@ -1598,5 +1682,5 @@
 	cursor=cursor->next;
       }
-      printFullDescription(in,children,type,ns,ns_ows,nc2,vid);
+      printFullDescription(doc,in,children,type,ns,ns_ows,nc2,vid,fromDb,serviceType);
       xmlAddChild(nc1,nc2);
       freeElements(&children);
@@ -1604,5 +1688,4 @@
     }else
       xmlAddChild(nc1,nc2);
-    
     e=e->next;
   }
@@ -2588,5 +2671,5 @@
       toto=getMap(tmpI->content,"asReference");
 #ifdef USE_MS
-      if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL)
+      if(toto!=NULL && strcasecmp(toto->value,"true")==0 && (testMap==NULL || strncasecmp(testMap->value,"true",4)!=0) )
 #else
       if(toto!=NULL && strcasecmp(toto->value,"true")==0)
