From 5d222c8d5c419bf3e0e62a15809cabe95793b691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Tue, 11 Jul 2023 19:40:04 +0200 Subject: irc: create default options irc.ctcp.* when file irc.conf is created (issue #1974) --- src/plugins/irc/irc-config.c | 52 ++++++++++++++++++++++++++++++++++---------- src/plugins/irc/irc-ctcp.h | 2 ++ 2 files changed, 43 insertions(+), 11 deletions(-) (limited to 'src/plugins/irc') diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index cc4164f83..0fde4767b 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -1425,10 +1425,10 @@ irc_config_reload (const void *pointer, void *data, */ int -irc_config_msgbuffer_create_option (const void *pointer, void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +irc_config_msgbuffer_create_option_cb (const void *pointer, void *data, + struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, const char *value) { struct t_config_option *ptr_option; char *name_lower; @@ -1499,15 +1499,45 @@ irc_config_msgbuffer_create_option (const void *pointer, void *data, return rc; } +/* + * Writes default ctcp reply formats. + */ + +int +irc_config_ctcp_write_default_cb (const void *pointer, void *data, + struct t_config_file *config_file, + const char *section_name) +{ + int i; + + /* make C compiler happy */ + (void) pointer; + (void) data; + + if (!weechat_config_write_line (config_file, section_name, NULL)) + return WEECHAT_CONFIG_WRITE_ERROR; + + for (i = 0; irc_ctcp_default_reply[i].name; i++) + { + if (!weechat_config_write_line (config_file, + irc_ctcp_default_reply[i].name, + "\"%s\"", + irc_ctcp_default_reply[i].reply)) + return WEECHAT_CONFIG_WRITE_ERROR; + } + + return WEECHAT_CONFIG_WRITE_OK; +} + /* * Sets a ctcp reply format. */ int -irc_config_ctcp_create_option (const void *pointer, void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, const char *value) +irc_config_ctcp_create_option_cb (const void *pointer, void *data, + struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, const char *value) { struct t_config_option *ptr_option; int rc; @@ -3747,7 +3777,7 @@ irc_config_init () NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - &irc_config_msgbuffer_create_option, NULL, NULL, + &irc_config_msgbuffer_create_option_cb, NULL, NULL, NULL, NULL, NULL); /* CTCP */ @@ -3756,8 +3786,8 @@ irc_config_init () 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, - &irc_config_ctcp_create_option, NULL, NULL, + &irc_config_ctcp_write_default_cb, NULL, NULL, + &irc_config_ctcp_create_option_cb, NULL, NULL, NULL, NULL, NULL); /* ignore */ diff --git a/src/plugins/irc/irc-ctcp.h b/src/plugins/irc/irc-ctcp.h index 57a7ecb67..c2b165f05 100644 --- a/src/plugins/irc/irc-ctcp.h +++ b/src/plugins/irc/irc-ctcp.h @@ -31,6 +31,8 @@ struct t_irc_ctcp_reply char *reply; /* CTCP reply format */ }; +extern struct t_irc_ctcp_reply irc_ctcp_default_reply[]; + extern const char *irc_ctcp_get_default_reply (const char *ctcp); extern const char *irc_ctcp_get_reply (struct t_irc_server *server, const char *ctcp); -- cgit v1.2.3