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