[svn-commits] mmichelson: branch mmichelson/rls-rlmi r418255 - /team/mmichelson/rls-rlmi/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jul 9 16:09:01 CDT 2014


Author: mmichelson
Date: Wed Jul  9 16:08:54 2014
New Revision: 418255

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418255
Log:
Eliminate hard-coded URIs in bodies.

This changes the way that local URIs are generated.
This makes it so that embedded presence bodies generate
a URI that is local to the resource.


Modified:
    team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c

Modified: team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c?view=diff&rev=418255&r1=418254&r2=418255
==============================================================================
--- team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c Wed Jul  9 16:08:54 2014
@@ -414,6 +414,8 @@
 	unsigned int version;
 	/*! For lists, indicates if full state should always be communicated. */
 	unsigned int full_state;
+	/*! URI associated with the subscription */
+	pjsip_sip_uri *uri;
 	/*! Name of resource being subscribed to */
 	char resource[0];
 };
@@ -970,6 +972,7 @@
 		const char *resource, struct sip_subscription_tree *tree)
 {
 	struct ast_sip_subscription *sub;
+	pjsip_sip_uri *contact_uri;
 
 	sub = ao2_alloc(sizeof(*sub) + strlen(resource) + 1, subscription_destructor);
 	if (!sub) {
@@ -988,6 +991,11 @@
 		ao2_ref(sub, -1);
 		return NULL;
 	}
+
+	sub->uri = pjsip_sip_uri_create(tree->dlg->pool, PJ_FALSE);
+	contact_uri = pjsip_uri_get_uri(tree->dlg->local.contact->uri);
+	pjsip_sip_uri_assign(tree->dlg->pool, sub->uri, contact_uri);
+	pj_strdup2(tree->dlg->pool, &sub->uri->user, resource);
 
 	sub->handler = handler;
 	sub->subscription_state = PJSIP_EVSUB_STATE_ACTIVE;
@@ -1446,18 +1454,20 @@
 }
 
 static void add_rlmi_resource(pj_pool_t *pool, pj_xml_node *rlmi, const char *cid,
-		const char *resource_name, const char *resource_uri, pjsip_evsub_state state)
+		const char *resource_name, const pjsip_sip_uri *resource_uri, pjsip_evsub_state state)
 {
 	pj_xml_node *resource;
 	pj_xml_node *name;
 	pj_xml_node *instance;
 	char id[AST_UUID_STR_LEN];
+	char uri[PJSIP_MAX_URL_SIZE];
 
 	resource = ast_sip_presence_xml_create_node(pool, rlmi, "resource");
 	name = ast_sip_presence_xml_create_node(pool, resource, "name");
 	instance = ast_sip_presence_xml_create_node(pool, resource, "instance");
 
-	ast_sip_presence_xml_create_attr(pool, resource, "uri", resource_uri);
+	pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, resource_uri, uri, sizeof(uri));
+	ast_sip_presence_xml_create_attr(pool, resource, "uri", uri);
 
 	pj_strdup2(pool, &name->content, resource_name);
 
@@ -1471,7 +1481,7 @@
 struct body_part {
 	const char *cid;
 	const char *resource;
-	const char *uri;
+	pjsip_sip_uri *uri;
 	pjsip_evsub_state state;
 	pjsip_multipart_part *part;
 };
@@ -1529,7 +1539,7 @@
 	AST_VECTOR_FREE(parts);
 }
 
-static struct body_part *allocate_body_part(const struct ast_sip_subscription *sub)
+static struct body_part *allocate_body_part(pj_pool_t *pool, const struct ast_sip_subscription *sub)
 {
 	struct body_part *bp;
 
@@ -1546,8 +1556,7 @@
 
 	bp->resource = sub->resource;
 	bp->state = sub->subscription_state;
-	/* XXX This is hardcoded */
-	bp->uri = "sip:johndoe at example.org";
+	bp->uri = sub->uri;
 
 	return bp;
 }
@@ -1577,7 +1586,7 @@
 	for (i = 0; i < AST_VECTOR_SIZE(&sub->children); ++i) {
 		/* XXX This should probably be factored into a function */
 		struct ast_sip_subscription *child = AST_VECTOR_GET(&sub->children, i);
-		struct body_part *bp = allocate_body_part(child);
+		struct body_part *bp = allocate_body_part(pool, child);
 		pjsip_generic_string_hdr *cid;
 		static const pj_str_t cid_name = { "Content-ID", 10 };
 		pjsip_msg_body *body;
@@ -1732,8 +1741,7 @@
 
 void ast_sip_subscription_get_local_uri(struct ast_sip_subscription *sub, char *buf, size_t size)
 {
-	pjsip_dialog *dlg = sub->tree->dlg;
-	ast_copy_pj_str(buf, &dlg->local.info_str, size);
+	pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, sub->uri, buf, size);
 }
 
 void ast_sip_subscription_get_remote_uri(struct ast_sip_subscription *sub, char *buf, size_t size)




More information about the svn-commits mailing list