[mapserver-commits] r8266 - in trunk/mapserver: . mapscript/php3

svn at osgeo.org svn at osgeo.org
Fri Dec 19 10:21:43 EST 2008


Author: aboudreault
Date: 2008-12-19 10:21:43 -0500 (Fri, 19 Dec 2008)
New Revision: 8266

Removed:
   trunk/mapserver/mapscript/php3/hashtable_i.c
Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapscript/php3/mapscript_i.c
   trunk/mapserver/mapscript/php3/php_mapscript.c
   trunk/mapserver/mapscript/php3/php_mapscript.h
Log:
Added hashtable object and metadata methods for php-mapscript (#2773)


Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2008-12-19 14:35:17 UTC (rev 8265)
+++ trunk/mapserver/HISTORY.TXT	2008-12-19 15:21:43 UTC (rev 8266)
@@ -12,6 +12,8 @@
 Current Version (5.3-dev, SVN trunk):
 ------------------------------------
 
+- Added hashtable object and metadata methods for php-mapscript (#2773)
+
 - mappostgis.c: Fix trailing spaces in fixed varchar fields (#2817)
 
 - RFC48 implementation: GEOMTRANSFORM on styleObj (#2825)

Deleted: trunk/mapserver/mapscript/php3/hashtable_i.c
===================================================================
--- trunk/mapserver/mapscript/php3/hashtable_i.c	2008-12-19 14:35:17 UTC (rev 8265)
+++ trunk/mapserver/mapscript/php3/hashtable_i.c	2008-12-19 15:21:43 UTC (rev 8266)
@@ -1,73 +0,0 @@
-/*
- * hashtable_i.c: This file was originally based on the SWIG interface 
- *                file hashtable.i
- *
- * $Id$
- *
- */
-
-
-#include "php_mapscript.h"
-
-
-
-/* ========================================================================
- * Include maphash header, first stating declarations to ignore
- * ======================================================================== */
-
-#include "../../maphash.h"
-
-/* ======================================================================== 
- * Extension methods
- * ======================================================================== */
-
-    // New instance
-    hashTableObj *hashTableObj_new() {
-        return msCreateHashTable();
-    }
-
-    // Destroy instance
-    void hashTableObj_destroy(hashTableObj *self) {
-        msFreeHashTable(self);
-    }
-
-    // set a hash item given key and value
-    int hashTableObj_set(hashTableObj *self, const char *key, const char *value) {
-        if (msInsertHashTable(self, key, value) == NULL) {
-	        return MS_FAILURE;
-        }
-        return MS_SUCCESS;
-    }
-
-    // get value from item by its key
-    const char *hashTableObj_get(hashTableObj *self, const char *key) {
-        char *value = NULL;
-        if (!key) {
-            msSetError(MS_HASHERR, "NULL key", "get");
-        }
-     
-        value = (char *) msLookupHashTable(self, key);
-        if (!value) {
-            msSetError(MS_HASHERR, "Key %s does not exist", "get", key);
-            return NULL;
-        }
-        return value;
-    }
-
-    // Remove one item from hash table
-    int *hashTableObj_remove(hashTableObj *self, const char *key) {
-        return msRemoveHashTable(self, key);
-    }
-
-    // Clear all items in hash table (to NULL)
-    void *hashTableObj_clear(hashTableObj *self) {
-        msFreeHashItems(self);
-        initHashTable(self);
-    }
-
-    // Return the next key or first key if prevkey == NULL
-    char *hashTableObj_nextKey(hashTableObj *self, const char *prevkey) {
-        char *key;
-        key = msNextKeyFromHashTable(self, prevkey);
-        return key;
-    }

Modified: trunk/mapserver/mapscript/php3/mapscript_i.c
===================================================================
--- trunk/mapserver/mapscript/php3/mapscript_i.c	2008-12-19 14:35:17 UTC (rev 8265)
+++ trunk/mapserver/mapscript/php3/mapscript_i.c	2008-12-19 15:21:43 UTC (rev 8266)
@@ -39,6 +39,7 @@
 #include "../../mapsymbol.h"
 #include "../../mapshape.h"
 #include "../../mapproject.h"
+#include "../../maphash.h"
 
 /**********************************************************************
  * class extensions for mapObj
@@ -1329,3 +1330,47 @@
     msFreeCharArray(self->ParamValues, self->NumParams);
     free(self);
 }
+
+
+/**********************************************************************
+ * class extensions hashTableObj
+ **********************************************************************/
+
+// New instance
+hashTableObj *hashTableObj_new() {
+   return msCreateHashTable();
+}
+
+// Destroy instance
+void hashTableObj_destroy(hashTableObj *self) {
+   msFreeHashTable(self);
+}
+
+// set a hash item given key and value
+int hashTableObj_set(hashTableObj *self, const char *key, const char *value) {
+   if (msInsertHashTable(self, key, value) == NULL) {
+      return MS_FAILURE;
+   }
+   return MS_SUCCESS;
+}
+
+// get value from item by its key
+const char *hashTableObj_get(hashTableObj *self, const char *key) {
+   return (msLookupHashTable(self, key));
+}
+
+// Remove one item from hash table
+int hashTableObj_remove(hashTableObj *self, const char *key) {
+   return (msRemoveHashTable(self, key));
+}
+
+// Clear all items in hash table (to NULL)
+void hashTableObj_clear(hashTableObj *self) {
+   msFreeHashItems(self);
+   initHashTable(self);
+}
+
+// Return the next key or first key if previousKey == NULL
+char *hashTableObj_nextKey(hashTableObj *self, const char *previousKey) {
+   return ((char *)msNextKeyFromHashTable(self, previousKey));
+}

Modified: trunk/mapserver/mapscript/php3/php_mapscript.c
===================================================================
--- trunk/mapserver/mapscript/php3/php_mapscript.c	2008-12-19 14:35:17 UTC (rev 8265)
+++ trunk/mapserver/mapscript/php3/php_mapscript.c	2008-12-19 15:21:43 UTC (rev 8266)
@@ -370,6 +370,12 @@
 DLEXPORT void php_ms_cgirequest_getValue(INTERNAL_FUNCTION_PARAMETERS);
 DLEXPORT void php_ms_cgirequest_getValueByName(INTERNAL_FUNCTION_PARAMETERS);
 
+DLEXPORT void php3_ms_hashtable_get(INTERNAL_FUNCTION_PARAMETERS);
+DLEXPORT void php3_ms_hashtable_set(INTERNAL_FUNCTION_PARAMETERS);
+DLEXPORT void php3_ms_hashtable_remove(INTERNAL_FUNCTION_PARAMETERS);
+DLEXPORT void php3_ms_hashtable_clear(INTERNAL_FUNCTION_PARAMETERS);
+DLEXPORT void php3_ms_hashtable_nextkey(INTERNAL_FUNCTION_PARAMETERS);
+
 static long _phpms_build_img_object(imageObj *im, webObj *pweb,
                                     HashTable *list, pval *return_value  TSRMLS_DC);
 static long _phpms_build_layer_object(layerObj *player, int parent_map_id,
@@ -434,7 +440,10 @@
 static long _phpms_build_querymap_object(queryMapObj *pquerymap,
                                       HashTable *list, pval *return_value TSRMLS_DC);
 
+static long _phpms_build_hashtable_object(hashTableObj *hashtable,
+                                          HashTable *list, pval *return_value TSRMLS_DC);
 
+
 /* ==================================================================== */
 /*      utility functions prototypes.                                   */
 /* ==================================================================== */
@@ -493,6 +502,7 @@
 static int le_mssymbol;
 static int le_msquerymap;
 static int le_mscgirequest;
+static int le_mshashtable;
 
 /* 
  * Declare any global variables you may need between the BEGIN
@@ -560,6 +570,7 @@
 static zend_class_entry *symbol_class_entry_ptr;
 static zend_class_entry *querymap_class_entry_ptr;
 static zend_class_entry *cgirequest_class_entry_ptr;
+static zend_class_entry *hashtable_class_entry_ptr;
 
 #ifdef ZEND_ENGINE_2  // PHP5
 ZEND_BEGIN_ARG_INFO(one_arg_force_ref, 0)
@@ -960,8 +971,15 @@
     {NULL, NULL, NULL}
 };
 
+function_entry php_hashtable_class_functions[] = {
+    {"get",             php3_ms_hashtable_get,        NULL},    
+    {"set",             php3_ms_hashtable_set,        NULL},    
+    {"remove",          php3_ms_hashtable_remove,     NULL},    
+    {"clear",           php3_ms_hashtable_clear,      NULL},
+    {"nextkey",         php3_ms_hashtable_nextkey,    NULL},  
+    {NULL, NULL, NULL}
+};
 
-
 function_entry php_cgirequest_class_functions[] = {
     {"loadparams",             php_ms_cgirequest_loadParams,   NULL},
     {"setparameter",             php_ms_cgirequest_setParameter,   NULL},
@@ -1084,8 +1102,9 @@
     PHPMS_GLOBAL(le_mscgirequest)= 
         register_list_destructors(php_ms_free_cgirequest, NULL);
     
+    PHPMS_GLOBAL(le_mshashtable)= register_list_destructors(php3_ms_free_stub, 
+                                                            NULL);
 
-
     /* boolean constants*/
     REGISTER_LONG_CONSTANT("MS_TRUE",       MS_TRUE,        const_flag);
     REGISTER_LONG_CONSTANT("MS_FALSE",      MS_FALSE,       const_flag);
@@ -1374,6 +1393,9 @@
      INIT_CLASS_ENTRY(tmp_class_entry, "ms_cgirequest_obj", php_cgirequest_class_functions);
      cgirequest_class_entry_ptr = zend_register_internal_class(&tmp_class_entry TSRMLS_CC);
 
+     INIT_CLASS_ENTRY(tmp_class_entry, "ms_hashtable_obj", php_hashtable_class_functions);
+     hashtable_class_entry_ptr = zend_register_internal_class(&tmp_class_entry TSRMLS_CC);
+
     return SUCCESS;
 }
 
@@ -6612,6 +6634,10 @@
     _phpms_build_color_object(&(player->offsite),list, new_obj_ptr TSRMLS_CC);
     _phpms_add_property_object(return_value, "offsite", new_obj_ptr, E_ERROR TSRMLS_CC);
 
+    MAKE_STD_ZVAL(new_obj_ptr);
+    _phpms_build_hashtable_object(&(player->metadata),list, new_obj_ptr TSRMLS_CC);
+    _phpms_add_property_object(return_value, "metadata",new_obj_ptr,E_ERROR TSRMLS_CC);
+
     if (player->connectiontype == MS_GRATICULE && 
         player->layerinfo != NULL)
     {
@@ -9019,6 +9045,10 @@
     PHPMS_ADD_PROP_STR(return_value,   "keyimage",  pclass->keyimage);
 
     PHPMS_ADD_PROP_STR(return_value,   "group",  pclass->group);
+
+    MAKE_STD_ZVAL(new_obj_ptr);
+    _phpms_build_hashtable_object(&(pclass->metadata),list, new_obj_ptr TSRMLS_CC);
+    _phpms_add_property_object(return_value, "metadata",new_obj_ptr,E_ERROR TSRMLS_CC);
     
     return class_id;
 }
@@ -12416,13 +12446,7 @@
                                     HashTable *list, pval *return_value TSRMLS_DC)
 {
     int         web_id;
-#ifdef PHP4
     pval        *new_obj_ptr;
-#else
-    pval        new_obj_param;  /* No, it's not a pval * !!! */
-    pval        *new_obj_ptr;
-    new_obj_ptr = &new_obj_param;
-#endif
 
     if (pweb == NULL)
         return 0;
@@ -12454,13 +12478,15 @@
     PHPMS_ADD_PROP_STR(return_value,  "browseformat",   pweb->browseformat);
     
     
-#ifdef PHP4
     MAKE_STD_ZVAL(new_obj_ptr);
-#endif
     _phpms_build_rect_object(&(pweb->extent), PHPMS_GLOBAL(le_msrect_ref), 
                              list, new_obj_ptr TSRMLS_CC);
     _phpms_add_property_object(return_value, "extent", new_obj_ptr,E_ERROR TSRMLS_CC);
 
+    MAKE_STD_ZVAL(new_obj_ptr);
+    _phpms_build_hashtable_object(&(pweb->metadata),list, new_obj_ptr TSRMLS_CC);
+    _phpms_add_property_object(return_value, "metadata",new_obj_ptr,E_ERROR TSRMLS_CC);
+
     return web_id;
 }
 
@@ -15553,6 +15579,214 @@
 }
 /* }}} */
 
+/*=====================================================================
+ *         PHP function wrappers - hashtable object
+ *====================================================================*/
+
+static long _phpms_build_hashtable_object(hashTableObj *hashtable,
+                                          HashTable *list, pval *return_value TSRMLS_DC)
+{
+    int hashtable_id;
+
+    if (hashtable == NULL)
+      return 0;
+
+    hashtable_id = php3_list_insert(hashtable, PHPMS_GLOBAL(le_mshashtable));
+
+    _phpms_object_init(return_value, hashtable_id, php_hashtable_class_functions,
+                       PHP4_CLASS_ENTRY(hashtable_class_entry_ptr) TSRMLS_CC);
+
+    return hashtable_id;
+}
+
+
+/**********************************************************************
+ *                        hashtable->get()
+ **********************************************************************/
+
+/* {{{ proto int hashtable.get(string key)
+   Get a value from item by its key. Returns empty string if not found. */
+
+DLEXPORT void php3_ms_hashtable_get(INTERNAL_FUNCTION_PARAMETERS)
+{
+    hashTableObj *self;
+    pval         *pKey, *pThis;  
+    const char   *pszValue=NULL;
+    HashTable   *list=NULL;
+
+    pThis = getThis();
+
+    if (pThis == NULL ||
+        getParameters(ht, 1, &pKey) != SUCCESS)
+    {
+        WRONG_PARAM_COUNT;
+    }
+
+    self = (hashTableObj *)_phpms_fetch_handle(pThis, PHPMS_GLOBAL(le_mshashtable),
+                                               list TSRMLS_CC);
+
+    convert_to_string(pKey);
+
+    if ((self == NULL) ||
+        ((pszValue = hashTableObj_get(self, pKey->value.str.val)) == NULL))
+    {
+       pszValue = "";
+    }
+
+    RETURN_STRING((char *)pszValue, 1);
+}
+/* }}} */
+
+/**********************************************************************
+ *                        hashtable->set()
+ **********************************************************************/
+
+/* {{{ proto int hashtable.set(string key, string value)
+   Set a hash item given key and value. Returns MS_FAILURE on error. */
+
+DLEXPORT void php3_ms_hashtable_set(INTERNAL_FUNCTION_PARAMETERS)
+{
+    hashTableObj *self;
+    pval         *pKey, *pValue, *pThis;
+    int          nStatus = MS_FAILURE;
+    HashTable   *list=NULL;
+
+    pThis = getThis();
+
+    if (pThis == NULL ||
+        getParameters(ht, 2, &pKey, &pValue) != SUCCESS)
+    {
+        WRONG_PARAM_COUNT;
+    }
+
+    self = (hashTableObj *)_phpms_fetch_handle(pThis, PHPMS_GLOBAL(le_mshashtable),
+                                               list TSRMLS_CC);
+
+    if (self == NULL)
+       RETURN_LONG(nStatus);
+          
+    convert_to_string(pKey);
+    convert_to_string(pValue);      
+    
+    if ((nStatus = hashTableObj_set(self, pKey->value.str.val, 
+                                    pValue->value.str.val)) != MS_SUCCESS)
+    {
+        _phpms_report_mapserver_error(E_ERROR);
+    }
+
+    RETURN_LONG(nStatus);
+}
+/* }}} */
+
+/**********************************************************************
+ *                        hashtable->remove()
+ **********************************************************************/
+
+/* {{{ proto int hashtable.remove(string key)
+   Remove one item from hash table. Returns MS_FAILURE on error. */
+
+DLEXPORT void php3_ms_hashtable_remove(INTERNAL_FUNCTION_PARAMETERS)
+{
+    hashTableObj *self;
+    pval         *pKey, *pThis;  
+    int           nStatus = MS_FAILURE;
+    HashTable   *list=NULL;
+
+    pThis = getThis();
+
+    if (pThis == NULL ||
+        getParameters(ht, 1, &pKey) != SUCCESS)
+    {
+        WRONG_PARAM_COUNT;
+    }
+
+    self = (hashTableObj *)_phpms_fetch_handle(pThis, PHPMS_GLOBAL(le_mshashtable),
+                                               list TSRMLS_CC);
+    if (self == NULL)
+       RETURN_LONG(nStatus);
+
+    convert_to_string(pKey);
+
+    if ((nStatus = hashTableObj_remove(self, pKey->value.str.val)) != MS_SUCCESS)
+    {
+       _phpms_report_mapserver_error(E_ERROR);
+    }
+    
+    RETURN_LONG(nStatus);
+}
+/* }}} */
+
+/**********************************************************************
+ *                        hashtable->clear()
+ **********************************************************************/
+
+/* {{{ proto int hashtable.clear()
+   Clear all items in hash table (to NULL). */
+
+DLEXPORT void php3_ms_hashtable_clear(INTERNAL_FUNCTION_PARAMETERS)
+{
+    hashTableObj *self;
+    pval         *pThis;  
+    HashTable   *list=NULL;
+
+    pThis = getThis();
+
+    if (pThis == NULL || ARG_COUNT(ht) > 0)
+    {
+        WRONG_PARAM_COUNT;
+    }
+
+    self = (hashTableObj *)_phpms_fetch_handle(pThis, PHPMS_GLOBAL(le_mshashtable),
+                                               list TSRMLS_CC);
+
+    if (self == NULL)
+       return;
+    
+    hashTableObj_clear(self);
+}
+/* }}} */
+
+/**********************************************************************
+ *                        hashtable->nextkey()
+ **********************************************************************/
+
+/* {{{ proto int hashtable.nextkey(string previousKey)
+   Return the next key or first key if previousKey == NULL. 
+   Returns NULL if no item is in the hashTable or end of hashTable reached */
+
+DLEXPORT void php3_ms_hashtable_nextkey(INTERNAL_FUNCTION_PARAMETERS)
+{
+    hashTableObj *self;
+    pval         *pPreviousKey, *pThis;
+    char         *pszKey = "", *pszValue = NULL;
+    HashTable   *list=NULL;
+
+    pThis = getThis();
+
+    if (pThis == NULL ||
+        getParameters(ht, 1, &pPreviousKey) != SUCCESS)
+    {
+        WRONG_PARAM_COUNT;
+    }
+
+    self = (hashTableObj *)_phpms_fetch_handle(pThis, PHPMS_GLOBAL(le_mshashtable),
+                                               list TSRMLS_CC);
+
+    convert_to_string(pPreviousKey);
+
+    if (strcmp(pPreviousKey->value.str.val,"") != 0)
+    {
+       pszKey = pPreviousKey->value.str.val;
+    }
+
+    if ((self == NULL) || 
+        (pszValue = hashTableObj_nextKey(self, pszKey)) == NULL)
+       return;
+
+    RETURN_STRING(pszValue, 1);
+}
+/* }}} */
+
 /* ==================================================================== */
 /*      utility functions related to msio                               */
 /* ==================================================================== */

Modified: trunk/mapserver/mapscript/php3/php_mapscript.h
===================================================================
--- trunk/mapserver/mapscript/php3/php_mapscript.h	2008-12-19 14:35:17 UTC (rev 8265)
+++ trunk/mapserver/mapscript/php3/php_mapscript.h	2008-12-19 15:21:43 UTC (rev 8266)
@@ -296,15 +296,12 @@
                                          char* pszSymbolName);
 styleObj       *styleObj_clone(styleObj *style);
 
-/*=====================================================================
- *                   Internal functions from hashtable_i.c
- *====================================================================*/
 hashTableObj   *hashTableObj_new();
 int             hashTableObj_set(hashTableObj *self, const char *key, 
                                  const char *value);
 const char     *hashTableObj_get(hashTableObj *self, const char *key);
-int            *hashTableObj_remove(hashTableObj *self, const char *key);
-void           *hashTableObj_clear(hashTableObj *self);
+int            hashTableObj_remove(hashTableObj *self, const char *key);
+void           hashTableObj_clear(hashTableObj *self);
 char           *hashTableObj_nextKey(hashTableObj *self, const char *prevkey);
 
 



More information about the mapserver-commits mailing list