mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 22:45:42 +02:00
Add support of /upgrade in Relay plugin
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,8 @@
|
||||
#ifndef __WEECHAT_RELAY_BUFFER_H
|
||||
#define __WEECHAT_RELAY_BUFFER_H 1
|
||||
|
||||
#define RELAY_BUFFER_NAME "relay.list"
|
||||
|
||||
extern struct t_gui_buffer *relay_buffer;
|
||||
extern int relay_buffer_selected_line;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,7 +43,11 @@ extern void relay_client_irc_recv (struct t_relay_client *client,
|
||||
const char *data);
|
||||
extern void relay_client_irc_close_connection (struct t_relay_client *client);
|
||||
extern void relay_client_irc_alloc (struct t_relay_client *client);
|
||||
extern void relay_client_irc_alloc_with_infolist (struct t_relay_client *client,
|
||||
struct t_infolist *infolist);
|
||||
extern void relay_client_irc_free (struct t_relay_client *client);
|
||||
extern int relay_client_irc_add_to_infolist (struct t_infolist_item *item,
|
||||
struct t_relay_client *client);
|
||||
extern void relay_client_irc_print_log (struct t_relay_client *client);
|
||||
|
||||
#endif /* __WEECHAT_RELAY_CLIENT_IRC_H */
|
||||
|
||||
@@ -207,6 +207,27 @@ relay_client_weechat_alloc (struct t_relay_client *client)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_client_weechat_alloc_with_infolist: init relay data specific to
|
||||
* weechat protocol with an infolist
|
||||
*/
|
||||
|
||||
void
|
||||
relay_client_weechat_alloc_with_infolist (struct t_relay_client *client,
|
||||
struct t_infolist *infolist)
|
||||
{
|
||||
struct t_relay_client_weechat_data *weechat_data;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) infolist;
|
||||
|
||||
client->protocol_data = malloc (sizeof (*weechat_data));
|
||||
if (client->protocol_data)
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_client_weechat_free: free relay data specific to weechat protocol
|
||||
*/
|
||||
@@ -218,6 +239,22 @@ relay_client_weechat_free (struct t_relay_client *client)
|
||||
free (client->protocol_data);
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_client_weechat_add_to_infolist: add client weechat data in an
|
||||
* infolist item
|
||||
* return 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
int
|
||||
relay_client_weechat_add_to_infolist (struct t_infolist_item *item,
|
||||
struct t_relay_client *client)
|
||||
{
|
||||
if (!item || !client)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_client_weechat_print_log: print weechat client infos in log (usually
|
||||
* for crash dump)
|
||||
|
||||
@@ -38,7 +38,11 @@ struct t_relay_client_weechat_data
|
||||
extern void relay_client_weechat_recv (struct t_relay_client *client,
|
||||
const char *data);
|
||||
extern void relay_client_weechat_alloc (struct t_relay_client *client);
|
||||
extern void relay_client_weechat_alloc_with_infolist (struct t_relay_client *client,
|
||||
struct t_infolist *infolist);
|
||||
extern void relay_client_weechat_free (struct t_relay_client *client);
|
||||
extern int relay_client_weechat_add_to_infolist (struct t_infolist_item *item,
|
||||
struct t_relay_client *client);
|
||||
extern void relay_client_weechat_print_log (struct t_relay_client *client);
|
||||
|
||||
#endif /* __WEECHAT_RELAY_CLIENT_WEECHAT_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -49,13 +49,12 @@ struct t_relay_client
|
||||
char *address; /* string with IP address */
|
||||
enum t_relay_status status; /* status (connecting, active,..) */
|
||||
enum t_relay_protocol protocol; /* protocol (irc,..) */
|
||||
char *protocol_string; /* string used for protocol */
|
||||
char *protocol_args; /* arguments used for protocol */
|
||||
/* example: server for irc protocol */
|
||||
time_t listen_start_time; /* when listening started */
|
||||
time_t start_time; /* time of client connection */
|
||||
time_t end_time; /* time of client disconnection */
|
||||
struct t_hook *hook_fd; /* hook for socket or child pipe */
|
||||
struct t_hook *hook_timer; /* timeout for recever accept */
|
||||
time_t last_activity; /* time of last byte received/sent */
|
||||
unsigned long bytes_recv; /* bytes received from client */
|
||||
unsigned long bytes_sent; /* bytes sent to client */
|
||||
@@ -71,6 +70,7 @@ extern int relay_client_count;
|
||||
|
||||
extern int relay_client_valid (struct t_relay_client *client);
|
||||
extern struct t_relay_client *relay_client_search_by_number (int number);
|
||||
extern int relay_client_recv_cb (void *arg_client, int fd);
|
||||
extern struct t_relay_client *relay_client_new (int sock, char *address,
|
||||
struct t_relay_server *server);
|
||||
extern void relay_client_set_status (struct t_relay_client *client,
|
||||
|
||||
@@ -132,7 +132,7 @@ relay_command_server_list ()
|
||||
RELAY_COLOR_CHAT,
|
||||
RELAY_COLOR_CHAT_BUFFER,
|
||||
relay_protocol_string[ptr_server->protocol],
|
||||
ptr_server->protocol_string,
|
||||
ptr_server->protocol_args,
|
||||
RELAY_COLOR_CHAT,
|
||||
date_start);
|
||||
i++;
|
||||
|
||||
@@ -90,7 +90,7 @@ relay_completion_relays_cb (void *data, const char *completion_item,
|
||||
{
|
||||
snprintf (protocol_name, sizeof (protocol_name), "%s.%s",
|
||||
relay_protocol_string[ptr_server->protocol],
|
||||
ptr_server->protocol_string);
|
||||
ptr_server->protocol_args);
|
||||
weechat_hook_completion_list_add (completion, protocol_name,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ relay_config_create_option_port (void *data,
|
||||
const char *value)
|
||||
{
|
||||
int rc, protocol_number;
|
||||
char *error, *protocol, *protocol_string;
|
||||
char *error, *protocol, *protocol_args;
|
||||
long port;
|
||||
struct t_relay_server *ptr_server;
|
||||
|
||||
@@ -184,13 +184,13 @@ relay_config_create_option_port (void *data,
|
||||
|
||||
rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
|
||||
|
||||
relay_server_get_protocol_string (option_name,
|
||||
&protocol, &protocol_string);
|
||||
relay_server_get_protocol_args (option_name,
|
||||
&protocol, &protocol_args);
|
||||
|
||||
protocol_number = -1;
|
||||
port = -1;
|
||||
|
||||
if (protocol && protocol_string)
|
||||
if (protocol && protocol_args)
|
||||
protocol_number = relay_protocol_search (protocol);
|
||||
|
||||
if (protocol_number < 0)
|
||||
@@ -234,7 +234,7 @@ relay_config_create_option_port (void *data,
|
||||
&relay_config_change_port_cb, NULL,
|
||||
&relay_config_delete_port_cb, NULL);
|
||||
|
||||
if (relay_server_new (protocol_number, protocol_string, port))
|
||||
if (relay_server_new (protocol_number, protocol_args, port))
|
||||
rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
|
||||
else
|
||||
rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
|
||||
@@ -242,8 +242,8 @@ relay_config_create_option_port (void *data,
|
||||
|
||||
if (protocol)
|
||||
free (protocol);
|
||||
if (protocol_string)
|
||||
free (protocol_string);
|
||||
if (protocol_args)
|
||||
free (protocol_args);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "../weechat-plugin.h"
|
||||
#include "relay.h"
|
||||
#include "relay-raw.h"
|
||||
#include "relay-buffer.h"
|
||||
#include "relay-client.h"
|
||||
#include "relay-config.h"
|
||||
|
||||
@@ -57,39 +58,6 @@ relay_raw_message_print (struct t_relay_raw_message *raw_message)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_raw_input_data_cb: callback for input data in Relay raw buffer
|
||||
*/
|
||||
|
||||
int
|
||||
relay_raw_input_data_cb (void *data, struct t_gui_buffer *buffer,
|
||||
const char *input_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
if (weechat_strcasecmp (input_data, "q") == 0)
|
||||
weechat_buffer_close (buffer);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_raw_buffer_close_cb: callback called when Relay raw buffer is closed
|
||||
*/
|
||||
|
||||
int
|
||||
relay_raw_buffer_close_cb (void *data, struct t_gui_buffer *buffer)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) buffer;
|
||||
|
||||
relay_raw_buffer = NULL;
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_raw_open: open Relay raw buffer
|
||||
*/
|
||||
@@ -106,8 +74,8 @@ relay_raw_open (int switch_to_buffer)
|
||||
if (!relay_raw_buffer)
|
||||
{
|
||||
relay_raw_buffer = weechat_buffer_new (RELAY_RAW_BUFFER_NAME,
|
||||
&relay_raw_input_data_cb, NULL,
|
||||
&relay_raw_buffer_close_cb, NULL);
|
||||
&relay_buffer_input_cb, NULL,
|
||||
&relay_buffer_close_cb, NULL);
|
||||
|
||||
/* failed to create buffer ? then return */
|
||||
if (!relay_raw_buffer)
|
||||
@@ -288,7 +256,7 @@ relay_raw_message_add (struct t_relay_client *client, int send,
|
||||
client->id,
|
||||
weechat_color ("chat_delimiters"),
|
||||
weechat_color ("chat_server"),
|
||||
client->protocol_string,
|
||||
client->protocol_args,
|
||||
(send) ?
|
||||
weechat_color ("chat_prefix_quit") :
|
||||
weechat_color ("chat_prefix_join"),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,7 @@
|
||||
struct t_relay_server
|
||||
{
|
||||
enum t_relay_protocol protocol; /* protocol (irc,..) */
|
||||
char *protocol_string; /* string used for protocol */
|
||||
char *protocol_args; /* arguments used for protocol */
|
||||
/* example: server for irc protocol */
|
||||
int port; /* listening on this port */
|
||||
int sock; /* socket for connection */
|
||||
@@ -36,15 +36,15 @@ struct t_relay_server
|
||||
extern struct t_relay_server *relay_servers;
|
||||
extern struct t_relay_server *last_relay_server;
|
||||
|
||||
extern void relay_server_get_protocol_string (const char *protocol_and_string,
|
||||
char **protocol,
|
||||
char **protocol_string);
|
||||
extern struct t_relay_server *relay_server_search (const char *protocol_and_string);
|
||||
extern void relay_server_get_protocol_args (const char *protocol_and_string,
|
||||
char **protocol,
|
||||
char **protocol_args);
|
||||
extern struct t_relay_server *relay_server_search (const char *protocol_and_args);
|
||||
extern struct t_relay_server *relay_server_search_port (int port);
|
||||
extern void relay_server_close_socket (struct t_relay_server *server);
|
||||
extern int relay_server_create_socket (struct t_relay_server *server);
|
||||
extern struct t_relay_server *relay_server_new (enum t_relay_protocol protocol,
|
||||
const char *protocol_string,
|
||||
const char *protocol_args,
|
||||
int port);
|
||||
extern void relay_server_update_port (struct t_relay_server *server, int port);
|
||||
extern void relay_server_free (struct t_relay_server *server);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,8 @@
|
||||
|
||||
enum t_relay_upgrade_type
|
||||
{
|
||||
RELAY_UPGRADE_TYPE_RELAY = 0,
|
||||
RELAY_UPGRADE_TYPE_CLIENT = 0,
|
||||
RELAY_UPGRADE_TYPE_RAW_MESSAGE,
|
||||
};
|
||||
|
||||
extern int relay_upgrade_save ();
|
||||
|
||||
@@ -136,6 +136,8 @@ relay_debug_dump_cb (void *data, const char *signal, const char *type_data,
|
||||
int
|
||||
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
{
|
||||
int i, upgrading;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
@@ -158,6 +160,19 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
|
||||
relay_info_init ();
|
||||
|
||||
/* look at arguments */
|
||||
upgrading = 0;
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if (weechat_strcasecmp (argv[i], "--upgrade") == 0)
|
||||
{
|
||||
upgrading = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (upgrading)
|
||||
relay_upgrade_load ();
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user