jabberd2  2.6.1
Data Structures | Macros | Typedefs | Functions
nad.h File Reference

Not A DOM. More...

Go to the source code of this file.

Data Structures

struct  nad_elem_st
 
struct  nad_attr_st
 
struct  nad_ns_st
 
struct  nad_st
 

Macros

#define JABBERD2_API   extern
 
#define NAD_ENAME(N, E)   (N->cdata + N->elems[E].iname)
 
#define NAD_ENAME_L(N, E)   (N->elems[E].lname)
 
#define NAD_CDATA(N, E)   (N->cdata + N->elems[E].icdata)
 
#define NAD_CDATA_L(N, E)   (N->elems[E].lcdata)
 
#define NAD_ANAME(N, A)   (N->cdata + N->attrs[A].iname)
 
#define NAD_ANAME_L(N, A)   (N->attrs[A].lname)
 
#define NAD_AVAL(N, A)   (N->cdata + N->attrs[A].ival)
 
#define NAD_AVAL_L(N, A)   (N->attrs[A].lval)
 
#define NAD_NURI(N, NS)   (N->cdata + N->nss[NS].iuri)
 
#define NAD_NURI_L(N, NS)   (N->nss[NS].luri)
 
#define NAD_NPREFIX(N, NS)   (N->cdata + N->nss[NS].iprefix)
 
#define NAD_NPREFIX_L(N, NS)   (N->nss[NS].lprefix)
 
#define NAD_ENS(N, E)   (N->elems[E].my_ns)
 
#define NAD_ANS(N, A)   (N->attrs[A].my_ns)
 

Typedefs

typedef struct nad_stnad_t
 

Functions

JABBERD2_API nad_t nad_new (void)
 create a new nad More...
 
JABBERD2_API nad_t nad_copy (nad_t nad)
 copy a nad More...
 
JABBERD2_API void nad_free (nad_t nad)
 free that nad More...
 
JABBERD2_API int nad_find_elem (nad_t nad, unsigned int elem, int ns, const char *name, int depth)
 find the next element with this name/depth More...
 
JABBERD2_API int nad_find_attr (nad_t nad, unsigned int elem, int ns, const char *name, const char *val)
 find the first matching attribute (and optionally value) More...
 
JABBERD2_API int nad_find_namespace (nad_t nad, unsigned int elem, const char *uri, const char *prefix)
 find the first matching namespace (and optionally prefix) More...
 
JABBERD2_API int nad_find_scoped_namespace (nad_t nad, const char *uri, const char *prefix)
 find a namespace in scope (and optionally prefix) More...
 
JABBERD2_API int nad_find_elem_path (nad_t nad, unsigned 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 child (recurses) "?attrib" to match the first tag with that attrib defined "?attrib=value" to match the first tag with that attrib and value or any combination: "name/name/?attrib", etc More...
 
JABBERD2_API void nad_set_attr (nad_t nad, unsigned int elem, int ns, const char *name, const char *val, int vallen)
 reset or store the given attribute More...
 
JABBERD2_API int nad_insert_elem (nad_t nad, unsigned int parent, int ns, const char *name, const char *cdata)
 insert and return a new element as a child of this one More...
 
JABBERD2_API void nad_drop_elem (nad_t nad, unsigned int elem)
 remove an element (and its subelements) More...
 
JABBERD2_API void nad_wrap_elem (nad_t nad, unsigned int elem, int ns, const char *name)
 wrap an element with another element More...
 
JABBERD2_API int nad_insert_nad (nad_t dest, int delem, nad_t src, int selem)
 insert part of a nad into another nad More...
 
JABBERD2_API int nad_append_elem (nad_t nad, int ns, const char *name, int depth)
 append and return a new element More...
 
JABBERD2_API int nad_append_attr (nad_t nad, int ns, const char *name, const char *val)
 append attribs to the last element More...
 
JABBERD2_API void nad_append_cdata (nad_t nad, const char *cdata, int len, int depth)
 append more cdata to the last element More...
 
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) More...
 
JABBERD2_API int nad_append_namespace (nad_t nad, unsigned int elem, const char *uri, const char *prefix)
 declare a namespace on an already existing element More...
 
JABBERD2_API void nad_print (nad_t nad, unsigned int elem, const char **xml, int *len)
 create a string representation of the given element (and children), point references to it More...
 
JABBERD2_API void nad_serialize (nad_t nad, char **buf, int *len)
 serialize and deserialize a nad More...
 
JABBERD2_API nad_t nad_deserialize (const char *buf)
 
JABBERD2_API nad_t nad_parse (const char *buf, int len)
 create a nad from raw xml More...
 

Detailed Description

Not A DOM.

Author
Jeremie Miller
Robert Norris
Date
2004/05/05 23:49:38
Revision
1.3

NAD is very simplistic, and requires all string handling to use a length. Apps using this must be aware of the structure and access it directly for most information. NADs can only be built by successively using the append functions correctly. After built, they can be modified using other functions, or by direct access. To access cdata on an elem or attr, use nad->cdata + nad->xxx[index].ixxx for the start, and .lxxx for len.

Namespace support seems to work, but hasn't been thoroughly tested. in particular, editing the NAD after its creation might have quirks. use at your own risk! Note that nad_add_namespace() brings a namespace into scope for the next element added with nad_append_elem(), nad_insert_elem() or nad_wrap_elem() (and by extension, any of its subelements). This is the same way that Expat does things, so nad_add_namespace() can be driven from Expat's StartNamespaceDeclHandler. See nad_parse() for an example of how to use Expat to drive NAD.

Definition in file nad.h.

Macro Definition Documentation

◆ JABBERD2_API

#define JABBERD2_API   extern

Definition at line 65 of file nad.h.

◆ NAD_ENAME

#define NAD_ENAME (   N,
 
)    (N->cdata + N->elems[E].iname)

◆ NAD_ENAME_L

#define NAD_ENAME_L (   N,
 
)    (N->elems[E].lname)

◆ NAD_CDATA

#define NAD_CDATA (   N,
 
)    (N->cdata + N->elems[E].icdata)

◆ NAD_CDATA_L

#define NAD_CDATA_L (   N,
 
)    (N->elems[E].lcdata)

◆ NAD_ANAME

#define NAD_ANAME (   N,
 
)    (N->cdata + N->attrs[A].iname)

Definition at line 187 of file nad.h.

Referenced by config_load_with_id().

◆ NAD_ANAME_L

#define NAD_ANAME_L (   N,
 
)    (N->attrs[A].lname)

Definition at line 188 of file nad.h.

Referenced by config_load_with_id().

◆ NAD_AVAL

#define NAD_AVAL (   N,
 
)    (N->cdata + N->attrs[A].ival)

◆ NAD_AVAL_L

#define NAD_AVAL_L (   N,
 
)    (N->attrs[A].lval)

◆ NAD_NURI

#define NAD_NURI (   N,
  NS 
)    (N->cdata + N->nss[NS].iuri)

◆ NAD_NURI_L

#define NAD_NURI_L (   N,
  NS 
)    (N->nss[NS].luri)

◆ NAD_NPREFIX

#define NAD_NPREFIX (   N,
  NS 
)    (N->cdata + N->nss[NS].iprefix)

Definition at line 193 of file nad.h.

Referenced by nad_find_namespace(), nad_find_scoped_namespace(), and nad_insert_nad().

◆ NAD_NPREFIX_L

#define NAD_NPREFIX_L (   N,
  NS 
)    (N->nss[NS].lprefix)

Definition at line 194 of file nad.h.

Referenced by nad_find_namespace(), nad_find_scoped_namespace(), and nad_insert_nad().

◆ NAD_ENS

#define NAD_ENS (   N,
 
)    (N->elems[E].my_ns)

◆ NAD_ANS

#define NAD_ANS (   N,
 
)    (N->attrs[A].my_ns)

Definition at line 197 of file nad.h.

Typedef Documentation

◆ nad_t

typedef struct nad_st * nad_t

Function Documentation

◆ nad_new()

JABBERD2_API nad_t nad_new ( void  )

◆ nad_copy()

JABBERD2_API nad_t nad_copy ( nad_t  nad)

◆ nad_free()

JABBERD2_API void nad_free ( nad_t  nad)

◆ nad_find_elem()

JABBERD2_API int nad_find_elem ( nad_t  nad,
unsigned int  elem,
int  ns,
const char *  name,
int  depth 
)

◆ nad_find_attr()

JABBERD2_API int nad_find_attr ( nad_t  nad,
unsigned int  elem,
int  ns,
const char *  name,
const char *  val 
)

◆ nad_find_namespace()

JABBERD2_API int nad_find_namespace ( nad_t  nad,
unsigned int  elem,
const char *  uri,
const char *  prefix 
)

◆ nad_find_scoped_namespace()

JABBERD2_API int nad_find_scoped_namespace ( nad_t  nad,
const char *  uri,
const char *  prefix 
)

◆ nad_find_elem_path()

JABBERD2_API int nad_find_elem_path ( nad_t  nad,
unsigned 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 child (recurses) "?attrib" to match the first tag with that attrib defined "?attrib=value" to match the first tag with that attrib and value or any combination: "name/name/?attrib", etc

find elem using XPath like query name – "name" for the child tag of that name "name/name" for a sub child (recurses) "?attrib" to match the first tag with that attrib defined "?attrib=value" to match the first tag with that attrib and value or any combination: "name/name/?attrib", etc

Definition at line 322 of file nad.c.

References _nad_ptr_check, nad_st::ecur, nad_find_attr(), nad_find_elem(), nad_find_elem_path(), and nad_find_namespace().

Referenced by filter_packet(), and nad_find_elem_path().

◆ nad_set_attr()

JABBERD2_API void nad_set_attr ( nad_t  nad,
unsigned int  elem,
int  ns,
const char *  name,
const char *  val,
int  vallen 
)

◆ nad_insert_elem()

JABBERD2_API int nad_insert_elem ( nad_t  nad,
unsigned int  parent,
int  ns,
const char *  name,
const char *  cdata 
)

◆ nad_drop_elem()

JABBERD2_API void nad_drop_elem ( nad_t  nad,
unsigned int  elem 
)

remove an element (and its subelements)

Definition at line 484 of file nad.c.

References _nad_ptr_check, nad_elem_st::depth, nad_st::ecur, nad_st::elems, and nad_elem_st::parent.

Referenced by _announce_pkt_sm(), _help_pkt_sm(), _iq_ping_reply(), _roster_in_sess(), and _session_in_router().

◆ nad_wrap_elem()

JABBERD2_API void nad_wrap_elem ( nad_t  nad,
unsigned int  elem,
int  ns,
const char *  name 
)

◆ nad_insert_nad()

JABBERD2_API int nad_insert_nad ( nad_t  dest,
int  delem,
nad_t  src,
int  selem 
)

◆ nad_append_elem()

JABBERD2_API int nad_append_elem ( nad_t  nad,
int  ns,
const char *  name,
int  depth 
)

append and return a new element

append and return a new element

Definition at line 711 of file nad.c.

References _nad_cdata(), _nad_ptr_check, nad_elem_st::attr, nad_elem_st::depth, nad_st::depths, nad_st::dlen, nad_st::ecur, nad_st::elems, nad_st::elen, nad_elem_st::icdata, nad_elem_st::iname, nad_elem_st::itail, nad_elem_st::lcdata, nad_elem_st::lname, nad_elem_st::ltail, nad_elem_st::my_ns, NAD_SAFE, nad_elem_st::ns, nad_elem_st::parent, and nad_st::scope.

Referenced by _address_features(), _amp_pkt_sm(), _authreg_auth_get(), _authreg_auth_set(), _authreg_register_get(), _authreg_register_set(), _bind_features(), _c2s_client_sx_callback(), _config_startElement(), _disco_agents_result(), _disco_info_result(), _disco_items_result(), _disco_pkt_router(), _disco_pkt_sm(), _disco_sessions_result(), _disco_user_result(), _help_disco_extend(), _in_result(), _iq_vcard_to_pkt(), _iq_version_disco_extend(), _nad_parse_element_start(), _offline_pkt_user(), _out_dialback(), _out_verify(), _pbx_presence_nad(), _pep_out_sess(), _roster_in_sess_s10n(), _roster_pkt_user(), _roster_set_item(), _roster_update_walker(), _router_advertise(), _router_advertise_reverse(), _s2s_db_features(), _sm_build_route(), _sx_ack_features(), _sx_compress_features(), _sx_element_start(), _sx_sasl_abort(), _sx_sasl_challenge(), _sx_sasl_failure(), _sx_sasl_features(), _sx_sasl_response(), _sx_sasl_success(), _sx_server_notify_header(), _sx_ssl_features(), amp_build_response_pkt(), c2s_router_sx_callback(), pkt_create(), s2s_router_sx_callback(), sm_c2s_action(), sm_sx_callback(), and sx_sasl_auth().

◆ nad_append_attr()

JABBERD2_API int nad_append_attr ( nad_t  nad,
int  ns,
const char *  name,
const char *  val 
)

◆ nad_append_cdata()

JABBERD2_API void nad_append_cdata ( nad_t  nad,
const char *  cdata,
int  len,
int  depth 
)

◆ nad_add_namespace()

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)

add a namespace to the next element (ie, called when the namespace comes into scope)

Definition at line 778 of file nad.c.

References _nad_cdata(), _nad_ptr_check, nad_ns_st::iprefix, nad_ns_st::iuri, nad_ns_st::lprefix, nad_ns_st::luri, nad_find_scoped_namespace(), NAD_SAFE, nad_st::ncur, nad_ns_st::next, nad_st::nlen, nad_st::nss, and nad_st::scope.

Referenced by _address_features(), _amp_pkt_sm(), _authreg_auth_get(), _authreg_auth_set(), _authreg_register_get(), _authreg_register_set(), _bind_features(), _c2s_client_sx_callback(), _disco_agents_result(), _disco_info_result(), _disco_items_result(), _disco_pkt_router(), _disco_pkt_sm(), _disco_sessions_result(), _help_disco_extend(), _in_packet(), _in_result(), _iq_vcard_to_pkt(), _iq_version_disco_extend(), _nad_parse_element_start(), _nad_parse_namespace_start(), _offline_pkt_user(), _out_dialback(), _out_verify(), _pbx_presence_nad(), _privacy_in_sess(), _privacy_out_router(), _roster_in_sess_s10n(), _roster_insert_item(), _roster_pkt_user(), _roster_set_item(), _roster_update_walker(), _router_advertise(), _router_advertise_reverse(), _router_sx_callback(), _s2s_db_features(), _sm_build_route(), _sx_compress_features(), _sx_element_start(), _sx_namespace_start(), _sx_sasl_abort(), _sx_sasl_challenge(), _sx_sasl_failure(), _sx_sasl_features(), _sx_sasl_response(), _sx_sasl_success(), _sx_server_notify_header(), _sx_ssl_features(), amp_build_response_pkt(), c2s_router_sx_callback(), nad_insert_nad(), pkt_create(), pkt_delay(), s2s_router_sx_callback(), sm_c2s_action(), sm_packet(), sm_sx_callback(), stanza_error(), and sx_sasl_auth().

◆ nad_append_namespace()

JABBERD2_API int nad_append_namespace ( nad_t  nad,
unsigned int  elem,
const char *  uri,
const char *  prefix 
)

declare a namespace on an already existing element

declare a namespace on an already existing element

Definition at line 814 of file nad.c.

References _nad_cdata(), _nad_ptr_check, nad_st::elems, nad_ns_st::iprefix, nad_ns_st::iuri, nad_ns_st::lprefix, nad_ns_st::luri, nad_find_namespace(), NAD_SAFE, nad_st::ncur, nad_ns_st::next, nad_st::nlen, nad_elem_st::ns, and nad_st::nss.

Referenced by _nad_parse_element_start(), _sx_element_start(), sess_route(), and sm_packet().

◆ nad_print()

JABBERD2_API void nad_print ( nad_t  nad,
unsigned int  elem,
const char **  xml,
int *  len 
)

create a string representation of the given element (and children), point references to it

Definition at line 1208 of file nad.c.

References _nad_lp0(), _nad_ptr_check, nad_st::ccur, and nad_st::cdata.

Referenced by _help_pkt_sm(), _router_process_route(), _sx_nad_write(), _sx_process_read(), _sx_server_notify_header(), c2s_router_sx_callback(), and filter_packet().

◆ nad_serialize()

JABBERD2_API void nad_serialize ( nad_t  nad,
char **  buf,
int *  len 
)

serialize and deserialize a nad

serialize and deserialize a nad

[buflen][ecur][acur][ncur][ccur][elems][attrs][nss][cdata]

nothing is done with endianness or word length, so the nad must be serialized and deserialized on the same platform

buflen is not actually used by deserialize(), but is provided as a convenience to the application so it knows how many bytes to read before passing them in to deserialize()

the depths array is not stored, so after deserialization nad_append_elem() and nad_append_cdata() will not work. this is rarely a problem

Definition at line 1236 of file nad.c.

References _nad_ptr_check, nad_st::acur, nad_st::attrs, nad_st::ccur, nad_st::cdata, nad_st::ecur, nad_st::elems, nad_st::ncur, and nad_st::nss.

◆ nad_deserialize()

JABBERD2_API nad_t nad_deserialize ( const char *  buf)

◆ nad_parse()

JABBERD2_API nad_t nad_parse ( const char *  buf,
int  len 
)