[svn-commits] file: branch file/pjsip-outbound-publish r419941 - /team/file/pjsip-outbound-...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 4 14:41:34 CDT 2014


Author: file
Date: Mon Aug  4 14:41:30 2014
New Revision: 419941

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419941
Log:
Bit more. This concludes my looking at this today.

Modified:
    team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c

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=419941&r1=419940&r2=419941
==============================================================================
--- team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c (original)
+++ team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c Mon Aug  4 14:41:30 2014
@@ -385,12 +385,7 @@
 	datastore->info = info;
 	if (ast_strlen_zero(uid)) {
 		/* They didn't provide an ID so we'll provide one ourself */
-		struct ast_uuid *uuid = ast_uuid_generate();
-		if (!uuid) {
-			return NULL;
-		}
-		uid_ptr = ast_uuid_to_str(uuid, uuid_buf, sizeof(uuid_buf));
-		ast_free(uuid);
+		uid_ptr = ast_uuid_generate_str(uuid_buf, sizeof(uuid_buf));
 	}
 
 	datastore->uid = ast_strdup(uid_ptr);
@@ -475,9 +470,14 @@
 int ast_sip_publish_client_send(struct ast_sip_outbound_publish_client *client,
 	const struct ast_sip_body *body)
 {
+	SCOPED_AO2LOCK(lock, client);
 	struct sip_outbound_publish_message *message;
 	size_t type_len = 0, subtype_len = 0, body_text_len = 0;
 	int res;
+
+	if (!client->client) {
+		return -1;
+	}
 
 	/* If a body is present we need more space for the contents of it */
 	if (body) {
@@ -501,9 +501,7 @@
 		message->body.body_text = strcpy(dst, body->body_text);
 	}
 
-	ao2_lock(client);
 	AST_LIST_INSERT_TAIL(&client->queue, message, entry);
-	ao2_unlock(client);
 
 	res = ast_sip_push_task(NULL, sip_publish_client_service_queue, ao2_bump(client));
 	if (res) {
@@ -533,8 +531,6 @@
 	}
 
 	ao2_cleanup(state->datastores);
-
-	ast_log(LOG_NOTICE, "Destroying state\n");
 }
 
 /*!
@@ -567,6 +563,92 @@
 	return 1;
 }
 
+static void sip_outbound_publish_callback(struct pjsip_publishc_cbparam *param);
+
+/*! \brief Helper function that allocates a pjsip publish client and configures it */
+static int sip_outbound_publish_client_alloc(void *data)
+{
+	struct ast_sip_outbound_publish *publish = data;
+	pjsip_publishc_opt opt = {
+		.queue_request = PJ_FALSE,
+	};
+	pj_str_t event, server_uri, to_uri, from_uri;
+	pj_status_t status;
+
+	if (!publish->state->client &&
+		pjsip_publishc_create(ast_sip_get_pjsip_endpoint(), &opt, publish, sip_outbound_publish_callback,
+		&publish->state->client) != PJ_SUCCESS) {
+		return -1;
+	}
+
+	if (!ast_strlen_zero(publish->outbound_proxy)) {
+		pjsip_route_hdr route_set, *route;
+		static const pj_str_t ROUTE_HNAME = { "Route", 5 };
+
+		pj_list_init(&route_set);
+
+		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);
+
+		pjsip_publishc_set_route_set(publish->state->client, &route_set);
+	}
+
+	pj_cstr(&event, publish->event);
+	pj_cstr(&server_uri, publish->server_uri);
+	pj_cstr(&to_uri, S_OR(publish->to_uri, publish->server_uri));
+	pj_cstr(&from_uri, S_OR(publish->from_uri, publish->server_uri));
+
+	status = pjsip_publishc_init(publish->state->client, &event, &server_uri, &from_uri, &to_uri,
+		publish->expiration);
+	if (status == PJSIP_EINVALIDURI) {
+		pj_pool_t *pool;
+		pj_str_t tmp;
+		pjsip_uri *uri;
+
+		pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "URI Validation", 256, 256);
+		if (!pool) {
+			ast_log(LOG_ERROR, "Could not create pool for URI validation on outbound publish '%s'\n",
+				ast_sorcery_object_get_id(publish));
+			return -1;
+		}
+
+		pj_strdup2_with_null(pool, &tmp, publish->server_uri);
+		uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0);
+		if (!uri) {
+			ast_log(LOG_ERROR, "Invalid server URI '%s' specified on outbound publish '%s'\n",
+				publish->server_uri, ast_sorcery_object_get_id(publish));
+		}
+
+		if (!ast_strlen_zero(publish->to_uri)) {
+			pj_strdup2_with_null(pool, &tmp, publish->to_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",
+					publish->to_uri, ast_sorcery_object_get_id(publish));
+			}
+		}
+
+		if (!ast_strlen_zero(publish->from_uri)) {
+			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 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;
+	} else if (status != PJ_SUCCESS) {
+		return -1;
+	}
+
+	return 0;
+}
+
 /*! \brief Callback function for publish client responses */
 static void sip_outbound_publish_callback(struct pjsip_publishc_cbparam *param)
 {
@@ -584,30 +666,13 @@
 	ao2_lock(publish->state);
 
 	if (param->code == 412) {
-		pjsip_publishc_opt opt = {
-			.queue_request = PJ_FALSE,
-		};
-		pj_str_t event, server_uri, to_uri, from_uri;
-
 		pjsip_publishc_destroy(publish->state->client);
-		if (pjsip_publishc_create(ast_sip_get_pjsip_endpoint(), &opt, publish, sip_outbound_publish_callback,
-			&publish->state->client) != PJ_SUCCESS) {
+		publish->state->client = NULL;
+
+		if (sip_outbound_publish_client_alloc(publish)) {
 			ast_log(LOG_ERROR, "Failed to create a new outbound publish client for '%s' on 412 response\n",
 				ast_sorcery_object_get_id(publish));
-			return;
-		}
-
-		pj_cstr(&event, publish->event);
-		pj_cstr(&server_uri, publish->server_uri);
-		pj_cstr(&to_uri, S_OR(publish->to_uri, publish->server_uri));
-		pj_cstr(&from_uri, S_OR(publish->from_uri, publish->server_uri));
-
-		/* Re-initialize the publish client so it starts with fresh state */
-		if (pjsip_publishc_init(publish->state->client, &event, &server_uri, &from_uri, &to_uri,
-			publish->expiration) != PJ_SUCCESS) {
-			ast_log(LOG_ERROR, "Failed to initialize outbound publish '%s' to send an initial PUBLISH on 412 response\n",
-				ast_sorcery_object_get_id(publish));
-			return;
+			goto end;
 		}
 
 		/* Setting this to NULL will cause a new PUBLISH to get created and sent for the same underlying body */
@@ -620,7 +685,9 @@
 		if (!expires || !expires->ivalue) {
 			ast_log(LOG_ERROR, "Received 423 response on outbound publish '%s' without a Min-Expires header\n",
 				ast_sorcery_object_get_id(publish));
-			return;
+			pjsip_publishc_destroy(publish->state->client);
+			publish->state->client = NULL;
+			goto end;
 		}
 
 		pjsip_publishc_update_expires(publish->state->client, expires->ivalue);
@@ -636,95 +703,19 @@
 		schedule_publish_refresh(publish, param->rdata);
 	}
 
+end:
+	if (!publish->state->client) {
+		struct sip_outbound_publish_message *message;
+
+		while ((message = AST_LIST_REMOVE_HEAD(&publish->state->queue, entry))) {
+			ast_free(message);
+		}
+	} else {
+		if (ast_sip_push_task(NULL, sip_publish_client_service_queue, ao2_bump(publish->state))) {
+			ao2_ref(publish->state, -1);
+		}
+	}
 	ao2_unlock(publish->state);
-
-	if (ast_sip_push_task(NULL, sip_publish_client_service_queue, ao2_bump(publish->state))) {
-		ao2_ref(publish->state, -1);
-	}
-}
-
-/*! \brief Helper function that allocates a pjsip publish client and configures it */
-static int sip_outbound_publish_client_alloc(void *data)
-{
-	struct ast_sip_outbound_publish *publish = data;
-	pjsip_publishc_opt opt = {
-		.queue_request = PJ_FALSE,
-	};
-	pj_str_t event, server_uri, to_uri, from_uri;
-	pj_status_t status;
-
-	if (!publish->state->client &&
-		pjsip_publishc_create(ast_sip_get_pjsip_endpoint(), &opt, publish, sip_outbound_publish_callback,
-		&publish->state->client) != PJ_SUCCESS) {
-		return -1;
-	}
-
-	if (!ast_strlen_zero(publish->outbound_proxy)) {
-		pjsip_route_hdr route_set, *route;
-		static const pj_str_t ROUTE_HNAME = { "Route", 5 };
-
-		pj_list_init(&route_set);
-
-		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);
-
-		pjsip_publishc_set_route_set(publish->state->client, &route_set);
-	}
-
-	pj_cstr(&event, publish->event);
-	pj_cstr(&server_uri, publish->server_uri);
-	pj_cstr(&to_uri, S_OR(publish->to_uri, publish->server_uri));
-	pj_cstr(&from_uri, S_OR(publish->from_uri, publish->server_uri));
-
-	status = pjsip_publishc_init(publish->state->client, &event, &server_uri, &from_uri, &to_uri,
-		publish->expiration);
-	if (status == PJSIP_EINVALIDURI) {
-		pj_pool_t *pool;
-		pj_str_t tmp;
-		pjsip_uri *uri;
-
-		pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "URI Validation", 256, 256);
-		if (!pool) {
-			ast_log(LOG_ERROR, "Could not create pool for URI validation on outbound publish '%s'\n",
-				ast_sorcery_object_get_id(publish));
-			return -1;
-		}
-
-		pj_strdup2_with_null(pool, &tmp, publish->server_uri);
-		uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0);
-		if (!uri) {
-			ast_log(LOG_ERROR, "Invalid server URI '%s' specified on outbound publish '%s'\n",
-				publish->server_uri, ast_sorcery_object_get_id(publish));
-		}
-
-		if (!ast_strlen_zero(publish->to_uri)) {
-			pj_strdup2_with_null(pool, &tmp, publish->to_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",
-					publish->to_uri, ast_sorcery_object_get_id(publish));
-			}
-		}
-
-		if (!ast_strlen_zero(publish->from_uri)) {
-			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 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;
-	} else if (status != PJ_SUCCESS) {
-		return -1;
-	}
-
-	return 0;
 }
 
 #define DATASTORE_BUCKETS 53




More information about the svn-commits mailing list