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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 2 10:22:36 CST 2009


Author: mmichelson
Date: Wed Dec  2 10:22:31 2009
New Revision: 232298

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=232298
Log:
Fill in the function to add the CC Call-Info header to responses.


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=232298&r1=232297&r2=232298
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Wed Dec  2 10:22:31 2009
@@ -3404,6 +3404,21 @@
 	return agent;
 }
 
+static int find_by_call_pvt_helper(void *obj, void *arg, int flags)
+{
+	struct ast_cc_agent *agent = obj;
+	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
+	struct sip_pvt *call_pvt = arg;
+
+	return agent_pvt->original_call == call_pvt ? CMP_MATCH | CMP_STOP : 0;
+}
+
+static struct ast_cc_agent *find_sip_cc_agent_by_call_pvt(struct sip_pvt *pvt)
+{
+	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_call_pvt_helper, pvt, "SIP");
+	return agent;
+}
+
 static int sip_cc_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan)
 {
 	struct sip_cc_agent_pvt *agent_pvt = ast_calloc(1, sizeof(*agent_pvt));
@@ -11763,6 +11778,10 @@
 
 static void add_cc_call_info_to_response(struct sip_pvt *p, struct sip_request *resp)
 {
+	char uri[SIPBUFSIZE];
+	struct ast_str *header = ast_str_alloca(SIPBUFSIZE);
+	struct ast_cc_agent *agent = find_sip_cc_agent_by_call_pvt(p);
+	struct sip_cc_agent_pvt *agent_pvt;
 	/* We need to add a Call-Info header to this response. What is in it, you ask?
 	 * First, we generate a URI that the caller should send a SUBSCRIBE to. Then, we provide
 	 * two parameters, purpose=call-completion and one of m=BS, m=NR, or m=NL.
@@ -11774,6 +11793,29 @@
 	 *
 	 * The m= part is not taken care of yet, but it's also not really all that important.
 	 */
+
+	if (!agent) {
+		/* Um, what? How could the SIP_OFFER_CC flag be set but there not be an
+		 * agent? Oh well, we'll just warn and return without adding the header.
+		 */
+		ast_log(LOG_WARNING, "Can't find SIP CC agent for call '%s' even though OFFER_CC flag was set?\n", p->callid);
+		return;
+	}
+
+	agent_pvt = agent->private_data;
+	
+	if (!ast_strlen_zero(agent_pvt->subscribe_uri)) {
+		ast_copy_string(uri, agent_pvt->subscribe_uri, sizeof(uri));
+	} else {
+		generate_uri(p, uri, sizeof(uri));
+		ast_copy_string(agent_pvt->subscribe_uri, uri, sizeof(agent_pvt->subscribe_uri));
+	}
+	/* XXX Hardcode "NR" as the m reason for now. This should perhaps be changed
+	 * to be more accurate. This parameter has no bearing on the actual operation
+	 * of the feature; it's just there for informational purposes.
+	 */
+	ast_str_set(&header, 0, "<%s>;purpose=call-completion;m=%s", uri, "NR");
+	add_header(resp, "Call-Info", ast_str_buffer(header));
 }
 
 /*! \brief Used for 200 OK and 183 early media




More information about the asterisk-commits mailing list