Mercurial > pidgin
annotate src/protocols/jabber/libxode.h @ 4560:eb32b3acef97
[gaim-migrate @ 4841]
Now that we have something else under 'Interfaces', I feel fine with removing things.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Sun, 09 Feb 2003 00:47:57 +0000 |
parents | 988485669631 |
children | 8d8bf0d31a23 |
rev | line source |
---|---|
3630 | 1 #ifndef _WIN32 |
2 #include <syslog.h> | |
3 #include <sys/socket.h> | |
4 #include <netinet/in.h> | |
5 #include <netdb.h> | |
6 #include <arpa/inet.h> | |
7 #include <strings.h> | |
8 #include <arpa/nameser.h> | |
9 #include <resolv.h> | |
10 #include <unistd.h> | |
11 #else | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
12 #include <winsock.h> |
3630 | 13 #endif |
14 | |
2086 | 15 #include <string.h> |
16 #include <stdlib.h> | |
17 #include <sys/types.h> | |
18 #include <stdio.h> | |
19 #include <setjmp.h> | |
20 #include <sys/stat.h> | |
21 #include <fcntl.h> | |
22 #include <errno.h> | |
23 #include <signal.h> | |
24 #include <sys/time.h> | |
2903
7630fb86df77
[gaim-migrate @ 2916]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
25 #include <time.h> |
2086 | 26 |
27 #include "xmlparse.h" | |
28 #ifdef HAVE_CONFIG_H | |
29 #include <config.h> | |
30 #endif /* HAVE_CONFIG_H */ | |
31 | |
32 /* | |
33 ** Arrange to use either varargs or stdargs | |
34 */ | |
35 | |
36 #define MAXSHORTSTR 203 /* max short string length */ | |
37 #define QUAD_T unsigned long long | |
38 | |
39 #ifdef __STDC__ | |
40 | |
41 #include <stdarg.h> | |
42 | |
43 # define VA_LOCAL_DECL va_list ap; | |
44 # define VA_START(f) va_start(ap, f) | |
45 # define VA_END va_end(ap) | |
46 | |
47 #else /* __STDC__ */ | |
48 | |
49 # include <varargs.h> | |
50 | |
51 # define VA_LOCAL_DECL va_list ap; | |
52 # define VA_START(f) va_start(ap) | |
53 # define VA_END va_end(ap) | |
54 | |
55 #endif /* __STDC__ */ | |
56 | |
57 | |
58 #ifndef INCL_LIBXODE_H | |
59 #define INCL_LIBXODE_H | |
60 | |
61 #ifdef __cplusplus | |
62 extern "C" { | |
63 #endif | |
64 | |
65 | |
66 #ifndef HAVE_SNPRINTF | |
67 extern int ap_snprintf(char *, size_t, const char *, ...); | |
68 #define snprintf ap_snprintf | |
69 #endif | |
70 | |
71 #ifndef HAVE_VSNPRINTF | |
72 extern int ap_vsnprintf(char *, size_t, const char *, va_list ap); | |
73 #define vsnprintf ap_vsnprintf | |
74 #endif | |
75 | |
76 #define ZONE zonestr(__FILE__,__LINE__) | |
77 char *zonestr(char *file, int line); | |
78 | |
79 /* --------------------------------------------------------- */ | |
80 /* */ | |
81 /* Pool-based memory management routines */ | |
82 /* */ | |
83 /* --------------------------------------------------------- */ | |
84 | |
85 #undef POOL_DEBUG | |
86 /* | |
87 flip these, this should be a prime number for top # of pools debugging | |
88 #define POOL_DEBUG 40009 | |
89 */ | |
90 | |
91 /* pheap - singular allocation of memory */ | |
92 struct pheap | |
93 { | |
94 void *block; | |
95 int size, used; | |
96 }; | |
97 | |
98 /* pool_cleaner - callback type which is associated | |
99 with a pool entry; invoked when the pool entry is | |
100 free'd */ | |
101 typedef void (*pool_cleaner)(void *arg); | |
102 | |
103 /* pfree - a linked list node which stores an | |
104 allocation chunk, plus a callback */ | |
105 struct pfree | |
106 { | |
107 pool_cleaner f; | |
108 void *arg; | |
109 struct pheap *heap; | |
110 struct pfree *next; | |
111 }; | |
112 | |
113 /* pool - base node for a pool. Maintains a linked list | |
114 of pool entries (pfree) */ | |
115 typedef struct pool_struct | |
116 { | |
117 int size; | |
118 struct pfree *cleanup; | |
119 struct pheap *heap; | |
120 #ifdef POOL_DEBUG | |
121 char name[8], zone[32]; | |
122 int lsize; | |
123 } _pool, *pool; | |
124 #define pool_new() _pool_new(ZONE) | |
125 #define pool_heap(i) _pool_new_heap(i,ZONE) | |
126 #else | |
127 } _pool, *pool; | |
128 #define pool_heap(i) _pool_new_heap(i,NULL) | |
129 #define pool_new() _pool_new(NULL) | |
130 #endif | |
131 | |
132 pool _pool_new(char *zone); /* new pool :) */ | |
133 pool _pool_new_heap(int size, char *zone); /* creates a new memory pool with an initial heap size */ | |
134 void *pmalloc(pool p, int size); /* wrapper around malloc, takes from the pool, cleaned up automatically */ | |
135 void *pmalloc_x(pool p, int size, char c); /* Wrapper around pmalloc which prefils buffer with c */ | |
136 void *pmalloco(pool p, int size); /* YAPW for zeroing the block */ | |
137 char *pstrdup(pool p, const char *src); /* wrapper around strdup, gains mem from pool */ | |
138 void pool_stat(int full); /* print to stderr the changed pools and reset */ | |
139 char *pstrdupx(pool p, const char *src); /* temp stub */ | |
140 void pool_cleanup(pool p, pool_cleaner f, void *arg); /* calls f(arg) before the pool is freed during cleanup */ | |
141 void pool_free(pool p); /* calls the cleanup functions, frees all the data on the pool, and deletes the pool itself */ | |
142 int pool_size(pool p); /* returns total bytes allocated in this pool */ | |
143 | |
144 | |
145 | |
146 | |
147 /* --------------------------------------------------------- */ | |
148 /* */ | |
149 /* Socket helper stuff */ | |
150 /* */ | |
151 /* --------------------------------------------------------- */ | |
152 #ifndef MAXHOSTNAMELEN | |
153 #define MAXHOSTNAMELEN 64 | |
154 #endif | |
155 | |
156 #define NETSOCKET_SERVER 0 | |
157 #define NETSOCKET_CLIENT 1 | |
158 #define NETSOCKET_UDP 2 | |
159 | |
160 int make_netsocket(u_short port, char *host, int type); | |
161 struct in_addr *make_addr(char *host); | |
162 int set_fd_close_on_exec(int fd, int flag); | |
163 | |
164 | |
165 /* --------------------------------------------------------- */ | |
166 /* */ | |
167 /* String management routines */ | |
168 /* */ | |
169 /* --------------------------------------------------------- */ | |
170 char *j_strdup(const char *str); /* provides NULL safe strdup wrapper */ | |
171 char *j_strcat(char *dest, char *txt); /* strcpy() clone */ | |
172 int j_strcmp(const char *a, const char *b); /* provides NULL safe strcmp wrapper */ | |
173 int j_strcasecmp(const char *a, const char *b); /* provides NULL safe strcasecmp wrapper */ | |
174 int j_strncmp(const char *a, const char *b, int i); /* provides NULL safe strncmp wrapper */ | |
175 int j_strncasecmp(const char *a, const char *b, int i); /* provides NULL safe strncasecmp wrapper */ | |
176 int j_strlen(const char *a); /* provides NULL safe strlen wrapper */ | |
177 int j_atoi(const char *a, int def); /* checks for NULL and uses default instead, convienence */ | |
178 void str_b64decode(char *str); /* what it says */ | |
179 | |
180 | |
181 /* --------------------------------------------------------- */ | |
182 /* */ | |
183 /* SHA calculations */ | |
184 /* */ | |
185 /* --------------------------------------------------------- */ | |
186 #if (SIZEOF_INT == 4) | |
187 typedef unsigned int uint32; | |
188 #elif (SIZEOF_SHORT == 4) | |
189 typedef unsigned short uint32; | |
190 #else | |
191 typedef unsigned int uint32; | |
192 #endif /* HAVEUINT32 */ | |
193 | |
194 int sha_hash(int *data, int *hash); | |
195 int sha_init(int *hash); | |
196 char *shahash(char *str); /* NOT THREAD SAFE */ | |
197 void shahash_r(const char* str, char hashbuf[40]); /* USE ME */ | |
198 | |
199 int strprintsha(char *dest, int *hashval); | |
200 | |
201 | |
202 /* --------------------------------------------------------- */ | |
203 /* */ | |
204 /* Hashtable functions */ | |
205 /* */ | |
206 /* --------------------------------------------------------- */ | |
207 typedef int (*KEYHASHFUNC)(const void *key); | |
208 typedef int (*KEYCOMPAREFUNC)(const void *key1, const void *key2); | |
209 typedef int (*TABLEWALKFUNC)(void *user_data, const void *key, void *data); | |
210 | |
211 typedef void *HASHTABLE; | |
212 | |
213 HASHTABLE ghash_create(int buckets, KEYHASHFUNC hash, KEYCOMPAREFUNC cmp); | |
214 void ghash_destroy(HASHTABLE tbl); | |
215 void *ghash_get(HASHTABLE tbl, const void *key); | |
216 int ghash_put(HASHTABLE tbl, const void *key, void *value); | |
217 int ghash_remove(HASHTABLE tbl, const void *key); | |
218 int ghash_walk(HASHTABLE tbl, TABLEWALKFUNC func, void *user_data); | |
219 int str_hash_code(const char *s); | |
220 | |
221 | |
222 /* --------------------------------------------------------- */ | |
223 /* */ | |
224 /* XML escaping utils */ | |
225 /* */ | |
226 /* --------------------------------------------------------- */ | |
227 char *strescape(pool p, char *buf); /* Escape <>&'" chars */ | |
228 char *strunescape(pool p, char *buf); | |
229 | |
230 | |
231 /* --------------------------------------------------------- */ | |
232 /* */ | |
233 /* String pools (spool) functions */ | |
234 /* */ | |
235 /* --------------------------------------------------------- */ | |
236 struct spool_node | |
237 { | |
238 char *c; | |
239 struct spool_node *next; | |
240 }; | |
241 | |
242 typedef struct spool_struct | |
243 { | |
244 pool p; | |
245 int len; | |
246 struct spool_node *last; | |
247 struct spool_node *first; | |
248 } *spool; | |
249 | |
250 spool spool_new(pool p); /* create a string pool */ | |
251 void spooler(spool s, ...); /* append all the char * args to the pool, terminate args with s again */ | |
252 char *spool_print(spool s); /* return a big string */ | |
253 void spool_add(spool s, char *str); /* add a single char to the pool */ | |
254 char *spools(pool p, ...); /* wrap all the spooler stuff in one function, the happy fun ball! */ | |
255 | |
256 | |
257 /* --------------------------------------------------------- */ | |
258 /* */ | |
259 /* xmlnodes - Document Object Model */ | |
260 /* */ | |
261 /* --------------------------------------------------------- */ | |
262 #define NTYPE_TAG 0 | |
263 #define NTYPE_ATTRIB 1 | |
264 #define NTYPE_CDATA 2 | |
265 | |
266 #define NTYPE_LAST 2 | |
267 #define NTYPE_UNDEF -1 | |
268 | |
269 /* -------------------------------------------------------------------------- | |
270 Node structure. Do not use directly! Always use accessor macros | |
271 and methods! | |
272 -------------------------------------------------------------------------- */ | |
273 typedef struct xmlnode_t | |
274 { | |
275 char* name; | |
276 unsigned short type; | |
277 char* data; | |
278 int data_sz; | |
279 int complete; | |
280 pool p; | |
281 struct xmlnode_t* parent; | |
282 struct xmlnode_t* firstchild; | |
283 struct xmlnode_t* lastchild; | |
284 struct xmlnode_t* prev; | |
285 struct xmlnode_t* next; | |
286 struct xmlnode_t* firstattrib; | |
287 struct xmlnode_t* lastattrib; | |
288 } _xmlnode, *xmlnode; | |
289 | |
290 /* Node creation routines */ | |
291 xmlnode xmlnode_wrap(xmlnode x,const char* wrapper); | |
292 xmlnode xmlnode_new_tag(const char* name); | |
293 xmlnode xmlnode_new_tag_pool(pool p, const char* name); | |
294 xmlnode xmlnode_insert_tag(xmlnode parent, const char* name); | |
295 xmlnode xmlnode_insert_cdata(xmlnode parent, const char* CDATA, unsigned int size); | |
296 xmlnode xmlnode_insert_tag_node(xmlnode parent, xmlnode node); | |
297 void xmlnode_insert_node(xmlnode parent, xmlnode node); | |
298 xmlnode xmlnode_str(char *str, int len); | |
299 xmlnode xmlnode_file(char *file); | |
300 xmlnode xmlnode_dup(xmlnode x); /* duplicate x */ | |
301 xmlnode xmlnode_dup_pool(pool p, xmlnode x); | |
302 | |
303 /* Node Memory Pool */ | |
304 pool xmlnode_pool(xmlnode node); | |
305 xmlnode _xmlnode_new(pool p, const char *name, unsigned int type); | |
306 | |
307 /* Node editing */ | |
308 void xmlnode_hide(xmlnode child); | |
309 void xmlnode_hide_attrib(xmlnode parent, const char *name); | |
310 | |
311 /* Node deletion routine, also frees the node pool! */ | |
312 void xmlnode_free(xmlnode node); | |
313 | |
314 /* Locates a child tag by name and returns it */ | |
315 xmlnode xmlnode_get_tag(xmlnode parent, const char* name); | |
316 char* xmlnode_get_tag_data(xmlnode parent, const char* name); | |
317 | |
318 /* Attribute accessors */ | |
319 void xmlnode_put_attrib(xmlnode owner, const char* name, const char* value); | |
320 char* xmlnode_get_attrib(xmlnode owner, const char* name); | |
321 void xmlnode_put_expat_attribs(xmlnode owner, const char** atts); | |
322 | |
323 /* Bastard am I, but these are fun for internal use ;-) */ | |
324 void xmlnode_put_vattrib(xmlnode owner, const char* name, void *value); | |
325 void* xmlnode_get_vattrib(xmlnode owner, const char* name); | |
326 | |
327 /* Node traversal routines */ | |
328 xmlnode xmlnode_get_firstattrib(xmlnode parent); | |
329 xmlnode xmlnode_get_firstchild(xmlnode parent); | |
330 xmlnode xmlnode_get_lastchild(xmlnode parent); | |
331 xmlnode xmlnode_get_nextsibling(xmlnode sibling); | |
332 xmlnode xmlnode_get_prevsibling(xmlnode sibling); | |
333 xmlnode xmlnode_get_parent(xmlnode node); | |
334 | |
335 /* Node information routines */ | |
336 char* xmlnode_get_name(xmlnode node); | |
337 char* xmlnode_get_data(xmlnode node); | |
338 int xmlnode_get_datasz(xmlnode node); | |
339 int xmlnode_get_type(xmlnode node); | |
340 | |
341 int xmlnode_has_children(xmlnode node); | |
342 int xmlnode_has_attribs(xmlnode node); | |
343 | |
344 /* Node-to-string translation */ | |
345 char* xmlnode2str(xmlnode node); | |
346 | |
347 /* Node-to-terminated-string translation | |
348 -- useful for interfacing w/ scripting langs */ | |
349 char* xmlnode2tstr(xmlnode node); | |
350 | |
351 int xmlnode_cmp(xmlnode a, xmlnode b); /* compares a and b for equality */ | |
352 | |
353 int xmlnode2file(char *file, xmlnode node); /* writes node to file */ | |
354 | |
355 /* Expat callbacks */ | |
356 void expat_startElement(void* userdata, const char* name, const char** atts); | |
357 void expat_endElement(void* userdata, const char* name); | |
358 void expat_charData(void* userdata, const char* s, int len); | |
359 | |
360 /*********************** | |
361 * XSTREAM Section | |
362 ***********************/ | |
363 | |
364 #define XSTREAM_MAXNODE 1000000 | |
365 #define XSTREAM_MAXDEPTH 100 | |
366 | |
367 #define XSTREAM_ROOT 0 /* root element */ | |
368 #define XSTREAM_NODE 1 /* normal node */ | |
369 #define XSTREAM_CLOSE 2 /* closed </stream:stream> */ | |
370 #define XSTREAM_ERR 4 /* parser error */ | |
371 | |
372 typedef void (*xstream_onNode)(int type, xmlnode x, void *arg); /* xstream event handler */ | |
373 | |
374 typedef struct xstream_struct | |
375 { | |
376 XML_Parser parser; | |
377 xmlnode node; | |
378 char *cdata; | |
379 int cdata_len; | |
380 pool p; | |
381 xstream_onNode f; | |
382 void *arg; | |
383 int status; | |
384 int depth; | |
385 } *xstream, _xstream; | |
386 | |
387 xstream xstream_new(pool p, xstream_onNode f, void *arg); /* create a new xstream */ | |
388 int xstream_eat(xstream xs, char *buff, int len); /* parse new data for this xstream, returns last XSTREAM_* status */ | |
389 | |
390 /* convience functions */ | |
391 xmlnode xstream_header(char *namespace, char *to, char *from); | |
392 char *xstream_header_char(xmlnode x); | |
393 | |
394 /* SHA.H */ | |
395 /* | |
396 * The contents of this file are subject to the Mozilla Public | |
397 * License Version 1.1 (the "License"); you may not use this file | |
398 * except in compliance with the License. You may obtain a copy of | |
399 * the License at http://www.mozilla.org/MPL/ | |
400 * | |
401 * Software distributed under the License is distributed on an "AS | |
402 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
403 * implied. See the License for the specific language governing | |
404 * rights and limitations under the License. | |
405 * | |
406 * The Original Code is SHA 180-1 Header File | |
407 * | |
408 * The Initial Developer of the Original Code is Paul Kocher of | |
409 * Cryptography Research. Portions created by Paul Kocher are | |
410 * Copyright (C) 1995-9 by Cryptography Research, Inc. All | |
411 * Rights Reserved. | |
412 * | |
413 * Contributor(s): | |
414 * | |
415 * Paul Kocher | |
416 * | |
417 * Alternatively, the contents of this file may be used under the | |
418 * terms of the GNU General Public License Version 2 or later (the | |
419 * "GPL"), in which case the provisions of the GPL are applicable | |
420 * instead of those above. If you wish to allow use of your | |
421 * version of this file only under the terms of the GPL and not to | |
422 * allow others to use your version of this file under the MPL, | |
423 * indicate your decision by deleting the provisions above and | |
424 * replace them with the notice and other provisions required by | |
425 * the GPL. If you do not delete the provisions above, a recipient | |
426 * may use your version of this file under either the MPL or the | |
427 * GPL. | |
428 */ | |
429 | |
430 typedef struct { | |
431 unsigned long H[5]; | |
432 unsigned long W[80]; | |
433 int lenW; | |
434 unsigned long sizeHi,sizeLo; | |
435 } SHA_CTX; | |
436 | |
437 | |
438 void shaInit(SHA_CTX *ctx); | |
439 void shaUpdate(SHA_CTX *ctx, unsigned char *dataIn, int len); | |
440 void shaFinal(SHA_CTX *ctx, unsigned char hashout[20]); | |
441 void shaBlock(unsigned char *dataIn, int len, unsigned char hashout[20]); | |
442 | |
443 | |
444 /* END SHA.H */ | |
445 | |
446 #ifdef __cplusplus | |
447 } | |
448 #endif | |
449 | |
450 #endif /* INCL_LIBXODE_H */ |