Index: /trunk/docs/kernel/configuration.rst
===================================================================
--- /trunk/docs/kernel/configuration.rst	(revision 816)
+++ /trunk/docs/kernel/configuration.rst	(revision 817)
@@ -127,4 +127,7 @@
 --------------------------------
 
+All the additional sections discribed in the following section are
+optional.
+
 Headers section
 ...............................
@@ -225,4 +228,41 @@
 value stored before the Service execution.
 
+Security section
+...............................
+
+The ``[security]`` section can be used to define what headers, the
+ZOO-Kernel has initially received in the request, should be passed
+to other servers for accessing resources (such as WMS, WFS, WCS
+or any other file passed as a reference). This section contains two
+parameters:
+
+ * ``attributes``: The header to pass to other servers (such as
+   Authorization, Cookie, User-Agent ...),
+ * ``hosts``: The host for wich the restriction apply (can be "*" to
+   forward header to every server or a coma separated list of host
+   names, domain, IP).
+
+Both parameters are mandatory.
+
+Suppose you need to share Authorization, Cookie and User-Agent to
+every server for accessing ressources, then yo ucan use the following
+section definition:
+
+.. code:: 
+
+    [security]
+    attributes=Authorization,Cookie,User-Agent
+    hosts=*
+
+In case only local servers require such header forwarding, you may use
+the following definition:
+
+.. code:: 
+
+    [security]
+    attributes=Authorization,Cookie,User-Agent
+    hosts=localhost,127.0.0.1
+
+
 .. _zoo_activate_db_backend:
 
Index: /trunk/thirds/cgic206/Makefile
===================================================================
--- /trunk/thirds/cgic206/Makefile	(revision 816)
+++ /trunk/thirds/cgic206/Makefile	(revision 817)
@@ -3,9 +3,9 @@
 ifeq ($(OS),Darwin)
 	MACOS_CFLAGS=-arch x86_64
-	LIBS= -L./ -lcgic /usr/lib/libfcgi.dylib
+	LIBS= -L./ -lcgic /usr/local/lib/libfcgi.dylib
 else
 	LIBS= -L./ -lcgic /usr/lib/libfcgi.a
 endif
-CFLAGS=-g -Wall ${MACOS_CFLAGS}
+CFLAGS=-I/usr/local/include -g -Wall ${MACOS_CFLAGS}
 CC=gcc
 AR=ar
Index: /trunk/zoo-project/HISTORY.txt
===================================================================
--- /trunk/zoo-project/HISTORY.txt	(revision 816)
+++ /trunk/zoo-project/HISTORY.txt	(revision 817)
@@ -1,3 +1,8 @@
-Version 1.6.0-dev
+Version 1.7.0-dev
+  * Pass all headers listed in the attributes parameter from the
+  [security] section to the hosts listed in the hosts parameter of the
+  same section (ticket #139)
+
+Version 1.6.0
   * Add the C# as a supported programming language for Services 
   * Add nested inputs and outputs support (WPS 2.0.0)
Index: /trunk/zoo-project/zoo-kernel/caching.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/caching.c	(revision 816)
+++ /trunk/zoo-project/zoo-kernel/caching.c	(revision 817)
@@ -292,4 +292,5 @@
   int hasAFailure=0;
   if(hInternet!=NULL && hInternet->nb>0){
+    AddHeaderEntries(hInternet,*m);
     processDownloads(hInternet);
     maps* content=*inputs;
Index: /trunk/zoo-project/zoo-kernel/configure.ac
===================================================================
--- /trunk/zoo-project/zoo-kernel/configure.ac	(revision 816)
+++ /trunk/zoo-project/zoo-kernel/configure.ac	(revision 817)
@@ -1,3 +1,3 @@
-AC_INIT([ZOO Kernel], [1.6.0], [bugs@zoo-project.org])
+AC_INIT([ZOO Kernel], [1.7.0], [bugs@zoo-project.org])
 
 # Checks for programs.
Index: /trunk/zoo-project/zoo-kernel/ulinet.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/ulinet.c	(revision 816)
+++ /trunk/zoo-project/zoo-kernel/ulinet.c	(revision 817)
@@ -30,4 +30,5 @@
 #include "ulinet.h"
 #include <assert.h>
+#include <ctype.h>
 
 /**
@@ -219,4 +220,98 @@
 
 /**
+ * Add missing headers to an existing _HINTERNET
+ * 
+ * 
+ * @param handle the _HINTERNET pointer
+ * @param key the header parameter name
+ * @param value the header parameter value
+ * @return 0 if the operation succeeded, -1 in other case.
+ */
+int AddMissingHeaderEntry(_HINTERNET* handle,const char* key,const char* value){
+  int length=strlen(key)+strlen(value)+3;
+  char *entry=(char*)malloc((length)*sizeof(char));
+  if(entry==NULL)
+    return -1;
+  snprintf (entry, length, "%s: %s", key, value);
+  handle->header = curl_slist_append (handle->header, entry);
+  free(entry);
+  return 0;
+}
+
+/**
+ * Verify if a host is protected (appear in [security] > hosts)
+ *
+ * @param protectedHosts string containing all the protected hosts (coma separated)
+ * @param url string used to extract the host from
+ * @return 1 if the host is listed as protected, 0 in other case
+ */
+int isProtectedHost(const char* protectedHosts,const char* url){
+  char *token, *saveptr;
+  token = strtok_r (url, "//", &saveptr);
+  int cnt=0;
+  char* host;
+  while(token!=NULL && cnt<=1){
+    fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,token);
+    if(cnt==1)
+      fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,strstr(protectedHosts,token));
+    fflush(stderr);
+    if(cnt==1 && strstr(protectedHosts,token)!=NULL){
+      fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,strstr(protectedHosts,token));
+      return 1;
+    }
+    token = strtok_r (NULL, "/", &saveptr);
+    cnt+=1;
+  }
+  return 0;
+}
+
+/**
+ * Add headers defined in [security] > attributes to an existing HINTERNET
+ * @see isProtectedHost, AddMissingHeaderEntry
+ * 
+ * @param handle the _HINTERNET pointer
+ * @param conf the header parameter name
+ * @param value the header parameter value
+ * @return 0 if the operation succeeded, -1 in other case.
+ */
+void AddHeaderEntries(HINTERNET* handle,maps* conf){
+  map* passThrough=getMapFromMaps(conf,"security","attributes");
+  map* targetHosts=getMapFromMaps(conf,"security","hosts");
+  char* passedHeader[10];
+  int cnt=0;
+  if(passThrough!=NULL && targetHosts!=NULL){
+    char *tmp=zStrdup(passThrough->value);
+    char *token, *saveptr;
+    token = strtok_r (tmp, ",", &saveptr);
+    for(int i=0;i<handle->nb;i++){
+      if(targetHosts->value[0]=='*' || isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){
+	while (token != NULL){
+	  int length=strlen(token)+6;
+	  char* tmp1=(char*)malloc(length*sizeof(char));
+	  snprintf(tmp1,6,"HTTP_");
+	  for(int i=0;token[i]!='\0';i++){
+	    if(token[i]!='-')
+	      tmp1[5+i]=toupper(token[i]);
+	    else
+	      tmp1[5+i]='_';
+	    tmp1[5+i+1]='\0';
+	  }
+	  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);
+	  free(tmp1);
+	  if(handle->ihandle[i].header!=NULL)
+	    curl_easy_setopt(handle->ihandle[i].handle,CURLOPT_HTTPHEADER,handle->ihandle[i].header);
+	  cnt+=1;
+	  token = strtok_r (NULL, ",", &saveptr);
+	}
+      }
+    }
+    free(tmp);
+  }
+}
+
+/**
  * Close a HINTERNET connection and free allocated resources
  *
@@ -241,4 +336,6 @@
     if(handle.post!=NULL)
       free(handle.post);
+    if(handle.url!=NULL)
+      free(handle.url);
     free(handle.mimeType);
     handle.mimeType = NULL;
@@ -270,4 +367,5 @@
   hInternet->ihandle[hInternet->nb].hasCacheFile=0;
   hInternet->ihandle[hInternet->nb].nDataAlloc = 0;
+  hInternet->ihandle[hInternet->nb].url = NULL;
   hInternet->ihandle[hInternet->nb].mimeType = NULL;
   hInternet->ihandle[hInternet->nb].nDataLen = 0;
@@ -340,4 +438,5 @@
 
   curl_easy_setopt(hInternet->ihandle[hInternet->nb].handle,CURLOPT_URL,lpszUrl);
+  hInternet->ihandle[hInternet->nb].url = zStrdup(lpszUrl);
 
   curl_multi_add_handle(hInternet->handle,hInternet->ihandle[hInternet->nb].handle);
Index: /trunk/zoo-project/zoo-kernel/ulinet.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/ulinet.h	(revision 816)
+++ /trunk/zoo-project/zoo-kernel/ulinet.h	(revision 817)
@@ -30,4 +30,5 @@
 #include <fcntl.h>
 #include <curl/curl.h>
+#include "service.h"
 #ifndef WIN32
 #include <unistd.h>
@@ -84,4 +85,5 @@
     FILE* file; //!< the file pointer
     unsigned char *pabyData; //!< the downloaded content
+    char *url; //!< the url used to access the server
     char *mimeType; //!< the mimeType returned by the server
     char *post; //!< the potential POST XML content
@@ -134,4 +136,8 @@
   HINTERNET InternetOpen(char*,int,char*,char*,int);
 
+  int isProtectedHost(const char*,const char*);
+  int AddMissingHeaderEntry(_HINTERNET*,const char*,const char*);
+  void AddHeaderEntries(HINTERNET*,maps*);
+
   void InternetCloseHandle(HINTERNET*);
 
Index: /trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 816)
+++ /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 817)
@@ -2100,6 +2100,6 @@
               addMapsToMaps (&m, tmpSess);
               freeMaps (&tmpSess);
-              free (tmpSess);
             }
+	  free (tmpSess);
         }
     }
