[asterisk-commits] dvossel: branch dvossel/sip_resource_list_trunk r186680 - /team/dvossel/sip_r...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 6 12:52:48 CDT 2009
Author: dvossel
Date: Mon Apr 6 12:52:37 2009
New Revision: 186680
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=186680
Log:
RFC 4226 implementation update. Added support for resourcelist type in sip.conf. builds resource lists and extensions to monitor.
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=186680&r1=186679&r2=186680
==============================================================================
--- team/dvossel/sip_resource_list_trunk/channels/chan_sip.c (original)
+++ team/dvossel/sip_resource_list_trunk/channels/chan_sip.c Mon Apr 6 12:52:37 2009
@@ -1885,7 +1885,6 @@
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;
@@ -2106,6 +2105,26 @@
} submwil;
/*! \brief
+ * \note The only member of the rlist used here is the name field
+ */
+static int rlist_hash_cb(const void *obj, const int flags)
+{
+ const struct sip_rlist *rlist = obj;
+
+ return ast_str_case_hash(rlist->name);
+}
+
+/*!
+ * \note The only member of the rlist used here is the name field
+ */
+static int rlist_cmp_cb(void *obj, void *arg, int flags)
+{
+ struct sip_rlist *rlist = obj, *rlist2 = arg;
+
+ return !strcasecmp(rlist->name, rlist2->name) ? CMP_MATCH | CMP_STOP : 0;
+}
+
+/*! \brief
* \note The only member of the peer used here is the name field
*/
static int peer_hash_cb(const void *obj, const int flags)
@@ -2946,9 +2965,9 @@
return peer;
}
-static void *unref_rlist(struct sip_rlist *rlist)
-{
- ao2_ref(rlist, -1);
+static void *unref_rlist(struct sip_rlist *rlist, char *tag)
+{
+ ao2_t_ref(rlist, -1, tag);
return NULL;
}
@@ -20993,7 +21012,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)
@@ -23175,6 +23194,23 @@
}
}
+static int add_rlist_resource(struct sip_rlist *rlist, const char *monitorexten)
+{
+ struct sip_rlist_resource *resource;
+
+ if (!(resource = ast_calloc(1, sizeof(*resource)))) {
+ return -1;
+ }
+
+ ast_string_field_init(resource, 128);
+ ast_string_field_set(resource, exten, monitorexten);
+
+ AST_LIST_INSERT_TAIL(&rlist->resources, resource, entry);
+
+ ast_log(LOG_NOTICE, "ADD RESOURCE %s, to RLIST %s\n", resource->exten, rlist->name); //todohere remove
+ return 0;
+}
+
static struct sip_rlist *build_rlist(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
{
struct sip_rlist *rlist = NULL;
@@ -23182,27 +23218,35 @@
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_find(rlists, &tmp_rlist, OBJ_POINTER);
+
+ rlist = ao2_t_find(rlists, &tmp_rlist, OBJ_POINTER, "ao2_find in rlists table");
/* 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 */
+ destroy_rlist_resources(rlist);
found++;
} else {
- if (!(rlist = ao2_alloc(sizeof(*rlist), sip_destroy_rlist))) {
+ if (!(rlist = ao2_t_alloc(sizeof(*rlist), sip_destroy_rlist, "allocate a rlist struct"))) {
return NULL;
}
- if (ast_string_field_init(rlist, 512)) {
+ if (ast_string_field_init(rlist, 256)) {
ao2_ref(rlist, -1);
return NULL;
}
- }
-
-
-// for (; v || ((v = alt) && !(alt=NULL)); v = v->next) { todohere add parsing for config
-
+
+ ast_copy_string(rlist->name, name, sizeof(rlist->name));
+ }
+
+ for (; v || ((v = alt) && !(alt = NULL)); v = v->next) {
+ if (!strcasecmp(v->name, "monitor")) {
+ add_rlist_resource(rlist, v->value);
+ } else if (!strcasecmp(v->name, "context")) {
+ ast_string_field_set(rlist, context, v->value);
+ }
+ }
return rlist;
}
@@ -23806,7 +23850,7 @@
ASTOBJ_CONTAINER_DESTROYALL(®l, 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);
+ ao2_t_callback(rlists, OBJ_NODATA, rlist_markall_func, NULL, "callback to mark all rlists");
}
/* Reset certificate handling for TLS sessions */
@@ -24467,30 +24511,25 @@
ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
continue;
} else {
- if (!strcasecmp(utype, "user")) {
- ;
- } else if (!strcasecmp(utype, "friend")) {
- ;
- } else if (!strcasecmp(utype, "peer")) {
- ;
+ if (!strcasecmp(utype, "user") || !strcasecmp(utype, "friend") || !strcasecmp(utype, "peer")) {
+ peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
+ if (peer) {
+ ao2_t_link(peers, peer, "link peer into peers table");
+ if ((peer->type & SIP_TYPE_PEER) && peer->addr.sin_addr.s_addr) {
+ ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table");
+ }
+ unref_peer(peer, "unref the result of the build_peer call. Now, the links from the tables are the only ones left.");
+ peer_count++;
+ }
} 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);
+ ao2_t_link(rlists, rlist, "link rlist into rlists table");
+ unref_rlist(rlist, "unref the result of the build_rlist call. Now, the links from the tables are the only ones left,");
}
} else {
ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf");
continue;
- }
- peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
- if (peer) {
- ao2_t_link(peers, peer, "link peer into peers table");
- if ((peer->type & SIP_TYPE_PEER) && peer->addr.sin_addr.s_addr) {
- ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table");
- }
- unref_peer(peer, "unref the result of the build_peer call. Now, the links from the tables are the only ones left.");
- peer_count++;
}
}
}
@@ -25114,7 +25153,7 @@
/* 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);
+ ao2_t_callback(rlists, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, rlist_is_marked, NULL, "callback to remove all marked rlists");
ast_debug(4, "--------------- Done destroying pruned peers\n");
@@ -25204,6 +25243,9 @@
ast_verbose("SIP channel loading...\n");
/* the fact that ao2_containers can't resize automatically is a major worry! */
/* if the number of objects gets above MAX_XXX_BUCKETS, things will slow down */
+ /* rlists uses the same size as hash_peer_size, this may need to change */
+
+ rlists = ao2_t_container_alloc(hash_peer_size, rlist_hash_cb, rlist_cmp_cb, "allocate rlists");
peers = ao2_t_container_alloc(hash_peer_size, peer_hash_cb, peer_cmp_cb, "allocate peers");
peers_by_ip = ao2_t_container_alloc(hash_peer_size, peer_iphash_cb, peer_ipcmp_cb, "allocate peers_by_ip");
dialogs = ao2_t_container_alloc(hash_dialog_size, dialog_hash_cb, dialog_cmp_cb, "allocate dialogs");
@@ -25397,6 +25439,7 @@
ASTOBJ_CONTAINER_DESTROYALL(&submwil, sip_subscribe_mwi_destroy);
ASTOBJ_CONTAINER_DESTROY(&submwil);
+ ao2_t_ref(rlists, -1, "unref the rlists table");
ao2_t_ref(peers, -1, "unref the peers table");
ao2_t_ref(peers_by_ip, -1, "unref the peers_by_ip table");
ao2_t_ref(dialogs, -1, "unref the dialogs table");
More information about the asterisk-commits
mailing list