[asterisk-commits] marquis: branch marquis/pubsub-distributed-events r213878 - in /team/marquis/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Aug 24 15:14:07 CDT 2009
Author: marquis
Date: Mon Aug 24 15:14:03 2009
New Revision: 213878
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=213878
Log:
There are several reasons why it not only doesn't make sense but is a lot more complicated to support event distribution to multiple XMPP connections. This commit will prevent such. Now only the first connection configured with "distribute_events=yes" will do so.
Modified:
team/marquis/pubsub-distributed-events/include/asterisk/jabber.h
team/marquis/pubsub-distributed-events/res/res_jabber.c
Modified: team/marquis/pubsub-distributed-events/include/asterisk/jabber.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/marquis/pubsub-distributed-events/include/asterisk/jabber.h?view=diff&rev=213878&r1=213877&r2=213878
==============================================================================
--- team/marquis/pubsub-distributed-events/include/asterisk/jabber.h (original)
+++ team/marquis/pubsub-distributed-events/include/asterisk/jabber.h Mon Aug 24 15:14:03 2009
@@ -83,7 +83,8 @@
enum {
AJI_AUTOPRUNE = (1 << 0),
AJI_AUTOREGISTER = (1 << 1),
- AJI_XEP0248 = ( 1 << 2)
+ AJI_XEP0248 = ( 1 << 2),
+ AJI_PUBSUB = ( 1 << 3)
};
enum aji_btype {
Modified: team/marquis/pubsub-distributed-events/res/res_jabber.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/marquis/pubsub-distributed-events/res/res_jabber.c?view=diff&rev=213878&r1=213877&r2=213878
==============================================================================
--- team/marquis/pubsub-distributed-events/res/res_jabber.c (original)
+++ team/marquis/pubsub-distributed-events/res/res_jabber.c Mon Aug 24 15:14:03 2009
@@ -285,6 +285,8 @@
static struct aji_client_container clients;
static struct aji_capabilities *capabilities = NULL;
+static struct ast_event_sub *mwi_sub = NULL;
+static struct ast_event_sub *device_state_sub = NULL;
/*! \brief Global flags, initialized to default values */
static struct ast_flags globalflags = { AJI_AUTOREGISTER };
@@ -2476,7 +2478,7 @@
/*!
- * \brief Callback function for evnts
+ * \brief Callback function for events
* \param ast_event
* \param data void pointer to ast_client structure
* \return void
@@ -2513,8 +2515,18 @@
*/
static void aji_init_event_distribution(struct aji_client *client)
{
- struct ast_event_sub *mwi_sub;
- struct ast_event_sub *device_state_sub;
+ if(!mwi_sub) {
+ mwi_sub = ast_event_subscribe(AST_EVENT_MWI, aji_event_cb, "aji_mwi_subscription",
+ client, AST_EVENT_IE_END);
+ }
+ if(!device_state_sub) {
+ if (ast_enable_distributed_devstate()) {
+ return;
+ }
+ device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE_CHANGE,
+ aji_event_cb, "aji_devstate_subscription", client, AST_EVENT_IE_END);
+ ast_event_dump_cache(device_state_sub);
+ }
if(ast_test_flag(&globalflags, AJI_XEP0248)) {
aji_create_pubsub_collection(client, "device_state");
aji_create_pubsub_collection(client, "message_waiting");
@@ -2523,21 +2535,12 @@
aji_create_pubsub_node(client, NULL, "message_waiting", NULL);
}
- mwi_sub = ast_event_subscribe(AST_EVENT_MWI, aji_event_cb, "aji_mwi_subscription",
- client, AST_EVENT_IE_END);
- ast_log(LOG_DEBUG, "Subscribed to MWI\n");
+
iks_filter_add_rule(client->f, aji_handle_pubsub_event, client, IKS_RULE_TYPE,
IKS_PAK_MESSAGE, IKS_RULE_FROM, client->pubsub_node, IKS_RULE_DONE);
iks_filter_add_rule(client->f, aji_handle_publish_error, client, IKS_RULE_TYPE,
IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_DONE);
- if (ast_enable_distributed_devstate()) {
- return;
- }
- device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE_CHANGE, aji_event_cb,
- "aji_devstate_subscription", client, AST_EVENT_IE_END);
- ast_event_dump_cache(device_state_sub);
- ast_log(LOG_DEBUG, "Subscribed to Devstate changes\n");
}
/*!
@@ -3278,7 +3281,12 @@
if (client->component) {
ast_log(LOG_ERROR, "Client cannot be configure to be both a component and to distribute events! Event distribution will be disabled.\n");
} else {
- client->distribute_events= 1;
+ if(ast_test_flag(&globalflags, AJI_PUBSUB)) {
+ ast_log(LOG_ERROR, "Only one connection can be configured for distributed events.\n");
+ } else {
+ ast_set_flag(&globalflags, AJI_PUBSUB);
+ client->distribute_events = 1;
+ }
}
}
} else if (!strcasecmp(var->name, "pubsub_node")) {
@@ -3632,7 +3640,12 @@
ast_unregister_application(app_ajistatus);
ast_manager_unregister("JabberSend");
ast_custom_function_unregister(&jabberstatus_function);
-
+ if(mwi_sub) {
+ ast_event_unsubscribe(mwi_sub);
+ }
+ if(device_state_sub) {
+ ast_event_unsubscribe(device_state_sub);
+ }
ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
ASTOBJ_RDLOCK(iterator);
ast_debug(3, "JABBER: Releasing and disconnecting client: %s\n", iterator->name);
More information about the asterisk-commits
mailing list