[svn-commits] mmichelson: branch mmichelson/subscription_abstraction r416642 - in /team/mmi...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 18 13:19:15 CDT 2014


Author: mmichelson
Date: Wed Jun 18 13:19:12 2014
New Revision: 416642

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416642
Log:
Reinstate user-agent gathering in res_pjsip_exten_state.

In an effort to not make this too terrible, the pubsub
API now offers a way to get SIP headers from the initial
SUBSCRIBE request. This way, there's not a single
seemingly-random API call to get the User-Agent. Other
headers can be grabbed if necessary.


Modified:
    team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h
    team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c
    team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
    team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in

Modified: team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h?view=diff&rev=416642&r1=416641&r2=416642
==============================================================================
--- team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h (original)
+++ team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h Wed Jun 18 13:19:12 2014
@@ -349,6 +349,8 @@
 
 const char *ast_sip_subscription_get_resource_name(struct ast_sip_subscription *sub);
 
+void *ast_sip_subscription_get_header(const struct ast_sip_subscription *sub, const char *header);
+
 /*!
  * \brief Send a request created via a PJSIP evsub method
  *

Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c?view=diff&rev=416642&r1=416641&r2=416642
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_exten_state.c Wed Jun 18 13:19:12 2014
@@ -96,6 +96,23 @@
 	ao2_cleanup(sub->sip_sub);
 }
 
+static char *get_user_agent(const struct ast_sip_subscription *sip_sub)
+{
+	size_t size;
+	char *user_agent = NULL;
+	pjsip_user_agent_hdr *user_agent_hdr = ast_sip_subscription_get_header(
+			sip_sub, "User-Agent");
+
+	if (!user_agent_hdr) {
+		return NULL;
+	}
+
+	size = pj_strlen(&user_agent_hdr->hvalue) + 1;
+	user_agent = ast_malloc(size);
+	ast_copy_pj_str(user_agent, &user_agent_hdr->hvalue, size);
+	return ast_str_to_lower(user_agent);
+}
+
 /*!
  * \internal
  * \brief Initialize the last extension state to something outside
@@ -123,13 +140,7 @@
 	exten_state_sub->sip_sub = ao2_bump(sip_sub);
 	exten_state_sub->last_exten_state = INITIAL_LAST_EXTEN_STATE;
 	exten_state_sub->last_presence_state = AST_PRESENCE_NOT_SET;
-	/* XXX TODO Previously, user agent was reaped from the rdata here and stored on the
-	 * exten_state_sub. This was useful for determining if the phone being communicated with
-	 * is a Digium phone.
-	 *
-	 * This needs to be made available somehow. Maybe it could just be on the base
-	 * ast_sip_subscription structure? Seems a bit specialized though.
-	 */
+	exten_state_sub->user_agent = get_user_agent(sip_sub);
 	return exten_state_sub;
 }
 

Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c?view=diff&rev=416642&r1=416641&r2=416642
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c Wed Jun 18 13:19:12 2014
@@ -121,6 +121,7 @@
 };
 
 #define MOD_DATA_PERSISTENCE "sub_persistence"
+#define MOD_DATA_MSG "sub_msg"
 
 static const pj_str_t str_event_name = { "Event", 5 };
 
@@ -835,8 +836,22 @@
 	pjsip_evsub_create_uas(dlg, &pubsub_cb, rdata, 0, &sub->reality.real.evsub);
 	subscription_setup_dialog(sub, dlg);
 
+	ast_sip_mod_data_set(dlg->pool, dlg->mod_data, pubsub_module.id, MOD_DATA_MSG,
+			pjsip_msg_clone(dlg->pool, rdata->msg_info.msg));
+
 	add_subscription(sub);
 	return sub;
+}
+
+void *ast_sip_subscription_get_header(const struct ast_sip_subscription *sub, const char *header)
+{
+	pjsip_dialog *dlg = sip_subscription_get_dlg(sub);
+	pjsip_msg *msg = ast_sip_mod_data_get(dlg->mod_data, pubsub_module.id, MOD_DATA_MSG);
+	pj_str_t name;
+
+	pj_cstr(&name, header);
+
+	return pjsip_msg_find_hdr_by_name(msg, &name, NULL);
 }
 
 struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,

Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in?view=diff&rev=416642&r1=416641&r2=416642
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in Wed Jun 18 13:19:12 2014
@@ -34,6 +34,7 @@
 		LINKER_SYMBOL_PREFIXast_sip_subscription_notify;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_get_local_uri;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_get_remote_uri;
+		LINKER_SYMBOL_PREFIXast_sip_subscription_get_header;
 	local:
 		*;
 };




More information about the svn-commits mailing list