Sat Apr 26 2014 22:03:21

Asterisk developer's documentation


xmpp.h File Reference

XMPP Interface. More...

#include <openssl/ssl.h>
#include <openssl/err.h>
#include <iksemel.h>
#include "asterisk/utils.h"
#include "asterisk/astobj2.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/pbx.h"
Include dependency graph for xmpp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_xmpp_buddy
 XMPP Buddy. More...
struct  ast_xmpp_capabilities
 Resource capabilities. More...
struct  ast_xmpp_client
 XMPP Client Connection. More...
struct  ast_xmpp_message
 XMPP Message. More...
struct  ast_xmpp_resource
 XMPP Resource. More...

Defines

#define IKS_NET_EXPIRED   12
#define NET_IO_BUF_SIZE   16384
#define SECURE   4
#define TRY_SECURE   2
#define XMPP_MAX_ATTRLEN   256
 Maximum size of an attribute.
#define XMPP_MAX_JIDLEN   3071
#define XMPP_MAX_RESJIDLEN   1023
 Maximum size of a resource JID.

Enumerations

enum  xmpp_state {
  XMPP_STATE_DISCONNECTING, XMPP_STATE_DISCONNECTED, XMPP_STATE_CONNECTING, XMPP_STATE_REQUEST_TLS,
  XMPP_STATE_REQUESTED_TLS, XMPP_STATE_AUTHENTICATE, XMPP_STATE_AUTHENTICATING, XMPP_STATE_ROSTER,
  XMPP_STATE_CONNECTED
}
 Client connection states. More...

Functions

int ast_xmpp_chatroom_invite (struct ast_xmpp_client *client, const char *user, const char *room, const char *message)
 Invite a user to an XMPP multi-user chatroom.
int ast_xmpp_chatroom_join (struct ast_xmpp_client *client, const char *room, const char *nickname)
 Join an XMPP multi-user chatroom.
int ast_xmpp_chatroom_leave (struct ast_xmpp_client *client, const char *room, const char *nickname)
 Leave an XMPP multi-user chatroom.
int ast_xmpp_chatroom_send (struct ast_xmpp_client *client, const char *nickname, const char *address, const char *message)
 Send a message to an XMPP multi-user chatroom.
int ast_xmpp_client_disconnect (struct ast_xmpp_client *client)
 Disconnect an XMPP client connection.
struct ast_xmpp_clientast_xmpp_client_find (const char *name)
 Find an XMPP client connection using a given name.
void ast_xmpp_client_lock (struct ast_xmpp_client *client)
 Lock an XMPP client connection.
int ast_xmpp_client_send (struct ast_xmpp_client *client, iks *stanza)
 Send an XML stanza out using an established XMPP client connection.
int ast_xmpp_client_send_message (struct ast_xmpp_client *client, const char *user, const char *message)
 Send a message to a given user using an established XMPP client connection.
void ast_xmpp_client_unlock (struct ast_xmpp_client *client)
 Unlock an XMPP client connection.
void ast_xmpp_client_unref (struct ast_xmpp_client *client)
 Release XMPP client connection reference.
void ast_xmpp_increment_mid (char *mid)
 Helper function which increments the message identifier.

Detailed Description

XMPP Interface.

Author:
Joshua Colp <jcolp@digium.com>
ExtRef:
IKSEMEL http://iksemel.jabberstudio.org

Definition in file xmpp.h.


Define Documentation

#define IKS_NET_EXPIRED   12

Definition at line 41 of file xmpp.h.

#define NET_IO_BUF_SIZE   16384

Definition at line 38 of file xmpp.h.

#define SECURE   4

Definition at line 33 of file xmpp.h.

#define TRY_SECURE   2

Definition at line 32 of file xmpp.h.

#define XMPP_MAX_ATTRLEN   256

Maximum size of an attribute.

Definition at line 67 of file xmpp.h.

Referenced by xmpp_action_hook().

#define XMPP_MAX_JIDLEN   3071
#define XMPP_MAX_RESJIDLEN   1023

Maximum size of a resource JID.

Definition at line 64 of file xmpp.h.

Referenced by xmpp_join_exec(), xmpp_leave_exec(), and xmpp_sendgroup_exec().


Enumeration Type Documentation

enum xmpp_state

Client connection states.

Enumerator:
XMPP_STATE_DISCONNECTING 

Client is disconnecting

XMPP_STATE_DISCONNECTED 

Client is disconnected

XMPP_STATE_CONNECTING 

Client is connecting

XMPP_STATE_REQUEST_TLS 

Client should request TLS

XMPP_STATE_REQUESTED_TLS 

Client has requested TLS

XMPP_STATE_AUTHENTICATE 

Client needs to authenticate

XMPP_STATE_AUTHENTICATING 

Client is authenticating

XMPP_STATE_ROSTER 

Client is currently getting the roster

XMPP_STATE_CONNECTED 

Client is fully connected

Definition at line 70 of file xmpp.h.

                {
        XMPP_STATE_DISCONNECTING,   /*!< Client is disconnecting */
        XMPP_STATE_DISCONNECTED,    /*!< Client is disconnected */
        XMPP_STATE_CONNECTING,      /*!< Client is connecting */
        XMPP_STATE_REQUEST_TLS,     /*!< Client should request TLS */
        XMPP_STATE_REQUESTED_TLS,   /*!< Client has requested TLS */
        XMPP_STATE_AUTHENTICATE,    /*!< Client needs to authenticate */
        XMPP_STATE_AUTHENTICATING,  /*!< Client is authenticating */
        XMPP_STATE_ROSTER,          /*!< Client is currently getting the roster */
        XMPP_STATE_CONNECTED,       /*!< Client is fully connected */
};

Function Documentation

int ast_xmpp_chatroom_invite ( struct ast_xmpp_client client,
const char *  user,
const char *  room,
const char *  message 
)

Invite a user to an XMPP multi-user chatroom.

Parameters:
clientPointer to the client
userJID of the user
roomName of the chatroom
messageMessage to send with the invitation
Return values:
0on success
-1on failure

Definition at line 791 of file res_xmpp.c.

References ast_xmpp_client_lock(), ast_xmpp_client_send(), ast_xmpp_client_unlock(), ast_xmpp_increment_mid(), and ast_xmpp_client::mid.

{
   int res = 0;
   iks *invite, *body = NULL, *namespace = NULL;

   if (!(invite = iks_new("message")) || !(body = iks_new("body")) || !(namespace = iks_new("x"))) {
      res = -1;
      goto done;
   }

   iks_insert_attrib(invite, "to", user);
   ast_xmpp_client_lock(client);
   iks_insert_attrib(invite, "id", client->mid);
   ast_xmpp_increment_mid(client->mid);
   ast_xmpp_client_unlock(client);
   iks_insert_cdata(body, message, 0);
   iks_insert_node(invite, body);
   iks_insert_attrib(namespace, "xmlns", "jabber:x:conference");
   iks_insert_attrib(namespace, "jid", room);
   iks_insert_node(invite, namespace);

   res = ast_xmpp_client_send(client, invite);

done:
   iks_delete(namespace);
   iks_delete(body);
   iks_delete(invite);

   return res;
}
int ast_xmpp_chatroom_join ( struct ast_xmpp_client client,
const char *  room,
const char *  nickname 
)

Join an XMPP multi-user chatroom.

Parameters:
clientPointer to the client
roomName of the chatroom
nicknameNickname to use
Return values:
0on success
-1on failure

Definition at line 858 of file res_xmpp.c.

References xmpp_client_set_group_presence().

Referenced by xmpp_join_exec().

{
   return xmpp_client_set_group_presence(client, room, IKS_SHOW_AVAILABLE, nickname);
}
int ast_xmpp_chatroom_leave ( struct ast_xmpp_client client,
const char *  room,
const char *  nickname 
)

Leave an XMPP multi-user chatroom.

Parameters:
clientPointer to the client
roomName of the chatroom
nicknameNickname being used
Return values:
0on success
-1on failure

Definition at line 868 of file res_xmpp.c.

References xmpp_client_set_group_presence().

Referenced by xmpp_leave_exec().

{
   return xmpp_client_set_group_presence(client, room, IKS_SHOW_UNAVAILABLE, nickname);
}
int ast_xmpp_chatroom_send ( struct ast_xmpp_client client,
const char *  nickname,
const char *  address,
const char *  message 
)

Send a message to an XMPP multi-user chatroom.

Parameters:
clientPointer to the client
nicknameNickname to use
AddressAddress of the room
messageMessage itself
Return values:
0on success
-1on failure

Definition at line 863 of file res_xmpp.c.

References xmpp_client_send_message().

Referenced by xmpp_sendgroup_exec().

{
   return xmpp_client_send_message(client, 1, nickname, address, message);
}
int ast_xmpp_client_disconnect ( struct ast_xmpp_client client)

Disconnect an XMPP client connection.

Parameters:
clientPointer to the client
Return values:
0on success
-1on failure

Definition at line 3395 of file res_xmpp.c.

References ast_event_unsubscribe(), AST_PTHREADT_NULL, ast_xmpp_client::device_state_sub, ast_xmpp_client::mwi_sub, ast_xmpp_client::parser, SECURE, ast_xmpp_client::ssl_context, ast_xmpp_client::ssl_session, ast_xmpp_client::state, ast_xmpp_client::stream_flags, ast_xmpp_client::thread, xmpp_pubsub_unsubscribe(), XMPP_STATE_DISCONNECTED, and XMPP_STATE_DISCONNECTING.

Referenced by xmpp_client_config_post_apply(), xmpp_client_destructor(), and xmpp_client_reconnect().

{
   if ((client->thread != AST_PTHREADT_NULL) && !pthread_equal(pthread_self(), client->thread)) {
      client->state = XMPP_STATE_DISCONNECTING;
      pthread_join(client->thread, NULL);
      client->thread = AST_PTHREADT_NULL;
   }

   if (client->mwi_sub) {
      ast_event_unsubscribe(client->mwi_sub);
      client->mwi_sub = NULL;
      xmpp_pubsub_unsubscribe(client, "message_waiting");
   }

   if (client->device_state_sub) {
      ast_event_unsubscribe(client->device_state_sub);
      client->device_state_sub = NULL;
      xmpp_pubsub_unsubscribe(client, "device_state");
   }

#ifdef HAVE_OPENSSL
   if (client->stream_flags & SECURE) {
      SSL_shutdown(client->ssl_session);
      SSL_CTX_free(client->ssl_context);
      SSL_free(client->ssl_session);
   }

   client->stream_flags = 0;
#endif

   if (client->parser) {
      iks_disconnect(client->parser);
   }

   client->state = XMPP_STATE_DISCONNECTED;

   return 0;
}
struct ast_xmpp_client* ast_xmpp_client_find ( const char *  name) [read]

Find an XMPP client connection using a given name.

Parameters:
nameName of the client connection
Return values:
non-NULLon success
NULLon failure
Note:
This will return the client connection with the reference count incremented by one.

Definition at line 729 of file res_xmpp.c.

References ao2_cleanup, ao2_global_obj_ref, ao2_ref, globals, and xmpp_config_find().

Referenced by custom_connection_handler().

{
   RAII_VAR(struct xmpp_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
   RAII_VAR(struct ast_xmpp_client_config *, clientcfg, NULL, ao2_cleanup);

   if (!cfg || !cfg->clients || !(clientcfg = xmpp_config_find(cfg->clients, name))) {
      return NULL;
   }

   ao2_ref(clientcfg->client, +1);
   return clientcfg->client;
}
void ast_xmpp_client_lock ( struct ast_xmpp_client client)
int ast_xmpp_client_send ( struct ast_xmpp_client client,
iks *  stanza 
)
int ast_xmpp_client_send_message ( struct ast_xmpp_client client,
const char *  user,
const char *  message 
)

Send a message to a given user using an established XMPP client connection.

Parameters:
clientPointer to the client
userUser the message should be sent to
messageThe message to send
Return values:
0on success
-1on failure

Definition at line 786 of file res_xmpp.c.

References xmpp_client_send_message().

Referenced by jingle_sendtext(), manager_jabber_send(), xmpp_send_cb(), and xmpp_send_exec().

{
   return xmpp_client_send_message(client, 0, NULL, user, message);
}
void ast_xmpp_client_unlock ( struct ast_xmpp_client client)
void ast_xmpp_client_unref ( struct ast_xmpp_client client)

Release XMPP client connection reference.

Parameters:
clientPointer to the client

Definition at line 742 of file res_xmpp.c.

References ao2_ref.

Referenced by jingle_endpoint_destructor(), and jingle_session_destructor().

{
   ao2_ref(client, -1);
}
void ast_xmpp_increment_mid ( char *  mid)

Helper function which increments the message identifier.

Parameters:
midPointer to a string containing the message identifier

Definition at line 873 of file res_xmpp.c.

Referenced by ast_xmpp_chatroom_invite(), jingle_send_session_action(), jingle_send_session_info(), jingle_send_session_terminate(), jingle_send_transport_info(), xmpp_client_authenticate_digest(), xmpp_client_authenticating(), xmpp_client_send_disco_info_request(), xmpp_component_register_set_hook(), xmpp_ping_request(), and xmpp_pubsub_iq_create().

{
   int i = 0;

   for (i = strlen(mid) - 1; i >= 0; i--) {
      if (mid[i] != 'z') {
         mid[i] = mid[i] + 1;
         i = 0;
      } else {
         mid[i] = 'a';
      }
   }
}