1
0
mirror of https://github.com/irssi/irssi.git synced 2025-02-02 15:08:01 -05:00

replaced net_transmit by net_sendbuffer_send in the irssi-proxy module, there were no checks if the buffer was sent completely with net_transmit

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3947 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Valentin Batz 2005-08-24 19:25:47 +00:00 committed by vb
parent efd4febee6
commit bc91469cf7
3 changed files with 28 additions and 18 deletions

View File

@ -20,6 +20,7 @@
#include "module.h" #include "module.h"
#include "network.h" #include "network.h"
#include "net-sendbuffer.h"
#include "settings.h" #include "settings.h"
#include "irssi-version.h" #include "irssi-version.h"
#include "recode.h" #include "recode.h"
@ -40,7 +41,7 @@ void proxy_outdata(CLIENT_REC *client, const char *data, ...)
va_start(args, data); va_start(args, data);
str = g_strdup_vprintf(data, args); str = g_strdup_vprintf(data, args);
net_transmit(client->handle, str, strlen(str)); net_sendbuffer_send(client->handle, str, strlen(str));
g_free(str); g_free(str);
va_end(args); va_end(args);
@ -64,7 +65,7 @@ void proxy_outdata_all(IRC_SERVER_REC *server, const char *data, ...)
CLIENT_REC *rec = tmp->data; CLIENT_REC *rec = tmp->data;
if (rec->connected && rec->server == server) if (rec->connected && rec->server == server)
net_transmit(rec->handle, str, len); net_sendbuffer_send(rec->handle, str, len);
} }
g_free(str); g_free(str);

View File

@ -30,6 +30,15 @@
#include "fe-common/core/printtext.h" /* FIXME: evil. need to do fe-proxy */ #include "fe-common/core/printtext.h" /* FIXME: evil. need to do fe-proxy */
struct _NET_SENDBUF_REC {
GIOChannel *handle;
int send_tag;
int bufsize;
int bufpos;
char *buffer; /* Buffer is NULL until it's actually needed. */
};
GSList *proxy_listens; GSList *proxy_listens;
GSList *proxy_clients; GSList *proxy_clients;
@ -48,8 +57,8 @@ static void remove_client(CLIENT_REC *rec)
"Proxy: Client disconnected from %s", rec->host); "Proxy: Client disconnected from %s", rec->host);
g_free(rec->proxy_address); g_free(rec->proxy_address);
net_disconnect(rec->handle); net_sendbuffer_destroy(rec->handle, TRUE);
g_source_remove(rec->tag); g_source_remove(rec->recv_tag);
line_split_free(rec->buffer); line_split_free(rec->buffer);
g_free_not_null(rec->nick); g_free_not_null(rec->nick);
g_free_not_null(rec->host); g_free_not_null(rec->host);
@ -171,7 +180,8 @@ static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args,
for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) {
CLIENT_REC *rec = tmp->data; CLIENT_REC *rec = tmp->data;
if ((g_strcasecmp(client->listen->ircnet,rec->listen->ircnet) == 0) && if ((g_strcasecmp(client->listen->ircnet,rec->listen->ircnet) == 0) &&
(client->tag != rec->tag)) { /* kludgy way to check if the clients aren't the same */
(client->recv_tag != rec->recv_tag)) {
if (rec->want_ctcp == 1) if (rec->want_ctcp == 1)
proxy_outdata(rec, ":%s NOTICE %s :Another client is now receiving CTCPs sent to %s\n", proxy_outdata(rec, ":%s NOTICE %s :Another client is now receiving CTCPs sent to %s\n",
rec->proxy_address, rec->nick, rec->listen->ircnet); rec->proxy_address, rec->nick, rec->listen->ircnet);
@ -299,7 +309,7 @@ static void sig_listen_client(CLIENT_REC *client)
g_return_if_fail(client != NULL); g_return_if_fail(client != NULL);
while (g_slist_find(proxy_clients, client) != NULL) { while (g_slist_find(proxy_clients, client) != NULL) {
recvlen = net_receive(client->handle, tmpbuf, sizeof(tmpbuf)); recvlen = net_receive(client->handle->handle, tmpbuf, sizeof(tmpbuf));
ret = line_split(tmpbuf, recvlen, &str, &client->buffer); ret = line_split(tmpbuf, recvlen, &str, &client->buffer);
if (ret == -1) { if (ret == -1) {
/* connection lost */ /* connection lost */
@ -326,6 +336,7 @@ static void sig_listen(LISTEN_REC *listen)
{ {
CLIENT_REC *rec; CLIENT_REC *rec;
IPADDR ip; IPADDR ip;
NET_SENDBUF_REC *sendbuf;
GIOChannel *handle; GIOChannel *handle;
char host[MAX_IP_LEN]; char host[MAX_IP_LEN];
int port; int port;
@ -337,10 +348,10 @@ static void sig_listen(LISTEN_REC *listen)
if (handle == NULL) if (handle == NULL)
return; return;
net_ip2host(&ip, host); net_ip2host(&ip, host);
sendbuf = net_sendbuffer_create(handle, 0);
rec = g_new0(CLIENT_REC, 1); rec = g_new0(CLIENT_REC, 1);
rec->listen = listen; rec->listen = listen;
rec->handle = handle; rec->handle = sendbuf;
rec->host = g_strdup(host); rec->host = g_strdup(host);
if (strcmp(listen->ircnet, "*") == 0) { if (strcmp(listen->ircnet, "*") == 0) {
rec->proxy_address = g_strdup("irc.proxy"); rec->proxy_address = g_strdup("irc.proxy");
@ -350,7 +361,7 @@ static void sig_listen(LISTEN_REC *listen)
rec->server = servers == NULL ? NULL : rec->server = servers == NULL ? NULL :
IRC_SERVER(server_find_chatnet(listen->ircnet)); IRC_SERVER(server_find_chatnet(listen->ircnet));
} }
rec->tag = g_input_add(handle, G_INPUT_READ, rec->recv_tag = g_input_add(handle, G_INPUT_READ,
(GInputFunction) sig_listen_client, rec); (GInputFunction) sig_listen_client, rec);
proxy_clients = g_slist_prepend(proxy_clients, rec); proxy_clients = g_slist_prepend(proxy_clients, rec);
@ -403,7 +414,7 @@ static void sig_server_event(IRC_SERVER_REC *server, const char *line,
if (sscanf(signal+6, "%p", &client) == 1) { if (sscanf(signal+6, "%p", &client) == 1) {
/* send it to specific client only */ /* send it to specific client only */
if (g_slist_find(proxy_clients, client) != NULL) if (g_slist_find(proxy_clients, client) != NULL)
net_transmit(((CLIENT_REC *) client)->handle, next_line->str, next_line->len); net_sendbuffer_send(((CLIENT_REC *) client)->handle, next_line->str, next_line->len);
g_free(event); g_free(event);
signal_stop(); signal_stop();
return; return;
@ -418,11 +429,10 @@ static void sig_server_event(IRC_SERVER_REC *server, const char *line,
CLIENT_REC *rec = tmp->data; CLIENT_REC *rec = tmp->data;
if (rec->want_ctcp == 1) { if (rec->want_ctcp == 1) {
/* one of the clients answers */ /* only CTCP for the chatnet where client is connected to will be forwarded */
/* patched, so only CTCP for the chatnet where client is connected to will be forwarded */ if (strstr(rec->proxy_address, server->connrec->chatnet) != NULL) {
if (strstr(rec->proxy_address,server->connrec->chatnet) != NULL) { net_sendbuffer_send(rec->handle,
net_transmit(rec->handle, next_line->str, next_line->len);
next_line->str, next_line->len);
signal_stop(); signal_stop();
} }
} }

View File

@ -21,9 +21,8 @@ typedef struct {
LINEBUF_REC *buffer; LINEBUF_REC *buffer;
char *nick, *host; char *nick, *host;
GIOChannel *handle; NET_SENDBUF_REC *handle;
int tag; int recv_tag;
char *proxy_address; char *proxy_address;
LISTEN_REC *listen; LISTEN_REC *listen;
IRC_SERVER_REC *server; IRC_SERVER_REC *server;