mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 08:13:14 +02:00
Reintroduce /upgrade command, working only with core and IRC plugin today
Command will be improved in near future and other plugins like xfer will be modified to manage upgrade process.
This commit is contained in:
@@ -28,7 +28,8 @@ irc-input.c irc-input.h
|
||||
irc-mode.c irc-mode.h
|
||||
irc-nick.c irc-nick.h
|
||||
irc-protocol.c irc-protocol.h
|
||||
irc-server.c irc-server.h)
|
||||
irc-server.c irc-server.h
|
||||
irc-upgrade.c irc-upgrade.h)
|
||||
SET_TARGET_PROPERTIES(irc PROPERTIES PREFIX "")
|
||||
|
||||
CHECK_INCLUDE_FILES("regex.h" HAVE_REGEX_H)
|
||||
|
||||
@@ -47,7 +47,9 @@ irc_la_SOURCES = irc.c \
|
||||
irc-protocol.c \
|
||||
irc-protocol.h \
|
||||
irc-server.c \
|
||||
irc-server.h
|
||||
irc-server.h \
|
||||
irc-upgrade.c \
|
||||
irc-upgrade.h
|
||||
|
||||
irc_la_LDFLAGS = -module
|
||||
irc_la_LIBADD = $(IRC_LFLAGS) $(GNUTLS_LFLAGS)
|
||||
|
||||
@@ -53,16 +53,23 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
|
||||
weechat_prefix ("error"), "irc");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create buffer for channel */
|
||||
new_buffer = weechat_buffer_new (server->name, channel_name,
|
||||
&irc_input_data_cb, NULL,
|
||||
&irc_buffer_close_cb, NULL);
|
||||
if (!new_buffer)
|
||||
|
||||
/* create buffer for channel (or use existing one) */
|
||||
new_buffer = weechat_buffer_search (server->name, channel_name);
|
||||
if (new_buffer)
|
||||
weechat_nicklist_remove_all (new_buffer);
|
||||
else
|
||||
{
|
||||
free (new_channel);
|
||||
return NULL;
|
||||
new_buffer = weechat_buffer_new (server->name, channel_name,
|
||||
&irc_input_data_cb, NULL,
|
||||
&irc_buffer_close_cb, NULL);
|
||||
if (!new_buffer)
|
||||
{
|
||||
free (new_channel);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (channel_type == IRC_CHANNEL_TYPE_CHANNEL)
|
||||
{
|
||||
weechat_buffer_set (new_buffer, "nick", server->nick);
|
||||
@@ -124,6 +131,20 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
|
||||
return new_channel;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_channel_set_topic: set topic for a channel
|
||||
*/
|
||||
|
||||
void
|
||||
irc_channel_set_topic (struct t_irc_channel *channel, char *topic)
|
||||
{
|
||||
if (channel->topic)
|
||||
free (channel->topic);
|
||||
|
||||
channel->topic = (topic) ? strdup (topic) : NULL;
|
||||
weechat_buffer_set (channel->buffer, "title", channel->topic);
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_channel_free: free a channel and remove it from channels list
|
||||
*/
|
||||
@@ -353,6 +374,52 @@ irc_channel_add_nick_speaking (struct t_irc_channel *channel, const char *nick)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_channel_add_to_infolist: add a channel in an infolist
|
||||
* return 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
int
|
||||
irc_channel_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_irc_channel *channel)
|
||||
{
|
||||
struct t_infolist_item *ptr_item;
|
||||
|
||||
if (!infolist || !channel)
|
||||
return 0;
|
||||
|
||||
ptr_item = weechat_infolist_new_item (infolist);
|
||||
if (!ptr_item)
|
||||
return 0;
|
||||
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "type", channel->type))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "name", channel->name))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "topic", channel->topic))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "modes", channel->modes))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "limit", channel->limit))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "key", channel->key))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "nicks_count", channel->nicks_count))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "checking_away", channel->checking_away))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "away_message", channel->away_message))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "cycle", channel->cycle))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "display_creation_date", channel->display_creation_date))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "nick_completion_reset", channel->nick_completion_reset))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_channel_print_log: print channel infos in log (usually for crash dump)
|
||||
*/
|
||||
|
||||
@@ -58,6 +58,7 @@ extern struct t_irc_channel *irc_channel_new (struct t_irc_server *server,
|
||||
int channel_type,
|
||||
const char *channel_name,
|
||||
int switch_to_channel);
|
||||
extern void irc_channel_set_topic (struct t_irc_channel *channel, char *topic);
|
||||
extern void irc_channel_free (struct t_irc_server *server,
|
||||
struct t_irc_channel *channel);
|
||||
extern void irc_channel_free_all (struct t_irc_server *server);
|
||||
@@ -75,6 +76,8 @@ extern void irc_channel_set_away (struct t_irc_channel *channel, const char *nic
|
||||
int is_away);
|
||||
extern void irc_channel_add_nick_speaking (struct t_irc_channel *channel,
|
||||
const char *nick);
|
||||
extern int irc_channel_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_irc_channel *channel);
|
||||
extern void irc_channel_print_log (struct t_irc_channel *channel);
|
||||
|
||||
#endif /* irc-channel.h */
|
||||
|
||||
@@ -860,8 +860,8 @@ irc_command_dcc (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
struct sockaddr_in addr;
|
||||
socklen_t length;
|
||||
unsigned long address;
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_plugin_infolist_item *item;
|
||||
struct t_infolist *infolist;
|
||||
struct t_infolist_item *item;
|
||||
char plugin_id[128], str_address[128];
|
||||
|
||||
IRC_GET_SERVER_CHANNEL(buffer);
|
||||
|
||||
@@ -295,7 +295,7 @@ irc_config_server_delete_cb (void *data, struct t_config_option *option)
|
||||
int i, index_option, length;
|
||||
char *name, *mask;
|
||||
struct t_irc_server *ptr_server;
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_infolist *infolist;
|
||||
|
||||
index_option = irc_config_search_server_option (data);
|
||||
if (index_option >= 0)
|
||||
@@ -340,7 +340,7 @@ irc_config_server_delete_cb (void *data, struct t_config_option *option)
|
||||
void
|
||||
irc_config_reload_servers_from_config ()
|
||||
{
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_infolist *infolist;
|
||||
struct t_irc_server *ptr_server;
|
||||
struct t_config_option *ptr_option;
|
||||
char *name, *full_name, *server_name, *pos_option;
|
||||
|
||||
@@ -555,6 +555,36 @@ irc_nick_as_prefix (struct t_irc_nick *nick, const char *nickname,
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_nick_add_to_infolist: add a nick in an infolist
|
||||
* return 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
int
|
||||
irc_nick_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_irc_nick *nick)
|
||||
{
|
||||
struct t_infolist_item *ptr_item;
|
||||
|
||||
if (!infolist || !nick)
|
||||
return 0;
|
||||
|
||||
ptr_item = weechat_infolist_new_item (infolist);
|
||||
if (!ptr_item)
|
||||
return 0;
|
||||
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "name", nick->name))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "host", nick->host))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "flags", nick->flags))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "color", nick->color))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_nick_print_log: print nick infos in log (usually for crash dump)
|
||||
*/
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
|
||||
#define IRC_NICK_CHANOWNER 1
|
||||
#define IRC_NICK_CHANADMIN 2
|
||||
#define IRC_NICK_OP 4
|
||||
#define IRC_NICK_HALFOP 8
|
||||
#define IRC_NICK_VOICE 16
|
||||
#define IRC_NICK_AWAY 32
|
||||
#define IRC_NICK_CHANADMIN2 64
|
||||
#define IRC_NICK_CHANADMIN2 4
|
||||
#define IRC_NICK_OP 8
|
||||
#define IRC_NICK_HALFOP 16
|
||||
#define IRC_NICK_VOICE 32
|
||||
#define IRC_NICK_AWAY 64
|
||||
#define IRC_NICK_CHANUSER 128
|
||||
#define IRC_NICK_SET_FLAG(nick, set, flag) \
|
||||
if (set) \
|
||||
@@ -79,6 +79,8 @@ extern void irc_nick_set_away (struct t_irc_channel *channel,
|
||||
struct t_irc_nick *nick, int is_away);
|
||||
extern char *irc_nick_as_prefix (struct t_irc_nick *nick, const char *nickname,
|
||||
const char *force_color);
|
||||
extern int irc_nick_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_irc_nick *nick);
|
||||
extern void irc_nick_print_log (struct t_irc_nick *nick);
|
||||
|
||||
#endif /* irc-nick.h */
|
||||
|
||||
@@ -300,11 +300,8 @@ irc_protocol_cmd_join (struct t_irc_server *server, const char *command,
|
||||
if (!ptr_channel->nicks)
|
||||
{
|
||||
if (ptr_channel->topic)
|
||||
{
|
||||
free (ptr_channel->topic);
|
||||
ptr_channel->topic = NULL;
|
||||
weechat_buffer_set (ptr_channel->buffer, "title", NULL);
|
||||
}
|
||||
irc_channel_set_topic (ptr_channel, NULL);
|
||||
|
||||
ptr_channel->display_creation_date = 1;
|
||||
}
|
||||
|
||||
@@ -758,11 +755,7 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command,
|
||||
}
|
||||
}
|
||||
if (!ptr_channel->topic)
|
||||
{
|
||||
ptr_channel->topic = strdup ((host) ? host : "");
|
||||
weechat_buffer_set (ptr_channel->buffer,
|
||||
"title", ptr_channel->topic);
|
||||
}
|
||||
irc_channel_set_topic (ptr_channel, host);
|
||||
|
||||
weechat_printf_tags (ptr_channel->buffer,
|
||||
tags,
|
||||
@@ -1058,8 +1051,8 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command,
|
||||
{
|
||||
char *nick, *host, *pos_args, *pos_end_01, *pos, *pos_message;
|
||||
char *dcc_args, *pos_file, *pos_addr, *pos_port, *pos_size, *pos_start_resume; /* for DCC */
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_plugin_infolist_item *item;
|
||||
struct t_infolist *infolist;
|
||||
struct t_infolist_item *item;
|
||||
char plugin_id[128];
|
||||
struct t_irc_channel *ptr_channel;
|
||||
struct t_irc_nick *ptr_nick;
|
||||
@@ -1770,12 +1763,8 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command,
|
||||
}
|
||||
}
|
||||
if (!ptr_channel->topic)
|
||||
{
|
||||
ptr_channel->topic = strdup (host);
|
||||
weechat_buffer_set (ptr_channel->buffer,
|
||||
"title", ptr_channel->topic);
|
||||
}
|
||||
|
||||
irc_channel_set_topic (ptr_channel, host);
|
||||
|
||||
pos_args += 8;
|
||||
pos_end_01 = strchr (pos, '\01');
|
||||
if (pos_end_01)
|
||||
@@ -1877,11 +1866,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command,
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
}
|
||||
if (ptr_channel->topic)
|
||||
free (ptr_channel->topic);
|
||||
ptr_channel->topic = strdup (host);
|
||||
weechat_buffer_set (ptr_channel->buffer, "title",
|
||||
ptr_channel->topic);
|
||||
irc_channel_set_topic (ptr_channel, host);
|
||||
|
||||
weechat_printf_tags (ptr_channel->buffer,
|
||||
"irc_privmsg,notify_private",
|
||||
@@ -2112,15 +2097,7 @@ irc_protocol_cmd_topic (struct t_irc_server *server, const char *command,
|
||||
}
|
||||
|
||||
if (ptr_channel)
|
||||
{
|
||||
if (ptr_channel->topic)
|
||||
free (ptr_channel->topic);
|
||||
if (pos_topic)
|
||||
ptr_channel->topic = strdup (pos_topic);
|
||||
else
|
||||
ptr_channel->topic = strdup ("");
|
||||
weechat_buffer_set (ptr_channel->buffer, "title", ptr_channel->topic);
|
||||
}
|
||||
irc_channel_set_topic (ptr_channel, pos_topic);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
@@ -3022,12 +2999,7 @@ irc_protocol_cmd_332 (struct t_irc_server *server, const char *command,
|
||||
ptr_channel = irc_channel_search (server, argv[3]);
|
||||
|
||||
if (ptr_channel && ptr_channel->nicks)
|
||||
{
|
||||
if (ptr_channel->topic)
|
||||
free (ptr_channel->topic);
|
||||
ptr_channel->topic = strdup (pos_topic);
|
||||
weechat_buffer_set (ptr_channel->buffer, "title", ptr_channel->topic);
|
||||
}
|
||||
irc_channel_set_topic (ptr_channel, pos_topic);
|
||||
|
||||
weechat_printf_tags ((ptr_channel && ptr_channel->nicks) ?
|
||||
ptr_channel->buffer : server->buffer,
|
||||
@@ -3567,7 +3539,7 @@ irc_protocol_cmd_366 (struct t_irc_server *server, const char *command,
|
||||
int argc, char **argv, char **argv_eol)
|
||||
{
|
||||
struct t_irc_channel *ptr_channel;
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_infolist *infolist;
|
||||
struct t_config_option *ptr_option;
|
||||
int num_nicks, num_op, num_halfop, num_voice, num_normal, length, i;
|
||||
char *string, *prefix;
|
||||
|
||||
+108
-11
@@ -227,14 +227,14 @@ irc_server_set_nick (struct t_irc_server *server, const char *nick)
|
||||
free (server->nick);
|
||||
server->nick = (nick) ? strdup (nick) : NULL;
|
||||
|
||||
weechat_buffer_set (server->buffer, "nick", nick);
|
||||
weechat_buffer_set (server->buffer, "nick", (void *)nick);
|
||||
|
||||
weechat_buffer_set (server->buffer, "highlight_words", nick);
|
||||
weechat_buffer_set (server->buffer, "highlight_words", (void *)nick);
|
||||
|
||||
for (ptr_channel = server->channels; ptr_channel;
|
||||
ptr_channel = ptr_channel->next_channel)
|
||||
{
|
||||
weechat_buffer_set (ptr_channel->buffer, "nick", nick);
|
||||
weechat_buffer_set (ptr_channel->buffer, "nick", (void *)nick);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -770,7 +770,7 @@ irc_server_rename (struct t_irc_server *server, const char *new_name)
|
||||
{
|
||||
int length;
|
||||
char *option_name, *name, *pos_option;
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_infolist *infolist;
|
||||
struct t_config_option *ptr_option;
|
||||
|
||||
/* check if another server exists with this name */
|
||||
@@ -1765,7 +1765,7 @@ irc_server_connect_cb (void *arg_server, int status)
|
||||
irc_server_login (server);
|
||||
server->hook_fd = weechat_hook_fd (server->sock,
|
||||
1, 0, 0,
|
||||
irc_server_recv_cb,
|
||||
&irc_server_recv_cb,
|
||||
server);
|
||||
break;
|
||||
case WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND:
|
||||
@@ -2353,7 +2353,7 @@ int
|
||||
irc_server_xfer_send_ready_cb (void *data, const char *signal,
|
||||
const char *type_data, void *signal_data)
|
||||
{
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_infolist *infolist;
|
||||
struct t_irc_server *server, *ptr_server;
|
||||
char *plugin_name, *plugin_id, *type, *filename;
|
||||
int spaces_in_name;
|
||||
@@ -2363,7 +2363,7 @@ irc_server_xfer_send_ready_cb (void *data, const char *signal,
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
|
||||
infolist = (struct t_plugin_infolist *)signal_data;
|
||||
infolist = (struct t_infolist *)signal_data;
|
||||
|
||||
if (weechat_infolist_next (infolist))
|
||||
{
|
||||
@@ -2426,7 +2426,7 @@ int
|
||||
irc_server_xfer_resume_ready_cb (void *data, const char *signal,
|
||||
const char *type_data, void *signal_data)
|
||||
{
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_infolist *infolist;
|
||||
struct t_irc_server *server, *ptr_server;
|
||||
char *plugin_name, *plugin_id, *filename;
|
||||
int spaces_in_name;
|
||||
@@ -2436,7 +2436,7 @@ irc_server_xfer_resume_ready_cb (void *data, const char *signal,
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
|
||||
infolist = (struct t_plugin_infolist *)signal_data;
|
||||
infolist = (struct t_infolist *)signal_data;
|
||||
|
||||
if (weechat_infolist_next (infolist))
|
||||
{
|
||||
@@ -2483,7 +2483,7 @@ irc_server_xfer_send_accept_resume_cb (void *data, const char *signal,
|
||||
const char *type_data,
|
||||
void *signal_data)
|
||||
{
|
||||
struct t_plugin_infolist *infolist;
|
||||
struct t_infolist *infolist;
|
||||
struct t_irc_server *server, *ptr_server;
|
||||
char *plugin_name, *plugin_id, *filename;
|
||||
int spaces_in_name;
|
||||
@@ -2493,7 +2493,7 @@ irc_server_xfer_send_accept_resume_cb (void *data, const char *signal,
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
|
||||
infolist = (struct t_plugin_infolist *)signal_data;
|
||||
infolist = (struct t_infolist *)signal_data;
|
||||
|
||||
if (weechat_infolist_next (infolist))
|
||||
{
|
||||
@@ -2527,6 +2527,103 @@ irc_server_xfer_send_accept_resume_cb (void *data, const char *signal,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_server_add_to_infolist: add a server in an infolist
|
||||
* return 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
int
|
||||
irc_server_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_irc_server *server)
|
||||
{
|
||||
struct t_infolist_item *ptr_item;
|
||||
|
||||
if (!infolist || !server)
|
||||
return 0;
|
||||
|
||||
ptr_item = weechat_infolist_new_item (infolist);
|
||||
if (!ptr_item)
|
||||
return 0;
|
||||
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "name", server->name))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "autoconnect", server->autoconnect))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect", server->autoreconnect))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "autoreconnect_delay", server->autoreconnect_delay))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "temp_server", server->temp_server))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "addresses", server->addresses))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "ipv6", server->ipv6))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "ssl", server->ssl))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "password", server->password))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "nicks", server->nicks))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "username", server->username))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "realname", server->realname))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "local_hostname", server->local_hostname))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "command", server->command))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "command_delay", server->command_delay))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "autojoin", server->autojoin))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "autorejoin", server->autorejoin))
|
||||
return 0;
|
||||
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "current_address", server->current_address))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "sock", server->sock))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "is_connected", server->is_connected))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "ssl_connected", server->ssl_connected))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "unterminated_message", server->unterminated_message))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "nick", server->nick))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "nick_modes", server->nick_modes))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "prefix", server->prefix))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_time (ptr_item, "reconnect_start", server->reconnect_start))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_time (ptr_item, "command_time", server->command_time))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "reconnect_join", server->reconnect_join))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "disable_autojoin", server->disable_autojoin))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "is_away", server->is_away))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "away_message", server->away_message))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_time (ptr_item, "away_time", server->away_time))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "lag", server->lag))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_buffer (ptr_item, "lag_check_time", &(server->lag_check_time), sizeof (struct timeval)))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_time (ptr_item, "lag_next_check", server->lag_next_check))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "queue_msg", server->queue_msg))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_time (ptr_item, "last_user_message", server->last_user_message))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_server_print_log: print server infos in log (usually for crash dump)
|
||||
*/
|
||||
|
||||
@@ -169,6 +169,7 @@ extern int irc_server_connect (struct t_irc_server *server,
|
||||
int disable_autojoin);
|
||||
extern void irc_server_auto_connect (int auto_connect, int temp_server);
|
||||
extern void irc_server_autojoin_channels ();
|
||||
extern int irc_server_recv_cb (void *arg_server);
|
||||
extern int irc_server_timer_cb (void *data);
|
||||
extern void irc_server_outqueue_free_all (struct t_irc_server *server);
|
||||
extern int irc_server_get_channel_count (struct t_irc_server *server);
|
||||
@@ -189,6 +190,8 @@ extern int irc_server_xfer_resume_ready_cb (void *data, const char *signal,
|
||||
extern int irc_server_xfer_send_accept_resume_cb (void *data, const char *signal,
|
||||
const char *type_data,
|
||||
void *signal_data);
|
||||
extern int irc_server_add_to_infolist (struct t_infolist *infolist,
|
||||
struct t_irc_server *server);
|
||||
extern void irc_server_print_log ();
|
||||
|
||||
#endif /* irc-server.h */
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* 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; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/* irc-upgrade.c: save/restore IRC plugin data */
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "irc.h"
|
||||
#include "irc-upgrade.h"
|
||||
#include "irc-buffer.h"
|
||||
#include "irc-input.h"
|
||||
#include "irc-server.h"
|
||||
#include "irc-channel.h"
|
||||
#include "irc-nick.h"
|
||||
|
||||
|
||||
struct t_irc_server *irc_upgrade_current_server = NULL;
|
||||
struct t_irc_channel *irc_upgrade_current_channel = NULL;
|
||||
|
||||
|
||||
/*
|
||||
* irc_upgrade_save_all_data: save servers/channels/nicks info to upgrade file
|
||||
*/
|
||||
|
||||
int
|
||||
irc_upgrade_save_all_data (struct t_upgrade_file *upgrade_file)
|
||||
{
|
||||
struct t_infolist *infolist;
|
||||
struct t_irc_server *ptr_server;
|
||||
struct t_irc_channel *ptr_channel;
|
||||
struct t_irc_nick *ptr_nick;
|
||||
int rc;
|
||||
|
||||
for (ptr_server = irc_servers; ptr_server;
|
||||
ptr_server = ptr_server->next_server)
|
||||
{
|
||||
/* save server */
|
||||
infolist = weechat_infolist_new ();
|
||||
if (!infolist)
|
||||
return 0;
|
||||
if (!irc_server_add_to_infolist (infolist, ptr_server))
|
||||
{
|
||||
weechat_infolist_free (infolist);
|
||||
return 0;
|
||||
}
|
||||
rc = weechat_upgrade_write_object (upgrade_file,
|
||||
IRC_UPGRADE_TYPE_SERVER,
|
||||
infolist);
|
||||
weechat_infolist_free (infolist);
|
||||
if (!rc)
|
||||
return 0;
|
||||
|
||||
for (ptr_channel = ptr_server->channels; ptr_channel;
|
||||
ptr_channel = ptr_channel->next_channel)
|
||||
{
|
||||
/* save channel */
|
||||
infolist = weechat_infolist_new ();
|
||||
if (!infolist)
|
||||
return 0;
|
||||
if (!irc_channel_add_to_infolist (infolist, ptr_channel))
|
||||
{
|
||||
weechat_infolist_free (infolist);
|
||||
return 0;
|
||||
}
|
||||
rc = weechat_upgrade_write_object (upgrade_file,
|
||||
IRC_UPGRADE_TYPE_CHANNEL,
|
||||
infolist);
|
||||
weechat_infolist_free (infolist);
|
||||
if (!rc)
|
||||
return 0;
|
||||
|
||||
for (ptr_nick = ptr_channel->nicks; ptr_nick;
|
||||
ptr_nick = ptr_nick->next_nick)
|
||||
{
|
||||
/* save nick */
|
||||
infolist = weechat_infolist_new ();
|
||||
if (!infolist)
|
||||
return 0;
|
||||
if (!irc_nick_add_to_infolist (infolist, ptr_nick))
|
||||
{
|
||||
weechat_infolist_free (infolist);
|
||||
return 0;
|
||||
}
|
||||
rc = weechat_upgrade_write_object (upgrade_file,
|
||||
IRC_UPGRADE_TYPE_NICK,
|
||||
infolist);
|
||||
weechat_infolist_free (infolist);
|
||||
if (!rc)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_upgrade_save: save upgrade file
|
||||
* return 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
int
|
||||
irc_upgrade_save ()
|
||||
{
|
||||
int rc;
|
||||
struct t_upgrade_file *upgrade_file;
|
||||
|
||||
upgrade_file = weechat_upgrade_create (IRC_UPGRADE_FILENAME, 1);
|
||||
if (!upgrade_file)
|
||||
return 0;
|
||||
|
||||
rc = irc_upgrade_save_all_data (upgrade_file);
|
||||
|
||||
weechat_upgrade_close (upgrade_file);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_upgrade_set_buffer_callbacks: restore buffers callbacks (input and
|
||||
* close) for buffers created by IRC plugin
|
||||
*/
|
||||
|
||||
void
|
||||
irc_upgrade_set_buffer_callbacks ()
|
||||
{
|
||||
struct t_infolist *infolist;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
|
||||
infolist = weechat_infolist_get ("buffer", NULL, NULL);
|
||||
if (infolist)
|
||||
{
|
||||
while (weechat_infolist_next (infolist))
|
||||
{
|
||||
if (weechat_infolist_pointer (infolist, "plugin") == weechat_irc_plugin)
|
||||
{
|
||||
ptr_buffer = weechat_infolist_pointer (infolist, "pointer");
|
||||
weechat_buffer_set (ptr_buffer, "close_callback", &irc_buffer_close_cb);
|
||||
weechat_buffer_set (ptr_buffer, "input_callback", &irc_input_data_cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_upgrade_read_cb: read callback for
|
||||
*/
|
||||
|
||||
int
|
||||
irc_upgrade_read_cb (int object_id,
|
||||
struct t_infolist *infolist)
|
||||
{
|
||||
int flags, sock, size;
|
||||
char *str, *buf;
|
||||
struct t_irc_nick *ptr_nick;
|
||||
|
||||
weechat_infolist_reset_item_cursor (infolist);
|
||||
while (weechat_infolist_next (infolist))
|
||||
{
|
||||
switch (object_id)
|
||||
{
|
||||
case IRC_UPGRADE_TYPE_SERVER:
|
||||
irc_upgrade_current_server = irc_server_search (weechat_infolist_string (infolist, "name"));
|
||||
if (irc_upgrade_current_server)
|
||||
{
|
||||
irc_upgrade_current_server->buffer = weechat_buffer_search (irc_upgrade_current_server->name,
|
||||
irc_upgrade_current_server->name);
|
||||
irc_upgrade_current_server->current_address = weechat_infolist_integer (infolist, "current_address");
|
||||
|
||||
sock = weechat_infolist_integer (infolist, "sock");
|
||||
if (sock >= 0)
|
||||
{
|
||||
irc_upgrade_current_server->sock = sock;
|
||||
irc_upgrade_current_server->hook_fd = weechat_hook_fd (irc_upgrade_current_server->sock,
|
||||
1, 0, 0,
|
||||
&irc_server_recv_cb,
|
||||
irc_upgrade_current_server);
|
||||
}
|
||||
irc_upgrade_current_server->is_connected = weechat_infolist_integer (infolist, "is_connected");
|
||||
irc_upgrade_current_server->ssl_connected = weechat_infolist_integer (infolist, "ssl_connected");
|
||||
str = weechat_infolist_string (infolist, "unterminated_message");
|
||||
if (str)
|
||||
irc_upgrade_current_server->unterminated_message = strdup (str);
|
||||
str = weechat_infolist_string (infolist, "nick");
|
||||
if (str)
|
||||
irc_server_set_nick (irc_upgrade_current_server, str);
|
||||
str = weechat_infolist_string (infolist, "nick_modes");
|
||||
if (str)
|
||||
irc_upgrade_current_server->nick_modes = strdup (str);
|
||||
str = weechat_infolist_string (infolist, "prefix");
|
||||
if (str)
|
||||
irc_upgrade_current_server->prefix = strdup (str);
|
||||
irc_upgrade_current_server->reconnect_start = weechat_infolist_time (infolist, "reconnect_start");
|
||||
irc_upgrade_current_server->command_time = weechat_infolist_time (infolist, "command_time");
|
||||
irc_upgrade_current_server->reconnect_join = weechat_infolist_integer (infolist, "reconnect_join");
|
||||
irc_upgrade_current_server->disable_autojoin = weechat_infolist_integer (infolist, "disable_autojoin");
|
||||
irc_upgrade_current_server->is_away = weechat_infolist_integer (infolist, "is_away");
|
||||
str = weechat_infolist_string (infolist, "away_message");
|
||||
if (str)
|
||||
irc_upgrade_current_server->away_message = strdup (str);
|
||||
irc_upgrade_current_server->away_time = weechat_infolist_time (infolist, "away_time");
|
||||
irc_upgrade_current_server->lag = weechat_infolist_integer (infolist, "lag");
|
||||
buf = weechat_infolist_buffer (infolist, "lag_check_time", &size);
|
||||
if (buf)
|
||||
memcpy (&(irc_upgrade_current_server->lag_check_time), buf, size);
|
||||
irc_upgrade_current_server->lag_next_check = weechat_infolist_time (infolist, "lag_next_check");
|
||||
irc_upgrade_current_server->queue_msg = weechat_infolist_integer (infolist, "queue_msg");
|
||||
irc_upgrade_current_server->last_user_message = weechat_infolist_time (infolist, "last_user_message");
|
||||
}
|
||||
break;
|
||||
case IRC_UPGRADE_TYPE_CHANNEL:
|
||||
if (irc_upgrade_current_server)
|
||||
{
|
||||
irc_upgrade_current_channel = irc_channel_new (irc_upgrade_current_server,
|
||||
weechat_infolist_integer (infolist, "type"),
|
||||
weechat_infolist_string (infolist, "name"),
|
||||
0);
|
||||
if (irc_upgrade_current_channel)
|
||||
{
|
||||
str = weechat_infolist_string (infolist, "topic");
|
||||
if (str)
|
||||
irc_channel_set_topic (irc_upgrade_current_channel, str);
|
||||
str = weechat_infolist_string (infolist, "modes");
|
||||
if (str)
|
||||
irc_upgrade_current_channel->modes = strdup (str);
|
||||
irc_upgrade_current_channel->limit = weechat_infolist_integer (infolist, "limit");
|
||||
str = weechat_infolist_string (infolist, "key");
|
||||
if (str)
|
||||
irc_upgrade_current_channel->key = strdup (str);
|
||||
irc_upgrade_current_channel->checking_away = weechat_infolist_integer (infolist, "checking_away");
|
||||
str = weechat_infolist_string (infolist, "away_message");
|
||||
if (str)
|
||||
irc_upgrade_current_channel->away_message = strdup (str);
|
||||
irc_upgrade_current_channel->cycle = weechat_infolist_integer (infolist, "cycle");
|
||||
irc_upgrade_current_channel->display_creation_date = weechat_infolist_integer (infolist, "display_creation_date");
|
||||
irc_upgrade_current_channel->nick_completion_reset = weechat_infolist_integer (infolist, "nick_completion_reset");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IRC_UPGRADE_TYPE_NICK:
|
||||
if (irc_upgrade_current_server && irc_upgrade_current_channel)
|
||||
{
|
||||
flags = weechat_infolist_integer (infolist, "flags");
|
||||
ptr_nick = irc_nick_new (irc_upgrade_current_server,
|
||||
irc_upgrade_current_channel,
|
||||
weechat_infolist_string (infolist, "name"),
|
||||
flags & IRC_NICK_CHANOWNER,
|
||||
flags & IRC_NICK_CHANADMIN,
|
||||
flags & IRC_NICK_CHANADMIN2,
|
||||
flags & IRC_NICK_OP,
|
||||
flags & IRC_NICK_HALFOP,
|
||||
flags & IRC_NICK_VOICE,
|
||||
flags & IRC_NICK_CHANUSER);
|
||||
if (ptr_nick)
|
||||
{
|
||||
str = weechat_infolist_string (infolist, "host");
|
||||
if (str)
|
||||
ptr_nick->host = strdup (str);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_upgrade_load: load upgrade file
|
||||
* return 1 if ok, 0 if error
|
||||
*/
|
||||
|
||||
int
|
||||
irc_upgrade_load ()
|
||||
{
|
||||
int rc;
|
||||
struct t_upgrade_file *upgrade_file;
|
||||
|
||||
irc_upgrade_set_buffer_callbacks ();
|
||||
|
||||
upgrade_file = weechat_upgrade_create (IRC_UPGRADE_FILENAME, 0);
|
||||
rc = weechat_upgrade_read (upgrade_file, &irc_upgrade_read_cb);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
|
||||
* See README for License detail, AUTHORS for developers list.
|
||||
*
|
||||
* 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; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 __WEECHAT_IRC_UPGRADE_H
|
||||
#define __WEECHAT_IRC_UPGRADE_H 1
|
||||
|
||||
#define IRC_UPGRADE_FILENAME "irc"
|
||||
|
||||
/* For developers: please add new values ONLY AT THE END of enums */
|
||||
|
||||
enum t_irc_upgrade_type
|
||||
{
|
||||
IRC_UPGRADE_TYPE_SERVER = 0,
|
||||
IRC_UPGRADE_TYPE_CHANNEL,
|
||||
IRC_UPGRADE_TYPE_NICK,
|
||||
};
|
||||
|
||||
extern int irc_upgrade_save ();
|
||||
extern int irc_upgrade_load ();
|
||||
|
||||
#endif /* irc-upgrade.h */
|
||||
+39
-4
@@ -31,6 +31,7 @@
|
||||
#include "irc-server.h"
|
||||
#include "irc-channel.h"
|
||||
#include "irc-nick.h"
|
||||
#include "irc-upgrade.h"
|
||||
|
||||
|
||||
WEECHAT_PLUGIN_NAME("irc");
|
||||
@@ -45,6 +46,8 @@ struct t_weechat_plugin *weechat_irc_plugin = NULL;
|
||||
struct t_hook *irc_hook_timer = NULL;
|
||||
struct t_hook *irc_hook_timer_check_away = NULL;
|
||||
|
||||
int irc_signal_upgrade_received = 0; /* signal "upgrade" received ? */
|
||||
|
||||
|
||||
/*
|
||||
* irc_signal_quit_cb: callback for "quit" signal
|
||||
@@ -73,6 +76,25 @@ irc_signal_quit_cb (void *data, const char *signal, const char *type_data,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_signal_upgrade_cb: callback for "upgrade" signal
|
||||
*/
|
||||
|
||||
int
|
||||
irc_signal_upgrade_cb (void *data, const char *signal, const char *type_data,
|
||||
void *signal_data)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) signal;
|
||||
(void) type_data;
|
||||
(void) signal_data;
|
||||
|
||||
irc_signal_upgrade_received = 1;
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_plugin_init: initialize IRC plugin
|
||||
*/
|
||||
@@ -80,7 +102,7 @@ irc_signal_quit_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, auto_connect;
|
||||
int i, auto_connect, upgrading;
|
||||
|
||||
weechat_plugin = plugin;
|
||||
|
||||
@@ -95,6 +117,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
/* hook some signals */
|
||||
irc_debug_init ();
|
||||
weechat_hook_signal ("quit", &irc_signal_quit_cb, NULL);
|
||||
weechat_hook_signal ("upgrade", &irc_signal_upgrade_cb, NULL);
|
||||
weechat_hook_signal ("xfer_send_ready", &irc_server_xfer_send_ready_cb, NULL);
|
||||
weechat_hook_signal ("xfer_resume_ready", &irc_server_xfer_resume_ready_cb, NULL);
|
||||
weechat_hook_signal ("xfer_send_accept_resume", &irc_server_xfer_send_accept_resume_cb, NULL);
|
||||
@@ -104,6 +127,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
|
||||
/* look at arguments */
|
||||
auto_connect = 1;
|
||||
upgrading = 0;
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
if ((weechat_strcasecmp (argv[i], "-a") == 0)
|
||||
@@ -122,9 +146,16 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
argv[i]);
|
||||
}
|
||||
}
|
||||
else if (weechat_strcasecmp (argv[i], "--upgrade") == 0)
|
||||
{
|
||||
upgrading = 1;
|
||||
}
|
||||
}
|
||||
|
||||
irc_server_auto_connect (auto_connect, 0);
|
||||
|
||||
if (upgrading)
|
||||
irc_upgrade_load ();
|
||||
else
|
||||
irc_server_auto_connect (auto_connect, 0);
|
||||
|
||||
irc_hook_timer = weechat_hook_timer (1 * 1000, 0, 0,
|
||||
&irc_server_timer_cb, NULL);
|
||||
@@ -152,7 +183,11 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
|
||||
|
||||
irc_config_write ();
|
||||
|
||||
irc_server_disconnect_all ();
|
||||
if (irc_signal_upgrade_received)
|
||||
irc_upgrade_save ();
|
||||
else
|
||||
irc_server_disconnect_all ();
|
||||
|
||||
irc_server_free_all ();
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
Reference in New Issue
Block a user