本文整理汇总了C++中rbtree_finddata函数的典型用法代码示例。如果您正苦于以下问题:C++ rbtree_finddata函数的具体用法?C++ rbtree_finddata怎么用?C++ rbtree_finddata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rbtree_finddata函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: rbtree_finddata
static indexed_modcallable *lookup_by_index(rbtree_t *components,
int comp, int idx)
{
indexed_modcallable myc;
myc.comp = comp;
myc.idx = idx;
return rbtree_finddata(components, &myc);
}
开发者ID:claude191,项目名称:freeradius-server,代码行数:10,代码来源:modules.c
示例2: strlcpy
/** Find a map processor by name
*
* @param[in] name of map processor.
* @return
* - #map_proc matching name.
* - NULL if none was found.
*/
map_proc_t *map_proc_find(char const *name)
{
map_proc_t find;
if (!map_proc_root) return NULL;
strlcpy(find.name, name, sizeof(find.name));
find.length = strlen(find.name);
return rbtree_finddata(map_proc_root, &find);
}
开发者ID:K1ngR1chard,项目名称:freeradius-server,代码行数:18,代码来源:map_proc.c
示例3: mod_map_proc
/** Perform a search and map the result of the search to server attributes
*
* @param[in] mod_inst #rlm_csv_t
* @param[in] proc_inst mapping map entries to field numbers.
* @param[in,out] request The current request.
* @param[in] key key to look for
* @param[in] maps Head of the map list.
* @return
* - #RLM_MODULE_NOOP no rows were returned.
* - #RLM_MODULE_UPDATED if one or more #VALUE_PAIR were added to the #REQUEST.
* - #RLM_MODULE_FAIL if an error occurred.
*/
static rlm_rcode_t mod_map_proc(void *mod_inst, UNUSED void *proc_inst, REQUEST *request,
char const *key, vp_map_t const *maps)
{
rlm_csv_t *inst = mod_inst;
rlm_csv_entry_t *e, my_entry;
vp_map_t const *map;
my_entry.key = key;
e = rbtree_finddata(inst->tree, &my_entry);
if (!e) return RLM_MODULE_NOOP;
RINDENT();
for (map = maps;
map != NULL;
map = map->next) {
int field;
char *field_name;
/*
* Avoid memory allocations if possible.
*/
if (map->rhs->type != TMPL_TYPE_LITERAL) {
if (tmpl_aexpand(request, &field_name, request, map->rhs, NULL, NULL) < 0) {
RDEBUG("Failed expanding RHS at %s", map->lhs->name);
return RLM_MODULE_FAIL;
}
} else {
memcpy(&field_name, &map->rhs->name, sizeof(field_name)); /* const */
}
field = fieldname2offset(inst, field_name);
if (field_name != map->rhs->name) talloc_free(field_name);
if (field < 0) {
RDEBUG("No such field name %s", map->rhs->name);
return RLM_MODULE_FAIL;
}
/*
* Pass the raw data to the callback, which will
* create the VP and add it to the map.
*/
if (map_to_request(request, map, csv_map_getvalue, e->data[field]) < 0) {
return RLM_MODULE_FAIL;
}
}
return RLM_MODULE_UPDATED;
}
开发者ID:K1ngR1chard,项目名称:freeradius-server,代码行数:63,代码来源:rlm_csv.c
示例4: fr_network_socket_delete
/** Delete a socket from a network. MUST be called only by the listener itself!.
*
* @param nr the network
* @param listen Functions and context.
*/
int fr_network_socket_delete(fr_network_t *nr, fr_listen_t const *listen)
{
fr_network_socket_t *s, my_socket;
my_socket.listen = listen;
s = rbtree_finddata(nr->sockets, &my_socket);
if (!s) {
return -1;
}
fr_network_socket_dead(nr, s);
return 0;
}
开发者ID:bt4,项目名称:freeradius-server,代码行数:19,代码来源:network.c
示例5: _map_proc_unregister
/** Unregister a map processor
*
* @param[in] proc to unregister.
*/
static int _map_proc_unregister(map_proc_t *proc)
{
map_proc_t find;
map_proc_t *found;
strlcpy(find.name, proc->name, sizeof(find.name));
find.length = strlen(find.name);
found = rbtree_finddata(map_proc_root, &find);
if (!found) return 0;
rbtree_deletebydata(map_proc_root, found);
return 0;
}
开发者ID:K1ngR1chard,项目名称:freeradius-server,代码行数:19,代码来源:map_proc.c
示例6: fr_network_listen_read
/** Signal the network to read from a listener
*
* @param nr the network
* @param listen the listener to read from
*/
void fr_network_listen_read(fr_network_t *nr, fr_listen_t const *listen)
{
fr_network_socket_t my_socket, *s;
(void) talloc_get_type_abort(nr, fr_network_t);
(void) talloc_get_type_abort_const(listen, fr_listen_t);
my_socket.listen = listen;
s = rbtree_finddata(nr->sockets, &my_socket);
if (!s) return;
/*
* Go read the socket.
*/
fr_network_read(nr->el, s->fd, 0, s);
}
开发者ID:bt4,项目名称:freeradius-server,代码行数:21,代码来源:network.c
示例7: xlat_unregister
/** Unregister an xlat function
*
* We can only have one function to call per name, so the passing of "func"
* here is extraneous.
*
* @param[in] name xlat to unregister.
* @param[in] func unused.
* @param[in] instance data.
*/
void xlat_unregister(char const *name, UNUSED RAD_XLAT_FUNC func, void *instance)
{
xlat_t *c;
xlat_t my_xlat;
if (!name) return;
strlcpy(my_xlat.name, name, sizeof(my_xlat.name));
my_xlat.length = strlen(my_xlat.name);
c = rbtree_finddata(xlat_root, &my_xlat);
if (!c) return;
if (c->instance != instance) return;
rbtree_deletebydata(xlat_root, c);
}
开发者ID:dleo,项目名称:freeradius-server,代码行数:26,代码来源:xlat.c
示例8: fr_heap_peek
/*
* Find a cached entry.
*/
static rlm_cache_entry_t *cache_find(rlm_cache_t *inst, REQUEST *request,
char const *key)
{
int ttl;
rlm_cache_entry_t *c, my_c;
VALUE_PAIR *vp;
/*
* Look at the expiry heap.
*/
c = fr_heap_peek(inst->heap);
if (!c) {
rad_assert(rbtree_num_elements(inst->cache) == 0);
return NULL;
}
/*
* If it's time to expire an old entry, do so now.
*/
if (c->expires < request->timestamp) {
fr_heap_extract(inst->heap, c);
rbtree_deletebydata(inst->cache, c);
}
/*
* Is there an entry for this key?
*/
my_c.key = key;
c = rbtree_finddata(inst->cache, &my_c);
if (!c) return NULL;
/*
* Yes, but it expired, OR the "forget all" epoch has
* passed. Delete it, and pretend it doesn't exist.
*/
if ((c->expires < request->timestamp) ||
(c->created < inst->epoch)) {
delete:
RDEBUG("Entry has expired, removing");
fr_heap_extract(inst->heap, c);
rbtree_deletebydata(inst->cache, c);
return NULL;
}
开发者ID:capone1992,项目名称:freeradius-server,代码行数:48,代码来源:rlm_cache.c
示例9: rbtree_finddata
/*
* Find a client in the RADCLIENTS list by number.
* This is a support function for the statistics code.
*/
RADCLIENT *client_findbynumber(RADCLIENT_LIST const *clients, int number)
{
if (!clients) clients = root_clients;
if (!clients) return NULL;
if (number >= tree_num_max) return NULL;
if (tree_num) {
RADCLIENT myclient;
myclient.number = number;
return rbtree_finddata(tree_num, &myclient);
}
return NULL;
}
开发者ID:arr2036,项目名称:freeradius-server,代码行数:22,代码来源:client.c
示例10: strlcpy
/*
* find the appropriate registered xlat function.
*/
static xlat_t *xlat_find(const char *module)
{
xlat_t my_xlat;
/*
* Look for dictionary attributes first.
*/
if ((dict_attrbyname(module) != NULL) ||
(strchr(module, '[') != NULL) ||
(strchr(module, '#') != NULL)) {
module = "request";
}
strlcpy(my_xlat.module, module, sizeof(my_xlat.module));
my_xlat.length = strlen(my_xlat.module);
return rbtree_finddata(xlat_root, &my_xlat);
}
开发者ID:HAJC,项目名称:freeradius-server,代码行数:21,代码来源:xlat.c
示例11: xlat_unregister
/**
* @brief Unregister an xlat function.
*
* We can only have one function to call per name, so the
* passing of "func" here is extraneous.
*
* @param module xlat to unregister
* @param func Unused
* @return Void.
*/
void xlat_unregister(const char *module, RAD_XLAT_FUNC func, void *instance)
{
xlat_t *c;
xlat_t my_xlat;
func = func; /* -Wunused */
if (!module) return;
strlcpy(my_xlat.module, module, sizeof(my_xlat.module));
my_xlat.length = strlen(my_xlat.module);
c = rbtree_finddata(xlat_root, &my_xlat);
if (!c) return;
if (c->instance != instance) return;
rbtree_deletebydata(xlat_root, c);
}
开发者ID:rssh,项目名称:freeradius-server,代码行数:29,代码来源:xlat.c
示例12: rbtree_finddata
/** Retrieve module/thread specific instance data for a module
*
* @param[in] mi to find thread specific data for.
* @return
* - Thread specific instance data on success.
* - NULL if module has no thread instance data.
*/
module_thread_instance_t *module_thread_instance_find(module_instance_t *mi)
{
rbtree_t *tree = module_thread_inst_tree;
module_thread_instance_t find = { .mod_inst = mi->dl_inst->data };
return rbtree_finddata(tree, &find);
}
/** Retrieve module/thread specific instance data for a module
*
* @param[in] mod_inst Module specific instance to find thread_data for.
* @return
* - Thread specific instance data on success.
* - NULL if module has no thread instance data.
*/
void *module_thread_instance_by_data(void *mod_inst)
{
rbtree_t *tree = module_thread_inst_tree;
module_thread_instance_t find = { .mod_inst = mod_inst }, *found;
开发者ID:alagoutte,项目名称:freeradius-server,代码行数:26,代码来源:module.c
示例13: cmd_stats_socket
static int cmd_stats_socket(FILE *fp, FILE *fp_err, void *ctx, fr_cmd_info_t const *info)
{
fr_network_t const *nr = ctx;
fr_network_socket_t *s, my_s;
my_s.number = info->box[0]->vb_uint32;
s = rbtree_finddata(nr->sockets_by_num, &my_s);
if (!s) {
fprintf(fp_err, "No such socket number '%s'.\n", info->argv[0]);
return -1;
}
fprintf(fp, "count.in\t%" PRIu64 "\n", s->stats.in);
fprintf(fp, "count.out\t%" PRIu64 "\n", s->stats.out);
fprintf(fp, "count.dup\t%" PRIu64 "\n", s->stats.dup);
fprintf(fp, "count.dropped\t%" PRIu64 "\n", s->stats.dropped);
return 0;
}
开发者ID:bt4,项目名称:freeradius-server,代码行数:20,代码来源:network.c
示例14: policy_evaluate_name
/*
* Evaluate a policy, keyed by name.
*/
static int policy_evaluate_name(policy_state_t *state, const char *name)
{
int rcode;
const policy_item_t *this;
policy_named_t mypolicy, *policy;
mypolicy.name = name;
policy = rbtree_finddata(state->inst->policies, &mypolicy);
if (!policy) return RLM_MODULE_FAIL;
DEBUG2("rlm_policy: Evaluating policy %s", name);
rad_assert(policy->item.type != POLICY_TYPE_BAD);
rad_assert(policy->item.type < POLICY_TYPE_NUM_TYPES);
rcode = policy_stack_push(state, policy->policy);
if (!rcode) {
return RLM_MODULE_FAIL;
}
/*
* FIXME: Look for magic keywords like "return",
* where the packet gets accepted/rejected/whatever
*/
while (policy_stack_pop(state, &this)) {
rad_assert(this != NULL);
rad_assert(this->type != POLICY_TYPE_BAD);
rad_assert(this->type < POLICY_TYPE_NUM_TYPES);
debug_evaluate("Evaluating at line %d\n",
this->lineno);
rcode = (*evaluate_functions[this->type])(state,
this);
if (!rcode) {
return RLM_MODULE_FAIL;
}
} /* loop until the stack is empty */
return state->rcode;
}
开发者ID:joyphone,项目名称:freeradius-server,代码行数:43,代码来源:evaluate.c
示例15: switch
/*
* Find a client in the RADCLIENTS list.
*/
RADCLIENT *client_find(RADCLIENT_LIST const *clients, fr_ipaddr_t const *ipaddr, int proto)
{
int32_t i, max_prefix;
RADCLIENT myclient;
if (!clients) clients = root_clients;
if (!clients || !ipaddr) return NULL;
switch (ipaddr->af) {
case AF_INET:
max_prefix = 32;
break;
case AF_INET6:
max_prefix = 128;
break;
default :
return NULL;
}
for (i = max_prefix; i >= (int32_t) clients->min_prefix; i--) {
void *data;
myclient.ipaddr = *ipaddr;
myclient.proto = proto;
fr_ipaddr_mask(&myclient.ipaddr, i);
if (!clients->trees[i]) continue;
data = rbtree_finddata(clients->trees[i], &myclient);
if (data) return data;
}
return NULL;
}
开发者ID:arr2036,项目名称:freeradius-server,代码行数:40,代码来源:client.c
示例16: got_packet
static void got_packet(UNUSED uint8_t *args, const struct pcap_pkthdr *header, const uint8_t *data)
{
static int count = 1; /* Packets seen */
/*
* Define pointers for packet's attributes
*/
const struct ip_header *ip; /* The IP header */
const struct udp_header *udp; /* The UDP header */
const uint8_t *payload; /* Packet payload */
/*
* And define the size of the structures we're using
*/
int size_ethernet = sizeof(struct ethernet_header);
int size_ip = sizeof(struct ip_header);
int size_udp = sizeof(struct udp_header);
/*
* For FreeRADIUS
*/
RADIUS_PACKET *packet, *original;
struct timeval elapsed;
/*
* Define our packet's attributes
*/
if ((data[0] == 2) && (data[1] == 0) &&
(data[2] == 0) && (data[3] == 0)) {
ip = (const struct ip_header*) (data + 4);
} else {
ip = (const struct ip_header*)(data + size_ethernet);
}
udp = (const struct udp_header*)(((const uint8_t *) ip) + size_ip);
payload = (const uint8_t *)(((const uint8_t *) udp) + size_udp);
packet = rad_alloc(NULL, 0);
if (!packet) {
fprintf(stderr, "Out of memory\n");
return;
}
packet->src_ipaddr.af = AF_INET;
packet->src_ipaddr.ipaddr.ip4addr.s_addr = ip->ip_src.s_addr;
packet->src_port = ntohs(udp->udp_sport);
packet->dst_ipaddr.af = AF_INET;
packet->dst_ipaddr.ipaddr.ip4addr.s_addr = ip->ip_dst.s_addr;
packet->dst_port = ntohs(udp->udp_dport);
memcpy(&packet->data, &payload, sizeof(packet->data));
packet->data_len = header->len - (payload - data);
if (!rad_packet_ok(packet, 0)) {
DEBUG(log_dst, "Packet: %s\n", fr_strerror());
DEBUG(log_dst, " From %s:%d\n", inet_ntoa(ip->ip_src), ntohs(udp->udp_sport));
DEBUG(log_dst, " To: %s:%d\n", inet_ntoa(ip->ip_dst), ntohs(udp->udp_dport));
DEBUG(log_dst, " Type: %s\n", fr_packet_codes[packet->code]);
rad_free(&packet);
return;
}
switch (packet->code) {
case PW_COA_REQUEST:
/* we need a 16 x 0 byte vector for decrypting encrypted VSAs */
original = nullpacket;
break;
case PW_AUTHENTICATION_ACK:
/* look for a matching request and use it for decoding */
original = rbtree_finddata(request_tree, packet);
break;
case PW_AUTHENTICATION_REQUEST:
/* save the request for later matching */
original = rad_alloc_reply(NULL, packet);
if (original) { /* just ignore allocation failures */
rbtree_deletebydata(request_tree, original);
rbtree_insert(request_tree, original);
}
/* fallthrough */
default:
/* don't attempt to decode any encrypted attributes */
original = NULL;
}
/*
* Decode the data without bothering to check the signatures.
*/
if (rad_decode(packet, original, radius_secret) != 0) {
rad_free(&packet);
fr_perror("decode");
return;
}
/*
* We've seen a successfull reply to this, so delete it now
//.........这里部分代码省略.........
开发者ID:jcartermeru,项目名称:freeradius-server,代码行数:101,代码来源:radsniff.c
示例17: strlcpy
/*
* Find a module on disk or in memory, and link to it.
*/
static module_entry_t *linkto_module(const char *module_name,
CONF_SECTION *cs)
{
module_entry_t myentry;
module_entry_t *node;
lt_dlhandle handle = NULL;
char module_struct[256];
char *p;
const module_t *module;
strlcpy(myentry.name, module_name, sizeof(myentry.name));
node = rbtree_finddata(module_tree, &myentry);
if (node) return node;
/*
* Link to the module's rlm_FOO{} module structure.
*
* The module_name variable has the version number
* embedded in it, and we don't want that here.
*/
strcpy(module_struct, module_name);
p = strrchr(module_struct, '-');
if (p) *p = '\0';
#if !defined(WITH_LIBLTDL) && defined(HAVE_DLFCN_H) && defined(RTLD_SELF)
module = lt_dlsym(RTLD_SELF, module_struct);
if (module) goto open_self;
#endif
/*
* Keep the handle around so we can dlclose() it.
*/
handle = fr_dlopenext(module_name);
if (handle == NULL) {
cf_log_err(cf_sectiontoitem(cs),
"Failed to link to module '%s': %s\n",
module_name, lt_dlerror());
return NULL;
}
DEBUG3(" (Loaded %s, checking if it's valid)", module_name);
/*
* libltld MAY core here, if the handle it gives us contains
* garbage data.
*/
module = lt_dlsym(handle, module_struct);
if (!module) {
cf_log_err(cf_sectiontoitem(cs),
"Failed linking to %s structure: %s\n",
module_name, lt_dlerror());
lt_dlclose(handle);
return NULL;
}
#if !defined(WIT_LIBLTDL) && defined (HAVE_DLFCN_H) && defined(RTLD_SELF)
open_self:
#endif
/*
* Before doing anything else, check if it's sane.
*/
if (module->magic != RLM_MODULE_MAGIC_NUMBER) {
lt_dlclose(handle);
cf_log_err(cf_sectiontoitem(cs),
"Invalid version in module '%s'",
module_name);
return NULL;
}
/* make room for the module type */
node = rad_malloc(sizeof(*node));
memset(node, 0, sizeof(*node));
strlcpy(node->name, module_name, sizeof(node->name));
node->module = module;
node->handle = handle;
cf_log_module(cs, "Linked to module %s", module_name);
/*
* Add the module as "rlm_foo-version" to the configuration
* section.
*/
if (!rbtree_insert(module_tree, node)) {
radlog(L_ERR, "Failed to cache module %s", module_name);
lt_dlclose(handle);
free(node);
return NULL;
}
return node;
}
开发者ID:candlerb,项目名称:freeradius-server,代码行数:95,代码来源:modules.c
示例18: rs_process_packet
//.........这里部分代码省略.........
current->dst_ipaddr.af = AF_INET6;
memcpy(¤t->dst_ipaddr.ipaddr.ip6addr.s6_addr, &ip6->ip_dst.s6_addr,
sizeof(current->dst_ipaddr.ipaddr.ip6addr.s6_addr));
}
current->src_port = ntohs(udp->udp_sport);
current->dst_port = ntohs(udp->udp_dport);
if (!rad_packet_ok(current, 0, &reason)) {
DEBUG("(%i) ** %s **", count, fr_strerror());
DEBUG("(%i) %s Id %i %s:%s:%d -> %s:%d\t+%u.%03u", count,
fr_packet_codes[current->code], current->id,
event->in->name,
fr_inet_ntop(current->src_ipaddr.af, ¤t->src_ipaddr.ipaddr), current->src_port,
fr_inet_ntop(current->dst_ipaddr.af, ¤t->dst_ipaddr.ipaddr), current->dst_port,
(unsigned int) elapsed.tv_sec, ((unsigned int) elapsed.tv_usec / 1000));
rad_free(¤t);
return;
}
switch (current->code) {
case PW_CODE_COA_REQUEST:
/* we need a 16 x 0 byte vector for decrypting encrypted VSAs */
original = nullpacket;
break;
case PW_CODE_ACCOUNTING_RESPONSE:
case PW_CODE_AUTHENTICATION_REJECT:
case PW_CODE_AUTHENTICATION_ACK:
response = true;
/* look for a matching request and use it for decoding */
original = rbtree_finddata(request_tree, current);
break;
case PW_CODE_ACCOUNTING_REQUEST:
case PW_CODE_AUTHENTICATION_REQUEST:
/* save the request for later matching */
original = rad_alloc_reply(event->conf, current);
original->timestamp = header->ts;
if (original) { /* just ignore allocation failures */
rbtree_deletebydata(request_tree, original);
rbtree_insert(request_tree, original);
}
/* fallthrough */
default:
/* don't attempt to decode any encrypted attributes */
original = NULL;
}
/*
* Decode the data without bothering to check the signatures.
*/
if (rad_decode(current, original, event->conf->radius_secret) != 0) {
rad_free(¤t);
fr_perror("decode");
return;
}
if (filter_vps && rs_filter_packet(current)) {
rad_free(¤t);
DEBUG("Packet number %d doesn't match", count++);
return;
}
if (event->out) {
开发者ID:liuyanning,项目名称:freeradius-server,代码行数:67,代码来源:radsniff.c
示例19: check_handler
static void check_handler(void *data)
{
int do_warning = FALSE;
uint8_t state[8];
check_handler_t *check = data;
if (!check) return;
if (!check->inst || !check->handler) {
free(check);
return;
}
if (!check->inst->handler_tree) goto done;
PTHREAD_MUTEX_LOCK(&(check->inst->handler_mutex));
if (!rbtree_finddata(check->inst->handler_tree, check->handler)) {
goto done;
}
/*
* The session has continued *after* this packet.
* Don't do a warning.
*/
if (check->handler->trips > check->trips) {
goto done;
}
/*
* No TLS means no warnings.
*/
if (!check->handler->tls) goto done;
/*
* If we're being deleted early, it's likely because we
* received a transmit from the client that re-uses the
* same RADIUS Id, which forces the current packet to be
* deleted. In that case, ignore the error.
*/
if (time(NULL) < (check->handler->timestamp + 3)) goto done;
if (!check->handler->finished) {
do_warning = TRUE;
memcpy(state, check->handler->state, sizeof(state));
}
done:
PTHREAD_MUTEX_UNLOCK(&(check->inst->handler_mutex));
free(check);
if (do_warning) {
DEBUGW("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
DEBUGW("!! EAP session with state 0x%02x%02x%02x%02x%02x%02x%02x%02x did not finish! !!",
state[0], state[1],
state[2], state[3],
state[4], state[5],
state[6], state[7]);
DEBUGW("!! Please read http://wiki.freeradius.org/guide/Certificate_Compatibility !!");
DEBUGW("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}
开发者ID:jcartermeru,项目名称:freeradius-server,代码行数:62,代码来源:mem.c
示例20: xlat_register
/** Register an xlat function.
*
* @param[in] name xlat name.
* @param[in] func xlat function to be called.
* @param[in] escape function to sanitize any sub expansions passed to the xlat function.
* @param[in] instance of module that's registering the xlat function.
* @return 0 on success, -1 on failure
*/
int xlat_register(char const *name, RAD_XLAT_FUNC func, RADIUS_ESCAPE_STRING escape, void *instance)
{
xlat_t *c;
xlat_t my_xlat;
rbnode_t *node;
if (!name || !*name) {
DEBUG("xlat_register: Invalid xlat name");
return -1;
}
/*
* First time around, build up the tree...
*
* FIXME: This code should be hoisted out of this function,
* and into a global "initialization". But it isn't critical...
*/
if (!xlat_root) {
#ifdef WITH_UNLANG
int i;
#endif
xlat_root = rbtree_create(xlat_cmp, NULL, 0);
if (!xlat_root) {
DEBUG("xlat_register: Failed to create tree");
return -1;
}
#ifdef WITH_UNLANG
for (i = 0; xlat_foreach_names[i] != NULL; i++) {
xlat_register(xlat_foreach_names[i],
xlat_foreach, NULL, &xlat_inst[i]);
c = xlat_find(xlat_foreach_names[i]);
rad_assert(c != NULL);
c->internal = true;
}
#endif
#define XLAT_REGISTER(_x) xlat_register(STRINGIFY(_x), xlat_ ## _x, NULL, NULL); \
c = xlat_find(STRINGIFY(_x)); \
rad_assert(c != NULL); \
c->internal = true
XLAT_REGISTER(integer);
XLAT_REGISTER(strlen);
XLAT_REGISTER(length);
XLAT_REGISTER(hex);
XLAT_REGISTER(string);
XLAT_REGISTER(xlat);
XLAT_REGISTER(module);
XLAT_REGISTER(debug_attr);
xlat_register("debug", xlat_debug, NULL, &xlat_inst[0]);
c = xlat_find("debug");
rad_assert(c != NULL);
c->internal = true;
}
/*
* If it already exists, replace the instance.
*/
strlcpy(my_xlat.name, name, sizeof(my_xlat.name));
my_xlat.length = strlen(my_xlat.name);
c = rbtree_finddata(xlat_root, &my_xlat);
if (c) {
if (c->internal) {
DEBUG("xlat_register: Cannot re-define internal xlat");
return -1;
}
c->func = func;
c->escape = escape;
c->instance = instance;
return 0;
}
/*
* Doesn't exist. Create it.
*/
c = talloc_zero(xlat_root, xlat_t);
c->func = func;
c->escape = escape;
strlcpy(c->name, name, sizeof(c->name));
c->length = strlen(c->name);
c->instance = instance;
node = rbtree_insert_node(xlat_root, c);
if (!node) {
talloc_free(c);
return -1;
}
//.........这里部分代码省略.........
开发者ID:dleo,项目名称:freeradius-server,代码行数:101,代码来源:xlat.c
注:本文中的rbtree_finddata函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论