From 8944a5f52d6d49ad646837e4595132500ddaccfe Mon Sep 17 00:00:00 2001 From: Valery Febvre Date: Mon, 2 Aug 2004 23:59:26 +0000 Subject: [PATCH] - Replaced some charPtrConst_wrap() calls by charPtr_wrap() - Added GPtrArray_wrap() function to wrap GPtrArray into Python list. - Added session_getattr() function, we can get now providerIDs and is_dirty properties of Session objects. --- python/environs/py_identity.c | 2 +- python/environs/py_login.c | 2 +- python/environs/py_logout.c | 2 +- python/environs/py_session.c | 35 +++++++++++++++++++++++--- python/environs/py_session.h | 2 +- python/examples/login.py | 3 +++ python/lasso.py | 27 +++++++++++++++++--- python/lassomod.c | 1 + python/protocols/py_authn_request.c | 4 +-- python/wrap_objs.c | 38 ++++++++++++++++++++++++----- python/wrap_objs.h | 8 +++--- 11 files changed, 103 insertions(+), 21 deletions(-) diff --git a/python/environs/py_identity.c b/python/environs/py_identity.c index 403fa749..a7c466b2 100644 --- a/python/environs/py_identity.c +++ b/python/environs/py_identity.c @@ -74,5 +74,5 @@ PyObject *identity_dump(PyObject *self, PyObject *args) { dump = lasso_identity_dump(LassoIdentity_get(identity_obj)); - return (charPtrConst_wrap(dump)); + return (charPtr_wrap(dump)); } diff --git a/python/environs/py_login.c b/python/environs/py_login.c index 4a41be6d..862e7113 100644 --- a/python/environs/py_login.c +++ b/python/environs/py_login.c @@ -240,7 +240,7 @@ PyObject *login_dump(PyObject *self, PyObject *args) { ret = lasso_login_dump(LassoLogin_get(login_obj)); - return (charPtrConst_wrap(ret)); + return (charPtr_wrap(ret)); } PyObject *login_init_authn_request(PyObject *self, PyObject *args) { diff --git a/python/environs/py_logout.c b/python/environs/py_logout.c index 22681d7c..4038dce5 100644 --- a/python/environs/py_logout.c +++ b/python/environs/py_logout.c @@ -154,7 +154,7 @@ PyObject *logout_get_next_providerID(PyObject *self, PyObject *args) { remote_providerID = lasso_logout_get_next_providerID(LassoLogout_get(logout_obj)); - return (charPtrConst_wrap(remote_providerID)); + return (charPtr_wrap(remote_providerID)); } PyObject *logout_init_request(PyObject *self, PyObject *args) { diff --git a/python/environs/py_session.c b/python/environs/py_session.c index cbe396ae..1a7040db 100644 --- a/python/environs/py_session.c +++ b/python/environs/py_session.c @@ -42,6 +42,35 @@ PyObject *LassoSession_wrap(LassoSession *session) { /******************************************************************************/ +PyObject *session_getattr(PyObject *self, PyObject *args) { + PyObject *session_obj; + LassoSession *session; + const char *attr; + + if (CheckArgs(args, "OS:session_get_attr")) { + if (!PyArg_ParseTuple(args, "Os:session_get_attr", &session_obj, &attr)) + return NULL; + } + else return NULL; + + session = LassoSession_get(session_obj); + + if (!strcmp(attr, "__members__")) { + return Py_BuildValue("[ss]", "providerIDs", "is_dirty"); + } + if (!strcmp(attr, "providerIDs")) { + return (GPtrArray_wrap(session->providerIDs)); + } + if (!strcmp(attr, "is_dirty")) { + return (int_wrap(session->is_dirty)); + } + + Py_INCREF(Py_None); + return (Py_None); +} + +/******************************************************************************/ + PyObject *session_new(PyObject *self, PyObject *args) { return (LassoSession_wrap(lasso_session_new())); } @@ -107,7 +136,7 @@ PyObject *session_dump(PyObject *self, PyObject *args) { dump = lasso_session_dump(LassoSession_get(session_obj)); - return (charPtrConst_wrap(dump)); + return (charPtr_wrap(dump)); } PyObject *session_get_assertion(PyObject *self, PyObject *args) { @@ -143,7 +172,7 @@ PyObject *session_get_authentication_method(PyObject *self, PyObject *args) { authentication_method = lasso_session_get_authentication_method(LassoSession_get(session_obj), remote_providerID); - return (charPtrConst_wrap(authentication_method)); + return (charPtr_wrap(authentication_method)); } PyObject *session_get_next_assertion_remote_providerID(PyObject *self, PyObject *args) { @@ -159,7 +188,7 @@ PyObject *session_get_next_assertion_remote_providerID(PyObject *self, PyObject remote_providerID = lasso_session_get_next_assertion_remote_providerID(LassoSession_get(session_obj)); - return (charPtrConst_wrap(remote_providerID)); + return (charPtr_wrap(remote_providerID)); } PyObject *session_remove_assertion(PyObject *self, PyObject *args) { diff --git a/python/environs/py_session.h b/python/environs/py_session.h index 182dc869..d383840a 100644 --- a/python/environs/py_session.h +++ b/python/environs/py_session.h @@ -36,9 +36,9 @@ typedef struct { #define LassoSession_get(v) (((v) == Py_None) ? NULL : (((LassoSession_object *)(PyObject_GetAttr(v, PyString_FromString("_o"))))->obj)) PyObject *LassoSession_wrap(LassoSession *session); +PyObject *session_getattr(PyObject *self, PyObject *args); PyObject *session_new(PyObject *self, PyObject *args); PyObject *session_new_from_dump(PyObject *self, PyObject *args); - PyObject *session_add_assertion(PyObject *self, PyObject *args); PyObject *session_destroy(PyObject *self, PyObject *args); PyObject *session_dump(PyObject *self, PyObject *args); diff --git a/python/examples/login.py b/python/examples/login.py index b379ab02..e2354b4f 100644 --- a/python/examples/login.py +++ b/python/examples/login.py @@ -26,6 +26,7 @@ splogin.request.set_isPassive(0) splogin.request.set_forceAuthn(1) splogin.request.set_nameIDPolicy(lasso.libNameIDPolicyTypeFederated) splogin.request.set_relayState("fake") +splogin.request.set_consent(lasso.libConsentObtained) splogin.request.set_protocolProfile(lasso.libProtocolProfileBrwsArt) splogin.build_authn_request_msg() @@ -60,6 +61,8 @@ if idplogin.protocolProfile == lasso.loginProtocolProfileBrwsArt: "", lasso.httpMethodRedirect) print "ret = %d, msg_url = %s" % (ret, idplogin.msg_url) + sess = idplogin.get_session() + print sess.providerIDs #################### # Service provider # diff --git a/python/lasso.py b/python/lasso.py index 4d317feb..940dcbb8 100644 --- a/python/lasso.py +++ b/python/lasso.py @@ -835,6 +835,19 @@ class Session: """ self._o = _obj + def __isprivate(self, name): + return name == '_o' + + def __getattr__(self, name): + if self.__isprivate(name): + return self.__dict__[name] + if name[:2] == "__" and name[-2:] == "__" and name != "__members__": + raise AttributeError, name + ret = lassomod.session_getattr(self, name) + if ret is None: + raise AttributeError, name + return ret + def new(cls): obj = lassmod.session_new() return Session(obj) @@ -894,11 +907,19 @@ class Profile: new = classmethod(new) def get_identity(self): - return Identity(_obj=lassomod.profile_get_identity(self)) + obj = lassomod.profile_get_identity(self) + if obj != None: + return Identity(_obj=obj) + else: + return None def get_session(self): - return Session(_obj=lassomod.profile_get_session(self)) - + obj = lassomod.profile_get_session(self) + if obj != None: + return Session(_obj=obj) + else: + return None + def is_identity_dirty(self): return lassomod.profile_is_identity_dirty(self) diff --git a/python/lassomod.c b/python/lassomod.c index 370fa0b6..b80bd580 100644 --- a/python/lassomod.c +++ b/python/lassomod.c @@ -282,6 +282,7 @@ static PyMethodDef lasso_methods[] = { {"server_dump", server_dump, METH_VARARGS}, /* py_session.h */ + {"session_getattr", session_getattr, METH_VARARGS}, {"session_new", session_new, METH_VARARGS}, {"session_new_from_dump", session_new_from_dump, METH_VARARGS}, {"session_add_assertion", session_add_assertion, METH_VARARGS}, diff --git a/python/protocols/py_authn_request.c b/python/protocols/py_authn_request.c index 71a188fa..579f7973 100644 --- a/python/protocols/py_authn_request.c +++ b/python/protocols/py_authn_request.c @@ -66,10 +66,10 @@ PyObject *authn_request_set_requestAuthnContext(PyObject *self, PyObject *args) return NULL; if (authnContextClassRefs_obj != Py_None) { - authnContextClassRefs = PythonStringList2_get(authnContextClassRefs_obj); + authnContextClassRefs = GPtrArray_get(authnContextClassRefs_obj); } if (authnContextStatementRefs_obj != Py_None) { - authnContextStatementRefs = PythonStringList2_get(authnContextStatementRefs_obj); + authnContextStatementRefs = GPtrArray_get(authnContextStatementRefs_obj); } lasso_authn_request_set_requestAuthnContext(LassoAuthnRequest_get(request_obj), diff --git a/python/wrap_objs.c b/python/wrap_objs.c index 74d136b1..6ca35ee8 100644 --- a/python/wrap_objs.c +++ b/python/wrap_objs.c @@ -4,7 +4,7 @@ /* Functions to wrap Python objects -> C objects */ /*****************************************************************************/ -xmlChar **PythonStringList_get(PyObject *list_obj) { +xmlChar** PythonStringList_get(PyObject *list_obj) { int i; xmlChar **list = NULL; @@ -19,7 +19,7 @@ xmlChar **PythonStringList_get(PyObject *list_obj) { return list; } -GPtrArray *PythonStringList2_get(PyObject *list_obj) { +GPtrArray* GPtrArray_get(PyObject *list_obj) { int i; GPtrArray *list = NULL; @@ -27,8 +27,9 @@ GPtrArray *PythonStringList2_get(PyObject *list_obj) { /* convert Python list into a GLib GPtrArray */ list = g_ptr_array_new(); - for (i=0; i Python objects */ +/*****************************************************************************/ + +PyObject* GPtrArray_wrap(GPtrArray *array) { + PyObject *list; + int i; + + list = PyList_New(array->len); + for (i=0; ilen; i++) { + /* PyList_SetItem(list, i, */ + /* PyString_FromString((char *) g_ptr_array_index(array, i))); */ + PyList_SET_ITEM(list, i, + PyString_FromString((char *) g_ptr_array_index(array, i))); + } + + /* free array */ + /* for (i=0; ilen; i++) { */ + /* xmlFree(array->pdata[i]); */ + /* } */ + /* g_ptr_array_free(array, TRUE); */ + + return (list); +} + /*****************************************************************************/ /* Functions to wrap LibXML objects -> Python objects */ /*****************************************************************************/ -PyObject *xmlCharPtr_wrap(xmlChar *str) { +PyObject* xmlCharPtr_wrap(xmlChar *str) { PyObject *ret; if (str == NULL) { @@ -79,11 +105,11 @@ PyObject *xmlCharPtr_wrap(xmlChar *str) { } ret = PyString_FromString((char *) str); /* deallocation */ - /* xmlFree(str); */ + xmlFree(str); return (ret); } -PyObject *wrap_xmlCharPtrConst(const xmlChar *str) { +PyObject *xmlCharPtrConst_wrap(const xmlChar *str) { PyObject *ret; if (str == NULL) { diff --git a/python/wrap_objs.h b/python/wrap_objs.h index 3e779ab1..7b2e5e62 100644 --- a/python/wrap_objs.h +++ b/python/wrap_objs.h @@ -49,15 +49,17 @@ typedef struct { /* Functions to wrap Python objects -> C objects */ #define PythonFile_get(v) (((v) == Py_None) ? NULL : (PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout)) -xmlChar **PythonStringList_get(PyObject *list_obj); -GPtrArray *PythonStringList2_get(PyObject *list_obj); +xmlChar** PythonStringList_get(PyObject *list_obj); +GPtrArray* GPtrArray_get(PyObject *list_obj); PyObject *int_wrap(int val); PyObject *charPtr_wrap(char *str); PyObject *charPtrConst_wrap(const char *str); +PyObject* GPtrArray_wrap(GPtrArray *array); + PyObject *xmlCharPtr_wrap(xmlChar *str); -PyObject *wrap_xmlCharPtrConst(const xmlChar *str); +PyObject *xmlCharPtrConst_wrap(const xmlChar *str); PyObject *wrap_xmlDocPtr(xmlDocPtr doc); PyObject *wrap_xmlNodePtr(xmlNodePtr node); PyObject *wrap_xmlNodeSetPtr(xmlNodeSetPtr nset);