summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:04:32 +0000
committerFrederic Peters <fpeters@entrouvert.com>2008-04-29 12:04:32 +0000
commitc8762f405baaac8cbb6475b39d4fbd701a34060a (patch)
treeeb2ab078ae4ccc7af0cb7869e4c78d72bcb7dca9
parentdedaa6e0eebeeb6d46f721e3c1a2022b75267901 (diff)
downloadlasso-c8762f405baaac8cbb6475b39d4fbd701a34060a.tar.gz
lasso-c8762f405baaac8cbb6475b39d4fbd701a34060a.tar.xz
lasso-c8762f405baaac8cbb6475b39d4fbd701a34060a.zip
[project @ fpeters@0d.be-20071102093734-mv4amat73ulcri17]
merged Damien branch Original author: Frederic Peters <fpeters@0d.be> Date: 2007-11-02 10:37:34.842000+01:00
-rw-r--r--bindings/lang_php5_helpers/php_code.py29
-rw-r--r--bindings/lang_php5_helpers/wrapper_source.py88
-rwxr-xr-xbindings/php5/tests/profile_tests.php113
3 files changed, 175 insertions, 55 deletions
diff --git a/bindings/lang_php5_helpers/php_code.py b/bindings/lang_php5_helpers/php_code.py
index a0b7b73f..2b6fc994 100644
--- a/bindings/lang_php5_helpers/php_code.py
+++ b/bindings/lang_php5_helpers/php_code.py
@@ -182,7 +182,10 @@ function cptrToPhp ($cptr) {
# Setters
print >> self.fd, ' protected function set_%s($value) {' % mname
- print >> self.fd, ' %s_%s_set($this->_cptr, $value);' % (klass.name, 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, ''
@@ -262,7 +265,7 @@ function cptrToPhp ($cptr) {
print >> self.fd, ' } else if ($rc > 0) {' # recoverable error
print >> self.fd, ' return $rc;'
print >> self.fd, ' } else if ($rc < 0) {' # unrecoverable error
- print >> self.fd, ' Error::throw_on_rc($rc);'
+ print >> self.fd, ' LassoError::throw_on_rc($rc);'
print >> self.fd, ' }'
else:
print >> self.fd, ' return %s($this->_cptr%s);' % (m.name, c_args)
@@ -279,7 +282,7 @@ function cptrToPhp ($cptr) {
done_cats.append(cat)
parent_cat = exc_cat.attrib.get('parent', '')
print >> self.fd, '''\
-class %sError extends %sError {}
+class Lasso%sError extends Lasso%sError {}
''' % (cat, parent_cat)
exceptions_dict = {}
@@ -301,40 +304,34 @@ class %sError extends %sError {}
parent_cat = ''
print >> self.fd, '''\
-class %sError extends %sError {}
+class Lasso%sError extends Lasso%sError {}
''' % (cat, parent_cat)
if detail not in exceptions_dict:
print >> self.fd, '''\
-class %sError extends %sError {
+class Lasso%sError extends Lasso%sError {
protected $code = %s;
}
''' % (detail, cat, c[1])
exceptions_dict[detail] = c[1]
print >> self.fd, '''\
-class Error extends Exception {
- protected $code = null;
+class LassoError extends Exception {
protected static $exceptions_dict = array('''
for k, v in exceptions_dict.items():
- print >> self.fd, ' %s => "%sError",' % (v, k)
+ print >> self.fd, ' %s => "Lasso%sError",' % (v, k)
print >> self.fd, '''\
);
public static function throw_on_rc($rc) {
$exception = self::$exceptions_dict[$rc];
- if (class_exists($exception)) {
- throw new $exception();
- } else {
- throw new Exception();
+ if (! class_exists($exception)) {
+ $exception = "LassoError";
}
+ throw new $exception(lasso_strerror($rc), $rc);
}
-
-/* public function __toString() {
- return "<" . get_class($this) . "(" . $this->code . "): " . lasso_strerror($this->code) . ">";
- } */
}
'''
diff --git a/bindings/lang_php5_helpers/wrapper_source.py b/bindings/lang_php5_helpers/wrapper_source.py
index bdb373ed..ec31262b 100644
--- a/bindings/lang_php5_helpers/wrapper_source.py
+++ b/bindings/lang_php5_helpers/wrapper_source.py
@@ -137,7 +137,15 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
} else {
RETURN_NULL();
}'''
- elif vtype in ('GList*',):
+ elif vtype in ('GList*',) and options.get('elem_type') == 'char*':
+ print >> self.fd, '''\
+ array_init(return_value);
+ for (item = g_list_first(return_c_value); item != NULL; item = g_list_next(item)) {
+ add_next_index_string(return_value, item->data, 1);
+ }
+
+'''
+ elif vtype in ('GList*',) and options.get('elem_type') != 'char*':
print >> self.fd, ' RETURN_NULL();'
else:
print >> self.fd, '''\
@@ -223,26 +231,30 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
print >> self.fd, '}'
print >> self.fd, ''
+
def generate_getter(self, klassname, m_type, m_name, m_options):
+ if m_type == 'GList*' and m_options.get('elem_type') != 'char*':
+ print >> sys.stderr, 'E: GList argument : %s of %s, with type : %s' % (m_name, klassname, m_options.get('elem_type'))
+ return
+
+ function_name = '%s_%s_get' % (klassname, format_attribute(m_name))
function_name = '%s_%s_get' % (klassname, utils.format_as_camelcase(m_name))
print >> self.fd, '''PHP_FUNCTION(%s)
{''' % function_name
self.functions_list.append(function_name)
- # FIXME: must handle GLists and objects as well
- if m_type == "GList*":
- print >> self.fd, '''\
- RETURN_NULL();
-}
-'''
- return
- print >> self.fd, ' %s return_c_value;' % m_type
+ if self.is_object(m_type):
+ print >> self.fd, ' %s return_c_value = NULL;' % m_type
+ else:
+ print >> self.fd, ' %s return_c_value;' % m_type
print >> self.fd, ' %s* this;' % klassname
print >> self.fd, ' zval* zval_this;'
print >> self.fd, ' PhpGObjectPtr *cvt_this;'
if self.is_object(m_type):
print >> self.fd, ' PhpGObjectPtr *self;'
+ elif m_type == 'GList*' and m_options.get('elem_type') == 'char*':
+ print >> self.fd, ' GList* item = NULL;'
print >> self.fd, ''
print >> self.fd, '''\
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zval_this) == FAILURE) {
@@ -254,31 +266,29 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
''' % (klassname)
if self.is_object(m_type):
- print >> self.fd, ' return_c_value = g_object_ref(this->%s);' % m_name;
+ print >> self.fd, ' if (this->%s != NULL) {' % m_name
+ print >> self.fd, ' return_c_value = g_object_ref(this->%s);' % m_name
+ print >> self.fd, ' }'
else:
- print >> self.fd, ' return_c_value = this->%s;' % m_name;
+ print >> self.fd, ' return_c_value = this->%s;' % m_name
self.return_value(m_type, m_options)
print >> self.fd, '}'
print >> self.fd, ''
+
def generate_setter(self, klassname, m_type, m_name, m_options):
+ if m_type == 'GList*' and m_options.get('elem_type') != 'char*':
+ print >> sys.stderr, 'E: GList argument : %s of %s, with type : %s' % (m_name, klassname, m_options.get('elem_type'))
+ return
+
+ function_name = '%s_%s_set' % (klassname, format_attribute(m_name))
function_name = '%s_%s_set' % (klassname, utils.format_as_camelcase(m_name))
print >> self.fd, '''PHP_FUNCTION(%s)
{''' % function_name
self.functions_list.append(function_name)
- # FIXME: must handle GLists and objects as well
- if m_type not in ['char*', 'const char*', 'gchar*', 'const gchar*'] \
- + ['int', 'gint', 'gboolean', 'const gboolean'] \
- + self.binding_data.enums :
- print >> self.fd, '''\
- RETURN_NULL();
-}
-'''
- return
-
print >> self.fd, ' %s* this;' % klassname
print >> self.fd, ' zval* zval_this;'
print >> self.fd, ' PhpGObjectPtr *cvt_this;'
@@ -288,6 +298,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
parse_tuple_args = []
arg_type = m_type
arg_name = m_name
+ arg_options = m_options
if arg_type in ('char*', 'const char*', 'gchar*', 'const gchar*'):
arg_type = arg_type.replace('const ', '')
parse_tuple_format += 's'
@@ -298,18 +309,27 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
parse_tuple_format += '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 : ', m_name
- print >> self.fd, ' %s %s = NULL;' % (arg_type, arg_name)
+ # Must also handle lists of Objects
+ elif arg_type == 'GList*' and arg_options.get('elem_type') == 'char*':
+ parse_tuple_format += 'a'
+ parse_tuple_args.append('&zval_%s' % arg_name)
+ print >> self.fd, ' %s zval_%s;' % ('zval*', arg_name)
+ print >> self.fd, ' %s %s_data;' % ('zval**', arg_name)
+ print >> self.fd, ' %s %s_hashtable;' % ('HashTable*', arg_name)
+ print >> self.fd, ' %s %s_pointer;' % ('HashPosition', arg_name)
+ print >> self.fd, ' %s %s_size;' % ('int', arg_name)
else:
parse_tuple_format += '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)
print >> self.fd, ' %s cvt_%s = NULL;' % ('PhpGObjectPtr*', arg_name)
if parse_tuple_args:
parse_tuple_arg = parse_tuple_args[0]
+ else:
+ print >> self.fd, '}'
+ print >> self.fd, ''
+ return
print >> self.fd, ''
print >> self.fd, '''\
@@ -336,6 +356,24 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
print >> self.fd, ' } else {'
print >> self.fd, ' this->%s = NULL;' % m_name
print >> self.fd, ' }'
+ elif parse_tuple_format == 'a':
+ if m_options.get('elem_type') == 'char*':
+ print >> self.fd, '''
+ if (this->%(name)s) {
+ /* free existing list */
+ g_list_foreach(this->%(name)s, (GFunc)g_free, NULL);
+ g_list_free(this->%(name)s);
+ }
+ %(name)s_hashtable = Z_ARRVAL_P(zval_%(name)s);
+ %(name)s_size = zend_hash_num_elements(%(name)s_hashtable);
+ for (zend_hash_internal_pointer_reset_ex(%(name)s_hashtable, &%(name)s_pointer);
+ zend_hash_get_current_data_ex(%(name)s_hashtable, (void**) &%(name)s_data, &%(name)s_pointer) == SUCCESS;
+ zend_hash_move_forward_ex(%(name)s_hashtable, &%(name)s_pointer)) {
+ if (Z_TYPE_PP(%(name)s_data) == IS_STRING) {
+ this->%(name)s = g_list_append(this->%(name)s, estrndup(Z_STRVAL_PP(%(name)s_data), Z_STRLEN_PP(%(name)s_data)));
+ }
+ }
+''' % { '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)
diff --git a/bindings/php5/tests/profile_tests.php b/bindings/php5/tests/profile_tests.php
index 3e353781..2aa900cc 100755
--- a/bindings/php5/tests/profile_tests.php
+++ b/bindings/php5/tests/profile_tests.php
@@ -25,16 +25,16 @@
require("../lasso.php");
-define("DATA_DIR", "../../tests/data/");
+define("DATA_DIR", "../../../tests/data/");
function test01() {
echo "Server construction, dump & newFromDump... ";
$server = new LassoServer(
- DATA_DIR . "sp1-la/metadata.xml",
- DATA_DIR . "sp1-la/private-key-raw.pem",
- NULL,
- DATA_DIR . "sp1-la/certificate.pem");
+ DATA_DIR . "sp1-la/metadata.xml",
+ DATA_DIR . "sp1-la/private-key-raw.pem",
+ NULL,
+ DATA_DIR . "sp1-la/certificate.pem");
$server->addProvider(
LASSO_PROVIDER_ROLE_IDP,
DATA_DIR . "idp1-la/metadata.xml",
@@ -73,10 +73,10 @@ function test03() {
echo "SP login; testing access to authentication request... ";
$server = new LassoServer(
- DATA_DIR . "sp1-la/metadata.xml",
- DATA_DIR . "sp1-la/private-key-raw.pem",
- NULL,
- DATA_DIR . "sp1-la/certificate.pem");
+ DATA_DIR . "sp1-la/metadata.xml",
+ DATA_DIR . "sp1-la/private-key-raw.pem",
+ NULL,
+ DATA_DIR . "sp1-la/certificate.pem");
$server->addProvider(
LASSO_PROVIDER_ROLE_IDP,
DATA_DIR . "idp1-la/metadata.xml",
@@ -98,13 +98,40 @@ function test03() {
}
function test04() {
+ echo "SP login; testing processing of an empty Response... ";
+
+ $server = new LassoServer(
+ DATA_DIR . "sp1-la/metadata.xml",
+ DATA_DIR . "sp1-la/private-key-raw.pem",
+ NULL,
+ DATA_DIR . "sp1-la/certificate.pem");
+ $server->addProvider(
+ LASSO_PROVIDER_ROLE_IDP,
+ DATA_DIR . "idp1-la/metadata.xml",
+ DATA_DIR . "idp1-la/public-key.pem",
+ DATA_DIR . "idp1-la/certificate.pem");
+
+ $login = new LassoLogin($server);
+ try {
+ $login->processResponseMsg("");
+ }
+ catch (LassoError $error) {
+ if ($error->getCode() != LASSO_PARAM_ERROR_INVALID_VALUE) {
+ throw $error;
+ }
+ }
+
+ echo "OK.\n";
+}
+
+function test05() {
echo "Conversion of a lib:AuthnRequest with an AuthnContext into a query and back... ";
$spServer = new LassoServer(
- DATA_DIR . "sp1-la/metadata.xml",
- DATA_DIR . "sp1-la/private-key-raw.pem",
- NULL,
- DATA_DIR . "sp1-la/certificate.pem");
+ DATA_DIR . "sp1-la/metadata.xml",
+ DATA_DIR . "sp1-la/private-key-raw.pem",
+ NULL,
+ DATA_DIR . "sp1-la/certificate.pem");
$spServer->addProvider(
LASSO_PROVIDER_ROLE_IDP,
DATA_DIR . "idp1-la/metadata.xml",
@@ -116,22 +143,80 @@ function test04() {
$requestAuthnContext = new LassoLibRequestAuthnContext();
$authnContextClassRefsList = array(LASSO_LIB_AUTHN_CONTEXT_CLASS_REF_PASSWORD);
$requestAuthnContext->authnContextClassRef = $authnContextClassRefsList;
+ assert(! is_null($requestAuthnContext->authnContextClassRef));
+ assert(sizeof($requestAuthnContext->authnContextClassRef) == 1);
$request = $spLogin->request;
$request->requestAuthnContext = $requestAuthnContext;
+ assert(! is_null($request->requestAuthnContext));
$request->protocolProfile = LASSO_LIB_PROTOCOL_PROFILE_BRWS_ART;
$spLogin->buildAuthnRequestMsg();
- var_dump($spLogin->msgUrl);
$authnRequestUrl = $spLogin->msgUrl;
assert(! is_null($spLogin->msgUrl));
assert($spLogin->msgUrl != "");
+ $idpServer = new LassoServer(
+ DATA_DIR . "idp1-la/metadata.xml",
+ DATA_DIR . "idp1-la/private-key-raw.pem",
+ NULL,
+ DATA_DIR . "idp1-la/certificate.pem");
+ $idpServer->addProvider(
+ LASSO_PROVIDER_ROLE_IDP,
+ DATA_DIR . "sp1-la/metadata.xml",
+ DATA_DIR . "sp1-la/public-key.pem",
+ DATA_DIR . "sp1-la/certificate.pem");
+
+ $idpLogin = new LassoLogin($idpServer);
+ list($urlBase, $authnRequestQuery) = split("\?", $spLogin->msgUrl, 2);
+ assert($authnRequestQuery != "");
+ $idpLogin->processAuthnRequestMsg($authnRequestQuery);
+ $request = $idpLogin->request;
+ assert(! is_null($request));
+ assert(! is_null($request->requestAuthnContext));
+ assert($request->requestAuthnContext != "");
+ $requestAuthnContext = $request->requestAuthnContext;
+ assert(sizeof($requestAuthnContext->authnContextClassRef) == 1);
+ assert($requestAuthnContext->authnContextClassRef[0] == LASSO_LIB_AUTHN_CONTEXT_CLASS_REF_PASSWORD);
+
echo "OK.\n";
}
+function test06() {
+ echo "SP logout without session and identity; testing initRequest... ";
+
+ $server = new LassoServer(
+ DATA_DIR . "sp1-la/metadata.xml",
+ DATA_DIR . "sp1-la/private-key-raw.pem",
+ NULL,
+ DATA_DIR . "sp1-la/certificate.pem");
+ $server->addProvider(
+ LASSO_PROVIDER_ROLE_IDP,
+ DATA_DIR . "idp1-la/metadata.xml",
+ DATA_DIR . "idp1-la/public-key.pem",
+ DATA_DIR . "idp1-la/certificate.pem");
+
+ $logout = new LassoLogout($server);
+ try {
+ $logout->initRequest();
+ 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;
+ }
+ }
+
+ echo "OK.\n";
+}
+
+
lasso_init();
test01();
test02();
test03();
test04();
+test05();
+test06();
+test07();
lasso_shutdown();