author | Tero Marttila <terom@fixme.fi> |
Mon, 16 Mar 2009 22:06:39 +0200 | |
changeset 69 | 6f298b6e0d5f |
parent 68 | 591a574f390e |
child 70 | a9a4c5e6aa30 |
permissions | -rw-r--r-- |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
1 |
#include "module.h" |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
2 |
#include "irc_chan.h" |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
3 |
#include "error.h" |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
#include "log.h" |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
|
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
6 |
#include <stdlib.h> |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
7 |
#include <string.h> |
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
8 |
|
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
9 |
#include <event2/event.h> |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
10 |
#include <evsql.h> |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
|
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
/** |
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
|
13 |
* The irc_log module state. |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
*/ |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
15 |
struct irc_log_ctx { |
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
16 |
/** The nexus this module is loaded for */ |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
17 |
struct nexus *nexus; |
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
18 |
|
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
/** The database connection */ |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
struct evsql *db; |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
21 |
}; |
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
|
22 |
|
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
|
23 |
/** |
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
|
24 |
* 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
|
25 |
*/ |
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
|
26 |
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
|
27 |
/** 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
|
28 |
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
|
29 |
|
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
|
30 |
/** 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
|
31 |
struct irc_chan *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
|
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 |
|
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 |
* 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
|
36 |
*/ |
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
|
37 |
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
|
38 |
{ |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
39 |
struct irc_log_ctx *ctx = arg; |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
40 |
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
|
41 |
|
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
42 |
(void) ctx; |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
43 |
|
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
44 |
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
|
45 |
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
|
46 |
|
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
47 |
// ok |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
48 |
evsql_result_free(res); |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
49 |
} |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
50 |
|
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
|
51 |
/** |
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
|
52 |
* 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
|
53 |
* |
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
|
54 |
* Any of source, target, message can be NULL to insert NULLs |
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
|
55 |
*/ |
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
|
56 |
static err_t irc_log_event (struct irc_log_ctx *ctx, struct irc_chan *chan, 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
|
57 |
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
|
58 |
{ |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
59 |
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
|
60 |
|
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
|
61 |
// unpack the nick/user/hostname args, as source can be 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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
|
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
66 |
// 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
|
67 |
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
|
68 |
"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
|
69 |
" 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
|
70 |
" ) 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
|
71 |
" $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
|
72 |
" )", { |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
} |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
83 |
}; |
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
|
84 |
|
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
|
85 |
// 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
|
86 |
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
|
87 |
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
|
88 |
|
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
|
89 |
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
|
90 |
} |
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 |
|
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 |
// run the INSERT |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
93 |
if ((query = evsql_query_exec(ctx->db, NULL, &sql, &irc_log_on_sql_result, ctx, |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
94 |
chan->net->info.network, irc_chan_name(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
|
95 |
nickname, username, hostname, |
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
|
96 |
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
|
97 |
)) == 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
|
98 |
// 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
|
99 |
log_error("evsql_query_exec failed for %s:%s - %s!%s@%s - %s -> %s - %s", |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
100 |
chan->net->info.network, irc_chan_name(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
|
101 |
nickname, username, hostname, |
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
|
102 |
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
|
103 |
); |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
104 |
|
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
|
105 |
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
|
106 |
} |
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
|
107 |
|
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
|
108 |
// 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
|
109 |
log_debug("%s:%s - %s!%s@%s - %s -> %s - %s", |
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
|
110 |
chan->net->info.network, irc_chan_name(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
|
111 |
nickname, username, hostname, |
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 |
type, target, 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
|
113 |
); |
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
|
114 |
|
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 |
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
|
116 |
} |
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
117 |
|
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
|
118 |
/** |
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
|
119 |
* Parse the prefix into a nickmask and pass on to irc_log_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
|
120 |
*/ |
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
|
121 |
static err_t irc_log_event_prefix (struct irc_log_ctx *ctx, struct irc_chan *chan, const char *prefix, |
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
|
122 |
const char *type, const char *target, const char *message) |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
123 |
{ |
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
|
124 |
char prefix_buf[IRC_PREFIX_MAX]; |
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
|
125 |
struct irc_nm nm; |
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
|
126 |
err_t 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
|
127 |
|
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
|
128 |
// parse nickmask |
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
|
129 |
if ((err = irc_nm_parse(&nm, prefix_buf, prefix))) |
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
|
130 |
return err; |
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
|
131 |
|
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
|
132 |
// log |
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
|
133 |
return irc_log_event(ctx, chan, &nm, type, target, message); |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
134 |
} |
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
|
135 |
|
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
|
136 |
/** |
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 |
* 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
|
138 |
* |
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 |
* :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
|
140 |
*/ |
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 |
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
|
142 |
{ |
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 |
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
|
144 |
|
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
|
145 |
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
|
146 |
|
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
|
147 |
irc_log_event_prefix(chan_ctx->ctx, chan_ctx->chan, line->prefix, line->command, NULL, 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
|
148 |
} |
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
|
149 |
|
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
|
150 |
/** |
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
|
151 |
* 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
|
152 |
* |
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
|
153 |
* :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
|
154 |
* |
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
|
155 |
* 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
|
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 |
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
|
158 |
{ |
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
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
|
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
|
163 |
// 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
|
164 |
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
|
165 |
// 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
|
166 |
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
|
167 |
*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
|
168 |
|
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 |
// 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
|
170 |
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
|
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 |
// 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
|
173 |
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
|
174 |
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
|
175 |
} |
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
|
176 |
|
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 |
// log |
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 |
irc_log_event_prefix(chan_ctx->ctx, chan_ctx->chan, line->prefix, line->command, NULL, 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
|
179 |
} |
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
|
180 |
|
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
|
181 |
/** |
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
|
182 |
* 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
|
183 |
* |
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
|
184 |
* :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
|
185 |
*/ |
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
|
186 |
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
|
187 |
{ |
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
|
188 |
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
|
189 |
|
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
|
190 |
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
|
191 |
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
|
192 |
|
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
|
193 |
irc_log_event_prefix(chan_ctx->ctx, chan_ctx->chan, line->prefix, line->command, target, 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
|
194 |
} |
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
|
195 |
|
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
|
196 |
/** |
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
|
197 |
* 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
|
198 |
* |
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
|
199 |
* 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
|
200 |
*/ |
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
|
201 |
static struct irc_cmd_handler _chan_cmd_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
|
202 |
{ "JOIN", &irc_log_on_chan_generic }, |
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
|
203 |
{ "PART", &irc_log_on_chan_generic }, |
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
|
204 |
{ "MODE", &irc_log_on_chan_MODE }, |
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
|
205 |
{ "TOPIC", &irc_log_on_chan_generic }, |
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
|
206 |
{ "KICK", &irc_log_on_chan_KICK }, |
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
|
207 |
{ "PRIVMSG", &irc_log_on_chan_generic }, |
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
|
208 |
{ "NOTICE", &irc_log_on_chan_generic }, |
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
|
209 |
{ 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
|
210 |
}; |
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
|
211 |
|
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 |
/** |
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 |
* 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
|
214 |
* |
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 |
* 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
|
216 |
*/ |
38
0c2e0cb46c3a
implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents:
37
diff
changeset
|
217 |
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
|
218 |
.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
|
219 |
.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
|
220 |
}; |
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
|
221 |
|
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
|
222 |
/** |
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
|
223 |
* 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
|
224 |
*/ |
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
|
225 |
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
|
226 |
{ |
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
|
227 |
// 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
|
228 |
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
|
229 |
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
|
230 |
|
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
|
231 |
// 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
|
232 |
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
|
233 |
} |
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
|
234 |
|
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
|
235 |
/** |
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
|
236 |
* 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
|
237 |
*/ |
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
|
238 |
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
|
239 |
{ |
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
|
240 |
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
|
241 |
|
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
|
242 |
// 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
|
243 |
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
|
244 |
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
|
245 |
|
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
|
246 |
// 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
|
247 |
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
|
248 |
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
|
249 |
|
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
|
250 |
// 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
|
251 |
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
|
252 |
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
|
253 |
|
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
|
254 |
// 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
|
255 |
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
|
256 |
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
|
257 |
|
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
|
258 |
// 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
|
259 |
// XXX: move this to when we first JOIN the 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
|
260 |
if ((ERROR_CODE(err) = irc_log_event(ctx, chan_ctx->chan, NULL, "OPEN", NULL, 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
|
261 |
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
|
262 |
|
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
|
263 |
// 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
|
264 |
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
|
265 |
|
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
|
266 |
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
|
267 |
|
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
|
268 |
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
|
269 |
// 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
|
270 |
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
|
271 |
|
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
|
272 |
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
|
273 |
} |
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
|
274 |
|
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
|
275 |
/** |
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
|
276 |
* 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
|
277 |
*/ |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
278 |
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
|
279 |
{ |
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
|
280 |
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
|
281 |
|
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
282 |
// allocate |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
283 |
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
|
284 |
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
|
285 |
|
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
286 |
// store |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
287 |
ctx->nexus = nexus; |
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
288 |
|
65
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
289 |
log_info("module initialized"); |
d7508879ad01
add --module support, and tweak irc_net docs
Tero Marttila <terom@fixme.fi>
parents:
61
diff
changeset
|
290 |
|
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
|
291 |
// ok |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
292 |
*ctx_ptr = ctx; |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
293 |
|
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
|
294 |
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
|
295 |
} |
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
|
296 |
|
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
|
297 |
/** |
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
|
298 |
* 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
|
299 |
* |
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
|
300 |
* 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
|
301 |
* |
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
|
302 |
* 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
|
303 |
*/ |
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
|
304 |
static err_t irc_log_conf_db_info (struct irc_log_ctx *ctx, char *value, struct error_info *err) |
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
|
305 |
{ |
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
|
306 |
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
|
307 |
|
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
|
308 |
// 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
|
309 |
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
|
310 |
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
|
311 |
|
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
|
312 |
// 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
|
313 |
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
|
314 |
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
|
315 |
|
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
|
316 |
// 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
|
317 |
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
|
318 |
} |
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
|
319 |
|
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
|
320 |
/** |
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
|
321 |
* 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
|
322 |
* |
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
|
323 |
* 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
|
324 |
* |
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
|
325 |
* 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
|
326 |
* 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
|
327 |
*/ |
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
|
328 |
static err_t irc_log_conf_channel (struct irc_log_ctx *ctx, char *value, struct error_info *err) |
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
|
329 |
{ |
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
|
330 |
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
|
331 |
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
|
332 |
|
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
|
333 |
// 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
|
334 |
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
|
335 |
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
|
336 |
|
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
|
337 |
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
|
338 |
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
|
339 |
|
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
|
340 |
// 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
|
341 |
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
|
342 |
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
|
343 |
|
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
|
344 |
// 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
|
345 |
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
|
346 |
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
|
347 |
|
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
|
348 |
// 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
|
349 |
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
|
350 |
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
|
351 |
|
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
|
352 |
// 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
|
353 |
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
|
354 |
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
|
355 |
|
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
|
356 |
// 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
|
357 |
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
|
358 |
} |
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
|
359 |
|
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
|
360 |
/** |
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
|
361 |
* 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
|
362 |
*/ |
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
363 |
static err_t irc_log_conf (void *mod_ctx, const char *name, char *value, struct error_info *err) |
55
6f7f6ae729d0
'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents:
45
diff
changeset
|
364 |
{ |
56
942370000450
compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents:
55
diff
changeset
|
365 |
struct irc_log_ctx *ctx = mod_ctx; |
67
aa94bf2b5f9b
implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
366 |
|
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
|
367 |
if (strcmp(name, "db_info") == 0) { |
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
|
368 |
return irc_log_conf_db_info(ctx, value, 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
|
369 |
|
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
|
370 |
} else if (strcmp(name, "channel") == 0) { |
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
|
371 |
return irc_log_conf_channel(ctx, value, 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
|
372 |
|
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
|
373 |
} else { |
66
ef8c9d7daf62
all options are now fully implemented
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
374 |
RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown configuration option"); |
23
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
375 |
} |
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
|
376 |
|
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
|
377 |
// ok |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
378 |
return SUCCESS; |
542c73d07d3c
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
379 |
} |
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
|
380 |
|
57
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
381 |
/** |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
382 |
* 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
|
383 |
*/ |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
384 |
struct module_funcs irc_log_funcs = { |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
385 |
.init = &irc_log_init, |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
386 |
.conf = &irc_log_conf, |
ce1accba5fc7
slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents:
56
diff
changeset
|
387 |
}; |
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
|
388 |