[asterisk-commits] branch mogorman/asterisk-xmpp r23953 - in
/team/mogorman/asterisk-xmpp: ./ res/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon May 1 08:22:50 MST 2006
Author: mogorman
Date: Mon May 1 10:22:49 2006
New Revision: 23953
URL: http://svn.digium.com/view/asterisk?rev=23953&view=rev
Log:
added function to reconnect if disconnected.
Modified:
team/mogorman/asterisk-xmpp/configure.ac
team/mogorman/asterisk-xmpp/res/res_jabber.c
Modified: team/mogorman/asterisk-xmpp/configure.ac
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/configure.ac?rev=23953&r1=23952&r2=23953&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/configure.ac (original)
+++ team/mogorman/asterisk-xmpp/configure.ac Mon May 1 10:22:49 2006
@@ -159,6 +159,7 @@
AST_EXT_LIB([asound], [snd_spcm_init], [alsa/asoundlib.h], [ALSA], [Advanced Linux Sound Architecture], [-lm -ldl])
AST_EXT_LIB([curses], [initscr], [curses.h], [CURSES], [curses], [])
+AST_EXT_LIB([iksemel], [iks_start_sasl], [iksemel.h], [IKSEMEL], [Iksemel Jabber Library])
AST_EXT_LIB([mfcr2], [mfcr2_MakeCall], [libmfcr2.h], [MFCR2], [MFCR2])
AST_EXT_LIB([nbs], [nbs_setup], [nbs.h], [NBS], [Network Broadcast Sound])
AST_EXT_LIB([ncurses], [initscr], [curses.h], [NCURSES], [ncurses], [])
@@ -174,7 +175,6 @@
AST_EXT_LIB([tds], [tds_version], [tds.h], [FREETDS], [FreeTDS])
AST_EXT_LIB([vorbis], [vorbis_info_init], [vorbis/codec.h], [VORBIS], [Vorbis], [-lm -lvorbisenc])
AST_EXT_LIB([z], [compress], [zlib.h], [ZLIB], [zlib])
-AST_EXT_LIB([iksemel], [iks_start_sasl], [iksemel.h], [IKSEMEL], [Iksemel Jabber Library])
if test "x${PBX_OSTYPE}" = "xLinux" ; then
AST_EXT_LIB([ossaudio], [oss_ioctl_mixer], [linux/soundcard.h], [OSS], [Open Sound System])
Modified: team/mogorman/asterisk-xmpp/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/res_jabber.c?rev=23953&r1=23952&r2=23953&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_jabber.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_jabber.c Mon May 1 10:22:49 2006
@@ -85,6 +85,7 @@
static int aji_ditems_handler(void *udata,ikspak *pak);
static int aji_register_query_handler(void *udata,ikspak *pak);
static int aji_register_approve_handler(void *udata,ikspak *pak);
+static int aji_reconnect(struct aji_client *client);
static char debug_usage[] =
"Usage: JABBER debug\n"
@@ -151,6 +152,12 @@
*/
static void aji_buddy_destroy(struct aji_buddy *obj)
{
+ struct aji_resource *tmp = NULL;
+ while(tmp) {
+ tmp = obj->resources;
+ obj->resources = obj->resources->next;
+ free(tmp);
+ }
free(obj);
obj =NULL;
}
@@ -324,6 +331,7 @@
}
if(buf)
free(buf);
+// ASTOBJ_UNREF(client);
}
/*!
@@ -857,7 +865,7 @@
int status, priority;
struct aji_buddy *buddy = NULL;
struct aji_resource *tmp = NULL, *last= NULL, *found = NULL;
-
+
buddy = ASTOBJ_CONTAINER_FIND(&client->buddies,pak->from->partial);
if(!buddy)
{
@@ -872,6 +880,7 @@
if(!strcasecmp(tmp->resource,pak->from->resource)) {
tmp->status=status;
tmp->jinglecapable=gtalk_yuck(pak->x);
+ found = tmp;
if(status == 6) { /* Sign off Destroy resource */
ast_verbose("KILL THE SIGN OFF!\n");
found = tmp;
@@ -1142,21 +1151,24 @@
struct aji_client *client = (struct aji_client *) data;
while (res == IKS_OK) {
res = iks_recv(client->p,1);
+ client->timeout--;
if(res==IKS_HOOK) {
ast_log(LOG_WARNING,"JABBER: Got hook event.\n");
break;
- }
- if(res==IKS_NET_TLSFAIL) {
+ } else if(res==IKS_NET_TLSFAIL) {
ast_log(LOG_ERROR,"JABBER: Failure in tls.\n");
break;
- }
- client->timeout--;
- if(client->timeout == 0 && client->state !=AJI_CONNECTED) {
+ } else if(client->timeout == 0 && client->state !=AJI_CONNECTED) {
res = -1;
ast_log(LOG_WARNING, "JABBER: Network Timeout\n");
- }
- if(res==IKS_NET_RWERR) {
+ } else if(res==IKS_NET_RWERR) {
ast_log(LOG_ERROR, "JABBER: socket read error\n");
+ }
+
+ if(res != IKS_OK){
+ ast_verbose("reconnecting %d\n",res);
+ res = aji_reconnect(client);
+ res = IKS_OK;
}
}
@@ -1427,6 +1439,24 @@
return IKS_FILTER_EAT;
}
+static int aji_reconnect(struct aji_client *client)
+{
+ int res=0;
+
+ client->state=AJI_DISCONNECTED;
+ iks_parser_reset(client->p);
+ client->authorized=0;
+ switch (client->component){
+ case AJI_COMPONENT:
+ res = aji_component_initialize(client);
+ break;
+ case AJI_CLIENT:
+ res = aji_client_initialize(client);
+ break;
+ }
+ return res;
+}
+
/*!
* \brief connects as a client to jabber server.
* \param aji_client struct, and xml packet.
@@ -1477,15 +1507,14 @@
goto failed;
}
client->stack = iks_stack_new(8192,8192);
+
if (!client->stack) {
ast_log(LOG_WARNING, "Failed to allocate stack for client '%s'\n", client->name);
goto failedstack;
}
- if (client->f)
- iks_filter_delete(client->f);
-
- client->f = iks_filter_new();
+ if (!client->f)
+ client->f = iks_filter_new();
if (!client->f) {
ast_log(LOG_WARNING, "Failed to create filter for client '%s'\n", client->name);
@@ -1493,6 +1522,7 @@
}
iks_set_log_hook(client->p,aji_log_hook);
+
if(!strchr(client->user,'/')) {
resource = NULL;
asprintf(&resource,"%s/asterisk", client->user);
@@ -1504,6 +1534,7 @@
client->jid = iks_id_new(client->stack,client->user);
}
connected = iks_connect_via(client->p, client->serverhost, client->port, client->server);
+
if(connected== IKS_NET_NOCONN) {
ast_log(LOG_ERROR, "JABBER ERROR: No Connection\n");
goto failed;
@@ -1511,7 +1542,8 @@
if(connected == IKS_NET_NODNS) {
ast_log(LOG_ERROR, "JABBER ERROR: No DNS\n");
goto failed;
- }
+ } else
+ iks_recv(client->p,30);
return 1;
failedfilter:
@@ -1536,9 +1568,12 @@
int connected=1;
if(!client->f)
client->f = iks_filter_new();
- client->stack = iks_stack_new(8192,8192);
- client->jid = iks_id_new(client->stack, client->user);
- client->p = iks_stream_new("jabber:component:accept", client, aji_act_hook);
+ if(!client->stack)
+ client->stack = iks_stack_new(8192,8192);
+ if(!client->jid)
+ client->jid = iks_id_new(client->stack, client->user);
+ if(!client->p)
+ client->p = iks_stream_new("jabber:component:accept", client, aji_act_hook);
iks_set_log_hook(client->p, aji_log_hook);
connected =iks_connect_via(client->p, client->server, client->port, client->user);
More information about the asterisk-commits
mailing list