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

Add of "modifier" hook, migration of charset plugin to new API, SIGHUP signal catched (reload all config files), better config files reloading

This commit is contained in:
Sebastien Helleu
2008-01-24 16:50:20 +01:00
parent 25c5bc6421
commit ed26a0389c
48 changed files with 2335 additions and 1113 deletions
+60 -69
View File
@@ -207,6 +207,64 @@ irc_config_change_notify_levels ()
{
}
/*
* irc_config_reload: reload IRC configuration file
*/
int
irc_config_reload (struct t_config_file *config_file)
{
struct t_irc_server *ptr_server, *next_server;
int rc;
/* make C compiler happy */
(void) config_file;
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,
_("%s%s: warning: server \"%s\" not found "
"in configuration file, not deleted in "
"memory because it's currently used"),
weechat_prefix ("error"), "irc",
ptr_server->name);
}
else
irc_server_free (ptr_server);
}
ptr_server = next_server;
}
}
return rc;
}
/*
* irc_config_read_server_line: read a server line in configuration file
*/
@@ -410,7 +468,8 @@ irc_config_init ()
{
struct t_config_section *ptr_section;
irc_config_file = weechat_config_new (IRC_CONFIG_FILENAME);
irc_config_file = weechat_config_new (IRC_CONFIG_FILENAME,
&irc_config_reload);
if (!irc_config_file)
return 0;
@@ -726,74 +785,6 @@ irc_config_read ()
return rc;
}
/*
* irc_config_reload_cb: read IRC configuration file
*/
int
irc_config_reload_cb (void *data, char *event, void *pointer)
{
struct t_irc_server *ptr_server, *next_server;
int rc;
/* make C compiler happy */
(void) data;
(void) event;
(void) pointer;
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,
_("%s%s: warning: server \"%s\" not found "
"in configuration file. It has not been "
"deleted because it's used now."),
weechat_prefix ("info"), "irc",
ptr_server->name);
}
else
irc_server_free (ptr_server);
}
ptr_server = next_server;
}
weechat_printf (NULL,
_("%s%s: configuration file reloaded"),
weechat_prefix ("info"), "irc");
return WEECHAT_RC_OK;
}
weechat_printf (NULL,
_("%s%s: failed to reload configuration file"),
weechat_prefix ("error"), "irc");
return WEECHAT_RC_ERROR;
}
/*
* irc_config_write: write IRC configuration file
* return: 0 if ok
-1
View File
@@ -69,7 +69,6 @@ struct t_config_option *irc_config_log_hide_nickserv_pwd;
int irc_config_init ();
int irc_config_read ();
int irc_config_reload_cb ();
int irc_config_write ();
#endif /* irc-config.h */
+1 -1
View File
@@ -499,7 +499,7 @@ irc_protocol_recv_command (struct t_irc_server *server, char *entire_line,
if (!command)
return -2;
/* look for IRC command */
cmd_found = -1;
for (i = 0; irc_protocol_messages[i].name; i++)
+2 -2
View File
@@ -37,8 +37,8 @@ struct t_irc_protocol_msg
t_irc_recv_func2 *recv_function2; /* function called when msg is received */
};
extern int irc_protocol_is_highlight (char *, char *);
extern int irc_protocol_recv_command (struct t_irc_server *, char *, char *, char *, char *);
extern int irc_protocol_is_highlight (char *message, char *nick);
extern int irc_protocol_recv_command (struct t_irc_server *server, char *entire_line, char *host, char *command, char *arguments);
extern int irc_protocol_cmd_error (struct t_irc_server *server, int argc, char **argv, char **argv_eol, int ignore, int highlight);
extern int irc_protocol_cmd_invite (struct t_irc_server *server, int argc, char **argv, char **argv_eol, int ignore, int highlight);
extern int irc_protocol_cmd_join (struct t_irc_server *server, int argc, char **argv, char **argv_eol, int ignore, int highlight);
+95 -17
View File
@@ -986,24 +986,33 @@ irc_server_sendf (struct t_irc_server *server, char *format, ...)
/*
* irc_server_parse_message: parse IRC message and return pointer to
* host, command and arguments (if any)
* host, command, channel, target nick and arguments
* (if any)
*/
void
irc_server_parse_message (char *message, char **host, char **command, char **args)
irc_server_parse_message (char *message, char **nick, char **host,
char **command, char **channel, char **arguments)
{
char *pos, *pos2;
char *pos, *pos2, *pos3, *pos4;
*nick = NULL;
*host = NULL;
*command = NULL;
*args = NULL;
*channel = NULL;
*arguments = NULL;
if (message[0] == ':')
{
pos2 = strchr (message, '!');
pos = strchr (message, ' ');
if (pos2)
*nick = weechat_strndup (message + 1, pos2 - (message + 1));
else if (pos)
*nick = weechat_strndup (message + 1, pos - (message + 1));
if (pos)
{
*host = strndup (message + 1, pos - (message + 1));
*host = weechat_strndup (message + 1, pos - (message + 1));
pos++;
}
else
@@ -1019,11 +1028,47 @@ irc_server_parse_message (char *message, char **host, char **command, char **arg
pos2 = strchr (pos, ' ');
if (pos2)
{
*command = strndup (pos, pos2 - pos);
*command = weechat_strndup (pos, pos2 - pos);
pos2++;
while (pos2[0] == ' ')
pos2++;
*args = strdup (pos2);
*arguments = strdup (pos2);
if (pos2[0] != ':')
{
if (irc_channel_is_channel (pos2))
{
pos3 = strchr (pos2, ' ');
if (pos3)
*channel = weechat_strndup (pos2, pos3 - pos2);
else
*channel = strdup (pos2);
}
else
{
pos3 = strchr (pos2, ' ');
if (!*nick)
{
if (pos3)
*nick = weechat_strndup (pos2, pos3 - pos2);
else
*nick = strdup (pos2);
}
if (pos3)
{
pos3++;
while (pos3[0] == ' ')
pos3++;
if (irc_channel_is_channel (pos3))
{
pos4 = strchr (pos3, ' ');
if (pos4)
*channel = weechat_strndup (pos3, pos4 - pos3);
else
*channel = strdup (pos3);
}
}
}
}
}
}
}
@@ -1171,7 +1216,9 @@ irc_server_msgq_flush ()
{
struct t_irc_message *next;
char *ptr_data, *new_msg, *ptr_msg, *pos;
char *host, *command, *args;
char *nick, *host, *command, *channel, *arguments, *msg_decoded;
char *modifier_data, *ptr_chan_nick;
int length;
while (irc_recv_msgq)
{
@@ -1220,17 +1267,48 @@ irc_server_msgq_flush ()
pos = strchr (ptr_msg, '\n');
if (pos)
pos[0] = '\0';
//if (new_msg)
// gui_chat_printf_raw_data (irc_recv_msgq->server,
// 0, 1, ptr_msg);
irc_server_parse_message (ptr_msg, &host,
&command, &args);
irc_server_parse_message (ptr_msg, &nick, &host,
&command, &channel,
&arguments);
/* convert charset for message */
msg_decoded = NULL;
ptr_chan_nick = (channel) ? channel : nick;
length = strlen (weechat_plugin->name) + 1 +
strlen (irc_recv_msgq->server->name) + 1 +
((ptr_chan_nick) ? strlen (ptr_chan_nick) : 0) + 1;
modifier_data = (char *)malloc (length);
if (modifier_data)
{
if (ptr_chan_nick)
{
snprintf (modifier_data, length, "%s.%s.%s",
weechat_plugin->name,
irc_recv_msgq->server->name,
ptr_chan_nick);
}
else
{
snprintf (modifier_data, length, "%s.%s.%s",
weechat_plugin->name,
irc_recv_msgq->server->name,
ptr_chan_nick);
}
msg_decoded = weechat_hook_modifier_exec ("charset_decode",
modifier_data,
ptr_msg);
free (modifier_data);
}
switch (irc_protocol_recv_command (irc_recv_msgq->server,
ptr_msg,
host, command, args))
(msg_decoded) ?
msg_decoded : ptr_msg,
host, command,
arguments))
{
case -1:
weechat_printf (irc_recv_msgq->server->buffer,
@@ -1251,9 +1329,9 @@ irc_server_msgq_flush ()
_("%s%s: unknown command: "
"cmd=\"%s\", "
"host=\"%s\", "
"args=\"%s\""),
"arguments=\"%s\""),
weechat_prefix ("error"),
"irc", command, host, args);
"irc", command, host, arguments);
break;
}
@@ -1261,8 +1339,8 @@ irc_server_msgq_flush ()
free (host);
if (command)
free (command);
if (args)
free (args);
if (arguments)
free (arguments);
if (pos)
{
+3 -2
View File
@@ -161,8 +161,9 @@ extern int irc_server_send (struct t_irc_server *server, char *buffer,
int size_buf);
extern void irc_server_outqueue_send (struct t_irc_server *server);
extern void irc_server_sendf (struct t_irc_server *server, char *format, ...);
extern void irc_server_parse_message (char *message, char **host,
char **command, char **args);
extern void irc_server_parse_message (char *message, char **nick,
char **host, char **command,
char **channel, char **arguments);
extern int irc_server_recv_cb (void *arg_server);
extern void irc_server_timer_cb (void *empty);
extern void irc_server_timer_check_away (void *empty);
+5 -3
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* irc-core.c: main IRC functions */
/* irc.c: IRC plugin for WeeChat */
#ifdef HAVE_CONFIG_H
@@ -185,7 +185,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
/* hook signals */
weechat_hook_signal ("dump_data", &irc_dump_data_cb, NULL);
weechat_hook_signal ("config_reload", &irc_config_reload_cb, NULL);
weechat_hook_signal ("quit", &irc_quit_cb, NULL);
weechat_hook_signal ("debug", &irc_debug_cb, NULL);
@@ -213,8 +212,11 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
*/
int
weechat_plugin_end ()
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
/* make C compiler happy */
(void) plugin;
irc_config_write ();
irc_server_disconnect_all ();