Index: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/main.cfg
===================================================================
--- branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/main.cfg	(revision 549)
+++ branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/main.cfg	(revision 553)
@@ -1,46 +1,14 @@
-[mm]
-biLayerAlias=Carte,Ortophoto,Ortophoto 2005,Parcels,Etat Major,Cassini,Elev
-editingToolbar=select,add,edit
-navName=Authenticate,Permalink,Twitter sharing,Facebook sharing,Scroll,Pan,Geolocate,Track my position,Zoom Box,Zoom To Max Extent,Identify,Identify Circle,Mesure Distance,Mesure Area,Print,Profile
-scales=443744273,221872136,110936068,55468034,27734017,13867008,6933504,3466752,1733376,866688,433344,216672,108336,54168,27084,13542,6771,3385,1692
-rasterToolbarAlias=Profile,Contour,Shaded Relief,Color Relief,Slope Map,Clip
-supportedDbs=PostGIS,MySQL
-mapcacheUrl=http://127.0.0.1/cache/
-biLayers=GEOGRAPHICALGRIDSYSTEMS.MAPS,ORTHOIMAGERY.ORTHOPHOTOS,ORTHOIMAGERY.ORTHOPHOTOS2000-2005,CADASTRALPARCELS.PARCELS,GEOGRAPHICALGRIDSYSTEMS.ETATMAJOR40,GEOGRAPHICALGRIDSYSTEMS.CASSINI,ELEVATION.SLOPES
-bgLayers=google.maps.MapTypeId.TERRAIN,null,google.maps.MapTypeId.SATELLITE,google.maps.MapTypeId.HYBRID
-bpDefault=g
-bgName=Google
-bbLayers=Road,Aerial,AerialWithLabels
-navIcon=auth,permalink,tshare,fshare,scroll,pan,geoloc,track,zoom-in,zoomtomaxextent,info,infocircle,dist,area,print,terrain-profile
-bbName=Bing
-boLayerAlias=OpenStreetMap
-bmLayerAlias=Streets,Satelite
-toolbars=Vector
-navId=authenticate,permalink,tshare,fshare,scroll,control,geolocate,track,zoomin,zoomtomaxextent,getFeature,getFeatureCircle,line,polygon,print,profile
-navIdX=authenticate,permalink,tshare,fshare,zoomtomaxextent,print
-navIdXX=scroll
-navIdF=loadLoginForm,permalink,shareOnTwitter,shareOnFB,gotoMaxExtent,printIntoDocument
-nvIID=getFeature,getFeatureCircle
-osmApiUrl=http://open.mapquestapi.com/xapi/api/0.6/
-vectorToolbar=buffer,spatial-buffer,centroid,boundary,convexhull,simplify,spatial-query
-bmLayers=Map,Aerial
-boName=OSM
-editingToolbarAlias=Select feature,Add feature,Edit feature
-boLayers=OSM
-address=http://127.0.0.1/mm
-bmName=MapQuest
-bpList=g,b,i
-uomsName=Foot,Meter,Deegree
-adminTheme=green
-vectorToolbarAlias=Buffer,BufferMask,Centroid,Boundary,ConvexHull,Simplify,SpatialQuery
-mapcacheCfg=/Users/djay/Sites/mapcache.xml
-dateFormat=%A %d %B %Y
-uomsId=english,metric,geographic
-oldToolbars=Editing,Raster
-rasterToolbar=profile,contour,shaded_relief,color_relief,slope_map,clip
-bgLayerAlias=Physical,Streets,Satelite,Hybrid
-bbLayerAlias=Streets,Satelite,Hybrid
-sizeLimit=100M
-biName=IGN
+[server]
+req_worker=10
+async_worker=10
+max_requests=200
+listen=/tmp/zoo.sock
+listen_queue=200
+listen_owner=81
+listen_group=81
+listen_mode=0660
+uid=65534
+gid=65534
+#rootDir=/var/www/zoo-wps/cgi-bin
 
 [headers]
@@ -73,11 +41,10 @@
 isTrial=true
 dataPath=/Users/djay/Sites/data
-tmpPath=/Users/djay/Sites/tmp
+tmpPath=/tmp/
 supportedDbs=PostGIS,MySQL,WFS
-cacheDir=/Users/djay/Sites/cache
+cacheDir=/tmp/
 rootUrl=/~djay/mm-np/public/
 publicationUrl=/~djay/pm-np/
 dblink=/Users/djay/Sites/mm.db
-mmPath=/Users/djay/Sites/mm-np/
 sessPath=/Users/djay/Sites/tmp
 version=1.0.0
@@ -88,27 +55,11 @@
 Rpy2=true
 applicationAddress=http://127.0.0.1/~djay/mm-np/
-mmAddress=/~djay/mm-np/
 publicationPath=/Users/djay/Sites/pm-np/
-msOgcVersion=1.0.0
-serverAddress=http://127.0.0.1/np-bin/zoo_loader.cgi
+serverAddress=http://127.0.0.1
 lang=fr-FR,en-US,ja-JP
-mapserverAddress=http://127.0.0.1/np-bin/mapserv.cgi
 tmpUrl=http://127.0.0.1/~djay/tmp/
-templatesPath=/Users/djay/Sites/mm-np/templates/
 templatesAddress=http://127.0.0.1/~djay/pm-np/tmpl/
-crs=IGNF:LAMB93
 jsCache=dev
 cssCache=prod
 cookiePrefix=MMID
 
-[npdb]
-host=127.0.0.1
-schema=velo
-user=postgres
-dbname=demogis
-port=5432
-
-[oo]
-external=true
-path=/Applications/LibreOffice.app/Contents/program/python
-ghostscript=/usr/local/bin/gs
Index: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_zcfg.c
===================================================================
--- branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_zcfg.c	(revision 549)
+++ branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_zcfg.c	(revision 553)
@@ -126,5 +126,5 @@
 init_services_conf (char *rootDir)
 {
-  maps *m = (maps *) malloc (MAP_SIZE);
+  maps *m = (maps *) malloc (MAPS_SIZE);
   GList *L = NULL;
   scanServiceCfg (rootDir, &L, 0);
@@ -138,5 +138,6 @@
       serviceCfgList = g_list_append (serviceCfgList, s1);
     }
-  freeMaps(&m);
+
+  //freeMaps(&m);
 }
 
Index: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_loader.c
===================================================================
--- branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_loader.c	(revision 549)
+++ branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_loader.c	(revision 553)
@@ -62,4 +62,6 @@
 #include <glib.h>
 #include <sys/stat.h>
+#include <ctype.h>
+
 }
 
@@ -476,23 +478,236 @@
 main (int argc, char *argv[])
 {
-  maps *main_config;
-  int max_requests, start_servers;
-  start_servers = 10;
-  max_requests= 100;
-  main_config = (maps *) malloc (MAP_SIZE);
-  conf_read ("main.cfg", main_config);
-  char ntmp[1024];
-#ifndef WIN32
-  getcwd (ntmp, 1024);
-#else
-  _getcwd (ntmp, 1024);
-#endif
-  char *rootDir = "/var/www/zoo-wps/cgi-bin";
+
+
+ int debug_flag = 0;
+ int background_flag = 0;
+ char *file_value = NULL;
+ int index;
+ int c;
+
+ opterr = 0;
+ while ((c = getopt (argc, argv, "dbhf:")) != -1)
+      switch (c)
+      {
+      case 'd':
+        debug_flag = 1;
+        break;
+      case 'b':
+        background_flag = 1;
+        break;
+      case 'h':
+        fprintf(stderr,"TODO: need to print help\n");
+        fflush(stderr);
+        return 0;
+      case 'f':
+        file_value = optarg;
+        break;
+      case '?':
+        if (optopt == 'f')
+          fprintf (stderr, "Option -%c requires an argument.\n", optopt);
+        else if (isprint (optopt))
+          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+        else
+          fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
+        return 1;
+      default:
+        abort ();
+      }
+
+
+  maps *conf;
+  conf = (maps *) malloc (MAPS_SIZE);
+  
+  int ret = conf_read (file_value, conf);
+  if ( ret == 2){
+    //a verifier mais conf_read ne renvoie jamais 0
+    fprintf(stderr,"Erreur lors de la lecture de %s\n",file_value);
+    return 1;
+  }
+
+  char *rootDir;
+  map *m_rootDir = getMapFromMaps (conf, "server", "rootDir");
+  if (m_rootDir == NULL){
+    fprintf(stderr,"Configuration error: rootDir");
+    return 2;
+  }
+  else {
+   rootDir = (char*)malloc((strlen(m_rootDir->value) +1)*sizeof(char*));
+   strncpy(rootDir,m_rootDir->value,strlen(m_rootDir->value));
+   rootDir[strlen(m_rootDir->value)] = '\0';
+   //freeMap(&m_rootDir);
+  }
+
+  int req_worker;
+  map *m_req_worker = getMapFromMaps (conf, "server", "req_worker");
+  if (m_req_worker == NULL){
+    fprintf(stderr,"Configuration error: req_worker not found");
+    return 2;
+  }
+  else {
+    req_worker=atoi(m_req_worker->value);
+    //freeMap(&m_req_worker);
+    if (req_worker == 0){
+        fprintf(stderr,"Configuration error: req_worker");
+        return 2;
+    }
+  }
+  
+  int async_worker;
+  map *m_async_worker = getMapFromMaps (conf, "server", "async_worker");  
+  if (m_async_worker == NULL){
+    fprintf(stderr,"Configuration error: async_worker not found");
+    return 2;
+  }
+  else {
+    async_worker = atoi(m_async_worker->value);
+    //freeMap(&m_async_worker);
+    if (async_worker == 0){
+        fprintf(stderr,"Configuration error: req_worker");
+        return 2;
+    }
+  }
+
+  int max_requests;
+  map *m_max_requests = getMapFromMaps (conf, "server", "max_requests");
+  if (m_max_requests == NULL){
+    fprintf(stderr,"Configuration error: max_requests");
+    return 2;
+  }
+  else {
+    max_requests = atoi(m_max_requests->value);
+    //freeMap(&m_max_requests);
+    if (max_requests == 0){
+        fprintf(stderr,"Configuration error: max_requests");
+        return 2;
+    }
+  }
+
+  map *m_listen = getMapFromMaps (conf, "server", "listen");
+  char *listen;
+  if (m_listen == NULL){
+    fprintf(stderr,"Configuration error: listen not found");
+    return 2;
+  }
+  else {
+    listen = (char *)malloc((strlen(m_listen->value) +1)*sizeof(char*));
+    strncpy(listen,m_listen->value,strlen(m_listen->value));
+    listen[strlen(m_listen->value)] = '\0';
+    //freeMap(&m_listen);
+  }
+  int listen_owner;
+  map *m_listen_owner = getMapFromMaps (conf, "server", "listen_owner");
+  if (m_listen_owner == NULL){
+    fprintf(stderr,"Configuration error: listen_owner");
+    return 2;
+  }
+  else {
+    listen_owner = atoi(m_listen_owner->value);
+    //freeMap(&m_listen_owner);
+    if (listen_owner == 0){
+        fprintf(stderr,"Configuration error: listen_owner");
+        return 2;
+    }
+  }
+
+  int listen_group;
+  map *m_listen_group = getMapFromMaps (conf, "server", "listen_group");
+  if (m_listen_group == NULL){
+    fprintf(stderr,"Configuration error: listen_group");
+    return 2;
+  }
+  else {
+    listen_group = atoi(m_listen_group->value);
+    //freeMap(&m_listen_group);
+    if (listen_group == 0){
+        fprintf(stderr,"Configuration error: listen_group");
+        return 2;
+    }
+  }
+
+  char * listen_mode;
+  map *m_listen_mode = getMapFromMaps (conf, "server", "listen_mode");
+  if (m_listen_mode == NULL){
+    fprintf(stderr,"Configuration error: listen_mode");
+    return 2;
+  }
+  else {
+    listen_mode = (char *)malloc((strlen(m_listen_mode->value) +1)*sizeof(char*));
+    strncpy(listen_mode,m_listen_mode->value,strlen(m_listen_mode->value));
+    listen_mode[strlen(m_listen_mode->value)] = '\0';
+    //freeMap(&m_listen_mode);
+  }
+
+  int listen_queue;
+  map *m_listen_queue = getMapFromMaps (conf, "server", "listen_queue");
+  if (m_listen_queue == NULL){
+    fprintf(stderr,"Configuration error: listen_queue");
+    return 2;
+  }
+  else {
+    listen_queue = atoi(m_listen_queue->value);
+    //freeMap(&m_listen_queue);
+    if (listen_queue == 0){
+        fprintf(stderr,"Configuration error: listen_queue");
+        return 2;
+    }
+  }
+
+  int id_user;
+  map *m_user = getMapFromMaps (conf, "server", "uid");
+  if (m_user == NULL){
+    fprintf(stderr,"Configuration error: id_user");
+    return 2;
+  }
+  else {
+    id_user = atoi(m_user->value);
+    //freeMap(&m_user);
+    if (id_user == 0){
+        fprintf(stderr,"Configuration error: id_user");
+        return 2;
+    }
+  }
+
+
+  int id_group;
+  map *m_group = getMapFromMaps (conf, "server", "gid");
+  if (m_group == NULL){
+    fprintf(stderr,"Configuration error: gid");
+    return 2;
+  }
+  else {
+    id_group = atoi(m_group->value);
+    //freeMap(&m_group);
+    if (id_group == 0){
+        fprintf(stderr,"Configuration error: id_group");
+        return 2;
+    }
+  }
+
+  int sock = FCGX_OpenSocket(listen, listen_queue); 
+  init_services_conf (rootDir);
+  
+  ret = chown(listen, listen_owner, listen_group); 
+  if (ret != 0){
+    fprintf(stderr,"Change owner error on : %s\n",listen);
+    return 3;
+  }
+  
+  ret = setgid(id_group);
+  if (ret != 0){
+    fprintf(stderr,"Change gid error\n");
+    return 3;
+  }
+
+  ret = setuid(id_user);
+  if (ret != 0){
+    fprintf(stderr,"Change uid error\n");
+    return 3;
+  }
+ 
   int fork_status = fork();
   if (fork_status == 0){
     //child
     int forker_pid = getpid();
-    init_services_conf (rootDir);
-    int sock = FCGX_OpenSocket(PATH_SOCKET, 1000);
     FCGX_Init();
     FCGX_Request request;
@@ -500,5 +715,5 @@
     int i;
     int count_request = 0;
-    for (i = 0; i< start_servers; i++){
+    for (i = 0; i< req_worker; i++){
         fork_status = fork();
         if (fork_status == 0){
@@ -532,6 +747,4 @@
   while(1);
 
-
-
   }
   
Index: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 549)
+++ branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 553)
@@ -212,129 +212,4 @@
 }
 
-/**
-int
-recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix,
-                int saved_stdout, int level, void (func) (maps *,
-                                                          xmlNodePtr,
-                                                          service *))
-{
-  struct dirent *dp;
-  int scount = 0;
-
-  if (conf_dir == NULL)
-    return 1;
-  DIR *dirp = opendir (conf_dir);
-  if (dirp == NULL)
-    {
-      if (level > 0)
-        return 1;
-      else
-        return -1;
-    }
-  char tmp1[25];
-  sprintf (tmp1, "sprefix_%d", level);
-  char levels[17];
-  sprintf (levels, "%d", level);
-  setMapInMaps (m, "lenv", "level", levels);
-  while ((dp = readdir (dirp)) != NULL)
-    if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK)
-        && dp->d_name[0] != '.' && strstr (dp->d_name, ".") == NULL)
-      {
-
-        char *tmp =
-          (char *)
-          malloc ((strlen (conf_dir) + strlen (dp->d_name) +
-                   2) * sizeof (char));
-        sprintf (tmp, "%s/%s", conf_dir, dp->d_name);
-
-        if (prefix != NULL)
-          {
-            prefix = NULL;
-          }
-        prefix = (char *) malloc ((strlen (dp->d_name) + 2) * sizeof (char));
-        sprintf (prefix, "%s.", dp->d_name);
-
-        // map* tmpMap=getMapFromMaps(m,"lenv",tmp1);
-
-        int res;
-        if (prefix != NULL)
-          {
-            setMapInMaps (m, "lenv", tmp1, prefix);
-            char levels1[17];
-            sprintf (levels1, "%d", level + 1);
-            setMapInMaps (m, "lenv", "level", levels1);
-            res =
-              recursReaddirF (m, n, tmp, prefix, saved_stdout,
-                              level + 1, func);
-            sprintf (levels1, "%d", level);
-            setMapInMaps (m, "lenv", "level", levels1);
-            free (prefix);
-            prefix = NULL;
-          }
-        else
-          res = -1;
-        free (tmp);
-        if (res < 0)
-          {
-            return res;
-          }
-      }
-    else
-      {
-        if (dp->d_name[0] != '.' && strstr (dp->d_name, ".zcfg") != 0)
-          {
-            int t;
-            char tmps1[1024];
-            memset (tmps1, 0, 1024);
-            snprintf (tmps1, 1024, "%s/%s", conf_dir, dp->d_name);
-            service *s1 = (service *) malloc (SERVICE_SIZE);
-            if (s1 == NULL)
-              {
-                dup2 (saved_stdout, fileno (stdout));
-                errorException (m, _("Unable to allocate memory."),
-                                "InternalError", NULL);
-                return -1;
-              }
-#ifdef DEBUG
-            fprintf (stderr,
-                     "#################\n%s\n#################\n", tmps1);
-#endif
-            t = readServiceFile (m, tmps1, &s1, dp->d_name);
-
-            if (t < 0)
-              {
-                map *tmp00 = getMapFromMaps (m, "lenv", "message");
-                char tmp01[1024];
-                if (tmp00 != NULL)
-                  sprintf (tmp01,
-                           _
-                           ("Unable to parse the ZCFG file: %s (%s)"),
-                           dp->d_name, tmp00->value);
-                else
-                  sprintf (tmp01,
-                           _
-                           ("Unable to parse the ZCFG file: %s."),
-                           dp->d_name);
-                dup2 (saved_stdout, fileno (stdout));
-                errorException (m, tmp01, "InternalError", NULL);
-                freeMaps (&m);
-                free (m);
-                return -1;
-              }
-#ifdef DEBUG
-            dumpService (s1);
-            fflush (stdout);
-            fflush (stderr);
-#endif
-            func (m, n, s1);
-            freeService (&s1);
-            free (s1);
-            scount++;
-          }
-      }
-  (void) closedir (dirp);
-  return 1;
-}
-**/
 xmlXPathObjectPtr
 extractFromDoc (xmlDocPtr doc, const char *search)
