Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 490)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 492)
@@ -257,4 +257,5 @@
 #endif
 	t=readServiceFile(m,tmps1,&s1,dp->d_name);
+
 	if(t<0){
 	  dumpMaps(m);
@@ -961,4 +962,5 @@
 	char buff1[1024];
 	while(tmps!=NULL){
+	  int hasVal=-1;
 	  char *corig=strdup(tmps);
 	  if(strstr(corig,".")!=NULL){
@@ -966,4 +968,5 @@
 	    s1=(service*)malloc(SERVICE_SIZE);
 	    t=readServiceFile(m,buff1,&s1,corig);
+
 	    if(t<0){
 	      map* tmp00=getMapFromMaps(m,"lenv","message");
@@ -977,4 +980,5 @@
 	      freeMaps(&m);
 	      free(m);
+	      free(REQUEST);
 	      return 1;
 	    }
@@ -989,15 +993,14 @@
 	    setMapInMaps(m,"lenv","level","0");
 	  }
-	  free(corig);
 	  
 	  memset(buff,0,256);
-	  snprintf(buff,256,"%s.zcfg",tmps);
+	  snprintf(buff,256,"%s.zcfg",corig);
+	  free(corig);
 	  memset(buff1,0,1024);
 #ifdef DEBUG
 	  printf("\n#######%s\n########\n",buff);
 #endif
-	  while ((dp = readdir(dirp)) != NULL)
-	    if( (strcasecmp("all.zcfg",buff)==0 && strstr(dp->d_name,".zcfg")>0)
-		|| strcasecmp(dp->d_name,buff)==0 ){
+	  while ((dp = readdir(dirp)) != NULL){
+	    if( strcasecmp(dp->d_name,buff)==0 ){
 	      memset(buff1,0,1024);
 	      snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name);
@@ -1025,4 +1028,8 @@
 		freeMaps(&m);
 		free(m);
+		free(orig);
+		free(REQUEST);
+		closedir(dirp);
+		xmlFreeDoc(doc);
 		return 1;
 	      }
@@ -1035,5 +1042,24 @@
 	      s1=NULL;
 	      scount++;
+	      hasVal=1;
 	    }
+	  }
+	  if(hasVal<0){
+	    map* tmp00=getMapFromMaps(m,"lenv","message");
+	    char tmp01[1024];
+	    if(tmp00!=NULL)
+	      sprintf(tmp01,_("Unable to parse the ZCFG file: %s (%s)"),buff,tmp00->value);
+	    else
+	      sprintf(tmp01,_("Unable to parse the ZCFG file: %s."),buff);
+	    dup2(saved_stdout,fileno(stdout));
+	    errorException(m, tmp01,"InvalidParameterValue","Identifier");
+	    freeMaps(&m);
+	    free(m);
+	    free(orig);
+	    free(REQUEST);
+	    closedir(dirp);
+	    xmlFreeDoc(doc);
+	    return 1;
+	  }
 	  rewinddir(dirp);
 	  tmps=strtok_r(NULL,",",&saveptr);
@@ -1271,5 +1297,5 @@
       free(REQUEST);
       free(SERVICE_URL);
-      InternetCloseHandle(hInternet);
+      InternetCloseHandle(&hInternet);
       freeService(&s1);
       free(s1);
@@ -1399,5 +1425,5 @@
 		free(REQUEST);
 		free(SERVICE_URL);
-		InternetCloseHandle(hInternet);
+		InternetCloseHandle(&hInternet);
 		freeService(&s1);
 		free(s1);
@@ -1407,16 +1433,15 @@
 	      fprintf(stderr,"REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",tmpv1+1);
 #endif
-	      addToMap(tmpmaps->content,tmpn1,tmpx2);
-	      
+	      addToMap(tmpmaps->content,tmpn1,tmpx2);	      
 #ifndef WIN32
 	      if(CHECK_INET_HANDLE(hInternet))
 #endif
 		{
-		  if(loadRemoteFile(&m,&tmpmaps->content,hInternet,tmpx2)<0){
+		  if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,tmpx2)<0){
 		    freeMaps(&m);
 		    free(m);
 		    free(REQUEST);
 		    free(SERVICE_URL);
-		    InternetCloseHandle(hInternet);
+		    InternetCloseHandle(&hInternet);
 		    freeService(&s1);
 		    free(s1);
@@ -1445,5 +1470,5 @@
 		free(REQUEST);
 		free(SERVICE_URL);
-		InternetCloseHandle(hInternet);
+		InternetCloseHandle(&hInternet);
 		freeService(&s1);
 		free(s1);
@@ -1575,10 +1600,10 @@
 		  if(!(ltmp!=NULL && strncmp(ltmp->value,"POST",4)==0)
 		     && CHECK_INET_HANDLE(hInternet)){
-		    if(loadRemoteFile(&m,&tmpmaps->content,hInternet,(char*)val)!=0){
+		    if(loadRemoteFile(&m,&tmpmaps->content,&hInternet,(char*)val)!=0){
 		      freeMaps(&m);
 		      free(m);
 		      free(REQUEST);
 		      free(SERVICE_URL);
-		      InternetCloseHandle(hInternet);
+		      InternetCloseHandle(&hInternet);
 		      freeService(&s1);
 		      free(s1);
@@ -1597,5 +1622,5 @@
 #endif
 	    xmlNodePtr cur3=cur2->children;
-	    HINTERNET hInternetP;
+	    /*	    HINTERNET hInternetP;
 	    hInternetP=InternetOpen(
 #ifndef WIN32
@@ -1604,6 +1629,6 @@
 				   "ZooWPSClient\0",
 				   INTERNET_OPEN_TYPE_PRECONFIG,
-				   NULL,NULL, 0);
-	    hInternetP.header=NULL;
+				   NULL,NULL, 0);*/
+	    //hInternet.ihandle[hInternet.nb].header=NULL;
 	    while(cur3!=NULL){
 	      while(cur3!=NULL && cur3->type!=XML_ELEMENT_NODE)
@@ -1638,5 +1663,5 @@
 		  xmlFree(val);
 		}
-		hInternetP.header=curl_slist_append(hInternetP.header, has);
+		hInternet.ihandle[hInternet.nb].header=curl_slist_append(hInternet.ihandle[hInternet.nb].header, has);
 		if(has!=NULL)
 		  free(has);
@@ -1675,23 +1700,9 @@
 #ifdef POST_DEBUG
 		    fprintf(stderr,"%s %s\n",btmp->value,tmp);
-		    curl_easy_setopt(hInternetP.handle, CURLOPT_VERBOSE, 1);
-#endif
-		    res=InternetOpenUrl(hInternetP,btmp->value,tmp,strlen(tmp),
+		    curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
+#endif
+		    hInternet.waitingRequests[hInternet.nb]=strdup(tmp);
+		    InternetOpenUrl(&hInternet,btmp->value,hInternet.waitingRequests[hInternet.nb],strlen(hInternet.waitingRequests[hInternet.nb]),
 					INTERNET_FLAG_NO_CACHE_WRITE,0);
-		    char* tmpContent = (char*)malloc((res.nDataLen+1)*sizeof(char));
-		    if(tmpContent == NULL){
-		      return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
-		    }
-		    size_t dwRead;
-		    InternetReadFile(res, (LPVOID)tmpContent,
-				     res.nDataLen, &dwRead);
-		    tmpContent[res.nDataLen]=0;
-		    if(hInternetP.header!=NULL)
-		      curl_slist_free_all(hInternetP.header);
-		    addToMap(tmpmaps->content,"value",tmpContent);
-		    free(tmpContent);
-#ifdef POST_DEBUG
-		    fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);
-#endif		    
 		  }
 		  free(tmp);
@@ -1708,50 +1719,38 @@
 					   INTERNET_OPEN_TYPE_PRECONFIG,
 					   NULL,NULL, 0);
-		    if(!CHECK_INET_HANDLE(bInternet))
+		    if(!CHECK_INET_HANDLE(hInternet))
 		      fprintf(stderr,"WARNING : hInternet handle failed to initialize");
 #ifdef POST_DEBUG
 		    curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1);
 #endif
-		    res1=InternetOpenUrl(bInternet,(char*)val,NULL,0,
+		    bInternet.waitingRequests[0]=strdup((char*)val);
+		    res1=InternetOpenUrl(&bInternet,bInternet.waitingRequests[0],NULL,0,
 					 INTERNET_FLAG_NO_CACHE_WRITE,0);
+		    processDownloads(&bInternet);
 		    char* tmp=
-		      (char*)malloc((res1.nDataLen+1)*sizeof(char));
+		      (char*)malloc((bInternet.ihandle[0].nDataLen+1)*sizeof(char));
 		    if(tmp == NULL){
 		      return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
 		    }
 		    size_t bRead;
-		    InternetReadFile(res1, (LPVOID)tmp,
-				     res1.nDataLen, &bRead);
-		    tmp[res1.nDataLen]=0;
-		    InternetCloseHandle(bInternet);
+		    InternetReadFile(bInternet.ihandle[0], (LPVOID)tmp,
+				     bInternet.ihandle[0].nDataLen, &bRead);
+		    tmp[bInternet.ihandle[0].nDataLen]=0;
+		    InternetCloseHandle(&bInternet);
 		    map *btmp=getMap(tmpmaps->content,"href");
 		    if(btmp!=NULL){
 #ifdef POST_DEBUG
 		      fprintf(stderr,"%s %s\n",btmp->value,tmp);
-		      curl_easy_setopt(hInternetP.handle, CURLOPT_VERBOSE, 1);
-#endif
-		      res=InternetOpenUrl(hInternetP,btmp->value,tmp,
-					  strlen(tmp),
+#endif
+		      hInternet.waitingRequests[hInternet.nb]=strdup(tmp);
+		      res=InternetOpenUrl(&hInternet,btmp->value,hInternet.waitingRequests[hInternet.nb],
+					  strlen(hInternet.waitingRequests[hInternet.nb]),
 					  INTERNET_FLAG_NO_CACHE_WRITE,0);
-		      char* tmpContent = (char*)malloc((res.nDataLen+1)*sizeof(char));
-		      if(tmpContent == NULL){
-			return errorException(m, _("Unable to allocate memory."), "InternalError",NULL);
-		      }
-		      size_t dwRead;
-		      InternetReadFile(res, (LPVOID)tmpContent,
-				       res.nDataLen, &dwRead);
-		      tmpContent[res.nDataLen]=0;
-		      if(hInternetP.header!=NULL)
-			curl_slist_free_all(hInternetP.header);
-		      addToMap(tmpmaps->content,"value",tmpContent);
-#ifdef POST_DEBUG
-		      fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);
-#endif
 		    }
+		    free(tmp);
 		  }
 	      }
 	      cur3=cur3->next;
 	    }
-	    InternetCloseHandle(hInternetP);
 #ifdef POST_DEBUG
 	    fprintf(stderr,"Header and Body was parsed from Reference \n");
@@ -1901,5 +1900,5 @@
 		free(REQUEST);
 		free(SERVICE_URL);
-		InternetCloseHandle(hInternet);
+		InternetCloseHandle(&hInternet);
 		freeService(&s1);
 		free(s1);
@@ -2148,7 +2147,8 @@
   }
   
+  runHttpRequests(&m,&request_input_real_format,&hInternet);
 
   //  if(CHECK_INET_HANDLE(hInternet))
-  InternetCloseHandle(hInternet);
+  InternetCloseHandle(&hInternet);
 
 #ifdef DEBUG
