bin/load/loader.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- stop_updates
- main
1 #include <sys/types.h>
2 #include <fcntl.h>
3 #include <signal.h>
4
5 #include <ud.h>
6 #include <ud_int.h>
7 #include <constants.h>
8 #include <properties.h>
9
10
11 #include "ca_configFns.h"
12 #include "ca_dictSyms.h"
13 #include "ca_macros.h"
14 #include "ca_srcAttribs.h"
15
16
17
18
19 void stop_updates()
/* [<][>][^][v][top][bottom][index][help] */
20 {
21 char print_buf[STR_M];
22
23 fprintf(stderr, "Updates interrupted..\n");
24 sprintf(print_buf, "%d", 0);
25 CO_set_const("UD.do_update", print_buf);
26 return;
27 }
28
29
30
31
32 /***********************************************
33 ******* MAIN **********************************
34 ***********************************************/
35
36
37 int main(int argc, char** argv) {
/* [<][>][^][v][top][bottom][index][help] */
38 FILE *file = NULL;
39 FILE *logfile;
40 char *logname="log.XXXX";
41 int c;
42 extern int optind;
43 extern char *optarg;
44 int errflg = 0;
45 int dummy_allowed;
46 int start_object;
47 int num_ok, num_failed;
48 long num_skip=0;
49 struct _nrtm *nrtm=NULL;
50 UD_stream_t ud_stream;
51 Log_t log;
52 int current_serial=-1;
53 int load_pass=0;
54 int delay=1;
55 char *prop_file_name=NULL;
56 char *logfilename=NULL;
57 int do_update;
58 char *source_name = "RIPE";
59 ca_dbSource_t *source_hdl;
60 char *db_host, *db_name, *db_user, *db_passwd;
61 int db_port;
62
63
64
65 struct sigaction sig;
66
67 num_ok=0; num_failed=0;
68 dummy_allowed=0;
69
70 // strcpy(db_host, "rowan.ripe.net");
71
72 start_object = 1;
73
74 while ((c = getopt(argc, argv, "n:M:L:p:s:?")) != EOF)
75 switch (c) {
76 case 'n':
77 num_skip=atol(optarg);
78 break;
79 case 'p':
80 prop_file_name = optarg;
81 break;
82 case 'L':
83 load_pass=atoi(optarg);
84 dummy_allowed=1;
85 break;
86 case 's':
87 source_name=optarg;
88 break;
89 case '?':
90 default :
91 errflg++;
92 break;
93 }
94 if (errflg) {
95 fprintf(stderr,"usage: standalone [-L pass#] [-n num_skip] [-p properties] file\n");
96 exit (2);
97 }
98
99
100 sig.sa_handler=stop_updates;
101 sigemptyset(&sig.sa_mask);
102 sig.sa_flags=SA_RESTART;
103 sigaction(SIGINT, &sig, NULL);
104 sigaction(SIGTERM, &sig, NULL);
105
106 /* 2. Load properties object from prop_file. */
107 fprintf(stderr,"Properties:\n");
108 if(prop_file_name==NULL)prop_file_name=".properties";
109 PR_load(prop_file_name);
110 fprintf(stderr,"%s\n", PR_to_string() );
111
112 /* 3. Set the constants. */
113 fprintf(stderr,"Constants:\n");
114 CO_set();
115 fprintf(stderr,"%s\n", CO_to_string() );
116
117 /* 3a. Populate dictionary and load config */
118 ca_populateDictionary(dictionary, VARS);
119 ca_readConfig(CO_get_config_file(), confVars, VARS);
120 fprintf(stderr, "Configuration file: %s - ok\n", CO_get_config_file());
121
122
123 /* set mode of operation: unprotected (dummy allowed), updates, standalone */
124 ud_stream.ud_mode=7;
125
126 /* get the source handle */
127 source_hdl = ca_get_SourceHandleByName(source_name);
128
129 /* get error log facility */
130 logfilename=ca_get_srcnrtmlog(source_hdl);
131
132
133 /* Connect to the database */
134 db_host = ca_get_srcdbmachine(source_hdl);
135 db_port = ca_get_srcdbport(source_hdl);
136 db_name = ca_get_srcdbname(source_hdl);
137 db_user = ca_get_srcdbuser(source_hdl);
138 db_passwd = ca_get_srcdbpassword(source_hdl);
139
140 /* fprintf(stderr, "D: Making SQL connection to %s@%s ...", CO_get_database(), CO_get_host()); */
141 fprintf(stderr, "D: Making SQL connection to %s@%s ...", db_name, db_host);
142
143 /* ud_stream.db_connection=SQ_get_connection2(); */
144 ud_stream.db_connection=SQ_get_connection(db_host, db_port, db_name, db_user, db_passwd);
145
146
147 if(! ud_stream.db_connection) {
148 fprintf(stderr, "D: ERROR: no SQL connection\n");
149 return;
150 }
151
152 fprintf(stderr, "OK\n");
153
154
155
156 ud_stream.nrtm=NULL;
157
158 ud_stream.log.logfile = fopen(logfilename, "a+");
159 ud_stream.log.num_ok=0;
160 ud_stream.log.num_failed=0;
161
162 free(db_host);
163 free(db_name);
164 free(db_user);
165 free(db_passwd);
166 free(logfilename);
167
168
169 if(optind<argc) file=fopen(argv[optind], "r"); else file=stdin;
170
171 if (file==NULL) { fprintf(stderr, "Cannot open data stream. Exiting..\n");
172 exit(1); }
173
174
175 ud_stream.stream=file;
176 ud_stream.num_skip=num_skip;
177 ud_stream.load_pass=load_pass;
178
179 /* Start to process the stream */
180
181 fprintf(stderr, "starting processing stream\n");
182 num_ok=UD_process_stream(&ud_stream);
183 fprintf(stderr, "processing stream finished\n");
184 fprintf(stderr, "%d objects processed\n", num_ok);
185
186 return(0);
187
188 } /* main() */
189
190
191
192