diff options
Diffstat (limited to 'python')
-rwxr-xr-x | python/examples/test.py | 28 | ||||
-rwxr-xr-x | python/generator_lasso_strings.py | 84 | ||||
-rw-r--r-- | python/lasso.py | 98 | ||||
-rw-r--r-- | python/lasso_strings.py | 81 | ||||
-rw-r--r-- | python/lassomod.c | 10 | ||||
-rw-r--r-- | python/lassomod.h | 24 | ||||
-rw-r--r-- | python/protocols/py_single_sign_on_and_federation.c | 111 | ||||
-rw-r--r-- | python/protocols/py_single_sign_on_and_federation.h | 41 | ||||
-rw-r--r-- | python/py_lasso.h | 29 | ||||
-rwxr-xr-x | python/setup.py | 15 | ||||
-rw-r--r-- | python/utils.c | 16 | ||||
-rw-r--r-- | python/utils.h | 8 | ||||
-rw-r--r-- | python/wrap_objs.h | 2 | ||||
-rw-r--r-- | python/xml/py_xml.c | 77 | ||||
-rw-r--r-- | python/xml/py_xml.h | 41 |
15 files changed, 646 insertions, 19 deletions
diff --git a/python/examples/test.py b/python/examples/test.py new file mode 100755 index 00000000..b636b38a --- /dev/null +++ b/python/examples/test.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python + +import sys +sys.path.insert(0, '../') +import lasso + +print lasso.init() + +req = lasso.AuthnRequest("providerid.com", + "federated", + "false", + "true", + "", # None + "3", + None, + None, + "", # None + "", # None + 0, + None, + "obtained") + +req.request.dump("iso-8859-1", 1) + +#req.dump("iso-8859-1", 1) +#req.destroy() + +#print lasso.shutdown() diff --git a/python/generator_lasso_strings.py b/python/generator_lasso_strings.py new file mode 100755 index 00000000..e00afdfd --- /dev/null +++ b/python/generator_lasso_strings.py @@ -0,0 +1,84 @@ +#! /usr/bin/env python +# +# $Id$ +# +# PyLasso - Python bindings for Lasso library +# Automatic generation of lasso_strings.py with lasso/xml/strings.c +# +# Copyright (C) 2004 Entr'ouvert +# http://lasso.labs.libre-entreprise.org +# +# Author: Valery Febvre <vfebvre@easter-eggs.com> +# +# 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 + +import re, sys + +MATCH_BLANK = re.compile(r'^\s*\n$') +MATCH_COMMENT = re.compile(r'^[ /]+(?P<text>.*)\n$') +MATCH_CONST = re.compile(r'^const\s+gchar\s+(?P<name>\w+)\[\]\s*=\s+(?P<value>.*)\n$') + +header = """# $%s$ +# +# PyLasso - Python bindings for Lasso library +# +# Copyright (C) 2004 Entr'ouvert +# http://lasso.labs.libre-entreprise.org +# +# Author: Valery Febvre <vfebvre@easter-eggs.com> +# +# 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 +# +""" % "Id" + +file_in = sys.argv[1] +file_out = "./lasso_strings.py" + +fd_in = open(file_in, "r") +fd_out = open(file_out, "w+") +fd_out.write(header) + +line = fd_in.readline() +while line: + match = MATCH_CONST.search(line) + if match: + fd_out.write("%s = %s\n" % (match.group('name')[5:], + match.group('value')[:-1])) + else: + match = MATCH_COMMENT.search(line) + if match: + fd_out.write("# %s\n" % match.group('text')) + else: + match = MATCH_BLANK.search(line) + if match: + fd_out.write("\n") + else: + print "Unknown format, this line is ignored: %s" % line + line = fd_in.readline() + +fd_in.close() +fd_out.close() diff --git a/python/lasso.py b/python/lasso.py new file mode 100644 index 00000000..b90f8e73 --- /dev/null +++ b/python/lasso.py @@ -0,0 +1,98 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# +# $Id$ +# +# PyLasso - Python bindings for Lasso Library +# +# Copyright (C) 2003-2004 Easter-eggs, Valery Febvre +# http://lasso.labs.libre-entreprise.org +# +# Author: Valery Febvre <vfebvre@easter-eggs.com> +# +# 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 + +__docformat__ = "plaintext en" + +import lassomod +from lasso_strings import * + +class Error(Exception): + def __init__(self, msg): + self.msg = msg + def __str__(self): + return repr(self.msg) + +def init(): + """ + """ + return lassomod.init() + +def shutdown(): + """ + """ + return lassomod.shutdown() + +class AuthnRequest: + def __init__(self, providerID, nameIDPolicy, forceAuthn, isPassive, + protocolProfile, assertionConsumerServiceID, authnContextClassRefs, + authnContextStatementRefs, authnContextComparison, relayState, + proxyCount, idpList, consent, _obj=None): + """ + """ + if _obj != None: + self._o = _obj + return + self._o = lassomod.authn_request_build(providerID, + nameIDPolicy, + forceAuthn, + isPassive, + protocolProfile, + assertionConsumerServiceID, + authnContextClassRefs, + authnContextStatementRefs, + authnContextComparison, + relayState, + proxyCount, + idpList, + consent) + if self._o is None: raise Error('lasso_authn_request_build() failed') + 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.authn_request_getattr(self, name) + if ret is None: + raise AttributeError, name + if name == "request": + ret = Node(_obj=ret) + return ret + +class Node: + def __init__(self, _obj=None): + """ + """ + if _obj != None: + self._o = _obj + return + #self._o = lassomod.(size) + if self._o is None: raise Error('lasso_node_new() failed') + def dump(self, encoding, format): + lassomod.node_dump(self, encoding, format) + def destroy(self): + lassomod.node_unref(self) diff --git a/python/lasso_strings.py b/python/lasso_strings.py new file mode 100644 index 00000000..2ac7e1be --- /dev/null +++ b/python/lasso_strings.py @@ -0,0 +1,81 @@ +# $Id$ +# +# PyLasso - Python bindings for Lasso library +# +# Copyright (C) 2004 Entr'ouvert +# http://lasso.labs.libre-entreprise.org +# +# Author: Valery Febvre <vfebvre@easter-eggs.com> +# +# 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 +# +# * $Id$ +# * +# * Lasso - A free implementation of the Liberty Alliance specifications. +# * +# * Copyright (C) 2004 Entr'ouvert +# * http://lasso.entrouvert.org +# * +# * Author: Valery Febvre <vfebvre@easter-eggs.com> +# * +# * 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 +# */ + + +# *****************************************************************************/ +# * Liberty Alliance */ +# *****************************************************************************/ + +# * Versioning */ +LibMajorVersion = "1" +LibMinorVersion = "2" + +# * NameIDPolicyType */ +LibNameIDPolicyTypeNone = "none" +LibNameIDPolicyTypeOneTime = "onetime" +LibNameIDPolicyTypeFederated = "federated" +LibNameIDPolicyTypeAny = "any" + +# * AuthnContextComparison */ +LibAuthnContextComparisonExact = "exact" +LibAuthnContextComparisonMinimum = "minimum" +LibAuthnContextComparisonBetter = "better" + +# * StatusCodes */ +LibStatusCodeFederationDoesNotExist = "lib:FederationDoesNotExist" +LibStatusCodeNoPassive = "lib:NoPassive" +LibStatusCodeRequestDenied = "lib:RequestDenied" +LibStatusCodeSuccess = "lib:Success" + +# *****************************************************************************/ +# * SAML */ +# *****************************************************************************/ + +# * Versioning */ +SamlMajorVersion = "1" +SamlMinorVersion = "0" + diff --git a/python/lassomod.c b/python/lassomod.c index 75ef2087..1f5a2b8c 100644 --- a/python/lassomod.c +++ b/python/lassomod.c @@ -25,6 +25,8 @@ #include "lassomod.h" #include "py_lasso.h" +#include "xml/py_xml.h" +#include "protocols/py_single_sign_on_and_federation.h" static PyMethodDef lasso_methods[] = { /* py_lasso.h */ @@ -34,6 +36,14 @@ static PyMethodDef lasso_methods[] = { {"check_version", check_version, METH_VARARGS}, {"check_version_ext", check_version_ext, METH_VARARGS}, + /* py_xml.h */ + {"node_dump", node_dump, METH_VARARGS}, + {"node_unref", node_unref, METH_VARARGS}, + + /* py_single_sign_on_and_federation.h */ + {"authn_request_getattr", authn_request_getattr, METH_VARARGS}, + {"authn_request_build", authn_request_build, METH_VARARGS}, + {NULL, NULL} /* End of Methods Sentinel */ }; diff --git a/python/lassomod.h b/python/lassomod.h index 21972734..391d7aa5 100644 --- a/python/lassomod.h +++ b/python/lassomod.h @@ -1,3 +1,27 @@ +/* $Id$ + * + * PyLasso -- Python bindings for Lasso library + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.labs.libre-entreprise.org + * + * Author: Valery Febvre <vfebvre@easter-eggs.com> + * + * 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 + */ + #ifndef __PYLASSO_LASSOMOD_H__ #define __PYLASSO_LASSOMOD_H__ diff --git a/python/protocols/py_single_sign_on_and_federation.c b/python/protocols/py_single_sign_on_and_federation.c new file mode 100644 index 00000000..d44e6ac0 --- /dev/null +++ b/python/protocols/py_single_sign_on_and_federation.c @@ -0,0 +1,111 @@ +/* $Id$ + * + * PyLasso -- Python bindings for Lasso library + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.labs.libre-entreprise.org + * + * Author: Valery Febvre <vfebvre@easter-eggs.com> + * + * 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 + */ + +#include "../lassomod.h" + +#include "py_single_sign_on_and_federation.h" + +PyObject *wrap_LassoAuthnRequest(LassoAuthnRequest *request) { + PyObject *ret; + + if (request == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + ret = PyCObject_FromVoidPtrAndDesc((void *) request, + (char *) "LassoAuthnRequest *", NULL); + return (ret); +} + +/******************************************************************************/ +/* LassoAuthnRequest */ +/******************************************************************************/ + +PyObject *authn_request_getattr(PyObject *self, PyObject *args) { + PyObject *lareq_obj; + LassoAuthnRequest *lareq; + const char *attr; + + if (CheckArgs(args, "OS:authn_request_get_attr")) { + if (!PyArg_ParseTuple(args, "Os:authn_request_get_attr", &lareq_obj, &attr)) + return NULL; + } + else return NULL; + + lareq = LassoAuthnRequest_get(lareq_obj); + + if (!strcmp(attr, "__members__")) + return Py_BuildValue("[s]", "request"); + if (!strcmp(attr, "request")) + return (wrap_LassoNode(lareq->request)); + + Py_INCREF(Py_None); + return (Py_None); +} + +/******************************************************************************/ + +PyObject *authn_request_build(PyObject *self, PyObject *args) { + PyObject *authnContextClassRefs_obj, *authnContextStatementRefs_obj; + PyObject *idpList_obj; + const xmlChar *providerID; + const xmlChar *nameIDPolicy; + const xmlChar *forceAuthn; + const xmlChar *isPassive; + const xmlChar *protocolProfile; + const xmlChar *assertionConsumerServiceID; + GPtrArray *authnContextClassRefs = NULL; + GPtrArray *authnContextStatementRefs = NULL; + const xmlChar *authnContextComparison; + const xmlChar *relayState; + gint proxyCount; + GPtrArray *idpList = NULL; + const xmlChar *consent; + + LassoAuthnRequest *request; + + if(!PyArg_ParseTuple(args, (char *) "ssssssOOssiOs:build_authn_request", + &providerID, &nameIDPolicy, &forceAuthn, &isPassive, + &protocolProfile, &assertionConsumerServiceID, + &authnContextClassRefs, &authnContextStatementRefs, + &authnContextComparison, &relayState, &proxyCount, + &idpList, &consent)) + return NULL; + + request = lasso_authn_request_build(providerID, + nameIDPolicy, + forceAuthn, + isPassive, + protocolProfile, + assertionConsumerServiceID, + NULL, + NULL, + authnContextComparison, + relayState, + proxyCount, + NULL, + consent); + + return (wrap_LassoAuthnRequest(request)); +} diff --git a/python/protocols/py_single_sign_on_and_federation.h b/python/protocols/py_single_sign_on_and_federation.h new file mode 100644 index 00000000..d8acb324 --- /dev/null +++ b/python/protocols/py_single_sign_on_and_federation.h @@ -0,0 +1,41 @@ +/* $Id$ + * + * PyLasso -- Python bindings for Lasso library + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.labs.libre-entreprise.org + * + * Author: Valery Febvre <vfebvre@easter-eggs.com> + * + * 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 + */ + +#ifndef __PYLASSO_PY_SINGLE_SIGN_ON_AND_FEDERATION_H__ +#define __PYLASSO_PY_SINGLE_SIGN_ON_AND_FEDERATION_H__ + +#include <lasso/protocols/single_sign_on_and_federation.h> + +typedef struct { + PyObject_HEAD + LassoAuthnRequest *obj; +} LassoAuthnRequest_object; + +#define LassoAuthnRequest_get(v) (((v) == Py_None) ? NULL : (((LassoAuthnRequest_object *)(PyObject_GetAttr(v, PyString_FromString("_o"))))->obj)) +PyObject *LassoAuthnRequest_wrap(LassoAuthnRequest *request); + +PyObject *authn_request_getattr(PyObject *self, PyObject *args); +PyObject *authn_request_build(PyObject *self, PyObject *args); + +#endif /* __PYLASSO_PY_SINGLE_SIGN_ON_AND_FEDERATION_H__ */ diff --git a/python/py_lasso.h b/python/py_lasso.h index 5fea5d70..772db156 100644 --- a/python/py_lasso.h +++ b/python/py_lasso.h @@ -1,5 +1,34 @@ +/* $Id$ + * + * PyLasso -- Python bindings for Lasso library + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.labs.libre-entreprise.org + * + * Author: Valery Febvre <vfebvre@easter-eggs.com> + * + * 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 + */ + +#ifndef __PYLASSO_PY_LASSO_H__ +#define __PYLASSO_PY_LASSO_H__ + PyObject *init(PyObject *self, PyObject *args); PyObject *shutdown(PyObject *self, PyObject *args); PyObject *check_version_exact(PyObject *self, PyObject *args); PyObject *check_version(PyObject *self, PyObject *args); PyObject *check_version_ext(PyObject *self, PyObject *args); + +#endif /* __PYLASSO_PY_LASSO_H__ */ diff --git a/python/setup.py b/python/setup.py index 9611ca99..ba8a2d35 100755 --- a/python/setup.py +++ b/python/setup.py @@ -163,12 +163,12 @@ if xmlsec1_libs[:2] not in ["-l", "-L"]: if xmlsec1_libs[:2] not in ["-l", "-L"]: print "Error : cannot get XMLSec1 linker flags" -print gobject_cflags -print gobject_libs -print libxml2_cflags -print libxml2_libs -print xmlsec1_cflags -print xmlsec1_libs +#print gobject_cflags +#print gobject_libs +#print libxml2_cflags +#print libxml2_libs +#print xmlsec1_cflags +#print xmlsec1_libs extract_cflags(gobject_cflags) extract_libs(gobject_libs) @@ -185,7 +185,8 @@ library_dirs.append('../lasso/.libs') libraries.append('lasso') em = Extension("lassomod", - sources = ["py_lasso.c", + sources = ["py_lasso.c", "xml/py_xml.c", + "protocols/py_single_sign_on_and_federation.c", "lassomod.c", "utils.c", "wrap_objs.c"], define_macros = define_macros, diff --git a/python/utils.c b/python/utils.c index 3ea4d171..763c41e1 100644 --- a/python/utils.c +++ b/python/utils.c @@ -1,9 +1,9 @@ /* $Id$ * - * PyXMLSec - Python bindings for XML Security library (XMLSec) + * PyLasso - Python bindings for Lasso library * - * Copyright (C) 2003-2004 Easter-eggs, Valery Febvre - * http://pyxmlsec.labs.libre-entreprise.org + * Copyright (C) 2004 Entr'ouvert + * http://lasso.labs.libre-entreprise.org * * Author: Valery Febvre <vfebvre@easter-eggs.com> * @@ -44,7 +44,7 @@ int CheckArgs(PyObject *args, char *format) { if (format[i] == 'O' || format[i] == 'o') { if (!PyInstance_Check(obj)) { if (format[i] == 'o' && obj == Py_None) continue; - PyErr_Format(xmlsec_error, + PyErr_Format(lasso_error, "%s() argument %d must be an instance.", format + nb_args, i+1); return 0; @@ -54,7 +54,7 @@ int CheckArgs(PyObject *args, char *format) { else if (format[i] == 'C' || format[i] == 'c') { if (!PyCallable_Check(obj)) { if (format[i] == 'c' && obj == Py_None) continue; - PyErr_Format(xmlsec_error, + PyErr_Format(lasso_error, "%s() argument %d must be callable.", format + nb_args, i+1); return 0; @@ -64,7 +64,7 @@ int CheckArgs(PyObject *args, char *format) { else if (format[i] == 'S' || format[i] == 's') { if (!PyString_Check(obj)) { if (format[i] == 's' && obj == Py_None) continue; - PyErr_Format(xmlsec_error, + PyErr_Format(lasso_error, "%s() argument %d must be a string.", format + nb_args, i+1); return 0; @@ -74,7 +74,7 @@ int CheckArgs(PyObject *args, char *format) { else if (format[i] == 'I' || format[i] == 'i') { if (!PyInt_Check(obj)) { if (format[i] == 'i' && obj == Py_None) continue; - PyErr_Format(xmlsec_error, + PyErr_Format(lasso_error, "%s() argument %d must be an integer.", format + nb_args, i+1); return 0; @@ -84,7 +84,7 @@ int CheckArgs(PyObject *args, char *format) { else if (format[i] == 'F' || format[i] == 'f') { if (!PyFile_Check(obj)) { if (format[i] == 'f' && obj == Py_None) continue; - PyErr_Format(xmlsec_error, + PyErr_Format(lasso_error, "%s() argument %d must be a file.", format + nb_args, i+1); return 0; diff --git a/python/utils.h b/python/utils.h index 49df83ce..9f5be831 100644 --- a/python/utils.h +++ b/python/utils.h @@ -1,11 +1,11 @@ -#ifndef __PYXMLSEC_UTILS_H__ -#define __PYXMLSEC_UTILS_H__ +#ifndef __PYLASSO_UTILS_H__ +#define __PYLASSO_UTILS_H__ #undef _POSIX_C_SOURCE #include <Python.h> -extern PyObject *xmlsec_error; +extern PyObject *lasso_error; int CheckArgs(PyObject *args, char *format); -#endif /* __PYXMLSEC_UTILS_H__ */ +#endif /* __PYLASSO_UTILS_H__ */ diff --git a/python/wrap_objs.h b/python/wrap_objs.h index c0889a10..2812bb71 100644 --- a/python/wrap_objs.h +++ b/python/wrap_objs.h @@ -9,6 +9,8 @@ #include <xmlsec/xmlsec.h> +#include <lasso/protocols/protocols.h> + typedef struct { PyObject_HEAD xmlDocPtr obj; diff --git a/python/xml/py_xml.c b/python/xml/py_xml.c new file mode 100644 index 00000000..c9e1cc72 --- /dev/null +++ b/python/xml/py_xml.c @@ -0,0 +1,77 @@ +/* $Id$ + * + * PyLasso -- Python bindings for Lasso library + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.labs.libre-entreprise.org + * + * Author: Valery Febvre <vfebvre@easter-eggs.com> + * + * 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 + */ + +#include "../lassomod.h" + +#include "py_xml.h" + +PyObject *wrap_LassoNode(LassoNode *node) { + PyObject *ret; + + if (node == NULL) { + Py_INCREF(Py_None); + return (Py_None); + } + ret = PyCObject_FromVoidPtrAndDesc((void *) node, + (char *) "LassoNode *", NULL); + return (ret); +} + +/******************************************************************************/ +/* LassoNode */ +/******************************************************************************/ + +PyObject *node_dump(PyObject *self, PyObject *args) { + PyObject *node_obj; + xmlChar *encoding; + int format; + + if (CheckArgs(args, "OSI:node_dump")) { + if(!PyArg_ParseTuple(args, (char *) "Osi:node_dump", + &node_obj, &encoding, &format)) + return NULL; + } + else return NULL; + + lasso_node_dump(LassoNode_get(node_obj), encoding, format); + + Py_INCREF(Py_None); + return (Py_None); +} + +PyObject *node_unref(PyObject *self, PyObject *args) { + PyObject *node_obj; + + if (CheckArgs(args, "O:node_unref")) { + if(!PyArg_ParseTuple(args, (char *) "O:node_unref", &node_obj)) + return NULL; + } + else return NULL; + + /* FIXME: should used a fct lasso_node_unref() ??? */ + g_object_unref (G_OBJECT (LassoNode_get(node_obj))); + + Py_INCREF(Py_None); + return (Py_None); +} diff --git a/python/xml/py_xml.h b/python/xml/py_xml.h new file mode 100644 index 00000000..b72dbe55 --- /dev/null +++ b/python/xml/py_xml.h @@ -0,0 +1,41 @@ +/* $Id$ + * + * PyLasso -- Python bindings for Lasso library + * + * Copyright (C) 2004 Entr'ouvert + * http://lasso.labs.libre-entreprise.org + * + * Author: Valery Febvre <vfebvre@easter-eggs.com> + * + * 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 + */ + +#ifndef __PYLASSO_PY_XML_H__ +#define __PYLASSO_PY_XML_H__ + +#include "../../lasso/xml/xml.h" + +typedef struct { + PyObject_HEAD + LassoNode *obj; +} LassoNode_object; + +#define LassoNode_get(v) (((v) == Py_None) ? NULL : (((LassoNode_object *)(PyObject_GetAttr(v, PyString_FromString("_o"))))->obj)) +PyObject *LassoNode_wrap(LassoNode *node); + +PyObject *node_dump(PyObject *self, PyObject *args); +PyObject *node_unref(PyObject *self, PyObject *args); + +#endif /* __PYLASSO_PY_XML_H__ */ |