src/irc_log.c
author Tero Marttila <terom@fixme.fi>
Mon, 30 Mar 2009 01:47:44 +0300
changeset 88 233916a00429
parent 83 c8e2dac08207
child 100 cfb7776bd6f0
permissions -rw-r--r--
implement CTCP-ACTION for irc_log and test
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"
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
     3
#include "config.h"
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
     4
#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
     5
#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
     6
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
     7
#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
     8
#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
     9
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    10
#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
    11
#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
    12
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
    13
/**
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    14
 * 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
    15
 */
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    16
struct irc_log_ctx {
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    17
    /** The nexus this module is loaded for */
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    18
    struct nexus *nexus;
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    19
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
    20
    /** 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
    21
    struct evsql *db;
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    22
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    23
    /**
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    24
     * Our logged channels
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    25
     */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    26
    TAILQ_HEAD(irc_log_ctx_channels, irc_log_chan) channels;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    27
    
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    28
    /** Are we currently unloading ourself (via irc_log_unload) ? */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    29
    bool unloading;
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    30
};
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
    31
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    32
/**
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    33
 * State required to use irc_cmd_handler with irc_chan.handlers.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    34
 */
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    35
struct irc_log_chan {
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    36
    /** The irc_log context */
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    37
    struct irc_log_ctx *ctx;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    38
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    39
    /** The target channel */
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    40
    struct irc_chan *chan;
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    41
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    42
    /** Are we stopping (irc_log_chan_stop called)? */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    43
    bool stopping;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    44
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    45
    /** We are part of the irc_log_ctx.channels list */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    46
    TAILQ_ENTRY(irc_log_chan) ctx_channels;
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    47
};
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    48
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    49
/*
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    50
 * Forward-declare
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    51
 */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    52
static void irc_log_chan_destroy (struct irc_log_chan *chan_ctx);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    53
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    54
/**
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    55
 * The irc_log_ctx has completed stopping all the channels, and should now destroy itself
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    56
 */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    57
static void irc_log_stopped (struct irc_log_ctx *ctx)
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    58
{
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    59
    // schedule an evsql_destroy
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    60
    if (evsql_destroy_next(ctx->db))
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    61
        log_fatal("evsql_destroy_next failed");
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    62
    
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    63
    // free ourself
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    64
    free(ctx);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    65
}
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    66
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    67
/**
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    68
 * The irc_log_chan has completed shutdown
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    69
 */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    70
static void irc_log_chan_stopped (struct irc_log_chan *chan_ctx)
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    71
{
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    72
    struct irc_log_ctx *ctx = chan_ctx->ctx;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    73
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    74
    // destroy the channel
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    75
    irc_log_chan_destroy(chan_ctx);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    76
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    77
    // was it the final channel for unloading?
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    78
    if (ctx->unloading && TAILQ_EMPTY(&ctx->channels))
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    79
        irc_log_stopped(ctx);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    80
}
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    81
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    82
/**
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    83
 * Our evsql result handler for irc_log_event INSERTs.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
    84
 */
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
    85
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
    86
{
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    87
    struct irc_log_chan *chan_ctx = arg;
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
    88
    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
    89
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    90
    // check errors
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
    91
    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
    92
        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
    93
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    94
    // ok, don't need the result anymore
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
    95
    evsql_result_free(res);
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    96
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    97
    // if stopping, then handle that
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    98
    if (chan_ctx->stopping)
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    99
        irc_log_chan_stopped(chan_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
   100
}
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   101
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   102
/**
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   103
 * Log the event into our database.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   104
 *
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   105
 * Any of chan_ctx, source, target, message can be NULL to insert NULLs
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   106
 */
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   107
static err_t irc_log_event (struct irc_log_ctx *ctx, struct irc_log_chan *chan_ctx, const struct irc_nm *source,
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
   108
        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
   109
{
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   110
    struct evsql_query *query;
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   111
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   112
    // unpack the nick/user/hostname args, as source can be NULL
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   113
    const char *network = chan_ctx ? chan_ctx->chan->net->info.network : NULL;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   114
    const char *channel = chan_ctx ? irc_chan_name(chan_ctx->chan) : NULL;
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   115
    const char *nickname = source ? source->nickname : NULL;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   116
    const char *username = source ? source->username : NULL;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   117
    const char *hostname = source ? source->hostname : NULL;
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
   118
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   119
    // 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
   120
    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
   121
        "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
   122
        "  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
   123
        " ) 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
   124
        "  $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
   125
        " )", { 
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   126
            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
   127
            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
   128
            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
   129
            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
   130
            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
   131
            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
   132
            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
   133
            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
   134
            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
   135
        }
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   136
    };
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   137
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   138
    // drop lines if not connected
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   139
    if (ctx->db == NULL) {
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   140
        log_warn("no database connected");
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   141
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   142
        return ERR_MODULE_CONF;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   143
    }
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
   144
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   145
    // run the INSERT
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   146
    if ((query = evsql_query_exec(ctx->db, NULL, &sql, &irc_log_on_sql_result, chan_ctx,
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   147
        network, channel, nickname, username, hostname, type, target, message
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
   148
    )) == 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
   149
        // 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
   150
        log_error("evsql_query_exec failed for %s:%s - %s!%s@%s - %s -> %s - %s", 
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   151
            network, channel, nickname, username, hostname, type, target, message
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
   152
        );
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   153
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   154
        return ERR_EVSQL_QUERY_EXEC;
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
   155
    }
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   156
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   157
    // ok
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   158
    log_debug("%s:%s - %s!%s@%s - %s -> %s - %s", 
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   159
        network, channel, nickname, username, hostname, type, target, message
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   160
    );
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   161
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   162
    return SUCCESS;
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
   163
}
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 66
diff changeset
   164
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   165
/**
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   166
 * Log a simple channel event of the form:
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   167
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   168
 * :nm <type> <channel> [<msg>]
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   169
 */
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   170
static void irc_log_on_chan_generic (const struct irc_line *line, void *arg)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   171
{
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   172
    struct irc_log_chan *chan_ctx = arg;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   173
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   174
    const char *msg = line->args[1];
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   175
75
ff6272398d2e change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   176
    irc_log_event(chan_ctx->ctx, chan_ctx, line->source, line->command, NULL, msg);
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   177
}
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   178
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   179
/**
80
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   180
 * Log a NICK event on a channel
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   181
 *
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   182
 * :nm NICK <nickname>
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   183
 *
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   184
 * This logs the new nickname as the target
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   185
 */
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   186
static void irc_log_on_chan_NICK (const struct irc_line *line, void *arg)
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   187
{
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   188
    struct irc_log_chan *chan_ctx = arg;
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   189
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   190
    const char *nickname = line->args[0];
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   191
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   192
    // log it
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   193
    irc_log_event(chan_ctx->ctx, chan_ctx, line->source, line->command, nickname, NULL);
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   194
}
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   195
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   196
/**
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   197
 * Log a QUIT event on a channel
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   198
 *
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   199
 * :nm QUIT [<message>]
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   200
 */
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   201
static void irc_log_on_chan_QUIT (const struct irc_line *line, void *arg)
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   202
{
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   203
    struct irc_log_chan *chan_ctx = arg;
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   204
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   205
    const char *message = line->args[0];
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   206
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   207
    // log it
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   208
    irc_log_event(chan_ctx->ctx, chan_ctx, line->source, line->command, NULL, message);
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   209
}
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   210
1b989bc67760 add NICK/QUIT logging to irc_log
Tero Marttila <terom@fixme.fi>
parents: 75
diff changeset
   211
/**
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   212
 * Log a MODE event on a channel
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   213
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   214
 * :nm MODE <channel> [<modearg> [...]]
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   215
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   216
 * This conacts all the modeargs together, and logs that as the message
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   217
 */
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   218
static void irc_log_on_chan_MODE (const struct irc_line *line, void *arg)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   219
{
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   220
    struct irc_log_chan *chan_ctx = arg;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   221
    char message[512], *ptr = message;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   222
    const char *cmdarg;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   223
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   224
    // iterate over each arg
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   225
    FOREACH_IRC_LINE_ARGS(line, cmdarg) {
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   226
        // separate with spaces
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   227
        if (cmdarg > line->args[0])
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   228
            *ptr++ = ' ';
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   229
        
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   230
        // append
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   231
        ptr += snprintf(ptr, (message + 512 - ptr), "%s", cmdarg);
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   232
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   233
        // buffer full?
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   234
        if (ptr > message + 512)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   235
            break;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   236
    }
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   237
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   238
    // log
75
ff6272398d2e change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   239
    irc_log_event(chan_ctx->ctx, chan_ctx, line->source, line->command, NULL, message);
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   240
}
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   241
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   242
/**
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   243
 * Log a KICK event on a channel
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   244
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   245
 * :nm KICK <channel> <target> [<comment>]
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   246
 */
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   247
static void irc_log_on_chan_KICK (const struct irc_line *line, void *arg)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   248
{
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   249
    struct irc_log_chan *chan_ctx = arg;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   250
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   251
    const char *target = line->args[1];    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   252
    const char *msg = line->args[2];
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   253
75
ff6272398d2e change irc_line.prefix into a
Tero Marttila <terom@fixme.fi>
parents: 70
diff changeset
   254
    irc_log_event(chan_ctx->ctx, chan_ctx, line->source, line->command, target, msg);
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   255
}
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   256
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   257
/**
88
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   258
 * Log a CTCP ACTION message on a channel
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   259
 *
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   260
 * :nm "CTCP ACTION" <channel> <action>
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   261
 */
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   262
static void irc_log_on_chan_CTCP_ACTION (const struct irc_line *line, void *arg)
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   263
{
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   264
    struct irc_log_chan *chan_ctx = arg;
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   265
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   266
    const char *action = line->args[1];
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   267
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   268
    irc_log_event(chan_ctx->ctx, chan_ctx, line->source, "ACTION", NULL, action);
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   269
}
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   270
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   271
/**
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   272
 * Our low-level channel-specific message handlers for logged channels.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   273
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   274
 * Note that these get a `struct irc_log_chan*` as an argument.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   275
 */
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   276
static struct irc_cmd_handler _chan_cmd_handlers[] = {
88
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   277
    {   "NICK",         &irc_log_on_chan_NICK           },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   278
    {   "QUIT",         &irc_log_on_chan_QUIT           },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   279
    {   "JOIN",         &irc_log_on_chan_generic        },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   280
    {   "PART",         &irc_log_on_chan_generic        },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   281
    {   "MODE",         &irc_log_on_chan_MODE           },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   282
    {   "TOPIC",        &irc_log_on_chan_generic        },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   283
    {   "KICK",         &irc_log_on_chan_KICK           },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   284
    {   "PRIVMSG",      &irc_log_on_chan_generic        },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   285
    {   "NOTICE",       &irc_log_on_chan_generic        },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   286
    {   "CTCP ACTION",  &irc_log_on_chan_CTCP_ACTION    },
233916a00429 implement CTCP-ACTION for irc_log and test
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   287
    {   NULL,           NULL                            }
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   288
};
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   289
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   290
/**
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   291
 * Our high-level channel-specific callbacks for logged channels.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   292
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   293
 * Note that these get a `struct irc_log_chan*` as an argument.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   294
 */
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   295
static struct irc_chan_callbacks _chan_callbacks = {
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   296
    .on_self_join       = NULL,
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   297
    .on_msg             = 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
   298
};
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
   299
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   300
/**
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   301
 * Release resources associated with the given irc_log_chan without doing any clean shutdown stuff
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   302
 */
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   303
static void irc_log_chan_destroy (struct irc_log_chan *chan_ctx)
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   304
{
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   305
    // remove any handlers/callbacks
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   306
    irc_cmd_remove(&chan_ctx->chan->handlers, _chan_cmd_handlers, chan_ctx);
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   307
    irc_chan_remove_callbacks(chan_ctx->chan, &_chan_callbacks, chan_ctx);
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   308
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   309
    // remove from channels list
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   310
    TAILQ_REMOVE(&chan_ctx->ctx->channels, chan_ctx, ctx_channels);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   311
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   312
    // free ourselves
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   313
    free(chan_ctx);
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   314
}
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   315
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   316
/**
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   317
 * Begin logging the given channel
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   318
 */
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   319
static err_t irc_log_chan (struct irc_log_ctx *ctx, struct irc_chan *chan, struct error_info *err)
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   320
{
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   321
    struct irc_log_chan *chan_ctx;
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   322
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   323
    // alloc
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   324
    if ((chan_ctx = calloc(1, sizeof(*chan_ctx))) == NULL)
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   325
        return SET_ERROR(err, ERR_CALLOC);
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   326
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   327
    // store
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   328
    chan_ctx->ctx = ctx;
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   329
    chan_ctx->chan = chan;
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   330
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   331
    // add to channels list
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   332
    TAILQ_INSERT_TAIL(&ctx->channels, chan_ctx, ctx_channels);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   333
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   334
    // add low-level handlers
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   335
    if ((ERROR_CODE(err) = irc_cmd_add(&chan_ctx->chan->handlers, _chan_cmd_handlers, chan_ctx)))
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   336
        goto error;
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   337
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   338
    // add channel callbacks
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   339
    if ((ERROR_CODE(err) = irc_chan_add_callbacks(chan_ctx->chan, &_chan_callbacks, chan_ctx)))
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   340
        goto error;
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   341
    
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   342
    // log an OPEN message
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   343
    // XXX: move this to when we first JOIN the channel
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   344
    if ((ERROR_CODE(err) = irc_log_event(ctx, chan_ctx, NULL, "OPEN", NULL, NULL)))
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   345
        goto error;
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   346
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   347
    // ok
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   348
    log_info("logging channel %s:%s", chan_ctx->chan->net->info.network, irc_chan_name(chan_ctx->chan));
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   349
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   350
    return SUCCESS;
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   351
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   352
error:
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   353
    // cleanup
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   354
    irc_log_chan_destroy(chan_ctx);
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   355
    
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   356
    return ERROR_CODE(err);
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   357
}
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   358
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   359
/**
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   360
 * Stop logging the given channel, shutting it down nicely and then releasing its resources.
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   361
 *
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   362
 * If shutting it down nicely fails, this just destroys it.
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   363
 */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   364
static err_t irc_log_chan_stop (struct irc_log_chan *chan_ctx)
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   365
{
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   366
    err_t err;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   367
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   368
    // mark it as stopping, so the result callback knows to destroy it
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   369
    chan_ctx->stopping = true;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   370
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   371
    // log the CLOSE event
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   372
    if ((err = irc_log_event(chan_ctx->ctx, chan_ctx, NULL, "CLOSE", NULL, NULL)))
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   373
        goto error;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   374
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   375
    // ok
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   376
    return SUCCESS;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   377
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   378
error:
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   379
    // destroy it uncleanly
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   380
    irc_log_chan_destroy(chan_ctx);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   381
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   382
    return err;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   383
}
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   384
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   385
/**
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   386
 * Allocate and initialize an irc_log_ctx. This doesn't do very much, the real magic happens in irc_log_conf.
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   387
 */
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   388
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
   389
{
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
   390
    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
   391
    
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   392
    // allocate
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   393
    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
   394
        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
   395
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   396
    // store
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   397
    ctx->nexus = nexus;
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   398
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   399
    // initialize
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   400
    TAILQ_INIT(&ctx->channels);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   401
65
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   402
    log_info("module initialized");
d7508879ad01 add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents: 61
diff changeset
   403
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
   404
    // ok
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   405
    *ctx_ptr = ctx;
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   406
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   407
    return 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
   408
}
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
   409
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   410
/**
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   411
 * Process the irc_log.db_info config option.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   412
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   413
 * Creates a new evsql handle.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   414
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   415
 * Fails if ctx->db is already set.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   416
 */
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   417
static err_t irc_log_conf_db_info (void *_ctx, char *value, struct error_info *err)
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   418
{
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   419
    struct irc_log_ctx *ctx = _ctx;
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   420
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   421
    log_info("connect to database: %s", value);
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   422
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   423
    // already connected?
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   424
    if (ctx->db)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   425
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "irc_log.db_info already set");
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   426
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   427
    // create a new evsql handle
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   428
    if ((ctx->db = evsql_new_pq(ctx->nexus->ev_base, value, NULL, NULL)) == NULL)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   429
       return SET_ERROR(err, ERR_EVSQL_NEW_PQ);
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   430
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   431
    // ok
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   432
    return SUCCESS;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   433
}
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   434
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   435
/**
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   436
 * Process the irc_log.channel config option.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   437
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   438
 * Creates a new irc_log_chan context, looks up the channel, adds our command handlers, and logs an OPEN event.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   439
 *
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   440
 * Fails if the value is invalid, we don't have a database connected, the channel doesn't exist, adding our command
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   441
 * handlers/callbacks fails, or sending the initial INSERT-OPEN query fails.
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   442
 */
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   443
static err_t irc_log_conf_channel (void *_ctx, char *value, struct error_info *err)
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   444
{
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   445
    struct irc_log_ctx *ctx = _ctx;
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   446
    const char *network, *channel;
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   447
    struct irc_chan *chan;
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   448
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   449
    // parse required args
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   450
    if ((network = strsep(&value, ":")) == NULL)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   451
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "invalid <network> for irc_log.channel");
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   452
        
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   453
    if ((channel = strsep(&value, ":")) == NULL)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   454
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "invalid <channel> for irc_log.channel");
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   455
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   456
    // extraneous stuff?
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   457
    if (value)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   458
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "trailing data for irc_log.channel");
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   459
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   460
    // have a db configured?
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   461
    if (!ctx->db)
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   462
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "irc_log.channel used without any irc_log.db_info");
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   463
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   464
    // get the channel?
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   465
    if ((chan = irc_client_get_chan(ctx->nexus->client, network, channel)) == NULL)
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   466
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown channel name");
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   467
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   468
    // begin logging it
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   469
    if (irc_log_chan(ctx, chan, err))
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
   470
        return ERROR_CODE(err);
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   471
    
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   472
    // ok
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   473
    return SUCCESS;
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   474
}
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   475
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   476
/**
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   477
 * Our configuration options
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   478
 */
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   479
struct config_option irc_log_config_options[] = {
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   480
    {   "db_info",  CONFIG_STRING,  &irc_log_conf_db_info,  "[<key>=<value> [...]]",    "set database connection info, see libpq docs"  },
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   481
    {   "channel",  CONFIG_STRING,  &irc_log_conf_channel,  "<network>:<channel>",      "log the given channel"                         },
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   482
    {   NULL,       0,              NULL,                   NULL,                       NULL                                            }
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   483
};
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   484
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   485
/**
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   486
 * Set a config option
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   487
 */
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   488
static err_t irc_log_conf (void *_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
   489
{
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   490
    struct irc_log_ctx *ctx = _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
   491
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   492
    // wrong state
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   493
    if (ctx->unloading)
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   494
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "module is being unloaded");
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   495
    
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   496
    // apply it
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   497
    return config_apply(irc_log_config_options, ctx, name, value, 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
   498
}
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
   499
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   500
/**
70
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   501
 * Deinitialize, logging CLOSE events for all channels, and removing any hooks we've added
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   502
 */
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   503
static err_t irc_log_unload (void *_ctx)
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   504
{
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   505
    struct irc_log_ctx *ctx = _ctx;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   506
    struct irc_log_chan *chan_ctx;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   507
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   508
    // update our state to mark ourselves as unloading
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   509
    ctx->unloading = true;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   510
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   511
    // stop logging each channel
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   512
    TAILQ_FOREACH(chan_ctx, &ctx->channels, ctx_channels) {
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   513
        irc_log_chan_stop(chan_ctx);
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   514
    }
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   515
    
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   516
    // wait for all the channels to be stopped, which will call irc_log_stopped
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   517
    return SUCCESS;
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   518
}
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   519
a9a4c5e6aa30 implement module unloading, although module_destroy is currently never called
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   520
/**
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   521
 * 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
   522
 */
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   523
struct module_funcs irc_log_funcs = {
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   524
    .init               = &irc_log_init,
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   525
    .conf               = &irc_log_conf,
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   526
    .config_options     = irc_log_config_options,
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 80
diff changeset
   527
    .unload             = &irc_log_unload,
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   528
};
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   529