1 | /***************************************
2 | $Revision: 1.9 $
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 "rp.h"
47 | #include "nh.h"
48 |
49 |
50 | #include "globaldefs.h"
51 | /* #include "isnic.h" */
52 | #include "bitmask.h"
53 | #include "which_keytypes.h"
54 |
55 |
56 | /*+ String sizes +*/
57 | #define STR_S 63
58 | #define STR_M 255
59 | #define STR_L 1023
60 | #define STR_XL 4095
61 | #define STR_XXL 16383
62 | #define STR_XXXL 65535
63 |
64 |
65 | #define MAX_NIC_HDL 30
66 |
67 |
68 | /* class type for dummy objects */
69 | #define DUMMY_TYPE 100
70 |
71 |
72 | typedef struct _Attribute_t {
73 | A_Type_t type;
74 | char *value;
75 | } Attribute_t;
76 |
77 | typedef struct _Object_t {
78 | C_Type_t type;
79 | long id;
80 | GSList *attributes;
81 | GString *object;
82 | } Object_t;
83 |
84 | #define MAX_DUMMIES 16
85 |
86 | typedef struct _Transaction {
87 | SQ_connection_t *sql_connection;
88 | Object_t *object; /* ptr to the object */
89 | int thread_ins; /* Thread number to mark(backup) creates */
90 | int thread_upd; /* Thread number to mark(backup) updates */
91 | long object_id; /* Object id which the transaction is carried out for */
92 | long sequence_id; /* for last and history tables */
93 | int dummy; /* Permission to create dummies for PE, RO objects (initial population) */
94 | int ndummy; /* number of attempts to create dummy */
95 | long dummy_id[MAX_DUMMIES]; /* to store object_id's of dummies */
96 | int action; /* indicates wether we are updating/deleting creating a new object */
97 | int load_pass; /* No. of the pass for initial loading , 0 otherwise */
98 | int standalone; /* 0 if server */
99 | C_Type_t class_type;
100 | int succeeded;
101 | int error;
102 | GString *error_script;
103 | char *save; /* for saving attribute (U2 & pn:) values */
104 | rp_upd_pack_t *packptr; /* To store radix tree data */
105 | nic_handle_t *nh; /* To store NIC handle data */
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 | #define S_CLIENTADDERSS "CLIENTADDRESS"
115 |
116 |
117 | typedef enum {
118 | RF_RIPE=1,
119 | RF_INTERNIC,
120 | RF_SIMPLE,
121 | RF_CLIENTADDRESS
122 | } refer_t;
123 |
124 | #define RF_DEF_PORT 43
125 |
126 |
127 | #define CURRENT_SERIAL_FILE "./RIPE.CURRENTSERIAL"
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 | struct _nrtm {
137 | const char *server;
138 | int port;
139 | int version;
140 | long current_serial;
141 | Transaction_t *tr;
142 | char object_name[STR_M];
143 | int op;
144 | };
145 |
146 | typedef struct _Log_t {
147 | int num_ok;
148 | int num_failed;
149 | FILE *logfile;
150 | } Log_t;
151 |
152 | typedef struct UD_stream_t_ {
153 | FILE * stream;
154 | int num_skip;
155 | int load_pass;
156 | int ud_mode;
157 | struct _nrtm *nrtm;
158 | /*const char *db_host;
159 | int db_port;
160 | const char *db_name;
161 | const char *db_user;
162 | const char *db_pswd; */
163 | SQ_connection_t *db_connection;
164 | Log_t log;
165 | char *error_script;
166 | } UD_stream_t;
167 |
168 |
169 |
170 |
171 | /*++++++++++++++++++ Function Prototypes +++++++++++++++++++++*/
172 |
173 | FILE *get_NRTM_stream(struct _nrtm *nrtm, int upto_last);
174 |
175 | int UD_process_stream(UD_stream_t *ud_stream);
176 |
177 | int object_process(Transaction_t *tr);
178 |
179 | int commit(Transaction_t *tr);
180 |
181 | int rollback(Transaction_t *tr);
182 |
183 | int delete(Transaction_t *tr);
184 |
185 |
186 |
187 | int isdummy(Transaction_t *tr);
188 | long get_object_id(Transaction_t *tr);
189 | long get_sequence_id(Transaction_t *tr);
190 | char *get_field_str(SQ_connection_t *sql_connection, char *field,
191 | char *ref_tbl_name, char *ref_name,
192 | char * attr_value, char *condition);
193 | char *get_qresult_str(SQ_connection_t *sql_connection, char *query);
194 |
195 |
196 | void attribute_free(void *data, void *ptr);
197 |
198 | Attribute_t *attribute_upd(Attribute_t *attr, int newtype, char *newvalue);
199 |
200 | Attribute_t *attribute_new1(int type, const char *value);
201 |
202 | Attribute_t *attribute_new(const char *line);
203 |
204 | void object_free(Object_t *obj);
205 |
206 | Object_t *object_new(const char *line);
207 |
208 | void transaction_free(Transaction_t *tr);
209 |
210 | Transaction_t *transaction_new(SQ_connection_t *sql_connection, C_Type_t class_type);
211 |
212 | void get_rx_data(void *element_data, void *tr_ptr);
213 |
214 | #if 0
215 | void set_rx_orig(rx_bin_data_t *rx_data, char *origin);
216 | void set_rx_pref4(char *avalue, rx_bin_data_t *rx_data,
217 | unsigned *prefix, unsigned *prefix_length);
218 | void set_rx_pref6(char *avalue, rx_bin_data_t *rx_data,
219 | ip_v6word_t *high, ip_v6word_t *low, unsigned *prefix_length);
220 | void set_rx_rang(char *avalue, rx_inum_data_t *rx_data,
221 | unsigned *begin_in, unsigned *end_in);
222 | int update_rx_inum(rx_oper_mt mode, rx_regid_t reg_id, rx_inum_data_t *rx_data, long in_id);
223 | int update_rx_bin(rx_oper_mt mode, rx_regid_t reg_id, rx_bin_data_t *rx_data, long rt_id);
224 | int update_rx_dom(rx_oper_mt mode, rx_regid_t reg_id, rx_dom_data_t *rx_data, long dn_id);
225 | #endif
226 |
227 | char *convert_rf(char *avalue, int *type, int *port);
228 | int convert_as_range(const char *as_range, int *begin, int *end);
229 | time_t convert_time(char *asc_time);
230 |
231 |
232 | long create_serial(Transaction_t *tr);
233 |
234 |
235 | #endif /* _UD_INT_H */
236 |