26 |
28 |
27 static struct irc_chan_callbacks _chan_callbacks = { |
29 static struct irc_chan_callbacks _chan_callbacks = { |
28 .on_msg = on_chan_msg, |
30 .on_msg = on_chan_msg, |
29 }; |
31 }; |
30 |
32 |
31 err_t irc_log_init (struct event_base *ev_base, const struct irc_log_info *info) |
33 void* irc_log_init (struct modules *modules, struct error_info *err) |
32 { |
34 { |
33 struct irc_log_ctx *ctx = &_ctx; |
35 struct irc_log_ctx *ctx; |
|
36 |
|
37 (void) modules; |
|
38 (void) err; |
|
39 |
|
40 // XXX: static pointer |
|
41 ctx = &_ctx; |
|
42 |
|
43 // ok |
|
44 return ctx; |
|
45 } |
|
46 |
|
47 err_t irc_log_conf (struct module *module, const char *name, char *value) |
|
48 { |
|
49 struct irc_log_ctx *ctx = module->ctx; |
|
50 struct nexus *nexus = module->modules->nexus; |
34 err_t err; |
51 err_t err; |
35 |
52 |
36 // open the database connection |
53 if (strcmp(name, "db_info") == 0) { |
37 if (info->db_info) { |
54 log_info("connect to database: %s", value); |
38 log_info("connect to database: %s", info->db_info); |
|
39 |
55 |
40 if ((ctx->db = evsql_new_pq(ev_base, info->db_info, NULL, NULL)) == NULL) |
56 if ((ctx->db = evsql_new_pq(nexus->ev_base, value, NULL, NULL)) == NULL) |
41 return ERR_EVSQL_NEW_PQ; |
57 return ERR_EVSQL_NEW_PQ; |
|
58 |
|
59 } else if (strcmp(name, "channel") == 0) { |
|
60 const char *network = strsep(&value, ":"); |
|
61 const char *channel = value; |
|
62 |
|
63 struct irc_chan *chan; |
|
64 |
|
65 // kill missing tokens |
|
66 if (!network || !channel) |
|
67 // XXX: need to fix the error crap |
|
68 return -1; |
|
69 |
|
70 // get the channel? |
|
71 if ((chan = irc_client_get_chan(nexus->client, network, channel)) == NULL) |
|
72 return -1; |
|
73 |
|
74 // add channel callbacks |
|
75 if ((err = irc_chan_add_callbacks(chan, &_chan_callbacks, ctx))) |
|
76 return err; |
|
77 |
|
78 } else { |
|
79 return -1; |
|
80 |
42 } |
81 } |
43 |
|
44 if (info->channel) { |
|
45 log_info("log channel: %s", irc_chan_name(info->channel)); |
|
46 } |
|
47 |
|
48 // add channel callbacks |
|
49 if ((err = irc_chan_add_callbacks(info->channel, &_chan_callbacks, ctx))) |
|
50 goto error; |
|
51 |
82 |
52 // ok |
83 // ok |
53 return SUCCESS; |
84 return SUCCESS; |
54 |
|
55 error: |
|
56 // XXX: cleanup |
|
57 |
|
58 return err; |
|
59 } |
85 } |
60 |
86 |