src/nexus.c
branchmodules
changeset 55 6f7f6ae729d0
parent 53 12d806823775
child 56 942370000450
equal deleted inserted replaced
54:9f74e924b01a 55:6f7f6ae729d0
    42     printf(" --log-channel          channel to log\n");
    42     printf(" --log-channel          channel to log\n");
    43 }
    43 }
    44 
    44 
    45 void on_sigint (evutil_socket_t sig, short what, void *arg)
    45 void on_sigint (evutil_socket_t sig, short what, void *arg)
    46 {
    46 {
    47     struct nexus_ctx *ctx = arg;
    47     struct nexus *ctx = arg;
    48 
    48 
    49     (void) sig;
    49     (void) sig;
    50     (void) what;
    50     (void) what;
    51     
    51     
    52     if (ctx->client && !ctx->client->quitting) {
    52     if (ctx->client && !ctx->client->quitting) {
    71 
    71 
    72 int main (int argc, char **argv) 
    72 int main (int argc, char **argv) 
    73 {
    73 {
    74     int opt, option_index;
    74     int opt, option_index;
    75     struct signals *signals;
    75     struct signals *signals;
    76     struct nexus_ctx ctx;
    76     struct nexus ctx;
    77     struct irc_net *net;
    77     struct irc_net *net;
    78     struct error_info err;
    78     struct error_info err;
    79 
    79 
    80     struct irc_net_info net_info = {
    80     struct irc_net_info net_info = {
    81         .network                    = NULL,
    81         .network                    = "default",
    82         .hostname                   = DEFAULT_HOST,
    82         .hostname                   = DEFAULT_HOST,
    83         .service                    = DEFAULT_PORT,
    83         .service                    = DEFAULT_PORT,
    84         .use_ssl                    = false,
    84         .use_ssl                    = false,
    85         .register_info              = {
    85         .register_info              = {
    86             .nickname               = "SpBotDev",
    86             .nickname               = "SpBotDev",
    87             .username               = "spbot-dev",
    87             .username               = "spbot-dev",
    88             .realname               = "SpBot (development version)",
    88             .realname               = "SpBot (development version)",
    89         }
    89         }
    90     };
    90     };
    91 
    91 
       
    92     // XXX: hardcode irc_log config
       
    93     char *log_db_info = NULL;
    92     struct irc_chan_info log_chan_info = {
    94     struct irc_chan_info log_chan_info = {
    93         .channel                    = NULL, 
    95         .channel                    = NULL, 
    94     };
       
    95 
       
    96     struct irc_log_info log_info = {
       
    97         .db_info                    = NULL,
       
    98         .channel                    = NULL,
       
    99     };
    96     };
   100 
    97 
   101     bool port_default = true;
    98     bool port_default = true;
   102     
    99     
   103     // parse options
   100     // parse options
   123                     net_info.service = DEFAULT_PORT_SSL;
   120                     net_info.service = DEFAULT_PORT_SSL;
   124 
   121 
   125                 break;
   122                 break;
   126             
   123             
   127             case OPT_LOG_DATABASE:
   124             case OPT_LOG_DATABASE:
   128                 log_info.db_info = optarg;
   125                 log_db_info = optarg;
   129                 break;
   126                 break;
   130 
   127 
   131             case OPT_LOG_CHANNEL:
   128             case OPT_LOG_CHANNEL:
   132                 log_chan_info.channel = optarg;
   129                 log_chan_info.channel = optarg;
   133                 break;
   130                 break;
   147         FATAL("signals_create");
   144         FATAL("signals_create");
   148 
   145 
   149     // initialize sock module
   146     // initialize sock module
   150     if (sock_init(ctx.ev_base, &err))
   147     if (sock_init(ctx.ev_base, &err))
   151         FATAL_ERROR(&err, "sock_init");
   148         FATAL_ERROR(&err, "sock_init");
       
   149 
       
   150     // modules 
       
   151     if ((ERROR_CODE(&err) = modules_create(&ctx.modules, &ctx)))
       
   152         FATAL_ERROR(&err, "modules_create");
   152     
   153     
   153     // the IRC client
   154     // the IRC client
   154     if (irc_client_create(&ctx.client, &err))
   155     if (irc_client_create(&ctx.client, &err))
   155         FATAL_ERROR(&err, "irc_client_create");
   156         FATAL_ERROR(&err, "irc_client_create");
   156 
   157 
   164         ||  (ERROR_CODE(&err) = signals_add(signals, SIGINT, &on_sigint, &ctx))
   165         ||  (ERROR_CODE(&err) = signals_add(signals, SIGINT, &on_sigint, &ctx))
   165     )
   166     )
   166         FATAL_ERROR(&err, "signals_add");
   167         FATAL_ERROR(&err, "signals_add");
   167     
   168     
   168     // logging?
   169     // logging?
   169     if (log_info.db_info || log_chan_info.channel) {
   170     if (log_db_info || log_chan_info.channel) {
       
   171         struct module *mod_irc_log;
       
   172 
       
   173         struct module_info mod_irc_log_info = {
       
   174             .name = "irc_log",
       
   175             .path = "modules/irc_log.so"
       
   176         };
       
   177 
       
   178         // load the module
       
   179         if (module_load(ctx.modules, &mod_irc_log, &mod_irc_log_info, &err))
       
   180             FATAL_ERROR(&err, "module_load");
       
   181 
   170         // get the channel
   182         // get the channel
   171         if (log_chan_info.channel && (log_info.channel = irc_net_add_chan(net, &log_chan_info)) == NULL)
   183         if (log_chan_info.channel) {
   172             FATAL("irc_net_add_chan");
   184             // create the channel
   173         
   185             if ((irc_net_add_chan(net, &log_chan_info)) == NULL)
   174         // init the irc_log module
   186                 FATAL("irc_net_add_chan");
   175         if ((ERROR_CODE(&err) = irc_log_init(ctx.ev_base, &log_info)))
   187 
   176             FATAL_ERROR(&err, "irc_log_init");
   188             // configure it
       
   189             // XXX: hardcoded
       
   190             if ((ERROR_CODE(&err) = module_conf(mod_irc_log, "channel", "default/#test")))
       
   191                 FATAL_ERROR(&err, "module_conf(irc_log, '%s', '%s)", "channel", "default/#test");
       
   192         }
       
   193 
       
   194         // configure the databse info
       
   195         if (log_db_info && (ERROR_CODE(&err) = module_conf(mod_irc_log, "db_info", log_db_info)))
       
   196             FATAL_ERROR(&err, "module_conf(irc_log, 'db_info', '%s')", log_db_info);
   177     }
   197     }
   178 
   198 
   179     // run event loop
   199     // run event loop
   180     if (event_base_dispatch(ctx.ev_base))
   200     if (event_base_dispatch(ctx.ev_base))
   181         FATAL("event_base_dispatch");
   201         FATAL("event_base_dispatch");