diff options
author | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:08:51 +0000 |
---|---|---|
committer | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:08:51 +0000 |
commit | 1b3acf88af0388020053167b4646ee6c08e09e73 (patch) | |
tree | 8a2c6f375111861e9a53ddbc1615ba66e0140626 /bindings | |
parent | 500495f0dd0df08c51e95f22e7d1ec0bac354030 (diff) | |
download | lasso-1b3acf88af0388020053167b4646ee6c08e09e73.tar.gz lasso-1b3acf88af0388020053167b4646ee6c08e09e73.tar.xz lasso-1b3acf88af0388020053167b4646ee6c08e09e73.zip |
[project @ fpeters@0d.be-20080328175710-s4031yloqsdbmvel]
merging benjamin branch
Original author: Frederic Peters <fpeters@0d.be>
Date: 2008-03-28 18:57:10.522000+01:00
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/lang_php5_helpers/wrapper_source.py | 44 | ||||
-rw-r--r-- | bindings/lang_php5_helpers/wrapper_source_top.c | 13 | ||||
-rw-r--r-- | bindings/php5/Makefile.am | 2 | ||||
-rw-r--r-- | bindings/php5/examples/Makefile.am | 1 | ||||
-rw-r--r-- | bindings/php5/tests/Makefile.am | 6 | ||||
-rwxr-xr-x | bindings/php5/tests/binding_tests.php | 1 | ||||
-rwxr-xr-x | bindings/php5/tests/binding_tests.sh | 3 | ||||
-rwxr-xr-x | bindings/php5/tests/profile_tests.php | 11 | ||||
-rwxr-xr-x | bindings/php5/tests/profile_tests.sh | 3 |
9 files changed, 62 insertions, 22 deletions
diff --git a/bindings/lang_php5_helpers/wrapper_source.py b/bindings/lang_php5_helpers/wrapper_source.py index e08c089c..3905d048 100644 --- a/bindings/lang_php5_helpers/wrapper_source.py +++ b/bindings/lang_php5_helpers/wrapper_source.py @@ -165,26 +165,28 @@ PHP_MSHUTDOWN_FUNCTION(lasso) self.functions_list.append(name) print >> self.fd, '''PHP_FUNCTION(%s) {''' % name - parse_tuple_format = '' + parse_tuple_format = [] parse_tuple_args = [] for arg in m.args: arg_type, arg_name, arg_options = arg if arg_type in ('char*', 'const char*', 'gchar*', 'const gchar*'): arg_type = arg_type.replace('const ', '') - parse_tuple_format += 's' + parse_tuple_format.append('s!') parse_tuple_args.append('&%s_str, &%s_len' % (arg_name, arg_name)) print >> self.fd, ' %s %s = NULL;' % ('char*', arg_name) print >> self.fd, ' %s %s_str = NULL;' % ('char*', arg_name) print >> self.fd, ' %s %s_len = 0;' % ('int', arg_name) elif arg_type in ['int', 'gint', 'gboolean', 'const gboolean'] + self.binding_data.enums: - parse_tuple_format += 'l' + parse_tuple_format.append('l') parse_tuple_args.append('&%s' % arg_name) print >> self.fd, ' %s %s;' % ('long', arg_name) elif arg_type == 'GList*': - print >> sys.stderr, 'E: GList argument in', name - print >> self.fd, ' %s %s = NULL;' % (arg_type, arg_name) + parse_tuple_format.append('a!') + parse_tuple_args.append('&zval_%s' % arg_name) + print >> self.fd, ' %s zval_%s = NULL;' % ('zval*', arg_name) + print >> self.fd, ' %s %s = NULL;' % ('GList*', arg_name) else: - parse_tuple_format += 'r' + parse_tuple_format.append('r') parse_tuple_args.append('&zval_%s' % arg_name) print >> self.fd, ' %s %s = NULL;' % (arg_type, arg_name) print >> self.fd, ' %s zval_%s = NULL;' % ('zval*', arg_name) @@ -204,17 +206,26 @@ PHP_MSHUTDOWN_FUNCTION(lasso) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "%s"%s) == FAILURE) { RETURN_FALSE; } -''' % (parse_tuple_format, parse_tuple_args) +''' % (''.join(parse_tuple_format), parse_tuple_args) for f, arg in zip(parse_tuple_format, m.args): - if f == 's': + if f.startswith('s'): print >> self.fd, '''\ - if (%(name)s_str && strcmp(%(name)s_str, "") != 0) { - %(name)s = estrndup(%(name)s_str, %(name)s_len); - } ''' % {'name': arg[1]} - elif f == 'r': + %(name)s = %(name)s_str;''' % {'name': arg[1]} + elif f.startswith('r'): print >> self.fd, ' ZEND_FETCH_RESOURCE(cvt_%s, PhpGObjectPtr *, &zval_%s, -1, PHP_LASSO_SERVER_RES_NAME, le_lasso_server);' % (arg[1], arg[1]) print >> self.fd, ' %s = (%s)cvt_%s->obj;' % (arg[1], arg[0], arg[1]) + elif f.startswith('a'): + elem_type = arg[2].get('elem_type') + if elem_type == 'char*': + print >> self.fd, ' %(name)s = get_list_from_array_of_strings(zval_%(name)s);' % {'name': arg[1]} + else: + print >> sys.stderr, 'E: In %(function)s arg %(name)s is of type GList<%(elem)s>' % { 'function': m.name, 'name': arg[1], 'elem': elem_type } + elif f == 'l': + pass + else: + raise Exception('%s format inconnu' % f) + if m.return_type is not None: print >> self.fd, ' return_c_value = ', @@ -223,6 +234,15 @@ PHP_MSHUTDOWN_FUNCTION(lasso) else: print >> self.fd, ' ', print >> self.fd, '%s(%s);' % (m.name, ', '.join([x[1] for x in m.args])) + # Free the converted arguments + + for f, arg in zip(parse_tuple_format, m.args): + if f.startswith('a'): + elem_type = arg[2].get('elem_type') + if elem_type == 'char*': + print >> self.fd, ' if (%(name)s) {' % { 'name': arg[1] } + print >> self.fd, ' free_list(%(name)s,free);' % { 'name': arg[1] } + print >> self.fd, ' }' self.return_value(m.return_type, {}) diff --git a/bindings/lang_php5_helpers/wrapper_source_top.c b/bindings/lang_php5_helpers/wrapper_source_top.c index 877d4b7d..5a1ca6fd 100644 --- a/bindings/lang_php5_helpers/wrapper_source_top.c +++ b/bindings/lang_php5_helpers/wrapper_source_top.c @@ -8,6 +8,7 @@ #include "php_lasso.h" /* utility functions */ +static void free_glist(GList **list, GFunc free_function); #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 14) /* copy of private struct and g_hash_table_get_keys from GLib internals @@ -96,6 +97,18 @@ PHP_FUNCTION(lasso_get_object_typename) RETURN_STRING(self->typename, 1); } +/* List handling */ +static void +free_glist(GList **list, GFunc free_function) { + g_return_if_fail(list); + if (*list) { + if (free_function) { + g_list_foreach(*list, free_function, NULL); + } + g_list_free(*list); + } + *list = NULL; +} /* Conversion functions */ static char* diff --git a/bindings/php5/Makefile.am b/bindings/php5/Makefile.am index a5682282..7c898803 100644 --- a/bindings/php5/Makefile.am +++ b/bindings/php5/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = tests examples + if PHP5_ENABLED INCLUDES = -I$(top_srcdir) \ -I$(top_builddir) \ diff --git a/bindings/php5/examples/Makefile.am b/bindings/php5/examples/Makefile.am new file mode 100644 index 00000000..731cee07 --- /dev/null +++ b/bindings/php5/examples/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = get_attributes_from_assertion.php diff --git a/bindings/php5/tests/Makefile.am b/bindings/php5/tests/Makefile.am new file mode 100644 index 00000000..72851d43 --- /dev/null +++ b/bindings/php5/tests/Makefile.am @@ -0,0 +1,6 @@ +if PHP5_ENABLED +TESTS = profile_tests.sh binding_tests.sh +endif + +EXTRA_DIST = profile_tests.php binding_tests.php + diff --git a/bindings/php5/tests/binding_tests.php b/bindings/php5/tests/binding_tests.php index d4614154..240be092 100755 --- a/bindings/php5/tests/binding_tests.php +++ b/bindings/php5/tests/binding_tests.php @@ -1,4 +1,3 @@ -#! /usr/bin/env php <?php # Lasso - A free implementation of the Liberty Alliance specifications. # diff --git a/bindings/php5/tests/binding_tests.sh b/bindings/php5/tests/binding_tests.sh new file mode 100755 index 00000000..9f3e9e17 --- /dev/null +++ b/bindings/php5/tests/binding_tests.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +php5 -n -d extension_dir=../.libs binding_tests.php diff --git a/bindings/php5/tests/profile_tests.php b/bindings/php5/tests/profile_tests.php index cb8f4ade..71d525bf 100755 --- a/bindings/php5/tests/profile_tests.php +++ b/bindings/php5/tests/profile_tests.php @@ -1,4 +1,3 @@ -#! /usr/bin/env php <?php # Lasso - A free implementation of the Liberty Alliance specifications. # @@ -112,10 +111,7 @@ function test04() { try { $login->processResponseMsg(""); } - catch (LassoError $error) { - if ($error->getCode() != LASSO_PARAM_ERROR_INVALID_VALUE) { - throw $error; - } + catch (LassoProfileInvalidMsgError $error) { } echo "OK.\n"; @@ -193,10 +189,7 @@ function test06() { echo "logout.initRequest without having set identity before should fail\n"; assert(False); } - catch (LassoError $error) { - if ($error->getCode() != LASSO_PROFILE_ERROR_SESSION_NOT_FOUND) { - throw $error; - } + catch (LassoProfileSessionNotFoundError $error) { } echo "OK.\n"; diff --git a/bindings/php5/tests/profile_tests.sh b/bindings/php5/tests/profile_tests.sh new file mode 100755 index 00000000..446131df --- /dev/null +++ b/bindings/php5/tests/profile_tests.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +php5 -n -d extension_dir=../.libs profile_tests.php |