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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 10 14:48:51 CDT 2014


Author: mmichelson
Date: Thu Jul 10 14:48:45 2014
New Revision: 418360

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418360
Log:
Switch from using UUIDs for Content-ID and multipart boundaries to something more simple.

Is this cryptographically secure? No.
Does this generate an ID that is unique across time and space? No.

Does this generate something that is INSANELY unlikely to conflict with anything within the same NOTIFY request? Yes!
Does this reduce the size of NOTIFY bodies by a noticeable amount? Yes!


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=418360&r1=418359&r2=418360
==============================================================================
--- team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c Thu Jul 10 14:48:45 2014
@@ -1474,6 +1474,18 @@
 	return res;
 }
 
+static char *generate_random_string(char *buf, size_t size)
+{
+	int i;
+
+	for (i = 0; i < size - 1; ++i) {
+		buf[i] = 'a' + (ast_random() % 26);
+	}
+	buf[i] = '\0';
+
+	return buf;
+}
+
 static void add_rlmi_resource(pj_pool_t *pool, pj_xml_node *rlmi, const pjsip_generic_string_hdr *cid,
 		const char *resource_name, const pjsip_sip_uri *resource_uri, pjsip_evsub_state state)
 {
@@ -1482,7 +1494,7 @@
 	pj_xml_node *name;
 	pj_xml_node *instance;
 	pj_xml_attr *cid_attr;
-	char id[AST_UUID_STR_LEN];
+	char id[6];
 	char uri[PJSIP_MAX_URL_SIZE];
 
 	pj_str_t cid_stripped = {
@@ -1499,7 +1511,7 @@
 
 	pj_strdup2(pool, &name->content, resource_name);
 
-	ast_uuid_generate_str(id, sizeof(id));
+	generate_random_string(id, sizeof(id));
 	ast_sip_presence_xml_create_attr(pool, instance, "id", id);
 	ast_sip_presence_xml_create_attr(pool, instance, "state",
 			state == PJSIP_EVSUB_STATE_TERMINATED ? "terminated" : "active");
@@ -1522,14 +1534,14 @@
 {
 	static const pj_str_t cid_name = { "Content-ID", 10 };
 	pjsip_generic_string_hdr *cid;
-	char id[AST_UUID_STR_LEN];
+	char id[6];
 	size_t alloc_size;
 	pj_str_t cid_value;
 
 	alloc_size = sizeof(id) + pj_strlen(&sub->uri->host) + 3;
 	cid_value.ptr = pj_pool_alloc(pool, alloc_size);
 	cid_value.slen = sprintf(cid_value.ptr, "<%s@%.*s>",
-			ast_uuid_generate_str(id, sizeof(id)),
+			generate_random_string(id, sizeof(id)),
 			(int) pj_strlen(&sub->uri->host), pj_strbuf(&sub->uri->host));
 	cid = pjsip_generic_string_hdr_create(pool, &cid_name, &cid_value);
 
@@ -1648,6 +1660,8 @@
 {
 	pjsip_media_type media_type;
 	pjsip_param *media_type_param;
+	char boundary[6];
+	pj_str_t pj_boundary;
 
 	pjsip_media_type_init2(&media_type, "multipart", "related");
 
@@ -1659,7 +1673,8 @@
 
 	pj_list_insert_before(&media_type.param, media_type_param);
 	
-	return pjsip_multipart_create(pool, &media_type, NULL);
+	pj_cstr(&pj_boundary, generate_random_string(boundary, sizeof(boundary)));
+	return pjsip_multipart_create(pool, &media_type, &pj_boundary);
 }
 
 static pjsip_msg_body *generate_list_body(pj_pool_t *pool, struct ast_sip_subscription *sub,




More information about the svn-commits mailing list