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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 18 13:31:29 CST 2010


Author: mmichelson
Date: Mon Jan 18 13:31:25 2010
New Revision: 241013

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=241013
Log:
Get rid of duplication in transmit_publish and transmit_invite.


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=241013&r1=241012&r2=241013
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Mon Jan 18 13:31:25 2010
@@ -1736,6 +1736,14 @@
 	CC_READY,
 };
 
+enum sip_publish_type {
+	SIP_PUBLISH_UNKNOWN,
+	SIP_PUBLISH_INITIAL,
+	SIP_PUBLISH_REFRESH,
+	SIP_PUBLISH_MODIFY,
+	SIP_PUBLISH_REMOVE,
+};
+
 static struct {
 	enum ast_cc_service_type service;
 	const char *service_string;
@@ -1823,6 +1831,10 @@
 };
 
 struct sip_epa_entry {
+	/* When we are going to send a publish, we need to
+	 * know the type of PUBLISH to send.
+	 */
+	enum sip_publish_type publish_type;
 	/* When we send a PUBLISH, we have to be
    	 * sure to include the entity tag that we
    	 * received in the previous response.
@@ -1889,14 +1901,6 @@
  */
 int esc_etag_counter;
 static const int DEFAULT_PUBLISH_EXPIRES = 3600;
-
-enum sip_publish_type {
-	SIP_PUBLISH_UNKNOWN,
-	SIP_PUBLISH_INITIAL,
-	SIP_PUBLISH_REFRESH,
-	SIP_PUBLISH_MODIFY,
-	SIP_PUBLISH_REMOVE,
-};
 
 /*!
  * \brief common ESC items for all event types
@@ -3616,6 +3620,8 @@
 		dialog_unref(monitor_instance->subscription_pvt, "Unref monitor instance ref of subscription pvt");
 	}
 	if (monitor_instance->suspension_entry) {
+		monitor_instance->suspension_entry->body[0] = '\0';
+		transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_REMOVE ,monitor_instance->notify_uri);
 		ao2_ref(monitor_instance->suspension_entry, -1);
 	}
 	if (monitor_instance->monitor) {
@@ -12480,9 +12486,9 @@
 static int transmit_publish(struct sip_epa_entry *epa_entry, enum sip_publish_type publish_type, const char * const explicit_uri)
 {
 	struct sip_pvt *pvt;
-	struct sip_request req;
 	int expires;
-	char expires_str[10];
+
+	epa_entry->publish_type = publish_type;
 
 	if (!(pvt = sip_alloc(NULL, NULL, 0, SIP_PUBLISH, NULL))) {
 		return -1;
@@ -12492,49 +12498,17 @@
 
 	create_addr(pvt, epa_entry->destination, NULL, TRUE);
 	ast_sip_ouraddrfor(&pvt->sa.sin_addr, &pvt->ourip, pvt);
-
-	req.method = SIP_PUBLISH;
-
-	pvt->branch = ast_random();
-	build_via(pvt);
-
-	initreqprep(&req, pvt, SIP_PUBLISH, explicit_uri);
-
 	ast_set_flag(&pvt->flags[0], SIP_OUTGOING);
-
-	if (pvt->options && pvt->options->auth) {
-		add_header(&req, pvt->options->authheader, pvt->options->auth);
-	}
-
-	add_header(&req, "Event", epa_entry->static_data->name);
-
 	expires = (publish_type == SIP_PUBLISH_REMOVE) ? 0 : DEFAULT_PUBLISH_EXPIRES;
-	snprintf(expires_str, sizeof(expires_str), "%d", expires);
 	pvt->expiry = expires;
-	add_header(&req, "Expires", expires_str);
-
-	if (publish_type != SIP_PUBLISH_INITIAL) {
-		add_header(&req, "SIP-If-Match", epa_entry->entity_tag);
-	}
-
-	if (publish_type == SIP_PUBLISH_INITIAL || publish_type == SIP_PUBLISH_MODIFY) {
-		add_header(&req, "Content-Type", "application/pidf+xml");
-		add_header_contentLength(&req, strlen(epa_entry->body));
-		add_line(&req, epa_entry->body);
-	} else {
-		add_header_contentLength(&req, 0);
-	}
-
-	initialize_initreq(pvt, &req);
 
 	/* Bump refcount for sip_pvt's reference */
 	ao2_ref(epa_entry, +1);
 	pvt->epa_entry = epa_entry;
 
-	send_request(pvt, &req, XMIT_RELIABLE, pvt->ocseq);
+	transmit_invite(pvt, SIP_PUBLISH, FALSE, 2, explicit_uri);
 	sip_pvt_unlock(pvt);
 	dialog_unref(pvt, "Done with the sip_pvt allocated for transmitting PUBLISH");
-
 	return 0;
 }
 
@@ -12681,9 +12655,16 @@
 		snprintf(expires, sizeof(expires), "%d", p->expiry);
 		add_header(&req, "Event", "call-completion");
 		add_header(&req, "Expires", expires);
-		add_header(&req, "Content-Type", "application/pidf+xml");
-		add_header_contentLength(&req, strlen(p->epa_entry->body));
-		add_line(&req, p->epa_entry->body);
+		if (p->epa_entry->publish_type != SIP_PUBLISH_INITIAL) {
+			add_header(&req, "SIP-If-Match", p->epa_entry->entity_tag);
+		}
+		if (!ast_strlen_zero(p->epa_entry->body)) {
+			add_header(&req, "Content-Type", "application/pidf+xml");
+			add_header_contentLength(&req, strlen(p->epa_entry->body));
+			add_line(&req, p->epa_entry->body);
+		} else {
+			add_header_contentLength(&req, 0);
+		}
 	} else {
 		add_header_contentLength(&req, 0);
     }




More information about the asterisk-commits mailing list