File rx/rx_search.c

  $Revision: 1.37 $

Radix tree (rx). rx_search.c - functions to search nodes of the tree
Status: NOT REVUED, TESTED, COMPLETE
Design and implementation by: Marek Bukowy

Included Files


Global Variable Lock

pthread_mutex_t Lock
Included from /home/shane/code/RIP/include/ca_defs.h
Visible in:  aa/aa.c
   ac/access_control.c
   ca/ca_configFns.c
   ca/ca_initFn.c
   ca/ca_sanityCheck.c
   ca/ca_sourceLoader.c
   ca/ca_values.c
   co/constants.c
   df/defs.c
   er/er.c
   er/er_arrays.c
   er/er_macro.c
   er/er_paths.c
   er/er_print.c
   ip/ip.c
   ma/bitmask.c
   mm/mm.c
   nh/nh.c
   pa/gpg.c
   pa/spawn.c
   pc/pc_commands.c
   pc/protocol_config.c
   pm/pm_serials.c
   pm/protocol_mirror.c
   pr/properties.c
   pw/protocol_whois.c
   qc/mg_getopt.c
   qc/query_command.c
   qi/query_instructions.c
   rp/rp_convert.c
   rp/rp_load.c
   rp/rp_search.c
   rp/rp_tree.c
   rp/rp_update.c
   rx/rx_node.c
   rx/rx_print.c
   rx/rx_search.c
Used in: ca_get_adminIntElement()ca/ca_configFns.c
  ca_get_adminStrElement()ca/ca_configFns.c
  ca_get_boolean()ca/ca_configFns.c
  ca_get_dirlist()ca/ca_configFns.c
  ca_get_int()ca/ca_configFns.c
  ca_get_string()ca/ca_configFns.c
  ca_set_boolean()ca/ca_configFns.c
  ca_srchandle2Intelement()ca/ca_configFns.c
  ca_srchandle2Strelement()ca/ca_configFns.c

Global Function RX_bin_search()

  builds a stack for this prefix, finds *nodes* in the stack 
  and appends *copies of the data leaves* to the LL of answers;

sorts by SQL object keys and uniq's the data
finds: 0 or 1 nodes for exact search 0 or 1 nodes for exless (0 if no less specific node found) any number (incl. 0) for {more|less}-n specific
then copies the nodes/dataleaves to the answer structs and appends them to the given LL. So, effectively, the number of answers can be anything from 0 to infinity, because objects may be duplicate even at the same node.
returns errcode.
algorithm:
builds stack[MAXBIT (==128)];
if( more/less-depth && par_a == 0)
run rx_nod_search, then
if(more spec) rx_nod_walk(maxdepth=n, append_to_LL() ); if(less spec) do { append(LL, stack[i]) } while(i-- && n--); otherwise just set LL

The routine provides _at_least_ max_count answers. It will *try* to stop after max_count as soon as possible - but it's the higher level routine that should do the final cut.
er_ret_t RX_bin_search ( rx_srch_mt search_mode, int par_a, int par_b, rx_tree_t* tree, ip_prefix_t* prefix, GList** datleaves, int max_count )
Prototyped in: /home/shane/code/RIP/include/rxroutines.h
Calls: ER_dbg_va()er/er.c
  rx_build_stack()rx/rx_search.c
  rx_nod_search()rx/rx_search.c
  UT_calloc_real(), g_list_first(), g_list_length(), g_list_nth_data(), g_list_prepend(), wr_real_clear_list()
Called by: AC_findcreate_account_l()ac/access_control.c
  AC_findcreate_acl_l()ac/access_control.c
  RP_asc_search()rp/rp_search.c
  ac_find_acl_l()ac/access_control.c
  rp_preflist_search()rp/rp_search.c

Global Function rx_build_stack()

Descends the given tree following the last prefix bit to get [past]
the node with the given prefix.
It fills up a stack of COPIES of nodes, including glue nodes.

Then it also sets the number of elements on the stack: set maxdepth to the position where a next one would be written ( = last + 1, or number of nodes pushed)
The dmodes:
RX_STK_QUERY_NOGLUE = (search exact/less spec) stop when * the current prefix length >= newprefix length * the current prefix does not match anymore * do not add glue nodes
RX_STK_QUERY_ALLNOD = as above, except that the glue and data nodes are treated equally (i.e. glue nodes are not skipped)
RX_STK_CREAT = descend until the next non-glue node past the one found in exact mode (for creation)
er_ret_t rx_build_stack ( rx_nodcpy_t stack[], int* maxdepth, rx_tree_t* tree, ip_prefix_t* newpref, rx_stk_mt dmode )
Prototyped in: /home/shane/code/RIP/include/rxroutines.h
Calls: ER_dbg_va()er/er.c
  ER_is_traced()er/er.c
  IP_addr_bit_get()ip/ip.c
  IP_addr_cmp()ip/ip.c
  IP_pref_b2a()ip/ip.c
  memcpy()
Called by: RX_bin_search()rx/rx_search.c
  rx_bin_node()rx/rx_node.c

Global Function rx_nod_search()

er_ret_t rx_nod_search ( rx_srch_mt search_mode, int par_a, int par_b, rx_tree_t* tree, ip_prefix_t* prefix, rx_nodcpy_t stack[], int stackcount, GList** nodlist, int max_count, void )
Prototyped in: /home/shane/code/RIP/include/rxroutines.h
Calls: ER_dbg_va()er/er.c
  ER_is_traced()er/er.c
  IP_addr_cmp()ip/ip.c
  IP_pref_b2a()ip/ip.c
  RX_text_srch_mode()rx/rx_print.c
  rx_nod_append()rx/rx_search.c
  rx_nod_print()rx/rx_print.c
  fprintf(), memcmp(), rx_walk_tree()
Called by: RX_bin_search()rx/rx_search.c
  rx_bin_node()rx/rx_node.c
References Functions: rx_walk_hook_adddoubles()rx/rx_search.c
  rx_walk_hook_addnode()rx/rx_search.c

Local Function asctime_r()

static char* asctime_r ( const struct tm* __tm, char* __buf )
Included from: /usr/include/time.h
Calls: __posix_asctime_r()

Local Function ctime_r()

static char* ctime_r ( const time_t* __time, char* __buf )
Included from: /usr/include/time.h
Calls: __posix_ctime_r()

Local Function getlogin_r()

static int getlogin_r ( char* __name, int __len )
Included from: /usr/include/unistd.h
Calls: __posix_getlogin_r()

Local Function readdir_r()

static int readdir_r ( DIR* __dp, struct dirent* __ent, struct dirent** __res )
Included from: /usr/include/dirent.h
Calls: __posix_readdir_r()

Local Function rx_nod_append()

   helper for the nod_search routine: 

allocate a new node copy struct, copy the struct and add to nodlist
static er_ret_t rx_nod_append ( GList** nodlist, rx_nodcpy_t* element )
Calls: UT_malloc_real(), g_list_prepend(), memcpy()
Called by: rx_nod_search()rx/rx_search.c
  rx_walk_hook_adddoubles()rx/rx_search.c
  rx_walk_hook_addnode()rx/rx_search.c

Local Function rx_walk_hook_adddoubles()

  helper for DBLS lookup in rx_nod_search 

adds a node to the list of answers.
static er_ret_t rx_walk_hook_adddoubles ( rx_node_t* node, int level, int nodecounter, void* userptr )
Calls: ER_dbg_va()er/er.c
  ER_is_traced()er/er.c
  rx_nod_append()rx/rx_search.c
  rx_nod_print()rx/rx_print.c
  g_list_length()
Used in: rx_nod_search()rx/rx_search.c

Local Function rx_walk_hook_addnode()

  helper for MORE specific lookup in rx_nod_search 

adds a node to the list of answers.
static er_ret_t rx_walk_hook_addnode ( rx_node_t* node, int level, int nodecounter, void* userptr )
Calls: rx_nod_append()rx/rx_search.c
  memset()
Used in: rx_nod_search()rx/rx_search.c

Local Function sigwait()

static int sigwait ( const sigset_t* __setp, int* __signo )
Included from: /usr/include/signal.h
Calls: __posix_sigwait()

Local Function ttyname_r()

static int ttyname_r ( int __fildes, char* __buf, size_t __size )
Included from: /usr/include/unistd.h
Calls: __posix_ttyname_r()