Skip to content

Instantly share code, notes, and snippets.

@dequis dequis/bitlbee_ssl.c
Last active Mar 11, 2018

Embed
What would you like to do?
// gcc -g -shared -fPIC $(pkg-config --cflags bitlbee) bitlbee_ssl.c -o bitlbee_ssl.so
#include <bitlbee.h>
#include <ssl_client.h>
static void
beessl_init(account_t *acct)
{
}
static gboolean
beessl_cb_read(gpointer data, gint fd, b_input_condition cond)
{
struct im_connection *ic = data;
void *conn = ic->proto_data;
gchar buf[512];
gchar *stringy;
gssize size;
if (conn == NULL) {
return FALSE;
}
size = ssl_read(conn, buf, sizeof(buf));
if (size == 0) {
imcb_error(ic, "Disconnected");
imc_logout(ic, FALSE);
return FALSE;
}
stringy = g_strndup(buf, size);
imcb_buddy_msg(ic, "peer", stringy, 0, 0);
g_free(stringy);
return TRUE;
}
static gboolean
beessl_cb_open(gpointer data, gint error, gpointer ssl, b_input_condition cond)
{
struct im_connection *ic = data;
void *conn = ic->proto_data;
if ((ssl == NULL) || (error != SSL_OK)) {
ic->proto_data = NULL;
imcb_error(ic, "Error");
return FALSE;
}
b_input_add(ssl_getfd(conn), B_EV_IO_READ, beessl_cb_read, ic);
imcb_add_buddy(ic, "peer", NULL);
imcb_buddy_status(ic, "peer", BEE_USER_ONLINE, NULL, NULL);
imcb_connected(ic);
return FALSE;
}
static void
beessl_login(account_t *acc)
{
struct im_connection *ic = imcb_new(acc);
imcb_log(ic, "Connecting");
ic->proto_data = ssl_connect(acc->user, atoi(acc->pass), TRUE, beessl_cb_open, ic);
if (ic->proto_data == NULL) {
beessl_cb_open(ic, SSL_NOHANDSHAKE, NULL, 0);
}
}
static void
beessl_logout(struct im_connection *ic)
{
void *conn = ic->proto_data;
ssl_disconnect(conn);
ic->proto_data = NULL;
}
static int
beessl_buddy_msg(struct im_connection *ic, char *to, char *message, int flags)
{
void *conn = ic->proto_data;
ssl_write(conn, message, strlen(message));
ssl_write(conn, "\n", 1);
return 0;
}
G_MODULE_EXPORT void
init_plugin(void)
{
struct prpl *dpp;
static const struct prpl pp = {
.name = "ssl",
.init = beessl_init,
.login = beessl_login,
.logout = beessl_logout,
.buddy_msg = beessl_buddy_msg,
.handle_cmp = g_strcmp0,
};
dpp = g_memdup(&pp, sizeof pp);
register_protocol(dpp);
}
#ifdef BITLBEE_ABI_VERSION_CODE
G_MODULE_EXPORT struct plugin_info *
init_plugin_info(void)
{
static struct plugin_info info = {
BITLBEE_ABI_VERSION_CODE,
"ssl",
"0.0.0",
"ssl protocol plugin",
"dequis <dx@dxzone.com.ar>",
""
};
return &info;
}
#endif
00:16 <@dx|ssl> ac add ssl irc.freenode.net 6697
00:16 <@root> Account successfully added with tag ssl
00:16 <@dx|ssl> ac on
00:16 <@root> Trying to get all accounts connected...
00:16 <@root> ssl - Logging in: Connecting
00:16 -!- peer [peer@ssl] has joined &bitlbee
00:16 -!- ServerMode/&bitlbee [+v peer] by localhost.localdomain
00:16 <@root> ssl - Logging in: Logged in
00:16 <peer> :wolfe.freenode.net NOTICE * :*** Looking up your hostname...
00:16 <peer> :wolfe.freenode.net NOTICE * :*** Checking Ident
00:16 <peer> :wolfe.freenode.net NOTICE * :*** Couldn't look up your hostname
00:16 <peer> :wolfe.freenode.net NOTICE * :*** No Ident response
00:16 <dx|ssl> cap ls
00:16 <peer> :wolfe.freenode.net CAP * LS :account-notify extended-join identify-msg multi-prefix sasl
00:16 <dx|ssl> user a a a a
00:16 <dx|ssl> nick dx2
00:16 <dx|ssl> cap end
00:16 <peer> :wolfe.freenode.net 001 dx2 :Welcome to the freenode Internet Relay Chat Network dx2
00:16 <peer> :wolfe.freenode.net 002 dx2 :Your host is wolfe.freenode.net[2001:948:7:7::140/6697], running version ircd-seven-1.1.4
00:16 <peer> :wolfe.freenode.net 003 dx2 :This server was created Wed Jan 18 2017 at 02:26:17 CET
00:16 <peer> :wolfe.freenode.net 004 dx2 wolfe.freenode.net ircd-seven-1.1.4 DOQRSZaghilopswz CFILMPQSbcefgijklmnopqrstvz bkloveqjfI
00:16 <peer> :wolfe.freenode.net 005 dx2 CHANTYPES=# EXCEPTS INVEX CHANMODES=eIbq,k,flj,CFLMPQScgimnprstz CHANLIMIT=#:120 PREFIX=(ov)@+ MAXLIST=bqeI:100 MODES=4 NETWORK=freenode STATUSMSG=@+ CALLERID=g CASEMAPPING=rfc1459 :are supported by this server
00:16 <peer> :wolfe.freenode.net 005 dx2 CHARSET=ascii NICKLEN=16 CHANNELLEN=50 TOPICLEN=390 DEAF=D FNC TARGMAX=NAMES:1,LIST:1,KICK:1,WHOIS:1,PRIVMSG:4,NOTICE:4,ACCEPT:,MONITOR: EXTBAN=$,ajrxz CLIENTVER=3.0 KNOCK SAFELIST ELIST=CTU :are supported by this server
00:16 <peer> :wolfe.freenode.net 005 dx2 WHOX CPRIVMSG CNOTICE ETRACE :are supported by this server
00:16 <peer> :wolfe.freenode.net 251 dx2 :There are 127 users and 82799 invisible on 34 servers
00:16 <peer> :wolfe.freenode.net 252 dx2 26 :IRC Operators online
00:16 <peer> :wolfe.freenode.net 253 dx2 2 :unknown connection(s)
00:16 <peer> :wolfe.freenode.net 254 dx2 48870 :channels formed
00:16 <peer> :wolfe.freenode.net 255 dx2 :I have 4477 clients and 1 servers
00:16 <peer> :wolfe.freenode.net 265 dx2 4477 7170 :Current local users 4477, max 7170
00:16 <peer> :wolfe.freenode.net 266 dx2 82926 97718 :Current global users 82926, max 97718
00:16 <peer> :wolfe.freenode.net 250 dx2 :Highest connection count: 7172 (7170 clients) (1940293 connections received)
00:16 <peer> :wolfe.freenode.net 375 dx2 :- wolfe.freenode.net Message of the Day -
00:16 <peer> :wolfe.freenode.net 372 dx2 :- Welcome to wolfe.freenode.net in Stockholm, SE.
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.