annotate src/protocols/jabber/lib.h @ 5679:0a0116686d51

[gaim-migrate @ 6097] let the prpls know about the new API changes committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Mon, 02 Jun 2003 22:24:07 +0000
parents 988485669631
children 5239a3b4ab33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
1 #ifdef HAVE_CONFIG_H
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
2 #include <config.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
3 #endif /* HAVE_CONFIG_H */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
4
3664
1a6d3f3bc682 [gaim-migrate @ 3793]
Luke Schierer <lschiere@pidgin.im>
parents: 3630
diff changeset
5 #include <sys/types.h>
1a6d3f3bc682 [gaim-migrate @ 3793]
Luke Schierer <lschiere@pidgin.im>
parents: 3630
diff changeset
6 /*this must happen before sys/socket.h or freebsd won't compile*/
1a6d3f3bc682 [gaim-migrate @ 3793]
Luke Schierer <lschiere@pidgin.im>
parents: 3630
diff changeset
7
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
8 #ifndef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
9 #include <syslog.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
10 #include <strings.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
11 #include <sys/param.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
12 #include <sys/socket.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
13 #include <netinet/in.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
14 #include <netdb.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
15 #include <arpa/inet.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
16 #include <unistd.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
17 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
18 #include <winsock.h>
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3127
diff changeset
19 #endif
3127
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 #include <string.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 #include <stdlib.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 #include <stdio.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include <setjmp.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 #include <sys/stat.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 #include <fcntl.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include <errno.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
28 #include <signal.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include <sys/time.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include <stdarg.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include <ctype.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include <time.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include "xmlparse.h"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 /*
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 ** Arrange to use either varargs or stdargs
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 #define MAXSHORTSTR 203 /* max short string length */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 #define QUAD_T unsigned long long
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 #ifdef __STDC__
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 #include <stdarg.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 # define VA_LOCAL_DECL va_list ap;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 # define VA_START(f) va_start(ap, f)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 # define VA_END va_end(ap)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 #else /* __STDC__ */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 # include <varargs.h>
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 # define VA_LOCAL_DECL va_list ap;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 # define VA_START(f) va_start(ap)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 # define VA_END va_end(ap)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 #endif /* __STDC__ */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 #ifndef INCL_LIB_H
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 #define INCL_LIB_H
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 #ifdef __cplusplus
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 extern "C" {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 #endif
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 #ifndef HAVE_SNPRINTF
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 extern int ap_snprintf(char *, size_t, const char *, ...);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 #define snprintf ap_snprintf
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 #endif
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 #ifndef HAVE_VSNPRINTF
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 extern int ap_vsnprintf(char *, size_t, const char *, va_list ap);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 #define vsnprintf ap_vsnprintf
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 #endif
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 #define ZONE zonestr(__FILE__,__LINE__)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 char *zonestr(char *file, int line);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 /* Pool-based memory management routines */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 #undef POOL_DEBUG
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 /*
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91 flip these, this should be a prime number for top # of pools debugging
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 #define POOL_DEBUG 40009
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 /* pheap - singular allocation of memory */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 struct pheap
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 void *block;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 int size, used;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 };
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 /* pool_cleaner - callback type which is associated
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
103 with a pool entry; invoked when the pool entry is
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104 free'd */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
105 typedef void (*pool_cleaner)(void *arg);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107 /* pfree - a linked list node which stores an
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
108 allocation chunk, plus a callback */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109 struct pfree
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
110 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
111 pool_cleaner f;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
112 void *arg;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 struct pheap *heap;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
114 struct pfree *next;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 };
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 /* pool - base node for a pool. Maintains a linked list
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 of pool entries (pfree) */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 typedef struct pool_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 int size;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 struct pfree *cleanup;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 struct pheap *heap;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 #ifdef POOL_DEBUG
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 char name[8], zone[32];
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 int lsize;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 } _pool, *pool;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 #define pool_new() _pool_new(ZONE)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 #define pool_heap(i) _pool_new_heap(i,ZONE)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 #else
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 } _pool, *pool;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 #define pool_heap(i) _pool_new_heap(i,NULL)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 #define pool_new() _pool_new(NULL)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 #endif
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 pool _pool_new(char *zone); /* new pool :) */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 pool _pool_new_heap(int size, char *zone); /* creates a new memory pool with an initial heap size */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 void *pmalloc(pool p, int size); /* wrapper around malloc, takes from the pool, cleaned up automatically */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139 void *pmalloc_x(pool p, int size, char c); /* Wrapper around pmalloc which prefils buffer with c */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 void *pmalloco(pool p, int size); /* YAPW for zeroing the block */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 char *pstrdup(pool p, const char *src); /* wrapper around strdup, gains mem from pool */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 void pool_stat(int full); /* print to stderr the changed pools and reset */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 char *pstrdupx(pool p, const char *src); /* temp stub */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 void pool_cleanup(pool p, pool_cleaner f, void *arg); /* calls f(arg) before the pool is freed during cleanup */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 void pool_free(pool p); /* calls the cleanup functions, frees all the data on the pool, and deletes the pool itself */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 int pool_size(pool p); /* returns total bytes allocated in this pool */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 /* Socket helper stuff */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 #ifndef MAXHOSTNAMELEN
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 #define MAXHOSTNAMELEN 64
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 #endif
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 #define NETSOCKET_SERVER 0
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 #define NETSOCKET_CLIENT 1
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 #define NETSOCKET_UDP 2
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 int make_netsocket(u_short port, char *host, int type);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 struct in_addr *make_addr(char *host);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 int set_fd_close_on_exec(int fd, int flag);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 /* String management routines */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 char *j_strdup(const char *str); /* provides NULL safe strdup wrapper */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 char *j_strcat(char *dest, char *txt); /* strcpy() clone */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 int j_strcmp(const char *a, const char *b); /* provides NULL safe strcmp wrapper */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 int j_strcasecmp(const char *a, const char *b); /* provides NULL safe strcasecmp wrapper */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 int j_strncmp(const char *a, const char *b, int i); /* provides NULL safe strncmp wrapper */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 int j_strncasecmp(const char *a, const char *b, int i); /* provides NULL safe strncasecmp wrapper */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 int j_strlen(const char *a); /* provides NULL safe strlen wrapper */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 int j_atoi(const char *a, int def); /* checks for NULL and uses default instead, convienence */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 void str_b64decode(char *str); /* what it says */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 /* SHA calculations */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 #if (SIZEOF_INT == 4)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 typedef unsigned int uint32;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 #elif (SIZEOF_SHORT == 4)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 typedef unsigned short uint32;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 #else
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 typedef unsigned int uint32;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 #endif /* HAVEUINT32 */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 char *shahash(char *str); /* NOT THREAD SAFE */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 void shahash_r(const char* str, char hashbuf[40]); /* USE ME */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 int strprintsha(char *dest, int *hashval);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 /* Hashtable functions */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209 typedef struct xhn_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 struct xhn_struct *next;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 const char *key;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 void *val;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 } *xhn, _xhn;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 typedef struct xht_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 pool p;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 int prime;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 struct xhn_struct *zen;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 } *xht, _xht;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 xht xhash_new(int prime);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224 void xhash_put(xht h, const char *key, void *val);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 void *xhash_get(xht h, const char *key);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 void xhash_zap(xht h, const char *key);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227 void xhash_free(xht h);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 typedef void (*xhash_walker)(xht h, const char *key, void *val, void *arg);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 void xhash_walk(xht h, xhash_walker w, void *arg);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 /* DEPRECIATED Hashtable functions */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236 typedef int (*KEYHASHFUNC)(const void *key);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 typedef int (*KEYCOMPAREFUNC)(const void *key1, const void *key2);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 typedef int (*TABLEWALKFUNC)(void *user_data, const void *key, void *data);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 typedef void *HASHTABLE;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 HASHTABLE ghash_create(int buckets, KEYHASHFUNC hash, KEYCOMPAREFUNC cmp);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 HASHTABLE ghash_create_pool(pool p, int buckets, KEYHASHFUNC hash, KEYCOMPAREFUNC cmp);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 void ghash_destroy(HASHTABLE tbl);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245 void *ghash_get(HASHTABLE tbl, const void *key);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 int ghash_put(HASHTABLE tbl, const void *key, void *value);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 int ghash_remove(HASHTABLE tbl, const void *key);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248 int ghash_walk(HASHTABLE tbl, TABLEWALKFUNC func, void *user_data);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 int str_hash_code(const char *s);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 /* XML escaping utils */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 char *strescape(pool p, char *buf); /* Escape <>&'" chars */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258 char *strunescape(pool p, char *buf);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 /* String pools (spool) functions */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 struct spool_node
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 char *c;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 struct spool_node *next;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 };
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 typedef struct spool_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274 pool p;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 int len;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 struct spool_node *last;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277 struct spool_node *first;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 } *spool;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280 spool spool_new(pool p); /* create a string pool */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 void spooler(spool s, ...); /* append all the char * args to the pool, terminate args with s again */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282 char *spool_print(spool s); /* return a big string */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 void spool_add(spool s, char *str); /* add a single char to the pool */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 char *spools(pool p, ...); /* wrap all the spooler stuff in one function, the happy fun ball! */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 /* xmlnodes - Document Object Model */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 #define NTYPE_TAG 0
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 #define NTYPE_ATTRIB 1
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 #define NTYPE_CDATA 2
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296 #define NTYPE_LAST 2
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 #define NTYPE_UNDEF -1
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 /* --------------------------------------------------------------------------
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300 Node structure. Do not use directly! Always use accessor macros
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301 and methods!
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 -------------------------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 typedef struct xmlnode_t
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 char* name;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 unsigned short type;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 char* data;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 int data_sz;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 int complete;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310 pool p;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 struct xmlnode_t* parent;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 struct xmlnode_t* firstchild;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 struct xmlnode_t* lastchild;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 struct xmlnode_t* prev;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 struct xmlnode_t* next;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 struct xmlnode_t* firstattrib;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 struct xmlnode_t* lastattrib;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 } _xmlnode, *xmlnode;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 /* Node creation routines */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 xmlnode xmlnode_wrap(xmlnode x,const char* wrapper);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 xmlnode xmlnode_new_tag(const char* name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 xmlnode xmlnode_new_tag_pool(pool p, const char* name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 xmlnode xmlnode_insert_tag(xmlnode parent, const char* name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 xmlnode xmlnode_insert_cdata(xmlnode parent, const char* CDATA, unsigned int size);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 xmlnode xmlnode_insert_tag_node(xmlnode parent, xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 void xmlnode_insert_node(xmlnode parent, xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 xmlnode xmlnode_str(char *str, int len);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329 xmlnode xmlnode_file(char *file);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 char* xmlnode_file_borked(char *file); /* same as _file but returns the parsing error */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 xmlnode xmlnode_dup(xmlnode x); /* duplicate x */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 xmlnode xmlnode_dup_pool(pool p, xmlnode x);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334 /* Node Memory Pool */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 pool xmlnode_pool(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336 xmlnode _xmlnode_new(pool p, const char *name, unsigned int type);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 /* Node editing */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 void xmlnode_hide(xmlnode child);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 void xmlnode_hide_attrib(xmlnode parent, const char *name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 /* Node deletion routine, also frees the node pool! */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 void xmlnode_free(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 /* Locates a child tag by name and returns it */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 xmlnode xmlnode_get_tag(xmlnode parent, const char* name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 char* xmlnode_get_tag_data(xmlnode parent, const char* name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 /* Attribute accessors */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 void xmlnode_put_attrib(xmlnode owner, const char* name, const char* value);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 char* xmlnode_get_attrib(xmlnode owner, const char* name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 void xmlnode_put_expat_attribs(xmlnode owner, const char** atts);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 /* Bastard am I, but these are fun for internal use ;-) */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 void xmlnode_put_vattrib(xmlnode owner, const char* name, void *value);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 void* xmlnode_get_vattrib(xmlnode owner, const char* name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 /* Node traversal routines */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 xmlnode xmlnode_get_firstattrib(xmlnode parent);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 xmlnode xmlnode_get_firstchild(xmlnode parent);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 xmlnode xmlnode_get_lastchild(xmlnode parent);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 xmlnode xmlnode_get_nextsibling(xmlnode sibling);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 xmlnode xmlnode_get_prevsibling(xmlnode sibling);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 xmlnode xmlnode_get_parent(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 /* Node information routines */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 char* xmlnode_get_name(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 char* xmlnode_get_data(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 int xmlnode_get_datasz(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 int xmlnode_get_type(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 int xmlnode_has_children(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 int xmlnode_has_attribs(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 /* Node-to-string translation */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 char* xmlnode2str(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 /* Node-to-terminated-string translation
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 -- useful for interfacing w/ scripting langs */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380 char* xmlnode2tstr(xmlnode node);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382 int xmlnode_cmp(xmlnode a, xmlnode b); /* compares a and b for equality */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 int xmlnode2file(char *file, xmlnode node); /* writes node to file */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 /* Expat callbacks */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 void expat_startElement(void* userdata, const char* name, const char** atts);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388 void expat_endElement(void* userdata, const char* name);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 void expat_charData(void* userdata, const char* s, int len);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391 /***********************
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 * XSTREAM Section
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 ***********************/
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 #define XSTREAM_MAXNODE 1000000
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396 #define XSTREAM_MAXDEPTH 100
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 #define XSTREAM_ROOT 0 /* root element */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 #define XSTREAM_NODE 1 /* normal node */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400 #define XSTREAM_CLOSE 2 /* closed </stream:stream> */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401 #define XSTREAM_ERR 4 /* parser error */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 typedef void (*xstream_onNode)(int type, xmlnode x, void *arg); /* xstream event handler */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 typedef struct xstream_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 XML_Parser parser;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 xmlnode node;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 char *cdata;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 int cdata_len;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 pool p;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 xstream_onNode f;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413 void *arg;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 int status;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 int depth;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 } *xstream, _xstream;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 xstream xstream_new(pool p, xstream_onNode f, void *arg); /* create a new xstream */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 int xstream_eat(xstream xs, char *buff, int len); /* parse new data for this xstream, returns last XSTREAM_* status */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421 /* convience functions */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 xmlnode xstream_header(char *namespace, char *to, char *from);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423 char *xstream_header_char(xmlnode x);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426 typedef struct {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427 unsigned long H[5];
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 unsigned long W[80];
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429 int lenW;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 unsigned long sizeHi,sizeLo;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 } j_SHA_CTX;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434 void shaInit(j_SHA_CTX *ctx);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 void shaUpdate(j_SHA_CTX *ctx, unsigned char *dataIn, int len);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436 void shaFinal(j_SHA_CTX *ctx, unsigned char hashout[20]);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
437 void shaBlock(unsigned char *dataIn, int len, unsigned char hashout[20]);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 /********** END OLD libxode.h BEGIN OLD jabber.h *************/
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
441 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
442 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 /* JID structures & constants */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446 #define JID_RESOURCE 1
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 #define JID_USER 2
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448 #define JID_SERVER 4
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 typedef struct jid_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 pool p;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 char* resource;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 char* user;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 char* server;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 char* full;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 struct jid_struct *next; /* for lists of jids */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 } *jid;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460 jid jid_new(pool p, char *idstr); /* Creates a jabber id from the idstr */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 void jid_set(jid id, char *str, int item); /* Individually sets jid components */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 char* jid_full(jid id); /* Builds a string type=user/resource@server from the jid data */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463 int jid_cmp(jid a, jid b); /* Compares two jid's, returns 0 for perfect match */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 int jid_cmpx(jid a, jid b, int parts); /* Compares just the parts specified as JID_|JID_ */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 jid jid_append(jid a, jid b); /* Appending b to a (list), no dups */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466 xmlnode jid_xres(jid id); /* Returns xmlnode representation of the resource?query=string */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 xmlnode jid_nodescan(jid id, xmlnode x); /* Scans the children of the node for a matching jid attribute */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 jid jid_user(jid a); /* returns the same jid but just of the user@host part */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 /* JPacket structures & constants */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476 #define JPACKET_UNKNOWN 0x00
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477 #define JPACKET_MESSAGE 0x01
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 #define JPACKET_PRESENCE 0x02
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479 #define JPACKET_IQ 0x04
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480 #define JPACKET_S10N 0x08
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 #define JPACKET__UNKNOWN 0
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 #define JPACKET__NONE 1
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 #define JPACKET__ERROR 2
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 #define JPACKET__CHAT 3
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 #define JPACKET__GROUPCHAT 4
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487 #define JPACKET__GET 5
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 #define JPACKET__SET 6
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 #define JPACKET__RESULT 7
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490 #define JPACKET__SUBSCRIBE 8
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 #define JPACKET__SUBSCRIBED 9
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 #define JPACKET__UNSUBSCRIBE 10
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 #define JPACKET__UNSUBSCRIBED 11
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494 #define JPACKET__AVAILABLE 12
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495 #define JPACKET__UNAVAILABLE 13
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
496 #define JPACKET__PROBE 14
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
497 #define JPACKET__HEADLINE 15
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 #define JPACKET__INVISIBLE 16
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500 typedef struct jpacket_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 unsigned char type;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503 int subtype;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504 int flag;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 void* aux1;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 xmlnode x;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507 jid to;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508 jid from;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 char* iqns;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 xmlnode iq;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 pool p;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 } *jpacket, _jpacket;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 jpacket jpacket_new(xmlnode x); /* Creates a jabber packet from the xmlnode */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 jpacket jpacket_reset(jpacket p); /* Resets the jpacket values based on the xmlnode */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 int jpacket_subtype(jpacket p); /* Returns the subtype value (looks at xmlnode for it) */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521 /* Presence Proxy DB structures & constants */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 typedef struct ppdb_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 jid id; /* entry data */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 int pri;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 xmlnode x;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 struct ppdb_struct* user; /* linked list for user@server */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 pool p; /* db-level data */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 struct ppdb_struct* next;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 } _ppdb, *ppdb;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 ppdb ppdb_insert(ppdb db, jid id, xmlnode x); /* Inserts presence into the proxy */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 xmlnode ppdb_primary(ppdb db, jid id); /* Fetches the matching primary presence for the id */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 void ppdb_free(ppdb db); /* Frees the db and all entries */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 xmlnode ppdb_get(ppdb db, jid id); /* Called successively to return each presence xmlnode */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 /* for the id and children, returns NULL at the end */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 /* Simple Jabber Rate limit functions */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 typedef struct jlimit_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
548 char *key;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 int start;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 int points;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551 int maxt, maxp;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552 pool p;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 } *jlimit, _jlimit;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555 jlimit jlimit_new(int maxt, int maxp);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556 void jlimit_free(jlimit r);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 int jlimit_check(jlimit r, char *key, int points);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
558
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560 // #define KARMA_DEBUG
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 // default to disable karma
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562 #define KARMA_READ_MAX(k) (abs(k)*100) /* how much you are allowed to read off the sock */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 #define KARMA_INIT 5 /* internal "init" value */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 #define KARMA_HEARTBEAT 2 /* seconds to register for heartbeat */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 #define KARMA_MAX 10 /* total max karma you can have */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 #define KARMA_INC 1 /* how much to increment every KARMA_HEARTBEAT seconds */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 #define KARMA_DEC 0 /* how much to penalize for reading KARMA_READ_MAX in
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568 KARMA_HEARTBEAT seconds */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 #define KARMA_PENALTY -5 /* where you go when you hit 0 karma */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570 #define KARMA_RESTORE 5 /* where you go when you payed your penelty or INIT */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 #define KARMA_RESETMETER 0 /* Reset byte meter on restore default is falst */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573 struct karma
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 int init; /* struct initialized */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 int reset_meter; /* reset the byte meter on restore */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 int val; /* current karma value */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 long bytes; /* total bytes read (in that time period) */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579 int max; /* max karma you can have */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 int inc,dec; /* how much to increment/decrement */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 int penalty,restore; /* what penalty (<0) or restore (>0) */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582 time_t last_update; /* time this was last incremented */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 };
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585 struct karma *karma_new(pool p); /* creates a new karma object, with default values */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586 void karma_copy(struct karma *new, struct karma *old); /* makes a copy of old in new */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
587 void karma_increment(struct karma *k); /* inteligently increments karma */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 void karma_decrement(struct karma *k, long bytes_read); /* inteligently decrements karma */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
589 int karma_check(struct karma *k,long bytes_read); /* checks to see if we have good karma */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
591
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 /* Error structures & constants */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
596 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 typedef struct terror_struct
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 {
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 int code;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 char msg[64];
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602 } terror;
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 #define TERROR_BAD (terror){400,"Bad Request"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 #define TERROR_AUTH (terror){401,"Unauthorized"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606 #define TERROR_PAY (terror){402,"Payment Required"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 #define TERROR_FORBIDDEN (terror){403,"Forbidden"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608 #define TERROR_NOTFOUND (terror){404,"Not Found"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609 #define TERROR_NOTALLOWED (terror){405,"Not Allowed"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 #define TERROR_NOTACCEPTABLE (terror){406,"Not Acceptable"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 #define TERROR_REGISTER (terror){407,"Registration Required"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 #define TERROR_REQTIMEOUT (terror){408,"Request Timeout"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613 #define TERROR_CONFLICT (terror){409,"Conflict"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 #define TERROR_INTERNAL (terror){500,"Internal Server Error"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616 #define TERROR_NOTIMPL (terror){501,"Not Implemented"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 #define TERROR_EXTERNAL (terror){502,"Remote Server Error"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 #define TERROR_UNAVAIL (terror){503,"Service Unavailable"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 #define TERROR_EXTTIMEOUT (terror){504,"Remote Server Timeout"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 #define TERROR_DISCONNECTED (terror){510,"Disconnected"}
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624 /* Namespace constants */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
626 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627 #define NSCHECK(x,n) (j_strcmp(xmlnode_get_attrib(x,"xmlns"),n) == 0)
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
629 #define NS_CLIENT "jabber:client"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
630 #define NS_SERVER "jabber:server"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
631 #define NS_AUTH "jabber:iq:auth"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
632 #define NS_REGISTER "jabber:iq:register"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633 #define NS_ROSTER "jabber:iq:roster"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 #define NS_OFFLINE "jabber:x:offline"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
635 #define NS_AGENT "jabber:iq:agent"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636 #define NS_AGENTS "jabber:iq:agents"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 #define NS_DELAY "jabber:x:delay"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638 #define NS_VERSION "jabber:iq:version"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 #define NS_TIME "jabber:iq:time"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 #define NS_VCARD "vcard-temp"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641 #define NS_PRIVATE "jabber:iq:private"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 #define NS_SEARCH "jabber:iq:search"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
643 #define NS_OOB "jabber:iq:oob"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 #define NS_XOOB "jabber:x:oob"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645 #define NS_ADMIN "jabber:iq:admin"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 #define NS_FILTER "jabber:iq:filter"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647 #define NS_AUTH_0K "jabber:iq:auth:0k"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 #define NS_BROWSE "jabber:iq:browse"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649 #define NS_EVENT "jabber:x:event"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 #define NS_CONFERENCE "jabber:iq:conference"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 #define NS_SIGNED "jabber:x:signed"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 #define NS_ENCRYPTED "jabber:x:encrypted"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653 #define NS_GATEWAY "jabber:iq:gateway"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 #define NS_LAST "jabber:iq:last"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
655 #define NS_ENVELOPE "jabber:x:envelope"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656 #define NS_EXPIRE "jabber:x:expire"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 #define NS_XHTML "http://www.w3.org/1999/xhtml"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 #define NS_XDBGINSERT "jabber:xdb:ginsert"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660 #define NS_XDBNSLIST "jabber:xdb:nslist"
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
661
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
662
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
663 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
665 /* JUtil functions */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
666 /* */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667 /* --------------------------------------------------------- */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668 xmlnode jutil_presnew(int type, char *to, char *status); /* Create a skeleton presence packet */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669 xmlnode jutil_iqnew(int type, char *ns); /* Create a skeleton iq packet */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 xmlnode jutil_msgnew(char *type, char *to, char *subj, char *body);
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671 /* Create a skeleton message packet */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
672 xmlnode jutil_header(char* xmlns, char* server); /* Create a skeleton stream packet */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
673 int jutil_priority(xmlnode x); /* Determine priority of this packet */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674 void jutil_tofrom(xmlnode x); /* Swaps to/from fields on a packet */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 xmlnode jutil_iqresult(xmlnode x); /* Generate a skeleton iq/result, given a iq/query */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
676 char* jutil_timestamp(void); /* Get stringified timestamp */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
677 void jutil_error(xmlnode x, terror E); /* Append an <error> node to x */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
678 void jutil_delay(xmlnode msg, char *reason); /* Append a delay packet to msg */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
679 char* jutil_regkey(char *key, char *seed); /* pass a seed to generate a key, pass the key again to validate (returns it) */
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
680
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
681
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
682 #ifdef __cplusplus
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
683 }
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684 #endif
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
685
4e7cefc55971 [gaim-migrate @ 3142]
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
686 #endif /* INCL_LIB_H */