src/nexus.c
author Tero Marttila <terom@fixme.fi>
Mon, 16 Mar 2009 00:09:53 +0200
branchbuild-cmake
changeset 61 4ba21936518a
parent 56 942370000450
child 63 d399a1d915a3
permissions -rw-r--r--
temporarily disable evsql stuff
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
     1
#include "nexus.h"
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
     2
#include "irc_log.h"
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     3
#include "signals.h"
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     4
#include "log.h"
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
#include <stdlib.h>
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
     7
#include <stdbool.h>
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
#include <stdio.h>
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
     9
#include <getopt.h>
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    10
#include <signal.h>
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
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 22
diff changeset
    16
enum option_code {
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
    17
    _OPT_LOG_BEGIN      = 0x00ff,
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
    18
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
    OPT_LOG_DATABASE,
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
    20
    OPT_LOG_CHANNEL,
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
    21
};
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
    22
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    23
static struct option options[] = {
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
    24
    {"help",            0,  NULL,   'h'                 },
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
    25
    {"hostname",        1,  NULL,   'H'                 },
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
    26
    {"port",            1,  NULL,   'P'                 },
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
    27
    {"ssl",             0,  NULL,   'S'                 },
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
    {"log-database",    1,  NULL,   OPT_LOG_DATABASE    },
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
    {"log-channel",     1,  NULL,   OPT_LOG_CHANNEL     },
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
    {0,                 0,  0,      0                   },
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    31
};
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    32
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    33
void usage (const char *exe) 
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    34
{
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    35
    printf("Usage: %s [OPTIONS]\n", exe);
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    36
    printf("\n");
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    37
    printf(" --help / -h            display this message\n");
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    38
    printf(" --hostname / -H HOST   set hostname to connect to\n");
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    39
    printf(" --port / -P PORT       set service port to connect to\n");
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    40
    printf(" --ssl / -S             use SSL\n");
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
    41
    printf(" --log-database         database connection string for logging\n");
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
    42
    printf(" --log-channel          channel to log\n");
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
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    45
void on_sigint (evutil_socket_t sig, short what, void *arg)
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    46
{
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
    47
    struct nexus *ctx = arg;
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    49
    (void) sig;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    50
    (void) what;
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    51
    
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    52
    if (ctx->client && !ctx->client->quitting) {
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    53
        log_info("Quitting...");
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    54
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    55
        // quit it
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    56
        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
    57
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    58
    } else {
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    59
        log_error("Aborting");
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    60
        
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    61
        // die
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    62
        if (ctx->client) {
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    63
            irc_client_destroy(ctx->client);
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    64
            ctx->client = NULL;
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    65
        }
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    66
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    67
        // exit
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    68
        event_base_loopexit(ctx->ev_base, NULL);
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    69
    }
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    70
}
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    71
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    72
int main (int argc, char **argv) 
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    73
{
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    74
    int opt, option_index;
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    75
    struct signals *signals;
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
    76
    struct nexus ctx;
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    77
    struct irc_net *net;
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    78
    struct error_info err;
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    80
    struct irc_net_info net_info = {
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
    81
        .network                    = "default",
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    82
        .hostname                   = DEFAULT_HOST,
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    83
        .service                    = DEFAULT_PORT,
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    84
        .use_ssl                    = false,
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    85
        .register_info              = {
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    86
            .nickname               = "SpBotDev",
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    87
            .username               = "spbot-dev",
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    88
            .realname               = "SpBot (development version)",
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    89
        }
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    90
    };
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents: 25
diff changeset
    91
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
    92
    // XXX: hardcode irc_log config
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
    93
    char *log_db_info = NULL;
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents: 25
diff changeset
    94
    struct irc_chan_info log_chan_info = {
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents: 25
diff changeset
    95
        .channel                    = NULL, 
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents: 25
diff changeset
    96
    };
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents: 25
diff changeset
    97
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    98
    bool port_default = true;
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
    99
    
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   100
    // parse options
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   101
    while ((opt = getopt_long(argc, argv, "hH:P:S", options, &option_index)) != -1) {
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   102
        switch (opt) {
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   103
            case 'h':
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   104
                usage(argv[0]);
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   105
                return EXIT_SUCCESS;
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   106
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   107
            case 'H':
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
   108
                net_info.hostname = optarg;
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   109
                break;
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   110
            
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   111
            case 'P':
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
   112
                net_info.service = optarg;
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   113
                port_default = false;
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   114
                break;
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   115
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   116
            case 'S':
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
   117
                net_info.use_ssl = true;
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   118
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   119
                if (port_default)
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
   120
                    net_info.service = DEFAULT_PORT_SSL;
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
   121
16
20ce0029e4a0 missing break
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
   122
                break;
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
   123
            
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
   124
            case OPT_LOG_DATABASE:
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
   125
                log_db_info = optarg;
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
   126
                break;
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
   127
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
   128
            case OPT_LOG_CHANNEL:
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents: 25
diff changeset
   129
                log_chan_info.channel = optarg;
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
   130
                break;
15
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   131
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   132
            case '?':
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   133
                usage(argv[0]);
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   134
                return EXIT_FAILURE;
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   135
        }
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   136
    }
9bbeace56269 add some simple command-line options
Tero Marttila <terom@fixme.fi>
parents: 14
diff changeset
   137
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   138
    // initialize libevent
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   139
    if ((ctx.ev_base = event_base_new()) == NULL)
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   140
        FATAL("event_base_new");
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   141
    
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   142
    // initialize signal handlers
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   143
    if ((ERROR_CODE(&err) = signals_create(&signals, ctx.ev_base)))
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   144
        FATAL("signals_create");
9
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   145
4c4c906cc649 add sock_stream_callbacks and ev_base
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   146
    // initialize sock module
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   147
    if (sock_init(ctx.ev_base, &err))
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   148
        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
   149
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
   150
    // modules 
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
   151
    if ((ERROR_CODE(&err) = modules_create(&ctx.modules, &ctx)))
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
   152
        FATAL_ERROR(&err, "modules_create");
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
   153
    
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   154
    // the IRC client
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   155
    if (irc_client_create(&ctx.client, &err))
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   156
        FATAL_ERROR(&err, "irc_client_create");
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   157
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
   158
    // the IRC network
53
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   159
    if (irc_client_add_net(ctx.client, &net, &net_info))
12d806823775 add irc_client module, plus nexus.h header
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
   160
        FATAL_ERR(ERROR_CODE(&err), "irc_client_add_net");
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   161
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   162
    // add our signal handlers
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   163
    if (
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   164
            (ERROR_CODE(&err) = signals_add(signals, SIGPIPE, &signals_ignore, signals))
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   165
        ||  (ERROR_CODE(&err) = signals_add(signals, SIGINT, &on_sigint, &ctx))
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   166
    )
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   167
        FATAL_ERROR(&err, "signals_add");
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
   168
    
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
   169
    // logging?
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
   170
    if (log_db_info || log_chan_info.channel) {
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
   171
        struct module *mod_irc_log;
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
   172
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
   173
        struct module_info mod_irc_log_info = {
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
   174
            .name = "irc_log",
61
4ba21936518a temporarily disable evsql stuff
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   175
            .path = "modules/libirc_log.so"
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
   176
        };
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
   177
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
   178
        // load the module
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
   179
        if (module_load(ctx.modules, &mod_irc_log, &mod_irc_log_info, &err))
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
   180
            FATAL_ERROR(&err, "module_load");
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
   181
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents: 25
diff changeset
   182
        // get the channel
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
   183
        if (log_chan_info.channel) {
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   184
            char conf_channel[] = "default/#test";
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   185
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
   186
            // create the channel
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
   187
            if ((irc_net_add_chan(net, &log_chan_info)) == NULL)
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
   188
                FATAL("irc_net_add_chan");
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
   189
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
   190
            // configure it
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
   191
            // XXX: hardcoded
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   192
            if (module_conf(mod_irc_log, "channel", conf_channel, &err))
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   193
                FATAL_ERROR(&err, "module_conf(irc_log, '%s', '%s)", "channel", conf_channel);
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
   194
        }
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
   195
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
   196
        // configure the databse info
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   197
        if (log_db_info && module_conf(mod_irc_log, "db_info", log_db_info, &err))
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
   198
            FATAL_ERROR(&err, "module_conf(irc_log, 'db_info', '%s')", log_db_info);
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
   199
    }
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   200
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   201
    // run event loop
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   202
    if (event_base_dispatch(ctx.ev_base))
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   203
        FATAL("event_base_dispatch");
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   204
    
11
14e79683c48c working event-based operation for sock_tcp
Tero Marttila <terom@fixme.fi>
parents: 10
diff changeset
   205
    // ok, no cleanup
0
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   206
    return 0;
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   207
}
317e5bc59627 initial code...
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   208