[asterisk-commits] mmichelson: branch group/CCSS r232016 - /team/group/CCSS/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 1 17:55:05 CST 2009


Author: mmichelson
Date: Tue Dec  1 17:55:01 2009
New Revision: 232016

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=232016
Log:
Create a function to generate a URI.

For now, the user section of the URI is just a random string
using the get_random_string function in chan_sip, but it would be
better to use a UUID. For now, I have just made a comment about it.


Modified:
    team/group/CCSS/channels/chan_sip.c

Modified: team/group/CCSS/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/channels/chan_sip.c?view=diff&rev=232016&r1=232015&r2=232016
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Tue Dec  1 17:55:01 2009
@@ -8198,6 +8198,23 @@
 	return buf;
 }
 
+static char *generate_uri(struct sip_pvt *pvt, char *buf, size_t size)
+{
+	struct ast_str *uri = ast_str_alloca(256);
+	int ourport = ntohs(pvt->ourip.sin_port);
+	ast_str_set(&uri, 0, "%s", pvt->socket.type == SIP_TRANSPORT_TLS ? "sips:" : "sip:");
+	/* Here would be a great place to generate a UUID, but for now we'll
+	 * use the handy random string generation function we already have
+	 */
+	ast_str_append(&uri, 0, "%s", generate_random_string(buf, size));
+	ast_str_append(&uri, 0, "@%s", ast_inet_ntoa(pvt->ourip.sin_addr));
+	if (!sip_standard_port(pvt->socket.type, ourport)) {
+		ast_str_append(&uri, 0, ":%d", ourport);
+	}
+	ast_copy_string(buf, ast_str_buffer(uri), size);
+	return buf;
+}
+
 /*! \brief Build SIP Call-ID value for a non-REGISTER transaction */
 static void build_callid_pvt(struct sip_pvt *pvt)
 {
@@ -12566,6 +12583,7 @@
 {
 	struct sip_request req;
 	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
+	char uri[SIPBUFSIZE];
 	char state_str[64];
 
 	if (state < CC_QUEUED || state > CC_READY) {
@@ -12575,16 +12593,17 @@
 
 	reqprep(&req, subscription, SIP_NOTIFY, 0, TRUE);
 	ast_copy_string(state_str, sip_cc_notify_state_map[state].state_string, sizeof(state_str));
-	generate_random_string(agent_pvt->notify_uri, sizeof(agent_pvt->notify_uri));
 	add_header(&req, "Content-Type", "application/call-completion");
-	add_header_contentLength(&req, strlen(state_str) + strlen(agent_pvt->notify_uri));
+	if (state == CC_READY) {
+		generate_uri(subscription, agent_pvt->notify_uri, sizeof(agent_pvt->notify_uri));
+		snprintf(uri, sizeof(uri) - 1, "cc-uri: %s", agent_pvt->notify_uri);
+	}
+	add_header_contentLength(&req, strlen(state_str) + 
+			state == CC_READY ? strlen(uri) : 0);
 	add_line(&req, state_str);
-	/* XXX This is a bit haphazard. The URI should be of the form
-	 * cc-URI: <URI>, so that's lacking. Of course the URI can't just
-	 * be a random string, it needs to be an actual SIP URI. Take care of this
-	 * ASAP
-	 */
-	add_line(&req, agent_pvt->notify_uri);
+	if (state == CC_READY) {
+		add_line(&req, uri);
+	}
 	return send_request(subscription, &req, XMIT_RELIABLE, subscription->ocseq);
 }
 




More information about the asterisk-commits mailing list