mirror of
https://github.com/weechat/weechat.git
synced 2026-06-12 14:14:48 +02:00
Added config_reload event for IRC plugin
This commit is contained in:
@@ -827,10 +827,13 @@ config_file_reload (struct t_config_file *config_file)
|
||||
for (ptr_section = config_file->sections; ptr_section;
|
||||
ptr_section = ptr_section->next_section)
|
||||
{
|
||||
for (ptr_option = ptr_section->options; ptr_option;
|
||||
ptr_option = ptr_option->next_option)
|
||||
if (!ptr_section->callback_read)
|
||||
{
|
||||
ptr_option->loaded = 0;
|
||||
for (ptr_option = ptr_section->options; ptr_option;
|
||||
ptr_option = ptr_option->next_option)
|
||||
{
|
||||
ptr_option->loaded = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -841,15 +844,18 @@ config_file_reload (struct t_config_file *config_file)
|
||||
for (ptr_section = config_file->sections; ptr_section;
|
||||
ptr_section = ptr_section->next_section)
|
||||
{
|
||||
for (ptr_option = ptr_section->options; ptr_option;
|
||||
ptr_option = ptr_option->next_option)
|
||||
if (!ptr_section->callback_read)
|
||||
{
|
||||
if (!ptr_option->loaded)
|
||||
for (ptr_option = ptr_section->options; ptr_option;
|
||||
ptr_option = ptr_option->next_option)
|
||||
{
|
||||
if (config_file_option_reset (ptr_option) == 2)
|
||||
if (!ptr_option->loaded)
|
||||
{
|
||||
if (ptr_option->callback_change)
|
||||
(void) (ptr_option->callback_change) ();
|
||||
if (config_file_option_reset (ptr_option) == 2)
|
||||
{
|
||||
if (ptr_option->callback_change)
|
||||
(void) (ptr_option->callback_change) ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -327,7 +327,7 @@ weechat_parse_args (int argc, char *argv[])
|
||||
_("Warning: unable to create server "
|
||||
"('%s'), ignored\n"),
|
||||
argv[i]);
|
||||
irc_server_destroy (&server_tmp);
|
||||
irc_server_free_data (&server_tmp);
|
||||
server_cmd_line = 1;
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -106,6 +106,7 @@ struct t_config_option *irc_config_server_autorejoin;
|
||||
struct t_config_option *irc_config_server_notify_levels;
|
||||
|
||||
struct t_irc_server *irc_config_server = NULL;
|
||||
int irc_config_reload_flag;
|
||||
|
||||
|
||||
/*
|
||||
@@ -260,7 +261,8 @@ irc_config_read_server_line (void *config_file, char *option_name, char *value)
|
||||
if (irc_config_server)
|
||||
{
|
||||
irc_server_init_with_config_options (irc_config_server,
|
||||
irc_config_section_server);
|
||||
irc_config_section_server,
|
||||
irc_config_reload_flag);
|
||||
}
|
||||
irc_config_server = irc_server_alloc ();
|
||||
if (!irc_config_server)
|
||||
@@ -710,27 +712,80 @@ irc_config_read ()
|
||||
int rc;
|
||||
|
||||
irc_config_server = NULL;
|
||||
|
||||
irc_config_reload_flag = 0;
|
||||
|
||||
rc = weechat_config_read (irc_config_file);
|
||||
|
||||
if (irc_config_server)
|
||||
irc_server_init_with_config_options (irc_config_server,
|
||||
irc_config_section_server);
|
||||
irc_config_section_server,
|
||||
irc_config_reload_flag);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_reload: read IRC configuration file
|
||||
* return: 0 = successful
|
||||
* -1 = configuration file file not found
|
||||
* -2 = error in configuration file
|
||||
*/
|
||||
|
||||
int
|
||||
irc_config_reload ()
|
||||
{
|
||||
return weechat_config_reload (irc_config_file);
|
||||
struct t_irc_server *ptr_server, *next_server;
|
||||
int rc;
|
||||
|
||||
irc_config_server = NULL;
|
||||
irc_config_reload_flag = 1;
|
||||
for (ptr_server = irc_servers; ptr_server;
|
||||
ptr_server = ptr_server->next_server)
|
||||
{
|
||||
ptr_server->reloaded_from_config = 0;
|
||||
}
|
||||
|
||||
rc = weechat_config_reload (irc_config_file);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
|
||||
if (irc_config_server)
|
||||
irc_server_init_with_config_options (irc_config_server,
|
||||
irc_config_section_server,
|
||||
irc_config_reload_flag);
|
||||
|
||||
ptr_server = irc_servers;
|
||||
while (ptr_server)
|
||||
{
|
||||
next_server = ptr_server->next_server;
|
||||
|
||||
if (!ptr_server->reloaded_from_config)
|
||||
{
|
||||
if (ptr_server->is_connected)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%sIrc: warning: server \"%s\" not found in "
|
||||
"configuration file, but was not deleted "
|
||||
"(currently used)"),
|
||||
weechat_prefix ("info"),
|
||||
ptr_server->name);
|
||||
}
|
||||
else
|
||||
irc_server_free (ptr_server);
|
||||
}
|
||||
|
||||
ptr_server = next_server;
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
_("%sIrc configuration file reloaded"),
|
||||
weechat_prefix ("info"));
|
||||
return PLUGIN_RC_SUCCESS;
|
||||
}
|
||||
|
||||
weechat_printf (NULL,
|
||||
_("%sIrc: failed to reload alias configuration "
|
||||
"file"),
|
||||
weechat_prefix ("error"));
|
||||
return PLUGIN_RC_FAILED;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -100,6 +100,7 @@ irc_server_init (struct t_irc_server *server)
|
||||
server->notify_levels = NULL;
|
||||
|
||||
/* internal vars */
|
||||
server->reloaded_from_config = 0;
|
||||
server->child_pid = 0;
|
||||
server->child_read = -1;
|
||||
server->child_write = -1;
|
||||
@@ -264,89 +265,151 @@ irc_server_init_with_url (struct t_irc_server *server, char *irc_url)
|
||||
|
||||
void
|
||||
irc_server_init_with_config_options (struct t_irc_server *server,
|
||||
void *section)
|
||||
void *section,
|
||||
int config_reload)
|
||||
{
|
||||
struct t_config_option *ptr_option;
|
||||
struct t_irc_server *ptr_server;
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_name");
|
||||
if (ptr_option)
|
||||
server->name = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
if (!ptr_option)
|
||||
{
|
||||
irc_server_free (server);
|
||||
return;
|
||||
}
|
||||
|
||||
if (config_reload)
|
||||
{
|
||||
for (ptr_server = irc_servers; ptr_server;
|
||||
ptr_server = ptr_server->next_server)
|
||||
{
|
||||
if ((ptr_server != server)
|
||||
&& (strcmp (ptr_server->name,
|
||||
weechat_config_string (ptr_option)) == 0))
|
||||
break;
|
||||
}
|
||||
if (ptr_server)
|
||||
irc_server_free (server);
|
||||
else
|
||||
ptr_server = server;
|
||||
}
|
||||
else
|
||||
ptr_server = server;
|
||||
|
||||
if (ptr_server->name)
|
||||
free (ptr_server->name);
|
||||
ptr_server->name = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_autoconnect");
|
||||
if (ptr_option)
|
||||
server->autoconnect = weechat_config_integer (ptr_option);
|
||||
ptr_server->autoconnect = weechat_config_integer (ptr_option);
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_autoreconnect");
|
||||
if (ptr_option)
|
||||
server->autoreconnect = weechat_config_integer (ptr_option);
|
||||
ptr_server->autoreconnect = weechat_config_integer (ptr_option);
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_autoreconnect_delay");
|
||||
if (ptr_option)
|
||||
server->autoreconnect_delay = weechat_config_integer (ptr_option);
|
||||
ptr_server->autoreconnect_delay = weechat_config_integer (ptr_option);
|
||||
|
||||
if (ptr_server->address)
|
||||
free (ptr_server->address);
|
||||
ptr_server->address = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_address");
|
||||
if (ptr_option)
|
||||
server->address = strdup (weechat_config_string (ptr_option));
|
||||
ptr_server->address = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_port");
|
||||
if (ptr_option)
|
||||
server->port = weechat_config_integer (ptr_option);
|
||||
ptr_server->port = weechat_config_integer (ptr_option);
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_ipv6");
|
||||
if (ptr_option)
|
||||
server->ipv6 = weechat_config_integer (ptr_option);
|
||||
ptr_server->ipv6 = weechat_config_integer (ptr_option);
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_ssl");
|
||||
if (ptr_option)
|
||||
server->ssl = weechat_config_integer (ptr_option);
|
||||
ptr_server->ssl = weechat_config_integer (ptr_option);
|
||||
|
||||
if (ptr_server->password)
|
||||
free (ptr_server->password);
|
||||
ptr_server->password = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_password");
|
||||
if (ptr_option)
|
||||
server->password = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_server->password = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
if (ptr_server->nick1)
|
||||
free (ptr_server->nick1);
|
||||
ptr_server->nick1 = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_nick1");
|
||||
if (ptr_option)
|
||||
server->nick1 = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_server->nick1 = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
if (ptr_server->nick2)
|
||||
free (ptr_server->nick2);
|
||||
ptr_server->nick2 = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_nick2");
|
||||
if (ptr_option)
|
||||
server->nick2 = strdup (weechat_config_string (ptr_option));
|
||||
ptr_server->nick2 = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
if (ptr_server->nick3)
|
||||
free (ptr_server->nick3);
|
||||
ptr_server->nick3 = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_nick3");
|
||||
if (ptr_option)
|
||||
server->nick3 = strdup (weechat_config_string (ptr_option));
|
||||
ptr_server->nick3 = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
if (ptr_server->username)
|
||||
free (ptr_server->username);
|
||||
ptr_server->username = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_username");
|
||||
if (ptr_option)
|
||||
server->username = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_server->username = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
if (ptr_server->realname)
|
||||
free (ptr_server->realname);
|
||||
ptr_server->realname = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_realname");
|
||||
if (ptr_option)
|
||||
server->realname = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_server->realname = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
if (ptr_server->hostname)
|
||||
free (ptr_server->hostname);
|
||||
ptr_server->hostname = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_hostname");
|
||||
if (ptr_option)
|
||||
server->hostname = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_server->hostname = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
if (ptr_server->command)
|
||||
free (ptr_server->command);
|
||||
ptr_server->command = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_command");
|
||||
if (ptr_option)
|
||||
server->command = strdup (weechat_config_string (ptr_option));
|
||||
ptr_server->command = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_command_delay");
|
||||
if (ptr_option)
|
||||
server->command_delay = weechat_config_integer (ptr_option);
|
||||
ptr_server->command_delay = weechat_config_integer (ptr_option);
|
||||
|
||||
if (ptr_server->autojoin)
|
||||
free (ptr_server->autojoin);
|
||||
ptr_server->autojoin = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_autojoin");
|
||||
if (ptr_option)
|
||||
server->autojoin = strdup (weechat_config_string (ptr_option));
|
||||
ptr_server->autojoin = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_autorejoin");
|
||||
if (ptr_option)
|
||||
server->autorejoin = weechat_config_integer (ptr_option);
|
||||
ptr_server->autorejoin = weechat_config_integer (ptr_option);
|
||||
|
||||
if (ptr_server->notify_levels)
|
||||
free (ptr_server->notify_levels);
|
||||
ptr_server->notify_levels = NULL;
|
||||
ptr_option = weechat_config_search_option (NULL, section, "server_notify_levels");
|
||||
if (ptr_option)
|
||||
server->notify_levels = strdup (weechat_config_string (ptr_option));
|
||||
ptr_server->notify_levels = strdup (weechat_config_string (ptr_option));
|
||||
|
||||
ptr_server->reloaded_from_config = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -454,11 +517,11 @@ irc_server_outqueue_free_all (struct t_irc_server *server)
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_server_destroy: free server data (not struct himself)
|
||||
* irc_server_free_data: free server data
|
||||
*/
|
||||
|
||||
void
|
||||
irc_server_destroy (struct t_irc_server *server)
|
||||
irc_server_free_data (struct t_irc_server *server)
|
||||
{
|
||||
if (!server)
|
||||
return;
|
||||
@@ -534,7 +597,7 @@ irc_server_free (struct t_irc_server *server)
|
||||
if (server->next_server)
|
||||
(server->next_server)->prev_server = server->prev_server;
|
||||
|
||||
irc_server_destroy (server);
|
||||
irc_server_free_data (server);
|
||||
free (server);
|
||||
irc_servers = new_irc_servers;
|
||||
}
|
||||
@@ -2686,6 +2749,7 @@ irc_server_print_log ()
|
||||
weechat_log_printf (" autojoin. . . . . . : '%s'", ptr_server->autojoin);
|
||||
weechat_log_printf (" autorejoin. . . . . : %d", ptr_server->autorejoin);
|
||||
weechat_log_printf (" notify_levels . . . : %s", ptr_server->notify_levels);
|
||||
weechat_log_printf (" reloaded_from_config: %d", ptr_server->reloaded_from_config);
|
||||
weechat_log_printf (" child_pid . . . . . : %d", ptr_server->child_pid);
|
||||
weechat_log_printf (" child_read . . . . : %d", ptr_server->child_read);
|
||||
weechat_log_printf (" child_write . . . . : %d", ptr_server->child_write);
|
||||
|
||||
@@ -78,6 +78,7 @@ struct t_irc_server
|
||||
char *notify_levels; /* channels notify levels */
|
||||
|
||||
/* internal vars */
|
||||
int reloaded_from_config; /* 1 if reloaded from config file */
|
||||
pid_t child_pid; /* pid of child process (connecting) */
|
||||
int child_read; /* to read into child pipe */
|
||||
int child_write; /* to write into child pipe */
|
||||
@@ -133,15 +134,18 @@ extern struct t_irc_message *irc_recv_msgq, *irc_msgq_last_msg;
|
||||
|
||||
extern void irc_server_init (struct t_irc_server *);
|
||||
extern int irc_server_init_with_url (struct t_irc_server *, char *);
|
||||
extern void irc_server_init_with_config_options (struct t_irc_server *, void *);
|
||||
extern void irc_server_init_with_config_options (struct t_irc_server *, void *,
|
||||
int);
|
||||
extern struct t_irc_server *irc_server_alloc ();
|
||||
extern void irc_server_outqueue_free_all (struct t_irc_server *);
|
||||
extern void irc_server_destroy (struct t_irc_server *);
|
||||
extern void irc_server_free_data (struct t_irc_server *);
|
||||
extern void irc_server_free (struct t_irc_server *);
|
||||
extern void irc_server_free_all ();
|
||||
extern struct t_irc_server *irc_server_new (char *, int, int, int, int, char *, int, int, int,
|
||||
char *, char *, char *, char *, char *, char *,
|
||||
char *, char *, int, char *, int, char *);
|
||||
extern struct t_irc_server *irc_server_new (char *, int, int, int, int, char *,
|
||||
int, int, int, char *, char *,
|
||||
char *, char *, char *, char *,
|
||||
char *, char *, int, char *, int,
|
||||
char *);
|
||||
extern struct t_irc_server *irc_server_duplicate (struct t_irc_server *, char *);
|
||||
extern int irc_server_rename (struct t_irc_server *, char *);
|
||||
extern int irc_server_send (struct t_irc_server *, char *, int);
|
||||
|
||||
@@ -135,6 +135,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
|
||||
return PLUGIN_RC_FAILED;
|
||||
|
||||
irc_create_directories ();
|
||||
|
||||
weechat_hook_event ("config_reload", irc_config_reload, NULL);
|
||||
|
||||
//irc_server_auto_connect (1, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user