src/nexus.c
author Tero Marttila <terom@fixme.fi>
Wed, 01 Apr 2009 00:57:34 +0300
changeset 105 b6b183fbf373
parent 103 454aea1e4f11
child 106 f00661136ac2
permissions -rw-r--r--
implement a separate nexus_lua module
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     1
#include "nexus.h"
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     2
#include "signals.h"
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     3
#include "log.h"
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
#include <stdlib.h>
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
     6
#include <stdbool.h>
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
#include <stdio.h>
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
     8
#include <getopt.h>
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     9
#include <signal.h>
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    10
#include <string.h>
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    12
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    13
 * Command-line option codes
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    14
 */
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    15
enum option_code {
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    16
    OPT_HELP            = 'h',
98
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    17
    OPT_DEFAULTS        = 'D',
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    18
    OPT_NETWORK         = 'n',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    19
    OPT_CHANNEL         = 'c',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    20
    OPT_MODULE          = 'm',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    21
    OPT_CONFIG          = 'C',
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    22
    OPT_DEBUG           = 'd',
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    23
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    24
    /** Options without short names */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    25
    _OPT_EXT_BEGIN      = 0x00ff,
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    26
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    27
    OPT_CONSOLE,
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
    28
};
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    29
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    30
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    31
 * Command-line option definitions
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    32
 */
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    33
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
    34
    {"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
    35
    {"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
    36
    {"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
    37
    {"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
    38
    {"module",          1,  NULL,   OPT_MODULE      },
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    39
    {"config",          1,  NULL,   OPT_CONFIG      },
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    40
    {"debug",           0,  NULL,   OPT_DEBUG       },
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    41
    {"console",         0,  NULL,   OPT_CONSOLE     },
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    42
    {0,                 0,  0,      0               },
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    43
};
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    44
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    45
/**
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    46
 * 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
    47
 *
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    48
 * 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
    49
 */
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    50
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
    51
{
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    52
    printf("Usage: %s [OPTIONS]\n", exe);
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    53
    printf("\n");
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    54
    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
    55
    printf(" --defaults / -D        set the IRC client default info using '<nickname>:<username>:<realname>'\n");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    56
    printf(" --network / -n         add an IRC network using '<name>:<hostname>[:<port>[:ssl]]' format\n");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    57
    printf(" --channel / -c         add an IRC channel using '<network>:<channel>' format\n");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    58
    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
    59
    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
    60
    printf(" --debug / -d           set logging level to DEBUG\n");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    61
    printf(" --console              use the interactive console\n");
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    62
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    63
    // 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
    64
    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
    65
        struct module *module;
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    66
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    67
        printf("\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    68
        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
    69
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    70
        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
    71
            printf("\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    72
            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
    73
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
    74
            // 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
    75
            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
    76
                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
    77
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
    78
                for (opt = module->desc->config_options; opt->name && opt->type; opt++) {
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    79
                    printf(" --config %s:%s:%s\t\t%s\n", module->info.name, opt->name, opt->description, opt->help);
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    80
                }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    81
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    82
            } else {
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    83
                printf("\t???\n");
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    84
            }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    85
        }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
    86
    }
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    87
}
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    88
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    89
/**
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
    90
 * 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
    91
 */
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
    92
static err_t apply_defaults (struct nexus *nexus, char *opt, struct error_info *err)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
    93
{
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
    94
    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
    95
        .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
    96
        .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
    97
        .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
    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
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
    // 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
   101
    if ((defaults.register_info.nickname = strsep(&opt, ":")) == NULL)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   102
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <nickname> field for --defaults");
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   103
    
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
    if ((defaults.register_info.username = strsep(&opt, ":")) == NULL)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   105
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <username> field for --defaults");
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   106
    
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   107
    if ((defaults.register_info.realname = strsep(&opt, ":")) == NULL)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   108
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <realname> field for --defaults");
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   109
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
    // 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
   111
    if (opt)
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   112
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel");
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   113
    
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   114
    // 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
   115
    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
   116
            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
   117
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   118
    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
   119
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
    // ok
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   121
    return SET_ERROR(err, SUCCESS);
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   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
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
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   125
 * 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
   126
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   127
static err_t apply_network (struct nexus *nexus, char *opt, struct error_info *err)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   128
{
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
   129
    struct irc_net_info info;
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   130
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   131
    // 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
   132
    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
   133
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   134
    // parse the required fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   135
    if ((info.network = strsep(&opt, ":")) == NULL)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   136
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --network");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   137
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   138
    if ((info.hostname = strsep(&opt, ":")) == NULL)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   139
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <hostname> field for --network");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   140
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   141
    // parse the optional fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   142
    if (opt)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   143
        info.service = strsep(&opt, ":");
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 any remaining flags
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   146
    while (opt) {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   147
        char *flag = strsep(&opt, ":");
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 (strcmp(flag, "ssl"))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   150
            info.use_ssl = true;
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
        else
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   153
            RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unrecognized flag for --network");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   154
    }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   155
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   156
    // create the net
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   157
    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
   158
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   159
    if (irc_client_add_net(nexus->client, NULL, &info, err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   160
        return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   161
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   162
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   163
    return SET_ERROR(err, SUCCESS);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   164
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   165
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   166
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   167
 * 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
   168
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   169
static err_t apply_channel (struct nexus *nexus, char *opt, struct error_info *err)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   170
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   171
    const char *network = NULL;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   172
    struct irc_net *net;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   173
    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
   174
        .channel            = NULL,
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   175
    };
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   176
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   177
    // parse the required fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   178
    if ((network = strsep(&opt, ":")) == NULL)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   179
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <network> field for --channel");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   180
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   181
    if ((info.channel = strsep(&opt, ":")) == NULL)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   182
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <channel> field for --channel");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   183
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   184
    // trailing garbage?
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   185
    if (opt)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   186
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   187
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   188
    // look up the net
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   189
    if ((net = irc_client_get_net(nexus->client, network)) == NULL)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   190
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unknown network for --channel");
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   191
    
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   192
    // add the channel
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   193
    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
   194
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   195
    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
   196
        return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   197
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   198
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   199
    return SUCCESS;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   200
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   201
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   202
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   203
 * 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
   204
 */
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   205
static err_t apply_module (struct nexus *nexus, char *opt, struct error_info *err)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   206
{
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   207
    struct module_info info = {
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   208
        .name       = NULL,
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   209
        .path       = NULL,
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   210
    };
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   211
    struct module *module;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   212
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   213
    // parse the required fields
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   214
    if ((info.name = strsep(&opt, ":")) == NULL)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   215
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --module");
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   216
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   217
    if ((info.path = strsep(&opt, ":")) == NULL)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   218
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <path> field for --module");
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   219
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   220
    // trailing garbage?
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   221
    if (opt)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   222
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "trailing values for --channel");
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   223
    
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   224
    // load it
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   225
    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
   226
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   227
    if (module_load(nexus->modules, &module, &info, err))
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   228
        return ERROR_CODE(err);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   229
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   230
    // ok
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   231
    return SUCCESS;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   232
}
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   233
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   234
/**
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   235
 * Parse and apply a --config option, calling the module's conf func.
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   236
 */
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   237
static err_t apply_config (struct nexus *nexus, char *opt, struct error_info *err)
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   238
{
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   239
    struct module *module;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   240
    const char *module_name, *conf_name;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   241
    char *conf_value;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   242
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   243
    // parse the required fields
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   244
    if ((module_name = strsep(&opt, ":")) == NULL)
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   245
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <module> field for --config");
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   246
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   247
    if ((conf_name = strsep(&opt, ":")) == NULL)
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   248
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "missing <name> field for --config");
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   249
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   250
    // 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
   251
    conf_value = opt;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   252
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   253
    // lookup the module
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   254
    if ((module = module_get(nexus->modules, module_name)) == NULL)
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   255
        RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "unknown module for --config");
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   256
    
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   257
    // do the config
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   258
    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
   259
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
   260
    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
   261
        return ERROR_CODE(err);
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   262
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   263
    // ok
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   264
    return SUCCESS;
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   265
}
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   266
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   267
/**
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   268
 * Open the console
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   269
 */
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   270
static err_t apply_console (struct nexus *nexus, struct error_info *err)
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   271
{
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   272
    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
   273
        .prompt     = "> ",
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   274
    };
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   275
    struct console *console;
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   276
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   277
    log_info("initializing the console");
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   278
    
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
   279
    // init the console
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   280
    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
   281
        return ERROR_CODE(err);
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
   282
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
   283
    // 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
   284
    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
   285
        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
   286
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
   287
    // 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
   288
    return SUCCESS;
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   289
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   290
error:
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   291
    console_destroy(console);
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   292
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   293
    return ERROR_CODE(err);
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   294
}
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   295
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   296
/**
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   297
 * 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
   298
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   299
static err_t parse_args (struct nexus *nexus, int argc, char **argv, struct error_info *err)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   300
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   301
    int opt, option_index;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   302
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   303
    // parse options
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   304
    while ((opt = getopt_long(argc, argv, "hn:c:m:C:", options, &option_index)) != -1) {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   305
        switch (opt) {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   306
            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
   307
                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
   308
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   309
                // XXX: return instead
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   310
                exit(EXIT_SUCCESS);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   311
            
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   312
            case OPT_NETWORK:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   313
                if (apply_network(nexus, optarg, err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   314
                    return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   315
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   316
                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
   317
            
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
   318
            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
   319
                if (apply_defaults(nexus, optarg, err))
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   320
                    return ERROR_CODE(err);
f357f835f0d5 add irc_client_defaults to apply default values for irc_client_add_net irc_net_info, implement --defaults cmd opt and lua_client_connect
Tero Marttila <terom@fixme.fi>
parents: 93
diff changeset
   321
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
   322
                break;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   323
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   324
            case OPT_CHANNEL:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   325
                if (apply_channel(nexus, optarg, err))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   326
                    return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   327
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   328
                break;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   329
            
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   330
            case OPT_MODULE:
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   331
                if (apply_module(nexus, optarg, err))
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   332
                    return ERROR_CODE(err);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   333
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   334
                break;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   335
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   336
            case OPT_CONFIG:
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   337
                if (apply_config(nexus, optarg, err))
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   338
                    return ERROR_CODE(err);
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   339
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   340
                break;
79
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   341
            
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   342
            case OPT_DEBUG:
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   343
                set_log_level(LOG_DEBUG);
e26f972300e4 add --debug option to nexus
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
   344
                break;
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   345
            
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   346
            case OPT_CONSOLE:
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   347
                if (apply_console(nexus, err))
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   348
                    return ERROR_CODE(err);
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   349
                
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   350
                break;
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   351
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   352
            case '?':
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 79
diff changeset
   353
                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
   354
                return SET_ERROR(err, ERR_CMD_OPT);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   355
        }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   356
    }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   357
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   358
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   359
    return SUCCESS;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   360
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   361
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   362
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
   363
{
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   364
    // destroy the console
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   365
    if (nexus->lua_console)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   366
        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
   367
    
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   368
    nexus->lua_console = NULL;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   369
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   370
    // unload the modules
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   371
    if (nexus->modules)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   372
       modules_unload(nexus->modules);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   373
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   374
    // quit the irc client
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   375
    if (nexus->client)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   376
       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
   377
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   378
    // remove the signal handlers
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   379
    if (nexus->signals)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   380
        signals_free(nexus->signals);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   381
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   382
    nexus->signals = NULL;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   383
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   384
    // 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
   385
    nexus->shutdown = true;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   386
}
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   387
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   388
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
   389
{
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   390
    // destroy the lua state
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   391
    if (nexus->lua)
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   392
        nexus_lua_destroy(nexus->lua);
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   393
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   394
    // destroy the modules
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   395
    if (nexus->modules)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   396
        modules_destroy(nexus->modules);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   397
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   398
    nexus->modules = NULL;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   399
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   400
    // destroy the irc client
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   401
    if (nexus->client)
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   402
        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
   403
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   404
    nexus->client = NULL;
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   405
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   406
    // then force-quit the event loop
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   407
    event_base_loopbreak(nexus->ev_base);
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   408
}
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   409
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   410
static void on_sigint (evutil_socket_t sig, short what, void *arg)
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   411
{
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   412
    struct nexus *nexus = arg;
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   413
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   414
    (void) sig;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   415
    (void) what;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   416
    
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   417
    log_info("Quitting...");
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   418
    
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   419
    // shutdown
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   420
    nexus_shutdown(nexus);
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   421
}
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   422
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   423
int main (int argc, char **argv) 
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   424
{
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   425
    struct nexus _nexus, *nexus = &_nexus;
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   426
    struct error_info err;
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   427
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   428
    // zero nexus
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   429
    memset(nexus, 0, sizeof(*nexus));
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   430
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   431
    // initialize libevent
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   432
    if ((nexus->ev_base = event_base_new()) == NULL)
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   433
        FATAL("event_base_new");
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   434
    
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   435
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   436
    // initialize signal handlers
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   437
    if ((ERROR_CODE(&err) = signals_create(&nexus->signals, nexus->ev_base)))
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   438
        FATAL("signals_create");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   439
 
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   440
    // 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
   441
    if (signal_ignore(SIGPIPE, &err))
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   442
        FATAL_ERROR(&err, "signals_ignore(SIGPIPE)");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   443
    
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   444
    // XXX: add our SIGINT handler after console_init()?
71
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   445
    if ((ERROR_CODE(&err) = signals_add(nexus->signals, SIGINT, &on_sigint, nexus)))
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   446
        FATAL_ERROR(&err, "signals_add(SIGINT)");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   447
 
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   448
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   449
    // initialize sock module
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   450
    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
   451
        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
   452
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   453
    // modules 
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   454
    if ((ERROR_CODE(&err) = modules_create(&nexus->modules, nexus)))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   455
        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
   456
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   457
    // the IRC client
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   458
    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
   459
        FATAL_ERROR(&err, "irc_client_create");
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   460
    
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   461
    // lua state
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   462
    if (nexus_lua_create(&nexus->lua, nexus, &err))
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   463
        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
   464
105
b6b183fbf373 implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents: 103
diff changeset
   465
    
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   466
    // parse args
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   467
    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
   468
        FATAL_ERROR(&err, "parse_args");
92
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   469
99661e5aac91 add a simple interactive readline console
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   470
  
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   471
    // 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
   472
    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
   473
103
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   474
    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
   475
        if (nexus->shutdown) {
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   476
            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
   477
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   478
        } else {
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   479
            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
   480
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   481
        }
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   482
    }
454aea1e4f11 implement nexus_shutdown, lua_modules/lua_module, and lua_nexus
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
   483
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   484
    // ok, no cleanup
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   485
    return 0;
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   486
}
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   487