src/nexus.c
author Tero Marttila <terom@fixme.fi>
Mon, 16 Mar 2009 01:03:41 +0200
changeset 65 d7508879ad01
parent 63 d399a1d915a3
child 66 ef8c9d7daf62
permissions -rw-r--r--
add --module support, and tweak irc_net docs
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
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    12
#define DEFAULT_HOST "irc.fixme.fi"
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    13
#define DEFAULT_PORT "6667"
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    14
#define DEFAULT_PORT_SSL "6697"
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    16
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    17
 * Command-line option codes
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    18
 */
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
    19
enum option_code {
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    20
    OPT_HELP            = 'h',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    21
    OPT_NETWORK         = 'n',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    22
    OPT_CHANNEL         = 'c',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    23
    OPT_MODULE          = 'm',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    24
    OPT_CONFIG          = 'C',
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    25
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    26
    /** Options without short names */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    27
    _OPT_EXT_BEGIN      = 0x00ff,
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
};
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    30
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    31
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    32
 * Command-line option definitions
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    33
 */
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    34
static struct option options[] = {
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    35
    {"help",            0,  NULL,   OPT_HELP        },
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      },
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    40
    {0,                 0,  0,      0               },
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    41
};
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    42
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    43
/**
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    44
 * Display --help output on stdout
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    45
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    46
static void usage (const char *exe) 
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    47
{
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    48
    printf("Usage: %s [OPTIONS]\n", exe);
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    49
    printf("\n");
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    50
    printf(" --help / -h            display this message\n");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    51
    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
    52
    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
    53
    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
    54
    printf(" --config / -C          add a module configuration option using '<mod_name>:<name>[:<value>]' format\n");
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    55
}
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    56
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    57
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
    58
 * 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
    59
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    60
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
    61
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    62
    struct irc_net_info info = {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    63
        .network            = NULL,
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    64
        .hostname           = NULL,
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    65
        .service            = DEFAULT_PORT,
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    66
        .use_ssl            = false,
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    67
        .register_info      = {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    68
            .nickname       = "SpBotDev",
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    69
            .username       = "spbot-dev",
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    70
            .realname       = "SpBot (development version)"
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    71
        }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    72
    };
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    73
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    74
    // parse the required fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    75
    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
    76
        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
    77
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    78
    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
    79
        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
    80
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    81
    // parse the optional fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    82
    if (opt)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    83
        info.service = strsep(&opt, ":");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    84
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    85
    // parse any remaining flags
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    86
    while (opt) {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    87
        char *flag = strsep(&opt, ":");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    88
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    89
        if (strcmp(flag, "ssl"))
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    90
            info.use_ssl = true;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    91
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    92
        else
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    93
            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
    94
    }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    95
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
    96
    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
    97
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    98
    // create the net
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
    99
    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
   100
        return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   101
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   102
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   103
    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
   104
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   105
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   106
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   107
 * 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
   108
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   109
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
   110
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   111
    const char *network = NULL;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   112
    struct irc_net *net;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   113
    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
   114
        .channel            = NULL,
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   115
    };
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   116
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   117
    // parse the required fields
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   118
    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
   119
        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
   120
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   121
    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
   122
        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
   123
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   124
    // trailing garbage?
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   125
    if (opt)
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   126
        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
   127
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   128
    // look up the net
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   129
    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
   130
        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
   131
    
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   132
    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
   133
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   134
    // add the channel
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   135
    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
   136
        return ERROR_CODE(err);
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
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   139
    return SUCCESS;
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
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   142
/**
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   143
 * 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
   144
 */
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   145
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
   146
{
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   147
    struct module_info info = {
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   148
        .name       = NULL,
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   149
        .path       = NULL,
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   150
    };
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   151
    struct module *module;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   152
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   153
    // parse the required fields
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   154
    if ((info.name = strsep(&opt, ":")) == NULL)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   155
        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
   156
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   157
    if ((info.path = strsep(&opt, ":")) == NULL)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   158
        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
   159
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   160
    // trailing garbage?
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   161
    if (opt)
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   162
        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
   163
    
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   164
    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
   165
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   166
    // load it
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   167
    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
   168
        return ERROR_CODE(err);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   169
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   170
    // ok
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   171
    return SUCCESS;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   172
}
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   173
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   174
/**
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   175
 * 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
   176
 */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   177
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
   178
{
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   179
    int opt, option_index;
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
    // parse options
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   182
    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
   183
        switch (opt) {
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   184
            case OPT_HELP:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   185
                usage(argv[0]);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   186
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   187
                // XXX: return instead
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   188
                exit(EXIT_SUCCESS);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   189
            
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   190
            case OPT_NETWORK:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   191
                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
   192
                    return ERROR_CODE(err);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   193
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   194
                break;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   195
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   196
            case OPT_CHANNEL:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   197
                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
   198
                    return ERROR_CODE(err);
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
                break;
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
            case OPT_MODULE:
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   203
                if (apply_module(nexus, optarg, err))
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   204
                    return ERROR_CODE(err);
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   205
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   206
                break;
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
   207
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   208
            case OPT_CONFIG:
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   209
                RETURN_SET_ERROR_STR(err, ERR_CMD_OPT, "option unimplemented");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   210
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   211
            case '?':
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   212
                usage(argv[0]);
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   213
                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
   214
        }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   215
    }
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   216
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   217
    // ok
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   218
    return SUCCESS;
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   219
}
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   220
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   221
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
   222
{
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
   223
    struct nexus *ctx = arg;
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   224
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   225
    (void) sig;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   226
    (void) what;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   227
    
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   228
    if (ctx->client && !ctx->client->quitting) {
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   229
        log_info("Quitting...");
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   230
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   231
        // quit it
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   232
        irc_client_quit(ctx->client, "Goodbye, cruel world ;(");
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   233
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   234
    } else {
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   235
        log_error("Aborting");
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   236
        
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   237
        // die
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   238
        if (ctx->client) {
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   239
            irc_client_destroy(ctx->client);
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   240
            ctx->client = NULL;
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   241
        }
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   242
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   243
        // exit
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   244
        event_base_loopexit(ctx->ev_base, NULL);
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   245
    }
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   246
}
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   247
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   248
int main (int argc, char **argv) 
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   249
{
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   250
    struct signals *signals;
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   251
    struct error_info err;
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   252
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   253
    struct nexus _nexus, *nexus = &_nexus;
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   254
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   255
    // zero nexus
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   256
    memset(nexus, 0, sizeof(*nexus));
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   257
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   258
    // initialize libevent
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   259
    if ((nexus->ev_base = event_base_new()) == NULL)
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   260
        FATAL("event_base_new");
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   261
    
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   262
    // initialize signal handlers
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   263
    if ((ERROR_CODE(&err) = signals_create(&signals, nexus->ev_base)))
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   264
        FATAL("signals_create");
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   265
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   266
    // add our signal handlers
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   267
    if (
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   268
            (ERROR_CODE(&err) = signals_add(signals, SIGPIPE, &signals_ignore, signals))
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   269
        ||  (ERROR_CODE(&err) = signals_add(signals, SIGINT, &on_sigint, nexus))
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   270
    )
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   271
        FATAL_ERROR(&err, "signals_add");
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   272
 
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   273
    // initialize sock module
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   274
    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
   275
        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
   276
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   277
    // modules 
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   278
    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
   279
        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
   280
    
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   281
    // the IRC client
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   282
    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
   283
        FATAL_ERROR(&err, "irc_client_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
   284
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   285
    // parse args
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   286
    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
   287
        FATAL_ERROR(&err, "parse_args");
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   288
   
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   289
    // run event loop
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   290
    if (event_base_dispatch(nexus->ev_base))
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   291
        FATAL("event_base_dispatch");
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   292
    
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   293
    // ok, no cleanup
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   294
    return 0;
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   295
}
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   296