Sat Mar 26 11:22:43 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"

Include dependency graph for jabber.h:

This graph shows which files directly or indirectly include this file:

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_container
struct  aji_message
struct  aji_resource
struct  aji_transport_container
struct  aji_version
struct  messages

Defines

#define AJI_MAX_JIDLEN   3071
#define AJI_MAX_RESJIDLEN   1023
#define IKS_NET_EXPIRED   12
#define NET_IO_BUF_SIZE   4096

Enumerations

enum  { AJI_AUTOPRUNE = (1 << 0), AJI_AUTOREGISTER = (1 << 1) }
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.
struct aji_client * ast_aji_get_client (const char *name)
 grab a aji_client structure by label name or JID (without the resource string)
struct aji_client_container * ast_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)
 join 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.


Detailed Description

AJI - The Asterisk Jabber Interface.

Definition in file jabber.h.


Define Documentation

#define AJI_MAX_JIDLEN   3071

Definition at line 73 of file jabber.h.

Referenced by gtalk_show_channels(), and jingle_show_channels().

#define AJI_MAX_RESJIDLEN   1023

Definition at line 74 of file jabber.h.

#define IKS_NET_EXPIRED   12

Definition at line 57 of file jabber.h.

Referenced by aji_recv(), and aji_recv_loop().

#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 

Definition at line 83 of file jabber.h.

00083      {
00084    AJI_AUTOPRUNE = (1 << 0),
00085    AJI_AUTOREGISTER = (1 << 1)
00086 };

enum aji_btype

Enumerator:
AJI_USER 
AJI_TRANS 
AJI_UTRANS 

Definition at line 88 of file jabber.h.

00088                {
00089    AJI_USER=0,
00090    AJI_TRANS=1,
00091    AJI_UTRANS=2
00092 };

enum aji_state

Enumerator:
AJI_DISCONNECTING 
AJI_DISCONNECTED 
AJI_CONNECTING 
AJI_CONNECTED 

Definition at line 76 of file jabber.h.

00076                {
00077    AJI_DISCONNECTING,
00078    AJI_DISCONNECTED,
00079    AJI_CONNECTING,
00080    AJI_CONNECTED
00081 };


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.

Open Chat session

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 1884 of file res_jabber.c.

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

01885 {
01886    int res = 0;
01887    iks *iq = NULL;
01888    iq = iks_new("iq");
01889 
01890    if (iq && client) {
01891       iks_insert_attrib(iq, "type", "get");
01892       iks_insert_attrib(iq, "to", server);
01893       iks_insert_attrib(iq, "id", client->mid);
01894       ast_aji_increment_mid(client->mid);
01895       ast_aji_send(client, iq);
01896    } else 
01897       ast_log(LOG_ERROR, "Out of memory.\n");
01898 
01899    iks_delete(iq);
01900 
01901    return res;
01902 }

int ast_aji_disconnect ( struct aji_client *  client  ) 

disconnect from jabber server.

Disconnect jabber client

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

Definition at line 2373 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().

02374 {
02375    if (client) {
02376       ast_verb(4, "JABBER: Disconnecting\n");
02377 #ifdef HAVE_OPENSSL
02378       if (client->stream_flags & SECURE) {
02379          SSL_shutdown(client->ssl_session);
02380          SSL_CTX_free(client->ssl_context);
02381          SSL_free(client->ssl_session);
02382       }
02383 #endif
02384       iks_disconnect(client->p);
02385       iks_parser_delete(client->p);
02386       ASTOBJ_UNREF(client, aji_client_destroy);
02387    }
02388 
02389    return 1;
02390 }

struct aji_client* ast_aji_get_client ( const char *  name  )  [read]

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 2947 of file res_jabber.c.

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

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

02948 {
02949    struct aji_client *client = NULL;
02950    char *aux = NULL;
02951 
02952    client = ASTOBJ_CONTAINER_FIND(&clients, name);
02953    if (!client && strchr(name, '@')) {
02954       ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
02955          aux = ast_strdupa(iterator->user);
02956          if (strchr(aux, '/')) {
02957             /* strip resource for comparison */
02958             aux = strsep(&aux, "/");
02959          }
02960          if (!strncasecmp(aux, name, strlen(aux))) {
02961             client = iterator;
02962          }           
02963       });
02964    }
02965 
02966    return client;
02967 }

struct aji_client_container* ast_aji_get_clients ( void   )  [read]

Definition at line 2969 of file res_jabber.c.

References clients.

Referenced by gtalk_load_config(), and jingle_load_config().

02970 {
02971    return &clients;
02972 }

void ast_aji_increment_mid ( char *  mid  ) 

increments the mid field for messages and other events.

Parameters:
mid char.
Returns:
void.

Definition at line 2028 of file res_jabber.c.

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

02029 {
02030    int i = 0;
02031 
02032    for (i = strlen(mid) - 1; i >= 0; i--) {
02033       if (mid[i] != 'z') {
02034          mid[i] = mid[i] + 1;
02035          i = 0;
02036       } else
02037          mid[i] = 'a';
02038    }
02039 }

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

invite to a chatroom.

Invite to opened Chat session

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

Definition at line 1941 of file res_jabber.c.

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

01942 {
01943    int res = 0;
01944    iks *invite, *body, *namespace;
01945 
01946    invite = iks_new("message");
01947    body = iks_new("body");
01948    namespace = iks_new("x");
01949    if (client && invite && body && namespace) {
01950       iks_insert_attrib(invite, "to", user);
01951       iks_insert_attrib(invite, "id", client->mid);
01952       ast_aji_increment_mid(client->mid);
01953       iks_insert_cdata(body, message, 0);
01954       iks_insert_attrib(namespace, "xmlns", "jabber:x:conference");
01955       iks_insert_attrib(namespace, "jid", room);
01956       iks_insert_node(invite, body);
01957       iks_insert_node(invite, namespace);
01958       res = ast_aji_send(client, invite);
01959    } else 
01960       ast_log(LOG_ERROR, "Out of memory.\n");
01961 
01962    iks_delete(body);
01963    iks_delete(namespace);
01964    iks_delete(invite);
01965    
01966    return res;
01967 }

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

join a chatroom.

Join existing Chat session

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

Definition at line 1910 of file res_jabber.c.

References ast_aji_send(), ast_log(), and LOG_ERROR.

01911 {
01912    int res = 0;
01913    iks *presence = NULL, *priority = NULL;
01914    presence = iks_new("presence");
01915    priority = iks_new("priority");
01916    if (presence && priority && client) {
01917       iks_insert_cdata(priority, "0", 1);
01918       iks_insert_attrib(presence, "to", room);
01919       iks_insert_node(presence, priority);
01920       res = ast_aji_send(client, presence);
01921       iks_insert_cdata(priority, "5", 1);
01922       iks_insert_attrib(presence, "to", room);
01923       res = ast_aji_send(client, presence);
01924    } else 
01925       ast_log(LOG_ERROR, "Out of memory.\n");
01926    
01927    iks_delete(presence);
01928    iks_delete(priority);
01929    
01930    return res;
01931 }

int ast_aji_send ( struct aji_client *  client,
iks *  x 
)

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

sends messages.

Send jabber chat message from connected client to jabber URI

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

Definition at line 1857 of file res_jabber.c.

References AJI_CONNECTED, ast_aji_send(), ast_log(), aji_client::jid, LOG_ERROR, LOG_WARNING, and aji_client::state.

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

01858 {
01859    int res = 0;
01860    iks *message_packet = NULL;
01861    if (client->state == AJI_CONNECTED) {
01862       message_packet = iks_make_msg(IKS_TYPE_CHAT, address, message);
01863       if (message_packet) {
01864          iks_insert_attrib(message_packet, "from", client->jid->full);
01865          res = ast_aji_send(client, message_packet);
01866       } else {
01867          ast_log(LOG_ERROR, "Out of memory.\n");
01868       }
01869 
01870       iks_delete(message_packet);
01871    } else
01872       ast_log(LOG_WARNING, "JABBER: Not connected can't send\n");
01873    return 1;
01874 }


Generated on Sat Mar 26 11:22:44 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.9