Make util symbols private (i.e. prefix _getdns)

This commit is contained in:
Willem Toorop 2015-08-19 16:07:01 +02:00
parent 09492cbf46
commit 450aabefcc
13 changed files with 239 additions and 239 deletions

View File

@ -64,7 +64,7 @@
void *plain_mem_funcs_user_arg = MF_PLAIN;
typedef struct host_name_addrs {
getdns_rbnode_t node;
_getdns_rbnode_t node;
getdns_list *ipv4addrs;
getdns_list *ipv6addrs;
uint8_t host_name[];
@ -117,7 +117,7 @@ static void set_ub_edns_maximum_udp_payload_size(struct getdns_context*,
/* Stuff to make it compile pedantically */
#define RETURN_IF_NULL(ptr, code) if(ptr == NULL) return code;
static void destroy_local_host(getdns_rbnode_t * node, void *arg)
static void destroy_local_host(_getdns_rbnode_t * node, void *arg)
{
getdns_context *context = (getdns_context *)arg;
host_name_addrs *hnas = (host_name_addrs *)node;
@ -231,7 +231,7 @@ add_local_host(getdns_context *context, getdns_dict *address, const char *str)
canonicalize_dname(host_name);
if (!(hnas = (host_name_addrs *)getdns_rbtree_search(
if (!(hnas = (host_name_addrs *)_getdns_rbtree_search(
&context->local_hosts, host_name))) {
if (!(hnas = (host_name_addrs *)GETDNS_XMALLOC(context->mf,
@ -265,7 +265,7 @@ add_local_host(getdns_context *context, getdns_dict *address, const char *str)
GETDNS_FREE(context->mf, hnas);
} else if (!hnas_found)
(void)getdns_rbtree_insert(&context->local_hosts, &hnas->node);
(void)_getdns_rbtree_insert(&context->local_hosts, &hnas->node);
}
static getdns_dict *
@ -642,7 +642,7 @@ upstream_init(getdns_upstream *upstream,
upstream->has_server_cookie = 0;
/* Tracking of network requests on this socket */
getdns_rbtree_init(&upstream->netreq_by_query_id,
_getdns_rbtree_init(&upstream->netreq_by_query_id,
net_req_query_id_cmp);
}
@ -843,8 +843,8 @@ getdns_context_create_with_extended_memory_functions(
result->resolution_type_set = 0;
getdns_rbtree_init(&result->outbound_requests, transaction_id_cmp);
getdns_rbtree_init(&result->local_hosts, local_host_cmp);
_getdns_rbtree_init(&result->outbound_requests, transaction_id_cmp);
_getdns_rbtree_init(&result->local_hosts, local_host_cmp);
result->resolution_type = GETDNS_RESOLUTION_RECURSING;
if ((r = create_default_namespaces(result)))
@ -1022,7 +1022,7 @@ getdns_context_destroy(struct getdns_context *context)
context->trust_anchors != context->trust_anchors_spc)
GETDNS_FREE(context->mf, context->trust_anchors);
getdns_traverse_postorder(&context->local_hosts,
_getdns_traverse_postorder(&context->local_hosts,
destroy_local_host, context);
GETDNS_FREE(context->my_mf, context);
@ -1963,7 +1963,7 @@ getdns_context_cancel_request(getdns_context *context,
return GETDNS_RETURN_INVALID_PARAMETER;
/* delete the node from the tree */
if (!(dnsreq = (getdns_dns_req *)getdns_rbtree_delete(
if (!(dnsreq = (getdns_dns_req *)_getdns_rbtree_delete(
&context->outbound_requests, &transaction_id)))
return GETDNS_RETURN_UNKNOWN_TRANSACTION;
@ -2245,7 +2245,7 @@ getdns_context_track_outbound_request(getdns_dns_req *dnsreq)
return GETDNS_RETURN_INVALID_PARAMETER;
dnsreq->node.key = &(dnsreq->trans_id);
if (!getdns_rbtree_insert(
if (!_getdns_rbtree_insert(
&dnsreq->context->outbound_requests, &dnsreq->node))
return GETDNS_RETURN_GENERIC_ERROR;
@ -2259,7 +2259,7 @@ getdns_context_clear_outbound_request(getdns_dns_req *dnsreq)
if (!dnsreq)
return GETDNS_RETURN_INVALID_PARAMETER;
if (!getdns_rbtree_delete(
if (!_getdns_rbtree_delete(
&dnsreq->context->outbound_requests, &dnsreq->trans_id))
return GETDNS_RETURN_GENERIC_ERROR;
@ -2340,7 +2340,7 @@ getdns_bindata_destroy(struct mem_funcs *mfs,
/* TODO: Remove next_timeout argument from getdns_context_get_num_pending_requests
*/
void getdns_handle_timeouts(struct getdns_event_base* base, struct timeval* now,
void _getdns_handle_timeouts(struct _getdns_event_base* base, struct timeval* now,
struct timeval* wait);
uint32_t
getdns_context_get_num_pending_requests(struct getdns_context* context,
@ -2354,7 +2354,7 @@ getdns_context_get_num_pending_requests(struct getdns_context* context,
context->extension->vmt->run_once(context->extension, 0);
/* TODO: Remove this when next_timeout is gone */
getdns_handle_timeouts(context->mini_event.base,
_getdns_handle_timeouts(context->mini_event.base,
&context->mini_event.time_tv, next_timeout ? next_timeout : &dispose);
return context->outbound_requests.count;
@ -2394,7 +2394,7 @@ typedef struct timeout_accumulator {
} timeout_accumulator;
static void
accumulate_outstanding_transactions(getdns_rbnode_t* node, void* arg) {
accumulate_outstanding_transactions(_getdns_rbnode_t* node, void* arg) {
timeout_accumulator* acc = (timeout_accumulator*) arg;
acc->ids[acc->idx] = *((getdns_transaction_t*) node->key);
acc->idx++;
@ -2407,7 +2407,7 @@ cancel_outstanding_requests(struct getdns_context* context, int fire_callback) {
int i;
acc.idx = 0;
acc.ids = GETDNS_XMALLOC(context->my_mf, getdns_transaction_t, context->outbound_requests.count);
getdns_traverse_postorder(&context->outbound_requests, accumulate_outstanding_transactions, &acc);
_getdns_traverse_postorder(&context->outbound_requests, accumulate_outstanding_transactions, &acc);
for (i = 0; i < acc.idx; ++i) {
getdns_context_cancel_request(context, acc.ids[i], fire_callback);
}
@ -2618,7 +2618,7 @@ getdns_context_local_namespace_resolve(
canonicalize_dname(lookup);
if (!(hnas = (host_name_addrs *)
getdns_rbtree_search(&context->local_hosts, lookup)))
_getdns_rbtree_search(&context->local_hosts, lookup)))
return GETDNS_RETURN_GENERIC_ERROR;
if (!hnas->ipv4addrs && (!ipv6 || !hnas->ipv6addrs))

View File

@ -106,7 +106,7 @@ typedef struct getdns_upstream {
/* Pipelining of TCP network requests */
getdns_network_req *write_queue;
getdns_network_req *write_queue_last;
getdns_rbtree_t netreq_by_query_id;
_getdns_rbtree_t netreq_by_query_id;
/* EDNS cookies */
uint32_t secret;
@ -173,7 +173,7 @@ struct getdns_context {
#endif
/* A tree to hold local host information*/
getdns_rbtree_t local_hosts;
_getdns_rbtree_t local_hosts;
int return_dnssec_status;
@ -185,7 +185,7 @@ struct getdns_context {
/*
* outbound requests -> transaction to getdns_dns_req
*/
getdns_rbtree_t outbound_requests;
_getdns_rbtree_t outbound_requests;
/* Event loop extension. */
getdns_eventloop *extension;

View File

@ -1,7 +1,7 @@
/**
*
* getdns dict management functions, note that the internal storage is
* accomplished via an getdns_rbtree_t
* accomplished via an _getdns_rbtree_t
*
* Interfaces originally taken from the getdns API description pseudo implementation.
*
@ -60,7 +60,7 @@ struct getdns_dict_item *
getdns_dict_find(const struct getdns_dict *dict, const char *key)
{
return (struct getdns_dict_item *)
getdns_rbtree_search((getdns_rbtree_t *)&(dict->root), key);
_getdns_rbtree_search((_getdns_rbtree_t *)&(dict->root), key);
} /* getdns_dict_find */
struct getdns_dict_item *
@ -69,14 +69,14 @@ getdns_dict_find_and_add(struct getdns_dict *dict, const char *key)
struct getdns_dict_item *item;
item = (struct getdns_dict_item *)
getdns_rbtree_search(&(dict->root), key);
_getdns_rbtree_search(&(dict->root), key);
if (!item) {
/* add a node */
item = GETDNS_MALLOC(dict->mf, struct getdns_dict_item);
item->node.key = getdns_strdup(&dict->mf, key);
item->data.n = 0;
getdns_rbtree_insert(&(dict->root), (getdns_rbnode_t *) item);
_getdns_rbtree_insert(&(dict->root), (_getdns_rbnode_t *) item);
}
return item;
} /* getdns_dict_find_and_add */
@ -99,7 +99,7 @@ getdns_dict_get_names(const getdns_dict *dict, getdns_list **answer)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
RBTREE_FOR(item, struct getdns_dict_item *,
(getdns_rbtree_t *)&(dict->root)) {
(_getdns_rbtree_t *)&(dict->root)) {
getdns_list_append_string(*answer, item->node.key);
}
return GETDNS_RETURN_GOOD;
@ -234,7 +234,7 @@ getdns_dict_create_with_extended_memory_functions(
dict->mf.mf.ext.realloc = realloc;
dict->mf.mf.ext.free = free;
getdns_rbtree_init(&(dict->root),
_getdns_rbtree_init(&(dict->root),
(int (*)(const void *, const void *)) strcmp);
return dict;
}
@ -305,7 +305,7 @@ getdns_dict_copy(const struct getdns_dict * srcdict,
retval = GETDNS_RETURN_GOOD;
RBTREE_FOR(item, struct getdns_dict_item *,
(struct getdns_rbtree_t *)&(srcdict->root)) {
(struct _getdns_rbtree_t *)&(srcdict->root)) {
key = (char *) item->node.key;
switch (item->dtype) {
case t_bindata:
@ -346,7 +346,7 @@ getdns_dict_copy(const struct getdns_dict * srcdict,
* @return void
*/
void
getdns_dict_item_free(getdns_rbnode_t * node, void *arg)
getdns_dict_item_free(_getdns_rbnode_t * node, void *arg)
{
struct getdns_dict_item *item = (struct getdns_dict_item *) node;
struct getdns_dict *dict = (struct getdns_dict *)arg;
@ -377,7 +377,7 @@ void
getdns_dict_destroy(struct getdns_dict *dict)
{
if (!dict) return;
getdns_traverse_postorder(&(dict->root), getdns_dict_item_free, dict);
_getdns_traverse_postorder(&(dict->root), getdns_dict_item_free, dict);
GETDNS_FREE(dict->mf, dict);
} /* getdns_dict_destroy */
@ -829,7 +829,7 @@ getdns_pp_dict(gldns_buffer * buf, size_t indent,
i = 0;
indent += 2;
RBTREE_FOR(item, struct getdns_dict_item *,
(getdns_rbtree_t *)&(dict->root)) {
(_getdns_rbtree_t *)&(dict->root)) {
if (i && gldns_buffer_printf(buf, ",") < 0)
return -1;
@ -1111,7 +1111,7 @@ getdns_dict_remove_name(struct getdns_dict *this_dict, const char *name)
return GETDNS_RETURN_NO_SUCH_DICT_NAME;
/* cleanup */
getdns_rbtree_delete(&this_dict->root, name);
_getdns_rbtree_delete(&this_dict->root, name);
getdns_dict_item_free(&item->node, this_dict);
return GETDNS_RETURN_GOOD;

View File

@ -52,7 +52,7 @@ union getdns_item
*/
struct getdns_dict_item
{
getdns_rbnode_t node;
_getdns_rbnode_t node;
getdns_data_type dtype;
union getdns_item data;
};
@ -66,7 +66,7 @@ struct getdns_dict_item
*/
struct getdns_dict
{
getdns_rbtree_t root;
_getdns_rbtree_t root;
struct mem_funcs mf;
};

View File

@ -43,7 +43,7 @@ static void
getdns_mini_event_cleanup(getdns_eventloop *loop)
{
getdns_mini_event *ext = (getdns_mini_event *)loop;
getdns_event_base_free(ext->base);
_getdns_event_base_free(ext->base);
}
void
@ -54,9 +54,9 @@ getdns_mini_event_destroy(getdns_mini_event *ext)
GETDNS_FREE(ext->mf, ext);
}
void getdns_handle_timeouts(struct getdns_event_base* base,
void _getdns_handle_timeouts(struct _getdns_event_base* base,
struct timeval* now, struct timeval* wait);
int getdns_handle_select(struct getdns_event_base* base, struct timeval* wait);
int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait);
static int
getdns_mini_event_settime(getdns_mini_event *ext)
@ -77,12 +77,12 @@ getdns_mini_event_run(getdns_eventloop *loop)
return;
do {
(void) getdns_handle_timeouts(ext->base, &ext->time_tv, &wait);
(void) _getdns_handle_timeouts(ext->base, &ext->time_tv, &wait);
if (!ext->n_events)
break;
if (getdns_handle_select(ext->base, &wait))
if (_getdns_handle_select(ext->base, &wait))
break;
} while (ext->n_events);
@ -98,14 +98,14 @@ getdns_mini_event_run_once(getdns_eventloop *loop, int blocking)
if (blocking) {
if (getdns_mini_event_settime(ext) < 0)
return;
getdns_handle_timeouts(ext->base, &ext->time_tv, &wait);
if (getdns_handle_select(ext->base, &wait) < 0)
_getdns_handle_timeouts(ext->base, &ext->time_tv, &wait);
if (_getdns_handle_select(ext->base, &wait) < 0)
return;
} else if (getdns_handle_select(ext->base, &immediately) < 0)
} else if (_getdns_handle_select(ext->base, &immediately) < 0)
return;
getdns_handle_timeouts(ext->base, &ext->time_tv, &wait);
_getdns_handle_timeouts(ext->base, &ext->time_tv, &wait);
}
static getdns_return_t
@ -117,7 +117,7 @@ getdns_mini_event_clear(getdns_eventloop *loop, getdns_eventloop_event *el_ev)
assert(el_ev->ev);
DEBUG_SCHED("1. getdns_mini_event_clear(loop: %p, el_ev: %p[userarg: %p, r: %p, w: %p, t: %p, ev: %p]); n_events: %d, times: %d\n", loop, el_ev, el_ev->userarg, el_ev->read_cb, el_ev->write_cb, el_ev->timeout_cb, el_ev->ev, (int)ext->n_events, (int)ext->base->times->count);
if (getdns_event_del(el_ev->ev) != 0)
if (_getdns_event_del(el_ev->ev) != 0)
r = GETDNS_RETURN_GENERIC_ERROR;
GETDNS_FREE(ext->mf, el_ev->ev);
@ -152,19 +152,19 @@ getdns_mini_event_schedule(getdns_eventloop *loop,
int fd, uint64_t timeout, getdns_eventloop_event *el_ev)
{
getdns_mini_event *ext = (getdns_mini_event *)loop;
struct getdns_event *my_ev;
struct _getdns_event *my_ev;
struct timeval tv = { timeout / 1000, (timeout % 1000) * 1000 };
assert(el_ev);
assert(!(el_ev->read_cb || el_ev->write_cb) || fd >= 0);
assert( el_ev->read_cb || el_ev->write_cb || el_ev->timeout_cb);
if (!(my_ev = GETDNS_MALLOC(ext->mf, struct getdns_event)))
if (!(my_ev = GETDNS_MALLOC(ext->mf, struct _getdns_event)))
return GETDNS_RETURN_MEMORY_ERROR;
el_ev->ev = my_ev;
DEBUG_SCHED("1. getdns_mini_event_schedule(loop: %p, fd: %d, timeout: %"PRId64", el_ev: %p[userarg: %p, r: %p, w: %p, t: %p, ev: %p]); n_events: %d\n", loop, fd, timeout, el_ev, el_ev->userarg, el_ev->read_cb, el_ev->write_cb, el_ev->timeout_cb, el_ev->ev, (int)ext->n_events);
getdns_event_set(my_ev, fd, (
_getdns_event_set(my_ev, fd, (
(el_ev->read_cb ? EV_READ|EV_PERSIST : 0) |
(el_ev->write_cb ? EV_WRITE|EV_PERSIST : 0) |
(el_ev->timeout_cb ? EV_TIMEOUT : 0)),
@ -173,8 +173,8 @@ getdns_mini_event_schedule(getdns_eventloop *loop,
if (getdns_mini_event_settime(ext))
goto error;
(void) getdns_event_base_set(ext->base, my_ev);
if (getdns_event_add(my_ev, el_ev->timeout_cb ? &tv : NULL))
(void) _getdns_event_base_set(ext->base, my_ev);
if (_getdns_event_add(my_ev, el_ev->timeout_cb ? &tv : NULL))
goto error;
ext->n_events++;
@ -207,7 +207,7 @@ getdns_mini_event_init(getdns_context *context, getdns_mini_event *ext)
ext->n_events = 0;
ext->loop.vmt = &getdns_mini_event_vmt;
ext->base = getdns_event_init(&ext->time_secs, &ext->time_tv);
ext->base = _getdns_event_init(&ext->time_secs, &ext->time_tv);
if (!ext->base)
return GETDNS_RETURN_MEMORY_ERROR;

View File

@ -39,12 +39,12 @@
#include "types-internal.h"
typedef struct getdns_mini_event {
getdns_eventloop loop;
time_t time_secs;
struct timeval time_tv;
struct getdns_event_base *base;
size_t n_events;
struct mem_funcs mf;
getdns_eventloop loop;
time_t time_secs;
struct timeval time_tv;
struct _getdns_event_base *base;
size_t n_events;
struct mem_funcs mf;
} getdns_mini_event;
getdns_return_t

View File

@ -424,7 +424,7 @@ stub_cleanup(getdns_network_req *netreq)
/* Delete from upstream->netreq_by_query_id (if present) */
query_id_intptr = (intptr_t)netreq->query_id;
(void) getdns_rbtree_delete(
(void) _getdns_rbtree_delete(
&upstream->netreq_by_query_id, (void *)query_id_intptr);
/* Delete from upstream->write_queue (if present) */
@ -485,7 +485,7 @@ upstream_erred(getdns_upstream *upstream)
}
while (upstream->netreq_by_query_id.count) {
netreq = (getdns_network_req *)
getdns_rbtree_first(&upstream->netreq_by_query_id);
_getdns_rbtree_first(&upstream->netreq_by_query_id);
stub_cleanup(netreq);
netreq->state = NET_REQ_FINISHED;
priv_getdns_check_dns_req_complete(netreq->owner);
@ -698,7 +698,7 @@ stub_tcp_write(int fd, getdns_tcp_state *tcp, getdns_network_req *netreq)
query_id_intptr = (intptr_t)query_id;
netreq->node.key = (void *)query_id_intptr;
} while (!getdns_rbtree_insert(
} while (!_getdns_rbtree_insert(
&netreq->upstream->netreq_by_query_id, &netreq->node));
GLDNS_ID_SET(netreq->query, query_id);
@ -1060,7 +1060,7 @@ stub_tls_write(getdns_upstream *upstream, getdns_tcp_state *tcp,
query_id_intptr = (intptr_t)query_id;
netreq->node.key = (void *)query_id_intptr;
} while (!getdns_rbtree_insert(
} while (!_getdns_rbtree_insert(
&netreq->upstream->netreq_by_query_id, &netreq->node));
GLDNS_ID_SET(netreq->query, query_id);
@ -1291,7 +1291,7 @@ upstream_read_cb(void *userarg)
/* Lookup netreq */
query_id = (uint16_t) q;
query_id_intptr = (intptr_t) query_id;
netreq = (getdns_network_req *)getdns_rbtree_delete(
netreq = (getdns_network_req *)_getdns_rbtree_delete(
&upstream->netreq_by_query_id, (void *)query_id_intptr);
if (! netreq) /* maybe canceled */ {
/* reset read buffer */

View File

@ -175,7 +175,7 @@ typedef struct getdns_tcp_state {
typedef struct getdns_network_req
{
/* For storage in upstream->netreq_by_query_id */
getdns_rbnode_t node;
_getdns_rbnode_t node;
/* the async_id from unbound */
int unbound_id;
/* state var */
@ -227,7 +227,7 @@ typedef struct getdns_network_req
*/
typedef struct getdns_dns_req {
/* For storage in context->outbound_requests */
getdns_rbnode_t node;
_getdns_rbnode_t node;
/* name */
uint8_t name[256];

View File

@ -8,24 +8,24 @@ for f in mini_event.c mini_event.h rbtree.c rbtree.h
do
wget http://unbound.net/svn/trunk/util/$f || \
ftp http://unbound.net/svn/trunk/util/$f || continue
sed -e 's/event_/getdns_event_/g' \
-e 's/signal_add/getdns_signal_add/g' \
-e 's/signal_del/getdns_signal_del/g' \
-e 's/signal_set/getdns_signal_set/g' \
-e 's/evtimer_/getdns_evtimer_/g' \
-e 's/struct event/struct getdns_event/g' \
-e 's/mini_ev_cmp/getdns_mini_ev_cmp/g' \
sed -e 's/event_/_getdns_event_/g' \
-e 's/signal_add/_getdns_signal_add/g' \
-e 's/signal_del/_getdns_signal_del/g' \
-e 's/signal_set/_getdns_signal_set/g' \
-e 's/evtimer_/_getdns_evtimer_/g' \
-e 's/struct event/struct _getdns_event/g' \
-e 's/mini_ev_cmp/_getdns_mini_ev_cmp/g' \
-e 's/static void handle_timeouts/void handle_timeouts/g' \
-e 's/handle_timeouts/getdns_handle_timeouts/g' \
-e 's/handle_timeouts/_getdns_handle_timeouts/g' \
-e 's/static int handle_select/int handle_select/g' \
-e 's/handle_select/getdns_handle_select/g' \
-e 's/handle_select/_getdns_handle_select/g' \
-e 's/#include "rbtree\.h"/#include "util\/rbtree.h"/g' \
-e 's/rbnode_/getdns_rbnode_/g' \
-e 's/rbtree_/getdns_rbtree_/g' \
-e 's/traverse_post/getdns_traverse_post/g' \
-e 's/rbnode_/_getdns_rbnode_/g' \
-e 's/rbtree_/_getdns_rbtree_/g' \
-e 's/traverse_post/_getdns_traverse_post/g' \
-e 's/#include "fptr_wlist\.h"/#include "util\/fptr_wlist.h"/g' \
-e 's/#include "log\.h"/#include "util\/log.h"/g' \
-e '/^#define getdns_.* minigetdns_/d' \
-e '/^#define _getdns_.* mini_getdns_/d' \
-e '/^\/\* redefine to use our own namespace so that on platforms where$/d' \
-e '/^ \* linkers crosslink library-private symbols with other symbols, it works \*\//d' \
$f > ../$f

View File

@ -52,10 +52,10 @@
#include "util/fptr_wlist.h"
/** compare events in tree, based on timevalue, ptr for uniqueness */
int getdns_mini_ev_cmp(const void* a, const void* b)
int _getdns_mini_ev_cmp(const void* a, const void* b)
{
const struct getdns_event *e = (const struct getdns_event*)a;
const struct getdns_event *f = (const struct getdns_event*)b;
const struct _getdns_event *e = (const struct _getdns_event*)a;
const struct _getdns_event *f = (const struct _getdns_event*)b;
if(e->ev_timeout.tv_sec < f->ev_timeout.tv_sec)
return -1;
if(e->ev_timeout.tv_sec > f->ev_timeout.tv_sec)
@ -73,7 +73,7 @@ int getdns_mini_ev_cmp(const void* a, const void* b)
/** set time */
static int
settime(struct getdns_event_base* base)
settime(struct _getdns_event_base* base)
{
if(gettimeofday(base->time_tv, NULL) < 0) {
return -1;
@ -85,22 +85,22 @@ settime(struct getdns_event_base* base)
}
/** create event base */
void *getdns_event_init(time_t* time_secs, struct timeval* time_tv)
void *_getdns_event_init(time_t* time_secs, struct timeval* time_tv)
{
struct getdns_event_base* base = (struct getdns_event_base*)malloc(
sizeof(struct getdns_event_base));
struct _getdns_event_base* base = (struct _getdns_event_base*)malloc(
sizeof(struct _getdns_event_base));
if(!base)
return NULL;
memset(base, 0, sizeof(*base));
base->time_secs = time_secs;
base->time_tv = time_tv;
if(settime(base) < 0) {
getdns_event_base_free(base);
_getdns_event_base_free(base);
return NULL;
}
base->times = getdns_rbtree_create(getdns_mini_ev_cmp);
base->times = _getdns_rbtree_create(_getdns_mini_ev_cmp);
if(!base->times) {
getdns_event_base_free(base);
_getdns_event_base_free(base);
return NULL;
}
base->capfd = MAX_FDS;
@ -108,15 +108,15 @@ void *getdns_event_init(time_t* time_secs, struct timeval* time_tv)
if((int)FD_SETSIZE < base->capfd)
base->capfd = (int)FD_SETSIZE;
#endif
base->fds = (struct getdns_event**)calloc((size_t)base->capfd,
sizeof(struct getdns_event*));
base->fds = (struct _getdns_event**)calloc((size_t)base->capfd,
sizeof(struct _getdns_event*));
if(!base->fds) {
getdns_event_base_free(base);
_getdns_event_base_free(base);
return NULL;
}
base->signals = (struct getdns_event**)calloc(MAX_SIG, sizeof(struct getdns_event*));
base->signals = (struct _getdns_event**)calloc(MAX_SIG, sizeof(struct _getdns_event*));
if(!base->signals) {
getdns_event_base_free(base);
_getdns_event_base_free(base);
return NULL;
}
#ifndef S_SPLINT_S
@ -127,27 +127,27 @@ void *getdns_event_init(time_t* time_secs, struct timeval* time_tv)
}
/** get version */
const char *getdns_event_get_version(void)
const char *_getdns_event_get_version(void)
{
return "mini-event-"PACKAGE_VERSION;
}
/** get polling method, select */
const char *getdns_event_get_method(void)
const char *_getdns_event_get_method(void)
{
return "select";
}
/** call timeouts handlers, and return how long to wait for next one or -1 */
void getdns_handle_timeouts(struct getdns_event_base* base, struct timeval* now,
void _getdns_handle_timeouts(struct _getdns_event_base* base, struct timeval* now,
struct timeval* wait)
{
struct getdns_event* p;
struct _getdns_event* p;
#ifndef S_SPLINT_S
wait->tv_sec = (time_t)-1;
#endif
while((getdns_rbnode_t*)(p = (struct getdns_event*)getdns_rbtree_first(base->times))
while((_getdns_rbnode_t*)(p = (struct _getdns_event*)_getdns_rbtree_first(base->times))
!=RBTREE_NULL) {
#ifndef S_SPLINT_S
if(p->ev_timeout.tv_sec > now->tv_sec ||
@ -167,7 +167,7 @@ void getdns_handle_timeouts(struct getdns_event_base* base, struct timeval* now,
}
#endif
/* event times out, remove it */
(void)getdns_rbtree_delete(base->times, p);
(void)_getdns_rbtree_delete(base->times, p);
p->ev_events &= ~EV_TIMEOUT;
fptr_ok(fptr_whitelist_event(p->ev_callback));
(*p->ev_callback)(p->ev_fd, EV_TIMEOUT, p->ev_arg);
@ -175,7 +175,7 @@ void getdns_handle_timeouts(struct getdns_event_base* base, struct timeval* now,
}
/** call select and callbacks for that */
int getdns_handle_select(struct getdns_event_base* base, struct timeval* wait)
int _getdns_handle_select(struct _getdns_event_base* base, struct timeval* wait)
{
fd_set r, w;
int ret, i;
@ -227,7 +227,7 @@ int getdns_handle_select(struct getdns_event_base* base, struct timeval* wait)
}
/** run select in a loop */
int getdns_event_base_dispatch(struct getdns_event_base* base)
int _getdns_event_base_dispatch(struct _getdns_event_base* base)
{
struct timeval wait;
if(settime(base) < 0)
@ -235,11 +235,11 @@ int getdns_event_base_dispatch(struct getdns_event_base* base)
while(!base->need_to_exit)
{
/* see if timeouts need handling */
getdns_handle_timeouts(base, base->time_tv, &wait);
_getdns_handle_timeouts(base, base->time_tv, &wait);
if(base->need_to_exit)
return 0;
/* do select */
if(getdns_handle_select(base, &wait) < 0) {
if(_getdns_handle_select(base, &wait) < 0) {
if(base->need_to_exit)
return 0;
return -1;
@ -249,7 +249,7 @@ int getdns_event_base_dispatch(struct getdns_event_base* base)
}
/** exit that loop */
int getdns_event_base_loopexit(struct getdns_event_base* base,
int _getdns_event_base_loopexit(struct _getdns_event_base* base,
struct timeval* ATTR_UNUSED(tv))
{
base->need_to_exit = 1;
@ -257,7 +257,7 @@ int getdns_event_base_loopexit(struct getdns_event_base* base,
}
/* free event base, free events yourself */
void getdns_event_base_free(struct getdns_event_base* base)
void _getdns_event_base_free(struct _getdns_event_base* base)
{
if(!base)
return;
@ -271,7 +271,7 @@ void getdns_event_base_free(struct getdns_event_base* base)
}
/** set content of event */
void getdns_event_set(struct getdns_event* ev, int fd, short bits,
void _getdns_event_set(struct _getdns_event* ev, int fd, short bits,
void (*cb)(int, short, void *), void* arg)
{
ev->node.key = ev;
@ -284,18 +284,18 @@ void getdns_event_set(struct getdns_event* ev, int fd, short bits,
}
/* add event to a base */
int getdns_event_base_set(struct getdns_event_base* base, struct getdns_event* ev)
int _getdns_event_base_set(struct _getdns_event_base* base, struct _getdns_event* ev)
{
ev->ev_base = base;
ev->added = 0;
return 0;
}
/* add event to make it active, you may not change it with getdns_event_set anymore */
int getdns_event_add(struct getdns_event* ev, struct timeval* tv)
/* add event to make it active, you may not change it with _getdns_event_set anymore */
int _getdns_event_add(struct _getdns_event* ev, struct timeval* tv)
{
if(ev->added)
getdns_event_del(ev);
_getdns_event_del(ev);
if(ev->ev_fd != -1 && ev->ev_fd >= ev->ev_base->capfd)
return -1;
if( (ev->ev_events&(EV_READ|EV_WRITE)) && ev->ev_fd != -1) {
@ -321,19 +321,19 @@ int getdns_event_add(struct getdns_event* ev, struct timeval* tv)
ev->ev_timeout.tv_sec++;
}
#endif
(void)getdns_rbtree_insert(ev->ev_base->times, &ev->node);
(void)_getdns_rbtree_insert(ev->ev_base->times, &ev->node);
}
ev->added = 1;
return 0;
}
/* remove event, you may change it again */
int getdns_event_del(struct getdns_event* ev)
int _getdns_event_del(struct _getdns_event* ev)
{
if(ev->ev_fd != -1 && ev->ev_fd >= ev->ev_base->capfd)
return -1;
if((ev->ev_events&EV_TIMEOUT))
(void)getdns_rbtree_delete(ev->ev_base->times, &ev->node);
(void)_getdns_rbtree_delete(ev->ev_base->times, &ev->node);
if((ev->ev_events&(EV_READ|EV_WRITE)) && ev->ev_fd != -1) {
ev->ev_base->fds[ev->ev_fd] = NULL;
FD_CLR(FD_SET_T ev->ev_fd, &ev->ev_base->reads);
@ -346,11 +346,11 @@ int getdns_event_del(struct getdns_event* ev)
}
/** which base gets to handle signals */
static struct getdns_event_base* signal_base = NULL;
static struct _getdns_event_base* signal_base = NULL;
/** signal handler */
static RETSIGTYPE sigh(int sig)
{
struct getdns_event* ev;
struct _getdns_event* ev;
if(!signal_base || sig < 0 || sig >= MAX_SIG)
return;
ev = signal_base->signals[sig];
@ -361,7 +361,7 @@ static RETSIGTYPE sigh(int sig)
}
/** install signal handler */
int getdns_signal_add(struct getdns_event* ev, struct timeval* ATTR_UNUSED(tv))
int _getdns_signal_add(struct _getdns_event* ev, struct timeval* ATTR_UNUSED(tv))
{
if(ev->ev_fd == -1 || ev->ev_fd >= MAX_SIG)
return -1;
@ -375,7 +375,7 @@ int getdns_signal_add(struct getdns_event* ev, struct timeval* ATTR_UNUSED(tv))
}
/** remove signal handler */
int getdns_signal_del(struct getdns_event* ev)
int _getdns_signal_del(struct _getdns_event* ev)
{
if(ev->ev_fd == -1 || ev->ev_fd >= MAX_SIG)
return -1;
@ -386,7 +386,7 @@ int getdns_signal_del(struct getdns_event* ev)
#else /* USE_MINI_EVENT */
#ifndef USE_WINSOCK
int getdns_mini_ev_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
int _getdns_mini_ev_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
{
return 0;
}

View File

@ -79,12 +79,12 @@
#define MAX_SIG 32
/** event base */
struct getdns_event_base
struct _getdns_event_base
{
/** sorted by timeout (absolute), ptr */
getdns_rbtree_t* times;
_getdns_rbtree_t* times;
/** array of 0 - maxfd of ptr to event for it */
struct getdns_event** fds;
struct _getdns_event** fds;
/** max fd in use */
int maxfd;
/** capacity - size of the fds array */
@ -100,7 +100,7 @@ struct getdns_event_base
/** ready plus newly added events. */
content;
/** array of 0 - maxsig of ptr to event for it */
struct getdns_event** signals;
struct _getdns_event** signals;
/** if we need to exit */
int need_to_exit;
/** where to store time in seconds */
@ -112,14 +112,14 @@ struct getdns_event_base
/**
* Event structure. Has some of the event elements.
*/
struct getdns_event {
struct _getdns_event {
/** node in timeout rbtree */
getdns_rbnode_t node;
_getdns_rbnode_t node;
/** is event already added */
int added;
/** event base it belongs to */
struct getdns_event_base *ev_base;
struct _getdns_event_base *ev_base;
/** fd to poll or -1 for timeouts. signal number for sigs. */
int ev_fd;
/** what events this event is interested in, see EV_.. above. */
@ -135,44 +135,44 @@ struct getdns_event {
/* function prototypes (some are as they appear in event.h) */
/** create event base */
void *getdns_event_init(time_t* time_secs, struct timeval* time_tv);
void *_getdns_event_init(time_t* time_secs, struct timeval* time_tv);
/** get version */
const char *getdns_event_get_version(void);
const char *_getdns_event_get_version(void);
/** get polling method, select */
const char *getdns_event_get_method(void);
const char *_getdns_event_get_method(void);
/** run select in a loop */
int getdns_event_base_dispatch(struct getdns_event_base *);
int _getdns_event_base_dispatch(struct _getdns_event_base *);
/** exit that loop */
int getdns_event_base_loopexit(struct getdns_event_base *, struct timeval *);
int _getdns_event_base_loopexit(struct _getdns_event_base *, struct timeval *);
/** free event base. Free events yourself */
void getdns_event_base_free(struct getdns_event_base *);
void _getdns_event_base_free(struct _getdns_event_base *);
/** set content of event */
void getdns_event_set(struct getdns_event *, int, short, void (*)(int, short, void *), void *);
void _getdns_event_set(struct _getdns_event *, int, short, void (*)(int, short, void *), void *);
/** add event to a base. You *must* call this for every event. */
int getdns_event_base_set(struct getdns_event_base *, struct getdns_event *);
/** add event to make it active. You may not change it with getdns_event_set anymore */
int getdns_event_add(struct getdns_event *, struct timeval *);
int _getdns_event_base_set(struct _getdns_event_base *, struct _getdns_event *);
/** add event to make it active. You may not change it with _getdns_event_set anymore */
int _getdns_event_add(struct _getdns_event *, struct timeval *);
/** remove event. You may change it again */
int getdns_event_del(struct getdns_event *);
int _getdns_event_del(struct _getdns_event *);
/** add a timer */
#define getdns_evtimer_add(ev, tv) getdns_event_add(ev, tv)
#define _getdns_evtimer_add(ev, tv) _getdns_event_add(ev, tv)
/** remove a timer */
#define getdns_evtimer_del(ev) getdns_event_del(ev)
#define _getdns_evtimer_del(ev) _getdns_event_del(ev)
/* uses different implementation. Cannot mix fd/timeouts and signals inside
* the same struct getdns_event. create several event structs for that. */
* the same struct _getdns_event. create several event structs for that. */
/** install signal handler */
int getdns_signal_add(struct getdns_event *, struct timeval *);
int _getdns_signal_add(struct _getdns_event *, struct timeval *);
/** set signal event contents */
#define getdns_signal_set(ev, x, cb, arg) \
getdns_event_set(ev, x, EV_SIGNAL|EV_PERSIST, cb, arg)
#define _getdns_signal_set(ev, x, cb, arg) \
_getdns_event_set(ev, x, EV_SIGNAL|EV_PERSIST, cb, arg)
/** remove signal handler */
int getdns_signal_del(struct getdns_event *);
int _getdns_signal_del(struct _getdns_event *);
#endif /* USE_MINI_EVENT and not USE_WINSOCK */
/** compare events in tree, based on timevalue, ptr for uniqueness */
int getdns_mini_ev_cmp(const void* a, const void* b);
int _getdns_mini_ev_cmp(const void* a, const void* b);
#endif /* MINI_EVENT_H */

View File

@ -50,7 +50,7 @@
#define RED 1
/** the NULL node, global alloc */
getdns_rbnode_t getdns_rbtree_null_node = {
_getdns_rbnode_t _getdns_rbtree_null_node = {
RBTREE_NULL, /* Parent. */
RBTREE_NULL, /* Left. */
RBTREE_NULL, /* Right. */
@ -59,13 +59,13 @@ getdns_rbnode_t getdns_rbtree_null_node = {
};
/** rotate subtree left (to preserve redblack property) */
static void getdns_rbtree_rotate_left(getdns_rbtree_t *rbtree, getdns_rbnode_t *node);
static void _getdns_rbtree_rotate_left(_getdns_rbtree_t *rbtree, _getdns_rbnode_t *node);
/** rotate subtree right (to preserve redblack property) */
static void getdns_rbtree_rotate_right(getdns_rbtree_t *rbtree, getdns_rbnode_t *node);
static void _getdns_rbtree_rotate_right(_getdns_rbtree_t *rbtree, _getdns_rbnode_t *node);
/** Fixup node colours when insert happened */
static void getdns_rbtree_insert_fixup(getdns_rbtree_t *rbtree, getdns_rbnode_t *node);
static void _getdns_rbtree_insert_fixup(_getdns_rbtree_t *rbtree, _getdns_rbnode_t *node);
/** Fixup node colours when delete happened */
static void getdns_rbtree_delete_fixup(getdns_rbtree_t* rbtree, getdns_rbnode_t* child, getdns_rbnode_t* child_parent);
static void _getdns_rbtree_delete_fixup(_getdns_rbtree_t* rbtree, _getdns_rbnode_t* child, _getdns_rbnode_t* child_parent);
/*
* Creates a new red black tree, intializes and returns a pointer to it.
@ -73,25 +73,25 @@ static void getdns_rbtree_delete_fixup(getdns_rbtree_t* rbtree, getdns_rbnode_t*
* Return NULL on failure.
*
*/
getdns_rbtree_t *
getdns_rbtree_create (int (*cmpf)(const void *, const void *))
_getdns_rbtree_t *
_getdns_rbtree_create (int (*cmpf)(const void *, const void *))
{
getdns_rbtree_t *rbtree;
_getdns_rbtree_t *rbtree;
/* Allocate memory for it */
rbtree = (getdns_rbtree_t *) malloc(sizeof(getdns_rbtree_t));
rbtree = (_getdns_rbtree_t *) malloc(sizeof(_getdns_rbtree_t));
if (!rbtree) {
return NULL;
}
/* Initialize it */
getdns_rbtree_init(rbtree, cmpf);
_getdns_rbtree_init(rbtree, cmpf);
return rbtree;
}
void
getdns_rbtree_init(getdns_rbtree_t *rbtree, int (*cmpf)(const void *, const void *))
_getdns_rbtree_init(_getdns_rbtree_t *rbtree, int (*cmpf)(const void *, const void *))
{
/* Initialize it */
rbtree->root = RBTREE_NULL;
@ -104,9 +104,9 @@ getdns_rbtree_init(getdns_rbtree_t *rbtree, int (*cmpf)(const void *, const void
*
*/
static void
getdns_rbtree_rotate_left(getdns_rbtree_t *rbtree, getdns_rbnode_t *node)
_getdns_rbtree_rotate_left(_getdns_rbtree_t *rbtree, _getdns_rbnode_t *node)
{
getdns_rbnode_t *right = node->right;
_getdns_rbnode_t *right = node->right;
node->right = right->left;
if (right->left != RBTREE_NULL)
right->left->parent = node;
@ -131,9 +131,9 @@ getdns_rbtree_rotate_left(getdns_rbtree_t *rbtree, getdns_rbnode_t *node)
*
*/
static void
getdns_rbtree_rotate_right(getdns_rbtree_t *rbtree, getdns_rbnode_t *node)
_getdns_rbtree_rotate_right(_getdns_rbtree_t *rbtree, _getdns_rbnode_t *node)
{
getdns_rbnode_t *left = node->left;
_getdns_rbnode_t *left = node->left;
node->left = left->right;
if (left->right != RBTREE_NULL)
left->right->parent = node;
@ -154,9 +154,9 @@ getdns_rbtree_rotate_right(getdns_rbtree_t *rbtree, getdns_rbnode_t *node)
}
static void
getdns_rbtree_insert_fixup(getdns_rbtree_t *rbtree, getdns_rbnode_t *node)
_getdns_rbtree_insert_fixup(_getdns_rbtree_t *rbtree, _getdns_rbnode_t *node)
{
getdns_rbnode_t *uncle;
_getdns_rbnode_t *uncle;
/* While not at the root and need fixing... */
while (node != rbtree->root && node->parent->color == RED) {
@ -179,12 +179,12 @@ getdns_rbtree_insert_fixup(getdns_rbtree_t *rbtree, getdns_rbnode_t *node)
/* Are we the right child? */
if (node == node->parent->right) {
node = node->parent;
getdns_rbtree_rotate_left(rbtree, node);
_getdns_rbtree_rotate_left(rbtree, node);
}
/* Now we're the left child, repaint and rotate... */
node->parent->color = BLACK;
node->parent->parent->color = RED;
getdns_rbtree_rotate_right(rbtree, node->parent->parent);
_getdns_rbtree_rotate_right(rbtree, node->parent->parent);
}
} else {
uncle = node->parent->parent->left;
@ -204,12 +204,12 @@ getdns_rbtree_insert_fixup(getdns_rbtree_t *rbtree, getdns_rbnode_t *node)
/* Are we the right child? */
if (node == node->parent->left) {
node = node->parent;
getdns_rbtree_rotate_right(rbtree, node);
_getdns_rbtree_rotate_right(rbtree, node);
}
/* Now we're the right child, repaint and rotate... */
node->parent->color = BLACK;
node->parent->parent->color = RED;
getdns_rbtree_rotate_left(rbtree, node->parent->parent);
_getdns_rbtree_rotate_left(rbtree, node->parent->parent);
}
}
}
@ -223,17 +223,17 @@ getdns_rbtree_insert_fixup(getdns_rbtree_t *rbtree, getdns_rbnode_t *node)
* Returns NULL on failure or the pointer to the newly added node
* otherwise.
*/
getdns_rbnode_t *
getdns_rbtree_insert (getdns_rbtree_t *rbtree, getdns_rbnode_t *data)
_getdns_rbnode_t *
_getdns_rbtree_insert (_getdns_rbtree_t *rbtree, _getdns_rbnode_t *data)
{
/* XXX Not necessary, but keeps compiler quiet... */
int r = 0;
/* We start at the root of the tree */
getdns_rbnode_t *node = rbtree->root;
getdns_rbnode_t *parent = RBTREE_NULL;
_getdns_rbnode_t *node = rbtree->root;
_getdns_rbnode_t *parent = RBTREE_NULL;
fptr_ok(fptr_whitelist_getdns_rbtree_cmp(rbtree->cmp));
fptr_ok(fptr_whitelist__getdns_rbtree_cmp(rbtree->cmp));
/* Lets find the new parent... */
while (node != RBTREE_NULL) {
/* Compare two keys, do we have a duplicate? */
@ -267,7 +267,7 @@ getdns_rbtree_insert (getdns_rbtree_t *rbtree, getdns_rbnode_t *data)
}
/* Fix up the red-black properties... */
getdns_rbtree_insert_fixup(rbtree, data);
_getdns_rbtree_insert_fixup(rbtree, data);
return data;
}
@ -276,12 +276,12 @@ getdns_rbtree_insert (getdns_rbtree_t *rbtree, getdns_rbnode_t *data)
* Searches the red black tree, returns the data if key is found or NULL otherwise.
*
*/
getdns_rbnode_t *
getdns_rbtree_search (getdns_rbtree_t *rbtree, const void *key)
_getdns_rbnode_t *
_getdns_rbtree_search (_getdns_rbtree_t *rbtree, const void *key)
{
getdns_rbnode_t *node;
_getdns_rbnode_t *node;
if (getdns_rbtree_find_less_equal(rbtree, key, &node)) {
if (_getdns_rbtree_find_less_equal(rbtree, key, &node)) {
return node;
} else {
return NULL;
@ -295,13 +295,13 @@ static void swap_int8(uint8_t* x, uint8_t* y)
}
/** helpers for delete: swap node pointers */
static void swap_np(getdns_rbnode_t** x, getdns_rbnode_t** y)
static void swap_np(_getdns_rbnode_t** x, _getdns_rbnode_t** y)
{
getdns_rbnode_t* t = *x; *x = *y; *y = t;
_getdns_rbnode_t* t = *x; *x = *y; *y = t;
}
/** Update parent pointers of child trees of 'parent' */
static void change_parent_ptr(getdns_rbtree_t* rbtree, getdns_rbnode_t* parent, getdns_rbnode_t* old, getdns_rbnode_t* new)
static void change_parent_ptr(_getdns_rbtree_t* rbtree, _getdns_rbnode_t* parent, _getdns_rbnode_t* old, _getdns_rbnode_t* new)
{
if(parent == RBTREE_NULL)
{
@ -315,30 +315,30 @@ static void change_parent_ptr(getdns_rbtree_t* rbtree, getdns_rbnode_t* parent,
if(parent->right == old) parent->right = new;
}
/** Update parent pointer of a node 'child' */
static void change_child_ptr(getdns_rbnode_t* child, getdns_rbnode_t* old, getdns_rbnode_t* new)
static void change_child_ptr(_getdns_rbnode_t* child, _getdns_rbnode_t* old, _getdns_rbnode_t* new)
{
if(child == RBTREE_NULL) return;
log_assert(child->parent == old || child->parent == new);
if(child->parent == old) child->parent = new;
}
getdns_rbnode_t*
getdns_rbtree_delete(getdns_rbtree_t *rbtree, const void *key)
_getdns_rbnode_t*
_getdns_rbtree_delete(_getdns_rbtree_t *rbtree, const void *key)
{
getdns_rbnode_t *to_delete;
getdns_rbnode_t *child;
if((to_delete = getdns_rbtree_search(rbtree, key)) == 0) return 0;
_getdns_rbnode_t *to_delete;
_getdns_rbnode_t *child;
if((to_delete = _getdns_rbtree_search(rbtree, key)) == 0) return 0;
rbtree->count--;
/* make sure we have at most one non-leaf child */
if(to_delete->left != RBTREE_NULL && to_delete->right != RBTREE_NULL)
{
/* swap with smallest from right subtree (or largest from left) */
getdns_rbnode_t *smright = to_delete->right;
_getdns_rbnode_t *smright = to_delete->right;
while(smright->left != RBTREE_NULL)
smright = smright->left;
/* swap the smright and to_delete elements in the tree,
* but the getdns_rbnode_t is first part of user data struct
* but the _getdns_rbnode_t is first part of user data struct
* so cannot just swap the keys and data pointers. Instead
* readjust the pointers left,right,parent */
@ -390,7 +390,7 @@ getdns_rbtree_delete(getdns_rbtree_t *rbtree, const void *key)
/* change child to BLACK, removing a RED node is no problem */
if(child!=RBTREE_NULL) child->color = BLACK;
}
else getdns_rbtree_delete_fixup(rbtree, child, to_delete->parent);
else _getdns_rbtree_delete_fixup(rbtree, child, to_delete->parent);
/* unlink completely */
to_delete->parent = RBTREE_NULL;
@ -400,9 +400,9 @@ getdns_rbtree_delete(getdns_rbtree_t *rbtree, const void *key)
return to_delete;
}
static void getdns_rbtree_delete_fixup(getdns_rbtree_t* rbtree, getdns_rbnode_t* child, getdns_rbnode_t* child_parent)
static void _getdns_rbtree_delete_fixup(_getdns_rbtree_t* rbtree, _getdns_rbnode_t* child, _getdns_rbnode_t* child_parent)
{
getdns_rbnode_t* sibling;
_getdns_rbnode_t* sibling;
int go_up = 1;
/* determine sibling to the node that is one-black short */
@ -422,8 +422,8 @@ static void getdns_rbtree_delete_fixup(getdns_rbtree_t* rbtree, getdns_rbnode_t*
child_parent->color = RED;
sibling->color = BLACK;
if(child_parent->right == child)
getdns_rbtree_rotate_right(rbtree, child_parent);
else getdns_rbtree_rotate_left(rbtree, child_parent);
_getdns_rbtree_rotate_right(rbtree, child_parent);
else _getdns_rbtree_rotate_left(rbtree, child_parent);
/* new sibling after rotation */
if(child_parent->right == child) sibling = child_parent->left;
else sibling = child_parent->right;
@ -468,7 +468,7 @@ static void getdns_rbtree_delete_fixup(getdns_rbtree_t* rbtree, getdns_rbnode_t*
{
sibling->color = RED;
sibling->right->color = BLACK;
getdns_rbtree_rotate_left(rbtree, sibling);
_getdns_rbtree_rotate_left(rbtree, sibling);
/* new sibling after rotation */
if(child_parent->right == child) sibling = child_parent->left;
else sibling = child_parent->right;
@ -480,7 +480,7 @@ static void getdns_rbtree_delete_fixup(getdns_rbtree_t* rbtree, getdns_rbnode_t*
{
sibling->color = RED;
sibling->left->color = BLACK;
getdns_rbtree_rotate_right(rbtree, sibling);
_getdns_rbtree_rotate_right(rbtree, sibling);
/* new sibling after rotation */
if(child_parent->right == child) sibling = child_parent->left;
else sibling = child_parent->right;
@ -493,21 +493,21 @@ static void getdns_rbtree_delete_fixup(getdns_rbtree_t* rbtree, getdns_rbnode_t*
{
log_assert(sibling->left->color == RED);
sibling->left->color = BLACK;
getdns_rbtree_rotate_right(rbtree, child_parent);
_getdns_rbtree_rotate_right(rbtree, child_parent);
}
else
{
log_assert(sibling->right->color == RED);
sibling->right->color = BLACK;
getdns_rbtree_rotate_left(rbtree, child_parent);
_getdns_rbtree_rotate_left(rbtree, child_parent);
}
}
int
getdns_rbtree_find_less_equal(getdns_rbtree_t *rbtree, const void *key, getdns_rbnode_t **result)
_getdns_rbtree_find_less_equal(_getdns_rbtree_t *rbtree, const void *key, _getdns_rbnode_t **result)
{
int r;
getdns_rbnode_t *node;
_getdns_rbnode_t *node;
log_assert(result);
@ -515,7 +515,7 @@ getdns_rbtree_find_less_equal(getdns_rbtree_t *rbtree, const void *key, getdns_r
node = rbtree->root;
*result = NULL;
fptr_ok(fptr_whitelist_getdns_rbtree_cmp(rbtree->cmp));
fptr_ok(fptr_whitelist__getdns_rbtree_cmp(rbtree->cmp));
/* While there are children... */
while (node != RBTREE_NULL) {
@ -540,19 +540,19 @@ getdns_rbtree_find_less_equal(getdns_rbtree_t *rbtree, const void *key, getdns_r
* Finds the first element in the red black tree
*
*/
getdns_rbnode_t *
getdns_rbtree_first (getdns_rbtree_t *rbtree)
_getdns_rbnode_t *
_getdns_rbtree_first (_getdns_rbtree_t *rbtree)
{
getdns_rbnode_t *node;
_getdns_rbnode_t *node;
for (node = rbtree->root; node->left != RBTREE_NULL; node = node->left);
return node;
}
getdns_rbnode_t *
getdns_rbtree_last (getdns_rbtree_t *rbtree)
_getdns_rbnode_t *
_getdns_rbtree_last (_getdns_rbtree_t *rbtree)
{
getdns_rbnode_t *node;
_getdns_rbnode_t *node;
for (node = rbtree->root; node->right != RBTREE_NULL; node = node->right);
return node;
@ -562,10 +562,10 @@ getdns_rbtree_last (getdns_rbtree_t *rbtree)
* Returns the next node...
*
*/
getdns_rbnode_t *
getdns_rbtree_next (getdns_rbnode_t *node)
_getdns_rbnode_t *
_getdns_rbtree_next (_getdns_rbnode_t *node)
{
getdns_rbnode_t *parent;
_getdns_rbnode_t *parent;
if (node->right != RBTREE_NULL) {
/* One right, then keep on going left... */
@ -581,10 +581,10 @@ getdns_rbtree_next (getdns_rbnode_t *node)
return node;
}
getdns_rbnode_t *
getdns_rbtree_previous(getdns_rbnode_t *node)
_getdns_rbnode_t *
_getdns_rbtree_previous(_getdns_rbnode_t *node)
{
getdns_rbnode_t *parent;
_getdns_rbnode_t *parent;
if (node->left != RBTREE_NULL) {
/* One left, then keep on going right... */
@ -602,19 +602,19 @@ getdns_rbtree_previous(getdns_rbnode_t *node)
/** recursive descent traverse */
static void
getdns_traverse_post(void (*func)(getdns_rbnode_t*, void*), void* arg, getdns_rbnode_t* node)
_getdns_traverse_post(void (*func)(_getdns_rbnode_t*, void*), void* arg, _getdns_rbnode_t* node)
{
if(!node || node == RBTREE_NULL)
return;
/* recurse */
getdns_traverse_post(func, arg, node->left);
getdns_traverse_post(func, arg, node->right);
_getdns_traverse_post(func, arg, node->left);
_getdns_traverse_post(func, arg, node->right);
/* call user func */
(*func)(node, arg);
}
void
getdns_traverse_postorder(getdns_rbtree_t* tree, void (*func)(getdns_rbnode_t*, void*), void* arg)
_getdns_traverse_postorder(_getdns_rbtree_t* tree, void (*func)(_getdns_rbnode_t*, void*), void* arg)
{
getdns_traverse_post(func, arg, tree->root);
_getdns_traverse_post(func, arg, tree->root);
}

View File

@ -45,20 +45,20 @@
/**
* This structure must be the first member of the data structure in
* the rbtree. This allows easy casting between an getdns_rbnode_t and the
* the rbtree. This allows easy casting between an _getdns_rbnode_t and the
* user data (poor man's inheritance).
*/
typedef struct getdns_rbnode_t getdns_rbnode_t;
typedef struct _getdns_rbnode_t _getdns_rbnode_t;
/**
* The getdns_rbnode_t struct definition.
* The _getdns_rbnode_t struct definition.
*/
struct getdns_rbnode_t {
struct _getdns_rbnode_t {
/** parent in rbtree, RBTREE_NULL for root */
getdns_rbnode_t *parent;
_getdns_rbnode_t *parent;
/** left node (smaller items) */
getdns_rbnode_t *left;
_getdns_rbnode_t *left;
/** right node (larger items) */
getdns_rbnode_t *right;
_getdns_rbnode_t *right;
/** pointer to sorting key */
const void *key;
/** colour of this node */
@ -66,16 +66,16 @@ struct getdns_rbnode_t {
};
/** The nullpointer, points to empty node */
#define RBTREE_NULL &getdns_rbtree_null_node
#define RBTREE_NULL &_getdns_rbtree_null_node
/** the global empty node */
extern getdns_rbnode_t getdns_rbtree_null_node;
extern _getdns_rbnode_t _getdns_rbtree_null_node;
/** An entire red black tree */
typedef struct getdns_rbtree_t getdns_rbtree_t;
typedef struct _getdns_rbtree_t _getdns_rbtree_t;
/** definition for tree struct */
struct getdns_rbtree_t {
struct _getdns_rbtree_t {
/** The root of the red-black tree */
getdns_rbnode_t *root;
_getdns_rbnode_t *root;
/** The number of the nodes in the tree */
size_t count;
@ -92,14 +92,14 @@ struct getdns_rbtree_t {
* @param cmpf: compare function (like strcmp) takes pointers to two keys.
* @return: new tree, empty.
*/
getdns_rbtree_t *getdns_rbtree_create(int (*cmpf)(const void *, const void *));
_getdns_rbtree_t *_getdns_rbtree_create(int (*cmpf)(const void *, const void *));
/**
* Init a new tree (malloced by caller) with given key compare function.
* @param rbtree: uninitialised memory for new tree, returned empty.
* @param cmpf: compare function (like strcmp) takes pointers to two keys.
*/
void getdns_rbtree_init(getdns_rbtree_t *rbtree, int (*cmpf)(const void *, const void *));
void _getdns_rbtree_init(_getdns_rbtree_t *rbtree, int (*cmpf)(const void *, const void *));
/**
* Insert data into the tree.
@ -107,7 +107,7 @@ void getdns_rbtree_init(getdns_rbtree_t *rbtree, int (*cmpf)(const void *, const
* @param data: element to insert.
* @return: data ptr or NULL if key already present.
*/
getdns_rbnode_t *getdns_rbtree_insert(getdns_rbtree_t *rbtree, getdns_rbnode_t *data);
_getdns_rbnode_t *_getdns_rbtree_insert(_getdns_rbtree_t *rbtree, _getdns_rbnode_t *data);
/**
* Delete element from tree.
@ -116,7 +116,7 @@ getdns_rbnode_t *getdns_rbtree_insert(getdns_rbtree_t *rbtree, getdns_rbnode_t *
* @return: node that is now unlinked from the tree. User to delete it.
* returns 0 if node not present
*/
getdns_rbnode_t *getdns_rbtree_delete(getdns_rbtree_t *rbtree, const void *key);
_getdns_rbnode_t *_getdns_rbtree_delete(_getdns_rbtree_t *rbtree, const void *key);
/**
* Find key in tree. Returns NULL if not found.
@ -124,7 +124,7 @@ getdns_rbnode_t *getdns_rbtree_delete(getdns_rbtree_t *rbtree, const void *key);
* @param key: key that must match.
* @return: node that fits or NULL.
*/
getdns_rbnode_t *getdns_rbtree_search(getdns_rbtree_t *rbtree, const void *key);
_getdns_rbnode_t *_getdns_rbtree_search(_getdns_rbtree_t *rbtree, const void *key);
/**
* Find, but match does not have to be exact.
@ -135,45 +135,45 @@ getdns_rbnode_t *getdns_rbtree_search(getdns_rbtree_t *rbtree, const void *key);
* @return: true if exact match in result. Else result points to <= element,
* or NULL if key is smaller than the smallest key.
*/
int getdns_rbtree_find_less_equal(getdns_rbtree_t *rbtree, const void *key,
getdns_rbnode_t **result);
int _getdns_rbtree_find_less_equal(_getdns_rbtree_t *rbtree, const void *key,
_getdns_rbnode_t **result);
/**
* Returns first (smallest) node in the tree
* @param rbtree: tree
* @return: smallest element or NULL if tree empty.
*/
getdns_rbnode_t *getdns_rbtree_first(getdns_rbtree_t *rbtree);
_getdns_rbnode_t *_getdns_rbtree_first(_getdns_rbtree_t *rbtree);
/**
* Returns last (largest) node in the tree
* @param rbtree: tree
* @return: largest element or NULL if tree empty.
*/
getdns_rbnode_t *getdns_rbtree_last(getdns_rbtree_t *rbtree);
_getdns_rbnode_t *_getdns_rbtree_last(_getdns_rbtree_t *rbtree);
/**
* Returns next larger node in the tree
* @param rbtree: tree
* @return: next larger element or NULL if no larger in tree.
*/
getdns_rbnode_t *getdns_rbtree_next(getdns_rbnode_t *rbtree);
_getdns_rbnode_t *_getdns_rbtree_next(_getdns_rbnode_t *rbtree);
/**
* Returns previous smaller node in the tree
* @param rbtree: tree
* @return: previous smaller element or NULL if no previous in tree.
*/
getdns_rbnode_t *getdns_rbtree_previous(getdns_rbnode_t *rbtree);
_getdns_rbnode_t *_getdns_rbtree_previous(_getdns_rbnode_t *rbtree);
/**
* Call with node=variable of struct* with getdns_rbnode_t as first element.
* Call with node=variable of struct* with _getdns_rbnode_t as first element.
* with type is the type of a pointer to that struct.
*/
#define RBTREE_FOR(node, type, rbtree) \
for(node=(type)getdns_rbtree_first(rbtree); \
(getdns_rbnode_t*)node != RBTREE_NULL; \
node = (type)getdns_rbtree_next((getdns_rbnode_t*)node))
for(node=(type)_getdns_rbtree_first(rbtree); \
(_getdns_rbnode_t*)node != RBTREE_NULL; \
node = (type)_getdns_rbtree_next((_getdns_rbnode_t*)node))
/**
* Call function for all elements in the redblack tree, such that
@ -186,7 +186,7 @@ getdns_rbnode_t *getdns_rbtree_previous(getdns_rbnode_t *rbtree);
* The function must not alter the rbtree.
* @param arg: user argument.
*/
void getdns_traverse_postorder(getdns_rbtree_t* tree, void (*func)(getdns_rbnode_t*, void*),
void _getdns_traverse_postorder(_getdns_rbtree_t* tree, void (*func)(_getdns_rbnode_t*, void*),
void* arg);
#endif /* UTIL_RBTREE_H_ */