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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 1 15:04:48 CST 2009


Author: mmichelson
Date: Tue Dec  1 15:04:45 2009
New Revision: 231852

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=231852
Log:
Add the CC-specific SUBSCRIBE handler. Pretty simple IMHO.

I also needed to make use of ast_cc_agent_callback again in order
to find a SIP CC agent by the SUBSCRIBE URI. 


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=231852&r1=231851&r2=231852
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Tue Dec  1 15:04:45 2009
@@ -3363,10 +3363,17 @@
 	 * We store that URI here.
 	 */
 	char notify_uri[SIPBUFSIZE];
+	/* When we advertise call completion to a caller,
+	 * we provide a URI for the caller to use when
+	 * he sends us a SUBSCRIBE. We store it for matching
+	 * purposes when we receive the SUBSCRIBE from the
+	 * caller.
+	 */
+	char subscribe_uri[SIPBUFSIZE];
 	char is_available;
 };
 
-static int find_by_uri_helper(void *obj, void *arg, int flags)
+static int find_by_notify_uri_helper(void *obj, void *arg, int flags)
 {
 	struct ast_cc_agent *agent = obj;
 	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
@@ -3375,9 +3382,24 @@
 	return !strcmp(agent_pvt->notify_uri, uri) ? CMP_MATCH | CMP_STOP : 0;
 }
 
-static struct ast_cc_agent *find_sip_cc_agent_by_uri(const char * const uri)
-{
-	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_uri_helper, (char *)uri, "SIP");
+static struct ast_cc_agent *find_sip_cc_agent_by_notify_uri(const char * const uri)
+{
+	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_notify_uri_helper, (char *)uri, "SIP");
+	return agent;
+}
+
+static int find_by_subscribe_uri_helper(void *obj, void *arg, int flags)
+{
+	struct ast_cc_agent *agent = obj;
+	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
+	const char *uri = arg;
+
+	return !strcmp(agent_pvt->subscribe_uri, uri) ? CMP_MATCH | CMP_STOP : 0;
+}
+
+static struct ast_cc_agent *find_sip_cc_agent_by_subscribe_uri(const char * const uri)
+{
+	struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_subscribe_uri_helper, (char *)uri, "SIP");
 	return agent;
 }
 
@@ -3445,6 +3467,7 @@
 	struct sip_cc_agent_pvt *agent_pvt = agent->private_data;
 	
 	sip_pvt_lock(agent_pvt->subscribe_pvt);
+	ast_set_flag(&agent_pvt->subscribe_pvt->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
 	transmit_response(agent_pvt->subscribe_pvt, "200 OK", &agent_pvt->subscribe_pvt->initreq);
 	transmit_cc_notify(agent, agent_pvt->subscribe_pvt, CC_QUEUED);
 	sip_pvt_unlock(agent_pvt->subscribe_pvt);
@@ -23205,7 +23228,7 @@
 static int cc_esc_publish_initial_handler(struct sip_pvt *pvt, struct sip_request *req, struct event_state_compositor *esc, struct sip_esc_entry *esc_entry)
 {
 	const char *uri = REQ_OFFSET_TO_STR(req, rlPart2);
-	struct ast_cc_agent *agent = find_sip_cc_agent_by_uri(uri);
+	struct ast_cc_agent *agent = find_sip_cc_agent_by_notify_uri(uri);
 	struct sip_cc_agent_pvt *agent_pvt;
 
 	if (!agent) {
@@ -23427,7 +23450,24 @@
 
 static int handle_cc_subscribe(struct sip_pvt *p, struct sip_request *req)
 {
-	/* XXX STUB */
+	const char *uri = REQ_OFFSET_TO_STR(req, rlPart2);
+	struct ast_cc_agent *agent = find_sip_cc_agent_by_subscribe_uri(uri);
+	struct sip_cc_agent_pvt *agent_pvt;
+
+	if (!agent) {
+		ast_log(LOG_WARNING, "Invalid URI '%s' in CC subscribe\n", uri);
+		transmit_response(p, "404 Not Found", req);
+		return -1;
+	}
+
+	agent_pvt = agent->private_data;
+	agent_pvt->subscribe_pvt = dialog_ref(p, "SIP CC agent gains reference to subscription dialog");
+	ast_cc_agent_accept_request(agent->core_id, "SIP caller has requested CC via SUBSCRIBE");
+
+	/* We don't send a response here. That is done in the agent's ack callback or in the
+	 * agent destructor, should a failure occur before we have responded
+	 */
+
 	return 0;
 }
 




More information about the asterisk-commits mailing list