My Project
|
#include <NPLJabberClient.h>
Public Types | |
enum | MessageType { MsgType_normal = -1, MsgType_error, MsgType_chat, MsgType_groupchat, MsgType_headline } |
message type More... | |
typedef boost::bimap< int, std::string > | StringMap_Type |
Public Member Functions | |
CNPLJabberClient (boost::asio::io_service &io_service, const char *sJID) | |
Create a new jabber client instance with the given jabber client ID. More... | |
int | ProcessMessage (int timeout=10) |
Use this periodically to receive data from the socket and to feed the parser. More... | |
virtual void | handleLog (LogLevel level, LogArea area, const std::string &message) |
virtual void | onConnect () |
virtual void | onDisconnect (ConnectionError e) |
virtual bool | onTLSConnect (const CertInfo &info) |
virtual void | handleMessage (const gloox::Message &stanza, MessageSession *) |
virtual void | handleMessageEvent (const JID &from, MessageEventType event) |
virtual void | handleChatState (const JID &from, ChatStateType state) |
virtual void | handleMessageSession (MessageSession *session) |
virtual void | onResourceBindError (ResourceBindError error) |
virtual void | onSessionCreateError (SessionCreateError error) |
virtual void | handleItemSubscribed (const JID &jid) |
virtual void | handleItemAdded (const JID &jid) |
virtual void | handleItemUnsubscribed (const JID &jid) |
virtual void | handleItemRemoved (const JID &jid) |
virtual void | handleItemUpdated (const JID &jid) |
virtual void | handleRoster (const Roster &roster) |
virtual void | handleRosterError (const gloox::IQ &) |
virtual void | handleRosterPresence (const RosterItem &item, const std::string &resource, gloox::Presence::PresenceType presence, const std::string &) |
virtual void | handleSelfPresence (const RosterItem &item, const std::string &resource, gloox::Presence::PresenceType presence, const std::string &) |
virtual bool | handleSubscriptionRequest (const JID &jid, const std::string &) |
virtual bool | handleUnsubscriptionRequest (const JID &jid, const std::string &) |
virtual void | handleNonrosterPresence (const gloox::Presence &) |
virtual void | handleRegistrationFields (const JID &, int fields, std::string instructions) |
virtual void | handleRegistrationResult (const JID &, RegistrationResult result) |
virtual void | handleAlreadyRegistered (const JID &) |
virtual void | handleDataForm (const JID &, const DataForm &) |
virtual void | handleOOB (const JID &, const OOB &oob) |
bool | Connect () |
Connect to the server. More... | |
void | Close () |
Close down the connection, as gracefully as possible. More... | |
bool | WriteNPLMessage (const char *to, const char *neuronfile, const char *sCode) |
Send a NPL message. More... | |
bool | WriteRawString (const char *rawstring) |
Send raw string. More... | |
bool | SendMessage (int t, const char *to, const char *body) |
/ More... | |
bool | SendMessage (const char *to, const char *body) |
Send a message packet to another user More... | |
bool | Login () |
Initiate the auth process. More... | |
bool | SetPresence (int t, const char *status, const char *show, int priority) |
/ More... | |
const char * | GetRoster () |
Get a full roster. More... | |
bool | Subscribe (const char *jid, const char *name, const char *groups, const char *msg) |
Use this function to subscribe to a new JID. More... | |
void | Unsubscribe (const char *to, const char *msg) |
Use this function to unsubscribe from a contact's presence. More... | |
virtual void | RegisterCreateAccount (const char *username, const char *password) |
to create an account: More... | |
virtual void | RegisterChangePassword (const char *password) |
to change an account's password: More... | |
virtual void | RegisterRemoveAccount () |
to delete an account: More... | |
virtual StatisticsJabber | GetStatistics () |
Returns a StatisticsStruct containing byte and stanza counts for the current active connection. More... | |
void | RemoveRosterItem (const char *to, const char *msg) |
OBSOLETED. | |
bool | AllowSubscription (const char *to, bool bAllow) |
this function is called in OnSubscription method to confirm or refuse a subscription request from another user. More... | |
void | GetAgents () |
OBSOLETED: Request a list of agents from the server. | |
bool | Register (const char *jid) |
obsoleted: Attempt to register a new user. More... | |
const char * | GetRosterItemDetail (const char *jid) |
OBSOLETED: Retrieve details of a given roster item. More... | |
const char * | GetRosterGroups () |
OBSOLETED The group names for the roster as a string. More... | |
const char * | GetRosterItems () |
OBSOLETED The Roster Item jids as a string. More... | |
void | AddEventListener (int nListenerType, const char *callbackScript) |
void | AddEventListener1 (const char *sListenerType, const char *callbackScript) |
void | RemoveEventListener (int nListenerType, const char *callbackScript) |
remove a NPL call back script from a given even listener More... | |
void | RemoveEventListener1 (const char *sListenerType, const char *callbackScript) |
void | ClearEventListener (int nListenerType) |
clear all NPL call back script from a given even listener More... | |
void | ClearEventListener1 (const char *sListenerType) |
void | ResetAllEventListeners () |
clear all registered event listeners More... | |
const std::string | GetID () |
Creates a string which is unique in the current instance and can be used as an ID for queries. More... | |
const string & | GetStatus () const |
Returns the current status message. | |
int | GetConnectionStatus () const |
This describes the possible states of a stream. More... | |
int | GetAuthError () const |
Use this function to retrieve the type of the authentication error after it occurs and you received a ConnectionError of type ConnAuthenticationFailed from the ConnectionListener. More... | |
void | WhitespacePing () |
Sends a whitespace ping to the server. More... | |
void | XmppPing (const string &sTo) |
Sends a XMPP Ping (XEP-0199) to the given JID. More... | |
const std::string & | GetXmlLang () const |
Retrieves the value of the xml:lang attribute of the initial stream. More... | |
void | SetXmlLang (const std::string &xmllang) |
void | SetClientCert (const std::string &clientKey, const std::string &clientCerts) |
Use this function to set the user's certificate and private key. More... | |
const char * | GetUser () |
The username to connect as. More... | |
void | SetUser (const char *sValue) |
The username to connect as. More... | |
int | GetPriority () |
Priority for this connection. More... | |
void | SetPriority (int nValue) |
Priority for this connection. More... | |
const char * | GetPassword () |
The password to use for connecting. More... | |
void | SetPassword (const char *sValue) |
The password to use for connecting. More... | |
bool | GetAutoLogin () |
Automatically log in on connection. More... | |
void | SetAutoLogin (bool nValue) |
Automatically log in on connection. More... | |
bool | GetAutoRoster () |
Automatically retrieve roster on connection. More... | |
void | SetAutoRoster (bool nValue) |
Automatically retrieve roster on connection. More... | |
bool | GetAutoIQErrors () |
Automatically send back 501/feature-not-implemented to IQs that have not been handled. More... | |
void | SetAutoIQErrors (bool nValue) |
Automatically send back 501/feature-not-implemented to IQs that have not been handled. More... | |
bool | GetAutoPresence () |
Automatically send presence on connection. More... | |
void | SetAutoPresence (bool nValue) |
Automatically send presence on connection. More... | |
const char * | GetResource () |
The connecting resource. More... | |
void | SetResource (const char *sValue) |
The connecting resource. More... | |
bool | GetIsAuthenticated () |
Are we currently connected? | |
void | SetIsAuthenticated (bool bValue) |
Are we currently connected? | |
const char * | GetServer () |
The name of the server to connect to. More... | |
void | SetServer (const char *Server) |
The name of the server to connect to. More... | |
const char * | GetNetworkHost () |
The address to use on the "to" attribute of the stream:stream. More... | |
void | SetNetworkHost (const char *sValue) |
The address to use on the "to" attribute of the stream:stream. More... | |
int | GetPort () |
Automatically send presence on connection. More... | |
void | SetPort (int nValue) |
Automatically send presence on connection. More... | |
bool | GetPlaintextAuth () |
Allow plaintext authentication? default to false. | |
void | SetPlaintextAuth (bool bValue) |
Allow plaintext authentication? default to false. | |
bool | IsSSLon () |
Is the current connection SSL/TLS protected? | |
bool | IsCompressionOn () |
Is the current connection XEP-138 compressed? | |
bool | GetSSL () |
Do SSL3/TLS1 on startup. | |
void | SetSSL (bool bValue) |
Do SSL3/TLS1 on startup. | |
bool | GetAutoStartTLS () |
Allow Start-TLS on connection, if the server supports it. | |
void | SetAutoStartTLS (bool bValue) |
Allow Start-TLS on connection, if the server supports it. | |
bool | GetAutoStartCompression () |
Allow start compression on connection, if the server supports it. | |
void | SetAutoStartCompression (bool bValue) |
Allow start compression on connection, if the server supports it. | |
float | GetKeepAlive () |
Time, in seconds, between keep-alive spaces. More... | |
void | SetKeepAlive (float KeepAlive) |
Time, in seconds, between keep-alive spaces. More... | |
float | GetAutoReconnect () |
Seconds before automatically reconnecting if the connection drops. More... | |
void | SetAutoReconnect (float AutoReconnect) |
Seconds before automatically reconnecting if the connection drops. More... | |
const char * | GetServerVersion () |
The version string returned in the server's open stream element. More... | |
bool | GetRequiresSASL () |
Is SASL required? This will default to true in the future. More... | |
void | SetRequiresSASL (bool bValue) |
Is SASL required? This will default to true in the future. More... | |
Static Public Member Functions | |
static void | AddStringMap (int nID, const char *sString) |
add string a string mapping. More... | |
static void | ClearStringMap () |
clear all string mapping | |
Protected Member Functions | |
virtual bool | AddEvent (int nEventType, const char *precode=NULL, const char *postcode=NULL) |
Activate the given code of a type of event The activated script will send to the script buffer and wait for the script engine to execute it. More... | |
virtual bool | CallEvent (int nEventType, const char *precode=NULL, const char *postcode=NULL) |
call the given code of a type of event It is similar to AddEvent, except that the callback functions are activated immediately and return after the callback returns. More... | |
const char * | GetStringByID (int nID) |
get a string by id in the string map More... | |
int | GetIDByString (const char *sString) |
get id by string in the string map More... | |
const string & | GetJIDKey () |
this is the unique key of this JC instance. More... | |
void | SetJIDKey (const string &sJIDKey) |
never call this function, unless you know why. More... | |
Protected Attributes | |
Client * | m_client |
MessageSession * | m_session |
MessageEventFilter * | m_messageEventFilter |
ChatStateFilter * | m_chatStateFilter |
Registration * | m_reg |
JCOptions | m_Options |
bool | m_bIsAuthenticated |
float | m_fKeepAlive |
float | m_fAutoReconnect |
CJabberEventBinding | m_eventbinding |
string | m_sUsername |
only used for creating a new user account. More... | |
string | m_sPassword |
string | m_sStatus |
presence status | |
string | m_sThisJIDKey |
this is the unique key of this JC instance. More... | |
boost::asio::io_service * | m_pIOService |
dispatcher IO service object for the connection socket. More... | |
ParaEngine::mutex | m_mutex |
Static Protected Attributes | |
static StringMap_Type | g_mapStringMap |
we will automatically encode NPL filename string if it is in this string map. More... | |
NPL jabber client.
CNPLJabberClient::CNPLJabberClient | ( | boost::asio::io_service & | io_service, |
const char * | sJID | ||
) |
Create a new jabber client instance with the given jabber client ID.
It does not open a connection immediately.
sJID | such as "lixizhi@paraengine.com" |
|
protectedvirtual |
Activate the given code of a type of event The activated script will send to the script buffer and wait for the script engine to execute it.
The function will return immediately. So the script execution is asynchronous.
nEventType | event type |
precode | the script to be activated before the user-defined script code. |
postcode | the script to be activated after the user-defined script code. |
|
virtual |
nListenerType | enum from JabberEvents |
callbackScript | an NPL callback script. |
Implements ParaEngine::INPLJabberClient.
|
static |
add string a string mapping.
We will automatically encode NPL filename string if it is in this string map. It means shorter message sent over the network. use AddStringMap whenever you want to add a string to the map. Please note, that the sender and the receiver must maintain the same string map in memory in order to have consistent string translation result. the function is static, it will apply to all client instances.
nID | the integer to encode the string. it is usually positive. |
sString | the string for the id. if input is NULL, it means removing the mapping of nID. |
|
virtual |
this function is called in OnSubscription method to confirm or refuse a subscription request from another user.
to | the JID |
bAllow | true to allow subscription, false to deny |
Implements ParaEngine::INPLJabberClient.
|
protectedvirtual |
call the given code of a type of event It is similar to AddEvent, except that the callback functions are activated immediately and return after the callback returns.
The function will return immediately. So the script execution is asynchronous.
nEventType | event type |
precode | the script to be activated before the user-defined script code. |
postcode | the script to be activated after the user-defined script code. |
|
virtual |
clear all NPL call back script from a given even listener
nListenerType | type of message listener. The user can register NPL callback script with any one listener type. |
Implements ParaEngine::INPLJabberClient.
|
virtual |
Close down the connection, as gracefully as possible.
Implements ParaEngine::INPLJabberClient.
|
virtual |
Connect to the server.
This happens asynchronously, and could take a couple of seconds to get the full handshake completed. This will auth, send presence, and request roster info, if the Auto* properties are set.
Implements ParaEngine::INPLJabberClient.
int ParaEngine::CNPLJabberClient::GetAuthError | ( | ) | const |
Use this function to retrieve the type of the authentication error after it occurs and you received a ConnectionError of type ConnAuthenticationFailed from the ConnectionListener.
|
inlinevirtual |
Automatically send back 501/feature-not-implemented to IQs that have not been handled.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Automatically log in on connection.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Automatically send presence on connection.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Seconds before automatically reconnecting if the connection drops.
-1 to disable, 0 for immediate. Default to 30 seconds
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Automatically retrieve roster on connection.
Implements ParaEngine::INPLJabberClient.
int ParaEngine::CNPLJabberClient::GetConnectionStatus | ( | ) | const |
This describes the possible states of a stream.
const std::string ParaEngine::CNPLJabberClient::GetID | ( | ) |
Creates a string which is unique in the current instance and can be used as an ID for queries.
|
protected |
get id by string in the string map
|
inlineprotected |
this is the unique key of this JC instance.
This is always the same as the bare JID of this instance. this key is set automatically, when an JC instance is created.
|
inlinevirtual |
Time, in seconds, between keep-alive spaces.
default to 20f
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
The address to use on the "to" attribute of the stream:stream.
You can put the network hostname or IP address of the server to connect to. If none is specified, the Server will be used. Eventually, when SRV is supported, this will be deprecated.
Implements ParaEngine::INPLJabberClient.
|
virtual |
The password to use for connecting.
This may be sent across the wire plaintext, if the server doesn't support digest and PlaintextAuth is true.
Implements ParaEngine::INPLJabberClient.
|
virtual |
Automatically send presence on connection.
Implements ParaEngine::INPLJabberClient.
|
virtual |
Priority for this connection.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Is SASL required? This will default to true in the future.
Implements ParaEngine::INPLJabberClient.
|
virtual |
The connecting resource.
Used to identify a unique connection.
Implements ParaEngine::INPLJabberClient.
|
virtual |
Get a full roster.
Implements ParaEngine::INPLJabberClient.
|
virtual |
OBSOLETED The group names for the roster as a string.
each group name is separated by ; such as "general;friends;relatives;"
Implements ParaEngine::INPLJabberClient.
|
virtual |
OBSOLETED: Retrieve details of a given roster item.
jid |
Implements ParaEngine::INPLJabberClient.
|
virtual |
OBSOLETED The Roster Item jids as a string.
each name is separated by ; such as "lixizhi@pala5.cn;Andy@pala5.cn;"
Implements ParaEngine::INPLJabberClient.
|
virtual |
The name of the server to connect to.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
The version string returned in the server's open stream element.
Implements ParaEngine::INPLJabberClient.
|
virtual |
Returns a StatisticsStruct containing byte and stanza counts for the current active connection.
Implements ParaEngine::INPLJabberClient.
|
protected |
get a string by id in the string map
|
virtual |
The username to connect as.
Implements ParaEngine::INPLJabberClient.
const std::string & ParaEngine::CNPLJabberClient::GetXmlLang | ( | ) | const |
Retrieves the value of the xml:lang attribute of the initial stream.
Default is 'en', i.e. if not changed by a call to setXmlLang().
|
virtual |
Initiate the auth process.
Implements ParaEngine::INPLJabberClient.
int ParaEngine::CNPLJabberClient::ProcessMessage | ( | int | timeout = 10 | ) |
Use this periodically to receive data from the socket and to feed the parser.
timeout | The timeout in microseconds to use for select. Default of -1 means blocking until data was available. |
|
virtual |
obsoleted: Attempt to register a new user.
This will fire OnRegisterInfo to retrieve information about the new user, and OnRegistered when the registration is complete or failed.
jid | The user to register |
Implements ParaEngine::INPLJabberClient.
|
virtual |
to change an account's password:
Implements ParaEngine::INPLJabberClient.
|
virtual |
to create an account:
Implements ParaEngine::INPLJabberClient.
|
virtual |
to delete an account:
Implements ParaEngine::INPLJabberClient.
|
virtual |
remove a NPL call back script from a given even listener
nListenerType | type of message listener. The user can register NPL callback script with any one listener type. |
callbackScript | the script to be called when the listener event is raised. Usually parameters are stored in a NPL parameter called "msg". |
Implements ParaEngine::INPLJabberClient.
|
virtual |
clear all registered event listeners
Implements ParaEngine::INPLJabberClient.
|
virtual |
/
/ Send a message packet to another user /
/
t | type of MessageType |
/
to | Who to send it to? |
/
body | The message. |
Implements ParaEngine::INPLJabberClient.
|
virtual |
Send a message packet to another user
to | Who to send it to? |
body | The message. |
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Automatically send back 501/feature-not-implemented to IQs that have not been handled.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Automatically log in on connection.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Automatically send presence on connection.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Seconds before automatically reconnecting if the connection drops.
-1 to disable, 0 for immediate. Default to 30 seconds
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Automatically retrieve roster on connection.
Implements ParaEngine::INPLJabberClient.
void ParaEngine::CNPLJabberClient::SetClientCert | ( | const std::string & | clientKey, |
const std::string & | clientCerts | ||
) |
Use this function to set the user's certificate and private key.
The certificate will be presented to the server upon request and can be used for SASL EXTERNAL authentication. The user's certificate file should be a bundle of more than one certificate in PEM format. The first one in the file should be the user's certificate, each cert following that one should have signed the previous one.
clientKey | The absolute path to the user's private key in PEM format. |
clientCerts | A path to a certificate bundle in PEM format. |
|
inlineprotected |
never call this function, unless you know why.
|
inlinevirtual |
Time, in seconds, between keep-alive spaces.
default to 20f
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
The address to use on the "to" attribute of the stream:stream.
/ You can put the network hostname or IP address of the server to connect to. / If none is specified, the Server will be used. / Eventually, when SRV is supported, this will be deprecated.
Implements ParaEngine::INPLJabberClient.
|
virtual |
The password to use for connecting.
This may be sent across the wire plaintext, if the server doesn't support digest and PlaintextAuth is true.
Implements ParaEngine::INPLJabberClient.
|
virtual |
Automatically send presence on connection.
Implements ParaEngine::INPLJabberClient.
|
virtual |
/
/ Send a presence packet to the server /
/
t | What kind? public enum PresenceType { / |
/ None specified /
available = -1, /
/ May I subscribe to you? /
subscribe, /
/ Yes, you may subscribe. /
subscribed, /
/ Unsubscribe from this entity. /
unsubscribe, /
/ No, you may not subscribe. /
unsubscribed, /
/ Offline /
unavailable, /
/ server-side only. /
probe, /
/ A presence error. /
error, /
/ Invisible presence: we're unavailable to them, but still see / theirs. /
invisible }
/
status | How to show us? |
/
show | away, dnd, etc. |
/
priority | How to prioritize this connection. / Higher number mean higher priority. 0 minumum, 127 max. / -1 means this is a presence-only connection. |
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
Priority for this connection.
Implements ParaEngine::INPLJabberClient.
|
virtual |
Is SASL required? This will default to true in the future.
Implements ParaEngine::INPLJabberClient.
|
inlinevirtual |
The connecting resource.
Used to identify a unique connection.
Implements ParaEngine::INPLJabberClient.
|
virtual |
The name of the server to connect to.
Implements ParaEngine::INPLJabberClient.
|
virtual |
The username to connect as.
Implements ParaEngine::INPLJabberClient.
|
virtual |
Use this function to subscribe to a new JID.
The contact is added to the roster automatically (by compliant servers, as required by RFC 3921).
jid | The address to subscribe to. |
name | The displayed name of the contact. |
groups | A list of groups the contact belongs to. separated by ";". Currently only one group is supported. |
msg | A message sent along with the request. |
Implements ParaEngine::INPLJabberClient.
|
virtual |
Use this function to unsubscribe from a contact's presence.
You will no longer receive presence from this contact. This will have the side-effect of bi-directionally unsubscribing to/from the user.
to | The JID to remove |
msg | A message to send along with the request. |
Implements ParaEngine::INPLJabberClient.
void ParaEngine::CNPLJabberClient::WhitespacePing | ( | ) |
Sends a whitespace ping to the server.
|
virtual |
Send a NPL message.
The message is queued in a output message queue and this function returns immediately.
msg | a NPL table converted to secure code. |
The current NPL message is sent via a special normal chat message subtype: MsgType_normal subject: NI:id or NF:string body: msg table scode
Implements ParaEngine::INPLJabberClient.
|
virtual |
Send raw string.
Implements ParaEngine::INPLJabberClient.
void ParaEngine::CNPLJabberClient::XmppPing | ( | const string & | sTo | ) |
Sends a XMPP Ping (XEP-0199) to the given JID.
There is currently no way to know whether the remote entity answered (other than registering an IQ handler for the urn:xmpp:ping namespace).
|
staticprotected |
we will automatically encode NPL filename string if it is in this string map.
It means shorter message sent over the network. use AddStringMap whenever you want to add a string to the map. Please note, that the sender and the receiver must maintain the same string map in memory in order to have consistent string translation result.
|
protected |
dispatcher IO service object for the connection socket.
|
protected |
this is the unique key of this JC instance.
This is always the same as the bare JID of this instance. this key is set automatically, when an JC instance is created.
|
protected |
only used for creating a new user account.