Wed Apr 6 11:30:05 2011

Asterisk developer's documentation


jabber.h File Reference

AJI - The Asterisk Jabber Interface. More...

#include <openssl/ssl.h>
#include <openssl/err.h>
#include <iksemel.h>
#include "asterisk/astobj.h"
#include "asterisk/linkedlists.h"

Go to the source code of this file.

Data Structures

struct  aji_buddy
struct  aji_buddy_container
struct  aji_capabilities
struct  aji_client
struct  aji_client::messages
struct  aji_client_container
struct  aji_message
struct  aji_resource
struct  aji_transport_container
struct  aji_version

Defines

#define AJI_MAX_ATTRLEN   256
#define AJI_MAX_JIDLEN   3071
#define AJI_MAX_RESJIDLEN   1023
#define IKS_NET_EXPIRED   12
#define MUC_NS   "http://jabber.org/protocol/muc"
#define NET_IO_BUF_SIZE   4096

Enumerations

enum  { AJI_AUTOPRUNE = (1 << 0), AJI_AUTOREGISTER = (1 << 1), AJI_AUTOACCEPT = (1 << 2) }
enum  { AJI_XEP0248 = (1 << 0), AJI_PUBSUB = (1 << 1), AJI_PUBSUB_AUTOCREATE = (1 << 2) }
enum  aji_btype { AJI_USER = 0, AJI_TRANS = 1, AJI_UTRANS = 2 }
enum  aji_state { AJI_DISCONNECTING, AJI_DISCONNECTED, AJI_CONNECTING, AJI_CONNECTED }

Functions

int ast_aji_check_roster (void)
int ast_aji_create_chat (struct aji_client *client, char *room, char *server, char *topic)
 create a chatroom.
int ast_aji_disconnect (struct aji_client *client)
 disconnect from jabber server.
aji_clientast_aji_get_client (const char *name)
 grab a aji_client structure by label name or JID (without the resource string)
aji_client_containerast_aji_get_clients (void)
void ast_aji_increment_mid (char *mid)
 increments the mid field for messages and other events.
int ast_aji_invite_chat (struct aji_client *client, char *user, char *room, char *message)
 invite to a chatroom.
int ast_aji_join_chat (struct aji_client *client, char *room, char *nick)
 join a chatroom.
int ast_aji_leave_chat (struct aji_client *client, char *room, char *nick)
 leave a chatroom.
int ast_aji_send (struct aji_client *client, iks *x)
 Wraps raw sending.
int ast_aji_send_chat (struct aji_client *client, const char *address, const char *message)
 sends messages.
int ast_aji_send_groupchat (struct aji_client *client, const char *nick, const char *address, const char *message)
 sends message to a groupchat Prior to sending messages to a groupchat, one must be connected to it.


Detailed Description

AJI - The Asterisk Jabber Interface.

Definition in file jabber.h.


Define Documentation

#define AJI_MAX_ATTRLEN   256

Definition at line 75 of file jabber.h.

Referenced by aji_act_hook().

#define AJI_MAX_JIDLEN   3071

Definition at line 73 of file jabber.h.

Referenced by acf_jabberreceive_read(), aji_send_raw_chat(), aji_set_group_presence(), gtalk_show_channels(), and jingle_show_channels().

#define AJI_MAX_RESJIDLEN   1023

Definition at line 74 of file jabber.h.

Referenced by aji_join_exec(), aji_leave_exec(), and aji_sendgroup_exec().

#define IKS_NET_EXPIRED   12

Definition at line 57 of file jabber.h.

Referenced by aji_recv(), and aji_recv_loop().

#define MUC_NS   "http://jabber.org/protocol/muc"

Definition at line 77 of file jabber.h.

Referenced by aji_set_group_presence().

#define NET_IO_BUF_SIZE   4096

Definition at line 55 of file jabber.h.

Referenced by aji_recv().


Enumeration Type Documentation

anonymous enum

Enumerator:
AJI_AUTOPRUNE 
AJI_AUTOREGISTER 
AJI_AUTOACCEPT 

Definition at line 86 of file jabber.h.

00086      {
00087    AJI_AUTOPRUNE = (1 << 0),
00088    AJI_AUTOREGISTER = (1 << 1),
00089    AJI_AUTOACCEPT = (1 << 2),
00090 };

anonymous enum

Enumerator:
AJI_XEP0248 
AJI_PUBSUB 
AJI_PUBSUB_AUTOCREATE 

Definition at line 92 of file jabber.h.

00092      {
00093    AJI_XEP0248 = (1 << 0),
00094    AJI_PUBSUB = (1 << 1),
00095    AJI_PUBSUB_AUTOCREATE = (1 << 2),
00096 };

enum aji_btype

Enumerator:
AJI_USER 
AJI_TRANS 
AJI_UTRANS 

Definition at line 98 of file jabber.h.

00098                {
00099    AJI_USER = 0,
00100    AJI_TRANS = 1,
00101    AJI_UTRANS = 2,
00102 };

enum aji_state

Enumerator:
AJI_DISCONNECTING 
AJI_DISCONNECTED 
AJI_CONNECTING 
AJI_CONNECTED 

Definition at line 79 of file jabber.h.

00079                {
00080    AJI_DISCONNECTING,
00081    AJI_DISCONNECTED,
00082    AJI_CONNECTING,
00083    AJI_CONNECTED
00084 };


Function Documentation

int ast_aji_check_roster ( void   ) 

int ast_aji_create_chat ( struct aji_client client,
char *  room,
char *  server,
char *  topic 
)

create a chatroom.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
room name of room
server name of server
topic topic for the room.
Returns:
0.

Definition at line 2621 of file res_jabber.c.

References ast_aji_increment_mid(), ast_aji_send(), ast_log(), LOG_ERROR, and aji_client::mid.

02622 {
02623    int res = 0;
02624    iks *iq = NULL;
02625    iq = iks_new("iq");
02626 
02627    if (iq && client) {
02628       iks_insert_attrib(iq, "type", "get");
02629       iks_insert_attrib(iq, "to", server);
02630       iks_insert_attrib(iq, "id", client->mid);
02631       ast_aji_increment_mid(client->mid);
02632       ast_aji_send(client, iq);
02633    } else {
02634       ast_log(LOG_ERROR, "Out of memory.\n");
02635    }
02636 
02637    iks_delete(iq);
02638 
02639    return res;
02640 }

int ast_aji_disconnect ( struct aji_client client  ) 

disconnect from jabber server.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
Returns:
1.

Definition at line 3126 of file res_jabber.c.

References aji_client_destroy(), ast_verb, ASTOBJ_UNREF, aji_client::p, aji_client::ssl_context, aji_client::ssl_session, and aji_client::stream_flags.

Referenced by unload_module().

03127 {
03128    if (client) {
03129       ast_verb(4, "JABBER: Disconnecting\n");
03130 #ifdef HAVE_OPENSSL
03131       if (client->stream_flags & SECURE) {
03132          SSL_shutdown(client->ssl_session);
03133          SSL_CTX_free(client->ssl_context);
03134          SSL_free(client->ssl_session);
03135       }
03136 #endif
03137       iks_disconnect(client->p);
03138       iks_parser_delete(client->p);
03139       ASTOBJ_UNREF(client, aji_client_destroy);
03140    }
03141 
03142    return 1;
03143 }

struct aji_client* ast_aji_get_client ( const char *  name  ) 

grab a aji_client structure by label name or JID (without the resource string)

Parameters:
name label or JID
Returns:
aji_client.

Definition at line 4563 of file res_jabber.c.

References ast_strdupa, ASTOBJ_CONTAINER_FIND, ASTOBJ_CONTAINER_TRAVERSE, clients, and strsep().

Referenced by acf_jabberreceive_read(), acf_jabberstatus_read(), aji_join_exec(), aji_leave_exec(), aji_send_exec(), aji_sendgroup_exec(), aji_status_exec(), gtalk_create_member(), gtalk_newcall(), gtalk_request(), jingle_create_member(), jingle_newcall(), jingle_request(), and manager_jabber_send().

04564 {
04565    struct aji_client *client = NULL;
04566    char *aux = NULL;
04567 
04568    client = ASTOBJ_CONTAINER_FIND(&clients, name);
04569    if (!client && strchr(name, '@')) {
04570       ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
04571          aux = ast_strdupa(iterator->user);
04572          if (strchr(aux, '/')) {
04573             /* strip resource for comparison */
04574             aux = strsep(&aux, "/");
04575          }
04576          if (!strncasecmp(aux, name, strlen(aux))) {
04577             client = iterator;
04578          }
04579       });
04580    }
04581 
04582    return client;
04583 }

struct aji_client_container* ast_aji_get_clients ( void   ) 

Definition at line 4585 of file res_jabber.c.

References clients.

04586 {
04587    return &clients;
04588 }

void ast_aji_increment_mid ( char *  mid  ) 

increments the mid field for messages and other events.

Parameters:
mid char.
Returns:
void.

Definition at line 2765 of file res_jabber.c.

Referenced by aji_act_hook(), aji_handle_presence(), aji_pubsub_iq_create(), aji_register_approve_handler(), ast_aji_create_chat(), ast_aji_invite_chat(), gtalk_action(), gtalk_create_candidates(), gtalk_invite(), jingle_accept_call(), jingle_action(), jingle_create_candidates(), jingle_digit(), and jingle_transmit_invite().

02766 {
02767    int i = 0;
02768 
02769    for (i = strlen(mid) - 1; i >= 0; i--) {
02770       if (mid[i] != 'z') {
02771          mid[i] = mid[i] + 1;
02772          i = 0;
02773       } else
02774          mid[i] = 'a';
02775    }
02776 }

int ast_aji_invite_chat ( struct aji_client client,
char *  user,
char *  room,
char *  message 
)

invite to a chatroom.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
user 
room 
message 
Returns:
res.

Definition at line 2673 of file res_jabber.c.

References ast_aji_increment_mid(), ast_aji_send(), ast_log(), LOG_ERROR, and aji_client::mid.

02674 {
02675    int res = 0;
02676    iks *invite, *body, *namespace;
02677 
02678    invite = iks_new("message");
02679    body = iks_new("body");
02680    namespace = iks_new("x");
02681    if (client && invite && body && namespace) {
02682       iks_insert_attrib(invite, "to", user);
02683       iks_insert_attrib(invite, "id", client->mid);
02684       ast_aji_increment_mid(client->mid);
02685       iks_insert_cdata(body, message, 0);
02686       iks_insert_attrib(namespace, "xmlns", "jabber:x:conference");
02687       iks_insert_attrib(namespace, "jid", room);
02688       iks_insert_node(invite, body);
02689       iks_insert_node(invite, namespace);
02690       res = ast_aji_send(client, invite);
02691    } else {
02692       ast_log(LOG_ERROR, "Out of memory.\n");
02693    }
02694 
02695    iks_delete(body);
02696    iks_delete(namespace);
02697    iks_delete(invite);
02698 
02699    return res;
02700 }

int ast_aji_join_chat ( struct aji_client client,
char *  room,
char *  nick 
)

join a chatroom.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
room room to join
nick the nickname to use in this room
Returns:
IKS_OK on success, any other value on failure.

Definition at line 2649 of file res_jabber.c.

References aji_set_group_presence().

Referenced by aji_join_exec().

02650 {
02651    return aji_set_group_presence(client, room, IKS_SHOW_AVAILABLE, nick, NULL);
02652 }

int ast_aji_leave_chat ( struct aji_client client,
char *  room,
char *  nick 
)

leave a chatroom.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
room room to leave
nick the nickname used in this room
Returns:
IKS_OK on success, any other value on failure.

Definition at line 2661 of file res_jabber.c.

References aji_set_group_presence().

Referenced by aji_leave_exec().

02662 {
02663    return aji_set_group_presence(client, room, IKS_SHOW_UNAVAILABLE, nick, NULL);
02664 }

int ast_aji_send ( struct aji_client client,
iks *  x 
)

Wraps raw sending.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
x the XMPP packet to send
Returns:
IKS_OK on success, any other value on failure

Definition at line 1435 of file res_jabber.c.

References aji_send_raw().

Referenced by aji_act_hook(), aji_client_info_handler(), aji_create_pubsub_node(), aji_delete_pubsub_node(), aji_dinfo_handler(), aji_ditems_handler(), aji_get_roster(), aji_handle_presence(), aji_handle_pubsub_error(), aji_handle_subscribe(), aji_pruneregister(), aji_publish_device_state(), aji_publish_mwi(), aji_pubsub_purge_nodes(), aji_pubsub_subscribe(), aji_register_approve_handler(), aji_register_query_handler(), aji_request_pubsub_nodes(), aji_send_raw_chat(), aji_set_group_presence(), aji_set_presence(), aji_start_sasl(), ast_aji_create_chat(), ast_aji_invite_chat(), gtalk_action(), gtalk_add_candidate(), gtalk_create_candidates(), gtalk_invite(), gtalk_response(), jingle_accept_call(), jingle_action(), jingle_add_candidate(), jingle_create_candidates(), jingle_digit(), jingle_response(), and jingle_transmit_invite().

01436 {
01437    return aji_send_raw(client, iks_string(iks_stack(x), x));
01438 }

int ast_aji_send_chat ( struct aji_client client,
const char *  address,
const char *  message 
)

sends messages.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
address 
message 
Return values:
IKS_OK success
-1 failure

Definition at line 2557 of file res_jabber.c.

References aji_send_raw_chat().

Referenced by aji_send_exec(), aji_test(), gtalk_sendtext(), jingle_sendtext(), and manager_jabber_send().

02558 {
02559    return aji_send_raw_chat(client, 0, NULL, address, message);
02560 }

int ast_aji_send_groupchat ( struct aji_client client,
const char *  nick,
const char *  address,
const char *  message 
)

sends message to a groupchat Prior to sending messages to a groupchat, one must be connected to it.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
nick the nickname we use in the chatroom
address the user the messages must be sent to
message the message to send
Returns:
IKS_OK on success, any other value on failure

Definition at line 2571 of file res_jabber.c.

References aji_send_raw_chat().

Referenced by aji_sendgroup_exec().

02571                                                                                                                   {
02572    return aji_send_raw_chat(client, 1, nick, address, message);
02573 }


Generated on Wed Apr 6 11:30:05 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7