From 30d1744ffce823312d51379585e8c19f722ea4d6 Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Fri, 7 Nov 2008 22:39:30 +0000 Subject: Add ability to pass arbitrary data to the ao2_callback_fn (called from ao2_callback and ao2_find). Currently, passing OBJ_POINTER to either of these mandates that the passed 'arg' is a hashable object, making searching for an ao2 object based on outside criteria difficult. Reviewed by Russell and Mark M. via ReviewBoard: http://reviewboard.digium.com/r/36/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@155401 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_console.c | 8 +++---- channels/chan_iax2.c | 38 ++++++++++++++++---------------- channels/chan_sip.c | 58 ++++++++++++++++++++++++------------------------- 3 files changed, 52 insertions(+), 52 deletions(-) (limited to 'channels') diff --git a/channels/chan_console.c b/channels/chan_console.c index c7090a160..e895cf10d 100644 --- a/channels/chan_console.c +++ b/channels/chan_console.c @@ -251,7 +251,7 @@ static struct console_pvt *find_pvt(const char *name) .name = name, }; - return ao2_find(pvts, &tmp_pvt, OBJ_POINTER); + return ao2_find(pvts, &tmp_pvt, NULL, OBJ_POINTER); } /*! @@ -1351,7 +1351,7 @@ static void build_device(struct ast_config *cfg, const char *name) unref_pvt(pvt); } -static int pvt_mark_destroy_cb(void *obj, void *arg, int flags) +static int pvt_mark_destroy_cb(void *obj, void *arg, void *data, int flags) { struct console_pvt *pvt = obj; pvt->destroy = 1; @@ -1403,7 +1403,7 @@ static int load_config(int reload) return -1; } - ao2_callback(pvts, OBJ_NODATA, pvt_mark_destroy_cb, NULL); + ao2_callback(pvts, OBJ_NODATA, pvt_mark_destroy_cb, NULL, NULL); ast_mutex_lock(&globals_lock); for (v = ast_variable_browse(cfg, "general"); v; v = v->next) @@ -1429,7 +1429,7 @@ static int pvt_hash_cb(const void *obj, const int flags) return ast_str_hash(pvt->name); } -static int pvt_cmp_cb(void *obj, void *arg, int flags) +static int pvt_cmp_cb(void *obj, void *arg, void *data, int flags) { struct console_pvt *pvt = obj, *pvt2 = arg; diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 09d2dff27..b89fa102a 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -1399,7 +1399,7 @@ static int peer_hash_cb(const void *obj, const int flags) /*! * \note The only member of the peer passed here guaranteed to be set is the name field */ -static int peer_cmp_cb(void *obj, void *arg, int flags) +static int peer_cmp_cb(void *obj, void *arg, void *data, int flags) { struct iax2_peer *peer = obj, *peer2 = arg; @@ -1419,7 +1419,7 @@ static int user_hash_cb(const void *obj, const int flags) /*! * \note The only member of the user passed here guaranteed to be set is the name field */ -static int user_cmp_cb(void *obj, void *arg, int flags) +static int user_cmp_cb(void *obj, void *arg, void *data, int flags) { struct iax2_user *user = obj, *user2 = arg; @@ -1437,7 +1437,7 @@ static struct iax2_peer *find_peer(const char *name, int realtime) .name = name, }; - peer = ao2_find(peers, &tmp_peer, OBJ_POINTER); + peer = ao2_find(peers, &tmp_peer, NULL, OBJ_POINTER); /* Now go for realtime if applicable */ if(!peer && realtime) @@ -1511,7 +1511,7 @@ static void iax2_destroy_helper(struct chan_iax2_pvt *pvt) .name = pvt->username, }; - user = ao2_find(users, &tmp_user, OBJ_POINTER); + user = ao2_find(users, &tmp_user, NULL, OBJ_POINTER); if (user) { ast_atomic_fetchadd_int(&user->curauthreq, -1); user_unref(user); @@ -1778,7 +1778,7 @@ static int __find_callno(unsigned short callno, unsigned short dcallno, struct s memcpy(&tmp_pvt.addr, sin, sizeof(tmp_pvt.addr)); - if ((pvt = ao2_find(iax_peercallno_pvts, &tmp_pvt, OBJ_POINTER))) { + if ((pvt = ao2_find(iax_peercallno_pvts, &tmp_pvt, NULL, OBJ_POINTER))) { if (return_locked) { ast_mutex_lock(&iaxsl[pvt->callno]); } @@ -5407,7 +5407,7 @@ static char *handle_cli_iax2_unregister(struct ast_cli_entry *e, int cmd, struct }; struct iax2_peer *peer; - peer = ao2_find(peers, &tmp_peer, OBJ_POINTER); + peer = ao2_find(peers, &tmp_peer, NULL, OBJ_POINTER); if (peer) { expire_registry(peer_ref(peer)); /* will release its own reference when done */ peer_unref(peer); /* ref from ao2_find() */ @@ -6299,7 +6299,7 @@ static int authenticate_request(int call_num) .name = p->username, }; - user = ao2_find(users, &tmp_user, OBJ_POINTER); + user = ao2_find(users, &tmp_user, NULL, OBJ_POINTER); if (user) { if (user->curauthreq == user->maxauthreq) authreq_restrict = 1; @@ -6349,7 +6349,7 @@ static int authenticate_verify(struct chan_iax2_pvt *p, struct iax_ies *ies) .name = p->username, }; - user = ao2_find(users, &tmp_user, OBJ_POINTER); + user = ao2_find(users, &tmp_user, NULL, OBJ_POINTER); if (user) { if (ast_test_flag(p, IAX_MAXAUTHREQ)) { ast_atomic_fetchadd_int(&user->curauthreq, -1); @@ -10226,7 +10226,7 @@ static int iax2_poke_noanswer(const void *data) return 0; } -static int iax2_poke_peer_cb(void *obj, void *arg, int flags) +static int iax2_poke_peer_cb(void *obj, void *arg, void *data, int flags) { struct iax2_peer *peer = obj; @@ -10666,7 +10666,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st }; if (!temponly) { - peer = ao2_find(peers, &tmp_peer, OBJ_POINTER); + peer = ao2_find(peers, &tmp_peer, NULL, OBJ_POINTER); if (peer && !ast_test_flag(peer, IAX_DELME)) firstpass = 0; } @@ -10920,7 +10920,7 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st }; if (!temponly) { - user = ao2_find(users, &tmp_user, OBJ_POINTER); + user = ao2_find(users, &tmp_user, NULL, OBJ_POINTER); if (user && !ast_test_flag(user, IAX_DELME)) firstpass = 0; } @@ -11120,7 +11120,7 @@ cleanup: return user; } -static int peer_delme_cb(void *obj, void *arg, int flags) +static int peer_delme_cb(void *obj, void *arg, void *data, int flags) { struct iax2_peer *peer = obj; @@ -11129,7 +11129,7 @@ static int peer_delme_cb(void *obj, void *arg, int flags) return 0; } -static int user_delme_cb(void *obj, void *arg, int flags) +static int user_delme_cb(void *obj, void *arg, void *data, int flags) { struct iax2_user *user = obj; @@ -11142,7 +11142,7 @@ static void delete_users(void) { struct iax2_registry *reg; - ao2_callback(users, 0, user_delme_cb, NULL); + ao2_callback(users, 0, user_delme_cb, NULL, NULL); AST_LIST_LOCK(®istrations); while ((reg = AST_LIST_REMOVE_HEAD(®istrations, entry))) { @@ -11162,7 +11162,7 @@ static void delete_users(void) } AST_LIST_UNLOCK(®istrations); - ao2_callback(peers, 0, peer_delme_cb, NULL); + ao2_callback(peers, 0, peer_delme_cb, NULL, NULL); } static void prune_users(void) @@ -12410,7 +12410,7 @@ static int unload_module(void) return __unload_module(); } -static int peer_set_sock_cb(void *obj, void *arg, int flags) +static int peer_set_sock_cb(void *obj, void *arg, void *data, int flags) { struct iax2_peer *peer = obj; @@ -12427,7 +12427,7 @@ static int pvt_hash_cb(const void *obj, const int flags) return pvt->peercallno; } -static int pvt_cmp_cb(void *obj, void *arg, int flags) +static int pvt_cmp_cb(void *obj, void *arg, void *data, int flags) { struct chan_iax2_pvt *pvt = obj, *pvt2 = arg; @@ -12541,8 +12541,8 @@ static int load_module(void) iax2_do_register(reg); AST_LIST_UNLOCK(®istrations); - ao2_callback(peers, 0, peer_set_sock_cb, NULL); - ao2_callback(peers, 0, iax2_poke_peer_cb, NULL); + ao2_callback(peers, 0, peer_set_sock_cb, NULL, NULL); + ao2_callback(peers, 0, iax2_poke_peer_cb, NULL, NULL); reload_firmware(0); diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 28b03ef9d..7211f8de1 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -1963,7 +1963,7 @@ static int peer_hash_cb(const void *obj, const int flags) /*! * \note The only member of the peer used here is the name field */ -static int peer_cmp_cb(void *obj, void *arg, int flags) +static int peer_cmp_cb(void *obj, void *arg, void *data, int flags) { struct sip_peer *peer = obj, *peer2 = arg; @@ -1990,7 +1990,7 @@ static int peer_iphash_cb(const void *obj, const int flags) /*! * \note the peer's addr struct provides to fields combined to make a key: the sin_addr.s_addr and sin_port fields. */ -static int peer_ipcmp_cb(void *obj, void *arg, int flags) +static int peer_ipcmp_cb(void *obj, void *arg, void *data, int flags) { struct sip_peer *peer = obj, *peer2 = arg; @@ -2019,7 +2019,7 @@ static int dialog_hash_cb(const void *obj, const int flags) /*! * \note The only member of the dialog used here callid string */ -static int dialog_cmp_cb(void *obj, void *arg, int flags) +static int dialog_cmp_cb(void *obj, void *arg, void *data, int flags) { struct sip_pvt *pvt = obj, *pvt2 = arg; @@ -4435,9 +4435,9 @@ static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int struct sip_peer tmp_peer; /* Inline function to assist finding peers by name only */ - auto int find_by_name(void *obj, void *arg, int flags); + auto int find_by_name(void *obj, void *arg, void *data, int flags); - int find_by_name(void *obj, void *arg, int flags) + int find_by_name(void *obj, void *arg, void *data, int flags) { struct sip_peer *search = obj, *match = arg; @@ -4457,15 +4457,15 @@ static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int if (peer) { ast_copy_string(tmp_peer.name, peer, sizeof(tmp_peer.name)); - p = ao2_t_callback(peers, OBJ_POINTER, find_by_name, &tmp_peer, "ao2_find in peers table"); + p = ao2_t_callback(peers, OBJ_POINTER, find_by_name, &tmp_peer, NULL, "ao2_find in peers table"); } else if (sin) { /* search by addr? */ tmp_peer.addr.sin_addr.s_addr = sin->sin_addr.s_addr; tmp_peer.addr.sin_port = sin->sin_port; tmp_peer.flags[0].flags = 0; - p = ao2_t_find(peers_by_ip, &tmp_peer, OBJ_POINTER, "ao2_find in peers_by_ip table"); /* WAS: p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */ + p = ao2_t_find(peers_by_ip, &tmp_peer, NULL, OBJ_POINTER, "ao2_find in peers_by_ip table"); /* WAS: p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */ if (!p) { ast_set_flag(&tmp_peer.flags[0], SIP_INSECURE_PORT); - p = ao2_t_find(peers_by_ip, &tmp_peer, OBJ_POINTER, "ao2_find in peers_by_ip table 2"); /* WAS: p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */ + p = ao2_t_find(peers_by_ip, &tmp_peer, NULL, OBJ_POINTER, "ao2_find in peers_by_ip table 2"); /* WAS: p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */ if (p) { return p; } @@ -6566,7 +6566,7 @@ struct find_call_cb_arg { * code to determine whether this is the pvt that we are looking for. * Return FALSE if not found, true otherwise. p is unlocked. */ -static int find_call_cb(void *__pvt, void *__arg, int flags) +static int find_call_cb(void *__pvt, void *__arg, void *data, int flags) { struct sip_pvt *p = __pvt; struct find_call_cb_arg *arg = __arg; @@ -6664,7 +6664,7 @@ restartsearch: struct sip_pvt tmp_dialog = { .callid = callid, }; - sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find in dialogs"); + sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, NULL, OBJ_POINTER, "ao2_find in dialogs"); if (sip_pvt_ptr) { /* well, if we don't find it-- what IS in there? */ /* Found the call */ sip_pvt_lock(sip_pvt_ptr); @@ -6672,7 +6672,7 @@ restartsearch: } } else { /* in pedantic mode! -- do the fancy linear search */ ao2_lock(dialogs); - p = ao2_t_callback(dialogs, 0 /* single, data */, find_call_cb, &arg, "pedantic linear search for dialog"); + p = ao2_t_callback(dialogs, 0 /* single, data */, find_call_cb, &arg, NULL, "pedantic linear search for dialog"); if (p) { if (sip_pvt_trylock(p)) { ao2_unlock(dialogs); @@ -12032,7 +12032,7 @@ static struct sip_pvt *get_sip_pvt_byid_locked(const char *callid, const char *t /* Search dialogs and find the match */ - sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find of dialog in dialogs table"); + sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, NULL, OBJ_POINTER, "ao2_find of dialog in dialogs table"); if (sip_pvt_ptr) { /* Go ahead and lock it (and its owner) before returning */ sip_pvt_lock(sip_pvt_ptr); @@ -13375,7 +13375,7 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str #undef FORMAT2 } -static int peer_dump_func(void *userobj, void *arg, int flags) +static int peer_dump_func(void *userobj, void *arg, void *data, int flags) { struct sip_peer *peer = userobj; int refc = ao2_t_ref(userobj, 0, ""); @@ -13386,7 +13386,7 @@ static int peer_dump_func(void *userobj, void *arg, int flags) return 0; } -static int dialog_dump_func(void *userobj, void *arg, int flags) +static int dialog_dump_func(void *userobj, void *arg, void *data, int flags) { struct sip_pvt *pvt = userobj; int refc = ao2_t_ref(userobj, 0, ""); @@ -13417,11 +13417,11 @@ static char *sip_show_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_a if (a->argc != 3) return CLI_SHOWUSAGE; ast_cli(a->fd, "-= Peer objects: %d static, %d realtime, %d autocreate =-\n\n", speerobjs, rpeerobjs, apeerobjs); - ao2_t_callback(peers, OBJ_NODATA, peer_dump_func, &a->fd, "initiate ao2_callback to dump peers"); + ao2_t_callback(peers, OBJ_NODATA, peer_dump_func, &a->fd, NULL, "initiate ao2_callback to dump peers"); ast_cli(a->fd, "-= Registry objects: %d =-\n\n", regobjs); ASTOBJ_CONTAINER_DUMP(a->fd, tmp, sizeof(tmp), ®l); ast_cli(a->fd, "-= Dialog objects:\n\n"); - ao2_t_callback(dialogs, OBJ_NODATA, dialog_dump_func, &a->fd, "initiate ao2_callback to dump dialogs"); + ao2_t_callback(dialogs, OBJ_NODATA, dialog_dump_func, &a->fd, NULL, "initiate ao2_callback to dump dialogs"); return CLI_SUCCESS; } /*! \brief Print call group and pickup group */ @@ -13501,7 +13501,7 @@ static void cleanup_stale_contexts(char *new, char *old) to be destroyed, toss it into the queue. Have a separate thread do the locking and destruction */ -static int dialog_needdestroy(void *dialogobj, void *arg, int flags) +static int dialog_needdestroy(void *dialogobj, void *arg, void *data, int flags) { struct sip_pvt *dialog = dialogobj; time_t *t = arg; @@ -13565,7 +13565,7 @@ static int dialog_needdestroy(void *dialogobj, void *arg, int flags) /* this func is used with ao2_callback to unlink/delete all marked peers */ -static int peer_is_marked(void *peerobj, void *arg, int flags) +static int peer_is_marked(void *peerobj, void *arg, void *data, int flags) { struct sip_peer *peer = peerobj; return peer->the_mark ? CMP_MATCH : 0; @@ -13672,7 +13672,7 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli unref_peer(pi, "toss iterator peer ptr"); } if (pruned) { - ao2_t_callback(peers, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, peer_is_marked, 0, + ao2_t_callback(peers, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, peer_is_marked, NULL, NULL, "initiating callback to remove marked peers"); ast_cli(a->fd, "%d peers pruned.\n", pruned); } else @@ -13682,7 +13682,7 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli if (prunepeer) { struct sip_peer tmp; ast_copy_string(tmp.name, name, sizeof(tmp.name)); - if ((peer = ao2_t_find(peers, &tmp, OBJ_POINTER | OBJ_UNLINK, "finding to unlink from peers"))) { + if ((peer = ao2_t_find(peers, &tmp, NULL, OBJ_POINTER | OBJ_UNLINK, "finding to unlink from peers"))) { if (peer->addr.sin_addr.s_addr) { ao2_t_unlink(peers_by_ip, peer, "unlinking peer from peers_by_ip also"); } @@ -14246,7 +14246,7 @@ static char *sip_unregister(struct ast_cli_entry *e, int cmd, struct ast_cli_arg } /*! \brief Callback for show_chanstats */ -static int show_chanstats_cb(void *__cur, void *__arg, int flags) +static int show_chanstats_cb(void *__cur, void *__arg, void *data, int flags) { #define FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s (%-2.2s) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n" #define FORMAT "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%-2.2u%%) %-6.6u %-10.10u%-1.1s %-10.10u (%-2.2u%%) %-6.6u\n" @@ -14325,7 +14325,7 @@ static char *sip_show_channelstats(struct ast_cli_entry *e, int cmd, struct ast_ ast_cli(a->fd, FORMAT2, "Peer", "Call ID", "Duration", "Recv: Pack", "Lost", "%", "Jitter", "Send: Pack", "Lost", "Jitter"); /* iterate on the container and invoke the callback on each item */ - ao2_t_callback(dialogs, OBJ_NODATA, show_chanstats_cb, &arg, "callback to sip show chanstats"); + ao2_t_callback(dialogs, OBJ_NODATA, show_chanstats_cb, &arg, NULL, "callback to sip show chanstats"); ast_cli(a->fd, "%d active SIP channel%s\n", arg.numchans, (arg.numchans != 1) ? "s" : ""); return CLI_SUCCESS; } @@ -14600,7 +14600,7 @@ static const struct cfsubscription_types *find_subscription_type(enum subscripti #define FORMAT "%-15.15s %-10.10s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s\n" /*! \brief callback for show channel|subscription */ -static int show_channels_cb(void *__cur, void *__arg, int flags) +static int show_channels_cb(void *__cur, void *__arg, void *data, int flags) { struct sip_pvt *cur = __cur; struct __show_chan_arg *arg = __arg; @@ -14672,7 +14672,7 @@ static char *sip_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_ ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox", "Expiry"); /* iterate on the container and invoke the callback on each item */ - ao2_t_callback(dialogs, OBJ_NODATA, show_channels_cb, &arg, "callback to show channels"); + ao2_t_callback(dialogs, OBJ_NODATA, show_channels_cb, &arg, NULL, "callback to show channels"); /* print summary information */ ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans, @@ -20616,7 +20616,7 @@ static void *do_monitor(void *data) of time since the last time we did it (when MWI is being sent, we can get back to this point every millisecond or less) */ - ao2_t_callback(dialogs, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, dialog_needdestroy, &t, + ao2_t_callback(dialogs, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, dialog_needdestroy, &t, NULL, "callback to remove dialogs w/needdestroy"); /* the old methodology would be to restart the search for dialogs to delete with every @@ -21826,7 +21826,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str during reload */ ast_copy_string(tmp_peer.name, name, sizeof(tmp_peer.name)); - peer = ao2_t_find(peers, &tmp_peer, OBJ_POINTER | OBJ_UNLINK, "find and unlink peer from peers table"); + peer = ao2_t_find(peers, &tmp_peer, NULL, OBJ_POINTER | OBJ_UNLINK, "find and unlink peer from peers table"); } if (peer) { @@ -22268,7 +22268,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str return peer; } -static int peer_markall_func(void *device, void *arg, int flags) +static int peer_markall_func(void *device, void *arg, void *data, int flags) { struct sip_peer *peer = device; peer->the_mark = 1; @@ -22373,7 +22373,7 @@ static int reload_config(enum channelreloadreason reason) /* Then, actually destroy users and registry */ ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); ast_debug(4, "--------------- Done destroying registry list\n"); - ao2_t_callback(peers, OBJ_NODATA, peer_markall_func, 0, "callback to mark all peers"); + ao2_t_callback(peers, OBJ_NODATA, peer_markall_func, NULL, NULL, "callback to mark all peers"); } /* Reset certificate handling for TLS sessions */ @@ -23668,7 +23668,7 @@ static int sip_do_reload(enum channelreloadreason reason) start_poke = time(0); /* Prune peers who still are supposed to be deleted */ - ao2_t_callback(peers, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, peer_is_marked, 0, + ao2_t_callback(peers, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, peer_is_marked, NULL, NULL, "callback to remove marked peers"); ast_debug(4, "--------------- Done destroying pruned peers\n"); -- cgit v1.2.3