[asterisk-commits] file: branch file/pjsip-outbound-publish r419075 - in /team/file/pjsip-outbou...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 21 07:10:43 CDT 2014


Author: file
Date: Mon Jul 21 07:10:36 2014
New Revision: 419075

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419075
Log:
Incorporate review feedback.

Modified:
    team/file/pjsip-outbound-publish/include/asterisk/res_pjsip_outbound_publish.h
    team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c
    team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.exports.in
    team/file/pjsip-outbound-publish/res/res_pjsip_publish_asterisk.c
    team/file/pjsip-outbound-publish/res/res_pjsip_pubsub.c

Modified: team/file/pjsip-outbound-publish/include/asterisk/res_pjsip_outbound_publish.h
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-outbound-publish/include/asterisk/res_pjsip_outbound_publish.h?view=diff&rev=419075&r1=419074&r2=419075
==============================================================================
--- team/file/pjsip-outbound-publish/include/asterisk/res_pjsip_outbound_publish.h (original)
+++ team/file/pjsip-outbound-publish/include/asterisk/res_pjsip_outbound_publish.h Mon Jul 21 07:10:36 2014
@@ -26,6 +26,11 @@
 struct ast_datastore_info;
 
 /*!
+ * \brief Opaque structure representing outbound publish configuration
+ */
+struct ast_sip_outbound_publish;
+
+/*!
  * \brief Opaque structure representing an outbound publish client
  */
 struct ast_sip_outbound_publish_client;
@@ -40,12 +45,14 @@
 	/*!
 	 * \brief Called when a publisher should start publishing.
 	 *
+	 * \param configuration The outbound publish configuration, event-specific configuration
+	 *        is accessible using extended sorcery fields
 	 * \param client The publish client that can be used to send PUBLISH messages.
-	 * \param configuration Key value pair list of configuration for publisher.
 	 * \retval 0 success
 	 * \retval -1 failure
 	 */
-	int (*start_publishing)(struct ast_sip_outbound_publish_client *client, struct ast_variable *configuration);
+	int (*start_publishing)(struct ast_sip_outbound_publish *configuration,
+		struct ast_sip_outbound_publish_client *client);
 
 	/*!
 	 * \brief Called when a publisher should stop publishing.

Modified: team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c?view=diff&rev=419075&r1=419074&r2=419075
==============================================================================
--- team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c (original)
+++ team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c Mon Jul 21 07:10:36 2014
@@ -57,7 +57,7 @@
 					<synopsis>Authentication object to be used for outbound publishes.</synopsis>
 				</configOption>
 				<configOption name="outbound_proxy" default="">
-					<synopsis>Outbound Proxy used to send publishes</synopsis>
+					<synopsis>SIP URI of the outbound proxy used to send publishes</synopsis>
 				</configOption>
 				<configOption name="server_uri">
 					<synopsis>SIP URI of the server and entity to publish to</synopsis>
@@ -118,7 +118,7 @@
 };
 
 /*! \brief Outbound publish information */
-struct sip_outbound_publish {
+struct ast_sip_outbound_publish {
 	/*! \brief Sorcery object details */
 	SORCERY_OBJECT(details);
 	/*! \brief Stringfields */
@@ -138,8 +138,6 @@
 	unsigned int expiration;
 	/*! \brief Configured authentication credentials */
 	struct ast_sip_auth_vector outbound_auths;
-	/*! \brief Event specific configuration items */
-	struct ast_variable *event_configuration;
 	/*! \brief Outbound publish state */
 	struct ast_sip_outbound_publish_client *state;
 };
@@ -169,7 +167,7 @@
 {
 	RAII_VAR(struct ao2_container *, publishes, ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "outbound-publish", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL), ao2_cleanup);
 	struct ao2_iterator i;
-	struct sip_outbound_publish *publish;
+	struct ast_sip_outbound_publish *publish;
 
 	if (!publishes) {
 		return;
@@ -184,7 +182,7 @@
 			if (!handler) {
 				ast_debug(2, "Could not find handler for event '%s' for outbound publish client '%s'\n",
 					publish->event, ast_sorcery_object_get_id(publish));
-			} else if (handler->start_publishing(publish->state, publish->event_configuration)) {
+			} else if (handler->start_publishing(publish, publish->state)) {
 				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 {
@@ -202,7 +200,7 @@
 
 struct ast_sip_outbound_publish_client *ast_sip_publish_client_get(const char *name)
 {
-	RAII_VAR(struct sip_outbound_publish *, publish, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "outbound-publish", name), ao2_cleanup);
+	RAII_VAR(struct ast_sip_outbound_publish *, publish, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "outbound-publish", name), ao2_cleanup);
 
 	if (!publish) {
 		return NULL;
@@ -257,7 +255,7 @@
 /*! \brief Destructor function for publish information */
 static void sip_outbound_publish_destroy(void *obj)
 {
-	struct sip_outbound_publish *publish = obj;
+	struct ast_sip_outbound_publish *publish = obj;
 	SCOPED_LOCK(lock, &publisher_handlers, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
 	struct ast_sip_event_publisher_handler *handler = find_publisher_handler_for_event_name(publish->event);
 
@@ -266,7 +264,6 @@
 	}
 	ao2_cleanup(publish->state);
 	ast_sip_auth_vector_destroy(&publish->outbound_auths);
-	ast_variables_destroy(publish->event_configuration);
 
 	ast_string_field_free_memory(publish);
 }
@@ -274,7 +271,7 @@
 /*! \brief Allocator function for publish information */
 static void *sip_outbound_publish_alloc(const char *name)
 {
-	struct sip_outbound_publish *publish = ast_sorcery_generic_alloc(sizeof(*publish),
+	struct ast_sip_outbound_publish *publish = ast_sorcery_generic_alloc(sizeof(*publish),
 		sip_outbound_publish_destroy);
 
 	if (!publish || ast_string_field_init(publish, 256)) {
@@ -303,6 +300,7 @@
 {
 	RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
 	const char *uid_ptr = uid;
+	char uuid_buf[AST_UUID_STR_LEN];
 
 	if (!info) {
 		return NULL;
@@ -317,7 +315,6 @@
 	if (ast_strlen_zero(uid)) {
 		/* They didn't provide an ID so we'll provide one ourself */
 		struct ast_uuid *uuid = ast_uuid_generate();
-		char uuid_buf[AST_UUID_STR_LEN];
 		if (!uuid) {
 			return NULL;
 		}
@@ -350,13 +347,13 @@
 struct ast_datastore *ast_sip_publish_client_get_datastore(struct ast_sip_outbound_publish_client *client,
 	const char *name)
 {
-	return ao2_find(client->datastores, name, OBJ_KEY);
+	return ao2_find(client->datastores, name, OBJ_SEARCH_KEY);
 }
 
 void ast_sip_publish_client_remove_datastore(struct ast_sip_outbound_publish_client *client,
 	const char *name)
 {
-	ao2_callback(client->datastores, OBJ_KEY | OBJ_UNLINK | OBJ_NODATA, NULL, (void *) name);
+	ao2_find(client->datastores, name, OBJ_SEARCH_KEY | OBJ_UNLINK | OBJ_NODATA);
 }
 
 static int sip_publish_client_service_queue(void *data)
@@ -365,29 +362,38 @@
 	SCOPED_AO2LOCK(lock, client);
 	struct sip_outbound_publish_message *message;
 	pjsip_tx_data *tdata;
+	pj_status_t status;
 
 	if (client->sending || !(message = AST_LIST_FIRST(&client->queue))) {
 		return 0;
 	}
 
 	if (pjsip_publishc_publish(client->client, PJ_TRUE, &tdata) != PJ_SUCCESS) {
-		goto error;
+		goto fatal;
 	}
 
 	if (!ast_strlen_zero(message->body.type) && !ast_strlen_zero(message->body.subtype) &&
 		ast_sip_add_body(tdata, &message->body)) {
-		goto error;
-	}
-
-	if (pjsip_publishc_send(client->client, tdata) != PJ_SUCCESS) {
-		goto error;
+		goto fatal;
+	}
+
+	status = pjsip_publishc_send(client->client, tdata);
+	if (status == PJ_EBUSY) {
+		/* We attempted to send the message but something else got there first */
+		goto service;
+	} else if (status != PJ_SUCCESS) {
+		goto fatal;
 	}
 
 	client->sending = message;
 
 	return 0;
 
-error:
+fatal:
+	AST_LIST_REMOVE_HEAD(&client->queue, entry);
+	ast_free(message);
+
+service:
 	if (ast_sip_push_task(NULL, sip_publish_client_service_queue, ao2_bump(client))) {
 		ao2_ref(client, -1);
 	}
@@ -467,7 +473,7 @@
  * \param existing The pre-existing outbound publish
  * \param applied The newly-created publish
  */
-static int can_reuse_publish(struct sip_outbound_publish *existing, struct sip_outbound_publish *applied)
+static int can_reuse_publish(struct ast_sip_outbound_publish *existing, struct ast_sip_outbound_publish *applied)
 {
 	int i;
 
@@ -490,7 +496,7 @@
 /*! \brief Callback function for publish client responses */
 static void sip_outbound_publish_callback(struct pjsip_publishc_cbparam *param)
 {
-	struct sip_outbound_publish *publish = param->token;
+	struct ast_sip_outbound_publish *publish = param->token;
 
 	if (param->code == 401 || param->code == 407) {
 		pjsip_tx_data *tdata;
@@ -504,9 +510,11 @@
 	ao2_lock(publish->state);
 
 	/* Remove the message currently being sent so that when the queue is serviced another will get sent */
-	AST_LIST_REMOVE_HEAD(&publish->state->queue, entry);
-	ast_free(publish->state->sending);
-	publish->state->sending = NULL;
+	if (publish->state->sending) {
+		AST_LIST_REMOVE_HEAD(&publish->state->queue, entry);
+		ast_free(publish->state->sending);
+		publish->state->sending = NULL;
+	}
 
 	ao2_unlock(publish->state);
 
@@ -518,7 +526,7 @@
 /*! \brief Helper function that allocates a pjsip publish client and configures it */
 static int sip_outbound_publish_client_alloc(void *data)
 {
-	struct sip_outbound_publish *publish = data;
+	struct ast_sip_outbound_publish *publish = data;
 	pj_pool_t *pool;
 	pj_str_t tmp;
 	pjsip_uri *uri;
@@ -558,7 +566,7 @@
 		pj_strdup2_with_null(pool, &tmp, publish->from_uri);
 		uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0);
 		if (!uri) {
-			ast_log(LOG_ERROR, "Invalid to URI '%s' specified on outbound publish '%s'\n",
+			ast_log(LOG_ERROR, "Invalid from URI '%s' specified on outbound publish '%s'\n",
 				publish->from_uri, ast_sorcery_object_get_id(publish));
 			pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
 			return -1;
@@ -576,13 +584,11 @@
 	if (!ast_strlen_zero(publish->outbound_proxy)) {
 		pjsip_route_hdr route_set, *route;
 		static const pj_str_t ROUTE_HNAME = { "Route", 5 };
-		pj_str_t tmp;
 
 		pj_list_init(&route_set);
 
-		pj_strdup2_with_null(pjsip_publishc_get_pool(publish->state->client), &tmp, publish->outbound_proxy);
-		if (!(route = pjsip_parse_hdr(pjsip_publishc_get_pool(publish->state->client), &ROUTE_HNAME, tmp.ptr,
-			tmp.slen, NULL))) {
+		if (!(route = pjsip_parse_hdr(pjsip_publishc_get_pool(publish->state->client), &ROUTE_HNAME,
+			(char*)publish->outbound_proxy, strlen(publish->outbound_proxy), NULL))) {
 			return -1;
 		}
 		pj_list_insert_nodes_before(&route_set, route);
@@ -648,8 +654,8 @@
 /*! \brief Apply function which finds or allocates a state structure */
 static int sip_outbound_publish_apply(const struct ast_sorcery *sorcery, void *obj)
 {
-	RAII_VAR(struct sip_outbound_publish *, existing, ast_sorcery_retrieve_by_id(sorcery, "outbound-publish", ast_sorcery_object_get_id(obj)), ao2_cleanup);
-	struct sip_outbound_publish *applied = obj;
+	RAII_VAR(struct ast_sip_outbound_publish *, existing, ast_sorcery_retrieve_by_id(sorcery, "outbound-publish", ast_sorcery_object_get_id(obj)), ao2_cleanup);
+	struct ast_sip_outbound_publish *applied = obj;
 
 	if (ast_strlen_zero(applied->server_uri)) {
 		ast_log(LOG_ERROR, "No server URI specified on outbound publish '%s'\n",
@@ -683,33 +689,9 @@
 
 static int outbound_auth_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
-	struct sip_outbound_publish *publish = obj;
+	struct ast_sip_outbound_publish *publish = obj;
 
 	return ast_sip_auth_vector_init(&publish->outbound_auths, var->value);
-}
-
-static int event_configuration_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
-{
-	struct sip_outbound_publish *publish = obj;
-	/* The name starts after configure_ */
-	const char *name = var->name + 10;
-	struct ast_variable *item;
-
-	if (ast_strlen_zero(name) || ast_strlen_zero(var->value)) {
-		return -1;
-	}
-
-	item = ast_variable_new(name, var->value, "");
-	if (!item) {
-		return -1;
-	}
-
-	if (publish->event_configuration) {
-		item->next = publish->event_configuration;
-	}
-	publish->event_configuration = item;
-
-	return 0;
 }
 
 static int load_module(void)
@@ -722,14 +704,13 @@
 	}
 
 	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "type", "", OPT_NOOP_T, 0, 0);
-	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "server_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_publish, server_uri));
-	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "from_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_publish, from_uri));
-	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "event", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_publish, event));
-	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "to_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_publish, to_uri));
-	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_publish, outbound_proxy));
-	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "expiration", "3600", OPT_UINT_T, 0, FLDSET(struct sip_outbound_publish, expiration));
+	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "server_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, server_uri));
+	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "from_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, from_uri));
+	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "event", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, event));
+	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "to_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, to_uri));
+	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, outbound_proxy));
+	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "expiration", "3600", OPT_UINT_T, 0, FLDSET(struct ast_sip_outbound_publish, expiration));
 	ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "outbound-publish", "outbound_auth", "", outbound_auth_handler, NULL, NULL, 0, 0);
-	ast_sorcery_object_fields_register(ast_sip_get_sorcery(), "outbound-publish", "^configure_", event_configuration_handler, NULL);
 	ast_sorcery_reload_object(ast_sip_get_sorcery(), "outbound-publish");
 
 	AST_RWLIST_RDLOCK(&publisher_handlers);

Modified: team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.exports.in?view=diff&rev=419075&r1=419074&r2=419075
==============================================================================
--- team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.exports.in (original)
+++ team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.exports.in Mon Jul 21 07:10:36 2014
@@ -1,13 +1,6 @@
 {
 	global:
-		LINKER_SYMBOL_PREFIXast_sip_publish_client_get;
-		LINKER_SYMBOL_PREFIXast_sip_register_event_publisher_handler;
-		LINKER_SYMBOL_PREFIXast_sip_unregister_event_publisher_handler;
-		LINKER_SYMBOL_PREFIXast_sip_publish_client_alloc_datastore;
-		LINKER_SYMBOL_PREFIXast_sip_publish_client_add_datastore;
-		LINKER_SYMBOL_PREFIXast_sip_publish_client_get_datastore;
-		LINKER_SYMBOL_PREFIXast_sip_publish_client_remove_datastore;
-		LINKER_SYMBOL_PREFIXast_sip_publish_client_send;
+		LINKER_SYMBOL_PREFIXast_sip_*;
 	local:
 		*;
 };

Modified: team/file/pjsip-outbound-publish/res/res_pjsip_publish_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-outbound-publish/res/res_pjsip_publish_asterisk.c?view=diff&rev=419075&r1=419074&r2=419075
==============================================================================
--- team/file/pjsip-outbound-publish/res/res_pjsip_publish_asterisk.c (original)
+++ team/file/pjsip-outbound-publish/res/res_pjsip_publish_asterisk.c Mon Jul 21 07:10:36 2014
@@ -190,7 +190,7 @@
 
 	text = ast_json_dump_string(json);
 	if (!text) {
-		ast_json_free(json);
+		ast_json_unref(json);
 		return;
 	}
 	body.body_text = text;
@@ -198,7 +198,7 @@
 	ast_sip_publish_client_send(publisher_state->client, &body);
 
 	ast_json_free(text);
-	ast_json_free(json);
+	ast_json_unref(json);
 }
 
 /*!
@@ -249,7 +249,7 @@
 
 	text = ast_json_dump_string(json);
 	if (!text) {
-		ast_json_free(json);
+		ast_json_unref(json);
 		return;
 	}
 	body.body_text = text;
@@ -257,7 +257,7 @@
 	ast_sip_publish_client_send(publisher_state->client, &body);
 
 	ast_json_free(text);
-	ast_json_free(json);
+	ast_json_unref(json);
 }
 
 static int cached_devstate_cb(void *obj, void *arg, int flags)
@@ -297,11 +297,12 @@
 	return 0;
 }
 
-static int asterisk_start_publishing(struct ast_sip_outbound_publish_client *client, struct ast_variable *configuration)
+static int asterisk_start_publishing(struct ast_sip_outbound_publish *configuration,
+	struct ast_sip_outbound_publish_client *client)
 {
 	RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
 	struct asterisk_publisher_state *publisher_state;
-	struct ast_variable *field;
+	const char *value;
 	struct ao2_container *cached;
 
 	datastore = ast_sip_publish_client_alloc_datastore(&asterisk_publisher_state_datastore, "asterisk-publisher");
@@ -315,35 +316,29 @@
 	}
 	datastore->data = publisher_state;
 
-	for (field = configuration; field; field = field->next) {
-		if (!strcasecmp(field->name, "device_state_filter")) {
-			if (build_regex(&publisher_state->device_state_regex, field->value)) {
-				ao2_ref(datastore, -1);
-				return -1;
-			}
-			publisher_state->device_state_filter = 1;
-		} else if (!strcasecmp(field->name, "device_state")) {
-			publisher_state->device_state = ast_true(field->value);
-		} else if (!strcasecmp(field->name, "mailbox_state_filter")) {
-			if (build_regex(&publisher_state->mailbox_state_regex, field->value)) {
-				ao2_ref(datastore, -1);
-				return -1;
-			}
-			publisher_state->mailbox_state_filter = 1;
-		} else if (!strcasecmp(field->name, "mailbox_state")) {
-			publisher_state->mailbox_state = ast_true(field->value);
-		} else {
-			ast_log(LOG_ERROR, "Unknown publisher configuration item named '%s'\n",
-				field->name);
-			ao2_ref(datastore, -1);
-			return -1;
-		}
+	value = ast_sorcery_object_get_extended(configuration, "device_state_filter");
+	if (!ast_strlen_zero(value) && build_regex(&publisher_state->device_state_regex, value)) {
+		return -1;
+	}
+
+	value = ast_sorcery_object_get_extended(configuration, "device_state");
+	if (!ast_strlen_zero(value)) {
+		publisher_state->device_state = ast_true(value);
+	}
+
+	value = ast_sorcery_object_get_extended(configuration, "mailbox_state_filter");
+	if (!ast_strlen_zero(value) && build_regex(&publisher_state->mailbox_state_regex, value)) {
+		return -1;
+	}
+
+	value = ast_sorcery_object_get_extended(configuration, "mailbox_state");
+	if (!ast_strlen_zero(value)) {
+		publisher_state->mailbox_state = ast_true(value);
 	}
 
 	publisher_state->client = ao2_bump(client);
 
 	if (ast_sip_publish_client_add_datastore(client, datastore)) {
-		ao2_ref(datastore, -1);
 		return -1;
 	}
 
@@ -351,10 +346,9 @@
 		publisher_state->device_state_subscription = stasis_subscribe(ast_device_state_topic_all(),
 			asterisk_publisher_devstate_cb, ao2_bump(datastore));
 		if (!publisher_state->device_state_subscription) {
-			ao2_ref(datastore, -1);
+			ast_sip_publish_client_remove_datastore(client, "asterisk-publisher");
 			return -1;
 		}
-
 
 		cached = stasis_cache_dump(ast_device_state_cache(), NULL);
 		ao2_callback(cached, OBJ_NODATA, cached_devstate_cb, datastore);
@@ -367,9 +361,8 @@
 		if (!publisher_state->mailbox_state_subscription) {
 			if (publisher_state->device_state_subscription) {
 				stasis_unsubscribe_and_join(publisher_state->device_state_subscription);
-				ao2_ref(datastore, -1);
 			}
-			ao2_ref(datastore, -1);
+			ast_sip_publish_client_remove_datastore(client, "asterisk-publisher");
 			return -1;
 		}
 
@@ -489,11 +482,6 @@
 	}
 
 	item_id = ast_strdupa(uniqueid);
-	if (!item_id) {
-		ast_debug(2, "Received mailbox state on resource '%s' for uniqueid '%s' but it could not be turned into a mailbox\n",
-			ast_sorcery_object_get_id(config), uniqueid);
-		return -1;
-	}
 	mailbox = strsep(&item_id, "@");
 
 	ast_publish_mwi_state_full(mailbox, item_id, new_msgs, old_msgs, NULL, pubsub_eid);
@@ -550,7 +538,7 @@
 {
 	RAII_VAR(struct asterisk_publication_config *, config, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "asterisk-publication",
 		ast_sip_publication_get_event_configuration(pub)), ao2_cleanup);
-	RAII_VAR(struct ast_json *, json, NULL, ast_json_free);
+	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 	const char *eid, *type;
 	struct ast_eid pubsub_eid;
 	int res = -1;
@@ -561,8 +549,8 @@
 	}
 
 	/* We only accept JSON for content */
-	if (pj_stricmp2(&body->content_type.type, "application") ||
-		pj_stricmp2(&body->content_type.subtype, "json")) {
+	if (pj_strcmp2(&body->content_type.type, "application") ||
+		pj_strcmp2(&body->content_type.subtype, "json")) {
 		ast_debug(2, "Received unsupported content type for Asterisk event on resource '%s'\n",
 			ast_sorcery_object_get_id(config));
 		return -1;
@@ -647,7 +635,7 @@
 
 	text = ast_json_dump_string(json);
 	if (!text) {
-		ast_json_free(json);
+		ast_json_unref(json);
 		ao2_ref(publications, -1);
 		return;
 	}
@@ -656,7 +644,7 @@
 	ao2_callback(publications, OBJ_NODATA, send_refresh_cb, &body);
 
 	ast_json_free(text);
-	ast_json_free(json);
+	ast_json_unref(json);
 	ao2_ref(publications, -1);
 }
 
@@ -720,7 +708,7 @@
 	}
 
 	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "asterisk-publication", "type", "", OPT_NOOP_T, 0, 0);
-	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "asterisk-publication", "publish", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct asterisk_publication_config, publish));	
+	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "asterisk-publication", "publish", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct asterisk_publication_config, publish));
 	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "asterisk-publication", "device_state", "no", OPT_BOOL_T, 1, FLDSET(struct asterisk_publication_config, device_state));
 	ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "asterisk-publication", "device_state_filter", "", regex_filter_handler, NULL, NULL, 0, 0);
 	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "asterisk-publication", "mailbox_state", "no", OPT_BOOL_T, 1, FLDSET(struct asterisk_publication_config, mailbox_state));

Modified: team/file/pjsip-outbound-publish/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-outbound-publish/res/res_pjsip_pubsub.c?view=diff&rev=419075&r1=419074&r2=419075
==============================================================================
--- team/file/pjsip-outbound-publish/res/res_pjsip_pubsub.c (original)
+++ team/file/pjsip-outbound-publish/res/res_pjsip_pubsub.c Mon Jul 21 07:10:36 2014
@@ -1147,7 +1147,7 @@
 
 void ast_sip_subscription_remove_datastore(struct ast_sip_subscription *subscription, const char *name)
 {
-	ao2_callback(subscription->datastores, OBJ_KEY | OBJ_UNLINK | OBJ_NODATA, NULL, (void *) name);
+	ao2_find(subscription->datastores, name, OBJ_SEARCH_KEY | OBJ_UNLINK | OBJ_NODATA);
 }
 
 int ast_sip_publication_add_datastore(struct ast_sip_publication *publication, struct ast_datastore *datastore)
@@ -2145,6 +2145,7 @@
 static int resource_event_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	struct ast_sip_publication_resource *resource = obj;
+	/* The event configuration name starts with 'event_' so skip past it to get the real name */
 	const char *event = var->name + 6;
 	struct ast_variable *item;
 




More information about the asterisk-commits mailing list