diff options
author | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:04:48 +0000 |
---|---|---|
committer | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:04:48 +0000 |
commit | 42934cb50ee967a650d6c894180df76c34815dd6 (patch) | |
tree | b484f3ef8cae9b4d4c9d4f9eb0b079b2636482ab | |
parent | bebf0b17639a292af7349c3427bc2dd993b145fb (diff) | |
download | lasso-42934cb50ee967a650d6c894180df76c34815dd6.tar.gz lasso-42934cb50ee967a650d6c894180df76c34815dd6.tar.xz lasso-42934cb50ee967a650d6c894180df76c34815dd6.zip |
[project @ fpeters@0d.be-20071106133809-z6qxlw10eooqrkwp]
merged damien branch
Original author: Frederic Peters <fpeters@0d.be>
Date: 2007-11-06 14:38:09.490000+01:00
-rw-r--r-- | bindings/lang_php5_helpers/php_code.py | 60 | ||||
-rw-r--r-- | bindings/lang_php5_helpers/wrapper_source.py | 79 | ||||
-rw-r--r-- | bindings/lang_php5_helpers/wrapper_source_top.c | 73 | ||||
-rw-r--r-- | bindings/lang_python_wrapper_top.c | 3 | ||||
-rwxr-xr-x | bindings/php5/tests/binding_tests.php | 49 | ||||
-rwxr-xr-x | bindings/php5/tests/profile_tests.php | 27 |
6 files changed, 223 insertions, 68 deletions
diff --git a/bindings/lang_php5_helpers/php_code.py b/bindings/lang_php5_helpers/php_code.py index 2b6fc994..6f572147 100644 --- a/bindings/lang_php5_helpers/php_code.py +++ b/bindings/lang_php5_helpers/php_code.py @@ -20,6 +20,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import re +import sys import utils @@ -169,25 +170,42 @@ function cptrToPhp ($cptr) { options = m[2] # Getters - print >> self.fd, ' protected function get_%s() {' % mname - if self.is_object(m[0]): - print >> self.fd, ' $cptr = %s_%s_get($this->_cptr);' % (klass.name, mname) - print >> self.fd, ' if (! is_null($cptr)) {' - print >> self.fd, ' return cptrToPhp($cptr);' - print >> self.fd, ' }' - print >> self.fd, ' return null;' + for m2 in klass.methods: + # If method is already defined in C, don't define it twice + if '_get_' in m2.name: + class_name = re.match(r'lasso_(.*)_get_\w+', m2.name).group(1) + attr_name = re.match(r'lasso_.*_get_(\w+)', m2.name).group(1) + if class_name and attr_name: + class_name = 'Lasso' + class_name.capitalize() + if class_name == klass.name and attr_name == mname: + print >> sys.stderr, 'W: Bad function name : %s function prevents \ +writing a standard accessor for attribute "%s"' % (m2.name, attr_name) + break else: - print >> self.fd, ' return %s_%s_get($this->_cptr);' % (klass.name, mname) - print >> self.fd, ' }' + print >> self.fd, ' protected function get_%s() {' % mname + if self.is_object(m[0]): + print >> self.fd, ' $cptr = %s_%s_get($this->_cptr);' % (klass.name, mname) + print >> self.fd, ' if (! is_null($cptr)) {' + print >> self.fd, ' return cptrToPhp($cptr);' + print >> self.fd, ' }' + print >> self.fd, ' return null;' + else: + print >> self.fd, ' return %s_%s_get($this->_cptr);' % (klass.name, mname) + print >> self.fd, ' }' # Setters - print >> self.fd, ' protected function set_%s($value) {' % mname - if self.is_object(m[0]): - print >> self.fd, ' %s_%s_set($this->_cptr, $value->_cptr);' % (klass.name, mname) + for m2 in klass.methods: + # If method is already defined in C, don't define it twice + if m2.name == 'set_%s' % mname: + break else: - print >> self.fd, ' %s_%s_set($this->_cptr, $value);' % (klass.name, mname) - print >> self.fd, ' }' - print >> self.fd, '' + print >> self.fd, ' protected function set_%s($value) {' % mname + if self.is_object(m[0]): + print >> self.fd, ' %s_%s_set($this->_cptr, $value->_cptr);' % (klass.name, mname) + else: + print >> self.fd, ' %s_%s_set($this->_cptr, $value);' % (klass.name, mname) + print >> self.fd, ' }' + print >> self.fd, '' def generate_methods(self, klass): @@ -203,7 +221,17 @@ function cptrToPhp ($cptr) { setter = [x for x in methods if x.name == setter_name][0] methods.remove(setter) except IndexError: - pass + setter = None + mname = re.match(r'lasso_.*_get_(\w+)', m.name).group(1) + + print >> self.fd, ' protected function get_%s() {' % mname + print >> self.fd, ' return %s($this->_cptr);' % (m.name) + print >> self.fd, ' }' + if setter: + print >> self.fd, ' protected function set_%s($value) {' % mname + print >> self.fd, ' %s($this->_cptr, $value);' % (setter.name) + print >> self.fd, ' }' + print >> self.fd, '' # second pass on methods, real methods method_prefix = utils.format_as_underscored(klass.name) + '_' diff --git a/bindings/lang_php5_helpers/wrapper_source.py b/bindings/lang_php5_helpers/wrapper_source.py index a7b6f781..02404f33 100644 --- a/bindings/lang_php5_helpers/wrapper_source.py +++ b/bindings/lang_php5_helpers/wrapper_source.py @@ -20,6 +20,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys +import os import utils @@ -31,7 +32,7 @@ class WrapperSource: def is_object(self, t): return t not in ['char*', 'const char*', 'gchar*', 'const gchar*', 'GList*', - 'int', 'gint', 'gboolean', 'const gboolean'] + self.binding_data.enums + 'xmlNode*', 'int', 'gint', 'gboolean', 'const gboolean'] + self.binding_data.enums def generate(self): self.generate_header() @@ -51,61 +52,37 @@ class WrapperSource: print >> self.fd, '''\ /* this file has been generated automatically; do not edit */ - -#include <php.h> -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION -#include <lasso/lasso.h> ''' + + print >> self.fd, open(os.path.join(self.binding_data.src_dir, + 'lang_php5_helpers/wrapper_source_top.c')).read() + for h in self.binding_data.headers: print >> self.fd, '#include <%s>' % h print >> self.fd, '' print >> self.fd, '''\ -#include "php_lasso.h" - -int le_lasso_server; - -ZEND_GET_MODULE(lasso) - -typedef struct { - GObject *obj; - char *typename; -} PhpGObjectPtr; - -PHP_FUNCTION(lasso_get_object_typename) -{ - PhpGObjectPtr *self; - zval *zval_self; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zval_self) == FAILURE) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(self, PhpGObjectPtr *, &zval_self, -1, PHP_LASSO_SERVER_RES_NAME, le_lasso_server); - RETURN_STRING(self->typename, 1); -} - PHP_MINIT_FUNCTION(lasso) { le_lasso_server = zend_register_list_destructors_ex(NULL, NULL, PHP_LASSO_SERVER_RES_NAME, module_number); ''' def generate_constants(self): - constant_types = { - 'i': 'LONG', - 's': 'STRING' - } print >> self.fd, ' /* Constants (both enums and defines) */' for c in self.binding_data.constants: - if c[0] not in constant_types: - print >> sys.stderr, 'W: no support for %s constant type (%s)' % (c[0], c[1]) - continue - print >> self.fd, ' REGISTER_%(type)s_CONSTANT("%(name)s", %(name)s, CONST_CS|CONST_PERSISTENT);' \ - % {'type': constant_types[c[0]], 'name': c[1]} + if c[0] == 'i': + print >> self.fd, ' REGISTER_LONG_CONSTANT("%s", %s, CONST_CS|CONST_PERSISTENT);' % (c[1], c[1]) + elif c[0] == 's': + print >> self.fd, ' REGISTER_STRING_CONSTANT("%s", %s, CONST_CS|CONST_PERSISTENT);' % (c[1], c[1]) + elif c[0] == 'b': + print >> self.fd, '''\ +#ifdef %s + REGISTER_LONG_CONSTANT("%s", 1, CONST_CS|CONST_PERSISTENT); +#else + REGISTER_LONG_CONSTANT("%s", 0, CONST_CS|CONST_PERSISTENT); +#endif''' % (c[1], c[1], c[1]) + else: + print >> sys.stderr, 'E: unknown constant type: %r' % c[0] print >> self.fd, '' def generate_middle(self): @@ -140,6 +117,15 @@ PHP_MSHUTDOWN_FUNCTION(lasso) } else { RETURN_NULL(); }''' + elif vtype == 'xmlNode*': + print >> self.fd, '''\ + char* xmlString = get_string_from_xml_node(return_c_value); + if (xmlString) { + RETURN_STRING(xmlString, 1); + } else { + RETURN_NULL(); + } +''' elif vtype in ('GList*',) and options.get('elem_type') == 'char*': print >> self.fd, '''\ array_init(return_value); @@ -300,7 +286,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso) arg_type = m_type arg_name = m_name arg_options = m_options - if arg_type in ('char*', 'const char*', 'gchar*', 'const gchar*'): + if arg_type in ('char*', 'const char*', 'gchar*', 'const gchar*', 'xmlNode*'): arg_type = arg_type.replace('const ', '') parse_tuple_format += 's' parse_tuple_args.append('&%s_str, &%s_len' % (arg_name, arg_name)) @@ -353,7 +339,10 @@ PHP_MSHUTDOWN_FUNCTION(lasso) print >> self.fd, ' efree(this->%s);' % m_name print >> self.fd, ' }' print >> self.fd, ' if (%s_str && strcmp(%s_str, "") != 0) {' % (m_name, m_name) - print >> self.fd, ' this->%s = estrndup(%s_str, %s_len);' % (m_name, m_name, m_name) + if arg_type == 'xmlNode*': + print >> self.fd, ' this->%s = get_xml_node_from_string(%s_str);' % (m_name, m_name) + else: + print >> self.fd, ' this->%s = estrndup(%s_str, %s_len);' % (m_name, m_name, m_name) print >> self.fd, ' } else {' print >> self.fd, ' this->%s = NULL;' % m_name print >> self.fd, ' }' @@ -376,7 +365,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso) } ''' % { '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, ' 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, '}' diff --git a/bindings/lang_php5_helpers/wrapper_source_top.c b/bindings/lang_php5_helpers/wrapper_source_top.c new file mode 100644 index 00000000..1868a754 --- /dev/null +++ b/bindings/lang_php5_helpers/wrapper_source_top.c @@ -0,0 +1,73 @@ +#include <php.h> +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION +#include <lasso/lasso.h> +#include "php_lasso.h" + +int le_lasso_server; + +ZEND_GET_MODULE(lasso) + +typedef struct { + GObject *obj; + char *typename; +} PhpGObjectPtr; + +PHP_FUNCTION(lasso_get_object_typename) +{ + PhpGObjectPtr *self; + zval *zval_self; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zval_self) == FAILURE) { + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(self, PhpGObjectPtr *, &zval_self, -1, PHP_LASSO_SERVER_RES_NAME, le_lasso_server); + RETURN_STRING(self->typename, 1); +} + +static char* +get_string_from_xml_node(xmlNode *xmlnode) +{ + xmlOutputBufferPtr buf; + char *xmlString; + + if (xmlnode == NULL) { + return NULL; + } + + buf = xmlAllocOutputBuffer(NULL); + if (buf == NULL) { + xmlString = NULL; + } else { + xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL); + xmlOutputBufferFlush(buf); + if (buf->conv == NULL) { + xmlString = estrdup((char*)buf->buffer->content); + } else { + xmlString = estrdup((char*)buf->conv->content); + } + xmlOutputBufferClose(buf); + } + + return xmlString; +} + +static xmlNode* +get_xml_node_from_string(char *string) { + xmlDoc *doc; + xmlNode *node; + + doc = xmlReadDoc((xmlChar*)string, NULL, NULL, XML_PARSE_NONET); + node = xmlDocGetRootElement(doc); + if (node != NULL) { + node = xmlCopyNode(node, 1); + } + xmlFreeDoc(doc); + + return node; +} + diff --git a/bindings/lang_python_wrapper_top.c b/bindings/lang_python_wrapper_top.c index 1e9c682f..885351e5 100644 --- a/bindings/lang_python_wrapper_top.c +++ b/bindings/lang_python_wrapper_top.c @@ -113,7 +113,6 @@ static PyObject* get_pystring_from_xml_node(xmlNode *xmlnode) { xmlOutputBufferPtr buf; - char *xmlString; PyObject *pystring = NULL; if (xmlnode == NULL) { @@ -122,7 +121,7 @@ get_pystring_from_xml_node(xmlNode *xmlnode) buf = xmlAllocOutputBuffer(NULL); if (buf == NULL) { - xmlString = NULL; + pystring = NULL; } else { xmlNodeDumpOutput(buf, NULL, xmlnode, 0, 1, NULL); xmlOutputBufferFlush(buf); diff --git a/bindings/php5/tests/binding_tests.php b/bindings/php5/tests/binding_tests.php new file mode 100755 index 00000000..1a2d999d --- /dev/null +++ b/bindings/php5/tests/binding_tests.php @@ -0,0 +1,49 @@ +#! /usr/bin/env php +<?php +# Lasso - A free implementation of the Liberty Alliance specifications. +# +# Copyright (C) 2004-2007 Entr'ouvert +# http://lasso.entrouvert.org +# +# Authors: See AUTHORS file in top-level directory. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +require("../lasso.php"); + +define("DATA_DIR", "../../../tests/data/"); + +function test01() { + echo "Testing lasso_provider_get_organization binding which must return an xmlNode*... "; + + $organisation_string = '<Organization xmlns="urn:liberty:metadata:2003-08"> + <OrganizationName>Name of the organization</OrganizationName> + </Organization>'; + + $server = new LassoServer( + DATA_DIR . "sp1-la/metadata.xml", + DATA_DIR . "sp1-la/private-key-raw.pem", + NULL, + DATA_DIR . "sp1-la/certificate.pem"); + assert(!is_null($server->organization)); + assert($server->organization == $organisation_string); + + echo "OK.\n"; +} + +lasso_init(); +test01(); +lasso_shutdown(); + diff --git a/bindings/php5/tests/profile_tests.php b/bindings/php5/tests/profile_tests.php index 2aa900cc..04e32848 100755 --- a/bindings/php5/tests/profile_tests.php +++ b/bindings/php5/tests/profile_tests.php @@ -1,10 +1,8 @@ #! /usr/bin/env php <?php -# $Id: binding_tests.php 3238 2007-05-30 17:24:50Z dlaniel $ -# -# PHP unit tests for Lasso library -# -# * Copyright (C) 2004-2007 Entr'ouvert +# Lasso - A free implementation of the Liberty Alliance specifications. +# +# Copyright (C) 2004-2007 Entr'ouvert # http://lasso.entrouvert.org # # Authors: See AUTHORS file in top-level directory. @@ -209,6 +207,25 @@ function test06() { echo "OK.\n"; } +function test07() { + echo "IDP logout without session and identity; testing logout.getNextProviderId... "; + + $server = new LassoServer( + DATA_DIR . "idp1-la/metadata.xml", + DATA_DIR . "idp1-la/private-key-raw.pem", + NULL, + DATA_DIR . "idp1-la/certificate.pem"); + $server->addProvider( + LASSO_PROVIDER_ROLE_IDP, + DATA_DIR . "sp1-la/metadata.xml", + DATA_DIR . "sp1-la/public-key.pem", + DATA_DIR . "sp1-la/certificate.pem"); + + $logout = new LassoLogout($server); + assert(is_null($logout->next_providerID)); + + echo "OK.\n"; +} lasso_init(); test01(); |