Index: trunk/zoo-project/HISTORY.txt
===================================================================
--- trunk/zoo-project/HISTORY.txt	(revision 585)
+++ trunk/zoo-project/HISTORY.txt	(revision 586)
@@ -1,6 +1,8 @@
 Version 1.5.0-dev
+  * Add ZOO-API for the PHP language (with documentation)
+  * Add doxygen comments in source code
   * Add support for multiple Exception nodes
   * Add a length key when creating MapArray
-  * Add Orfeo Toolbox support for applications as a service
+  * Add OTB support for applications as a service
   * Add the otb2zcfg utility to produce zcfg for otb applications
   * Add OTB Application Observer to have progress status updates
Index: trunk/zoo-project/zoo-kernel/service_internal_js.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 585)
+++ trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 586)
@@ -386,5 +386,5 @@
  *
  * @param cx the JavaScript context
- * @param globale the global JavaScript object (not used)
+ * @param global the global JavaScript object (not used)
  * @param filename the file name to load
  * @return a JavaScript Object on success, NULL if an errro occured
Index: trunk/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_ms.c	(revision 585)
+++ trunk/zoo-project/zoo-kernel/service_internal_ms.c	(revision 586)
@@ -23,5 +23,7 @@
  */
 
-#ifdef USE_MS
+/**
+ * Cross platform definition of layerObj->class
+ */
 #ifndef WIN32
 #define CLASS class
@@ -32,4 +34,5 @@
 
 /**
+ * Get a list of configuration keys having a corresponding mandatory ows_*.
  * Map composed by a main.cfg maps name as key and the corresponding 
  * MapServer Mafile Metadata name to use
@@ -38,4 +41,7 @@
  *  - http://mapserver.org/ogc/wfs_server.html
  *  - http://mapserver.org/ogc/wcs_server.html
+ *
+ * @return a new map containing a table linking a name of a configuration key
+ * to a corresponding mandatory ows_* keyword (ie. "fees" => "ows_fees").
  */
 map* getCorrespondance(){
@@ -67,4 +73,15 @@
 }
 
+/**
+ * Add width and height keys to an output maps containing the maximum width
+ * and height for displaying the full data extent.
+ * Restriction to an image having a size of 640x480 (width * height)
+ *
+ * @param output 
+ * @param minx the lower left x coordinate
+ * @param miny the lower left y coordinate
+ * @param maxx the upper right x coordinate
+ * @param maxy the upper right y coordinate
+ */
 void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){
   double maxWidth=640;
@@ -104,4 +121,11 @@
 }
 
+/**
+ * Add a Reference key to an output containing the WMFS/WFS/WCS request for
+ * accessing service result
+ * 
+ * @param m the conf maps containing the main.cfg settings
+ * @param tmpI the specific output maps to add the Reference key
+ */
 void setReferenceUrl(maps* m,maps* tmpI){
   outputMapfile(m,tmpI);
@@ -205,6 +229,12 @@
 
 /**
- * Set projection using Authority Code and Name if available or fallback to 
- * proj4 definition if available or fallback to default EPSG:4326
+ * Set projection for a layer in a MAPFILE using Authority Code and Name if
+ * available or fallback to proj4 definition if available or fallback to
+ * default EPSG:4326
+ *
+ * @param output the output maps
+ * @param m the opened mapObj
+ * @param myLayer the layerObj
+ * @param pszProjection a char* containing the SRS definition in WKT format
  */
 void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer,
@@ -299,4 +329,17 @@
 }
 
+/**
+ * Set the MAPFILE extent, the the ows_extent for the layer, add wms_extent and
+ * wfs_extent to the output maps and call setMapSize.
+ *
+ * @param output the specific output
+ * @param m the mapObj
+ * @param myLayer the layerObj
+ * @param minX the lower left x coordinate
+ * @param minY the lower left y coordinate
+ * @param maxX the upper right x coordinate
+ * @param maxY the upper right y coordinate
+ * @see setMapSize
+ */
 void setMsExtent(maps* output,mapObj* m,layerObj* myLayer,
 		 double minX,double minY,double maxX,double maxY){
@@ -357,4 +400,11 @@
 }
 
+/**
+ * Try to open a vector output and define the corresponding layer in the MAPFILE
+ *
+ * @param conf the conf maps containing the main.cfg settings
+ * @param output the specific output maps
+ * @param m the mapObj
+ */
 int tryOgr(maps* conf,maps* output,mapObj* m){
 
@@ -663,5 +713,11 @@
 }
 
-
+/**
+ * Try to open a raster output and define the corresponding layer in the MAPFILE
+ *
+ * @param conf the conf maps containing the main.cfg settings
+ * @param output the specific output maps
+ * @param m the mapObj
+ */
 int tryGdal(maps* conf,maps* output,mapObj* m){
   map* tmpMap=getMap(output->content,"storage");
@@ -914,9 +970,12 @@
 /**
  * Create a MapFile for WMS, WFS or WCS Service output
+ *
+ * @param conf the conf maps containing the main.cfg settings
+ * @param outputs a specific output maps
  */
 void outputMapfile(maps* conf,maps* outputs){
 
   /**
-   * Firs store the value on disk
+   * First store the value on disk
    */
   map* mime=getMap(outputs->content,"mimeType");
@@ -1106,3 +1165,2 @@
 }
 
-#endif
Index: trunk/zoo-project/zoo-kernel/service_internal_ms.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_ms.h	(revision 585)
+++ trunk/zoo-project/zoo-kernel/service_internal_ms.h	(revision 586)
@@ -24,5 +24,4 @@
 #ifndef ZOO_SERVICE_INTERNAL_MS_H
 #define ZOO_SERVICE_INTERNAL_MS_H 1
-#ifdef USE_MS
 
 #include <sys/stat.h>
@@ -44,21 +43,8 @@
 extern "C" {
 #endif
-  //#include <mapserver.h>
-  /**
-   * Map composed by a main.cfg maps name as key and the corresponding 
-   * MapServer Mafile Metadata name to use
-   * see doc from here :
-   *  - http://mapserver.org/ogc/wms_server.html
-   *  - http://mapserver.org/ogc/wfs_server.html
-   *  - http://mapserver.org/ogc/wcs_server.html
-   */
   map* getCorrespondance();
   void setMapSize(maps* output,double minx,double miny,double maxy,double maxx);
   void setReferenceUrl(maps* m,maps* tmpI);
 
-  /**
-   * Set projection using Authority Code and Name if available or fallback to 
-   * proj4 definition if available or fallback to default EPSG:4326
-   */
   void setSrsInformations(maps* output,mapObj* m,layerObj* myLayer, char* pszProjection);
   
@@ -68,7 +54,4 @@
   
   int tryGdal(maps* conf,maps* output,mapObj* m);
-  /**
-   * Create a MapFile for WMS, WFS or WCS Service output
-   */
   void outputMapfile(maps* conf,maps* outputs);
 #ifdef __cplusplus
@@ -77,4 +60,3 @@
 
 #endif
-#endif
  
Index: trunk/zoo-project/zoo-kernel/service_internal_php.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_php.c	(revision 585)
+++ trunk/zoo-project/zoo-kernel/service_internal_php.c	(revision 586)
@@ -32,12 +32,137 @@
 #include <zend_stream.h>
 
-#ifdef ZTS
-void ***tsrm_ls;
-#endif
-
 zval *php_Array_from_maps(maps* t);
 zval*  php_Array_from_map(map*);
 maps* php_maps_from_Array(HashTable* t);
 map* php_map_from_HasTable(HashTable* t);
+
+#ifdef ZTS
+void ***tsrm_ls;
+#endif
+
+ZEND_BEGIN_MODULE_GLOBALS(zoo)
+long _SERVICE_SUCCEEDED;
+long _SERVICE_FAILED;
+ZEND_END_MODULE_GLOBALS(zoo)
+
+#ifdef ZTS
+#define ZOO_G(v) TSRMG(zoo_globals_id, zend_zoo_globals *, v)
+#else
+#define ZOO_G(v) (zoo_globals.v)
+#endif
+
+#define PHP_ZOO_VERSION "1.0"
+#define PHP_ZOO_EXTNAME "ZOO"
+
+PHP_MINIT_FUNCTION(zoo);
+PHP_MSHUTDOWN_FUNCTION(zoo);
+PHP_RINIT_FUNCTION(zoo);
+
+PHP_FUNCTION(zoo_Translate);
+PHP_FUNCTION(zoo_UpdateStatus);
+PHP_FUNCTION(zoo_SERVICE_SUCCEEDED);
+PHP_FUNCTION(zoo_SERVICE_FAILED);
+
+extern zend_module_entry zoo_module_entry;
+#define phpext_zoo_ptr &zoo_entry
+
+ZEND_DECLARE_MODULE_GLOBALS(zoo)
+
+static zend_function_entry zoo_functions[] = {
+  PHP_FE(zoo_Translate, NULL)
+  PHP_FE(zoo_UpdateStatus, NULL)
+  PHP_FE(zoo_SERVICE_SUCCEEDED, NULL)
+  PHP_FE(zoo_SERVICE_FAILED, NULL)
+  {NULL, NULL, NULL}
+};
+
+zend_module_entry zoo_module_entry = {
+#if ZEND_MODULE_API_NO >= 20010901
+    STANDARD_MODULE_HEADER,
+#endif
+    PHP_ZOO_EXTNAME,
+    zoo_functions,
+    PHP_MINIT(zoo),
+    PHP_MSHUTDOWN(zoo),
+    PHP_RINIT(zoo),
+    NULL,
+    NULL,
+#if ZEND_MODULE_API_NO >= 20010901
+    PHP_ZOO_VERSION,
+#endif
+    STANDARD_MODULE_PROPERTIES
+};
+
+ZEND_GET_MODULE(zoo)
+
+PHP_INI_BEGIN()
+PHP_INI_END()
+
+static void
+php_zoo_init_globals(zend_zoo_globals *zoo_globals)
+{
+  zoo_globals->_SERVICE_SUCCEEDED=3;
+  zoo_globals->_SERVICE_FAILED=4;
+}
+
+PHP_RINIT_FUNCTION(zoo)
+{
+  return SUCCESS;
+}
+
+PHP_MINIT_FUNCTION(zoo)
+{
+  ZEND_INIT_MODULE_GLOBALS(zoo, php_zoo_init_globals,NULL);
+  REGISTER_INI_ENTRIES();
+  return SUCCESS;
+}
+
+PHP_MSHUTDOWN_FUNCTION(zoo)
+{
+  UNREGISTER_INI_ENTRIES();
+  return SUCCESS;
+}
+
+PHP_FUNCTION(zoo_Translate)
+{
+  char *value;
+  int value_len;
+  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) {
+    RETURN_NULL();
+  }
+  RETURN_STRING(_ss(value), 1);
+}
+
+PHP_FUNCTION(zoo_UpdateStatus)
+{
+  zval *arr;
+  char *message;
+  int message_len;
+  long pourcent;
+  char *status=(char*)malloc(4*sizeof(char));
+  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "asl", &arr, &message, &message_len,&pourcent) == FAILURE) {
+    RETURN_NULL();
+  }
+  HashTable* t=HASH_OF(arr);
+  maps* conf=php_maps_from_Array(t);
+  setMapInMaps(conf,"lenv","message",message);
+  sprintf(status,"%d",pourcent);
+  setMapInMaps(conf,"lenv","status",status);
+  _updateStatus(conf);
+  freeMaps(&conf);
+  free(conf);
+  free(status);
+  RETURN_NULL();
+}
+
+PHP_FUNCTION(zoo_SERVICE_SUCCEEDED)
+{
+  RETURN_LONG(ZOO_G(_SERVICE_SUCCEEDED));
+}
+
+PHP_FUNCTION(zoo_SERVICE_FAILED)
+{
+  RETURN_LONG(ZOO_G(_SERVICE_FAILED));
+}
 
 /**
@@ -62,24 +187,33 @@
 
   tmp=getMap(s->content,"serviceProvider");
+  map* cwd=getMapFromMaps(m,"lenv","cwd");
+  map* mp=getMap(request,"metapath");
+  char *scriptName;
+  if(mp!=NULL && strlen(mp->value)>0){
+    scriptName=(char*)malloc((strlen(cwd->value)+strlen(mp->value)+strlen(tmp->value)+3)*sizeof(char));
+    sprintf(scriptName,"%s/%s/%s",cwd->value,mp->value,tmp->value);
+  }else{
+    scriptName=(char*)malloc((strlen(cwd->value)+strlen(tmp->value)+2)*sizeof(char));
+    sprintf(scriptName,"%s/%s",cwd->value,tmp->value);
+  }
   zend_file_handle iscript;
-  iscript.type=ZEND_HANDLE_FP;
+  iscript.type=ZEND_HANDLE_FD;
+  iscript.opened_path=NULL;
   iscript.filename=tmp->value;
-  iscript.opened_path=NULL;
-  //iscript.free_filname=0;
-  if(!(iscript.handle.fp=fopen(iscript.filename,"rb"))){
+  iscript.free_filename=0;
+  FILE* temp=fopen(scriptName,"rb");
+  if(temp==NULL){
     char tmp1[1024];
-    sprintf(tmp1,"Unable to load PHP file %s",tmp->value);
-    map* err=createMap("text",tmp1);
-    addToMap(err,"code","NoApplicableCode");
-    printExceptionReportResponse(m,err);
-    exit(-1);
-  }
-
-  php_embed_init(0,NULL,&tsrm_ls);
+    sprintf(tmp1,_("Unable to load the PHP file %s"),tmp->value);
+    free(scriptName);
+    return errorException(m,tmp1,"NoApplicableCode",NULL);
+  }
+  iscript.handle.fd=fileno(temp);
+
+  php_embed_init(0,NULL PTSRMLS_CC);
    
   zend_try {
-
+    zend_startup_module(&zoo_module_entry);
     php_execute_script(&iscript TSRMLS_CC);
-
     zval *iargs[3];
     zval iret, ifunc,ifile;
@@ -89,21 +223,25 @@
     iargs[1] = php_Array_from_maps(*real_inputs);
     iargs[2] = php_Array_from_maps(*real_outputs);
-    
-    call_user_function(EG(function_table), NULL, &ifunc, &iret, 3, iargs TSRMLS_CC);
-
-    HashTable* t=HASH_OF(iargs[2]);
-    *real_outputs=php_maps_from_Array(t);
-    
-    char tmp1[1024];
-
-    res=SERVICE_SUCCEEDED;
-
+      
+    if((res=call_user_function(EG(function_table), NULL, &ifunc, &iret, 3, iargs TSRMLS_CC))==SUCCESS){
+      
+      HashTable* t=HASH_OF(iargs[2]);
+      HashTable* t1=HASH_OF(iargs[0]);
+      *real_outputs=php_maps_from_Array(t);
+      *main_conf=php_maps_from_Array(t1);
+
+      res=Z_LVAL(iret);
+    }else{
+      free(scriptName);
+      fclose(temp);
+      return errorException(m,"Unable to process.","NoApplicableCode",NULL);;
+    }
   } zend_catch { 
-    map* err=createMap("text","Unable to process.");
-    addToMap(err,"code","NoApplicableCode");
-    printExceptionReportResponse(m,err);
-    exit(-1);
+    free(scriptName);
+    fclose(temp);
+    return errorException(m,"Unable to process.","NoApplicableCode",NULL);;
   } zend_end_try();
-
+  free(scriptName);
+  fclose(temp);
   php_embed_shutdown(TSRMLS_C);
 
@@ -216,6 +354,9 @@
     if(final_res==NULL)
       final_res=cursor;
-    else
+    else{
       addMapsToMaps(&final_res,cursor);
+      freeMaps(&cursor);
+      free(cursor);
+    }
 #ifdef DEBUG
     fprintf(stderr,"key : %s\n",key);
@@ -289,16 +430,2 @@
   return final_res;
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: trunk/zoo-project/zoo-services/hello-php/cgi-env/hello.php
===================================================================
--- trunk/zoo-project/zoo-services/hello-php/cgi-env/hello.php	(revision 586)
+++ trunk/zoo-project/zoo-services/hello-php/cgi-env/hello.php	(revision 586)
@@ -0,0 +1,34 @@
+<?
+
+/**
+ * Author : Gérald FENOY
+ *
+ * Copyright 2009-20013 GeoLabs SARL. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+function HelloPHP(&$main_conf,&$inputs,&$outputs){
+  $tmp="Hello ".$inputs["S"]["value"]." from the PHP world !!";
+  $outputs["Result"]["value"]=zoo_Translate($tmp);
+  zoo_UpdateStatus($main_conf,"Final step",99);
+  return zoo_SERVICE_SUCCEEDED();
+}
+
+?>
Index: trunk/zoo-project/zoo-services/hello-php/hello.php
===================================================================
--- trunk/zoo-project/zoo-services/hello-php/hello.php	(revision 585)
+++ 	(revision )
@@ -1,33 +1,0 @@
-<?
-
-/**
- * Author : Gérald FENOY
- *
- * Copyright 2009-20013 GeoLabs SARL. All rights reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-function HelloPHP(&$main_conf,&$inputs,&$outputs){
-  $outputs=Array();
-  $outputs["Result"]["value"]="Hello ".$inputs[S][value]." from the PHP world !!";
-  return 3;
-}
-
-?>
