merge in new iksemel patches

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11645 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West 2009-02-04 23:59:19 +00:00
parent 40b19bf28b
commit 2005e1862f
22 changed files with 7991 additions and 462 deletions

View File

@ -1 +0,0 @@
Fri Mar 16 17:15:40 EDT 2007

View File

@ -1,3 +1,32 @@
2007-08-02 Gurer
* tst-iks.c: test for new append/prepend functions added.
2007-08-01 Gurer
* Patch from Benjamin Bennett:
base64.c: fix padding
* sha.c: 64bit fix (long -> int)
* iks.c: new funcs: iks_append, iks_prepend
iks_append_cdata, iks_prepend_cdata
* stream.c: iks_sasl_challenge split into smaller functions
This change also fixes some possible leaks which are detected
by Coverity Inc's excellent Prevent product.
2006-05-19 Gurer
* dom.c: fixed (size % FILE_IO_BUFFER_SIZE) problem in iks_load()
2005-08-29 Gurer
* Patch from Jakob Schroter:
iksemel.texi: small documentation update
* Patch from Darrell Karbott:
sax.c: use fixed instead of floating point (for arm)
mark static const data properly
explicit char* uchar* casts
2004-08-14 Gurer
* version bump to 1.3
* patch from Roland Hedberg
io-posix.c: io_connect now tries all addrinfo values.
2004-08-05 Gurer
* iksemel.h: ikstransport cosmetic cleanup.
* iksemel.texi: mingw notice added.

View File

@ -1,3 +1,22 @@
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.

View File

@ -1,5 +1,5 @@
iksemel 1.2
iksemel 1.3
Copyright (c) 2000-2004 Gurer Ozen <madcat@e-kolay.net>

View File

@ -1,10 +1,9 @@
dnl Process this file with autoconf to produce a configure script.
AC_INIT
AC_PREREQ(2.50)
AC_CONFIG_AUX_DIR(build)
AC_CONFIG_SRCDIR([configure.ac])
AM_INIT_AUTOMAKE(iksemel,1.2)
AC_CONFIG_HEADERS(include/config.h)
AM_INIT_AUTOMAKE(iksemel,1.3)
AM_CONFIG_HEADER(include/config.h)
AC_CANONICAL_HOST
@ -46,7 +45,7 @@ AC_SEARCH_LIBS(recv,socket)
AC_CHECK_FUNCS(getopt_long)
AC_CHECK_FUNCS(getaddrinfo)
AX_PATH_LIBGNUTLS(,AC_DEFINE(HAVE_GNUTLS,,"Use libgnutls"))
AM_PATH_LIBGNUTLS(,AC_DEFINE(HAVE_GNUTLS,,"Use libgnutls"))
dnl Check -Wall flag of GCC
if test "x$GCC" = "xyes"; then
@ -55,35 +54,6 @@ if test "x$GCC" = "xyes"; then
fi
fi
AC_DEFUN([AX_COMPILER_VENDOR],
[
AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
[ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=unknown
# note: don't check for gcc first since some other compilers define __GNUC__
for ventest in intel:__ICC,__ECC,__INTEL_COMPILER ibm:__xlc__,__xlC__,__IBMC__,__IBMCPP__ gnu:__GNUC__ sun:__SUNPRO_C,__SUNPRO_CC hp:__HP_cc,__HP_aCC dec:__DECC,__DECCXX,__DECC_VER,__DECCXX_VER borland:__BORLANDC__,__TURBOC__ comeau:__COMO__ cray:_CRAYC kai:__KCC lcc:__LCC__ metrowerks:__MWERKS__ sgi:__sgi,sgi microsoft:_MSC_VER watcom:__WATCOMC__ portland:__PGI; do
vencpp="defined("`echo $ventest | cut -d: -f2 | sed 's/,/) || defined(/g'`")"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
#if !($vencpp)
thisisanerror;
#endif
])], [ax_cv_]_AC_LANG_ABBREV[_compiler_vendor=`echo $ventest | cut -d: -f1`; break])
done
])
])
AX_COMPILER_VENDOR
# Enable 64 bit build
AC_ARG_ENABLE(64,
[AC_HELP_STRING([--enable-64],[build with 64 bit support])],[enable_64="$enable_64"],[enable_64="no"])
if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then
if test "${enable_64}" = "yes"; then
CFLAGS="$CFLAGS -m64"
CXXFLAGS="$CXXFLAGS -m64"
fi
fi
dnl Generating makefiles
AC_CONFIG_FILES([
Makefile

File diff suppressed because it is too large Load Diff

View File

@ -594,28 +594,30 @@ Node contains an attribute and its value.
@deftypefun char* iks_name (iks* @var{x});
Returns the name of the tag for nodes with the type @var{IKS_TAG}.
Returns an attribute's name for nodes of type IKS_ATTRIBUTE.
@end deftypefun
@deftypefun char* iks_cdata (iks* @var{x});
Returns a pointer to node's character data if available, NULL otherwise.
Returns an attribute's value for nodes of type IKS_ATTRIBUTE.
@end deftypefun
@deftypefun size_t iks_cdata_size (iks* @var{x});
@deftypefun size_t iks_cdata_size (iks *@var{x});
Returns the size of the node's character data in bytes.
@end deftypefun
@deftypefun int iks_has_children (iks* @var{x});
@deftypefun int iks_has_children (iks *@var{x});
Returns a non-zero value if node @var{x} has a child node.
@end deftypefun
@deftypefun int iks_has_attribs (iks* @var{x});
@deftypefun int iks_has_attribs (iks *@var{x});
Returns a non-zero value if node @var{x} has attributes.
@end deftypefun
Last group of the functions simplifies finding and accessing the content
of a specific node:
@deftypefun iks* iks_find (iks* @var{x}, const char* @var{name});
@deftypefun iks* iks_find (iks *@var{x}, const char *@var{name});
Searches a IKS_TAG type of node with @var{name} as tag name in child
nodes of @var{x}. Returns a pointer to the node if found, NULL otherwise.
@end deftypefun

7210
libs/iksemel/doc/texinfo.tex Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2004 Gurer Ozen <madcat@e-kolay.net>
** Copyright (C) 2000-2007 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.
*/
@ -26,7 +26,6 @@ char *iks_stack_strcat (ikstack *s, char *old, size_t old_len, const char *src,
void iks_stack_stat (ikstack *s, size_t *allocated, size_t *used);
void iks_stack_delete (ikstack **sp);
/***** utilities *****/
void *iks_malloc (size_t size);
@ -63,6 +62,10 @@ iks *iks_insert (iks *x, const char *name);
iks *iks_insert_cdata (iks *x, const char *data, size_t len);
iks *iks_insert_attrib (iks *x, const char *name, const char *value);
iks *iks_insert_node (iks *x, iks *y);
iks *iks_append (iks *x, const char *name);
iks *iks_prepend (iks *x, const char *name);
iks *iks_append_cdata (iks *x, const char *data, size_t len);
iks *iks_prepend_cdata (iks *x, const char *data, size_t len);
void iks_hide (iks *x);
void iks_delete (iks *x);
iks *iks_next (iks *x);

View File

@ -33,6 +33,9 @@ basename="s,^.*/,,g"
# function.
progpath="$0"
# define SED for historic ltconfig's generated by Libtool 1.3
test -z "$SED" && SED=sed
# The name of this program:
progname=`echo "$progpath" | $SED $basename`
modename="$progname"
@ -51,6 +54,13 @@ TIMESTAMP=" (1.1220.2.365 2005/12/18 22:14:06)"
if test -n "${ZSH_VERSION+set}" ; then
setopt NO_GLOB_SUBST
fi
# Same for EGREP, and just to be sure, do LTCC as well
if test "X$EGREP" = X ; then
EGREP=egrep
fi
if test "X$LTCC" = X ; then
LTCC=${CC-gcc}
fi
# Check that we have a working $echo.
if test "X$1" = X--no-reexec; then
@ -137,6 +147,30 @@ preserve_args=
lo2o="s/\\.lo\$/.${objext}/"
o2lo="s/\\.${objext}\$/.lo/"
if test -z "$max_cmd_len"; then
i=0
testring="ABCD"
new_result=
# If test is not a shell built-in, we'll probably end up computing a
# maximum length that is only half of the actual maximum length, but
# we can't tell.
while (test "X"`$SHELL $0 --fallback-echo "X$testring" 2>/dev/null` \
= "XX$testring") >/dev/null 2>&1 &&
new_result=`expr "X$testring" : ".*" 2>&1` &&
max_cmd_len="$new_result" &&
test "$i" != 17 # 1/2 MB should be enough
do
i=`expr $i + 1`
testring="$testring$testring"
done
testring=
# Add a significant safety factor because C++ compilers can tack on massive
# amounts of additional arguments before passing them to the linker.
# It appears as though 1/2 is a usable value.
max_cmd_len=`expr $max_cmd_len \/ 2`
fi
#####################################
# Shell function definitions:
# This seems to be the best place for them
@ -257,7 +291,17 @@ func_infer_tag ()
esac
CC_quoted="$CC_quoted $arg"
done
# user sometimes does CC=<HOST>-gcc so we need to match that to 'gcc'
trimedcc=`echo ${CC} | $SED -e "s/${host}-//g"`
# and sometimes libtool has CC=<HOST>-gcc but user does CC=gcc
extendcc=${host}-${CC}
case "$@ " in
"cc "* | " cc "* | "${host}-cc "* | " ${host}-cc "*|\
"gcc "* | " gcc "* | "${host}-gcc "* | " ${host}-gcc "*)
tagname=CC
break ;;
"$trimedcc "* | " $trimedcc "* | "`$echo $trimedcc` "* | " `$echo $trimedcc` "*|\
"$extendcc "* | " $extendcc "* | "`$echo $extendcc` "* | " `$echo $extendcc` "*|\
" $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*)
# The compiler in the base compile command matches
# the one in the tagged configuration.
@ -851,7 +895,7 @@ if test -z "$show_help"; then
# Lock this critical section if it is needed
# We use this script file to make the link, it avoids creating a new file
if test "$need_locks" = yes; then
until $run ln "$progpath" "$lockfile" 2>/dev/null; do
until $run ln "$srcfile" "$lockfile" 2>/dev/null; do
$show "Waiting for $lockfile to be removed"
sleep 2
done
@ -3642,6 +3686,13 @@ EOF
*) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
esac
done
# It is ok to link against an archive when
# building a shared library.
if $AR -t $potlib > /dev/null 2>&1; then
newdeplibs="$newdeplibs $a_deplib"
a_deplib=""
break 2
fi
if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \
| ${SED} 10q \
| $EGREP "$file_magic_regex" > /dev/null; then
@ -5379,6 +5430,11 @@ else
$echo >> $output "\
if test \"\$libtool_execute_magic\" != \"$magic\"; then
# Run the actual program with our arguments.
# Make sure env LD_LIBRARY_PATH does not mess us up
if test -n \"\${LD_LIBRARY_PATH+set}\"; then
export LD_LIBRARY_PATH=\$progdir:\$LD_LIBRARY_PATH
fi
"
case $host in
# Backslashes separate directories on plain windows
@ -5606,9 +5662,48 @@ fi\
$echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2
exit $EXIT_FAILURE
fi
newdependency_libs="$newdependency_libs $libdir/$name"
if test "X$EGREP" = X ; then
EGREP=egrep
fi
# We do not want PiSi's install root ($INSTALL_ROOT) present. Check only for
# this if the .la is being installed.
if test "$installed" = yes && test "$INSTALL_ROOT"; then
eval mynewdependency_lib=`echo "$libdir/$name" |sed -e "s:$INSTALL_ROOT:/:g" -e 's:/\+:/:g'`
else
mynewdependency_lib="$libdir/$name"
fi
# Do not add duplicates
if test "$mynewdependency_lib"; then
my_little_ninja_foo_1=`echo $newdependency_libs |$EGREP -e "$mynewdependency_lib"`
if test -z "$my_little_ninja_foo_1"; then
newdependency_libs="$newdependency_libs $mynewdependency_lib"
fi
fi
;;
*)
if test "$installed" = yes; then
# We do not want PiSi's build root ($WORK_DIR) present.
my_little_ninja_foo_2=`echo $deplib |$EGREP -e "$WORK_DIR"`
# We do not want PiSi's install root ($INSTALL_ROOT) present.
my_little_ninja_foo_3=`echo $deplib |$EGREP -e "$INSTALL_ROOT"`
if test -n "$my_little_ninja_foo_2" && test "$WORK_DIR"; then
mynewdependency_lib=""
elif test -n "$my_little_ninja_foo_3" && test "$INSTALL_DIR"; then
eval mynewdependency_lib=`echo "$deplib" |sed -e "s:$INSTALL_DIR:/:g" -e 's:/\+:/:g'`
else
mynewdependency_lib="$deplib"
fi
else
mynewdependency_lib="$deplib"
fi
# Do not add duplicates
if test "$mynewdependency_lib"; then
my_little_ninja_foo_4=`echo $newdependency_libs |$EGREP -e "$mynewdependency_lib"`
if test -z "$my_little_ninja_foo_4"; then
newdependency_libs="$newdependency_libs $mynewdependency_lib"
fi
fi
;;
*) newdependency_libs="$newdependency_libs $deplib" ;;
esac
done
dependency_libs="$newdependency_libs"
@ -5660,6 +5755,10 @@ fi\
case $host,$output,$installed,$module,$dlname in
*cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
esac
# Do not add duplicates
if test "$installed" = yes && test "$INSTALL_DIR"; then
install_libdir=`echo "$install_libdir" |sed -e "s:$INSTALL_DIR:/:g" -e 's:/\+:/:g'`
fi
$echo > $output "\
# $outputname - a libtool library file
# Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP

View File

@ -24,6 +24,6 @@ libiksemel_la_SOURCES = \
md5.c \
base64.c
libiksemel_la_LDFLAGS = -version-info 3:0:0 -no-undefined
libiksemel_la_LDFLAGS = -version-info 4:0:1 -no-undefined
libiksemel_la_CFLAGS = $(CFLAGS) $(LIBGNUTLS_CFLAGS)
libiksemel_la_LIBADD = $(LIBGNUTLS_LIBS)

View File

@ -7,27 +7,30 @@
#include "common.h"
#include "iksemel.h"
static char base64_charset[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char base64_charset[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char *iks_base64_decode(const char *buf)
{
char *res, *save, *foo, val;
char *res, *save;
char val;
const char *foo;
const char *end;
int index;
size_t len;
if (!buf)
return NULL;
index = iks_strlen(buf)*6 / 8 + 1;
save = res = iks_malloc(index);
memset(res, 0, index);
index = 0;
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) {
@ -66,6 +69,7 @@ char *iks_base64_encode(const char *buf, int len)
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];
@ -85,14 +89,15 @@ char *iks_base64_encode(const char *buf, int len)
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++ = '=';
*res++ = '=';
*res = 0;
return save;
}

View File

@ -37,6 +37,8 @@ tagHook (struct dom_data *data, char *name, char **atts, int type)
}
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 {
@ -130,8 +132,9 @@ iks_load (const char *fname, iks **xptr)
if (len < FILE_IO_BUF_SIZE) {
if (0 == feof (f)) {
ret = IKS_FILE_RWERR;
len = 0;
break;
}
if (0 == len) ret = IKS_OK;
done = 1;
}
if (len > 0) {

View File

@ -1,5 +1,5 @@
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2004 Gurer Ozen <madcat@e-kolay.net>
** Copyright (C) 2000-2007 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.
*/
@ -183,6 +183,106 @@ iks_insert_node (iks *x, iks *y)
return y;
}
iks *
iks_append (iks *x, const char *name)
{
iks *y;
if (!x) return NULL;
y = iks_new_within (name, x->s);
if (!y) return NULL;
if (x->next) {
x->next->prev = y;
} else {
IKS_TAG_LAST_CHILD (x->parent) = y;
}
y->next = x->next;
x->next = y;
y->parent = x->parent;
y->prev = x;
return y;
}
iks *
iks_prepend (iks *x, const char *name)
{
iks *y;
if (!x) return NULL;
y = iks_new_within (name, x->s);
if (!y) return NULL;
if (x->prev) {
x->prev->next = y;
} else {
IKS_TAG_CHILDREN (x->parent) = y;
}
y->prev = x->prev;
x->prev = y;
y->parent = x->parent;
y->next = x;
return y;
}
iks *
iks_append_cdata (iks *x, const char *data, size_t len)
{
iks *y;
if (!x || !data) return NULL;
if (len == 0) len = strlen (data);
y = iks_new_within (NULL, x->s);
if (!y) return NULL;
y->type = IKS_CDATA;
IKS_CDATA_CDATA (y) = iks_stack_strdup (x->s, data, len);
if (!IKS_CDATA_CDATA (y)) return NULL;
IKS_CDATA_LEN (y) = len;
if (x->next) {
x->next->prev = y;
} else {
IKS_TAG_LAST_CHILD (x->parent) = y;
}
y->next = x->next;
x->next = y;
y->parent = x->parent;
y->prev = x;
return y;
}
iks *
iks_prepend_cdata (iks *x, const char *data, size_t len)
{
iks *y;
if (!x || !data) return NULL;
if (len == 0) len = strlen (data);
y = iks_new_within (NULL, x->s);
if (!y) return NULL;
y->type = IKS_CDATA;
IKS_CDATA_CDATA(y) = iks_stack_strdup (x->s, data, len);
if (!IKS_CDATA_CDATA (y)) return NULL;
IKS_CDATA_LEN (y) = len;
if (x->prev) {
x->prev->next = y;
} else {
IKS_TAG_CHILDREN (x->parent) = y;
}
y->prev = x->prev;
x->prev = y;
y->parent = x->parent;
y->next = x;
return y;
}
void
iks_hide (iks *x)
{
@ -379,7 +479,7 @@ char *
iks_name (iks *x)
{
if (x) {
if (IKS_TAG == x->type)
if (IKS_TAG == x->type)
return IKS_TAG_NAME (x);
else
return IKS_ATTRIB_NAME (x);

View File

@ -192,10 +192,11 @@ iks_stack_delete (ikstack **sp)
}
s = *sp;
if (!s) {
return;
}
*sp = NULL;
c = s->meta->next;
while (c) {
@ -210,5 +211,4 @@ iks_stack_delete (ikstack **sp)
c = tmp;
}
iks_free (s);
}

View File

@ -36,6 +36,7 @@ io_connect (iksparser *prs, void **socketptr, const char *server, int port)
struct addrinfo hints;
struct addrinfo *addr_res, *addr_ptr;
char port_str[6];
int err = 0;
hints.ai_flags = AI_CANONNAME;
hints.ai_family = PF_UNSPEC;
@ -52,14 +53,20 @@ io_connect (iksparser *prs, void **socketptr, const char *server, int port)
addr_ptr = addr_res;
while (addr_ptr) {
err = IKS_NET_NOSOCK;
sock = socket (addr_ptr->ai_family, addr_ptr->ai_socktype, addr_ptr->ai_protocol);
if (sock != -1) break;
if (sock != -1) {
err = IKS_NET_NOCONN;
tmp = connect (sock, addr_ptr->ai_addr, addr_ptr->ai_addrlen);
if (tmp == 0) break;
io_close ((void *) sock);
sock = -1;
}
addr_ptr = addr_ptr->ai_next;
}
if (sock == -1) return IKS_NET_NOSOCK;
tmp = connect (sock, addr_ptr->ai_addr, addr_ptr->ai_addrlen);
freeaddrinfo (addr_res);
if (sock == -1) return err;
#else
struct hostent *host;
struct sockaddr_in sin;
@ -74,11 +81,11 @@ io_connect (iksparser *prs, void **socketptr, const char *server, int port)
if (sock == -1) return IKS_NET_NOSOCK;
tmp = connect (sock, (struct sockaddr *)&sin, sizeof (struct sockaddr_in));
#endif
if (tmp != 0) {
io_close ((void *) sock);
return IKS_NET_NOCONN;
}
#endif
*socketptr = (void *) sock;
@ -135,7 +142,6 @@ io_recv (void *socket, char *buffer, size_t buf_len, int timeout)
}
t++;
}
}
}

View File

@ -173,8 +173,8 @@ iks_make_auth (iksid *id, const char *pass, const char *sid)
char buf[41];
iksha *sha;
sha = iks_sha_new ();
iks_sha_hash (sha, sid, strlen (sid), 0);
iks_sha_hash (sha, pass, strlen (pass), 1);
iks_sha_hash (sha, (const unsigned char*)sid, strlen (sid), 0);
iks_sha_hash (sha, (const unsigned char*)pass, strlen (pass), 1);
iks_sha_print (sha, buf);
iks_sha_delete (sha);
iks_insert_cdata (iks_insert (y, "digest"), buf, 40);

View File

@ -43,7 +43,7 @@ struct iksmd5_struct {
unsigned char blen;
};
static unsigned long int T[] =
static const unsigned long int T[] =
{ 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
@ -151,7 +151,7 @@ void iks_md5(const char *data, char *buf)
{
iksmd5 *md5 = iks_md5_new();
iks_md5_hash(md5, data, strlen(data), 1);
iks_md5_hash(md5, (const unsigned char*)data, strlen(data), 1);
iks_md5_print(md5, buf);
iks_md5_delete(md5);
}

View File

@ -149,7 +149,8 @@ stack_expand (iksparser *prs, int len)
if (need < prs->stack_max) {
need = prs->stack_max * 2;
} else {
need = prs->stack_max + (need * 1.2);
/* need x 1.2 for integer only archs like ARM */
need = prs->stack_max + ( (need * 6) / 5);
}
tmp = iks_malloc (need);
if (!tmp) return 0;

View File

@ -11,10 +11,10 @@ static void sha_buffer (iksha *sha, const unsigned char *data, int len);
static void sha_calculate (iksha *sha);
struct iksha_struct {
unsigned long hash[5];
unsigned long buf[80];
unsigned int hash[5];
unsigned int buf[80];
int blen;
unsigned long lenhi, lenlo;
unsigned int lenhi, lenlo;
};
iksha *
@ -32,11 +32,11 @@ void
iks_sha_reset (iksha *sha)
{
memset (sha, 0, sizeof (iksha));
sha->hash[0] = 0x67452301L;
sha->hash[1] = 0xefcdab89L;
sha->hash[2] = 0x98badcfeL;
sha->hash[3] = 0x10325476L;
sha->hash[4] = 0xc3d2e1f0L;
sha->hash[0] = 0x67452301;
sha->hash[1] = 0xefcdab89;
sha->hash[2] = 0x98badcfe;
sha->hash[3] = 0x10325476;
sha->hash[4] = 0xc3d2e1f0;
}
void
@ -74,7 +74,7 @@ iks_sha_print (iksha *sha, char *hash)
for (i=0; i<5; i++)
{
sprintf (hash, "%08lx", sha->hash[i]);
sprintf (hash, "%08x", sha->hash[i]);
hash += 8;
}
}
@ -91,7 +91,7 @@ iks_sha (const char *data, char *hash)
iksha *sha;
sha = iks_sha_new ();
iks_sha_hash (sha, data, strlen (data), 1);
iks_sha_hash (sha, (const unsigned char*)data, strlen (data), 1);
iks_sha_print (sha, hash);
iks_free (sha);
}
@ -103,7 +103,7 @@ sha_buffer (iksha *sha, const unsigned char *data, int len)
for (i=0; i<len; i++) {
sha->buf[sha->blen / 4] <<= 8;
sha->buf[sha->blen / 4] |= (unsigned long)data[i];
sha->buf[sha->blen / 4] |= (unsigned int)data[i];
if ((++sha->blen) % 64 == 0) {
sha_calculate (sha);
sha->blen = 0;
@ -128,7 +128,7 @@ static void
sha_calculate (iksha *sha)
{
int i;
unsigned long A, B, C, D, E, TMP;
unsigned int A, B, C, D, E, TMP;
for (i=16; i<80; i++)
sha->buf[i] = SRL (sha->buf[i-3] ^ sha->buf[i-8] ^ sha->buf[i-14] ^ sha->buf[i-16], 1);
@ -139,10 +139,10 @@ sha_calculate (iksha *sha)
D = sha->hash[3];
E = sha->hash[4];
SHA (0, 19, ((C^D)&B)^D, 0x5a827999L);
SHA (20, 39, B^C^D, 0x6ed9eba1L);
SHA (40, 59, (B&C)|(D&(B|C)), 0x8f1bbcdcL);
SHA (60, 79, B^C^D, 0xca62c1d6L);
SHA (0, 19, ((C^D)&B)^D, 0x5a827999);
SHA (20, 39, B^C^D, 0x6ed9eba1);
SHA (40, 59, (B&C)|(D&(B|C)), 0x8f1bbcdc);
SHA (60, 79, B^C^D, 0xca62c1d6);
sha->hash[0] += A;
sha->hash[1] += B;

View File

@ -1,5 +1,5 @@
/* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2004 Gurer Ozen <madcat@e-kolay.net>
** Copyright (C) 2000-2007 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.
*/
@ -122,106 +122,143 @@ insert_attribs (iks *x, char **atts)
#define CNONCE_LEN 4
static void
iks_sasl_challenge (struct stream_data *data, iks *challenge)
parse_digest (char *message, const char *key, char **value_ptr, char **value_end_ptr)
{
char *b;
iks *x;
char *t;
b = iks_cdata (iks_child (challenge));
if (!b) return;
*value_ptr = NULL;
*value_end_ptr = NULL;
b = iks_base64_decode (b);
t = strstr(message, key);
if (t) {
t += strlen(key);
*value_ptr = t;
while (t[0] != '\0') {
if (t[0] != '\\' && t[1] == '"') {
++t;
*value_end_ptr = t;
return;
}
++t;
}
}
}
if (strstr (b, "rspauth")) {
x = iks_new("response");
static iks *
make_sasl_response (struct stream_data *data, char *message)
{
iks *x = NULL;
char *realm, *realm_end;
char *nonce, *nonce_end;
char cnonce[CNONCE_LEN*8 + 1];
iksmd5 *md5;
unsigned char a1_h[16], a1[33], a2[33], response_value[33];
char *response, *response_coded;
int i;
parse_digest(message, "realm=\"", &realm, &realm_end);
parse_digest(message, "nonce=\"", &nonce, &nonce_end);
/* nonce is necessary for auth */
if (!nonce || !nonce_end) return NULL;
*nonce_end = '\0';
/* if no realm is given use the server hostname */
if (realm) {
if (!realm_end) return NULL;
*realm_end = '\0';
} else {
char *realm, *nonce, *charset = NULL, *algorithm = NULL;
char *realm_end, *nonce_end, cnonce[CNONCE_LEN*8 + 1];
unsigned char a1_h[16], a1[33], a2[33], response_value[33];
char *response, *response_coded;
iksmd5 *md5;
int i;
realm = (char *) data->server;
}
realm = strstr (b, "realm");
if (realm) {
realm += 7;
do {
realm_end = strchr(realm, '"');
} while (*(realm_end - 1) == '\\');
} else {
realm_end = 0;
realm = (char *) data->server;
}
nonce = strstr (b, "nonce");
if (nonce) {
nonce += 7;
do {
nonce_end = strchr (nonce, '"');
} while (*(nonce - 1) == '\\');
} else {
iks_free (b);
return;
}
charset = strstr (b, "charset");
if (charset) charset += 8;
algorithm = strstr (b, "algorithm");
if (algorithm) algorithm += 10;
if (realm_end) *realm_end = 0;
*nonce_end = 0;
/* generate random client challenge */
for (i = 0; i < CNONCE_LEN; ++i)
sprintf (cnonce + i*8, "%08x", rand());
for (i = 0; i < CNONCE_LEN; ++i)
sprintf (cnonce + i*8, "%08x", rand());
md5 = iks_md5_new();
if (!md5) return NULL;
md5 = iks_md5_new();
iks_md5_hash (md5, data->auth_username, iks_strlen (data->auth_username), 0);
iks_md5_hash (md5, ":", 1, 0);
iks_md5_hash (md5, realm, iks_strlen (realm), 0);
iks_md5_hash (md5, ":", 1, 0);
iks_md5_hash (md5, data->auth_pass, iks_strlen (data->auth_pass), 1);
iks_md5_digest (md5, a1_h);
iks_md5_reset (md5);
iks_md5_hash (md5, a1_h, 16, 0);
iks_md5_hash (md5, ":", 1, 0);
iks_md5_hash (md5, nonce, iks_strlen (nonce), 0);
iks_md5_hash (md5, ":", 1, 0);
iks_md5_hash (md5, cnonce, iks_strlen (cnonce), 1);
iks_md5_print (md5, a1);
iks_md5_reset (md5);
iks_md5_hash (md5, "AUTHENTICATE:xmpp/", 18, 0);
iks_md5_hash (md5, data->server, iks_strlen (data->server), 1);
iks_md5_print (md5, a2);
iks_md5_reset (md5);
iks_md5_hash (md5, a1, 32, 0);
iks_md5_hash (md5, ":", 1, 0);
iks_md5_hash (md5, nonce, iks_strlen (nonce), 0);
iks_md5_hash (md5, ":00000001:", 10, 0);
iks_md5_hash (md5, cnonce, iks_strlen (cnonce), 0);
iks_md5_hash (md5, ":auth:", 6, 0);
iks_md5_hash (md5, a2, 32, 1);
iks_md5_print (md5, response_value);
iks_md5_delete (md5);
iks_md5_hash (md5, (const unsigned char*)data->auth_username, iks_strlen (data->auth_username), 0);
iks_md5_hash (md5, (const unsigned char*)":", 1, 0);
iks_md5_hash (md5, (const unsigned char*)realm, iks_strlen (realm), 0);
iks_md5_hash (md5, (const unsigned char*)":", 1, 0);
iks_md5_hash (md5, (const unsigned char*)data->auth_pass, iks_strlen (data->auth_pass), 1);
iks_md5_digest (md5, a1_h);
i = iks_strlen (data->auth_username) + iks_strlen (realm) +
iks_strlen (nonce) + iks_strlen (data->server) +
CNONCE_LEN*8 + 136;
response = iks_malloc (i);
sprintf (response, "username=\"%s\",realm=\"%s\",nonce=\"%s\""
",cnonce=\"%s\",nc=00000001,qop=auth,digest-uri=\""
"xmpp/%s\",response=%s,charset=utf-8",
data->auth_username, realm, nonce, cnonce,
data->server, response_value);
response_coded = iks_base64_encode (response, 0);
iks_md5_reset (md5);
iks_md5_hash (md5, (const unsigned char*)a1_h, 16, 0);
iks_md5_hash (md5, (const unsigned char*)":", 1, 0);
iks_md5_hash (md5, (const unsigned char*)nonce, iks_strlen (nonce), 0);
iks_md5_hash (md5, (const unsigned char*)":", 1, 0);
iks_md5_hash (md5, (const unsigned char*)cnonce, iks_strlen (cnonce), 1);
iks_md5_print (md5, (char*)a1);
iks_md5_reset (md5);
iks_md5_hash (md5, (const unsigned char*)"AUTHENTICATE:xmpp/", 18, 0);
iks_md5_hash (md5, (const unsigned char*)data->server, iks_strlen (data->server), 1);
iks_md5_print (md5, (char*)a2);
iks_md5_reset (md5);
iks_md5_hash (md5, (const unsigned char*)a1, 32, 0);
iks_md5_hash (md5, (const unsigned char*)":", 1, 0);
iks_md5_hash (md5, (const unsigned char*)nonce, iks_strlen (nonce), 0);
iks_md5_hash (md5, (const unsigned char*)":00000001:", 10, 0);
iks_md5_hash (md5, (const unsigned char*)cnonce, iks_strlen (cnonce), 0);
iks_md5_hash (md5, (const unsigned char*)":auth:", 6, 0);
iks_md5_hash (md5, (const unsigned char*)a2, 32, 1);
iks_md5_print (md5, (char*)response_value);
iks_md5_delete (md5);
i = iks_strlen (data->auth_username) + iks_strlen (realm) +
iks_strlen (nonce) + iks_strlen (data->server) +
CNONCE_LEN*8 + 136;
response = iks_malloc (i);
if (!response) return NULL;
sprintf (response, "username=\"%s\",realm=\"%s\",nonce=\"%s\""
",cnonce=\"%s\",nc=00000001,qop=auth,digest-uri=\""
"xmpp/%s\",response=%s,charset=utf-8",
data->auth_username, realm, nonce, cnonce,
data->server, response_value);
response_coded = iks_base64_encode (response, 0);
if (response_coded) {
x = iks_new ("response");
iks_insert_cdata (x, response_coded, 0);
iks_free (response);
iks_free (response_coded);
}
iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL);
iks_send (data->prs, x);
iks_delete (x);
iks_free (b);
iks_free (response);
return x;
}
static void
iks_sasl_challenge (struct stream_data *data, iks *challenge)
{
char *message;
iks *x;
char *tmp;
tmp = iks_cdata (iks_child (challenge));
if (!tmp) return;
/* decode received blob */
message = iks_base64_decode (tmp);
if (!message) return;
/* reply the challenge */
if (strstr (message, "rspauth")) {
x = iks_new ("response");
} else {
x = make_sasl_response (data, message);
}
if (x) {
iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL);
iks_send (data->prs, x);
iks_delete (x);
}
iks_free (message);
}
static int

View File

@ -17,6 +17,8 @@ int main (int argc, char *argv[])
"<iq type='result' to='ydobon@jabber.org'><query xmlns='jabber:iq:version'>"
"<name>TestClient</name><os>SuxOS 2000</os><version><stable solidity='rock'/>"
"1.2.0 patchlevel 2</version></query></iq>";
static char xml2[] =
"<Ni><C/>lala<br/><A/>Hello World<B/></Ni>";
iks *x, *y, *z;
char *t;
@ -52,5 +54,24 @@ int main (int argc, char *argv[])
}
iks_delete(x);
x = iks_new ("Ni");
y = iks_insert (x, "br");
z = iks_prepend_cdata (y, "lala", 4);
iks_prepend (z, "C");
z = iks_insert_cdata (x, "Hello", 5);
y = iks_append (z, "B");
iks_prepend (z, "A");
iks_append_cdata (z, " ", 1);
iks_prepend_cdata (y, "World", 5);
t = iks_string (iks_stack (x), x);
if(!t || strcmp(t, xml2) != 0) {
printf("Result: %s\n", t);
printf("Expected: %s\n", xml2);
return 1;
}
iks_delete(x);
return 0;
}