Kaydet (Commit) f424f65e authored tarafından meduketto's avatar meduketto

current iksemel code imported as is.


git-svn-id: https://iksemel.googlecode.com/svn/trunk@2 6ddeccfd-2234-0410-8ab0-45b763562eda
üst e90ccd29
Author
======
Gurer Ozen <madcat@e-kolay.net>
Contributions
=============
Bernhard R. Link (code)
Fabien Ninoles (code)
Evan Prodromou (jabberx improvements, project maintenance)
David Yitzchak Cohen (countless bug reports)
Benoit Laniel (mingw port)
Darrell Karbott (ikstransport)
Rafal Piotrowski (SASL auth)
This diff is collapsed.
This diff is collapsed.
License:
========
iksemel is developed and released under GNU Lesser General Public License.
A copy of the license can be found in the file COPYING. You should read it
before sending patches to the iksemel, since it is implicitly assumed that
your patches are also submitted under the LGPL license.
Roadmap:
========
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
is supported. Some things like UTF16, entity definitons, DTDs will be eventually
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:
============
doc/
* iksemel.texi Documentation in texinfo format.
include/
* common.h Internal header for some common definitions.
* iksemel.h Library API
* finetune.h Default memory allocation sizes.
src/
* ikstack.c Memory management functions.
* utility.c Small string utility functions.
* iks.c XML tree management.
* sax.c SAX parser.
* dom.c DOM parser.
* stream.c Stream parser.
* sha.c SHA1 hash functions.
* jabber.c Jabber utilities.
* filter.c Packet filter for Jabber.
test/
(self test programs)
tools/
(varius utility programs)
Basic Installation
==================
These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, a file
`config.cache' that saves the results of its tests to speed up
reconfiguring, and a file `config.log' containing compiler output
(useful mainly for debugging `configure').
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If at some point `config.cache'
contains results you don't want to keep, you may remove or edit it.
The file `configure.in' is used to create `configure' by a program
called `autoconf'. You only need `configure.in' if you want to change
it or regenerate `configure' using a newer version of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system. If you're
using `csh' on an old version of System V, you might need to type
`sh ./configure' instead to prevent `csh' from trying to execute
`configure' itself.
Running `configure' takes awhile. While running, it prints some
messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. You can give `configure'
initial values for variables by setting them in the environment. Using
a Bourne-compatible shell, you can do that on the command line like
this:
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
Or on systems that have the `env' program, you can do it like this:
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not supports the `VPATH'
variable, you have to compile the package for one architecture at a time
in the source code directory. After you have installed the package for
one architecture, use `make distclean' before reconfiguring for another
architecture.
Installation Names
==================
By default, `make install' will install the package's files in
`/usr/local/bin', `/usr/local/man', etc. You can specify an
installation prefix other than `/usr/local' by giving `configure' the
option `--prefix=PATH'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', the package will use
PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=PATH' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' can not figure out
automatically, but needs to determine by the type of host the package
will run on. Usually `configure' can figure that out, but if it prints
a message saying it can not guess the host type, give it the
`--host=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name with three fields:
CPU-COMPANY-SYSTEM
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the host type.
If you are building compiler tools for cross-compiling, you can also
use the `--target=TYPE' option to select the type of system they will
produce code for and the `--build=TYPE' option to select the type of
system on which you are compiling the package.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Operation Controls
==================
`configure' recognizes the following options to control how it
operates.
`--cache-file=FILE'
Use and save the results of the tests in FILE instead of
`./config.cache'. Set FILE to `/dev/null' to disable caching, for
debugging `configure'.
`--help'
Print a summary of the options to `configure', and exit.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--version'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`configure' also accepts some other, not widely useful, options.
##
## Process this file with automake to produce Makefile.in
##
SUBDIRS = include src tools test doc
EXTRA_DIST = HACKING iksemel.pc.in
pkgconfigdir=$(libdir)/pkgconfig
pkgconfig_DATA = iksemel.pc
snapshot:
$(MAKE) dist distdir=$(PACKAGE)-`date +"%y%m%d"`
mv $(PACKAGE)-`date +"%y%m%d"`.tar.gz ../
ikslite:
cp include/iksemel.h ../
cat include/finetune.h src/utility.c src/ikstack.c src/sax.c src/iks.c src/dom.c >../iksemel.c
V1.3 (2007-08-02)
* Project is moved to
http://code.google.com/p/iksemel/
there is also a new mailing list at:
http://groups.google.com/group/iksemel
Please use those instead of old jabberstudio.org addresses.
* iksemel is now participating in Coverity Inc's free software
quality improvement program (http://scan.coverity.com). As a
first result, a few problems found by Coverity's static analysis
tool in the iks_sasl_challenge() are fixed in this release, and
other than that, iksemel passes from defect test with no problems.
* Extra padding problem in the base64 encoder is fixed. Some servers
were having problems with extra '=' padded SASL digests.
* New dom functions: iks_append(), iks_prepend(), iks_append_cdata(),
iks_prepend_cdata(). You can append/prepend new nodes within the
siblings with them, insert_ functions were only appending at the
last child. Thus editing a tree is much easier now.
* iks_load was giving error on files with multiply of 4Kb sizes, fixed.
V1.2 (2004-08-06)
* SASL authentication.
* SSH connections via gnutls library.
* Socket code abstracted, you can even provide your own transport functions.
* Compiles on Windows with MinGW.
* iks_sha_print() uses lowercase hex numbers to comply with latest jabber.
* New stack implementation, much faster and uses less memory.
Unfortunately API has changed a bit:
iks_stack_strcat, strcatv, print functions removed.
iks_stack_stats modified.
iks_stack_strecat renamed to iks_stack_strcat.
iks_stack_new takes two chunk sizes, one for structures one for strings.
iks_stack_strdup returns (char *).
V1.1 (2003-09-11)
* Minor sax parser speed up.
* iks_string() and dom parser performance is improved greatly.
* iksperf: new tool for measuring iksemel performance.
* ikslint: better error checking. supports stdin. can display tag usage histogram.
* New dom functions: iks_copy(), iks_copy_within(), iks_root(), iks_tree().
* License of the documentation changed to GPL from GNU FDL.
V1.0 (2003-06-29)
* API redesigned.
* iconv interface removed.
* ikslint and iksroster tools.
* Jabber packet filter.
* IPv6 support.
* iks_find_with_attrib, iks_next_tag, iks_prev_tag, iks_first_tag functions.
* Parser improvements (CDATA sections, comments, UTF8 validity checks)
* Memory pools are replaced with object stacks.
V0.1 (2002-10-30)
* First release.
iksemel 1.4
Copyright (c) 2000-2007 Gurer Ozen <madcat@e-kolay.net>
Introduction:
-------------
This is an XML parser library mainly designed for Jabber applications.
It provides SAX, DOM, and special Jabber stream APIs. Library is coded
in ANSI C except the network code (which is POSIX compatible), thus
highly portable. Iksemel is released under GNU Lesser General Public
License. A copy of the license is included in the COPYING file.
Requirements:
-------------
Libtool, Automake and Autoconf packages are required for compiling cvs
versions.
Compiling & Install:
--------------------
If you got the source from CVS, type
./autogen.sh
for creating configuration script and files.
Then type
./configure
make
now library is compiled. You can test it with
make check
and install it with
(become root if necessary)
make install
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)
* parser: &#1234; and &#xA25F; like entities must be unescaped.
* 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
anything else? :-)
#!/bin/sh
# Run this to generate the configure script.
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "Error: You must have 'autoconf' installed on your system in order"
echo " to generate a configure script."
echo
exit 1
}
(autoheader --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "Error: You must have 'autoheader' installed on your system in"
echo " order to generate a configure script."
echo " (Note that 'autoheader' is part of the 'autoconf' package)"
echo
exit 1
}
(libtool --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "Error: You must have 'libtool' installed on your system in order"
echo " to generate a configure script."
echo
exit 1
}
(automake --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "Error: You must have 'automake' installed on your system in order"
echo " to generate a configure script."
echo
exit 1
}
(aclocal --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "Error: You must have 'aclocal' installed on your system in order"
echo " to generate a configure script."
echo " (Note that 'aclocal' is part of the 'automake' package)"
echo
exit 1
}
srcdir=`dirname $0`
echo "Running libtoolize..."
libtoolize --copy --force --automake
echo "Running aclocal..."
aclocal
echo "Running autoheader..."
autoheader
echo "Running automake..."
automake --add-missing --gnu --include-deps
echo "Running autoconf..."
autoconf
echo
echo "Done!"
echo "Now run $srcdir/configure in order to create Makefiles."
echo
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_CONFIG_HEADER(include/config.h)
AC_CANONICAL_HOST
dnl Checks for programs
AC_PROG_CC
AC_PROG_INSTALL
AC_CHECK_TOOL(OBJDUMP, objdump, :)
AM_PROG_LIBTOOL
AC_LANG_C
dnl Checks for header files
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h strings.h errno.h)
dnl Checks for typedefs and structures
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_CHECK_MEMBERS([struct stat.st_blksize])
dnl Special check for windows
case "$host_os" in
*mingw*)
AC_CHECK_LIB(wsock32, main, , AC_MSG_ERROR(Winsock is needed for a Win32 build.))
;;
esac
dnl Check for posix io
AC_ARG_ENABLE(default-io,
[ --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])
fi
AM_CONDITIONAL(DO_POSIX, test "x$defio" = "xyes")
dnl Checks for library functions
AC_SEARCH_LIBS(recv,socket)
AC_CHECK_FUNCS(getopt_long)
AC_CHECK_FUNCS(getaddrinfo)
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
CFLAGS="$CFLAGS -Wall"
fi
fi
dnl Generating makefiles
AC_CONFIG_FILES([
Makefile
iksemel.pc
src/Makefile
include/Makefile
tools/Makefile
test/Makefile
doc/Makefile
])
AC_OUTPUT
##
## Process this file with automake to produce Makefile.in
##
info_TEXINFOS = iksemel.texi
This diff is collapsed.
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: iksemel
Description: XML parser library for Jabber
Version: @VERSION@
Libs: -L${libdir} -liksemel
Cflags: -I${includedir}
##
## Process this file with automake to produce Makefile.in
##
include_HEADERS = iksemel.h
noinst_HEADERS = common.h finetune.h
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <stdio.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#elif HAVE_STRINGS_H
#include <strings.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifndef errno
extern int errno;
#endif
#include "finetune.h"
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
/* minimum sax buffer size */
#define SAX_BUFFER_MIN_SIZE 128
/* sax parser structure plus extra data of dom parser */
#define DEFAULT_DOM_CHUNK_SIZE 256
/* sax parser structure plus extra data of stream parser */
#define DEFAULT_STREAM_CHUNK_SIZE 256
/* iks structure, its data, child iks structures, for stream parsing */
#define DEFAULT_IKS_CHUNK_SIZE 1024
/* iks structure, its data, child iks structures, for file parsing */
#define DEFAULT_DOM_IKS_CHUNK_SIZE 2048
/* rule structure and from/to/id/ns strings */
#define DEFAULT_RULE_CHUNK_SIZE 128
/* file is read by blocks with this size */
#define FILE_IO_BUF_SIZE 4096
/* network receive buffer */
#define NET_IO_BUF_SIZE 4096
This diff is collapsed.
##
## Process this file with automake to produce Makefile.in
##
INCLUDES = -I$(top_srcdir)/include
lib_LTLIBRARIES = libiksemel.la
if DO_POSIX
posix_c = io-posix.c
endif
libiksemel_la_SOURCES = \
ikstack.c \
utility.c \
iks.c \
sax.c \
dom.c \
$(posix_c) \
stream.c \
sha.c \
jabber.c \
filter.c \
md5.c \
base64.c
libiksemel_la_LDFLAGS = -version-info 4:0:1 -no-undefined
libiksemel_la_CFLAGS = $(CFLAGS) $(LIBGNUTLS_CFLAGS)
libiksemel_la_LIBADD = $(LIBGNUTLS_LIBS)
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
#include "common.h"
#include "iksemel.h"
static const char base64_charset[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char *iks_base64_decode(const char *buf)
{
char *res, *save;
char val;
const char *foo;
const char *end;
int index;
size_t len;
if (!buf)
return NULL;
len = iks_strlen(buf) * 6 / 8 + 1;
save = res = iks_malloc(len);
if (!save)
return NULL;
memset(res, 0, len);
index = 0;
end = buf + iks_strlen(buf);
while (*buf && buf < end) {
if (!(foo = strchr(base64_charset, *buf)))
foo = base64_charset;
val = (int)(foo - base64_charset);
buf++;
switch (index) {
case 0:
*res |= val << 2;
break;
case 1:
*res++ |= val >> 4;
*res |= val << 4;
break;
case 2:
*res++ |= val >> 2;
*res |= val << 6;
break;
case 3:
*res++ |= val;
break;
}
index++;
index %= 4;
}
*res = 0;
return save;
}
char *iks_base64_encode(const char *buf, int len)
{
char *res, *save;
int k, t;
len = (len > 0) ? (len) : (iks_strlen(buf));
save = res = iks_malloc((len*8) / 6 + 4);
if (!save) return NULL;
for (k = 0; k < len/3; ++k) {
*res++ = base64_charset[*buf >> 2];
t = ((*buf & 0x03) << 4);
buf++;
*res++ = base64_charset[t | (*buf >> 4)];
t = ((*buf & 0x0F) << 2);
buf++;
*res++ = base64_charset[t | (*buf >> 6)];
*res++ = base64_charset[*buf++ & 0x3F];
}
switch (len % 3) {
case 2:
*res++ = base64_charset[*buf >> 2];
t = ((*buf & 0x03) << 4);
buf++;
*res++ = base64_charset[t | (*buf >> 4)];
*res++ = base64_charset[((*buf++ & 0x0F) << 2)];
*res++ = '=';
break;
case 1:
*res++ = base64_charset[*buf >> 2];
*res++ = base64_charset[(*buf++ & 0x03) << 4];
*res++ = '=';
*res++ = '=';
break;
}
*res = 0;
return save;
}
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
#include "common.h"
#include "iksemel.h"
struct dom_data {
iks **iksptr;
iks *current;
size_t chunk_size;
};
static int
tagHook (struct dom_data *data, char *name, char **atts, int type)
{
iks *x;
if (IKS_OPEN == type || IKS_SINGLE == type) {
if (data->current) {
x = iks_insert (data->current, name);
} else {
ikstack *s;
s = iks_stack_new (data->chunk_size, data->chunk_size);
x = iks_new_within (name, s);
}
if (atts) {
int i=0;
while (atts[i]) {
iks_insert_attrib (x, atts[i], atts[i+1]);
i += 2;
}
}
data->current = x;
}
if (IKS_CLOSE == type || IKS_SINGLE == type) {
x = iks_parent (data->current);
if (iks_strcmp(iks_name(data->current), name) != 0)
return IKS_BADXML;
if (x)
data->current = x;
else {
*(data->iksptr) = data->current;
data->current = NULL;
}
}
return IKS_OK;
}
static int
cdataHook (struct dom_data *data, char *cdata, size_t len)
{
if (data->current) iks_insert_cdata (data->current, cdata, len);
return IKS_OK;
}
static void
deleteHook (struct dom_data *data)
{
if (data->current) iks_delete (data->current);
data->current = NULL;
}
iksparser *
iks_dom_new (iks **iksptr)
{
ikstack *s;
struct dom_data *data;
*iksptr = NULL;
s = iks_stack_new (DEFAULT_DOM_CHUNK_SIZE, 0);
if (!s) return NULL;
data = iks_stack_alloc (s, sizeof (struct dom_data));
data->iksptr = iksptr;
data->current = NULL;
data->chunk_size = DEFAULT_DOM_IKS_CHUNK_SIZE;
return iks_sax_extend (s, data, (iksTagHook *) tagHook, (iksCDataHook *) cdataHook, (iksDeleteHook *) deleteHook);
}
void
iks_set_size_hint (iksparser *prs, size_t approx_size)
{
size_t cs;
struct dom_data *data = iks_user_data (prs);
cs = approx_size / 10;
if (cs < DEFAULT_DOM_IKS_CHUNK_SIZE) cs = DEFAULT_DOM_IKS_CHUNK_SIZE;
data->chunk_size = cs;
}
iks *
iks_tree (const char *xml_str, size_t len, int *err)
{
iksparser *prs;
iks *x;
int e;
if (0 == len) len = strlen (xml_str);
prs = iks_dom_new (&x);
if (!prs) {
if (err) *err = IKS_NOMEM;
return NULL;
}
e = iks_parse (prs, xml_str, len, 1);
if (err) *err = e;
iks_parser_delete (prs);
return x;
}
int
iks_load (const char *fname, iks **xptr)
{
iksparser *prs;
char *buf;
FILE *f;
int len, done = 0;
int ret;
*xptr = NULL;
buf = iks_malloc (FILE_IO_BUF_SIZE);
if (!buf) return IKS_NOMEM;
ret = IKS_NOMEM;
prs = iks_dom_new (xptr);
if (prs) {
f = fopen (fname, "r");
if (f) {
while (0 == done) {
len = fread (buf, 1, FILE_IO_BUF_SIZE, f);
if (len < FILE_IO_BUF_SIZE) {
if (0 == feof (f)) {
ret = IKS_FILE_RWERR;
break;
}
if (0 == len) ret = IKS_OK;
done = 1;
}
if (len > 0) {
int e;
e = iks_parse (prs, buf, len, done);
if (IKS_OK != e) {
ret = e;
break;
}
if (done) ret = IKS_OK;
}
}
fclose (f);
} else {
if (ENOENT == errno) ret = IKS_FILE_NOFILE;
else ret = IKS_FILE_NOACCESS;
}
iks_parser_delete (prs);
}
iks_free (buf);
return ret;
}
int
iks_save (const char *fname, iks *x)
{
FILE *f;
char *data;
int ret;
ret = IKS_NOMEM;
data = iks_string (NULL, x);
if (data) {
ret = IKS_FILE_NOACCESS;
f = fopen (fname, "w");
if (f) {
ret = IKS_FILE_RWERR;
if (fputs (data, f) >= 0) ret = IKS_OK;
fclose (f);
}
iks_free (data);
}
return ret;
}
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>
** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License.
*/
#include "common.h"
#include "iksemel.h"
struct iksrule_struct {
struct iksrule_struct *next, *prev;
ikstack *s;
void *user_data;
iksFilterHook *filterHook;
char *id;
char *from;
char *ns;
int score;
int rules;
enum ikstype type;
enum iksubtype subtype;
};
struct iksfilter_struct {
iksrule *rules;
iksrule *last_rule;
};
iksfilter *
iks_filter_new (void)
{
iksfilter *f;
f = iks_malloc (sizeof (iksfilter));
if (!f) return NULL;
memset (f, 0, sizeof (iksfilter));
return f;
}
iksrule *
iks_filter_add_rule (iksfilter *f, iksFilterHook *filterHook, void *user_data, ...)
{
ikstack *s;
iksrule *rule;
va_list ap;
int type;
s = iks_stack_new (sizeof (iksrule), DEFAULT_RULE_CHUNK_SIZE);
if (!s) return NULL;
rule = iks_stack_alloc (s, sizeof (iksrule));
memset (rule, 0, sizeof (iksrule));
rule->s = s;
rule->user_data = user_data;
rule->filterHook = filterHook;
va_start (ap, user_data);
while (1) {
type = va_arg (ap, int);
if (IKS_RULE_DONE == type) break;
rule->rules += type;
switch (type) {
case IKS_RULE_TYPE:
rule->type = va_arg (ap, int);
break;
case IKS_RULE_SUBTYPE:
rule->subtype = va_arg (ap, int);
break;
case IKS_RULE_ID:
rule->id = iks_stack_strdup (s, va_arg (ap, char *), 0);
break;
case IKS_RULE_NS:
rule->ns = iks_stack_strdup (s, va_arg (ap, char *), 0);
break;
case IKS_RULE_FROM:
rule->from = iks_stack_strdup (s, va_arg (ap, char *), 0);
break;
case IKS_RULE_FROM_PARTIAL:
rule->from = iks_stack_strdup (s, va_arg (ap, char *), 0);
break;
}
}
va_end (ap);
if (!f->rules) f->rules = rule;
if (f->last_rule) f->last_rule->next = rule;
rule->prev = f->last_rule;
f->last_rule = rule;
return rule;
}
void
iks_filter_remove_rule (iksfilter *f, iksrule *rule)
{
if (rule->prev) rule->prev->next = rule->next;
if (rule->next) rule->next->prev = rule->prev;
if (f->rules == rule) f->rules = rule->next;
if (f->last_rule == rule) f->last_rule = rule->prev;
iks_stack_delete (rule->s);
}
void
iks_filter_remove_hook (iksfilter *f, iksFilterHook *filterHook)
{
iksrule *rule, *tmp;
rule = f->rules;
while (rule) {
tmp = rule->next;
if (rule->filterHook == filterHook) iks_filter_remove_rule (f, rule);
rule = tmp;
}
}
void
iks_filter_packet (iksfilter *f, ikspak *pak)
{
iksrule *rule, *max_rule;
int fail, score, max_score;
rule = f->rules;
max_rule = NULL;
max_score = 0;
while (rule) {
score = 0;
fail = 0;
if (rule->rules & IKS_RULE_TYPE) {
if (rule->type == pak->type) score += 1; else fail = 1;
}
if (rule->rules & IKS_RULE_SUBTYPE) {
if (rule->subtype == pak->subtype) score += 2; else fail = 1;
}
if (rule->rules & IKS_RULE_ID) {
if (iks_strcmp (rule->id, pak->id) == 0) score += 16; else fail = 1;
}
if (rule->rules & IKS_RULE_NS) {
if (iks_strcmp (rule->ns, pak->ns) == 0) score += 4; else fail = 1;
}
if (rule->rules & IKS_RULE_FROM) {
if (pak->from && iks_strcmp (rule->from, pak->from->full) == 0) score += 8; else fail = 1;
}
if (rule->rules & IKS_RULE_FROM_PARTIAL) {
if (pak->from && iks_strcmp (rule->from, pak->from->partial) == 0) score += 8; else fail = 1;
}
if (fail != 0) score = 0;
rule->score = score;
if (score > max_score) {
max_rule = rule;
max_score = score;
}
rule = rule->next;
}
while (max_rule) {
if (IKS_FILTER_EAT == max_rule->filterHook (max_rule->user_data, pak)) return;
max_rule->score = 0;
max_rule = NULL;
max_score = 0;
rule = f->rules;
while (rule) {
if (rule->score > max_score) {
max_rule = rule;
max_score = rule->score;
}
rule = rule->next;
}
}
}
void
iks_filter_delete (iksfilter *f)
{
iksrule *rule, *tmp;
rule = f->rules;
while (rule) {
tmp = rule->next;
iks_stack_delete (rule->s);
rule = tmp;
}
iks_free (f);
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
##
## Process this file with automake to produce Makefile.in
##
INCLUDES = -I$(top_srcdir)/include
bin_PROGRAMS = ikslint iksroster iksperf
noinst_HEADERS = perf.h
ikslint_LDADD = $(top_builddir)/src/libiksemel.la
ikslint_SOURCES = ikslint.c hash.c
iksroster_LDADD = $(top_builddir)/src/libiksemel.la
iksroster_SOURCES = iksroster.c
iksperf_LDADD = $(top_builddir)/src/libiksemel.la
iksperf_SOURCES = iksperf.c perf.c
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment