mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-12 01:24:23 +01:00
routing: Added simple IRC library based on io_loop
The IRC library can login and keep its connection alive by replying to PING messages. It also exposes a callback that handles PRIVMSG commands and can inject messages from outside, e.g., based on a timer or a lightning event.
This commit is contained in:
67
irc.h
Normal file
67
irc.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef LIGHTNING_IRC_H
|
||||
#define LIGHTNING_IRC_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.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 "daemon/lightningd.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;
|
||||
};
|
||||
|
||||
/* Callback to register for incoming messages */
|
||||
extern void (*irc_privmsg_cb)(struct ircstate *, const struct privmsg *);
|
||||
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 */
|
||||
Reference in New Issue
Block a user