[svn-commits] mmichelson: branch group/CCSS r229748 - /team/group/CCSS/channels/chan_sip.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Nov 12 15:31:21 CST 2009


Author: mmichelson
Date: Thu Nov 12 15:31:17 2009
New Revision: 229748

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=229748
Log:
* Wrote transmit_response_with_sip_etag for sending responses to PUBLISH requests
* Changed all instances of "eid" and "entity_id" to "etag" and "entity_tag" to better
  match the terminology in RFC3903
* Wrote an entity tag generation function.

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=229748&r1=229747&r2=229748
==============================================================================
--- team/group/CCSS/channels/chan_sip.c (original)
+++ team/group/CCSS/channels/chan_sip.c Thu Nov 12 15:31:17 2009
@@ -1652,7 +1652,7 @@
 /*!
  * Used to create new entity IDs by ESCs.
  */
-int esc_eid_counter;
+int esc_etag_counter;
 static const int DEFAULT_PUBLISH_EXPIRES = 3600;
 
 enum sip_publish_type {
@@ -1696,7 +1696,7 @@
 	 * received PUBLISH and store it in this
 	 * structure.
 	 */
-	char *entity_id;
+	char entity_tag[30];
 	/*!
 	 * The ID for the scheduler. We schedule
 	 * destruction of a sip_esc_entry when we
@@ -1826,7 +1826,7 @@
 static int esc_hash_fn(const void *obj, const int flags)
 {
 	const struct sip_esc_entry *entry = obj;
-	return ast_str_hash(entry->entity_id);
+	return ast_str_hash(entry->entity_tag);
 }
 
 static int esc_cmp_fn(void *obj, void *arg, int flags)
@@ -1834,7 +1834,7 @@
 	struct sip_esc_entry *entry1 = obj;
 	struct sip_esc_entry *entry2 = arg;
 
-	return (!strcmp(entry1->entity_id, entry2->entity_id)) ? (CMP_MATCH | CMP_STOP) : 0;
+	return (!strcmp(entry1->entity_tag, entry2->entity_tag)) ? (CMP_MATCH | CMP_STOP) : 0;
 }
 
 static struct event_state_compositor *get_esc(const char * const event_package) {
@@ -1847,9 +1847,11 @@
 	return NULL;
 }
 
-static struct sip_esc_entry *get_esc_entry(const char * entity_id, struct event_state_compositor *esc) {
+static struct sip_esc_entry *get_esc_entry(const char * entity_tag, struct event_state_compositor *esc) {
 	struct sip_esc_entry *entry;
-	struct sip_esc_entry finder = { .entity_id = (char *)entity_id };
+	struct sip_esc_entry finder;
+
+	ast_copy_string(finder.entity_tag, entity_tag, sizeof(finder.entity_tag));
 
 	entry = ao2_find(esc->compositor, &finder, OBJ_POINTER);
 
@@ -1937,6 +1939,11 @@
 	for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) {
 		ao2_ref(event_state_compositors[i].compositor, -1);
 	}
+}
+
+static int create_new_sip_etag(void)
+{
+	return ast_atomic_fetchadd_int(&esc_etag_counter, +1);
 }
 
 /*! \brief Struct to handle custom SIP notify requests. Dynamically allocated when needed */
@@ -10200,6 +10207,19 @@
 		}
 	}
 	return send_response(p, &resp, reliable, seqno);
+}
+
+static int transmit_response_with_sip_etag(struct sip_pvt *p, const char *msg, const struct sip_request *req, struct sip_esc_entry *esc_entry)
+{
+	struct sip_request resp;
+	int new_etag;
+
+	new_etag = create_new_sip_etag();
+	snprintf(esc_entry->entity_tag, sizeof(esc_entry->entity_tag), "%d", new_etag);
+	respprep(&resp, p, msg, req);
+	add_header(&resp, "SIP-ETag", esc_entry->entity_tag);
+
+	return send_response(p, &resp, 0, 0);
 }
 
 static int temp_pvt_init(void *data)
@@ -22495,10 +22515,10 @@
 	return 1;
 }
 
-static enum sip_publish_type determine_sip_publish_type(struct sip_request *req, const char * const event, const char * const eid, const char * const expires)
+static enum sip_publish_type determine_sip_publish_type(struct sip_request *req, const char * const event, const char * const etag, const char * const expires)
 {
 	int expires_int;
-	int eid_present = !ast_strlen_zero(eid);
+	int etag_present = !ast_strlen_zero(etag);
 	int body_present = req->lines > 0;
 
 	if (ast_strlen_zero(expires)) {
@@ -22513,11 +22533,11 @@
 
 	if (expires_int == 0) {
 		return SIP_PUBLISH_REMOVE;
-	} else if (!eid_present && body_present) {
+	} else if (!etag_present && body_present) {
 		return SIP_PUBLISH_INITIAL;
-	} else if (eid_present && !body_present) {
+	} else if (etag_present && !body_present) {
 		return SIP_PUBLISH_REFRESH;
-	} else if (eid_present && body_present) {
+	} else if (etag_present && body_present) {
 		return SIP_PUBLISH_MODIFY;
 	}
 
@@ -22541,12 +22561,12 @@
 	return res;
 }
 
-static int handle_sip_publish_refresh(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const eid, const int expires)
-{
-	struct sip_esc_entry *esc_entry = get_esc_entry(eid, esc);
+static int handle_sip_publish_refresh(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const etag, const int expires)
+{
+	struct sip_esc_entry *esc_entry = get_esc_entry(etag, esc);
 	int expires_ms = expires * 1000;
 	int res = 0;
-	/* A refresh is pretty simple. We need to verify that the eid corresponds to an esc entry of ours.
+	/* A refresh is pretty simple. We need to verify that the etag corresponds to an esc entry of ours.
 	 * If it does, great. We just reschedule destruction of the entry for later.
 	 */
 
@@ -22567,9 +22587,9 @@
 	return res;
 }
 
-static int handle_sip_publish_modify(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const eid, const int expires)
-{
-	struct sip_esc_entry *esc_entry = get_esc_entry(eid, esc);
+static int handle_sip_publish_modify(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const etag, const int expires)
+{
+	struct sip_esc_entry *esc_entry = get_esc_entry(etag, esc);
 	int expires_ms = expires * 1000;
 	int res = 0;
 
@@ -22589,9 +22609,9 @@
 	return res;
 }
 
-static int handle_sip_publish_remove(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const eid)
-{
-	struct sip_esc_entry *esc_entry = get_esc_entry(eid, esc);
+static int handle_sip_publish_remove(struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char * const etag)
+{
+	struct sip_esc_entry *esc_entry = get_esc_entry(etag, esc);
 	int res = 0;
 
 	if (!esc_entry) {
@@ -22611,7 +22631,7 @@
 
 static int handle_request_publish(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, const char *uri)
 {
-	const char *eid = get_header(req, "SIP-If-Match");
+	const char *etag = get_header(req, "SIP-If-Match");
 	const char *event = get_header(req, "Event");
 	struct event_state_compositor *esc;
 	enum sip_publish_type publish_type;
@@ -22628,11 +22648,6 @@
 		transmit_response(p, "489 Bad Event", req);
 		return -1;
 	}
-
-	/* Okay, we've taken care of the Bad Event scenarios.
-	 * We're going to have a hard line that PUBLISHes must
-	 * be authenticated.
-	 */
 
 	res = check_user(p, req, SIP_PUBLISH, uri, XMIT_RELIABLE, sin);
 	if (res == AUTH_CHALLENGE_SENT) {
@@ -22650,7 +22665,7 @@
 		return 0;
 	}
 
-	publish_type = determine_sip_publish_type(req, event, eid, expires_str);
+	publish_type = determine_sip_publish_type(req, event, etag, expires_str);
 
 	switch (publish_type) {
 	case SIP_PUBLISH_UNKNOWN:
@@ -22660,13 +22675,13 @@
 		handle_sip_publish_initial(p, req, esc, expires_int);
 		break;
 	case SIP_PUBLISH_REFRESH:
-		handle_sip_publish_refresh(p, req, esc, eid, expires_int);
+		handle_sip_publish_refresh(p, req, esc, etag, expires_int);
 		break;
 	case SIP_PUBLISH_MODIFY:
-		handle_sip_publish_modify(p, req, esc, eid, expires_int);
+		handle_sip_publish_modify(p, req, esc, etag, expires_int);
 		break;
 	case SIP_PUBLISH_REMOVE:
-		handle_sip_publish_remove(p, req, esc, eid);
+		handle_sip_publish_remove(p, req, esc, etag);
 		break;
 	default:
 		break;




More information about the svn-commits mailing list