[svn-commits] mmichelson: trunk r408006 - in /trunk: ./ res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Feb 13 12:52:10 CST 2014


Author: mmichelson
Date: Thu Feb 13 12:52:08 2014
New Revision: 408006

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=408006
Log:
Remove all PJSIP MWI-specific use from our MWI code.

PJSIP has built-in MWI code that could be useful to some
degree, but our utilization of the API actually made our
code a bit more cluttered since we had to have special
cases peppered throughout.

With this change, we move to using the pjsip_evsub API
instead, which streamlines the code by removing special
cases.

Review: https://reviewboard.asterisk.org/r/3205
........

Merged revisions 408005 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/res/res_pjsip_mwi.c
    trunk/res/res_pjsip_pubsub.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_mwi.c?view=diff&rev=408006&r1=408005&r2=408006
==============================================================================
--- trunk/res/res_pjsip_mwi.c (original)
+++ trunk/res/res_pjsip_mwi.c Thu Feb 13 12:52:08 2014
@@ -251,8 +251,7 @@
 	struct ast_sip_endpoint *endpoint;
 	pjsip_evsub_state state;
 	const char *reason;
-	const pjsip_media_type *mwi_type;
-	const pj_str_t *body_text;
+	const struct ast_sip_body *body;
 };
 
 static int send_unsolicited_mwi_notify_to_contact(void *obj, void *arg, int flags)
@@ -262,12 +261,10 @@
 	struct ast_sip_endpoint *endpoint = mwi_data->endpoint;
 	pjsip_evsub_state state = mwi_data->state;
 	const char *reason = mwi_data->reason;
-	const pjsip_media_type *mwi_type = mwi_data->mwi_type;
-	const pj_str_t *body_text = mwi_data->body_text;
+	const struct ast_sip_body *body = mwi_data->body;
 	struct ast_sip_contact *contact = obj;
 	const char *state_name;
 	pjsip_tx_data *tdata;
-	pjsip_msg_body *msg_body;
 	pjsip_sub_state_hdr *sub_state;
 	pjsip_event_hdr *event;
 	const pjsip_hdr *allow_events = pjsip_evsub_get_allow_events_hdr(NULL);
@@ -307,15 +304,14 @@
 	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) event);
 
 	pjsip_msg_add_hdr(tdata->msg, pjsip_hdr_shallow_clone(tdata->pool, allow_events));
-	msg_body = pjsip_msg_body_create(tdata->pool, &mwi_type->type, &mwi_type->subtype, body_text);
-	tdata->msg->body = msg_body;
+	ast_sip_add_body(tdata, body);
 	ast_sip_send_request(tdata, NULL, endpoint, NULL, NULL);
 
 	return 0;
 }
 
 static void send_unsolicited_mwi_notify(struct mwi_subscription *sub, pjsip_evsub_state state, const char *reason,
-		const pjsip_media_type *mwi_type, const pj_str_t *body_text)
+		struct ast_sip_body *body)
 {
 	RAII_VAR(struct ast_sip_endpoint *, endpoint, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(),
 				"endpoint", sub->id), ao2_cleanup);
@@ -343,8 +339,7 @@
 			.endpoint = endpoint,
 			.state = state,
 			.reason = reason,
-			.mwi_type = mwi_type,
-			.body_text = body_text,
+			.body = body,
 		};
 
 		if (!aor) {
@@ -369,17 +364,18 @@
 		.old_msgs = 0,
 		.new_msgs = 0,
 	};
-	RAII_VAR(struct ast_str *, body, ast_str_create(64), ast_free_ptr);
+	RAII_VAR(struct ast_str *, body_text, ast_str_create(64), ast_free_ptr);
 	pjsip_tx_data *tdata;
 	pj_str_t reason_str;
-	pj_str_t pj_body;
-	const char *type = sub->is_solicited ?
+	struct ast_sip_body body;
+
+	body.type = sub->is_solicited ?
 		ast_sip_subscription_get_body_type(sub->sip_sub) :
 		MWI_TYPE;
-	const char *subtype = sub->is_solicited ?
+
+	body.subtype = sub->is_solicited ?
 		ast_sip_subscription_get_body_subtype(sub->sip_sub) :
 		MWI_SUBTYPE;
-	pjsip_media_type mwi_type = { { 0,}, };
 
 	ao2_callback(sub->stasis_subs, OBJ_NODATA, get_message_count, &counter);
 
@@ -388,28 +384,25 @@
 		reason_str_ptr = &reason_str;
 	}
 
-	if (ast_sip_pubsub_generate_body_content(type, subtype, &counter, &body)) {
+	if (ast_sip_pubsub_generate_body_content(body.type, body.subtype, &counter, &body_text)) {
 		ast_log(LOG_WARNING, "Unable to generate SIP MWI NOTIFY body.\n");
 		return;
 	}
 
-	pj_cstr(&pj_body, ast_str_buffer(body));
-	pj_cstr(&mwi_type.type, type);
-	pj_cstr(&mwi_type.subtype, subtype);
+	body.body_text = ast_str_buffer(body_text);
 
 	ast_debug(5, "Sending %s MWI NOTIFY to endpoint %s, new messages: %d, old messages: %d\n",
 			sub->is_solicited ? "solicited" : "unsolicited", sub->id, counter.new_msgs,
 			counter.old_msgs);
 
 	if (sub->is_solicited) {
-		if (pjsip_mwi_notify(ast_sip_subscription_get_evsub(sub->sip_sub),
-				state,
-				NULL,
-				reason_str_ptr,
-				&mwi_type,
-				&pj_body,
-				&tdata) != PJ_SUCCESS) {
+		if (pjsip_evsub_notify(ast_sip_subscription_get_evsub(sub->sip_sub),
+					state, NULL, reason_str_ptr, &tdata) != PJ_SUCCESS) {
 			ast_log(LOG_WARNING, "Unable to create MWI NOTIFY request to %s.\n", sub->id);
+			return;
+		}
+		if (ast_sip_add_body(tdata, &body)) {
+			ast_log(LOG_WARNING, "Unable to add body to MWI NOTIFY request\n");
 			return;
 		}
 		if (ast_sip_subscription_send_request(sub->sip_sub, tdata) != PJ_SUCCESS) {
@@ -417,7 +410,7 @@
 			return;
 		}
 	} else {
-		send_unsolicited_mwi_notify(sub, state, reason, &mwi_type, &pj_body);
+		send_unsolicited_mwi_notify(sub, state, reason, &body);
 	}
 }
 
@@ -580,10 +573,21 @@
 static void mwi_resubscribe(struct ast_sip_subscription *sub,
 		pjsip_rx_data *rdata, struct ast_sip_subscription_response_data *response_data)
 {
-	pjsip_tx_data *tdata;
-
-	pjsip_mwi_current_notify(ast_sip_subscription_get_evsub(sub), &tdata);
-	ast_sip_subscription_send_request(sub, tdata);
+	struct mwi_subscription *mwi_sub;
+	pjsip_evsub_state state;
+	pjsip_evsub *evsub;
+	RAII_VAR(struct ast_datastore *, mwi_datastore,
+			ast_sip_subscription_get_datastore(sub, "MWI datastore"), ao2_cleanup);
+
+	if (!mwi_datastore) {
+		return;
+	}
+
+	mwi_sub = mwi_datastore->data;
+	evsub = ast_sip_subscription_get_evsub(sub);
+	state = pjsip_evsub_get_state(evsub);
+
+	send_mwi_notify(mwi_sub, state, NULL);
 }
 
 static void mwi_subscription_timeout(struct ast_sip_subscription *sub)

Modified: trunk/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_pubsub.c?view=diff&rev=408006&r1=408005&r2=408006
==============================================================================
--- trunk/res/res_pjsip_pubsub.c (original)
+++ trunk/res/res_pjsip_pubsub.c Thu Feb 13 12:52:08 2014
@@ -373,19 +373,11 @@
 	 * built-in events
 	 */
 	if (role == AST_SIP_NOTIFIER) {
-		if (!strcmp(event, "message-summary")) {
-			pjsip_mwi_create_uas(dlg, &pubsub_cb, rdata, &evsub);
-		} else {
-			pjsip_evsub_create_uas(dlg, &pubsub_cb, rdata, 0, &evsub);
-		}
+		pjsip_evsub_create_uas(dlg, &pubsub_cb, rdata, 0, &evsub);
 	} else {
-		if (!strcmp(event, "message-summary")) {
-			pjsip_mwi_create_uac(dlg, &pubsub_cb, 0, &evsub);
-		} else {
-			pj_str_t pj_event;
-			pj_cstr(&pj_event, event);
-			pjsip_evsub_create_uac(dlg, &pubsub_cb, &pj_event, 0, &evsub);
-		}
+		pj_str_t pj_event;
+		pj_cstr(&pj_event, event);
+		pjsip_evsub_create_uac(dlg, &pubsub_cb, &pj_event, 0, &evsub);
 	}
 	return evsub;
 }
@@ -678,11 +670,7 @@
 
 	pj_cstr(&event, handler->event_name);
 
-	if (!strcmp(handler->event_name, "message-summary")) {
-		pjsip_mwi_init_module(ast_sip_get_pjsip_endpoint(), pjsip_evsub_instance());
-	} else {
-		pjsip_evsub_register_pkg(&pubsub_module, &event, DEFAULT_EXPIRES, i, accept);
-	}
+	pjsip_evsub_register_pkg(&pubsub_module, &event, DEFAULT_EXPIRES, i, accept);
 
 	sub_add_handler(handler);
 	return 0;




More information about the svn-commits mailing list