Changeset 90836dc4f3981b6170b18cc3b4b5f23483704454

Show
Ignore:
Timestamp:
05/10/10 22:40:15 (2 years ago)
Author:
Antti-Juhani Kaijanaho <antti-juhani@…>
Children:
c04e3c7b94fa30438cb7c897e866588a2a959589
Parents:
d0c602a82418184b3475ba518ead4af1d648a4d9
git-committer:
Antti-Juhani Kaijanaho <antti-juhani@…> (05/10/10 22:40:15)
Message:

Move options procsesing to config

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@…>

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • alue_posix.cc

    r33c5f1c r90836dc  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    2626 
    2727#include <boost/asio.hpp> 
    28 #include <boost/program_options.hpp> 
    2928#include <cerrno> 
    3029#include <cstring> 
     
    3837#include <signal.h> 
    3938#include <sys/resource.h> 
    40 #include <sys/types.h> 
    41 #include <sys/utsname.h> 
    4239#include <unistd.h> 
    4340 
     
    6158int main(int argc, char *argv[]) 
    6259{ 
    63         namespace po = boost::program_options; 
    6460 
    6561        rlimit rlim; 
    66         if (getrlimit(RLIMIT_AS, &rlim) == -1) 
    67         { 
    68                 std::cerr << "getrlimit failed: " << strerror(errno)  
    69                           << std::endl; 
    70                 return 1; 
    71         } 
    72  
    73         struct utsname uts; 
    74         if (uname(&uts) == -1) 
    75         { 
    76                 std::cerr << "uname failed: " << strerror(errno) << std::endl; 
    77                 return 1; 
    78         } 
    79  
    80         po::options_description opts; 
    81         opts.add_options() 
    82                 ( "help", "show this help message") 
    83                 ( "daemon", 
    84                   po::value<bool>()->default_value(true), 
    85                   "create a daemon process and exit immediately afterward") 
    86                 ( "user", po::value<std::string>(), 
    87                   "the user to run as (if started as root)") 
    88                 ( "canonical-name",  
    89                   po::value<std::string>()->default_value(uts.nodename), 
    90                   "the canonical name of this host" ) 
    91                 ("nntp-port", 
    92                  po::value<std::string>()->default_value("119"), 
    93                  "the port to listen on for NNTP clients") 
    94                 ("nntps-port", 
    95                  po::value<std::string>()->default_value("563"), 
    96                  "the port to listen on for NNTP/SSL clients") 
    97                 ("https-port", 
    98                  po::value<std::string>()->default_value("443"), 
    99                  "the port to listen on for HTTPS clients") 
    100                 ("key-file", 
    101                  po::value<std::string>()->default_value("key.pem"), 
    102                  "the file containing the SSL/TLS private key") 
    103                 ("cert-file", 
    104                  po::value<std::string>()->default_value("cert.pem"), 
    105                  "the file containing the SSL/TLS certificate") 
    106                 ("log-smtp", 
    107                  po::value<bool>()->default_value(false), 
    108                  "log SMTP extensively") 
    109                 ("log-http", 
    110                  po::value<bool>()->default_value(false), 
    111                  "log HTTP extensively (warning - user privacy invasive)") 
    112                 ("log-nntp", 
    113                  po::value<bool>()->default_value(false), 
    114                  "log HTTP extensively (warning - user privacy invasive)") 
    115                 ("logfile",  
    116                  po::value<std::string>()->default_value("alue.log"), 
    117                  "the name of the logfile") 
    118                 ("vm-limit", 
    119                  po::value<rlim_t>(&rlim.rlim_cur)->default_value(rlim.rlim_cur), 
    120                  "the AS (virtual memory) resource limit for this process") 
    121                 ("include-dir",  
    122                  po::value<std::string>()->default_value("templates/"), 
    123                  "include directory name") 
    124                 ("files-dir",  
    125                  po::value<std::string>()->default_value("templates/"), 
    126                  "verbatim HTTPS file directory name") 
    127                 ("config-file", 
    128                  po::value<std::string>()->default_value(CONFFILE), 
    129                  "name of the the configuration file") 
    130                 ("db-file", 
    131                  po::value<std::string>()->default_value("alue.db2"), 
    132                  "name of the database file") 
    133                 ("pw-file", 
    134                  po::value<std::string>()->default_value("passwds"), 
    135                  "name of the passwords file") 
    136                 ("home", 
    137                  po::value<std::string>()->default_value("/"), 
    138                  "name of the daemon home directory") 
    139                 ("operator-email",  
    140                  po::value<std::string>(), 
    141                  "a human operator's email address"); 
    142         po::store(po::parse_command_line(argc, argv, opts), config); 
    143         { 
    144                 std::string config_file_name = 
    145                         config["config-file"].as<std::string>(); 
    146                 std::ifstream config_file(config_file_name.c_str()); 
    147                 if (config_file) 
    148                         po::store(po::parse_config_file(config_file, opts), 
    149                                   config); 
    150         } 
    151         po::notify(config); 
    152  
    153         if (config.count("help") > 0) 
    154         { 
    155                 std::cout << opts << std::endl; 
    156                 return 0; 
    157         } 
     62        configure(argc, argv, rlim); 
    15863 
    15964        if (config.count("operator-email") == 0) 
  • config.cc

    r868b365 r90836dc  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    2020#include "config.hh" 
    2121 
     22#include <cerrno> 
     23#include <cstdlib> 
     24#include <fstream> 
     25#include <iostream> 
     26#include <sys/resource.h> 
     27#include <sys/utsname.h> 
     28#include <unistd.h> 
     29 
     30 
    2231boost::program_options::variables_map config; 
     32 
     33void configure(int argc, char *argv[], rlimit &rlim) 
     34{ 
     35        namespace po = boost::program_options; 
     36 
     37        if (getrlimit(RLIMIT_AS, &rlim) == -1) 
     38        { 
     39                std::cerr << "getrlimit failed: " << strerror(errno)  
     40                          << std::endl; 
     41                std::exit(1); 
     42        } 
     43 
     44        struct utsname uts; 
     45        if (uname(&uts) == -1) 
     46        { 
     47                std::cerr << "uname failed: " << strerror(errno) << std::endl; 
     48                std::exit(1); 
     49        } 
     50 
     51 
     52        po::options_description opts; 
     53        opts.add_options() 
     54                ( "help", "show this help message") 
     55                ( "daemon", 
     56                  po::value<bool>()->default_value(true), 
     57                  "create a daemon process and exit immediately afterward") 
     58                ( "user", po::value<std::string>(), 
     59                  "the user to run as (if started as root)") 
     60                ( "canonical-name",  
     61                  po::value<std::string>()->default_value(uts.nodename), 
     62                  "the canonical name of this host" ) 
     63                ("nntp-port", 
     64                 po::value<std::string>()->default_value("119"), 
     65                 "the port to listen on for NNTP clients") 
     66                ("nntps-port", 
     67                 po::value<std::string>()->default_value("563"), 
     68                 "the port to listen on for NNTP/SSL clients") 
     69                ("https-port", 
     70                 po::value<std::string>()->default_value("443"), 
     71                 "the port to listen on for HTTPS clients") 
     72                ("key-file", 
     73                 po::value<std::string>()->default_value("key.pem"), 
     74                 "the file containing the SSL/TLS private key") 
     75                ("cert-file", 
     76                 po::value<std::string>()->default_value("cert.pem"), 
     77                 "the file containing the SSL/TLS certificate") 
     78                ("log-smtp", 
     79                 po::value<bool>()->default_value(false), 
     80                 "log SMTP extensively") 
     81                ("log-http", 
     82                 po::value<bool>()->default_value(false), 
     83                 "log HTTP extensively (warning - user privacy invasive)") 
     84                ("log-nntp", 
     85                 po::value<bool>()->default_value(false), 
     86                 "log HTTP extensively (warning - user privacy invasive)") 
     87                ("logfile",  
     88                 po::value<std::string>()->default_value("alue.log"), 
     89                 "the name of the logfile") 
     90                ("vm-limit", 
     91                 po::value<rlim_t>(&rlim.rlim_cur)->default_value(rlim.rlim_cur), 
     92                 "the AS (virtual memory) resource limit for this process") 
     93                ("include-dir",  
     94                 po::value<std::string>()->default_value("templates/"), 
     95                 "include directory name") 
     96                ("files-dir",  
     97                 po::value<std::string>()->default_value("templates/"), 
     98                 "verbatim HTTPS file directory name") 
     99                ("config-file", 
     100                 po::value<std::string>()->default_value(CONFFILE), 
     101                 "name of the the configuration file") 
     102                ("db-file", 
     103                 po::value<std::string>()->default_value("alue.db2"), 
     104                 "name of the database file") 
     105                ("pw-file", 
     106                 po::value<std::string>()->default_value("passwds"), 
     107                 "name of the passwords file") 
     108                ("home", 
     109                 po::value<std::string>()->default_value("/"), 
     110                 "name of the daemon home directory") 
     111                ("operator-email",  
     112                 po::value<std::string>(), 
     113                 "a human operator's email address"); 
     114        po::store(po::parse_command_line(argc, argv, opts), config); 
     115        { 
     116                std::string config_file_name = 
     117                        config["config-file"].as<std::string>(); 
     118                std::ifstream config_file(config_file_name.c_str()); 
     119                if (config_file) 
     120                        po::store(po::parse_config_file(config_file, opts), 
     121                                  config); 
     122        } 
     123        po::notify(config); 
     124 
     125        if (config.count("help") > 0) 
     126        { 
     127                std::cout << opts << std::endl; 
     128                std::exit(0); 
     129        } 
     130} 
  • config.hh

    r868b365 r90836dc  
    11/*  This file is part of Alue, the multiprotocol Internet discussion daemon 
    22 
    3     Copyright © 2009 Antti-Juhani Kaijanaho 
     3    Copyright © 2009, 2010 Antti-Juhani Kaijanaho 
    44 
    55    Alue is free software: you can redistribute it and/or modify it 
     
    2222 
    2323#include <boost/program_options.hpp> 
     24#include <sys/resource.h> 
    2425 
    2526extern boost::program_options::variables_map config; 
    2627 
     28void configure(int argc, char *argv[], rlimit &rlim); 
    2729 
    2830#endif /* GUARD_CONFIG_HH */