Source File modules/co/constants.c

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