1 | /*************************************** 2 | $Revision: 1.4 $ 3 | 4 | Semi-internal header file for UD module 5 | 6 | Status: NOT REVUED, NOT TESTED 7 | 8 | Author(s): Andrei Robachevsky 9 | 10 | ******************/ /****************** 11 | Modification History: 12 | andrei (17/01/2000) Created. 13 | ******************/ /****************** 14 | Copyright (c) 2000 RIPE NCC 15 | 16 | All Rights Reserved 17 | 18 | Permission to use, copy, modify, and distribute this software and its 19 | documentation for any purpose and without fee is hereby granted, 20 | provided that the above copyright notice appear in all copies and that 21 | both that copyright notice and this permission notice appear in 22 | supporting documentation, and that the name of the author not be 23 | used in advertising or publicity pertaining to distribution of the 24 | software without specific, written prior permission. 25 | 26 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 27 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL 28 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 29 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 30 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 31 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 32 | ***************************************/ 33 | #ifndef _UD_INT_H 34 | #define _UD_INT_H 35 | 36 | #include <stdio.h> 37 | #include <strings.h> 38 | #include <glib.h> 39 | #include <stdlib.h> 40 | #include <ctype.h> 41 | #include <unistd.h> 42 | 43 | #include "defs.h" 44 | #include "mysql_driver.h" 45 | #include "iproutines.h" 46 | #include "rxroutines.h" 47 | 48 | 49 | #include "globaldefs.h" 50 | // #include "isnic.h" 51 | #include "bitmask.h" 52 | #include "which_keytypes.h" 53 | 54 | 55 | /*+ String sizes +*/ 56 | #define STR_S 63 57 | #define STR_M 255 58 | #define STR_L 1023 59 | #define STR_XL 4095 60 | #define STR_XXL 16383 61 | #define STR_XXXL 65535 62 | 63 | 64 | #define MAX_NIC_HDL 20 65 | 66 | 67 | /* row# of object.id in the table */ 68 | #define OBJECT_ID 1 69 | 70 | /* class type for dummy objects */ 71 | #define DUMMY_TYPE 100 72 | 73 | 74 | typedef struct _Attribute_t { 75 | A_Type_t type; 76 | char *value; 77 | } Attribute_t; 78 | 79 | typedef struct _Object_t { 80 | C_Type_t type; 81 | long id; 82 | GSList *attributes; 83 | GString *object; 84 | } Object_t; 85 | 86 | #define MAX_DUMMIES 16 87 | 88 | typedef struct _Transaction { 89 | SQ_connection_t *sql_connection; 90 | Object_t *object; // ptr to the object 91 | int thread_ins; // Thread number to mark(backup) creates 92 | int thread_upd; // Thread number to mark(backup) updates 93 | long object_id; // Object id which the transaction is carried out for 94 | long sequence_id; // for last and history tables 95 | int dummy; // Permission to create dummies for PE, RO objects (initial population) 96 | int ndummy; // number of attempts to create dummy 97 | long dummy_id[MAX_DUMMIES]; // to store object_id's of dummies 98 | int action; // indicates wether we are updating/deleting creating a new object 99 | int load_pass; // No. of te pass for initial loading , 0 otherwise 100 | int standalone; // 0 if server 101 | C_Type_t class_type; 102 | int succeeded; 103 | int error; 104 | GString *error_script; 105 | void *save; 106 | } Transaction_t; 107 | 108 | /*++++++++++++++++++++++++++++++++++++++++++++*/ 109 | 110 | /* Definitions for "refer" (domain referral mechanism) */ 111 | #define S_RIPE "RIPE" 112 | #define S_INTERNIC "InterNIC" 113 | #define S_SIMPLE "SIMPLE" 114 | 115 | #define RF_RIPE 1 116 | #define RF_INTERNIC 2 117 | #define RF_SIMPLE 0 118 | #define RF_DEF_PORT 43 119 | 120 | 121 | #define CURRENT_SERIAL_FILE "./RIPE.CURRENTSERIAL" 122 | //#define NRTM_ADD 1 123 | //#define NRTM_DEL 2 124 | #define OP_ADD 1 125 | #define OP_DEL 2 126 | #define OP_UPD 3 127 | #define OP_NOOP 4 128 | 129 | #define _NRTM_PORT 43 130 | #define _NRTM_VERSION 1 131 | #define _DB_PORT 3306 132 | #define _DB_NAME "andrei" 133 | #define _DB_USER "dbint" 134 | #define _DB_PSWD "reimp" 135 | 136 | #define IS_DUMMY_ALLOWED(a) ((a)&0x01) 137 | #define IS_UPDATE(a) ((a)&0x02) 138 | #define IS_STANDALONE(a) ((a)&0x04) 139 | 140 | struct _nrtm { 141 | char *server; 142 | int port; 143 | int version; 144 | int current_serial; 145 | Transaction_t *tr; 146 | char object_name[STR_M]; 147 | int op; 148 | }; 149 | 150 | typedef struct UD_stream_t_ { 151 | FILE * stream; 152 | int num_skip; 153 | int load_pass; 154 | // int dummy_allowed; 155 | int ud_mode; 156 | struct _nrtm *nrtm; 157 | char *db_host; 158 | int db_port; 159 | char *db_name; 160 | char *db_user; 161 | char *db_pswd; 162 | char *log; 163 | char *error_script; 164 | } UD_stream_t; 165 | 166 | typedef struct _Log_t { 167 | int num_ok; 168 | int num_failed; 169 | FILE *logfile; 170 | } Log_t; 171 | 172 | // Stuff needed for radix trees. 173 | //Here we save attributes. br-r-r... 174 | 175 | typedef struct rx_bin_data_t_ { 176 | ip_prefix_t mypref; 177 | char *origin; 178 | } rx_bin_data_t; 179 | 180 | typedef struct rx_inum_data_t_ { 181 | ip_range_t myrang; 182 | // char *origin; 183 | } rx_inum_data_t; 184 | 185 | 186 | 187 | 188 | #define TR_UPDATE 1000 189 | #define TR_INSERT 2000 190 | #define TR_CREATE TR_INSERT 191 | #define TR_DELETE 3000 192 | 193 | /* res_type for mysql_info */ 194 | #define SQL_RECORDS 0 195 | #define SQL_MATCHES 0 // for UPDATE queries (checking for duplicates) 196 | #define SQL_DUPLICATES 1 197 | #define SQL_WARNINGS 2 198 | 199 | 200 | /*++++++++++++++++++ Function Prototypes +++++++++++++++++++++*/ 201 | 202 | FILE *get_NRTM_stream(struct _nrtm *nrtm, int upto_last); 203 | 204 | int UD_process_stream(UD_stream_t *ud_stream); 205 | 206 | int object_process(Transaction_t *tr); 207 | 208 | int commit(Transaction_t *tr); 209 | 210 | int rollback(Transaction_t *tr); 211 | 212 | int delete(Transaction_t *tr); 213 | 214 | 215 | long get_object_id(Transaction_t *tr); 216 | long get_sequence_id(Transaction_t *tr); 217 | char *get_field_str(Transaction_t *tr, char *field, 218 | char *ref_tbl_name, char *ref_name, 219 | char * attr_value, char *condition); 220 | 221 | 222 | void attribute_free(void *data, void *ptr); 223 | 224 | Attribute_t *attribute_new1(int type, const char *value); 225 | 226 | Attribute_t *attribute_new(const char *line); 227 | 228 | void object_free(Object_t *obj); 229 | 230 | Object_t *object_new(const char *line); 231 | 232 | void transaction_free(Transaction_t *tr); 233 | 234 | Transaction_t *transaction_new(SQ_connection_t *sql_connection, C_Type_t class_type); 235 | 236 | void save_rx_pref(rx_bin_data_t *rx_data, unsigned int prefix, unsigned int prefix_length); 237 | void save_rx_orig(rx_bin_data_t *rx_data, char *origin); 238 | void save_rx_rang(rx_inum_data_t *rx_data, unsigned int begin_in, unsigned int end_in); 239 | int update_rx_inum(rx_oper_mt mode, rx_tree_t *mytree, rx_inum_data_t *rx_data, long in_id); 240 | int update_rx_bin(rx_oper_mt mode, rx_tree_t *mytree, rx_bin_data_t *rx_data, long rt_id); 241 | 242 | 243 | er_ret_t expand_rt(char *avalue, unsigned int *prefix, unsigned int *prefix_length); 244 | er_ret_t convert_if(char *avalue, unsigned int *address); 245 | er_ret_t convert_in(char *rangstr, unsigned int *begin_in, unsigned int *end_in); 246 | char *convert_rf(char *avalue, int *type, int *port); 247 | int convert_as_range(const char *as_range, int *begin, int *end); 248 | time_t convert_time(char *asc_time); 249 | 250 | 251 | 252 | 253 | #endif /* _UD_INT_H */ 254 |