add iksemel to in tree libs

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3756 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris committed 2006-12-20 15:45:14 +00:00
1 parent 7d37a04688
commit 83f4a9dc2f
66 files changed
+57293 -2

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
##
## 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
+355
View File
@@ -0,0 +1,355 @@
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
host_alias = @host_alias@
host_triplet = @host@
AR = @AR@
AS = @AS@
CC = @CC@
CXX = @CXX@
CXXCPP = @CXXCPP@
DLLTOOL = @DLLTOOL@
ECHO = @ECHO@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
F77 = @F77@
GCJ = @GCJ@
GCJFLAGS = @GCJFLAGS@
HAVE_LIB = @HAVE_LIB@
LIB = @LIB@
LIBGNUTLS_CFLAGS = @LIBGNUTLS_CFLAGS@
LIBGNUTLS_CONFIG = @LIBGNUTLS_CONFIG@
LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@
LIBTOOL = @LIBTOOL@
LN_S = @LN_S@
LTLIB = @LTLIB@
MAKEINFO = @MAKEINFO@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
RC = @RC@
STRIP = @STRIP@
VERSION = @VERSION@
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
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../include/config.h
CONFIG_CLEAN_FILES =
bin_PROGRAMS = ikslint$(EXEEXT) iksroster$(EXEEXT) iksperf$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
DEFS = @DEFS@ -I. -I$(srcdir) -I../include
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
ikslint_OBJECTS = ikslint.$(OBJEXT) hash.$(OBJEXT)
ikslint_DEPENDENCIES = $(top_builddir)/src/libiksemel.la
ikslint_LDFLAGS =
iksroster_OBJECTS = iksroster.$(OBJEXT)
iksroster_DEPENDENCIES = $(top_builddir)/src/libiksemel.la
iksroster_LDFLAGS =
iksperf_OBJECTS = iksperf.$(OBJEXT) perf.$(OBJEXT)
iksperf_DEPENDENCIES = $(top_builddir)/src/libiksemel.la
iksperf_LDFLAGS =
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
HEADERS = $(noinst_HEADERS)
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP_ENV = --best
SOURCES = $(ikslint_SOURCES) $(iksroster_SOURCES) $(iksperf_SOURCES)
OBJECTS = $(ikslint_OBJECTS) $(iksroster_OBJECTS) $(iksperf_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .S .c .lo .o .obj .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.ac $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps tools/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-binPROGRAMS:
clean-binPROGRAMS:
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
distclean-binPROGRAMS:
maintainer-clean-binPROGRAMS:
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(bindir)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
if test -f $$p; then \
echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`"; \
$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
list='$(bin_PROGRAMS)'; for p in $$list; do \
rm -f $(DESTDIR)$(bindir)/`echo $$p|sed 's/$(EXEEXT)$$//'|sed '$(transform)'|sed 's/$$/$(EXEEXT)/'`; \
done
.c.o:
$(COMPILE) -c $<
# FIXME: We should only use cygpath when building on Windows,
# and only if it is available.
.c.obj:
$(COMPILE) -c `cygpath -w $<`
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
-rm -f *.$(OBJEXT)
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
.c.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
.s.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
.S.lo:
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
distclean-libtool:
maintainer-clean-libtool:
ikslint$(EXEEXT): $(ikslint_OBJECTS) $(ikslint_DEPENDENCIES)
@rm -f ikslint$(EXEEXT)
$(LINK) $(ikslint_LDFLAGS) $(ikslint_OBJECTS) $(ikslint_LDADD) $(LIBS)
iksroster$(EXEEXT): $(iksroster_OBJECTS) $(iksroster_DEPENDENCIES)
@rm -f iksroster$(EXEEXT)
$(LINK) $(iksroster_LDFLAGS) $(iksroster_OBJECTS) $(iksroster_LDADD) $(LIBS)
iksperf$(EXEEXT): $(iksperf_OBJECTS) $(iksperf_DEPENDENCIES)
@rm -f iksperf$(EXEEXT)
$(LINK) $(iksperf_LDFLAGS) $(iksperf_OBJECTS) $(iksperf_LDADD) $(LIBS)
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags -o $$here/TAGS $(ETAGS_ARGS) $$tags $$unique $(LISP))
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = tools
distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$d/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am: install-binPROGRAMS
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am: uninstall-binPROGRAMS
uninstall: uninstall-am
all-am: Makefile $(PROGRAMS) $(HEADERS)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
$(mkinstalldirs) $(DESTDIR)$(bindir)
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-binPROGRAMS mostlyclean-compile \
mostlyclean-libtool mostlyclean-tags \
mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-binPROGRAMS clean-compile clean-libtool clean-tags \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-binPROGRAMS distclean-compile distclean-libtool \
distclean-tags distclean-generic clean-am
-rm -f libtool
distclean: distclean-am
maintainer-clean-am: maintainer-clean-binPROGRAMS \
maintainer-clean-compile maintainer-clean-libtool \
maintainer-clean-tags maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \
maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile mostlyclean-libtool distclean-libtool \
clean-libtool maintainer-clean-libtool tags mostlyclean-tags \
distclean-tags clean-tags maintainer-clean-tags distdir info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
+144
View File
@@ -0,0 +1,144 @@
/* 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 unsigned int
hash_str (const char *str)
{
const char *p;
unsigned int h = 0;
for (p = str; *p != '\0'; p++) {
h = ( h << 5 ) - h + *p;
}
return h;
}
struct item {
char *name;
unsigned int count;
struct item *next;
};
struct hash_s {
struct item **table;
unsigned int size;
unsigned int count;
ikstack *s;
};
typedef struct hash_s hash;
hash *
hash_new (unsigned int table_size)
{
hash *h;
h = malloc (sizeof (struct hash_s));
if (!h) return NULL;
h->table = calloc (sizeof (struct item *), table_size);
if (!h->table) {
free (h);
return NULL;
}
h->s = iks_stack_new (sizeof (hash) * 128, 8192);
if (!h->s) {
free (h->table);
free (h);
return NULL;
}
h->size = table_size;
h->count = 0;
return h;
}
char *
hash_insert (hash *h, const char *name)
{
struct item *t, *p;
unsigned int val;
val = hash_str (name) % h->size;
h->count++;
for (t = h->table[val]; t; t = t->next) {
if (strcmp (t->name, name) == 0)
break;
}
if (NULL == t) {
t = iks_stack_alloc (h->s, sizeof (struct item));
if (!t) return NULL;
t->name = iks_stack_strdup (h->s, name, 0);
t->count = 0;
t->next = NULL;
p = h->table[val];
if (!p) {
h->table[val] = t;
} else {
while (1) {
if (p->next == NULL) {
p->next = t;
break;
}
p = p->next;
}
}
}
t->count++;
return t->name;
}
static int
my_cmp (const void *a, const void *b)
{
unsigned int c1, c2;
c1 = (*(struct item **)a)->count;
c2 = (*(struct item **)b)->count;
if (c1 > c2)
return -1;
else if (c1 == c2)
return 0;
else
return 1;
}
void
hash_print (hash *h, char *title_fmt, char *line_fmt)
{
struct item **tags, *t;
unsigned int i = 0, pos = 0;
tags = calloc (sizeof (struct tag *), h->count);
for (; i < h->size; i ++) {
for (t = h->table[i]; t; t = t->next) {
tags[pos++] = t;
}
}
qsort (tags, pos, sizeof (struct item *), my_cmp);
printf (title_fmt, pos);
for (i = 0; i < pos; i++) {
printf (line_fmt, tags[i]->name, tags[i]->count);
}
free (tags);
}
void
hash_delete (hash *h)
{
iks_stack_delete (h->s);
free (h->table);
free (h);
}
+283
View File
@@ -0,0 +1,283 @@
/* 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 hash_s;
typedef struct hash_s hash;
hash *hash_new (unsigned int table_size);
char *hash_insert (hash *table, const char *name);
void hash_print (hash *h, char *title_fmt, char *line_fmt);
void hash_delete (hash *table);
#include <sys/stat.h>
#ifdef HAVE_GETOPT_LONG
#include <getopt.h>
#endif
#ifdef HAVE_GETOPT_LONG
static struct option longopts[] = {
{ "stats", 0, 0, 's' },
{ "histogram", 0, 0, 't' },
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
};
#endif
static char *shortopts = "sthV";
static void
print_usage (void)
{
puts ("Usage: ikslint [OPTIONS] FILE\n"
"This tool checks the well-formedness of an XML document.\n"
" -s, --stats Print statistics.\n"
" -t, --histogram Print tag histogram.\n"
" -h, --help Print this text and exit.\n"
" -V, --version Print version and exit.\n"
#ifndef HAVE_GETOPT_LONG
"(long options are not supported on your system)\n"
#endif
"Report bugs to <iksemel-dev@jabberstudio.org>.");
}
/* calculate and print statistics */
int lint_pr_stats = 0;
/* print tag histogram */
int lint_pr_hist = 0;
hash *tag_table;
char **tag_list;
int tag_size, tag_pos;
void
tag_push (const char *name)
{
if (!tag_list) {
tag_size = 128;
tag_list = malloc (sizeof (char *) * tag_size);
if (!tag_list) exit (2);
}
tag_list[tag_pos] = hash_insert (tag_table, name);
if (!tag_list[tag_pos]) exit (2);
tag_pos++;
if (tag_pos == tag_size) {
char **tmp;
tmp = malloc (sizeof (char *) * tag_size * 2);
if (!tmp) exit (2);
memcpy (tmp, tag_list, sizeof (char *) * tag_size);
free (tag_list);
tag_list = tmp;
tag_size *= 2;
}
}
char *
tag_pull (void)
{
tag_pos--;
return tag_list[tag_pos];
}
struct stats {
unsigned int level;
unsigned int max_depth;
unsigned int nr_tags;
unsigned int nr_stags;
unsigned int cdata_size;
};
int
tagHook (void *udata, char *name, char **atts, int type)
{
struct stats *st = (struct stats *) udata;
char *tmp;
switch (type) {
case IKS_OPEN:
tag_push (name);
st->level++;
if (st->level > st->max_depth) st->max_depth = st->level;
break;
case IKS_CLOSE:
tmp = tag_pull ();
if (iks_strcmp (tmp, name) != 0) {
fprintf (stderr, "Tag mismatch, expecting '%s', got '%s'.\n",
tmp, name);
return IKS_HOOK;
}
st->level--;
st->nr_tags++;
break;
case IKS_SINGLE:
if (NULL == hash_insert (tag_table, name)) exit (2);
st->nr_stags++;
break;
}
return IKS_OK;
}
int
cdataHook (void *udata, char *data, size_t len)
{
struct stats *st = (struct stats *) udata;
st->cdata_size += len;
return IKS_OK;
}
void
check_file (char *fname)
{
iksparser *prs;
struct stats st;
FILE *f;
char *buf;
struct stat fs;
size_t sz, blk, ret, pos;
enum ikserror err;
int done;
memset (&st, 0, sizeof (struct stats));
prs = iks_sax_new (&st, tagHook, cdataHook);
if (NULL == prs) exit (2);
if (fname) {
if (stat (fname, &fs) != 0) {
fprintf (stderr, "Cannot access file '%s'.\n", fname);
exit (1);
}
sz = fs.st_size;
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
blk = fs.st_blksize;
#else
blk = 4096;
#endif
f = fopen (fname, "r");
if (!f) {
fprintf (stderr, "Cannot open file '%s'.\n", fname);
exit (1);
}
buf = malloc (blk);
if (!buf) {
fclose (f);
fprintf (stderr, "Cannot allocate %d bytes.\n", blk);
exit (2);
}
} else {
f = stdin;
blk = 4096;
sz = 0;
buf = malloc (blk);
if (!buf) exit (2);
}
tag_table = hash_new (367);
if (!tag_table) exit (2);
pos = 0;
done = 0;
while (0 == done) {
ret = fread (buf, 1, blk, f);
pos += ret;
if (feof (f)) {
done = 1;
} else {
if (ret != blk) {
if (fname)
fprintf (stderr, "Read error in file '%s'.\n", fname);
else
fprintf (stderr, "Read error in stream.\n");
exit (1);
}
}
err = iks_parse (prs, buf, ret, done);
switch (err) {
case IKS_OK:
break;
case IKS_NOMEM:
exit (2);
case IKS_BADXML:
if (fname)
fprintf (stderr, "Invalid xml at byte %ld, line %ld in file '%s'.\n",
iks_nr_bytes (prs), iks_nr_lines (prs), fname);
else
fprintf (stderr, "Invalid xml at byte %ld, line %ld in stream.\n",
iks_nr_bytes (prs), iks_nr_lines (prs));
exit (1);
case IKS_HOOK:
if (fname)
fprintf (stderr, "Byte %ld, line %ld in file '%s'.\n",
iks_nr_bytes (prs), iks_nr_lines (prs), fname);
else
fprintf (stderr, "Byte %ld, line %ld in stream.\n",
iks_nr_bytes (prs), iks_nr_lines (prs));
exit (1);
}
}
free (buf);
if (fname) fclose (f);
if (fname && (lint_pr_stats || lint_pr_hist)) {
printf ("File '%s' (%d bytes):\n", fname, sz);
}
if (lint_pr_stats) {
printf ("Tags: %d pairs, %d single, %d max depth.\n", st.nr_tags, st.nr_stags, st.max_depth);
printf ("Total size of character data: %d bytes.\n", st.cdata_size);
}
if (lint_pr_hist) {
hash_print (tag_table,
"Histogram of %d unique tags:\n",
"<%s> %d times.\n");
}
hash_delete (tag_table);
iks_parser_delete (prs);
}
int
main (int argc, char *argv[])
{
int c;
#ifdef HAVE_GETOPT_LONG
int i;
while ((c = getopt_long (argc, argv, shortopts, longopts, &i)) != -1) {
#else
while ((c = getopt (argc, argv, shortopts)) != -1) {
#endif
switch (c) {
case 's':
lint_pr_stats = 1;
break;
case 't':
lint_pr_hist = 1;
break;
case 'h':
print_usage ();
exit (0);
case 'V':
puts ("ikslint (iksemel) "VERSION);
exit (0);
}
}
if (!argv[optind]) {
check_file (NULL);
} else {
for (; optind < argc; optind++) {
check_file (argv[optind]);
}
}
return 0;
}
+316
View File
@@ -0,0 +1,316 @@
/* 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"
#include "perf.h"
#include <sys/stat.h>
#ifdef HAVE_GETOPT_LONG
#include <getopt.h>
#endif
#ifdef HAVE_GETOPT_LONG
static struct option longopts[] = {
{ "all", 0, 0, 'a' },
{ "sax", 0, 0, 's' },
{ "dom", 0, 0, 'd' },
{ "serialize", 0, 0, 'e' },
{ "sha1", 0, 0, '1' },
{ "block", required_argument, 0, 'b' },
{ "memdbg", 0, 0, 'm' },
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
};
#endif
static char *shortopts = "asde1b:mhV";
static void
print_usage (void)
{
puts ("Usage: iksperf [OPTIONS] FILE\n"
"This tool measures the performance of the iksemel library.\n"
" -a, --all Make all tests.\n"
" -s, --sax Sax test.\n"
" -d, --dom Tree generating test.\n"
" -e, --serialize Tree serializing test.\n"
" -1, --sha1 SHA1 hashing test.\n"
" -b, --block SIZE Parse the file in SIZE byte blocks.\n"
" -m, --memdbg Trace malloc and free calls.\n"
" -h, --help Print this text and exit.\n"
" -V, --version Print version and exit.\n"
#ifndef HAVE_GETOPT_LONG
"(long options are not supported on your system)\n"
#endif
"Report bugs to <iksemel-dev@jabberstudio.org>.");
}
/* if not 0, file is parsed in block_size byte blocks */
int block_size;
char *load_file (const char *fname, int *sizeptr)
{
FILE *f;
char *buf;
struct stat fs;
size_t size, ret;
if (stat (fname, &fs) != 0) {
fprintf (stderr, "Cannot access file '%s'.\n", fname);
exit (1);
}
size = fs.st_size;
printf ("Test file '%s' (%d bytes):\n", fname, size);
f = fopen (fname, "rb");
if (!f) {
fprintf (stderr, "Cannot open file.\n");
exit (1);
}
buf = malloc (size);
if (!buf) {
fclose (f);
fprintf (stderr, "Cannot allocate %d bytes for buffer.\n", size);
exit (2);
}
ret = fread (buf, 1, size, f);
if (ret < size) {
fprintf (stderr, "Read error in file.\n");
exit (1);
}
*sizeptr = size;
fclose (f);
return buf;
}
/* stats */
int sax_tag;
int sax_cdata;
int
tagHook (void *udata, char *name, char **atts, int type)
{
++sax_tag;
return IKS_OK;
}
int
cdataHook (void *udata, char *data, size_t len)
{
++sax_cdata;
return IKS_OK;
}
void
sax_test (char *buf, int len)
{
unsigned long time;
iksparser *prs;
int bs, i, err;
bs = block_size;
if (0 == bs) bs = len;
sax_tag = 0;
sax_cdata = 0;
t_reset ();
prs = iks_sax_new (NULL, tagHook, cdataHook);
i = 0;
while (i < len) {
if (i + bs > len) bs = len - i;
err = iks_parse (prs, buf + i, bs, 0);
switch (err) {
case IKS_OK:
break;
case IKS_NOMEM:
exit (2);
case IKS_BADXML:
fprintf (stderr, "Invalid xml at byte %ld, line %ld\n",
iks_nr_bytes (prs), iks_nr_lines (prs));
exit (1);
case IKS_HOOK:
exit (1);
}
i += bs;
}
time = t_elapsed ();
printf ("SAX: parsing took %ld milliseconds.\n", time);
printf ("SAX: tag hook called %d, cdata hook called %d times.\n", sax_tag, sax_cdata);
iks_parser_delete (prs);
}
void dom_test (char *buf, int len)
{
int bs, i, err;
iksparser *prs;
unsigned long time;
iks *x;
size_t allocated, used;
bs = block_size;
if (0 == bs) bs = len;
t_reset ();
prs = iks_dom_new (&x);
iks_set_size_hint (prs, len);
i = 0;
while (i < len) {
if (i + bs > len) bs = len - i;
err = iks_parse (prs, buf + i, bs, 0);
switch (err) {
case IKS_OK:
break;
case IKS_NOMEM:
exit (2);
case IKS_BADXML:
fprintf (stderr, "Invalid xml at byte %ld, line %ld\n",
iks_nr_bytes (prs), iks_nr_lines (prs));
exit (1);
case IKS_HOOK:
exit (1);
}
i += bs;
}
time = t_elapsed ();
iks_stack_stat (iks_stack (x), &allocated, &used);
printf ("DOM: parsing and building the tree took %ld milliseconds.\n", time);
printf ("DOM: ikstack: %d bytes allocated, %d bytes used.\n", allocated, used);
t_reset ();
iks_delete (x);
time = t_elapsed ();
printf ("DOM: deleting the tree took %ld milliseconds.\n", time);
iks_parser_delete (prs);
}
void
serialize_test (char *buf, int len)
{
unsigned long time;
iks *x;
iksparser *prs;
char *xml;
int err;
prs = iks_dom_new (&x);
err = iks_parse (prs, buf, len, 1);
switch (err) {
case IKS_OK:
break;
case IKS_NOMEM:
exit (2);
case IKS_BADXML:
fprintf (stderr, "Invalid xml at byte %ld, line %ld\n",
iks_nr_bytes (prs), iks_nr_lines (prs));
exit (1);
case IKS_HOOK:
exit (1);
}
iks_parser_delete (prs);
t_reset ();
xml = iks_string (iks_stack (x), x);
time = t_elapsed ();
printf ("Serialize: serializing the tree took %ld milliseconds.\n", time);
iks_delete (x);
}
void
sha_test (char *buf, int len)
{
unsigned long time;
iksha *s;
char out[41];
t_reset ();
s = iks_sha_new ();
iks_sha_hash (s, buf, len, 1);
iks_sha_print (s, out);
out[40] = '\0';
iks_sha_delete (s);
time = t_elapsed ();
printf ("SHA: hashing took %ld milliseconds.\n", time);
printf ("SHA: hash [%s]\n", out);
}
int
main (int argc, char *argv[])
{
int test_type = 0;
int c;
#ifdef HAVE_GETOPT_LONG
int i;
while ((c = getopt_long (argc, argv, shortopts, longopts, &i)) != -1) {
#else
while ((c = getopt (argc, argv, shortopts)) != -1) {
#endif
switch (c) {
case 'a':
test_type = 0xffff;
break;
case 's':
test_type |= 1;
break;
case 'd':
test_type |= 2;
break;
case 'e':
test_type |= 4;
break;
case '1':
test_type |= 8;
break;
case 'b':
block_size = atoi (optarg);
break;
case 'm':
m_trace ();
break;
case 'h':
print_usage ();
exit (0);
case 'V':
puts ("iksperf (iksemel) "VERSION);
exit (0);
}
}
for (; optind < argc; optind++) {
char *buf;
int len;
buf = load_file (argv[optind], &len);
if (test_type & 1) sax_test (buf, len);
if (test_type == 0 || test_type & 2) dom_test (buf, len);
if (test_type & 4) serialize_test (buf, len);
if (test_type & 8) sha_test (buf, len);
free (buf);
}
return 0;
}
+379
View File
@@ -0,0 +1,379 @@
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2004 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"
#ifdef HAVE_GETOPT_LONG
#include <getopt.h>
#endif
#ifdef _WIN32
#include <winsock.h>
#endif
#ifdef HAVE_GETOPT_LONG
static struct option longopts[] = {
{ "backup", required_argument, 0, 'b' },
{ "restore", required_argument, 0, 'r' },
{ "file", required_argument, 0, 'f' },
{ "timeout", required_argument, 0, 't' },
{ "secure", 0, 0, 's' },
{ "sasl", 0, 0, 'a' },
{ "log", 0, 0, 'l' },
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
};
#endif
static char *shortopts = "b:r:f:t:salhV";
static void
print_usage (void)
{
puts ("Usage: iksroster [OPTIONS]\n"
"This is a backup tool for your jabber roster.\n"
" -b, --backup=JID Download roster from the server.\n"
" -r, --restore=JID Upload roster to the server.\n"
" -f, --file=FILE Load/Save roster to this file.\n"
" -t, --timeout=SECS Set network timeout.\n"
" -s, --secure Use encrypted connection.\n"
" -a, --sasl Use SASL authentication.\n"
" -l, --log Print exchanged xml data.\n"
" -h, --help Print this text and exit.\n"
" -V, --version Print version and exit.\n"
#ifndef HAVE_GETOPT_LONG
"(long options are not supported on your system)\n"
#endif
#ifndef HAVE_GNUTLS
"(secure connections are not supported on your system)\n"
#endif
"Report bugs to <iksemel-dev@jabberstudio.org>.");
}
/* stuff we keep per session */
struct session {
iksparser *prs;
iksid *acc;
char *pass;
int features;
int authorized;
int counter;
int set_roster;
int job_done;
};
/* precious roster we'll deal with */
iks *my_roster;
/* out packet filter */
iksfilter *my_filter;
/* connection time outs if nothing comes for this much seconds */
int opt_timeout = 30;
/* connection flags */
int opt_use_tls;
int opt_use_sasl;
int opt_log;
void
j_error (char *msg)
{
fprintf (stderr, "iksroster: %s\n", msg);
exit (2);
}
int
on_result (struct session *sess, ikspak *pak)
{
iks *x;
if (sess->set_roster == 0) {
x = iks_make_iq (IKS_TYPE_GET, IKS_NS_ROSTER);
iks_insert_attrib (x, "id", "roster");
iks_send (sess->prs, x);
iks_delete (x);
} else {
iks_insert_attrib (my_roster, "type", "set");
iks_send (sess->prs, my_roster);
}
return IKS_FILTER_EAT;
}
int
on_stream (struct session *sess, int type, iks *node)
{
sess->counter = opt_timeout;
switch (type) {
case IKS_NODE_START:
if (opt_use_tls && !iks_is_secure (sess->prs)) {
iks_start_tls (sess->prs);
break;
}
if (!opt_use_sasl) {
iks *x;
x = iks_make_auth (sess->acc, sess->pass, iks_find_attrib (node, "id"));
iks_insert_attrib (x, "id", "auth");
iks_send (sess->prs, x);
iks_delete (x);
}
break;
case IKS_NODE_NORMAL:
if (strcmp ("stream:features", iks_name (node)) == 0) {
sess->features = iks_stream_features (node);
if (opt_use_sasl) {
if (opt_use_tls && !iks_is_secure (sess->prs)) break;
if (sess->authorized) {
iks *t;
if (sess->features & IKS_STREAM_BIND) {
t = iks_make_resource_bind (sess->acc);
iks_send (sess->prs, t);
iks_delete (t);
}
if (sess->features & IKS_STREAM_SESSION) {
t = iks_make_session ();
iks_insert_attrib (t, "id", "auth");
iks_send (sess->prs, t);
iks_delete (t);
}
} else {
if (sess->features & IKS_STREAM_SASL_MD5)
iks_start_sasl (sess->prs, IKS_SASL_DIGEST_MD5, sess->acc->user, sess->pass);
else if (sess->features & IKS_STREAM_SASL_PLAIN)
iks_start_sasl (sess->prs, IKS_SASL_PLAIN, sess->acc->user, sess->pass);
}
}
} else if (strcmp ("failure", iks_name (node)) == 0) {
j_error ("sasl authentication failed");
} else if (strcmp ("success", iks_name (node)) == 0) {
sess->authorized = 1;
iks_send_header (sess->prs, sess->acc->server);
} else {
ikspak *pak;
pak = iks_packet (node);
iks_filter_packet (my_filter, pak);
if (sess->job_done == 1) return IKS_HOOK;
}
break;
case IKS_NODE_STOP:
j_error ("server disconnected");
case IKS_NODE_ERROR:
j_error ("stream error");
}
if (node) iks_delete (node);
return IKS_OK;
}
int
on_error (void *user_data, ikspak *pak)
{
j_error ("authorization failed");
return IKS_FILTER_EAT;
}
int
on_roster (struct session *sess, ikspak *pak)
{
my_roster = pak->x;
sess->job_done = 1;
return IKS_FILTER_EAT;
}
void
on_log (struct session *sess, const char *data, size_t size, int is_incoming)
{
if (iks_is_secure (sess->prs)) fprintf (stderr, "Sec");
if (is_incoming) fprintf (stderr, "RECV"); else fprintf (stderr, "SEND");
fprintf (stderr, "[%s]\n", data);
}
void
j_setup_filter (struct session *sess)
{
if (my_filter) iks_filter_delete (my_filter);
my_filter = iks_filter_new ();
iks_filter_add_rule (my_filter, (iksFilterHook *) on_result, sess,
IKS_RULE_TYPE, IKS_PAK_IQ,
IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,
IKS_RULE_ID, "auth",
IKS_RULE_DONE);
iks_filter_add_rule (my_filter, on_error, sess,
IKS_RULE_TYPE, IKS_PAK_IQ,
IKS_RULE_SUBTYPE, IKS_TYPE_ERROR,
IKS_RULE_ID, "auth",
IKS_RULE_DONE);
iks_filter_add_rule (my_filter, (iksFilterHook *) on_roster, sess,
IKS_RULE_TYPE, IKS_PAK_IQ,
IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,
IKS_RULE_ID, "roster",
IKS_RULE_DONE);
}
void
j_connect (char *jabber_id, char *pass, int set_roster)
{
struct session sess;
int e;
memset (&sess, 0, sizeof (sess));
sess.prs = iks_stream_new (IKS_NS_CLIENT, &sess, (iksStreamHook *) on_stream);
if (opt_log) iks_set_log_hook (sess.prs, (iksLogHook *) on_log);
sess.acc = iks_id_new (iks_parser_stack (sess.prs), jabber_id);
if (NULL == sess.acc->resource) {
/* user gave no resource name, use the default */
char *tmp;
tmp = iks_malloc (strlen (sess.acc->user) + strlen (sess.acc->server) + 9 + 3);
sprintf (tmp, "%s@%s/%s", sess.acc->user, sess.acc->server, "iksroster");
sess.acc = iks_id_new (iks_parser_stack (sess.prs), tmp);
iks_free (tmp);
}
sess.pass = pass;
sess.set_roster = set_roster;
j_setup_filter (&sess);
e = iks_connect_tcp (sess.prs, sess.acc->server, IKS_JABBER_PORT);
switch (e) {
case IKS_OK:
break;
case IKS_NET_NODNS:
j_error ("hostname lookup failed");
case IKS_NET_NOCONN:
j_error ("connection failed");
default:
j_error ("io error");
}
sess.counter = opt_timeout;
while (1) {
e = iks_recv (sess.prs, 1);
if (IKS_HOOK == e) break;
if (IKS_NET_TLSFAIL == e) j_error ("tls handshake failed");
if (IKS_OK != e) j_error ("io error");
sess.counter--;
if (sess.counter == 0) j_error ("network timeout");
}
iks_parser_delete (sess.prs);
}
int
main (int argc, char *argv[])
{
char *from = NULL;
char *to = NULL;
char *file = NULL;
char from_pw[128], to_pw[128];
int c;
#ifdef HAVE_GETOPT_LONG
int i;
while ((c = getopt_long (argc, argv, shortopts, longopts, &i)) != -1) {
#else
while ((c = getopt (argc, argv, shortopts)) != -1) {
#endif
switch (c) {
case 'b':
from = optarg;
printf ("Password for %s: ", optarg);
fflush (stdout);
fgets (from_pw, 127, stdin);
strtok (from_pw, "\r\n");
break;
case 'r':
to = optarg;
printf ("Password for %s: ", optarg);
fflush (stdout);
fgets (to_pw, 127, stdin);
strtok (to_pw, "\r\n");
break;
case 'f':
file = strdup (optarg);
break;
case 't':
opt_timeout = atoi (optarg);
if (opt_timeout < 10) opt_timeout = 10;
break;
case 's':
if (!iks_has_tls ()) {
puts ("Cannot make encrypted connections.");
puts ("iksemel library is not compiled with GnuTLS support.");
exit (1);
}
opt_use_tls = 1;
break;
case 'a':
opt_use_sasl = 1;
break;
case 'l':
opt_log = 1;
break;
case 'h':
print_usage ();
exit (0);
case 'V':
puts ("iksroster (iksemel) "VERSION);
exit (0);
}
}
if (from == NULL && to == NULL) {
puts ("What I'm supposed to do?");
print_usage ();
exit (1);
}
if (to && (from == NULL && file == NULL)) {
puts ("Store which roster?");
print_usage ();
exit (1);
}
#ifdef _WIN32
WSADATA wsaData;
WSAStartup (MAKEWORD (1,1), &wsaData);
#endif
if (from) {
j_connect (from, from_pw, 0);
if (file) {
switch (iks_save (file, my_roster)) {
case IKS_OK:
break;
case IKS_FILE_NOACCESS:
j_error ("cannot write to file");
default:
j_error ("file io error");
}
}
} else {
switch (iks_load (file, &my_roster)) {
case IKS_OK:
break;
case IKS_FILE_NOFILE:
j_error ("file not found");
case IKS_FILE_NOACCESS:
j_error ("cannot read file");
default:
j_error ("file io error");
}
}
if (to) {
j_connect (to, to_pw, 1);
}
#ifdef _WIN32
WSACleanup ();
#endif
return 0;
}
+84
View File
@@ -0,0 +1,84 @@
/* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#include <limits.h>
#else
#include <sys/time.h>
#endif
#include "iksemel.h"
/* timing functions */
#ifdef _WIN32
static DWORD start_tv;
void
t_reset (void)
{
start_tv = GetTickCount ();
}
unsigned long
t_elapsed (void)
{
DWORD end_tv;
end_tv = GetTickCount ();
if (end_tv < start_tv)
return UINT_MAX - (start_tv - end_tv - 1);
else
return end_tv - start_tv;
}
#else
static struct timeval start_tv;
void
t_reset (void)
{
gettimeofday (&start_tv, NULL);
}
unsigned long
t_elapsed (void)
{
unsigned long msec;
struct timeval cur_tv;
gettimeofday (&cur_tv, NULL);
msec = (cur_tv.tv_sec * 1000) + (cur_tv.tv_usec / 1000);
msec -= (start_tv.tv_sec * 1000) + (start_tv.tv_usec / 1000);
return msec;
}
#endif
/* memory functions */
static void *
m_malloc (size_t size)
{
void *ptr = malloc (size);
printf ("MEM: malloc (%d) => %p\n", size, ptr);
return ptr;
}
static void
m_free (void *ptr)
{
printf ("MEM: free (%p)\n", ptr);
}
void
m_trace (void)
{
iks_set_mem_funcs (m_malloc, m_free);
}
+10
View File
@@ -0,0 +1,10 @@
/* 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.
*/
void t_reset (void);
unsigned long t_elapsed (void);
void m_trace (void);