Kaydet (Commit) 36e5b94c authored tarafından Suleyman Poyraz's avatar Suleyman Poyraz

Added full support python3-api for iksemel. Should be write tests

üst 796cdd8a
......@@ -50,9 +50,6 @@ config.h.in
.libs/
#Iks test files
test/tst-*
#Iks compiled files
doc/iksemel
include/config.h
......@@ -60,6 +57,15 @@ include/stamp-h1
tools/ikslint
tools/iksperf
tools/iksroster
test/tst-dom
test/tst-filter
test/tst-iks
test/tst-ikstack
test/tst-jid
test/tst-sha
test/tst-md5
test/tst-sax
#Makefile files
Makefile
......
......@@ -2,7 +2,7 @@
Author
======
Gurer Ozen <madcat@e-kolay.net>
Gurer Ozen <meduketto at gmail.com>
Contributions
......
This diff is collapsed.
2011-10-18 Gurer
* python/: Python bindings and test scripts
2011-10-10 Gurer
* iks.c: iks_string() returns nul terminated strings for cdata nodes
2011-10-07 Gurer
* sax.c: Fix handling of ending ]] sequences in CDATA sections
bug report and patch by oscarvdbosch
* tst-sax.c: Test coverage for fixed bug
2011-10-06 Gurer
* configure.ac: without-openssl and without-gnutls options added
2011-10-06 Gurer
* configure.ac: Check openssl, it is preferred over gnutls
* tls-openssl.c: TLS backend for the openssl library
2011-10-05 Gurer
* md5.c: Fix padding for multiples of 64 bytes
* tst-md5.c: Test coverage for fixed bug
2009-08-30 Gurer
* configure.ac: use pkgconfig for checking gnutls
* INSTALL: updated by the autoreconf call
* README: gnutls dependency is mentioned
2009-08-07 Gurer
* tls-gnutls.c: support timeout value in tls_recv
2009-08-06 Gurer
* iksemel.h: new ikstls structure and definitions
* tls-gnutls.c: new file, GNUTLS implemantation moved here
* stream.c: TLS code is abstracted with new TLS interface
2009-07-25 Gurer
* version bump to 1.5 after the release
2009-07-22 Gurer
* io-posix.c: send/recv now handles EAGAIN/EINTR.
2009-07-21 Gurer
* tst-md5.c: MD5 test improved with examples from RFC1321
* iksroster.c: Plain text auth option patch from issue tracker.
2009-07-20 Gurer
* tst-sax.c: Fix a va_arg bug with 64bit platforms.
2009-07-18 Gurer
* sax.c: Fix attribute array out-of-bounds condition.
* iksperf.c: Fix a warning, and use size_t instead of int.
2009-07-04 Gurer
* md5.c: use iks_malloc/free like everywhere else.
(reported by Vinay Deshpande)
* stream.c: don't leak locally processed challenge node.
2009-04-02 Gurer
* sax.c: utf8 validation bug is fixed. Some valid utf8
sequences were not allowed before. Security check is moved
after sequence end point, so position of IKS_BADXML errors
are changed.
* tst-sax.c: test case for validation bug added.
2009-03-31 Gurer
* Patch by Timothy Lee:
sax.c: Whitespace between "attr, =, value" is valid now.
tst-sax.c: I also added a simple test for that.
2007-08-10 Gurer
* version bump to 1.4 after the release
......
......@@ -8,8 +8,8 @@ before sending patches to the iksemel, since it is implicitly assumed that
your patches are also submitted under the LGPL license.
Roadmap:
========
General Idea:
=============
Main goal of the iksemel is removing complexity from programs using the
library and the library itself. This is the reason why only a subset of XML
......@@ -18,33 +18,6 @@ implemented when we found ways to implement them without adding
too much complexity to the iksemel code. Somewhat external standarts
(XPath, XQuery, XSLT, vs) will probably not make it into the iksemel.
* validation
I think easiest way to add this feature is writing another parser based on the
sax parser which parses a dtd (either from sax parser's markup callback which
needs to be implemented or from an external source via iks_vsax_set_dtd() call)
and checks the arguments of sax callbacks. Using it via dom or stream parsers
can require some clever tricks. there are also xml schemas. they are easy to parse
(it is xml anyway) but can be hard to apply.
* utf16
There are two sides of this. Improving parser to accept utf16 can be relatively
easy. But on the client side things can get confusing. What will be the default
character set used by iks_new(), iks_insert_cdata() and similar functions? and
how they will allow other charsets to be used. Supporting more than utf8 and
utf16 is more difficult. Hopefully there is no immediate need for this. Jabber
uses only utf8 and you can use iconv if you are using another charset in your
application. Btw, there is also byte order issue which is silly. Inventor of BOM
crap must be killed.
* jabber roster
Roster handling generally depends on the UI system used. But I think a generic
roster handler which parses roster result, pushes, presence changes and
allows application to access and display this data can be useful. Challenge
here is making it UI independent and extensible by the application.
File Layout:
============
......
This diff is collapsed.
......@@ -2,7 +2,11 @@
## Process this file with automake to produce Makefile.in
##
SUBDIRS = include src tools test doc
if DO_PYTHON
python_d = python
endif
SUBDIRS = include src tools $(python_d) test doc
EXTRA_DIST = HACKING iksemel.pc.in
......
V1.4 (2018-02-18)
* Lookuping the codes and start new developing
* Added iks_set_cdata function
* Write a pyiks.c module for using iksemel in python
V1.5 (upcoming release)
* You can now use OpenSSL or GNUTLS as the TLS back-end (compile time option).
* Python bindings. You can use iksemel from Python as an XMPP client library
or as a very fast and memory efficient XML parser.
V1.4 (2009-07-25)
* Some previously rejected valid UTF8 sequences are now accepted.
* Whitespace is allowed between attribute name, equal sign and value.
* Small fixes all around (see ChangeLog).
V1.3 (2007-08-02)
* Project is moved to
......
iksemel 1.4
Copyright (c) 2000-2007 Gurer Ozen <madcat@e-kolay.net>
Copyright (c) 2000-2007 Gurer Ozen
Copyright (c) 2016-2018 Suleyman Poyraz (Zaryob)
Introduction:
-------------
......
This file contains a simple list of TODO items.
More general ideas can be found in the roadmap part of the file HACKING.
(in order of importance)
==> 1.5 release, abi/api compatible, will be released in a few months
* parser: &#1234; and &#xA25F; like entities must be unescaped.
==> 1.6 release abi/api compatible, early 2010
* rewrite sax parser for better performance and correctness
* xml pretty printer
* file stream based xml printer
==> 2.0 release, major abi/api changes
* offer a high level jabber api for managing connection details
* input/output modules for encodings (utf8/16), compression (zlib,bzip2),
and source (file, memory, network stream).
==> ideas
* packet filter or a generic xml filter? something like a simplified xpath?
* a separate utf8 validator function can be useful
* utf8 <-> utf16 conversion functions can be useful
* add python and ruby module files
* add programming support into cpp
anything else? :-)
File mode changed from 100644 to 100755
......@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_INIT
AC_PREREQ(2.50)
AC_CONFIG_SRCDIR([configure.ac])
AM_INIT_AUTOMAKE(iksemel,1.4)
AM_INIT_AUTOMAKE(iksemel,1.5)
AM_CONFIG_HEADER(include/config.h)
AC_CANONICAL_HOST
......@@ -13,6 +13,7 @@ AC_PROG_INSTALL
AC_CHECK_TOOL(OBJDUMP, objdump, :)
AM_PROG_LIBTOOL
AC_LANG_C
PKG_PROG_PKG_CONFIG
dnl Checks for header files
AC_HEADER_STDC
......@@ -33,10 +34,10 @@ esac
dnl Check for posix io
AC_ARG_ENABLE(default-io,
[ --disable-default-io disable builtin socket transport code ],
defio=$enableval, defio=yes)
AS_HELP_STRING([--disable-default-io],[disable builtin socket transport code]),
defio=$enableval, defio=yes)
if test "$defio" = yes; then
AC_DEFINE(USE_DEFAULT_IO,1,[Define this is you want default transport])
AC_DEFINE(USE_DEFAULT_IO,1,[Define this is you want default transport])
fi
AM_CONDITIONAL(DO_POSIX, test "x$defio" = "xyes")
......@@ -45,8 +46,6 @@ AC_SEARCH_LIBS(recv,socket)
AC_CHECK_FUNCS(getopt_long)
AC_CHECK_FUNCS(getaddrinfo)
dnl AM_PATH_LIBGNUTLS(,AC_DEFINE(HAVE_GNUTLS,,"Use libgnutls"))
dnl Check -Wall flag of GCC
if test "x$GCC" = "xyes"; then
if test -z "`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
......@@ -54,6 +53,84 @@ if test "x$GCC" = "xyes"; then
fi
fi
dnl Options for overriding TLS checks
AC_ARG_WITH([openssl],
AS_HELP_STRING([--without-openssl],[disable checking for openssl]),
[with_openssl=$enableval],
[with_openssl=yes]
)
AC_ARG_WITH([gnutls],
AS_HELP_STRING([--without-gnutls],[disable checking for GNU TLS]),
[with_gnutls=$enableval],
[with_gnutls=yes]
)
dnl Check OpenSSL
if test "x$with_openssl" = "xyes"; then
PKG_CHECK_MODULES([OPENSSL], openssl >= 0.9.8, have_openssl=yes, have_openssl=no)
if test "x$have_openssl" = "xyes"; then
LIBOPENSSL_CFLAGS="$OPENSSL_CFLAGS"
LIBOPENSSL_LIBS="$OPENSSL_LIBS"
AC_SUBST(LIBOPENSSL_CFLAGS)
AC_SUBST(LIBOPENSSL_LIBS)
AC_DEFINE(HAVE_OPENSSL, 1, [whether to use OpenSSL support.])
fi
fi
dnl Check GNU TLS
if test "x$with_gnutls" = "xyes"; then
if test "x$have_openssl" != "xyes"; then
PKG_CHECK_MODULES([GNUTLS], gnutls >= 2.0.0, have_gnutls=yes, have_gnutls=no)
if test "x$have_gnutls" = "xyes"; then
LIBGNUTLS_CFLAGS="$GNUTLS_CFLAGS"
LIBGNUTLS_LIBS="$GNUTLS_LIBS"
AC_SUBST(LIBGNUTLS_CFLAGS)
AC_SUBST(LIBGNUTLS_LIBS)
AC_DEFINE(HAVE_GNUTLS, 1, [whether to use GnuTSL support.])
fi
fi
fi
dnl Option for overriding Python check
AC_ARG_ENABLE([python],
AS_HELP_STRING([--disable-python],[disable checking for Python bindings]),
[with_python=$enableval],
[with_python=yes]
)
dnl a macro to check for ability to create python extensions
dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
dnl function also defines PYTHON_INCLUDES
AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
[AC_REQUIRE([AM_PATH_PYTHON])
AC_MSG_CHECKING(for headers required to compile python extensions)
dnl deduce PYTHON_INCLUDES
py_prefix=`$PYTHON -c "import sys; print(sys.prefix)"`
py_exec_prefix=`$PYTHON -c "import sys; print(sys.exec_prefix)"`
PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
if test "$py_prefix" != "$py_exec_prefix"; then
PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
fi
AC_SUBST(PYTHON_INCLUDES)
dnl check if the headers exist:
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
AC_TRY_CPP([#include <Python.h>],dnl
[AC_MSG_RESULT(found)
$1],dnl
[AC_MSG_RESULT(not found)
$2])
CPPFLAGS="$save_CPPFLAGS"
])
dnl Check Python for binding
if test "x$with_python" = "xyes"; then
with_python=no
AM_PATH_PYTHON([3.2], , [:])
AM_CHECK_PYTHON_HEADERS(with_python=yes,[AC_MSG_ERROR(could not find Python headers)])
fi
AM_CONDITIONAL([DO_PYTHON], [test "x$with_python" = "xyes"])
dnl Generating makefiles
AC_CONFIG_FILES([
Makefile
......@@ -61,6 +138,7 @@ iksemel.pc
src/Makefile
include/Makefile
tools/Makefile
python/Makefile
test/Makefile
doc/Makefile
])
......
##
## Process this file with automake to produce Makefile.in
##
INCLUDES = -I$(top_srcdir)/include $(PYTHON_INCLUDES)
pyexec_LTLIBRARIES = iksemel.la
iksemel_la_LIBADD = $(top_builddir)/src/libiksemel.la
iksemel_la_SOURCES = pyiksemel.c stream.c jid.c document.c node.c exceptions.c
iksemel_la_CFLAGS = $(CFLAGS) -fno-strict-aliasing -Wunused-variable -Wunused-function -Wincompatible-pointer-types
iksemel_la_LDFLAGS = -avoid-version -module -export-symbols-regex initiksemel
#include "exceptions.h"
#include "document.h"
#include "node.h"
/* Document */
static PyTypeObject Document_type = {
PyVarObject_HEAD_INIT(NULL,0)
"iksemel.Node", /* tp_name */
sizeof(Document), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)Document_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"XML doc object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0 /* tp_new */
};
/* Iterator */
static PyTypeObject Iter_type = {
PyVarObject_HEAD_INIT(NULL,0)
"iksemel.Iter", /* tp_name */
sizeof(Iter), /* tp_basicsize */
0, /* tp_itemsize */
0, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"XML iter object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
(getiterfunc)Iter_iter, /* tp_iter */
(iternextfunc)Iter_next,/* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0 /* tp_new */
};
static void
Document_dealloc(Document *self)
{
if (self->document) iks_delete(self->document);
PyTypeObject* ob_type(PyObject *self);
}
static PyObject *
Iter_iter(Iter *self)
{
Py_INCREF(self);
return (PyObject *)self;
}
static PyObject *
Iter_next(Iter *self)
{
iks *node;
node = self->node;
if (!node) return NULL;
if (self->tags) {
self->node = iks_next_tag(node);
if (self->node && self->tagname) {
while (self->node && (strcmp(self->tagname, iks_name(self->node)) != 0)) {
self->node = iks_next_tag(self->node);
}
}
} else {
self->node = iks_next(node);
}
return new_node(self->doc, node);
}
static PyObject *
new_node(Document *doc, iks *xml)
{
Node *node;
int ref = 1;
if (!xml) return PyErr_NoMemory();
if (!doc) {
doc = PyObject_New(Document, &Document_type);
doc->document = xml;
ref = 0;
}
node = PyObject_New(Node, &Node_type);
node->doc = doc;
if (ref) {
Py_INCREF(doc);
}
node->node = xml;
return (PyObject *)node;
}
static PyObject *
Document_parse(PyObject *self, PyObject *args)
{
char *file;
iks *doc;
int e;
if (!PyArg_ParseTuple(args, "s", &file))
return NULL;
e = iks_load(file, &doc);
switch (e) {
case IKS_OK:
break;
case IKS_NOMEM:
return PyErr_NoMemory();
case IKS_BADXML:
exceptions_parse();
default:
return PyErr_SetFromErrnoWithFilename(PyExc_OSError, file);
}
return new_node(NULL, doc);
}
static PyObject *
Document_parseString(PyObject *self, PyObject *args)
{
iks *doc;
char *str;
int e;
if (!PyArg_ParseTuple(args, "s", &str))
return NULL;
doc = iks_tree(str, 0, &e);
if (!doc) {
if (e == IKS_NOMEM) {
return PyErr_NoMemory();
} else {
exceptions_parse();
return NULL;
}
}
return new_node(NULL, doc);
}
static PyObject *
Document_newDocument(PyObject *self, PyObject *args)
{
iks *doc;
char *name;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
doc = iks_new(name);
return new_node(NULL, doc);
}
void
Setup_Document(PyObject *module)
{
Document_type.tp_new = PyType_GenericNew;
if (PyType_Ready(&Document_type) < 0) return;
Py_INCREF(&Document_type);
Iter_type.tp_new = PyType_GenericNew;
if (PyType_Ready(&Iter_type) < 0) return;
Py_INCREF(&Iter_type);
}
#ifndef DOCUMENT_H
#define DOCUMENT_H 1
#include <Python.h>
#include "iksemel.h"
/*** Document ***/
typedef struct {
PyObject_HEAD
iks *document;
} Document;
static PyTypeObject Document_type;
static void Document_dealloc(Document *self);
static PyObject *Document_parse(PyObject *self, PyObject *args);
static PyObject *Document_parseString(PyObject *self, PyObject *args);
static PyObject *Document_newDocument(PyObject *self, PyObject *args);
/*** Iterator ***/
typedef struct {
PyObject_HEAD
Document *doc;
iks *node;
int tags;
char *tagname;
} Iter;
static PyTypeObject Iter_type;
static PyObject *Iter_iter(Iter *self);
static PyObject *Iter_next(Iter *self);
static PyObject *new_node(Document *doc, iks *xml);
/*** Setup ***/
void Setup_Document(PyObject *module);
#endif /* DOCUMENT_H */
/* iksemel (XML parser for Jabber)
** Copyright (C) 2011 Gurer Ozen
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
#include "exceptions.h"
void
Setup_Exception(PyObject *module)
{
ParseError = PyErr_NewException("iksemel.ParseError", NULL, NULL);
Py_INCREF(ParseError);
PyModule_AddObject(module, "ParseError", ParseError);
NotTag = PyErr_NewException("iksemel.NotTag", NULL, NULL);
Py_INCREF(NotTag);
PyModule_AddObject(module, "NotTag", NotTag);
NotData = PyErr_NewException("iksemel.NotData", NULL, NULL);
Py_INCREF(NotData);
PyModule_AddObject(module, "NotData", NotData);
NotStream = PyErr_NewException("iksemel.NotStream", NULL, NULL);
Py_INCREF(NotStream);
PyModule_AddObject(module, "NotStream", NotStream);
}
// FIXME: provide err, lineno, etc
PyObject *
exceptions_parse(void)
{
PyErr_SetNone(ParseError);
return NULL;
}
// FIXME: more info on error type
PyObject *
exceptions_object_notdata(int e)
{
PyErr_SetNone(NotData);
return NULL;
}
PyObject *
exceptions_object_nottag(int e)
{
PyErr_SetNone(NotTag);
return NULL;
}
PyObject *
exceptions_stream(int e)
{
PyErr_SetNone(NotStream);
return NULL;
}
/* iksemel (XML parser for Jabber)
** Copyright (C) 2011 Gurer Ozen
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H 1
#include <Python.h>
/*** Objects ***/
static PyObject *ParseError;
static PyObject *NotTag;
static PyObject *NotData;
static PyObject *NotStream;
/*** Exceptions ***/
PyObject *exceptions_parse(void);
PyObject *exceptions_stream(int e);
PyObject *exceptions_object(int e);
/*** Setup ***/
void Setup_Exception(PyObject *module);
#endif /* EXCEPTIONS_H */
/* iksemel (XML parser for Jabber)
** Copyright (C) 2011 Gurer Ozen
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
#include "jid.h"
#include <structmember.h>
// NOTE: This class uses custom implementation of JID parsing
// instead of the iks_id_new from jabber.c
//
static PyMemberDef JID_members[] = {
{ "local", T_OBJECT_EX, offsetof(JID, local), 0, "localpart" },
{ "domain", T_OBJECT_EX, offsetof(JID, domain), 0, "domainpart" },
{ "resource", T_OBJECT_EX, offsetof(JID, resource), 0, "resourcepart" },
{ NULL }
};
static PyTypeObject JID_type = {
PyVarObject_HEAD_INIT(NULL, 0)
"iksemel.JID", /* tp_name */
sizeof(JID), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)JID_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
<