Mercurial > pidgin.yaz
changeset 3127:4e7cefc55971
[gaim-migrate @ 3142]
Upgraded jabber to most recent stable version
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 04 Apr 2002 03:04:57 +0000 |
parents | e883f604174e |
children | 8249e2c4b7ed |
files | src/protocols/jabber/Makefile.am src/protocols/jabber/expat.c src/protocols/jabber/genhash.c src/protocols/jabber/hashtable.c src/protocols/jabber/jid.c src/protocols/jabber/jpacket.c src/protocols/jabber/jutil.c src/protocols/jabber/karma.c src/protocols/jabber/lib.h src/protocols/jabber/pool.c src/protocols/jabber/pproxy.c src/protocols/jabber/rate.c src/protocols/jabber/sha.c src/protocols/jabber/snprintf.c src/protocols/jabber/socket.c src/protocols/jabber/str.c src/protocols/jabber/xhash.c src/protocols/jabber/xmlnode.c src/protocols/jabber/xmlparse.c src/protocols/jabber/xmlrole.c src/protocols/jabber/xmltok.c src/protocols/jabber/xmltok_impl.c src/protocols/jabber/xmltok_ns.c src/protocols/jabber/xstream.c |
diffstat | 24 files changed, 1759 insertions(+), 867 deletions(-) [+] |
line wrap: on
line diff
--- a/src/protocols/jabber/Makefile.am Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/Makefile.am Thu Apr 04 03:04:57 2002 +0000 @@ -17,8 +17,10 @@ genhash.c \ hashtable.c \ hashtable.h \ + karma.c \ iasciitab.h \ latin1tab.h \ + lib.h \ libxode.h \ nametab.h \ pool.c \ @@ -27,6 +29,7 @@ socket.c \ str.c \ utf8tab.h \ + xhash.c \ xmldef.h \ xmlnode.c \ xmlparse.c \ @@ -63,7 +66,9 @@ hashtable.c \ hashtable.h \ iasciitab.h \ + karma.c \ latin1tab.h \ + lib.h \ libxode.h \ nametab.h \ pool.c \ @@ -72,6 +77,7 @@ socket.c \ str.c \ utf8tab.h \ + xhash.c \ xmldef.h \ xmlnode.c \ xmlparse.c \
--- a/src/protocols/jabber/expat.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/expat.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,23 +1,45 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include <libxode.h> +#include "lib.h" void expat_startElement(void* userdata, const char* name, const char** atts) { @@ -128,15 +150,45 @@ return node; /* return the xmlnode x points to */ } +char* xmlnode_file_borked(char *file) +{ + XML_Parser p; + char buf[BUFSIZ]; + static char err[1024]; + int fd, len, done; + + if(NULL == file) + return "no file specified"; + + fd = open(file,O_RDONLY); + if(fd < 0) + return "unable to open file"; + + p = XML_ParserCreate(NULL); + while(1) + { + len = read(fd, buf, BUFSIZ); + done = len < BUFSIZ; + if(!XML_Parse(p, buf, len, done)) + { + snprintf(err,1023,"%s at line %d and column %d",XML_ErrorString(XML_GetErrorCode(p)),XML_GetErrorLineNumber(p),XML_GetErrorColumnNumber(p)); + XML_ParserFree(p); + close(fd); + return err; + } + } +} + int xmlnode2file(char *file, xmlnode node) { - char *doc; + char *doc, *ftmp; int fd, i; if(file == NULL || node == NULL) return -1; - fd = open(file, O_CREAT | O_WRONLY | O_TRUNC, 0600); + ftmp = spools(xmlnode_pool(node),file,".t.m.p",xmlnode_pool(node)); + fd = open(ftmp, O_CREAT | O_WRONLY | O_TRUNC, 0600); if(fd < 0) return -1; @@ -146,6 +198,12 @@ return -1; close(fd); + + if(rename(ftmp,file) < 0) + { + unlink(ftmp); + return -1; + } return 1; }
--- a/src/protocols/jabber/genhash.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/genhash.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,490 +1,101 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ -#include <libxode.h> - -/***************************************************************************** - * Internal type definitions - */ - -typedef struct tagHNODE -{ - struct tagHNODE *next; /* next node in list */ - const void *key; /* key pointer */ - void *value; /* value pointer */ -} HNODE; - -#define SLAB_NUM_NODES 64 /* allocate this many nodes per slab */ - -typedef struct tagHSLAB -{ - struct tagHSLAB *next; /* next slab pointer */ - HNODE nodes[SLAB_NUM_NODES]; /* the actual nodes */ -} HSLAB; - -#define HASH_NUM_BUCKETS 509 /* should be a prime number; see Knuth */ - -typedef struct tagHASHTABLE_INTERNAL -{ - unsigned long sig1; /* first signature word */ - KEYHASHFUNC hash; /* hash function */ - KEYCOMPAREFUNC cmp; /* comparison function */ - int count; /* table entry count */ - int bcount; /* bucket count */ - HNODE **buckets; /* the hash buckets */ - unsigned long sig2; /* second signature word */ - -} HASHTABLE_INTERNAL; - -#define HASH_SIG1 0x68736148UL /* "Hash" */ -#define HASH_SIG2 0x6F627245UL /* "Erbo" */ - -#define do_hash(tb,key) ((*((tb)->hash))(key) % ((tb)->bcount)) - -static HNODE *s_free_nodes = NULL; /* free nodes list */ -static HSLAB *s_slabs = NULL; /* node slabs list */ - -/***************************************************************************** - * Internal functions - */ - -static HNODE *allocate_node( - const void *key, /* key pointer for this node */ - void *value) /* value pointer for this node */ -/* - allocate_node allocates a new hash node and fills it. Returns NULL if the - node could not be allocated. -*/ -{ - HNODE *rc; /* return from this function */ + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. + * + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ - if (!s_free_nodes) - { /* allocate a new slabful of nodes and chain them to make a new free list */ - register int i; /* loop counter */ - HSLAB *slab = (HSLAB *)malloc(sizeof(HSLAB)); - if (!slab) - return NULL; - memset(slab,0,sizeof(HSLAB)); - slab->next = s_slabs; - for (i=0; i<(SLAB_NUM_NODES-1); i++) - slab->nodes[i].next = &(slab->nodes[i+1]); - s_free_nodes = &(slab->nodes[0]); - s_slabs = slab; - - } /* end if */ +#include "lib.h" - /* grab a node off the fron of the free list and fill it */ - rc = s_free_nodes; - s_free_nodes = rc->next; - rc->next = NULL; - rc->key = key; - rc->value = value; - return rc; - -} /* end allocate_node */ - -static void free_node( - HNODE *node) /* node to be freed */ -/* - free_node returns a hash node to the list. -*/ -{ - /* zap the node contents to avoid problems later */ - memset(node,0,sizeof(HNODE)); - - /* chain it onto the free list */ - node->next = s_free_nodes; - s_free_nodes = node; +/*** stubs that hook back to new xhash */ -} /* end free_node */ - -static HNODE *find_node( - HASHTABLE_INTERNAL *tab, /* pointer to hash table */ - const void *key, /* key value to look up */ - int bucket) /* bucket number (-1 to have function compute it) */ -/* - find_node walks a hash bucket to find a node whose key matches the named key value. - Returns the node pointer, or NULL if it's not found. -*/ +HASHTABLE ghash_create(int buckets, KEYHASHFUNC hash, KEYCOMPAREFUNC cmp) { - register HNODE *p; /* search pointer/return from this function */ - - if (bucket<0) /* compute hash value if we don't know it already */ - bucket = do_hash(tab,key); - - /* search through the bucket contents */ - for (p=tab->buckets[bucket]; p; p=p->next) - if ((*(tab->cmp))(key,p->key)==0) - return p; /* found! */ - - return NULL; /* not found */ - -} /* end find_node */ - -static HASHTABLE_INTERNAL *handle2ptr( - HASHTABLE tbl) /* hash table handle */ -/* - handle2ptr converts a hash table handle into a pointer and checks its signatures - to make sure someone's not trying to pull a whizzer on this module. -*/ -{ - register HASHTABLE_INTERNAL *rc = (HASHTABLE_INTERNAL *)tbl; - if ((rc->sig1==HASH_SIG1) && (rc->sig2==HASH_SIG2)) - return rc; /* signatures match */ - else - return NULL; /* yIkes! */ + return xhash_new(buckets); } -/***************************************************************************** - * External functions - */ - -HASHTABLE ghash_create(int buckets, KEYHASHFUNC hash, KEYCOMPAREFUNC cmp) -/* - Description: - Creates a new hash table. - - Input: - Parameters: - buckets - Number of buckets to allocate for the hash table; this value - should be a prime number for maximum efficiency. - hash - Key hash code function to use. - cmp - Key comparison function to use. - - Output: - Returns: - NULL - Table could not be allocated. - Other - Handle to the new hashtable. -*/ +HASHTABLE ghash_create_pool(pool p, int buckets, KEYHASHFUNC hash, KEYCOMPAREFUNC cmp) { - HASHTABLE_INTERNAL *tab; /* new table structure */ - char *allocated; - - if (!hash || !cmp) - return NULL; /* bogus! */ - - if (buckets<=0) - buckets = HASH_NUM_BUCKETS; - - /* allocate a hash table structure */ - allocated = malloc(sizeof(HASHTABLE_INTERNAL) + (buckets * sizeof(HNODE *))); - if (!allocated) - return NULL; /* memory error */ - - /* fill the fields of the hash table */ - tab = (HASHTABLE_INTERNAL *)allocated; - allocated += sizeof(HASHTABLE_INTERNAL); - memset(tab,0,sizeof(HASHTABLE_INTERNAL)); - memset(allocated,0,buckets * sizeof(HNODE *)); - tab->sig1 = HASH_SIG1; - tab->hash = hash; - tab->cmp = cmp; - tab->bcount = buckets; - tab->buckets = (HNODE **)allocated; - tab->sig2 = HASH_SIG2; - - return (HASHTABLE)tab; /* Qa'pla! */ - -} /* end ghash_create */ + xht h = xhash_new(buckets); + pool_cleanup(p, (pool_cleaner)xhash_free, h); + return h; +} void ghash_destroy(HASHTABLE tbl) -/* - Description: - Destroys a hash table. - - Input: - Parameters: - tbl - Table to be destroyed. - - Output: - Returns: - Nothing. -*/ { - HASHTABLE_INTERNAL *tab; /* new table structure */ - int i; /* loop counter */ - HNODE *p, *p2; /* temporary pointers */ - - if (!tbl) - return; /* bogus! */ - - /* Convert the handle to a table pointer. */ - tab = handle2ptr(tbl); - if (!tab) - return; - - /* Nuke the nodes it contains. */ - for (i=0; i<tab->bcount; i++) - { /* free the contents of each bucket */ - p = tab->buckets[i]; - while (p) - { /* free each node in turn */ - p2 = p->next; - free_node(p); - p = p2; - - } /* end while */ - - } /* end for */ - - free(tab); /* bye bye now! */ - -} /* end ghash_destroy */ + xhash_free(tbl); +} void *ghash_get(HASHTABLE tbl, const void *key) -/* - Description: - Retrieves a value stored in the hash table. - - Input: - Parameters: - tbl - The hash table to look in. - key - The key value to search on. - - Output: - Returns: - NULL - Value not found. - Other - Value corresponding to the specified key. -*/ { - HASHTABLE_INTERNAL *tab; /* internal table pointer */ - HNODE *node; /* hash node */ - void *rc = NULL; /* return from this function */ - - if (!tbl || !key) - return NULL; /* bogus! */ - - /* Convert the handle to a table pointer. */ - tab = handle2ptr(tbl); - if (!tab) - return NULL; /* error */ - - /* Attempt to find the node. */ - node = find_node(tab,key,-1); - if (node) - rc = node->value; /* found it! */ - - return rc; - -} /* end ghash_get */ + return xhash_get(tbl, key); +} int ghash_put(HASHTABLE tbl, const void *key, void *value) -/* - Description: - Associates a key with a value in this hash table. - - Input: - Parameters: - tbl - Hash table to add. - key - Key to use for the value in the table. - value - Value to add for this key. - - Output: - Returns: - 1 - Success. - 0 - Failure. - - Notes: - If the specified key is already in the hashtable, its value will be replaced. -*/ { - HASHTABLE_INTERNAL *tab; /* internal table pointer */ - int bucket; /* bucket value goes into */ - HNODE *node; /* hash node */ - int rc = 1; /* return from this function */ - - if (!tbl || !key || !value) - return 0; /* bogus! */ - - /* Convert the handle to a table pointer. */ - tab = handle2ptr(tbl); - if (!tab) - return 0; /* error */ - - - /* Compute the hash bucket and try to find an existing node. */ - bucket = do_hash(tab,key); - node = find_node(tab,key,bucket); - if (!node) - { /* OK, try to allocate a new node. */ - node = allocate_node(key,value); - if (node) - { /* Chain the new node into the hash table. */ - node->next = tab->buckets[bucket]; - tab->buckets[bucket] = node; - tab->count++; - - } /* end if */ - else /* allocation error */ - rc = 0; - - } /* end if */ - else /* already in table - just reassign value */ - node->value = value; - - return rc; - -} /* end ghash_put */ + xhash_put(tbl, key, value); + return 1; +} int ghash_remove(HASHTABLE tbl, const void *key) -/* - Description: - Removes an entry from a hash table, given its key. - - Input: - Parameters: - tbl - Hash table to remove from. - key - Key of value to remove. - - Output: - Returns: - 1 - Success. - 0 - Failure; key not present in hash table. -*/ { - HASHTABLE_INTERNAL *tab; /* internal table pointer */ - int bucket; /* bucket value goes into */ - HNODE *node; /* hash node */ - register HNODE *p; /* removal pointer */ - int rc = 1; /* return from this function */ - - if (!tbl || !key) - return 0; /* bogus! */ + xhash_zap(tbl, key); + return 1; +} - /* Convert the handle to a table pointer. */ - tab = handle2ptr(tbl); - if (!tab) - return 0; /* error */ - - - /* Compute the hash bucket and try to find an existing node. */ - bucket = do_hash(tab,key); - node = find_node(tab,key,bucket); - if (node) - { /* look to unchain it from the bucket it's in */ - if (node==tab->buckets[bucket]) - tab->buckets[bucket] = node->next; /* unchain at head */ - else - { /* unchain in middle of list */ - for (p=tab->buckets[bucket]; p->next!=node; p=p->next) ; - p->next = node->next; - - } /* end else */ - - free_node(node); /* bye bye now! */ - tab->count--; - - } /* end if */ - else /* node not found */ - rc = 0; - - return rc; - -} /* end ghash_remove */ int ghash_walk(HASHTABLE tbl, TABLEWALKFUNC func, void *user_data) -/* - Description: - "Walks" through a hash table, calling a callback function for each element - stored in it. - - Input: - Parameters: - tbl - Hash table to walk. - func - Function to be called for each node. It takes three parameters, - a user data pointer, a key value pointer, and a data value pointer. - It returns 0 to stop the enumeration or 1 to keep it going. - user_data - Value to use as the first parameter for the callback - function. +{ + int i; + xhn n; + xht h = (xht)tbl; - Output: - Returns: - 0 - Error occurred. - Other - Number of nodes visited up to and including the one for which - the callback function returned 0, if it did; ranges from 1 - to the number of nodes in the hashtable. -*/ -{ - HASHTABLE_INTERNAL *tab; /* internal table pointer */ - int i; /* loop counter */ - int running = 1; /* we're still running */ - int count = 0; /* number of nodes visited before stop node */ - register HNODE *p, *p2; /* loop pointer */ + for(i = 0; i < h->prime; i++) + for(n = &h->zen[i]; n != NULL; n = n->next) + if(n->key != NULL && n->val != NULL) + (*func)(user_data, n->key, n->val); - if (!tbl || !func) - return -1; /* bogus values! */ - - /* Convert the handle to a table pointer. */ - tab = handle2ptr(tbl); - if (!tab) - return -1; /* error */ + return 1; +} - for (i=0; running && (i<tab->bcount); i++) - { /* visit the contents of each bucket */ - p = tab->buckets[i]; - while (running && p) - { /* visit each node in turn */ - p2 = p->next; - count++; - running = (*func)(user_data,p->key,p->value); - p = p2; - - } /* end while */ - - } /* end for */ - - return count; - -} /* end ghash_walk */ - +int _xhasher(const char *key); int str_hash_code(const char *s) -/* - Description: - Generates a hash code for a string. This function uses the ELF hashing - algorithm as reprinted in Andrew Binstock, "Hashing Rehashed," _Dr. - Dobb's Journal_, April 1996. - - Input: - Parameters: - s - The string to be hashed. - - Output: - Returns: - A hash code for the string. -*/ { - /* ELF hash uses unsigned chars and unsigned arithmetic for portability */ - const unsigned char *name = (const unsigned char *)s; - unsigned long h = 0, g; - - if (!name) - return 0; /* anti-NULL guard not in the original */ + return _xhasher(s); +} - while (*name) - { /* do some fancy bitwanking on the string */ - h = (h << 4) + (unsigned long)(*name++); - if ((g = (h & 0xF0000000UL))!=0) - h ^= (g >> 24); - h &= ~g; - - } /* end while */ - - return (int)h; - -}
--- a/src/protocols/jabber/hashtable.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/hashtable.c Thu Apr 04 03:04:57 2002 +0000 @@ -17,15 +17,6 @@ Contributor(s): -Alternatively, the contents of this file may be used under the terms -of the GNU General Public License (the "GPL"), in which case the -provisions of the GPL are applicable instead of those above. If you -wish to allow use of your version of this file only under the terms of -the GPL and not to allow others to use your version of this file under -the MPL, indicate your decision by deleting the provisions above and -replace them with the notice and other provisions required by the -GPL. If you do not delete the provisions above, a recipient may use -your version of this file under either the MPL or the GPL. */ #include "xmldef.h"
--- a/src/protocols/jabber/jid.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/jid.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,27 +1,49 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include "jabber.h" +#include "lib.h" jid jid_safe(jid id) { - char *str; + unsigned char *str; if(strlen(id->server) == 0 || strlen(id->server) > 255) return NULL; @@ -57,10 +79,8 @@ str = pstrdup(p, idstr); - id = pmalloc(p,sizeof(struct jid_struct)); - id->full = id->server = id->user = id->resource = NULL; + id = pmalloco(p,sizeof(struct jid_struct)); id->p = p; - id->next = NULL; resource = strstr(str,"/"); if(resource != NULL) @@ -285,3 +305,17 @@ return cur; } + +jid jid_user(jid a) +{ + jid ret; + + if(a == NULL || a->resource == NULL) return a; + + ret = pmalloco(a->p,sizeof(struct jid_struct)); + ret->p = a->p; + ret->user = a->user; + ret->server = a->server; + + return ret; +}
--- a/src/protocols/jabber/jpacket.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/jpacket.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,23 +1,45 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include "jabber.h" +#include "lib.h" jpacket jpacket_new(xmlnode x) { @@ -55,6 +77,10 @@ p->subtype = JPACKET__UNAVAILABLE; else if(strcmp(val,"probe") == 0) p->subtype = JPACKET__PROBE; + else if(strcmp(val,"error") == 0) + p->subtype = JPACKET__ERROR; + else if(strcmp(val,"invisible") == 0) + p->subtype = JPACKET__INVISIBLE; else if(*val == 's' || *val == 'u') p->type = JPACKET_S10N; else if(strcmp(val,"available") == 0)
--- a/src/protocols/jabber/jutil.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/jutil.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,4 +1,45 @@ -#include "jabber.h" +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. + * + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ + +#include "lib.h" /* util for making presence packets */ xmlnode jutil_presnew(int type, char *to, char *status) @@ -26,6 +67,9 @@ case JPACKET__UNAVAILABLE: xmlnode_put_attrib(pres,"type","unavailable"); break; + case JPACKET__INVISIBLE: + xmlnode_put_attrib(pres,"type","invisible"); + break; } if(to != NULL) xmlnode_put_attrib(pres,"to",to);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/protocols/jabber/karma.c Thu Apr 04 03:04:57 2002 +0000 @@ -0,0 +1,144 @@ +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. + * + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ +#include "lib.h" + +void karma_copy(struct karma *new, struct karma *old) +{ + new->init = old->init; + new->val = old->val; + new->bytes = old->bytes; + new->max = old->max; + new->inc = old->inc; + new->dec = old->dec; + new->penalty = old->penalty; + new->restore = old->restore; + new->last_update = old->last_update; + new->reset_meter = old->reset_meter; +} + +struct karma *karma_new(pool p) +{ + struct karma *new; + if(p == NULL) + return NULL; + + new = pmalloco(p, sizeof(struct karma)); + new->init = 0; + new->bytes = 0; + new->val = KARMA_INIT; + new->max = KARMA_MAX; + new->inc = KARMA_INC; + new->dec = KARMA_DEC; + new->penalty = KARMA_PENALTY; + new->restore = KARMA_RESTORE; + new->last_update = 0; + new->reset_meter = KARMA_RESETMETER; + + return new; +} + +void karma_increment(struct karma *k) +{ + /* set the current time, and check if we can increment */ + time_t cur_time = time(NULL); + int punishment_over = 0; + + /* only increment every KARMA_HEARTBEAT seconds */ + if( ( k->last_update + KARMA_HEARTBEAT > cur_time ) && k->last_update != 0) + return; + + /* if incrementing will raise >= 0 */ + if( ( k->val < 0 ) && ( k->val + k->inc >= 0 ) ) + punishment_over = 1; + + /* increment the karma value */ + k->val += k->inc; + if( k->val > k->max ) k->val = k->max; /* can only be so good */ + + /* lower our byte count, if we have good karma */ + if( k->val > 0 ) k->bytes -= ( KARMA_READ_MAX(k->val) ); + if( k->bytes < 0 ) k->bytes = 0; + + /* our karma has *raised* to 0 */ + if( punishment_over ) + /* Set Restore value and clear byte meter */ + { + k->val = k->restore; + /* Total absolution for transgression */ + if(k->reset_meter) k->bytes = 0; + } + + /* reset out counter */ + k->last_update = cur_time; +} + +void karma_decrement(struct karma *k, long bytes_read) +{ + + /* Increment the bytes read since last since last karma_increment */ + k->bytes += bytes_read; + + /* Check if our byte meter has exceeded the Max bytes our meter is allowed. */ + + if(k->bytes > KARMA_READ_MAX(k->val)) + { + /* Our meter has exceeded it's allowable lower our karma */ + k->val -= k->dec; + + /* if below zero, set to penalty */ + if(k->val <= 0) k->val = k->penalty; + } +} + +/* returns 0 on okay check, 1 on bad check */ +int karma_check(struct karma *k,long bytes_read) +{ + /* Check the need to increase or decrease karma */ + karma_increment(k); + karma_decrement(k, bytes_read); + + /* check its karma */ + if(k->val <= 0) + return 1; /* bad */ + + /* everything is okay */ + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/protocols/jabber/lib.h Thu Apr 04 03:04:57 2002 +0000 @@ -0,0 +1,678 @@ + +#include <string.h> +#include <stdlib.h> +#include <sys/types.h> +#include <stdio.h> +#include <setjmp.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <signal.h> +#include <syslog.h> +#include <strings.h> +#include <unistd.h> +#include <sys/param.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <arpa/inet.h> +#include <sys/time.h> +#include <stdarg.h> +#include <ctype.h> +#include <time.h> + +#include "xmlparse.h" + +/* +** Arrange to use either varargs or stdargs +*/ + +#define MAXSHORTSTR 203 /* max short string length */ +#define QUAD_T unsigned long long + +#ifdef __STDC__ + +#include <stdarg.h> + +# define VA_LOCAL_DECL va_list ap; +# define VA_START(f) va_start(ap, f) +# define VA_END va_end(ap) + +#else /* __STDC__ */ + +# include <varargs.h> + +# define VA_LOCAL_DECL va_list ap; +# define VA_START(f) va_start(ap) +# define VA_END va_end(ap) + +#endif /* __STDC__ */ + + +#ifndef INCL_LIB_H +#define INCL_LIB_H + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifndef HAVE_SNPRINTF +extern int ap_snprintf(char *, size_t, const char *, ...); +#define snprintf ap_snprintf +#endif + +#ifndef HAVE_VSNPRINTF +extern int ap_vsnprintf(char *, size_t, const char *, va_list ap); +#define vsnprintf ap_vsnprintf +#endif + +#define ZONE zonestr(__FILE__,__LINE__) +char *zonestr(char *file, int line); + +/* --------------------------------------------------------- */ +/* */ +/* Pool-based memory management routines */ +/* */ +/* --------------------------------------------------------- */ + +#undef POOL_DEBUG +/* + flip these, this should be a prime number for top # of pools debugging +#define POOL_DEBUG 40009 +*/ + +/* pheap - singular allocation of memory */ +struct pheap +{ + void *block; + int size, used; +}; + +/* pool_cleaner - callback type which is associated + with a pool entry; invoked when the pool entry is + free'd */ +typedef void (*pool_cleaner)(void *arg); + +/* pfree - a linked list node which stores an + allocation chunk, plus a callback */ +struct pfree +{ + pool_cleaner f; + void *arg; + struct pheap *heap; + struct pfree *next; +}; + +/* pool - base node for a pool. Maintains a linked list + of pool entries (pfree) */ +typedef struct pool_struct +{ + int size; + struct pfree *cleanup; + struct pheap *heap; +#ifdef POOL_DEBUG + char name[8], zone[32]; + int lsize; +} _pool, *pool; +#define pool_new() _pool_new(ZONE) +#define pool_heap(i) _pool_new_heap(i,ZONE) +#else +} _pool, *pool; +#define pool_heap(i) _pool_new_heap(i,NULL) +#define pool_new() _pool_new(NULL) +#endif + +pool _pool_new(char *zone); /* new pool :) */ +pool _pool_new_heap(int size, char *zone); /* creates a new memory pool with an initial heap size */ +void *pmalloc(pool p, int size); /* wrapper around malloc, takes from the pool, cleaned up automatically */ +void *pmalloc_x(pool p, int size, char c); /* Wrapper around pmalloc which prefils buffer with c */ +void *pmalloco(pool p, int size); /* YAPW for zeroing the block */ +char *pstrdup(pool p, const char *src); /* wrapper around strdup, gains mem from pool */ +void pool_stat(int full); /* print to stderr the changed pools and reset */ +char *pstrdupx(pool p, const char *src); /* temp stub */ +void pool_cleanup(pool p, pool_cleaner f, void *arg); /* calls f(arg) before the pool is freed during cleanup */ +void pool_free(pool p); /* calls the cleanup functions, frees all the data on the pool, and deletes the pool itself */ +int pool_size(pool p); /* returns total bytes allocated in this pool */ + + + + +/* --------------------------------------------------------- */ +/* */ +/* Socket helper stuff */ +/* */ +/* --------------------------------------------------------- */ +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 64 +#endif + +#define NETSOCKET_SERVER 0 +#define NETSOCKET_CLIENT 1 +#define NETSOCKET_UDP 2 + +#ifndef WIN32 +int make_netsocket(u_short port, char *host, int type); +struct in_addr *make_addr(char *host); +int set_fd_close_on_exec(int fd, int flag); +#endif + + +/* --------------------------------------------------------- */ +/* */ +/* String management routines */ +/* */ +/* --------------------------------------------------------- */ +char *j_strdup(const char *str); /* provides NULL safe strdup wrapper */ +char *j_strcat(char *dest, char *txt); /* strcpy() clone */ +int j_strcmp(const char *a, const char *b); /* provides NULL safe strcmp wrapper */ +int j_strcasecmp(const char *a, const char *b); /* provides NULL safe strcasecmp wrapper */ +int j_strncmp(const char *a, const char *b, int i); /* provides NULL safe strncmp wrapper */ +int j_strncasecmp(const char *a, const char *b, int i); /* provides NULL safe strncasecmp wrapper */ +int j_strlen(const char *a); /* provides NULL safe strlen wrapper */ +int j_atoi(const char *a, int def); /* checks for NULL and uses default instead, convienence */ +void str_b64decode(char *str); /* what it says */ + + +/* --------------------------------------------------------- */ +/* */ +/* SHA calculations */ +/* */ +/* --------------------------------------------------------- */ +#if (SIZEOF_INT == 4) +typedef unsigned int uint32; +#elif (SIZEOF_SHORT == 4) +typedef unsigned short uint32; +#else +typedef unsigned int uint32; +#endif /* HAVEUINT32 */ + +char *shahash(char *str); /* NOT THREAD SAFE */ +void shahash_r(const char* str, char hashbuf[40]); /* USE ME */ + +int strprintsha(char *dest, int *hashval); + + +/* --------------------------------------------------------- */ +/* */ +/* Hashtable functions */ +/* */ +/* --------------------------------------------------------- */ +typedef struct xhn_struct +{ + struct xhn_struct *next; + const char *key; + void *val; +} *xhn, _xhn; + +typedef struct xht_struct +{ + pool p; + int prime; + struct xhn_struct *zen; +} *xht, _xht; + +xht xhash_new(int prime); +void xhash_put(xht h, const char *key, void *val); +void *xhash_get(xht h, const char *key); +void xhash_zap(xht h, const char *key); +void xhash_free(xht h); +typedef void (*xhash_walker)(xht h, const char *key, void *val, void *arg); +void xhash_walk(xht h, xhash_walker w, void *arg); + +/* --------------------------------------------------------- */ +/* */ +/* DEPRECIATED Hashtable functions */ +/* */ +/* --------------------------------------------------------- */ +typedef int (*KEYHASHFUNC)(const void *key); +typedef int (*KEYCOMPAREFUNC)(const void *key1, const void *key2); +typedef int (*TABLEWALKFUNC)(void *user_data, const void *key, void *data); + +typedef void *HASHTABLE; + +HASHTABLE ghash_create(int buckets, KEYHASHFUNC hash, KEYCOMPAREFUNC cmp); +HASHTABLE ghash_create_pool(pool p, int buckets, KEYHASHFUNC hash, KEYCOMPAREFUNC cmp); +void ghash_destroy(HASHTABLE tbl); +void *ghash_get(HASHTABLE tbl, const void *key); +int ghash_put(HASHTABLE tbl, const void *key, void *value); +int ghash_remove(HASHTABLE tbl, const void *key); +int ghash_walk(HASHTABLE tbl, TABLEWALKFUNC func, void *user_data); +int str_hash_code(const char *s); + + +/* --------------------------------------------------------- */ +/* */ +/* XML escaping utils */ +/* */ +/* --------------------------------------------------------- */ +char *strescape(pool p, char *buf); /* Escape <>&'" chars */ +char *strunescape(pool p, char *buf); + + +/* --------------------------------------------------------- */ +/* */ +/* String pools (spool) functions */ +/* */ +/* --------------------------------------------------------- */ +struct spool_node +{ + char *c; + struct spool_node *next; +}; + +typedef struct spool_struct +{ + pool p; + int len; + struct spool_node *last; + struct spool_node *first; +} *spool; + +spool spool_new(pool p); /* create a string pool */ +void spooler(spool s, ...); /* append all the char * args to the pool, terminate args with s again */ +char *spool_print(spool s); /* return a big string */ +void spool_add(spool s, char *str); /* add a single char to the pool */ +char *spools(pool p, ...); /* wrap all the spooler stuff in one function, the happy fun ball! */ + + +/* --------------------------------------------------------- */ +/* */ +/* xmlnodes - Document Object Model */ +/* */ +/* --------------------------------------------------------- */ +#define NTYPE_TAG 0 +#define NTYPE_ATTRIB 1 +#define NTYPE_CDATA 2 + +#define NTYPE_LAST 2 +#define NTYPE_UNDEF -1 + +/* -------------------------------------------------------------------------- + Node structure. Do not use directly! Always use accessor macros + and methods! + -------------------------------------------------------------------------- */ +typedef struct xmlnode_t +{ + char* name; + unsigned short type; + char* data; + int data_sz; + int complete; + pool p; + struct xmlnode_t* parent; + struct xmlnode_t* firstchild; + struct xmlnode_t* lastchild; + struct xmlnode_t* prev; + struct xmlnode_t* next; + struct xmlnode_t* firstattrib; + struct xmlnode_t* lastattrib; +} _xmlnode, *xmlnode; + +/* Node creation routines */ +xmlnode xmlnode_wrap(xmlnode x,const char* wrapper); +xmlnode xmlnode_new_tag(const char* name); +xmlnode xmlnode_new_tag_pool(pool p, const char* name); +xmlnode xmlnode_insert_tag(xmlnode parent, const char* name); +xmlnode xmlnode_insert_cdata(xmlnode parent, const char* CDATA, unsigned int size); +xmlnode xmlnode_insert_tag_node(xmlnode parent, xmlnode node); +void xmlnode_insert_node(xmlnode parent, xmlnode node); +xmlnode xmlnode_str(char *str, int len); +xmlnode xmlnode_file(char *file); +char* xmlnode_file_borked(char *file); /* same as _file but returns the parsing error */ +xmlnode xmlnode_dup(xmlnode x); /* duplicate x */ +xmlnode xmlnode_dup_pool(pool p, xmlnode x); + +/* Node Memory Pool */ +pool xmlnode_pool(xmlnode node); +xmlnode _xmlnode_new(pool p, const char *name, unsigned int type); + +/* Node editing */ +void xmlnode_hide(xmlnode child); +void xmlnode_hide_attrib(xmlnode parent, const char *name); + +/* Node deletion routine, also frees the node pool! */ +void xmlnode_free(xmlnode node); + +/* Locates a child tag by name and returns it */ +xmlnode xmlnode_get_tag(xmlnode parent, const char* name); +char* xmlnode_get_tag_data(xmlnode parent, const char* name); + +/* Attribute accessors */ +void xmlnode_put_attrib(xmlnode owner, const char* name, const char* value); +char* xmlnode_get_attrib(xmlnode owner, const char* name); +void xmlnode_put_expat_attribs(xmlnode owner, const char** atts); + +/* Bastard am I, but these are fun for internal use ;-) */ +void xmlnode_put_vattrib(xmlnode owner, const char* name, void *value); +void* xmlnode_get_vattrib(xmlnode owner, const char* name); + +/* Node traversal routines */ +xmlnode xmlnode_get_firstattrib(xmlnode parent); +xmlnode xmlnode_get_firstchild(xmlnode parent); +xmlnode xmlnode_get_lastchild(xmlnode parent); +xmlnode xmlnode_get_nextsibling(xmlnode sibling); +xmlnode xmlnode_get_prevsibling(xmlnode sibling); +xmlnode xmlnode_get_parent(xmlnode node); + +/* Node information routines */ +char* xmlnode_get_name(xmlnode node); +char* xmlnode_get_data(xmlnode node); +int xmlnode_get_datasz(xmlnode node); +int xmlnode_get_type(xmlnode node); + +int xmlnode_has_children(xmlnode node); +int xmlnode_has_attribs(xmlnode node); + +/* Node-to-string translation */ +char* xmlnode2str(xmlnode node); + +/* Node-to-terminated-string translation + -- useful for interfacing w/ scripting langs */ +char* xmlnode2tstr(xmlnode node); + +int xmlnode_cmp(xmlnode a, xmlnode b); /* compares a and b for equality */ + +int xmlnode2file(char *file, xmlnode node); /* writes node to file */ + +/* Expat callbacks */ +void expat_startElement(void* userdata, const char* name, const char** atts); +void expat_endElement(void* userdata, const char* name); +void expat_charData(void* userdata, const char* s, int len); + +/*********************** + * XSTREAM Section + ***********************/ + +#define XSTREAM_MAXNODE 1000000 +#define XSTREAM_MAXDEPTH 100 + +#define XSTREAM_ROOT 0 /* root element */ +#define XSTREAM_NODE 1 /* normal node */ +#define XSTREAM_CLOSE 2 /* closed </stream:stream> */ +#define XSTREAM_ERR 4 /* parser error */ + +typedef void (*xstream_onNode)(int type, xmlnode x, void *arg); /* xstream event handler */ + +typedef struct xstream_struct +{ + XML_Parser parser; + xmlnode node; + char *cdata; + int cdata_len; + pool p; + xstream_onNode f; + void *arg; + int status; + int depth; +} *xstream, _xstream; + +xstream xstream_new(pool p, xstream_onNode f, void *arg); /* create a new xstream */ +int xstream_eat(xstream xs, char *buff, int len); /* parse new data for this xstream, returns last XSTREAM_* status */ + +/* convience functions */ +xmlnode xstream_header(char *namespace, char *to, char *from); +char *xstream_header_char(xmlnode x); + + +typedef struct { + unsigned long H[5]; + unsigned long W[80]; + int lenW; + unsigned long sizeHi,sizeLo; +} j_SHA_CTX; + + +void shaInit(j_SHA_CTX *ctx); +void shaUpdate(j_SHA_CTX *ctx, unsigned char *dataIn, int len); +void shaFinal(j_SHA_CTX *ctx, unsigned char hashout[20]); +void shaBlock(unsigned char *dataIn, int len, unsigned char hashout[20]); + +/********** END OLD libxode.h BEGIN OLD jabber.h *************/ + +/* --------------------------------------------------------- */ +/* */ +/* JID structures & constants */ +/* */ +/* --------------------------------------------------------- */ +#define JID_RESOURCE 1 +#define JID_USER 2 +#define JID_SERVER 4 + +typedef struct jid_struct +{ + pool p; + char* resource; + char* user; + char* server; + char* full; + struct jid_struct *next; /* for lists of jids */ +} *jid; + +jid jid_new(pool p, char *idstr); /* Creates a jabber id from the idstr */ +void jid_set(jid id, char *str, int item); /* Individually sets jid components */ +char* jid_full(jid id); /* Builds a string type=user/resource@server from the jid data */ +int jid_cmp(jid a, jid b); /* Compares two jid's, returns 0 for perfect match */ +int jid_cmpx(jid a, jid b, int parts); /* Compares just the parts specified as JID_|JID_ */ +jid jid_append(jid a, jid b); /* Appending b to a (list), no dups */ +xmlnode jid_xres(jid id); /* Returns xmlnode representation of the resource?query=string */ +xmlnode jid_nodescan(jid id, xmlnode x); /* Scans the children of the node for a matching jid attribute */ +jid jid_user(jid a); /* returns the same jid but just of the user@host part */ + + +/* --------------------------------------------------------- */ +/* */ +/* JPacket structures & constants */ +/* */ +/* --------------------------------------------------------- */ +#define JPACKET_UNKNOWN 0x00 +#define JPACKET_MESSAGE 0x01 +#define JPACKET_PRESENCE 0x02 +#define JPACKET_IQ 0x04 +#define JPACKET_S10N 0x08 + +#define JPACKET__UNKNOWN 0 +#define JPACKET__NONE 1 +#define JPACKET__ERROR 2 +#define JPACKET__CHAT 3 +#define JPACKET__GROUPCHAT 4 +#define JPACKET__GET 5 +#define JPACKET__SET 6 +#define JPACKET__RESULT 7 +#define JPACKET__SUBSCRIBE 8 +#define JPACKET__SUBSCRIBED 9 +#define JPACKET__UNSUBSCRIBE 10 +#define JPACKET__UNSUBSCRIBED 11 +#define JPACKET__AVAILABLE 12 +#define JPACKET__UNAVAILABLE 13 +#define JPACKET__PROBE 14 +#define JPACKET__HEADLINE 15 +#define JPACKET__INVISIBLE 16 + +typedef struct jpacket_struct +{ + unsigned char type; + int subtype; + int flag; + void* aux1; + xmlnode x; + jid to; + jid from; + char* iqns; + xmlnode iq; + pool p; +} *jpacket, _jpacket; + +jpacket jpacket_new(xmlnode x); /* Creates a jabber packet from the xmlnode */ +jpacket jpacket_reset(jpacket p); /* Resets the jpacket values based on the xmlnode */ +int jpacket_subtype(jpacket p); /* Returns the subtype value (looks at xmlnode for it) */ + + +/* --------------------------------------------------------- */ +/* */ +/* Presence Proxy DB structures & constants */ +/* */ +/* --------------------------------------------------------- */ +typedef struct ppdb_struct +{ + jid id; /* entry data */ + int pri; + xmlnode x; + struct ppdb_struct* user; /* linked list for user@server */ + pool p; /* db-level data */ + struct ppdb_struct* next; +} _ppdb, *ppdb; + +ppdb ppdb_insert(ppdb db, jid id, xmlnode x); /* Inserts presence into the proxy */ +xmlnode ppdb_primary(ppdb db, jid id); /* Fetches the matching primary presence for the id */ +void ppdb_free(ppdb db); /* Frees the db and all entries */ +xmlnode ppdb_get(ppdb db, jid id); /* Called successively to return each presence xmlnode */ + /* for the id and children, returns NULL at the end */ + + +/* --------------------------------------------------------- */ +/* */ +/* Simple Jabber Rate limit functions */ +/* */ +/* --------------------------------------------------------- */ +typedef struct jlimit_struct +{ + char *key; + int start; + int points; + int maxt, maxp; + pool p; +} *jlimit, _jlimit; + +jlimit jlimit_new(int maxt, int maxp); +void jlimit_free(jlimit r); +int jlimit_check(jlimit r, char *key, int points); + + +// #define KARMA_DEBUG +// default to disable karma +#define KARMA_READ_MAX(k) (abs(k)*100) /* how much you are allowed to read off the sock */ +#define KARMA_INIT 5 /* internal "init" value */ +#define KARMA_HEARTBEAT 2 /* seconds to register for heartbeat */ +#define KARMA_MAX 10 /* total max karma you can have */ +#define KARMA_INC 1 /* how much to increment every KARMA_HEARTBEAT seconds */ +#define KARMA_DEC 0 /* how much to penalize for reading KARMA_READ_MAX in + KARMA_HEARTBEAT seconds */ +#define KARMA_PENALTY -5 /* where you go when you hit 0 karma */ +#define KARMA_RESTORE 5 /* where you go when you payed your penelty or INIT */ +#define KARMA_RESETMETER 0 /* Reset byte meter on restore default is falst */ + +struct karma +{ + int init; /* struct initialized */ + int reset_meter; /* reset the byte meter on restore */ + int val; /* current karma value */ + long bytes; /* total bytes read (in that time period) */ + int max; /* max karma you can have */ + int inc,dec; /* how much to increment/decrement */ + int penalty,restore; /* what penalty (<0) or restore (>0) */ + time_t last_update; /* time this was last incremented */ +}; + +struct karma *karma_new(pool p); /* creates a new karma object, with default values */ +void karma_copy(struct karma *new, struct karma *old); /* makes a copy of old in new */ +void karma_increment(struct karma *k); /* inteligently increments karma */ +void karma_decrement(struct karma *k, long bytes_read); /* inteligently decrements karma */ +int karma_check(struct karma *k,long bytes_read); /* checks to see if we have good karma */ + + + +/* --------------------------------------------------------- */ +/* */ +/* Error structures & constants */ +/* */ +/* --------------------------------------------------------- */ +typedef struct terror_struct +{ + int code; + char msg[64]; +} terror; + +#define TERROR_BAD (terror){400,"Bad Request"} +#define TERROR_AUTH (terror){401,"Unauthorized"} +#define TERROR_PAY (terror){402,"Payment Required"} +#define TERROR_FORBIDDEN (terror){403,"Forbidden"} +#define TERROR_NOTFOUND (terror){404,"Not Found"} +#define TERROR_NOTALLOWED (terror){405,"Not Allowed"} +#define TERROR_NOTACCEPTABLE (terror){406,"Not Acceptable"} +#define TERROR_REGISTER (terror){407,"Registration Required"} +#define TERROR_REQTIMEOUT (terror){408,"Request Timeout"} +#define TERROR_CONFLICT (terror){409,"Conflict"} + +#define TERROR_INTERNAL (terror){500,"Internal Server Error"} +#define TERROR_NOTIMPL (terror){501,"Not Implemented"} +#define TERROR_EXTERNAL (terror){502,"Remote Server Error"} +#define TERROR_UNAVAIL (terror){503,"Service Unavailable"} +#define TERROR_EXTTIMEOUT (terror){504,"Remote Server Timeout"} +#define TERROR_DISCONNECTED (terror){510,"Disconnected"} + +/* --------------------------------------------------------- */ +/* */ +/* Namespace constants */ +/* */ +/* --------------------------------------------------------- */ +#define NSCHECK(x,n) (j_strcmp(xmlnode_get_attrib(x,"xmlns"),n) == 0) + +#define NS_CLIENT "jabber:client" +#define NS_SERVER "jabber:server" +#define NS_AUTH "jabber:iq:auth" +#define NS_REGISTER "jabber:iq:register" +#define NS_ROSTER "jabber:iq:roster" +#define NS_OFFLINE "jabber:x:offline" +#define NS_AGENT "jabber:iq:agent" +#define NS_AGENTS "jabber:iq:agents" +#define NS_DELAY "jabber:x:delay" +#define NS_VERSION "jabber:iq:version" +#define NS_TIME "jabber:iq:time" +#define NS_VCARD "vcard-temp" +#define NS_PRIVATE "jabber:iq:private" +#define NS_SEARCH "jabber:iq:search" +#define NS_OOB "jabber:iq:oob" +#define NS_XOOB "jabber:x:oob" +#define NS_ADMIN "jabber:iq:admin" +#define NS_FILTER "jabber:iq:filter" +#define NS_AUTH_0K "jabber:iq:auth:0k" +#define NS_BROWSE "jabber:iq:browse" +#define NS_EVENT "jabber:x:event" +#define NS_CONFERENCE "jabber:iq:conference" +#define NS_SIGNED "jabber:x:signed" +#define NS_ENCRYPTED "jabber:x:encrypted" +#define NS_GATEWAY "jabber:iq:gateway" +#define NS_LAST "jabber:iq:last" +#define NS_ENVELOPE "jabber:x:envelope" +#define NS_EXPIRE "jabber:x:expire" +#define NS_XHTML "http://www.w3.org/1999/xhtml" + +#define NS_XDBGINSERT "jabber:xdb:ginsert" +#define NS_XDBNSLIST "jabber:xdb:nslist" + + +/* --------------------------------------------------------- */ +/* */ +/* JUtil functions */ +/* */ +/* --------------------------------------------------------- */ +xmlnode jutil_presnew(int type, char *to, char *status); /* Create a skeleton presence packet */ +xmlnode jutil_iqnew(int type, char *ns); /* Create a skeleton iq packet */ +xmlnode jutil_msgnew(char *type, char *to, char *subj, char *body); + /* Create a skeleton message packet */ +xmlnode jutil_header(char* xmlns, char* server); /* Create a skeleton stream packet */ +int jutil_priority(xmlnode x); /* Determine priority of this packet */ +void jutil_tofrom(xmlnode x); /* Swaps to/from fields on a packet */ +xmlnode jutil_iqresult(xmlnode x); /* Generate a skeleton iq/result, given a iq/query */ +char* jutil_timestamp(void); /* Get stringified timestamp */ +void jutil_error(xmlnode x, terror E); /* Append an <error> node to x */ +void jutil_delay(xmlnode msg, char *reason); /* Append a delay packet to msg */ +char* jutil_regkey(char *key, char *seed); /* pass a seed to generate a key, pass the key again to validate (returns it) */ + + +#ifdef __cplusplus +} +#endif + +#endif /* INCL_LIB_H */
--- a/src/protocols/jabber/pool.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/pool.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,44 +1,45 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - * - * 2/27/00:3am, random plans by jer - * - * ok based on gprof, we really need some innovation here... my thoughs are this: - * - * most things are strings, so have a string-based true-blue garbage collector - * one big global hash containing all the strings created by any pstrdup, returning const char * - * a refcount on each string block - * when a pool is freed, it moves down the refcount - * garbage collector collects pools on the free stack, and runs through the hash for unused strings - * j_strcmp can check for == (if they are both from a pstrdup) - * - * let's see... this would change: - * pstrdup: do a hash lookup, success=return, fail=pmalloc & hash put - * pool_free: - * - * - * - * - * - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include "libxode.h" -#include "config.h" +#include "lib.h" #ifdef POOL_DEBUG @@ -77,8 +78,12 @@ sprintf(p->name,"%X",p); if(pool__disturbed == NULL) + { + pool__disturbed = 1; /* reentrancy flag! */ pool__disturbed = ghash_create(POOL_DEBUG,(KEYHASHFUNC)str_hash_code,(KEYCOMPAREFUNC)j_strcmp); - ghash_put(pool__disturbed,p->name,p); + } + if(pool__disturbed != 1) + ghash_put(pool__disturbed,p->name,p); #endif return p;
--- a/src/protocols/jabber/pproxy.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/pproxy.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,23 +1,45 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include "jabber.h" +#include "lib.h" /* these aren't the most efficient things in the world, a hash optimized for tiny spaces would be far better */ @@ -49,7 +71,6 @@ ppdb ppdb_insert(ppdb db, jid id, xmlnode x) { - char *res; ppdb cur, curu; pool p; @@ -60,7 +81,7 @@ if(db == NULL) { p = pool_heap(1024); - db = _ppdb_new(p,id); + db = _ppdb_new(p,NULL); } cur = _ppdb_get(db,id); @@ -81,25 +102,17 @@ cur->next = db->next; db->next = cur; - /* this is a presence from a resource, make an entry for just the user */ - if(id->user != NULL && id->resource != NULL) + /* if this is a user's resource presence, get the the user entry */ + if(id->user != NULL && (curu = _ppdb_get(db,jid_user(id))) != cur) { - /* modify the id to just user@host */ - res = id->resource; - jid_set(id,NULL,JID_RESOURCE); - curu = _ppdb_get(db,id); - /* no user entry, make one */ if(curu == NULL) { - curu = _ppdb_new(db->p,id); + curu = _ppdb_new(db->p,jid_user(id)); curu->next = db->next; db->next = curu; } - /* restore the id */ - jid_set(id,res,JID_RESOURCE); - /* insert this resource into the user list */ cur->user = curu->user; curu->user = cur;
--- a/src/protocols/jabber/rate.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/rate.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,24 +1,45 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ - -#include "jabber.h" +#include "lib.h" jlimit jlimit_new(int maxt, int maxp) {
--- a/src/protocols/jabber/sha.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/sha.c Thu Apr 04 03:04:57 2002 +0000 @@ -18,26 +18,13 @@ * * Contributor(s): * - * Paul Kocher - * - * Alternatively, the contents of this file may be used under the - * terms of the GNU General Public License Version 2 or later (the - * "GPL"), in which case the provisions of the GPL are applicable - * instead of those above. If you wish to allow use of your - * version of this file only under the terms of the GPL and not to - * allow others to use your version of this file under the MPL, - * indicate your decision by deleting the provisions above and - * replace them with the notice and other provisions required by - * the GPL. If you do not delete the provisions above, a recipient - * may use your version of this file under either the MPL or the - * GPL. */ -#include "libxode.h" +#include "lib.h" -static void shaHashBlock(SHA_CTX *ctx); +static void shaHashBlock(j_SHA_CTX *ctx); -void shaInit(SHA_CTX *ctx) { +void shaInit(j_SHA_CTX *ctx) { int i; ctx->lenW = 0; @@ -56,7 +43,7 @@ } -void shaUpdate(SHA_CTX *ctx, unsigned char *dataIn, int len) { +void shaUpdate(j_SHA_CTX *ctx, unsigned char *dataIn, int len) { int i; /* Read the data into W and process blocks as they get full @@ -74,7 +61,7 @@ } -void shaFinal(SHA_CTX *ctx, unsigned char hashout[20]) { +void shaFinal(j_SHA_CTX *ctx, unsigned char hashout[20]) { unsigned char pad0x80 = 0x80; unsigned char pad0x00 = 0x00; unsigned char padlen[8]; @@ -105,12 +92,12 @@ /* * Re-initialize the context (also zeroizes contents) */ - shaInit(ctx); + shaInit(ctx); } void shaBlock(unsigned char *dataIn, int len, unsigned char hashout[20]) { - SHA_CTX ctx; + j_SHA_CTX ctx; shaInit(&ctx); shaUpdate(&ctx, dataIn, len); @@ -118,9 +105,9 @@ } -#define SHA_ROTL(X,n) (((X) << (n)) | ((X) >> (32-(n)))) +#define SHA_ROTL(X,n) ((((X) << (n)) | ((X) >> (32-(n)))) & 0xffffffffL) -static void shaHashBlock(SHA_CTX *ctx) { +static void shaHashBlock(j_SHA_CTX *ctx) { int t; unsigned long A,B,C,D,E,TEMP; @@ -135,19 +122,19 @@ E = ctx->H[4]; for (t = 0; t <= 19; t++) { - TEMP = SHA_ROTL(A,5) + (((C^D)&B)^D) + E + ctx->W[t] + 0x5a827999L; + TEMP = (SHA_ROTL(A,5) + (((C^D)&B)^D) + E + ctx->W[t] + 0x5a827999L) & 0xffffffffL; E = D; D = C; C = SHA_ROTL(B, 30); B = A; A = TEMP; } for (t = 20; t <= 39; t++) { - TEMP = SHA_ROTL(A,5) + (B^C^D) + E + ctx->W[t] + 0x6ed9eba1L; + TEMP = (SHA_ROTL(A,5) + (B^C^D) + E + ctx->W[t] + 0x6ed9eba1L) & 0xffffffffL; E = D; D = C; C = SHA_ROTL(B, 30); B = A; A = TEMP; } for (t = 40; t <= 59; t++) { - TEMP = SHA_ROTL(A,5) + ((B&C)|(D&(B|C))) + E + ctx->W[t] + 0x8f1bbcdcL; + TEMP = (SHA_ROTL(A,5) + ((B&C)|(D&(B|C))) + E + ctx->W[t] + 0x8f1bbcdcL) & 0xffffffffL; E = D; D = C; C = SHA_ROTL(B, 30); B = A; A = TEMP; } for (t = 60; t <= 79; t++) { - TEMP = SHA_ROTL(A,5) + (B^C^D) + E + ctx->W[t] + 0xca62c1d6L; + TEMP = (SHA_ROTL(A,5) + (B^C^D) + E + ctx->W[t] + 0xca62c1d6L) & 0xffffffffL; E = D; D = C; C = SHA_ROTL(B, 30); B = A; A = TEMP; }
--- a/src/protocols/jabber/snprintf.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/snprintf.c Thu Apr 04 03:04:57 2002 +0000 @@ -53,7 +53,7 @@ * <panos@alumni.cs.colorado.edu> for xinetd. */ -#include <libxode.h> +#include "lib.h" #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
--- a/src/protocols/jabber/socket.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/socket.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,30 +1,52 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include "libxode.h" +#include "lib.h" /* socket.c * * Simple wrapper to make socket creation easy. * type = NETSOCKET_SERVER is local listening socket * type = NETSOCKET_CLIENT is connection socket - * type = NETSOCKET_UDP + * type = NETSOCKET_UDP is a UDP connection socket */ int make_netsocket(u_short port, char *host, int type) @@ -45,7 +67,7 @@ return(-1); saddr = make_addr(host); - if(saddr == NULL) + if(saddr == NULL && type != NETSOCKET_UDP) return(-1); sa.sin_family = AF_INET; sa.sin_port = htons(port); @@ -80,12 +102,15 @@ return(-1); } - /* specify default recipient for read/write */ - sa.sin_addr.s_addr = saddr->s_addr; - if(connect(s,(struct sockaddr*)&sa,sizeof sa) < 0) + /* if specified, use a default recipient for read/write */ + if(host != NULL && saddr != NULL) { - close(s); - return(-1); + sa.sin_addr.s_addr = saddr->s_addr; + if(connect(s,(struct sockaddr*)&sa,sizeof sa) < 0) + { + close(s); + return(-1); + } } }
--- a/src/protocols/jabber/str.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/str.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,23 +1,45 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include "libxode.h" +#include "lib.h" char *j_strdup(const char *str) { @@ -42,8 +64,12 @@ { if(a == NULL || b == NULL) return -1; - else - return strcmp(a, b); + + while(*a == *b && *a != '\0' && *b != '\0'){ a++; b++; } + + if(*a == *b) return 0; + + return -1; } int j_strcasecmp(const char *a, const char *b) @@ -136,7 +162,7 @@ while(1) { arg = va_arg(ap,char *); - if((int)arg == (int)s) + if((spool)arg == s) break; else spool_add(s, arg); @@ -185,7 +211,7 @@ while(1) { arg = va_arg(ap,char *); - if((int)arg == (int)p) + if((pool)arg == p) break; else spool_add(s, arg); @@ -344,7 +370,7 @@ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */ }; - phase = 0; + d = dlast = phase = 0; for (cur = str; *cur != '\0'; ++cur ) { d = table[(int)*cur];
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/protocols/jabber/xhash.c Thu Apr 04 03:04:57 2002 +0000 @@ -0,0 +1,194 @@ +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. + * + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ + +#include "lib.h" + + +/* Generates a hash code for a string. + * This function uses the ELF hashing algorithm as reprinted in + * Andrew Binstock, "Hashing Rehashed," Dr. Dobb's Journal, April 1996. + */ +int _xhasher(const char *s) +{ + /* ELF hash uses unsigned chars and unsigned arithmetic for portability */ + const unsigned char *name = (const unsigned char *)s; + unsigned long h = 0, g; + + while (*name) + { /* do some fancy bitwanking on the string */ + h = (h << 4) + (unsigned long)(*name++); + if ((g = (h & 0xF0000000UL))!=0) + h ^= (g >> 24); + h &= ~g; + + } + + return (int)h; +} + + +xhn _xhash_node_new(xht h, int index) +{ + xhn n; + int i = index % h->prime; + + /* get existing empty one */ + for(n = &h->zen[i]; n != NULL; n = n->next) + if(n->key == NULL) + return n; + + /* overflowing, new one! */ + n = pmalloco(h->p, sizeof(_xhn)); + n->next = h->zen[i].next; + h->zen[i].next = n; + return n; +} + + +xhn _xhash_node_get(xht h, const char *key, int index) +{ + xhn n; + int i = index % h->prime; + for(n = &h->zen[i]; n != NULL; n = n->next) + if(j_strcmp(key, n->key) == 0) + return n; + return NULL; +} + + +xht xhash_new(int prime) +{ + xht xnew; + pool p; + +/* log_debug(ZONE,"creating new hash table of size %d",prime); */ + + p = pool_heap(sizeof(_xhn)*prime + sizeof(_xht)); + xnew = pmalloco(p, sizeof(_xht)); + xnew->prime = prime; + xnew->p = p; + xnew->zen = pmalloco(p, sizeof(_xhn)*prime); /* array of xhn size of prime */ + return xnew; +} + + +void xhash_put(xht h, const char *key, void *val) +{ + int index; + xhn n; + + if(h == NULL || key == NULL) + return; + + index = _xhasher(key); + + /* if existing key, replace it */ + if((n = _xhash_node_get(h, key, index)) != NULL) + { +/* log_debug(ZONE,"replacing %s with new val %X",key,val); */ + + n->key = key; + n->val = val; + return; + } + +/* log_debug(ZONE,"saving %s val %X",key,val); */ + + /* new node */ + n = _xhash_node_new(h, index); + n->key = key; + n->val = val; +} + + +void *xhash_get(xht h, const char *key) +{ + xhn n; + + if(h == NULL || key == NULL || (n = _xhash_node_get(h, key, _xhasher(key))) == NULL) + { +/* log_debug(ZONE,"failed lookup of %s",key); */ + return NULL; + } + +/* log_debug(ZONE,"found %s returning %X",key,n->val); */ + return n->val; +} + + +void xhash_zap(xht h, const char *key) +{ + xhn n; + + if(h == NULL || key == NULL || (n = _xhash_node_get(h, key, _xhasher(key))) == NULL) + return; + +/* log_debug(ZONE,"zapping %s",key); */ + + /* kill an entry by zeroing out the key */ + n->key = NULL; +} + + +void xhash_free(xht h) +{ +/* log_debug(ZONE,"hash free %X",h); */ + + if(h != NULL) + pool_free(h->p); +} + +void xhash_walk(xht h, xhash_walker w, void *arg) +{ + int i; + xhn n; + + if(h == NULL || w == NULL) + return; + +/* log_debug(ZONE,"walking %X",h); */ + + for(i = 0; i < h->prime; i++) + for(n = &h->zen[i]; n != NULL; n = n->next) + if(n->key != NULL && n->val != NULL) + (*w)(h, n->key, n->val, arg); +} +
--- a/src/protocols/jabber/xmlnode.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/xmlnode.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,23 +1,45 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. + * + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include "libxode.h" +#include "lib.h" /* Internal routines */ xmlnode _xmlnode_new(pool p, const char* name, unsigned int type) @@ -35,8 +57,7 @@ } /* Allocate & zero memory */ - result = (xmlnode)pmalloc(p, sizeof(_xmlnode)); - memset(result, '\0', sizeof(_xmlnode)); + result = (xmlnode)pmalloco(p, sizeof(_xmlnode)); /* Initialize fields */ if (type != NTYPE_CDATA) @@ -64,7 +85,7 @@ { xmlnode result; - if(parent == NULL || name == NULL) return NULL; + if(parent == NULL || (type != NTYPE_CDATA && name == NULL)) return NULL; /* If parent->firstchild is NULL, simply create a new node for the first child */ if (parent->firstchild == NULL) @@ -100,18 +121,37 @@ return NULL; } -static char* _xmlnode_merge(pool p, char* dest, unsigned int destsize, const char* src, unsigned int srcsize) +void _xmlnode_merge(xmlnode data) { - char* result; - result = (char*)pmalloc(p, destsize + srcsize + 1); - memcpy(result, dest, destsize); - memcpy(result+destsize, src, srcsize); - result[destsize + srcsize] = '\0'; + xmlnode cur; + char *merge, *scur; + int imerge; + + /* get total size of all merged cdata */ + imerge = 0; + for(cur = data; cur != NULL && cur->type == NTYPE_CDATA; cur = cur->next) + imerge += cur->data_sz; - /* WARNING: major ugly hack: since we're throwing the old data away, let's jump in the pool and subtract it from the size, this is for xmlstream's big-node checking */ - p->size -= destsize; + /* copy in current data and then spin through all of them and merge */ + scur = merge = pmalloc(data->p,imerge + 1); + for(cur = data; cur != NULL && cur->type == NTYPE_CDATA; cur = cur->next) + { + memcpy(scur,cur->data,cur->data_sz); + scur += cur->data_sz; + } + *scur = '\0'; - return result; + /* this effectively hides all of the merged-in chunks */ + data->next = cur; + if(cur == NULL) + data->parent->lastchild = data; + else + cur->prev = data; + + /* reset data */ + data->data = merge; + data->data_sz = imerge; + } static void _xmlnode_hide_sibling(xmlnode child) @@ -155,7 +195,7 @@ xmlnode tmp; if(!node || xmlnode_get_type(node)!=NTYPE_TAG) - return NULL; + return NULL; s = spool_new(xmlnode_pool(node)); if(!s) return(NULL); @@ -166,38 +206,32 @@ { if(xmlnode_get_type(node) == NTYPE_TAG) { - if(xmlnode_has_children(node)) - { - _xmlnode_tag2str(s,node,1); - node = xmlnode_get_firstchild(node); - level++; - continue; - } - else + if(xmlnode_has_children(node)) { - _xmlnode_tag2str(s,node,0); - } - } - else - { - spool_add(s,strescape(xmlnode_pool(node),xmlnode_get_data(node))); - } - } + _xmlnode_tag2str(s,node,1); + node = xmlnode_get_firstchild(node); + level++; + continue; + }else{ + _xmlnode_tag2str(s,node,0); + } + }else{ + spool_add(s,strescape(xmlnode_pool(node),xmlnode_get_data(node))); + } + } tmp = xmlnode_get_nextsibling(node); - if(!tmp) + if(!tmp) { - node = xmlnode_get_parent(node); - level--; - if(level>=0) _xmlnode_tag2str(s,node,2); - if(level<1) break; - dir = 1; - } - else - { - node = tmp; - dir = 0; - } + node = xmlnode_get_parent(node); + level--; + if(level>=0) _xmlnode_tag2str(s,node,2); + if(level<1) break; + dir = 1; + }else{ + node = tmp; + dir = 0; + } } return s; @@ -260,8 +294,6 @@ /* * xmlnode_insert_cdata -- append character data to a tag - * If last child of the parent is CDATA, merges CDATA nodes. Otherwise - * creates a CDATA node, and appends it to the parent's child list. * * parameters * parent -- parent tag @@ -283,22 +315,13 @@ if(size == -1) size = strlen(CDATA); - if ((parent->lastchild != NULL) && (parent->lastchild->type == NTYPE_CDATA)) - { - result = parent->lastchild; - result->data = _xmlnode_merge(result->p, result->data, result->data_sz, CDATA, size); - result->data_sz = result->data_sz + size; - } - else + result = _xmlnode_insert(parent, NULL, NTYPE_CDATA); + if (result != NULL) { - result = _xmlnode_insert(parent, "", NTYPE_CDATA); - if (result != NULL) - { - result->data = (char*)pmalloc(result->p, size + 1); - memcpy(result->data, CDATA, size); - result->data[size] = '\0'; - result->data_sz = size; - } + result->data = (char*)pmalloc(result->p, size + 1); + memcpy(result->data, CDATA, size); + result->data[size] = '\0'; + result->data_sz = size; } return result; @@ -314,7 +337,8 @@ * "name/name" for a sub child (recurses) * "?attrib" to match the first tag with that attrib defined * "?attrib=value" to match the first tag with that attrib and value - * or any combination: "name/name/?attrib", etc + * "=cdata" to match the cdata contents of the child + * or any combination: "name/name/?attrib", "name=cdata", etc * * results * a pointer to the tag matching search criteria @@ -325,17 +349,43 @@ char *str, *slash, *qmark, *equals; xmlnode step, ret; + if(parent == NULL || parent->firstchild == NULL || name == NULL || name == '\0') return NULL; - if(strstr(name, "/") == NULL && strstr(name,"?") == NULL) + if(strstr(name, "/") == NULL && strstr(name,"?") == NULL && strstr(name, "=") == NULL) return _xmlnode_search(parent->firstchild, name, NTYPE_TAG); - /* jer's note: why can't I modify the name directly, why do I have to strdup it? damn c grrr! */ str = strdup(name); slash = strstr(str, "/"); qmark = strstr(str, "?"); equals = strstr(str, "="); + if(equals != NULL && (slash == NULL || equals < slash) && (qmark == NULL || equals < qmark)) + { /* of type =cdata */ + + *equals = '\0'; + equals++; + + for(step = parent->firstchild; step != NULL; step = xmlnode_get_nextsibling(step)) + { + if(xmlnode_get_type(step) != NTYPE_TAG) + continue; + + if(*str != '\0') + if(j_strcmp(xmlnode_get_name(step),str) != 0) + continue; + + if(j_strcmp(xmlnode_get_data(step),equals) != 0) + continue; + + break; + } + + free(str); + return step; + } + + if(qmark != NULL && (slash == NULL || qmark < slash)) { /* of type ?attrib */ @@ -528,33 +578,34 @@ char* xmlnode_get_data(xmlnode node) { - xmlnode cur; + if(xmlnode_get_type(node) == NTYPE_TAG) /* loop till we find a CDATA in the children */ + for(node = xmlnode_get_firstchild(node); node != NULL; node = xmlnode_get_nextsibling(node)) + if(xmlnode_get_type(node) == NTYPE_CDATA) break; if(node == NULL) return NULL; - if(xmlnode_get_type(node) == NTYPE_TAG) /* loop till we find a CDATA */ - { - for(cur = xmlnode_get_firstchild(node); cur != NULL; cur = xmlnode_get_nextsibling(cur)) - if(xmlnode_get_type(cur) == NTYPE_CDATA) - return cur->data; - }else{ - return node->data; - } - return NULL; + /* check for a dirty node w/ unassembled cdata chunks */ + if(xmlnode_get_type(node->next) == NTYPE_CDATA) + _xmlnode_merge(node); + + return node->data; } int xmlnode_get_datasz(xmlnode node) { - if (node != NULL) - return node->data_sz; - return (int)NULL; + if(xmlnode_get_type(node) != NTYPE_CDATA) return 0; + + /* check for a dirty node w/ unassembled cdata chunks */ + if(xmlnode_get_type(node->next) == NTYPE_CDATA) + _xmlnode_merge(node); + return node->data_sz; } int xmlnode_get_type(xmlnode node) { if (node != NULL) return node->type; - return (int)NULL; + return NTYPE_UNDEF; } int xmlnode_has_children(xmlnode node)
--- a/src/protocols/jabber/xmlparse.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/xmlparse.c Thu Apr 04 03:04:57 2002 +0000 @@ -17,15 +17,6 @@ Contributor(s): -Alternatively, the contents of this file may be used under the terms -of the GNU General Public License (the "GPL"), in which case the -provisions of the GPL are applicable instead of those above. If you -wish to allow use of your version of this file only under the terms of -the GPL and not to allow others to use your version of this file under -the MPL, indicate your decision by deleting the provisions above and -replace them with the notice and other provisions required by the -GPL. If you do not delete the provisions above, a recipient may use -your version of this file under either the MPL or the GPL. */ #include "xmldef.h" @@ -190,7 +181,6 @@ static Processor contentProcessor; static Processor cdataSectionProcessor; static Processor epilogProcessor; -static Processor errorProcessor; static Processor externalEntityInitProcessor; static Processor externalEntityInitProcessor2; static Processor externalEntityInitProcessor3; @@ -2333,15 +2323,6 @@ } } -static -enum XML_Error errorProcessor(XML_Parser parser, - const char *s, - const char *end, - const char **nextPtr) -{ - return errorCode; -} - static enum XML_Error storeAttributeValue(XML_Parser parser, const ENCODING *enc, int isCdata, const char *ptr, const char *end, @@ -2483,10 +2464,11 @@ const char *entityTextPtr, const char *entityTextEnd) { - const ENCODING *internalEnc = ns ? XmlGetInternalEncodingNS() : XmlGetInternalEncoding(); + const ENCODING *internalEnc; STRING_POOL *pool = &(dtd.pool); entityTextPtr += encoding->minBytesPerChar; entityTextEnd -= encoding->minBytesPerChar; + internalEnc = ns ? XmlGetInternalEncodingNS() : XmlGetInternalEncoding(); for (;;) { const char *next; int tok = XmlEntityValueTok(encoding, entityTextPtr, entityTextEnd, &next);
--- a/src/protocols/jabber/xmlrole.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/xmlrole.c Thu Apr 04 03:04:57 2002 +0000 @@ -17,15 +17,6 @@ Contributor(s): -Alternatively, the contents of this file may be used under the terms -of the GNU General Public License (the "GPL"), in which case the -provisions of the GPL are applicable instead of those above. If you -wish to allow use of your version of this file only under the terms of -the GPL and not to allow others to use your version of this file under -the MPL, indicate your decision by deleting the provisions above and -replace them with the notice and other provisions required by the -GPL. If you do not delete the provisions above, a recipient may use -your version of this file under either the MPL or the GPL. */ #include "xmldef.h"
--- a/src/protocols/jabber/xmltok.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/xmltok.c Thu Apr 04 03:04:57 2002 +0000 @@ -17,15 +17,6 @@ Contributor(s): -Alternatively, the contents of this file may be used under the terms -of the GNU General Public License (the "GPL"), in which case the -provisions of the GPL are applicable instead of those above. If you -wish to allow use of your version of this file only under the terms of -the GPL and not to allow others to use your version of this file under -the MPL, indicate your decision by deleting the provisions above and -replace them with the notice and other provisions required by the -GPL. If you do not delete the provisions above, a recipient may use -your version of this file under either the MPL or the GPL. */ #include "xmldef.h" @@ -1491,7 +1482,7 @@ break; } } - *encPtr = encodingTable[INIT_ENC_INDEX(enc)]; + *encPtr = encodingTable[(int)INIT_ENC_INDEX(enc)]; return XmlTok(*encPtr, state, ptr, end, nextTokPtr); }
--- a/src/protocols/jabber/xmltok_impl.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/xmltok_impl.c Thu Apr 04 03:04:57 2002 +0000 @@ -17,15 +17,6 @@ Contributor(s): -Alternatively, the contents of this file may be used under the terms -of the GNU General Public License (the "GPL"), in which case the -provisions of the GPL are applicable instead of those above. If you -wish to allow use of your version of this file only under the terms of -the GPL and not to allow others to use your version of this file under -the MPL, indicate your decision by deleting the provisions above and -replace them with the notice and other provisions required by the -GPL. If you do not delete the provisions above, a recipient may use -your version of this file under either the MPL or the GPL. */ #ifndef IS_INVALID_CHAR @@ -1391,7 +1382,7 @@ { enum { other, inName, inValue } state = inName; int nAtts = 0; - int open; + int open = 0; for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) { switch (BYTE_TYPE(enc, ptr)) {
--- a/src/protocols/jabber/xmltok_ns.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/xmltok_ns.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,21 +1,23 @@ /* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ +The contents of this file are subject to the Mozilla Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.mozilla.org/MPL/ + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is expat. + +The Initial Developer of the Original Code is James Clark. +Portions created by James Clark are Copyright (C) 1998, 1999 +James Clark. All Rights Reserved. + +Contributor(s): + +*/ const ENCODING *NS(XmlGetUtf8InternalEncoding)() {
--- a/src/protocols/jabber/xstream.c Thu Apr 04 00:59:12 2002 +0000 +++ b/src/protocols/jabber/xstream.c Thu Apr 04 03:04:57 2002 +0000 @@ -1,24 +1,45 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. +/* -------------------------------------------------------------------------- + * + * License + * + * The contents of this file are subject to the Jabber Open Source License + * Version 1.0 (the "JOSL"). You may not copy or use this file, in either + * source code or executable form, except in compliance with the JOSL. You + * may obtain a copy of the JOSL at http://www.jabber.org/ or at + * http://www.opensource.org/. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Software distributed under the JOSL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL + * for the specific language governing rights and limitations under the + * JOSL. + * + * Copyrights + * + * Portions created by or assigned to Jabber.com, Inc. are + * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact + * information for Jabber.com, Inc. is available at http://www.jabber.com/. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Jabber - * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ - */ + * Portions Copyright (c) 1998-1999 Jeremie Miller. + * + * Acknowledgements + * + * Special thanks to the Jabber Open Source Contributors for their + * suggestions and support of Jabber. + * + * Alternatively, the contents of this file may be used under the terms of the + * GNU General Public License Version 2 or later (the "GPL"), in which case + * the provisions of the GPL are applicable instead of those above. If you + * wish to allow use of your version of this file only under the terms of the + * GPL and not to allow others to use your version of this file under the JOSL, + * indicate your decision by deleting the provisions above and replace them + * with the notice and other provisions required by the GPL. If you do not + * delete the provisions above, a recipient may use your version of this file + * under either the JOSL or the GPL. + * + * + * --------------------------------------------------------------------------*/ -#include <libxode.h> -#include <time.h> +#include "lib.h" /* xstream is a way to have a consistent method of handling incoming XML Stream based events... it doesn't handle the generation of an XML Stream, but provides some facilities to help do that */