diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 958efbf0dc..546f14da10 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 7663b1b652..cd0324dab1 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 4f338af44d..8c3e19446f 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);