[asterisk-commits] mjordan: branch mjordan/trunk-astdb-cluster r432913 - in /team/mjordan/trunk-...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 13 15:25:54 CDT 2015
Author: mjordan
Date: Fri Mar 13 15:25:51 2015
New Revision: 432913
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432913
Log:
AstDB clustering: add shared DB functions; res_pjsip support
Modified:
team/mjordan/trunk-astdb-cluster/funcs/func_db.c
team/mjordan/trunk-astdb-cluster/include/asterisk/astdb.h
team/mjordan/trunk-astdb-cluster/include/asterisk/event_defs.h
team/mjordan/trunk-astdb-cluster/main/db.c
team/mjordan/trunk-astdb-cluster/res/res_pjsip_outbound_publish.c
team/mjordan/trunk-astdb-cluster/res/res_pjsip_publish_asterisk.c
team/mjordan/trunk-astdb-cluster/res/res_pjsip_pubsub.c
Modified: team/mjordan/trunk-astdb-cluster/funcs/func_db.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/funcs/func_db.c?view=diff&rev=432913&r1=432912&r2=432913
==============================================================================
--- team/mjordan/trunk-astdb-cluster/funcs/func_db.c (original)
+++ team/mjordan/trunk-astdb-cluster/funcs/func_db.c Fri Mar 13 15:25:51 2015
@@ -437,7 +437,7 @@
/* Generally, failure is benign (key exists) */
ast_debug(2, "Failed to create shared family '%s'\n", value);
} else {
- ast_verb(4, "Created %s shared family '%s'",
+ ast_verb(4, "Created %s shared family '%s'\n",
share_type == SHARED_DB_TYPE_GLOBAL ? "GLOBAL" : "UNIQUE",
value);
}
Modified: team/mjordan/trunk-astdb-cluster/include/asterisk/astdb.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/include/asterisk/astdb.h?view=diff&rev=432913&r1=432912&r2=432913
==============================================================================
--- team/mjordan/trunk-astdb-cluster/include/asterisk/astdb.h (original)
+++ team/mjordan/trunk-astdb-cluster/include/asterisk/astdb.h Fri Mar 13 15:25:51 2015
@@ -29,6 +29,9 @@
#endif
#include "asterisk/utils.h"
+
+struct stasis_topic;
+struct stasis_message_type;
enum ast_db_shared_type {
/* Items in the shared family are common across all Asterisk instances */
@@ -37,15 +40,17 @@
SHARED_DB_TYPE_UNIQUE,
};
+/*! \brief An actual entry in the AstDB */
struct ast_db_entry {
+ /*! The next entry, if there are multiple entries */
struct ast_db_entry *next;
+ /*! The key of the entry */
char *key;
+ /*! The data associated with the key */
char data[0];
};
-struct stasis_topic;
-struct stasis_message_type;
-
+/*! \brief A shared family of keys in the AstDB */
struct ast_db_shared_family {
/*! How the family is shared */
enum ast_db_shared_type share_type;
@@ -55,31 +60,61 @@
char name[0];
};
+/*!
+ * \since 14.0.0
+ * \brief Create a new database entry
+ *
+ * \param key The key of the entry in the database
+ * \param value The value of the entry
+ *
+ * \note The entry returned is allocated on the heap, and should be
+ * disposed of using \ref ast_db_freetree
+ *
+ * \retval NULL on error
+ * \retval \c ast_db_entry on success
+ */
struct ast_db_entry *ast_db_entry_create(const char *key, const char *value);
-struct ast_db_shared_family *ast_db_shared_family_alloc(const char *family, enum ast_db_shared_type share_type);
-
-int ast_db_publish_shared_message(struct stasis_message_type *type, struct ast_db_shared_family *shared_family, struct ast_eid *eid);
-
-void ast_db_refresh_shared(void);
+/*!
+ * \since 14.0.0
+ * \brief Create a shared database family
+ *
+ * \param family The family to share
+ * \param share_type The way in which the family should be shared
+ *
+ * \note The \c ast_db_shared_family structure is an \c ao2 ref counted
+ * object.
+ *
+ * \retval NULL on error
+ * \retval an \c ao2 ref counted \c ast_db_shared_family object
+ */
+struct ast_db_shared_family *ast_db_shared_family_alloc(const char *family,
+ enum ast_db_shared_type share_type);
/*! \addtogroup StasisTopicsAndMessages
* @{
*/
+/*!
+ * \since 14.0.0
+ * \brief Topic for families that should be passed to clustered Asterisk
+ * instances
+ *
+ * \retval A stasis topic
+ */
struct stasis_topic *ast_db_cluster_topic(void);
/*!
- * \since 14
- * \brief Message type for an RTCP message sent from this Asterisk instance
+ * \since 14.0.0
+ * \brief Message type for an update to a shared family
*
* \retval A stasis message type
*/
struct stasis_message_type *ast_db_put_shared_type(void);
/*!
- * \since 14
- * \brief Message type for an RTCP message received from some external source
+ * \since 14.0.0
+ * \brief Message type for deletion of a shared family
*
* \retval A stasis message type
*/
@@ -88,12 +123,64 @@
/* }@ */
/*!
- * \brief @@@@
- */
-int ast_db_put_shared(const char *family, enum ast_db_shared_type);
-
+ * \since 14.0.0
+ * \brief Publish a message for a shared family
+ *
+ * \param type The \c stasis_message_type indicating what happened to
+ the shared family
+ * \param shared_family The shared family that was updated
+ * \param eid The server that conveyed the update
+ *
+ * \retval 0 success
+ * \retval -1 error
+ */
+int ast_db_publish_shared_message(struct stasis_message_type *type,
+ struct ast_db_shared_family *shared_family, struct ast_eid *eid);
+
+/*!
+ * \since 14.0.0
+ * \brief Refresh the state of all shared families
+ *
+ * \details
+ * This will cause Stasis messages to be generated that contain the current
+ * key/value pairs of all shared families. This can be used to send the state
+ * of all shared families to other Asterisk instances.
+ */
+void ast_db_refresh_shared(void);
+
+
+/*!
+ * \since 14.0.0
+ * \brief Add a new shared family
+ *
+ * \param family The family to share
+ * \param share_type The way in which the family should be shared
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_db_put_shared(const char *family, enum ast_db_shared_type share_type);
+
+/*!
+ * \since 14.0.0
+ * \brief Delete a shared family
+ *
+ * \param family The family whose shared status should be removed
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
int ast_db_del_shared(const char *family);
+/*!
+ * \since 14.0.0
+ * \brief Check if a family is shared
+ *
+ * \param family The family to verify
+ *
+ * \retval 0 The family is not shared
+ * \retval 1 The family is shared
+ */
int ast_db_is_shared(const char *family);
/*! \brief Get key value specified by family/key */
Modified: team/mjordan/trunk-astdb-cluster/include/asterisk/event_defs.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/include/asterisk/event_defs.h?view=diff&rev=432913&r1=432912&r2=432913
==============================================================================
--- team/mjordan/trunk-astdb-cluster/include/asterisk/event_defs.h (original)
+++ team/mjordan/trunk-astdb-cluster/include/asterisk/event_defs.h Fri Mar 13 15:25:51 2015
@@ -58,8 +58,10 @@
AST_EVENT_ACL_CHANGE = 0x0b,
/*! Send out a ping for debugging distributed events */
AST_EVENT_PING = 0x0c,
+ /*! Send out a shared database event */
+ AST_EVENT_DB_SHARED = 0x0d,
/*! Number of event types. This should be the last event type + 1 */
- AST_EVENT_TOTAL = 0x0d,
+ AST_EVENT_TOTAL = 0x0e,
};
/*! \brief Event Information Element types */
@@ -302,8 +304,38 @@
* Payload type: UINT
*/
AST_EVENT_IE_CACHABLE = 0x003d,
+ /*!
+ * \brief AstDB Family
+ * Used by: AST_EVENT_DB_SHARED
+ * Payload type: STR
+ */
+ AST_EVENT_IE_DB_FAMILY = 0x003e,
+ /*!
+ * \brief AstDB action to take
+ * Used by: AST_EVENT_DB_SHARED
+ * Payload type: STR
+ */
+ AST_EVENT_ID_DB_ACTION_TYPE = 0x003f,
+ /*!
+ * \brief AstDB share type
+ * Used by: AST_EVENT_DB_SHARED
+ * Payload type: UINT
+ */
+ AST_EVENT_IE_DB_SHARE_TYPE = 0x0040,
+ /*!
+ * \brief AstDB key
+ * Used by: AST_EVENT_DB_SHARED
+ * Payload type: STR
+ */
+ AST_EVENT_IE_DB_KEY = 0x0041,
+ /*!
+ * \brief AstDB value
+ * Used by: AST_EVENT_DB_SHARED
+ * Payload type: STR
+ */
+ AST_EVENT_IE_DB_VALUE = 0x0042,
/*! \brief Must be the last IE value +1 */
- AST_EVENT_IE_TOTAL = 0x003e,
+ AST_EVENT_IE_TOTAL = 0x0043,
};
/*!
Modified: team/mjordan/trunk-astdb-cluster/main/db.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/main/db.c?view=diff&rev=432913&r1=432912&r2=432913
==============================================================================
--- team/mjordan/trunk-astdb-cluster/main/db.c (original)
+++ team/mjordan/trunk-astdb-cluster/main/db.c Fri Mar 13 15:25:51 2015
@@ -51,6 +51,7 @@
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/manager.h"
+#include "asterisk/event.h"
/*** DOCUMENTATION
<manager name="DBGet" language="en_US">
@@ -115,12 +116,15 @@
/*! \brief A container of families to share across Asterisk instances */
static struct ao2_container *shared_families;
+/*! \brief The Stasis topic for shared families */
static struct stasis_topic *db_cluster_topic;
+/*! \brief A Stasis message router for handling external AstDB updates */
static struct stasis_message_router *message_router;
static void db_sync(void);
+/*! \brief The AstDB key used to store which families are shared across restarts */
#define SHARED_FAMILY "__asterisk_shared_family"
#define DEFINE_SQL_STATEMENT(stmt,sql) static sqlite3_stmt *stmt; \
@@ -223,6 +227,9 @@
return entry;
}
+/*! \internal
+ * \brief AO2 destructor for \c ast_db_shared_family
+ */
static void shared_db_family_dtor(void *obj)
{
struct ast_db_shared_family *family = obj;
@@ -245,6 +252,9 @@
return shared_family;
}
+/*! \internal
+ * \brief Clone a \c ast_db_shared_family
+ */
static struct ast_db_shared_family *db_shared_family_clone(const struct ast_db_shared_family *shared_family)
{
struct ast_db_shared_family *clone;
@@ -254,6 +264,9 @@
return clone;
}
+/*! \internal
+ * \brief AO2 container sort function for \c ast_db_shared_family
+ */
static int db_shared_family_sort_fn(const void *obj_left, const void *obj_right, int flags)
{
const struct ast_db_shared_family *left = obj_left;
@@ -275,7 +288,6 @@
}
return cmp;
}
-
static int db_create_astdb(void)
{
@@ -436,7 +448,7 @@
return res;
}
-static int db_put_shared(const char *family, const char *key, const char *value)
+static int db_entry_put_shared(const char *family, const char *key, const char *value)
{
struct ast_db_shared_family *shared_family;
struct ast_db_shared_family *clone;
@@ -468,7 +480,7 @@
return 0;
}
-static int db_del_shared(const char *family, const char *key)
+static int db_entry_del_shared(const char *family, const char *key)
{
struct ast_db_shared_family *shared_family;
struct ast_db_shared_family *clone;
@@ -558,7 +570,7 @@
sqlite3_reset(put_stmt);
db_sync();
if (share) {
- db_put_shared(family, key, value);
+ db_entry_put_shared(family, key, value);
}
ast_mutex_unlock(&dblock);
@@ -664,7 +676,7 @@
sqlite3_reset(del_stmt);
db_sync();
if (share) {
- db_del_shared(family, key);
+ db_entry_del_shared(family, key);
}
ast_mutex_unlock(&dblock);
@@ -707,7 +719,7 @@
sqlite3_reset(stmt);
db_sync();
if (share) {
- db_del_shared(prefix, NULL);
+ db_entry_del_shared(prefix, NULL);
}
ast_mutex_unlock(&dblock);
@@ -863,6 +875,71 @@
return CLI_SUCCESS;
}
+static char *handle_cli_database_put_shared(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int res;
+ enum ast_db_shared_type share_type;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "database put shared";
+ e->usage =
+ "Usage: database put shared <family> <type>\n"
+ " Creates a new shared family of the given type,\n"
+ " where type is either 'unique' or 'global'.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 5) {
+ return CLI_SHOWUSAGE;
+ }
+
+ if (!strcasecmp(a->argv[4], "unique")) {
+ share_type = SHARED_DB_TYPE_UNIQUE;
+ } else if (!strcasecmp(a->argv[4], "global")) {
+ share_type = SHARED_DB_TYPE_GLOBAL;
+ } else {
+ ast_cli(a->fd, "Unknown share type: '%s'\n", a->argv[4]);
+ return CLI_SUCCESS;
+ }
+
+ res = ast_db_put_shared(a->argv[3], share_type);
+ if (res) {
+ ast_cli(a->fd, "Could not share family '%s' (is it already shared?)\n", a->argv[3]);
+ } else {
+ ast_cli(a->fd, "Shared database family '%s'.\n", a->argv[3]);
+ }
+ return CLI_SUCCESS;
+}
+
+static char *handle_cli_database_del_shared(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int res;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "database del shared";
+ e->usage =
+ "Usage: database del shared <family>\n"
+ " Deletes the shared status of a database family.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 4) {
+ return CLI_SHOWUSAGE;
+ }
+ res = ast_db_del_shared(a->argv[3]);
+ if (res) {
+ ast_cli(a->fd, "Shared family '%s' does not exist.\n", a->argv[3]);
+ } else {
+ ast_cli(a->fd, "Shared database family '%s' removed.\n", a->argv[3]);
+ }
+ return CLI_SUCCESS;
+}
static char *handle_cli_database_deltree(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int num_deleted;
@@ -896,6 +973,45 @@
ast_cli(a->fd, "%d database entries removed.\n",num_deleted);
}
return CLI_SUCCESS;
+}
+
+static int print_database_show(struct ast_cli_args *a, sqlite3_stmt *stmt)
+{
+ int counter = 0;
+
+ ast_cli(a->fd, "%-50s: %-25s %s\n", "Key", "Data", "Shared");
+ ast_cli(a->fd, "-------------------------------------------------- ------------------------- ------\n");
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ struct ast_db_shared_family *shared_family;
+ const char *key_s;
+ const char *value_s;
+ char *family_s;
+ char *delim;
+
+ if (!(key_s = (const char *) sqlite3_column_text(stmt, 0))) {
+ break;
+ }
+ if (!(value_s = (const char *) sqlite3_column_text(stmt, 1))) {
+ break;
+ }
+ family_s = ast_strdup(key_s);
+ if (!family_s) {
+ break;
+ }
+ delim = strchr(family_s + 1, '/');
+ *delim = '\0';
+
+ shared_family = ao2_find(shared_families, family_s + 1, OBJ_SEARCH_KEY);
+
+ ++counter;
+ ast_cli(a->fd, "%-50s: %-25s %s\n", key_s, value_s,
+ shared_family ? (shared_family->share_type == SHARED_DB_TYPE_UNIQUE ? "(U)" : "(G)") : "");
+
+ ao2_cleanup(shared_family);
+ ast_free(family_s);
+ }
+
+ return counter;
}
static char *handle_cli_database_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -941,19 +1057,7 @@
return NULL;
}
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- const char *key_s, *value_s;
- if (!(key_s = (const char *) sqlite3_column_text(stmt, 0))) {
- ast_log(LOG_WARNING, "Skipping invalid key!\n");
- continue;
- }
- if (!(value_s = (const char *) sqlite3_column_text(stmt, 1))) {
- ast_log(LOG_WARNING, "Skipping invalid value!\n");
- continue;
- }
- ++counter;
- ast_cli(a->fd, "%-50s: %-25s\n", key_s, value_s);
- }
+ counter = print_database_show(a, stmt);
sqlite3_reset(stmt);
ast_mutex_unlock(&dblock);
@@ -989,29 +1093,8 @@
return NULL;
}
- while (sqlite3_step(showkey_stmt) == SQLITE_ROW) {
- const char *key_s, *value_s;
- char *family_s;
- char *delim;
-
- if (!(key_s = (const char *) sqlite3_column_text(showkey_stmt, 0))) {
- break;
- }
- if (!(value_s = (const char *) sqlite3_column_text(showkey_stmt, 1))) {
- break;
- }
- family_s = ast_strdup(key_s);
- if (!family_s) {
- break;
- }
- delim = strchr(family_s + 1, '/');
- *delim = '\0';
-
- ++counter;
- ast_cli(a->fd, "%-50s: %-25s %s\n", key_s, value_s,
- ast_db_is_shared(family_s + 1) ? "(S)" : "");
- ast_free(family_s);
- }
+ counter = print_database_show(a, showkey_stmt);
+
sqlite3_reset(showkey_stmt);
ast_mutex_unlock(&dblock);
@@ -1059,13 +1142,15 @@
}
static struct ast_cli_entry cli_database[] = {
- AST_CLI_DEFINE(handle_cli_database_show, "Shows database contents"),
- AST_CLI_DEFINE(handle_cli_database_showkey, "Shows database contents"),
- AST_CLI_DEFINE(handle_cli_database_get, "Gets database value"),
- AST_CLI_DEFINE(handle_cli_database_put, "Adds/updates database value"),
- AST_CLI_DEFINE(handle_cli_database_del, "Removes database key/value"),
- AST_CLI_DEFINE(handle_cli_database_deltree, "Removes database keytree/values"),
- AST_CLI_DEFINE(handle_cli_database_query, "Run a user-specified query on the astdb"),
+ AST_CLI_DEFINE(handle_cli_database_show, "Shows database contents"),
+ AST_CLI_DEFINE(handle_cli_database_showkey, "Shows database contents"),
+ AST_CLI_DEFINE(handle_cli_database_get, "Gets database value"),
+ AST_CLI_DEFINE(handle_cli_database_put, "Adds/updates database value"),
+ AST_CLI_DEFINE(handle_cli_database_del, "Removes database key/value"),
+ AST_CLI_DEFINE(handle_cli_database_put_shared, "Add a shared family"),
+ AST_CLI_DEFINE(handle_cli_database_del_shared, "Remove a shared family"),
+ AST_CLI_DEFINE(handle_cli_database_deltree, "Removes database keytree/values"),
+ AST_CLI_DEFINE(handle_cli_database_query, "Run a user-specified query on the astdb"),
};
static int manager_dbput(struct mansession *s, const struct message *m)
@@ -1254,7 +1339,6 @@
if (!message) {
return -1;
}
-
stasis_publish(ast_db_cluster_topic(), message);
return 0;
@@ -1343,25 +1427,21 @@
"entries", shared_family->entries ? db_entries_to_json(shared_family->entries) : ast_json_null());
}
-static struct ast_event *db_put_shared_type_to_event(struct stasis_message *message)
-{
- return NULL;
-}
-
struct stasis_topic *ast_db_cluster_topic(void)
{
return db_cluster_topic;
}
STASIS_MESSAGE_TYPE_DEFN(ast_db_put_shared_type,
- .to_event = db_put_shared_type_to_event,
.to_json = db_shared_family_to_json,
);
STASIS_MESSAGE_TYPE_DEFN(ast_db_del_shared_type,
- .to_event = db_del_shared_type_to_event,
.to_json = db_shared_family_to_json,
);
+/*! \internal
+ * \brief Stasis message callback for external updates to AstDB shared families
+ */
static void db_put_shared_msg_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
{
struct ast_db_shared_family *shared_family;
@@ -1375,6 +1455,7 @@
return;
}
+ /* Pass on any updates that originated from ourselves */
eid = stasis_message_eid(message);
if (!eid || !ast_eid_cmp(eid, &ast_eid_default)) {
return;
@@ -1403,6 +1484,9 @@
}
}
+/*! \internal
+ * \brief Stasis message callback for external deletes to AstDB shared families
+ */
static void db_del_shared_msg_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
{
struct ast_db_shared_family *shared_family;
@@ -1414,6 +1498,7 @@
return;
}
+ /* Pass on any updates that originated from ourselves */
eid = stasis_message_eid(message);
if (!eid || !ast_eid_cmp(eid, &ast_eid_default)) {
return;
@@ -1467,6 +1552,39 @@
ast_mutex_unlock(&dblock);
}
+/*! \internal
+ * \brief Rebuild shared families from any stored in the AstDB
+ */
+static void restore_shared_families(void)
+{
+ struct ast_db_entry *entry;
+ struct ast_db_entry *cur;
+
+ entry = ast_db_gettree(SHARED_FAMILY, "");
+ for (cur = entry; cur; cur = cur->next) {
+ enum ast_db_shared_type share_type;
+ const char *family;
+
+ /* Find the 'key', which is the name of the shared family */
+ family = strchr(cur->key + 1, '/') + 1;
+ if (!family) {
+ continue;
+ }
+
+ if (!strcasecmp(cur->data, "unique")) {
+ share_type = SHARED_DB_TYPE_UNIQUE;
+ } else if (!strcasecmp(cur->data, "global")) {
+ share_type = SHARED_DB_TYPE_GLOBAL;
+ } else {
+ continue;
+ }
+
+ ast_db_put_shared(family, share_type);
+ }
+
+ ast_db_freetree(entry);
+}
+
int astdb_init(void)
{
shared_families = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_MUTEX,
@@ -1501,6 +1619,8 @@
ao2_ref(shared_families, -1);
return -1;
}
+
+ restore_shared_families();
ast_cond_init(&dbcond, NULL);
if (ast_pthread_create_background(&syncthread, NULL, db_sync_thread, NULL)) {
Modified: team/mjordan/trunk-astdb-cluster/res/res_pjsip_outbound_publish.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/res/res_pjsip_outbound_publish.c?view=diff&rev=432913&r1=432912&r2=432913
==============================================================================
--- team/mjordan/trunk-astdb-cluster/res/res_pjsip_outbound_publish.c (original)
+++ team/mjordan/trunk-astdb-cluster/res/res_pjsip_outbound_publish.c Fri Mar 13 15:25:51 2015
@@ -370,6 +370,8 @@
ast_log(LOG_ERROR, "Failed to start outbound publish with event '%s' for client '%s'\n",
publish->event, ast_sorcery_object_get_id(publish));
} else {
+ ast_debug(2, "Started outbound publish client '%s' for event '%s'\n",
+ ast_sorcery_object_get_id(publish), publish->event);
state->client->started = 1;
}
} else if (state->client->started && !handler && removed && !strcmp(publish->event, removed->event_name)) {
@@ -380,6 +382,9 @@
ast_log(LOG_WARNING, "Could not stop refresh timer on client '%s'\n",
ast_sorcery_object_get_id(publish));
ao2_ref(state->client, -1);
+ } else {
+ ast_debug(2, "Stopped outbound publish client '%s'\n",
+ ast_sorcery_object_get_id(publish));
}
}
ao2_ref(publish, -1);
@@ -429,6 +434,8 @@
}
sub_add_handler(handler);
+
+ ast_debug(1, "Registered publisher handler for event '%s'\n", handler->event_name);
sip_outbound_publish_synchronize(NULL);
Modified: team/mjordan/trunk-astdb-cluster/res/res_pjsip_publish_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/res/res_pjsip_publish_asterisk.c?view=diff&rev=432913&r1=432912&r2=432913
==============================================================================
--- team/mjordan/trunk-astdb-cluster/res/res_pjsip_publish_asterisk.c (original)
+++ team/mjordan/trunk-astdb-cluster/res/res_pjsip_publish_asterisk.c Fri Mar 13 15:25:51 2015
@@ -59,7 +59,7 @@
<configOption name="mailboxstate_publish">
<synopsis>Optional name of a publish item that can be used to publish a request for full mailbox state information.</synopsis>
</configOption>
- <configOption name="dbstate_publish">
+ <configOption name="db_publish">
<synopsis>Optional name of a publish item that can be used to publish a request for full AstDB state information.</synopsis>
</configOption>
<configOption name="device_state" default="no">
@@ -187,10 +187,28 @@
}
}
-/*! \brief Datastore for attaching devicestate publisher state information */
+/*! \brief Datastore for attaching MWI publisher state information */
static const struct ast_datastore_info asterisk_mwi_publisher_state_datastore = {
.type = "asterisk-mwi-publisher",
.destroy = asterisk_mwi_publisher_state_destroy,
+};
+
+static void asterisk_db_publisher_state_destroy(void *obj)
+{
+ struct asterisk_db_publisher_state *publisher_state = obj;
+
+ ao2_cleanup(publisher_state->client);
+
+ if (publisher_state->db_state_filter) {
+ regfree(&publisher_state->db_state_regex);
+ }
+}
+
+
+/*! \brief Datastore for attaching database publisher state information */
+static const struct ast_datastore_info asterisk_db_publisher_state_datastore = {
+ .type = "asterisk-db-publisher",
+ .destroy = asterisk_db_publisher_state_destroy,
};
/*!
@@ -336,6 +354,11 @@
return;
}
+ if (stasis_message_type(msg) != ast_db_put_shared_type()
+ && stasis_message_type(msg) != ast_db_del_shared_type()) {
+ return;
+ }
+
eid = stasis_message_eid(msg);
if (!eid || ast_eid_cmp(&ast_eid_default, eid)) {
/* If the event is aggregate, unknown, or didn't originate from this
@@ -350,6 +373,7 @@
if (publisher_state->db_state_filter && regexec(&publisher_state->db_state_regex, shared_family->name, 0, NULL, 0)) {
/* Outgoing AstDB state is filtered and the family wasn't allowed */
+ ast_debug(3, "Filtered out state family '%s'\n", shared_family->name);
return;
}
@@ -578,7 +602,7 @@
struct asterisk_db_publisher_state *publisher_state;
const char *value;
- datastore = ast_sip_publish_client_alloc_datastore(&asterisk_mwi_publisher_state_datastore, "asterisk-db-publisher");
+ datastore = ast_sip_publish_client_alloc_datastore(&asterisk_db_publisher_state_datastore, "asterisk-db-publisher");
if (!datastore) {
return -1;
}
@@ -596,7 +620,6 @@
}
publisher_state->db_state_filter = 1;
}
-
publisher_state->client = ao2_bump(client);
if (ast_sip_publish_client_add_datastore(client, datastore)) {
@@ -1261,7 +1284,7 @@
ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "asterisk-publication", "db_state_filter", "", regex_filter_handler, NULL, NULL, 0, 0);
ast_sorcery_reload_object(ast_sip_get_sorcery(), "asterisk-publication");
- for (i = 0; i < ARRAY_LEN(&publish_handlers); i++) {
+ for (i = 0; i < ARRAY_LEN(publish_handlers); i++) {
if (ast_sip_register_publish_handler(publish_handlers[i])) {
ast_log(LOG_WARNING, "Unable to register event publication handler %s\n",
publish_handlers[i]->event_name);
@@ -1272,7 +1295,7 @@
}
}
- for (i = 0; i < ARRAY_LEN(&event_publisher_handlers); i++) {
+ for (i = 0; i < ARRAY_LEN(event_publisher_handlers); i++) {
if (ast_sip_register_event_publisher_handler(event_publisher_handlers[i])) {
ast_log(LOG_WARNING, "Unable to register event publisher handler %s\n",
event_publisher_handlers[i]->event_name);
@@ -1302,11 +1325,11 @@
{
int i;
- for (i = 0; i < ARRAY_LEN(&publish_handlers); i++) {
+ for (i = 0; i < ARRAY_LEN(publish_handlers); i++) {
ast_sip_unregister_publish_handler(publish_handlers[i]);
}
- for (i = 0; i < ARRAY_LEN(&event_publisher_handlers); i++) {
+ for (i = 0; i < ARRAY_LEN(event_publisher_handlers); i++) {
ast_sip_unregister_event_publisher_handler(event_publisher_handlers[i]);
}
Modified: team/mjordan/trunk-astdb-cluster/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/trunk-astdb-cluster/res/res_pjsip_pubsub.c?view=diff&rev=432913&r1=432912&r2=432913
==============================================================================
--- team/mjordan/trunk-astdb-cluster/res/res_pjsip_pubsub.c (original)
+++ team/mjordan/trunk-astdb-cluster/res/res_pjsip_pubsub.c Fri Mar 13 15:25:51 2015
@@ -2331,6 +2331,8 @@
publish_add_handler(handler);
+ ast_debug(1, "Registered publish handler for event '%s'\n", handler->event_name);
+
ast_module_ref(ast_module_info->self);
return 0;
@@ -2770,11 +2772,14 @@
resource = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "inbound-publication", resource_name);
if (!resource) {
+ ast_debug(1, "No publication resource found for resource: '%s'\n", resource_name);
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 404, NULL, NULL, NULL);
return NULL;
}
if (!ast_strlen_zero(resource->endpoint) && strcmp(resource->endpoint, ast_sorcery_object_get_id(endpoint))) {
+ ast_debug(1, "Resource endpoint '%s' does not match endpoint '%s'\n",
+ resource->endpoint, ast_sorcery_object_get_id(endpoint));
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 403, NULL, NULL, NULL);
return NULL;
}
@@ -2786,6 +2791,7 @@
}
if (!event_configuration_name) {
+ ast_debug(1, "Configuration did not contain a match for event '%s'\n", handler->event_name);
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 404, NULL, NULL, NULL);
return NULL;
}
More information about the asterisk-commits
mailing list