[svn-commits] mmichelson: branch mmichelson/rls-rlmi r420259 - in /team/mmichelson/rls-rlmi...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 6 13:44:56 CDT 2014


Author: mmichelson
Date: Wed Aug  6 13:44:54 2014
New Revision: 420259

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=420259
Log:
Address Kevin's review comments.

The review has a "Ship It!" on it, so I won't be posting
another diff to review board.


Modified:
    team/mmichelson/rls-rlmi/include/asterisk/strings.h
    team/mmichelson/rls-rlmi/main/strings.c
    team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c

Modified: team/mmichelson/rls-rlmi/include/asterisk/strings.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-rlmi/include/asterisk/strings.h?view=diff&rev=420259&r1=420258&r2=420259
==============================================================================
--- team/mmichelson/rls-rlmi/include/asterisk/strings.h (original)
+++ team/mmichelson/rls-rlmi/include/asterisk/strings.h Wed Aug  6 13:44:54 2014
@@ -1196,4 +1196,20 @@
  */
 void ast_str_container_remove(struct ao2_container *str_container, const char *remove);
 
+/*!
+ * \brief Create a pseudo-random string of a fixed length.
+ *
+ * This function is useful for generating a string whose randomness
+ * does not need to be across all time and space, does not need to
+ * be cryptographically secure, and needs to fit in a limited space.
+ *
+ * This function will write a null byte at the final position
+ * in the buffer (buf[size - 1]). So if you pass in a size of
+ * 10, then this will generate a random 9-character string.
+ *
+ * \param buf Buffer to write random string into.
+ * \param size The size of the buffer.
+ * \return A pointer to buf
+ */
+char *ast_generate_random_string(char *buf, size_t size);
 #endif /* _ASTERISK_STRINGS_H */

Modified: team/mmichelson/rls-rlmi/main/strings.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/rls-rlmi/main/strings.c?view=diff&rev=420259&r1=420258&r2=420259
==============================================================================
--- team/mmichelson/rls-rlmi/main/strings.c (original)
+++ team/mmichelson/rls-rlmi/main/strings.c Wed Aug  6 13:44:54 2014
@@ -195,3 +195,15 @@
 {
 	ao2_find(str_container, remove, OBJ_SEARCH_KEY | OBJ_NODATA | OBJ_UNLINK);
 }
+
+char *ast_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;
+}

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=420259&r1=420258&r2=420259
==============================================================================
--- team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/rls-rlmi/res/res_pjsip_pubsub.c Wed Aug  6 13:44:54 2014
@@ -1491,42 +1491,6 @@
 }
 
 /*!
- * \param Create a pseudo-random string of a fixed length.
- *
- * This function is useful for generating a string whose randomness
- * does not need to be across all time and space.
- *
- * This is currently used for boundaries and Content-ID
- * headers for multipart bodies. This is used instead of a UUID
- * for two main reasons:
- *
- * 1) Since it is possible to generate many Content-IDs in a
- * single multipart body, this is quicker than creating UUIDs.
- * 2) Since multipart bodies tend to be large, using a smaller
- * random string than a UUID can reduce the size of the generated
- * bodies.
- *
- * This function will write a null byte at the final position
- * in the buffer (buf[size - 1]). So if you pass in a size of
- * 10, then this will generate a random 9-character string.
- *
- * \param buf Buffer to write random string into.
- * \param size The size of the buffer.
- * \return A pointer to buf
- */
-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;
-}
-
-/*!
  * \brief Add a resource XML element to an RLMI body
  *
  * Each resource element represents a subscribed resource in the list. This function currently
@@ -1565,7 +1529,7 @@
 
 	pj_strdup2(pool, &name->content, resource_name);
 
-	generate_random_string(id, sizeof(id));
+	ast_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",
@@ -1630,7 +1594,7 @@
 	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>",
-			generate_random_string(id, sizeof(id)),
+			ast_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);
 
@@ -1707,11 +1671,11 @@
 	rlmi_part = pjsip_multipart_create_part(pool);
 
 	rlmi_part->body = PJ_POOL_ZALLOC_T(pool, pjsip_msg_body);
-    pj_strdup(pool, &rlmi_part->body->content_type.type, &rlmi_type);
-    pj_strdup(pool, &rlmi_part->body->content_type.subtype, &rlmi_subtype);
-    pj_list_init(&rlmi_part->body->content_type.param);
-
-    rlmi_part->body->data = pj_xml_clone(pool, rlmi);
+	pj_strdup(pool, &rlmi_part->body->content_type.type, &rlmi_type);
+	pj_strdup(pool, &rlmi_part->body->content_type.subtype, &rlmi_subtype);
+	pj_list_init(&rlmi_part->body->content_type.param);
+
+	rlmi_part->body->data = pj_xml_clone(pool, rlmi);
 	rlmi_part->body->clone_data = rlmi_clone_data;
 	rlmi_part->body->print_body = rlmi_print_body;
 
@@ -1820,7 +1784,7 @@
 
 	pj_list_insert_before(&media_type.param, media_type_param);
 
-	pj_cstr(&pj_boundary, generate_random_string(boundary, sizeof(boundary)));
+	pj_cstr(&pj_boundary, ast_generate_random_string(boundary, sizeof(boundary)));
 	return pjsip_multipart_create(pool, &media_type, &pj_boundary);
 }
 
@@ -1942,7 +1906,7 @@
 				NULL, NULL, &tdata) != PJ_SUCCESS) {
 		return -1;
 	}
-	
+
 	tdata->msg->body = generate_notify_body(tdata->pool, sub_tree->root, force_full_state);
 	if (!tdata->msg->body) {
 		pjsip_tx_data_dec_ref(tdata);




More information about the svn-commits mailing list