#include #include #include #include #include #include #include #include #include #include #include #include #include "xmlparse.h" int j_strcmp(const char *a, const char *b); /* ** Arrange to use either varargs or stdargs */ #define MAXSHORTSTR 203 /* max short string length */ #define QUAD_T unsigned long long #if defined(__STDC__) || defined(_WIN32) #include # define VA_LOCAL_DECL va_list ap; # define VA_START(f) va_start(ap, f) # define VA_END va_end(ap) #else /* __STDC__ */ # include # 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 /* --------------------------------------------------------- */ /* */ /* 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 */ 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 */ /* --------------------------------------------------------- */ /* */ /* 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 *hos
utils/*
a *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 */ /* --------------------------------------------------------- */ /* */ /* 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" #ifdef __cplusplus } #endif #endif /* INCL_LIB_H */