class XMPPUtils

General XMPP utilities. More...

Full nameTelEngine::XMPPUtils
Definition#include <libs/yjabber/xmpputils.h>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Static Methods

Public Members


Detailed Description

This class is a general XMPP utilities

enum Presence { Probe, Subscribe, Subscribed, Unavailable, Unsubscribe, Unsubscribed, PresenceError, PresenceNone }

Presence

Presence type enumeration

enum MsgType { Chat, GroupChat, HeadLine, Normal, MsgError, }

MsgType

Message type enumeration

enum IqType { IqSet, IqGet, IqResult, IqError, IqCount }

IqType

Iq type enumeration

enum CommandAction { CommExecute, CommCancel, CommPrev, CommNext, CommComplete, }

CommandAction

Command action enumeration

enum CommandStatus { CommExecuting, CommCompleted, CommCancelled, }

CommandStatus

Command status enumeration

enum AuthMethod { AuthNone = 0x00, AuthSHA1 = 0x01, AuthMD5 = 0x02, AuthPlain = 0x04, AuthDialback = 0x08, }

AuthMethod

Authentication methods

inline bool  isResponse (const XmlElement& xml)

isResponse

[static]

Check if an xml element has type 'result' or 'error'

Parameters:
xmlThe element to check

Returns: True if the element is a response one

inline XmlElement*  createElement (const char* name, const char* text = 0, const String& ns = String::empty())

createElement

[static]

Create an XML element

Parameters:
nameElement's name
textOptional text for the element
nsOptional element namespace

Returns: A valid XmlElement pointer

inline XmlElement*  createElement (int type, const char* text = 0)

createElement

[static]

Create an XML element

Parameters:
typeElement's type
textOptional text for the element

Returns: A valid XmlElement pointer

inline XmlElement*  createElement (const char* name, int ns, const char* text = 0)

createElement

[static]

Create an XML element with an 'xmlns' attribute

Parameters:
nameElement's name
nsOptional 'xmlns' attribute as enumeration
textOptional text for the element

Returns: A valid XmlElement pointer

inline XmlElement*  createElement (int type, int ns, const char* text = 0)

createElement

[static]

Create an XML element with an 'xmlns' attribute

Parameters:
typeElement's type
ns'xmlns' attribute as enumeration
textOptional text for the element

Returns: A valid XmlElement pointer

XmlElement*  createElement (const XmlElement& src, bool response, bool result)

createElement

[static]

Partially build an XML element from another one. Copy tag and 'to', 'from', 'type', 'id' attributes

Parameters:
srcSource element
responseTrue to reverse 'to' and 'from' attributes
resultTrue to set type to "result", false to set it to "error". Ignored if response is false

XmlElement*  createIq (IqType type, const char* from = 0, const char* to = 0, const char* id = 0)

createIq

[static]

Create an 'iq' element

Parameters:
typeIq type as enumeration
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute

Returns: A valid XmlElement pointer

inline XmlElement*  createIqResult (const char* from, const char* to, const char* id, XmlElement* child = 0)

createIqResult

[static]

Create an 'iq' result element

Parameters:
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
childOptional element child (will be consumed)

Returns: A valid XmlElement pointer

XmlElement*  createIqError (const char* from, const char* to, XmlElement*& xml, int type, int error, const char* text = 0)

createIqError

[static]

Create an 'iq' error from a received element. Consume the received element. Add the given element to the error stanza if the 'id' attribute is missing

Parameters:
fromThe 'from' attribute
toThe 'to' attribute
xmlReceived element
typeError type
errorThe error
textOptional text to add to the error element

Returns: A valid XmlElement pointer or 0 if xml

XmlElement*  createVCard (bool get, const char* from, const char* to, const char* id)

createVCard

[static]

Create an 'iq' element with a 'vcard' child

Parameters:
getTrue to set the iq's type to 'get', false to set it to 'set'
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute

Returns: A valid XmlElement pointer

XmlElement*  createCommand (CommandAction action, const char* node, const char* sessionId = 0)

createCommand

[static]

Create a 'command' element

Parameters:
actionThe command action
nodeThe command
sessionIdOptional session ID for the command

Returns: A valid XmlElement pointer

XmlElement*  createIqDisco (bool info, bool req, const char* from, const char* to, const char* id, const char* node = 0, const char* cap = 0)

createIqDisco

[static]

Create a disco info/items 'iq' element with a 'query' child

Parameters:
infoTrue to create a query info request. False to create a query items request
reqTrue to create a request (type=get), false to create a response (type=result)
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
nodeOptional 'node' attribute
capOptional capability to be set as 'node' suffix

Returns: A valid XmlElement pointer

XmlElement*  createIqVersionRes (const char* from, const char* to, const char* id, const char* name, const char* version, const char* os = 0)

createIqVersionRes

[static]

Create a version 'iq' result as defined in XEP-0092

Parameters:
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
nameProgram name
versionProgram version
osOptional operating system

Returns: A valid XmlElement pointer

XmlElement*  createError (int type, int error, const char* text = 0)

createError

[static]

Create a 'error' element

Parameters:
typeError type
errorThe error
textOptional text to add to the error element

Returns: A valid XmlElement pointer

XmlElement*  createError (XmlElement* xml, int type, int error, const char* text = 0)

createError

[static]

Create an error from a received element. Consume the received element. Reverse 'to' and 'from' attributes

Parameters:
xmlReceived element
typeError type
errorThe error
textOptional text to add to the error element

Returns: A valid XmlElement pointer or 0 if xml is 0

XmlElement*  createStreamError (int error, const char* text = 0)

createStreamError

[static]

Create a 'stream:error' element

Parameters:
errorThe XMPP defined condition
textOptional text to add to the error

Returns: A valid XmlElement pointer

XmlElement*  createRegisterQuery (IqType type, const char* from, const char* to, const char* id, XmlElement* child1 = 0, XmlElement* child2 = 0, XmlElement* child3 = 0)

createRegisterQuery

[static]

Build a register query element

Parameters:
typeIq type as enumeration
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
child1Optional child of query element
child2Optional child of query element
child3Optional child of query element

Returns: Valid XmlElement pointer

inline XmlElement*  createIqAuthGet (const char* id)

createIqAuthGet

[static]

Build a jabber:iq:auth 'iq' get element

Parameters:
idElement 'id' attribute

Returns: A valid XmlElement pointer

XmlElement*  createIqAuthSet (const char* id, const char* username, const char* resource, const char* authStr, bool digest)

createIqAuthSet

[static]

Build a jabber:iq:auth 'iq' set element

Parameters:
idElement 'id' attribute
usernameThe username
resourceThe resource
authStrAuthentication string
digestTrue if authentication string is a digest, false if it's a plain password

Returns: A valid XmlElement pointer

XmlElement*  createIqAuthOffer (const char* id, bool digest = true, bool plain = false)

createIqAuthOffer

[static]

Build a jabber:iq:auth 'iq' offer in response to a 'get' request

Parameters:
idElement 'id' attribute
digestOffer digest authentication
plainOffer plain password authentication

Returns: A valid XmlElement pointer

inline XmlElement*  createRegisterQuery (const char* from, const char* to, const char* id, const char* username, const char* password)

createRegisterQuery

[static]

Build an register query element used to create/set username/password

Parameters:
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
usernameThe username
passwordThe password

Returns: Valid XmlElement pointer

inline XmlElement*  createFailure (XMPPNamespace::Type ns, XMPPError::Type error = XMPPError::NoError)

createFailure

[static]

Create a failure element

Parameters:
nsElement namespace
errorOptional error

Returns: XmlElement pointer

inline XmlElement*  createXOobUrl (const char* url, const char* desc = 0)

createXOobUrl

[static]

Create an 'x' jabber:x:oob url element as described in XEP-0066

Parameters:
urlThe URL
descOptional description

Returns: XmlElement pointer

XmlElement*  createDelay (unsigned int timeSec, const char* from = 0, unsigned int fractions = 0, const char* text = 0)

createDelay

[static]

Create a 'delay' element as defined in XEP-0203

Parameters:
timeSecThe time to encode (in seconds)
fromOptional 'from' attribute
fractionsOptional second fractions
textOptional xml element text

Returns: XmlElement pointer

inline bool  remove (XmlElement& xml)

remove

[static]

Check if an element has a child with 'remove' tag

Parameters:
xmlThe element to check

Returns: True if the element has a child with 'remove' tag

inline bool  required (XmlElement& xml)

required

[static]

Check if an element has a child with 'required' tag

Parameters:
xmlThe element to check

Returns: True if the element has a child with 'required' tag

int  priority (XmlElement& xml, int defVal = 0)

priority

[static]

Check if an element has a child with 'priority' tag

Parameters:
xmlThe element to check
defValDefault value to return if not found or invalid integer

Returns: Element priority

inline void  setPriority (XmlElement& xml, const char* prio)

setPriority

[static]

Add a 'priority' child to an element

Parameters:
xmlThe element to set
prioPriority text

inline int  xmlns (XmlElement& xml)

xmlns

[static]

Get an element's namespace

Parameters:
xmlElement

Returns: Element namespace as enumeration

inline bool  hasDefaultXmlns (const XmlElement& xml, int ns)

hasDefaultXmlns

[static]

Check if the given element has a given default namespace

Parameters:
xmlElement to check
nsNamespace value to check

Returns: True if the given element has the requested default namespace

inline bool  hasXmlns (const XmlElement& xml, int ns)

hasXmlns

[static]

Check if the given element has a given namespace

Parameters:
xmlElement to check
nsNamespace value to check

Returns: True if the given element is in the requested namespace

inline bool  setXmlns (XmlElement& xml, const String& name = String::empty(), bool addAttr = false, int ns = XMPPNamespace::Count)

setXmlns

[static]

Set an element's namespace

Parameters:
xmlElement
nameNamespace attribute name
addAttrTrue to add the namespace attribute value
nsNamespace value as enumeration

Returns: True on success

inline bool  setStreamXmlns (XmlElement& xml, bool addAttr = true)

setStreamXmlns

[static]

Set the 'stream' namespace to an element

Parameters:
xmlElement
addAttrTrue to add the xmlns attribute

Returns: True on success

inline bool  setDbXmlns (XmlElement& xml)

setDbXmlns

[static]

Set the 'db' namespace to an element

Parameters:
xmlElement

Returns: True on success

XmlElement*  findFirstChild (const XmlElement& xml, int t = XmlTag::Count, int ns = XMPPNamespace::Count)

findFirstChild

[static]

Find an element's first child element in a given namespace

Parameters:
xmlElement
tOptional element tag as enumeration
nsOptional element namespace as enumeration

Returns: XmlElement pointer or 0 if not found

XmlElement*  findNextChild (const XmlElement& xml, XmlElement* start, int t = XmlTag::Count, int ns = XMPPNamespace::Count)

findNextChild

[static]

Find an element's next child element

Parameters:
xmlElement
startStarting child
tOptional element tag as enumeration
nsOptional element namespace as enumeration

Returns: XmlElement pointer or 0 if not found

void  decodeError (XmlElement* xml, int ns = XMPPNamespace::Count, String* error = 0, String* text = 0)

decodeError

[static]

Find an error child of a given element and decode it

Parameters:
xmlThe element
nsExpected error condition namespace. If not set, defaults to stream error namespace if the element is a stream error or to stanza error namespace otherwise
errorOptional string to be filled with error tag
textOptional string to be filled with error text

void  decodeError (XmlElement* xml, String& error, String& text)

decodeError

[static]

Decode a stream error or stanza error

Parameters:
xmlThe element
errorThe error condition
textThe stanza's error or error text

void  encodeDateTimeSec (String& buf, unsigned int timeSec, unsigned int fractions = 0)

encodeDateTimeSec

[static]

Encode EPOCH time given in seconds to a date/time profile as defined in XEP-0082 and XML Schema Part 2: Datatypes Second Edition

Parameters:
bufDestination string
timeSecThe time to encode (in seconds)
fractionsOptional second fractions

unsigned int  decodeDateTimeSec (const String& time, unsigned int* fractions = 0)

decodeDateTimeSec

[static]

Decode a date/time profile as defined in XEP-0082 and XML Schema Part 2: Datatypes Second Edition to EPOCH time

Parameters:
timeThe date/time string
fractionsPointer to integer to be filled with second fractions, if present

Returns: The decoded time in seconds, -1 on error

unsigned int  decodeDateTimeSecXDelay (const String& time)

decodeDateTimeSecXDelay

[static]

Decode a date/time stamp as defined in XEP-0091 (jabber:x:delay)

Parameters:
timeThe date/time string

Returns: The decoded time in seconds, -1 on error

void  print (String& xmlStr, XmlChild& xml, bool verbose)

print

[static]

Print an XmlElement to a string

Parameters:
xmlStrThe destination string
xmlThe xml to print
verboseTrue to print XML data on multiple lines

void  toList (XmlElement& xml, NamedList& dest, const char* prefix)

toList

[static]

Put an element's name, text and attributes to a list of parameters

Parameters:
xmlThe element
destDestination list
prefixPrefix to add to parameters

bool  split (NamedList& dest, const char* src, const char sep, bool nameFirst)

split

[static]

Split a string at a delimiter character and fills a named list with its parts Skip empty parts

Parameters:
destThe destination NamedList
srcPointer to the string
sepThe delimiter
nameFirstTrue to add the parts as name and index as value. False to do the other way

int  decodeFlags (const String& src, const TokenDict* dict)

decodeFlags

[static]

Decode a comma separated list of flags and put them into an integer mask

Parameters:
srcSource string
dictDictionary containing flag names and values

Returns: The mask of found flags

void  buildFlags (String& dest, int src, const TokenDict* dict)

buildFlags

[static]

Encode a mask of flags to a comma separated list of names

Parameters:
destDestination string
srcSource mask
dictDictionary containing flag names and values

bool  addChidren (XmlElement* dest, ObjList& list)

addChidren

[static]

Add child elements from a list to a destination element

Parameters:
destDestination XmlElement
listA list containing XML elements

Returns: True if at least one child was added

XmlElement*  createEntityCaps (const String& hash, const char* node)

createEntityCaps

[static]

Create a 'c' entity capability element as defined in XEP 0115

Parameters:
hashThe 'ver' attribute
nodeThe 'node' attribute

Returns: XmlElement pointer or 0 on failure

XmlElement*  createEntityCapsGTalkV1 (const char* node = 0, bool muc = false)

createEntityCapsGTalkV1

[static]

Create a 'c' entity capability element as defined by GTalk

Parameters:
nodeOptional node attribute, defaults to GTalk's node
mucAdvertise MUC capability

Returns: A valid XmlElement pointer

XmlElement*  createPresence (const char* from, const char* to, Presence type = PresenceNone)

createPresence

[static]

Create an 'presence' element

Parameters:
fromThe 'from' attribute
toThe 'to' attribute
typePresence type as enumeration

Returns: A valid XmlElement pointer

XmlElement*  createMessage (const char* type, const char* from, const char* to, const char* id, const char* body)

createMessage

[static]

Create a 'message' element

Parameters:
typeMessage type string
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
bodyThe message body

Returns: A valid XmlElement pointer

inline XmlElement*  createMessage (MsgType type, const char* from, const char* to, const char* id, const char* body)

createMessage

[static]

Create a 'message' element

Parameters:
typeMessage type as enumeration
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
bodyThe message body

Returns: A valid XmlElement pointer

XmlElement*  createDialbackKey (const char* from, const char* to, const char* key)

createDialbackKey

[static]

Build a dialback 'db:result' xml element used to send a dialback key

Parameters:
fromThe sender
toThe recipient
keyThe dialback key

Returns: XmlElement pointer

XmlElement*  createDialbackResult (const char* from, const char* to, XMPPError::Type rsp = XMPPError::NoError)

createDialbackResult

[static]

Build a dialback 'db:result' xml element used to send a dialback key response

Parameters:
fromThe sender
toThe recipient
rspThe response as enumeration: set it to NoError if valid, NotAuthorized if invalid or any other error to send a db:result error type

Returns: XmlElement pointer

XmlElement*  createDialbackVerify (const char* from, const char* to, const char* id, const char* key)

createDialbackVerify

[static]

Build a dialback 'db:verify' xml element

Parameters:
fromThe sender
toThe recipient
idThe 'id' attribute (stream id)
keyThe dialback key

Returns: XmlElement pointer

XmlElement*  createDialbackVerifyRsp (const char* from, const char* to, const char* id, XMPPError::Type rsp = XMPPError::NoError)

createDialbackVerifyRsp

[static]

Build a dialback 'db:verify' response xml element

Parameters:
fromThe sender
toThe recipient
idThe 'id' attribute (stream id)
rspThe response as enumeration: set it to NoError if valid, NotAuthorized if invalid or any other error to send a db:verify error type

Returns: XmlElement pointer

int  decodeDbRsp (XmlElement* xml)

decodeDbRsp

[static]

Decode a dialback verify or result response element

Parameters:
xmlThe element

Returns: The response as enumeration: NoError if valid, NotAuthorized if invalid or any other error if set in the response

inline XmlElement*  createSubject (const char* subject)

createSubject

[static]

Build a 'subject' xml element

Parameters:
subjectElement text

Returns: XmlElement pointer

inline const String&  subject (XmlElement& xml)

subject

[static]

Get an element's subject (the text of the first 'subject' child)

Parameters:
xmlThe element

Returns: Element subject or an empty string

inline XmlElement*  createBody (const char* body, int ns = XMPPNamespace::Count)

createBody

[static]

Build a 'body' xml element

Parameters:
bodyElement text
nsOptional namespace

Returns: XmlElement pointer

const String&  body (XmlElement& xml, int ns = XMPPNamespace::Count)

body

[static]

Retrieve the text of an element's body child

Parameters:
xmlThe element
nsOptional body namespace to match (default: match parent's namespace)

Returns: Body or empty string

inline XmlElement*  createParameter (const char* name, const char* value, const char* tag = "parameter")

createParameter

[static]

Build a name/value parameter xml element

Parameters:
nameThe 'name' attribute
valueThe value parameter
tagOptional element tag (defaults to 'parameter')

Returns: XmlElement pointer

inline XmlElement*  createParameter (const NamedString& pair, const char* tag = "parameter")

createParameter

[static]

Build a name/value parameter xml element

Parameters:
pairThe name/value pair
tagOptional element tag (defaults to 'parameter')

Returns: XmlElement pointer

inline int  ns (const XmlElement& xml)

ns

[static]

Get an element's namespace

Parameters:
xmlThe element

Returns: The namespace integer value as XMPPNamespace value

inline int  tag (const XmlElement& xml)

tag

[static]

Get an XML tag enumeration value associated with an element's tag

Parameters:
xmlThe element to check

Returns: Xml tag as enumeration

inline bool  getTag (const XmlElement& xml, int& tag, int& ns)

getTag

[static]

Get an XML element's tag and namespace

Parameters:
xmlThe element to check
tagElement tag as enumeration
nsElement namespace as enumeration

Returns: True if data was succesfully retrieved

inline bool  isTag (const XmlElement& xml, int tag, int ns)

isTag

[static]

Check if an xml element has a given tag (without prefix) and namespace

Parameters:
xmlThe element to check
tagTag to check
nsNamespace to check

Returns: True if the element has the requested tag and namespace

inline bool  isUnprefTag (const XmlElement& xml, int tag)

isUnprefTag

[static]

Check if an xml element has a given tag (without prefix)

Parameters:
xmlThe element to check
tagTag to check

Returns: True if the element has the requested tag

inline bool  isStanza (const XmlElement& xml)

isStanza

[static]

Check if a given element is a stanza one ('iq', 'message' or 'presence')

Parameters:
xmlThe element to check

Returns: True if the element is a stanza

XmlElement*  getXml (GenObject* gen)

getXml

[static]

Retrieve an xml element from a NamedPointer. Release NamedPointer ownership if found

Parameters:
genThe object to be processed

Returns: XmlElement pointer or 0

XmlElement*  getXml (const String& data)

getXml

[static]

Parse a string to an XmlElement

Parameters:
dataXML data to parse

Returns: XmlElement pointer or 0 if the string is an invalid xml or contains more then one element

XmlElement*  getXml (NamedList& list, const char* param = "xml", const char* extra = "data")

getXml

[static]

Retrieve an xml element from a list parameter. Clear the given parameter from list if an XmlElement is found Try to build (parse) from an extra parameter if not found

Parameters:
listThe list of parameters
paramThe name of the parameter with the xml element
extraOptional parameter containing xml string data

Returns: XmlElement pointer or 0

XmlElement*  getPresenceXml (NamedList& list, const char* param = "xml", const char* extra = "data", Presence type = PresenceNone, bool build = true)

getPresenceXml

[static]

Retrieve a presence xml element from a list parameter. Clear the given parameter from list if an XmlElement is found. Try to build (parse) from an extra parameter if not found. Build a presence stanza from parameters if an element is not found

Parameters:
listThe list of parameters
paramThe name of the parameter with the xml element
extraOptional parameter containing xml string data
typePresence type to build
buildTrue to build a message stanza if an element is not found

Returns: XmlElement pointer or 0

XmlElement*  getChatXml (NamedList& list, const char* param = "xml", const char* extra = "data", bool build = true)

getChatXml

[static]

Retrieve a chat (message) xml element from a list parameter. Clear the given parameter from list if an XmlElement is found. Try to build (parse) from an extra parameter if not found. Build a message stanza from parameters if an element is not found

Parameters:
listThe list of parameters
paramThe name of the parameter with the xml element
extraOptional parameter containing xml string data
buildTrue to build a message stanza if an element is not found

Returns: XmlElement pointer or 0

int  cmpBytes (const String& s1, const String& s2)

cmpBytes

[static]

Byte compare 2 strings.

Parameters:
s1The first string
s2The second string

Returns: Return -1 if s1 < s2, 1 if s1 > s2 or 0 if the 2 strings are equal

inline Presence  presenceType (const char* text)

presenceType

[static]

Get the type of a 'presence' stanza as enumeration

Parameters:
textThe text to check

Returns: Presence type as enumeration

inline const char*  presenceText (Presence presence)

presenceText

[static]

Get the text from a presence type

Parameters:
presenceThe presence type

Returns: The associated text or 0

inline MsgType  msgType (const char* text)

msgType

[static]

Get the type of a 'message' stanza

Parameters:
textThe text to check

Returns: Message type as enumeration

inline const char*  msgText (MsgType msg)

msgText

[static]

Get the text from a message type

Parameters:
msgThe message type

Returns: The associated text or 0

inline IqType  iqType (const char* text)

iqType

[static]

Get the type of an 'iq' stanza as enumeration

Parameters:
textThe text to check

Returns: Iq type as enumeration

inline int  authMeth (const char* text, int defVal = AuthNone)

authMeth

[static]

Get the authentication method associated with a given text

Parameters:
textThe text to check
defValDefault value to return if not found

Returns: Authentication method

static XMPPNamespace s_ns

s_ns

static XMPPError s_error

s_error

static XmlTag s_tag

s_tag

static const TokenDict s_presence[]

s_presence[]

static const TokenDict s_msg[]

s_msg[]

static const TokenDict s_iq[]

s_iq[]

static const TokenDict s_commandAction[]

s_commandAction[]

static const TokenDict s_commandStatus[]

s_commandStatus[]

static const TokenDict s_authMeth[]

s_authMeth[]


Generated by: paulc on bussard on Tue Apr 12 17:15:21 2011, using kdoc 2.0a54.