Mercurial > ~mikael > mcabber > hg
comparison mcabber/libjabber/libxode.h @ 417:c3ae9251c197
Sync libjabber with upstream
Sync with jabberd-1.4.4.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 01 Sep 2005 23:29:21 +0200 |
parents | bf3d6e241714 |
children | 9054697b1a06 |
comparison
equal
deleted
inserted
replaced
416:48e7808c4191 | 417:c3ae9251c197 |
---|---|
1 /* | |
2 * jabberd - Jabber Open Source Server | |
3 * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, | |
4 * Ryan Eatmon, Robert Norris | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA | |
19 */ | |
20 | |
21 #ifdef HAVE_CONFIG_H | |
22 # include <config.h> | |
23 #endif | |
24 | |
1 #include <string.h> | 25 #include <string.h> |
2 #include <stdlib.h> | 26 #include <stdlib.h> |
3 #include <sys/types.h> | 27 #include <sys/types.h> |
4 #include <stdio.h> | 28 #include <stdio.h> |
5 #include <setjmp.h> | 29 #include <setjmp.h> |
6 #include <sys/stat.h> | 30 #include <sys/stat.h> |
7 #include <fcntl.h> | 31 #include <fcntl.h> |
8 #include <errno.h> | 32 #include <errno.h> |
9 #include <signal.h> | 33 #include <signal.h> |
10 #include <syslog.h> | |
11 #include <strings.h> | 34 #include <strings.h> |
12 #include <unistd.h> | 35 #include <unistd.h> |
13 #include <sys/socket.h> | 36 #include <sys/time.h> |
37 #include <syslog.h> | |
14 #include <netinet/in.h> | 38 #include <netinet/in.h> |
15 #include <netdb.h> | 39 #include <netdb.h> |
16 #include <arpa/inet.h> | 40 #include <arpa/inet.h> |
17 #include <sys/time.h> | 41 #include <sys/socket.h> |
18 | 42 |
19 #include "xmlparse.h" | 43 #include "xmlparse.h" |
20 #ifdef HAVE_CONFIG_H | |
21 #include <config.h> | |
22 #endif /* HAVE_CONFIG_H */ | |
23 | 44 |
24 /* | 45 /* |
25 ** Arrange to use either varargs or stdargs | 46 ** Arrange to use either varargs or stdargs |
26 */ | 47 */ |
27 | 48 |
28 #define MAXSHORTSTR 203 /* max short string length */ | 49 #define MAXSHORTSTR 203 /* max short string length */ |
29 #define QUAD_T unsigned long long | 50 #define QUAD_T unsigned long long |
30 | 51 |
31 #ifdef __STDC__ | 52 #ifdef __STDC__ |
32 | 53 |
33 #include <stdarg.h> | 54 #include <stdarg.h> |
34 | 55 |
75 /* --------------------------------------------------------- */ | 96 /* --------------------------------------------------------- */ |
76 | 97 |
77 #undef POOL_DEBUG | 98 #undef POOL_DEBUG |
78 /* | 99 /* |
79 flip these, this should be a prime number for top # of pools debugging | 100 flip these, this should be a prime number for top # of pools debugging |
80 #define POOL_DEBUG 40009 | 101 #define POOL_DEBUG 40009 |
81 */ | 102 */ |
82 | 103 |
83 /* pheap - singular allocation of memory */ | 104 /* pheap - singular allocation of memory */ |
84 struct pheap | 105 struct pheap |
85 { | 106 { |
86 void *block; | 107 void *block; |
87 int size, used; | 108 int size, used; |
88 }; | 109 }; |
89 | 110 |
90 /* pool_cleaner - callback type which is associated | 111 /* pool_cleaner - callback type which is associated |
91 with a pool entry; invoked when the pool entry is | 112 with a pool entry; invoked when the pool entry is |
92 free'd */ | 113 free'd */ |
93 typedef void (*pool_cleaner)(void *arg); | 114 typedef void (*pool_cleaner)(void *arg); |
94 | 115 |
95 /* pfree - a linked list node which stores an | 116 /* pfree - a linked list node which stores an |
96 allocation chunk, plus a callback */ | 117 allocation chunk, plus a callback */ |
111 struct pheap *heap; | 132 struct pheap *heap; |
112 #ifdef POOL_DEBUG | 133 #ifdef POOL_DEBUG |
113 char name[8], zone[32]; | 134 char name[8], zone[32]; |
114 int lsize; | 135 int lsize; |
115 } _pool, *pool; | 136 } _pool, *pool; |
116 #define pool_new() _pool_new(ZONE) | 137 #define pool_new() _pool_new(__FILE__,__LINE__) |
117 #define pool_heap(i) _pool_new_heap(i,ZONE) | 138 #define pool_heap(i) _pool_new_heap(i,__FILE__,__LINE__) |
118 #else | 139 #else |
119 } _pool, *pool; | 140 } _pool, *pool; |
120 #define pool_heap(i) _pool_new_heap(i,NULL) | 141 #define pool_heap(i) _pool_new_heap(i, NULL, 0) |
121 #define pool_new() _pool_new(NULL) | 142 #define pool_new() _pool_new(NULL, 0) |
122 #endif | 143 #endif |
123 | 144 |
124 pool _pool_new(char *zone); /* new pool :) */ | 145 pool _pool_new(char *zone, int line); /* new pool :) */ |
125 pool _pool_new_heap(int size, char *zone); /* creates a new memory pool with an initial heap size */ | 146 pool _pool_new_heap(int size, char *zone, int line); /* creates a new memory pool with an initial heap size */ |
126 void *pmalloc(pool p, int size); /* wrapper around malloc, takes from the pool, cleaned up automatically */ | 147 void *pmalloc(pool p, int size); /* wrapper around malloc, takes from the pool, cleaned up automatically */ |
127 void *pmalloc_x(pool p, int size, char c); /* Wrapper around pmalloc which prefils buffer with c */ | 148 void *pmalloc_x(pool p, int size, char c); /* Wrapper around pmalloc which prefils buffer with c */ |
128 void *pmalloco(pool p, int size); /* YAPW for zeroing the block */ | 149 void *pmalloco(pool p, int size); /* YAPW for zeroing the block */ |
129 char *pstrdup(pool p, const char *src); /* wrapper around strdup, gains mem from pool */ | 150 char *pstrdup(pool p, const char *src); /* wrapper around strdup, gains mem from pool */ |
130 void pool_stat(int full); /* print to stderr the changed pools and reset */ | 151 void pool_stat(int full); /* print to stderr the changed pools and reset */ |
244 } *spool; | 265 } *spool; |
245 | 266 |
246 spool spool_new(pool p); /* create a string pool */ | 267 spool spool_new(pool p); /* create a string pool */ |
247 void spooler(spool s, ...); /* append all the char * args to the pool, terminate args with s again */ | 268 void spooler(spool s, ...); /* append all the char * args to the pool, terminate args with s again */ |
248 char *spool_print(spool s); /* return a big string */ | 269 char *spool_print(spool s); /* return a big string */ |
249 void spool_add(spool s, char *str); /* add a single char to the pool */ | 270 void spool_add(spool s, char *str); /* add a single string to the pool */ |
250 char *spools(pool p, ...); /* wrap all the spooler stuff in one function, the happy fun ball! */ | 271 char *spools(pool p, ...); /* wrap all the spooler stuff in one function, the happy fun ball! */ |
251 | 272 |
252 | 273 |
253 /* --------------------------------------------------------- */ | 274 /* --------------------------------------------------------- */ |
254 /* */ | 275 /* */ |
260 #define NTYPE_CDATA 2 | 281 #define NTYPE_CDATA 2 |
261 | 282 |
262 #define NTYPE_LAST 2 | 283 #define NTYPE_LAST 2 |
263 #define NTYPE_UNDEF -1 | 284 #define NTYPE_UNDEF -1 |
264 | 285 |
265 /* -------------------------------------------------------------------------- | 286 /* -------------------------------------------------------------------------- |
266 Node structure. Do not use directly! Always use accessor macros | 287 Node structure. Do not use directly! Always use accessor macros |
267 and methods! | 288 and methods! |
268 -------------------------------------------------------------------------- */ | 289 -------------------------------------------------------------------------- */ |
269 typedef struct xmlnode_t | 290 typedef struct xmlnode_t |
270 { | 291 { |
271 char* name; | 292 char* name; |
273 char* data; | 294 char* data; |
274 int data_sz; | 295 int data_sz; |
275 int complete; | 296 int complete; |
276 pool p; | 297 pool p; |
277 struct xmlnode_t* parent; | 298 struct xmlnode_t* parent; |
278 struct xmlnode_t* firstchild; | 299 struct xmlnode_t* firstchild; |
279 struct xmlnode_t* lastchild; | 300 struct xmlnode_t* lastchild; |
280 struct xmlnode_t* prev; | 301 struct xmlnode_t* prev; |
281 struct xmlnode_t* next; | 302 struct xmlnode_t* next; |
282 struct xmlnode_t* firstattrib; | 303 struct xmlnode_t* firstattrib; |
283 struct xmlnode_t* lastattrib; | 304 struct xmlnode_t* lastattrib; |
284 } _xmlnode, *xmlnode; | 305 } _xmlnode, *xmlnode; |
285 | 306 |
286 /* Node creation routines */ | 307 /* Node creation routines */ |
287 xmlnode xmlnode_wrap(xmlnode x,const char* wrapper); | 308 xmlnode xmlnode_wrap(xmlnode x,const char* wrapper); |
288 xmlnode xmlnode_new_tag(const char* name); | 309 xmlnode xmlnode_new_tag(const char* name); |
289 xmlnode xmlnode_new_tag_pool(pool p, const char* name); | 310 xmlnode xmlnode_new_tag_pool(pool p, const char* name); |
290 xmlnode xmlnode_insert_tag(xmlnode parent, const char* name); | 311 xmlnode xmlnode_insert_tag(xmlnode parent, const char* name); |
291 xmlnode xmlnode_insert_cdata(xmlnode parent, const char* CDATA, unsigned int size); | 312 xmlnode xmlnode_insert_cdata(xmlnode parent, const char* CDATA, unsigned int size); |
292 xmlnode xmlnode_insert_tag_node(xmlnode parent, xmlnode node); | 313 xmlnode xmlnode_insert_tag_node(xmlnode parent, xmlnode node); |
293 void xmlnode_insert_node(xmlnode parent, xmlnode node); | 314 void xmlnode_insert_node(xmlnode parent, xmlnode node); |
294 xmlnode xmlnode_str(char *str, int len); | 315 xmlnode xmlnode_str(char *str, int len); |
295 xmlnode xmlnode_file(char *file); | 316 xmlnode xmlnode_file(char *file); |
338 int xmlnode_has_attribs(xmlnode node); | 359 int xmlnode_has_attribs(xmlnode node); |
339 | 360 |
340 /* Node-to-string translation */ | 361 /* Node-to-string translation */ |
341 char* xmlnode2str(xmlnode node); | 362 char* xmlnode2str(xmlnode node); |
342 | 363 |
343 /* Node-to-terminated-string translation | 364 /* Node-to-terminated-string translation |
344 -- useful for interfacing w/ scripting langs */ | 365 -- useful for interfacing w/ scripting langs */ |
345 char* xmlnode2tstr(xmlnode node); | 366 char* xmlnode2tstr(xmlnode node); |
346 | 367 |
347 int xmlnode_cmp(xmlnode a, xmlnode b); /* compares a and b for equality */ | 368 int xmlnode_cmp(xmlnode a, xmlnode b); /* compares a and b for equality */ |
348 | 369 |
349 int xmlnode2file(char *file, xmlnode node); /* writes node to file */ | 370 int xmlnode2file(char *file, xmlnode node); /* writes node to file */ |
371 int xmlnode2file_limited(char *file, xmlnode node, size_t sizelimit); | |
350 | 372 |
351 /* Expat callbacks */ | 373 /* Expat callbacks */ |
352 void expat_startElement(void* userdata, const char* name, const char** atts); | 374 void expat_startElement(void* userdata, const char* name, const char** atts); |
353 void expat_endElement(void* userdata, const char* name); | 375 void expat_endElement(void* userdata, const char* name); |
354 void expat_charData(void* userdata, const char* s, int len); | 376 void expat_charData(void* userdata, const char* s, int len); |
386 /* convience functions */ | 408 /* convience functions */ |
387 xmlnode xstream_header(char *nspace, char *to, char *from); | 409 xmlnode xstream_header(char *nspace, char *to, char *from); |
388 char *xstream_header_char(xmlnode x); | 410 char *xstream_header_char(xmlnode x); |
389 | 411 |
390 /* SHA.H */ | 412 /* SHA.H */ |
391 /* | 413 /* |
392 * The contents of this file are subject to the Mozilla Public | 414 * The contents of this file are subject to the Mozilla Public |
393 * License Version 1.1 (the "License"); you may not use this file | 415 * License Version 1.1 (the "License"); you may not use this file |
394 * except in compliance with the License. You may obtain a copy of | 416 * except in compliance with the License. You may obtain a copy of |
395 * the License at http://www.mozilla.org/MPL/ | 417 * the License at http://www.mozilla.org/MPL/ |
396 * | 418 * |
397 * Software distributed under the License is distributed on an "AS | 419 * Software distributed under the License is distributed on an "AS |
398 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | 420 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
399 * implied. See the License for the specific language governing | 421 * implied. See the License for the specific language governing |
400 * rights and limitations under the License. | 422 * rights and limitations under the License. |
401 * | 423 * |
402 * The Original Code is SHA 180-1 Header File | 424 * The Original Code is SHA 180-1 Header File |
403 * | 425 * |
404 * The Initial Developer of the Original Code is Paul Kocher of | 426 * The Initial Developer of the Original Code is Paul Kocher of |
405 * Cryptography Research. Portions created by Paul Kocher are | 427 * Cryptography Research. Portions created by Paul Kocher are |
406 * Copyright (C) 1995-9 by Cryptography Research, Inc. All | 428 * Copyright (C) 1995-9 by Cryptography Research, Inc. All |
407 * Rights Reserved. | 429 * Rights Reserved. |
408 * | 430 * |
409 * Contributor(s): | 431 * Contributor(s): |
410 * | 432 * |
411 * Paul Kocher | 433 * Paul Kocher |
412 * | 434 * |
413 * Alternatively, the contents of this file may be used under the | 435 * Alternatively, the contents of this file may be used under the |
414 * terms of the GNU General Public License Version 2 or later (the | 436 * terms of the GNU General Public License Version 2 or later (the |
415 * "GPL"), in which case the provisions of the GPL are applicable | 437 * "GPL"), in which case the provisions of the GPL are applicable |
416 * instead of those above. If you wish to allow use of your | 438 * instead of those above. If you wish to allow use of your |
417 * version of this file only under the terms of the GPL and not to | 439 * version of this file only under the terms of the GPL and not to |
418 * allow others to use your version of this file under the MPL, | 440 * allow others to use your version of this file under the MPL, |
419 * indicate your decision by deleting the provisions above and | 441 * indicate your decision by deleting the provisions above and |
420 * replace them with the notice and other provisions required by | 442 * replace them with the notice and other provisions required by |
421 * the GPL. If you do not delete the provisions above, a recipient | 443 * the GPL. If you do not delete the provisions above, a recipient |