[pisa-src] r1410 - in trunk/pisasd: sdconf.c sdconf.h sdmain.c

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Thu, 29 Oct 2009 15:06:56 +0100

Author: tjansen
Date: Thu Oct 29 15:06:56 2009
New Revision: 1410

Log:
There is only one globally available sd_cfg, no need to pass pointers around.

Modified:
   trunk/pisasd/sdconf.c
   trunk/pisasd/sdconf.h
   trunk/pisasd/sdmain.c

Modified: trunk/pisasd/sdconf.c
==============================================================================
--- trunk/pisasd/sdconf.c       Thu Oct 29 15:05:18 2009        (r1409)
+++ trunk/pisasd/sdconf.c       Thu Oct 29 15:06:56 2009        (r1410)
@@ -29,87 +29,77 @@
 
 /**
  * Initialize general configuration of server daemon.
- *
- * @param sdconf  sd_conf structure to be initialized
  */
-void sdconf_init(sd_conf *sdconf)
+void sdconf_init(void)
 {
-       memset(sdconf->conffile, 0, sizeof(sdconf->conffile));
-       memset(sdconf->debuglevel, 0, sizeof(sdconf->debuglevel));
-       memset(sdconf->ifname_eth, 0, sizeof(sdconf->ifname_eth));
-       memset(&sdconf->ipaddr, 0, sizeof(sdconf->ipaddr));
-       memset(&sdconf->dyn_min, 0, sizeof(sdconf->dyn_min));
-       memset(&sdconf->dyn_max, 0, sizeof(sdconf->dyn_max));
-       memset(&sdconf->dyn_mask, 0, sizeof(sdconf->dyn_mask));
+       memset(sd_cfg.conffile, 0, sizeof(sd_cfg.conffile));
+       memset(sd_cfg.debuglevel, 0, sizeof(sd_cfg.debuglevel));
+       memset(sd_cfg.ifname_eth, 0, sizeof(sd_cfg.ifname_eth));
+       memset(&sd_cfg.ipaddr, 0, sizeof(sd_cfg.ipaddr));
+       memset(&sd_cfg.dyn_min, 0, sizeof(sd_cfg.dyn_min));
+       memset(&sd_cfg.dyn_max, 0, sizeof(sd_cfg.dyn_max));
+       memset(&sd_cfg.dyn_mask, 0, sizeof(sd_cfg.dyn_mask));
 
        memset(authorized_cfg_file, 0, sizeof(authorized_cfg_file));
 
-       sdconf->port_control = 0;
-       sdconf->port_data = 0;
-       sdconf->is_relay = 0;
+       sd_cfg.port_control = 0;
+       sd_cfg.port_data = 0;
+       sd_cfg.is_relay = 0;
 
-       memset(&sdconf->nat_up, 0, sizeof(sdconf->nat_up));
-       memset(&sdconf->nat_down, 0, sizeof(sdconf->nat_down));
+       memset(&sd_cfg.nat_up, 0, sizeof(sd_cfg.nat_up));
+       memset(&sd_cfg.nat_down, 0, sizeof(sd_cfg.nat_down));
 }
 
 /**
  * Destroy general configurations of server daemon.
- *
- * @param sdconf  sd_conf structure to be destroyed
  */
-void sdconf_destroy(sd_conf *sdconf)
+void sdconf_destroy(void)
 {
-       pisa_hitlist_destroy(sdconf->hit_allowed);
+       pisa_hitlist_destroy(sd_cfg.hit_allowed);
        pisa_cfg_cleanup();
 }
 
 /**
  * Setup the configuration file before doing any read/write operations.
- *
- * @param sdconf  sd_conf structure to be set up
  */
-void sdconf_setup_conffile(sd_conf *sdconf)
+void sdconf_setup_conffile(void)
 {
        /* Use default path if no config file was given per commandline 
argument */
-       if (sdconf->conffile[0] == '\0') {
+       if (sd_cfg.conffile[0] == '\0') {
                        pisa_check_and_create_dir(PISA_CONFDIR_PATH, 
DEFAULT_CONFIG_DIR_MODE);
-                       strncpy(sdconf->conffile, PISASD_CONFFILE_FULLPATH, 
sizeof(sdconf->conffile));
+                       strncpy(sd_cfg.conffile, PISASD_CONFFILE_FULLPATH, 
sizeof(sd_cfg.conffile));
        }
 
-       if (pisa_cfg_setup_file(sdconf->conffile) <= 0) {
-               PISA_ERROR("Cannot read the config file %s\n", 
sdconf->conffile);
+       if (pisa_cfg_setup_file(sd_cfg.conffile) <= 0) {
+               PISA_ERROR("Cannot read the config file %s\n", sd_cfg.conffile);
                exit(EXIT_FAILURE);
        }
 
-       PISA_INFO("Using configuration file %s\n", sdconf->conffile);
+       PISA_INFO("Using configuration file %s\n", sd_cfg.conffile);
 }
 
-void sdconf_read_is_relay(sd_conf *sdconf)
+void sdconf_read_is_relay(void)
 {
-        pisa_cfg_get_bool_value("is_relay",&sdconf->is_relay);
+        pisa_cfg_get_bool_value("is_relay",&sd_cfg.is_relay);
 }
 
 /**
  * Read the debug level from the configuration file.
- *
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-static void sdconf_read_debuglevel(sd_conf *sdconf)
+static void sdconf_read_debuglevel(void)
 {
        /* Determine the appropriate interface name for listening connections */
-       if (*sdconf->debuglevel == '\0') {
-               if (!pisa_cfg_get_string_value("debuglevel", 
sdconf->debuglevel, sizeof(sdconf->debuglevel))) {
+       if (*sd_cfg.debuglevel == '\0') {
+               if (!pisa_cfg_get_string_value("debuglevel", sd_cfg.debuglevel, 
sizeof(sd_cfg.debuglevel))) {
                        PISA_DEBUG("Using the default debuglevel %s\n",
                                   PISASD_DEFAULT_DEBUGLEVEL);
-                       strncpy(sdconf->debuglevel, PISASD_DEFAULT_DEBUGLEVEL, 
sizeof(sdconf->debuglevel));
+                       strncpy(sd_cfg.debuglevel, PISASD_DEFAULT_DEBUGLEVEL, 
sizeof(sd_cfg.debuglevel));
                }
        }
 }
 
 /**
  * Read the debug type mask from the configuration file.
- *
- * @param cdconf  cd_conf structure where conf settings are stored
  */
 static void sdconf_read_debugtypemask(void)
 {
@@ -121,73 +111,65 @@
 
 /**
  * Read the ethernet interface name from the configuration file.
- *
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-static void sdconf_read_ifname_eth(sd_conf *sdconf)
+static void sdconf_read_ifname_eth(void)
 {
        /* Determine the appropriate ethernet interface name for listening 
connections */
-       if (*sdconf->ifname_eth == '\0') {
-               if (!pisa_cfg_get_string_value("interface_eth", 
sdconf->ifname_eth, sizeof(sdconf->ifname_eth))) {
+       if (*sd_cfg.ifname_eth == '\0') {
+               if (!pisa_cfg_get_string_value("interface_eth", 
sd_cfg.ifname_eth, sizeof(sd_cfg.ifname_eth))) {
                        PISA_DEBUG("Using the default ethernet interface name 
%s\n",
                                   PISASD_DEFAULT_IFNAME_ETH);
-                       strncpy(sdconf->ifname_eth, PISASD_DEFAULT_IFNAME_ETH, 
sizeof(sdconf->ifname_eth));
+                       strncpy(sd_cfg.ifname_eth, PISASD_DEFAULT_IFNAME_ETH, 
sizeof(sd_cfg.ifname_eth));
                }
        }
 }
 
 /**
  * Read the listening port number from the configuration file.
- *
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-static void sdconf_read_portnumber_control(sd_conf *sdconf)
+static void sdconf_read_portnumber_control(void)
 {
        /* Determine the appropriate port number for listening connections */
-       if (sdconf->port_control > MAX_PORTNUM) {
+       if (sd_cfg.port_control > MAX_PORTNUM) {
                PISA_ERROR("Error: Port number must be %d at most!\n"
                           "Run with -h to see usage\n",
                           MAX_PORTNUM);
                exit(EXIT_FAILURE);
-       } else if (sdconf->port_control == 0) {
-               if (!pisa_cfg_get_int_value("port_control", 
&sdconf->port_control)) {
+       } else if (sd_cfg.port_control == 0) {
+               if (!pisa_cfg_get_int_value("port_control", 
&sd_cfg.port_control)) {
                        PISA_DEBUG("Using the default port number %d\n",
                                   PISASD_DEFAULT_PORTNUM_CONTROL);
-                       sdconf->port_control = PISASD_DEFAULT_PORTNUM_CONTROL;
+                       sd_cfg.port_control = PISASD_DEFAULT_PORTNUM_CONTROL;
                }
        }
 }
 
 /**
  * Read the listening port number from the configuration file.
- *
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-static void sdconf_read_portnumber_data(sd_conf *sdconf)
+static void sdconf_read_portnumber_data(void)
 {
        /* Determine the appropriate port number for listening connections */
-       if (sdconf->port_data > MAX_PORTNUM) {
+       if (sd_cfg.port_data > MAX_PORTNUM) {
                PISA_ERROR("Error: Port number must be %d at most!\n"
                           "Run with -h to see usage\n",
                           MAX_PORTNUM);
                exit(EXIT_FAILURE);
-       } else if (sdconf->port_data == 0) {
-               if (!pisa_cfg_get_int_value("port_data", &sdconf->port_data)) {
+       } else if (sd_cfg.port_data == 0) {
+               if (!pisa_cfg_get_int_value("port_data", &sd_cfg.port_data)) {
                        PISA_DEBUG("Using the default port number %d\n",
                                   PISASD_DEFAULT_PORTNUM_DATA);
-                       sdconf->port_data = PISASD_DEFAULT_PORTNUM_DATA;
+                       sd_cfg.port_data = PISASD_DEFAULT_PORTNUM_DATA;
                }
        }
 }
 
 /**
  * Set the global debug level variable
- *
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-void sdconf_set_debuglevel(sd_conf *sdconf)
+void sdconf_set_debuglevel(void)
 {
-       char *dlstr = sdconf->debuglevel;
+       char *dlstr = sd_cfg.debuglevel;
        int debuglevel = PISA_LOGDEBUG_MEDIUM;
 
        if (strncasecmp(dlstr, "all", MAX_DEBUGLEVEL_STR) == 0) {
@@ -207,7 +189,6 @@
 
 /**
  * Setup the authorized_hosts configuration file before doing any read/write 
operations.
- *
  */
 void sdconf_setup_authorized_hosts_conffile(void)
 {
@@ -226,9 +207,8 @@
 
 /**
  * Reads the server ip from the pisasd.conf file
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-static void sdconf_read_srv_ipv4(sd_conf *sdconf)
+static void sdconf_read_srv_ipv4(void)
 {
        char ip_tmp[INET_ADDRSTRLEN];
 
@@ -238,7 +218,7 @@
        }
        else
        {
-               if(inet_pton(AF_INET, ip_tmp, &sdconf->ipaddr) != 1)
+               if(inet_pton(AF_INET, ip_tmp, &sd_cfg.ipaddr) != 1)
                {
                        PISA_ERROR("Error: Reading server ip address 
failed.\n");
                }
@@ -247,9 +227,8 @@
 
 /**
  * Reads the minimum ip for the dynamic ip range from the pisasd.conf file
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-static void sdconf_read_dyn_min(sd_conf *sdconf)
+static void sdconf_read_dyn_min(void)
 {
        char ip_tmp[INET_ADDRSTRLEN];
 
@@ -259,7 +238,7 @@
        }
        else
        {
-               if(inet_pton(AF_INET, ip_tmp, &sdconf->dyn_min) != 1)
+               if(inet_pton(AF_INET, ip_tmp, &sd_cfg.dyn_min) != 1)
                {
                        PISA_ERROR("Error: Minumum ip address is not an IPv4 
address.\n");
                }
@@ -268,9 +247,8 @@
 
 /**
  * Reads the maximum ip for the dynamic ip range from the pisasd.conf file
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-static void sdconf_read_dyn_max(sd_conf *sdconf)
+static void sdconf_read_dyn_max(void)
 {
        char ip_tmp[INET_ADDRSTRLEN];
 
@@ -280,7 +258,7 @@
        }
        else
        {
-               if(inet_pton(AF_INET, ip_tmp, &sdconf->dyn_max) != 1)
+               if(inet_pton(AF_INET, ip_tmp, &sd_cfg.dyn_max) != 1)
                {
                        PISA_ERROR("Error: Maximum ip address is not an IPv4 
address.\n");
                }
@@ -289,9 +267,8 @@
 
 /**
  * Reads the netmask for the dynamic ip range from the pisasd.conf file
- * @param sdconf  sd_conf structure where conf settings are stored
  */
-static void sdconf_read_dyn_netmask(sd_conf *sdconf)
+static void sdconf_read_dyn_netmask(void)
 {
        char ip_tmp[INET_ADDRSTRLEN];
 
@@ -301,7 +278,7 @@
        }
        else
        {
-               if(inet_pton(AF_INET, ip_tmp, &sdconf->dyn_mask) != 1)
+               if(inet_pton(AF_INET, ip_tmp, &sd_cfg.dyn_mask) != 1)
                {
                        PISA_ERROR("Error: Not a valid netmask.\n");
                }
@@ -311,23 +288,23 @@
 /**
  * Read basic settings from the configuration file
  */
-void sdconf_read_basic_confs(sd_conf *sdconf)
+void sdconf_read_basic_confs(void)
 {
        /* Read several configuration from pisasd.conf. */
-       sdconf_read_debuglevel(sdconf);
+       sdconf_read_debuglevel();
        sdconf_read_debugtypemask();
-       sdconf_read_ifname_eth(sdconf);
-       sdconf_read_portnumber_control(sdconf);
-       sdconf_read_portnumber_data(sdconf);
-       sdconf_read_srv_ipv4(sdconf);
-       sdconf_read_dyn_min(sdconf);
-       sdconf_read_dyn_max(sdconf);
-       sdconf_read_dyn_netmask(sdconf);
+       sdconf_read_ifname_eth();
+       sdconf_read_portnumber_control();
+       sdconf_read_portnumber_data();
+       sdconf_read_srv_ipv4();
+       sdconf_read_dyn_min();
+       sdconf_read_dyn_max();
+       sdconf_read_dyn_netmask();
 
-       sdconf_read_is_relay(sdconf);
+       sdconf_read_is_relay();
        /* NAT commands */
-       pisa_cfg_get_string_value("nat_up",sdconf->nat_up,NAT_STRING_MAX);
-       pisa_cfg_get_string_value("nat_down",sdconf->nat_down,NAT_STRING_MAX);
+       pisa_cfg_get_string_value("nat_up",sd_cfg.nat_up,NAT_STRING_MAX);
+       pisa_cfg_get_string_value("nat_down",sd_cfg.nat_down,NAT_STRING_MAX);
        /* Read a list of allowed HITs from authorized_hosts.cfg. */
-       sdconf->hit_allowed = pisa_hitlist_build("allowed_hosts");
+       sd_cfg.hit_allowed = pisa_hitlist_build("allowed_hosts");
 }

Modified: trunk/pisasd/sdconf.h
==============================================================================
--- trunk/pisasd/sdconf.h       Thu Oct 29 15:05:18 2009        (r1409)
+++ trunk/pisasd/sdconf.h       Thu Oct 29 15:06:56 2009        (r1410)
@@ -49,12 +49,12 @@
 /**
  * This must be called before any other call to the sdconf module.
  */
-void sdconf_init(sd_conf *sdconf);
-void sdconf_destroy(sd_conf *sdconf);
-void sdconf_set_debuglevel(sd_conf *sdconf);
+void sdconf_init(void);
+void sdconf_destroy(void);
+void sdconf_set_debuglevel(void);
 
-void sdconf_read_basic_confs(sd_conf *sdconf);
-void sdconf_setup_conffile(sd_conf *sdconf);
+void sdconf_read_basic_confs(void);
+void sdconf_setup_conffile(void);
 void sdconf_setup_authorized_hosts_conffile(void);
 
 #endif /* PISA_SDCONF_H */

Modified: trunk/pisasd/sdmain.c
==============================================================================
--- trunk/pisasd/sdmain.c       Thu Oct 29 15:05:18 2009        (r1409)
+++ trunk/pisasd/sdmain.c       Thu Oct 29 15:06:56 2009        (r1410)
@@ -314,13 +314,13 @@
 {
        PISA_DEBUG(PL_CONFIG, "Reloading basic configurations...\n");
 
-       sdconf_destroy(&sd_cfg);
+       sdconf_destroy();
        pisa_cfg_authorized_hosts_cleanup();
 
-       sdconf_setup_conffile(&sd_cfg);
+       sdconf_setup_conffile();
        sdconf_setup_authorized_hosts_conffile();
 
-       sdconf_read_basic_confs(&sd_cfg);
+       sdconf_read_basic_confs();
 }
 
 /**
@@ -370,7 +370,7 @@
 
        /* Set default values in context and config */
        sdctx_init();
-       sdconf_init(&sd_cfg);
+       sdconf_init();
 
        /* Receive and parse command line arguments.
         * Note that command line args must be obtained before calling any
@@ -386,7 +386,7 @@
        sd_perf_init();
 
        /* set the default or command line specified debug level */
-       sdconf_set_debuglevel(&sd_cfg);
+       sdconf_set_debuglevel();
 
        /* daemonize pisasd when running background mode */
        if (sd_ctx.flag_background)
@@ -397,16 +397,16 @@
        /* Setup configuration file.
         * This is needed before any sdconf_read_*() operations.
         */
-       sdconf_setup_conffile(&sd_cfg);
+       sdconf_setup_conffile();
 //     Use this line to use seperate authorized_hosts.cfg config file for 
allowed_hosts:
 //     sdconf_setup_authorized_hosts_conffile();
 //  Or this line to use the pisasd.cfg as before:
        pisa_cfg_authorized_hosts_setup_file(sd_cfg.conffile);
 
        /* Read several configuration from pisasd.conf. */
-       sdconf_read_basic_confs(&sd_cfg);
+       sdconf_read_basic_confs();
 
-       sdconf_set_debuglevel(&sd_cfg);
+       sdconf_set_debuglevel();
 
        /* Make default sockets */
        sd_ctx.fd_control = pisa_tunnel_open_socket(sd_cfg.port_control);
@@ -467,7 +467,7 @@
                pisa_sdnat_stop();
 
        sdctx_destroy();
-       sdconf_destroy(&sd_cfg);
+       sdconf_destroy();
        pisa_arp_cleanup();
 
        /* Close file descriptors. pisa_sched_cleanup takes care of the

Other related posts:

  • » [pisa-src] r1410 - in trunk/pisasd: sdconf.c sdconf.h sdmain.c - Thomas Jansen