diff options
author | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:10:36 +0000 |
---|---|---|
committer | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:10:36 +0000 |
commit | 4fc70143242a9de91ee14a73eb0f7b95958449f2 (patch) | |
tree | fb3f54e8a0acb2af41856e3b762d0bfbb6c3d484 | |
parent | c78a0c99cffddb2851bb0077c15cbc44c17f4ba5 (diff) | |
download | lasso-4fc70143242a9de91ee14a73eb0f7b95958449f2.tar.gz lasso-4fc70143242a9de91ee14a73eb0f7b95958449f2.tar.xz lasso-4fc70143242a9de91ee14a73eb0f7b95958449f2.zip |
[project @ fpeters@0d.be-20080423100400-sbs984j19ik6dxzi]
merge
Original author: Frederic Peters <fpeters@0d.be>
Date: 2008-04-23 12:04:00.477000+02:00
-rw-r--r-- | bindings/lang_php5_helpers/php_code.py | 22 | ||||
-rw-r--r-- | bindings/lang_php5_helpers/wrapper_source.py | 57 | ||||
-rw-r--r-- | bindings/lang_php5_helpers/wrapper_source_top.c | 24 | ||||
-rw-r--r-- | bindings/overrides.xml | 7 | ||||
-rw-r--r-- | bindings/php5/Makefile.am | 2 | ||||
-rwxr-xr-x | bindings/php5/tests/profile_tests.php | 3 | ||||
-rw-r--r-- | bindings/python/Makefile.am | 2 |
7 files changed, 69 insertions, 48 deletions
diff --git a/bindings/lang_php5_helpers/php_code.py b/bindings/lang_php5_helpers/php_code.py index a15a08b1..8b8eef84 100644 --- a/bindings/lang_php5_helpers/php_code.py +++ b/bindings/lang_php5_helpers/php_code.py @@ -52,20 +52,7 @@ class PhpCode: // Try to load Lasso extension if it's not already loaded. if (!extension_loaded('lasso')) { - if (strtolower(substr(PHP_OS, 0, 3)) === 'win') { - $extension_module = 'lasso.dll'; - } else { - // PHP_SHLIB_SUFFIX is available as of PHP 4.3.0, for older PHP assume 'so'. - // It gives 'dylib' on MacOS X which is for libraries, modules are 'so'. - if (PHP_SHLIB_SUFFIX === 'PHP_SHLIB_SUFFIX' || PHP_SHLIB_SUFFIX === 'dylib') { - $extension_module = 'lasso.so'; - } else { - $extension_module = 'lasso.'.PHP_SHLIB_SUFFIX; - } - } - if (!dl($extension_module)) { - die('E: Could not load Lasso extension module.\n'); - } + die("Lasso extension is not loaded"); } /* @@ -83,9 +70,13 @@ function cptrToPhp ($cptr) { return null; } -function getRequestTypeFromSoapMsg($mesg) { +function lassoGetRequestTypeFromSoapMsg($mesg) { return lasso_get_request_type_from_soap_msg($mesg); } + +function lassoRegisterIdWsf2DstService($prefix, $href) { + lasso_register_idwsf2_dst_service($prefix, $href); +} ''' def generate_class(self, klass): @@ -482,6 +473,5 @@ class LassoError extends Exception { def generate_footer(self): print >> self.fd, '''\ - lasso_init(); ?>''' diff --git a/bindings/lang_php5_helpers/wrapper_source.py b/bindings/lang_php5_helpers/wrapper_source.py index e37a26f3..a882d2fa 100644 --- a/bindings/lang_php5_helpers/wrapper_source.py +++ b/bindings/lang_php5_helpers/wrapper_source.py @@ -65,6 +65,7 @@ class WrapperSource: PHP_MINIT_FUNCTION(lasso) { le_lasso_server = zend_register_list_destructors_ex(php_gobject_generic_destructor, NULL, PHP_LASSO_SERVER_RES_NAME, module_number); + lasso_init(); ''' def generate_constants(self): @@ -92,39 +93,42 @@ PHP_MINIT_FUNCTION(lasso) PHP_MSHUTDOWN_FUNCTION(lasso) { - return SUCCESS; + lasso_shutdown(); } + ''' - def return_value(self, vtype, options): + def return_value(self, vtype, options, free = False): if vtype is None: return elif vtype == 'gboolean': - print >> self.fd, ' RETURN_BOOL(return_c_value);' + print >> self.fd, ' RETVAL_BOOL(return_c_value);' elif vtype in ['int', 'gint'] + self.binding_data.enums: - print >> self.fd, ' RETURN_LONG(return_c_value);' + print >> self.fd, ' RETVAL_LONG(return_c_value);' elif vtype in ('char*', 'gchar*'): print >> self.fd, '''\ if (return_c_value) { - RETURN_STRING(return_c_value, 1); + RETVAL_STRING(return_c_value, 1); } else { - RETURN_NULL(); + RETVAL_NULL(); }''' + if free: + print >> self.fd, ' free(return_c_value);' elif vtype in ('const char*', 'const gchar*'): print >> self.fd, '''\ if (return_c_value) { - RETURN_STRING(estrndup(return_c_value, strlen(return_c_value)), 0); + RETVAL_STRING((char*)return_c_value, 1); } else { - RETURN_NULL(); + RETVAL_NULL(); }''' elif vtype == 'xmlNode*': print >> self.fd, '''\ { char* xmlString = get_string_from_xml_node(return_c_value); if (xmlString) { - RETURN_STRING(xmlString, 1); + RETVAL_STRING(xmlString, 0); } else { - RETURN_NULL(); + RETVAL_NULL(); } } ''' @@ -133,14 +137,20 @@ PHP_MSHUTDOWN_FUNCTION(lasso) print >> self.fd, '''\ set_array_from_list_of_strings(return_c_value, &return_value); ''' + if free: + print >> self.fd, ' free_glist(&return_c_value, (GFunc)free);' elif options.get('elem_type') == 'xmlNode*': print >> self.fd, '''\ set_array_from_list_of_xmlnodes(return_c_value, &return_value); ''' + if free: + print >> self.fd, ' free_glist(&return_c_value, (GFunc)efree);' else: print >> self.fd, '''\ set_array_from_list_of_objects(return_c_value, &return_value); ''' + if free: + print >> self.fd, ' free_glist(&return_c_value, NULL);' elif vtype == 'GHashTable*': if options.get('elem_type') not in ('char*', 'xmlNode*'): print >> self.fd, '''\ @@ -152,10 +162,15 @@ PHP_MSHUTDOWN_FUNCTION(lasso) self = PhpGObjectPtr_New(G_OBJECT(return_c_value)); ZEND_REGISTER_RESOURCE(return_value, self, le_lasso_server); } else { - RETURN_NULL(); + RETVAL_NULL(); }''' + if free: +# print >> self.fd, ' printf("UNREF %p line %i\\n", return_c_value, __LINE__);' + print >> self.fd, ' g_object_unref(return_c_value); // Constructor' def generate_function(self, m): + if m.name in ('lasso_init','lasso_shutdown'): + return if m.rename: name = m.rename else: @@ -239,10 +254,10 @@ PHP_MSHUTDOWN_FUNCTION(lasso) elem_type = arg[2].get('elem_type') if elem_type == 'char*': print >> self.fd, ' if (%(name)s) {' % { 'name': arg[1] } - print >> self.fd, ' free_glist(%(name)s,free);' % { 'name': arg[1] } + print >> self.fd, ' free_glist(&%(name)s,(GFunc)free);' % { 'name': arg[1] } print >> self.fd, ' }' - self.return_value(m.return_type, {}) + self.return_value(m.return_type, {}, m.return_owner) print >> self.fd, '}' print >> self.fd, '' @@ -394,17 +409,25 @@ PHP_MSHUTDOWN_FUNCTION(lasso) ''' % { 'name': m_name } else: print >> self.fd, ''' - /* FIXME: Free the existing list */ + free_glist(&this->%(name)s, (GFunc)g_object_unref); this->%(name)s = get_list_from_array_of_objects(zval_%(name)s); ''' % { 'name': m_name } elif arg_type == 'GHashTable*' and arg_options.get('elem_type') != 'char*': print >> self.fd, '''\ - /* FIXME: Free the existing hashtable */ - this->%(name)s = get_hashtable_from_array_of_objects(zval_%(name)s); + { + GHashTable *oldhash = this->%(name)s; + this->%(name)s = get_hashtable_from_array_of_objects(zval_%(name)s); + g_hash_table_destroy(oldhash); + } ''' % { 'name': m_name } elif parse_tuple_format == 'r': print >> self.fd, ' ZEND_FETCH_RESOURCE(cvt_%s, PhpGObjectPtr*, &zval_%s, -1, PHP_LASSO_SERVER_RES_NAME, le_lasso_server);' % (m_name, m_name) - print >> self.fd, ' this->%s = (%s)cvt_%s->obj;' % (m_name, m_type, m_name) + print >> self.fd, ''' + g_object_ref(cvt_%(name)s->obj); + if (this->%(name)s) + g_object_unref(this->%(name)s); + this->%(name)s = (%(type)s)cvt_%(name)s->obj; +''' % { 'name': m_name, 'type': m_type } print >> self.fd, '}' print >> self.fd, '' diff --git a/bindings/lang_php5_helpers/wrapper_source_top.c b/bindings/lang_php5_helpers/wrapper_source_top.c index 4835913c..a2447d5d 100644 --- a/bindings/lang_php5_helpers/wrapper_source_top.c +++ b/bindings/lang_php5_helpers/wrapper_source_top.c @@ -24,6 +24,7 @@ typedef struct { char *typename; } PhpGObjectPtr; +/** FIXME: implement caching of objects inside GObjects using a GQuark */ static PhpGObjectPtr* PhpGObjectPtr_New(GObject *obj) { @@ -33,9 +34,10 @@ PhpGObjectPtr_New(GObject *obj) return NULL; } - self = (PhpGObjectPtr *)emalloc(sizeof(PhpGObjectPtr)); + self = (PhpGObjectPtr *)malloc(sizeof(PhpGObjectPtr)); self->obj = g_object_ref(obj); - self->typename = estrdup(G_OBJECT_TYPE_NAME(obj)); + self->typename = strdup(G_OBJECT_TYPE_NAME(obj)); + //printf("Allocating container %p for object %p of type %s with refcnt %i\n", self, obj, self->typename, obj->ref_count); return self; } @@ -60,12 +62,15 @@ static void php_gobject_generic_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC) if (gobject) { if (gobject->obj) { + //printf("Deallocating container %p\n", gobject); + //printf("Deallocating %p that has %u refcounts\n", gobject->obj, gobject->obj->ref_count); g_object_unref(G_OBJECT(gobject->obj)); + //printf("now %u refcounts\n", gobject->obj->ref_count); } if (gobject->typename) { - efree(gobject->typename); + free(gobject->typename); } - efree(gobject); + free(gobject); } } @@ -172,7 +177,6 @@ get_list_from_array_of_xmlnodes(zval* array) int size; zval** data; zval temp; - char *temp_str; GList* result = NULL; hashtable = Z_ARRVAL_P(array); @@ -183,8 +187,7 @@ get_list_from_array_of_xmlnodes(zval* array) temp = **data; zval_copy_ctor(&temp); convert_to_string(&temp); - temp_str = estrndup(Z_STRVAL(temp), Z_STRLEN(temp)); - result = g_list_append(result, get_xml_node_from_string(temp_str)); + result = g_list_append(result, get_xml_node_from_string(Z_STRVAL(temp))); zval_dtor(&temp); } return result; @@ -197,7 +200,7 @@ set_array_from_list_of_xmlnodes(GList* list, zval **array) { array_init(*array); for (item = g_list_first(list); item != NULL; item = g_list_next(item)) { if (item->data != NULL) { - add_next_index_string(*array, get_string_from_xml_node(item->data), 1); + add_next_index_string(*array, get_string_from_xml_node(item->data), 0); } else { add_next_index_null(*array); } @@ -221,6 +224,7 @@ get_list_from_array_of_objects(zval *array) zend_hash_move_forward_ex(hashtable, &pointer)) { cvt_temp = (PhpGObjectPtr*) zend_fetch_resource(data TSRMLS_CC, -1, PHP_LASSO_SERVER_RES_NAME, NULL, 1, le_lasso_server); if (cvt_temp != NULL) { + g_object_ref(cvt_temp->obj); result = g_list_append(result, cvt_temp->obj); } else { result = g_list_append(result, NULL); @@ -238,7 +242,7 @@ set_array_from_list_of_objects(GList *list, zval **array) array_init(*array); for (item = g_list_first(list); item != NULL; item = g_list_next(item)) { if (item->data != NULL) { - zval_item = emalloc(sizeof(PhpGObjectPtr)); + MAKE_STD_ZVAL(zval_item); ZEND_REGISTER_RESOURCE(zval_item, PhpGObjectPtr_New(item->data), le_lasso_server); add_next_index_zval(*array, zval_item); } else { @@ -296,7 +300,7 @@ set_array_from_hashtable_of_objects(GHashTable *hashtable, zval **array) for (keys = g_hash_table_get_keys(hashtable); keys; keys = g_list_next(keys)) { item = g_hash_table_lookup(hashtable, keys->data); if (item) { - zval_item = emalloc(sizeof(PhpGObjectPtr)); + MAKE_STD_ZVAL(zval_item); ZEND_REGISTER_RESOURCE(zval_item, PhpGObjectPtr_New(item), le_lasso_server); add_assoc_zval(*array, (char*)keys->data, zval_item); } else { diff --git a/bindings/overrides.xml b/bindings/overrides.xml index c8415452..95418671 100644 --- a/bindings/overrides.xml +++ b/bindings/overrides.xml @@ -9,6 +9,8 @@ <func name="lasso_profile_get_request_type_from_soap_msg" rename="lasso_get_request_type_from_soap_msg"/> <func name="lasso_session_get_assertions" return_owner="true"/> + <!-- LassoProvider --> + <func name="lasso_provider_get_metadata_list" return_owner="false"/> <!-- LassoProfile --> <func name="lasso_profile_get_nameIdentifier" rename="lasso_profile_get_federation_nameIdentifier" @@ -28,6 +30,7 @@ <func name="lasso_identity_get_offerings" return_type_qualifier="LassoNode*"> <param name="service_type" optional="true"/> </func> + <func name="lasso_identity_get_resource_offering" return_owner="false"/> <!-- LassoServer --> <func name="lasso_server_new"> <param name="metadata" optional="true"/> @@ -43,6 +46,9 @@ <param name="svcMDIDs" type="GList*" elem_type="char*"/> <param name="service_type"/> </func> + <func name="lasso_server_get_service" return_owner="false"/> + <!-- LassoSession --> + <func name="lasso_session_get_endpoint_reference" return_owner="false"/> <!-- LassoProvider --> <func name="lasso_provider_new"> <param name="public_key" optional="true"/> @@ -136,6 +142,7 @@ <func name="lasso_discovery_get_service"> <param name="service_type" optional="true"/> </func> + <func name="lasso_discovery_get_description_auto" return_owner="false"/> <!-- LassoDataService --> <func name="lasso_data_service_init_query"> <param name="select" optional="true"/> diff --git a/bindings/php5/Makefile.am b/bindings/php5/Makefile.am index 1ff0023f..7115995e 100644 --- a/bindings/php5/Makefile.am +++ b/bindings/php5/Makefile.am @@ -21,7 +21,7 @@ if WSF_ENABLED EXTRA_ARGS = --enable-id-wsf endif -lasso.php _lasso.c: ../lang_php5.py ../lang_php5_helpers/php_code.py ../lang_php5_helpers/wrapper_source.py ../lang_php5_helpers/wrapper_source_top.c +lasso.php _lasso.c: ../lang_php5.py ../lang_php5_helpers/php_code.py ../lang_php5_helpers/wrapper_source.py ../lang_php5_helpers/wrapper_source_top.c ../overrides.xml $(PYTHON) $(top_srcdir)/bindings/bindings.py -l php5 --src-dir=$(top_srcdir)/lasso/ $(EXTRA_ARGS) doc: diff --git a/bindings/php5/tests/profile_tests.php b/bindings/php5/tests/profile_tests.php index a6497a3b..50264330 100755 --- a/bindings/php5/tests/profile_tests.php +++ b/bindings/php5/tests/profile_tests.php @@ -216,7 +216,6 @@ function test07() { echo "OK.\n"; } -lasso_init(); test01(); test02(); test03(); @@ -224,5 +223,3 @@ test04(); test05(); test06(); test07(); -lasso_shutdown(); - diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am index 5e4c62a7..ff02fe17 100644 --- a/bindings/python/Makefile.am +++ b/bindings/python/Makefile.am @@ -28,7 +28,7 @@ if WSF_ENABLED EXTRA_ARGS = --enable-id-wsf endif -_lasso.c: +lasso.py _lasso.c: $(PYTHON) $(top_srcdir)/bindings/bindings.py -l python --src-dir=$(top_srcdir)/lasso/ $(EXTRA_ARGS) clean-local: |