1 | /*************************************** 2 | $Revision: 1.10 $ 3 | 4 | Radix tree (rx). rx_global.h - header file with definition of 5 | global vars for radix 6 | 7 | Status: NOT REVUED, TESTED, INCOMPLETE 8 | 9 | Design and implementation by: Marek Bukowy 10 | 11 | ******************/ /****************** 12 | Copyright (c) 1999,2000,2001,2002 RIPE NCC 13 | 14 | All Rights Reserved 15 | 16 | Permission to use, copy, modify, and distribute this software and its 17 | documentation for any purpose and without fee is hereby granted, 18 | provided that the above copyright notice appear in all copies and that 19 | both that copyright notice and this permission notice appear in 20 | supporting documentation, and that the name of the author not be 21 | used in advertising or publicity pertaining to distribution of the 22 | software without specific, written prior permission. 23 | 24 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 25 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL 26 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 27 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 28 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 29 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 30 | ***************************************/ 31 | 32 | #ifndef RP_H 33 | #define RP_H 34 | 35 | #include <stddef.h> /* definition of NULL */ 36 | #include <glib.h> 37 | #include <pthread.h> 38 | /*#include <DF_attribute_enum.def> / * attribute codes */ 39 | 40 | #include <defs.h> 41 | 42 | #include <iproutines.h> 43 | #include <erroutines.h> 44 | #include <rxroutines.h> 45 | #include <mysql_driver.h> 46 | 47 | 48 | #include "ca_defs.h" 49 | #include <thread.h> 50 | 51 | 52 | typedef struct { 53 | rx_fam_t fam; 54 | ip_space_t space; 55 | union { 56 | ip_prefix_t rt; 57 | ip_range_t in; 58 | } u; 59 | } rp_uni_t; 60 | 61 | 62 | 63 | typedef ca_dbSource_t * rp_regid_t; 64 | typedef A_Type_t rp_attr_t; 65 | 66 | 67 | typedef struct { 68 | rp_attr_t type; 69 | rp_uni_t uni; 70 | sql_key_t key; 71 | union { 72 | const char *origin; 73 | const char *domain; 74 | } d; 75 | } rp_upd_pack_t; 76 | 77 | #ifdef RP_IMPL 78 | #define EXTDEF(a,b) a = b; 79 | /* forest read write lock */ 80 | rw_lock_t rx_forest_rwlock = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 }; 81 | #else 82 | #define EXTDEF(a,b) extern a; 83 | extern rw_lock_t rx_forest_rwlock; 84 | #endif 85 | 86 | EXTDEF (GList *rx_forest, NULL) /* linked list of trees */ 87 | 88 | typedef struct { 89 | rp_regid_t reg_id; /*+ registry id +*/ 90 | rp_attr_t attr; /*+ extra tree attribute (within the same reg/spc/fam), allows 91 | using the same tree type for different object trees +*/ 92 | 93 | rx_tree_t *tree; /*+ tree +*/ 94 | } rp_tentry_t; 95 | 96 | er_ret_t RP_asc_load(char *filename, int maxobj, 97 | int operation, rp_regid_t reg_id); 98 | er_ret_t 99 | RP_tree_get ( rx_tree_t **treeptr, /*+ answer goes here, please +*/ 100 | rp_regid_t reg_id, /*+ id of the registry +*/ 101 | ip_space_t spc_id, /*+ type of space (ipv4/ipv6) +*/ 102 | rp_attr_t attr /*+ extra tree id (within the same reg/spc/fam +*/ 103 | ); 104 | er_ret_t 105 | RP_tree_add ( 106 | rp_regid_t reg_id, /*+ id of the registry +*/ 107 | rp_attr_t attr, /*+ extra tree id (within the same registry/space/family +*/ 108 | char *prefixstr, /*+ prefix the tree will cover (string) +*/ 109 | rx_mem_mt mem_mode, /* memory only, memory+sql, sql only +*/ 110 | rx_subtree_mt subtrees /*+ one of NONE, AUTO, HAND +*/ 111 | ); 112 | 113 | er_ret_t 114 | RP_tree_del (rx_tree_t *treeptr); /* pointer to a tree structrute */ 115 | 116 | er_ret_t 117 | RP_init_trees( rp_regid_t reg_id ); 118 | 119 | 120 | er_ret_t 121 | RP_asc_search ( 122 | rx_srch_mt search_mode, 123 | int par_a, 124 | int par_b, 125 | char *key, /*+ search term: (string) prefix/range/IP +*/ 126 | rp_regid_t reg_id, 127 | rp_attr_t attr, /*+ extra tree id (within the same reg/spc/fam +*/ 128 | GList **anslist, /*+ answers go here, please +*/ 129 | int max_count /*+ max # of answers. RX_ALLANS == unlimited +*/ 130 | ); 131 | er_ret_t 132 | RP_uni_node ( rx_oper_mt mode, /*+ MODE={cre|mod|del} +*/ 133 | rp_uni_t *uni, /*+ unified argument structure +*/ 134 | rp_attr_t attr, /*+ additional tree attribute +*/ 135 | rp_regid_t reg_id, /*+ id of the registry +*/ 136 | void *data, /*+ pointer to the payload +*/ 137 | unsigned datalen, /*+ length of the payload +*/ 138 | sql_key_t key /*+ the key to the SQL full-text +*/ 139 | ); 140 | er_ret_t 141 | RP_asc_node( rx_oper_mt mode, /*+ MODE={cre|mod|del} +*/ 142 | char *rangstr, /*+ string prefix/range/IP/inaddr +*/ 143 | rp_attr_t attr, /*+ additional tree attribute +*/ 144 | rp_regid_t reg_id, /*+ id of the registry +*/ 145 | void *data, /*+ pointer to the payload +*/ 146 | unsigned datalen, /*+ length of the payload +*/ 147 | sql_key_t key /*+ the key to the SQL full-text +*/ 148 | ); 149 | 150 | rx_fam_t RP_attr2fam( rp_attr_t type ); 151 | int RP_attr2spc(rp_attr_t type, ip_space_t space); 152 | er_ret_t 153 | RP_asc2uni(const char *astr, /*+ string prefix/range/IP/inaddr +*/ 154 | rp_attr_t attr, 155 | rp_uni_t *uni); /* destination pointer */ 156 | er_ret_t 157 | RP_asc2pack(rp_upd_pack_t *pack, rp_attr_t type, const char *string); 158 | 159 | 160 | er_ret_t RP_pack_set_orig( rp_attr_t attr,rp_upd_pack_t *pack, const char *origin); 161 | er_ret_t RP_pack_set_pref4(rp_attr_t attr,const char *avalue, rp_upd_pack_t *pack, 162 | unsigned *prefix, unsigned *prefix_length); 163 | er_ret_t RP_pack_set_revd( rp_attr_t attr,const char *avalue, rp_upd_pack_t *pack); 164 | er_ret_t RP_pack_set_pref6(rp_attr_t attr,const char *avalue, rp_upd_pack_t *pack, 165 | ip_v6word_t *high, ip_v6word_t *low, unsigned *prefix_length); 166 | er_ret_t RP_pack_set_rang( rp_attr_t attr,const char *avalue, rp_upd_pack_t *pack, 167 | unsigned *begin_in, unsigned *end_in); 168 | 169 | er_ret_t 170 | RP_pack_update(rx_oper_mt mode, 171 | rp_upd_pack_t *pack, 172 | rp_regid_t reg_id); /*+ id of the registry +*/ 173 | 174 | 175 | er_ret_t 176 | RP_pack_node(rx_oper_mt mode, 177 | rp_upd_pack_t *pack, 178 | rp_regid_t reg_id); 179 | er_ret_t 180 | RP_pack_node_l(rx_oper_mt mode, 181 | rp_upd_pack_t *pack, 182 | rx_tree_t *mytree); 183 | 184 | void rp_make_short(rp_upd_pack_t *pack, char **ptr, unsigned *len); 185 | 186 | er_ret_t RP_sql_load_reg(rp_regid_t reg_id); 187 | er_ret_t RP_asc_load(char *filename, int maxobj, int operation, 188 | rp_regid_t reg_id); 189 | int RP_attr2spc(rp_attr_t type, ip_space_t space); 190 | #undef EXTDEF 191 | #endif /* RP_H */