|
|
Base class for all Jabber streams. Basic stream data processing: send/receive XML elements, keep stream state, generate events
enum Type { c2s = 0, s2s, comp, cluster, TypeCount } | Type |
Stream type enumeration
enum State { Idle = 0, Connecting, WaitStart, Starting, Features, WaitTlsRsp, Securing, Auth, Challenge, Compressing, Register, Running, Destroy, } | State |
Stream state enumeration
enum Flags { NoAutoRestart = 0x00000001, TlsRequired = 0x00000002, AllowPlainAuth = 0x00000004, DialbackOnly = 0x00000008, RegisterUser = 0x00000010, Compress = 0x00000020, InError = 0x00000080, RosterRequested = 0x00000100, AvailableResource = 0x00000200, PositivePriority = 0x00000400, SetCompressed = 0x00010000, StreamSecured = 0x00020000, StreamTls = 0x00040000, StreamAuthenticated = 0x00080000, StreamRemoteVer1 = 0x00100000, StreamLocalVer1 = 0x00200000, StreamWaitBindRsp = 0x01000000, StreamWaitSessRsp = 0x02000000, StreamWaitChallenge = 0x04000000, StreamWaitChgRsp = 0x08000000, StreamRfc3920Chg = 0x10000000, StreamCompressed = 0x20000000, StreamCanCompress = 0x40000000, StreamFlags = 0x000000ff, InternalFlags = 0xffff0000, } | Flags |
Stream behaviour options
~JBStream ()
| ~JBStream |
[virtual]
Destructor. Gracefully close the stream and the socket
inline int type ()
| type |
[const]
Get the type of this stream. See the protocol enumeration of the engine
Returns: The type of this stream
inline int xmlns ()
| xmlns |
[const]
Retrieve this stream's default namespace
Returns: The stream default namespace
inline State state ()
| state |
[const]
Get the stream state
Returns: The stream state as enumeration.
inline bool incoming ()
| incoming |
[const]
Get the stream direction
Returns: True if the stream is an incoming one
inline bool outgoing ()
| outgoing |
[const]
Get the stream direction
Returns: True if the stream is an outgoing one
inline JBEngine* engine ()
| engine |
[const]
Get the stream's owner
Returns: Pointer to the engine owning this stream
inline const char* name ()
| name |
[const]
Get the stream's name
Returns: The stream's name
inline const String& id ()
| id |
[const]
Get the stream id
Returns: The stream id
inline bool isId (const String& str)
| isId |
Check if the stream id equals a given string. This method is thread safe
Parameters:
str | The string to check |
Returns: True if the given string equals this stream's id
inline const JabberID& local ()
| local |
[const]
Get the JID of the local side of this stream
Returns: The JID of the local side of this stream
inline void local (JabberID& jid)
| local |
Get the JID of the local side of this stream. This method is thread safe
Parameters:
jid | The JID to be filled with the local side of this stream |
inline void setLocal (const char* jid)
| setLocal |
Set the local party's JID
Parameters:
jid | Local party's jid to set |
inline const JabberID& remote ()
| remote |
[const]
Get the JID of the remote side of this stream
Returns: The JID of the remote side of this stream
inline void remote (JabberID& jid)
| remote |
Get the JID of the remote side of this stream. This method is thread safe
Parameters:
jid | The JID to be filled with the remote side of this stream |
inline bool remoteAddr (SocketAddr& addr)
| remoteAddr |
Get the remote party's address This method is thread safe
Parameters:
addr | The socket address to be filled with remote party's address |
Returns: True on success
inline bool localAddr (SocketAddr& addr)
| localAddr |
Get the local address This method is thread safe
Parameters:
addr | The socket address to be filled with local address |
Returns: True on success
inline int flags ()
| flags |
[const]
Get the stream flags
Returns: Stream flags
inline bool flag (int mask)
| flag |
[const]
Check if a given option (or option mask) is set
Parameters:
mask | The flag(s) to check |
Returns: True if set
inline void setTlsRequired (bool set)
| setTlsRequired |
Set or reset the TLS required flag This method is not thread safe
Parameters:
set | True to set, false to reset the flag |
void connectAddr (String& addr, int& port, String& localip, int& stat,
ObjList& srvs)
| connectAddr |
[const]
Retrieve connection address(es), port and status This method is not thread safe
Parameters:
addr | The remote ip |
port | The remote port |
localip | Local ip to bind |
stat | Current connect status |
srvs | List to copy stream SRV records |
void setRosterRequested (bool ok)
| setRosterRequested |
Set/reset RosterRequested flag This method is thread safe
Parameters:
ok | True to set, false to reset it |
bool setAvailableResource (bool ok, bool positive = true)
| setAvailableResource |
Set/reset AvailableResource/PositivePriority flags This method is thread safe
Parameters:
ok | True to set, false to reset it |
positive | True if an available resource has positive priority |
Returns: True if changed
bool readSocket (char* buf, unsigned int len)
| readSocket |
Read data from socket. Send it to the parser. Terminate the stream on socket or parser error
Parameters:
buf | Destination buffer |
len | Buffer length (must be greater then 1) |
Returns: True if data was received
JBClientStream* clientStream ()
| clientStream |
[virtual]
Get a client stream from this one
Returns: JBClientStream pointer or 0
JBServerStream* serverStream ()
| serverStream |
[virtual]
Get a server stream from this one
Returns: JBServerStream pointer or 0
JBClusterStream* clusterStream ()
| clusterStream |
[virtual]
Get a cluster stream from this one
Returns: JBClusterStream pointer
JBEvent* getEvent (u_int64_t time = Time::msecNow())
| getEvent |
Stream state processor. This method is thread safe
Parameters:
time | Current time |
Returns: JBEvent pointer or 0
bool sendStanza (XmlElement*& xml)
| sendStanza |
Send a stanza ('iq', 'message' or 'presence') or dialback elements in Running state. This method is thread safe
Parameters:
xml | Element to send (will be consumed and zeroed) |
Returns: True on success
bool sendStreamXml (State newState, XmlElement* first, XmlElement* second = 0,
XmlElement* third = 0)
| sendStreamXml |
Send stream related XML when negotiating the stream or some other stanza in non Running state All elements will be consumed This method is thread safe
Parameters:
newState | The new stream state to set on success |
first | The first element to send |
second | Optional second element to send |
third | Optional third element to send |
Returns: True on success
void start (XMPPFeatureList* features = 0, XmlElement* caps = 0, bool useVer1 = true)
| start |
Start the stream. This method should be called by the upper layer when processing an incoming stream Start event This method is thread safe
Parameters:
features | Optional features to advertise to the remote party of an incoming stream. The caller is responsable of freeing it. If processed, list's elements will be moved to stream's features list |
caps | Optional entity capabilities to be added to the stream features. Ignored for outgoing streams |
useVer1 | Advertise RFC3920 version. Ignored for outgoing streams |
bool authenticated (bool ok, const String& rsp = String::empty(),
XMPPError::Type error = XMPPError::NotAuthorized,
const char* username = 0, const char* id = 0, const char* resource = 0)
| authenticated |
Auth event result. This method should be called by the upper layer when processing an Auth event This method is thread safe
Parameters:
ok | True if the remote party was authenticated, false if authentication failed |
rsp | Optional success response content. Ignored if not authenticated |
error | Failure reason. Ignored if authenticated |
username | Authenticated user |
id | Non SASL auth response id |
resource | Client resource to set when non SASL authentication is used |
Returns: False if stream state is incorrect
void terminate (int location, bool destroy, XmlElement* xml,
int error = XMPPError::NoError, const char* reason = "",
bool final = false)
| terminate |
Terminate the stream. Send stream end tag or error. Reset the stream. Deref stream if destroying. This method is thread safe
Parameters:
location | The terminate request location: -1: upper layer, 0: internal, 1: remote |
destroy | True to destroy. False to terminate |
xml | Received XML element. The element will be consumed |
error | Termination reason. Set it to NoError to send stream end tag |
reason | Optional text to be added to the error stanza |
final | True if called from destructor |
void connectTerminated (Socket*& sock)
| connectTerminated |
[virtual]
Outgoing stream connect terminated notification. Send stream start if everithing is ok
Parameters:
sock | The connected socket, will be consumed and zeroed |
bool connecting (bool sync, int stat, ObjList& srvs)
| connecting |
[virtual]
Connecting notification. Start connect timer for synchronous connect This method is thread safe
Parameters:
sync | True if the connection is synchronous |
stat | Current status of the connect thread |
srvs | Current list of SRV records in the connect thread |
Returns: True if accepted
void* getObject (const String& name)
| getObject |
[const virtual]
Get an object from this stream
Parameters:
name | The name of the object to get |
Reimplemented from GenObject.
inline const char* stateName ()
| stateName |
[const]
Get the name of a stream state
Returns: The name of the stream state
inline const char* typeName ()
| typeName |
[const]
Get the name of a stream type
Returns: The name of the stream type
inline void buildSha1Digest (String& buf, const String& secret)
| buildSha1Digest |
Build a SHA1 digest from stream id and secret
Parameters:
buf | Destination buffer |
secret | The secret |
const String& toString ()
| toString |
[const virtual]
Get the string representation of this stream
Returns: Stream name
Reimplemented from GenObject.
inline Type lookupType (const char* text, Type defVal = TypeCount)
| lookupType |
[static]
Get the stream type associated with a given text
Parameters:
text | Stream type text to find |
defVal | Value to return if not found |
Returns: The stream type associated with a given text
SASL* m_sasl | m_sasl |
static const TokenDict s_stateName[] | s_stateName[] |
static const TokenDict s_flagName[] | s_flagName[] |
static const TokenDict s_typeName[] | s_typeName[] |
JBStream (JBEngine* engine, Socket* socket, Type t, bool ssl = false)
| JBStream |
[protected]
Constructor. Build an incoming stream from a socket
Parameters:
engine | Engine owning this stream |
socket | The socket |
t | Stream type as enumeration |
ssl | True if the socket is already using SSL/TLS |
JBStream (JBEngine* engine, Type t, const JabberID& local, const JabberID& remote,
const char* name = 0, const NamedList* params = 0)
| JBStream |
[protected]
Constructor. Build an outgoing stream
Parameters:
engine | Engine owning this stream |
t | Stream type as enumeration |
local | Local party jabber id |
remote | Remote party jabber id |
name | Optional stream name |
params | Optional stream parameters |
void destroyed ()
| destroyed |
[protected virtual]
Close the stream. Release memory
Reimplemented from RefObject.
bool canProcess (u_int64_t time)
| canProcess |
[protected virtual]
Check if stream state processor can continue. This method is called from getEvent() with the stream locked
Parameters:
time | Current time |
Returns: True to indicate stream availability to process its state, false to return the last event, if any
void process (u_int64_t time)
| process |
[protected virtual]
Process stream state. Get XML from parser's queue and process it This method is called from getEvent() with the stream locked
Parameters:
time | Current time |
bool processRunning (XmlElement* xml, const JabberID& from,
const JabberID& to)
| processRunning |
[protected virtual]
Process elements in Running state
Parameters:
xml | Received element (will be consumed) |
from | Already parsed source JID |
to | Already parsed destination JID |
Returns: False if stream termination was initiated
void checkTimeouts (u_int64_t time)
| checkTimeouts |
[protected virtual]
Check stream timeouts. This method is called from getEvent() with the stream locked, after the process() method returned without setting the last event
Parameters:
time | Current time |
void resetConnection (Socket* sock = 0)
| resetConnection |
[protected virtual]
Reset the stream's connection. Build a new XML parser if the socket is valid Release the old connection
Parameters:
sock | The new socket |
XmlElement* buildStreamStart ()
| buildStreamStart |
[protected virtual]
Build a stream start XML element
Returns: XmlElement pointer
bool processStart (const XmlElement* xml, const JabberID& from,
const JabberID& to)
| processStart |
[protected virtual]
Process stream start elements while waiting for them
Parameters:
xml | Received xml element |
from | The 'from' attribute |
to | The 'to' attribute |
Returns: False if stream termination was initiated
bool processAuth (XmlElement* xml, const JabberID& from,
const JabberID& to)
| processAuth |
[protected virtual]
Process elements in Auth state
Parameters:
xml | Received element (will be consumed) |
from | Already parsed source JID |
to | Already parsed destination JID |
Returns: False if stream termination was initiated
bool processCompressing (XmlElement* xml, const JabberID& from,
const JabberID& to)
| processCompressing |
[protected virtual]
Process elements in Compressing state
Parameters:
xml | Received element (will be consumed) |
from | Already parsed source JID |
to | Already parsed destination JID |
Returns: False if stream termination was initiated
bool processRegister (XmlElement* xml, const JabberID& from,
const JabberID& to)
| processRegister |
[protected virtual]
Process elements in Register state
Parameters:
xml | Received element (will be consumed) |
from | Already parsed source JID |
to | Already parsed destination JID |
Returns: False if stream termination was initiated
bool processStreamStart (const XmlElement* xml)
| processStreamStart |
[protected]
Check if a received stream start element is correct. Check namespaces and set stream version Check and set the id for outgoing streams Generate an id for incoming streams Terminate the stream if this conditions are met
Parameters:
xml | Received xml element |
Returns: False if stream termination was initiated
bool handleCompressReq (XmlElement* xml)
| handleCompressReq |
[protected]
Handle an already checked (tag and namespace) compress request Respond to it. Change stream state on success
Parameters:
xml | Received xml element (will be consumed) |
Returns: False if stream termination was initiated
bool streamError (XmlElement* xml)
| streamError |
[protected]
Check if a received element is a stream error one
Parameters:
xml | Received xml element |
Returns: True if stream termination was initiated (the xml will be consumed)
bool getJids (XmlElement* xml, JabberID& from, JabberID& to)
| getJids |
[protected]
Retrieve and check the 'from' and 'to' JIDs from a receive element
Parameters:
xml | Received xml element |
from | Jabber ID to set from the 'from' attribute |
to | Jabber ID to set from the 'to' attribute |
Returns: False if stream termination was initiated (the xml will be consumed)
bool checkStanzaRecv (XmlElement* xml, JabberID& from, JabberID& to)
| checkStanzaRecv |
[protected]
Check if a received element is a presence, message or iq qualified by the stream namespace and the stream is not authenticated. Validate 'from' for c2s streams Validate s2s 'to' domain and 'from' jid Fix 'from' or 'to' is needed
Parameters:
xml | Received xml element (will be consumed if false is returned) |
from | The sender of the stanza |
to | Stanza recipient |
Returns: False if the element was consumed (error was sent or stream termination was initiated)
void changeState (State newState, u_int64_t time = Time::msecNow())
| changeState |
[protected]
Change stream state. Reset state depending data
Parameters:
newState | The new stream state |
time | Current time |
XmlElement* checkCompress ()
| checkCompress |
[protected]
Check if the stream compress flag is set and compression was offered by remote party
Returns: Compress request XmlElement pointer or 0
void checkPendingEvent ()
| checkPendingEvent |
[protected]
Check for pending events. Set the last event
bool sendPending (bool streamOnly = false)
| sendPending |
[protected]
Send pending stream XML or stanzas Terminate the stream on error
Parameters:
streamOnly | Try to send only existing stream related XML elements |
Returns: True on success
bool writeSocket (const void* data, unsigned int& len)
| writeSocket |
[protected]
Write data to socket. Terminate the stream on socket error
Parameters:
data | Buffer to sent |
len | The number of bytes to send. Filled with actually sent bytes on exit |
Returns: True on success, false if stream termination was initiated
void updateFromRemoteDef ()
| updateFromRemoteDef |
[protected]
Update stream flags and remote connection data from engine
XMPPFeature* firstRequiredFeature ()
| firstRequiredFeature |
[protected]
Retrieve the first required feature in the list
Returns: XMPPFeature pointer or 0
bool dropXml (XmlElement*& xml, const char* reason)
| dropXml |
[protected]
Drop (delete) received XML element
Parameters:
xml | The element to delete |
reason | The reason |
Returns: True
inline bool destroyDropXml (XmlElement*& xml, XMPPError::Type error, const char* reason)
| destroyDropXml |
[protected]
Terminate (destroy) the stream. Drop (delete) received XML element
Parameters:
xml | The element to delete |
error | Terminate error |
reason | Drop reason |
Returns: False
void setFlags (int mask)
| setFlags |
[protected]
Set stream flag mask
Parameters:
mask | The bit mask to set |
void resetFlags (int mask)
| resetFlags |
[protected]
Reset stream flag mask
Parameters:
mask | The bit mask to reset |
inline void setSecured ()
| setSecured |
[protected]
Set secured flag. Remove feature from list
void setIdleTimer (u_int64_t msecNow = Time::msecNow())
| setIdleTimer |
[protected]
Set the idle timer in Running state
Parameters:
msecNow | Current time in milliseconds |
State m_state | m_state |
[protected]
String m_id | m_id |
[protected]
JabberID m_local | m_local |
[protected]
JabberID m_remote | m_remote |
[protected]
int m_flags | m_flags |
[protected]
XMPPNamespace::Type m_xmlns | m_xmlns |
[protected]
XMPPFeatureList m_features | m_features |
[protected]
JBEvent* m_lastEvent | m_lastEvent |
[protected]
ObjList m_events | m_events |
[protected]
ObjList m_pending | m_pending |
[protected]
u_int64_t m_setupTimeout | m_setupTimeout |
[protected]
u_int64_t m_startTimeout | m_startTimeout |
[protected]
u_int64_t m_pingTimeout | m_pingTimeout |
[protected]
u_int64_t m_nextPing | m_nextPing |
[protected]
u_int64_t m_idleTimeout | m_idleTimeout |
[protected]
u_int64_t m_connectTimeout | m_connectTimeout |
[protected]
unsigned int m_restart | m_restart |
[protected]
u_int64_t m_timeToFillRestart | m_timeToFillRestart |
[protected]
String m_pingId | m_pingId |
[protected]
Generated by: paulc on bussard on Tue Apr 12 17:15:21 2011, using kdoc 2.0a54. |