jabberd2  2.3.6
nad.h
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002-2004 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 
45 #ifndef INCL_UTIL_NAD_H
46 #define INCL_UTIL_NAD_H 1
47 
48 #ifdef HAVE_CONFIG_H
49 # include <config.h>
50 #endif
51 
52 #ifdef HAVE_SYS_TYPES_H
53 # include <sys/types.h>
54 #endif
55 
56 /* jabberd2 Windows DLL */
57 #ifndef JABBERD2_API
58 # ifdef _WIN32
59 # ifdef JABBERD2_EXPORTS
60 # define JABBERD2_API __declspec(dllexport)
61 # else /* JABBERD2_EXPORTS */
62 # define JABBERD2_API __declspec(dllimport)
63 # endif /* JABBERD2_EXPORTS */
64 # else /* _WIN32 */
65 # define JABBERD2_API extern
66 # endif /* _WIN32 */
67 #endif /* JABBERD2_API */
68 
69 struct nad_elem_st {
70  int parent;
71  int iname, lname;
72  int icdata, lcdata; /* cdata within this elem (up to first child) */
73  int itail, ltail; /* cdata after this elem */
74  int attr;
75  int ns;
76  int my_ns;
77  int depth;
78 };
79 
80 struct nad_attr_st {
81  int iname, lname;
82  int ival, lval;
83  int my_ns;
84  int next;
85 };
86 
87 struct nad_ns_st {
88  int iuri, luri;
90  int next;
91 };
92 
93 typedef struct nad_st
94 {
95  struct nad_elem_st *elems;
96  struct nad_attr_st *attrs;
97  struct nad_ns_st *nss;
98  char *cdata;
99  int *depths; /* for tracking the last elem at a depth */
100 
101  /* The size in bytes of the elems, attrs, nss and cdata buffers, respectively. */
102  int elen, alen, nlen, clen, dlen;
103 
104  /* The number of elements of each type of that data that are actually stored in the elems, attrs, nss and cdata buffers, respectively. */
105  int ecur, acur, ncur, ccur;
106 
107  int scope; /* currently scoped namespaces, get attached to the next element */
108  struct nad_st *next; /* for keeping a list of nads */
109 } *nad_t;
110 
113 
116 
118 JABBERD2_API void nad_free(nad_t nad);
119 
122 JABBERD2_API int nad_find_elem(nad_t nad, int elem, int ns, const char *name, int depth);
123 
125 JABBERD2_API int nad_find_attr(nad_t nad, int elem, int ns, const char *name, const char *val);
126 
128 JABBERD2_API int nad_find_namespace(nad_t nad, int elem, const char *uri, const char *prefix);
129 
131 JABBERD2_API int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix);
132 
140 JABBERD2_API int nad_find_elem_path(nad_t nad, int elem, int ns, const char *name);
141 
143 JABBERD2_API void nad_set_attr(nad_t nad, int elem, int ns, const char *name, const char *val, int vallen);
144 
146 JABBERD2_API int nad_insert_elem(nad_t nad, int elem, int ns, const char *name, const char *cdata);
147 
149 JABBERD2_API void nad_drop_elem(nad_t nad, int elem);
150 
152 JABBERD2_API void nad_wrap_elem(nad_t nad, int elem, int ns, const char *name);
153 
155 JABBERD2_API int nad_insert_nad(nad_t dest, int delem, nad_t src, int selem);
156 
158 JABBERD2_API int nad_append_elem(nad_t nad, int ns, const char *name, int depth);
159 
161 JABBERD2_API int nad_append_attr(nad_t nad, int ns, const char *name, const char *val);
162 
164 JABBERD2_API void nad_append_cdata(nad_t nad, const char *cdata, int len, int depth);
165 
167 JABBERD2_API int nad_add_namespace(nad_t nad, const char *uri, const char *prefix);
168 
170 JABBERD2_API int nad_append_namespace(nad_t nad, int elem, const char *uri, const char *prefix);
171 
173 JABBERD2_API void nad_print(nad_t nad, int elem, const char **xml, int *len);
174 
176 JABBERD2_API void nad_serialize(nad_t nad, char **buf, int *len);
177 JABBERD2_API nad_t nad_deserialize(const char *buf);
178 
180 JABBERD2_API nad_t nad_parse(const char *buf, int len);
181 
182 /* these are some helpful macros */
183 #define NAD_ENAME(N,E) (N->cdata + N->elems[E].iname)
184 #define NAD_ENAME_L(N,E) (N->elems[E].lname)
185 #define NAD_CDATA(N,E) (N->cdata + N->elems[E].icdata)
186 #define NAD_CDATA_L(N,E) (N->elems[E].lcdata)
187 #define NAD_ANAME(N,A) (N->cdata + N->attrs[A].iname)
188 #define NAD_ANAME_L(N,A) (N->attrs[A].lname)
189 #define NAD_AVAL(N,A) (N->cdata + N->attrs[A].ival)
190 #define NAD_AVAL_L(N,A) (N->attrs[A].lval)
191 #define NAD_NURI(N,NS) (N->cdata + N->nss[NS].iuri)
192 #define NAD_NURI_L(N,NS) (N->nss[NS].luri)
193 #define NAD_NPREFIX(N,NS) (N->cdata + N->nss[NS].iprefix)
194 #define NAD_NPREFIX_L(N,NS) (N->nss[NS].lprefix)
195 
196 #define NAD_ENS(N,E) (N->elems[E].my_ns)
197 #define NAD_ANS(N,A) (N->attrs[A].my_ns)
198 
199 #endif
int attr
Definition: nad.h:74
int iname
Definition: nad.h:81
struct nad_elem_st * elems
Definition: nad.h:95
struct nad_st * next
Definition: nad.h:108
Definition: nad.h:93
JABBERD2_API void nad_append_cdata(nad_t nad, const char *cdata, int len, int depth)
append more cdata to the last element
Definition: nad.c:737
JABBERD2_API int nad_append_attr(nad_t nad, int ns, const char *name, const char *val)
append attribs to the last element
Definition: nad.c:729
int ltail
Definition: nad.h:73
int next
Definition: nad.h:84
struct nad_attr_st * attrs
Definition: nad.h:96
int icdata
Definition: nad.h:72
JABBERD2_API void nad_print(nad_t nad, int elem, const char **xml, int *len)
create a string representation of the given element (and children), point references to it ...
Definition: nad.c:1192
int elen
Definition: nad.h:102
JABBERD2_API nad_t nad_new(void)
create a new nad
Definition: nad.c:125
JABBERD2_API void nad_serialize(nad_t nad, char **buf, int *len)
serialize and deserialize a nad
Definition: nad.c:1220
JABBERD2_API int nad_insert_elem(nad_t nad, int elem, int ns, const char *name, const char *cdata)
insert and return a new element as a child of this one
Definition: nad.c:433
int lname
Definition: nad.h:81
int lname
Definition: nad.h:71
JABBERD2_API int nad_insert_nad(nad_t dest, int delem, nad_t src, int selem)
insert part of a nad into another nad
Definition: nad.c:540
JABBERD2_API int nad_find_elem_path(nad_t nad, int elem, int ns, const char *name)
find elem using XPath like query name – "name" for the child tag of that name "name/name" for a sub ...
Definition: nad.c:320
int parent
Definition: nad.h:70
int clen
Definition: nad.h:102
struct nad_ns_st * nss
Definition: nad.h:97
JABBERD2_API int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix)
find a namespace in scope (and optionally prefix)
Definition: nad.c:290
int ecur
Definition: nad.h:105
JABBERD2_API void nad_free(nad_t nad)
free that nad
Definition: nad.c:178
JABBERD2_API int nad_append_elem(nad_t nad, int ns, const char *name, int depth)
append and return a new element
Definition: nad.c:695
int lval
Definition: nad.h:82
int acur
Definition: nad.h:105
JABBERD2_API int nad_append_namespace(nad_t nad, int elem, const char *uri, const char *prefix)
declare a namespace on an already existing element
Definition: nad.c:798
int alen
Definition: nad.h:102
#define JABBERD2_API
Definition: nad.h:65
int luri
Definition: nad.h:88
int dlen
Definition: nad.h:102
int ns
Definition: nad.h:75
JABBERD2_API nad_t nad_deserialize(const char *buf)
Definition: nad.c:1246
int lprefix
Definition: nad.h:89
int scope
Definition: nad.h:107
char * cdata
Definition: nad.h:98
JABBERD2_API int nad_find_elem(nad_t nad, int elem, int ns, const char *name, int depth)
find the next element with this name/depth
Definition: nad.c:204
JABBERD2_API void nad_wrap_elem(nad_t nad, int elem, int ns, const char *name)
wrap an element with another element
Definition: nad.c:503
int iprefix
Definition: nad.h:89
JABBERD2_API int nad_add_namespace(nad_t nad, const char *uri, const char *prefix)
add a namespace to the next element (ie, called when the namespace comes into scope) ...
Definition: nad.c:762
int * depths
Definition: nad.h:99
int nlen
Definition: nad.h:102
int ccur
Definition: nad.h:105
JABBERD2_API int nad_find_namespace(nad_t nad, int elem, const char *uri, const char *prefix)
find the first matching namespace (and optionally prefix)
Definition: nad.c:262
int ncur
Definition: nad.h:105
int next
Definition: nad.h:90
JABBERD2_API void nad_set_attr(nad_t nad, int elem, int ns, const char *name, const char *val, int vallen)
reset or store the given attribute
Definition: nad.c:403
int itail
Definition: nad.h:73
int ival
Definition: nad.h:82
int lcdata
Definition: nad.h:72
JABBERD2_API int nad_find_attr(nad_t nad, int elem, int ns, const char *name, const char *val)
find the first matching attribute (and optionally value)
Definition: nad.c:235
struct nad_st * nad_t
JABBERD2_API void nad_drop_elem(nad_t nad, int elem)
remove an element (and its subelements)
Definition: nad.c:480
Definition: nad.h:87
int depth
Definition: nad.h:77
int my_ns
Definition: nad.h:83
JABBERD2_API nad_t nad_parse(const char *buf, int len)
create a nad from raw xml
Definition: nad.c:1414
int my_ns
Definition: nad.h:76
int iname
Definition: nad.h:71
JABBERD2_API nad_t nad_copy(nad_t nad)
copy a nad
Definition: nad.c:145
int iuri
Definition: nad.h:88