Index: service.c
===================================================================
--- service.c	(Revision 5)
+++ service.c	(Arbeitskopie)
@@ -1,6 +1,8 @@
 #include "service.h"
 
-map* createMap(char* name,char* value){
+/* ************************************************************************* */
+
+map* createMap(const char* name, const char* value){
   map* tmp=(map *)malloc(sizeof(map*));
   tmp->name=strdup(name);
   tmp->value=strdup(value);
@@ -8,6 +10,8 @@
   return tmp;
 }
 
+/* ************************************************************************* */
+
 bool hasKey(map* m,char *key){
   map* tmp=m;
   while(tmp!=NULL){
@@ -16,11 +20,13 @@
     tmp=tmp->next;
   }
 #ifdef DEBUG_MAP
-  printf("NOT FOUND \n");
+  fprintf(stderr, "MAP NOT FOUND in service.c line %i\n", __LINE__);
 #endif
   return false;
 }
 
+/* ************************************************************************* */
+
 map* getMap(map* m,char *key){
   map* tmp=m;
   while(tmp!=NULL){
@@ -31,6 +37,8 @@
   return NULL;
 }
 
+/* ************************************************************************* */
+
 void* addToMap(map* m,char* n,char* v){
   if(hasKey(m,n)==false){
     map* _cursor=m;
@@ -44,6 +52,8 @@
   }
 }
 
+/* ************************************************************************* */
+
 void* _dumpMap(map* t){
   fprintf(stderr,"[%s] => [%s] \n",t->name,t->value);
   fflush(stderr);
Index: service_internal.h
===================================================================
--- service_internal.h	(Revision 5)
+++ service_internal.h	(Arbeitskopie)
@@ -80,6 +80,8 @@
 
   void addDefaultValues(maps**,elements*,maps*,char*);
 
+   /*defined in zoo_loader.c*/
+  int errorException(maps *m, const char *message, const char *errorcode);
 #ifdef __cplusplus
 }
 #endif
Index: service.h
===================================================================
--- service.h	(Revision 5)
+++ service.h	(Arbeitskopie)
@@ -49,7 +49,7 @@
 #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+sizeof(maps*)
 
 
-  static char* mtoupper(char* str){
+  static char* mtoupper(const char* str){
     char* tmp=strdup(str);
     if(tmp){
       int cnt=strlen(tmp);
@@ -111,7 +111,7 @@
     }
   }
 
-  static map* createMap(char* name,char* value){
+  static map* createMap(const char* name, const char* value){
     map* tmp=(map *)malloc(MAP_SIZE);
     tmp->name=strdup(name);
     tmp->value=strdup(value);
@@ -129,7 +129,7 @@
     return c;
   }
     
-  static bool hasKey(map* m,char *key){
+  static bool hasKey(map* m,const char *key){
     map* tmp=m;
     while(tmp!=NULL){
       if(strcmp(mtoupper(tmp->name),mtoupper(key))==0)
@@ -152,7 +152,7 @@
     return NULL;
   }
 
-  static map* getMap(map* m,char *key){
+  static map* getMap(map* m,const char *key){
     map* tmp=m;
     while(tmp!=NULL){
       if(strcmp(mtoupper(tmp->name),mtoupper(key))==0)
@@ -357,7 +357,7 @@
     return NULL;
   }
 
-  static void* addToMap(map* m,char* n,char* v){
+  static void* addToMap(map* m,const char* n,const char* v){
     if(hasKey(m,n)==false){
       map* _cursor=m;
       while(_cursor->next!=NULL)
Index: zoo_service_loader.c
===================================================================
--- zoo_service_loader.c	(Revision 5)
+++ zoo_service_loader.c	(Arbeitskopie)
@@ -70,6 +70,8 @@
 #include <time.h>
 #include <stdarg.h>
 
+/* ************************************************************************* */
+
 xmlNodeSet* extractFromDoc(xmlDocPtr doc,char* search){
   xmlXPathContextPtr xpathCtx;
   xmlXPathObjectPtr xpathObj;
@@ -79,10 +81,14 @@
   return xpathObj->nodesetval;
 }
 
+/* ************************************************************************* */
+
 void sigint_handler(int sig){
   fprintf(stderr,"Not this time!\n");
 }
 
+/* ************************************************************************* */
+
 int runRequest(map* request_inputs)
 {
 
@@ -94,38 +100,49 @@
   /**
    * Parsing service specfic configuration file
    */
-  m=(maps*)malloc(MAPS_SIZE);
+  m=(maps*)calloc(1, MAPS_SIZE);
+  if(m == NULL){
+    return errorException(m, "Unable to allocate memory.", "InternalError");
+  }
   char ntmp[1024];
 #ifndef WIN32
   getcwd(ntmp,1024);
 #else
   _getcwd(ntmp,1024);
 #endif
-  char conf_file[1024];
-  sprintf(conf_file,"%s/main.cfg",ntmp);  
+  char conf_file[10240];
+  snprintf(conf_file, 10240, "%s/main.cfg",ntmp);  
   conf_read(conf_file,m);
-  
+
+#ifdef DEBUG
+  fprintf(stderr, "***** BEGIN MAP\n");
+  dumpMap(request_inputs);
+  fprintf(stderr, "***** END MAP\n");
+#endif
   /**
    * Check for minimum inputs
    */
   r_inputs=getMap(request_inputs,"Request");
   if(r_inputs==NULLMAP){ 
-  tmps=createMap("text","Parameter <request> was not specified");
+    tmps=createMap("text","Parameter <request> was not specified");
     addToMap(tmps,"code","MissingParameterValue");
     printExceptionReportResponse(m,tmps);
     return 1;
   }
   else
     REQUEST=strdup(r_inputs->value);
+  
   r_inputs=NULL;
   r_inputs=getMap(request_inputs,"Service");
+
   if(r_inputs==NULLMAP){ 
     tmps=createMap("text","Parameter <service> was not specified");
     addToMap(tmps,"code","MissingParameterValue");
     printExceptionReportResponse(m,tmps);
     return 1;
   }
-  if(strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0){
+
+  if(strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))!=0){
     r_inputs=getMap(request_inputs,"Version");
     if(r_inputs==NULL){ 
       tmps=createMap("text","Parameter <version> was not specified");
@@ -139,26 +156,37 @@
    * Need to print std exception message here
    */
   char SP[1024];
-  if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)){
+
+  /*if ((argc < 5 && strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))!=0) || (argc < 4 && strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))==0)){*/
+  if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)) {
     r_inputs=getMap(request_inputs,"ServiceProvider");
+
+#ifdef DEBUG
+    fprintf(stderr, "***** BEGIN MAP\n");
+    dumpMap(r_inputs);
+    fprintf(stderr, "***** END MAP\n");
+#endif
+
     if(r_inputs==NULLMAP){
-      tmps=createMap("text","Parameter <serviceprovider> was not specified");
-      addToMap(tmps,"code","MissingParameterValue");
-      printExceptionReportResponse(m,tmps);    
+      errorException(m, "Parameter <serviceprovider> was not specified","MissingParameterValue");
       return 1;
     }
     else
-      sprintf(SP,"%s",r_inputs->value);
+      snprintf(SP, 1024, "%s",r_inputs->value);
+
     r_inputs=getMap(request_inputs,"MetaPath");
+
+#ifdef DEBUG
+    fprintf(stderr, "***** BEGIN MAP\n");
+    dumpMap(r_inputs);
+    fprintf(stderr, "***** END MAP\n");
+#endif
+
     if(r_inputs==NULLMAP){
-      tmps=createMap("text","Parameter <metapath> was not specified");
-      addToMap(tmps,"code","MissingParameterValue");
-      printExceptionReportResponse(m,tmps);    
+      errorException(m, "Parameter <metapath> was not specified", "MissingParameterValue");
       return 1;
     }
-    tmps=createMap("text","Parameter <unknown> was not specified");
-    addToMap(tmps,"code","MissingParameterValue");
-    printExceptionReportResponse(m,tmps);    
+    errorException(m, "Parameter <unknown> was not specified", "MissingParameterValue");
     return 1;
   }
 
@@ -175,28 +203,31 @@
   int scount=0;
 
 #ifdef DEBUG
+  fprintf(stderr, "***** BEGIN MAP\n");
   dumpMap(r_inputs);
+  fprintf(stderr, "***** END MAP\n");
 #endif
   char conf_dir[1024];
   int t;
   char tmps1[1024];
 
-  if(strcmp(mtoupper(REQUEST),mtoupper("GetCapabilities"))==0){
+  if(strncmp(mtoupper(REQUEST),"GETCAPABILITIES", strlen(mtoupper(REQUEST)))==0){
     int i=0;
     struct dirent *dp;
     r_inputs=NULL;
-    r_inputs=getMap(request_inputs,"metapath");
+    r_inputs=getMap(request_inputs,"MetaPath");
+
+    snprintf(conf_dir, 1024, "%s/%s",ntmp,r_inputs->value);
 #ifdef DEBUG
+    fprintf(stderr, "***** BEGIN MAP\n");
     dumpMap(r_inputs);
+    fprintf(stderr, "***** END MAP\n");
 #endif
-    sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value);
-	DIR *dirp = opendir(conf_dir);
+    DIR *dirp = opendir(conf_dir);
     if(dirp==NULL){
-      tmps=createMap("text","The specified path doesn't exist.");
-      addToMap(tmps,"code","InvalidParameterValue");
-      printExceptionReportResponse(m,tmps);    
-      return -1;
+      return errorException(m, "The specified meta path doesn't exist.","InvalidParameterValue");
     }
+
     xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
     doc->encoding = xmlCharStrdup ("UTF-8");
     r_inputs=NULL;
@@ -208,12 +239,16 @@
      */
     int saved_stdout = dup(fileno(stdout));
     dup2(fileno(stderr),fileno(stdout));
+
     while ((dp = readdir(dirp)) != NULL)
       if(strstr(dp->d_name,".zcfg")!=0){
-	sprintf(tmps1,"%s/%s",conf_dir,dp->d_name);
+	snprintf(tmps1, 1024, "%s/%s",conf_dir,dp->d_name);
 	char *tmps=tmps1;
-	s1=(service*)malloc(sizeof(service*));
-	s[0]=(service*)malloc(sizeof(service*));
+	s1=(service*)calloc(1, sizeof(service));
+	s[0]=(service*)calloc(1, sizeof(service));
+	if(s1 == NULL || s[0] == NULL){
+	  return errorException(m, "Unable to allocate memory.","InternalError");
+	}
 #ifdef DEBUG
 	fprintf(stderr,"#################\n%s\n#################\n",tmps1);
 #endif
@@ -232,7 +267,6 @@
     (void)closedir(dirp);
     fflush(stdout);
     dup2(saved_stdout,fileno(stdout));
-    
     printDocument(doc);
     fflush(stdout);
     xmlFree(n);
@@ -243,11 +277,9 @@
     if(r_inputs==NULL 
        || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){ 
       if(r_inputs!=NULL && strlen(r_inputs->value)==0)
-	tmps=createMap("text","Mandatory value for <identifier> was not specified");
+	errorException(m, "Mandatory value for <identifier> was not specified","MissingParameterValue");
       else
-	tmps=createMap("text","Mandatory <identifier> was not specified");
-      addToMap(tmps,"code","MissingParameterValue");
-      printExceptionReportResponse(m,tmps);
+	errorException(m, "Mandatory <identifier> was not specified","MissingParameterValue");
       return 1;
     }
 
@@ -256,12 +288,9 @@
     struct dirent *dp;
     DIR *dirp = opendir(conf_dir);
     if(dirp==NULL){
-      tmps=createMap("text","The specified metapath path doesn't exist.");
-      addToMap(tmps,"code","InvalidParameterValue");
-      printExceptionReportResponse(m,tmps);    
-      return -1;
+      return errorException(m, "The specified metapath path doesn't exist.","InvalidParameterValue");
     }
-    if(strcmp(mtoupper(REQUEST),"DESCRIBEPROCESS")==0){
+    if(strncmp(mtoupper(REQUEST),"DESCRIBEPROCESS", strlen(mtoupper(REQUEST)))==0){
       /**
        * Loop over Identifier list
        */
@@ -274,8 +303,8 @@
 	n = printDescribeProcessHeader(doc,r_inputs->value,m);
 
       r_inputs=getMap(request_inputs,"Identifier");
+
       char *tmps=strtok(r_inputs->value,",");
-      
       char buff[256];
       char buff1[1024];
       int i=0;
@@ -285,7 +314,7 @@
       dup2(fileno(stderr),fileno(stdout));
       while(tmps){
 	memset(buff,0,256);
-	sprintf(buff,"%s.zcfg",tmps);
+	snprintf(buff, 256, "%s.zcfg",tmps);
 	memset(buff1,0,1024);
 #ifdef DEBUG
 	fprintf(stderr,"\n#######%s\n########\n",buff1);
@@ -293,9 +322,12 @@
 	while ((dp = readdir(dirp)) != NULL)
 	  if(strcmp(dp->d_name,buff)==0){
 	    memset(buff1,0,1024);
-	    sprintf(buff1,"%s/%s",conf_dir,dp->d_name);
-	    s1=(service*)malloc(sizeof(service*));
-	    s[scount]=(service*)malloc(sizeof(service*));
+ 	    snprintf(buff1, 1024, "%s/%s",conf_dir,dp->d_name);
+	    s1=(service*)calloc(1, sizeof(service));
+	    s[scount]=(service*)calloc(1, sizeof(service));
+	  if(s1 == NULL || s[scount] == NULL){
+	    return errorException(m, "Unable to allocate memory.","InternalError");
+	  }
 #ifdef DEBUG
 	    fprintf(stderr,"#################\n%s\n#################\n",tmps1);
 #endif
@@ -318,15 +350,14 @@
       fflush(stdout);
       //xmlFree(n);
 #ifndef LINUX_FREE_ISSUE
-      free(s1);
+      if(s1)
+      	free(s1);
 #endif
       return 0;
     }
     else
-      if(strcmp(mtoupper(REQUEST),"EXECUTE")!=0){
-	tmps=createMap("text","Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.");
-	addToMap(tmps,"code","InvalidParameterValue");
-	printExceptionReportResponse(m,tmps);
+      if(strncmp(mtoupper(REQUEST),"EXECUTE", strlen(mtoupper(REQUEST)))!=0){
+	errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue");
 #ifdef DEBUG
 	fprintf(stderr,"No request found %s",REQUEST);
 #endif	
@@ -336,14 +367,18 @@
   }
   
   s1=NULL;
-  s1=(service*)malloc(sizeof(service*));
-  s[0]=(service*)malloc(sizeof(service*));
+  s1=(service*)calloc(1, sizeof(service));
+  s[0]=(service*)calloc(1, sizeof(service));
+  if(s1 == NULL || s[0] == NULL){
+    return errorException(m, "Unable to allocate memory.","InternalError");
+  }
+
   r_inputs=getMap(request_inputs,"MetaPath");
-  sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
+  snprintf(tmps1, 1024, "%s/%s",ntmp,r_inputs->value);
+
   r_inputs=getMap(request_inputs,"Identifier");
+  snprintf(tmps1, 1024, "%s/%s.zcfg",strdup(tmps1),r_inputs->value);
 
-  sprintf(tmps1,"%s/%s.zcfg",strdup(tmps1),r_inputs->value);
-
 #ifdef DEBUG
   fprintf(stderr,"Trying to load %s\n", tmps1);
 #endif
@@ -352,10 +387,9 @@
   t=getServiceFromFile(tmps1,&s1);
   fflush(stdout);
   dup2(saved_stdout,fileno(stdout));
+  /*What is 22 ????*/
   if(t==22){
-    tmps=createMap("text","The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.");
-    addToMap(tmps,"code","InvalidParameterValue");
-    printExceptionReportResponse(m,tmps);
+    errorException(m, "The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.", "InvalidParameterValue");
     exit(0);
   }
   s[0]=s1;
@@ -409,7 +443,7 @@
 #endif
       char current_output_as_string[10240];
       char cursor_output[10240];
-      sprintf(cursor_output,"%s",strdup(r_inputs->value));
+      snprintf(cursor_output, 10240, "%s",strdup(r_inputs->value));
       j=0;
       map* request_kvp_outputs=NULL;
 	
@@ -422,7 +456,10 @@
       fprintf(stderr,"OUTPUT [%s]\n",cursor_output);
 #endif
       pToken=strtok(cursor_output,";");
-      char** outputs_as_text=(char**)malloc(128*sizeof(char*));
+      char** outputs_as_text=(char**)calloc(128, sizeof(char*));
+      if(outputs_as_text == NULL) {
+	return errorException(m, "Unaböe to allocate memory", "InternalError");
+      }
       i=0;
       while(pToken!=NULL){
 #ifdef DEBUG
@@ -430,8 +467,11 @@
 	fflush(stderr);
 	fprintf(stderr,"***%s***\n",pToken);
 #endif
-	outputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char));
-	sprintf(outputs_as_text[i],"%s",pToken);
+	outputs_as_text[i]=(char*)calloc(strlen(pToken), sizeof(char));
+        if(outputs_as_text[i] == NULL) {
+	  return errorException(m, "Unable to allocate memory", "InternalError");
+	}
+	snprintf(outputs_as_text[i], strlen(pToken), "%s",pToken);
 	pToken = strtok(NULL,";");
 	i++;
       }
@@ -443,7 +483,10 @@
 	while(tmpc!=NULL){
 	  if(k==0){
 	    if(tmp_output==NULL){
-	      tmp_output=(maps*)malloc(MAPS_SIZE);
+	      tmp_output=(maps*)calloc(1, MAPS_SIZE);
+	      if(tmp_output == NULL){
+	        return errorException(m, "Unable to allocate memory.", "InternalError");
+	      }
 	      tmp_output->name=strdup(tmpc);
 	      tmp_output->content=NULL;
 	      tmp_output->next=NULL;
@@ -493,7 +536,7 @@
 #endif
     char current_input_as_string[40960];
     char cursor_input[40960];
-    sprintf(cursor_input,"%s",strdup(r_inputs->value));
+    snprintf(cursor_input, 40960, "%s",strdup(r_inputs->value));
     j=0;
     map* request_kvp_inputs=NULL;
   
@@ -502,7 +545,10 @@
      */
     char * pToken;
     pToken=strtok(cursor_input,";");
-    char** inputs_as_text=(char**)malloc(100*sizeof(char*));
+    char** inputs_as_text=(char**)calloc(100,sizeof(char*));
+    if(inputs_as_text == NULL){
+      return errorException(m, "Unable to allocate memory.", "InternalError");
+    }
     i=0;
     while(pToken!=NULL){
 #ifdef DEBUG
@@ -512,8 +558,11 @@
 #ifdef DEBUG
       fprintf(stderr,"***%s***\n",pToken);
 #endif
-      inputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char));
-      sprintf(inputs_as_text[i],"%s",pToken);
+      inputs_as_text[i]=(char*)calloc(strlen(pToken),sizeof(char));
+      if(inputs_as_text[i] == NULL){
+        return errorException(m, "Unable to allocate memory.", "InternalError");
+      }
+      snprintf(inputs_as_text[i], strlen(pToken), "%s",pToken);
       pToken = strtok(NULL,";");
       i++;
     }
@@ -536,7 +585,10 @@
 	fprintf(stderr,"***\n*** %s = %s ***\n",tmpn,tmpv+1);
 #endif
 	if(tmpmaps==NULL){
-	  tmpmaps=(maps*)malloc(MAPS_SIZE);
+	  tmpmaps=(maps*)calloc(1, MAPS_SIZE);
+          if(tmpmaps == NULL){
+            return errorException(m, "Unable to allocate memory.", "InternalError");
+          }
 	  tmpmaps->name=strdup(tmpn);
 	  tmpmaps->content=createMap("value",tmpv+1);
 	  tmpmaps->next=NULL;
@@ -574,7 +626,10 @@
 	      fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
 		      tmpv1+1,res.nDataAlloc,res.nDataLen);
 #endif
-	      char* tmpContent=(char*)malloc((res.nDataLen+1)*sizeof(char));
+	      char* tmpContent=(char*)calloc((res.nDataLen+1), sizeof(char));
+              if(tmpContent == NULL){
+                return errorException(m, "Unable to allocate memory.", "InternalError");
+              }
 	      size_t dwRead;
 	      InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
 	      map* tmpMap=getMap(tmpmaps->content,"value");
@@ -646,7 +701,10 @@
 	      xmlChar *val=
 		xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
 	      if(tmpmaps==NULL){
-		tmpmaps=(maps*)malloc(MAPS_SIZE);
+		tmpmaps=(maps*)calloc(1, MAPS_SIZE);
+                if(tmpmaps == NULL){
+                  return errorException(m, "Unable to allocate memory.", "InternalError");
+                }
 		tmpmaps->name=strdup((char*)val);
 		tmpmaps->content=NULL;
 		tmpmaps->next=NULL;
@@ -663,7 +721,10 @@
 	      xmlChar *val=
 		xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
 	      if(tmpmaps==NULL){
-		tmpmaps=(maps*)malloc(MAPS_SIZE);
+		tmpmaps=(maps*)calloc(1, MAPS_SIZE);
+                if(tmpmaps == NULL){
+                  return errorException(m, "Unable to allocate memory.", "InternalError");
+                }
 		tmpmaps->name="missingIndetifier";
 		tmpmaps->content=createMap((char*)cur2->name,(char*)val);
 		tmpmaps->next=NULL;
@@ -718,8 +779,10 @@
 		       && CHECK_INET_HANDLE(hInternet)){
 			res=InternetOpenUrl(hInternet,(char*)val,NULL,0,
 					    INTERNET_FLAG_NO_CACHE_WRITE,0);
-			char* tmpContent=
-			  (char*)malloc((res.nDataLen+1)*sizeof(char));
+			char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char));
+                        if(tmpContent == NULL){
+                          return errorException(m, "Unable to allocate memory.", "InternalError");
+                        }
 			size_t dwRead;
 			InternetReadFile(res, (LPVOID)tmpContent,
 					 res.nDataLen, &dwRead);
@@ -755,11 +818,17 @@
 		    fprintf(stderr,"%s = %s\n",ha[hai],(char*)val);
 #endif
 		    if(hai==0){
-		      key=(char*)malloc((1+strlen((char*)val))*sizeof(char));
-		      sprintf(key,"%s",(char*)val);
+		      key=(char*)calloc((1+strlen((char*)val)), sizeof(char));
+                      if(key == NULL){
+                        return errorException(m, "Unable to allocate memory.", "InternalError");
+                      }
+		      snprintf(key, (1+strlen((char*)val)), "%s",(char*)val);
 		    }else{
-		      has=(char*)malloc((3+strlen((char*)val)+strlen(key))*sizeof(char));
-		      sprintf(has,"%s: %s",key,(char*)val);
+		      has=(char*)calloc((3+strlen((char*)val)+strlen(key)), sizeof(char));
+                      if(has == NULL){
+                        return errorException(m, "Unable to allocate memory.", "InternalError");
+                      }
+		      snprintf(has,(3+strlen((char*)val)+strlen(key)), "%s: %s",key,(char*)val);
 #ifdef POST_DEBUG
 		      fprintf(stderr,"%s\n",has);
 #endif
@@ -772,7 +841,7 @@
 #ifdef POST_DEBUG
 		  fprintf(stderr,"Try to fetch the body part of the request ...\n");
 #endif
-		  if(strcmp(mtoupper((char*)cur3->name),mtoupper("Body"))==0 ){
+		  if(strncmp(mtoupper((char*)cur3->name),mtoupper("Body"), strlen(mtoupper((char*)cur3->name)))==0 ){
 #ifdef POST_DEBUG
 		    fprintf(stderr,"Body part found !!!\n",(char*)cur3->content);
 #endif
@@ -802,8 +871,10 @@
 #endif
 		      res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp),
 					  INTERNET_FLAG_NO_CACHE_WRITE,0);
-		      char* tmpContent=
-			(char*)malloc((res.nDataLen+1)*sizeof(char));
+		      char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
+                      if(tmpContent == NULL){
+                        return errorException(m, "Unable to allocate memory.", "InternalError");
+                      }
 		      size_t dwRead;
 		      InternetReadFile(res, (LPVOID)tmpContent,
 				       res.nDataLen, &dwRead);
@@ -834,8 +905,10 @@
 #endif
 		      res1=InternetOpenUrl(bInternet,(char*)val,NULL,0,
 					   INTERNET_FLAG_NO_CACHE_WRITE,0);
-		      char* tmp=
-			(char*)malloc((res1.nDataLen+1)*sizeof(char));
+		      char* tmp= (char*)calloc((res1.nDataLen+1), sizeof(char));
+		      if(tmp == NULL){
+                        return errorException(m, "Unable to allocate memory.", "InternalError");
+                      }
 		      size_t bRead;
 		      InternetReadFile(res1, (LPVOID)tmp,
 				       res1.nDataLen, &bRead);
@@ -850,8 +923,10 @@
 			res=InternetOpenUrl(hInternet,btmp->value,tmp,
 					    strlen(tmp),
 					    INTERNET_FLAG_NO_CACHE_WRITE,0);
-			char* tmpContent=
-			  (char*)malloc((res.nDataLen+1)*sizeof(char));
+			char* tmpContent= (char*)calloc((res.nDataLen+1),sizeof(char));
+                        if(tmpContent == NULL){
+                          return errorException(m, "Unable to allocate memory.", "InternalError");
+                        }
 			size_t dwRead;
 			InternetReadFile(res, (LPVOID)tmpContent,
 					 res.nDataLen, &dwRead);
@@ -1020,7 +1095,10 @@
 	 * A specific responseDocument node.
 	 */
 	if(tmpmaps==NULL){
-	  tmpmaps=(maps*)malloc(MAPS_SIZE);
+	  tmpmaps=(maps*)calloc(1, MAPS_SIZE);                      
+          if(tmpmaps == NULL){
+            return errorException(m, "Unable to allocate memory.", "InternalError");
+          }
 	  tmpmaps->name="unknownIdentifier";
 	  tmpmaps->next=NULL;
 	}
@@ -1091,7 +1169,10 @@
 		xmlChar *val=
 		  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
 		if(tmpmaps==NULL){
-		  tmpmaps=(maps*)malloc(MAPS_SIZE);
+		  tmpmaps=(maps*)calloc(1, MAPS_SIZE);
+                  if(tmpmaps == NULL){
+                    return errorException(m, "Unable to allocate memory.", "InternalError");
+                  }
 		  tmpmaps->name=strdup((char*)val);
 		  tmpmaps->content=NULL;
 		  tmpmaps->next=NULL;
@@ -1110,7 +1191,10 @@
 		xmlChar *val=
 		  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
 		if(tmpmaps==NULL){
-		  tmpmaps=(maps*)malloc(MAPS_SIZE);
+		  tmpmaps=(maps*)calloc(1, MAPS_SIZE);
+                  if(tmpmaps == NULL){
+                    return errorException(m, "Unable to allocate memory.", "InternalError");
+                  }
 		  tmpmaps->name="missingIndetifier";
 		  tmpmaps->content=createMap((char*)cur2->name,(char*)val);
 		  tmpmaps->next=NULL;
@@ -1166,7 +1250,10 @@
 	val=xmlGetProp(cur1,BAD_CAST outs[l]);
 	if(val!=NULL && strlen((char*)val)>0){
 	  if(tmpmaps==NULL){
-	    tmpmaps=(maps*)malloc(MAPS_SIZE);
+	    tmpmaps=(maps*)calloc(1, MAPS_SIZE);
+            if(tmpmaps == NULL){
+              return errorException(m, "Unable to allocate memory.", "InternalError");
+            }
 	    tmpmaps->name="unknownIdentifier";
 	    tmpmaps->content=createMap(outs[l],(char*)val);
 	    tmpmaps->next=NULL;
@@ -1190,7 +1277,10 @@
 	  val=
 	    xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
 	  if(tmpmaps==NULL){
-	    tmpmaps=(maps*)malloc(MAPS_SIZE);
+	    tmpmaps=(maps*)calloc(1, MAPS_SIZE);
+            if(tmpmaps == NULL){
+              return errorException(m, "Unable to allocate memory.", "InternalError");
+            }
 	    tmpmaps->name=strdup((char*)val);
 	    tmpmaps->content=NULL;
 	    tmpmaps->next=NULL;
@@ -1221,7 +1311,6 @@
   fprintf(stderr,"\n%i\n",i);
   dumpMaps(request_input_real_format);
   dumpMaps(request_output_real_format);
-  dumpElements();
 #endif
 
   /**
Index: service_conf.l
===================================================================
--- service_conf.l	(Revision 5)
+++ service_conf.l	(Arbeitskopie)
@@ -123,7 +123,7 @@
 chardata	[^<]*
 /*====================================================*/
 attname	[a-zA-Z0-9_\-]+
-attvalue1	[a-zA-Z0-9_\-.:" "\"\'/\\\(\)]+
+attvalue1	[=,;@a-zA-Z0-9_\-::.:" "\"\'/\\\(\)]+
 
 
 
Index: service_internal.c
===================================================================
--- service_internal.c	(Revision 5)
+++ service_internal.c	(Arbeitskopie)
@@ -24,17 +24,23 @@
 
 #include "service_internal.h"
 
+/* ************************************************************************* */
+
 /* Converts a hex character to its integer value */
 char from_hex(char ch) {
   return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
 }
 
+/* ************************************************************************* */
+
 /* Converts an integer value to its hex character*/
 char to_hex(char code) {
   static char hex[] = "0123456789abcdef";
   return hex[code & 15];
 }
 
+/* ************************************************************************* */
+
 /* Returns a url-encoded version of str */
 /* IMPORTANT: be sure to free() the returned string after use */
 char *url_encode(char *str) {
@@ -52,6 +58,8 @@
   return buf;
 }
 
+/* ************************************************************************* */
+
 /* Returns a url-decoded version of str */
 /* IMPORTANT: be sure to free() the returned string after use */
 char *url_decode(char *str) {
@@ -74,6 +82,8 @@
 }
 
 
+/* ************************************************************************* */
+
 void printProcessResponse1(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){
   if(getpid()==pid)
     printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");  
@@ -253,6 +263,7 @@
 
 }
 
+/* ************************************************************************* */
 
 void printProcessResponse(maps* m,int pid,service* serv,char* service,int status,map* inputs,map* outputs){
   
@@ -381,7 +392,9 @@
   nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
   mcursor=outputs;
   scursor=serv->outputs;
+#ifdef DEBUG
   //dumpMap(mcursor);
+#endif
   while(mcursor!=NULL && scursor!=NULL){
     //xmlAddChild(nc,xmlNewComment(BAD_CAST "Here we need to check for output format from metadata"));
     printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
@@ -422,6 +435,7 @@
 
 }
 
+/* ************************************************************************* */
 
 void printGetCapabilitiesResponse(service** serv,int sc,char* service,maps* m){
 
@@ -729,6 +743,8 @@
 
 }
 
+/* ************************************************************************* */
+
 xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,char* service,maps* m){
 
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
@@ -969,8 +985,6 @@
   nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings");
   xmlAddChild(n,nc);
 
-
-
   nc1 = xmlNewNode(ns, BAD_CAST "Languages");
   nc2 = xmlNewNode(ns, BAD_CAST "Default");
   nc3 = xmlNewNode(ns, BAD_CAST "Supported");
@@ -1020,6 +1034,8 @@
   return nc;
 }
 
+/* ************************************************************************* */
+
 void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){
 
   xmlNsPtr ns,ns_ows;
@@ -1087,8 +1103,9 @@
   xmlFree(xmlbuff);
 
 }
-  
 
+/* ************************************************************************* */
+
 void printDescribeProcessResponse(service* serv,char* service){
 
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
@@ -1363,6 +1380,8 @@
 
 }
 
+/* ************************************************************************* */
+
 xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){
 
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
@@ -1394,6 +1413,8 @@
   return n;
 }
 
+/* ************************************************************************* */
+
 void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service** serv,int sc){
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
   xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
@@ -1672,6 +1693,8 @@
 
 }
 
+/* ************************************************************************* */
+
 void printDescribeProcessDocument(xmlDocPtr doc){
   xmlChar *xmlbuff;
   int buffersize;
@@ -1691,6 +1714,8 @@
 }
 //printGetCapabilitiesHeader
 
+/* ************************************************************************* */
+
 void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){
   xmlNodePtr nc1;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
@@ -1723,6 +1748,8 @@
 
 }
 
+/* ************************************************************************* */
+
 void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){
   xmlNodePtr nc1,nc2,nc3;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
@@ -1751,6 +1778,8 @@
 
 }
 
+/* ************************************************************************* */
+
 void printIOType1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){
   xmlNodePtr nc1,nc2,nc3;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
@@ -1820,6 +1849,8 @@
 
 }
 
+/* ************************************************************************* */
+
 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){
   xmlNodePtr nc1,nc2,nc3;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
@@ -1864,6 +1895,8 @@
 
 }
 
+/* ************************************************************************* */
+
 void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,char* identifier,map* amap){
   xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
   xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
@@ -1883,6 +1916,8 @@
   }
 }
 
+/* ************************************************************************* */
+
 void printExceptionReportResponse(maps* m,map* s){
   
   printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");  
@@ -1959,6 +1994,7 @@
   xmlFree(doc);
 }
 
+/* ************************************************************************* */
 
 void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
 		    map* request_inputs1,int cpid,maps* m,int res){
@@ -2022,6 +2058,8 @@
   }
 }
 
+/* ************************************************************************* */
+
 char *base64(const unsigned char *input, int length)
 {
   BIO *bmem, *b64;
@@ -2044,6 +2082,8 @@
   return buff;
 }
 
+/* ************************************************************************* */
+
 void addDefaultValues(maps** out,elements* in,maps* m,char* type){
   elements* tmpInputs=in;
   maps* out1=*out;
@@ -2073,7 +2113,9 @@
       if(tmpMap==NULL)
 	addToMap(tmpMaps->content,"value","NULL");
       tmpMaps->next=NULL;
+#ifdef DEBUG
       dumpMaps(tmpMaps);
+#endif
       if(out1==NULL){
 	out1=(maps*)malloc(MAPS_SIZE);
 	out1->name=tmpMaps->name;
Index: service_internal_python.c
===================================================================
--- service_internal_python.c	(Revision 5)
+++ service_internal_python.c	(Arbeitskopie)
@@ -24,6 +24,8 @@
 
 #include "service_internal_python.h"
 
+/* ************************************************************************* */
+
 int python_support(maps* m,service* s,int argc,char** argv,map *inputs,map *outputs){
   Py_Initialize();
   PyObject *pName, *pModule, *pFunc;
@@ -135,6 +137,8 @@
   return 2;
 }
 
+/* ************************************************************************* */
+
 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
   maps* m=*main_conf;
   maps* inputs=*real_inputs;
@@ -286,6 +290,8 @@
   return res;
 }
 
+/* ************************************************************************* */
+
 PyDictObject* PyDict_FromMaps(maps* t){
   PyObject* res=PyDict_New( );
   maps* tmp=t;
@@ -299,6 +305,8 @@
   return (PyDictObject*) res;
 }
 
+/* ************************************************************************* */
+
 PyDictObject* PyDict_FromMap(map* t){
   PyObject* res=PyDict_New( );
   map* tmp=t;
@@ -312,6 +320,8 @@
   return (PyDictObject*) res;
 }
 
+/* ************************************************************************* */
+
 maps* mapsFromPyDict(PyDictObject* t){
   maps* res=NULL;
   maps* cursor=res;
@@ -350,6 +360,8 @@
   return res;
 }
 
+/* ************************************************************************* */
+
 map* mapFromPyDict(PyDictObject* t){
   map* res=NULL;
   PyObject* list=PyDict_Keys((PyObject*)t);
Index: zoo_loader.c
===================================================================
--- zoo_loader.c	(Revision 5)
+++ zoo_loader.c	(Arbeitskopie)
@@ -26,16 +26,15 @@
  * Specific includes
  */
 #include "fcgio.h"
-#include "fcgi_config.h" 
+#include "fcgi_config.h"
 #include "fcgi_stdio.h"
 #include <sys/types.h>
 #include <unistd.h>
-extern "C" {
+#include "service_internal.h"
+
+extern "C"
+{
 #include "cgic.h"
-}
-
-#include "service_internal.h"
-extern "C" {
 #include <libxml/tree.h>
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
@@ -43,22 +42,39 @@
 #include <libxml/xpathInternals.h>
 }
 
+xmlNodeSet *extractFromDoc (xmlDocPtr, char *);
+int runRequest (map *);
+
+using namespace std;
+
+/* ************************************************************************* */
+
+int errorException(maps *m, const char *message, const char *errorcode)
+{
+  map * errormap = createMap("text", message);
+  addToMap(errormap,"code", errorcode);
+  printExceptionReportResponse(m,errormap);    
+  return -1;
+}
+
+/* ************************************************************************* */
+
 #ifndef STRTOK_R
 char *
-strtok_r(char *s1, const char *s2, char **lasts)
+strtok_r (char *s1, const char *s2, char **lasts)
 {
   char *ret;
 
   if (s1 == NULL)
     s1 = *lasts;
-  while(*s1 && strchr(s2, *s1))
+  while (*s1 && strchr (s2, *s1))
     ++s1;
-  if(*s1 == '\0')
+  if (*s1 == '\0')
     return NULL;
   ret = s1;
-  while(*s1 && !strchr(s2, *s1))
+  while (*s1 && !strchr (s2, *s1))
     ++s1;
-  if(*s1)
+  if (*s1)
     *s1++ = '\0';
   *lasts = s1;
   return ret;
@@ -66,62 +82,68 @@
 
 #endif
 
-xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
-int runRequest(map*);
+/* ************************************************************************* */
 
-using namespace std;
-
-char* strtoupper(char* str)
+char *
+strtoupper (char *str)
 {
-  int leng=strlen(str);
-  for(int i=0; i<leng; i++)
-    if (97<=str[i]&&str[i]<=122)//a-z
-      str[i]-=32;
+  int leng = strlen (str);
+  for (int i = 0; i < leng; i++)
+    if (97 <= str[i] && str[i] <= 122)	//a-z
+      str[i] -= 32;
   return str;
 }
 
-char* strtolower(char* str)
+/* ************************************************************************* */
+
+char *
+strtolower (char *str)
 {
-  int leng=strlen(str);
-  for(int i=0; i<leng; i++)
-    if (65<=str[i]&&str[i]<=90)//A-Z
-      str[i]+=32;
+  int leng = strlen (str);
+  for (int i = 0; i < leng; i++)
+    if (65 <= str[i] && str[i] <= 90)	//A-Z
+      str[i] += 32;
   return str;
 }
 
-char* remplace(char* delim,char* rep,char* source){
-  if(strcmp(source,"")==0){
-#ifdef DEBUG
-    //char *tmp="RETURN NULL !\n";
-    //printf((void*)tmp);
-#endif
-    return "NULL";
-  }
+/* ************************************************************************* */
 
-  char *_token; 
-  char *origin=strdup(source);
-  char result[1024]="";
-  _token = strtok(source, delim);
+char *
+remplace (char *delim, char *rep, char *source)
+{
+  if (strcmp (source, "") == 0)
+    {
+      return "NULL";
+    }
+
+  char *_token;
+  char *origin = strdup (source);
+  char result[1024] = "";
+  _token = strtok (source, delim);
 #ifdef DEBUG
-  fprintf(stderr,"\nREPLACE TOKEN (%s == %s => %d)\n ",_token,origin,strcmp(_token,origin));
+  fprintf (stderr, "\nREPLACE TOKEN (%s == %s => %d)\n ", _token, origin,
+	   strcmp (_token, origin));
 #endif
-  if(strcmp(_token,origin)!=0)
-    while(_token!=NULL){
-      sprintf(result,"%s%s%s",result,_token,rep);
-      _token = strtok (NULL, delim);
-      if(_token==NULL)
-	result[strlen(result)-strlen(rep)]=0;
+  if (strcmp (_token, origin) != 0)
+    while (_token != NULL)
+      {
+	snprintf (result, 1024, "%s%s%s", result, _token, rep);
+	_token = strtok (NULL, delim);
+	if (_token == NULL)
+	  result[strlen (result) - strlen (rep)] = 0;
 #ifdef DEBUG
-      fprintf(stderr,"\n\nRESULT(%s)\n\n",result);
+	fprintf (stderr, "\n\nRESULT(%s)\n\n", result);
 #endif
-    }
+      }
   else
     return origin;
-  
-  return strdup(result);
+
+  return strdup (result);
 }
 
 
+/* ************************************************************************* */
+
 char *colors[] = {
   "red", "green", "blue"
 };
@@ -129,187 +151,248 @@
 #define colorsTotal 3
 #define TRUE -1
 #define FALSE -1
-static bool started=FALSE;
-static bool isStarted=FALSE;
+static bool started = FALSE;
+static bool isStarted = FALSE;
 
-int cgiMain(){
+/* ************************************************************************* */
+
+int
+cgiMain ()
+{
   /**
    * We'll use cgiOut as the default output (stdout) to produce plain text 
    * response.
    */
-  dup2(fileno(cgiOut),fileno(stdout));
+  dup2 (fileno (cgiOut), fileno (stderr));
 #ifdef DEBUG
-    fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-    fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n");
-    fflush(cgiOut);
+  fprintf (cgiOut,
+	   "Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
+  fprintf (cgiOut, "Welcome on ZOO verbose debuging mode \r\n\r\n");
+  fflush (cgiOut);
 #endif
-  
   /**
    * Read the main configuration file
    */
-  if(!isStarted){
-    maps* m;
-    m=(maps*)malloc(sizeof(maps*));  
-    conf_read("main.cfg",m);
+#ifdef DEBUG
+  fprintf (stderr, "Read main config file\n");
+#endif
+
+  if (!isStarted)
+    {
+      maps *m = NULL;
+      m = (maps *) calloc (1, sizeof (maps));
+      if (m == NULL)
+	{
+	  fprintf (stderr, "Unable to allocate memory for map in zoo_loader.c line %i", __LINE__);
+          return -1;
+	}
+      conf_read ("main.cfg", m);
 #ifdef REAL_FCGI
 #ifdef DEBUG
-    printf("ok passed");
-#endif    
-#endif    
-    isStarted=TRUE;
-  }
+      printf ("ok passed");
+#endif
+#endif
+      isStarted = TRUE;
+    }
 
 #ifdef DEBUG
-  char textb[23];
-  sprintf(textb,"\n%s\n%s\n",cgiRemoteAddr,cgiRequestMethod);
-  fprintf(stderr,"****%s\n%s\n***",textb,cgiQueryString);
+  fprintf (stderr, "Addr:%s\n", cgiRemoteAddr);
+  fprintf (stderr, "RequestMethod:%s\n", cgiRequestMethod);
+  fprintf (stderr, "Request: %s\n", cgiQueryString);
 #endif
 
-  map* tmp=NULL;
-    
-  if(strncmp(cgiContentType,"text/xml",8)==0){
-    char *buffer=new char[cgiContentLength];
-    if(fread(buffer,1,cgiContentLength,cgiIn)){
-      buffer[cgiContentLength]=0;
-      tmp=createMap("request",buffer);
-    }else{
-      /* Here we have to return an error message ... */
-      return 1; 
-    }
-  }
-  else{
-    char **array, **arrayStep;
-    if (cgiFormEntries(&array) != cgiFormSuccess) {
-      return 1;
-    }
-    arrayStep = array;
-    while (*arrayStep) {
-      char *value=new char[cgiContentLength];
-      cgiFormStringNoNewlines(*arrayStep, value, cgiContentLength);
+  map *tmpMap = NULL;
+
+  if (strncmp (cgiContentType, "text/xml", 8) == 0)
+    {
 #ifdef DEBUG
-      fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
+  fprintf (stderr, "XML Request\n");
 #endif
-      if(tmp!=NULL)
-	addToMap(tmp,*arrayStep,value);
+      char *buffer = new char[cgiContentLength];
+      if (fread (buffer, 1, cgiContentLength, cgiIn))
+	{
+	  buffer[cgiContentLength] = 0;
+	  tmpMap = createMap ("request", buffer);
+	}
       else
-	tmp=createMap(*arrayStep,value);
-      arrayStep++;
+	{
+          fprintf(stderr, "Unable to read cgi content in zoo_loader.c line %i\n", __LINE__);
+          return -1;
+	}
+      delete[]buffer;
     }
-    cgiStringArrayFree(array);
-  }
+  else
+    {
+#ifdef DEBUG
+  fprintf (stderr, "Key-Value Request\n");
+#endif
+      char **array, **arrayStep;
+      if (cgiFormEntries (&array) != cgiFormSuccess)
+	{
+	  return 1;
+	}
+      arrayStep = array;
+      while (*arrayStep)
+	{
+	  char *value = new char[cgiContentLength];
+	  cgiFormStringNoNewlines (*arrayStep, value, cgiContentLength);
+#ifdef DEBUG
+	  fprintf (stderr, "(( %s = %s ))", *arrayStep, value);
+#endif
+	  if (tmpMap != NULL)
+	    addToMap (tmpMap, *arrayStep, value);
+	  else
+	    tmpMap = createMap (*arrayStep, value);
+	  arrayStep++;
+	  delete[]value;
+	}
+      cgiStringArrayFree (array);
+    }
 
+#ifdef DEBUG
+  fprintf (stderr, "\nChecking request method: %s", cgiRequestMethod);
+#endif
+
   /**
    * In case that the POST method was used, then check if params came in XML
    * format (attribute request should be the once).
    */
-  if(strcmp(cgiRequestMethod,mtoupper("post"))==0 && count(tmp)==1){
+  if (strncmp (cgiRequestMethod, mtoupper ("post"), 4) == 0 && tmpMap != NULL
+      && count (tmpMap) == 1)
+    {
     /**
      * First include the MetaPath and the ServiceProvider default parameters
      * (which should be always available in GET params so in cgiQueryString)
      */
-    char *saveptr1, *saveptr2;
-    char *str1, *str2, *token, *subtoken;
-    str1=cgiQueryString;
-    token=strtok_r(str1,"&",&saveptr1);
-    while(token!=NULL){
+      char *saveptr1, *saveptr2;
+      char *str1, *str2, *token, *subtoken;
+      str1 = cgiQueryString;
+      token = strtok_r (str1, "&", &saveptr1);
+      while (token != NULL)
+	{
 #ifdef DEBUG
-      fprintf(stderr,"%s",token);
+	  fprintf (stderr, "%s", token);
 #endif
-      str2=token;
-      subtoken=strtok_r(str2,"=",&saveptr2);
+	  str2 = token;
+	  subtoken = strtok_r (str2, "=", &saveptr2);
 #ifdef DEBUG
-      fprintf(stderr,"%s\n",subtoken);
+	  fprintf (stderr, "%s\n", subtoken);
 #endif
-      char* tmp_name;
-      if(subtoken!=NULL){
-	tmp_name=subtoken;
+	  char *tmp_name;
+	  if (subtoken != NULL)
+	    {
+	      tmp_name = subtoken;
 #ifdef DEBUG
-	fprintf(stderr,"%s",subtoken);
+	      fprintf (stderr, "%s", subtoken);
 #endif
-	subtoken=strtok_r(NULL,"=",&saveptr2);
-	if(subtoken!=NULL)
-	  addToMap(tmp,tmp_name,subtoken);
-	else
-	  addToMap(tmp,tmp_name,"");
-      }
-      token=strtok_r(NULL,"&",&saveptr1);
-    }
+	      subtoken = strtok_r (NULL, "=", &saveptr2);
+	      if (subtoken != NULL)
+		addToMap (tmpMap, tmp_name, subtoken);
+	      else
+		addToMap (tmpMap, tmp_name, "");
+	    }
+	  token = strtok_r (NULL, "&", &saveptr1);
+	}
     /**
      * Store the original XML request in xrequest map
      */
-    map* t1=getMap(tmp,"request");
-    if(t1!=NULL){
-      addToMap(tmp,"xrequest",t1->value);
-      xmlInitParser();
-      xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);      
-      xmlNodePtr cur = xmlDocGetRootElement(doc);
-      char *tval;
-      tval=NULL;
-      tval = (char*) xmlGetProp(cur,BAD_CAST "service");
-      if(tval!=NULL)
-	addToMap(tmp,"service",tval);
-      tval=NULL;
-      tval = (char*) xmlGetProp(cur,BAD_CAST "language");
-      if(tval!=NULL)
-	addToMap(tmp,"language",tval);
-      
-      char* requests[3];
-      requests[0]="GetCapabilities";
-      requests[1]="DescribeProcess";
-      requests[2]="Execute";
-      for(int j=0;j<3;j++){
-	char tt[35];
-	sprintf(tt,"/*[local-name()='%s']",requests[j]);
-	xmlNodeSet* req=extractFromDoc(doc,tt);
+      map *t1 = getMap (tmpMap, "request");
+      if (t1 != NULL)
+	{
+	  addToMap (tmpMap, "xrequest", t1->value);
+	  xmlInitParser ();
+	  xmlDocPtr doc = xmlParseMemory (t1->value, cgiContentLength);
+	  xmlNodePtr cur = xmlDocGetRootElement (doc);
+	  char *tval;
+	  tval = NULL;
+	  tval = (char *) xmlGetProp (cur, BAD_CAST "service");
+	  if (tval != NULL)
+	    addToMap (tmpMap, "service", tval);
+	  tval = NULL;
+	  tval = (char *) xmlGetProp (cur, BAD_CAST "language");
+	  if (tval != NULL)
+	    addToMap (tmpMap, "language", tval);
+
+	  char *requests[3];
+	  requests[0] = "GetCapabilities";
+	  requests[1] = "DescribeProcess";
+	  requests[2] = "Execute";
+	  for (int j = 0; j < 3; j++)
+	    {
+	      char tt[35];
+	      snprintf (tt, 35, "/*[local-name()='%s']", requests[j]);
+	      xmlNodeSet *req = extractFromDoc (doc, tt);
 #ifdef DEBUG
-	fprintf(stderr,"%i",req->nodeNr);
+	      fprintf (stderr, "%i", req->nodeNr);
 #endif
-	if(req->nodeNr==1){
-	  t1->value=requests[j];
-	  j=2;
+	      if (req->nodeNr == 1)
+		{
+		  t1->value = requests[j];
+		  j = 2;
+		}
+	      xmlFree (req);
+	    }
+	  if (strncmp (mtoupper (t1->value), mtoupper ("GetCapabilities"), strlen(mtoupper (t1->value))) ==
+	      0)
+	    {
+	      xmlNodeSet *vers =
+		extractFromDoc (doc, "/*/*/*[local-name()='Version']");
+	      xmlChar *content =
+		xmlNodeListGetString (doc, vers->nodeTab[0]->xmlChildrenNode,
+				      1);
+	      addToMap (tmpMap, "version", (char *) content);
+	      xmlFree (vers);
+	      xmlFree (content);
+	    }
+	  else
+	    {
+	      tval = NULL;
+	      tval = (char *) xmlGetProp (cur, BAD_CAST "version");
+	      if (tval != NULL)
+		addToMap (tmpMap, "version", tval);
+	      xmlFree (tval);
+	      tval = (char *) xmlGetProp (cur, BAD_CAST "language");
+	      if (tval != NULL)
+		addToMap (tmpMap, "language", tval);
+	      xmlNodeSet *id =
+		extractFromDoc (doc, "/*/*[local-name()='Identifier']");
+	      char *identifiers = NULL;
+	      identifiers = (char *) malloc (cgiContentLength);
+              if(identifiers == NULL) {
+	        fprintf(stderr, "Unable to allocate memory in zoo_loader.c line %i\n", __LINE__);
+                return -1;
+	      }
+	      identifiers[0] = 0;
+	      for (int k = 0; k < id->nodeNr; k++)
+		{
+		  xmlChar *content =
+		    xmlNodeListGetString (doc,
+					  id->nodeTab[k]->xmlChildrenNode, 1);
+		  if (strlen (identifiers) > 0)
+		    {
+		      snprintf (identifiers, cgiContentLength, "%s,%s", identifiers, content);
+		      identifiers[strlen (identifiers)] = 0;
+		    }
+		  else
+		    {
+		      snprintf (identifiers, cgiContentLength, "%s", content);
+		      identifiers[strlen (identifiers)] = 0;
+		    }
+		  xmlFree (content);
+		}
+	      xmlFree (id);
+	      addToMap (tmpMap, "Identifier", identifiers);
+	    }
+	  //xmlCleanupParser();
+	  xmlFree (tval);
 	}
-	xmlFree(req);
-      }
-      if(strcmp(mtoupper(t1->value),mtoupper("GetCapabilities"))==0){	
-	xmlNodeSet* vers=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
-	xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);
-	addToMap(tmp,"version",(char*)content);
-	xmlFree(vers);
-	xmlFree(content);
-      }else{
-	tval=NULL;
-	tval = (char*) xmlGetProp(cur,BAD_CAST "version");
-	if(tval!=NULL)
-	  addToMap(tmp,"version",tval);
-	xmlFree(tval);
-	tval = (char*) xmlGetProp(cur,BAD_CAST "language");
-	if(tval!=NULL)
-	  addToMap(tmp,"language",tval);
-	xmlNodeSet* id=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
-	char* identifiers=NULL;
-	identifiers=(char*)malloc(cgiContentLength);
-	identifiers[0]=0;
-	for(int k=0;k<id->nodeNr;k++){
-	  xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
-	  if(strlen(identifiers)>0){
-	    sprintf(identifiers,"%s,%s",identifiers,content);
-	    identifiers[strlen(identifiers)]=0;
-	  }
-	  else{
-	    sprintf(identifiers,"%s",content);
-	    identifiers[strlen(identifiers)]=0;
-	  }
-	  xmlFree(content);
-	}
-	xmlFree(id);
-	addToMap(tmp,"Identifier",identifiers);
-      }
-      //xmlCleanupParser();
-      xmlFree(tval);
     }
-  }
+
+#ifdef DEBUG
+  fprintf (stderr, "\nRuning Request\n");
+#endif
   //dumpMap(tmp);
-  runRequest(tmp);
+  runRequest (tmpMap);
   //dumpMap(tmp);
 
   return 0;
