aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-08-23 16:53:52 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-08-23 16:53:52 +0000
commit49117809e47318400e72667ab884b8f86727cc76 (patch)
tree0ba219cf4a255dd0fa92b2e017dadbac29b6bf81
parent29b6e688cf787390d9ff0cea3da4e478e0497ee9 (diff)
This is a hack to maintain old behavior of chan_iax2. This ensures that if
the peers and users are being stored in a linked list, that they go in the list in the same order that the older code used. This is necessary to maintain the behavior of which peers and users get matched when traversing the container. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@80497 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--channels/chan_iax2.c8
-rw-r--r--include/asterisk/astobj2.h9
-rw-r--r--main/astobj2.c7
3 files changed, 17 insertions, 7 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 958efbf0d..546f14da1 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -9735,14 +9735,14 @@ static int set_config(char *config_file, int reload)
/* Start with general parameters, then specific parameters, user and peer */
user = build_user(cat, gen, ast_variable_browse(ucfg, cat), 0);
if (user) {
- ao2_link(users, user);
+ __ao2_link(users, user, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
user = NULL;
}
peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0);
if (peer) {
if (ast_test_flag(peer, IAX_DYNAMIC))
reg_source_db(peer);
- ao2_link(peers, peer);
+ __ao2_link(peers, peer, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
peer = NULL;
}
}
@@ -9779,7 +9779,7 @@ static int set_config(char *config_file, int reload)
if (!strcasecmp(utype, "user") || !strcasecmp(utype, "friend")) {
user = build_user(cat, ast_variable_browse(cfg, cat), NULL, 0);
if (user) {
- ao2_link(users, user);
+ __ao2_link(users, user, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
user = NULL;
}
}
@@ -9788,7 +9788,7 @@ static int set_config(char *config_file, int reload)
if (peer) {
if (ast_test_flag(peer, IAX_DYNAMIC))
reg_source_db(peer);
- ao2_link(peers, peer);
+ __ao2_link(peers, peer, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
peer = NULL;
}
} else if (strcasecmp(utype, "user")) {
diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h
index 7663b1b65..cd0324dab 100644
--- a/include/asterisk/astobj2.h
+++ b/include/asterisk/astobj2.h
@@ -368,8 +368,15 @@ int ao2_container_count(ao2_container *c);
* This function insert an object in a container according its key.
*
* \note Remember to set the key before calling this function.
+ *
+ * For Asterisk 1.4 only, there is a dirty hack here to ensure that chan_iax2
+ * can have objects linked in to the container at the head instead of tail
+ * when it is just a linked list. This is to maintain some existing behavior
+ * where the order must be maintained as it was before this conversion so that
+ * matching behavior doesn't change.
*/
-void *ao2_link(ao2_container *c, void *newobj);
+#define ao2_link(c, o) __ao2_link(c, o, 0)
+void *__ao2_link(ao2_container *c, void *newobj, int iax2_hack);
void *ao2_unlink(ao2_container *c, void *newobj);
/*! \struct Used as return value if the flag OBJ_MULTIPLE is set */
diff --git a/main/astobj2.c b/main/astobj2.c
index 4f338af44..8c3e19446 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -316,7 +316,7 @@ struct bucket_list {
/*
* link an object to a container
*/
-void *ao2_link(ao2_container *c, void *user_data)
+void *__ao2_link(ao2_container *c, void *user_data, int iax2_hack)
{
int i;
/* create a new list entry */
@@ -339,7 +339,10 @@ void *ao2_link(ao2_container *c, void *user_data)
i %= c->n_buckets;
p->astobj = obj;
p->version = ast_atomic_fetchadd_int(&c->version, 1);
- AST_LIST_INSERT_TAIL(&c->buckets[i], p, entry);
+ if (iax2_hack)
+ AST_LIST_INSERT_HEAD(&c->buckets[i], p, entry);
+ else
+ AST_LIST_INSERT_TAIL(&c->buckets[i], p, entry);
ast_atomic_fetchadd_int(&c->elements, 1);
ao2_unlock(c);