src/nexus.c
author Tero Marttila <terom@fixme.fi>
Sun, 19 Apr 2009 04:04:42 +0300
changeset 140 aa390e52eda8
parent 139 55b9dcc2b73a
child 170 1b2f28e26eef
permissions -rw-r--r--
implement ssl_cafile/verify/cert/pkey for x509 credentials
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     1
#include "nexus.h"
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
     2
#include "lua_config.h"
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     3
#include "log.h"
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
#include <stdlib.h>
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
     6
#include <stdbool.h>
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
#include <stdio.h>
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
     8
#include <getopt.h>
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     9
#include <signal.h>
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    10
#include <string.h>
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    12
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    13
 * Command-line option codes
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    14
 */
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    15
enum option_code {
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    16
    OPT_HELP            = 'h',
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    17
    OPT_DEFAULTS        = 'D',
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    18
    OPT_NETWORK         = 'n',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    19
    OPT_MODULE          = 'm',
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    20
    OPT_CONF            = 'C',
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    21
    OPT_DEBUG           = 'd',
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    22
    OPT_CONFIG          = 'c',
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    23
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    24
    /** Options without short names */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    25
    _OPT_EXT_BEGIN      = 0x00ff,
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    26
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    27
    OPT_CONSOLE,
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    28
    OPT_CHANNEL,
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    29
};
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    30
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    31
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    32
 * Command-line option definitions
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    33
 */
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    34
static struct option options[] = {
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    35
    {"help",            0,  NULL,   OPT_HELP        },
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    36
    {"defaults",        1,  NULL,   OPT_DEFAULTS    },
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    37
    {"network",         1,  NULL,   OPT_NETWORK     },
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    38
    {"channel",         1,  NULL,   OPT_CHANNEL     },
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    39
    {"module",          1,  NULL,   OPT_MODULE      },
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    40
    {"conf",            1,  NULL,   OPT_CONF        },
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    41
    {"debug",           0,  NULL,   OPT_DEBUG       },
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    42
    {"console",         0,  NULL,   OPT_CONSOLE     },
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    43
    {"config",          1,  NULL,   OPT_CONFIG      },
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    44
    {0,                 0,  0,      0               },
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    45
};
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    46
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    47
/**
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    48
 * Short command-line option defintion
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    49
 */
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    50
const char *short_options = "hn:c:m:C:d";
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    51
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    52
/**
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    53
 * Display --help output on stdout.
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    54
 *
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    55
 * If nexus is given, --config options for loaded modules are also listed
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    56
 */
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    57
static void usage (struct nexus *nexus, const char *exe)
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    58
{
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    59
    printf("Usage: %s [OPTIONS]\n", exe);
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    60
    printf("\n");
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    61
    printf(" --help / -h            display this message\n");
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    62
    printf(" --defaults / -D        set the IRC client default info using '<nickname>:<username>:<realname>'\n");
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
    63
    printf(" --network / -n         add an IRC network using '<name>:<hostname>[:<port>[:ssl][:ssl_cafile=<path>][:ssl_verify][:ssl_cert=<path>][:ssl_pkey=<path>]]' format\n");
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    64
    printf(" --channel              add an IRC channel using '<network>:<channel>' format\n");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    65
    printf(" --module / -m          add a module using '<name>:<path>' format\n");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    66
    printf(" --config / -C          add a module configuration option using '<mod_name>:<name>[:<value>]' format\n");
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    67
    printf(" --debug / -d           set logging level to DEBUG\n");
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
    68
    printf(" --config / -c          load a Lua config file from '<path>'\n");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    69
    printf(" --console              use the interactive console\n");
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    70
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    71
    // dump loaded module configs
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    72
    if (nexus && !TAILQ_EMPTY(&nexus->modules->list)) {
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    73
        struct module *module;
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    74
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    75
        printf("\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    76
        printf("Module configuration options\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    77
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    78
        TAILQ_FOREACH(module, &nexus->modules->list, modules_list) {
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    79
            printf("\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    80
            printf("%s:\n", module->info.name);
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    81
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 98
diff changeset
    82
            // XXX: shouldn't be accessing directly
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 98
diff changeset
    83
            if (module->desc->config_options) {
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    84
                const struct config_option *opt;
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    85
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 111
diff changeset
    86
                for (opt = module->desc->config_options; opt->name; opt++) {
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 111
diff changeset
    87
                    printf(" --config %s:%s:%s\t\t%s\n", module->info.name, opt->name, "xxx", opt->help);
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    88
                }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    89
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    90
            } else {
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    91
                printf("\t???\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    92
            }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    93
        }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    94
    }
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    95
}
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    96
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    97
/**
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    98
 * Parse and apply a --defaults option, setting the resulting defaults to our irc_client
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    99
 */
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   100
static err_t apply_defaults (struct nexus *nexus, char *opt, struct error_info *err)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   101
{
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   102
    struct irc_client_defaults defaults = {
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   103
        .register_info      = { NULL, NULL, NULL },
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 98
diff changeset
   104
        .service            = IRC_PORT,
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 98
diff changeset
   105
        .service_ssl        = IRC_SSL_PORT,
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   106
    };
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   107
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   108
    // parse the required fields
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   109
    if ((defaults.register_info.nickname = strsep(&opt, ":")) == NULL)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   110
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <nickname> field for --defaults");
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   111
    
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   112
    if ((defaults.register_info.username = strsep(&opt, ":")) == NULL)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   113
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <username> field for --defaults");
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   114
    
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   115
    if ((defaults.register_info.realname = strsep(&opt, ":")) == NULL)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   116
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <realname> field for --defaults");
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   117
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   118
    // trailing garbage?
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   119
    if (opt)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   120
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel");
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   121
    
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   122
    // apply them
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   123
    log_info("using default nick/user/real-name: %s/%s/%s", 
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   124
            defaults.register_info.nickname, defaults.register_info.username, defaults.register_info.realname);
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   125
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   126
    irc_client_set_defaults(nexus->client, &defaults);
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   127
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   128
    // ok
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   129
    return SET_ERROR(err, SUCCESS);
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   130
}
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   131
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   132
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   133
 * Parse and apply a --network option, adding the given network to our irc_client.
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   134
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   135
static err_t apply_network (struct nexus *nexus, char *opt, struct error_info *err)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   136
{
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   137
    struct irc_net_info info;
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   138
    const char *ssl_cafile = NULL, *ssl_cert = NULL, *ssl_pkey = NULL;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   139
    bool use_ssl = false, ssl_verify = false;
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   140
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   141
    // init to zero
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   142
    memset(&info, 0, sizeof(info));
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   143
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   144
    // parse the required fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   145
    if ((info.network = strsep(&opt, ":")) == NULL)
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   146
        JUMP_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --network");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   147
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   148
    if ((info.hostname = strsep(&opt, ":")) == NULL)
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   149
        JUMP_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <hostname> field for --network");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   150
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   151
    // parse the optional fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   152
    if (opt)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   153
        info.service = strsep(&opt, ":");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   154
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   155
    // parse any remaining flags
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   156
    while (opt) {
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   157
        char *flag_token = strsep(&opt, ":");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   158
        char *flag = strsep(&flag_token, "=");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   159
        char *value = flag_token;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   160
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   161
        if (strcmp(flag, "ssl") == 0) {
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   162
            use_ssl = true;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   163
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   164
        } else if (strcmp(flag, "ssl_cafile") == 0) {
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   165
            if (!value)
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   166
                JUMP_SET_ERROR_STR(err, ERR_CMD_OPT, "missing value for :ssl_cafile");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   167
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   168
            ssl_cafile = value;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   169
        
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   170
        } else if (strcmp(flag, "ssl_verify") == 0) {
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   171
            ssl_verify = true;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   172
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   173
        } else if (strcmp(flag, "ssl_cert") == 0) {
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   174
            if (!value)
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   175
                JUMP_SET_ERROR_STR(err, ERR_CMD_OPT, "missing value for :ssl_cert");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   176
            
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   177
            ssl_cert = value;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   178
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   179
        } else if (strcmp(flag, "ssl_pkey") == 0) {
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   180
            if (!value)
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   181
                JUMP_SET_ERROR_STR(err, ERR_CMD_OPT, "missing value for :ssl_pkey");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   182
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   183
            ssl_pkey = value;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   184
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   185
        } else
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   186
            JUMP_SET_ERROR_STR(err, ERR_CMD_OPT, "unrecognized flag for --network");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   187
    }
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   188
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   189
    // SSL?
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   190
    if (use_ssl || ssl_cafile || ssl_verify || ssl_cert || ssl_pkey) {
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   191
        // verify
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   192
        if ((ssl_cert || ssl_pkey) && !(ssl_cert && ssl_pkey))
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   193
            JUMP_SET_ERROR_STR(err, ERR_CMD_OPT, "must give both :ssl_cert/:ssl_pkey");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   194
        
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   195
        // create
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   196
        if (sock_ssl_client_cred_create(&info.ssl_cred, ssl_cafile, ssl_verify, ssl_cert, ssl_pkey, err))
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   197
            goto error;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   198
    }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   199
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   200
    // create the net
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   201
    log_info("add network '%s' at '%s:%s'", info.network, info.hostname, info.service);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   202
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   203
    if (irc_client_add_net(nexus->client, NULL, &info, err))
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   204
        goto error;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   205
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   206
    // ok
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   207
    return SUCCESS;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   208
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   209
error:
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   210
    // cleanup
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   211
    if (info.ssl_cred)
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   212
        sock_ssl_client_cred_put(info.ssl_cred);
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   213
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   214
    return ERROR_CODE(err);
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   215
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   216
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   217
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   218
 * Parse and apply a --channel option, adding the given channel to the given irc_net.
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   219
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   220
static err_t apply_channel (struct nexus *nexus, char *opt, struct error_info *err)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   221
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   222
    const char *network = NULL;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   223
    struct irc_net *net;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   224
    struct irc_chan_info info = {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   225
        .channel            = NULL,
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   226
    };
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   227
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   228
    // parse the required fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   229
    if ((network = strsep(&opt, ":")) == NULL)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   230
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <network> field for --channel");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   231
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   232
    if ((info.channel = strsep(&opt, ":")) == NULL)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   233
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <channel> field for --channel");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   234
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   235
    // trailing garbage?
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   236
    if (opt)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   237
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   238
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   239
    // look up the net
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   240
    if ((net = irc_client_get_net(nexus->client, network)) == NULL)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   241
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unknown network for --channel");
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   242
    
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   243
    // add the channel
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   244
    log_info("add channel '%s' on network '%s'", info.channel, net->info.network);
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   245
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   246
    if (irc_net_add_chan(net, NULL, &info, err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   247
        return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   248
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   249
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   250
    return SUCCESS;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   251
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   252
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   253
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   254
 * Parse and apply a --module option, loading the given module.
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   255
 */
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   256
static err_t apply_module (struct nexus *nexus, char *opt, struct error_info *err)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   257
{
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   258
    struct module_info info = {
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   259
        .name       = NULL,
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   260
        .path       = NULL,
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   261
    };
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   262
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   263
    // parse the required fields
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   264
    if ((info.name = strsep(&opt, ":")) == NULL)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   265
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --module");
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   266
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   267
    if ((info.path = strsep(&opt, ":")) == NULL)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   268
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <path> field for --module");
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   269
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   270
    // trailing garbage?
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   271
    if (opt)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   272
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel");
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   273
    
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   274
    // load it
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   275
    log_info("loading module '%s' from path '%s'", info.name, info.path);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   276
111
5a1ebffca81a fix refcount semantics for module_load and have module_unload call module_unloaded on module_desc::unload errors
Tero Marttila <terom@fixme.fi>
parents: 110
diff changeset
   277
    if (module_load(nexus->modules, NULL, &info, err))
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   278
        return ERROR_CODE(err);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   279
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   280
    // ok
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   281
    return SUCCESS;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   282
}
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   283
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   284
/**
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   285
 * Parse and apply a --conf option, calling the module's conf func.
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   286
 */
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   287
static err_t apply_conf (struct nexus *nexus, char *opt, struct error_info *err)
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   288
{
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   289
    struct module *module;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   290
    const char *module_name, *conf_name;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   291
    char *conf_value;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   292
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   293
    // parse the required fields
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   294
    if ((module_name = strsep(&opt, ":")) == NULL)
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   295
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <module> field for --config");
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   296
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   297
    if ((conf_name = strsep(&opt, ":")) == NULL)
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   298
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --config");
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   299
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   300
    // value is the rest of the data, might be NULL
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   301
    conf_value = opt;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   302
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   303
    // lookup the module
134
978041c1c04d update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents: 120
diff changeset
   304
    if ((module = modules_get(nexus->modules, module_name)) == NULL)
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   305
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unknown module for --config");
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   306
    
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   307
    // do the config
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   308
    log_info("applying module '%s' config name '%s' with value: %s", module->info.name, conf_name, conf_value);
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   309
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 98
diff changeset
   310
    if (module_conf_raw(module, conf_name, conf_value, err))
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   311
        return ERROR_CODE(err);
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   312
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   313
    // ok
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   314
    return SUCCESS;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   315
}
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   316
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   317
/**
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   318
 * Open the console
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   319
 */
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   320
static err_t apply_console (struct nexus *nexus, struct error_info *err)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   321
{
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   322
    struct console_config config = {
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   323
        .prompt     = "> ",
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   324
    };
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   325
    struct console *console;
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   326
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   327
    log_info("initializing the console");
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   328
    
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   329
    // init the console
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   330
    if (console_init(&console, nexus->ev_base, &config, NULL, NULL, err))
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   331
        return ERROR_CODE(err);
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   332
    
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   333
    // set it as the log output handler
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   334
    console_set_log_output(console);
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   335
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   336
    // create the lua console on top of that
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   337
    if (lua_console_create(&nexus->lua_console, console, nexus->lua, err))
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   338
        goto error;
93
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   339
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   340
    // ok
42ade8285570 add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
Tero Marttila <terom@fixme.fi>
parents: 92
diff changeset
   341
    return SUCCESS;
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   342
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   343
error:
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   344
    console_destroy(console);
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   345
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   346
    return ERROR_CODE(err);
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   347
}
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   348
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   349
err_t nexus_load_config (struct nexus *nexus, const char *path, struct error_info *err)
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   350
{
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   351
    return lua_config_load(nexus->lua, path, err);
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   352
}
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   353
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   354
/**
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   355
 * Load the lua config file from \a path
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   356
 */
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   357
static err_t apply_config (struct nexus *nexus, char *path, struct error_info *err)
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   358
{
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   359
    log_info("loading lua config from %s", path);
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   360
    
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   361
    return nexus_load_config(nexus, path, err);
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   362
}
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   363
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   364
/**
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   365
 * Parse arguments and apply them to the given nexus
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   366
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   367
static err_t parse_args (struct nexus *nexus, int argc, char **argv, struct error_info *err)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   368
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   369
    int opt, option_index;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   370
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   371
    // parse options
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   372
    while ((opt = getopt_long(argc, argv, short_options, options, &option_index)) != -1) {
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   373
        switch (opt) {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   374
            case OPT_HELP:
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   375
                usage(nexus, argv[0]);
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   376
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   377
                // XXX: return instead
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   378
                exit(EXIT_SUCCESS);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   379
            
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   380
            case OPT_NETWORK:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   381
                if (apply_network(nexus, optarg, err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   382
                    return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   383
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   384
                break;
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   385
            
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   386
            case OPT_DEFAULTS:
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   387
                if (apply_defaults(nexus, optarg, err))
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   388
                    return ERROR_CODE(err);
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   389
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   390
                break;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   391
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   392
            case OPT_CHANNEL:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   393
                if (apply_channel(nexus, optarg, err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   394
                    return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   395
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   396
                break;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   397
            
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   398
            case OPT_MODULE:
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   399
                if (apply_module(nexus, optarg, err))
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   400
                    return ERROR_CODE(err);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   401
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   402
                break;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   403
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   404
            case OPT_CONF:
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   405
                if (apply_conf(nexus, optarg, err))
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   406
                    return ERROR_CODE(err);
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   407
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   408
                break;
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   409
            
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   410
            case OPT_DEBUG:
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   411
                set_log_level(LOG_DEBUG);
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   412
                break;
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   413
            
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   414
            case OPT_CONSOLE:
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   415
                if (apply_console(nexus, err))
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   416
                    return ERROR_CODE(err);
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   417
                
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   418
                break;
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   419
            
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   420
            case OPT_CONFIG:
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   421
                if (apply_config(nexus, optarg, err))
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   422
                    return ERROR_CODE(err);
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   423
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 105
diff changeset
   424
                break;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   425
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   426
            case '?':
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   427
                usage(nexus, argv[0]);
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   428
                return SET_ERROR(err, ERR_CMD_OPT);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   429
        }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   430
    }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   431
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   432
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   433
    return SUCCESS;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   434
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   435
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   436
void nexus_shutdown (struct nexus *nexus)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   437
{
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   438
    // destroy the console
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   439
    if (nexus->lua_console)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   440
        lua_console_destroy(nexus->lua_console);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   441
    
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   442
    nexus->lua_console = NULL;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   443
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   444
    // unload the modules
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   445
    if (nexus->modules)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   446
       modules_unload(nexus->modules);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   447
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   448
    // quit the irc client
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   449
    if (nexus->client)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   450
       irc_client_quit(nexus->client, "Goodbye, cruel world ;(");
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   451
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   452
    // remove the signal handlers
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   453
    if (nexus->signals)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   454
        signals_free(nexus->signals);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   455
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   456
    nexus->signals = NULL;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   457
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   458
    // now event_base_dispatch should return once everythings' shut down...
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   459
    nexus->shutdown = true;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   460
}
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   461
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   462
void nexus_crash (struct nexus *nexus)
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   463
{
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   464
    // force-quit the event loop
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   465
    event_base_loopbreak(nexus->ev_base);
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   466
}
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   467
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   468
void nexus_destroy (struct nexus *nexus)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   469
{
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   470
    // destroy the console
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   471
    if (nexus->lua_console)
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   472
        lua_console_destroy(nexus->lua_console);
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   473
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   474
    // destroy the lua state
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   475
    if (nexus->lua)
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   476
        nexus_lua_destroy(nexus->lua);
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   477
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   478
    // destroy the modules
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   479
    if (nexus->modules)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   480
        modules_destroy(nexus->modules);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   481
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   482
    // destroy the irc client
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   483
    if (nexus->client)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   484
        irc_client_destroy(nexus->client);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   485
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   486
    // remove the signal handlers
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   487
    if (nexus->signals)
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   488
        signals_free(nexus->signals);
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 109
diff changeset
   489
    
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 109
diff changeset
   490
    // finally, the libevent base
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 109
diff changeset
   491
    if (nexus->ev_base)
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 109
diff changeset
   492
        event_base_free(nexus->ev_base);
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   493
110
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 109
diff changeset
   494
    // ok, nexus is now dead, so drop all pointers to make valgrind show things as leaked :)
43e9a7984955 fix operation of module_unload/module_destroy so that unloaded modules are now destroyed once they have been unloaded
Tero Marttila <terom@fixme.fi>
parents: 109
diff changeset
   495
    memset(nexus, 0, sizeof(*nexus));
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   496
}
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   497
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   498
static void on_sigint (evutil_socket_t sig, short what, void *arg)
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   499
{
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   500
    struct nexus *nexus = arg;
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   501
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   502
    (void) sig;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   503
    (void) what;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   504
    
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   505
    log_info("Quitting...");
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   506
    
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   507
    // shutdown
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   508
    nexus_shutdown(nexus);
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   509
}
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   510
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   511
int main (int argc, char **argv) 
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   512
{
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   513
    struct nexus _nexus, *nexus = &_nexus;
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   514
    struct error_info err;
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   515
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   516
    // zero nexus
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   517
    memset(nexus, 0, sizeof(*nexus));
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   518
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   519
    // initialize libevent
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   520
    if ((nexus->ev_base = event_base_new()) == NULL)
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   521
        FATAL("event_base_new");
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   522
    
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   523
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   524
    // initialize signal handlers
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   525
    if ((ERROR_CODE(&err) = signals_create(&nexus->signals, nexus->ev_base)))
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   526
        FATAL("signals_create");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   527
 
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   528
    // add our signal handlers
71
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   529
    if (signal_ignore(SIGPIPE, &err))
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   530
        FATAL_ERROR(&err, "signals_ignore(SIGPIPE)");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   531
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   532
    // XXX: add our SIGINT handler after console_init()?
71
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   533
    if ((ERROR_CODE(&err) = signals_add(nexus->signals, SIGINT, &on_sigint, nexus)))
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   534
        FATAL_ERROR(&err, "signals_add(SIGINT)");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   535
 
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   536
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   537
    // initialize sock module
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   538
    if (sock_init(nexus->ev_base, &err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   539
        FATAL_ERROR(&err, "sock_init");
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   540
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   541
    // modules 
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   542
    if ((ERROR_CODE(&err) = modules_create(&nexus->modules, nexus)))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   543
        FATAL_ERROR(&err, "modules_create");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   544
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   545
    // the IRC client
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   546
    if (irc_client_create(&nexus->client, &err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   547
        FATAL_ERROR(&err, "irc_client_create");
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   548
    
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   549
    // lua state
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   550
    if (nexus_lua_create(&nexus->lua, nexus, &err))
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   551
        FATAL_ERROR(&err, "nexus_lua_create");
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 53
diff changeset
   552
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   553
    
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   554
    // parse args
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   555
    if (parse_args(nexus, argc, argv, &err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   556
        FATAL_ERROR(&err, "parse_args");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   557
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   558
  
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   559
    // run event loop
71
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   560
    log_info("entering event loop");
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   561
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   562
    if (event_base_dispatch(nexus->ev_base)) {
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   563
        if (nexus->shutdown) {
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   564
            log_info("clean shutdown completed");
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   565
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   566
        } else {
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   567
            FATAL("event_base_dispatch returned without shutdown");
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   568
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   569
        }
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   570
    }
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   571
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   572
    // cleanup
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   573
    nexus_destroy(nexus);
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   574
    nexus = NULL;
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   575
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   576
    // ok
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   577
    return EXIT_SUCCESS;
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   578
}
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   579