1 | /***************************************
2 | $Revision: 1.11 $
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 | /*+ Maximum number of constants. +*/
63 | #define MAX_CONSTS 100
64 |
65 | /*+ Default values for constants. +*/
66 | #define DEFLT_MAX_THREADS "10"
67 | #define DEFLT_WHOIS_PORT "0"
68 | #define DEFLT_CONFIG_PORT "0"
69 | #define DEFLT_MIRROR_PORT "0"
70 | #define DEFLT_UPDATE_PORT "0"
71 | #define DEFLT_HOST "mysql.database.net"
72 | #define DEFLT_USER "xxx"
73 | #define DEFLT_PASSWORD "xxx"
74 | #define DEFLT_DATABASE_PORT "3306"
75 | #define DEFLT_DATABASE "RIPE"
76 | #define DEFLT_QUERY "SHOW TABLES"
77 | #define DEFLT_IN_QUERY "SELECT * FROM inetnum"
78 | #define DEFLT_RT_QUERY "SELECT * FROM route"
79 | #define DEFLT_AUTHENTICATE "0"
80 | #define DEFLT_WHOIS_SUSPENDED "0"
81 | #define DEFLT_WELCOME "Welcome to the whois R.I.P. server.\n"
82 | #define DEFLT_PROMPT "whois R.I.P. config> "
83 | #define DEFLT_CLEAR_SCREEN "0"
84 | #define DEFLT_SLEEP_TIME "1"
85 | #define DEFLT_ACCOUNTING "0"
86 | #define DEFLT_QUERY_LOGGING "1"
87 | #define DEFLT_QUERY_LOGFILE "stdout"
88 | #define DEFLT_INSTR_LOGGING "1"
89 | #define DEFLT_INSTR_LOGFILE "stdout"
90 | #define DEFLT_COMND_LOGGING "1"
91 | #define DEFLT_COMND_LOGFILE "stdout"
92 | #define DEFLT_TESTS_LOGGING "1"
93 | #define DEFLT_TESTS_LOGFILE "stdout"
94 | #define DEFLT_THREAD_LOGGING "1"
95 | #define DEFLT_THREAD_LOGFILE "stdout"
96 | #define DEFLT_SOCKET_LOGGING "1"
97 | #define DEFLT_SOCKET_LOGFILE "stdout"
98 | #define DEFLT_CONFIG_LOGGING "1"
99 | #define DEFLT_CONFIG_LOGFILE "stdout"
100 | #define DEFLT_NRTM_HOST "nrtm.nowhere.xx"
101 | #define DEFLT_NRTM_VERSION "1"
102 | #define DEFLT_NRTM_DELAY "600"
103 | #define DEFLT_NRTM_CSERFILE "RIPE.CURRENTSERIAL"
104 | #define DEFLT_NRTM_LOGFILE "nrtm.log"
105 | #define DEFLT_UPDATE_MODE "0"
106 |
107 | /*+ Each constant has a +*/
108 | struct _constant {
109 | const char *token; /*+ Token to be found in properties file. +*/
110 | const char *deflt; /*+ Default value for the constant. +*/
111 | int (*set_func)(void *, char *); /*+ Function to set the constant. +*/
112 | void *constant_ptr; /*+ Pointer to the constant value +*/
113 | char *(*show_func)(void *); /*+ Function to show the constant. +*/
114 | };
115 |
116 |
117 | /*+ The Constants array has a +*/
118 | typedef struct _Constants {
119 | int max_threads[1]; /*+ Maximum number of server threads. +*/
120 | char whois_port[64]; /*+ Port for whois clients to rendezvous with. +*/
121 | char config_port[64]; /*+ Port for config clients to rendezvous with. +*/
122 | char mirror_port[64]; /*+ Port for mirror clients to rendezvous with. +*/
123 | char update_port[64]; /*+ Port for DBupdate clients to rendezvous with. +*/
124 | char host[64]; /*+ Host for the database. +*/
125 | char user[64]; /*+ User for the database. +*/
126 | char password[64]; /*+ Password for the database. +*/
127 | int database_port[1]; /*+ Port for the database. +*/
128 | char database[64]; /*+ Database name. +*/
129 | char query[1024]; /*+ Query for the database. +*/
130 | char in_query[1024]; /*+ Query for the radix tree initialization. +*/
131 | char rt_query[1024]; /*+ Query for the radix tree initialization. +*/
132 | int authenticate[1]; /*+ Authenticate users. +*/
133 | int whois_suspended[1]; /*+ Suspend the whois server. +*/
134 | char welcome[1024]; /*+ Welcome for config protocol. +*/
135 | char prompt[1024]; /*+ Prompt for config protocol. +*/
136 | int clear_screen[1]; /*+ Clear screen after config commands. +*/
137 | int sleep_time[1]; /*+ Sleep time (in sec) between config commands. +*/
138 | int accounting[1]; /*+ Conduct accounting on whois queries. +*/
139 | int query_logging[1]; /*+ Log the SQL queries. +*/
140 | char query_logfile[1024]; /*+ Query logfile for the database. +*/
141 | int instr_logging[1]; /*+ Log the whois instrucs. +*/
142 | char instr_logfile[1024]; /*+ Query logfile for the whois instrucs. +*/
143 | int comnd_logging[1]; /*+ Log the whois commands. +*/
144 | char comnd_logfile[1024]; /*+ Query logfile for the whois commands. +*/
145 | int tests_logging[1]; /*+ Log the whois tests. +*/
146 | char tests_logfile[1024]; /*+ Query logfile for the whois tests. +*/
147 | int thread_logging[1]; /*+ Log the whois threads. +*/
148 | char thread_logfile[1024]; /*+ Query logfile for the whois threads. +*/
149 | int socket_logging[1]; /*+ Log the socket. +*/
150 | char socket_logfile[1024]; /*+ Logfile for the socket. +*/
151 | int config_logging[1]; /*+ Log the config. +*/
152 | char config_logfile[1024]; /*+ Logfile for the config. +*/
153 | char nrtm_host[64];/*+ NRTM server +*/
154 | char nrtm_port[64];/*+ Port of NRTM server when we are acting as a client +*/
155 | int nrtm_version[1];/*+ NRTM protocol version +*/
156 | int nrtm_delay[1];/*+ delay between syncs +*/
157 | char nrtm_cserialfile[1024];/*+ name of the file containing current serial +*/
158 | char nrtm_logfile[1024];/*+ NRTM logfile for failure reports +*/
159 | int do_nrtm[1];
160 | int update_mode[1];/*+ protected/unprotected (==dummy_allowed) +*/
161 | int do_update[1];
162 | } *Constants;
163 |
164 |
165 | /*
166 | * Global Variables
167 | */
168 | /*+ The array of Global Constants. +*/
169 | static Constants Global_constants=NULL;
170 |
171 | /*
172 | * Set Functions
173 | */
174 | static int set_string(void *constant, char *value) {
175 |
176 | strcpy((char *)constant, value);
177 |
178 | return 0;
179 | } /* set_string() */
180 |
181 | static int set_int(void *constant, char *value) {
182 | int i;
183 |
184 | i = atol(value);
185 | ((int *)constant)[0] = i;
186 |
187 | return 0;
188 | } /* set_int() */
189 |
190 | static int set_boolean(void *constant, char *value) {
191 | int result=1;
192 | int i;
193 |
194 | i = atol(value);
195 |
196 | /* If a valid boolean */
197 | if ( (i == 0) || (i == 1)) {
198 | ((int *)constant)[0] = i;
199 | result = 0;
200 | }
201 |
202 | return result;
203 | } /* set_boolean() */
204 |
205 |
206 | /*
207 | * Show Functions
208 | */
209 | /* AR. changed for unification with oter show funcs */
210 | static char *show_string(void *constant) {
211 | char *tmp;
212 |
213 | // tmp = calloc(1, strlen((char *)constant)+1);
214 | dieif( wr_malloc((void **)&tmp, strlen((char *)constant)+1) != UT_OK);
215 |
216 | strcpy(tmp, (char *)constant);
217 | /* return((char *)constant); */
218 | return tmp;
219 | } /* show_string() */
220 |
221 | static char *show_int(void *constant) {
222 | char *tmp;
223 |
224 | // tmp = calloc(1, 64);
225 | dieif( wr_malloc((void **)&tmp, 64) != UT_OK);
226 |
227 | sprintf(tmp, "%d", ((int *)constant)[0]);
228 | return tmp;
229 | } /* show_int() */
230 |
231 | static char *show_boolean(void *constant) {
232 | char *tmp;
233 |
234 | // tmp = calloc(1, 64);
235 | dieif( wr_malloc((void **)&tmp, 64) != UT_OK);
236 |
237 | sprintf(tmp, "%d", ((int *)constant)[0]);
238 | return tmp;
239 | } /* show_boolean() */
240 |
241 |
242 | /*
243 | * Get Functions
244 | */
245 | int CO_get_max_threads() {
246 | return Global_constants->max_threads[0];
247 | }
248 |
249 | const char *CO_get_whois_port() {
250 | return Global_constants->whois_port;
251 | }
252 |
253 | const char *CO_get_config_port() {
254 | return Global_constants->config_port;
255 | }
256 |
257 | const char *CO_get_mirror_port() {
258 | return Global_constants->mirror_port;
259 | }
260 |
261 | const char *CO_get_update_port() {
262 | return Global_constants->update_port;
263 | }
264 |
265 | const char *CO_get_host() {
266 | return Global_constants->host;
267 | }
268 |
269 | const char *CO_get_user() {
270 | return Global_constants->user;
271 | }
272 |
273 | const char *CO_get_password() {
274 | return Global_constants->password;
275 | }
276 |
277 | int CO_get_database_port() {
278 | return Global_constants->database_port[0];
279 | }
280 |
281 | const char *CO_get_database() {
282 | return Global_constants->database;
283 | }
284 |
285 | const char *CO_get_query() {
286 | return Global_constants->query;
287 | }
288 |
289 | const char *CO_get_in_query() {
290 | return Global_constants->in_query;
291 | }
292 |
293 | const char *CO_get_rt_query() {
294 | return Global_constants->rt_query;
295 | }
296 |
297 | int CO_get_authenticate() {
298 | return Global_constants->authenticate[0];
299 | }
300 |
301 | int CO_get_whois_suspended() {
302 | return Global_constants->whois_suspended[0];
303 | }
304 |
305 | const char *CO_get_welcome() {
306 | return Global_constants->welcome;
307 | }
308 |
309 | const char *CO_get_prompt() {
310 | return Global_constants->prompt;
311 | }
312 |
313 | int CO_get_clear_screen() {
314 | return Global_constants->clear_screen[0];
315 | }
316 |
317 | int CO_get_sleep_time() {
318 | return Global_constants->sleep_time[0];
319 | }
320 |
321 | int CO_get_accounting() {
322 | return Global_constants->accounting[0];
323 | }
324 |
325 | int CO_get_query_logging() {
326 | return Global_constants->query_logging[0];
327 | }
328 |
329 | const char *CO_get_query_logfile() {
330 | return Global_constants->query_logfile;
331 | }
332 |
333 | int CO_get_instr_logging() {
334 | return Global_constants->instr_logging[0];
335 | }
336 |
337 | const char *CO_get_instr_logfile() {
338 | return Global_constants->instr_logfile;
339 | }
340 |
341 | int CO_get_comnd_logging() {
342 | return Global_constants->comnd_logging[0];
343 | }
344 |
345 | const char *CO_get_comnd_logfile() {
346 | return Global_constants->comnd_logfile;
347 | }
348 |
349 | int CO_get_tests_logging() {
350 | return Global_constants->tests_logging[0];
351 | }
352 |
353 | const char *CO_get_tests_logfile() {
354 | return Global_constants->tests_logfile;
355 | }
356 |
357 | int CO_get_thread_logging() {
358 | return Global_constants->thread_logging[0];
359 | }
360 |
361 | const char *CO_get_thread_logfile() {
362 | return Global_constants->thread_logfile;
363 | }
364 |
365 | int CO_get_socket_logging() {
366 | return Global_constants->socket_logging[0];
367 | }
368 |
369 | const char *CO_get_socket_logfile() {
370 | return Global_constants->socket_logfile;
371 | }
372 |
373 | int CO_get_config_logging() {
374 | return Global_constants->config_logging[0];
375 | }
376 |
377 | const char *CO_get_config_logfile() {
378 | return Global_constants->config_logfile;
379 | }
380 |
381 | /*++++ NRTM stuff ++++*/
382 |
383 | const char *CO_get_nrtm_host() {
384 | return Global_constants->nrtm_host;
385 | }
386 |
387 | const char *CO_get_nrtm_port() {
388 | return Global_constants->nrtm_port;
389 | }
390 |
391 | int CO_get_nrtm_version() {
392 | return Global_constants->nrtm_version[0];
393 | }
394 |
395 | int CO_get_nrtm_delay() {
396 | return Global_constants->nrtm_delay[0];
397 | }
398 |
399 | const char *CO_get_nrtm_cserialfile() {
400 | return Global_constants->nrtm_cserialfile;
401 | }
402 |
403 | const char *CO_get_nrtm_logfile() {
404 | return Global_constants->nrtm_logfile;
405 | }
406 |
407 | int CO_get_do_nrtm() {
408 | return Global_constants->do_nrtm[0];
409 | }
410 |
411 | int CO_get_update_mode() {
412 | return Global_constants->update_mode[0];
413 | }
414 |
415 |
416 |
417 | int CO_get_do_update() {
418 | return Global_constants->do_update[0];
419 | }
420 |
421 |
422 |
423 | /*+
424 | * Contains the constant definitions for the Token, set_function, show_function.
425 | * (See: _constant)
426 | +*/
427 | static struct _constant constant[MAX_CONSTS];
428 |
429 | /* init_constants() */
430 | /*++++++++++++++++++++++++++++++++++++++
431 | Initialize all the constants.
432 |
433 | More:
434 | +html+ <PRE>
435 | Authors:
436 | ottrey
437 |
438 | +html+ </PRE><DL COMPACT>
439 | +html+ <DT>Online References:
440 | +html+ <DD><UL>
441 | +html+ </UL></DL>
442 |
443 | ++++++++++++++++++++++++++++++++++++++*/
444 | static void init_constants(void) {
445 | int n=0;
446 |
447 | constant[n].token="SV.max_threads";
448 | constant[n].deflt=DEFLT_MAX_THREADS;
449 | constant[n].set_func=set_int;
450 | constant[n].constant_ptr=Global_constants->max_threads;
451 | constant[n].show_func=show_int;
452 | n++;
453 |
454 | constant[n].token="SV.whois_port";
455 | constant[n].deflt=DEFLT_WHOIS_PORT;
456 | constant[n].set_func=set_string;
457 | constant[n].constant_ptr=Global_constants->whois_port;
458 | constant[n].show_func=show_string;
459 | n++;
460 |
461 | constant[n].token="SV.config_port";
462 | constant[n].deflt=DEFLT_CONFIG_PORT;
463 | constant[n].set_func=set_string;
464 | constant[n].constant_ptr=Global_constants->config_port;
465 | constant[n].show_func=show_string;
466 | n++;
467 |
468 | constant[n].token="SV.mirror_port";
469 | constant[n].deflt=DEFLT_MIRROR_PORT;
470 | constant[n].set_func=set_string;
471 | constant[n].constant_ptr=Global_constants->mirror_port;
472 | constant[n].show_func=show_string;
473 | n++;
474 |
475 | constant[n].token="SV.update_port";
476 | constant[n].deflt=DEFLT_UPDATE_PORT;
477 | constant[n].set_func=set_string;
478 | constant[n].constant_ptr=Global_constants->update_port;
479 | constant[n].show_func=show_string;
480 | n++;
481 |
482 | constant[n].token="DB.host";
483 | constant[n].deflt=DEFLT_HOST;
484 | constant[n].set_func=set_string;
485 | constant[n].constant_ptr=Global_constants->host;
486 | constant[n].show_func=show_string;
487 | n++;
488 |
489 | constant[n].token="DB.user";
490 | constant[n].deflt=DEFLT_USER;
491 | constant[n].set_func=set_string;
492 | constant[n].constant_ptr=Global_constants->user;
493 | constant[n].show_func=show_string;
494 | n++;
495 |
496 | constant[n].token="DB.password";
497 | constant[n].deflt=DEFLT_PASSWORD;
498 | constant[n].set_func=set_string;
499 | constant[n].constant_ptr=Global_constants->password;
500 | constant[n].show_func=show_string;
501 | n++;
502 |
503 | constant[n].token="DB.database_port";
504 | constant[n].deflt=DEFLT_DATABASE_PORT;
505 | constant[n].set_func=set_int;
506 | constant[n].constant_ptr=Global_constants->database_port;
507 | constant[n].show_func=show_int;
508 | n++;
509 |
510 | constant[n].token="DB.database";
511 | constant[n].deflt=DEFLT_DATABASE;
512 | constant[n].set_func=set_string;
513 | constant[n].constant_ptr=Global_constants->database;
514 | constant[n].show_func=show_string;
515 | n++;
516 |
517 | constant[n].token="DB.query";
518 | constant[n].deflt=DEFLT_QUERY;
519 | constant[n].set_func=set_string;
520 | constant[n].constant_ptr=Global_constants->query;
521 | constant[n].show_func=show_string;
522 | n++;
523 |
524 | constant[n].token="RX.in_query";
525 | constant[n].deflt=DEFLT_IN_QUERY;
526 | constant[n].set_func=set_string;
527 | constant[n].constant_ptr=Global_constants->in_query;
528 | constant[n].show_func=show_string;
529 | n++;
530 |
531 | constant[n].token="RX.rt_query";
532 | constant[n].deflt=DEFLT_RT_QUERY;
533 | constant[n].set_func=set_string;
534 | constant[n].constant_ptr=Global_constants->rt_query;
535 | constant[n].show_func=show_string;
536 | n++;
537 |
538 | constant[n].token="SV.authenticate";
539 | constant[n].deflt=DEFLT_AUTHENTICATE;
540 | constant[n].set_func=set_boolean;
541 | constant[n].constant_ptr=Global_constants->authenticate;
542 | constant[n].show_func=show_boolean;
543 | n++;
544 |
545 | constant[n].token="SV.whois_suspended";
546 | constant[n].deflt=DEFLT_WHOIS_SUSPENDED;
547 | constant[n].set_func=set_boolean;
548 | constant[n].constant_ptr=Global_constants->whois_suspended;
549 | constant[n].show_func=show_boolean;
550 | n++;
551 |
552 | constant[n].token="PC.welcome";
553 | constant[n].deflt=DEFLT_WELCOME;
554 | constant[n].set_func=set_string;
555 | constant[n].constant_ptr=Global_constants->welcome;
556 | constant[n].show_func=show_string;
557 | n++;
558 |
559 | constant[n].token="PC.prompt";
560 | constant[n].deflt=DEFLT_PROMPT;
561 | constant[n].set_func=set_string;
562 | constant[n].constant_ptr=Global_constants->prompt;
563 | constant[n].show_func=show_string;
564 | n++;
565 |
566 | constant[n].token="PC.clear_screen";
567 | constant[n].deflt=DEFLT_CLEAR_SCREEN;
568 | constant[n].set_func=set_boolean;
569 | constant[n].constant_ptr=Global_constants->clear_screen;
570 | constant[n].show_func=show_boolean;
571 | n++;
572 |
573 | constant[n].token="PC.sleep_time";
574 | constant[n].deflt=DEFLT_SLEEP_TIME;
575 | constant[n].set_func=set_int;
576 | constant[n].constant_ptr=Global_constants->sleep_time;
577 | constant[n].show_func=show_int;
578 | n++;
579 |
580 | constant[n].token="WQ.accounting";
581 | constant[n].deflt=DEFLT_ACCOUNTING;
582 | constant[n].set_func=set_boolean;
583 | constant[n].constant_ptr=Global_constants->accounting;
584 | constant[n].show_func=show_boolean;
585 | n++;
586 |
587 | constant[n].token="LO.query_logging";
588 | constant[n].deflt=DEFLT_QUERY_LOGGING;
589 | constant[n].set_func=set_boolean;
590 | constant[n].constant_ptr=Global_constants->query_logging;
591 | constant[n].show_func=show_boolean;
592 | n++;
593 |
594 | constant[n].token="LO.query_logfile";
595 | constant[n].deflt=DEFLT_QUERY_LOGFILE;
596 | constant[n].set_func=set_string;
597 | constant[n].constant_ptr=Global_constants->query_logfile;
598 | constant[n].show_func=show_string;
599 | n++;
600 |
601 | constant[n].token="LO.instr_logging";
602 | constant[n].deflt=DEFLT_INSTR_LOGGING;
603 | constant[n].set_func=set_boolean;
604 | constant[n].constant_ptr=Global_constants->instr_logging;
605 | constant[n].show_func=show_boolean;
606 | n++;
607 |
608 | constant[n].token="LO.insrt_logfile";
609 | constant[n].deflt=DEFLT_INSTR_LOGFILE;
610 | constant[n].set_func=set_string;
611 | constant[n].constant_ptr=Global_constants->instr_logfile;
612 | constant[n].show_func=show_string;
613 | n++;
614 |
615 | constant[n].token="LO.comnd_logging";
616 | constant[n].deflt=DEFLT_COMND_LOGGING;
617 | constant[n].set_func=set_boolean;
618 | constant[n].constant_ptr=Global_constants->comnd_logging;
619 | constant[n].show_func=show_boolean;
620 | n++;
621 |
622 | constant[n].token="LO.comnd_logfile";
623 | constant[n].deflt=DEFLT_COMND_LOGFILE;
624 | constant[n].set_func=set_string;
625 | constant[n].constant_ptr=Global_constants->comnd_logfile;
626 | constant[n].show_func=show_string;
627 | n++;
628 |
629 | constant[n].token="LO.tests_logging";
630 | constant[n].deflt=DEFLT_TESTS_LOGGING;
631 | constant[n].set_func=set_boolean;
632 | constant[n].constant_ptr=Global_constants->tests_logging;
633 | constant[n].show_func=show_boolean;
634 | n++;
635 |
636 | constant[n].token="LO.tests_logfile";
637 | constant[n].deflt=DEFLT_TESTS_LOGFILE;
638 | constant[n].set_func=set_string;
639 | constant[n].constant_ptr=Global_constants->tests_logfile;
640 | constant[n].show_func=show_string;
641 | n++;
642 |
643 | constant[n].token="LO.thread_logging";
644 | constant[n].deflt=DEFLT_THREAD_LOGGING;
645 | constant[n].set_func=set_boolean;
646 | constant[n].constant_ptr=Global_constants->thread_logging;
647 | constant[n].show_func=show_boolean;
648 | n++;
649 |
650 | constant[n].token="LO.thread_logfile";
651 | constant[n].deflt=DEFLT_THREAD_LOGFILE;
652 | constant[n].set_func=set_string;
653 | constant[n].constant_ptr=Global_constants->thread_logfile;
654 | constant[n].show_func=show_string;
655 | n++;
656 |
657 | constant[n].token="LO.socket_logging";
658 | constant[n].deflt=DEFLT_SOCKET_LOGGING;
659 | constant[n].set_func=set_boolean;
660 | constant[n].constant_ptr=Global_constants->socket_logging;
661 | constant[n].show_func=show_boolean;
662 | n++;
663 |
664 | constant[n].token="LO.socket_logfile";
665 | constant[n].deflt=DEFLT_SOCKET_LOGFILE;
666 | constant[n].set_func=set_string;
667 | constant[n].constant_ptr=Global_constants->socket_logfile;
668 | constant[n].show_func=show_string;
669 | n++;
670 |
671 | constant[n].token="LO.config_logging";
672 | constant[n].deflt=DEFLT_CONFIG_LOGGING;
673 | constant[n].set_func=set_boolean;
674 | constant[n].constant_ptr=Global_constants->config_logging;
675 | constant[n].show_func=show_boolean;
676 | n++;
677 |
678 | constant[n].token="LO.config_logfile";
679 | constant[n].deflt=DEFLT_CONFIG_LOGFILE;
680 | constant[n].set_func=set_string;
681 | constant[n].constant_ptr=Global_constants->config_logfile;
682 | constant[n].show_func=show_string;
683 | n++;
684 |
685 | constant[n].token="MI.nrtm_host";
686 | constant[n].deflt=DEFLT_NRTM_HOST;
687 | constant[n].set_func=set_string;
688 | constant[n].constant_ptr=Global_constants->nrtm_host;
689 | constant[n].show_func=show_string;
690 | n++;
691 |
692 | constant[n].token="MI.nrtm_port";
693 | constant[n].deflt=DEFLT_MIRROR_PORT;
694 | constant[n].set_func=set_string;
695 | constant[n].constant_ptr=Global_constants->nrtm_port;
696 | constant[n].show_func=show_string;
697 | n++;
698 |
699 | constant[n].token="MI.nrtm_version";
700 | constant[n].deflt=DEFLT_NRTM_VERSION;
701 | constant[n].set_func=set_int;
702 | constant[n].constant_ptr=Global_constants->nrtm_version;
703 | constant[n].show_func=show_int;
704 | n++;
705 |
706 | constant[n].token="MI.nrtm_delay";
707 | constant[n].deflt=DEFLT_NRTM_DELAY;
708 | constant[n].set_func=set_int;
709 | constant[n].constant_ptr=Global_constants->nrtm_delay;
710 | constant[n].show_func=show_int;
711 | n++;
712 |
713 | constant[n].token="MI.nrtm_cserialfile";
714 | constant[n].deflt=DEFLT_NRTM_CSERFILE;
715 | constant[n].set_func=set_string;
716 | constant[n].constant_ptr=Global_constants->nrtm_cserialfile;
717 | constant[n].show_func=show_string;
718 | n++;
719 |
720 | constant[n].token="MI.nrtm_logfile";
721 | constant[n].deflt=DEFLT_NRTM_LOGFILE;
722 | constant[n].set_func=set_string;
723 | constant[n].constant_ptr=Global_constants->nrtm_logfile;
724 | constant[n].show_func=show_string;
725 | n++;
726 |
727 | constant[n].token="MI.do_nrtm";
728 | constant[n].deflt="1";
729 | constant[n].set_func=set_int;
730 | constant[n].constant_ptr=Global_constants->do_nrtm;
731 | constant[n].show_func=show_int;
732 | n++;
733 |
734 | constant[n].token="UD.update_mode";
735 | constant[n].deflt=DEFLT_UPDATE_MODE;
736 | constant[n].set_func=set_int;
737 | constant[n].constant_ptr=Global_constants->update_mode;
738 | constant[n].show_func=show_int;
739 | n++;
740 |
741 | constant[n].token="UD.do_update";
742 | constant[n].deflt="1";
743 | constant[n].set_func=set_int;
744 | constant[n].constant_ptr=Global_constants->do_update;
745 | constant[n].show_func=show_int;
746 | n++;
747 |
748 | constant[n].token=NULL;
749 |
750 | } /* init_constants() */
751 |
752 |
753 | /* CO_to_string() */
754 | /*++++++++++++++++++++++++++++++++++++++
755 | Returns the constants as a string.
756 |
757 | More:
758 | +html+ <PRE>
759 | Authors:
760 | ottrey
761 |
762 | +html+ </PRE><DL COMPACT>
763 | +html+ <DT>Online References:
764 | +html+ <DD><UL>
765 | +html+ </UL></DL>
766 |
767 | ++++++++++++++++++++++++++++++++++++++*/
768 | char *CO_to_string(void) {
769 | char *consts;
770 | const char *token;
771 | char *value;
772 | char tmp_consts[2048];
773 | char tmp_const[128];
774 | int i=0;
775 |
776 | sprintf(tmp_consts, "Constants = { ");
777 | while(constant[i].token != NULL) {
778 | token = constant[i].token;
779 | value = constant[i].show_func(constant[i].constant_ptr);
780 | sprintf(tmp_const, "\n[%s]=\"%s\"", token, value);
781 | wr_free(value); /* Otherwise we have memory leaks */
782 | strcat(tmp_consts, tmp_const);
783 | i++;
784 | }
785 | strcat(tmp_consts, "}");
786 |
787 | //consts = calloc(1, strlen(tmp_consts)+1);
788 | dieif( wr_malloc((void **)&consts, strlen(tmp_consts)+1) != UT_OK);
789 |
790 | strcpy(consts, tmp_consts);
791 |
792 | return consts;
793 | } /* CO_to_string() */
794 |
795 |
796 | char *CO_const_to_string(char *name) {
797 | char *result=NULL;
798 | int i;
799 |
800 | for (i=0; constant[i].token != NULL; i++) {
801 | if (strcmp(constant[i].token, name) == 0) {
802 | result = constant[i].show_func(constant[i].constant_ptr);
803 | break;
804 | }
805 | }
806 |
807 | return result;
808 | } /* CO_const_to_string() */
809 |
810 | /* CO_set_const() */
811 | /*++++++++++++++++++++++++++++++++++++++
812 | Sets the value of one constant. Returns 0 if no error.
813 |
814 | More:
815 | +html+ <PRE>
816 | Authors:
817 | ottrey
818 |
819 | +html+ </PRE><DL COMPACT>
820 | +html+ <DT>Online References:
821 | +html+ <DD><UL>
822 | +html+ </UL></DL>
823 |
824 | ++++++++++++++++++++++++++++++++++++++*/
825 | int CO_set_const(char *name, char *value) {
826 | int result=1;
827 | int i;
828 |
829 | for (i=0; constant[i].token != NULL; i++) {
830 | if (strcmp(constant[i].token, name) == 0) {
831 | result = constant[i].set_func((void *)constant[i].constant_ptr, value);
832 | break;
833 | }
834 | }
835 |
836 | return result;
837 | } /* CO_set_const() */
838 |
839 |
840 | /* CO_set() */
841 | /*++++++++++++++++++++++++++++++++++++++
842 | Sets the constants from the properties module.
843 | Returns the number of constants set.
844 |
845 | More:
846 | +html+ <PRE>
847 | Authors:
848 | ottrey
849 | +html+ </PRE><DL COMPACT>
850 | +html+ <DT>Online References:
851 | +html+ <DD><UL>
852 | +html+ <LI><A HREF="../src/.properties">.properties</A>
853 | +html+ </UL></DL>
854 |
855 | ++++++++++++++++++++++++++++++++++++++*/
856 | char *CO_set(void) {
857 | int i;
858 | int set_count=0;
859 | int set;
860 | char result_buff[256];
861 | char *result;
862 | char *property;
863 |
864 | /* Initialize if necessary */
865 | if (Global_constants == NULL) {
866 | // Global_constants = (Constants)calloc(1, sizeof(struct _Constants));
867 | dieif( wr_calloc((void **)&Global_constants, 1,
868 | sizeof(struct _Constants)) != UT_OK);
869 |
870 | init_constants();
871 | }
872 |
873 | for (i=0; constant[i].token != NULL; i++) {
874 | property = PR_get_property(constant[i].token, constant[i].deflt);
875 | set = constant[i].set_func((void *)constant[i].constant_ptr, property);
876 | wr_free(property);
877 | if (set == 0) {
878 | set_count++;
879 | }
880 | }
881 |
882 | sprintf(result_buff, "%d out of %d constant(s) set.", set_count, i);
883 |
884 | // result = (char *)calloc(1, strlen(result_buff)+1);
885 | dieif( wr_malloc((void **)&result, strlen(result_buff)+1) != UT_OK);
886 | strcpy(result, result_buff);
887 |
888 | return result;
889 | } /* CO_set() */
890 |