1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-15 04:28:09 -04:00

Change coding style

This commit is contained in:
hawken93 2014-10-03 23:30:37 +02:00
parent f153922759
commit a35e5b4f9d
14 changed files with 257 additions and 354 deletions

5
TODO
View File

@ -1,3 +1,8 @@
- New proxy code crashes if an invalid proxy_type setting is used
- Remove old socks code
- Lots of warnings at least when using socks5
- Clean up coding style
19:36 [IRCNet] [muzzy] more bugs in irssi, apparently the new version: foo splits out, 19:36 [IRCNet] [muzzy] more bugs in irssi, apparently the new version: foo splits out,
bar joins, bar changes his nick to foo, foo splits again -> bar joins, bar changes his nick to foo, foo splits again ->
Glib warning "is already in split list (how?)" .. :) Glib warning "is already in split list (how?)" .. :)

View File

@ -552,7 +552,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
return gchan; return gchan;
} }
GIOChannel *net_connect_proxy_ssl(struct network_proxy const *proxy, char const *host, int port, GIOChannel *net_connect_proxy_ssl(struct network_proxy const *proxy, char const *host, int port,
IPADDR *ip, IPADDR *my_ip, SERVER_REC *server) IPADDR *ip, IPADDR *my_ip, SERVER_REC *server)
{ {
GIOChannel *handle, *ssl_handle; GIOChannel *handle, *ssl_handle;

View File

@ -1,18 +1,20 @@
/* --*- c -*-- /*
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> network-proxy-http.c : irssi
*
* This program is free software; you can redistribute it and/or modify Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License. This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* This program is distributed in the hope that it will be useful, the Free Software Foundation; version 2 and/or 3 of the License.
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the This program is distributed in the hope that it will be useful,
* GNU General Public License for more details. but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* You should have received a copy of the GNU General Public License GNU General Public License for more details.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "module.h" #include "module.h"
#include "network-proxy-http.h" #include "network-proxy-http.h"
@ -25,10 +27,9 @@
#include "network.h" #include "network.h"
#include "network-proxy-priv.h" #include "network-proxy-priv.h"
static void static void network_proxy_http_destroy(struct network_proxy *proxy)
network_proxy_http_destroy(struct network_proxy *proxy)
{ {
struct _network_proxy_http *self = container_of(proxy, struct _network_proxy_http, proxy); struct _network_proxy_http *self = container_of(proxy, struct _network_proxy_http, proxy);
g_free((void *)self->password); g_free((void *)self->password);
_network_proxy_destroy(proxy); _network_proxy_destroy(proxy);
@ -36,11 +37,10 @@ network_proxy_http_destroy(struct network_proxy *proxy)
g_free(self); g_free(self);
} }
static struct network_proxy * static struct network_proxy *network_proxy_http_clone(const struct network_proxy *proxy)
network_proxy_http_clone(struct network_proxy const *proxy)
{ {
struct _network_proxy_http *self = container_of(proxy, struct _network_proxy_http, proxy); struct _network_proxy_http *self = container_of(proxy, struct _network_proxy_http, proxy);
struct _network_proxy_http *res; struct _network_proxy_http *res;
res = g_malloc0(sizeof *res); res = g_malloc0(sizeof *res);
@ -49,10 +49,10 @@ network_proxy_http_clone(struct network_proxy const *proxy)
return &res->proxy; return &res->proxy;
} }
static bool static bool send_connect(struct _network_proxy_http *proxy, GIOChannel *ch,
send_connect(struct _network_proxy_http *proxy, GIOChannel *ch, char const *address, uint16_t port) const char *address, uint16_t port)
{ {
char port_str[6]; char port_str[6];
(void)proxy; (void)proxy;
sprintf(port_str, "%u", port); sprintf(port_str, "%u", port);
@ -68,16 +68,15 @@ send_connect(struct _network_proxy_http *proxy, GIOChannel *ch, char const *addr
return true; return true;
} }
static int static int read_response(struct _network_proxy_http *proxy, GIOChannel *ch)
read_response(struct _network_proxy_http *proxy, GIOChannel *ch)
{ {
GIOStatus status; GIOStatus status;
GString line = { .str = NULL }; GString line = { .str = NULL };
gsize term_pos; gsize term_pos;
GError *err = NULL; GError *err = NULL;
int state = 0; int state = 0;
int rc = 0; int rc = 0;
gchar *resp = NULL; gchar *resp = NULL;
(void)proxy; (void)proxy;
for (;;) { for (;;) {
@ -125,16 +124,15 @@ err:
return -1; return -1;
} }
static GIOChannel * static GIOChannel *network_proxy_http_connect(const struct network_proxy *proxy, const IPADDR *hint_ip,
network_proxy_http_connect(struct network_proxy const *proxy, IPADDR const *hint_ip, const char *address, int port)
char const *address, int port)
{ {
struct _network_proxy_http *self = container_of(proxy, struct _network_proxy_http, proxy); struct _network_proxy_http *self = container_of(proxy, struct _network_proxy_http, proxy);
GIOChannel *ch; GIOChannel *ch;
GIOFlags old_flags; GIOFlags old_flags;
GError *err = NULL; GError *err = NULL;
gchar const *line_term; const gchar *line_term;
gint line_term_sz; gint line_term_sz;
if (hint_ip) if (hint_ip)
ch = net_connect_ip(hint_ip, self->proxy.port, NULL); ch = net_connect_ip(hint_ip, self->proxy.port, NULL);
@ -171,23 +169,20 @@ err:
net_disconnect(ch); net_disconnect(ch);
return NULL; return NULL;
} }
struct network_proxy *_network_proxy_http_create(void)
struct network_proxy *
_network_proxy_http_create(void)
{ {
struct _network_proxy_http *res; struct _network_proxy_http *res;
res = g_malloc0(sizeof *res); res = g_malloc0(sizeof *res);
_network_proxy_create(&res->proxy); _network_proxy_create(&res->proxy);
res->password = g_strdup(settings_get_str("proxy_password")); res->password = g_strdup(settings_get_str("proxy_password"));
res->proxy.destroy = network_proxy_http_destroy; res->proxy.destroy = network_proxy_http_destroy;
res->proxy.connect = network_proxy_http_connect; res->proxy.connect = network_proxy_http_connect;
res->proxy.clone = network_proxy_http_clone; res->proxy.clone = network_proxy_http_clone;
return &res->proxy; return &res->proxy;
} }

View File

@ -1,29 +1,13 @@
/* --*- c -*--
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef H_IRSSI_SRC_CORE_PROXY_HTTP_H #ifndef H_IRSSI_SRC_CORE_PROXY_HTTP_H
#define H_IRSSI_SRC_CORE_PROXY_HTTP_H #define H_IRSSI_SRC_CORE_PROXY_HTTP_H
#include "network-proxy.h" #include "network-proxy.h"
struct _network_proxy_http { struct _network_proxy_http {
struct network_proxy proxy; struct network_proxy proxy;
char const *password; const char *password;
}; };
struct network_proxy * _network_proxy_http_create(void); struct network_proxy *_network_proxy_http_create(void);
#endif /* H_IRSSI_SRC_CORE_PROXY_HTTP_H */ #endif

View File

@ -1,19 +1,3 @@
/* --*- c -*--
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef H_IRSSI_SRC_CORE_PROXY_PRIV_H #ifndef H_IRSSI_SRC_CORE_PROXY_PRIV_H
#define H_IRSSI_SRC_CORE_PROXY_PRIV_H #define H_IRSSI_SRC_CORE_PROXY_PRIV_H
@ -26,38 +10,34 @@
(type *)( (char *)__mptr - offsetof(type,member) );}) (type *)( (char *)__mptr - offsetof(type,member) );})
inline static void inline static void _network_proxy_create(struct network_proxy *dst)
_network_proxy_create(struct network_proxy *dst)
{ {
dst->port = settings_get_int("proxy_port"); dst->port = settings_get_int("proxy_port");
dst->host = g_strdup(settings_get_str("proxy_address")); dst->host = g_strdup(settings_get_str("proxy_address"));
} }
inline static void inline static void _network_proxy_clone(struct network_proxy *dst, const struct network_proxy *src)
_network_proxy_clone(struct network_proxy *dst, struct network_proxy const *src)
{ {
dst->host = g_strdup(src->host); dst->host = g_strdup(src->host);
dst->port = src->port; dst->port = src->port;
dst->destroy = src->destroy; dst->destroy = src->destroy;
dst->connect = src->connect; dst->connect = src->connect;
dst->clone = src->clone; dst->clone = src->clone;
} }
inline static void inline static void _network_proxy_destroy(struct network_proxy *proxy)
_network_proxy_destroy(struct network_proxy *proxy)
{ {
g_free((void *)proxy->host); g_free((void *)proxy->host);
} }
inline static bool inline static bool _network_proxy_send_all(GIOChannel *ch, const void *buf, ssize_t len)
_network_proxy_send_all(GIOChannel *ch, void const *buf, ssize_t len)
{ {
GError *err = NULL; GError *err = NULL;
gsize written; gsize written;
GIOStatus status; GIOStatus status;
while ((status=g_io_channel_write_chars(ch, buf, len, &written, while ((status=g_io_channel_write_chars(ch, buf, len, &written,
&err))==G_IO_STATUS_AGAIN) &err))==G_IO_STATUS_AGAIN)
@ -74,15 +54,14 @@ _network_proxy_send_all(GIOChannel *ch, void const *buf, ssize_t len)
return false; return false;
} }
inline static bool inline static bool _network_proxy_recv_all(GIOChannel *ch, void *buf_v, size_t len)
_network_proxy_recv_all(GIOChannel *ch, void *buf_v, size_t len)
{ {
GError *err = NULL; GError *err = NULL;
gchar *buf = buf_v; gchar *buf = buf_v;
while (len>0) { while (len>0) {
GIOStatus status; GIOStatus status;
gsize l; gsize l;
status = g_io_channel_read_chars(ch, buf, len, &l, &err); status = g_io_channel_read_chars(ch, buf, len, &l, &err);
if (status==G_IO_STATUS_AGAIN) if (status==G_IO_STATUS_AGAIN)
@ -105,11 +84,10 @@ _network_proxy_recv_all(GIOChannel *ch, void *buf_v, size_t len)
return false; return false;
} }
inline static bool inline static bool _network_proxy_flush(GIOChannel *ch)
_network_proxy_flush(GIOChannel *ch)
{ {
GError *err = NULL; GError *err = NULL;
GIOStatus status; GIOStatus status;
while ((status=g_io_channel_flush(ch, &err))==G_IO_STATUS_AGAIN) while ((status=g_io_channel_flush(ch, &err))==G_IO_STATUS_AGAIN)
continue; continue;
@ -125,4 +103,4 @@ _network_proxy_flush(GIOChannel *ch)
return false; return false;
} }
#endif /* H_IRSSI_SRC_CORE_PROXY_PRIV_H */ #endif

View File

@ -1,18 +1,20 @@
/* --*- c -*-- /*
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> network-proxy-simple.c : irssi
*
* This program is free software; you can redistribute it and/or modify Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License. This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* This program is distributed in the hope that it will be useful, the Free Software Foundation; version 2 and/or 3 of the License.
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the This program is distributed in the hope that it will be useful,
* GNU General Public License for more details. but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* You should have received a copy of the GNU General Public License GNU General Public License for more details.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "module.h" #include "module.h"
#include "network-proxy-simple.h" #include "network-proxy-simple.h"
@ -20,10 +22,9 @@
#include "network-proxy-priv.h" #include "network-proxy-priv.h"
#include "network.h" #include "network.h"
static void static void network_proxy_simple_destroy(struct network_proxy *proxy)
network_proxy_simple_destroy(struct network_proxy *proxy)
{ {
struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy); struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy);
g_free((void *)self->password); g_free((void *)self->password);
g_free((void *)self->string_after); g_free((void *)self->string_after);
@ -34,27 +35,25 @@ network_proxy_simple_destroy(struct network_proxy *proxy)
g_free(self); g_free(self);
} }
static struct network_proxy * static struct network_proxy *network_proxy_simple_clone(const struct network_proxy *proxy)
network_proxy_simple_clone(struct network_proxy const *proxy)
{ {
struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy); struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy);
struct _network_proxy_simple *res; struct _network_proxy_simple *res;
res = g_malloc0(sizeof *res); res = g_malloc0(sizeof *res);
_network_proxy_clone(&res->proxy, &self->proxy); _network_proxy_clone(&res->proxy, &self->proxy);
res->string = g_strdup(self->string); res->string = g_strdup(self->string);
res->string_after = g_strdup(self->string_after); res->string_after = g_strdup(self->string_after);
res->password = g_strdup(self->password); res->password = g_strdup(self->password);
return &res->proxy; return &res->proxy;
} }
static GIOChannel * static GIOChannel *network_proxy_simple_connect(const struct network_proxy *proxy, const IPADDR *hint_ip,
network_proxy_simple_connect(struct network_proxy const *proxy, IPADDR const *hint_ip, char const *address, int port)
char const *address, int port)
{ {
struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy); struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy);
(void)address; (void)address;
(void)port; (void)port;
@ -64,12 +63,11 @@ network_proxy_simple_connect(struct network_proxy const *proxy, IPADDR const *hi
return net_connect(self->proxy.host, self->proxy.port, NULL); return net_connect(self->proxy.host, self->proxy.port, NULL);
} }
static void static void network_proxy_simple_send_string(const struct network_proxy *proxy,
network_proxy_simple_send_string(struct network_proxy const *proxy, const struct network_proxy_send_string_info *info)
struct network_proxy_send_string_info const *info)
{ {
struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy); struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy);
char *cmd; char *cmd;
if (self->password && self->password[0]) { if (self->password && self->password[0]) {
cmd = g_strdup_printf("PASS %s", self->password); cmd = g_strdup_printf("PASS %s", self->password);
@ -84,12 +82,11 @@ network_proxy_simple_send_string(struct network_proxy const *proxy,
} }
} }
static void static void network_proxy_simple_send_string_after(const struct network_proxy *proxy,
network_proxy_simple_send_string_after(struct network_proxy const *proxy, const struct network_proxy_send_string_info *info)
struct network_proxy_send_string_info const *info)
{ {
struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy); struct _network_proxy_simple *self = container_of(proxy, struct _network_proxy_simple, proxy);
char *cmd; char *cmd;
if (self->string_after && self->string_after[0]) { if (self->string_after && self->string_after[0]) {
cmd = g_strdup_printf(self->string_after, info->host, info->port); cmd = g_strdup_printf(self->string_after, info->host, info->port);
@ -98,23 +95,22 @@ network_proxy_simple_send_string_after(struct network_proxy const *proxy,
} }
} }
struct network_proxy * struct network_proxy *_network_proxy_simple_create(void)
_network_proxy_simple_create(void)
{ {
struct _network_proxy_simple *res; struct _network_proxy_simple *res;
res = g_malloc0(sizeof *res); res = g_malloc0(sizeof *res);
_network_proxy_create(&res->proxy); _network_proxy_create(&res->proxy);
res->string = g_strdup(settings_get_str("proxy_string")); res->string = g_strdup(settings_get_str("proxy_string"));
res->string_after = g_strdup(settings_get_str("proxy_string_after")); res->string_after = g_strdup(settings_get_str("proxy_string_after"));
res->password = g_strdup(settings_get_str("proxy_password")); res->password = g_strdup(settings_get_str("proxy_password"));
res->proxy.destroy = network_proxy_simple_destroy; res->proxy.destroy = network_proxy_simple_destroy;
res->proxy.connect = network_proxy_simple_connect; res->proxy.connect = network_proxy_simple_connect;
res->proxy.clone = network_proxy_simple_clone; res->proxy.clone = network_proxy_simple_clone;
res->proxy.send_string = network_proxy_simple_send_string; res->proxy.send_string = network_proxy_simple_send_string;
res->proxy.send_string_after = network_proxy_simple_send_string_after; res->proxy.send_string_after = network_proxy_simple_send_string_after;
return &res->proxy; return &res->proxy;

View File

@ -1,32 +1,16 @@
/* --*- c -*--
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef H_IRSSI_SRC_CORE_PROXY_SIMPLE_H #ifndef H_IRSSI_SRC_CORE_PROXY_SIMPLE_H
#define H_IRSSI_SRC_CORE_PROXY_SIMPLE_H #define H_IRSSI_SRC_CORE_PROXY_SIMPLE_H
#include "network-proxy.h" #include "network-proxy.h"
struct _network_proxy_simple { struct _network_proxy_simple {
struct network_proxy proxy; struct network_proxy proxy;
char const *string_after; const char *string_after;
char const *string; const char *string;
char const *password; const char *password;
}; };
struct network_proxy * _network_proxy_simple_create(void); struct network_proxy *_network_proxy_simple_create(void);
#endif /* H_IRSSI_SRC_CORE_PROXY_SIMPLE_H */ #endif

View File

@ -1,18 +1,20 @@
/* --*- c -*-- /*
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> network-proxy-socks5.c : irssi
*
* This program is free software; you can redistribute it and/or modify Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License. This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* This program is distributed in the hope that it will be useful, the Free Software Foundation; version 2 and/or 3 of the License.
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the This program is distributed in the hope that it will be useful,
* GNU General Public License for more details. but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* You should have received a copy of the GNU General Public License GNU General Public License for more details.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "module.h" #include "module.h"
#include "network-proxy-socks5.h" #include "network-proxy-socks5.h"
@ -26,45 +28,44 @@
/* RFC 1928 */ /* RFC 1928 */
struct client_greeting struct client_greeting
{ {
uint8_t ver; uint8_t ver;
uint8_t nmethods; uint8_t nmethods;
uint8_t methods[]; uint8_t methods[];
} __attribute__((__packed__)); } __attribute__((__packed__));
struct server_greeting struct server_greeting
{ {
uint8_t ver; uint8_t ver;
uint8_t method; uint8_t method;
} __attribute__((__packed__)); } __attribute__((__packed__));
struct server_response_plain struct server_response_plain
{ {
uint8_t ver; uint8_t ver;
uint8_t status; uint8_t status;
} __attribute__((__packed__)); } __attribute__((__packed__));
struct client_request struct client_request
{ {
uint8_t ver; uint8_t ver;
uint8_t cmd; uint8_t cmd;
uint8_t rsv; uint8_t rsv;
uint8_t atyp; uint8_t atyp;
uint8_t dst[]; uint8_t dst[];
} __attribute__((__packed__)); } __attribute__((__packed__));
struct server_response struct server_response
{ {
uint8_t ver; uint8_t ver;
uint8_t rep; uint8_t rep;
uint8_t res; uint8_t res;
uint8_t atyp; uint8_t atyp;
uint8_t bnd[]; uint8_t bnd[];
} __attribute__((__packed__)); } __attribute__((__packed__));
static void static void network_proxy_socks5_destroy(struct network_proxy *proxy)
network_proxy_socks5_destroy(struct network_proxy *proxy)
{ {
struct _network_proxy_socks5 *self = container_of(proxy, struct _network_proxy_socks5, proxy); struct _network_proxy_socks5 *self = container_of(proxy, struct _network_proxy_socks5, proxy);
g_free((void *)self->password); g_free((void *)self->password);
g_free((void *)self->username); g_free((void *)self->username);
@ -72,11 +73,10 @@ network_proxy_socks5_destroy(struct network_proxy *proxy)
g_free(self); g_free(self);
} }
static struct network_proxy * static struct network_proxy *network_proxy_socks5_clone(const struct network_proxy *proxy)
network_proxy_socks5_clone(struct network_proxy const *proxy)
{ {
struct _network_proxy_socks5 *self = container_of(proxy, struct _network_proxy_socks5, proxy); struct _network_proxy_socks5 *self = container_of(proxy, struct _network_proxy_socks5, proxy);
struct _network_proxy_socks5 *res; struct _network_proxy_socks5 *res;
res = g_malloc0(sizeof *res); res = g_malloc0(sizeof *res);
@ -86,8 +86,7 @@ network_proxy_socks5_clone(struct network_proxy const *proxy)
return &res->proxy; return &res->proxy;
} }
static bool static bool socks5_connect_unauthorized(GIOChannel *ch)
socks5_connect_unauthorized(GIOChannel *ch)
{ {
/* nothing to do here */ /* nothing to do here */
(void)ch; (void)ch;
@ -95,13 +94,12 @@ socks5_connect_unauthorized(GIOChannel *ch)
} }
/* TODO: test this method! */ /* TODO: test this method! */
static bool static bool socks5_connect_plain(const struct _network_proxy_socks5 *proxy, GIOChannel *ch)
socks5_connect_plain(struct _network_proxy_socks5 const *proxy, GIOChannel *ch)
{ {
uint8_t ver = 0x01; uint8_t ver = 0x01;
uint8_t ulen = strlen(proxy->username); uint8_t ulen = strlen(proxy->username);
uint8_t plen = proxy->password ? strlen(proxy->password) : 0; uint8_t plen = proxy->password ? strlen(proxy->password) : 0;
struct server_response_plain resp; struct server_response_plain resp;
if (ulen==0 || if (ulen==0 ||
!_network_proxy_send_all(ch, &ver, sizeof ver) || !_network_proxy_send_all(ch, &ver, sizeof ver) ||
@ -126,30 +124,29 @@ socks5_connect_plain(struct _network_proxy_socks5 const *proxy, GIOChannel *ch)
return true; return true;
} }
static bool static bool socks5_connect(const struct _network_proxy_socks5 *proxy, GIOChannel *ch,
socks5_connect(struct _network_proxy_socks5 const *proxy, GIOChannel *ch, const char *address, uint16_t port)
char const *address, uint16_t port)
{ {
bool rc; bool rc;
struct server_greeting s_greeting; struct server_greeting s_greeting;
struct server_response s_response; struct server_response s_response;
/* Phase 1: exchange greeting */ /* Phase 1: exchange greeting */
{ {
struct client_greeting c_greeting = { struct client_greeting c_greeting = {
.ver = 0x05, .ver = 0x05,
.nmethods = proxy->username && proxy->username[0] ? 2 : 1 .nmethods = proxy->username && proxy->username[0] ? 2 : 1
}; };
/* HACK: order is important because it depends upon /* HACK: order is important because it depends upon
* c_greeting.nmethods */ * c_greeting.nmethods */
char const methods[] = { char const methods[] = {
0x00, /* no authentication */ 0x00, /* no authentication */
0x02 /* username/password */ 0x02 /* username/password */
}; };
if (!_network_proxy_send_all(ch, &c_greeting, sizeof c_greeting) || if (!_network_proxy_send_all(ch, &c_greeting, sizeof c_greeting) ||
!_network_proxy_send_all(ch, methods, c_greeting.nmethods) || !_network_proxy_send_all(ch, methods, c_greeting.nmethods) ||
!_network_proxy_flush(ch) || !_network_proxy_flush(ch) ||
!_network_proxy_recv_all(ch, &s_greeting, sizeof s_greeting)) !_network_proxy_recv_all(ch, &s_greeting, sizeof s_greeting))
goto err; goto err;
@ -177,22 +174,22 @@ socks5_connect(struct _network_proxy_socks5 const *proxy, GIOChannel *ch,
/* Phase 3: connection request */ /* Phase 3: connection request */
{ {
struct client_request c_request = { struct client_request c_request = {
.ver = 0x05, .ver = 0x05,
.cmd = 0x01, /* CONNECT */ .cmd = 0x01, /* CONNECT */
.atyp = 0x03, /* domain name */ .atyp = 0x03, /* domain name */
}; };
uint8_t address_len = strlen(address); uint8_t address_len = strlen(address);
uint16_t dst_port = htons(port); uint16_t dst_port = htons(port);
uint16_t bnd_port; uint16_t bnd_port;
char bnd_address[257]; char bnd_address[257];
if (!_network_proxy_send_all(ch, &c_request, sizeof c_request) || if (!_network_proxy_send_all(ch, &c_request, sizeof c_request) ||
!_network_proxy_send_all(ch, &address_len, sizeof address_len) || !_network_proxy_send_all(ch, &address_len, sizeof address_len) ||
!_network_proxy_send_all(ch, address, address_len) || !_network_proxy_send_all(ch, address, address_len) ||
!_network_proxy_send_all(ch, &dst_port, sizeof dst_port) || !_network_proxy_send_all(ch, &dst_port, sizeof dst_port) ||
!_network_proxy_flush(ch) || !_network_proxy_flush(ch) ||
!_network_proxy_recv_all(ch, &s_response, sizeof s_response)) !_network_proxy_recv_all(ch, &s_response, sizeof s_response))
goto err; goto err;
if (s_response.ver != 0x05) { if (s_response.ver != 0x05) {
@ -212,7 +209,7 @@ socks5_connect(struct _network_proxy_socks5 const *proxy, GIOChannel *ch,
case 0x06: g_warning("SOCKS5: TTL expired"); break; case 0x06: g_warning("SOCKS5: TTL expired"); break;
case 0x07: g_warning("SOCKS5: Command not supported"); break; case 0x07: g_warning("SOCKS5: Command not supported"); break;
case 0x08: g_warning("SOCKS5: Address type not supported"); break; case 0x08: g_warning("SOCKS5: Address type not supported"); break;
default: g_warning("SOCKS5: unknown error %#04x", s_response.rep); break; default: g_warning("SOCKS5: unknown error %#04x", s_response.rep); break;
} }
if (!rc) if (!rc)
@ -220,8 +217,8 @@ socks5_connect(struct _network_proxy_socks5 const *proxy, GIOChannel *ch,
switch(s_response.atyp) { switch(s_response.atyp) {
case 0x01: { case 0x01: {
struct in_addr ip; struct in_addr ip;
if (!_network_proxy_recv_all(ch, &ip, sizeof ip) || if (!_network_proxy_recv_all(ch, &ip, sizeof ip) ||
!inet_ntop(AF_INET, &ip, bnd_address, sizeof bnd_address)) !inet_ntop(AF_INET, &ip, bnd_address, sizeof bnd_address))
rc = false; rc = false;
break; break;
@ -229,14 +226,14 @@ socks5_connect(struct _network_proxy_socks5 const *proxy, GIOChannel *ch,
case 0x04: { case 0x04: {
struct in6_addr ip; struct in6_addr ip;
if (!_network_proxy_recv_all(ch, &ip, sizeof ip) || if (!_network_proxy_recv_all(ch, &ip, sizeof ip) ||
!inet_ntop(AF_INET6, &ip, bnd_address, sizeof bnd_address)) !inet_ntop(AF_INET6, &ip, bnd_address, sizeof bnd_address))
rc = false; rc = false;
break; break;
} }
case 0x03: { case 0x03: {
uint8_t tmp; uint8_t tmp;
if (!_network_proxy_recv_all(ch, &tmp, sizeof tmp) || if (!_network_proxy_recv_all(ch, &tmp, sizeof tmp) ||
tmp==0 || tmp==0 ||
!_network_proxy_recv_all(ch, &bnd_address, tmp)) !_network_proxy_recv_all(ch, &bnd_address, tmp))
@ -267,17 +264,16 @@ err:
} }
static GIOChannel * static GIOChannel *network_proxy_socks5_connect(const struct network_proxy *proxy, const IPADDR *hint_ip,
network_proxy_socks5_connect(struct network_proxy const *proxy, IPADDR const *hint_ip, const char *address, int port)
char const *address, int port)
{ {
struct _network_proxy_socks5 *self = container_of(proxy, struct _network_proxy_socks5, proxy); struct _network_proxy_socks5 *self = container_of(proxy, struct _network_proxy_socks5, proxy);
GIOChannel *ch; GIOChannel *ch;
GIOFlags old_flags; GIOFlags old_flags;
gchar const *old_enc; const gchar *old_enc;
gboolean old_buf; gboolean old_buf;
GError *err = NULL; GError *err = NULL;
if (hint_ip) if (hint_ip)
ch = net_connect_ip(hint_ip, self->proxy.port, NULL); ch = net_connect_ip(hint_ip, self->proxy.port, NULL);
@ -287,9 +283,9 @@ network_proxy_socks5_connect(struct network_proxy const *proxy, IPADDR const *hi
if (!ch) if (!ch)
return NULL; return NULL;
old_enc = g_io_channel_get_encoding(ch); old_enc = g_io_channel_get_encoding(ch);
old_flags = g_io_channel_get_flags(ch); old_flags = g_io_channel_get_flags(ch);
old_buf = g_io_channel_get_buffered(ch); old_buf = g_io_channel_get_buffered(ch);
if (g_io_channel_set_encoding(ch, NULL, &err)!=G_IO_STATUS_NORMAL || if (g_io_channel_set_encoding(ch, NULL, &err)!=G_IO_STATUS_NORMAL ||
g_io_channel_set_flags(ch, old_flags & ~G_IO_FLAG_NONBLOCK, &err)!=G_IO_STATUS_NORMAL) g_io_channel_set_flags(ch, old_flags & ~G_IO_FLAG_NONBLOCK, &err)!=G_IO_STATUS_NORMAL)
@ -319,20 +315,19 @@ err:
return NULL; return NULL;
} }
struct network_proxy * struct network_proxy *_network_proxy_socks5_create(void)
_network_proxy_socks5_create(void)
{ {
struct _network_proxy_socks5 *res; struct _network_proxy_socks5 *res;
res = g_malloc0(sizeof *res); res = g_malloc0(sizeof *res);
_network_proxy_create(&res->proxy); _network_proxy_create(&res->proxy);
res->username = g_strdup(settings_get_str("proxy_username")); res->username = g_strdup(settings_get_str("proxy_username"));
res->password = g_strdup(settings_get_str("proxy_password")); res->password = g_strdup(settings_get_str("proxy_password"));
res->proxy.destroy = network_proxy_socks5_destroy; res->proxy.destroy = network_proxy_socks5_destroy;
res->proxy.connect = network_proxy_socks5_connect; res->proxy.connect = network_proxy_socks5_connect;
res->proxy.clone = network_proxy_socks5_clone; res->proxy.clone = network_proxy_socks5_clone;
return &res->proxy; return &res->proxy;
} }

View File

@ -1,31 +1,15 @@
/* --*- c -*--
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef H_IRSSI_SRC_CORE_PROXY_SOCKS5_H #ifndef H_IRSSI_SRC_CORE_PROXY_SOCKS5_H
#define H_IRSSI_SRC_CORE_PROXY_SOCKS5_H #define H_IRSSI_SRC_CORE_PROXY_SOCKS5_H
#include "network-proxy.h" #include "network-proxy.h"
struct _network_proxy_socks5 { struct _network_proxy_socks5 {
struct network_proxy proxy; struct network_proxy proxy;
char const *username; const char *username;
char const *password; const char *password;
}; };
struct network_proxy * _network_proxy_socks5_create(void); struct network_proxy *_network_proxy_socks5_create(void);
#endif /* H_IRSSI_SRC_CORE_PROXY_SOCKS5_H */ #endif

View File

@ -1,18 +1,20 @@
/* --*- c -*-- /*
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> network-proxy.c : irssi
*
* This program is free software; you can redistribute it and/or modify Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License. This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* This program is distributed in the hope that it will be useful, the Free Software Foundation; version 2 and/or 3 of the License.
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the This program is distributed in the hope that it will be useful,
* GNU General Public License for more details. but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* You should have received a copy of the GNU General Public License GNU General Public License for more details.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "module.h" #include "module.h"
@ -22,8 +24,7 @@
#include "network-proxy-http.h" #include "network-proxy-http.h"
#include "network-proxy-socks5.h" #include "network-proxy-socks5.h"
struct network_proxy * struct network_proxy *network_proxy_create(const char *type)
network_proxy_create(char const *type)
{ {
if (type==NULL) if (type==NULL)
return NULL; return NULL;

View File

@ -1,19 +1,3 @@
/* --*- c -*--
* Copyright (C) 2008 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 and/or 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef H_IRSSI_SRC_CORE_PROXY_H #ifndef H_IRSSI_SRC_CORE_PROXY_H
#define H_IRSSI_SRC_CORE_PROXY_H #define H_IRSSI_SRC_CORE_PROXY_H
@ -22,22 +6,21 @@
/* helper structure for the send_string*() functions of the network_proxy /* helper structure for the send_string*() functions of the network_proxy
* class */ * class */
struct network_proxy_send_string_info struct network_proxy_send_string_info {
{ const char *host; /* hostname of the IRC server */
char const *host; /* hostname of the IRC server */ uint16_t port; /* portnumber of the IRC server */
uint16_t port; /* portnumber of the IRC server */
/* function which is used to send string; usually irc_send_cmd_now() */ /* function which is used to send string; usually irc_send_cmd_now() */
void (*func)(void *obj, char const *); void (*func)(void *obj, const char *);
/* object for func */ /* object for func */
void *obj; void *obj;
}; };
struct network_proxy { struct network_proxy {
/* destroys the network_proxy structure which must not be used anymore /* destroys the network_proxy structure which must not be used anymore
* after; this memberfunction is mandatory */ * after; this memberfunction is mandatory */
void (*destroy)(struct network_proxy *); void (*destroy)(struct network_proxy *);
/* connects through the proxy; this memberfunction is mandatory /* connects through the proxy; this memberfunction is mandatory
* *
@ -46,36 +29,34 @@ struct network_proxy {
* \arg address the hostname where proxy shall connect to * \arg address the hostname where proxy shall connect to
* \arg port port address where proxy shall connect to * \arg port port address where proxy shall connect to
*/ */
GIOChannel * (*connect)(struct network_proxy const *, IPADDR const *hint_ip, GIOChannel *(*connect)(const struct *network_proxy, const IPADDR *hint_ip,
char const *address, int port); const char *address, int port);
/* clones the given network_proxy object; this memberfunction is /* clones the given network_proxy object; this memberfunction is
* mandatory */ * mandatory */
struct network_proxy * (*clone)(struct network_proxy const *); struct network_proxy *(*clone)(const struct *network_proxy);
/* sends a string after connection has been established but before IRC /* sends a string after connection has been established but before IRC
* authentication begins; this memberfunction is optional * authentication begins; this memberfunction is optional
*/ */
void (*send_string)(struct network_proxy const *, void (*send_string)(const struct *network_proxy,
struct network_proxy_send_string_info const *); const struct *network_proxy_send_string_info);
/* sends a string after connection IRC authentication suceeded; this /* sends a string after connection IRC authentication suceeded; this
* memberfunction is optional * memberfunction is optional
*/ */
void (*send_string_after)(struct network_proxy const *, void (*send_string_after)(const struct *network_proxy,
struct network_proxy_send_string_info const *); const struct *network_proxy_send_string_info);
/* hostname of proxy host */ /* hostname of proxy host */
char const *host; const char *host;
/* portnumber of proxy */ /* portnumber of proxy */
int port; int port;
}; };
/* factory method to create a proxy object based upon value of 'type' */ /* factory method to create a proxy object based upon value of 'type' */
struct network_proxy * network_proxy_create(char const *type); struct network_proxy *network_proxy_create(const char *type);
#endif
#endif /* H_IRSSI_SRC_CORE_PROXY_H */

View File

@ -231,14 +231,12 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
GIOChannel *net_connect_proxy(struct network_proxy const *proxy, GIOChannel *net_connect_proxy(struct network_proxy const *proxy,
char const *host, int port, IPADDR *ip, IPADDR *my_ip) char const *host, int port, IPADDR *ip, IPADDR *my_ip)
{ {
if (proxy) if (proxy)
return proxy->connect(proxy, ip, host, port); return proxy->connect(proxy, ip, host, port);
else else
return net_connect_ip(ip, port, my_ip); return net_connect_ip(ip, port, my_ip);
} }
/* Connect to named UNIX socket */ /* Connect to named UNIX socket */
GIOChannel *net_connect_unix(const char *path) GIOChannel *net_connect_unix(const char *path)
{ {

View File

@ -50,11 +50,13 @@ int net_ip_compare(IPADDR *ip1, IPADDR *ip2);
/* Connect to socket */ /* Connect to socket */
GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip); GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip);
/* Connect to socket with ip address and SSL*/ /* Connect to socket with ip address and SSL*/
GIOChannel *net_connect_proxy_ssl(struct network_proxy const *proxy, char const *host, int port, IPADDR *ip, IPADDR *my_ip, SERVER_REC *server); GIOChannel *net_connect_proxy_ssl(struct network_proxy const *proxy, char const *host, int port,
IPADDR *ip, IPADDR *my_ip, SERVER_REC *server);
int irssi_ssl_handshake(GIOChannel *handle); int irssi_ssl_handshake(GIOChannel *handle);
/* Connect to socket with ip address */ /* Connect to socket with ip address */
GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip); GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
GIOChannel *net_connect_proxy(struct network_proxy const *proxy, char const *host, int port, IPADDR *ip, IPADDR *my_ip); GIOChannel *net_connect_proxy(struct network_proxy const *proxy, char const *host, int port,
IPADDR *ip, IPADDR *my_ip);
/* Connect to named UNIX socket */ /* Connect to named UNIX socket */
GIOChannel *net_connect_unix(const char *path); GIOChannel *net_connect_unix(const char *path);
/* Disconnect socket */ /* Disconnect socket */

View File

@ -5,7 +5,7 @@ int chat_type; /* chat_protocol_lookup(xx) */
int refcount; int refcount;
struct network_proxy *proxy; struct network_proxy *proxy;
unsigned short family; /* 0 = don't care, AF_INET or AF_INET6 */ unsigned short family; /* 0 = don't care, AF_INET or AF_INET6 */
char *tag; /* try to keep this tag when connected to server */ char *tag; /* try to keep this tag when connected to server */