jabberd2  2.2.16
util/nad.h
Go to the documentation of this file.
00001 /*
00002  * jabberd - Jabber Open Source Server
00003  * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney,
00004  *                         Ryan Eatmon, Robert Norris
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
00019  */
00020 
00045 #ifndef INCL_UTIL_NAD_H
00046 #define INCL_UTIL_NAD_H 1
00047 
00048 #ifdef HAVE_CONFIG_H
00049 # include <config.h>
00050 #endif
00051 
00052 #ifdef HAVE_SYS_TYPES_H
00053 # include <sys/types.h>
00054 #endif
00055 
00056 /* jabberd2 Windows DLL */
00057 #ifndef JABBERD2_API
00058 # ifdef _WIN32
00059 #  ifdef JABBERD2_EXPORTS
00060 #   define JABBERD2_API  __declspec(dllexport)
00061 #  else /* JABBERD2_EXPORTS */
00062 #   define JABBERD2_API  __declspec(dllimport)
00063 #  endif /* JABBERD2_EXPORTS */
00064 # else /* _WIN32 */
00065 #  define JABBERD2_API extern
00066 # endif /* _WIN32 */
00067 #endif /* JABBERD2_API */
00068 
00069 struct nad_elem_st {
00070     int parent;
00071     int iname, lname;
00072     int icdata, lcdata; /* cdata within this elem (up to first child) */
00073     int itail, ltail; /* cdata after this elem */
00074     int attr;
00075     int ns;
00076     int my_ns;
00077     int depth;
00078 };
00079 
00080 struct nad_attr_st {
00081     int iname, lname;
00082     int ival, lval;
00083     int my_ns;
00084     int next;
00085 };
00086 
00087 struct nad_ns_st {
00088     int iuri, luri;
00089     int iprefix, lprefix;
00090     int next;
00091 };
00092 
00093 typedef struct nad_st
00094 {
00095     struct nad_elem_st *elems;
00096     struct nad_attr_st *attrs;
00097     struct nad_ns_st *nss;
00098     char *cdata;
00099     int *depths; /* for tracking the last elem at a depth */
00100 
00101     /* The size in bytes of the elems, attrs, nss and cdata buffers, respectively. */
00102     int elen, alen, nlen, clen, dlen;
00103 
00104     /* The number of elements of each type of that data that are actually stored in the elems, attrs, nss and cdata buffers, respectively. */
00105     int ecur, acur, ncur, ccur;
00106 
00107     int scope; /* currently scoped namespaces, get attached to the next element */
00108     struct nad_st *next; /* for keeping a list of nads */
00109 } *nad_t;
00110 
00112 JABBERD2_API nad_t nad_new(void);
00113 
00115 JABBERD2_API nad_t nad_copy(nad_t nad);
00116 
00118 JABBERD2_API void nad_free(nad_t nad);
00119 
00122 JABBERD2_API int nad_find_elem(nad_t nad, int elem, int ns, const char *name, int depth);
00123 
00125 JABBERD2_API int nad_find_attr(nad_t nad, int elem, int ns, const char *name, const char *val);
00126 
00128 JABBERD2_API int nad_find_namespace(nad_t nad, int elem, const char *uri, const char *prefix);
00129 
00131 JABBERD2_API int nad_find_scoped_namespace(nad_t nad, const char *uri, const char *prefix);
00132 
00140 JABBERD2_API int nad_find_elem_path(nad_t nad, int elem, int ns, const char *name);
00141 
00143 JABBERD2_API void nad_set_attr(nad_t nad, int elem, int ns, const char *name, const char *val, int vallen);
00144 
00146 JABBERD2_API int nad_insert_elem(nad_t nad, int elem, int ns, const char *name, const char *cdata);
00147 
00149 JABBERD2_API void nad_drop_elem(nad_t nad, int elem);
00150 
00152 JABBERD2_API void nad_wrap_elem(nad_t nad, int elem, int ns, const char *name);
00153 
00155 JABBERD2_API int nad_insert_nad(nad_t dest, int delem, nad_t src, int selem);
00156 
00158 JABBERD2_API int nad_append_elem(nad_t nad, int ns, const char *name, int depth);
00159 
00161 JABBERD2_API int nad_append_attr(nad_t nad, int ns, const char *name, const char *val);
00162 
00164 JABBERD2_API void nad_append_cdata(nad_t nad, const char *cdata, int len, int depth);
00165 
00167 JABBERD2_API int nad_add_namespace(nad_t nad, const char *uri, const char *prefix);
00168 
00170 JABBERD2_API int nad_append_namespace(nad_t nad, int elem, const char *uri, const char *prefix);
00171 
00173 JABBERD2_API void nad_print(nad_t nad, int elem, char **xml, int *len);
00174 
00176 JABBERD2_API void nad_serialize(nad_t nad, char **buf, int *len);
00177 JABBERD2_API nad_t nad_deserialize(const char *buf);
00178 
00180 JABBERD2_API nad_t nad_parse(const char *buf, int len);
00181 
00182 /* these are some helpful macros */
00183 #define NAD_ENAME(N,E) (N->cdata + N->elems[E].iname)
00184 #define NAD_ENAME_L(N,E) (N->elems[E].lname)
00185 #define NAD_CDATA(N,E) (N->cdata + N->elems[E].icdata)
00186 #define NAD_CDATA_L(N,E) (N->elems[E].lcdata)
00187 #define NAD_ANAME(N,A) (N->cdata + N->attrs[A].iname)
00188 #define NAD_ANAME_L(N,A) (N->attrs[A].lname)
00189 #define NAD_AVAL(N,A) (N->cdata + N->attrs[A].ival)
00190 #define NAD_AVAL_L(N,A) (N->attrs[A].lval)
00191 #define NAD_NURI(N,NS) (N->cdata + N->nss[NS].iuri)
00192 #define NAD_NURI_L(N,NS) (N->nss[NS].luri)
00193 #define NAD_NPREFIX(N,NS) (N->cdata + N->nss[NS].iprefix)
00194 #define NAD_NPREFIX_L(N,NS) (N->nss[NS].lprefix)
00195 
00196 #define NAD_ENS(N,E) (N->elems[E].my_ns)
00197 #define NAD_ANS(N,A) (N->attrs[A].my_ns)
00198 
00199 #endif