src/spbot/nexus.c
author Tero Marttila <terom@fixme.fi>
Thu, 28 May 2009 01:17:36 +0300
branchnew-lib-errors
changeset 219 cefec18b8268
parent 218 5229a5d098b2
permissions -rw-r--r--
some of the lib/transport stuff compiles
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"
219
cefec18b8268 some of the lib/transport stuff compiles
Tero Marttila <terom@fixme.fi>
parents: 218
diff changeset
     3
#include <lib/sock.h>
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
     4
#include <lib/log.h>
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
#include <stdlib.h>
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
     7
#include <stdbool.h>
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
#include <stdio.h>
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
     9
#include <getopt.h>
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    10
#include <signal.h>
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    11
#include <string.h>
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    13
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    14
 * Command-line option codes
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    15
 */
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
    16
enum option_code {
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    17
    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
    18
    OPT_DEFAULTS        = 'D',
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    19
    OPT_NETWORK         = 'n',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    20
    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
    21
    OPT_CONF            = 'C',
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    22
    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
    23
    OPT_CONFIG          = 'c',
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    24
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    25
    /** Options without short names */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    26
    _OPT_EXT_BEGIN      = 0x00ff,
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    27
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    28
    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
    29
    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
    30
};
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
    31
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    32
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    33
 * Command-line option definitions
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    34
 */
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    35
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
    36
    {"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
    37
    {"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
    38
    {"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
    39
    {"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
    40
    {"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
    41
    {"conf",            1,  NULL,   OPT_CONF        },
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    42
    {"debug",           0,  NULL,   OPT_DEBUG       },
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    43
    {"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
    44
    {"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
    45
    {0,                 0,  0,      0               },
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    46
};
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    47
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    48
/**
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
    49
 * 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
    50
 */
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
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
    52
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
    53
/**
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    54
 * 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
    55
 *
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    56
 * 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
    57
 */
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    58
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
    59
{
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    60
    printf("Usage: %s [OPTIONS]\n", exe);
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    61
    printf("\n");
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    62
    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
    63
    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
    64
    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
    65
    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
    66
    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
    67
    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
    68
    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
    69
    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
    70
    printf(" --console              use the interactive console\n");
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    71
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    72
    // 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
    73
    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
    74
        struct module *module;
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    75
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    76
        printf("\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    77
        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
    78
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    79
        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
    80
            printf("\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    81
            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
    82
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
    83
            // 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
    84
            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
    85
                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
    86
120
576bab0a1c5a modify config to support options with multiple params/values
Tero Marttila <terom@fixme.fi>
parents: 111
diff changeset
    87
                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
    88
                    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
    89
                }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    90
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    91
            } else {
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    92
                printf("\t???\n");
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
        }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    95
    }
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    96
}
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    97
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    98
/**
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
    99
 * 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
   100
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   101
static err_t apply_defaults (struct nexus *nexus, char *opt, error_t *err)
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
   102
{
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
    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
   104
        .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
   105
        .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
   106
        .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
   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
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
    // 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
   110
    if ((defaults.register_info.nickname = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   111
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <nickname> field for --defaults");
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
   112
    
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
    if ((defaults.register_info.username = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   114
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <username> field for --defaults");
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
   115
    
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
    if ((defaults.register_info.realname = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   117
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <realname> field for --defaults");
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
   118
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
    // 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
   120
    if (opt)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   121
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "trailing values for --channel");
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
   122
    
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
    // 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
   124
    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
   125
            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
   126
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
    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
   128
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
    // ok
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   130
    return SUCCESS;
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
   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
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
   133
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   134
 * 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
   135
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   136
static err_t apply_network (struct nexus *nexus, char *opt, error_t *err)
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   137
{
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
   138
    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
   139
    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
   140
    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
   141
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
    // 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
   143
    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
   144
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   145
    // parse the required fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   146
    if ((info.network = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   147
        JUMP_SET_ERROR_STR(err, &general_errors, 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
   148
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   149
    if ((info.hostname = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   150
        JUMP_SET_ERROR_STR(err, &general_errors, 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
   151
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   152
    // parse the optional fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   153
    if (opt)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   154
        info.service = strsep(&opt, ":");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   155
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   156
    // parse any remaining flags
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   157
    while (opt) {
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   158
        char *flag_token = strsep(&opt, ":");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   159
        char *flag = strsep(&flag_token, "=");
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   160
        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
   161
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   162
        if (strcmp(flag, "ssl") == 0) {
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   163
            use_ssl = true;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   164
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   165
        } 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
   166
            if (!value)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   167
                JUMP_SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing value for :ssl_cafile");
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   168
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   169
            ssl_cafile = value;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   170
        
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   171
        } 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
   172
            ssl_verify = true;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   173
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   174
        } 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
   175
            if (!value)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   176
                JUMP_SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing value for :ssl_cert");
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   177
            
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   178
            ssl_cert = value;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   179
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   180
        } 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
   181
            if (!value)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   182
                JUMP_SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing value for :ssl_pkey");
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   183
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   184
            ssl_pkey = value;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   185
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   186
        } else
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   187
            JUMP_SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "unrecognized flag for --network");
140
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
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   190
    // SSL?
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   191
    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
   192
        // verify
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   193
        if ((ssl_cert || ssl_pkey) && !(ssl_cert && ssl_pkey))
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   194
            JUMP_SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "must give both :ssl_cert/:ssl_pkey");
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   195
        
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   196
        // create
180
22967b165692 rename sock_ssl/sock_gnutls -> ssl/ssl_client
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
   197
        if (ssl_client_cred_create(&info.ssl_cred, ssl_cafile, ssl_verify, ssl_cert, ssl_pkey, err))
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   198
            goto error;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   199
    }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   200
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   201
    // create the net
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   202
    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
   203
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   204
    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
   205
        goto error;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   206
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   207
    // ok
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   208
    return SUCCESS;
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   209
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   210
error:
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   211
    // cleanup
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   212
    if (info.ssl_cred)
180
22967b165692 rename sock_ssl/sock_gnutls -> ssl/ssl_client
Tero Marttila <terom@fixme.fi>
parents: 170
diff changeset
   213
        ssl_client_cred_put(info.ssl_cred);
140
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   214
aa390e52eda8 implement ssl_cafile/verify/cert/pkey for x509 credentials
Tero Marttila <terom@fixme.fi>
parents: 139
diff changeset
   215
    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
   216
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   217
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   218
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   219
 * 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
   220
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   221
static err_t apply_channel (struct nexus *nexus, char *opt, error_t *err)
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   222
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   223
    const char *network = NULL;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   224
    struct irc_net *net;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   225
    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
   226
        .channel            = NULL,
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
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   229
    // parse the required fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   230
    if ((network = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   231
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <network> field for --channel");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   232
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   233
    if ((info.channel = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   234
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <channel> field for --channel");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   235
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   236
    // trailing garbage?
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   237
    if (opt)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   238
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "trailing values for --channel");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   239
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   240
    // look up the net
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   241
    if ((net = irc_client_get_net(nexus->client, network)) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   242
        return SET_ERROR_STR(err, &general_errors, 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
   243
    
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   244
    // add the channel
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   245
    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
   246
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   247
    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
   248
        return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   249
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   250
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   251
    return SUCCESS;
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
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   254
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   255
 * 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
   256
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   257
static err_t apply_module (struct nexus *nexus, char *opt, error_t *err)
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   258
{
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   259
    struct module_info info = {
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   260
        .name       = NULL,
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   261
        .path       = NULL,
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
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   264
    // parse the required fields
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   265
    if ((info.name = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   266
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <name> field for --module");
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   267
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   268
    if ((info.path = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   269
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <path> field for --module");
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   270
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   271
    // trailing garbage?
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   272
    if (opt)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   273
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "trailing values for --channel");
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   274
    
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   275
    // load it
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   276
    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
   277
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
   278
    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
   279
        return ERROR_CODE(err);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   280
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   281
    // ok
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   282
    return SUCCESS;
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
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   285
/**
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
   286
 * 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
   287
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   288
static err_t apply_conf (struct nexus *nexus, char *opt, error_t *err)
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   289
{
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   290
    struct module *module;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   291
    const char *module_name, *conf_name;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   292
    char *conf_value;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   293
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   294
    // parse the required fields
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   295
    if ((module_name = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   296
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <module> field for --config");
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   297
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   298
    if ((conf_name = strsep(&opt, ":")) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   299
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "missing <name> field for --config");
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   300
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   301
    // 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
   302
    conf_value = opt;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   303
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   304
    // 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
   305
    if ((module = modules_get(nexus->modules, module_name)) == NULL)
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   306
        return SET_ERROR_STR(err, &general_errors, ERR_CMD_OPT, "unknown module for --config");
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   307
    
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   308
    // do the config
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   309
    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
   310
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
   311
    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
   312
        return ERROR_CODE(err);
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   313
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   314
    // ok
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   315
    return SUCCESS;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   316
}
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   317
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   318
/**
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   319
 * Open the console
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   320
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   321
static err_t apply_console (struct nexus *nexus, error_t *err)
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   322
{
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   323
    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
   324
        .prompt     = "> ",
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   325
    };
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   326
    struct console *console;
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   327
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   328
    log_info("initializing the console");
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   329
    
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
   330
    // init the console
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   331
    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
   332
        return ERROR_CODE(err);
137
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   333
    
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   334
    // set it as the log output handler
c607c357c486 implement console_print and log_set_func
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   335
    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
   336
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
   337
    // 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
   338
    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
   339
        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
   340
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
    // 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
   342
    return SUCCESS;
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   343
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   344
error:
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   345
    console_destroy(console);
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   346
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   347
    return ERROR_CODE(err);
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   348
}
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   349
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   350
err_t nexus_load_config (struct nexus *nexus, const char *path, error_t *err)
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   351
{
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   352
    return lua_config_load(nexus->lua, path, err);
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   353
}
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   354
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   355
/**
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
   356
 * 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
   357
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   358
static err_t apply_config (struct nexus *nexus, char *path, error_t *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
   359
{
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
    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
   361
    
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   362
    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
   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
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
   365
/**
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   366
 * 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
   367
 */
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   368
static err_t parse_args (struct nexus *nexus, int argc, char **argv, error_t *err)
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   369
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   370
    int opt, option_index;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   371
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   372
    // 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
   373
    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
   374
        switch (opt) {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   375
            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
   376
                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
   377
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   378
                // XXX: return instead
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   379
                exit(EXIT_SUCCESS);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   380
            
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   381
            // XXX: come up with something nicer for parsing these command-line options            
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   382
            case OPT_NETWORK:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   383
                if (apply_network(nexus, optarg, err))
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   384
                    goto error;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   385
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   386
                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
   387
            
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
            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
   389
                if (apply_defaults(nexus, optarg, err))
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   390
                    goto error;
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
   391
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
   392
                break;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   393
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   394
            case OPT_CHANNEL:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   395
                if (apply_channel(nexus, optarg, err))
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   396
                    goto error;
63
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
                break;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   399
            
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   400
            case OPT_MODULE:
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   401
                if (apply_module(nexus, optarg, err))
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   402
                    goto error;
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   403
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   404
                break;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   405
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
   406
            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
   407
                if (apply_conf(nexus, optarg, err))
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   408
                    goto error;
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   409
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   410
                break;
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   411
            
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   412
            case OPT_DEBUG:
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   413
                set_log_level(LOG_DEBUG);
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   414
                break;
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   415
            
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   416
            case OPT_CONSOLE:
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   417
                if (apply_console(nexus, err))
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   418
                    goto error;
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   419
                
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   420
                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
   421
            
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
            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
   423
                if (apply_config(nexus, optarg, err))
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   424
                    goto error;
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
   425
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
   426
                break;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   427
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   428
            case '?':
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   429
                usage(nexus, argv[0]);
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   430
                return SET_ERROR(err, &general_errors, ERR_CMD_OPT);
63
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
    }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   433
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   434
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   435
    return SUCCESS;
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   436
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   437
error:
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   438
    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
   439
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   440
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   441
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
   442
{
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   443
    // destroy the console
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   444
    if (nexus->lua_console)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   445
        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
   446
    
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   447
    nexus->lua_console = NULL;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   448
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   449
    // unload the modules
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   450
    if (nexus->modules)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   451
       modules_unload(nexus->modules);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   452
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   453
    // quit the irc client
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   454
    if (nexus->client)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   455
       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
   456
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   457
    // remove the signal handlers
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   458
    if (nexus->signals)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   459
        signals_free(nexus->signals);
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
    nexus->signals = NULL;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   462
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   463
    // 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
   464
    nexus->shutdown = true;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   465
}
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   466
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   467
void nexus_crash (struct nexus *nexus)
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   468
{
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   469
    // force-quit the event loop
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   470
    event_base_loopbreak(nexus->ev_base);
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   471
}
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   472
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   473
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
   474
{
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   475
    // destroy the console
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   476
    if (nexus->lua_console)
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   477
        lua_console_destroy(nexus->lua_console);
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   478
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   479
    // destroy the lua state
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   480
    if (nexus->lua)
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   481
        nexus_lua_destroy(nexus->lua);
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   482
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   483
    // destroy the modules
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   484
    if (nexus->modules)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   485
        modules_destroy(nexus->modules);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   486
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   487
    // destroy the irc client
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   488
    if (nexus->client)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   489
        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
   490
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   491
    // remove the signal handlers
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   492
    if (nexus->signals)
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   493
        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
   494
    
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
    // 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
   496
    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
   497
        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
   498
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
   499
    // 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
   500
    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
   501
}
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   502
200
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 180
diff changeset
   503
static void on_sig_shutdown (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
   504
{
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   505
    struct nexus *nexus = arg;
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   506
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   507
    (void) sig;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   508
    (void) what;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   509
    
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   510
    if (!nexus->shutdown) {
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   511
        // shutdown
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   512
        log_info("Terminating...");
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   513
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   514
        nexus_shutdown(nexus);
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   515
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   516
    } else {
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   517
        // already tried to shutdown
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   518
        log_info("Crashing!");
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   519
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   520
        nexus_crash(nexus);
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   521
    }
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   522
}
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   523
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   524
int main (int argc, char **argv) 
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   525
{
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   526
    struct nexus _nexus, *nexus = &_nexus;
217
7728d6ec3abf nexus.c compiles
Tero Marttila <terom@fixme.fi>
parents: 200
diff changeset
   527
    error_t err;
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   528
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   529
    // zero nexus
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   530
    memset(nexus, 0, sizeof(*nexus));
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   531
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   532
    // initialize libevent
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   533
    if ((nexus->ev_base = event_base_new()) == NULL)
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   534
        FATAL("event_base_new");
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   535
    
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   536
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   537
    // initialize signal handlers
218
5229a5d098b2 some of spbot and lib compiles
Tero Marttila <terom@fixme.fi>
parents: 217
diff changeset
   538
    if (signals_create(&nexus->signals, nexus->ev_base, &err))
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   539
        FATAL("signals_create");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   540
 
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   541
    // 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
   542
    if (signal_ignore(SIGPIPE, &err))
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   543
        FATAL_ERROR(&err, "signals_ignore");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   544
    
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   545
    // add our SIGTERM handler before console_init()?
200
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 180
diff changeset
   546
    if (
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 180
diff changeset
   547
            (ERROR_CODE(&err) = signals_add(nexus->signals, SIGTERM, on_sig_shutdown, nexus))
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 180
diff changeset
   548
        ||  (ERROR_CODE(&err) = signals_add(nexus->signals, SIGINT, on_sig_shutdown, nexus))
c414343101df don't keep console SIGINT behaviour after it was destroyed, instead, have nexus handle it like SIGTERM, and have console override that
Tero Marttila <terom@fixme.fi>
parents: 180
diff changeset
   549
    )
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   550
        FATAL_ERROR(&err, "signals_add");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   551
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   552
    // initialize sock module
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   553
    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
   554
        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
   555
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   556
    // modules 
218
5229a5d098b2 some of spbot and lib compiles
Tero Marttila <terom@fixme.fi>
parents: 217
diff changeset
   557
    if (modules_create(&nexus->modules, nexus, &err))
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   558
        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
   559
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   560
    // the IRC client
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   561
    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
   562
        FATAL_ERROR(&err, "irc_client_create");
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   563
    
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   564
    // lua state
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   565
    if (nexus_lua_create(&nexus->lua, nexus, &err))
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   566
        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
   567
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   568
    
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   569
    // parse args
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   570
    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
   571
        FATAL_ERROR(&err, "parse_args");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   572
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   573
  
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   574
    // 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
   575
    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
   576
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   577
    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
   578
        if (nexus->shutdown) {
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   579
            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
   580
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   581
        } else {
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   582
            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
   583
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   584
        }
170
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   585
    } else {
1b2f28e26eef replace old SIGINT handling with SIGTERM, and have SIGINT just abort the console input line. Now EOF (^D) will cause lua_console to nexus_shutdown
Tero Marttila <terom@fixme.fi>
parents: 140
diff changeset
   586
        log_warn("zero return from event_base_dispatch");
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   587
    }
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   588
109
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   589
    // cleanup
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   590
    nexus_destroy(nexus);
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   591
    nexus = NULL;
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   592
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   593
    // ok
bfe9b9a8fe5b fix some more valgrind errors
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
   594
    return EXIT_SUCCESS;
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   595
}
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   596