xmpp cleanup
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@195 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
6c0ea31f81
commit
549d9ca93a
|
@ -72,7 +72,9 @@ static void event_handler (switch_event *event)
|
|||
switch_event_serialize(event, buf, sizeof(buf), NULL);
|
||||
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nEVENT\n--------------------------------\n%s\n", buf);
|
||||
msg = iks_make_msg(IKS_TYPE_NONE, globals.target_jid, buf);
|
||||
iks_insert_attrib(msg, "subject", "Event");
|
||||
iks_send(globals.session.parser, msg);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -132,15 +134,13 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_jid, globals.jid)
|
|||
|
||||
}
|
||||
|
||||
int
|
||||
on_result (struct session *sess, ikspak *pak)
|
||||
int on_result (struct session *sess, ikspak *pak)
|
||||
{
|
||||
|
||||
return IKS_FILTER_EAT;
|
||||
}
|
||||
|
||||
int
|
||||
on_stream (struct session *sess, int type, iks *node)
|
||||
int on_stream (struct session *sess, int type, iks *node)
|
||||
{
|
||||
sess->counter = opt_timeout;
|
||||
//iks *x;
|
||||
|
@ -177,6 +177,7 @@ on_stream (struct session *sess, int type, iks *node)
|
|||
} else if (strcmp ("failure", iks_name (node)) == 0) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sasl authentication failed\n");
|
||||
} else if (strcmp ("success", iks_name (node)) == 0) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "server connected\n");
|
||||
sess->authorized = 1;
|
||||
iks_send_header (sess->parser, sess->acc->server);
|
||||
} else {
|
||||
|
@ -203,23 +204,20 @@ on_stream (struct session *sess, int type, iks *node)
|
|||
return IKS_OK;
|
||||
}
|
||||
|
||||
int
|
||||
on_error (void *user_data, ikspak *pak)
|
||||
int on_error (void *user_data, ikspak *pak)
|
||||
{
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "authorization failed\n");
|
||||
return IKS_FILTER_EAT;
|
||||
}
|
||||
|
||||
void
|
||||
on_log (struct session *sess, const char *data, size_t size, int is_incoming)
|
||||
void on_log (struct session *sess, const char *data, size_t size, int is_incoming)
|
||||
{
|
||||
if (iks_is_secure (sess->parser)) fprintf (stderr, "Sec");
|
||||
if (is_incoming) fprintf (stderr, "RECV"); else fprintf (stderr, "SEND");
|
||||
fprintf (stderr, "[%s]\n", data);
|
||||
}
|
||||
|
||||
void
|
||||
j_setup_filter (struct session *sess)
|
||||
void j_setup_filter (struct session *sess)
|
||||
{
|
||||
if (my_filter) iks_filter_delete (my_filter);
|
||||
my_filter = iks_filter_new ();
|
||||
|
@ -235,54 +233,77 @@ j_setup_filter (struct session *sess)
|
|||
IKS_RULE_DONE);
|
||||
}
|
||||
|
||||
static void j_connect (char *jabber_id, char *pass)
|
||||
static void xmpp_connect (char *jabber_id, char *pass)
|
||||
{
|
||||
|
||||
int e;
|
||||
|
||||
memset (&globals.session, 0, sizeof (globals.session));
|
||||
globals.session.parser = iks_stream_new (IKS_NS_CLIENT, &globals.session, (iksStreamHook *) on_stream);
|
||||
if (globals.debug) iks_set_log_hook (globals.session.parser, (iksLogHook *) on_log);
|
||||
globals.session.acc = iks_id_new (iks_parser_stack (globals.session.parser), jabber_id);
|
||||
if (NULL == globals.session.acc->resource) {
|
||||
/* user gave no resource name, use the default */
|
||||
char *tmp;
|
||||
tmp = iks_malloc (strlen (globals.session.acc->user) + strlen (globals.session.acc->server) + 9 + 3);
|
||||
sprintf (tmp, "%s@%s/%s", globals.session.acc->user, globals.session.acc->server, modname);
|
||||
globals.session.acc = iks_id_new (iks_parser_stack (globals.session.parser), tmp);
|
||||
iks_free (tmp);
|
||||
}
|
||||
globals.session.pass = pass;
|
||||
|
||||
j_setup_filter (&globals.session);
|
||||
|
||||
e = iks_connect_tcp (globals.session.parser, globals.session.acc->server, IKS_JABBER_PORT);
|
||||
switch (e) {
|
||||
case IKS_OK:
|
||||
break;
|
||||
case IKS_NET_NODNS:
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "hostname lookup failed\n");
|
||||
case IKS_NET_NOCONN:
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "connection failed\n");
|
||||
default:
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "io error\n");
|
||||
}
|
||||
|
||||
globals.session.counter = opt_timeout;
|
||||
while (RUNNING == 1) {
|
||||
e = iks_recv (globals.session.parser, 1);
|
||||
if(globals.session.job_done) break;
|
||||
if (IKS_HOOK == e) break;
|
||||
if (!globals.session.authorized) {
|
||||
if (IKS_NET_TLSFAIL == e) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "tls handshake failed\n");
|
||||
if (IKS_OK != e) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "io error\n");
|
||||
globals.session.counter--;
|
||||
if (globals.session.counter == 0) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "network timeout\n");
|
||||
int e;
|
||||
memset (&globals.session, 0, sizeof (globals.session));
|
||||
globals.session.parser = iks_stream_new (IKS_NS_CLIENT, &globals.session, (iksStreamHook *) on_stream);
|
||||
if (globals.debug) iks_set_log_hook (globals.session.parser, (iksLogHook *) on_log);
|
||||
globals.session.acc = iks_id_new (iks_parser_stack (globals.session.parser), jabber_id);
|
||||
if (NULL == globals.session.acc->resource) {
|
||||
/* user gave no resource name, use the default */
|
||||
char *tmp;
|
||||
tmp = iks_malloc (strlen (globals.session.acc->user) + strlen (globals.session.acc->server) + 9 + 3);
|
||||
sprintf (tmp, "%s@%s/%s", globals.session.acc->user, globals.session.acc->server, modname);
|
||||
globals.session.acc = iks_id_new (iks_parser_stack (globals.session.parser), tmp);
|
||||
iks_free (tmp);
|
||||
}
|
||||
globals.session.pass = pass;
|
||||
|
||||
j_setup_filter (&globals.session);
|
||||
|
||||
e = iks_connect_tcp (globals.session.parser, globals.session.acc->server, IKS_JABBER_PORT);
|
||||
switch (e) {
|
||||
case IKS_OK:
|
||||
break;
|
||||
case IKS_NET_NODNS:
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "hostname lookup failed\n");
|
||||
case IKS_NET_NOCONN:
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "connection failed\n");
|
||||
default:
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "io error\n");
|
||||
switch_sleep(5000000);
|
||||
continue;
|
||||
}
|
||||
|
||||
globals.session.counter = opt_timeout;
|
||||
while (RUNNING == 1) {
|
||||
e = iks_recv (globals.session.parser, 1);
|
||||
|
||||
if(globals.session.job_done) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (IKS_HOOK == e) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (IKS_OK != e) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "io error %d\n", e);
|
||||
switch_sleep(5000000);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!globals.session.authorized) {
|
||||
if (IKS_NET_TLSFAIL == e) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "tls handshake failed\n");
|
||||
switch_sleep(5000000);
|
||||
break;
|
||||
}
|
||||
|
||||
if (globals.session.counter == 0) {
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "network timeout\n");
|
||||
switch_sleep(5000000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iks_disconnect(globals.session.parser);
|
||||
iks_parser_delete (globals.session.parser);
|
||||
globals.session.authorized = 0;
|
||||
}
|
||||
iks_disconnect(globals.session.parser);
|
||||
iks_parser_delete (globals.session.parser);
|
||||
globals.session.authorized = 0;
|
||||
RUNNING = 0;
|
||||
|
||||
}
|
||||
|
@ -313,18 +334,21 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_inte
|
|||
|
||||
SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
|
||||
{
|
||||
RUNNING = -1;
|
||||
|
||||
while (RUNNING) {
|
||||
switch_yield(1000);
|
||||
if (RUNNING) {
|
||||
RUNNING = -1;
|
||||
while (RUNNING) {
|
||||
switch_yield(1000);
|
||||
}
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
|
||||
{
|
||||
RUNNING = 1;
|
||||
j_connect(globals.jid, globals.passwd);
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "disconnecting client\n");
|
||||
return SWITCH_STATUS_TERM;
|
||||
xmpp_connect(globals.jid, globals.passwd);
|
||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "disconnecting client %d\n", RUNNING);
|
||||
return RUNNING ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue