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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 3 18:03:03 CDT 2009


Author: dvossel
Date: Fri Apr  3 18:02:59 2009
New Revision: 186529

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=186529
Log:
First progress on implementing RFC 4662 into chan_sip

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=186529&r1=186528&r2=186529
==============================================================================
--- team/dvossel/sip_resource_list_trunk/channels/chan_sip.c (original)
+++ team/dvossel/sip_resource_list_trunk/channels/chan_sip.c Fri Apr  3 18:02:59 2009
@@ -1699,6 +1699,8 @@
 	int laststate;				/*!< SUBSCRIBE: Last known extension state */
 	int dialogver;				/*!< SUBSCRIBE: Version for subscription dialog-info */
 
+	struct sip_rlist *rlist;	/*!< SUBSCRIBE: prt to resource list */
+
 	struct ast_dsp *vad;			/*!< Inband DTMF Detection dsp */
 
 	struct sip_peer *relatedpeer;		/*!< If this dialog is related to a peer, which one 
@@ -1821,6 +1823,30 @@
 enum sip_peer_type {
 	SIP_TYPE_PEER = (1 << 0),
 	SIP_TYPE_USER = (1 << 1),
+};
+
+struct sip_rlist_resource {
+	int stateid;
+	int laststate;
+	int dialogver;
+
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(exten);       /*!< this is an extension to watch within rlist */
+		AST_STRING_FIELD(context);
+	);
+
+	AST_LIST_ENTRY(sip_rlist_resource) entry;
+};
+
+/* todohere add brief */
+struct sip_rlist {
+	char name[80];		/*!< This is the extension to subscribe too for list */
+	AST_DECLARE_STRING_FIELDS (
+		AST_STRING_FIELD(context);
+	);
+	int version;
+	int the_mark;
+	AST_LIST_HEAD_NOLOCK(, sip_rlist_resource) resources;
 };
 
 /*! \brief Structure for SIP peer data, we place calls to peers if registered  or fixed IP address (host) 
@@ -2012,6 +2038,9 @@
 struct ao2_container *peers;
 struct ao2_container *peers_by_ip;
 
+/*! \brief  The list of resource lists... which sounds ridiculous  */
+struct ao2_container *rlists;
+
 /*! \brief  The register list: Other SIP proxies we register with and place calls to */
 static struct ast_register_list {
 	ASTOBJ_CONTAINER_COMPONENTS(struct sip_registry);
@@ -2448,8 +2477,9 @@
 
 /*--- Device object handling */
 static struct sip_peer *temp_peer(const char *name);
+static int update_call_counter(struct sip_pvt *fup, int event);
 static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime);
-static int update_call_counter(struct sip_pvt *fup, int event);
+static struct sip_rlist *build_rlist(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime);
 static void sip_destroy_peer(struct sip_peer *peer);
 static void sip_destroy_peer_fn(void *peer);
 static void set_peer_defaults(struct sip_peer *peer);
@@ -2836,14 +2866,12 @@
 	}
 
 	ast_debug(2, "Shutting down thread for %s server\n", tcptls_session->ssl ? "SSL" : "TCP");
-	
 
 	ao2_ref(tcptls_session, -1);
 	tcptls_session = NULL;
 
 	return NULL;
 }
-
 
 /*!
  * helper functions to unreference various types of objects.
@@ -2860,6 +2888,12 @@
 {
 	ao2_t_ref(peer, 1, tag);
 	return peer;
+}
+
+static void *unref_rlist(struct sip_rlist *rlist)
+{
+	ao2_ref(rlist, -1);
+	return NULL;
 }
 
 /*! \brief maintain proper refcounts for a sip_pvt's outboundproxy
@@ -4223,6 +4257,22 @@
 
 	while ((mailbox = AST_LIST_REMOVE_HEAD(&peer->mailboxes, entry)))
 		destroy_mailbox(mailbox);
+}
+
+static void destroy_rlist_resources(struct sip_rlist *rlist) {
+	struct sip_rlist_resource *resource = NULL;
+
+	while ((resource = AST_LIST_REMOVE_HEAD(&rlist->resources, entry))) {
+		ast_string_field_free_memory(resource);
+	}
+}
+
+static void sip_destroy_rlist(void *obj)
+{
+	struct sip_rlist *rlist = obj;
+	ast_debug(3, "Destroying rlist %s\n", rlist->name);
+	destroy_rlist_resources(rlist);
+	ast_string_field_free_memory(rlist);
 }
 
 static void sip_destroy_peer_fn(void *peer)
@@ -12435,7 +12485,7 @@
 		ast_verbose("Looking for %s in %s (domain %s)\n", uri, p->context, p->domain);
 
 	/* If this is a subscription we actually just need to see if a hint exists for the extension */
-	if (req->method == SIP_SUBSCRIBE) {
+	if (req->method == SIP_SUBSCRIBE) { //todohere search rlist for dest instead of just hints
 		char hint[AST_MAX_EXTENSION];
 		return (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten) ? 0 : -1);
 	} else {
@@ -14095,6 +14145,14 @@
 {
 	struct sip_peer *peer = peerobj;
 	return peer->the_mark ? CMP_MATCH : 0;
+}
+
+/* this func is used with ao2_callback to unlink/delete all marked
+   rlists */
+static int rlist_is_marked(void *rlistobj, void *arg, int flags)
+{
+	struct sip_rlist *rlist = rlistobj;
+	return rlist->the_mark ? CMP_MATCH : 0;
 }
 
 /*! \brief Remove temporary realtime objects from memory (CLI) */
@@ -20232,16 +20290,16 @@
 		return 0;
 	}
 
-	if (strcmp(event, "message-summary")) {
+	if (strcmp(event, "message-summary")) { //todohere get explanation
 		/* Get destination right away */
-		gotdest = get_destination(p, NULL);
+		gotdest = get_destination(p, NULL); // todohere get dest of list not hint.  err i dunno but we'll get this far as it is now
 	}
 
 	/* Get full contact header - this needs to be used as a request URI in NOTIFY's */
 	parse_ok_contact(p, req);
 
 	build_contact(p);
-	if (gotdest) {
+	if (gotdest) { // todohere will return 404 right now for rlist
 		transmit_response(p, "404 Not Found", req);
 		pvt_set_needdestroy(p, "subscription target not found");
 		if (authpeer)
@@ -20351,7 +20409,7 @@
 			/* 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"));
+		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)
@@ -22523,6 +22581,39 @@
 		AST_LIST_INSERT_TAIL(&peer->mailboxes, mailbox, entry);
 	}
 }
+
+static struct sip_rlist *build_rlist(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
+{
+	struct sip_rlist *rlist = NULL;
+
+	int found = 0;
+	struct sip_rlist tmp_rlist;
+
+	ast_copy_string(tmp_rlist.name, name, sizeof(tmp_rlist.name));
+	rlist = ao2_find(rlists, &tmp_rlist, OBJ_POINTER);
+
+	/* does rlist already exist, if so mark as found. else create new */
+	if (rlist) {
+		destroy_rlist_resources(rlist);  /* clear list of resources so we can rebuild them with config */
+		found++;
+	} else {
+		if (!(rlist = ao2_alloc(sizeof(*rlist), sip_destroy_rlist))) {
+			return NULL;
+		}
+
+		if (ast_string_field_init(rlist, 512)) {
+			ao2_ref(rlist, -1);
+			return NULL;
+		}
+	}
+
+
+//	for (; v || ((v = alt) && !(alt=NULL)); v = v->next) { todohere add parsing for config
+
+
+	return rlist;
+}
+
 
 /*! \brief Build peer from configuration (file or realtime static/dynamic) */
 static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
@@ -23015,6 +23106,13 @@
 	return 0;
 }
 
+static int rlist_markall_func(void *list, void *arg, int flags)
+{
+	struct sip_rlist *rlist = list;
+	rlist->the_mark = 1;
+	return 0;
+}
+
 /*! \brief Re-read SIP.conf config file
 \note	This function reloads all config data, except for
 	active peers (with registrations). They will only
@@ -23026,6 +23124,7 @@
 	struct ast_config *cfg, *ucfg;
 	struct ast_variable *v;
 	struct sip_peer *peer;
+	struct sip_rlist *rlist;
 	char *cat, *stringp, *context, *oldregcontext;
 	char newcontexts[AST_MAX_CONTEXT], oldcontexts[AST_MAX_CONTEXT];
 	struct ast_flags dummy[2];
@@ -23114,6 +23213,7 @@
 		ASTOBJ_CONTAINER_DESTROYALL(&regl, sip_registry_destroy);
 		ast_debug(4, "--------------- Done destroying registry list\n");
 		ao2_t_callback(peers, OBJ_NODATA, peer_markall_func, NULL, "callback to mark all peers");
+		ao2_callback(rlists, OBJ_NODATA, rlist_markall_func, NULL);
 	}
 	
 	/* Reset certificate handling for TLS sessions */
@@ -23780,6 +23880,12 @@
 				;
 			} else if (!strcasecmp(utype, "peer")) {
 				;
+			} else if (!strcasecmp(utype, "resourcelist")) {
+				rlist = build_rlist(cat, ast_variable_browse(cfg, cat), NULL, 0);
+				if (rlist) {  // todohere addrlists object and functions
+					ao2_link(rlists, rlist);
+					rlist = unref_rlist(rlist);
+				}
 			} else {
 				ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf");
 				continue;
@@ -23795,7 +23901,7 @@
 			}
 		}
 	}
-	
+
 	/* Set UDP address and open socket */
 	bindaddr.sin_family = AF_INET;
 	internip = bindaddr;
@@ -24407,15 +24513,16 @@
 static int sip_do_reload(enum channelreloadreason reason)
 {
 	time_t start_poke, end_poke;
-	
+
 	reload_config(reason);
 	ast_sched_dump(sched);
 
 	start_poke = time(0);
-	/* Prune peers who still are supposed to be deleted */
+	/* Prune rlists and peers who still are supposed to be deleted */
 	ao2_t_callback(peers, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, peer_is_marked, NULL,
 			"callback to remove marked peers");
-	
+	ao2_callback(rlists, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, rlist_is_marked, NULL);
+
 	ast_debug(4, "--------------- Done destroying pruned peers\n");
 
 	/* Send qualify (OPTIONS) to all peers */
@@ -24427,7 +24534,7 @@
 	sip_send_all_mwi_subscriptions();
 
 	end_poke = time(0);
-	
+
 	ast_debug(4, "do_reload finished. peer poke/prune reg contact time = %d sec.\n", (int)(end_poke-start_poke));
 
 	ast_debug(4, "--------------- SIP reload done\n");




More information about the asterisk-commits mailing list