src/irc_log.c
author Tero Marttila <terom@fixme.fi>
Mon, 16 Mar 2009 20:22:51 +0200
changeset 67 aa94bf2b5f9b
parent 66 ef8c9d7daf62
child 68 591a574f390e
permissions -rw-r--r--
implement the SQL logs table and the INSERT-logging code for mod_irc_log
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
     1
#include "module.h"
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
     2
#include "irc_chan.h"
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
     3
#include "error.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:
diff changeset
     4
#include "log.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:
diff changeset
     5
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
     6
#include <stdlib.h>
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: 45
diff changeset
     7
#include <string.h>
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: 45
diff changeset
     8
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
     9
#include <event2/event.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:
diff changeset
    10
#include <evsql.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:
diff changeset
    11
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:
diff changeset
    12
/**
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    13
 * The irc_log module state
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:
diff changeset
    14
 */
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    15
struct irc_log_ctx {
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    16
    /** The nexus this module is loaded for */
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    17
    struct nexus *nexus;
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
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:
diff changeset
    19
    /** The database connection */
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:
diff changeset
    20
    struct evsql *db;
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:
diff changeset
    21
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    22
};
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:
diff changeset
    23
67
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    24
static void irc_log_on_sql_result (struct evsql_result *res, void *arg)
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    25
{
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    26
    struct irc_log_ctx *ctx = arg;
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    27
    err_t err;
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    28
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    29
    (void) ctx;
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    30
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    31
    if ((err = evsql_result_check(res)))
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    32
        log_error("irc_log_event: %s", evsql_result_error(res));
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    33
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    34
    // ok
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    35
    evsql_result_free(res);
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    36
}
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    37
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    38
static void irc_log_event (struct irc_log_ctx *ctx, struct irc_chan *chan, const struct irc_nm *source,
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    39
        const char *type, const char *target, const char *message)
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    40
{
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    41
    struct evsql_query *query;
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    42
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    43
    // our SQL query
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    44
    static struct evsql_query_info sql = {
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    45
        "INSERT INTO logs ("
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    46
        "  network, channel, nickname, username, hostname, type, target, message"
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    47
        " ) VALUES ("
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    48
        "  $1::varchar, $2::varchar, $3::varchar, $4::varchar, $5::varchar, $6::varchar, $7::varchar, $8::varchar"
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    49
        " )", { 
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    50
            EVSQL_TYPE(STRING),     // network
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    51
            EVSQL_TYPE(STRING),     // channel
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    52
            EVSQL_TYPE(STRING),     // nickname
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    53
            EVSQL_TYPE(STRING),     // username
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    54
            EVSQL_TYPE(STRING),     // hostname
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    55
            EVSQL_TYPE(STRING),     // type
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    56
            EVSQL_TYPE(STRING),     // target
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    57
            EVSQL_TYPE(STRING),     // message
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    58
            EVSQL_TYPE_END
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    59
        }
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    60
    };
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    61
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    62
    // run the INSERT
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    63
    if ((query = evsql_query_exec(ctx->db, NULL, &sql, &irc_log_on_sql_result, ctx,
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    64
        chan->net->info.network, irc_chan_name(chan),
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    65
        source->nickname, source->username, source->hostname,
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    66
        type, target, message
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    67
    )) == NULL) {
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    68
        // XXX: get evsql_query error info somehow...
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    69
        log_error("evsql_query_exec failed for %s:%s - %s!%s@%s - %s -> %s - %s", 
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    70
            chan->net->info.network, irc_chan_name(chan),
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    71
            source->nickname, source->username, source->hostname,
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    72
            type, target, message
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    73
        );
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    74
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    75
    } else {
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    76
        log_debug("%s:%s - %s!%s@%s - %s -> %s - %s", 
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    77
            chan->net->info.network, irc_chan_name(chan),
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    78
            source->nickname, source->username, source->hostname,
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    79
            type, target, message
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    80
        );
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    81
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    82
    }
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    83
}
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    84
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
    85
static void on_chan_msg (struct irc_chan *chan, const struct irc_nm *source, const char *message, void *arg)
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:
diff changeset
    86
{
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:
diff changeset
    87
    struct irc_log_ctx *ctx = arg;
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:
diff changeset
    88
67
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
    89
    irc_log_event(ctx, chan, source, "PRIVMSG", NULL, message);
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:
diff changeset
    90
}
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:
diff changeset
    91
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    92
static struct irc_chan_callbacks _chan_callbacks = {
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    93
    .on_msg         = on_chan_msg,
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:
diff changeset
    94
};
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:
diff changeset
    95
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    96
static err_t irc_log_init (struct nexus *nexus, void **ctx_ptr, struct error_info *err)
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:
diff changeset
    97
{
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: 45
diff changeset
    98
    struct irc_log_ctx *ctx;
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    99
    
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   100
    // allocate
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   101
    if ((ctx = calloc(1, sizeof(*ctx))) == NULL)
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   102
        return SET_ERROR(err, ERR_CALLOC);
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: 45
diff changeset
   103
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   104
    // initialize
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   105
    memset(ctx, 0, sizeof(*ctx));
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   106
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   107
    // store
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   108
    ctx->nexus = nexus;
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   109
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   110
    log_info("module initialized");
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   111
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: 45
diff changeset
   112
    // ok
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   113
    *ctx_ptr = ctx;
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   114
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   115
    return SET_ERROR(err, SUCCESS);
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: 45
diff changeset
   116
}
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: 45
diff changeset
   117
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   118
static err_t irc_log_conf (void *mod_ctx, const char *name, char *value, struct error_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: 45
diff changeset
   119
{
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   120
    struct irc_log_ctx *ctx = mod_ctx;
67
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   121
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: 45
diff changeset
   122
    if (strcmp(name, "db_info") == 0) {
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: 45
diff changeset
   123
        log_info("connect to database: %s", value);
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:
diff changeset
   124
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   125
        if ((ctx->db = evsql_new_pq(ctx->nexus->ev_base, value, NULL, NULL)) == NULL)
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:
diff changeset
   126
           return ERR_EVSQL_NEW_PQ;
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: 45
diff changeset
   127
67
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   128
    } else if (strcmp(name, "channel") == 0) {
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   129
        const char *network = strsep(&value, ":");
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: 45
diff changeset
   130
        const char *channel = value;
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: 45
diff changeset
   131
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: 45
diff changeset
   132
        struct irc_chan *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: 45
diff changeset
   133
        
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: 45
diff changeset
   134
        // kill missing tokens
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: 45
diff changeset
   135
        if (!network || !channel) 
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   136
            RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "invalid '<network>:<channel>' value");
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: 45
diff changeset
   137
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: 45
diff changeset
   138
        // get the channel?
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   139
        if ((chan = irc_client_get_chan(ctx->nexus->client, network, channel)) == NULL)
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   140
            RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown channel name");
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: 45
diff changeset
   141
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: 45
diff changeset
   142
        // add channel callbacks
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   143
        if ((ERROR_CODE(err) = irc_chan_add_callbacks(chan, &_chan_callbacks, ctx)))
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   144
            return ERROR_CODE(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: 45
diff changeset
   145
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: 45
diff changeset
   146
    } else {
66
ef8c9d7daf62 all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents: 65
diff changeset
   147
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown configuration option");
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:
diff changeset
   148
    }
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:
diff changeset
   149
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:
diff changeset
   150
    // ok
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:
diff changeset
   151
    return SUCCESS;
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:
diff changeset
   152
}
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:
diff changeset
   153
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   154
/**
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   155
 * The module function table
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   156
 */
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   157
struct module_funcs irc_log_funcs = {
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   158
    .init       = &irc_log_init,
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   159
    .conf       = &irc_log_conf,
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   160
};