modules/co/constants.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- set_string
- set_int
- set_boolean
- show_string
- show_int
- show_boolean
- CO_get_max_threads
- CO_get_whois_port
- CO_get_config_port
- CO_get_mirror_port
- CO_get_update_port
- CO_get_host
- CO_get_user
- CO_get_password
- CO_get_database_port
- CO_get_database
- CO_get_query
- CO_get_in_query
- CO_get_rt_query
- CO_get_authenticate
- CO_get_whois_suspended
- CO_get_welcome
- CO_get_prompt
- CO_get_clear_screen
- CO_get_sleep_time
- CO_get_accounting
- CO_get_query_logging
- CO_get_query_logfile
- CO_get_instr_logging
- CO_get_instr_logfile
- CO_get_comnd_logging
- CO_get_comnd_logfile
- CO_get_tests_logging
- CO_get_tests_logfile
- CO_get_thread_logging
- CO_get_thread_logfile
- CO_get_socket_logging
- CO_get_socket_logfile
- CO_get_config_logging
- CO_get_config_logfile
- CO_get_config_file
- CO_get_nrtm_host
- CO_get_nrtm_port
- CO_get_nrtm_version
- CO_get_nrtm_delay
- CO_get_nrtm_cserialfile
- CO_get_nrtm_logfile
- CO_get_do_nrtm
- CO_get_update_mode
- CO_get_do_update
- CO_get_do_server
- source_foreach
- CO_sources_to_string
- CO_sources_list_to_string
- CO_get_sources
- CO_get_source
- CO_get_source_database
- init_constants
- CO_to_string
- CO_const_to_string
- CO_set_const
- CO_set
1 /***************************************
2 $Revision: 1.16 $
3
4 Constants module (co) - this _should_ eventually get merged in with the
5 config module.
6
7 Status: NOT REVUED, NOT TESTED
8
9 +html+ <DL COMPACT>
10 +html+ <DT>Online References:
11 +html+ <DD><UL>
12 +html+ </UL>
13 +html+ </DL>
14 +html+ <PRE>
15 Instructions for use:
16
17 To add a constant:
18 0. Add a default value for the constant. (string)
19 1. Add the constant declaration to the _Constants struct.
20 2. Add a CO_get_function()
21 3. Add initializing code to init_constants()
22
23 To access the constant:
24 use the CO_get<Constant>() function from your other code.
25 +html+ </PRE>
26
27 ******************/ /******************
28 Filename : constants.c
29 Author : ottrey@ripe.net
30 OSs Tested : Solaris
31 Related Modules : Used in conjunction with the properties module.
32 Problems :
33 To Do : Merge into a "config module"
34 Comments :
35 ******************/ /******************
36 Copyright (c) 1999 RIPE NCC
37
38 All Rights Reserved
39
40 Permission to use, copy, modify, and distribute this software and its
41 documentation for any purpose and without fee is hereby granted,
42 provided that the above copyright notice appear in all copies and that
43 both that copyright notice and this permission notice appear in
44 supporting documentation, and that the name of the author not be
45 used in advertising or publicity pertaining to distribution of the
46 software without specific, written prior permission.
47
48 THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
49 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
50 AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
51 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
52 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
53 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54 ***************************************/
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <string.h>
58
59 #include "memwrap.h"
60 #include "properties.h"
61
62 #define STR_XL 4095
63
64 /*+ Maximum number of constants. +*/
65 #define MAX_CONSTS 100
66
67 /*+ Default values for constants. +*/
68 #define DEFLT_MAX_THREADS "10"
69 #define DEFLT_WHOIS_PORT "0"
70 #define DEFLT_CONFIG_PORT "0"
71 #define DEFLT_MIRROR_PORT "0"
72 #define DEFLT_UPDATE_PORT "0"
73 #define DEFLT_HOST "mysql.database.net"
74 #define DEFLT_USER "xxx"
75 #define DEFLT_PASSWORD "xxx"
76 #define DEFLT_DATABASE_PORT "3306"
77 #define DEFLT_DATABASE "RIPE"
78 #define DEFLT_QUERY "SHOW TABLES"
79 #define DEFLT_IN_QUERY "SELECT * FROM inetnum"
80 #define DEFLT_RT_QUERY "SELECT * FROM route"
81 #define DEFLT_AUTHENTICATE "0"
82 #define DEFLT_WHOIS_SUSPENDED "0"
83 #define DEFLT_DO_SERVER "1"
84 #define DEFLT_WELCOME "Welcome to the whois R.I.P. server.\n"
85 #define DEFLT_PROMPT "whois R.I.P. config> "
86 #define DEFLT_CLEAR_SCREEN "0"
87 #define DEFLT_SLEEP_TIME "1"
88 #define DEFLT_ACCOUNTING "0"
89 #define DEFLT_QUERY_LOGGING "1"
90 #define DEFLT_QUERY_LOGFILE "stdout"
91 #define DEFLT_INSTR_LOGGING "1"
92 #define DEFLT_INSTR_LOGFILE "stdout"
93 #define DEFLT_COMND_LOGGING "1"
94 #define DEFLT_COMND_LOGFILE "stdout"
95 #define DEFLT_TESTS_LOGGING "1"
96 #define DEFLT_TESTS_LOGFILE "stdout"
97 #define DEFLT_THREAD_LOGGING "1"
98 #define DEFLT_THREAD_LOGFILE "stdout"
99 #define DEFLT_SOCKET_LOGGING "1"
100 #define DEFLT_SOCKET_LOGFILE "stdout"
101 #define DEFLT_CONFIG_LOGGING "1"
102 #define DEFLT_CONFIG_LOGFILE "stdout"
103 #define DEFLT_CONFIG_FILE "rip.config"
104 #define DEFLT_NRTM_HOST "nrtm.nowhere.xx"
105 #define DEFLT_NRTM_VERSION "1"
106 #define DEFLT_NRTM_DELAY "600"
107 #define DEFLT_NRTM_CSERFILE "RIPE.CURRENTSERIAL"
108 #define DEFLT_NRTM_LOGFILE "nrtm.log"
109 #define DEFLT_UPDATE_MODE "0"
110
111 /*+ Each constant has a +*/
112 struct _constant {
113 const char *token; /*+ Token to be found in properties file. +*/
114 const char *deflt; /*+ Default value for the constant. +*/
115 int (*set_func)(void *, char *); /*+ Function to set the constant. +*/
116 void *constant_ptr; /*+ Pointer to the constant value +*/
117 char *(*show_func)(void *); /*+ Function to show the constant. +*/
118 };
119
120
121 /*+ The Constants array has a +*/
122 typedef struct _Constants {
123 int max_threads[1]; /*+ Maximum number of server threads. +*/
124 char whois_port[64]; /*+ Port for whois clients to rendezvous with. +*/
125 char config_port[64]; /*+ Port for config clients to rendezvous with. +*/
126 char mirror_port[64]; /*+ Port for mirror clients to rendezvous with. +*/
127 char update_port[64]; /*+ Port for DBupdate clients to rendezvous with. +*/
128 char host[64]; /*+ Host for the database. +*/
129 char user[64]; /*+ User for the database. +*/
130 char password[64]; /*+ Password for the database. +*/
131 int database_port[1]; /*+ Port for the database. +*/
132 char database[64]; /*+ Database name. +*/
133 char query[1024]; /*+ Query for the database. +*/
134 char in_query[1024]; /*+ Query for the radix tree initialization. +*/
135 char rt_query[1024]; /*+ Query for the radix tree initialization. +*/
136 int authenticate[1]; /*+ Authenticate users. +*/
137 int whois_suspended[1]; /*+ Suspend the whois server. +*/
138 char welcome[1024]; /*+ Welcome for config protocol. +*/
139 char prompt[1024]; /*+ Prompt for config protocol. +*/
140 int clear_screen[1]; /*+ Clear screen after config commands. +*/
141 int sleep_time[1]; /*+ Sleep time (in sec) between config commands. +*/
142 int accounting[1]; /*+ Conduct accounting on whois queries. +*/
143 int query_logging[1]; /*+ Log the SQL queries. +*/
144 char query_logfile[1024]; /*+ Query logfile for the database. +*/
145 int instr_logging[1]; /*+ Log the whois instrucs. +*/
146 char instr_logfile[1024]; /*+ Query logfile for the whois instrucs. +*/
147 int comnd_logging[1]; /*+ Log the whois commands. +*/
148 char comnd_logfile[1024]; /*+ Query logfile for the whois commands. +*/
149 int tests_logging[1]; /*+ Log the whois tests. +*/
150 char tests_logfile[1024]; /*+ Query logfile for the whois tests. +*/
151 int thread_logging[1]; /*+ Log the whois threads. +*/
152 char thread_logfile[1024]; /*+ Query logfile for the whois threads. +*/
153 int socket_logging[1]; /*+ Log the socket. +*/
154 char socket_logfile[1024]; /*+ Logfile for the socket. +*/
155 int config_logging[1]; /*+ Log the config. +*/
156 char config_logfile[1024]; /*+ Logfile for the config. +*/
157 char config_file[1024]; /*+ File for the config. +*/
158 char nrtm_host[64];/*+ NRTM server +*/
159 char nrtm_port[64];/*+ Port of NRTM server when we are acting as a client +*/
160 int nrtm_version[1];/*+ NRTM protocol version +*/
161 int nrtm_delay[1];/*+ delay between syncs +*/
162 char nrtm_cserialfile[1024];/*+ name of the file containing current serial +*/
163 char nrtm_logfile[1024];/*+ NRTM logfile for failure reports +*/
164 int do_nrtm[1];
165 int update_mode[1];/*+ protected/unprotected (==dummy_allowed) +*/
166 int do_update[1]; /*+ switches on and off the updates +*/
167 int do_server[1]; /*+ turns off execution of the all servers(threads) +*/
168 } *Constants;
169
170 /* in addition, we make a table of Sources here: */
171 /*+ Source database mirrors +*/
172 typedef struct {
173 char src[32];
174 char db[32];
175 } source_info_t;
176
177 source_info_t const Sources[] = {
178 {"RIPE","RIPE6"}, /* the db part actually gets overwritten in
179 init_constants */
180
181 /* "ARIN",
182 "APNIC",
183 */
184
185 {"",""}
186 }; /* Sources */
187
188 char * const Sources_vector[] = {
189 "RIPE",
190 NULL
191 };
192
193 /*
194 * Global Variables
195 */
196 /*+ The array of Global Constants. +*/
197 static Constants Global_constants=NULL;
198
199 /*
200 * Set Functions
201 */
202 static int set_string(void *constant, char *value) {
/* [<][>][^][v][top][bottom][index][help] */
203
204 strcpy((char *)constant, value);
205
206 return 0;
207 } /* set_string() */
208
209 static int set_int(void *constant, char *value) {
/* [<][>][^][v][top][bottom][index][help] */
210 int i;
211
212 i = atol(value);
213 ((int *)constant)[0] = i;
214
215 return 0;
216 } /* set_int() */
217
218 static int set_boolean(void *constant, char *value) {
/* [<][>][^][v][top][bottom][index][help] */
219 int result=1;
220 int i;
221
222 i = atol(value);
223
224 /* If a valid boolean */
225 if ( (i == 0) || (i == 1)) {
226 ((int *)constant)[0] = i;
227 result = 0;
228 }
229
230 return result;
231 } /* set_boolean() */
232
233
234 /*
235 * Show Functions
236 */
237 /* AR. changed for unification with oter show funcs */
238 static char *show_string(void *constant) {
/* [<][>][^][v][top][bottom][index][help] */
239 char *tmp;
240
241 /* tmp = calloc(1, strlen((char *)constant)+1); */
242 dieif( wr_malloc((void **)&tmp, strlen((char *)constant)+1) != UT_OK);
243
244 strcpy(tmp, (char *)constant);
245 /* return((char *)constant); */
246 return tmp;
247 } /* show_string() */
248
249 static char *show_int(void *constant) {
/* [<][>][^][v][top][bottom][index][help] */
250 char *tmp;
251
252 /* tmp = calloc(1, 64); */
253 dieif( wr_malloc((void **)&tmp, 64) != UT_OK);
254
255 sprintf(tmp, "%d", ((int *)constant)[0]);
256 return tmp;
257 } /* show_int() */
258
259 static char *show_boolean(void *constant) {
/* [<][>][^][v][top][bottom][index][help] */
260 char *tmp;
261
262 /* tmp = calloc(1, 64); */
263 dieif( wr_malloc((void **)&tmp, 64) != UT_OK);
264
265 sprintf(tmp, "%d", ((int *)constant)[0]);
266 return tmp;
267 } /* show_boolean() */
268
269
270 /*
271 * Get Functions
272 */
273 int CO_get_max_threads() {
/* [<][>][^][v][top][bottom][index][help] */
274 return Global_constants->max_threads[0];
275 }
276
277 char *CO_get_whois_port() {
/* [<][>][^][v][top][bottom][index][help] */
278 return Global_constants->whois_port;
279 }
280
281 char *CO_get_config_port() {
/* [<][>][^][v][top][bottom][index][help] */
282 return Global_constants->config_port;
283 }
284
285 char *CO_get_mirror_port() {
/* [<][>][^][v][top][bottom][index][help] */
286 return Global_constants->mirror_port;
287 }
288
289 char *CO_get_update_port() {
/* [<][>][^][v][top][bottom][index][help] */
290 return Global_constants->update_port;
291 }
292
293 char *CO_get_host() {
/* [<][>][^][v][top][bottom][index][help] */
294 return Global_constants->host;
295 }
296
297 char *CO_get_user() {
/* [<][>][^][v][top][bottom][index][help] */
298 return Global_constants->user;
299 }
300
301 char *CO_get_password() {
/* [<][>][^][v][top][bottom][index][help] */
302 return Global_constants->password;
303 }
304
305 int CO_get_database_port() {
/* [<][>][^][v][top][bottom][index][help] */
306 return Global_constants->database_port[0];
307 }
308
309 char *CO_get_database() {
/* [<][>][^][v][top][bottom][index][help] */
310 return Global_constants->database;
311 }
312
313 char *CO_get_query() {
/* [<][>][^][v][top][bottom][index][help] */
314 return Global_constants->query;
315 }
316
317 char *CO_get_in_query() {
/* [<][>][^][v][top][bottom][index][help] */
318 return Global_constants->in_query;
319 }
320
321 char *CO_get_rt_query() {
/* [<][>][^][v][top][bottom][index][help] */
322 return Global_constants->rt_query;
323 }
324
325 int CO_get_authenticate() {
/* [<][>][^][v][top][bottom][index][help] */
326 return Global_constants->authenticate[0];
327 }
328
329 int CO_get_whois_suspended() {
/* [<][>][^][v][top][bottom][index][help] */
330 return Global_constants->whois_suspended[0];
331 }
332
333 char *CO_get_welcome() {
/* [<][>][^][v][top][bottom][index][help] */
334 return Global_constants->welcome;
335 }
336
337 char *CO_get_prompt() {
/* [<][>][^][v][top][bottom][index][help] */
338 return Global_constants->prompt;
339 }
340
341 int CO_get_clear_screen() {
/* [<][>][^][v][top][bottom][index][help] */
342 return Global_constants->clear_screen[0];
343 }
344
345 int CO_get_sleep_time() {
/* [<][>][^][v][top][bottom][index][help] */
346 return Global_constants->sleep_time[0];
347 }
348
349 int CO_get_accounting() {
/* [<][>][^][v][top][bottom][index][help] */
350 return Global_constants->accounting[0];
351 }
352
353 int CO_get_query_logging() {
/* [<][>][^][v][top][bottom][index][help] */
354 return Global_constants->query_logging[0];
355 }
356
357 char *CO_get_query_logfile() {
/* [<][>][^][v][top][bottom][index][help] */
358 return Global_constants->query_logfile;
359 }
360
361 int CO_get_instr_logging() {
/* [<][>][^][v][top][bottom][index][help] */
362 return Global_constants->instr_logging[0];
363 }
364
365 char *CO_get_instr_logfile() {
/* [<][>][^][v][top][bottom][index][help] */
366 return Global_constants->instr_logfile;
367 }
368
369 int CO_get_comnd_logging() {
/* [<][>][^][v][top][bottom][index][help] */
370 return Global_constants->comnd_logging[0];
371 }
372
373 char *CO_get_comnd_logfile() {
/* [<][>][^][v][top][bottom][index][help] */
374 return Global_constants->comnd_logfile;
375 }
376
377 int CO_get_tests_logging() {
/* [<][>][^][v][top][bottom][index][help] */
378 return Global_constants->tests_logging[0];
379 }
380
381 char *CO_get_tests_logfile() {
/* [<][>][^][v][top][bottom][index][help] */
382 return Global_constants->tests_logfile;
383 }
384
385 int CO_get_thread_logging() {
/* [<][>][^][v][top][bottom][index][help] */
386 return Global_constants->thread_logging[0];
387 }
388
389 char *CO_get_thread_logfile() {
/* [<][>][^][v][top][bottom][index][help] */
390 return Global_constants->thread_logfile;
391 }
392
393 int CO_get_socket_logging() {
/* [<][>][^][v][top][bottom][index][help] */
394 return Global_constants->socket_logging[0];
395 }
396
397 char *CO_get_socket_logfile() {
/* [<][>][^][v][top][bottom][index][help] */
398 return Global_constants->socket_logfile;
399 }
400
401 int CO_get_config_logging() {
/* [<][>][^][v][top][bottom][index][help] */
402 return Global_constants->config_logging[0];
403 }
404
405 char *CO_get_config_logfile() {
/* [<][>][^][v][top][bottom][index][help] */
406 return Global_constants->config_logfile;
407 }
408
409 char *CO_get_config_file() {
/* [<][>][^][v][top][bottom][index][help] */
410 return Global_constants->config_file;
411 }
412
413
414 /*++++ NRTM stuff ++++*/
415
416 char *CO_get_nrtm_host() {
/* [<][>][^][v][top][bottom][index][help] */
417 return Global_constants->nrtm_host;
418 }
419
420 char *CO_get_nrtm_port() {
/* [<][>][^][v][top][bottom][index][help] */
421 return Global_constants->nrtm_port;
422 }
423
424 int CO_get_nrtm_version() {
/* [<][>][^][v][top][bottom][index][help] */
425 return Global_constants->nrtm_version[0];
426 }
427
428 int CO_get_nrtm_delay() {
/* [<][>][^][v][top][bottom][index][help] */
429 return Global_constants->nrtm_delay[0];
430 }
431
432 char *CO_get_nrtm_cserialfile() {
/* [<][>][^][v][top][bottom][index][help] */
433 return Global_constants->nrtm_cserialfile;
434 }
435
436 char *CO_get_nrtm_logfile() {
/* [<][>][^][v][top][bottom][index][help] */
437 return Global_constants->nrtm_logfile;
438 }
439
440 int CO_get_do_nrtm() {
/* [<][>][^][v][top][bottom][index][help] */
441 return Global_constants->do_nrtm[0];
442 }
443
444 int CO_get_update_mode() {
/* [<][>][^][v][top][bottom][index][help] */
445 return Global_constants->update_mode[0];
446 }
447
448 int CO_get_do_update() {
/* [<][>][^][v][top][bottom][index][help] */
449 return Global_constants->do_update[0];
450 }
451
452 int CO_get_do_server() {
/* [<][>][^][v][top][bottom][index][help] */
453 return Global_constants->do_server[0];
454 }
455
456 /* source_foreach() */
457 /*++++++++++++++++++++++++++++++++++++++
458 Function to adds the source string to the created string from the Glist of sources.
459 It is called via g_list_foreach().
460
461 void *element_data The source name.
462
463 void *result_buf_ptr The string to be populated.
464
465 More:
466 +html+ <PRE>
467 Authors:
468 ottrey
469
470 +html+ </PRE><DL COMPACT>
471 +html+ <DT>Online References:
472 +html+ <DD><UL>
473 +html+ </UL></DL>
474
475 ++++++++++++++++++++++++++++++++++++++*/
476 static void source_foreach(void *element_data, void *result_buf_ptr) {
/* [<][>][^][v][top][bottom][index][help] */
477 char *source = element_data;
478 char *result_buf = (char *)result_buf_ptr;
479
480 strcat(result_buf, source);
481 strcat(result_buf, ",");
482
483 } /* source_foreach() */
484
485 /* CO_sources_to_string() */
486 /*++++++++++++++++++++++++++++++++++++++
487 Creates a string from Sources.
488
489 char * CO_sources_to_string Returns a string of the Sources.
490
491 More:
492 +html+ <PRE>
493 Authors:
494 ottrey
495
496 +html+ </PRE><DL COMPACT>
497 +html+ <DT>Online References:
498 +html+ <DD><UL>
499 +html+ </UL></DL>
500
501 ++++++++++++++++++++++++++++++++++++++*/
502 char * CO_sources_to_string(void) {
/* [<][>][^][v][top][bottom][index][help] */
503 char *result=NULL;
504 char result_buf[STR_XL];
505 int result_len;
506 int i;
507
508 strcpy(result_buf, "{");
509 for (i=0; Sources[i].src[0] != 0 ; i++) {
510 strcat(result_buf, Sources[i].src);
511 strcat(result_buf, ",");
512 }
513 result_len = strlen(result_buf);
514 result_buf[result_len-1] = '}';
515 result_buf[result_len] = '\0';
516
517 /* result = (char *)calloc(1, result_len+1); */
518 dieif( wr_malloc((void **)&result, result_len+1) != UT_OK);
519 strcpy(result, result_buf);
520
521 return result;
522
523 } /* CO_sources_to_string() */
524
525 /* CO_sources_list_to_string() */
526 /*++++++++++++++++++++++++++++++++++++++
527 Creates a string from the sources in the GList.
528
529 GList *sources_list The GList of sources.
530
531 More:
532 +html+ <PRE>
533 Authors:
534 ottrey
535
536 +html+ </PRE><DL COMPACT>
537 +html+ <DT>Online References:
538 +html+ <DD><UL>
539 +html+ </UL></DL>
540
541 ++++++++++++++++++++++++++++++++++++++*/
542 char *CO_sources_list_to_string(GList *sources_list) {
/* [<][>][^][v][top][bottom][index][help] */
543 char *result=NULL;
544 char result_buf[STR_XL];
545 int result_len;
546
547 strcpy(result_buf, "{");
548 g_list_foreach(sources_list, source_foreach, &result_buf);
549 result_len = strlen(result_buf);
550 if (result_len == 1) {
551 /* If an empty set */
552 result_buf[1] = '}';
553 result_buf[2] = '\0';
554 }
555 else {
556 result_buf[result_len-1] = '}';
557 result_buf[result_len] = '\0';
558 }
559
560 /* result = (char *)calloc(1, result_len+1); */
561 dieif( wr_malloc((void **)&result, result_len+1) != UT_OK);
562 strcpy(result, result_buf);
563
564 return result;
565
566 } /* CO_sources_list_to_string() */
567
568
569 char * const *CO_get_sources(void) {
/* [<][>][^][v][top][bottom][index][help] */
570 return Sources_vector;
571 } /* CO_get_sources() */
572
573 const char *CO_get_source(int index) {
/* [<][>][^][v][top][bottom][index][help] */
574 const char *s = Sources[index].src;
575
576 return (*s == 0)
577 ? NULL
578 : s;
579
580 } /* CO_get_source() */
581
582 const char *CO_get_source_database(int index) {
/* [<][>][^][v][top][bottom][index][help] */
583 const char *s = Sources[index].db;
584
585 return (*s == 0)
586 ? NULL
587 : s;
588
589 } /* CO_get_database() */
590
591
592
593 /*+
594 * Contains the constant definitions for the Token, set_function, show_function.
595 * (See: _constant)
596 +*/
597 static struct _constant constant[MAX_CONSTS];
598
599 /* init_constants() */
600 /*++++++++++++++++++++++++++++++++++++++
601 Initialize all the constants.
602
603 More:
604 +html+ <PRE>
605 Authors:
606 ottrey
607
608 +html+ </PRE><DL COMPACT>
609 +html+ <DT>Online References:
610 +html+ <DD><UL>
611 +html+ </UL></DL>
612
613 ++++++++++++++++++++++++++++++++++++++*/
614 static void init_constants(void) {
/* [<][>][^][v][top][bottom][index][help] */
615 int n=0;
616
617 constant[n].token="SV.max_threads";
618 constant[n].deflt=DEFLT_MAX_THREADS;
619 constant[n].set_func=set_int;
620 constant[n].constant_ptr=Global_constants->max_threads;
621 constant[n].show_func=show_int;
622 n++;
623
624 constant[n].token="SV.whois_port";
625 constant[n].deflt=DEFLT_WHOIS_PORT;
626 constant[n].set_func=set_string;
627 constant[n].constant_ptr=Global_constants->whois_port;
628 constant[n].show_func=show_string;
629 n++;
630
631 constant[n].token="SV.config_port";
632 constant[n].deflt=DEFLT_CONFIG_PORT;
633 constant[n].set_func=set_string;
634 constant[n].constant_ptr=Global_constants->config_port;
635 constant[n].show_func=show_string;
636 n++;
637
638 constant[n].token="SV.mirror_port";
639 constant[n].deflt=DEFLT_MIRROR_PORT;
640 constant[n].set_func=set_string;
641 constant[n].constant_ptr=Global_constants->mirror_port;
642 constant[n].show_func=show_string;
643 n++;
644
645 constant[n].token="SV.update_port";
646 constant[n].deflt=DEFLT_UPDATE_PORT;
647 constant[n].set_func=set_string;
648 constant[n].constant_ptr=Global_constants->update_port;
649 constant[n].show_func=show_string;
650 n++;
651
652 constant[n].token="DB.host";
653 constant[n].deflt=DEFLT_HOST;
654 constant[n].set_func=set_string;
655 constant[n].constant_ptr=Global_constants->host;
656 constant[n].show_func=show_string;
657 n++;
658
659 constant[n].token="DB.user";
660 constant[n].deflt=DEFLT_USER;
661 constant[n].set_func=set_string;
662 constant[n].constant_ptr=Global_constants->user;
663 constant[n].show_func=show_string;
664 n++;
665
666 constant[n].token="DB.password";
667 constant[n].deflt=DEFLT_PASSWORD;
668 constant[n].set_func=set_string;
669 constant[n].constant_ptr=Global_constants->password;
670 constant[n].show_func=show_string;
671 n++;
672
673 constant[n].token="DB.database_port";
674 constant[n].deflt=DEFLT_DATABASE_PORT;
675 constant[n].set_func=set_int;
676 constant[n].constant_ptr=Global_constants->database_port;
677 constant[n].show_func=show_int;
678 n++;
679
680 constant[n].token="DB.database";
681 constant[n].deflt=DEFLT_DATABASE;
682 constant[n].set_func=set_string;
683 constant[n].constant_ptr=Global_constants->database;
684 constant[n].show_func=show_string;
685 n++;
686
687 constant[n].token="DB.query";
688 constant[n].deflt=DEFLT_QUERY;
689 constant[n].set_func=set_string;
690 constant[n].constant_ptr=Global_constants->query;
691 constant[n].show_func=show_string;
692 n++;
693
694 constant[n].token="RX.in_query";
695 constant[n].deflt=DEFLT_IN_QUERY;
696 constant[n].set_func=set_string;
697 constant[n].constant_ptr=Global_constants->in_query;
698 constant[n].show_func=show_string;
699 n++;
700
701 constant[n].token="RX.rt_query";
702 constant[n].deflt=DEFLT_RT_QUERY;
703 constant[n].set_func=set_string;
704 constant[n].constant_ptr=Global_constants->rt_query;
705 constant[n].show_func=show_string;
706 n++;
707
708 constant[n].token="SV.authenticate";
709 constant[n].deflt=DEFLT_AUTHENTICATE;
710 constant[n].set_func=set_boolean;
711 constant[n].constant_ptr=Global_constants->authenticate;
712 constant[n].show_func=show_boolean;
713 n++;
714
715 constant[n].token="SV.whois_suspended";
716 constant[n].deflt=DEFLT_WHOIS_SUSPENDED;
717 constant[n].set_func=set_boolean;
718 constant[n].constant_ptr=Global_constants->whois_suspended;
719 constant[n].show_func=show_boolean;
720 n++;
721
722 constant[n].token="SV.do_server";
723 constant[n].deflt=DEFLT_DO_SERVER;
724 constant[n].set_func=set_boolean;
725 constant[n].constant_ptr=Global_constants->do_server;
726 constant[n].show_func=show_boolean;
727 n++;
728
729 constant[n].token="PC.welcome";
730 constant[n].deflt=DEFLT_WELCOME;
731 constant[n].set_func=set_string;
732 constant[n].constant_ptr=Global_constants->welcome;
733 constant[n].show_func=show_string;
734 n++;
735
736 constant[n].token="PC.prompt";
737 constant[n].deflt=DEFLT_PROMPT;
738 constant[n].set_func=set_string;
739 constant[n].constant_ptr=Global_constants->prompt;
740 constant[n].show_func=show_string;
741 n++;
742
743 constant[n].token="PC.clear_screen";
744 constant[n].deflt=DEFLT_CLEAR_SCREEN;
745 constant[n].set_func=set_boolean;
746 constant[n].constant_ptr=Global_constants->clear_screen;
747 constant[n].show_func=show_boolean;
748 n++;
749
750 constant[n].token="PC.sleep_time";
751 constant[n].deflt=DEFLT_SLEEP_TIME;
752 constant[n].set_func=set_int;
753 constant[n].constant_ptr=Global_constants->sleep_time;
754 constant[n].show_func=show_int;
755 n++;
756
757 constant[n].token="WQ.accounting";
758 constant[n].deflt=DEFLT_ACCOUNTING;
759 constant[n].set_func=set_boolean;
760 constant[n].constant_ptr=Global_constants->accounting;
761 constant[n].show_func=show_boolean;
762 n++;
763
764 constant[n].token="LO.query_logging";
765 constant[n].deflt=DEFLT_QUERY_LOGGING;
766 constant[n].set_func=set_boolean;
767 constant[n].constant_ptr=Global_constants->query_logging;
768 constant[n].show_func=show_boolean;
769 n++;
770
771 constant[n].token="LO.query_logfile";
772 constant[n].deflt=DEFLT_QUERY_LOGFILE;
773 constant[n].set_func=set_string;
774 constant[n].constant_ptr=Global_constants->query_logfile;
775 constant[n].show_func=show_string;
776 n++;
777
778 constant[n].token="LO.instr_logging";
779 constant[n].deflt=DEFLT_INSTR_LOGGING;
780 constant[n].set_func=set_boolean;
781 constant[n].constant_ptr=Global_constants->instr_logging;
782 constant[n].show_func=show_boolean;
783 n++;
784
785 constant[n].token="LO.insrt_logfile";
786 constant[n].deflt=DEFLT_INSTR_LOGFILE;
787 constant[n].set_func=set_string;
788 constant[n].constant_ptr=Global_constants->instr_logfile;
789 constant[n].show_func=show_string;
790 n++;
791
792 constant[n].token="LO.comnd_logging";
793 constant[n].deflt=DEFLT_COMND_LOGGING;
794 constant[n].set_func=set_boolean;
795 constant[n].constant_ptr=Global_constants->comnd_logging;
796 constant[n].show_func=show_boolean;
797 n++;
798
799 constant[n].token="LO.comnd_logfile";
800 constant[n].deflt=DEFLT_COMND_LOGFILE;
801 constant[n].set_func=set_string;
802 constant[n].constant_ptr=Global_constants->comnd_logfile;
803 constant[n].show_func=show_string;
804 n++;
805
806 constant[n].token="LO.tests_logging";
807 constant[n].deflt=DEFLT_TESTS_LOGGING;
808 constant[n].set_func=set_boolean;
809 constant[n].constant_ptr=Global_constants->tests_logging;
810 constant[n].show_func=show_boolean;
811 n++;
812
813 constant[n].token="LO.tests_logfile";
814 constant[n].deflt=DEFLT_TESTS_LOGFILE;
815 constant[n].set_func=set_string;
816 constant[n].constant_ptr=Global_constants->tests_logfile;
817 constant[n].show_func=show_string;
818 n++;
819
820 constant[n].token="LO.thread_logging";
821 constant[n].deflt=DEFLT_THREAD_LOGGING;
822 constant[n].set_func=set_boolean;
823 constant[n].constant_ptr=Global_constants->thread_logging;
824 constant[n].show_func=show_boolean;
825 n++;
826
827 constant[n].token="LO.thread_logfile";
828 constant[n].deflt=DEFLT_THREAD_LOGFILE;
829 constant[n].set_func=set_string;
830 constant[n].constant_ptr=Global_constants->thread_logfile;
831 constant[n].show_func=show_string;
832 n++;
833
834 constant[n].token="LO.socket_logging";
835 constant[n].deflt=DEFLT_SOCKET_LOGGING;
836 constant[n].set_func=set_boolean;
837 constant[n].constant_ptr=Global_constants->socket_logging;
838 constant[n].show_func=show_boolean;
839 n++;
840
841 constant[n].token="LO.socket_logfile";
842 constant[n].deflt=DEFLT_SOCKET_LOGFILE;
843 constant[n].set_func=set_string;
844 constant[n].constant_ptr=Global_constants->socket_logfile;
845 constant[n].show_func=show_string;
846 n++;
847
848 constant[n].token="LO.config_logging";
849 constant[n].deflt=DEFLT_CONFIG_LOGGING;
850 constant[n].set_func=set_boolean;
851 constant[n].constant_ptr=Global_constants->config_logging;
852 constant[n].show_func=show_boolean;
853 n++;
854
855 constant[n].token="LO.config_logfile";
856 constant[n].deflt=DEFLT_CONFIG_LOGFILE;
857 constant[n].set_func=set_string;
858 constant[n].constant_ptr=Global_constants->config_logfile;
859 constant[n].show_func=show_string;
860 n++;
861
862 constant[n].token="MI.nrtm_host";
863 constant[n].deflt=DEFLT_NRTM_HOST;
864 constant[n].set_func=set_string;
865 constant[n].constant_ptr=Global_constants->nrtm_host;
866 constant[n].show_func=show_string;
867 n++;
868
869 constant[n].token="MI.nrtm_port";
870 constant[n].deflt=DEFLT_MIRROR_PORT;
871 constant[n].set_func=set_string;
872 constant[n].constant_ptr=Global_constants->nrtm_port;
873 constant[n].show_func=show_string;
874 n++;
875
876 constant[n].token="MI.nrtm_version";
877 constant[n].deflt=DEFLT_NRTM_VERSION;
878 constant[n].set_func=set_int;
879 constant[n].constant_ptr=Global_constants->nrtm_version;
880 constant[n].show_func=show_int;
881 n++;
882
883 constant[n].token="MI.nrtm_delay";
884 constant[n].deflt=DEFLT_NRTM_DELAY;
885 constant[n].set_func=set_int;
886 constant[n].constant_ptr=Global_constants->nrtm_delay;
887 constant[n].show_func=show_int;
888 n++;
889
890 constant[n].token="MI.nrtm_cserialfile";
891 constant[n].deflt=DEFLT_NRTM_CSERFILE;
892 constant[n].set_func=set_string;
893 constant[n].constant_ptr=Global_constants->nrtm_cserialfile;
894 constant[n].show_func=show_string;
895 n++;
896
897 constant[n].token="MI.nrtm_logfile";
898 constant[n].deflt=DEFLT_NRTM_LOGFILE;
899 constant[n].set_func=set_string;
900 constant[n].constant_ptr=Global_constants->nrtm_logfile;
901 constant[n].show_func=show_string;
902 n++;
903
904 constant[n].token="MI.do_nrtm";
905 constant[n].deflt="1";
906 constant[n].set_func=set_int;
907 constant[n].constant_ptr=Global_constants->do_nrtm;
908 constant[n].show_func=show_int;
909 n++;
910
911 constant[n].token="UD.update_mode";
912 constant[n].deflt=DEFLT_UPDATE_MODE;
913 constant[n].set_func=set_int;
914 constant[n].constant_ptr=Global_constants->update_mode;
915 constant[n].show_func=show_int;
916 n++;
917
918 constant[n].token="UD.do_update";
919 constant[n].deflt="1";
920 constant[n].set_func=set_int;
921 constant[n].constant_ptr=Global_constants->do_update;
922 constant[n].show_func=show_int;
923 n++;
924
925 constant[n].token="CO.config_file";
926 constant[n].deflt=DEFLT_CONFIG_FILE;
927 constant[n].set_func=set_string;
928 constant[n].constant_ptr=Global_constants->config_file;
929 constant[n].show_func=show_string;
930 n++;
931
932 constant[n].token=NULL;
933
934 } /* init_constants() */
935
936
937 /* CO_to_string() */
938 /*++++++++++++++++++++++++++++++++++++++
939 Returns the constants as a string.
940
941 More:
942 +html+ <PRE>
943 Authors:
944 ottrey
945
946 +html+ </PRE><DL COMPACT>
947 +html+ <DT>Online References:
948 +html+ <DD><UL>
949 +html+ </UL></DL>
950
951 ++++++++++++++++++++++++++++++++++++++*/
952 char *CO_to_string(void) {
/* [<][>][^][v][top][bottom][index][help] */
953 char *consts;
954 const char *token;
955 char *value;
956 char tmp_consts[2048];
957 char tmp_const[1024];
958 int i=0;
959
960 sprintf(tmp_consts, "Constants = { ");
961 while(constant[i].token != NULL) {
962 token = constant[i].token;
963 value = constant[i].show_func(constant[i].constant_ptr);
964 sprintf(tmp_const, "\n[%s]=\"%s\"", token, value);
965 wr_free(value); /* Otherwise we have memory leaks */
966 strcat(tmp_consts, tmp_const);
967 i++;
968 }
969 strcat(tmp_consts, "}");
970
971 /* consts = calloc(1, strlen(tmp_consts)+1); */
972 dieif( wr_malloc((void **)&consts, strlen(tmp_consts)+1) != UT_OK);
973
974 strcpy(consts, tmp_consts);
975
976 return consts;
977 } /* CO_to_string() */
978
979
980 char *CO_const_to_string(char *name) {
/* [<][>][^][v][top][bottom][index][help] */
981 char *result=NULL;
982 int i;
983
984 for (i=0; constant[i].token != NULL; i++) {
985 if (strcmp(constant[i].token, name) == 0) {
986 result = constant[i].show_func(constant[i].constant_ptr);
987 break;
988 }
989 }
990
991 return result;
992 } /* CO_const_to_string() */
993
994 /* CO_set_const() */
995 /*++++++++++++++++++++++++++++++++++++++
996 Sets the value of one constant. Returns 0 if no error.
997
998 More:
999 +html+ <PRE>
1000 Authors:
1001 ottrey
1002
1003 +html+ </PRE><DL COMPACT>
1004 +html+ <DT>Online References:
1005 +html+ <DD><UL>
1006 +html+ </UL></DL>
1007
1008 ++++++++++++++++++++++++++++++++++++++*/
1009 int CO_set_const(char *name, char *value) {
/* [<][>][^][v][top][bottom][index][help] */
1010 int result=1;
1011 int i;
1012
1013 for (i=0; constant[i].token != NULL; i++) {
1014 if (strcmp(constant[i].token, name) == 0) {
1015 result = constant[i].set_func((void *)constant[i].constant_ptr, value);
1016 break;
1017 }
1018 }
1019
1020 return result;
1021 } /* CO_set_const() */
1022
1023
1024 /* CO_set() */
1025 /*++++++++++++++++++++++++++++++++++++++
1026 Sets the constants from the properties module.
1027 Returns the number of constants set.
1028
1029 More:
1030 +html+ <PRE>
1031 Authors:
1032 ottrey
1033 +html+ </PRE><DL COMPACT>
1034 +html+ <DT>Online References:
1035 +html+ <DD><UL>
1036 +html+ <LI><A HREF="../src/.properties">.properties</A>
1037 +html+ </UL></DL>
1038
1039 ++++++++++++++++++++++++++++++++++++++*/
1040 char *CO_set(void) {
/* [<][>][^][v][top][bottom][index][help] */
1041 int i;
1042 int set_count=0;
1043 int set;
1044 char result_buff[256];
1045 char *result;
1046 char *property;
1047
1048 /* Initialize if necessary */
1049 if (Global_constants == NULL) {
1050 /* Global_constants = (Constants)calloc(1, sizeof(struct _Constants)); */
1051 dieif( wr_calloc((void **)&Global_constants, 1,
1052 sizeof(struct _Constants)) != UT_OK);
1053
1054 init_constants();
1055 }
1056
1057 for (i=0; constant[i].token != NULL; i++) {
1058 property = PR_get_property(constant[i].token, constant[i].deflt);
1059 set = constant[i].set_func((void *)constant[i].constant_ptr, property);
1060 wr_free(property);
1061 if (set == 0) {
1062 set_count++;
1063 }
1064 }
1065
1066 sprintf(result_buff, "%d out of %d constant(s) set.", set_count, i);
1067
1068 /* result = (char *)calloc(1, strlen(result_buff)+1); */
1069 dieif( wr_malloc((void **)&result, strlen(result_buff)+1) != UT_OK);
1070 strcpy(result, result_buff);
1071
1072 return result;
1073 } /* CO_set() */
1074