expat.cc File Reference

reading/writing xmlnodes from/to files, reading xmlnodes from strings More...

#include <jabberdlib.h>

Data Structures

struct  _expat_callback_data

Typedefs

typedef struct
_expat_callback_data
expat_callback_data

Functions

void expat_startElement (void *userdata, const char *name, const char **atts)
void expat_endElement (void *userdata, const char *name)
void expat_charData (void *userdata, const char *s, int len)
xmlnode xmlnode_str (const char *str, int len)
xmlnode xmlnode_file (const char *file)
char const * xmlnode_file_borked (char const *file)
int xmlnode2file (char const *file, xmlnode node)
int xmlnode2file_limited (char const *file, xmlnode node, size_t sizelimit)
void xmlnode_put_expat_attribs (xmlnode owner, const char **atts, xmppd::ns_decl_list &nslist)

Detailed Description

reading/writing xmlnodes from/to files, reading xmlnodes from strings

This file implements some tools for the xmlnode implementation in xmlnode.c

The name of this file is confusing. This file does not contain the expat implementation. It contains some code that uses expat to parse XML and build xmlnodes.

Note:
jabberd14's codebase up to jabberd 1.4.3 had included expat's source. Later versions dynamically link against expat and don't include the code anymore.

Typedef Documentation


Function Documentation

void expat_charData ( void *  userdata,
const char *  s,
int  len 
)

callback function for CDATA nodes

This function will insert CDATA in an xmlnode

Parameters:
userdata pointer to the current xmlnode
s pointer to the CDATA string (not zero terminated!)
len length of the CDATA string

References _expat_callback_data::x, and xmlnode_insert_cdata().

Referenced by xmlnode_file(), and xmlnode_str().

void expat_endElement ( void *  userdata,
const char *  name 
)

callback function used for end elements

This function is used internally by expat.c as a callback function given to expat. It will complete an xmlnode and update the userdata pointer to point to the node that is parent of the next starting element.

Parameters:
userdata pointer to the current xmlnode
name name of the ending element (ignored by this function)

References _expat_callback_data::x, and xmlnode_get_parent().

Referenced by xmlnode_file(), and xmlnode_str().

void expat_startElement ( void *  userdata,
const char *  name,
const char **  atts 
)

callback function used for start elements

This function is used internally by expat.c as a callback function given to expat. It will create a new xmlnode and add it to the already created xmlnode tree.

Parameters:
userdata pointer to the parent xmlnode instance (NULL if this function is called for the root note)
name name of the starting element
atts attributes that are contained in the start element

References xmppd::ns_decl_list::get_nsprefix(), j_strcmp(), _expat_callback_data::ns, NS_DIALBACK, NS_STREAM, _expat_callback_data::parse_pool, pstrdup(), _expat_callback_data::x, xmlnode_insert_tag_ns(), xmlnode_new_tag_ns(), xmlnode_put_expat_attribs(), and XMLNS_SEPARATOR.

Referenced by xmlnode_file(), and xmlnode_str().

int xmlnode2file ( char const *  file,
xmlnode  node 
)

write an xmlnode to a file (without a size limit)

Parameters:
file the target file
node the xmlnode that should be written
Returns:
1 on success, -1 on failure

References xmlnode2file_limited().

Referenced by jsm_serialize(), and main().

int xmlnode2file_limited ( char const *  file,
xmlnode  node,
size_t  sizelimit 
)

write an xmlnode to a file, limited by size

Parameters:
file the target file
node the xmlnode that should be written
sizelimit the maximum length of the file to be written
Returns:
1 on success, 0 if failed due to size limit, -1 on failure

References j_strlen(), and xmlnode_serialize_string().

Referenced by xdb_file_phandler(), and xmlnode2file().

xmlnode xmlnode_file ( const char *  file  ) 

create an xmlnode instance (possibly including other xmlnode instances) by parsing a file

This function will parse a file containing an XML document and create an xmlnode graph

Parameters:
file the filename
Returns:
the graph of xmlnodes that represent the parsed document, NULL on failure

References expat_charData(), expat_endElement(), expat_startElement(), _expat_callback_data::ns, _expat_callback_data::parse_pool, pool_free(), pool_new, _expat_callback_data::x, xmlnode_free(), and XMLNS_SEPARATOR.

Referenced by configurate(), jsm_deserialize(), main(), and xdb_file_load().

char const* xmlnode_file_borked ( char const *  file  ) 

get message why parsing of a file failed

This function can be used to get a textual message why parsing an XML file failed.

Parameters:
file the filename
Returns:
pointer to a message why parsing failed, NULL if parsing did not fail

References XMLNS_SEPARATOR.

Referenced by configurate(), and main().

void xmlnode_put_expat_attribs ( xmlnode  owner,
const char **  atts,
xmppd::ns_decl_list nslist 
)

append attributes in the expat format to an existing xmlnode

Parameters:
owner where to add the attributes
atts the attributes in expat format (even indexes are the attribute names, odd indexes the values)
nslist list of currently defined prefixes for namespace IRIs

References xmppd::ns_decl_list::get_nsprefix(), j_strcmp(), NS_DIALBACK, NS_STREAM, pstrdup(), xmlnode_pool(), xmlnode_put_attrib_ns(), and XMLNS_SEPARATOR.

Referenced by expat_startElement().

xmlnode xmlnode_str ( const char *  str,
int  len 
)

create an xmlnode instance (possibly including other xmlnode instances) by parsing a string

This function will parse a string containing an XML document and create an xmlnode graph

Parameters:
str the string containing the XML document (not necessarily zero terminated)
len the length of the string (without the zero byte, if present)
Returns:
the graph of xmlnodes that represent the parsed document, NULL on failure

References expat_charData(), expat_endElement(), expat_startElement(), _expat_callback_data::ns, _expat_callback_data::parse_pool, pool_free(), pool_new, _expat_callback_data::x, xmlnode_free(), and XMLNS_SEPARATOR.

Referenced by main(), and xdb_file_phandler().


Generated on Thu Mar 11 06:00:05 2010 for jabberd14 by  doxygen 1.6.1