1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-10 19:53:13 +02:00

Added config file functions in plugins API, improved /reload and /save commands (now possible to reload/save some files only), fixed completion bug

This commit is contained in:
Sebastien Helleu
2008-01-27 10:48:29 +01:00
parent ed26a0389c
commit ad41486543
30 changed files with 4687 additions and 4118 deletions
+21 -9
View File
@@ -420,9 +420,10 @@ alias_free_all ()
*/
int
alias_config_reload (struct t_config_file *config_file)
alias_config_reload (void *data, struct t_config_file *config_file)
{
/* make C compiler happy */
(void) data;
(void) config_file;
alias_free_all ();
@@ -434,10 +435,11 @@ alias_config_reload (struct t_config_file *config_file)
*/
void
alias_config_read_line (struct t_config_file *config_file, char *option_name,
char *value)
alias_config_read_line (void *data, struct t_config_file *config_file,
char *option_name, char *value)
{
/* make C compiler happy */
(void) data;
(void) config_file;
if (option_name && value)
@@ -460,11 +462,14 @@ alias_config_read_line (struct t_config_file *config_file, char *option_name,
*/
void
alias_config_write_section (struct t_config_file *config_file,
alias_config_write_section (void *data, struct t_config_file *config_file,
char *section_name)
{
struct t_alias *ptr_alias;
/* make C compiler happy */
(void) data;
weechat_config_write_line (config_file, section_name, NULL);
for (ptr_alias = alias_list; ptr_alias;
@@ -482,9 +487,13 @@ alias_config_write_section (struct t_config_file *config_file,
*/
void
alias_config_write_default_aliases (struct t_config_file *config_file,
alias_config_write_default_aliases (void *data,
struct t_config_file *config_file,
char *section_name)
{
/* make C compiler happy */
(void) data;
weechat_config_write_line (config_file, section_name, NULL);
weechat_config_write_line (config_file, "SAY", "%s", "\"msg *\"");
@@ -524,14 +533,17 @@ alias_config_init ()
struct t_config_section *ptr_section;
alias_config_file = weechat_config_new (ALIAS_CONFIG_FILENAME,
&alias_config_reload);
&alias_config_reload, NULL);
if (!alias_config_file)
return 0;
ptr_section = weechat_config_new_section (alias_config_file, "alias",
alias_config_read_line,
alias_config_write_section,
alias_config_write_default_aliases);
&alias_config_read_line,
NULL,
&alias_config_write_section,
NULL,
&alias_config_write_default_aliases,
NULL);
if (!ptr_section)
{
weechat_config_free (alias_config_file);
+21 -9
View File
@@ -172,9 +172,10 @@ charset_free_all ()
*/
int
charset_config_reload (struct t_config_file *config_file)
charset_config_reload (void *data, struct t_config_file *config_file)
{
/* make C compiler happy */
(void) data;
(void) config_file;
charset_free_all ();
@@ -186,10 +187,11 @@ charset_config_reload (struct t_config_file *config_file)
*/
void
charset_config_read_line (struct t_config_file *config_file, char *option_name,
char *value)
charset_config_read_line (void *data, struct t_config_file *config_file,
char *option_name, char *value)
{
/* make C compiler happy */
(void) data;
(void) config_file;
if (option_name && value)
@@ -212,11 +214,14 @@ charset_config_read_line (struct t_config_file *config_file, char *option_name,
*/
void
charset_config_write_section (struct t_config_file *config_file,
charset_config_write_section (void *data, struct t_config_file *config_file,
char *section_name)
{
struct t_charset *ptr_charset;
/* make C compiler happy */
(void) data;
weechat_config_write_line (config_file, section_name, NULL);
for (ptr_charset = charset_list; ptr_charset;
@@ -234,9 +239,13 @@ charset_config_write_section (struct t_config_file *config_file,
*/
void
charset_config_write_default_charsets (struct t_config_file *config_file,
charset_config_write_default_charsets (void *data,
struct t_config_file *config_file,
char *section_name)
{
/* make C compiler happy */
(void) data;
weechat_config_write_line (config_file, section_name, NULL);
if (charset_terminal && charset_internal
@@ -258,14 +267,17 @@ charset_config_init ()
struct t_config_section *ptr_section;
charset_config_file = weechat_config_new (CHARSET_CONFIG_FILENAME,
&charset_config_reload);
&charset_config_reload, NULL);
if (!charset_config_file)
return 0;
ptr_section = weechat_config_new_section (charset_config_file, "charset",
charset_config_read_line,
charset_config_write_section,
charset_config_write_default_charsets);
&charset_config_read_line,
NULL,
&charset_config_write_section,
NULL,
&charset_config_write_default_charsets,
NULL);
if (!ptr_section)
{
weechat_config_free (charset_config_file);
+191 -121
View File
@@ -212,12 +212,13 @@ irc_config_change_notify_levels ()
*/
int
irc_config_reload (struct t_config_file *config_file)
irc_config_reload (void *data, struct t_config_file *config_file)
{
struct t_irc_server *ptr_server, *next_server;
int rc;
/* make C compiler happy */
(void) data;
(void) config_file;
irc_config_server = NULL;
@@ -270,13 +271,14 @@ irc_config_reload (struct t_config_file *config_file)
*/
void
irc_config_read_server_line (struct t_config_file *config_file,
irc_config_read_server_line (void *data, struct t_config_file *config_file,
char *option_name, char *value)
{
struct t_config_option *ptr_option;
int rc;
/* make C compiler happy */
(void) data;
(void) config_file;
if (option_name && value)
@@ -339,11 +341,14 @@ irc_config_read_server_line (struct t_config_file *config_file,
*/
void
irc_config_write_servers (struct t_config_file *config_file,
irc_config_write_servers (void *data, struct t_config_file *config_file,
char *section_name)
{
struct t_irc_server *ptr_server;
/* make C compiler happy */
(void) data;
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
{
@@ -397,12 +402,15 @@ irc_config_write_servers (struct t_config_file *config_file,
*/
void
irc_config_write_server_default (struct t_config_file *config_file,
irc_config_write_server_default (void *data, struct t_config_file *config_file,
char *section_name)
{
struct passwd *my_passwd;
char *realname, *pos;
/* make C compiler happy */
(void) data;
weechat_config_write_line (config_file, section_name, NULL);
weechat_config_write_line (config_file, "server_name", "%s", "\"freenode\"");
@@ -469,12 +477,14 @@ irc_config_init ()
struct t_config_section *ptr_section;
irc_config_file = weechat_config_new (IRC_CONFIG_FILENAME,
&irc_config_reload);
&irc_config_reload, NULL);
if (!irc_config_file)
return 0;
ptr_section = weechat_config_new_section (irc_config_file, "irc",
NULL, NULL, NULL);
NULL, NULL,
NULL, NULL,
NULL, NULL);
if (!ptr_section)
{
weechat_config_free (irc_config_file);
@@ -482,93 +492,114 @@ irc_config_init ()
}
irc_config_irc_one_server_buffer = weechat_config_new_option (
ptr_section, "irc_one_server_buffer", "boolean",
irc_config_file, ptr_section,
"irc_one_server_buffer", "boolean",
N_("use same buffer for all servers"),
NULL, 0, 0, "off", &irc_config_change_one_server_buffer);
NULL, 0, 0, "off", &irc_config_change_one_server_buffer, NULL);
irc_config_irc_open_near_server = weechat_config_new_option (
ptr_section, "irc_open_near_server", "boolean",
irc_config_file, ptr_section,
"irc_open_near_server", "boolean",
N_("open new channels/privates near server"),
NULL, 0, 0, "off", NULL);
NULL, 0, 0, "off", NULL, NULL);
irc_config_irc_nick_prefix = weechat_config_new_option (
ptr_section, "irc_nick_prefix", "string",
irc_config_file, ptr_section,
"irc_nick_prefix", "string",
N_("text to display before nick in chat window"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_irc_nick_suffix = weechat_config_new_option (
ptr_section, "irc_nick_suffix", "string",
irc_config_file, ptr_section,
"irc_nick_suffix", "string",
N_("text to display after nick in chat window"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_irc_nick_completion_smart = weechat_config_new_option (
ptr_section, "irc_nick_completion_smart", "boolean",
irc_config_file, ptr_section,
"irc_nick_completion_smart", "boolean",
N_("smart completion for nicks (completes with last speakers first)"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_irc_display_away = weechat_config_new_option (
ptr_section, "irc_display_away", "integer",
irc_config_file, ptr_section,
"irc_display_away", "integer",
N_("display message when (un)marking as away"),
"off|local|channel", 0, 0, "local", NULL);
"off|local|channel", 0, 0, "local", NULL, NULL);
irc_config_irc_show_away_once = weechat_config_new_option (
ptr_section, "irc_show_away_once", "boolean",
irc_config_file, ptr_section,
"irc_show_away_once", "boolean",
N_("show remote away message only once in private"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_irc_default_msg_part = weechat_config_new_option (
ptr_section, "irc_default_msg_part", "string",
irc_config_file, ptr_section,
"irc_default_msg_part", "string",
N_("default part message (leaving channel) ('%v' will be replaced by "
"WeeChat version in string)"),
NULL, 0, 0, "WeeChat %v", NULL);
NULL, 0, 0, "WeeChat %v", NULL, NULL);
irc_config_irc_notice_as_pv = weechat_config_new_option (
ptr_section, "irc_notice_as_pv", "boolean",
irc_config_file, ptr_section,
"irc_notice_as_pv", "boolean",
N_("display notices as private messages"),
NULL, 0, 0, "off", NULL);
NULL, 0, 0, "off", NULL, NULL);
irc_config_irc_away_check = weechat_config_new_option (
ptr_section, "irc_away_check", "integer",
irc_config_file, ptr_section,
"irc_away_check", "integer",
N_("interval between two checks for away (in minutes, 0 = never "
"check)"),
NULL, 0, INT_MAX, "0", &irc_config_change_away_check);
NULL, 0, INT_MAX, "0", &irc_config_change_away_check, NULL);
irc_config_irc_away_check_max_nicks = weechat_config_new_option (
ptr_section, "irc_away_check_max_nicks", "integer",
irc_config_file, ptr_section,
"irc_away_check_max_nicks", "integer",
N_("do not check away nicks on channels with high number of nicks "
"(0 = unlimited)"),
NULL, 0, INT_MAX, "0", &irc_config_change_away_check);
NULL, 0, INT_MAX, "0", &irc_config_change_away_check, NULL);
irc_config_irc_lag_check = weechat_config_new_option (
ptr_section, "irc_lag_check", "integer",
irc_config_file, ptr_section,
"irc_lag_check", "integer",
N_("interval between two checks for lag (in seconds, 0 = never "
"check)"),
NULL, 0, INT_MAX, "60", NULL);
NULL, 0, INT_MAX, "60", NULL, NULL);
irc_config_irc_lag_min_show = weechat_config_new_option (
ptr_section, "irc_lag_min_show", "integer",
irc_config_file, ptr_section,
"irc_lag_min_show", "integer",
N_("minimum lag to show (in seconds)"),
NULL, 0, INT_MAX, "1", NULL);
NULL, 0, INT_MAX, "1", NULL, NULL);
irc_config_irc_lag_disconnect = weechat_config_new_option (
ptr_section, "irc_lag_disconnect", "integer",
irc_config_file, ptr_section,
"irc_lag_disconnect", "integer",
N_("disconnect after important lag (in minutes, 0 = never "
"disconnect)"),
NULL, 0, INT_MAX, "5", NULL);
NULL, 0, INT_MAX, "5", NULL, NULL);
irc_config_irc_anti_flood = weechat_config_new_option (
ptr_section, "irc_anti_flood", "integer",
irc_config_file, ptr_section,
"irc_anti_flood", "integer",
N_("anti-flood: # seconds between two user messages (0 = no "
"anti-flood)"),
NULL, 0, 5, "2", NULL);
NULL, 0, 5, "2", NULL, NULL);
irc_config_irc_highlight = weechat_config_new_option (
ptr_section, "irc_highlight", "string",
irc_config_file, ptr_section,
"irc_highlight", "string",
N_("comma separated list of words to highlight (case insensitive "
"comparison, words may begin or end with \"*\" for partial match)"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_irc_colors_receive = weechat_config_new_option (
ptr_section, "irc_colors_receive", "boolean",
irc_config_file, ptr_section,
"irc_colors_receive", "boolean",
N_("when off, colors codes are ignored in incoming messages"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_irc_colors_send = weechat_config_new_option (
ptr_section, "irc_colors_send", "boolean",
irc_config_file, ptr_section,
"irc_colors_send", "boolean",
N_("allow user to send colors with special codes (^Cb=bold, "
"^Ccxx=color, ^Ccxx,yy=color+background, ^Cu=underline, "
"^Cr=reverse)"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_irc_send_unknown_commands = weechat_config_new_option (
ptr_section, "irc_send_unknown_commands", "boolean",
irc_config_file, ptr_section,
"irc_send_unknown_commands", "boolean",
N_("send unknown commands to IRC server"),
NULL, 0, 0, "off", NULL);
NULL, 0, 0, "off", NULL, NULL);
ptr_section = weechat_config_new_section (irc_config_file, "dcc",
NULL, NULL, NULL);
NULL, NULL,
NULL, NULL,
NULL, NULL);
if (!ptr_section)
{
weechat_config_free (irc_config_file);
@@ -576,62 +607,76 @@ irc_config_init ()
}
irc_config_dcc_auto_accept_files = weechat_config_new_option (
ptr_section, "dcc_auto_accept_files", "boolean",
irc_config_file, ptr_section,
"dcc_auto_accept_files", "boolean",
N_("automatically accept incoming dcc files (use carefully!)"),
NULL, 0, 0, "off", NULL);
NULL, 0, 0, "off", NULL, NULL);
irc_config_dcc_auto_accept_chats = weechat_config_new_option (
ptr_section, "dcc_auto_accept_chats", "boolean",
irc_config_file, ptr_section,
"dcc_auto_accept_chats", "boolean",
N_("automatically accept dcc chats (use carefully!)"),
NULL, 0, 0, "off", NULL);
NULL, 0, 0, "off", NULL, NULL);
irc_config_dcc_timeout = weechat_config_new_option (
ptr_section, "dcc_timeout", "integer",
irc_config_file, ptr_section,
"dcc_timeout", "integer",
N_("timeout for dcc request (in seconds)"),
NULL, 5, INT_MAX, "300", NULL);
NULL, 5, INT_MAX, "300", NULL, NULL);
irc_config_dcc_blocksize = weechat_config_new_option (
ptr_section, "dcc_blocksize", "integer",
irc_config_file, ptr_section,
"dcc_blocksize", "integer",
N_("block size for dcc packets in bytes"),
NULL, IRC_DCC_MIN_BLOCKSIZE, IRC_DCC_MAX_BLOCKSIZE, "65536",
NULL);
NULL, NULL);
irc_config_dcc_fast_send = weechat_config_new_option (
ptr_section, "dcc_fast_send", "boolean",
irc_config_file, ptr_section,
"dcc_fast_send", "boolean",
N_("does not wait for ACK when sending file"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_dcc_port_range = weechat_config_new_option (
ptr_section, "dcc_port_range", "string",
irc_config_file, ptr_section,
"dcc_port_range", "string",
N_("restricts outgoing dcc to use only ports in the given range "
"(useful for NAT) (syntax: a single port, ie. 5000 or a port "
"range, ie. 5000-5015, empty value means any port)"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_dcc_own_ip = weechat_config_new_option (
ptr_section, "dcc_own_ip", "string",
irc_config_file, ptr_section,
"dcc_own_ip", "string",
N_("IP or DNS address used for outgoing dcc "
"(if empty, local interface IP is used)"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_dcc_download_path = weechat_config_new_option (
ptr_section, "dcc_download_path", "string",
irc_config_file, ptr_section,
"dcc_download_path", "string",
N_("path for writing incoming files with dcc"),
NULL, 0, 0, "%h/dcc", NULL);
NULL, 0, 0, "%h/dcc", NULL, NULL);
irc_config_dcc_upload_path = weechat_config_new_option (
ptr_section, "dcc_upload_path", "string",
irc_config_file, ptr_section,
"dcc_upload_path", "string",
N_("path for reading files when sending thru dcc (when no path is "
"specified)"),
NULL, 0, 0, "~", NULL);
NULL, 0, 0, "~", NULL, NULL);
irc_config_dcc_convert_spaces = weechat_config_new_option (
ptr_section, "dcc_convert_spaces", "boolean",
irc_config_file, ptr_section,
"dcc_convert_spaces", "boolean",
N_("convert spaces to underscores when sending files"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_dcc_auto_rename = weechat_config_new_option (
ptr_section, "dcc_auto_rename", "boolean",
irc_config_file, ptr_section,
"dcc_auto_rename", "boolean",
N_("rename incoming files if already exists (add '.1', '.2', ...)"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_dcc_auto_resume = weechat_config_new_option (
ptr_section, "dcc_auto_resume", "boolean",
irc_config_file, ptr_section,
"dcc_auto_resume", "boolean",
N_("automatically resume dcc transfer if connection with remote host "
"is loosed"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
ptr_section = weechat_config_new_section (irc_config_file, "log",
NULL, NULL, NULL);
NULL, NULL,
NULL, NULL,
NULL, NULL);
if (!ptr_section)
{
weechat_config_free (irc_config_file);
@@ -639,26 +684,33 @@ irc_config_init ()
}
irc_config_log_auto_server = weechat_config_new_option (
ptr_section, "log_auto_server", "boolean",
irc_config_file, ptr_section,
"log_auto_server", "boolean",
N_("automatically log server messages"),
NULL, 0, 0, "off", &irc_config_change_log);
NULL, 0, 0, "off", &irc_config_change_log, NULL);
irc_config_log_auto_channel = weechat_config_new_option (
ptr_section, "log_auto_channel", "boolean",
irc_config_file, ptr_section,
"log_auto_channel", "boolean",
N_("automatically log channel chats"),
NULL, 0, 0, "off", &irc_config_change_log);
NULL, 0, 0, "off", &irc_config_change_log, NULL);
irc_config_log_auto_private = weechat_config_new_option (
ptr_section, "log_auto_private", "boolean",
irc_config_file, ptr_section,
"log_auto_private", "boolean",
N_("automatically log private chats"),
NULL, 0, 0, "off", &irc_config_change_log);
NULL, 0, 0, "off", &irc_config_change_log, NULL);
irc_config_log_hide_nickserv_pwd = weechat_config_new_option (
ptr_section, "log_hide_nickserv_pwd", "boolean",
irc_config_file, ptr_section,
"log_hide_nickserv_pwd", "boolean",
N_("hide password displayed by nickserv"),
NULL, 0, 0, "on", &irc_config_change_log);
NULL, 0, 0, "on", &irc_config_change_log, NULL);
ptr_section = weechat_config_new_section (irc_config_file, "server",
irc_config_read_server_line,
irc_config_write_servers,
irc_config_write_server_default);
&irc_config_read_server_line,
NULL,
&irc_config_write_servers,
NULL,
&irc_config_write_server_default,
NULL);
if (!ptr_section)
{
weechat_config_free (irc_config_file);
@@ -668,94 +720,112 @@ irc_config_init ()
irc_config_section_server = ptr_section;
irc_config_server_name = weechat_config_new_option (
ptr_section, "server_name", "string",
irc_config_file, ptr_section,
"server_name", "string",
N_("name associated to IRC server (for display only)"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_autoconnect = weechat_config_new_option (
ptr_section, "server_autoconnect", "boolean",
irc_config_file, ptr_section,
"server_autoconnect", "boolean",
N_("automatically connect to server when WeeChat is starting"),
NULL, 0, 0, "off", NULL);
NULL, 0, 0, "off", NULL, NULL);
irc_config_server_autoreconnect = weechat_config_new_option (
ptr_section, "server_autoreconnect", "boolean",
irc_config_file, ptr_section,
"server_autoreconnect", "boolean",
N_("automatically reconnect to server when disconnected"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_server_autoreconnect_delay = weechat_config_new_option (
ptr_section, "server_autoreconnect_delay", "integer",
irc_config_file, ptr_section,
"server_autoreconnect_delay", "integer",
N_("delay (in seconds) before trying again to reconnect to server"),
NULL, 0, 65535, "30", NULL);
NULL, 0, 65535, "30", NULL, NULL);
irc_config_server_address = weechat_config_new_option (
ptr_section, "server_address", "string",
irc_config_file, ptr_section,
"server_address", "string",
N_("IP address or hostname of IRC server"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_port = weechat_config_new_option (
ptr_section, "server_port", "integer",
irc_config_file, ptr_section,
"server_port", "integer",
N_("port for connecting to server"),
NULL, 0, 65535, "6667", NULL);
NULL, 0, 65535, "6667", NULL, NULL);
irc_config_server_ipv6 = weechat_config_new_option (
ptr_section, "server_ipv6", "boolean",
irc_config_file, ptr_section,
"server_ipv6", "boolean",
N_("use IPv6 protocol for server communication"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_server_ssl = weechat_config_new_option (
ptr_section, "server_ssl", "boolean",
irc_config_file, ptr_section,
"server_ssl", "boolean",
N_("use SSL for server communication"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_server_password = weechat_config_new_option (
ptr_section, "server_password", "string",
irc_config_file, ptr_section,
"server_password", "string",
N_("password for IRC server"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_nick1 = weechat_config_new_option (
ptr_section, "server_nick1", "string",
irc_config_file, ptr_section,
"server_nick1", "string",
N_("nickname to use on IRC server"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_nick2 = weechat_config_new_option (
ptr_section, "server_nick2", "string",
irc_config_file, ptr_section,
"server_nick2", "string",
N_("alternate nickname to use on IRC server (if nickname is already "
"used)"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_nick3 = weechat_config_new_option (
ptr_section, "server_nick3", "string",
irc_config_file, ptr_section, "server_nick3", "string",
N_("2nd alternate nickname to use on IRC server (if alternate "
"nickname is already used)"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_username = weechat_config_new_option (
ptr_section, "server_username", "string",
irc_config_file, ptr_section, "server_username", "string",
N_("user name to use on IRC server"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_realname = weechat_config_new_option (
ptr_section, "server_realname", "string",
irc_config_file, ptr_section,
"server_realname", "string",
N_("real name to use on IRC server"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_hostname = weechat_config_new_option (
ptr_section, "server_hostname", "string",
irc_config_file, ptr_section,
"server_hostname", "string",
N_("custom hostname/IP for server (optional, if empty local hostname "
"is used)"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_command = weechat_config_new_option (
ptr_section, "server_command", "string",
irc_config_file, ptr_section,
"server_command", "string",
N_("command(s) to run when connected to server (many commands should "
"be separated by ';', use '\\;' for a semicolon, special variables "
"$nick, $channel and $server are replaced by their value)"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_command_delay = weechat_config_new_option (
ptr_section, "server_command_delay", "integer",
irc_config_file, ptr_section,
"server_command_delay", "integer",
N_("delay (in seconds) after command was executed (example: give some "
"time for authentication)"),
NULL, 0, 3600, "0", NULL);
NULL, 0, 3600, "0", NULL, NULL);
irc_config_server_autojoin = weechat_config_new_option (
ptr_section, "server_autojoin", "string",
irc_config_file, ptr_section,
"server_autojoin", "string",
N_("comma separated list of channels to join when connected to server "
"(example: \"#chan1,#chan2,#chan3 key1,key2\")"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
irc_config_server_autorejoin = weechat_config_new_option (
ptr_section, "server_autorejoin", "string",
irc_config_file, ptr_section,
"server_autorejoin", "string",
N_("automatically rejoin channels when kicked"),
NULL, 0, 0, "on", NULL);
NULL, 0, 0, "on", NULL, NULL);
irc_config_server_notify_levels = weechat_config_new_option (
ptr_section, "server_notify_levels", "string",
irc_config_file, ptr_section,
"server_notify_levels", "string",
N_("comma separated list of notify levels for channels of this server "
"(format: #channel:1,..), a channel name '*' is reserved for "
"server default notify level"),
NULL, 0, 0, "", NULL);
NULL, 0, 0, "", NULL, NULL);
return 1;
}
+12 -7
View File
@@ -289,9 +289,10 @@ plugin_config_free_all ()
*/
int
plugin_config_reload (struct t_config_file *config_file)
plugin_config_reload (void *data, struct t_config_file *config_file)
{
/* make C compiler happy */
(void) data;
(void) config_file;
/* remove all plugin options */
@@ -309,12 +310,13 @@ plugin_config_reload (struct t_config_file *config_file)
*/
void
plugin_config_read_option (struct t_config_file *config_file,
plugin_config_read_option (void *data, struct t_config_file *config_file,
char *option_name, char *value)
{
char *value2;
/* make C compiler happy */
(void) data;
(void) config_file;
if (option_name && value)
@@ -332,11 +334,14 @@ plugin_config_read_option (struct t_config_file *config_file,
*/
void
plugin_config_write_options (struct t_config_file *config_file,
plugin_config_write_options (void *data, struct t_config_file *config_file,
char *section_name)
{
struct t_config_option *ptr_option;
/* make C compiler happy */
(void) data;
config_file_write_line (config_file, section_name, NULL);
for (ptr_option = plugin_options; ptr_option;
@@ -356,13 +361,13 @@ void
plugin_config_init ()
{
plugin_config = config_file_new (NULL, PLUGIN_CONFIG_FILENAME,
&plugin_config_reload);
&plugin_config_reload, NULL);
if (plugin_config)
{
config_file_new_section (plugin_config, "plugins",
&plugin_config_read_option,
&plugin_config_write_options,
NULL);
&plugin_config_read_option, NULL,
&plugin_config_write_options, NULL,
NULL, NULL);
}
}
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -213,7 +213,8 @@ weechat_lua_load (char *filename)
fclose (fp);
/* if script was registered, removing from list */
if (lua_current_script)
script_remove (weechat_lua_plugin, &lua_scripts, lua_current_script);
script_remove (weechat_lua_plugin, &lua_scripts,
lua_current_script);
return 0;
}
fclose (fp);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -370,8 +370,8 @@ weechat_python_load (char *filename)
/* if script was registered, removing from list */
if (python_current_script != NULL)
{
script_remove (weechat_python_plugin,
&python_scripts, python_current_script);
script_remove (weechat_python_plugin, &python_scripts,
python_current_script);
}
return 0;
}
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -376,8 +376,8 @@ weechat_ruby_load (char *filename)
if (ruby_current_script != NULL)
{
script_remove (weechat_ruby_plugin,
&ruby_scripts, ruby_current_script);
script_remove (weechat_ruby_plugin, &ruby_scripts,
ruby_current_script);
}
return 0;
+249 -20
View File
@@ -43,6 +43,247 @@ script_api_charset_set (struct t_plugin_script *script,
script->charset = (charset) ? strdup (charset) : NULL;
}
/*
* script_api_config_new: create a new configuration file
* return new configuration file, NULL if error
*/
struct t_config_file *
script_api_config_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *filename,
int (*callback_reload)(void *data,
struct t_config_file *config_file),
char *function)
{
struct t_script_callback *new_script_callback;
struct t_config_file *new_config_file;
if (function && function[0])
{
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
new_config_file = weechat_config_new (filename, callback_reload,
new_script_callback);
if (!new_config_file)
{
free (new_script_callback);
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
new_script_callback->config_file = new_config_file;
script_callback_add (script, new_script_callback);
}
else
{
new_config_file = weechat_config_new (filename, NULL, NULL);
}
return new_config_file;
}
/*
* script_api_config_new_section: create a new section in configuration file
* return new section, NULL if error
*/
struct t_config_section *
script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
char *name,
void (*callback_read)(void *data,
struct t_config_file *config_file,
char *option_name,
char *value),
char *function_read,
void (*callback_write)(void *data,
struct t_config_file *config_file,
char *section_name),
char *function_write,
void (*callback_write_default)(void *data,
struct t_config_file *config_file,
char *section_name),
char *function_write_default)
{
struct t_script_callback *new_script_callback1, *new_script_callback2;
struct t_script_callback *new_script_callback3;
struct t_config_section *new_section;
void *callback1, *callback2, *callback3;
new_script_callback1 = NULL;
new_script_callback2 = NULL;
new_script_callback3 = NULL;
callback1 = NULL;
callback2 = NULL;
callback3 = NULL;
if (function_read && function_read[0])
{
new_script_callback1 = script_callback_alloc ();
if (!new_script_callback1)
return NULL;
callback1 = callback_read;
}
if (function_write && function_write[0])
{
new_script_callback2 = script_callback_alloc ();
if (!new_script_callback2)
{
if (new_script_callback1)
free (new_script_callback1);
return NULL;
}
callback2 = callback_write;
}
if (function_write_default && function_write_default[0])
{
new_script_callback3 = script_callback_alloc ();
if (!new_script_callback3)
{
if (new_script_callback1)
free (new_script_callback1);
if (new_script_callback2)
free (new_script_callback2);
return NULL;
}
callback3 = callback_write_default;
}
new_section = weechat_config_new_section (config_file,
name,
callback1,
new_script_callback1,
callback2,
new_script_callback2,
callback3,
new_script_callback3);
if (!new_section)
{
if (new_script_callback1)
free (new_script_callback1);
if (new_script_callback2)
free (new_script_callback2);
if (new_script_callback3)
free (new_script_callback3);
return NULL;
}
if (new_script_callback1)
{
new_script_callback1->script = script;
new_script_callback1->function = strdup (function_read);
new_script_callback1->config_file = config_file;
new_script_callback1->config_section = new_section;
script_callback_add (script, new_script_callback1);
}
if (new_script_callback2)
{
new_script_callback2->script = script;
new_script_callback2->function = strdup (function_write);
new_script_callback2->config_file = config_file;
new_script_callback2->config_section = new_section;
script_callback_add (script, new_script_callback2);
}
if (new_script_callback3)
{
new_script_callback3->script = script;
new_script_callback3->function = strdup (function_write_default);
new_script_callback3->config_file = config_file;
new_script_callback3->config_section = new_section;
script_callback_add (script, new_script_callback3);
}
return new_section;
}
/*
* script_api_config_new_option: create a new option in section
* return new option, NULL if error
*/
struct t_config_option *
script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
struct t_config_section *section,
char *name, char *type,
char *description, char *string_values,
int min, int max, char *default_value,
void (*callback_change)(void *data),
char *function)
{
struct t_script_callback *new_script_callback;
struct t_config_option *new_option;
if (function && function[0])
{
new_script_callback = script_callback_alloc ();
if (!new_script_callback)
return NULL;
new_option = weechat_config_new_option (config_file, section, name, type,
description, string_values, min,
max, default_value,
callback_change,
new_script_callback);
if (!new_option)
{
free (new_script_callback);
return NULL;
}
new_script_callback->script = script;
new_script_callback->function = strdup (function);
new_script_callback->config_file = config_file;
new_script_callback->config_section = section;
new_script_callback->config_option = new_option;
script_callback_add (script, new_script_callback);
}
else
{
new_option = weechat_config_new_option (config_file, section, name, type,
description, string_values, min,
max, default_value, NULL, NULL);
}
return new_option;
}
/*
* script_api_config_free: free configuration file
*/
void
script_api_config_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file)
{
struct t_script_callback *ptr_script_callback;
if (!weechat_plugin || !script || !config_file)
return;
weechat_config_free (config_file);
for (ptr_script_callback = script->callbacks; ptr_script_callback;
ptr_script_callback = ptr_script_callback->next_callback)
{
if (ptr_script_callback->config_file == config_file)
script_callback_remove (script, ptr_script_callback);
}
}
/*
* script_api_printf: print a message
*/
@@ -140,10 +381,6 @@ script_api_hook_command (struct t_weechat_plugin *weechat_plugin,
if (!new_script_callback)
return NULL;
new_script_callback->script = NULL;
new_script_callback->function = NULL;
new_script_callback->hook = NULL;
new_hook = weechat_hook_command (command, description, args,
args_description, completion,
callback, new_script_callback);
@@ -423,10 +660,9 @@ script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
/*
* script_api_unhook: unhook something
* return 1 if ok, 0 if error
*/
int
void
script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook)
@@ -434,22 +670,16 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_script_callback *ptr_script_callback;
if (!weechat_plugin || !script || !hook)
return 0;
return;
weechat_unhook (hook);
for (ptr_script_callback = script->callbacks; ptr_script_callback;
ptr_script_callback = ptr_script_callback->next_callback)
{
if (ptr_script_callback->hook == hook)
break;
script_callback_remove (script, ptr_script_callback);
}
if (ptr_script_callback)
{
script_callback_remove (weechat_plugin, script, ptr_script_callback);
return 1;
}
return 0;
}
/*
@@ -457,8 +687,7 @@ script_api_unhook (struct t_weechat_plugin *weechat_plugin,
*/
void
script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script)
script_api_unhook_all (struct t_plugin_script *script)
{
struct t_script_callback *ptr_callback, *next_callback;
@@ -467,7 +696,7 @@ script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
{
next_callback = ptr_callback->next_callback;
script_callback_remove (weechat_plugin, script, ptr_callback);
script_callback_remove (script, ptr_callback);
ptr_callback = next_callback;
}
@@ -539,7 +768,7 @@ script_api_buffer_close (struct t_weechat_plugin *weechat_plugin,
if (ptr_script_callback)
{
script_callback_remove (weechat_plugin, script, ptr_script_callback);
script_callback_remove (script, ptr_script_callback);
}
}
+42 -5
View File
@@ -21,6 +21,44 @@
extern void script_api_charset_set (struct t_plugin_script *script,
char *charset);
extern struct t_config_file *script_api_config_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *filename,
int (*callback_reload)(void *data,
struct t_config_file *config_file),
char *function);
extern struct t_config_section *script_api_config_new_section (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
char *name,
void (*callback_read)(void *data,
struct t_config_file *config_file,
char *option_name,
char *value),
char *function_read,
void (*callback_write)(void *data,
struct t_config_file *config_file,
char *section_name),
char *function_write,
void (*callback_write_default)(void *data,
struct t_config_file *config_file,
char *section_name),
char *function_write_default);
extern struct t_config_option *script_api_config_new_option (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file,
struct t_config_section *section,
char *name,
char *type,
char *description,
char *string_values,
int min, int max,
char *default_value,
void (*callback_change)(void *data),
char *function);
extern void script_api_config_free (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_config_file *config_file);
extern void script_api_printf (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_gui_buffer *buffer,
@@ -95,11 +133,10 @@ extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat
char *modifier_data,
char *string),
char *function);
extern int script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook);
extern void script_api_unhook_all (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script);
extern void script_api_unhook (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
struct t_hook *hook);
extern void script_api_unhook_all (struct t_plugin_script *script);
struct t_gui_buffer *script_api_buffer_new (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
char *category, char *name,
+6 -7
View File
@@ -41,6 +41,9 @@ script_callback_alloc ()
{
new_script_callback->script = NULL;
new_script_callback->function = NULL;
new_script_callback->config_file = NULL;
new_script_callback->config_section = NULL;
new_script_callback->config_option = NULL;
new_script_callback->hook = NULL;
new_script_callback->buffer = NULL;
return new_script_callback;
@@ -69,8 +72,7 @@ script_callback_add (struct t_plugin_script *script,
*/
void
script_callback_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
script_callback_remove (struct t_plugin_script *script,
struct t_script_callback *script_callback)
{
/* remove callback from list */
@@ -86,8 +88,6 @@ script_callback_remove (struct t_weechat_plugin *weechat_plugin,
/* unhook and free data */
if (script_callback->function)
free (script_callback->function);
if (script_callback->hook)
weechat_unhook (script_callback->hook);
free (script_callback);
}
@@ -97,12 +97,11 @@ script_callback_remove (struct t_weechat_plugin *weechat_plugin,
*/
void
script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script)
script_callback_remove_all (struct t_plugin_script *script)
{
while (script->callbacks)
{
script_callback_remove (weechat_plugin, script, script->callbacks);
script_callback_remove (script, script->callbacks);
}
}
+9 -8
View File
@@ -21,10 +21,13 @@
struct t_script_callback
{
void *script; /* pointer to script */
char *function; /* script function called */
struct t_hook *hook; /* not NULL if hook */
struct t_gui_buffer *buffer; /* not NULL if buffer callback */
void *script; /* pointer to script */
char *function; /* script function called */
struct t_config_file *config_file; /* not NULL for config file */
struct t_config_section *config_section; /* not NULL for config section */
struct t_config_option *config_option; /* not NULL for config option */
struct t_hook *hook; /* not NULL for hook */
struct t_gui_buffer *buffer; /* not NULL for buffer callback*/
struct t_script_callback *prev_callback; /* link to next callback */
struct t_script_callback *next_callback; /* link to previous callback */
};
@@ -32,11 +35,9 @@ struct t_script_callback
extern struct t_script_callback *script_callback_alloc ();
extern void script_callback_add (struct t_plugin_script *script,
struct t_script_callback *callback);
extern void script_callback_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
extern void script_callback_remove (struct t_plugin_script *script,
struct t_script_callback *script_callback);
extern void script_callback_remove_all (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script);
extern void script_callback_remove_all (struct t_plugin_script *script);
extern void script_callback_print_log (struct t_weechat_plugin *weechat_plugin,
struct t_script_callback *script_callback);
+20 -1
View File
@@ -411,8 +411,27 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script **scripts,
struct t_plugin_script *script)
{
struct t_script_callback *ptr_script_callback;
for (ptr_script_callback = script->callbacks; ptr_script_callback;
ptr_script_callback = ptr_script_callback->next_callback)
{
if (ptr_script_callback->hook)
{
weechat_unhook (ptr_script_callback->hook);
}
if (ptr_script_callback->config_file
&& !ptr_script_callback->config_section
&& !ptr_script_callback->config_option)
{
if (weechat_config_boolean (weechat_config_get_weechat ("plugins_save_config_on_unload")))
weechat_config_write (ptr_script_callback->config_file);
weechat_config_free (ptr_script_callback->config_file);
}
}
/* remove all callbacks created by this script */
script_callback_remove_all (weechat_plugin, script);
script_callback_remove_all (script);
/* free data */
if (script->filename)
+39 -24
View File
@@ -157,28 +157,35 @@ struct t_weechat_plugin
/* config files */
struct t_config_file *(*config_new) (struct t_weechat_plugin *plugin,
char *filename,
int (*callback_reload)(struct t_config_file *config_file));
int (*callback_reload)(void *data,
struct t_config_file *config_file),
void *callback_reload_data);
struct t_config_section *(*config_new_section) (struct t_config_file *config_file,
char *name,
void (*callback_read)
(struct t_config_file *config_file,
char *option_name,
char *value),
void (*callback_write)
(struct t_config_file *config_file,
char *section_name),
void (*callback_write_default)
(struct t_config_file *config_file,
char *section_name));
void (*callback_read)(void *data,
struct t_config_file *config_file,
char *option_name,
char *value),
void *callback_read_data,
void (*callback_write)(void *data,
struct t_config_file *config_file,
char *section_name),
void *callback_write_data,
void (*callback_write_default)(void *data,
struct t_config_file *config_file,
char *section_name),
void *callback_write_default_data);
struct t_config_section *(*config_search_section) (struct t_config_file *config_file,
char *section_name);
struct t_config_option *(*config_new_option) (struct t_config_section *config_file,
struct t_config_option *(*config_new_option) (struct t_config_file *config_file,
struct t_config_section *section,
char *name, char *type,
char *description,
char *string_values,
int min, int max,
char *default_value,
void (*callback_change)());
void (*callback_change)(void *data),
void *callback_change_data);
struct t_config_option *(*config_search_option) (struct t_config_file *config_file,
struct t_config_section *section,
char *option_name);
@@ -449,22 +456,30 @@ struct t_weechat_plugin
weechat_plugin->list_free(__list)
/* config files */
#define weechat_config_new(__filename, __callback_reload) \
weechat_plugin->config_new(weechat_plugin, __filename, \
__callback_reload)
#define weechat_config_new(__filename, __callback_reload, \
__callback_reload_data) \
weechat_plugin->config_new(weechat_plugin, __filename, \
__callback_reload, \
__callback_reload_data)
#define weechat_config_new_section(__config, __name, __cb_read, \
__cb_write_std, __cb_write_def) \
__cb_read_data, __cb_write_std, \
__cb_write_std_data, __cb_write_def, \
__cb_write_def_data) \
weechat_plugin->config_new_section(__config, __name, __cb_read, \
__cb_write_std, __cb_write_def)
__cb_read_data, __cb_write_std, \
__cb_write_std_data,\
__cb_write_def, \
__cb_write_def_data)
#define weechat_config_search_section(__config, __name) \
weechat_plugin->config_search_section(__config, __name)
#define weechat_config_new_option(__section, __name, __type, __desc, \
__string_values, __min, __max, \
__default, __callback) \
weechat_plugin->config_new_option(__section, __name, __type, \
__desc, __string_values, \
#define weechat_config_new_option(__config, __section, __name, __type, \
__desc, __string_values, __min, \
__max, __default, __callback, \
__callback_data) \
weechat_plugin->config_new_option(__config, __section, __name, \
__type, __desc, __string_values, \
__min, __max, __default, \
__callback)
__callback, __callback_data)
#define weechat_config_search_option(__config, __section, __name) \
weechat_plugin->config_search_option(__config, __section, __name)
#define weechat_config_string_to_boolean(__string) \