jutil.cc File Reference

various utilities mainly for handling xmlnodes containing stanzas More...

#include <jabberdlib.h>

Defines

#define KEYBUF   100

Functions

xmlnode jutil_presnew (int type, char const *to, char const *status)
xmlnode jutil_iqnew (int type, char *ns)
xmlnode jutil_msgnew (char const *type, char const *to, char const *subj, char const *body)
int jutil_priority (xmlnode x)
void jutil_tofrom (xmlnode x)
xmlnode jutil_iqresult (xmlnode x)
char * jutil_timestamp (void)
char * jutil_timestamp_ms (char buffer[25])
void jutil_error_map (terror old, xterror *mapped)
void jutil_error_xmpp (xmlnode x, xterror E)
void jutil_error (xmlnode x, terror E)
void jutil_delay (xmlnode msg, char *reason)
char * jutil_regkey (char *key, char *seed)

Detailed Description

various utilities mainly for handling xmlnodes containing stanzas


Define Documentation

#define KEYBUF   100

Referenced by jutil_regkey().


Function Documentation

void jutil_delay ( xmlnode  msg,
char *  reason 
)

add a delayed delivery (XEP-0091) element to a message using the present timestamp. If a reason is given, this reason will be added as CDATA to the inserted element

Parameters:
msg the message where the element should be added
reason plain text information why the delayed delivery information has been added

References jutil_timestamp(), messages_get(), NS_DELAY, xmlnode_get_attrib_ns(), xmlnode_get_lang(), xmlnode_insert_cdata(), xmlnode_insert_tag_ns(), and xmlnode_put_attrib_ns().

void jutil_error ( xmlnode  x,
terror  E 
)

wrapper around jutil_error_xmpp for compatibility with modules for jabberd up to version 1.4.3

Deprecated:
use jutil_error_xmpp instead!
Parameters:
x the xmlnode that should become an stanza error message
E the strucutre that holds the error information

References jutil_error_map(), and jutil_error_xmpp().

void jutil_error_map ( terror  old,
xterror mapped 
)

map a terror structure to a xterror structure

terror structures have been used in jabberd14 up to version 1.4.3 but are not able to hold XMPP compliant stanza errors. The xterror structure has been introduced to be XMPP compliant. This function is to ease writting wrappers that accept terror structures and call the real functions that require now xterror structures

Parameters:
old the terror struct that should be converted
mapped pointer to the xterror struct that should be filled with the converted error

References terror_struct::code, xterror_struct::code, xterror_struct::condition, xterror_struct::msg, terror_struct::msg, and xterror_struct::type.

Referenced by jutil_error().

void jutil_error_xmpp ( xmlnode  x,
xterror  E 
)
xmlnode jutil_iqnew ( int  type,
char *  ns 
)

utility for making IQ stanzas, that contain a <query/> element in a different namespace

Note:
In traditional Jabber protocols the element inside an iq element has the name "query". This util is not able to create IQ stanzas that contain a query which a element that does not have the name "query"
Parameters:
type the type of the iq stanza (one of JPACKET__GET, JPACKET__SET, JPACKET__RESULT, JPACKET__ERROR)
ns the namespace of the <query/> element
Returns:
the created xmlnode

References JPACKET__ERROR, JPACKET__GET, JPACKET__RESULT, JPACKET__SET, NS_SERVER, xmlnode_insert_tag_ns(), xmlnode_new_tag_ns(), and xmlnode_put_attrib_ns().

xmlnode jutil_iqresult ( xmlnode  x  ) 

change and xmlnode to be the result xmlnode for the original iq query

Parameters:
x the xmlnode that should become the result for itself
Returns:
the result xmlnode (same as given as parameter x)

References jutil_tofrom(), xmlnode_get_firstchild(), xmlnode_get_nextsibling(), xmlnode_hide(), and xmlnode_put_attrib_ns().

Referenced by js_bounce_xmpp(), and js_mapi_create_additional_iq_result().

xmlnode jutil_msgnew ( char const *  type,
char const *  to,
char const *  subj,
char const *  body 
)

utility for making message stanzas

Parameters:
type the type of the message (as a string!)
to the recipient of the message
subj the subject of the message (NULL for no subject element)
body the body of the message
Returns:
the xmlnode containing the new message stanza

References j_strlen(), NS_SERVER, xmlnode_insert_cdata(), xmlnode_insert_tag_ns(), xmlnode_new_tag_ns(), and xmlnode_put_attrib_ns().

xmlnode jutil_presnew ( int  type,
char const *  to,
char const *  status 
)

utility for making presence stanzas

Parameters:
type the type of the presence (one of the JPACKET__* contants)
to to whom the presence should be sent, NULL for a broadcast presence
status optional status (CDATA for the <status/> element, NULL for no <status/> element)
Returns:
the xmlnode containing the created presence stanza

References j_strlen(), JPACKET__INVISIBLE, JPACKET__PROBE, JPACKET__SUBSCRIBE, JPACKET__SUBSCRIBED, JPACKET__UNAVAILABLE, JPACKET__UNSUBSCRIBE, JPACKET__UNSUBSCRIBED, NS_SERVER, xmlnode_insert_cdata(), xmlnode_insert_tag_ns(), xmlnode_new_tag_ns(), and xmlnode_put_attrib_ns().

Referenced by js_sc_session_new(), js_session_end(), and js_session_new().

int jutil_priority ( xmlnode  x  ) 

returns the priority on an available presence packet

Parameters:
x the xmlnode containing the presence packet
Returns:
the presence priority, -129 for unavailable presences and errors

References NS_SERVER, xhash_free(), xhash_new(), xhash_put(), xmlnode_get_attrib_ns(), xmlnode_get_data(), xmlnode_get_list_item(), and xmlnode_get_tags().

char* jutil_regkey ( char *  key,
char *  seed 
)

create or validate a key value for stone-age jabber protocols

Before dialback had been introduced for s2s (and therefore only in jabberd 1.0), Jabber used these keys to protect some iq requests. A client first had to request a key with a IQ get and use it inside the IQ set request. By being able to receive the key in the IQ get response, the client (more or less) proved to be who he claimed to be.

The implementation of this function uses a static array with KEYBUF entries (default value of KEYBUF is 100). Therefore a key gets invalid at the 100th key that is created afterwards. It is also invalidated after it has been validated once.

Deprecated:
This function is not really used anymore. jabberd14 does not check any keys anymore and only creates them in the jsm's mod_register.c for compatibility. This function is also used in mod_groups.c and the key is even checked there, but I do not know if mod_groups.c still works at all.
Parameters:
key for validation the key the client sent, for generation of a new key NULL
seed the seed for generating the key, must stay the same for the same user
Returns:
the new key when created, the key if the key has been validated, NULL if the key is invalid

References j_strcmp(), KEYBUF, and shahash().

char* jutil_timestamp ( void   ) 

get the present time as a textual timestamp in the format YYYYMMDDTHH:MM:SS

Note:
this function is not thread safe
Returns:
pointer to a static (!) buffer containing the timestamp (or NULL on failure)

Referenced by jutil_delay().

char* jutil_timestamp_ms ( char  buffer[25]  ) 

get the present time as a textual timestamp in the format YYYY-MM-DDTHH:MM:SS.MMMZ

Parameters:
buffer place where the timestamp should be written
Returns:
pointer to the buffer
void jutil_tofrom ( xmlnode  x  ) 

Generated on Sat Mar 13 06:00:07 2010 for jabberd14 by  doxygen 1.6.1