1    | /***************************************
2    |   $Revision: 1.22 $
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 "erroutines.h"
47   | #include "rp.h"
48   | #include "nh.h"
49   | #include "sk.h"
50   | #include "memwrap.h"
51   | 
52   | #include "ca_configFns.h"
53   | #include "ca_dictionary.h"
54   | #include "ca_macros.h"
55   | #include "ca_srcAttribs.h"
56   | 
57   | 
58   | 
59   | 
60   | #include "globaldefs.h"
61   | #include "bitmask.h"
62   | #include "which_keytypes.h"
63   | 
64   | 
65   | /*+ String sizes +*/
66   | #define STR_S   63
67   | #define STR_M   255
68   | #define STR_L   1023
69   | #define STR_XL  4095
70   | #define STR_XXL 16383
71   | #define STR_XXXL 65535
72   | 
73   | 
74   | #define MAX_NIC_HDL  30
75   | 
76   | 
77   | 
78   | typedef struct _Attribute_t { 
79   |   A_Type_t type;
80   |   char *value;
81   | } Attribute_t;
82   | 
83   | typedef struct _Object_t {
84   |   C_Type_t type;
85   |   long id;
86   |   GSList *attributes;
87   |   GString *object;
88   | } Object_t;
89   | 
90   | 
91   | typedef struct _obj_parse_t {
92   | 	Object_t *obj;
93   | 	char *object_name;
94   | 	GSList *new_attr_list;
95   | 	Attribute_t *current_attr;
96   | 	SQ_connection_t *sql_connection;
97   | 	nic_handle_t *nh_ptr;
98   | 	char *nic;
99   | 	int garbage;
100  | } Obj_parse_t;
101  | 
102  | #define MAX_DUMMIES 256
103  | 
104  | typedef struct _Transaction {
105  |   int thread_ins;      /* Thread number to mark(backup) creates */
106  |   int thread_upd;      /* Thread number to mark(backup) updates */
107  |   SQ_connection_t *sql_connection;
108  |   Object_t *object;    /* ptr to the object */
109  |   C_Type_t class_type;
110  |   long object_id;      /* Object id which the transaction is carried out for */
111  |   long sequence_id;    /* for last and history tables */
112  |   long serial_id;      /* serial ID, kept for crash recovery */
113  |   long transaction_id; /* ID of DBuopdate transaction */
114  |   int ndummy; /* number of attempts to create dummy */
115  |   long dummy_id[MAX_DUMMIES]; /* to store object_id's of dummies */
116  |   int load_pass; /* No. of the pass for initial loading , 0 otherwise */
117  |   /* XXX later we should merge 'succeeded' & 'error' into single 'succeeded' bitmask */
118  |   int action; /* indicates wether we are updating/deleting creating a new object */
119  |   int mode; /* indicates mode of operation (standalone, dummy, update, nrtm) */
120  |   int succeeded;
121  |   int error;
122  |   GString *error_script;
123  |   GString *query;
124  |   GString *K; /* object primary key */
125  |   char *save; /* for saving attribute (U2 & pn:) values */ 
126  |   rp_upd_pack_t *packptr; /* To store radix tree data */
127  |   nic_handle_t *nh; /* To store NIC handle data */
128  |   ca_dbSource_t *source_hdl;
129  |   int socket; /* socket to report to DBupdate */
130  | } Transaction_t;
131  | 
132  | /*++++++++++++++++++++++++++++++++++++++++++++*/
133  | 
134  | 
135  | struct _nrtm {
136  |  char *server; /* the hostname of the server */
137  |  int port;
138  |  int version;
139  |  long current_serial;
140  |  Transaction_t *tr;
141  |  char object_name[STR_XXL];
142  |  int op;
143  | };
144  |        
145  | typedef struct _Log_t {
146  |  int num_ok;
147  |  int num_failed;
148  | /* FILE *logfile; */
149  | } Log_t;
150  | 
151  | typedef struct UD_stream_t_ {
152  |  FILE * stream;
153  |  sk_conn_st condat;
154  |  int num_skip;
155  |  int load_pass;
156  |  int ud_mode;
157  |  struct _nrtm *nrtm;
158  |  SQ_connection_t *db_connection;
159  |  ca_dbSource_t *source_hdl; /* source we are mirroring */
160  |  Log_t log; 
161  |  char *error_script;
162  | } UD_stream_t;
163  |          
164  | 
165  | 
166  | 
167  | /*++++++++++++++++++ Function Prototypes +++++++++++++++++++++*/
168  | 
169  | int get_NRTM_fd(struct _nrtm *nrtm, int upto_last, char *source);
170  | 
171  | int UD_process_stream(UD_stream_t *ud_stream);
172  | 
173  | int object_process(Transaction_t *tr);
174  | 
175  | int UD_commit(Transaction_t *tr);
176  | int UD_commit_I(Transaction_t *tr);
177  | int UD_commit_II(Transaction_t *tr);
178  | 
179  | 
180  | int UD_rollback(Transaction_t *tr);
181  | 
182  | int UD_delete(Transaction_t *tr);
183  | 
184  | int UD_update_rx(Transaction_t *tr, rx_oper_mt mode);
185  | 
186  | int UD_ack(Transaction_t* tr);
187  | int UD_check_ref(Transaction_t *tr);
188  | 
189  | int isdummy(Transaction_t *tr);
190  | long get_object_id(Transaction_t *tr);
191  | long get_sequence_id(Transaction_t *tr);
192  | char *get_field_str(SQ_connection_t *sql_connection, char *field,
193  |                  char *ref_tbl_name, char *ref_name,
194  |                  char * attr_value, char *condition);
195  | char *get_qresult_str(SQ_connection_t *sql_connection, char *query);                 
196  | 
197  | 
198  | void attribute_free(void *data, void *ptr);
199  | 
200  | Attribute_t *attribute_upd(Attribute_t *attr, int newtype, char *newvalue);
201  | 
202  | Attribute_t *attribute_new1(int type, const char *value);
203  | 
204  | Attribute_t *attribute_new(const char *line);
205  | 
206  | void object_free(Object_t *obj);
207  | 
208  | Object_t *object_new(const char *line);
209  | 
210  | void transaction_free(Transaction_t *tr);
211  | 
212  | Transaction_t *transaction_new(SQ_connection_t *sql_connection, C_Type_t class_type);
213  | 
214  | void get_rx_data(void *element_data, void *tr_ptr);
215  | 
216  | void ud_each_primary_key_select(void *element_data, void *result_ptr);
217  | 
218  | 
219  | #if 0
220  | void set_rx_orig(rx_bin_data_t *rx_data, char *origin);
221  | void set_rx_pref4(char *avalue, rx_bin_data_t *rx_data, 
222  | 		  unsigned *prefix, unsigned *prefix_length);
223  | void set_rx_pref6(char *avalue, rx_bin_data_t *rx_data, 
224  | 		  ip_v6word_t *high, ip_v6word_t *low, unsigned *prefix_length);
225  | void set_rx_rang(char *avalue, rx_inum_data_t *rx_data, 
226  | 		 unsigned *begin_in, unsigned *end_in);
227  | int update_rx_inum(rx_oper_mt mode, rx_regid_t reg_id, rx_inum_data_t *rx_data, long in_id);
228  | int update_rx_bin(rx_oper_mt mode, rx_regid_t reg_id, rx_bin_data_t *rx_data, long rt_id);
229  | int update_rx_dom(rx_oper_mt mode, rx_regid_t reg_id, rx_dom_data_t *rx_data, long dn_id);
230  | #endif
231  | 
232  | char *convert_rf(char *avalue, int *type, int *port);
233  | int convert_as_range(const char *as_range, int *begin, int *end);
234  | time_t convert_time(char *asc_time);
235  | 
236  | int UD_lock_serial(Transaction_t *tr);
237  | int UD_unlock_serial(Transaction_t *tr);
238  | long UD_create_serial(Transaction_t *tr);
239  | int UD_comrol_serial(Transaction_t *tr, int commit);
240  | 
241  | #define UD_commit_serial(tr) UD_comrol_serial(tr, 1)
242  | #define UD_rollback_serial(tr) UD_comrol_serial(tr, 0)
243  | #endif /* _UD_INT_H */
244  | 
245  | 
246  | 
247  |