Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 605)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 607)
@@ -1,3 +1,3 @@
-/**
+/*
  * Author : Gérald FENOY
  *
@@ -120,5 +120,11 @@
 #endif
 
+/**
+ * Translation function for zoo-kernel
+ */
 #define _(String) dgettext ("zoo-kernel",String)
+/**
+ * Translation function for zoo-service
+ */
 #define __(String) dgettext ("zoo-service",String)
 
@@ -131,4 +137,15 @@
 extern int getServiceFromFile (maps *, const char *, service **);
 
+/**
+ * Parse the service file using getServiceFromFile or use getServiceFromYAML
+ * if YAML support was activated.
+ *
+ * @param conf the conf maps containing the main.cfg settings
+ * @param file the file name to parse
+ * @param service the service to update witht the file content
+ * @param name the service name
+ * @return true if the file can be parsed or false
+ * @see getServiceFromFile, getServiceFromYAML
+ */
 int
 readServiceFile (maps * conf, char *file, service ** service, char *name)
@@ -144,4 +161,11 @@
 }
 
+/**
+ * Replace a char by another one in a string
+ *
+ * @param str the string to update
+ * @param toReplace the char to replace
+ * @param toReplaceBy the char that will be used
+ */
 void
 translateChar (char *str, char toReplace, char toReplaceBy)
@@ -156,6 +180,11 @@
 
 /**
- * Create (or append to) an array valued maps
- * value = "["",""]"
+ * Create (or append to) an array valued maps value = "["",""]"
+ *
+ * @param m the conf maps containing the main.cfg settings
+ * @param mo the map to update
+ * @param mi the map to append
+ * @param elem the elements containing default definitions
+ * @return 0 on success, -1 on failure
  */
 int
@@ -237,6 +266,117 @@
 }
 
+/**
+ * Create the profile registry.
+ *
+ * The profile registry is optional (created only if the registry key is
+ * available in the [main] section of the main.cfg file) and can be used to
+ * store the profiles hierarchy. The registry is a directory which should
+ * contain the following sub-directories: 
+ *  * concept: direcotry containing .html files describing concept
+ *  * generic: directory containing .zcfg files for wps:GenericProcess
+ *  * implementation: directory containing .zcfg files for wps:Process
+ *
+ * @param m the conf maps containing the main.cfg settings
+ * @param r the registry to update
+ * @param reg_dir the resgitry 
+ * @param saved_stdout the saved stdout identifier
+ * @return 0 if the resgitry is null or was correctly updated, -1 on failure
+ */
 int
-recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix,
+createRegistry (maps* m,registry ** r, char *reg_dir, int saved_stdout)
+{
+  struct dirent *dp;
+  int scount = 0;
+
+  if (reg_dir == NULL)
+    return 0;
+  DIR *dirp = opendir (reg_dir);
+  if (dirp == NULL)
+    {
+      return -1;
+    }
+  while ((dp = readdir (dirp)) != NULL){
+    if ((dp->d_type == DT_DIR || dp->d_type == DT_LNK) && dp->d_name[0] != '.')
+      {
+
+        char * tmpName =
+          (char *) malloc ((strlen (reg_dir) + strlen (dp->d_name) + 2) *
+                           sizeof (char));
+        sprintf (tmpName, "%s/%s", reg_dir, dp->d_name);
+	
+	DIR *dirp1 = opendir (tmpName);
+	struct dirent *dp1;
+	while ((dp1 = readdir (dirp1)) != NULL){
+	  char* extn = strstr(dp1->d_name, ".zcfg");
+	  if(dp1->d_name[0] != '.' && extn != NULL && strlen(extn) == 5)
+	    {
+	      int t;
+	      char *tmps1=
+		(char *) malloc ((strlen (tmpName) + strlen (dp1->d_name) + 2) *
+				 sizeof (char));
+	      sprintf (tmps1, "%s/%s", tmpName, dp1->d_name);
+	      char *tmpsn = zStrdup (dp1->d_name);
+	      tmpsn[strlen (tmpsn) - 5] = 0;
+	      service* s1 = (service *) malloc (SERVICE_SIZE);
+	      if (s1 == NULL)
+		{
+		  dup2 (saved_stdout, fileno (stdout));
+		  errorException (m, _("Unable to allocate memory."),
+				  "InternalError", NULL);
+		  return -1;
+		}
+	      t = readServiceFile (m, tmps1, &s1, tmpsn);
+	      free (tmpsn);
+	      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)"),
+			     dp1->d_name, tmp00->value);
+		  else
+		    sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),
+			     dp1->d_name);
+		  dup2 (saved_stdout, fileno (stdout));
+		  errorException (m, tmp01, "InternalError", NULL);
+		  return -1;
+		}
+#ifdef DEBUG
+	      dumpService (s1);
+	      fflush (stdout);
+	      fflush (stderr);
+#endif
+	      if(strncasecmp(dp->d_name,"implementation",14)==0){
+		inheritance(*r,&s1);
+	      }
+	      addServiceToRegistry(r,dp->d_name,s1);
+	      freeService (&s1);
+	      free (s1);
+	      scount++;
+	    }
+	}
+	(void) closedir (dirp1);
+      }
+  }
+  (void) closedir (dirp);
+  return 0;
+}
+
+/**
+ * Recursivelly parse zcfg starting from the ZOO-Kernel cwd.
+ * Call the func function given in arguments after parsing the ZCFG file.
+ *
+ * @param m the conf maps containing the main.cfg settings
+ * @param r the registry containing profiles hierarchy
+ * @param n the root XML Node to add the sub-elements
+ * @param conf_dir the location of the main.cfg file (basically cwd)
+ * @param prefix the current prefix if any, or NULL
+ * @param saved_stdout the saved stdout identifier
+ * @param level the current level (number of sub-directories to reach the
+ * current path)
+ * @see inheritance, readServiceFile
+ */
+int
+recursReaddirF (maps * m, registry *r, xmlNodePtr n, char *conf_dir, char *prefix,
                 int saved_stdout, int level, void (func) (maps *, xmlNodePtr,
                                                           service *))
@@ -287,5 +427,5 @@
             setMapInMaps (m, "lenv", "level", levels1);
             res =
-              recursReaddirF (m, n, tmp, prefix, saved_stdout, level + 1,
+              recursReaddirF (m, r, n, tmp, prefix, saved_stdout, level + 1,
                               func);
             sprintf (levels1, "%d", level);
@@ -346,4 +486,5 @@
             fflush (stderr);
 #endif
+	    inheritance(r,&s1);
             func (m, n, s1);
             freeService (&s1);
@@ -356,4 +497,11 @@
 }
 
+/**
+ * Apply XPath Expression on XML document.
+ *
+ * @param doc the XML Document
+ * @param search the XPath expression
+ * @return xmlXPathObjectPtr containing the resulting nodes set
+ */
 xmlXPathObjectPtr
 extractFromDoc (xmlDocPtr doc, const char *search)
@@ -367,4 +515,9 @@
 }
 
+/**
+ * Signal handling function which simply call exit(0).
+ *
+ * @param sig the signal number
+ */
 void
 donothing (int sig)
@@ -376,4 +529,10 @@
 }
 
+/**
+ * Signal handling function which create an ExceptionReport node containing the
+ * information message corresponding to the signal number.
+ *
+ * @param sig the signal number
+ */
 void
 sig_handler (int sig)
@@ -416,4 +575,14 @@
 }
 
+/**
+ * Load a service provider and run the service function.
+ *
+ * @param myMap the conf maps containing the main.cfg settings
+ * @param s1 the service structure
+ * @param request_inputs map storing all the request parameters
+ * @param inputs the inputs maps
+ * @param ioutputs the outputs maps
+ * @param eres the result returned by the service execution
+ */
 void
 loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
@@ -876,4 +1045,11 @@
 #endif
 
+/**
+ * Process the request.
+ *
+ * @param inputs the request parameters map 
+ * @return 0 on sucess, other value on failure
+ * @see conf_read,recursReaddirF
+ */
 int
 runRequest (map ** inputs)
@@ -1113,4 +1289,6 @@
     SERVICE_URL = zStrdup (DEFAULT_SERVICE_URL);
 
+
+
   service *s1;
   int scount = 0;
@@ -1129,4 +1307,13 @@
   else
     snprintf (conf_dir, 1024, "%s", ntmp);
+
+  map* reg = getMapFromMaps (m, "main", "registry");
+  registry* zooRegistry=NULL;
+  if(reg!=NULL){
+    int saved_stdout = dup (fileno (stdout));
+    dup2 (fileno (stderr), fileno (stdout));
+    createRegistry (m,&zooRegistry,reg->value,saved_stdout);
+    dup2 (saved_stdout, fileno (stdout));
+  }
 
   if (strncasecmp (REQUEST, "GetCapabilities", 15) == 0)
@@ -1146,9 +1333,13 @@
       dup2 (fileno (stderr), fileno (stdout));
       if (int res =		  
-          recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,
+          recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
                           printGetCapabilitiesForProcess) < 0)
         {
           freeMaps (&m);
           free (m);
+	  if(zooRegistry!=NULL){
+	    freeRegistry(&zooRegistry);
+	    free(zooRegistry);
+	  }
           free (REQUEST);
           free (SERVICE_URL);
@@ -1160,4 +1351,8 @@
       freeMaps (&m);
       free (m);
+      if(zooRegistry!=NULL){
+	freeRegistry(&zooRegistry);
+	free(zooRegistry);
+      }
       free (REQUEST);
       free (SERVICE_URL);
@@ -1177,4 +1372,8 @@
           freeMaps (&m);
           free (m);
+	  if(zooRegistry!=NULL){
+	    freeRegistry(&zooRegistry);
+	    free(zooRegistry);
+	  }
           free (REQUEST);
           free (SERVICE_URL);
@@ -1200,5 +1399,5 @@
             {
               if (int res =
-                  recursReaddirF (m, n, conf_dir, NULL, saved_stdout, 0,
+                  recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
                                   printDescribeProcessForProcess) < 0)
                 return res;
@@ -1245,4 +1444,8 @@
                           freeMaps (&m);
                           free (m);
+			  if(zooRegistry!=NULL){
+			    freeRegistry(&zooRegistry);
+			    free(zooRegistry);
+			  }
                           free (REQUEST);
                           free (corig);
@@ -1259,4 +1462,5 @@
                       dumpService (s1);
 #endif
+		      inheritance(zooRegistry,&s1);
                       printDescribeProcessForProcess (m, n, s1);
                       freeService (&s1);
@@ -1321,4 +1525,8 @@
                                   freeMaps (&m);
                                   free (m);
+				  if(zooRegistry!=NULL){
+				    freeRegistry(&zooRegistry);
+				    free(zooRegistry);
+				  }
                                   free (orig);
                                   free (REQUEST);
@@ -1332,4 +1540,5 @@
                               dumpService (s1);
 #endif
+			      inheritance(zooRegistry,&s1);
                               printDescribeProcessForProcess (m, n, s1);
                               freeService (&s1);
@@ -1358,4 +1567,8 @@
                       freeMaps (&m);
                       free (m);
+		      if(zooRegistry!=NULL){
+			freeRegistry(&zooRegistry);
+			free(zooRegistry);
+		      }
                       free (orig);
                       free (REQUEST);
@@ -1379,4 +1592,8 @@
           freeMaps (&m);
           free (m);
+	  if(zooRegistry!=NULL){
+	    freeRegistry(&zooRegistry);
+	    free(zooRegistry);
+	  }
           free (REQUEST);
           free (SERVICE_URL);
@@ -1396,4 +1613,8 @@
           freeMaps (&m);
           free (m);
+	  if(zooRegistry!=NULL){
+	    freeRegistry(&zooRegistry);
+	    free(zooRegistry);
+	  }
           free (REQUEST);
           free (SERVICE_URL);
@@ -1410,4 +1631,8 @@
       freeMaps (&m);
       free (m);
+      if(zooRegistry!=NULL){
+	freeRegistry(&zooRegistry);
+	free(zooRegistry);
+      }
       free (REQUEST);
       free (SERVICE_URL);
@@ -1447,4 +1672,9 @@
   dup2 (fileno (stderr), fileno (stdout));
   t = readServiceFile (m, tmps1, &s1, r_inputs->value);
+  inheritance(zooRegistry,&s1);
+  if(zooRegistry!=NULL){
+    freeRegistry(&zooRegistry);
+    free(zooRegistry);
+  }
   fflush (stdout);
   dup2 (saved_stdout, fileno (stdout));
