forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc.h
69 lines (55 loc) · 1.67 KB
/
irc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef LIGHTNING_IRC_H
#define LIGHTNING_IRC_H
#include "config.h"
#include "daemon/lightningd.h"
#include <ccan/io/io.h>
#include <ccan/short_types/short_types.h>
#include <ccan/str/str.h>
#include <ccan/tal/str/str.h>
#include <ccan/time/time.h>
#include <ccan/timer/timer.h>
#include <netdb.h>
#include <stdio.h>
#include <sys/socket.h>
struct irccommand {
struct list_node list;
const char *prefix;
const char *command;
const char *params;
};
struct privmsg {
const char *channel;
const char *sender;
const char *msg;
};
struct ircstate {
/* Meta information */
const char *nick;
const char *server;
/* Connection and reading */
struct io_conn *conn;
char buffer[512];
size_t readlen;
size_t buffered;
/* Write queue related */
struct list_head writequeue;
char *writebuffer;
/* Pointer to external state, making it available to callbacks */
struct lightningd_state *dstate;
struct log *log;
/* Are we currently connected? */
bool connected;
/* Time to wait after getting disconnected before reconnecting. */
struct timerel reconnect_timeout;
};
/* Callbacks to register for incoming messages, events and raw commands */
extern void (*irc_privmsg_cb)(struct ircstate *, const struct privmsg *);
extern void (*irc_command_cb)(struct ircstate *, const struct irccommand *);
extern void (*irc_connect_cb)(struct ircstate *);
extern void (*irc_disconnect_cb)(struct ircstate *);
/* Send messages to IRC */
bool irc_send(struct ircstate *state, const char *command, const char *fmt, ...) PRINTF_FMT(3,4);
bool irc_send_msg(struct ircstate *state, struct privmsg *m);
/* Register IRC connection with io */
void irc_connect(struct ircstate *state);
#endif /* LIGHTNING_IRC_H */