[asterisk-commits] mmichelson: branch mmichelson/pub_sub r385547 - /team/mmichelson/pub_sub/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 12 16:46:42 CDT 2013


Author: mmichelson
Date: Fri Apr 12 16:46:38 2013
New Revision: 385547

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385547
Log:
Complete callbacks.

Ran some initial tests and got rid of some crashes. Right now, unsolicited
MWI is not working properly. It may be that the evsub framework is just not
very thrilled about trying to send an unsolicited NOTIFY. We shall soon see.


Modified:
    team/mmichelson/pub_sub/res/res_sip_mwi.c
    team/mmichelson/pub_sub/res/res_sip_pubsub.c
    team/mmichelson/pub_sub/res/res_sip_pubsub.exports.in

Modified: team/mmichelson/pub_sub/res/res_sip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_mwi.c?view=diff&rev=385547&r1=385546&r2=385547
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Fri Apr 12 16:46:38 2013
@@ -206,9 +206,10 @@
 	return 0;
 }
 
-static void send_mwi_notify(struct mwi_subscription *sub)
-{
-	static pj_str_t active_str = { "active", 6 };
+static void send_mwi_notify(struct mwi_subscription *sub, pjsip_evsub_state state, const char *reason)
+{
+	pj_str_t reason_str;
+	const pj_str_t *reason_str_ptr = NULL;
 	static pjsip_media_type mwi_type = {
 		.type = { "application", 11 },
 		.subtype = { "simple-message-summary", 22 },
@@ -223,14 +224,18 @@
 
 	ao2_callback(sub->stasis_subs, OBJ_NODATA, get_message_count, &counter);
 
+	if (reason) {
+		pj_cstr(&reason_str, reason);
+		reason_str_ptr = &reason_str;
+	}
 	/* XXX Not sure if the \r\n is actually necessary */
 	ast_str_append(&body, 0, "%d/%d(0/0)\r\n", counter.new_msgs, counter.old_msgs);
 	pj_cstr(&pj_body, ast_str_buffer(body));
 
 	pjsip_mwi_notify(ast_sip_subscription_get_evsub(sub->sip_sub),
-			PJSIP_EVSUB_STATE_ACTIVE,
-			&active_str,
+			state,
 			NULL,
+			reason_str_ptr,
 			&mwi_type,
 			&pj_body,
 			&tdata);
@@ -266,6 +271,7 @@
 	RAII_VAR(struct mwi_subscription *, sub, NULL, ao2_cleanup);
 	pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;
 	pjsip_sip_uri *sip_ruri;
+	pjsip_evsub *evsub;
 	char aor_name[80];
 	char *mailboxes;
 	char *mailbox;
@@ -307,7 +313,9 @@
 	}
 	ao2_link(mwi_subscriptions, sub);
 
-	send_mwi_notify(sub);
+	evsub = ast_sip_subscription_get_evsub(sub->sip_sub);
+	pjsip_evsub_accept(evsub, rdata, 200, NULL);
+	send_mwi_notify(sub, PJSIP_EVSUB_STATE_ACTIVE, NULL);
 
 	return sub->sip_sub;
 }
@@ -315,23 +323,46 @@
 static struct ast_sip_subscription_response_data *mwi_resubscribe(struct ast_sip_subscription *sub,
 		pjsip_rx_data *rdata)
 {
-	/* XXX STUB */
+	pjsip_tx_data *tdata;
+
+	pjsip_mwi_current_notify(ast_sip_subscription_get_evsub(sub), &tdata);
+	ast_sip_subscription_send_request(sub, tdata);
 	return NULL;
 }
 
 static void mwi_subscription_timeout(struct ast_sip_subscription *sub)
 {
-	/* XXX STUB */
+	struct mwi_subscription *mwi_sub;
+	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;
+
+	send_mwi_notify(mwi_sub, PJSIP_EVSUB_STATE_TERMINATED, "timeout");
 }
 
 static void mwi_subscription_terminated(struct ast_sip_subscription *sub, pjsip_rx_data *rdata)
 {
-	/* XXX STUB */
+	struct mwi_subscription *mwi_sub;
+	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;
+
+	send_mwi_notify(mwi_sub, PJSIP_EVSUB_STATE_TERMINATED, NULL);
 }
 
 static void mwi_notify_response(struct ast_sip_subscription *sub, pjsip_rx_data *rdata)
 {
-	/* XXX STUB */
+	/* We don't really care about NOTIFY responses for the moment */
 }
 
 static struct ast_sip_subscription_response_data *mwi_notify_request(struct ast_sip_subscription *sub,
@@ -356,7 +387,7 @@
 		return;
 	}
 	if (stasis_mwi_state_type() == stasis_message_type(msg)) {
-		send_mwi_notify(mwi_sub);
+		send_mwi_notify(mwi_sub, PJSIP_EVSUB_STATE_ACTIVE, NULL);
 	}
 }
 
@@ -398,7 +429,7 @@
 static void create_mwi_subscriptions(void)
 {
 	RAII_VAR(struct ao2_container *, endpoints, ast_sorcery_retrieve_by_fields(
-				ast_sip_get_sorcery(), "endpoint", AST_RETRIEVE_FLAG_ALL, NULL),
+				ast_sip_get_sorcery(), "endpoint", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL),
 			ao2_cleanup);
 
 	ao2_callback(endpoints, OBJ_NODATA, create_mwi_subscriptions_for_endpoint, NULL);

Modified: team/mmichelson/pub_sub/res/res_sip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_pubsub.c?view=diff&rev=385547&r1=385546&r2=385547
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_pubsub.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_pubsub.c Fri Apr 12 16:46:38 2013
@@ -158,10 +158,24 @@
 	if (role == AST_SIP_NOTIFIER) {
 		pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg);
 	} else {
-		dlg = ast_sip_create_dialog(endpoint, NULL, NULL);
-	}
+		RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
+
+		contact = ast_sip_location_retrieve_contact_from_aor_list(endpoint->aors);
+		if (!contact || ast_strlen_zero(contact->uri)) {
+			ast_log(LOG_WARNING, "No contacts configured for endpoint %s. Unable to create SIP subsription\n",
+					ast_sorcery_object_get_id(endpoint));
+			ao2_ref(sub, -1);
+			return NULL;
+		}
+		dlg = ast_sip_create_dialog(endpoint, contact->uri, NULL);
+	}
+	if (!dlg) {
+		ast_log(LOG_WARNING, "Unable to create dialog for SIP subscription\n");
+		ao2_ref(sub, -1);
+		return NULL;
+	}
+	sub->evsub = allocate_evsub(handler->event_name, role, endpoint, rdata, dlg);
 	ast_sip_dialog_set_serializer(dlg, sub->serializer);
-	sub->evsub = allocate_evsub(handler->event_name, role, endpoint, rdata, dlg);
 	pjsip_evsub_set_mod_data(sub->evsub, sub_module.id, sub);
 	ao2_ref(endpoint, +1);
 	sub->endpoint = endpoint;

Modified: team/mmichelson/pub_sub/res/res_sip_pubsub.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_pubsub.exports.in?view=diff&rev=385547&r1=385546&r2=385547
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_pubsub.exports.in (original)
+++ team/mmichelson/pub_sub/res/res_sip_pubsub.exports.in Fri Apr 12 16:46:38 2013
@@ -7,6 +7,7 @@
 		LINKER_SYMBOL_PREFIXast_sip_subscription_send_request;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_alloc_datastore;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_add_datastore;
+		LINKER_SYMBOL_PREFIXast_sip_subscription_get_datastore;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_remove_datastore;
 		LINKER_SYMBOL_PREFIXast_sip_register_subscription_handler;
 		LINKER_SYMBOL_PREFIXast_sip_unregister_subscription_handler;




More information about the asterisk-commits mailing list