Sat Mar 26 11:25:32 2011

Asterisk developer's documentation


res_jabber.c File Reference

A resource for interfacing Asterisk directly as a client or a component to a XMPP/Jabber compliant server. More...

#include "asterisk.h"
#include <ctype.h>
#include <iksemel.h>
#include "asterisk/channel.h"
#include "asterisk/jabber.h"
#include "asterisk/file.h"
#include "asterisk/config.h"
#include "asterisk/callerid.h"
#include "asterisk/lock.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/pbx.h"
#include "asterisk/md5.h"
#include "asterisk/acl.h"
#include "asterisk/utils.h"
#include "asterisk/module.h"
#include "asterisk/astobj.h"
#include "asterisk/astdb.h"
#include "asterisk/manager.h"

Include dependency graph for res_jabber.c:

Go to the source code of this file.

Defines

#define FALSE   0
#define JABBER_CONFIG   "jabber.conf"
#define TRUE   1

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int acf_jabberstatus_read (struct ast_channel *chan, const char *name, char *data, char *buf, size_t buflen)
static int aji_act_hook (void *data, int type, iks *node)
 The action hook parses the inbound packets, constantly running.
static void aji_buddy_destroy (struct aji_buddy *obj)
 Deletes the aji_buddy data structure.
static int aji_client_connect (void *data, ikspak *pak)
 connects as a client to jabber server.
static void aji_client_destroy (struct aji_client *obj)
 Deletes the aji_client data structure.
static int aji_client_info_handler (void *data, ikspak *pak)
 Handle add extra info.
static int aji_create_buddy (char *label, struct aji_client *client)
 creates buddy.
static int aji_create_client (char *label, struct ast_variable *var, int debug)
 creates aji_client structure.
static int aji_dinfo_handler (void *data, ikspak *pak)
 Handler of the return info packet.
static int aji_ditems_handler (void *data, ikspak *pak)
 Handles stuff.
static char * aji_do_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Reload jabber module.
static char * aji_do_set_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Turn on/off console debugging.
static int aji_filter_roster (void *data, ikspak *pak)
 filters the roster packet we get back from server.
static struct aji_resource * aji_find_resource (struct aji_buddy *buddy, char *name)
 Find the aji_resource we want.
static struct aji_version * aji_find_version (char *node, char *version, ikspak *pak)
 Find version in XML stream and populate our capabilities list.
static int aji_get_roster (struct aji_client *client)
 Get the roster of jabber users.
static void aji_handle_iq (struct aji_client *client, iks *node)
 Handles.
static void aji_handle_message (struct aji_client *client, ikspak *pak)
 Handles presence packets.
static void aji_handle_presence (struct aji_client *client, ikspak *pak)
 Check the presence info.
static void aji_handle_subscribe (struct aji_client *client, ikspak *pak)
 handles subscription requests.
static int aji_initialize (struct aji_client *client)
 prepares client for connect.
static int aji_io_recv (struct aji_client *client, char *buffer, size_t buf_len, int timeout)
 Secured or unsecured IO socket receiving function.
static int aji_is_secure (struct aji_client *client)
 Tests whether the connection is secured or not.
static int aji_load_config (int reload)
static void aji_log_hook (void *data, const char *xmpp, size_t size, int is_incoming)
 the debug loop.
static void aji_pruneregister (struct aji_client *client)
 goes through roster and prunes users not needed in list, or adds them accordingly.
static int aji_reconnect (struct aji_client *client)
 reconnect to jabber server
static int aji_recv (struct aji_client *client, int timeout)
 Tries to receive data from the Jabber server.
static void * aji_recv_loop (void *data)
 receive message loop.
static int aji_register_approve_handler (void *data, ikspak *pak)
 Unknown.
static int aji_register_query_handler (void *data, ikspak *pak)
 register handler for incoming querys (IQ's)
static int aji_reload (int reload)
 Reload the jabber module.
static int aji_send_exec (struct ast_channel *chan, void *data)
 Dial plan function to send a message.
static int aji_send_header (struct aji_client *client, const char *to)
 Sends XMPP header to the server.
static int aji_send_raw (struct aji_client *client, const char *xmlstr)
 Sends an XML string over an XMPP connection.
static void aji_set_presence (struct aji_client *client, char *to, char *from, int level, char *desc)
 set presence of client.
static char * aji_show_buddies (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show buddy lists.
static char * aji_show_clients (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show client status.
static int aji_start_sasl (struct aji_client *client, enum ikssasltype type, char *username, char *pass)
 A wrapper function for iks_start_sasl.
static int aji_start_tls (struct aji_client *client)
 Starts the TLS procedure.
static int aji_status_exec (struct ast_channel *chan, void *data)
 Dial plan function status(). puts the status of watched user into a channel variable.
static char * aji_test (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Send test message for debugging.
static int aji_tls_handshake (struct aji_client *client)
 TLS handshake, OpenSSL initialization.
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.
static int gtalk_yuck (iks *node)
 Jabber GTalk function.
static iks * jabber_make_auth (iksid *id, const char *pass, const char *sid)
 Setup the authentication struct.
static int load_module (void)
 Unload the jabber module.
static int manager_jabber_send (struct mansession *s, const struct message *m)
 Send a Jabber Message via call from the Manager.
static int reload (void)
 Wrapper for aji_reload.
static int unload_module (void)
 Unload the jabber module.

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS , .description = "AJI - Asterisk Jabber Interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, }
static struct ast_cli_entry aji_cli []
static char * app_ajisend = "JabberSend"
static char * app_ajistatus = "JabberStatus"
static struct ast_module_info * ast_module_info = &__mod_info
struct aji_capabilities * capabilities = NULL
struct aji_client_container clients
static struct ast_flags globalflags = { AJI_AUTOREGISTER }
 Global flags, initialized to default values.
static struct ast_custom_function jabberstatus_function
static char mandescr_jabber_send []


Detailed Description

A resource for interfacing Asterisk directly as a client or a component to a XMPP/Jabber compliant server.

References:

ExtRef:
Iksemel http://code.google.com/p/iksemel/
Todo:
If you unload this module, chan_gtalk/jingle will be dead. How do we handle that?

Dialplan applications need RETURN variable, like JABBERSENDSTATUS

Definition in file res_jabber.c.


Define Documentation

#define FALSE   0

Definition at line 176 of file res_jabber.c.

#define JABBER_CONFIG   "jabber.conf"

Todo:
This should really be renamed to xmpp.conf. For backwards compatibility, we need to read both files

Definition at line 173 of file res_jabber.c.

Referenced by aji_load_config().

#define TRUE   1

Definition at line 180 of file res_jabber.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 3104 of file res_jabber.c.

static void __unreg_module ( void   )  [static]

Definition at line 3104 of file res_jabber.c.

static int acf_jabberstatus_read ( struct ast_channel *  chan,
const char *  name,
char *  data,
char *  buf,
size_t  buflen 
) [static]

Definition at line 489 of file res_jabber.c.

References aji_find_resource(), ast_aji_get_client(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ASTOBJ_CONTAINER_FIND, aji_client::buddies, LOG_ERROR, LOG_NOTICE, LOG_WARNING, aji_resource::resource, aji_buddy::resources, and aji_resource::status.

00490 {
00491    struct aji_client *client = NULL;
00492    struct aji_buddy *buddy = NULL;
00493    struct aji_resource *r = NULL;
00494    int stat = 7;
00495    AST_DECLARE_APP_ARGS(args,
00496       AST_APP_ARG(sender);
00497       AST_APP_ARG(jid);
00498    );
00499    AST_DECLARE_APP_ARGS(jid,
00500       AST_APP_ARG(screenname);
00501       AST_APP_ARG(resource);
00502    );
00503 
00504    if (!data) {
00505       ast_log(LOG_ERROR, "Usage: JABBER_STATUS(<sender>,<jid>[/<resource>])\n");
00506       return 0;
00507    }
00508    AST_STANDARD_APP_ARGS(args, data);
00509 
00510    if (args.argc != 2) {
00511       ast_log(LOG_ERROR, "JABBER_STATUS requires 2 arguments: sender and jid.\n");
00512       return -1;
00513    }
00514 
00515    AST_NONSTANDARD_APP_ARGS(jid, args.jid, '/');
00516 
00517    if (!(client = ast_aji_get_client(args.sender))) {
00518       ast_log(LOG_WARNING, "Could not find sender connection: '%s'\n", args.sender);
00519       return -1;
00520    }
00521    buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, jid.screenname);
00522    if (!buddy) {
00523       ast_log(LOG_WARNING, "Could not find buddy in list: '%s'\n", jid.screenname);
00524       return -1;
00525    }
00526    r = aji_find_resource(buddy, jid.resource);
00527    if (!r && buddy->resources) 
00528       r = buddy->resources;
00529    if (!r)
00530       ast_log(LOG_NOTICE, "Resource %s of buddy %s was not found.\n", jid.resource, jid.screenname);
00531    else
00532       stat = r->status;
00533    snprintf(buf, buflen, "%d", stat);
00534    return 0;
00535 }

static int aji_act_hook ( void *  data,
int  type,
iks *  node 
) [static]

The action hook parses the inbound packets, constantly running.

Parameters:
data aji client structure
type type of packet
node the actual packet.
Returns:
IKS_OK or IKS_HOOK .

Definition at line 934 of file res_jabber.c.

References aji_client_connect(), aji_client_destroy(), AJI_CONNECTED, AJI_CONNECTING, AJI_DISCONNECTED, AJI_DISCONNECTING, aji_handle_iq(), aji_handle_message(), aji_handle_presence(), aji_handle_subscribe(), aji_is_secure(), aji_recv(), aji_send_header(), aji_send_raw(), aji_start_sasl(), aji_start_tls(), aji_tls_handshake(), asprintf, ast_aji_increment_mid(), ast_aji_send(), ast_debug, ast_free, ast_log(), ast_sha1_hash(), ASTOBJ_REF, ASTOBJ_UNREF, aji_client::authorized, aji_client::component, aji_client::f, jabber_make_auth(), aji_client::jid, LOG_ERROR, LOG_WARNING, aji_client::mid, aji_client::password, secret, aji_client::state, aji_client::stream_flags, aji_client::usesasl, and aji_client::usetls.

00935 {
00936    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
00937    ikspak *pak = NULL;
00938    iks *auth = NULL;
00939    int features = 0;
00940 
00941    if(!node) {
00942       ast_log(LOG_ERROR, "aji_act_hook was called with out a packet\n"); /* most likely cause type is IKS_NODE_ERROR lost connection */
00943       ASTOBJ_UNREF(client, aji_client_destroy);
00944       return IKS_HOOK;
00945    }
00946 
00947    if (client->state == AJI_DISCONNECTING) {
00948       ASTOBJ_UNREF(client, aji_client_destroy);
00949       return IKS_HOOK;
00950    }
00951 
00952    pak = iks_packet(node);
00953 
00954    if (!client->component) { /*client */
00955       switch (type) {
00956       case IKS_NODE_START:
00957          if (client->usetls && !aji_is_secure(client)) {
00958 #ifndef HAVE_OPENSSL
00959             ast_log(LOG_ERROR, "OpenSSL not installed. You need to install OpenSSL on this system, or disable the TLS option in your configuration file\n");
00960             ASTOBJ_UNREF(client, aji_client_destroy);
00961             return IKS_HOOK;
00962 #else
00963             if (aji_start_tls(client) == IKS_NET_TLSFAIL) {
00964                ast_log(LOG_ERROR, "Could not start TLS\n");
00965                ASTOBJ_UNREF(client, aji_client_destroy);
00966                return IKS_HOOK;     
00967             }
00968 #endif
00969             break;
00970          }
00971          if (!client->usesasl) {
00972             iks_filter_add_rule(client->f, aji_client_connect, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid, IKS_RULE_DONE);
00973             auth = jabber_make_auth(client->jid, client->password, iks_find_attrib(node, "id"));
00974             if (auth) {
00975                iks_insert_attrib(auth, "id", client->mid);
00976                iks_insert_attrib(auth, "to", client->jid->server);
00977                ast_aji_increment_mid(client->mid);
00978                ast_aji_send(client, auth);
00979                iks_delete(auth);
00980             } else
00981                ast_log(LOG_ERROR, "Out of memory.\n");
00982          }
00983          break;
00984 
00985       case IKS_NODE_NORMAL:
00986 #ifdef HAVE_OPENSSL
00987          if (client->stream_flags & TRY_SECURE) {
00988             if (!strcmp("proceed", iks_name(node))) {
00989                return aji_tls_handshake(client);
00990             }
00991          }
00992 #endif
00993          if (!strcmp("stream:features", iks_name(node))) {
00994             features = iks_stream_features(node);
00995             if (client->usesasl) {
00996                if (client->usetls && !aji_is_secure(client))
00997                   break;
00998                if (client->authorized) {
00999                   if (features & IKS_STREAM_BIND) {
01000                      iks_filter_add_rule(client->f, aji_client_connect, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_DONE);
01001                      auth = iks_make_resource_bind(client->jid);
01002                      if (auth) {
01003                         iks_insert_attrib(auth, "id", client->mid);
01004                         ast_aji_increment_mid(client->mid);
01005                         ast_aji_send(client, auth);
01006                         iks_delete(auth);
01007                      } else {
01008                         ast_log(LOG_ERROR, "Out of memory.\n");
01009                         break;
01010                      }
01011                   }
01012                   if (features & IKS_STREAM_SESSION) {
01013                      iks_filter_add_rule (client->f, aji_client_connect, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "auth", IKS_RULE_DONE);
01014                      auth = iks_make_session();
01015                      if (auth) {
01016                         iks_insert_attrib(auth, "id", "auth");
01017                         ast_aji_increment_mid(client->mid);
01018                         ast_aji_send(client, auth);
01019                         iks_delete(auth);
01020                      } else {
01021                         ast_log(LOG_ERROR, "Out of memory.\n");
01022                      }
01023                   }
01024                } else {
01025                   int ret;
01026                   if (!client->jid->user) {
01027                      ast_log(LOG_ERROR, "Malformed Jabber ID : %s (domain missing?)\n", client->jid->full);
01028                      break;
01029                   }
01030 
01031                   ret = aji_start_sasl(client, features, client->jid->user, client->password);
01032                   if (ret != IKS_OK) {
01033                      ASTOBJ_UNREF(client, aji_client_destroy);
01034                      return IKS_HOOK;
01035                   }
01036                   break;
01037                }
01038             }
01039          } else if (!strcmp("failure", iks_name(node))) {
01040             ast_log(LOG_ERROR, "JABBER: encryption failure. possible bad password.\n");
01041          } else if (!strcmp("success", iks_name(node))) {
01042             client->authorized = 1;
01043             aji_send_header(client, client->jid->server);
01044          }
01045          break;
01046       case IKS_NODE_ERROR: 
01047             ast_log(LOG_ERROR, "JABBER: Node Error\n");
01048             ASTOBJ_UNREF(client, aji_client_destroy);
01049             return IKS_HOOK;
01050             break;
01051       case IKS_NODE_STOP: 
01052             ast_log(LOG_WARNING, "JABBER: Disconnected\n");
01053             ASTOBJ_UNREF(client, aji_client_destroy);
01054             return IKS_HOOK;
01055             break;
01056       }
01057    } else if (client->state != AJI_CONNECTED && client->component) {
01058       switch (type) {
01059       case IKS_NODE_START:
01060          if (client->state == AJI_DISCONNECTED) {
01061             char secret[160], shasum[320], *handshake;
01062 
01063             sprintf(secret, "%s%s", pak->id, client->password);
01064             ast_sha1_hash(shasum, secret);
01065             handshake = NULL;
01066             if (asprintf(&handshake, "<handshake>%s</handshake>", shasum) >= 0) {
01067                aji_send_raw(client, handshake);
01068                ast_free(handshake);
01069                handshake = NULL;
01070             }
01071             client->state = AJI_CONNECTING;
01072             if(aji_recv(client, 1) == 2) /*XXX proper result for iksemel library on iks_recv of <handshake/> XXX*/
01073                client->state = AJI_CONNECTED;
01074             else
01075                ast_log(LOG_WARNING, "Jabber didn't seem to handshake, failed to authenticate.\n");
01076             break;
01077          }
01078          break;
01079 
01080       case IKS_NODE_NORMAL:
01081          break;
01082 
01083       case IKS_NODE_ERROR:
01084          ast_log(LOG_ERROR, "JABBER: Node Error\n");
01085          ASTOBJ_UNREF(client, aji_client_destroy);
01086          return IKS_HOOK;
01087 
01088       case IKS_NODE_STOP:
01089          ast_log(LOG_WARNING, "JABBER: Disconnected\n");
01090          ASTOBJ_UNREF(client, aji_client_destroy);
01091          return IKS_HOOK;
01092       }
01093    }
01094 
01095    switch (pak->type) {
01096    case IKS_PAK_NONE:
01097       ast_debug(1, "JABBER: I don't know what to do with paktype NONE.\n");
01098       break;
01099    case IKS_PAK_MESSAGE:
01100       aji_handle_message(client, pak);
01101       ast_debug(1, "JABBER: Handling paktype MESSAGE.\n");
01102       break;
01103    case IKS_PAK_PRESENCE:
01104       aji_handle_presence(client, pak);
01105       ast_debug(1, "JABBER: Handling paktype PRESENCE\n");
01106       break;
01107    case IKS_PAK_S10N:
01108       aji_handle_subscribe(client, pak);
01109       ast_debug(1, "JABBER: Handling paktype S10N\n");
01110       break;
01111    case IKS_PAK_IQ:
01112       ast_debug(1, "JABBER: Handling paktype IQ\n");
01113       aji_handle_iq(client, node);
01114       break;
01115    default:
01116       ast_debug(1, "JABBER: I don't know anything about paktype '%d'\n", pak->type);
01117       break;
01118    }
01119    
01120    iks_filter_packet(client->f, pak);
01121 
01122    if (node)
01123       iks_delete(node);
01124 
01125    ASTOBJ_UNREF(client, aji_client_destroy);
01126    return IKS_OK;
01127 }

static void aji_buddy_destroy ( struct aji_buddy *  obj  )  [static]

Deletes the aji_buddy data structure.

Parameters:
obj aji_buddy The structure we will delete.
Returns:
void.

Definition at line 281 of file res_jabber.c.

References ast_free, aji_resource::description, aji_resource::next, and aji_buddy::resources.

Referenced by aji_client_destroy(), aji_create_buddy(), and aji_handle_presence().

00282 {
00283    struct aji_resource *tmp;
00284 
00285    while ((tmp = obj->resources)) {
00286       obj->resources = obj->resources->next;
00287       ast_free(tmp->description);
00288       ast_free(tmp);
00289    }
00290 
00291    ast_free(obj);
00292 }

static int aji_client_connect ( void *  data,
ikspak *  pak 
) [static]

connects as a client to jabber server.

Parameters:
data void
pak ikspak iksemel packet
Returns:
res.

Definition at line 2317 of file res_jabber.c.

References aji_client_destroy(), AJI_CONNECTING, AJI_DISCONNECTED, aji_filter_roster(), aji_get_roster(), ast_log(), ASTOBJ_REF, ASTOBJ_UNREF, aji_client::component, aji_client::f, aji_client::jid, LOG_ERROR, aji_client::stack, and aji_client::state.

Referenced by aji_act_hook().

02318 {
02319    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
02320    int res = IKS_FILTER_PASS;
02321 
02322    if (client) {
02323       if (client->state == AJI_DISCONNECTED) {
02324          iks_filter_add_rule(client->f, aji_filter_roster, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "roster", IKS_RULE_DONE);
02325          client->state = AJI_CONNECTING;
02326          client->jid = (iks_find_cdata(pak->query, "jid")) ? iks_id_new(client->stack, iks_find_cdata(pak->query, "jid")) : client->jid;
02327          if (!client->component) { /*client*/
02328             aji_get_roster(client);
02329          }
02330          iks_filter_remove_hook(client->f, aji_client_connect);
02331          /* Once we remove the hook for this routine, we must return EAT or we will crash or corrupt memory */
02332          res = IKS_FILTER_EAT;
02333       }
02334    } else
02335       ast_log(LOG_ERROR, "Out of memory.\n");
02336 
02337    ASTOBJ_UNREF(client, aji_client_destroy);
02338    return res;
02339 }

static void aji_client_destroy ( struct aji_client *  obj  )  [static]

Deletes the aji_client data structure.

Parameters:
obj aji_client The structure we will delete.
Returns:
void.

Definition at line 257 of file res_jabber.c.

References aji_buddy_destroy(), ast_free, AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, ASTOBJ_CONTAINER_DESTROY, ASTOBJ_CONTAINER_DESTROYALL, aji_client::buddies, aji_client::f, aji_message::from, aji_message::list, aji_message::message, aji_client::messages, aji_client::p, and aji_client::stack.

Referenced by aji_act_hook(), aji_client_connect(), aji_client_info_handler(), aji_dinfo_handler(), aji_ditems_handler(), aji_log_hook(), aji_recv_loop(), aji_register_approve_handler(), aji_register_query_handler(), aji_reload(), ast_aji_disconnect(), and unload_module().

00258 {
00259    struct aji_message *tmp;
00260    ASTOBJ_CONTAINER_DESTROYALL(&obj->buddies, aji_buddy_destroy);
00261    ASTOBJ_CONTAINER_DESTROY(&obj->buddies);
00262    iks_filter_delete(obj->f);
00263    iks_parser_delete(obj->p);
00264    iks_stack_delete(obj->stack);
00265    AST_LIST_LOCK(&obj->messages);
00266    while ((tmp = AST_LIST_REMOVE_HEAD(&obj->messages, list))) {
00267       if (tmp->from)
00268          ast_free(tmp->from);
00269       if (tmp->message)
00270          ast_free(tmp->message);
00271    }
00272    AST_LIST_HEAD_DESTROY(&obj->messages);
00273    ast_free(obj);
00274 }

static int aji_client_info_handler ( void *  data,
ikspak *  pak 
) [static]

Handle add extra info.

Parameters:
data void
pak ikspak
Returns:
IKS_FILTER_EAT

Definition at line 1343 of file res_jabber.c.

References aji_client_destroy(), aji_find_resource(), ast_aji_send(), ast_log(), ASTOBJ_CONTAINER_FIND, ASTOBJ_REF, ASTOBJ_UNREF, aji_client::buddies, aji_resource::cap, aji_client::jid, aji_version::jingle, LOG_ERROR, LOG_NOTICE, and aji_resource::resource.

01344 {
01345    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
01346    struct aji_resource *resource = NULL;
01347    struct aji_buddy *buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, pak->from->partial);
01348 
01349    resource = aji_find_resource(buddy, pak->from->resource);
01350    if (pak->subtype == IKS_TYPE_RESULT) {
01351       if (!resource) {
01352          ast_log(LOG_NOTICE, "JABBER: Received client info from %s when not requested.\n", pak->from->full);
01353          ASTOBJ_UNREF(client, aji_client_destroy);
01354          return IKS_FILTER_EAT;
01355       }
01356       if (iks_find_with_attrib(pak->query, "feature", "var", "http://www.google.com/xmpp/protocol/voice/v1")) {
01357          resource->cap->jingle = 1;
01358       } else
01359          resource->cap->jingle = 0;
01360    } else if (pak->subtype == IKS_TYPE_GET) {
01361       iks *iq, *disco, *ident, *google, *query;
01362       iq = iks_new("iq");
01363       query = iks_new("query");
01364       ident = iks_new("identity");
01365       disco = iks_new("feature");
01366       google = iks_new("feature");
01367       if (iq && ident && disco && google) {
01368          iks_insert_attrib(iq, "from", client->jid->full);
01369          iks_insert_attrib(iq, "to", pak->from->full);
01370          iks_insert_attrib(iq, "type", "result");
01371          iks_insert_attrib(iq, "id", pak->id);
01372          iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
01373          iks_insert_attrib(ident, "category", "client");
01374          iks_insert_attrib(ident, "type", "pc");
01375          iks_insert_attrib(ident, "name", "asterisk");
01376          iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco#info");
01377          iks_insert_attrib(google, "var", "http://www.google.com/xmpp/protocol/voice/v1");
01378          iks_insert_node(iq, query);
01379          iks_insert_node(query, ident);
01380          iks_insert_node(query, google);
01381          iks_insert_node(query, disco);
01382          ast_aji_send(client, iq);
01383       } else
01384          ast_log(LOG_ERROR, "Out of Memory.\n");
01385 
01386       iks_delete(iq);
01387       iks_delete(query);
01388       iks_delete(ident);
01389       iks_delete(google);
01390       iks_delete(disco);
01391    } else if (pak->subtype == IKS_TYPE_ERROR) {
01392       ast_log(LOG_NOTICE, "User %s does not support discovery.\n", pak->from->full);
01393    }
01394    ASTOBJ_UNREF(client, aji_client_destroy);
01395    return IKS_FILTER_EAT;
01396 }

static int aji_create_buddy ( char *  label,
struct aji_client *  client 
) [static]

creates buddy.

Parameters:
label char.
client the configured XMPP client we use to connect to a XMPP server
Returns:
1 on success, 0 on failure. load config file.

1.

Definition at line 2873 of file res_jabber.c.

References aji_buddy_destroy(), ast_calloc, ast_copy_string(), ast_log(), ASTOBJ_CONTAINER_FIND, ASTOBJ_CONTAINER_LINK, ASTOBJ_INIT, ASTOBJ_UNLOCK, ASTOBJ_UNMARK, ASTOBJ_UNREF, ASTOBJ_WRLOCK, aji_client::buddies, LOG_WARNING, and aji_buddy::name.

Referenced by aji_create_client(), aji_handle_presence(), and aji_handle_subscribe().

static int aji_create_client ( char *  label,
struct ast_variable *  var,
int  debug 
) [static]

creates aji_client structure.

Parameters:
label 
var ast_variable
debug 
Returns:
0.

Definition at line 2653 of file res_jabber.c.

References AJI_AUTOPRUNE, AJI_AUTOREGISTER, aji_create_buddy(), AJI_DISCONNECTED, ast_calloc, ast_copy_flags, ast_copy_string(), ast_false(), AST_FLAGS_ALL, AST_LIST_HEAD_INIT, ast_log(), ast_set2_flag, ast_true(), ASTOBJ_CONTAINER_FIND, ASTOBJ_CONTAINER_INIT, ASTOBJ_CONTAINER_MARKALL, ASTOBJ_INIT, ASTOBJ_UNMARK, ASTOBJ_WRLOCK, aji_client::authorized, aji_client::buddies, clients, aji_client::component, aji_client::debug, aji_client::flags, aji_client::forcessl, aji_client::keepalive, LOG_ERROR, LOG_WARNING, aji_client::message_timeout, aji_client::messages, aji_client::mid, ast_variable::name, aji_client::name, ast_variable::next, aji_client::password, aji_client::port, aji_client::priority, aji_client::serverhost, aji_client::state, aji_client::status, aji_client::statusmessage, aji_client::timeout, aji_client::user, aji_client::usesasl, aji_client::usetls, and ast_variable::value.

Referenced by aji_load_config().

02654 {
02655    char *resource;
02656    struct aji_client *client = NULL;
02657    int flag = 0;
02658 
02659    client = ASTOBJ_CONTAINER_FIND(&clients,label);
02660    if (!client) {
02661       flag = 1;
02662       client = ast_calloc(1, sizeof(*client));
02663       if (!client) {
02664          ast_log(LOG_ERROR, "Out of memory!\n");
02665          return 0;
02666       }
02667       ASTOBJ_INIT(client);
02668       ASTOBJ_WRLOCK(client);
02669       ASTOBJ_CONTAINER_INIT(&client->buddies);
02670    } else {
02671       ASTOBJ_WRLOCK(client);
02672       ASTOBJ_UNMARK(client);
02673    }
02674    ASTOBJ_CONTAINER_MARKALL(&client->buddies);
02675    ast_copy_string(client->name, label, sizeof(client->name));
02676    ast_copy_string(client->mid, "aaaaa", sizeof(client->mid));
02677 
02678    /* Set default values for the client object */
02679    client->debug = debug;
02680    ast_copy_flags(&client->flags, &globalflags, AST_FLAGS_ALL);
02681    client->port = 5222;
02682    client->usetls = 1;
02683    client->usesasl = 1;
02684    client->forcessl = 0;
02685    client->keepalive = 1;
02686    client->timeout = 50;
02687    client->message_timeout = 100;
02688    AST_LIST_HEAD_INIT(&client->messages);
02689    client->component = 0;
02690    ast_copy_string(client->statusmessage, "Online and Available", sizeof(client->statusmessage));
02691    client->priority = 0;
02692    client->status = IKS_SHOW_AVAILABLE;
02693 
02694    if (flag) {
02695       client->authorized = 0;
02696       client->state = AJI_DISCONNECTED;
02697    }
02698    while (var) {
02699       if (!strcasecmp(var->name, "username"))
02700          ast_copy_string(client->user, var->value, sizeof(client->user));
02701       else if (!strcasecmp(var->name, "serverhost"))
02702          ast_copy_string(client->serverhost, var->value, sizeof(client->serverhost));
02703       else if (!strcasecmp(var->name, "secret"))
02704          ast_copy_string(client->password, var->value, sizeof(client->password));
02705       else if (!strcasecmp(var->name, "statusmessage"))
02706          ast_copy_string(client->statusmessage, var->value, sizeof(client->statusmessage));
02707       else if (!strcasecmp(var->name, "port"))
02708          client->port = atoi(var->value);
02709       else if (!strcasecmp(var->name, "timeout"))
02710          client->message_timeout = atoi(var->value);
02711       else if (!strcasecmp(var->name, "debug"))
02712          client->debug = (ast_false(var->value)) ? 0 : 1;
02713       else if (!strcasecmp(var->name, "type")) {
02714          if (!strcasecmp(var->value, "component"))
02715             client->component = 1;
02716       } else if (!strcasecmp(var->name, "usetls")) {
02717          client->usetls = (ast_false(var->value)) ? 0 : 1;
02718       } else if (!strcasecmp(var->name, "usesasl")) {
02719          client->usesasl = (ast_false(var->value)) ? 0 : 1;
02720       } else if (!strcasecmp(var->name, "forceoldssl"))
02721          client->forcessl = (ast_false(var->value)) ? 0 : 1;
02722       else if (!strcasecmp(var->name, "keepalive"))
02723          client->keepalive = (ast_false(var->value)) ? 0 : 1;
02724       else if (!strcasecmp(var->name, "autoprune"))
02725          ast_set2_flag(&client->flags, ast_true(var->value), AJI_AUTOPRUNE);
02726       else if (!strcasecmp(var->name, "autoregister"))
02727          ast_set2_flag(&client->flags, ast_true(var->value), AJI_AUTOREGISTER);
02728       else if (!strcasecmp(var->name, "buddy"))
02729          aji_create_buddy((char *)var->value, client);
02730       else if (!strcasecmp(var->name, "priority"))
02731          client->priority = atoi(var->value);
02732       else if (!strcasecmp(var->name, "status")) {
02733          if (!strcasecmp(var->value, "unavailable"))
02734             client->status = IKS_SHOW_UNAVAILABLE;
02735          else
02736          if (!strcasecmp(var->value, "available")
02737           || !strcasecmp(var->value, "online"))
02738             client->status = IKS_SHOW_AVAILABLE;
02739          else
02740          if (!strcasecmp(var->value, "chat")
02741           || !strcasecmp(var->value, "chatty"))
02742             client->status = IKS_SHOW_CHAT;
02743          else
02744          if (!strcasecmp(var->value, "away"))
02745             client->status = IKS_SHOW_AWAY;
02746          else
02747          if (!strcasecmp(var->value, "xa")
02748           || !strcasecmp(var->value, "xaway"))
02749             client->status = IKS_SHOW_XA;
02750          else
02751          if (!strcasecmp(var->value, "dnd"))
02752             client->status = IKS_SHOW_DND;
02753          else
02754          if (!strcasecmp(var->value, "invisible"))
02755          #ifdef IKS_SHOW_INVISIBLE
02756             client->status = IKS_SHOW_INVISIBLE;
02757          #else
02758          {
02759             ast_log(LOG_WARNING, "Your iksemel doesn't support invisible status: falling back to DND\n");
02760             client->status = IKS_SHOW_DND;
02761          }
02762          #endif
02763          else
02764             ast_log(LOG_WARNING, "Unknown presence status: %s\n", var->value);
02765       }
02766    /* no transport support in this version */
02767    /* else if (!strcasecmp(var->name, "transport"))
02768             aji_create_transport(var->value, client);
02769    */
02770       var = var->next;
02771    }
02772    if (!flag) {
02773       ASTOBJ_UNLOCK(client);
02774       ASTOBJ_UNREF(client, aji_client_destroy);
02775       return 1;
02776    }
02777 
02778    ast_copy_string(client->name_space, (client->component) ? "jabber:component:accept" : "jabber:client", sizeof(client->name_space));
02779    client->p = iks_stream_new(client->name_space, client, aji_act_hook);
02780    if (!client->p) {
02781       ast_log(LOG_ERROR, "Failed to create stream for client '%s'!\n", client->name);
02782       return 0;
02783    }
02784    client->stack = iks_stack_new(8192, 8192);
02785    if (!client->stack) {
02786       ast_log(LOG_ERROR, "Failed to allocate stack for client '%s'\n", client->name);
02787       return 0;
02788    }
02789    client->f = iks_filter_new();
02790    if (!client->f) {
02791       ast_log(LOG_ERROR, "Failed to create filter for client '%s'\n", client->name);
02792       return 0;
02793    }
02794    if (!strchr(client->user, '/') && !client->component) { /*client */
02795       resource = NULL;
02796       if (asprintf(&resource, "%s/asterisk", client->user) >= 0) {
02797          client->jid = iks_id_new(client->stack, resource);
02798          ast_free(resource);
02799       }
02800    } else
02801       client->jid = iks_id_new(client->stack, client->user);
02802    if (client->component) {
02803       iks_filter_add_rule(client->f, aji_dinfo_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
02804       iks_filter_add_rule(client->f, aji_ditems_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#items", IKS_RULE_DONE);
02805       iks_filter_add_rule(client->f, aji_register_query_handler, client, IKS_RULE_SUBTYPE, IKS_TYPE_GET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
02806       iks_filter_add_rule(client->f, aji_register_approve_handler, client, IKS_RULE_SUBTYPE, IKS_TYPE_SET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
02807    } else {
02808       iks_filter_add_rule(client->f, aji_client_info_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
02809    }
02810    iks_set_log_hook(client->p, aji_log_hook);
02811    ASTOBJ_UNLOCK(client);
02812    ASTOBJ_CONTAINER_LINK(&clients,client);
02813    return 1;
02814 }

static int aji_dinfo_handler ( void *  data,
ikspak *  pak 
) [static]

Handler of the return info packet.

Parameters:
data aji_client
pak ikspak
Returns:
IKS_FILTER_EAT

Definition at line 1403 of file res_jabber.c.

References aji_client_destroy(), aji_find_resource(), ast_aji_send(), ast_log(), ASTOBJ_CONTAINER_FIND, ASTOBJ_REF, ASTOBJ_UNREF, aji_client::buddies, aji_resource::cap, commands, aji_version::jingle, LOG_ERROR, LOG_NOTICE, LOG_WARNING, aji_resource::resource, aji_client::user, and version.

01404 {
01405    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
01406    char *node = NULL;
01407    struct aji_resource *resource = NULL;
01408    struct aji_buddy *buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, pak->from->partial);
01409 
01410    resource = aji_find_resource(buddy, pak->from->resource);
01411    if (pak->subtype == IKS_TYPE_ERROR) {
01412       ast_log(LOG_WARNING, "Received error from a client, turn on jabber debug!\n");
01413       return IKS_FILTER_EAT;
01414    }
01415    if (pak->subtype == IKS_TYPE_RESULT) {
01416       if (!resource) {
01417          ast_log(LOG_NOTICE,"JABBER: Received client info from %s when not requested.\n", pak->from->full);
01418          ASTOBJ_UNREF(client, aji_client_destroy);
01419          return IKS_FILTER_EAT;
01420       }
01421       if (iks_find_with_attrib(pak->query, "feature", "var", "http://www.google.com/xmpp/protocol/voice/v1")) {
01422          resource->cap->jingle = 1;
01423       } else
01424          resource->cap->jingle = 0;
01425    } else if (pak->subtype == IKS_TYPE_GET && !(node = iks_find_attrib(pak->query, "node"))) {
01426       iks *iq, *query, *identity, *disco, *reg, *commands, *gateway, *version, *vcard, *search;
01427 
01428       iq = iks_new("iq");
01429       query = iks_new("query");
01430       identity = iks_new("identity");
01431       disco = iks_new("feature");
01432       reg = iks_new("feature");
01433       commands = iks_new("feature");
01434       gateway = iks_new("feature");
01435       version = iks_new("feature");
01436       vcard = iks_new("feature");
01437       search = iks_new("feature");
01438 
01439       if (iq && query && identity && disco && reg && commands && gateway && version && vcard && search && client) {
01440          iks_insert_attrib(iq, "from", client->user);
01441          iks_insert_attrib(iq, "to", pak->from->full);
01442          iks_insert_attrib(iq, "id", pak->id);
01443          iks_insert_attrib(iq, "type", "result");
01444          iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
01445          iks_insert_attrib(identity, "category", "gateway");
01446          iks_insert_attrib(identity, "type", "pstn");
01447          iks_insert_attrib(identity, "name", "Asterisk The Open Source PBX");
01448          iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco");
01449          iks_insert_attrib(reg, "var", "jabber:iq:register");
01450          iks_insert_attrib(commands, "var", "http://jabber.org/protocol/commands");
01451          iks_insert_attrib(gateway, "var", "jabber:iq:gateway");
01452          iks_insert_attrib(version, "var", "jabber:iq:version");
01453          iks_insert_attrib(vcard, "var", "vcard-temp");
01454          iks_insert_attrib(search, "var", "jabber:iq:search");
01455 
01456          iks_insert_node(iq, query);
01457          iks_insert_node(query, identity);
01458          iks_insert_node(query, disco);
01459          iks_insert_node(query, reg);
01460          iks_insert_node(query, commands);
01461          iks_insert_node(query, gateway);
01462          iks_insert_node(query, version);
01463          iks_insert_node(query, vcard);
01464          iks_insert_node(query, search);
01465          ast_aji_send(client, iq);
01466       } else {
01467          ast_log(LOG_ERROR, "Out of memory.\n");
01468       }
01469 
01470       iks_delete(iq);
01471       iks_delete(query);
01472       iks_delete(identity);
01473       iks_delete(disco);
01474       iks_delete(reg);
01475       iks_delete(commands);
01476       iks_delete(gateway);
01477       iks_delete(version);
01478       iks_delete(vcard);
01479       iks_delete(search);
01480 
01481    } else if (pak->subtype == IKS_TYPE_GET && !strcasecmp(node, "http://jabber.org/protocol/commands")) {
01482       iks *iq, *query, *confirm;
01483       iq = iks_new("iq");
01484       query = iks_new("query");
01485       confirm = iks_new("item");
01486 
01487       if (iq && query && confirm && client) {
01488          iks_insert_attrib(iq, "from", client->user);
01489          iks_insert_attrib(iq, "to", pak->from->full);
01490          iks_insert_attrib(iq, "id", pak->id);
01491          iks_insert_attrib(iq, "type", "result");
01492          iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
01493          iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
01494          iks_insert_attrib(confirm, "node", "confirmaccount");
01495          iks_insert_attrib(confirm, "name", "Confirm AIM account");
01496          iks_insert_attrib(confirm, "jid", client->user);
01497          iks_insert_node(iq, query);
01498          iks_insert_node(query, confirm);
01499          ast_aji_send(client, iq);
01500       } else {
01501          ast_log(LOG_ERROR, "Out of memory.\n");
01502       }
01503 
01504       iks_delete(iq);
01505       iks_delete(query);
01506       iks_delete(confirm);
01507 
01508    } else if (pak->subtype == IKS_TYPE_GET && !strcasecmp(node, "confirmaccount")) {
01509       iks *iq, *query, *feature;
01510 
01511       iq = iks_new("iq");
01512       query = iks_new("query");
01513       feature = iks_new("feature");
01514 
01515       if (iq && query && feature && client) {
01516          iks_insert_attrib(iq, "from", client->user);
01517          iks_insert_attrib(iq, "to", pak->from->full);
01518          iks_insert_attrib(iq, "id", pak->id);
01519          iks_insert_attrib(iq, "type", "result");
01520          iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
01521          iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
01522          iks_insert_node(iq, query);
01523          iks_insert_node(query, feature);
01524          ast_aji_send(client, iq);
01525       } else {
01526          ast_log(LOG_ERROR, "Out of memory.\n");
01527       }
01528 
01529       iks_delete(iq);
01530       iks_delete(query);
01531       iks_delete(feature);
01532    }
01533 
01534    ASTOBJ_UNREF(client, aji_client_destroy);
01535    return IKS_FILTER_EAT;
01536 }

static int aji_ditems_handler ( void *  data,
ikspak *  pak 
) [static]

Handles stuff.

Parameters:
data void
pak ikspak
Returns:
IKS_FILTER_EAT.

Definition at line 1248 of file res_jabber.c.

References aji_client_destroy(), ast_aji_send(), ast_log(), ASTOBJ_REF, ASTOBJ_UNREF, LOG_ERROR, and aji_client::user.

01249 {
01250    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
01251    char *node = NULL;
01252 
01253    if (!(node = iks_find_attrib(pak->query, "node"))) {
01254       iks *iq = NULL, *query = NULL, *item = NULL;
01255       iq = iks_new("iq");
01256       query = iks_new("query");
01257       item = iks_new("item");
01258 
01259       if (iq && query && item) {
01260          iks_insert_attrib(iq, "from", client->user);
01261          iks_insert_attrib(iq, "to", pak->from->full);
01262          iks_insert_attrib(iq, "id", pak->id);
01263          iks_insert_attrib(iq, "type", "result");
01264          iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
01265          iks_insert_attrib(item, "node", "http://jabber.org/protocol/commands");
01266          iks_insert_attrib(item, "name", "Million Dollar Asterisk Commands");
01267          iks_insert_attrib(item, "jid", client->user);
01268 
01269          iks_insert_node(iq, query);
01270          iks_insert_node(query, item);
01271          ast_aji_send(client, iq);
01272       } else {
01273          ast_log(LOG_ERROR, "Out of memory.\n");
01274       }
01275 
01276       iks_delete(iq);
01277       iks_delete(query);
01278       iks_delete(item);
01279 
01280    } else if (!strcasecmp(node, "http://jabber.org/protocol/commands")) {
01281       iks *iq, *query, *confirm;
01282       iq = iks_new("iq");
01283       query = iks_new("query");
01284       confirm = iks_new("item");
01285       if (iq && query && confirm && client) {
01286          iks_insert_attrib(iq, "from", client->user);
01287          iks_insert_attrib(iq, "to", pak->from->full);
01288          iks_insert_attrib(iq, "id", pak->id);
01289          iks_insert_attrib(iq, "type", "result");
01290          iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
01291          iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
01292          iks_insert_attrib(confirm, "node", "confirmaccount");
01293          iks_insert_attrib(confirm, "name", "Confirm AIM account");
01294          iks_insert_attrib(confirm, "jid", "blog.astjab.org");
01295 
01296          iks_insert_node(iq, query);
01297          iks_insert_node(query, confirm);
01298          ast_aji_send(client, iq);
01299       } else {
01300          ast_log(LOG_ERROR, "Out of memory.\n");
01301       }
01302 
01303       iks_delete(iq);
01304       iks_delete(query);
01305       iks_delete(confirm);
01306 
01307    } else if (!strcasecmp(node, "confirmaccount")) {
01308       iks *iq = NULL, *query = NULL, *feature = NULL;
01309 
01310       iq = iks_new("iq");
01311       query = iks_new("query");
01312       feature = iks_new("feature");
01313 
01314       if (iq && query && feature && client) {
01315          iks_insert_attrib(iq, "from", client->user);
01316          iks_insert_attrib(iq, "to", pak->from->full);
01317          iks_insert_attrib(iq, "id", pak->id);
01318          iks_insert_attrib(iq, "type", "result");
01319          iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
01320          iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
01321          iks_insert_node(iq, query);
01322          iks_insert_node(query, feature);
01323          ast_aji_send(client, iq);
01324       } else {
01325          ast_log(LOG_ERROR, "Out of memory.\n");
01326       }
01327 
01328       iks_delete(iq);
01329       iks_delete(query);
01330       iks_delete(feature);
01331    }
01332 
01333    ASTOBJ_UNREF(client, aji_client_destroy);
01334    return IKS_FILTER_EAT;
01335 
01336 }

static char * aji_do_reload ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Reload jabber module.

Returns:
CLI_SUCCESS.

Definition at line 2475 of file res_jabber.c.

References aji_reload(), ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.

02476 {
02477    switch (cmd) {
02478    case CLI_INIT:
02479       e->command = "jabber reload";
02480       e->usage =
02481          "Usage: jabber reload\n"
02482          "       Reloads the Jabber module.\n";
02483       return NULL;
02484    case CLI_GENERATE:
02485       return NULL;
02486    }
02487 
02488    aji_reload(1);
02489    ast_cli(a->fd, "Jabber Reloaded.\n");
02490    return CLI_SUCCESS;
02491 }

static char * aji_do_set_debug ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Turn on/off console debugging.

Returns:
CLI_SUCCESS.

Definition at line 2435 of file res_jabber.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, clients, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.

02436 {
02437    switch (cmd) {
02438    case CLI_INIT:
02439       e->command = "jabber set debug {on|off}";
02440       e->usage =
02441          "Usage: jabber set debug {on|off}\n"
02442          "       Enables/disables dumping of XMPP/Jabber packets for debugging purposes.\n";
02443       return NULL;
02444    case CLI_GENERATE:
02445       return NULL;
02446    }
02447 
02448    if (a->argc != e->args)
02449       return CLI_SHOWUSAGE;
02450 
02451    if (!strncasecmp(a->argv[e->args - 1], "on", 2)) {
02452       ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
02453          ASTOBJ_RDLOCK(iterator); 
02454          iterator->debug = 1;
02455          ASTOBJ_UNLOCK(iterator);
02456       });
02457       ast_cli(a->fd, "Jabber Debugging Enabled.\n");
02458       return CLI_SUCCESS;
02459    } else if (!strncasecmp(a->argv[e->args - 1], "off", 3)) {
02460       ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
02461          ASTOBJ_RDLOCK(iterator); 
02462          iterator->debug = 0;
02463          ASTOBJ_UNLOCK(iterator);
02464       });
02465       ast_cli(a->fd, "Jabber Debugging Disabled.\n");
02466       return CLI_SUCCESS;
02467    }
02468    return CLI_SHOWUSAGE; /* defaults to invalid */
02469 }

static int aji_filter_roster ( void *  data,
ikspak *  pak 
) [static]

filters the roster packet we get back from server.

Parameters:
data void
pak ikspak iksemel packet.
Returns:
IKS_FILTER_EAT.

Definition at line 2190 of file res_jabber.c.

References AJI_AUTOPRUNE, AJI_AUTOREGISTER, AJI_CONNECTED, ast_clear_flag, ast_copy_flags, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_REF, ASTOBJ_UNLOCK, aji_client::buddies, aji_client::flags, and aji_client::state.

Referenced by aji_client_connect().

02191 {
02192    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
02193    int flag = 0;
02194    iks *x = NULL;
02195    struct aji_buddy *buddy;
02196    
02197    client->state = AJI_CONNECTED;
02198    ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
02199       ASTOBJ_RDLOCK(iterator);
02200       x = iks_child(pak->query);
02201       flag = 0;
02202       while (x) {
02203          if (!iks_strcmp(iks_name(x), "item")) {
02204             if (!strcasecmp(iterator->name, iks_find_attrib(x, "jid"))) {
02205                flag = 1;
02206                ast_clear_flag(&iterator->flags, AJI_AUTOPRUNE | AJI_AUTOREGISTER);
02207             }
02208          }
02209          x = iks_next(x);
02210       }
02211       if (!flag)
02212          ast_copy_flags(&iterator->flags, &client->flags, AJI_AUTOREGISTER);
02213       iks_delete(x);
02214       
02215       ASTOBJ_UNLOCK(iterator);
02216    });
02217 
02218    x = iks_child(pak->query);
02219    while (x) {
02220       flag = 0;
02221       if (iks_strcmp(iks_name(x), "item") == 0) {
02222          ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
02223             ASTOBJ_RDLOCK(iterator);
02224             if (!strcasecmp(iterator->name, iks_find_attrib(x, "jid")))
02225                flag = 1;
02226             ASTOBJ_UNLOCK(iterator);
02227          });
02228 
02229          if (flag) {
02230             /* found buddy, don't create a new one */
02231             x = iks_next(x);
02232             continue;
02233          }
02234          
02235          buddy = ast_calloc(1, sizeof(*buddy));
02236          if (!buddy) {
02237             ast_log(LOG_WARNING, "Out of memory\n");
02238             return 0;
02239          }
02240          ASTOBJ_INIT(buddy);
02241          ASTOBJ_WRLOCK(buddy);
02242          ast_copy_string(buddy->name, iks_find_attrib(x, "jid"), sizeof(buddy->name));
02243          ast_clear_flag(&buddy->flags, AST_FLAGS_ALL);
02244          if(ast_test_flag(&client->flags, AJI_AUTOPRUNE)) {
02245             ast_set_flag(&buddy->flags, AJI_AUTOPRUNE);
02246             ASTOBJ_MARK(buddy);
02247          } else if (!iks_strcmp(iks_find_attrib(x, "subscription"), "none") || !iks_strcmp(iks_find_attrib(x, "subscription"), "from")) {
02248             /* subscribe to buddy's presence only 
02249                if we really need to */
02250             ast_set_flag(&buddy->flags, AJI_AUTOREGISTER);
02251          }
02252          ASTOBJ_UNLOCK(buddy);
02253          if (buddy) {
02254             ASTOBJ_CONTAINER_LINK(&client->buddies, buddy);
02255             ASTOBJ_UNREF(buddy, aji_buddy_destroy);
02256          }
02257       }
02258       x = iks_next(x);
02259    }
02260 
02261    iks_delete(x);
02262    aji_pruneregister(client);
02263 
02264    ASTOBJ_UNREF(client, aji_client_destroy);
02265    return IKS_FILTER_EAT;
02266 }

static struct aji_resource* aji_find_resource ( struct aji_buddy *  buddy,
char *  name 
) [static, read]

Find the aji_resource we want.

Parameters:
buddy aji_buddy A buddy
name 
Returns:
aji_resource object

Definition at line 370 of file res_jabber.c.

References aji_resource::next, aji_resource::resource, and aji_buddy::resources.

Referenced by acf_jabberstatus_read(), aji_client_info_handler(), aji_dinfo_handler(), and aji_status_exec().

00371 {
00372    struct aji_resource *res = NULL;
00373    if (!buddy || !name)
00374       return res;
00375    res = buddy->resources;
00376    while (res) {
00377       if (!strcasecmp(res->resource, name)) {
00378          break;
00379       }
00380       res = res->next;
00381    }
00382    return res;
00383 }

static struct aji_version* aji_find_version ( char *  node,
char *  version,
ikspak *  pak 
) [static, read]

Find version in XML stream and populate our capabilities list.

Parameters:
node the node attribute in the caps element we'll look for or add to our list
version the version attribute in the caps element we'll look for or add to our list
pak struct The XML stanza we're processing
Returns:
a pointer to the added or found aji_version structure

Definition at line 303 of file res_jabber.c.

References ast_copy_string(), ast_free, ast_log(), ast_malloc, aji_version::jingle, LOG_ERROR, aji_capabilities::next, aji_version::next, aji_capabilities::node, aji_version::parent, aji_version::version, and aji_capabilities::versions.

Referenced by aji_handle_presence().

00304 {
00305    struct aji_capabilities *list = NULL;
00306    struct aji_version *res = NULL;
00307 
00308    list = capabilities;
00309 
00310    if(!node)
00311       node = pak->from->full;
00312    if(!version)
00313       version = "none supplied.";
00314    while(list) {
00315       if(!strcasecmp(list->node, node)) {
00316          res = list->versions;
00317          while(res) {
00318              if(!strcasecmp(res->version, version))
00319                 return res;
00320              res = res->next;
00321          }
00322          /* Specified version not found. Let's add it to 
00323             this node in our capabilities list */
00324          if(!res) {
00325             res = ast_malloc(sizeof(*res));
00326             if(!res) {
00327                ast_log(LOG_ERROR, "Out of memory!\n");
00328                return NULL;
00329             }
00330             res->jingle = 0;
00331             res->parent = list;
00332             ast_copy_string(res->version, version, sizeof(res->version));
00333             res->next = list->versions;
00334             list->versions = res;
00335             return res;
00336          }
00337       }
00338       list = list->next;
00339    }
00340    /* Specified node not found. Let's add it our capabilities list */
00341    if(!list) {
00342       list = ast_malloc(sizeof(*list));
00343       if(!list) {
00344          ast_log(LOG_ERROR, "Out of memory!\n");
00345          return NULL;
00346       }
00347       res = ast_malloc(sizeof(*res));
00348       if(!res) {
00349          ast_log(LOG_ERROR, "Out of memory!\n");
00350          ast_free(list);
00351          return NULL;
00352       }
00353       ast_copy_string(list->node, node, sizeof(list->node));
00354       ast_copy_string(res->version, version, sizeof(res->version));
00355       res->jingle = 0;
00356       res->parent = list;
00357       res->next = NULL;
00358       list->versions = res;
00359       list->next = capabilities;
00360       capabilities = list;
00361    }
00362    return res;
00363 }

static int aji_get_roster ( struct aji_client *  client  )  [static]

Get the roster of jabber users.

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

Definition at line 2295 of file res_jabber.c.

References aji_set_presence(), ast_aji_send(), aji_client::jid, aji_client::status, and aji_client::statusmessage.

Referenced by aji_client_connect(), and aji_reload().

02296 {
02297    iks *roster = NULL;
02298    roster = iks_make_iq(IKS_TYPE_GET, IKS_NS_ROSTER);
02299 
02300    if(roster) {
02301       iks_insert_attrib(roster, "id", "roster");
02302       aji_set_presence(client, NULL, client->jid->full, client->status, client->statusmessage);
02303       ast_aji_send(client, roster);
02304    }
02305 
02306    iks_delete(roster);
02307    
02308    return 1;
02309 }

static void aji_handle_iq ( struct aji_client *  client,
iks *  node 
) [static]

Handles.

<iq> 
tags.
Parameters:
client the configured XMPP client we use to connect to a XMPP server
node iks
Returns:
void.

Definition at line 1544 of file res_jabber.c.

Referenced by aji_act_hook().

01545 {
01546    /*Nothing to see here */
01547 }

static void aji_handle_message ( struct aji_client *  client,
ikspak *  pak 
) [static]

Handles presence packets.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
pak ikspak the node

Definition at line 1554 of file res_jabber.c.

References aji_message::arrived, ast_calloc, ast_copy_string(), ast_free, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_strdup, aji_message::from, aji_message::id, aji_message::list, aji_message::message, aji_client::message_timeout, and aji_client::messages.

Referenced by aji_act_hook().

01555 {
01556    struct aji_message *insert, *tmp;
01557    int flag = 0;
01558    
01559    if (!(insert = ast_calloc(1, sizeof(*insert))))
01560       return;
01561    time(&insert->arrived);
01562    if (iks_find_cdata(pak->x, "body"))
01563       insert->message = ast_strdup(iks_find_cdata(pak->x, "body"));
01564    if (pak->id)
01565       ast_copy_string(insert->id, pak->id, sizeof(insert->message));
01566    if (pak->from)
01567       insert->from = ast_strdup(pak->from->full);
01568    AST_LIST_LOCK(&client->messages);
01569    AST_LIST_TRAVERSE_SAFE_BEGIN(&client->messages, tmp, list) {
01570       if (flag) {
01571          AST_LIST_REMOVE_CURRENT(list);
01572          if (tmp->from)
01573             ast_free(tmp->from);
01574          if (tmp->message)
01575             ast_free(tmp->message);
01576       } else if (difftime(time(NULL), tmp->arrived) >= client->message_timeout) {
01577          flag = 1;
01578          AST_LIST_REMOVE_CURRENT(list);
01579          if (tmp->from)
01580             ast_free(tmp->from);
01581          if (tmp->message)
01582             ast_free(tmp->message);
01583       }
01584    }
01585    AST_LIST_TRAVERSE_SAFE_END;
01586    AST_LIST_INSERT_HEAD(&client->messages, insert, list);
01587    AST_LIST_UNLOCK(&client->messages);
01588 }

static void aji_handle_presence ( struct aji_client *  client,
ikspak *  pak 
) [static]

Check the presence info.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
pak ikspak

Definition at line 1594 of file res_jabber.c.

References aji_buddy_destroy(), AJI_CONNECTED, aji_create_buddy(), aji_find_version(), aji_set_presence(), ast_aji_increment_mid(), ast_aji_send(), ast_calloc, ast_copy_string(), ast_debug, ast_free, ast_log(), ast_strdup, ast_verbose, ASTOBJ_CONTAINER_FIND, ASTOBJ_UNLOCK, ASTOBJ_UNREF, ASTOBJ_WRLOCK, aji_client::buddies, aji_client::component, descrip, aji_resource::description, gtalk_yuck(), aji_client::jid, last, LOG_ERROR, LOG_NOTICE, aji_client::mid, aji_resource::next, option_debug, aji_resource::priority, aji_resource::resource, aji_buddy::resources, aji_client::state, aji_resource::status, aji_client::status, status, aji_client::statusmessage, type, and ver.

Referenced by aji_act_hook().

01595 {
01596    int status, priority;
01597    struct aji_buddy *buddy;
01598    struct aji_resource *tmp = NULL, *last = NULL, *found = NULL;
01599    char *ver, *node, *descrip, *type;
01600    
01601    if(client->state != AJI_CONNECTED)
01602       aji_create_buddy(pak->from->partial, client);
01603 
01604    buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, pak->from->partial);
01605    if (!buddy && pak->from->partial) {
01606       /* allow our jid to be used to log in with another resource */
01607       if (!strcmp((const char *)pak->from->partial, (const char *)client->jid->partial))
01608          aji_create_buddy(pak->from->partial, client);
01609       else
01610          ast_log(LOG_NOTICE, "Got presence packet from %s, someone not in our roster!!!!\n", pak->from->partial);
01611       return;
01612    }
01613    type = iks_find_attrib(pak->x, "type");
01614    if(client->component && type &&!strcasecmp("probe", type)) {
01615       aji_set_presence(client, pak->from->full, iks_find_attrib(pak->x, "to"), client->status, client->statusmessage);
01616       ast_verbose("what i was looking for \n");
01617    }
01618    ASTOBJ_WRLOCK(buddy);
01619    status = (pak->show) ? pak->show : 6;
01620    priority = atoi((iks_find_cdata(pak->x, "priority")) ? iks_find_cdata(pak->x, "priority") : "0");
01621    tmp = buddy->resources;
01622    descrip = ast_strdup(iks_find_cdata(pak->x,"status"));
01623 
01624    while (tmp && pak->from->resource) {
01625       if (!strcasecmp(tmp->resource, pak->from->resource)) {
01626          tmp->status = status;
01627          if (tmp->description) ast_free(tmp->description);
01628          tmp->description = descrip;
01629          found = tmp;
01630          if (status == 6) {   /* Sign off Destroy resource */
01631             if (last && found->next) {
01632                last->next = found->next;
01633             } else if (!last) {
01634                if (found->next)
01635                   buddy->resources = found->next;
01636                else
01637                   buddy->resources = NULL;
01638             } else if (!found->next) {
01639                if (last)
01640                   last->next = NULL;
01641                else
01642                   buddy->resources = NULL;
01643             }
01644             ast_free(found);
01645             found = NULL;
01646             break;
01647          }
01648          /* resource list is sorted by descending priority */
01649          if (tmp->priority != priority) {
01650             found->priority = priority;
01651             if (!last && !found->next)
01652                /* resource was found to be unique,
01653                   leave loop */
01654                break;
01655             /* search for resource in our list
01656                and take it out for the moment */
01657             if (last)
01658                last->next = found->next;
01659             else
01660                buddy->resources = found->next;
01661 
01662             last = NULL;
01663             tmp = buddy->resources;
01664             if (!buddy->resources)
01665                buddy->resources = found;
01666             /* priority processing */
01667             while (tmp) {
01668                /* insert resource back according to 
01669                   its priority value */
01670                if (found->priority > tmp->priority) {
01671                   if (last)
01672                      /* insert within list */
01673                      last->next = found;
01674                   found->next = tmp;
01675                   if (!last)
01676                      /* insert on top */
01677                      buddy->resources = found;
01678                   break;
01679                }
01680                if (!tmp->next) {
01681                   /* insert at the end of the list */
01682                   tmp->next = found;
01683                   found->next = NULL;
01684                   break;
01685                }
01686                last = tmp;
01687                tmp = tmp->next;
01688             }
01689          }
01690          break;
01691       }
01692       last = tmp;
01693       tmp = tmp->next;
01694    }
01695 
01696    /* resource not found in our list, create it */
01697    if (!found && status != 6 && pak->from->resource) {
01698       found = ast_calloc(1, sizeof(*found));
01699 
01700       if (!found) {
01701          ast_log(LOG_ERROR, "Out of memory!\n");
01702          return;
01703       }
01704       ast_copy_string(found->resource, pak->from->resource, sizeof(found->resource));
01705       found->status = status;
01706       found->description = descrip;
01707       found->priority = priority;
01708       found->next = NULL;
01709       last = NULL;
01710       tmp = buddy->resources;
01711       while (tmp) {
01712          if (found->priority > tmp->priority) {
01713             if (last)
01714                last->next = found;
01715             found->next = tmp;
01716             if (!last)
01717                buddy->resources = found;
01718             break;
01719          }
01720          if (!tmp->next) {
01721             tmp->next = found;
01722             break;
01723          }
01724          last = tmp;
01725          tmp = tmp->next;
01726       }
01727       if (!tmp)
01728          buddy->resources = found;
01729    }
01730    
01731    ASTOBJ_UNLOCK(buddy);
01732    ASTOBJ_UNREF(buddy, aji_buddy_destroy);
01733 
01734    node = iks_find_attrib(iks_find(pak->x, "c"), "node");
01735    ver = iks_find_attrib(iks_find(pak->x, "c"), "ver");
01736 
01737    /* handle gmail client's special caps:c tag */
01738    if (!node && !ver) {
01739       node = iks_find_attrib(iks_find(pak->x, "caps:c"), "node");
01740       ver = iks_find_attrib(iks_find(pak->x, "caps:c"), "ver");
01741    }
01742 
01743    /* retrieve capabilites of the new resource */
01744    if(status !=6 && found && !found->cap) {
01745       found->cap = aji_find_version(node, ver, pak);
01746       if(gtalk_yuck(pak->x)) /* gtalk should do discover */
01747          found->cap->jingle = 1;
01748       if(found->cap->jingle && option_debug > 4) {
01749          ast_debug(1,"Special case for google till they support discover.\n");
01750       }
01751       else {
01752          iks *iq, *query;
01753          iq = iks_new("iq");
01754          query = iks_new("query");
01755          if(query && iq)  {
01756             iks_insert_attrib(iq, "type", "get");
01757             iks_insert_attrib(iq, "to", pak->from->full);
01758             iks_insert_attrib(iq,"from", client->jid->full);
01759             iks_insert_attrib(iq, "id", client->mid);
01760             ast_aji_increment_mid(client->mid);
01761             iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
01762             iks_insert_node(iq, query);
01763             ast_aji_send(client, iq);
01764             
01765          } else
01766             ast_log(LOG_ERROR, "Out of memory.\n");
01767          
01768          iks_delete(query);
01769          iks_delete(iq);
01770       }
01771    }
01772    switch (pak->subtype) {
01773    case IKS_TYPE_AVAILABLE:
01774       ast_debug(3, "JABBER: I am available ^_* %i\n", pak->subtype);
01775       break;
01776    case IKS_TYPE_UNAVAILABLE:
01777       ast_debug(3, "JABBER: I am unavailable ^_* %i\n", pak->subtype);
01778       break;
01779    default:
01780       ast_debug(3, "JABBER: Ohh sexy and the wrong type: %i\n", pak->subtype);
01781    }
01782    switch (pak->show) {
01783    case IKS_SHOW_UNAVAILABLE:
01784       ast_debug(3, "JABBER: type: %i subtype %i\n", pak->subtype, pak->show);
01785       break;
01786    case IKS_SHOW_AVAILABLE:
01787       ast_debug(3, "JABBER: type is available\n");
01788       break;
01789    case IKS_SHOW_CHAT:
01790       ast_debug(3, "JABBER: type: %i subtype %i\n", pak->subtype, pak->show);
01791       break;
01792    case IKS_SHOW_AWAY:
01793       ast_debug(3, "JABBER: type is away\n");
01794       break;
01795    case IKS_SHOW_XA:
01796       ast_debug(3, "JABBER: type: %i subtype %i\n", pak->subtype, pak->show);
01797       break;
01798    case IKS_SHOW_DND:
01799       ast_debug(3, "JABBER: type: %i subtype %i\n", pak->subtype, pak->show);
01800       break;
01801    default:
01802       ast_debug(3, "JABBER: Kinky! how did that happen %i\n", pak->show);
01803    }
01804 }

static void aji_handle_subscribe ( struct aji_client *  client,
ikspak *  pak 
) [static]

handles subscription requests.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
pak ikspak iksemel packet.
Returns:
void.

Definition at line 1812 of file res_jabber.c.

References aji_create_buddy(), aji_set_presence(), ast_aji_send(), ast_log(), ast_verbose, ASTOBJ_CONTAINER_FIND, aji_client::buddies, aji_client::component, aji_client::jid, LOG_ERROR, option_verbose, aji_client::status, status, aji_client::statusmessage, and VERBOSE_PREFIX_3.

Referenced by aji_act_hook().

01813 {
01814    iks *presence = NULL, *status = NULL;
01815    struct aji_buddy* buddy = NULL;
01816 
01817    switch (pak->subtype) { 
01818    case IKS_TYPE_SUBSCRIBE:
01819       presence = iks_new("presence");
01820       status = iks_new("status");
01821       if (presence && status) {
01822          iks_insert_attrib(presence, "type", "subscribed");
01823          iks_insert_attrib(presence, "to", pak->from->full);
01824          iks_insert_attrib(presence, "from", client->jid->full);
01825          if (pak->id)
01826             iks_insert_attrib(presence, "id", pak->id);
01827          iks_insert_cdata(status, "Asterisk has approved subscription", 0);
01828          iks_insert_node(presence, status);
01829          ast_aji_send(client, presence);
01830       } else
01831          ast_log(LOG_ERROR, "Unable to allocate nodes\n");
01832 
01833       iks_delete(presence);
01834       iks_delete(status);
01835 
01836       if (client->component)
01837          aji_set_presence(client, pak->from->full, iks_find_attrib(pak->x, "to"), client->status, client->statusmessage);
01838    case IKS_TYPE_SUBSCRIBED:
01839       buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, pak->from->partial);
01840       if (!buddy && pak->from->partial) {
01841          aji_create_buddy(pak->from->partial, client);
01842       }
01843    default:
01844       if (option_verbose > 4) {
01845          ast_verbose(VERBOSE_PREFIX_3 "JABBER: This is a subcription of type %i\n", pak->subtype);
01846       }
01847    }
01848 }

static int aji_initialize ( struct aji_client *  client  )  [static]

prepares client for connect.

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

Definition at line 2346 of file res_jabber.c.

References ast_log(), aji_client::component, connected, aji_client::jid, LOG_ERROR, aji_client::name, aji_client::p, aji_client::port, S_OR, aji_client::serverhost, aji_client::stream_flags, and aji_client::user.

Referenced by aji_reconnect().

02347 {
02348    int connected = IKS_NET_NOCONN;
02349 
02350 #ifdef HAVE_OPENSSL  
02351    /* reset stream flags */
02352    client->stream_flags = 0;
02353 #endif
02354    /* If it's a component, connect to user, otherwise, connect to server */
02355    connected = iks_connect_via(client->p, S_OR(client->serverhost, client->jid->server), client->port, client->component ? client->user : client->jid->server);
02356 
02357    if (connected == IKS_NET_NOCONN) {
02358       ast_log(LOG_ERROR, "JABBER ERROR: No Connection\n");
02359       return IKS_HOOK;
02360    } else   if (connected == IKS_NET_NODNS) {
02361       ast_log(LOG_ERROR, "JABBER ERROR: No DNS %s for client to  %s\n", client->name, S_OR(client->serverhost, client->jid->server));
02362       return IKS_HOOK;
02363    }
02364 
02365    return IKS_OK;
02366 }

static int aji_io_recv ( struct aji_client *  client,
char *  buffer,
size_t  buf_len,
int  timeout 
) [static]

Secured or unsecured IO socket receiving function.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
buffer the reception buffer
buf_len the size of the buffer
timeout the select timer
Returns:
the number of read bytes on success, 0 on timeout expiration, -1 on error

Definition at line 669 of file res_jabber.c.

References aji_is_secure(), ast_poll, len(), aji_client::p, and aji_client::ssl_session.

Referenced by aji_recv().

00670 {
00671    struct pollfd pfd = { .events = POLLIN };
00672    int len, res;
00673 
00674 #ifdef HAVE_OPENSSL
00675    if (aji_is_secure(client)) {
00676       pfd.fd = SSL_get_fd(client->ssl_session);
00677       if (pfd.fd < 0) {
00678          return -1;
00679       }
00680    } else
00681 #endif /* HAVE_OPENSSL */
00682       pfd.fd = iks_fd(client->p);
00683 
00684    res = ast_poll(&pfd, 1, timeout > 0 ? timeout * 1000 : -1);
00685    if (res > 0) {
00686 #ifdef HAVE_OPENSSL
00687       if (aji_is_secure(client)) {
00688          len = SSL_read(client->ssl_session, buffer, buf_len);
00689       } else
00690 #endif /* HAVE_OPENSSL */
00691          len = recv(pfd.fd, buffer, buf_len, 0);
00692 
00693       if (len > 0) {
00694          return len;
00695       } else if (len <= 0) {
00696          return -1;
00697       }
00698    }
00699    return res;
00700 }

static int aji_is_secure ( struct aji_client *  client  )  [static]

Tests whether the connection is secured or not.

Returns:
0 if the connection is not secured

Definition at line 583 of file res_jabber.c.

References aji_client::stream_flags.

Referenced by aji_act_hook(), aji_io_recv(), aji_send_raw(), and aji_start_sasl().

00584 {
00585 #ifdef HAVE_OPENSSL
00586    return client->stream_flags & SECURE;
00587 #else
00588    return 0;
00589 #endif
00590 }

static int aji_load_config ( int  reload  )  [static]

Definition at line 2900 of file res_jabber.c.

References AJI_AUTOPRUNE, AJI_AUTOREGISTER, aji_create_client(), ast_category_browse(), ast_config_destroy(), ast_config_load, ast_false(), ast_log(), ast_set2_flag, ast_set_flag, ast_true(), ast_variable_browse(), ast_variable_retrieve(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, debug, JABBER_CONFIG, LOG_WARNING, ast_variable::name, ast_variable::next, ast_variable::value, and var.

Referenced by aji_reload().

02901 {
02902    char *cat = NULL;
02903    int debug = 0;
02904    struct ast_config *cfg = NULL;
02905    struct ast_variable *var = NULL;
02906    struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
02907 
02908    if ((cfg = ast_config_load(JABBER_CONFIG, config_flags)) == CONFIG_STATUS_FILEUNCHANGED)
02909       return -1;
02910 
02911    /* Reset flags to default value */
02912    ast_set_flag(&globalflags, AJI_AUTOREGISTER);
02913 
02914    if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
02915       ast_log(LOG_WARNING, "No such configuration file %s\n", JABBER_CONFIG);
02916       return 0;
02917    }
02918 
02919    cat = ast_category_browse(cfg, NULL);
02920    for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
02921       if (!strcasecmp(var->name, "debug")) {
02922          debug = (ast_false(ast_variable_retrieve(cfg, "general", "debug"))) ? 0 : 1;
02923       } else if (!strcasecmp(var->name, "autoprune")) {
02924          ast_set2_flag(&globalflags, ast_true(var->value), AJI_AUTOPRUNE);
02925       } else if (!strcasecmp(var->name, "autoregister")) {
02926          ast_set2_flag(&globalflags, ast_true(var->value), AJI_AUTOREGISTER);
02927       }
02928    }
02929 
02930    while (cat) {
02931       if (strcasecmp(cat, "general")) {
02932             var = ast_variable_browse(cfg, cat);
02933             aji_create_client(cat, var, debug);
02934       }
02935       cat = ast_category_browse(cfg, cat);
02936    }
02937    ast_config_destroy(cfg); /* or leak memory */
02938    return 1;
02939 }

static void aji_log_hook ( void *  data,
const char *  xmpp,
size_t  size,
int  is_incoming 
) [static]

the debug loop.

Parameters:
data void
xmpp xml data as string
size size of string
is_incoming direction of packet 1 for inbound 0 for outbound.

Definition at line 853 of file res_jabber.c.

References aji_client_destroy(), ast_strlen_zero(), ast_verbose, ASTOBJ_REF, ASTOBJ_UNREF, aji_client::debug, EVENT_FLAG_USER, manager_event, aji_client::name, and option_debug.

Referenced by aji_recv(), and aji_send_raw().

00854 {
00855    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
00856 
00857    if (!ast_strlen_zero(xmpp))
00858       manager_event(EVENT_FLAG_USER, "JabberEvent", "Account: %s\r\nPacket: %s\r\n", client->name, xmpp);
00859 
00860    if (client->debug) {
00861       if (is_incoming)
00862          ast_verbose("\nJABBER: %s INCOMING: %s\n", client->name, xmpp);
00863       else {
00864          if( strlen(xmpp) == 1) {
00865             if(option_debug > 2  && xmpp[0] == ' ') {
00866                ast_verbose("\nJABBER: Keep alive packet\n");
00867             }
00868          } else
00869             ast_verbose("\nJABBER: %s OUTGOING: %s\n", client->name, xmpp);
00870       }
00871 
00872    }
00873    ASTOBJ_UNREF(client, aji_client_destroy);
00874 }

static void aji_pruneregister ( struct aji_client *  client  )  [static]

goes through roster and prunes users not needed in list, or adds them accordingly.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
Returns:
void.
Note:
The messages here should be configurable.

Definition at line 2136 of file res_jabber.c.

References AJI_AUTOPRUNE, ast_aji_send(), ast_log(), ast_test_flag, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, aji_client::buddies, aji_client::jid, and LOG_ERROR.

02137 {
02138    int res = 0;
02139    iks *removeiq = iks_new("iq");
02140    iks *removequery = iks_new("query");
02141    iks *removeitem = iks_new("item");
02142    iks *send = iks_make_iq(IKS_TYPE_GET, "http://jabber.org/protocol/disco#items");
02143    if (!client || !removeiq || !removequery || !removeitem || !send) {
02144       ast_log(LOG_ERROR, "Out of memory.\n");
02145       goto safeout;
02146    }
02147 
02148    iks_insert_node(removeiq, removequery);
02149    iks_insert_node(removequery, removeitem);
02150    ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
02151       ASTOBJ_RDLOCK(iterator);
02152       /* For an aji_buddy, both AUTOPRUNE and AUTOREGISTER will never
02153        * be called at the same time */
02154       if (ast_test_flag(&iterator->flags, AJI_AUTOPRUNE)) { /* If autoprune is set on jabber.conf */
02155          res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_UNSUBSCRIBE, iterator->name,
02156                          "GoodBye. Your status is no longer needed by Asterisk the Open Source PBX"
02157                          " so I am no longer subscribing to your presence.\n"));
02158          res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_UNSUBSCRIBED, iterator->name,
02159                          "GoodBye.  You are no longer in the Asterisk config file so I am removing"
02160                          " your access to my presence.\n"));
02161          iks_insert_attrib(removeiq, "from", client->jid->full); 
02162          iks_insert_attrib(removeiq, "type", "set"); 
02163          iks_insert_attrib(removequery, "xmlns", "jabber:iq:roster");
02164          iks_insert_attrib(removeitem, "jid", iterator->name);
02165          iks_insert_attrib(removeitem, "subscription", "remove");
02166          res = ast_aji_send(client, removeiq);
02167       } else if (ast_test_flag(&iterator->flags, AJI_AUTOREGISTER)) {
02168          res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_SUBSCRIBE, iterator->name, 
02169                          "Greetings! I am the Asterisk Open Source PBX and I want to subscribe to your presence\n"));
02170          ast_clear_flag(&iterator->flags, AJI_AUTOREGISTER);
02171       }
02172       ASTOBJ_UNLOCK(iterator);
02173    });
02174 
02175  safeout:
02176    iks_delete(removeiq);
02177    iks_delete(removequery);
02178    iks_delete(removeitem);
02179    iks_delete(send);
02180    
02181    ASTOBJ_CONTAINER_PRUNE_MARKED(&client->buddies, aji_buddy_destroy);
02182 }

static int aji_reconnect ( struct aji_client *  client  )  [static]

reconnect to jabber server

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

Definition at line 2273 of file res_jabber.c.

References AJI_DISCONNECTED, aji_initialize(), aji_client::authorized, aji_client::p, aji_client::state, and aji_client::timeout.

Referenced by aji_recv_loop().

02274 {
02275    int res = 0;
02276 
02277    if (client->state)
02278       client->state = AJI_DISCONNECTED;
02279    client->timeout=50;
02280    if (client->p)
02281       iks_parser_reset(client->p);
02282    if (client->authorized)
02283       client->authorized = 0;
02284 
02285    res = aji_initialize(client);
02286 
02287    return res;
02288 }

static int aji_recv ( struct aji_client *  client,
int  timeout 
) [static]

Tries to receive data from the Jabber server.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
timeout the timeout value This function receives (encrypted or unencrypted) data from the XMPP server, and passes it to the parser.
Returns:
IKS_OK on success, IKS_NET_RWERR on IO error, IKS_NET_NOCONN, if no connection available, IKS_NET_EXPIRED on timeout expiration

Definition at line 711 of file res_jabber.c.

References aji_io_recv(), aji_log_hook(), ast_debug, ast_log(), buf, IKS_NET_EXPIRED, len(), LOG_WARNING, NET_IO_BUF_SIZE, and aji_client::p.

Referenced by aji_act_hook(), and aji_recv_loop().

00712 {
00713    int len, ret;
00714    char buf[NET_IO_BUF_SIZE - 1];
00715    char newbuf[NET_IO_BUF_SIZE - 1];
00716    int pos = 0;
00717    int newbufpos = 0;
00718    unsigned char c;
00719 
00720    memset(buf, 0, sizeof(buf));
00721    memset(newbuf, 0, sizeof(newbuf));
00722 
00723    while (1) {
00724       len = aji_io_recv(client, buf, NET_IO_BUF_SIZE - 2, timeout);
00725       if (len < 0) return IKS_NET_RWERR;
00726       if (len == 0) return IKS_NET_EXPIRED;
00727       buf[len] = '\0';
00728 
00729       /* our iksemel parser won't work as expected if we feed
00730          it with XML packets that contain multiple whitespace 
00731          characters between tags */
00732       while (pos < len) {
00733          c = buf[pos];
00734          /* if we stumble on the ending tag character,
00735             we skip any whitespace that follows it*/
00736          if (c == '>') {
00737             while (isspace(buf[pos+1])) {
00738                pos++;
00739             }
00740          }
00741          newbuf[newbufpos] = c;
00742          newbufpos ++;
00743          pos++;
00744       }
00745       pos = 0;
00746       newbufpos = 0;
00747 
00748       /* Log the message here, because iksemel's logHook is 
00749          unaccessible */
00750       aji_log_hook(client, buf, len, 1);
00751 
00752       /* let iksemel deal with the string length, 
00753          and reset our buffer */
00754       ret = iks_parse(client->p, newbuf, 0, 0);
00755       memset(newbuf, 0, sizeof(newbuf));
00756 
00757       switch (ret) {
00758       case IKS_NOMEM:
00759          ast_log(LOG_WARNING, "Parsing failure: Out of memory.\n");
00760          break;
00761       case IKS_BADXML:
00762          ast_log(LOG_WARNING, "Parsing failure: Invalid XML.\n");
00763          break;
00764       case IKS_HOOK:
00765          ast_log(LOG_WARNING, "Parsing failure: Hook returned an error.\n");
00766          break;
00767       }
00768       if (ret != IKS_OK) {
00769          return ret;
00770       }
00771       ast_debug(3, "XML parsing successful\n"); 
00772    }
00773    return IKS_OK;
00774 }

static void * aji_recv_loop ( void *  data  )  [static]

receive message loop.

Parameters:
data void
Returns:
void.

Definition at line 1975 of file res_jabber.c.

References aji_client_destroy(), AJI_CONNECTED, AJI_DISCONNECTING, aji_reconnect(), aji_recv(), aji_send_raw(), ast_debug, ast_log(), ASTOBJ_REF, ASTOBJ_UNREF, IKS_NET_EXPIRED, aji_client::keepalive, LOG_ERROR, LOG_WARNING, aji_client::state, and aji_client::timeout.

Referenced by aji_reload().

01976 {
01977    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
01978    int res = IKS_HOOK;
01979 
01980    while(res != IKS_OK) {
01981       ast_debug(3, "JABBER: Connecting.\n");
01982       res = aji_reconnect(client);
01983       sleep(4);
01984    }
01985 
01986    do {
01987       if (res == IKS_NET_RWERR || client->timeout == 0) {
01988          while(res != IKS_OK) {
01989             ast_debug(3, "JABBER: reconnecting.\n");
01990             res = aji_reconnect(client);
01991             sleep(4);
01992          }
01993       }
01994 
01995       res = aji_recv(client, 1);
01996       
01997       if (client->state == AJI_DISCONNECTING) {
01998          ast_debug(2, "Ending our Jabber client's thread due to a disconnect\n");
01999          pthread_exit(NULL);
02000       }
02001 
02002       /* Decrease timeout if no data received */
02003       if (res == IKS_NET_EXPIRED)
02004          client->timeout--;
02005 
02006       if (res == IKS_HOOK) 
02007          ast_log(LOG_WARNING, "JABBER: Got hook event.\n");
02008       else if (res == IKS_NET_TLSFAIL)
02009          ast_log(LOG_ERROR, "JABBER:  Failure in TLS.\n");
02010       else if (client->timeout == 0 && client->state == AJI_CONNECTED) {
02011          res = client->keepalive ? aji_send_raw(client, " ") : IKS_OK;
02012          if(res == IKS_OK)
02013             client->timeout = 50;
02014          else
02015             ast_log(LOG_WARNING, "JABBER:  Network Timeout\n");
02016       } else if (res == IKS_NET_RWERR)
02017          ast_log(LOG_WARNING, "JABBER: socket read error\n");
02018    } while (client);
02019    ASTOBJ_UNREF(client, aji_client_destroy);
02020    return 0;
02021 }

static int aji_register_approve_handler ( void *  data,
ikspak *  pak 
) [static]

Unknown.

Parameters:
data void
pak ikspak
Returns:
IKS_FILTER_EAT.

Definition at line 1134 of file res_jabber.c.

References aji_client_destroy(), ast_aji_increment_mid(), ast_aji_send(), ast_log(), ASTOBJ_REF, ASTOBJ_UNREF, aji_client::jid, LOG_ERROR, and aji_client::mid.

01135 {
01136    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
01137    iks *iq = NULL, *presence = NULL, *x = NULL;
01138 
01139    iq = iks_new("iq");
01140    presence = iks_new("presence");
01141    x = iks_new("x");
01142    if (client && iq && presence && x) {
01143       if (!iks_find(pak->query, "remove")) {
01144          iks_insert_attrib(iq, "from", client->jid->full);
01145          iks_insert_attrib(iq, "to", pak->from->full);
01146          iks_insert_attrib(iq, "id", pak->id);
01147          iks_insert_attrib(iq, "type", "result");
01148          ast_aji_send(client, iq);
01149 
01150          iks_insert_attrib(presence, "from", client->jid->full);
01151          iks_insert_attrib(presence, "to", pak->from->partial);
01152          iks_insert_attrib(presence, "id", client->mid);
01153          ast_aji_increment_mid(client->mid);
01154          iks_insert_attrib(presence, "type", "subscribe");
01155          iks_insert_attrib(x, "xmlns", "vcard-temp:x:update");
01156          iks_insert_node(presence, x);
01157          ast_aji_send(client, presence); 
01158       }
01159    } else {
01160       ast_log(LOG_ERROR, "Out of memory.\n");
01161    }
01162 
01163 
01164    iks_delete(iq);
01165    iks_delete(presence);
01166    iks_delete(x);
01167    
01168    ASTOBJ_UNREF(client, aji_client_destroy);
01169    return IKS_FILTER_EAT;
01170 }

static int aji_register_query_handler ( void *  data,
ikspak *  pak 
) [static]

register handler for incoming querys (IQ's)

Parameters:
data incoming aji_client request
pak ikspak
Returns:
IKS_FILTER_EAT.

Definition at line 1177 of file res_jabber.c.

References aji_client_destroy(), ast_aji_send(), ast_log(), ASTOBJ_CONTAINER_FIND, ASTOBJ_REF, ASTOBJ_UNREF, aji_client::buddies, LOG_ERROR, and aji_client::user.

01178 {
01179    struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
01180    struct aji_buddy *buddy = NULL; 
01181    char *node = NULL;
01182    iks *iq = NULL, *query = NULL;
01183 
01184    client = (struct aji_client *) data;
01185 
01186    buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, pak->from->partial);
01187    if (!buddy) {
01188       iks  *error = NULL, *notacceptable = NULL;
01189 
01190       ast_log(LOG_ERROR, "Someone.... %s tried to register but they aren't allowed\n", pak->from->partial);
01191       iq = iks_new("iq");
01192       query = iks_new("query");
01193       error = iks_new("error");
01194       notacceptable = iks_new("not-acceptable");
01195       if(iq && query && error && notacceptable) {
01196          iks_insert_attrib(iq, "type", "error");
01197          iks_insert_attrib(iq, "from", client->user);
01198          iks_insert_attrib(iq, "to", pak->from->full);
01199          iks_insert_attrib(iq, "id", pak->id);
01200          iks_insert_attrib(query, "xmlns", "jabber:iq:register");
01201          iks_insert_attrib(error, "code" , "406");
01202          iks_insert_attrib(error, "type", "modify");
01203          iks_insert_attrib(notacceptable, "xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas");
01204          iks_insert_node(iq, query);
01205          iks_insert_node(iq, error);
01206          iks_insert_node(error, notacceptable);
01207          ast_aji_send(client, iq);
01208       } else {
01209          ast_log(LOG_ERROR, "Out of memory.\n");
01210       }
01211 
01212       iks_delete(error);
01213       iks_delete(notacceptable);
01214    } else   if (!(node = iks_find_attrib(pak->query, "node"))) {
01215       iks *instructions = NULL;
01216       char *explain = "Welcome to Asterisk - the Open Source PBX.\n";
01217       iq = iks_new("iq");
01218       query = iks_new("query");
01219       instructions = iks_new("instructions");
01220       if (iq && query && instructions && client) {
01221          iks_insert_attrib(iq, "from", client->user);
01222          iks_insert_attrib(iq, "to", pak->from->full);
01223          iks_insert_attrib(iq, "id", pak->id);
01224          iks_insert_attrib(iq, "type", "result");
01225          iks_insert_attrib(query, "xmlns", "jabber:iq:register");
01226          iks_insert_cdata(instructions, explain, 0);
01227          iks_insert_node(iq, query);
01228          iks_insert_node(query, instructions);
01229          ast_aji_send(client, iq);
01230       } else {
01231          ast_log(LOG_ERROR, "Out of memory.\n");
01232       }
01233 
01234       iks_delete(instructions);
01235    }
01236    iks_delete(iq);
01237    iks_delete(query);
01238    ASTOBJ_UNREF(client, aji_client_destroy);
01239    return IKS_FILTER_EAT;
01240 }

static int aji_reload ( int  reload  )  [static]

Reload the jabber module.

Definition at line 3028 of file res_jabber.c.

References aji_client_destroy(), AJI_CONNECTING, AJI_DISCONNECTED, aji_get_roster(), aji_load_config(), aji_recv_loop(), ast_log(), ast_pthread_create_background, ASTOBJ_CONTAINER_MARKALL, ASTOBJ_CONTAINER_PRUNE_MARKED, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, clients, and LOG_ERROR.

Referenced by aji_do_reload(), load_module(), and reload().

03029 {
03030    int res;
03031 
03032    ASTOBJ_CONTAINER_MARKALL(&clients);
03033    if (!(res = aji_load_config(reload))) {
03034       ast_log(LOG_ERROR, "JABBER: Failed to load config.\n");
03035       return 0;
03036    } else if (res == -1)
03037       return 1;
03038 
03039    ASTOBJ_CONTAINER_PRUNE_MARKED(&clients, aji_client_destroy);
03040    ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
03041       ASTOBJ_RDLOCK(iterator);
03042       if(iterator->state == AJI_DISCONNECTED) {
03043          if (!iterator->thread)
03044             ast_pthread_create_background(&iterator->thread, NULL, aji_recv_loop, iterator);
03045       } else if (iterator->state == AJI_CONNECTING)
03046          aji_get_roster(iterator);
03047       ASTOBJ_UNLOCK(iterator);
03048    });
03049    
03050    return 1;
03051 }

static int aji_send_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Dial plan function to send a message.

Parameters:
chan ast_channel
data Data is sender|receiver|message.
Returns:
0 on success,-1 on error.

Definition at line 548 of file res_jabber.c.

References ast_aji_get_client(), ast_aji_send_chat(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), LOG_ERROR, LOG_WARNING, and s.

Referenced by load_module().

00549 {
00550    struct aji_client *client = NULL;
00551    char *s;
00552    AST_DECLARE_APP_ARGS(args,
00553       AST_APP_ARG(sender);
00554       AST_APP_ARG(recipient);
00555       AST_APP_ARG(message);
00556    );
00557 
00558    if (!data) {
00559       ast_log(LOG_ERROR, "Usage:  JabberSend(<sender>,<recipient>,<message>)\n");
00560       return 0;
00561    }
00562    s = ast_strdupa(data);
00563 
00564    AST_STANDARD_APP_ARGS(args, s);
00565    if (args.argc < 3) {
00566       ast_log(LOG_ERROR, "JabberSend requires 3 arguments: '%s'\n", (char *) data);
00567       return -1;
00568    }
00569 
00570    if (!(client = ast_aji_get_client(args.sender))) {
00571       ast_log(LOG_WARNING, "Could not find sender connection: '%s'\n", args.sender);
00572       return -1;
00573    }
00574    if (strchr(args.recipient, '@') && !ast_strlen_zero(args.message))
00575       ast_aji_send_chat(client, args.recipient, args.message);
00576    return 0;
00577 }

static int aji_send_header ( struct aji_client *  client,
const char *  to 
) [static]

Sends XMPP header to the server.

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

Definition at line 782 of file res_jabber.c.

References aji_send_raw(), len(), msg, and aji_client::name_space.

Referenced by aji_act_hook(), and aji_tls_handshake().

00783 {
00784    char *msg;
00785    int len, err;
00786 
00787    len = 91 + strlen(client->name_space) + 6 + strlen(to) + 16 + 1;
00788    msg = iks_malloc(len);
00789    if (!msg)
00790       return IKS_NOMEM;
00791    sprintf(msg, "<?xml version='1.0'?>"
00792       "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='"
00793       "%s' to='%s' version='1.0'>", client->name_space, to);
00794    err = aji_send_raw(client, msg);
00795    iks_free(msg);
00796    if (err != IKS_OK)
00797       return err;
00798 
00799    return IKS_OK;
00800 }

static int aji_send_raw ( struct aji_client *  client,
const char *  xmlstr 
) [static]

Sends an XML string over an XMPP connection.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
xmlstr the XML string to send The XML data is sent whether the connection is secured or not. In the latter case, we just call iks_send_raw().
Returns:
IKS_OK on success, any other value on failure

Definition at line 821 of file res_jabber.c.

References aji_is_secure(), aji_log_hook(), len(), aji_client::p, and aji_client::ssl_session.

Referenced by aji_act_hook(), aji_recv_loop(), aji_send_header(), and ast_aji_send().

00822 {
00823    int ret;
00824 #ifdef HAVE_OPENSSL
00825    int len = strlen(xmlstr);
00826 
00827    if (aji_is_secure(client)) {
00828       ret = SSL_write(client->ssl_session, xmlstr, len);
00829       if (ret) {
00830          /* Log the message here, because iksemel's logHook is 
00831             unaccessible */
00832          aji_log_hook(client, xmlstr, len, 0);
00833          return IKS_OK;
00834       }
00835    }
00836 #endif
00837    /* If needed, data will be sent unencrypted, and logHook will 
00838       be called inside iks_send_raw */
00839    ret = iks_send_raw(client->p, xmlstr);
00840    if (ret != IKS_OK)
00841       return ret; 
00842 
00843    return IKS_OK;
00844 }

static void aji_set_presence ( struct aji_client *  client,
char *  to,
char *  from,
int  level,
char *  desc 
) [static]

set presence of client.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
to user send it to
from user it came from
level 
desc 
Returns:
void.

Definition at line 2401 of file res_jabber.c.

References ast_aji_send(), ast_log(), LOG_ERROR, and aji_client::priority.

Referenced by aji_get_roster(), aji_handle_presence(), and aji_handle_subscribe().

02402 {
02403    int res = 0;
02404    iks *presence = iks_make_pres(level, desc);
02405    iks *cnode = iks_new("c");
02406    iks *priority = iks_new("priority");
02407    char priorityS[10];
02408 
02409    if (presence && cnode && client && priority) {
02410       if(to)
02411          iks_insert_attrib(presence, "to", to);
02412       if(from)
02413          iks_insert_attrib(presence, "from", from);
02414       snprintf(priorityS, sizeof(priorityS), "%d", client->priority);
02415       iks_insert_cdata(priority, priorityS, strlen(priorityS));
02416       iks_insert_node(presence, priority);
02417       iks_insert_attrib(cnode, "node", "http://www.asterisk.org/xmpp/client/caps");
02418       iks_insert_attrib(cnode, "ver", "asterisk-xmpp");
02419       iks_insert_attrib(cnode, "ext", "voice-v1");
02420       iks_insert_attrib(cnode, "xmlns", "http://jabber.org/protocol/caps");
02421       iks_insert_node(presence, cnode);
02422       res = ast_aji_send(client, presence);
02423    } else
02424       ast_log(LOG_ERROR, "Out of memory.\n");
02425 
02426    iks_delete(cnode);
02427    iks_delete(presence);
02428    iks_delete(priority);
02429 }

static char * aji_show_buddies ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Show buddy lists.

Returns:
CLI_SUCCESS.

Definition at line 2542 of file res_jabber.c.

References ast_cli(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, aji_client::buddies, aji_resource::cap, CLI_GENERATE, CLI_INIT, clients, ast_cli_entry::command, ast_cli_args::fd, aji_version::jingle, aji_resource::next, aji_capabilities::node, aji_version::parent, aji_resource::priority, aji_resource::resource, aji_resource::status, ast_cli_entry::usage, and aji_version::version.

02543 {
02544    struct aji_resource *resource;
02545    struct aji_client *client;
02546 
02547    switch (cmd) {
02548    case CLI_INIT:
02549       e->command = "jabber show buddies";
02550       e->usage =
02551          "Usage: jabber show buddies\n"
02552          "       Shows buddy lists of our clients\n";
02553       return NULL;
02554    case CLI_GENERATE:
02555       return NULL;
02556    }
02557 
02558    ast_cli(a->fd, "Jabber buddy lists\n");
02559    ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
02560       ast_cli(a->fd,"Client: %s\n", iterator->user);
02561       client = iterator;
02562       ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
02563          ASTOBJ_RDLOCK(iterator);
02564          ast_cli(a->fd,"\tBuddy:\t%s\n", iterator->name);
02565          if (!iterator->resources)
02566             ast_cli(a->fd,"\t\tResource: None\n"); 
02567          for (resource = iterator->resources; resource; resource = resource->next) {
02568             ast_cli(a->fd,"\t\tResource: %s\n", resource->resource);
02569             if(resource->cap) {
02570                ast_cli(a->fd,"\t\t\tnode: %s\n", resource->cap->parent->node);
02571                ast_cli(a->fd,"\t\t\tversion: %s\n", resource->cap->version);
02572                ast_cli(a->fd,"\t\t\tJingle capable: %s\n", resource->cap->jingle ? "yes" : "no");
02573             }
02574             ast_cli(a->fd,"\t\tStatus: %d\n", resource->status);
02575             ast_cli(a->fd,"\t\tPriority: %d\n", resource->priority);
02576          }
02577          ASTOBJ_UNLOCK(iterator);
02578       });
02579       iterator = client;
02580    });
02581    return CLI_SUCCESS;
02582 }

static char * aji_show_clients ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Show client status.

Returns:
CLI_SUCCESS.

Definition at line 2497 of file res_jabber.c.

References AJI_CONNECTED, AJI_CONNECTING, AJI_DISCONNECTED, ast_cli(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, clients, ast_cli_entry::command, ast_cli_args::fd, status, and ast_cli_entry::usage.

02498 {
02499    char *status;
02500    int count = 0;
02501    
02502    switch (cmd) {
02503    case CLI_INIT:
02504       e->command = "jabber show connected";
02505       e->usage =
02506          "Usage: jabber show connected\n"
02507          "       Shows state of clients and components\n";
02508       return NULL;
02509    case CLI_GENERATE:
02510       return NULL;
02511    }
02512 
02513    ast_cli(a->fd, "Jabber Users and their status:\n");
02514    ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
02515       ASTOBJ_RDLOCK(iterator);
02516       count++;
02517       switch (iterator->state) {
02518       case AJI_DISCONNECTED:
02519          status = "Disconnected";
02520          break;
02521       case AJI_CONNECTING:
02522          status = "Connecting";
02523          break;
02524       case AJI_CONNECTED:
02525          status = "Connected";
02526          break;
02527       default:
02528          status = "Unknown";
02529       }
02530       ast_cli(a->fd, "       User: %s     - %s\n", iterator->user, status);
02531       ASTOBJ_UNLOCK(iterator);
02532    });
02533    ast_cli(a->fd, "----\n");
02534    ast_cli(a->fd, "   Number of users: %d\n", count);
02535    return CLI_SUCCESS;
02536 }

static int aji_start_sasl ( struct aji_client *  client,
enum ikssasltype  type,
char *  username,
char *  pass 
) [static]

A wrapper function for iks_start_sasl.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
type the SASL authentication type. Supported types are PLAIN and MD5
username 
pass password.
Returns:
IKS_OK on success, IKSNET_NOTSUPP on failure.

Definition at line 885 of file res_jabber.c.

References aji_is_secure(), ast_aji_send(), ast_base64encode(), ast_log(), base64, len(), LOG_ERROR, aji_client::p, and s.

Referenced by aji_act_hook().

00886 {
00887    iks *x = NULL;
00888    int len;
00889    char *s;
00890    char *base64;
00891 
00892    /* trigger SASL DIGEST-MD5 only over an unsecured connection.
00893       iks_start_sasl is an iksemel API function and relies on GnuTLS,
00894       whereas we use OpenSSL */
00895    if ((type & IKS_STREAM_SASL_MD5) && !aji_is_secure(client))
00896       return iks_start_sasl(client->p, IKS_SASL_DIGEST_MD5, username, pass); 
00897    if (!(type & IKS_STREAM_SASL_PLAIN)) {
00898       ast_log(LOG_ERROR, "Server does not support SASL PLAIN authentication\n");
00899       return IKS_NET_NOTSUPP;
00900    }
00901 
00902    x = iks_new("auth"); 
00903    if (!x) {
00904       ast_log(LOG_ERROR, "Out of memory.\n");
00905       return IKS_NET_NOTSUPP;
00906    }
00907 
00908    iks_insert_attrib(x, "xmlns", IKS_NS_XMPP_SASL);
00909    len = strlen(username) + strlen(pass) + 3;
00910    s = alloca(len);
00911    base64 = alloca((len + 2) * 4 / 3);
00912    iks_insert_attrib(x, "mechanism", "PLAIN");
00913    snprintf(s, len, "%c%s%c%s", 0, username, 0, pass);
00914 
00915    /* exclude the NULL training byte from the base64 encoding operation
00916       as some XMPP servers will refuse it.
00917       The format for authentication is [authzid]\0authcid\0password
00918       not [authzid]\0authcid\0password\0 */
00919    ast_base64encode(base64, (const unsigned char *) s, len - 1, (len + 2) * 4 / 3);
00920    iks_insert_cdata(x, base64, 0);
00921    ast_aji_send(client, x);
00922    iks_delete(x);
00923 
00924    return IKS_OK;
00925 }

static int aji_start_tls ( struct aji_client *  client  )  [static]

Starts the TLS procedure.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
Returns:
IKS_OK on success, an error code if sending failed, IKS_NET_TLSFAIL if OpenSSL is not installed

Definition at line 599 of file res_jabber.c.

References aji_client::p, and aji_client::stream_flags.

Referenced by aji_act_hook().

00600 {
00601    int ret;
00602 
00603    /* This is sent not encrypted */
00604    ret = iks_send_raw(client->p, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
00605    if (ret)
00606       return ret;
00607 
00608    client->stream_flags |= TRY_SECURE;
00609    return IKS_OK;
00610 }

static int aji_status_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Dial plan function status(). puts the status of watched user into a channel variable.

Parameters:
chan ast_channel
data 
Returns:
0 on success, -1 on error

Definition at line 432 of file res_jabber.c.

References aji_find_resource(), ast_aji_get_client(), AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ASTOBJ_CONTAINER_FIND, aji_client::buddies, LOG_ERROR, LOG_NOTICE, LOG_WARNING, pbx_builtin_setvar_helper(), aji_resource::resource, aji_buddy::resources, s, aji_resource::status, and status.

Referenced by load_module().

00433 {
00434    struct aji_client *client = NULL;
00435    struct aji_buddy *buddy = NULL;
00436    struct aji_resource *r = NULL;
00437    char *s = NULL;
00438    int stat = 7;
00439    char status[2];
00440    static int deprecation_warning = 0;
00441    AST_DECLARE_APP_ARGS(args,
00442       AST_APP_ARG(sender);
00443       AST_APP_ARG(jid);
00444       AST_APP_ARG(variable);
00445    );
00446    AST_DECLARE_APP_ARGS(jid,
00447       AST_APP_ARG(screenname);
00448       AST_APP_ARG(resource);
00449    );
00450 
00451    if (deprecation_warning++ % 10 == 0)
00452       ast_log(LOG_WARNING, "JabberStatus is deprecated.  Please use the JABBER_STATUS dialplan function in the future.\n");
00453 
00454    if (!data) {
00455       ast_log(LOG_ERROR, "Usage: JabberStatus(<sender>,<jid>[/<resource>],<varname>\n");
00456       return 0;
00457    }
00458    s = ast_strdupa(data);
00459    AST_STANDARD_APP_ARGS(args, s);
00460 
00461    if (args.argc != 3) {
00462       ast_log(LOG_ERROR, "JabberStatus() requires 3 arguments.\n");
00463       return -1;
00464    }
00465 
00466    AST_NONSTANDARD_APP_ARGS(jid, args.jid, '/');
00467 
00468    if (!(client = ast_aji_get_client(args.sender))) {
00469       ast_log(LOG_WARNING, "Could not find sender connection: '%s'\n", args.sender);
00470       return -1;
00471    }
00472    buddy = ASTOBJ_CONTAINER_FIND(&client->buddies, jid.screenname);
00473    if (!buddy) {
00474       ast_log(LOG_WARNING, "Could not find buddy in list: '%s'\n", jid.screenname);
00475       return -1;
00476    }
00477    r = aji_find_resource(buddy, jid.resource);
00478    if (!r && buddy->resources) 
00479       r = buddy->resources;
00480    if (!r)
00481       ast_log(LOG_NOTICE, "Resource '%s' of buddy '%s' was not found\n", jid.resource, jid.screenname);
00482    else
00483       stat = r->status;
00484    snprintf(status, sizeof(status), "%d", stat);
00485    pbx_builtin_setvar_helper(chan, args.variable, status);
00486    return 0;
00487 }

static char * aji_test ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Send test message for debugging.

Returns:
CLI_SUCCESS,CLI_FAILURE.

Definition at line 2588 of file res_jabber.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_aji_send_chat(), ast_cli(), ast_verbose, ASTOBJ_CONTAINER_FIND, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, aji_client::buddies, aji_resource::cap, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, clients, ast_cli_entry::command, aji_resource::description, ast_cli_args::fd, aji_version::jingle, name, aji_resource::next, aji_capabilities::node, aji_version::parent, aji_resource::priority, aji_resource::resource, S_OR, aji_resource::status, ast_cli_entry::usage, and aji_version::version.

02589 {
02590    struct aji_client *client;
02591    struct aji_resource *resource;
02592    const char *name = "asterisk";
02593    struct aji_message *tmp;
02594 
02595    switch (cmd) {
02596    case CLI_INIT:
02597       e->command = "jabber test";
02598       e->usage =
02599          "Usage: jabber test [client]\n"
02600          "       Sends test message for debugging purposes.  A specific client\n"
02601          "       as configured in jabber.conf can be optionally specified.\n";
02602       return NULL;
02603    case CLI_GENERATE:
02604       return NULL;
02605    }
02606 
02607    if (a->argc > 3)
02608       return CLI_SHOWUSAGE;
02609    else if (a->argc == 3)
02610       name = a->argv[2];
02611 
02612    if (!(client = ASTOBJ_CONTAINER_FIND(&clients, name))) {
02613       ast_cli(a->fd, "Unable to find client '%s'!\n", name);
02614       return CLI_FAILURE;
02615    }
02616 
02617    /* XXX Does Matt really want everyone to use his personal address for tests? */ /* XXX yes he does */
02618    ast_aji_send_chat(client, "mogorman@astjab.org", "blahblah");
02619    ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
02620       ASTOBJ_RDLOCK(iterator);
02621       ast_verbose("User: %s\n", iterator->name);
02622       for (resource = iterator->resources; resource; resource = resource->next) {
02623          ast_verbose("Resource: %s\n", resource->resource);
02624          if(resource->cap) {
02625             ast_verbose("   client: %s\n", resource->cap->parent->node);
02626             ast_verbose("   version: %s\n", resource->cap->version);
02627             ast_verbose("   Jingle Capable: %d\n", resource->cap->jingle);
02628          }
02629          ast_verbose("  Priority: %d\n", resource->priority);
02630          ast_verbose("  Status: %d\n", resource->status); 
02631          ast_verbose("  Message: %s\n", S_OR(resource->description,"")); 
02632       }
02633       ASTOBJ_UNLOCK(iterator);
02634    });
02635    ast_verbose("\nOooh a working message stack!\n");
02636    AST_LIST_LOCK(&client->messages);
02637    AST_LIST_TRAVERSE(&client->messages, tmp, list) {
02638       ast_verbose("  Message from: %s with id %s @ %s %s\n",tmp->from, S_OR(tmp->id,""), ctime(&tmp->arrived), S_OR(tmp->message, ""));
02639    }
02640    AST_LIST_UNLOCK(&client->messages);
02641    ASTOBJ_UNREF(client, aji_client_destroy);
02642 
02643    return CLI_SUCCESS;
02644 }

static int aji_tls_handshake ( struct aji_client *  client  )  [static]

TLS handshake, OpenSSL initialization.

Parameters:
client the configured XMPP client we use to connect to a XMPP server
Returns:
IKS_OK on success, IKS_NET_TLSFAIL on failure

Definition at line 617 of file res_jabber.c.

References aji_send_header(), ast_debug, aji_client::jid, aji_client::p, aji_client::ssl_context, aji_client::ssl_method, aji_client::ssl_session, and aji_client::stream_flags.

Referenced by aji_act_hook().

00618 {
00619    int ret;
00620    int sock;
00621    
00622    ast_debug(1, "Starting TLS handshake\n"); 
00623 
00624    /* Choose an SSL/TLS protocol version, create SSL_CTX */
00625    client->ssl_method = SSLv3_method();
00626    client->ssl_context = SSL_CTX_new(client->ssl_method);                
00627    if (!client->ssl_context)
00628       return IKS_NET_TLSFAIL;
00629 
00630    /* Create new SSL session */
00631    client->ssl_session = SSL_new(client->ssl_context);
00632    if (!client->ssl_session)
00633       return IKS_NET_TLSFAIL;
00634 
00635    /* Enforce TLS on our XMPP connection */
00636    sock = iks_fd(client->p);
00637    ret = SSL_set_fd(client->ssl_session, sock);
00638    if (!ret)
00639       return IKS_NET_TLSFAIL;
00640 
00641    /* Perform SSL handshake */
00642    ret = SSL_connect(client->ssl_session);
00643    if (!ret)
00644       return IKS_NET_TLSFAIL;
00645 
00646    client->stream_flags &= (~TRY_SECURE);
00647    client->stream_flags |= SECURE;
00648 
00649    /* Sent over the established TLS connection */
00650    ret = aji_send_header(client, client->jid->server);
00651    if (ret != IKS_OK)
00652       return IKS_NET_TLSFAIL;
00653 
00654    ast_debug(1, "TLS started with server\n"); 
00655 
00656    return IKS_OK;
00657 }

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 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.

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.

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.

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.

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 }

static int gtalk_yuck ( iks *  node  )  [static]

Jabber GTalk function.

Parameters:
node iks
Returns:
1 on success, 0 on failure.

Definition at line 390 of file res_jabber.c.

Referenced by aji_handle_presence().

00391 {
00392    if (iks_find_with_attrib(node, "c", "node", "http://www.google.com/xmpp/client/caps"))
00393       return 1;
00394    return 0;
00395 }

static iks * jabber_make_auth ( iksid *  id,
const char *  pass,
const char *  sid 
) [static]

Setup the authentication struct.

Parameters:
id iksid
pass password
sid 
Returns:
x iks

Definition at line 404 of file res_jabber.c.

References ast_sha1_hash(), and buf.

Referenced by aji_act_hook().

00405 {
00406    iks *x, *y;
00407    x = iks_new("iq");
00408    iks_insert_attrib(x, "type", "set");
00409    y = iks_insert(x, "query");
00410    iks_insert_attrib(y, "xmlns", IKS_NS_AUTH);
00411    iks_insert_cdata(iks_insert(y, "username"), id->user, 0);
00412    iks_insert_cdata(iks_insert(y, "resource"), id->resource, 0);
00413    if (sid) {
00414       char buf[41];
00415       char sidpass[100];
00416       snprintf(sidpass, sizeof(sidpass), "%s%s", sid, pass);
00417       ast_sha1_hash(buf, sidpass);
00418       iks_insert_cdata(iks_insert(y, "digest"), buf, 0);
00419    } else {
00420       iks_insert_cdata(iks_insert(y, "password"), pass, 0);
00421    }
00422    return x;
00423 }

static int load_module ( void   )  [static]

static int manager_jabber_send ( struct mansession *  s,
const struct message *  m 
) [static]

Send a Jabber Message via call from the Manager.

Parameters:
s mansession Manager session
m message Message to send
Returns:
0

Definition at line 2987 of file res_jabber.c.

References ast_aji_get_client(), ast_aji_send_chat(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_ack(), and astman_send_error().

Referenced by load_module().

02988 {
02989    struct aji_client *client = NULL;
02990    const char *id = astman_get_header(m,"ActionID");
02991    const char *jabber = astman_get_header(m,"Jabber");
02992    const char *screenname = astman_get_header(m,"ScreenName");
02993    const char *message = astman_get_header(m,"Message");
02994 
02995    if (ast_strlen_zero(jabber)) {
02996       astman_send_error(s, m, "No transport specified");
02997       return 0;
02998    }
02999    if (ast_strlen_zero(screenname)) {
03000       astman_send_error(s, m, "No ScreenName specified");
03001       return 0;
03002    }
03003    if (ast_strlen_zero(message)) {
03004       astman_send_error(s, m, "No Message specified");
03005       return 0;
03006    }
03007 
03008    astman_send_ack(s, m, "Attempting to send Jabber Message");
03009    client = ast_aji_get_client(jabber);
03010    if (!client) {
03011       astman_send_error(s, m, "Could not find Sender");
03012       return 0;
03013    }
03014    if (strchr(screenname, '@') && message) {
03015       ast_aji_send_chat(client, screenname, message);
03016       astman_append(s, "Response: Success\r\n");
03017    } else {
03018       astman_append(s, "Response: Error\r\n");
03019    }
03020    if (!ast_strlen_zero(id)) {
03021       astman_append(s, "ActionID: %s\r\n",id);
03022    }
03023    astman_append(s, "\r\n");
03024    return 0;
03025 }

static int reload ( void   )  [static]

Wrapper for aji_reload.

Definition at line 3094 of file res_jabber.c.

References aji_reload().

03095 {
03096    aji_reload(1);
03097    return 0;
03098 }

static int unload_module ( void   )  [static]

Unload the jabber module.

Definition at line 3054 of file res_jabber.c.

References aji_client_destroy(), AJI_DISCONNECTING, ARRAY_LEN, ast_aji_disconnect(), ast_cli_unregister_multiple(), ast_custom_function_unregister(), ast_debug, ast_manager_unregister(), ast_unregister_application(), ASTOBJ_CONTAINER_DESTROY, ASTOBJ_CONTAINER_DESTROYALL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, and clients.

03055 {
03056 
03057    ast_cli_unregister_multiple(aji_cli, ARRAY_LEN(aji_cli));
03058    ast_unregister_application(app_ajisend);
03059    ast_unregister_application(app_ajistatus);
03060    ast_manager_unregister("JabberSend");
03061    ast_custom_function_unregister(&jabberstatus_function);
03062    
03063    ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
03064       ASTOBJ_WRLOCK(iterator);
03065       ast_debug(3, "JABBER: Releasing and disconnecting client: %s\n", iterator->name);
03066       iterator->state = AJI_DISCONNECTING;
03067       ASTOBJ_UNLOCK(iterator);
03068       pthread_join(iterator->thread, NULL);
03069       ast_aji_disconnect(iterator);
03070    });
03071 
03072    ASTOBJ_CONTAINER_DESTROYALL(&clients, aji_client_destroy);
03073    ASTOBJ_CONTAINER_DESTROY(&clients);
03074    return 0;
03075 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS , .description = "AJI - Asterisk Jabber Interface" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static]

Definition at line 3104 of file res_jabber.c.

struct ast_cli_entry aji_cli[] [static]

Definition at line 234 of file res_jabber.c.

char* app_ajisend = "JabberSend" [static]

Definition at line 242 of file res_jabber.c.

char* app_ajistatus = "JabberStatus" [static]

Definition at line 244 of file res_jabber.c.

Definition at line 3104 of file res_jabber.c.

Definition at line 247 of file res_jabber.c.

Referenced by ast_request().

struct ast_flags globalflags = { AJI_AUTOREGISTER } [static]

Global flags, initialized to default values.

Definition at line 250 of file res_jabber.c.

Initial value:

 {
   .name = "JABBER_STATUS",
   .read = acf_jabberstatus_read,
}

Definition at line 537 of file res_jabber.c.

char mandescr_jabber_send[] [static]

Definition at line 2974 of file res_jabber.c.


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