1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,307 +0,0 @@ |
1 |
-/* |
|
2 |
- * $Id$ |
|
3 |
- * |
|
4 |
- * This program is free software; you can redistribute it and/or modify |
|
5 |
- * it under the terms of the GNU General Public License as published by |
|
6 |
- * the Free Software Foundation; either version 2 of the License, or |
|
7 |
- * (at your option) any later version. |
|
8 |
- * |
|
9 |
- * This program is distributed in the hope that it will be useful, |
|
10 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
- * GNU General Public License for more details. |
|
13 |
- * |
|
14 |
- * You should have received a copy of the GNU General Public License |
|
15 |
- * along with this program; if not, write to the Free Software |
|
16 |
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
- * |
|
18 |
- * Jabber |
|
19 |
- * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ |
|
20 |
- */ |
|
21 |
- |
|
22 |
-/*! \file |
|
23 |
- * \ingroup xmpp |
|
24 |
- */ |
|
25 |
- |
|
26 |
-#include <string.h> |
|
27 |
-#include <stdlib.h> |
|
28 |
-#include <sys/types.h> |
|
29 |
-#include <stdio.h> |
|
30 |
-#include <errno.h> |
|
31 |
-#include <syslog.h> |
|
32 |
-#include <strings.h> |
|
33 |
-#include <unistd.h> |
|
34 |
-#include <sys/time.h> |
|
35 |
- |
|
36 |
-#include "expat.h" |
|
37 |
-#ifdef HAVE_CONFIG_H |
|
38 |
-#include <config.h> |
|
39 |
-#endif /* HAVE_CONFIG_H */ |
|
40 |
- |
|
41 |
-/* |
|
42 |
-** Arrange to use either varargs or stdargs |
|
43 |
-*/ |
|
44 |
- |
|
45 |
-#define MAXSHORTSTR 203 /* max short string length */ |
|
46 |
-#define QUAD_T unsigned long long |
|
47 |
- |
|
48 |
-#ifdef __STDC__ |
|
49 |
- |
|
50 |
-#include <stdarg.h> |
|
51 |
- |
|
52 |
-# define VA_LOCAL_DECL va_list ap; |
|
53 |
-# define VA_START(f) va_start(ap, f) |
|
54 |
-# define VA_END va_end(ap) |
|
55 |
- |
|
56 |
-#else /* __STDC__ */ |
|
57 |
- |
|
58 |
-# include <varargs.h> |
|
59 |
- |
|
60 |
-# define VA_LOCAL_DECL va_list ap; |
|
61 |
-# define VA_START(f) va_start(ap) |
|
62 |
-# define VA_END va_end(ap) |
|
63 |
- |
|
64 |
-#endif /* __STDC__ */ |
|
65 |
- |
|
66 |
- |
|
67 |
-#ifndef INCL_LIBXODE_H |
|
68 |
-#define INCL_LIBXODE_H |
|
69 |
- |
|
70 |
-#ifdef __cplusplus |
|
71 |
-extern "C" { |
|
72 |
-#endif |
|
73 |
- |
|
74 |
-#ifndef __OS_darwin |
|
75 |
-#ifndef HAVE_SNPRINTF |
|
76 |
-extern int ap_snprintf(char *, size_t, const char *, ...); |
|
77 |
-#define snprintf ap_snprintf |
|
78 |
-#endif |
|
79 |
- |
|
80 |
-#ifndef HAVE_VSNPRINTF |
|
81 |
-extern int ap_vsnprintf(char *, size_t, const char *, va_list ap); |
|
82 |
-#define vsnprintf ap_vsnprintf |
|
83 |
-#endif |
|
84 |
-#endif |
|
85 |
- |
|
86 |
-/* --------------------------------------------------------- */ |
|
87 |
-/* */ |
|
88 |
-/* Pool-based memory management routines */ |
|
89 |
-/* */ |
|
90 |
-/* --------------------------------------------------------- */ |
|
91 |
- |
|
92 |
- |
|
93 |
-/* xode_pool_cleaner - callback type which is associated |
|
94 |
- with a pool entry; invoked when the pool entry is |
|
95 |
- free'd */ |
|
96 |
-typedef void (*xode_pool_cleaner)(void *arg); |
|
97 |
- |
|
98 |
- |
|
99 |
-/* pheap - singular allocation of memory */ |
|
100 |
-struct xode_pool_heap |
|
101 |
-{ |
|
102 |
- void *block; |
|
103 |
- int size, used; |
|
104 |
-}; |
|
105 |
- |
|
106 |
-/* pool - base node for a pool. Maintains a linked list |
|
107 |
- of pool entries (pool_free) */ |
|
108 |
-typedef struct xode_pool_struct |
|
109 |
-{ |
|
110 |
- int size; |
|
111 |
- struct xode_pool_free *cleanup; |
|
112 |
- struct xode_pool_heap *heap; |
|
113 |
-} _xode_pool, *xode_pool; |
|
114 |
- |
|
115 |
-/* pool creation routines */ |
|
116 |
-xode_pool xode_pool_heap(int bytes); |
|
117 |
-xode_pool xode_pool_new(void); |
|
118 |
- |
|
119 |
-/* pool wrappers for malloc */ |
|
120 |
-void *xode_pool_malloc (xode_pool p, int size); |
|
121 |
-void *xode_pool_mallocx (xode_pool p, int size, char c); |
|
122 |
-void *xode_pool_malloco (xode_pool p, int size); |
|
123 |
- |
|
124 |
-/* wrapper around strdup, gains mem from pool */ |
|
125 |
-char *xode_pool_strdup (xode_pool p, const char *src); |
|
126 |
- |
|
127 |
-/* calls f(arg) before the pool is freed during cleanup */ |
|
128 |
-void xode_pool_cleanup (xode_pool p, xode_pool_cleaner f, void *arg); |
|
129 |
- |
|
130 |
-/* pool wrapper for free, called on a pool */ |
|
131 |
-void xode_pool_free (xode_pool p); |
|
132 |
- |
|
133 |
-/* returns total bytes allocated in this pool */ |
|
134 |
-int xode_pool_size (xode_pool p); |
|
135 |
- |
|
136 |
-/* --------------------------------------------------------- */ |
|
137 |
-/* */ |
|
138 |
-/* XML escaping utils */ |
|
139 |
-/* */ |
|
140 |
-/* --------------------------------------------------------- */ |
|
141 |
-char *xode_strescape(xode_pool p, char *buf); /* Escape <>&'" chars */ |
|
142 |
-char *xode_strunescape(xode_pool p, char *buf); |
|
143 |
- |
|
144 |
- |
|
145 |
-/* --------------------------------------------------------- */ |
|
146 |
-/* */ |
|
147 |
-/* String pools (spool) functions */ |
|
148 |
-/* */ |
|
149 |
-/* --------------------------------------------------------- */ |
|
150 |
-struct xode_spool_node |
|
151 |
-{ |
|
152 |
- char *c; |
|
153 |
- struct xode_spool_node *next; |
|
154 |
-}; |
|
155 |
- |
|
156 |
-typedef struct xode_spool_struct |
|
157 |
-{ |
|
158 |
- xode_pool p; |
|
159 |
- int len; |
|
160 |
- struct xode_spool_node *last; |
|
161 |
- struct xode_spool_node *first; |
|
162 |
-} *xode_spool; |
|
163 |
- |
|
164 |
-xode_spool xode_spool_new ( void ); /* create a string pool on a new pool */ |
|
165 |
-xode_spool xode_spool_newfrompool ( xode_pool p ); /* create a string pool from an existing pool */ |
|
166 |
-xode_pool xode_spool_getpool ( const xode_spool s ); /* returns the xode_pool used by this xode_spool */ |
|
167 |
-void xode_spooler ( xode_spool s, ... ); /* append all the char * args to the pool, terminate args with s again */ |
|
168 |
-char *xode_spool_tostr ( xode_spool s ); /* return a big string */ |
|
169 |
-void xode_spool_add ( xode_spool s, char *str ); /* add a single char to the pool */ |
|
170 |
-char *xode_spool_str ( xode_pool p, ... ); /* wrap all the spooler stuff in one function, the happy fun ball! */ |
|
171 |
-int xode_spool_getlen ( const xode_spool s ); /* returns the total length of the string contained in the pool */ |
|
172 |
-void xode_spool_free ( xode_spool s ); /* Free's the pool associated with the xode_spool */ |
|
173 |
- |
|
174 |
- |
|
175 |
-/* --------------------------------------------------------- */ |
|
176 |
-/* */ |
|
177 |
-/* xodes - Document Object Model */ |
|
178 |
-/* */ |
|
179 |
-/* --------------------------------------------------------- */ |
|
180 |
-#define XODE_TYPE_TAG 0 |
|
181 |
-#define XODE_TYPE_ATTRIB 1 |
|
182 |
-#define XODE_TYPE_CDATA 2 |
|
183 |
- |
|
184 |
-#define XODE_TYPE_LAST 2 |
|
185 |
-#define XODE_TYPE_UNDEF -1 |
|
186 |
- |
|
187 |
-/* -------------------------------------------------------------------------- |
|
188 |
- Node structure. Do not use directly! Always use accessors macros |
|
189 |
- and methods! |
|
190 |
- -------------------------------------------------------------------------- */ |
|
191 |
-typedef struct xode_struct |
|
192 |
-{ |
|
193 |
- char* name; |
|
194 |
- unsigned short type; |
|
195 |
- char* data; |
|
196 |
- int data_sz; |
|
197 |
- int complete; |
|
198 |
- xode_pool p; |
|
199 |
- struct xode_struct* parent; |
|
200 |
- struct xode_struct* firstchild; |
|
201 |
- struct xode_struct* lastchild; |
|
202 |
- struct xode_struct* prev; |
|
203 |
- struct xode_struct* next; |
|
204 |
- struct xode_struct* firstattrib; |
|
205 |
- struct xode_struct* lastattrib; |
|
206 |
-} _xode, *xode; |
|
207 |
- |
|
208 |
-/* Node creation routines */ |
|
209 |
-xode xode_wrap(xode x,const char* wrapper); |
|
210 |
-xode xode_new(const char* name); |
|
211 |
-xode xode_new_tag(const char* name); |
|
212 |
-xode xode_new_frompool(xode_pool p, const char* name); |
|
213 |
-xode xode_insert_tag(xode parent, const char* name); |
|
214 |
-xode xode_insert_cdata(xode parent, const char* CDATA, unsigned int size); |
|
215 |
-xode xode_insert_tagnode(xode parent, xode node); |
|
216 |
-void xode_insert_node(xode parent, xode node); |
|
217 |
-xode xode_from_str(char *str, int len); |
|
218 |
-xode xode_from_strx(char *str, int len, int *err, int *pos); |
|
219 |
-xode xode_from_file(char *file); |
|
220 |
-xode xode_dup(xode x); /* duplicate x */ |
|
221 |
-xode xode_dup_frompool(xode_pool p, xode x); |
|
222 |
- |
|
223 |
-/* Node Memory Pool */ |
|
224 |
-xode_pool xode_get_pool(xode node); |
|
225 |
- |
|
226 |
-/* Node editing */ |
|
227 |
-void xode_hide(xode child); |
|
228 |
-void xode_hide_attrib(xode parent, const char *name); |
|
229 |
- |
|
230 |
-/* Node deletion routine, also frees the node pool! */ |
|
231 |
-void xode_free(xode node); |
|
232 |
- |
|
233 |
-/* Locates a child tag by name and returns it */ |
|
234 |
-xode xode_get_tag(xode parent, const char* name); |
|
235 |
-char* xode_get_tagdata(xode parent, const char* name); |
|
236 |
- |
|
237 |
-/* Attribute accessors */ |
|
238 |
-void xode_put_attrib(xode owner, const char* name, const char* value); |
|
239 |
-char* xode_get_attrib(xode owner, const char* name); |
|
240 |
- |
|
241 |
-/* Bastard am I, but these are fun for internal use ;-) */ |
|
242 |
-void xode_put_vattrib(xode owner, const char* name, void *value); |
|
243 |
-void* xode_get_vattrib(xode owner, const char* name); |
|
244 |
- |
|
245 |
-/* Node traversal routines */ |
|
246 |
-xode xode_get_firstattrib(xode parent); |
|
247 |
-xode xode_get_firstchild(xode parent); |
|
248 |
-xode xode_get_lastchild(xode parent); |
|
249 |
-xode xode_get_nextsibling(xode sibling); |
|
250 |
-xode xode_get_prevsibling(xode sibling); |
|
251 |
-xode xode_get_parent(xode node); |
|
252 |
- |
|
253 |
-/* Node information routines */ |
|
254 |
-char* xode_get_name(xode node); |
|
255 |
-char* xode_get_data(xode node); |
|
256 |
-int xode_get_datasz(xode node); |
|
257 |
-int xode_get_type(xode node); |
|
258 |
- |
|
259 |
-int xode_has_children(xode node); |
|
260 |
-int xode_has_attribs(xode node); |
|
261 |
- |
|
262 |
-/* Node-to-string translation */ |
|
263 |
-char* xode_to_str(xode node); |
|
264 |
-char* xode_to_prettystr(xode node); /* Puts \t and \n to make a human-easily readable string */ |
|
265 |
- |
|
266 |
-int xode_cmp(xode a, xode b); /* compares a and b for equality */ |
|
267 |
- |
|
268 |
-int xode_to_file(char *file, xode node); /* writes node to file */ |
|
269 |
- |
|
270 |
- |
|
271 |
-/*********************** |
|
272 |
- * XSTREAM Section |
|
273 |
- ***********************/ |
|
274 |
- |
|
275 |
-#define XODE_STREAM_MAXNODE 1000000 |
|
276 |
-#define XODE_STREAM_MAXDEPTH 100 |
|
277 |
- |
|
278 |
-#define XODE_STREAM_ROOT 0 /* root element */ |
|
279 |
-#define XODE_STREAM_NODE 1 /* normal node */ |
|
280 |
-#define XODE_STREAM_CLOSE 2 /* closed root node */ |
|
281 |
-#define XODE_STREAM_ERROR 4 /* parser error */ |
|
282 |
- |
|
283 |
-typedef void (*xode_stream_onNode)(int type, xode x, void *arg); /* xstream event handler */ |
|
284 |
- |
|
285 |
-typedef struct xode_stream_struct |
|
286 |
-{ |
|
287 |
- XML_Parser parser; |
|
288 |
- xode node; |
|
289 |
- char *cdata; |
|
290 |
- int cdata_len; |
|
291 |
- xode_pool p; |
|
292 |
- xode_stream_onNode f; |
|
293 |
- void *arg; |
|
294 |
- int status; |
|
295 |
- int depth; |
|
296 |
-} *xode_stream, _xode_stream; |
|
297 |
- |
|
298 |
-xode_stream xode_stream_new(xode_pool p, xode_stream_onNode f, void *arg); /* create a new xstream */ |
|
299 |
-int xode_stream_eat(xode_stream xs, char *buff, int len); /* parse new data for this xstream, returns last XSTREAM_* status */ |
|
300 |
- |
|
301 |
-/* convenience functions */ |
|
302 |
- |
|
303 |
-#ifdef __cplusplus |
|
304 |
-} |
|
305 |
-#endif |
|
306 |
- |
|
307 |
-#endif /* INCL_LIBXODE_H */ |
- gwmap can get a valus as a list of
'sipdomain1=xmppdomain1;...;sipdomainN=xmppdomainN'
- whenever a sip-to-xmpp message is sent, any matching sipdomain in src
or dst address is translated to appropiate xmppdomain
- the other way around, when a xmpp-to-sip message is sent, then any
matching xmpp domain in src or dst address is translated to appropiate
sip domain
- this allow getting rid of the URI encoding with delimiter
- if a domain is not found, the src/dst domains are preserved as they
are in SIP to XMPP and vice versa
- if the xmppdomain is not provided explicitely, sipdomain is considered
to be also the xmpp domain
... | ... |
@@ -71,7 +71,7 @@ |
71 | 71 |
extern "C" { |
72 | 72 |
#endif |
73 | 73 |
|
74 |
- |
|
74 |
+#ifndef __OS_darwin |
|
75 | 75 |
#ifndef HAVE_SNPRINTF |
76 | 76 |
extern int ap_snprintf(char *, size_t, const char *, ...); |
77 | 77 |
#define snprintf ap_snprintf |
... | ... |
@@ -81,6 +81,7 @@ extern int ap_snprintf(char *, size_t, const char *, ...); |
81 | 81 |
extern int ap_vsnprintf(char *, size_t, const char *, va_list ap); |
82 | 82 |
#define vsnprintf ap_vsnprintf |
83 | 83 |
#endif |
84 |
+#endif |
|
84 | 85 |
|
85 | 86 |
/* --------------------------------------------------------- */ |
86 | 87 |
/* */ |
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4494 689a6050-402a-0410-94f2-e92a70836424
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1120 689a6050-402a-0410-94f2-e92a70836424
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,301 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * This program is free software; you can redistribute it and/or modify |
|
5 |
+ * it under the terms of the GNU General Public License as published by |
|
6 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
7 |
+ * (at your option) any later version. |
|
8 |
+ * |
|
9 |
+ * This program is distributed in the hope that it will be useful, |
|
10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
+ * GNU General Public License for more details. |
|
13 |
+ * |
|
14 |
+ * You should have received a copy of the GNU General Public License |
|
15 |
+ * along with this program; if not, write to the Free Software |
|
16 |
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
+ * |
|
18 |
+ * Jabber |
|
19 |
+ * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ |
|
20 |
+ */ |
|
21 |
+#include <string.h> |
|
22 |
+#include <stdlib.h> |
|
23 |
+#include <sys/types.h> |
|
24 |
+#include <stdio.h> |
|
25 |
+#include <errno.h> |
|
26 |
+#include <syslog.h> |
|
27 |
+#include <strings.h> |
|
28 |
+#include <unistd.h> |
|
29 |
+#include <sys/time.h> |
|
30 |
+ |
|
31 |
+#include "expat.h" |
|
32 |
+#ifdef HAVE_CONFIG_H |
|
33 |
+#include <config.h> |
|
34 |
+#endif /* HAVE_CONFIG_H */ |
|
35 |
+ |
|
36 |
+/* |
|
37 |
+** Arrange to use either varargs or stdargs |
|
38 |
+*/ |
|
39 |
+ |
|
40 |
+#define MAXSHORTSTR 203 /* max short string length */ |
|
41 |
+#define QUAD_T unsigned long long |
|
42 |
+ |
|
43 |
+#ifdef __STDC__ |
|
44 |
+ |
|
45 |
+#include <stdarg.h> |
|
46 |
+ |
|
47 |
+# define VA_LOCAL_DECL va_list ap; |
|
48 |
+# define VA_START(f) va_start(ap, f) |
|
49 |
+# define VA_END va_end(ap) |
|
50 |
+ |
|
51 |
+#else /* __STDC__ */ |
|
52 |
+ |
|
53 |
+# include <varargs.h> |
|
54 |
+ |
|
55 |
+# define VA_LOCAL_DECL va_list ap; |
|
56 |
+# define VA_START(f) va_start(ap) |
|
57 |
+# define VA_END va_end(ap) |
|
58 |
+ |
|
59 |
+#endif /* __STDC__ */ |
|
60 |
+ |
|
61 |
+ |
|
62 |
+#ifndef INCL_LIBXODE_H |
|
63 |
+#define INCL_LIBXODE_H |
|
64 |
+ |
|
65 |
+#ifdef __cplusplus |
|
66 |
+extern "C" { |
|
67 |
+#endif |
|
68 |
+ |
|
69 |
+ |
|
70 |
+#ifndef HAVE_SNPRINTF |
|
71 |
+extern int ap_snprintf(char *, size_t, const char *, ...); |
|
72 |
+#define snprintf ap_snprintf |
|
73 |
+#endif |
|
74 |
+ |
|
75 |
+#ifndef HAVE_VSNPRINTF |
|
76 |
+extern int ap_vsnprintf(char *, size_t, const char *, va_list ap); |
|
77 |
+#define vsnprintf ap_vsnprintf |
|
78 |
+#endif |
|
79 |
+ |
|
80 |
+/* --------------------------------------------------------- */ |
|
81 |
+/* */ |
|
82 |
+/* Pool-based memory management routines */ |
|
83 |
+/* */ |
|
84 |
+/* --------------------------------------------------------- */ |
|
85 |
+ |
|
86 |
+ |
|
87 |
+/* xode_pool_cleaner - callback type which is associated |
|
88 |
+ with a pool entry; invoked when the pool entry is |
|
89 |
+ free'd */ |
|
90 |
+typedef void (*xode_pool_cleaner)(void *arg); |
|
91 |
+ |
|
92 |
+ |
|
93 |
+/* pheap - singular allocation of memory */ |
|
94 |
+struct xode_pool_heap |
|
95 |
+{ |
|
96 |
+ void *block; |
|
97 |
+ int size, used; |
|
98 |
+}; |
|
99 |
+ |
|
100 |
+/* pool - base node for a pool. Maintains a linked list |
|
101 |
+ of pool entries (pool_free) */ |
|
102 |
+typedef struct xode_pool_struct |
|
103 |
+{ |
|
104 |
+ int size; |
|
105 |
+ struct xode_pool_free *cleanup; |
|
106 |
+ struct xode_pool_heap *heap; |
|
107 |
+} _xode_pool, *xode_pool; |
|
108 |
+ |
|
109 |
+/* pool creation routines */ |
|
110 |
+xode_pool xode_pool_heap(int bytes); |
|
111 |
+xode_pool xode_pool_new(void); |
|
112 |
+ |
|
113 |
+/* pool wrappers for malloc */ |
|
114 |
+void *xode_pool_malloc (xode_pool p, int size); |
|
115 |
+void *xode_pool_mallocx (xode_pool p, int size, char c); |
|
116 |
+void *xode_pool_malloco (xode_pool p, int size); |
|
117 |
+ |
|
118 |
+/* wrapper around strdup, gains mem from pool */ |
|
119 |
+char *xode_pool_strdup (xode_pool p, const char *src); |
|
120 |
+ |
|
121 |
+/* calls f(arg) before the pool is freed during cleanup */ |
|
122 |
+void xode_pool_cleanup (xode_pool p, xode_pool_cleaner f, void *arg); |
|
123 |
+ |
|
124 |
+/* pool wrapper for free, called on a pool */ |
|
125 |
+void xode_pool_free (xode_pool p); |
|
126 |
+ |
|
127 |
+/* returns total bytes allocated in this pool */ |
|
128 |
+int xode_pool_size (xode_pool p); |
|
129 |
+ |
|
130 |
+/* --------------------------------------------------------- */ |
|
131 |
+/* */ |
|
132 |
+/* XML escaping utils */ |
|
133 |
+/* */ |
|
134 |
+/* --------------------------------------------------------- */ |
|
135 |
+char *xode_strescape(xode_pool p, char *buf); /* Escape <>&'" chars */ |
|
136 |
+char *xode_strunescape(xode_pool p, char *buf); |
|
137 |
+ |
|
138 |
+ |
|
139 |
+/* --------------------------------------------------------- */ |
|
140 |
+/* */ |
|
141 |
+/* String pools (spool) functions */ |
|
142 |
+/* */ |
|
143 |
+/* --------------------------------------------------------- */ |
|
144 |
+struct xode_spool_node |
|
145 |
+{ |
|
146 |
+ char *c; |
|
147 |
+ struct xode_spool_node *next; |
|
148 |
+}; |
|
149 |
+ |
|
150 |
+typedef struct xode_spool_struct |
|
151 |
+{ |
|
152 |
+ xode_pool p; |
|
153 |
+ int len; |
|
154 |
+ struct xode_spool_node *last; |
|
155 |
+ struct xode_spool_node *first; |
|
156 |
+} *xode_spool; |
|
157 |
+ |
|
158 |
+xode_spool xode_spool_new ( void ); /* create a string pool on a new pool */ |
|
159 |
+xode_spool xode_spool_newfrompool ( xode_pool p ); /* create a string pool from an existing pool */ |
|
160 |
+xode_pool xode_spool_getpool ( const xode_spool s ); /* returns the xode_pool used by this xode_spool */ |
|
161 |
+void xode_spooler ( xode_spool s, ... ); /* append all the char * args to the pool, terminate args with s again */ |
|
162 |
+char *xode_spool_tostr ( xode_spool s ); /* return a big string */ |
|
163 |
+void xode_spool_add ( xode_spool s, char *str ); /* add a single char to the pool */ |
|
164 |
+char *xode_spool_str ( xode_pool p, ... ); /* wrap all the spooler stuff in one function, the happy fun ball! */ |
|
165 |
+int xode_spool_getlen ( const xode_spool s ); /* returns the total length of the string contained in the pool */ |
|
166 |
+void xode_spool_free ( xode_spool s ); /* Free's the pool associated with the xode_spool */ |
|
167 |
+ |
|
168 |
+ |
|
169 |
+/* --------------------------------------------------------- */ |
|
170 |
+/* */ |
|
171 |
+/* xodes - Document Object Model */ |
|
172 |
+/* */ |
|
173 |
+/* --------------------------------------------------------- */ |
|
174 |
+#define XODE_TYPE_TAG 0 |
|
175 |
+#define XODE_TYPE_ATTRIB 1 |
|
176 |
+#define XODE_TYPE_CDATA 2 |
|
177 |
+ |
|
178 |
+#define XODE_TYPE_LAST 2 |
|
179 |
+#define XODE_TYPE_UNDEF -1 |
|
180 |
+ |
|
181 |
+/* -------------------------------------------------------------------------- |
|
182 |
+ Node structure. Do not use directly! Always use accessors macros |
|
183 |
+ and methods! |
|
184 |
+ -------------------------------------------------------------------------- */ |
|
185 |
+typedef struct xode_struct |
|
186 |
+{ |
|
187 |
+ char* name; |
|
188 |
+ unsigned short type; |
|
189 |
+ char* data; |
|
190 |
+ int data_sz; |
|
191 |
+ int complete; |
|
192 |
+ xode_pool p; |
|
193 |
+ struct xode_struct* parent; |
|
194 |
+ struct xode_struct* firstchild; |
|
195 |
+ struct xode_struct* lastchild; |
|
196 |
+ struct xode_struct* prev; |
|
197 |
+ struct xode_struct* next; |
|
198 |
+ struct xode_struct* firstattrib; |
|
199 |
+ struct xode_struct* lastattrib; |
|
200 |
+} _xode, *xode; |
|
201 |
+ |
|
202 |
+/* Node creation routines */ |
|
203 |
+xode xode_wrap(xode x,const char* wrapper); |
|
204 |
+xode xode_new(const char* name); |
|
205 |
+xode xode_new_tag(const char* name); |
|
206 |
+xode xode_new_frompool(xode_pool p, const char* name); |
|
207 |
+xode xode_insert_tag(xode parent, const char* name); |
|
208 |
+xode xode_insert_cdata(xode parent, const char* CDATA, unsigned int size); |
|
209 |
+xode xode_insert_tagnode(xode parent, xode node); |
|
210 |
+void xode_insert_node(xode parent, xode node); |
|
211 |
+xode xode_from_str(char *str, int len); |
|
212 |
+xode xode_from_strx(char *str, int len, int *err, int *pos); |
|
213 |
+xode xode_from_file(char *file); |
|
214 |
+xode xode_dup(xode x); /* duplicate x */ |
|
215 |
+xode xode_dup_frompool(xode_pool p, xode x); |
|
216 |
+ |
|
217 |
+/* Node Memory Pool */ |
|
218 |
+xode_pool xode_get_pool(xode node); |
|
219 |
+ |
|
220 |
+/* Node editing */ |
|
221 |
+void xode_hide(xode child); |
|
222 |
+void xode_hide_attrib(xode parent, const char *name); |
|
223 |
+ |
|
224 |
+/* Node deletion routine, also frees the node pool! */ |
|
225 |
+void xode_free(xode node); |
|
226 |
+ |
|
227 |
+/* Locates a child tag by name and returns it */ |
|
228 |
+xode xode_get_tag(xode parent, const char* name); |
|
229 |
+char* xode_get_tagdata(xode parent, const char* name); |
|
230 |
+ |
|
231 |
+/* Attribute accessors */ |
|
232 |
+void xode_put_attrib(xode owner, const char* name, const char* value); |
|
233 |
+char* xode_get_attrib(xode owner, const char* name); |
|
234 |
+ |
|
235 |
+/* Bastard am I, but these are fun for internal use ;-) */ |
|
236 |
+void xode_put_vattrib(xode owner, const char* name, void *value); |
|
237 |
+void* xode_get_vattrib(xode owner, const char* name); |
|
238 |
+ |
|
239 |
+/* Node traversal routines */ |
|
240 |
+xode xode_get_firstattrib(xode parent); |
|
241 |
+xode xode_get_firstchild(xode parent); |
|
242 |
+xode xode_get_lastchild(xode parent); |
|
243 |
+xode xode_get_nextsibling(xode sibling); |
|
244 |
+xode xode_get_prevsibling(xode sibling); |
|
245 |
+xode xode_get_parent(xode node); |
|
246 |
+ |
|
247 |
+/* Node information routines */ |
|
248 |
+char* xode_get_name(xode node); |
|
249 |
+char* xode_get_data(xode node); |
|
250 |
+int xode_get_datasz(xode node); |
|
251 |
+int xode_get_type(xode node); |
|
252 |
+ |
|
253 |
+int xode_has_children(xode node); |
|
254 |
+int xode_has_attribs(xode node); |
|
255 |
+ |
|
256 |
+/* Node-to-string translation */ |
|
257 |
+char* xode_to_str(xode node); |
|
258 |
+char* xode_to_prettystr(xode node); /* Puts \t and \n to make a human-easily readable string */ |
|
259 |
+ |
|
260 |
+int xode_cmp(xode a, xode b); /* compares a and b for equality */ |
|
261 |
+ |
|
262 |
+int xode_to_file(char *file, xode node); /* writes node to file */ |
|
263 |
+ |
|
264 |
+ |
|
265 |
+/*********************** |
|
266 |
+ * XSTREAM Section |
|
267 |
+ ***********************/ |
|
268 |
+ |
|
269 |
+#define XODE_STREAM_MAXNODE 1000000 |
|
270 |
+#define XODE_STREAM_MAXDEPTH 100 |
|
271 |
+ |
|
272 |
+#define XODE_STREAM_ROOT 0 /* root element */ |
|
273 |
+#define XODE_STREAM_NODE 1 /* normal node */ |
|
274 |
+#define XODE_STREAM_CLOSE 2 /* closed root node */ |
|
275 |
+#define XODE_STREAM_ERROR 4 /* parser error */ |
|
276 |
+ |
|
277 |
+typedef void (*xode_stream_onNode)(int type, xode x, void *arg); /* xstream event handler */ |
|
278 |
+ |
|
279 |
+typedef struct xode_stream_struct |
|
280 |
+{ |
|
281 |
+ XML_Parser parser; |
|
282 |
+ xode node; |
|
283 |
+ char *cdata; |
|
284 |
+ int cdata_len; |
|
285 |
+ xode_pool p; |
|
286 |
+ xode_stream_onNode f; |
|
287 |
+ void *arg; |
|
288 |
+ int status; |
|
289 |
+ int depth; |
|
290 |
+} *xode_stream, _xode_stream; |
|
291 |
+ |
|
292 |
+xode_stream xode_stream_new(xode_pool p, xode_stream_onNode f, void *arg); /* create a new xstream */ |
|
293 |
+int xode_stream_eat(xode_stream xs, char *buff, int len); /* parse new data for this xstream, returns last XSTREAM_* status */ |
|
294 |
+ |
|
295 |
+/* convenience functions */ |
|
296 |
+ |
|
297 |
+#ifdef __cplusplus |
|
298 |
+} |
|
299 |
+#endif |
|
300 |
+ |
|
301 |
+#endif /* INCL_LIBXODE_H */ |