mirror of
https://github.com/irssi/irssi.git
synced 2026-08-23 02:22:36 +02:00
Change coding style
Based on original patch by hawken93 <hawken@thehawken.org> 3 Oct 2014
This commit is contained in:
parent
4b0610e317
commit
4a8a6cfcbf
14 changed files with 301 additions and 169 deletions
5
TODO
5
TODO
|
|
@ -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,
|
||||
bar joins, bar changes his nick to foo, foo splits again ->
|
||||
Glib warning "is already in split list (how?)" .. :)
|
||||
|
|
|
|||
|
|
@ -565,7 +565,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
|
|||
return gchan;
|
||||
}
|
||||
|
||||
GIOChannel *net_connect_proxy_ssl(struct network_proxy const *proxy, char const *host, int port,
|
||||
GIOChannel *net_connect_proxy_ssl(const struct network_proxy *proxy, const char *host, int port,
|
||||
IPADDR *ip, IPADDR *my_ip, SERVER_REC *server)
|
||||
{
|
||||
GIOChannel *handle, *ssl_handle;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@
|
|||
#include "network.h"
|
||||
#include "network-proxy-priv.h"
|
||||
|
||||
static void
|
||||
network_proxy_http_destroy(struct network_proxy *proxy)
|
||||
static void network_proxy_http_destroy(struct network_proxy *proxy)
|
||||
{
|
||||
struct _network_proxy_http *self = container_of(proxy, struct _network_proxy_http, proxy);
|
||||
|
||||
|
|
@ -49,8 +48,8 @@ network_proxy_http_clone(struct network_proxy const *proxy)
|
|||
return &res->proxy;
|
||||
}
|
||||
|
||||
static bool
|
||||
send_connect(struct _network_proxy_http *proxy, GIOChannel *ch, char const *address, uint16_t port)
|
||||
static bool send_connect(struct _network_proxy_http *proxy, GIOChannel *ch,
|
||||
char const *address, uint16_t port)
|
||||
{
|
||||
char port_str[6];
|
||||
|
||||
|
|
@ -68,8 +67,7 @@ send_connect(struct _network_proxy_http *proxy, GIOChannel *ch, char const *addr
|
|||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
read_response(struct _network_proxy_http *proxy, GIOChannel *ch)
|
||||
static int read_response(struct _network_proxy_http *proxy, GIOChannel *ch)
|
||||
{
|
||||
GIOStatus status;
|
||||
GString line = { .str = NULL };
|
||||
|
|
@ -125,8 +123,7 @@ err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static GIOChannel *
|
||||
network_proxy_http_connect(struct network_proxy const *proxy, IPADDR const *hint_ip,
|
||||
static GIOChannel *network_proxy_http_connect(struct network_proxy const *proxy, IPADDR const *hint_ip,
|
||||
char const *address, int port)
|
||||
{
|
||||
struct _network_proxy_http *self = container_of(proxy, struct _network_proxy_http, proxy);
|
||||
|
|
@ -175,8 +172,7 @@ err:
|
|||
}
|
||||
|
||||
|
||||
struct network_proxy *
|
||||
_network_proxy_http_create(void)
|
||||
struct network_proxy *_network_proxy_http_create(void)
|
||||
{
|
||||
struct _network_proxy_http *res;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,15 +26,13 @@
|
|||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
|
||||
inline static void
|
||||
_network_proxy_create(struct network_proxy *dst)
|
||||
inline static void _network_proxy_create(struct network_proxy *dst)
|
||||
{
|
||||
dst->port = settings_get_int("proxy_port");
|
||||
dst->host = g_strdup(settings_get_str("proxy_address"));
|
||||
}
|
||||
|
||||
inline static void
|
||||
_network_proxy_clone(struct network_proxy *dst, struct network_proxy const *src)
|
||||
inline static void _network_proxy_clone(struct network_proxy *dst, struct network_proxy const *src)
|
||||
{
|
||||
dst->host = g_strdup(src->host);
|
||||
dst->port = src->port;
|
||||
|
|
@ -44,16 +42,14 @@ _network_proxy_clone(struct network_proxy *dst, struct network_proxy const *src)
|
|||
dst->clone = src->clone;
|
||||
}
|
||||
|
||||
inline static void
|
||||
_network_proxy_destroy(struct network_proxy *proxy)
|
||||
inline static void _network_proxy_destroy(struct network_proxy *proxy)
|
||||
{
|
||||
g_free((void *)proxy->host);
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline static bool
|
||||
_network_proxy_send_all(GIOChannel *ch, void const *buf, ssize_t len)
|
||||
inline static bool _network_proxy_send_all(GIOChannel *ch, void const *buf, ssize_t len)
|
||||
{
|
||||
GError *err = NULL;
|
||||
gsize written;
|
||||
|
|
@ -74,8 +70,7 @@ _network_proxy_send_all(GIOChannel *ch, void const *buf, ssize_t len)
|
|||
return false;
|
||||
}
|
||||
|
||||
inline static bool
|
||||
_network_proxy_recv_all(GIOChannel *ch, void *buf_v, size_t len)
|
||||
inline static bool _network_proxy_recv_all(GIOChannel *ch, void *buf_v, size_t len)
|
||||
{
|
||||
GError *err = NULL;
|
||||
gchar *buf = buf_v;
|
||||
|
|
@ -105,8 +100,7 @@ _network_proxy_recv_all(GIOChannel *ch, void *buf_v, size_t len)
|
|||
return false;
|
||||
}
|
||||
|
||||
inline static bool
|
||||
_network_proxy_flush(GIOChannel *ch)
|
||||
inline static bool _network_proxy_flush(GIOChannel *ch)
|
||||
{
|
||||
GError *err = NULL;
|
||||
GIOStatus status;
|
||||
|
|
|
|||
128
src/core/network-proxy-simple.c
Normal file
128
src/core/network-proxy-simple.c
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
network-proxy-simple.c : irssi
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "network-proxy-simple.h"
|
||||
|
||||
#include "network-proxy-priv.h"
|
||||
#include "network.h"
|
||||
|
||||
static void network_proxy_simple_destroy(struct network_proxy *proxy)
|
||||
{
|
||||
struct network_proxy_simple *self = (struct network_proxy_simple *)proxy->privdata;
|
||||
|
||||
g_free(self->password);
|
||||
g_free(self->string_after);
|
||||
g_free(self->string);
|
||||
|
||||
g_free(self);
|
||||
|
||||
_network_proxy_destroy(proxy);
|
||||
|
||||
// We are responsible for the whole proxy struct
|
||||
g_free(proxy);
|
||||
}
|
||||
|
||||
static struct network_proxy *network_proxy_simple_clone(const struct network_proxy *proxy)
|
||||
{
|
||||
struct network_proxy_simple *self = (struct network_proxy_simple *)proxy->privdata;
|
||||
struct network_proxy *res;
|
||||
struct network_proxy_simple *newself;
|
||||
|
||||
// First make and set the parent struct
|
||||
res = g_malloc0(sizeof(struct network_proxy));
|
||||
_network_proxy_clone(res, proxy);
|
||||
|
||||
// Then allocate and set the private data
|
||||
newself = g_malloc0(sizeof(struct network_proxy_simple));
|
||||
res->privdata = (void *)newself;
|
||||
|
||||
newself->string = g_strdup(self->string);
|
||||
newself->string_after = g_strdup(self->string_after);
|
||||
newself->password = g_strdup(self->password);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static GIOChannel *network_proxy_simple_connect(const struct network_proxy *proxy,
|
||||
const IPADDR *hint_ip, char const *address, int port)
|
||||
{
|
||||
if (hint_ip)
|
||||
return net_connect_ip(hint_ip, proxy->port, NULL);
|
||||
else
|
||||
return net_connect(proxy->host, proxy->port, NULL);
|
||||
}
|
||||
|
||||
static void network_proxy_simple_send_string(const struct network_proxy *proxy,
|
||||
const struct network_proxy_send_string_info *info)
|
||||
{
|
||||
struct network_proxy_simple *self = (struct network_proxy_simple *)proxy->privdata;
|
||||
char *cmd;
|
||||
|
||||
if (self->password && self->password[0]) {
|
||||
cmd = g_strdup_printf("PASS %s", self->password);
|
||||
info->func(info->obj, cmd);
|
||||
g_free(cmd);
|
||||
}
|
||||
|
||||
if (self->string && self->string[0]) {
|
||||
cmd = g_strdup_printf(self->string, info->host, info->port);
|
||||
info->func(info->obj, cmd);
|
||||
g_free(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
static void network_proxy_simple_send_string_after(const struct network_proxy *proxy,
|
||||
const struct network_proxy_send_string_info *info)
|
||||
{
|
||||
struct network_proxy_simple *self = (struct network_proxy_simple *)proxy->privdata;
|
||||
char *cmd;
|
||||
|
||||
if (self->string_after && self->string_after[0]) {
|
||||
cmd = g_strdup_printf(self->string_after, info->host, info->port);
|
||||
info->func(info->obj, cmd);
|
||||
g_free(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
struct network_proxy *network_proxy_simple_create(void)
|
||||
{
|
||||
struct network_proxy *proxy;
|
||||
struct network_proxy_simple *self;
|
||||
|
||||
proxy = g_malloc0(sizeof(struct network_proxy));
|
||||
|
||||
// assume it could reset every variable to a known state
|
||||
_network_proxy_create(proxy);
|
||||
|
||||
self = g_malloc0(sizeof(struct network_proxy_simple));
|
||||
proxy->privdata = (void *)self;
|
||||
|
||||
self->string = g_strdup(settings_get_str("proxy_string"));
|
||||
self->string_after = g_strdup(settings_get_str("proxy_string_after"));
|
||||
self->password = g_strdup(settings_get_str("proxy_password"));
|
||||
|
||||
proxy->destroy = network_proxy_simple_destroy;
|
||||
proxy->connect = network_proxy_simple_connect;
|
||||
proxy->clone = network_proxy_simple_clone;
|
||||
|
||||
proxy->send_string = network_proxy_simple_send_string;
|
||||
proxy->send_string_after = network_proxy_simple_send_string_after;
|
||||
|
||||
return proxy;
|
||||
}
|
||||
14
src/core/network-proxy-simple.h
Normal file
14
src/core/network-proxy-simple.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef H_IRSSI_SRC_CORE_PROXY_SIMPLE_H
|
||||
#define H_IRSSI_SRC_CORE_PROXY_SIMPLE_H
|
||||
|
||||
#include "network-proxy.h"
|
||||
|
||||
struct network_proxy_simple {
|
||||
char *string_after;
|
||||
char *string;
|
||||
char *password;
|
||||
};
|
||||
|
||||
struct network_proxy *network_proxy_simple_create(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -61,8 +61,7 @@ struct server_response
|
|||
uint8_t bnd[];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
static void
|
||||
network_proxy_socks5_destroy(struct network_proxy *proxy)
|
||||
static void network_proxy_socks5_destroy(struct network_proxy *proxy)
|
||||
{
|
||||
struct _network_proxy_socks5 *self = container_of(proxy, struct _network_proxy_socks5, proxy);
|
||||
|
||||
|
|
@ -72,8 +71,7 @@ network_proxy_socks5_destroy(struct network_proxy *proxy)
|
|||
g_free(self);
|
||||
}
|
||||
|
||||
static struct network_proxy *
|
||||
network_proxy_socks5_clone(struct network_proxy const *proxy)
|
||||
static struct network_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 *res;
|
||||
|
|
@ -86,8 +84,7 @@ network_proxy_socks5_clone(struct network_proxy const *proxy)
|
|||
return &res->proxy;
|
||||
}
|
||||
|
||||
static bool
|
||||
socks5_connect_unauthorized(GIOChannel *ch)
|
||||
static bool socks5_connect_unauthorized(GIOChannel *ch)
|
||||
{
|
||||
/* nothing to do here */
|
||||
(void)ch;
|
||||
|
|
@ -95,8 +92,7 @@ socks5_connect_unauthorized(GIOChannel *ch)
|
|||
}
|
||||
|
||||
/* TODO: test this method! */
|
||||
static bool
|
||||
socks5_connect_plain(struct _network_proxy_socks5 const *proxy, GIOChannel *ch)
|
||||
static bool socks5_connect_plain(struct _network_proxy_socks5 const *proxy, GIOChannel *ch)
|
||||
{
|
||||
uint8_t ver = 0x01;
|
||||
uint8_t ulen = strlen(proxy->username);
|
||||
|
|
@ -126,8 +122,7 @@ socks5_connect_plain(struct _network_proxy_socks5 const *proxy, GIOChannel *ch)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
socks5_connect(struct _network_proxy_socks5 const *proxy, GIOChannel *ch,
|
||||
static bool socks5_connect(struct _network_proxy_socks5 const *proxy, GIOChannel *ch,
|
||||
char const *address, uint16_t port)
|
||||
{
|
||||
bool rc;
|
||||
|
|
@ -267,8 +262,7 @@ err:
|
|||
}
|
||||
|
||||
|
||||
static GIOChannel *
|
||||
network_proxy_socks5_connect(struct network_proxy const *proxy, IPADDR const *hint_ip,
|
||||
static GIOChannel *network_proxy_socks5_connect(struct network_proxy const *proxy, IPADDR const *hint_ip,
|
||||
char const *address, int port)
|
||||
{
|
||||
struct _network_proxy_socks5 *self = container_of(proxy, struct _network_proxy_socks5, proxy);
|
||||
|
|
@ -319,8 +313,7 @@ err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct network_proxy *
|
||||
_network_proxy_socks5_create(void)
|
||||
struct network_proxy *_network_proxy_socks5_create(void)
|
||||
{
|
||||
struct _network_proxy_socks5 *res;
|
||||
|
||||
|
|
|
|||
|
|
@ -198,8 +198,8 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
|
|||
}
|
||||
|
||||
/* Connect to socket */
|
||||
GIOChannel *net_connect_proxy(struct network_proxy const *proxy,
|
||||
char const *host, int port, IPADDR *ip, IPADDR *my_ip)
|
||||
GIOChannel *net_connect_proxy(const struct network_proxy *proxy,
|
||||
const char *host, int port, IPADDR *ip, IPADDR *my_ip)
|
||||
{
|
||||
if (proxy)
|
||||
return proxy->connect(proxy, ip, host, port);
|
||||
|
|
|
|||
|
|
@ -40,12 +40,14 @@ int net_ip_compare(IPADDR *ip1, IPADDR *ip2);
|
|||
/* Connect to socket */
|
||||
GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip);
|
||||
/* 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(const struct network_proxy *proxy, const char c*host, int port,
|
||||
IPADDR *ip, IPADDR *my_ip, SERVER_REC *server);
|
||||
|
||||
int irssi_ssl_handshake(GIOChannel *handle);
|
||||
/* Connect to socket with ip address */
|
||||
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(const struct network_proxy *proxy, const char *host, int port,
|
||||
IPADDR *ip, IPADDR *my_ip);
|
||||
/* Connect to named UNIX socket */
|
||||
GIOChannel *net_connect_unix(const char *path);
|
||||
/* Disconnect socket */
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ static void server_init(IRC_SERVER_REC *server)
|
|||
char *address, *ptr, *username, *cmd;
|
||||
GTimeVal now;
|
||||
|
||||
struct network_proxy_send_string_info const send_info = {
|
||||
const struct network_proxy_send_string_info send_info = {
|
||||
.host = server->connrec->address,
|
||||
.port = server->connrec->port,
|
||||
.func = irc_send_cmd_now_wrapper,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue