Skip to content

Commit

Permalink
walker needs r/w arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Feb 19, 2014
1 parent 5ec9518 commit e8fc902
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/include/libradius.h
Expand Up @@ -760,7 +760,8 @@ typedef enum {
#define RBTREE_FLAG_REPLACE (1 << 0)
#define RBTREE_FLAG_LOCK (1 << 1)

typedef int (*rb_comparator_t)(void const *a, void const *b);
typedef int (*rb_comparator_t)(void const *ctx, void const *data);
typedef int (*rb_walker_t)(void *ctx, void *data);
typedef void (*rb_free_t)(void *data);

rbtree_t *rbtree_create(rb_comparator_t compare, rb_free_t node_free, int flags);
Expand Down Expand Up @@ -791,7 +792,7 @@ void *rbtree_node2data(rbtree_t *tree, rbnode_t *node);
* or 2 to delete the current node and continue. This may be
* used to batch-delete select nodes from a locked rbtree.
*/
int rbtree_walk(rbtree_t *tree, rb_order_t order, rb_comparator_t compare, void *context);
int rbtree_walk(rbtree_t *tree, rb_order_t order, rb_walker_t compare, void *context);

/*
* Find a matching data item in an rbtree and, if one is found,
Expand Down
2 changes: 1 addition & 1 deletion src/include/packet.h
Expand Up @@ -61,7 +61,7 @@ bool fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd, int proto,
bool fr_packet_list_socket_del(fr_packet_list_t *pl, int sockfd);
bool fr_packet_list_socket_freeze(fr_packet_list_t *pl, int sockfd);
bool fr_packet_list_socket_thaw(fr_packet_list_t *pl, int sockfd);
int fr_packet_list_walk(fr_packet_list_t *pl, void *ctx, rb_comparator_t callback);
int fr_packet_list_walk(fr_packet_list_t *pl, void *ctx, rb_walker_t callback);
int fr_packet_list_fd_set(fr_packet_list_t *pl, fd_set *set);
RADIUS_PACKET *fr_packet_list_recv(fr_packet_list_t *pl, fd_set *set);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/packet.c
Expand Up @@ -820,7 +820,7 @@ bool fr_packet_list_id_free(fr_packet_list_t *pl,
* 1 means delete current node and stop
* 2 means delete current node and continue
*/
int fr_packet_list_walk(fr_packet_list_t *pl, void *ctx, rb_comparator_t callback)
int fr_packet_list_walk(fr_packet_list_t *pl, void *ctx, rb_walker_t callback)
{
if (!pl || !callback) return 0;

Expand Down
10 changes: 5 additions & 5 deletions src/lib/rbtree.c
Expand Up @@ -577,7 +577,7 @@ void *rbtree_callbydata(rbtree_t *tree, void const *data, rb_comparator_t compar
* We call ourselves recursively for each function, but that's OK,
* as the stack is only log(N) deep, which is ~12 entries deep.
*/
static int walk_node_pre_order(rbnode_t *x, rb_comparator_t compare, void *context)
static int walk_node_pre_order(rbnode_t *x, rb_walker_t compare, void *context)
{
int rcode;
rbnode_t *left, *right;
Expand All @@ -604,7 +604,7 @@ static int walk_node_pre_order(rbnode_t *x, rb_comparator_t compare, void *conte
/** rbtree_in_order
*
*/
static int walk_node_in_order(rbnode_t *x, rb_comparator_t compare, void *context)
static int walk_node_in_order(rbnode_t *x, rb_walker_t compare, void *context)
{
int rcode;
rbnode_t *right;
Expand All @@ -631,7 +631,7 @@ static int walk_node_in_order(rbnode_t *x, rb_comparator_t compare, void *contex
/** rbtree_post_order
*
*/
static int walk_node_post_order(rbnode_t *x, rb_comparator_t compare, void *context)
static int walk_node_post_order(rbnode_t *x, rb_walker_t compare, void *context)
{
int rcode;

Expand Down Expand Up @@ -665,7 +665,7 @@ static int walk_node_post_order(rbnode_t *x, rb_comparator_t compare, void *cont
* 1 - delete the node and stop walking
* 2 - delete the node and continue walking
*/
static int walk_delete_order(rbtree_t *tree, rb_comparator_t compare, void *context)
static int walk_delete_order(rbtree_t *tree, rb_walker_t compare, void *context)
{
rbnode_t *solid, *x;
int rcode = 0;
Expand Down Expand Up @@ -718,7 +718,7 @@ static int walk_delete_order(rbtree_t *tree, rb_comparator_t compare, void *cont
* The compare function should return 0 to continue walking.
* Any other value stops the walk, and is returned.
*/
int rbtree_walk(rbtree_t *tree, rb_order_t order, rb_comparator_t compare, void *context)
int rbtree_walk(rbtree_t *tree, rb_order_t order, rb_walker_t compare, void *context)
{
int rcode;

Expand Down
22 changes: 10 additions & 12 deletions src/main/process.c
Expand Up @@ -1678,10 +1678,10 @@ static void add_jitter(struct timeval *when)
/*
* Called by socket_del to remove requests with this socket
*/
static int eol_proxy_listener(void const *ctx, void const *data)
static int eol_proxy_listener(void *ctx, void *data)
{
rad_listen_t const *this = ctx;
RADIUS_PACKET * const *proxy_p = data;
rad_listen_t *this = ctx;
RADIUS_PACKET **proxy_p = data;
REQUEST *request;

request = fr_packet2myptr(REQUEST, proxy, proxy_p);
Expand All @@ -1707,10 +1707,10 @@ static int eol_proxy_listener(void const *ctx, void const *data)
}
#endif /* WITH_PROXY */

static int eol_listener(void const *ctx, void const *data)
static int eol_listener(void *ctx, void *data)
{
rad_listen_t const *this = ctx;
RADIUS_PACKET * const *packet_p = data;
rad_listen_t *this = ctx;
RADIUS_PACKET **packet_p = data;
REQUEST *request;

request = fr_packet2myptr(REQUEST, packet, packet_p);
Expand Down Expand Up @@ -3919,8 +3919,7 @@ int event_new_fd(rad_listen_t *this)
*/
if (this->type == RAD_LISTEN_PROXY) {
PTHREAD_MUTEX_LOCK(&proxy_mutex);
fr_packet_list_walk(proxy_list, this,
eol_proxy_listener);
fr_packet_list_walk(proxy_list, this, eol_proxy_listener);

if (!fr_packet_list_socket_del(proxy_list, this->fd)) {
ERROR("Fatal error removing socket: %s",
Expand All @@ -3937,8 +3936,7 @@ int event_new_fd(rad_listen_t *this)
/*
* EOL all requests using this socket.
*/
fr_packet_list_walk(pl, this,
eol_listener);
fr_packet_list_walk(pl, this, eol_listener);
}

/*
Expand Down Expand Up @@ -4267,7 +4265,7 @@ int radius_event_init(CONF_SECTION *cs, int have_children)
}


static int proxy_delete_cb(UNUSED void const *ctx, void const *data)
static int proxy_delete_cb(UNUSED void *ctx, void *data)
{
REQUEST *request = fr_packet2myptr(REQUEST, packet, data);

Expand All @@ -4291,7 +4289,7 @@ static int proxy_delete_cb(UNUSED void const *ctx, void const *data)
}


static int request_delete_cb(UNUSED void const *ctx, void const *data)
static int request_delete_cb(UNUSED void *ctx, void *data)
{
REQUEST *request = fr_packet2myptr(REQUEST, packet, data);

Expand Down
4 changes: 2 additions & 2 deletions src/main/radclient.c
Expand Up @@ -457,9 +457,9 @@ static int filename_cmp(void const *one, void const *two)
return strcmp((char const *) one, (char const *) two);
}

static int filename_walk(UNUSED void const *context, void const *data)
static int filename_walk(UNUSED void *context, void *data)
{
char const *filename = data;
char const *filename = data;

/*
* Read request(s) from the file.
Expand Down
8 changes: 4 additions & 4 deletions src/tests/rbmonkey.c
Expand Up @@ -54,7 +54,7 @@ static int comp(void const *a, void const *b)
}

#if 0
static int print_cb(UNUSED void const *ctx, void const *i)
static int print_cb(UNUSED void *ctx, void *i)
{
fprintf(stderr, "%i\n", *(int*)i);
return 0;
Expand All @@ -66,17 +66,17 @@ static int print_cb(UNUSED void const *ctx, void const *i)
static int r = 0;
static int rvals[MAXSIZE];

static int store_cb(UNUSED void const *ctx, void const *i)
static int store_cb(UNUSED void *ctx, void *i)
{
rvals[r++] = *(int const *)i;
return 0;
}

static int mask;

static int filter_cb(UNUSED void const *ctx, void const *i)
static int filter_cb(UNUSED void *ctx, void *i)
{
if ((*(int const *)i & mask) == (*(int const *)ctx & mask)) {
if ((*(int *)i & mask) == (*(int *)ctx & mask)) {
return 2;
}
return 0;
Expand Down

0 comments on commit e8fc902

Please sign in to comment.