Yate
XMPPUtils Class Reference

General XMPP utilities. More...

#include <xmpputils.h>

Public Types

enum  Presence {
  Probe , Subscribe , Subscribed , Unavailable ,
  Unsubscribe , Unsubscribed , PresenceError , PresenceNone
}
 
enum  MsgType {
  Chat , GroupChat , HeadLine , Normal ,
  MsgError
}
 
enum  IqType {
  IqSet , IqGet , IqResult , IqError ,
  IqCount
}
 
enum  CommandAction {
  CommExecute , CommCancel , CommPrev , CommNext ,
  CommComplete
}
 
enum  CommandStatus { CommExecuting , CommCompleted , CommCancelled }
 
enum  AuthMethod {
  AuthNone = 0x00 , AuthSHA1 = 0x01 , AuthMD5 = 0x02 , AuthPlain = 0x04 ,
  AuthDialback = 0x08
}
 

Static Public Member Functions

static int findTag (const String &tag, int *tags)
 
static bool isResponse (const XmlElement &xml)
 
static void getJIDTo (const NamedList &params, JabberID &jid)
 
static void getJIDFrom (const NamedList &params, JabberID &jid)
 
static XmlElement * createElement (const char *name, const char *text=0, const String &ns=String::empty())
 
static XmlElement * createElement (int type, const char *text=0)
 
static XmlElement * createElement (const char *name, int ns, const char *text=0)
 
static XmlElement * createElement (int type, int ns, const char *text=0)
 
static XmlElement * createElement (const XmlElement &src, bool response, bool result)
 
static XmlElement * createElementAttr (int tag, const String &attrName, const char *attrValue, int ns=XMPPNamespace::Count)
 
static XmlElement * createIq (IqType type, const char *from=0, const char *to=0, const char *id=0)
 
static XmlElement * createIqResult (const char *from, const char *to, const char *id, XmlElement *child=0)
 
static XmlElement * createIqError (const char *from, const char *to, XmlElement *&xml, int type, int error, const char *text=0)
 
static XmlElement * createPing (const char *id=0, const char *from=0, const char *to=0)
 
static XmlElement * createVCard (bool get, const char *from, const char *to, const char *id)
 
static XmlElement * createCommand (CommandAction action, const char *node, const char *sessionId=0)
 
static XmlElement * createIqDisco (bool info, bool req, const char *from, const char *to, const char *id, const char *node=0, const char *cap=0)
 
static XmlElement * createIqVersionRes (const char *from, const char *to, const char *id, const char *name, const char *version, const char *os=0)
 
static XmlElement * createError (int type, int error, const char *text=0)
 
static XmlElement * createError (XmlElement *xml, int type, int error, const char *text=0)
 
static XmlElement * createStreamError (int error, const char *text=0, const char *content=0)
 
static XmlElement * createRegisterQuery (IqType type, const char *from, const char *to, const char *id, XmlElement *child1=0, XmlElement *child2=0, XmlElement *child3=0)
 
static XmlElement * createIqAuthGet (const char *id)
 
static XmlElement * createIqAuthSet (const char *id, const char *username, const char *resource, const char *authStr, bool digest)
 
static XmlElement * createIqAuthOffer (const char *id, bool digest=true, bool plain=false)
 
static XmlElement * createRegisterQuery (const char *from, const char *to, const char *id, const char *username, const char *password)
 
static XmlElement * createFailure (XMPPNamespace::Type ns, XMPPError::Type error=XMPPError::NoError)
 
static XmlElement * createXOobUrl (const char *url, const char *desc=0)
 
static XmlElement * createDelay (unsigned int timeSec, const char *from=0, unsigned int fractions=0, const char *text=0)
 
static XmlElement * createFileNsTransfer (const char *name=0)
 
static XmlElement * createHash (const char *name, const char *value)
 
static void decodeHash (XmlElement &xml, const char *&name, const char *&value)
 
static XmlElement * createFileInfoShareMatch (XmlElement *child=0)
 
static XmlElement * createRSM (const NamedList &params, const String &prefix="rsm_")
 
static void addRSM (XmlElement *rsm, NamedList &params, const String &prefix="rsm_")
 
static bool remove (XmlElement &xml)
 
static bool required (XmlElement &xml)
 
static int priority (XmlElement &xml, int defVal=0)
 
static void setPriority (XmlElement &xml, const char *prio)
 
static int xmlns (XmlElement &xml)
 
static bool hasDefaultXmlns (const XmlElement &xml, int ns)
 
static bool hasXmlns (const XmlElement &xml, int ns)
 
static bool setXmlns (XmlElement &xml, const String &name=String::empty(), bool addAttr=false, int ns=XMPPNamespace::Count)
 
static bool setStreamXmlns (XmlElement &xml, bool addAttr=true)
 
static bool setDbXmlns (XmlElement &xml)
 
static XmlElement * findFirstChild (const XmlElement &xml, int t=XmlTag::Count, int ns=XMPPNamespace::Count)
 
static XmlElement * findNextChild (const XmlElement &xml, XmlElement *start, int t=XmlTag::Count, int ns=XMPPNamespace::Count)
 
static const StringchildText (XmlElement &xml, int tag, int ns=XMPPNamespace::Count)
 
static int childTextInt (XmlElement &xml, int tag, int ns=XMPPNamespace::Count, int defVal=0, int base=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true)
 
static void decodeError (XmlElement *xml, int ns=XMPPNamespace::Count, String *error=0, String *text=0, String *content=0)
 
static void decodeError (XmlElement *xml, String &error, String &text)
 
static void encodeDateTimeSec (String &buf, unsigned int timeSec, unsigned int fractions=0)
 
static unsigned int decodeDateTimeSec (const String &time, unsigned int *fractions=0)
 
static unsigned int decodeDateTimeSecXDelay (const String &time)
 
static void print (String &xmlStr, XmlChild &xml, bool verbose)
 
static void toList (XmlElement &xml, NamedList &dest, const char *prefix)
 
static bool split (NamedList &dest, const char *src, const char sep, bool nameFirst)
 
static int decodeFlags (const String &src, const TokenDict *dict)
 
static void buildFlags (String &dest, int src, const TokenDict *dict)
 
static bool addChidren (XmlElement *dest, ObjList &list)
 
static XmlElement * createEntityCaps (const String &hash, const char *node)
 
static XmlElement * createEntityCapsGTalkV1 (const char *node=0, bool muc=false)
 
static XmlElement * createPresence (const char *from, const char *to, Presence type=PresenceNone)
 
static XmlElement * createMessage (const char *type, const char *from, const char *to, const char *id, const char *body)
 
static XmlElement * createMessage (MsgType type, const char *from, const char *to, const char *id, const char *body)
 
static XmlElement * createDialbackKey (const char *from, const char *to, const char *key)
 
static XmlElement * createDialbackResult (const char *from, const char *to, XMPPError::Type rsp=XMPPError::NoError)
 
static XmlElement * createDialbackVerify (const char *from, const char *to, const char *id, const char *key)
 
static XmlElement * createDialbackVerifyRsp (const char *from, const char *to, const char *id, XMPPError::Type rsp=XMPPError::NoError)
 
static int decodeDbRsp (XmlElement *xml)
 
static XmlElement * createSubject (const char *subject)
 
static const Stringsubject (XmlElement &xml)
 
static XmlElement * createBody (const char *body, int ns=XMPPNamespace::Count)
 
static const Stringbody (XmlElement &xml, int ns=XMPPNamespace::Count)
 
static XmlElement * createParameter (const char *name, const char *value, const char *tag="parameter")
 
static XmlElement * createParameter (const NamedString &pair, const char *tag="parameter")
 
static int ns (const XmlElement &xml)
 
static int tag (const XmlElement &xml)
 
static bool getTag (const XmlElement &xml, int &tag, int &ns)
 
static bool isTag (const XmlElement &xml, int tag, int ns)
 
static bool isUnprefTag (const XmlElement &xml, int tag)
 
static bool isStanza (const XmlElement &xml)
 
static XmlElement * getXml (GenObject *gen, bool takeOwnerShip=true)
 
static XmlElement * getXml (const String &data)
 
static XmlElement * getXml (NamedList &list, const char *param="xml", const char *extra="data")
 
static XmlElement * getPresenceXml (NamedList &list, const char *param="xml", const char *extra="data", Presence type=PresenceNone, bool build=true)
 
static XmlElement * getChatXml (NamedList &list, const char *param="xml", const char *extra="data", bool build=true)
 
static int cmpBytes (const String &s1, const String &s2)
 
static Presence presenceType (const char *text)
 
static const char * presenceText (Presence presence)
 
static MsgType msgType (const char *text)
 
static const char * msgText (MsgType msg)
 
static IqType iqType (const char *text)
 
static int authMeth (const char *text, int defVal=AuthNone)
 

Static Public Attributes

static XMPPNamespace s_ns
 
static XMPPError s_error
 
static XmlTag s_tag
 
static const TokenDict s_presence []
 
static const TokenDict s_msg []
 
static const TokenDict s_iq []
 
static const TokenDict s_commandAction []
 
static const TokenDict s_commandStatus []
 
static const TokenDict s_authMeth []
 

Detailed Description

General XMPP utilities.

This class is a general XMPP utilities

Member Enumeration Documentation

◆ AuthMethod

enum AuthMethod

Authentication methods

◆ CommandAction

Command action enumeration

◆ CommandStatus

Command status enumeration

◆ IqType

enum IqType

Iq type enumeration

◆ MsgType

enum MsgType

Message type enumeration

◆ Presence

enum Presence

Presence type enumeration

Member Function Documentation

◆ addChidren()

static bool addChidren ( XmlElement * dest,
ObjList & list )
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

◆ addRSM()

static void addRSM ( XmlElement * rsm,
NamedList & params,
const String & prefix = "rsm_" )
static

Add Result Set Management (XEP-0059) set element child data to a parameter list

Parameters
rsmThe element in RSM namespace
paramsList of parameters to add the RSM data
prefixPrefix for RSM parameters

◆ authMeth()

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

Get the authentication method associated with a given text

Parameters
textThe text to check
defValDefault value to return if not found
Returns
Authentication method

References s_authMeth.

◆ body()

static const String & body ( XmlElement & xml,
int ns = XMPPNamespace::Count )
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

References ns().

Referenced by createBody(), createMessage(), and createMessage().

◆ buildFlags()

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

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

Parameters
destDestination string
srcSource mask
dictDictionary containing flag names and values

◆ childText()

static const String * childText ( XmlElement & xml,
int tag,
int ns = XMPPNamespace::Count )
inlinestatic

Retrieve a child's text

Parameters
xmlThe xml
tagChild tag
nsOptional child namespace
Returns
Pointer to child's text, 0 if the child was not found

References findFirstChild(), ns(), and tag().

Referenced by childTextInt().

◆ childTextInt()

static int childTextInt ( XmlElement & xml,
int tag,
int ns = XMPPNamespace::Count,
int defVal = 0,
int base = 0,
int minvalue = INT_MIN,
int maxvalue = INT_MAX,
bool clamp = true )
inlinestatic

Retrieve a child's text converted to integer

Parameters
xmlThe xml
tagChild tag
nsOptional child namespace
defValDefault to return if not found or the string is not a number
baseNumeration base, 0 to autodetect
minvalueMinimum value allowed
maxvalueMaximum value allowed
clampControl the out of bound values: true to adjust to the nearest bound, false to return the default value
Returns
Integer value

References childText(), ns(), tag(), and String::toInteger().

◆ cmpBytes()

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

Byte compare 2 strings.

Parameters
s1The first string
s2The second string
Returns
Return less then 0 if s1 < s2, greater then 0 if s1 > s2 or 0 if the 2 strings are equal

◆ createBody()

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

Build a 'body' xml element

Parameters
bodyElement text
nsOptional namespace
Returns
XmlElement pointer

References body(), createElement(), and ns().

◆ createCommand()

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

Create a 'command' element

Parameters
actionThe command action
nodeThe command
sessionIdOptional session ID for the command
Returns
A valid XmlElement pointer

◆ createDelay()

static XmlElement * createDelay ( unsigned int timeSec,
const char * from = 0,
unsigned int fractions = 0,
const char * text = 0 )
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

◆ createDialbackKey()

static XmlElement * createDialbackKey ( const char * from,
const char * to,
const char * key )
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

◆ createDialbackResult()

static XmlElement * createDialbackResult ( const char * from,
const char * to,
XMPPError::Type rsp = XMPPError::NoError )
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

◆ createDialbackVerify()

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

Build a dialback 'db:verify' xml element

Parameters
fromThe sender
toThe recipient
idThe 'id' attribute (stream id)
keyThe dialback key
Returns
XmlElement pointer

◆ createDialbackVerifyRsp()

static XmlElement * createDialbackVerifyRsp ( const char * from,
const char * to,
const char * id,
XMPPError::Type rsp = XMPPError::NoError )
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

◆ createElement() [1/5]

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

Create an XML element

Parameters
nameElement's name
textOptional text for the element
nsOptional element namespace
Returns
A valid XmlElement pointer

References String::empty(), and ns().

Referenced by createBody(), createElement(), createElement(), createElement(), createElementAttr(), createFailure(), createFileInfoShareMatch(), createIqAuthGet(), createRegisterQuery(), createSubject(), createXOobUrl(), and setPriority().

◆ createElement() [2/5]

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

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

References createElement(), String::empty(), ns(), and setXmlns().

◆ createElement() [3/5]

static XmlElement * createElement ( const XmlElement & src,
bool response,
bool result )
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

◆ createElement() [4/5]

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

Create an XML element

Parameters
typeElement's type
textOptional text for the element
Returns
A valid XmlElement pointer

References createElement(), and s_tag.

◆ createElement() [5/5]

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

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

References createElement(), ns(), and s_tag.

◆ createElementAttr()

static XmlElement * createElementAttr ( int tag,
const String & attrName,
const char * attrValue,
int ns = XMPPNamespace::Count )
inlinestatic

Create an element with an attribute

Parameters
tagElement tag
attrNameAttribute name
attrValueAttribute value
nsOptional 'xmlns' attribute as enumeration
Returns
A valid XmlElement pointer

References createElement(), ns(), and tag().

◆ createEntityCaps()

static XmlElement * createEntityCaps ( const String & hash,
const char * node )
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

◆ createEntityCapsGTalkV1()

static XmlElement * createEntityCapsGTalkV1 ( const char * node = 0,
bool muc = false )
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

◆ createError() [1/2]

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

Create a 'error' element

Parameters
typeError type
errorThe error
textOptional text to add to the error element
Returns
A valid XmlElement pointer

◆ createError() [2/2]

static XmlElement * createError ( XmlElement * xml,
int type,
int error,
const char * text = 0 )
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

◆ createFailure()

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

Create a failure element

Parameters
nsElement namespace
errorOptional error
Returns
XmlElement pointer

References createElement(), ns(), and s_error.

◆ createFileInfoShareMatch()

static XmlElement * createFileInfoShareMatch ( XmlElement * child = 0)
inlinestatic

Create a 'match' element in FileInfoShare namespace

Parameters
childOptional child
Returns
XmlElement pointer

References createElement().

◆ createFileNsTransfer()

static XmlElement * createFileNsTransfer ( const char * name = 0)
static

Create a 'file' element in file transfer namespace, add the name child if not empty

Parameters
nameOptional file name
Returns
XmlElement pointer

◆ createHash()

static XmlElement * createHash ( const char * name,
const char * value )
static

Create a 'hash' element as defined in XEP-0300

Parameters
nameHash name
valueHash value
Returns
XmlElement pointer

◆ createIq()

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

Create an 'iq' element

Parameters
typeIq type as enumeration
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
Returns
A valid XmlElement pointer

Referenced by createIqAuthGet(), and createIqResult().

◆ createIqAuthGet()

static XmlElement * createIqAuthGet ( const char * id)
inlinestatic

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

Parameters
idElement 'id' attribute
Returns
A valid XmlElement pointer

References createElement(), and createIq().

◆ createIqAuthOffer()

static XmlElement * createIqAuthOffer ( const char * id,
bool digest = true,
bool plain = false )
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

◆ createIqAuthSet()

static XmlElement * createIqAuthSet ( const char * id,
const char * username,
const char * resource,
const char * authStr,
bool digest )
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

◆ createIqDisco()

static XmlElement * createIqDisco ( bool info,
bool req,
const char * from,
const char * to,
const char * id,
const char * node = 0,
const char * cap = 0 )
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

◆ createIqError()

static XmlElement * createIqError ( const char * from,
const char * to,
XmlElement *& xml,
int type,
int error,
const char * text = 0 )
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

◆ createIqResult()

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

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

References createIq().

◆ createIqVersionRes()

static XmlElement * createIqVersionRes ( const char * from,
const char * to,
const char * id,
const char * name,
const char * version,
const char * os = 0 )
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

◆ createMessage() [1/2]

static XmlElement * createMessage ( const char * type,
const char * from,
const char * to,
const char * id,
const char * body )
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

References body().

Referenced by createMessage().

◆ createMessage() [2/2]

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

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

References body(), createMessage(), and msgText().

◆ createParameter() [1/2]

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

Build a name/value parameter xml element

Parameters
nameThe 'name' attribute
valueThe value parameter
tagOptional element tag (defaults to 'parameter')
Returns
XmlElement pointer

References tag().

Referenced by createParameter().

◆ createParameter() [2/2]

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

Build a name/value parameter xml element

Parameters
pairThe name/value pair
tagOptional element tag (defaults to 'parameter')
Returns
XmlElement pointer

References createParameter(), NamedString::name(), and tag().

◆ createPing()

static XmlElement * createPing ( const char * id = 0,
const char * from = 0,
const char * to = 0 )
static

Create an 'iq' element with a ping child

Parameters
idThe 'id' attribute
fromThe 'from' attribute
toThe 'to' attribute
Returns
A valid XmlElement pointer

◆ createPresence()

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

Create an 'presence' element

Parameters
fromThe 'from' attribute
toThe 'to' attribute
typePresence type as enumeration
Returns
A valid XmlElement pointer

◆ createRegisterQuery() [1/2]

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

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

References createElement(), and createRegisterQuery().

◆ createRegisterQuery() [2/2]

static XmlElement * createRegisterQuery ( IqType type,
const char * from,
const char * to,
const char * id,
XmlElement * child1 = 0,
XmlElement * child2 = 0,
XmlElement * child3 = 0 )
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

Referenced by createRegisterQuery().

◆ createRSM()

static XmlElement * createRSM ( const NamedList & params,
const String & prefix = "rsm_" )
static

Build a Result Set Management (XEP-0059) set element from a parameter list

Parameters
paramsList of parameters containing the RSM
prefixPrefix for RSM parameters
Returns
XmlElement pointer or 0

◆ createStreamError()

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

Create a 'stream:error' element

Parameters
errorThe XMPP defined condition
textOptional text to add to the error
contentOptional error condition element text
Returns
A valid XmlElement pointer

◆ createSubject()

static XmlElement * createSubject ( const char * subject)
inlinestatic

Build a 'subject' xml element

Parameters
subjectElement text
Returns
XmlElement pointer

References createElement(), and subject().

◆ createVCard()

static XmlElement * createVCard ( bool get,
const char * from,
const char * to,
const char * id )
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

◆ createXOobUrl()

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

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

Parameters
urlThe URL
descOptional description
Returns
XmlElement pointer

References createElement().

◆ decodeDateTimeSec()

static unsigned int decodeDateTimeSec ( const String & time,
unsigned int * fractions = 0 )
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

◆ decodeDateTimeSecXDelay()

static unsigned int decodeDateTimeSecXDelay ( const String & time)
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

◆ decodeDbRsp()

static int decodeDbRsp ( XmlElement * xml)
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

◆ decodeError() [1/2]

static void decodeError ( XmlElement * xml,
int ns = XMPPNamespace::Count,
String * error = 0,
String * text = 0,
String * content = 0 )
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
contentOptional string to be filled with error condition element text

References ns().

◆ decodeError() [2/2]

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

Decode a stream error or stanza error

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

◆ decodeFlags()

static int decodeFlags ( const String & src,
const TokenDict * dict )
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

Referenced by XMPPDirVal::replace().

◆ decodeHash()

static void decodeHash ( XmlElement & xml,
const char *& name,
const char *& value )
static

Decode a 'hash' element as defined in XEP-0300

Parameters
xmlXML element to handle
nameHash name
valueHash value

◆ encodeDateTimeSec()

static void encodeDateTimeSec ( String & buf,
unsigned int timeSec,
unsigned int fractions = 0 )
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

◆ findFirstChild()

static XmlElement * findFirstChild ( const XmlElement & xml,
int t = XmlTag::Count,
int ns = XMPPNamespace::Count )
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

References ns().

Referenced by childText(), remove(), required(), and subject().

◆ findNextChild()

static XmlElement * findNextChild ( const XmlElement & xml,
XmlElement * start,
int t = XmlTag::Count,
int ns = XMPPNamespace::Count )
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

References ns().

◆ findTag()

static int findTag ( const String & tag,
int * tags )
static

Find an xml tag in an array terminated with XmlTag::Count

Parameters
tagTag to find
tagsTags list
Returns
XmlTag value, XmlTag::Count if not found

References tag().

◆ getChatXml()

static XmlElement * getChatXml ( NamedList & list,
const char * param = "xml",
const char * extra = "data",
bool build = true )
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

◆ getJIDFrom()

static void getJIDFrom ( const NamedList & params,
JabberID & jid )
inlinestatic

Retrieve a JID from 'from' and 'from_instance' parameters

Parameters
paramsParameter list
jidDestination to be set

References JabberID::resource().

◆ getJIDTo()

static void getJIDTo ( const NamedList & params,
JabberID & jid )
inlinestatic

Retrieve a JID from 'to' and 'to_instance' parameters

Parameters
paramsParameter list
jidDestination to be set

References JabberID::resource().

◆ getPresenceXml()

static XmlElement * getPresenceXml ( NamedList & list,
const char * param = "xml",
const char * extra = "data",
Presence type = PresenceNone,
bool build = true )
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

◆ getTag()

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

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

References ns(), s_ns, s_tag, and tag().

Referenced by isStanza(), and isTag().

◆ getXml() [1/3]

static XmlElement * getXml ( const String & data)
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

◆ getXml() [2/3]

static XmlElement * getXml ( GenObject * gen,
bool takeOwnerShip = true )
static

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

Parameters
genThe object to be processed
takeOwnerShipTake ownership (defaults to true)
Returns
XmlElement pointer or 0

◆ getXml() [3/3]

static XmlElement * getXml ( NamedList & list,
const char * param = "xml",
const char * extra = "data" )
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

◆ hasDefaultXmlns()

static bool hasDefaultXmlns ( const XmlElement & xml,
int ns )
inlinestatic

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

References ns(), and s_ns.

◆ hasXmlns()

static bool hasXmlns ( const XmlElement & xml,
int ns )
inlinestatic

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

References ns(), and s_ns.

◆ iqType()

static IqType iqType ( const char * text)
inlinestatic

Get the type of an 'iq' stanza as enumeration

Parameters
textThe text to check
Returns
Iq type as enumeration

References s_iq.

◆ isResponse()

static bool isResponse ( const XmlElement & xml)
inlinestatic

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

Parameters
xmlThe element to check
Returns
True if the element is a response one

◆ isStanza()

static bool isStanza ( const XmlElement & xml)
inlinestatic

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

References getTag().

◆ isTag()

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

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

References getTag(), ns(), and tag().

◆ isUnprefTag()

static bool isUnprefTag ( const XmlElement & xml,
int tag )
inlinestatic

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

References s_tag, and tag().

◆ msgText()

static const char * msgText ( MsgType msg)
inlinestatic

Get the text from a message type

Parameters
msgThe message type
Returns
The associated text or 0

References s_msg.

Referenced by createMessage().

◆ msgType()

static MsgType msgType ( const char * text)
inlinestatic

Get the type of a 'message' stanza

Parameters
textThe text to check
Returns
Message type as enumeration

References s_msg.

◆ ns()

static int ns ( const XmlElement & xml)
inlinestatic

Get an element's namespace

Parameters
xmlThe element
Returns
The namespace integer value as XMPPNamespace value

References s_ns, and xmlns().

Referenced by body(), childText(), childTextInt(), createBody(), createElement(), createElement(), createElement(), createElementAttr(), createFailure(), decodeError(), findFirstChild(), findNextChild(), getTag(), hasDefaultXmlns(), hasXmlns(), isTag(), and setXmlns().

◆ presenceText()

static const char * presenceText ( Presence presence)
inlinestatic

Get the text from a presence type

Parameters
presenceThe presence type
Returns
The associated text or 0

References s_presence.

◆ presenceType()

static Presence presenceType ( const char * text)
inlinestatic

Get the type of a 'presence' stanza as enumeration

Parameters
textThe text to check
Returns
Presence type as enumeration

References s_presence.

◆ print()

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

Print an XmlElement to a string

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

◆ priority()

static int priority ( XmlElement & xml,
int defVal = 0 )
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

◆ remove()

static bool remove ( XmlElement & xml)
inlinestatic

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

References findFirstChild().

◆ required()

static bool required ( XmlElement & xml)
inlinestatic

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

References findFirstChild().

◆ setDbXmlns()

static bool setDbXmlns ( XmlElement & xml)
inlinestatic

Set the 'db' namespace to an element

Parameters
xmlElement
Returns
True on success

References setXmlns().

◆ setPriority()

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

Add a 'priority' child to an element

Parameters
xmlThe element to set
prioPriority text

References createElement().

◆ setStreamXmlns()

static bool setStreamXmlns ( XmlElement & xml,
bool addAttr = true )
inlinestatic

Set the 'stream' namespace to an element

Parameters
xmlElement
addAttrTrue to add the xmlns attribute
Returns
True on success

References setXmlns().

◆ setXmlns()

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

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

References String::empty(), ns(), and s_ns.

Referenced by createElement(), setDbXmlns(), and setStreamXmlns().

◆ split()

static bool split ( NamedList & dest,
const char * src,
const char sep,
bool nameFirst )
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

◆ subject()

static const String & subject ( XmlElement & xml)
inlinestatic

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

Parameters
xmlThe element
Returns
Element subject or an empty string

References String::empty(), and findFirstChild().

Referenced by createSubject().

◆ tag()

static int tag ( const XmlElement & xml)
inlinestatic

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

Parameters
xmlThe element to check
Returns
Xml tag as enumeration

References s_tag.

Referenced by childText(), childTextInt(), createElementAttr(), createParameter(), createParameter(), findTag(), getTag(), isTag(), and isUnprefTag().

◆ toList()

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

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

Parameters
xmlThe element
destDestination list
prefixPrefix to add to parameters

◆ xmlns()

static int xmlns ( XmlElement & xml)
inlinestatic

Get an element's namespace

Parameters
xmlElement
Returns
Element namespace as enumeration

References s_ns.

Referenced by ns().

Member Data Documentation

◆ s_authMeth

const TokenDict s_authMeth[]
static

Authentication methods names

Referenced by authMeth().

◆ s_commandAction

const TokenDict s_commandAction[]
static

Keep the command actions

◆ s_commandStatus

const TokenDict s_commandStatus[]
static

Keep the command status

◆ s_error

XMPPError s_error
static

Errors

Referenced by createFailure().

◆ s_iq

const TokenDict s_iq[]
static

Keep the types of 'iq' stanzas

Referenced by iqType().

◆ s_msg

const TokenDict s_msg[]
static

Keep the types of 'message' stanzas

Referenced by msgText(), and msgType().

◆ s_ns

XMPPNamespace s_ns
static

Namespaces

Referenced by getTag(), hasDefaultXmlns(), hasXmlns(), ns(), setXmlns(), and xmlns().

◆ s_presence

const TokenDict s_presence[]
static

Keep the types of 'presence' stanzas

Referenced by presenceText(), and presenceType().

◆ s_tag

XmlTag s_tag
static

XML tags

Referenced by createElement(), createElement(), getTag(), isUnprefTag(), and tag().


The documentation for this class was generated from the following file: