[asterisk-commits] dvossel: branch dvossel/sip_resource_list_trunk r186715 - /team/dvossel/sip_r...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 7 09:33:39 CDT 2009


Author: dvossel
Date: Tue Apr  7 09:33:35 2009
New Revision: 186715

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=186715
Log:
Subscriptions to resource lists works now.  Only thing left to do is add logic for sending NOTIFY and add locking to rlists.

Modified:
    team/dvossel/sip_resource_list_trunk/channels/chan_sip.c

Modified: team/dvossel/sip_resource_list_trunk/channels/chan_sip.c
URL: http://svn.digium.com/svn-view/asterisk/team/dvossel/sip_resource_list_trunk/channels/chan_sip.c?view=diff&rev=186715&r1=186714&r2=186715
==============================================================================
--- team/dvossel/sip_resource_list_trunk/channels/chan_sip.c (original)
+++ team/dvossel/sip_resource_list_trunk/channels/chan_sip.c Tue Apr  7 09:33:35 2009
@@ -1900,6 +1900,7 @@
 	);
 	int version;
 	int the_mark;
+	int num_watchers;
 	AST_LIST_HEAD_NOLOCK(, sip_pvt) watchers;
 	AST_LIST_HEAD_NOLOCK(, sip_rlist_resource) resources;
 };
@@ -4349,6 +4350,7 @@
 static void sip_destroy_rlist(void *obj)
 {
 	struct sip_rlist *rlist = obj;
+	//todohere do we need to handle the watchers here at all?
 	ast_debug(3, "Destroying rlist %s\n", rlist->name);
 	destroy_rlist_resources(rlist);
 	ast_string_field_free_memory(rlist);
@@ -4695,12 +4697,17 @@
 
 	rlist = ao2_t_find(rlists, &tmp_rlist, OBJ_POINTER, "ao2_find in rlist_find()");
 
-	if (rlist) { //todohere make sure it matches context as well
-		found = 1;
-		if (p) {
-			p->rlist = rlist;
-		} else {
-			ao2_t_ref(rlist, -1, "unref rlist in rlist_find");
+	if (rlist) {
+		if (!strcmp(rlist->context, context)) {
+			found = 1;
+			if (p) {
+				if (p->rlist) { /* if already associated with rlist, removebefore adding */
+					rlist_remove_watcher(p);
+				}
+				p->rlist = rlist;
+			} else {
+				ao2_t_ref(rlist, -1, "unref rlist in rlist_find");
+			}
 		}
 	}
 
@@ -20981,7 +20988,7 @@
 		/* Polycom phones only handle xpidf+xml, even if they say they can
 		   handle pidf+xml as well
 		*/
-		if (strstr(acceptheader, " application/rlmi+xml")) {
+		if (strstr(acceptheader, "application/rlmi+xml")) {
 			p->subscribed = DIALOG_RLMI_XML;
 		} else if (strstr(p->useragent, "Polycom")) {
 			p->subscribed = XPIDF_XML;
@@ -21067,22 +21074,14 @@
 	}
 
 	/* Add subscription for extension state from the PBX core */
-	if (p->subscribed != MWI_NOTIFICATION && !resubscribe) {
-
-		if (p->subscribed == DIALOG_RLMI_XML) {
-			//todohere add code to add this pvt to subscribe to rlist updates 
-			if (p->rlist) {
-				rlist_remove_watcher(p);
-			}
-			rlist_add_watcher(p);
-		} else {
-			if (p->stateid > -1) {
-				ast_extension_state_del(p->stateid, cb_extensionstate);
-				/* we need to dec the refcount, now that the extensionstate is removed */
-				dialog_unref(p, "the extensionstate containing this dialog ptr was deleted");
-			}
-			p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, dialog_ref(p,"copying dialog ptr into extension state struct"));
-		}
+	if ((p->subscribed != MWI_NOTIFICATION && !resubscribe) &&
+		(p->subscribed != DIALOG_RLMI_XML)) {
+		if (p->stateid > -1) {
+			ast_extension_state_del(p->stateid, cb_extensionstate);
+			/* we need to dec the refcount, now that the extensionstate is removed */
+			dialog_unref(p, "the extensionstate containing this dialog ptr was deleted");
+		}
+		p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, dialog_ref(p,"copying dialog ptr into extension state struct"));
 	}
 
 	if (!req->ignore && p)
@@ -21116,7 +21115,17 @@
 				ao2_unlock(p->relatedpeer);
 			}
 		} else if (p->subscribed == DIALOG_RLMI_XML) { /* resource lists extension states are handled differently */
-			//todohere add logic for resource lists, send 200ok, first notifiy, etc..
+			if (rlist_add_watcher(p) > 0) {
+				ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
+				transmit_response(p, "200 OK", req);
+				ast_string_field_build(p, subscribeuri, "%s@%s", p->exten, p->context);
+				//todohere force first notify
+			} else {
+				transmit_response(p, "404 Not found", req);
+				pvt_set_needdestroy(p, "no extension for SUBSCRIBE");
+				return 0;
+			}
+
 		} else {
 			struct sip_pvt *p_old;
 
@@ -23274,11 +23283,17 @@
 		if (p->rlist) {
 			dialog_ref(p, "add sip_pvt watcher to resource list notifications");
 			AST_LIST_INSERT_TAIL(&p->rlist->watchers, p, rlist_entry);
-			return 0;
-		}
-	}
-
-	return -1;
+			if (!p->rlist->num_watchers) { /* num_watchers is zero, meaning this is the first watcher so start monitoring */
+			// todohere add logic to start monitoring extensions since we have a watcher
+			}
+			p->rlist->num_watchers++;
+			return 1;
+		}
+	} else {
+		return -1;
+	}
+
+	return 0;
 }
 
 static int rlist_remove_watcher(struct sip_pvt *p)
@@ -23288,6 +23303,10 @@
 	}
 	if (p->rlist) {
 		AST_LIST_REMOVE(&p->rlist->watchers, p, rlist_entry);
+		p->rlist->num_watchers--;
+		if (!p->rlist->num_watchers) { /* num_watchers is decremented to zero, stop monitoring extensions. */
+			//todohere add logic to stop monitoring extensions since nothing is watching
+		}
 		ao2_t_ref(p->rlist, -1, "remove dialog's ref to resource list");
 		p->rlist = NULL;
 		dialog_unref(p, "remove sip_pvt from resource list notifications");
@@ -23317,7 +23336,6 @@
 	int found = 0;
 	struct sip_rlist tmp_rlist;
 
-	ast_log(LOG_NOTICE, "BUILDING RLIST %s\n", name); //todohere remove
 	ast_copy_string(tmp_rlist.name, name, sizeof(tmp_rlist.name));
 
 	rlist = ao2_t_find(rlists, &tmp_rlist, OBJ_POINTER, "ao2_find in rlists table");
@@ -23326,7 +23344,6 @@
 	if (rlist) {
 		destroy_rlist_resources(rlist); /* rlist found, remove all monitor resources and rebuild */
 		found++;
-		ast_log(LOG_NOTICE, "FOUND RLIST:%s", rlist->name); //todohere remove
 	} else {
 		if (!(rlist = ao2_t_alloc(sizeof(*rlist), sip_destroy_rlist, "allocate a rlist struct"))) {
 			return NULL;




More information about the asterisk-commits mailing list