mirror of
https://github.com/weechat/weechat.git
synced 2026-06-28 13:56:37 +02:00
Secured code to prevent buffer overflows and memory leaks
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2004-01-21
|
||||
ChangeLog - 2004-01-24
|
||||
|
||||
|
||||
Version 0.0.5 (under dev!):
|
||||
* secured code to prevent buffer overflows and memory leaks
|
||||
* fixed QUIT IRC command: now sent to all connected servers (not only current)
|
||||
* new Perl script function to display message in info bar ("IRC::print_infobar")
|
||||
* info bar highlight notifications
|
||||
|
||||
+199
-174
File diff suppressed because it is too large
Load Diff
+106
-74
@@ -84,7 +84,7 @@ t_weechat_command weechat_commands[] =
|
||||
0, 1, weechat_cmd_save, NULL },
|
||||
{ "set", N_("set config parameters"),
|
||||
N_("[option [value]]"), N_("option: name of an option\nvalue: value for option"),
|
||||
0, 2, weechat_cmd_set, NULL },
|
||||
0, 2, NULL, weechat_cmd_set },
|
||||
{ "unalias", N_("remove an alias"),
|
||||
N_("alias_name"), N_("alias_name: name of alias to remove"),
|
||||
1, 1, NULL, weechat_cmd_unalias },
|
||||
@@ -207,14 +207,14 @@ index_command_build ()
|
||||
i = 0;
|
||||
while (weechat_commands[i].command_name)
|
||||
{
|
||||
index_command_new (weechat_commands[i].command_name);
|
||||
(void) index_command_new (weechat_commands[i].command_name);
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while (irc_commands[i].command_name)
|
||||
{
|
||||
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
|
||||
index_command_new (irc_commands[i].command_name);
|
||||
(void) index_command_new (irc_commands[i].command_name);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -363,8 +363,11 @@ alias_new (char *alias_name, char *alias_command)
|
||||
{
|
||||
new_alias->alias_name = strdup (alias_name);
|
||||
new_alias->alias_command = (char *)malloc (strlen (alias_command) + 2);
|
||||
new_alias->alias_command[0] = '/';
|
||||
strcpy (new_alias->alias_command + 1, alias_command);
|
||||
if (new_alias->alias_command)
|
||||
{
|
||||
new_alias->alias_command[0] = '/';
|
||||
strcpy (new_alias->alias_command + 1, alias_command);
|
||||
}
|
||||
alias_insert_sorted (new_alias);
|
||||
return new_alias;
|
||||
}
|
||||
@@ -409,7 +412,7 @@ alias_free (t_weechat_alias *alias)
|
||||
*/
|
||||
|
||||
char **
|
||||
explode_string (char *string, char *separators, int num_items_max,
|
||||
explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
|
||||
int *num_items)
|
||||
{
|
||||
int i, n_items;
|
||||
@@ -502,7 +505,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
char *command, *pos, *ptr_args, **argv, *alias_command;
|
||||
t_weechat_alias *ptr_alias;
|
||||
|
||||
if ((!string[0]) || (string[0] != '/'))
|
||||
if ((!string) || (!string[0]) || (string[0] != '/'))
|
||||
return 0;
|
||||
|
||||
command = strdup (string);
|
||||
@@ -645,14 +648,18 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
length1 = strlen (ptr_alias->alias_command);
|
||||
length2 = strlen (ptr_args);
|
||||
alias_command = (char *)malloc (length1 + 1 + length2 + 1);
|
||||
strcpy (alias_command, ptr_alias->alias_command);
|
||||
alias_command[length1] = ' ';
|
||||
strcpy (alias_command + length1 + 1, ptr_args);
|
||||
exec_weechat_command (server, alias_command);
|
||||
free (alias_command);
|
||||
if (alias_command)
|
||||
{
|
||||
strcpy (alias_command, ptr_alias->alias_command);
|
||||
alias_command[length1] = ' ';
|
||||
strcpy (alias_command + length1 + 1, ptr_args);
|
||||
}
|
||||
(void) exec_weechat_command (server, alias_command);
|
||||
if (alias_command)
|
||||
free (alias_command);
|
||||
}
|
||||
else
|
||||
exec_weechat_command (server, ptr_alias->alias_command);
|
||||
(void) exec_weechat_command (server, ptr_alias->alias_command);
|
||||
|
||||
if (argv)
|
||||
{
|
||||
@@ -694,7 +701,7 @@ user_command (t_irc_server *server, char *command)
|
||||
if ((command[0] == '/') && (command[1] != '/'))
|
||||
{
|
||||
/* WeeChat internal command (or IRC command) */
|
||||
exec_weechat_command (server, command);
|
||||
(void) exec_weechat_command (server, command);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -772,7 +779,7 @@ weechat_cmd_alias (char *arguments)
|
||||
}
|
||||
if (!alias_new (arguments, pos))
|
||||
return -1;
|
||||
index_command_new (arguments);
|
||||
(void) index_command_new (arguments);
|
||||
gui_printf (NULL, _("Alias \"%s\" => \"%s\" created\n"),
|
||||
arguments, pos);
|
||||
}
|
||||
@@ -851,7 +858,10 @@ weechat_cmd_connect (int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
if (!ptr_server->window)
|
||||
gui_window_new (ptr_server, NULL, 1);
|
||||
{
|
||||
if (!gui_window_new (ptr_server, NULL, 1))
|
||||
return -1;
|
||||
}
|
||||
if (server_connect (ptr_server))
|
||||
{
|
||||
irc_login (ptr_server);
|
||||
@@ -994,7 +1004,7 @@ weechat_cmd_perl (int argc, char **argv)
|
||||
#ifdef PLUGINS
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
int handler_found;
|
||||
int handler_found, path_length;
|
||||
char *path_script;
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
@@ -1085,10 +1095,11 @@ weechat_cmd_perl (int argc, char **argv)
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
path_script = (char *) malloc ((strlen (weechat_home) +
|
||||
strlen (argv[1]) + 7) * sizeof (char));
|
||||
sprintf (path_script, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "perl", DIR_SEPARATOR, argv[1]);
|
||||
path_length = strlen (weechat_home) + strlen (argv[1]) + 7;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
snprintf (path_script, path_length, "%s%s%s%s%s",
|
||||
weechat_home, DIR_SEPARATOR, "perl",
|
||||
DIR_SEPARATOR, argv[1]);
|
||||
}
|
||||
plugin_load (PLUGIN_TYPE_PERL,
|
||||
(path_script) ? path_script : argv[1]);
|
||||
@@ -1430,7 +1441,7 @@ weechat_cmd_server (int argc, char **argv)
|
||||
|
||||
if (new_server->autoconnect)
|
||||
{
|
||||
gui_window_new (new_server, NULL, 1);
|
||||
(void) gui_window_new (new_server, NULL, 1);
|
||||
if (server_connect (new_server))
|
||||
irc_login (new_server);
|
||||
}
|
||||
@@ -1445,72 +1456,93 @@ weechat_cmd_server (int argc, char **argv)
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_cmd_set (int argc, char **argv)
|
||||
weechat_cmd_set (char *arguments)
|
||||
{
|
||||
char *option, *value;
|
||||
int i, j, section_displayed;
|
||||
char *color_name;
|
||||
|
||||
/* TODO: complete /set command */
|
||||
for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
|
||||
option = NULL;
|
||||
value = NULL;
|
||||
if (arguments && arguments[0])
|
||||
{
|
||||
section_displayed = 0;
|
||||
if ((i != CONFIG_SECTION_ALIAS) && (i != CONFIG_SECTION_SERVER))
|
||||
option = arguments;
|
||||
value = strchr (option, ' ');
|
||||
if (value)
|
||||
{
|
||||
for (j = 0; weechat_options[i][j].option_name; j++)
|
||||
value[0] = '\0';
|
||||
value++;
|
||||
while (value[0] == ' ')
|
||||
value++;
|
||||
}
|
||||
}
|
||||
|
||||
if (value && value[0])
|
||||
{
|
||||
gui_printf (NULL, "TODO: set value!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
|
||||
{
|
||||
section_displayed = 0;
|
||||
if ((i != CONFIG_SECTION_ALIAS) && (i != CONFIG_SECTION_SERVER))
|
||||
{
|
||||
if ((argc == 0) ||
|
||||
((argc > 0)
|
||||
&& (strstr (weechat_options[i][j].option_name, argv[0])
|
||||
!= NULL)))
|
||||
for (j = 0; weechat_options[i][j].option_name; j++)
|
||||
{
|
||||
if (!section_displayed)
|
||||
if ((!option) ||
|
||||
((option) && (option[0])
|
||||
&& (strstr (weechat_options[i][j].option_name, option)
|
||||
!= NULL)))
|
||||
{
|
||||
gui_printf (NULL, "[%s]\n",
|
||||
config_sections[i].section_name);
|
||||
section_displayed = 1;
|
||||
}
|
||||
switch (weechat_options[i][j].option_type)
|
||||
{
|
||||
case OPTION_TYPE_BOOLEAN:
|
||||
gui_printf (NULL, " %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
(*weechat_options[i][j].ptr_int) ?
|
||||
"ON" : "OFF");
|
||||
break;
|
||||
case OPTION_TYPE_INT:
|
||||
gui_printf (NULL,
|
||||
" %s = %d\n",
|
||||
weechat_options[i][j].option_name,
|
||||
*weechat_options[i][j].ptr_int);
|
||||
break;
|
||||
case OPTION_TYPE_INT_WITH_STRING:
|
||||
gui_printf (NULL,
|
||||
" %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
weechat_options[i][j].array_values[*weechat_options[i][j].ptr_int]);
|
||||
break;
|
||||
case OPTION_TYPE_COLOR:
|
||||
color_name = gui_get_color_by_value (*weechat_options[i][j].ptr_int);
|
||||
gui_printf (NULL,
|
||||
" %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
(color_name) ? color_name : _("(unknown)"));
|
||||
break;
|
||||
case OPTION_TYPE_STRING:
|
||||
gui_printf (NULL, " %s = %s\n",
|
||||
weechat_options[i][j].
|
||||
option_name,
|
||||
(*weechat_options[i][j].
|
||||
ptr_string) ?
|
||||
*weechat_options[i][j].
|
||||
ptr_string : "");
|
||||
break;
|
||||
if (!section_displayed)
|
||||
{
|
||||
gui_printf (NULL, "[%s]\n",
|
||||
config_sections[i].section_name);
|
||||
section_displayed = 1;
|
||||
}
|
||||
switch (weechat_options[i][j].option_type)
|
||||
{
|
||||
case OPTION_TYPE_BOOLEAN:
|
||||
gui_printf (NULL, " %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
(*weechat_options[i][j].ptr_int) ?
|
||||
"ON" : "OFF");
|
||||
break;
|
||||
case OPTION_TYPE_INT:
|
||||
gui_printf (NULL,
|
||||
" %s = %d\n",
|
||||
weechat_options[i][j].option_name,
|
||||
*weechat_options[i][j].ptr_int);
|
||||
break;
|
||||
case OPTION_TYPE_INT_WITH_STRING:
|
||||
gui_printf (NULL,
|
||||
" %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
weechat_options[i][j].array_values[*weechat_options[i][j].ptr_int]);
|
||||
break;
|
||||
case OPTION_TYPE_COLOR:
|
||||
color_name = gui_get_color_by_value (*weechat_options[i][j].ptr_int);
|
||||
gui_printf (NULL,
|
||||
" %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
(color_name) ? color_name : _("(unknown)"));
|
||||
break;
|
||||
case OPTION_TYPE_STRING:
|
||||
gui_printf (NULL, " %s = %s\n",
|
||||
weechat_options[i][j].
|
||||
option_name,
|
||||
(*weechat_options[i][j].
|
||||
ptr_string) ?
|
||||
*weechat_options[i][j].
|
||||
ptr_string : "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
gui_printf (NULL, "(TODO) \"/set\" command not fully developed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ extern int weechat_cmd_help (int, char **);
|
||||
extern int weechat_cmd_perl (int, char **);
|
||||
extern int weechat_cmd_save (int, char **);
|
||||
extern int weechat_cmd_server (int, char **);
|
||||
extern int weechat_cmd_set (int, char **);
|
||||
extern int weechat_cmd_set (char *);
|
||||
extern int weechat_cmd_unalias (char *);
|
||||
|
||||
#endif /* command.h */
|
||||
|
||||
+61
-34
@@ -97,10 +97,13 @@ wee_log_printf (char *message, ...)
|
||||
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
fprintf (log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
|
||||
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
|
||||
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
|
||||
buffer);
|
||||
if (date_tmp)
|
||||
fprintf (log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
|
||||
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
|
||||
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
|
||||
buffer);
|
||||
else
|
||||
fprintf (log_file, "[????-??-?? ??:??:??] %s", buffer);
|
||||
fflush (log_file);
|
||||
}
|
||||
|
||||
@@ -195,26 +198,26 @@ wee_parse_args (int argc, char *argv[])
|
||||
|| (strcmp (argv[i], "--config") == 0))
|
||||
{
|
||||
wee_display_config_options ();
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else if ((strcmp (argv[i], "-h") == 0)
|
||||
|| (strcmp (argv[i], "--help") == 0))
|
||||
{
|
||||
printf ("\n" WEE_USAGE1, argv[0]);
|
||||
printf ("%s", WEE_USAGE2);
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else if ((strcmp (argv[i], "-l") == 0)
|
||||
|| (strcmp (argv[i], "--license") == 0))
|
||||
{
|
||||
printf ("\n%s%s", WEE_LICENSE);
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else if ((strcmp (argv[i], "-v") == 0)
|
||||
|| (strcmp (argv[i], "--version") == 0))
|
||||
{
|
||||
printf (PACKAGE_VERSION "\n");
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else if ((strncasecmp (argv[i], "irc://", 6) == 0))
|
||||
{
|
||||
@@ -278,51 +281,75 @@ wee_create_dir (char *directory)
|
||||
void
|
||||
wee_create_home_dirs ()
|
||||
{
|
||||
char *dir_name;
|
||||
char *ptr_home, *dir_name;
|
||||
int dir_length;
|
||||
|
||||
/* TODO: rewrite this code for Windows version */
|
||||
ptr_home = getenv ("HOME");
|
||||
if (!ptr_home)
|
||||
{
|
||||
fprintf (stderr, _("%s unable to get HOME directory\n"),
|
||||
WEECHAT_ERROR);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
dir_length = strlen (ptr_home) + 10;
|
||||
weechat_home =
|
||||
(char *) malloc ((strlen (getenv ("HOME")) + 10) * sizeof (char));
|
||||
sprintf (weechat_home, "%s%s.weechat", getenv ("HOME"), DIR_SEPARATOR);
|
||||
(char *) malloc (dir_length * sizeof (char));
|
||||
if (!weechat_home)
|
||||
{
|
||||
fprintf (stderr, _("%s not enough memory for home directory\n"),
|
||||
WEECHAT_ERROR);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home,
|
||||
DIR_SEPARATOR);
|
||||
|
||||
/* create home directory "~/.weechat" ; error is fatal */
|
||||
if (!wee_create_dir (weechat_home))
|
||||
exit (1);
|
||||
{
|
||||
fprintf (stderr, _("%s unable to create ~/.weechat directory\n"),
|
||||
WEECHAT_ERROR);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
dir_name = (char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
dir_length = strlen (weechat_home) + 64;
|
||||
dir_name = (char *) malloc (dir_length * sizeof (char));
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
/* create "~/.weechat/perl" */
|
||||
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "perl");
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"perl");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/perl/autoload" */
|
||||
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "perl",
|
||||
DIR_SEPARATOR, "autoload");
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "perl", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_PYTHON
|
||||
/* create "~/.weechat/python" */
|
||||
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "python");
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"python");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/python/autoload" */
|
||||
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "python",
|
||||
DIR_SEPARATOR, "autoload");
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "python", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_RUBY
|
||||
/* create "~/.weechat/ruby" */
|
||||
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "ruby");
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"ruby");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/ruby/autoload" */
|
||||
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "ruby",
|
||||
DIR_SEPARATOR, "autoload");
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "ruby", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
@@ -352,18 +379,17 @@ wee_init_vars ()
|
||||
void
|
||||
wee_init_log ()
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
sprintf (filename, "%s/" WEECHAT_LOG_NAME, weechat_home);
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
snprintf (filename, filename_length, "%s/" WEECHAT_LOG_NAME, weechat_home);
|
||||
if ((log_file = fopen (filename, "wt")) == NULL)
|
||||
{
|
||||
free (filename);
|
||||
fprintf (stderr,
|
||||
_("%s unable to create/append to log file (~/.weechat/%s)"),
|
||||
WEECHAT_ERROR, WEECHAT_LOG_NAME);
|
||||
}
|
||||
WEECHAT_WARNING, WEECHAT_LOG_NAME);
|
||||
free (filename);
|
||||
}
|
||||
|
||||
@@ -418,7 +444,7 @@ wee_shutdown ()
|
||||
gui_end ();
|
||||
if (log_file)
|
||||
fclose (log_file);
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -448,12 +474,13 @@ main (int argc, char *argv[])
|
||||
break;
|
||||
case -1: /* config file not found */
|
||||
if (config_create_default () < 0)
|
||||
return 1;
|
||||
config_read ();
|
||||
return EXIT_FAILURE;
|
||||
if (config_read () != 0)
|
||||
return EXIT_FAILURE;
|
||||
break;
|
||||
default: /* other error (fatal) */
|
||||
server_free_all ();
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
gui_init (); /* init WeeChat interface */
|
||||
@@ -466,8 +493,8 @@ main (int argc, char *argv[])
|
||||
|
||||
plugin_end (); /* end plugin interface(s) */
|
||||
server_disconnect_all (); /* disconnect from all servers */
|
||||
config_write (NULL); /* save config file */
|
||||
(void) config_write (NULL); /* save config file */
|
||||
wee_shutdown (); /* quit WeeChat (oh no, why?) */
|
||||
|
||||
return 0; /* make gcc happy (never executed) */
|
||||
return EXIT_SUCCESS; /* make gcc happy (never executed) */
|
||||
}
|
||||
|
||||
+21
-6
@@ -754,15 +754,20 @@ config_default_values ()
|
||||
int
|
||||
config_read ()
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
FILE *file;
|
||||
int section, line_number, i, option_number;
|
||||
int server_found;
|
||||
char line[1024], *ptr_line, *pos, *pos2;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
if (!filename)
|
||||
return -2;
|
||||
snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME,
|
||||
weechat_home, DIR_SEPARATOR);
|
||||
if ((file = fopen (filename, "rt")) == NULL)
|
||||
{
|
||||
gui_printf (NULL, _("%s config file \"%s\" not found.\n"),
|
||||
@@ -955,6 +960,7 @@ config_read ()
|
||||
int
|
||||
config_create_default ()
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
FILE *file;
|
||||
int i, j;
|
||||
@@ -962,9 +968,13 @@ config_create_default ()
|
||||
struct passwd *my_passwd;
|
||||
char *realname, *pos;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
if (!filename)
|
||||
return -2;
|
||||
snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME,
|
||||
weechat_home, DIR_SEPARATOR);
|
||||
if ((file = fopen (filename, "wt")) == NULL)
|
||||
{
|
||||
gui_printf (NULL, _("%s cannot create file \"%s\"\n"),
|
||||
@@ -1111,6 +1121,7 @@ config_create_default ()
|
||||
int
|
||||
config_write (char *config_name)
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
FILE *file;
|
||||
int i, j;
|
||||
@@ -1122,9 +1133,13 @@ config_write (char *config_name)
|
||||
filename = strdup (config_name);
|
||||
else
|
||||
{
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
if (!filename)
|
||||
return -2;
|
||||
snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME,
|
||||
weechat_home, DIR_SEPARATOR);
|
||||
}
|
||||
|
||||
if ((file = fopen (filename, "wt")) == NULL)
|
||||
|
||||
+2
-2
@@ -203,7 +203,7 @@ extern t_gui_infobar *gui_infobar;
|
||||
/* prototypes */
|
||||
|
||||
/* GUI independent functions */
|
||||
extern t_gui_window *gui_window_new (void *, void *, int /*int, int, int, int*/); /* TODO: add coordinates and size */
|
||||
extern t_gui_window *gui_window_new (/*@null@*/ void *, /*@null@*/ void *, int /*int, int, int, int*/); /* TODO: add coordinates and size */
|
||||
extern void gui_window_clear (t_gui_window *);
|
||||
extern void gui_window_clear_all ();
|
||||
extern void gui_infobar_printf (int, int, char *, ...);
|
||||
@@ -245,7 +245,7 @@ extern void gui_pre_init (int *, char **[]);
|
||||
extern void gui_init ();
|
||||
extern void gui_window_free (t_gui_window *);
|
||||
extern void gui_end ();
|
||||
extern void gui_printf_color_type (t_gui_window *, int, int, char *, ...);
|
||||
extern void gui_printf_color_type (/*@null@*/ t_gui_window *, int, int, char *, ...);
|
||||
extern void gui_main_loop ();
|
||||
|
||||
#endif /* gui.h */
|
||||
|
||||
+19
-11
@@ -183,7 +183,7 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *arguments)
|
||||
_(" has joined "));
|
||||
gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
|
||||
"%s\n", arguments);
|
||||
nick_new (ptr_channel, host, 0, 0, 0);
|
||||
(void) nick_new (ptr_channel, host, 0, 0, 0);
|
||||
gui_redraw_window_nick (gui_current_window);
|
||||
return 0;
|
||||
}
|
||||
@@ -487,7 +487,7 @@ irc_cmd_recv_nick (t_irc_server *server, char *host, char *arguments)
|
||||
ptr_nick = nick_search (ptr_channel, host);
|
||||
if (ptr_nick)
|
||||
{
|
||||
nick_is_me = (strcmp (ptr_nick->nick, server->nick) == 0);
|
||||
nick_is_me = (strcmp (ptr_nick->nick, server->nick) == 0) ? 1 : 0;
|
||||
nick_change (ptr_channel, ptr_nick, arguments);
|
||||
irc_display_prefix (ptr_channel->window, PREFIX_INFO);
|
||||
if (nick_is_me)
|
||||
@@ -867,15 +867,23 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *arguments)
|
||||
if (strcmp (pos, "\01VERSION\01") == 0)
|
||||
{
|
||||
buf = (struct utsname *) malloc (sizeof (struct utsname));
|
||||
uname (buf);
|
||||
server_sendf (server,
|
||||
_("NOTICE %s :%sVERSION %s v%s"
|
||||
" compiled on %s, host \"%s\" is running "
|
||||
"%s %s / %s%s"),
|
||||
host, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
|
||||
&buf->nodename, &buf->sysname,
|
||||
&buf->release, &buf->machine, "\01\r\n");
|
||||
free (buf);
|
||||
if (buf && (uname (buf) == 0))
|
||||
{
|
||||
server_sendf (server,
|
||||
_("NOTICE %s :%sVERSION %s v%s"
|
||||
" compiled on %s, host \"%s\" is running "
|
||||
"%s %s / %s%s"),
|
||||
host, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
|
||||
&buf->nodename, &buf->sysname,
|
||||
&buf->release, &buf->machine, "\01\r\n");
|
||||
free (buf);
|
||||
}
|
||||
else
|
||||
server_sendf (server,
|
||||
_("NOTICE %s :%sVERSION %s v%s"
|
||||
" compiled on %s%s"),
|
||||
host, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
|
||||
"\01\r\n");
|
||||
irc_display_prefix (server->window, PREFIX_INFO);
|
||||
gui_printf_color (server->window,
|
||||
COLOR_WIN_CHAT, _("Received a "));
|
||||
|
||||
@@ -318,7 +318,7 @@ server_send (t_irc_server * server, char *buffer, int size_buf)
|
||||
* server_sendf: send formatted data to irc server
|
||||
*/
|
||||
|
||||
int
|
||||
void
|
||||
server_sendf (t_irc_server * server, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -326,14 +326,14 @@ server_sendf (t_irc_server * server, char *fmt, ...)
|
||||
int size_buf;
|
||||
|
||||
if (!server)
|
||||
return -1;
|
||||
return;
|
||||
|
||||
va_start (args, fmt);
|
||||
size_buf = vsnprintf (buffer, sizeof (buffer) - 1, fmt, args);
|
||||
va_end (args);
|
||||
|
||||
if ((size_buf == 0) || (strcmp (buffer, "\r\n") == 0))
|
||||
return 0;
|
||||
return;
|
||||
|
||||
buffer[sizeof (buffer) - 1] = '\0';
|
||||
if ((size_buf < 0) || (size_buf > (int) (sizeof (buffer) - 1)))
|
||||
@@ -343,7 +343,9 @@ server_sendf (t_irc_server * server, char *fmt, ...)
|
||||
gui_printf (server->window, "[DEBUG] Sending to server >>> %s\n", buffer);
|
||||
#endif
|
||||
buffer[size_buf - 2] = '\r';
|
||||
return server_send (server, buffer, size_buf);
|
||||
if (server_send (server, buffer, size_buf) <= 0)
|
||||
gui_printf (server->window, _("%s error sending data to IRC server\n"),
|
||||
WEECHAT_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+2
-2
@@ -151,7 +151,7 @@ extern void server_free_all ();
|
||||
extern t_irc_server *server_new (char *, int, int, char *, int, char *, char *,
|
||||
char *, char *, char *, char *, char *, char *);
|
||||
extern int server_send (t_irc_server *, char *, int);
|
||||
extern int server_sendf (t_irc_server *, char *, ...);
|
||||
extern void server_sendf (t_irc_server *, char *, ...);
|
||||
extern void server_recv (t_irc_server *);
|
||||
extern int server_connect ();
|
||||
extern void server_auto_connect (int);
|
||||
@@ -182,7 +182,7 @@ extern int nick_get_max_length (t_irc_channel *);
|
||||
|
||||
/* IRC display (irc-diplay.c) */
|
||||
|
||||
extern void irc_display_prefix (t_gui_window *, char *);
|
||||
extern void irc_display_prefix (/*@null@*/ t_gui_window *, char *);
|
||||
extern void irc_display_nick (t_gui_window *, t_irc_nick *, int, int, int, int);
|
||||
extern void irc_display_mode (t_gui_window *, char *, char, char *, char *,
|
||||
char *, char *);
|
||||
|
||||
@@ -61,14 +61,14 @@ extern t_plugin_script *perl_scripts;
|
||||
|
||||
extern void plugin_init ();
|
||||
extern void plugin_load (int, char *);
|
||||
extern void plugin_unload (int, char *);
|
||||
extern void plugin_unload (int, /*@null@*/ char *);
|
||||
extern t_plugin_handler *plugin_handler_search (t_plugin_handler *, char *);
|
||||
extern void plugin_handler_add (t_plugin_handler **, t_plugin_handler **,
|
||||
int, char *, char *);
|
||||
extern void plugin_handler_free_all_type (t_plugin_handler **,
|
||||
t_plugin_handler **, int);
|
||||
extern void plugin_event_msg (char *, char *);
|
||||
extern int plugin_exec_command (char *, char *);
|
||||
extern int plugin_exec_command (char *, /*@null@*/ char *);
|
||||
extern void plugin_end ();
|
||||
|
||||
#endif /* plugins.h */
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
WeeChat - Wee Enhanced Environment for Chat
|
||||
===========================================
|
||||
|
||||
ChangeLog - 2004-01-21
|
||||
ChangeLog - 2004-01-24
|
||||
|
||||
|
||||
Version 0.0.5 (under dev!):
|
||||
* secured code to prevent buffer overflows and memory leaks
|
||||
* fixed QUIT IRC command: now sent to all connected servers (not only current)
|
||||
* new Perl script function to display message in info bar ("IRC::print_infobar")
|
||||
* info bar highlight notifications
|
||||
|
||||
+196
-171
File diff suppressed because it is too large
Load Diff
+199
-174
File diff suppressed because it is too large
Load Diff
+106
-74
@@ -84,7 +84,7 @@ t_weechat_command weechat_commands[] =
|
||||
0, 1, weechat_cmd_save, NULL },
|
||||
{ "set", N_("set config parameters"),
|
||||
N_("[option [value]]"), N_("option: name of an option\nvalue: value for option"),
|
||||
0, 2, weechat_cmd_set, NULL },
|
||||
0, 2, NULL, weechat_cmd_set },
|
||||
{ "unalias", N_("remove an alias"),
|
||||
N_("alias_name"), N_("alias_name: name of alias to remove"),
|
||||
1, 1, NULL, weechat_cmd_unalias },
|
||||
@@ -207,14 +207,14 @@ index_command_build ()
|
||||
i = 0;
|
||||
while (weechat_commands[i].command_name)
|
||||
{
|
||||
index_command_new (weechat_commands[i].command_name);
|
||||
(void) index_command_new (weechat_commands[i].command_name);
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
while (irc_commands[i].command_name)
|
||||
{
|
||||
if (irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
|
||||
index_command_new (irc_commands[i].command_name);
|
||||
(void) index_command_new (irc_commands[i].command_name);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -363,8 +363,11 @@ alias_new (char *alias_name, char *alias_command)
|
||||
{
|
||||
new_alias->alias_name = strdup (alias_name);
|
||||
new_alias->alias_command = (char *)malloc (strlen (alias_command) + 2);
|
||||
new_alias->alias_command[0] = '/';
|
||||
strcpy (new_alias->alias_command + 1, alias_command);
|
||||
if (new_alias->alias_command)
|
||||
{
|
||||
new_alias->alias_command[0] = '/';
|
||||
strcpy (new_alias->alias_command + 1, alias_command);
|
||||
}
|
||||
alias_insert_sorted (new_alias);
|
||||
return new_alias;
|
||||
}
|
||||
@@ -409,7 +412,7 @@ alias_free (t_weechat_alias *alias)
|
||||
*/
|
||||
|
||||
char **
|
||||
explode_string (char *string, char *separators, int num_items_max,
|
||||
explode_string (/*@null@*/ char *string, char *separators, int num_items_max,
|
||||
int *num_items)
|
||||
{
|
||||
int i, n_items;
|
||||
@@ -502,7 +505,7 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
char *command, *pos, *ptr_args, **argv, *alias_command;
|
||||
t_weechat_alias *ptr_alias;
|
||||
|
||||
if ((!string[0]) || (string[0] != '/'))
|
||||
if ((!string) || (!string[0]) || (string[0] != '/'))
|
||||
return 0;
|
||||
|
||||
command = strdup (string);
|
||||
@@ -645,14 +648,18 @@ exec_weechat_command (t_irc_server *server, char *string)
|
||||
length1 = strlen (ptr_alias->alias_command);
|
||||
length2 = strlen (ptr_args);
|
||||
alias_command = (char *)malloc (length1 + 1 + length2 + 1);
|
||||
strcpy (alias_command, ptr_alias->alias_command);
|
||||
alias_command[length1] = ' ';
|
||||
strcpy (alias_command + length1 + 1, ptr_args);
|
||||
exec_weechat_command (server, alias_command);
|
||||
free (alias_command);
|
||||
if (alias_command)
|
||||
{
|
||||
strcpy (alias_command, ptr_alias->alias_command);
|
||||
alias_command[length1] = ' ';
|
||||
strcpy (alias_command + length1 + 1, ptr_args);
|
||||
}
|
||||
(void) exec_weechat_command (server, alias_command);
|
||||
if (alias_command)
|
||||
free (alias_command);
|
||||
}
|
||||
else
|
||||
exec_weechat_command (server, ptr_alias->alias_command);
|
||||
(void) exec_weechat_command (server, ptr_alias->alias_command);
|
||||
|
||||
if (argv)
|
||||
{
|
||||
@@ -694,7 +701,7 @@ user_command (t_irc_server *server, char *command)
|
||||
if ((command[0] == '/') && (command[1] != '/'))
|
||||
{
|
||||
/* WeeChat internal command (or IRC command) */
|
||||
exec_weechat_command (server, command);
|
||||
(void) exec_weechat_command (server, command);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -772,7 +779,7 @@ weechat_cmd_alias (char *arguments)
|
||||
}
|
||||
if (!alias_new (arguments, pos))
|
||||
return -1;
|
||||
index_command_new (arguments);
|
||||
(void) index_command_new (arguments);
|
||||
gui_printf (NULL, _("Alias \"%s\" => \"%s\" created\n"),
|
||||
arguments, pos);
|
||||
}
|
||||
@@ -851,7 +858,10 @@ weechat_cmd_connect (int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
if (!ptr_server->window)
|
||||
gui_window_new (ptr_server, NULL, 1);
|
||||
{
|
||||
if (!gui_window_new (ptr_server, NULL, 1))
|
||||
return -1;
|
||||
}
|
||||
if (server_connect (ptr_server))
|
||||
{
|
||||
irc_login (ptr_server);
|
||||
@@ -994,7 +1004,7 @@ weechat_cmd_perl (int argc, char **argv)
|
||||
#ifdef PLUGINS
|
||||
t_plugin_script *ptr_plugin_script;
|
||||
t_plugin_handler *ptr_plugin_handler;
|
||||
int handler_found;
|
||||
int handler_found, path_length;
|
||||
char *path_script;
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
@@ -1085,10 +1095,11 @@ weechat_cmd_perl (int argc, char **argv)
|
||||
path_script = NULL;
|
||||
else
|
||||
{
|
||||
path_script = (char *) malloc ((strlen (weechat_home) +
|
||||
strlen (argv[1]) + 7) * sizeof (char));
|
||||
sprintf (path_script, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "perl", DIR_SEPARATOR, argv[1]);
|
||||
path_length = strlen (weechat_home) + strlen (argv[1]) + 7;
|
||||
path_script = (char *) malloc (path_length * sizeof (char));
|
||||
snprintf (path_script, path_length, "%s%s%s%s%s",
|
||||
weechat_home, DIR_SEPARATOR, "perl",
|
||||
DIR_SEPARATOR, argv[1]);
|
||||
}
|
||||
plugin_load (PLUGIN_TYPE_PERL,
|
||||
(path_script) ? path_script : argv[1]);
|
||||
@@ -1430,7 +1441,7 @@ weechat_cmd_server (int argc, char **argv)
|
||||
|
||||
if (new_server->autoconnect)
|
||||
{
|
||||
gui_window_new (new_server, NULL, 1);
|
||||
(void) gui_window_new (new_server, NULL, 1);
|
||||
if (server_connect (new_server))
|
||||
irc_login (new_server);
|
||||
}
|
||||
@@ -1445,72 +1456,93 @@ weechat_cmd_server (int argc, char **argv)
|
||||
*/
|
||||
|
||||
int
|
||||
weechat_cmd_set (int argc, char **argv)
|
||||
weechat_cmd_set (char *arguments)
|
||||
{
|
||||
char *option, *value;
|
||||
int i, j, section_displayed;
|
||||
char *color_name;
|
||||
|
||||
/* TODO: complete /set command */
|
||||
for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
|
||||
option = NULL;
|
||||
value = NULL;
|
||||
if (arguments && arguments[0])
|
||||
{
|
||||
section_displayed = 0;
|
||||
if ((i != CONFIG_SECTION_ALIAS) && (i != CONFIG_SECTION_SERVER))
|
||||
option = arguments;
|
||||
value = strchr (option, ' ');
|
||||
if (value)
|
||||
{
|
||||
for (j = 0; weechat_options[i][j].option_name; j++)
|
||||
value[0] = '\0';
|
||||
value++;
|
||||
while (value[0] == ' ')
|
||||
value++;
|
||||
}
|
||||
}
|
||||
|
||||
if (value && value[0])
|
||||
{
|
||||
gui_printf (NULL, "TODO: set value!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
|
||||
{
|
||||
section_displayed = 0;
|
||||
if ((i != CONFIG_SECTION_ALIAS) && (i != CONFIG_SECTION_SERVER))
|
||||
{
|
||||
if ((argc == 0) ||
|
||||
((argc > 0)
|
||||
&& (strstr (weechat_options[i][j].option_name, argv[0])
|
||||
!= NULL)))
|
||||
for (j = 0; weechat_options[i][j].option_name; j++)
|
||||
{
|
||||
if (!section_displayed)
|
||||
if ((!option) ||
|
||||
((option) && (option[0])
|
||||
&& (strstr (weechat_options[i][j].option_name, option)
|
||||
!= NULL)))
|
||||
{
|
||||
gui_printf (NULL, "[%s]\n",
|
||||
config_sections[i].section_name);
|
||||
section_displayed = 1;
|
||||
}
|
||||
switch (weechat_options[i][j].option_type)
|
||||
{
|
||||
case OPTION_TYPE_BOOLEAN:
|
||||
gui_printf (NULL, " %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
(*weechat_options[i][j].ptr_int) ?
|
||||
"ON" : "OFF");
|
||||
break;
|
||||
case OPTION_TYPE_INT:
|
||||
gui_printf (NULL,
|
||||
" %s = %d\n",
|
||||
weechat_options[i][j].option_name,
|
||||
*weechat_options[i][j].ptr_int);
|
||||
break;
|
||||
case OPTION_TYPE_INT_WITH_STRING:
|
||||
gui_printf (NULL,
|
||||
" %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
weechat_options[i][j].array_values[*weechat_options[i][j].ptr_int]);
|
||||
break;
|
||||
case OPTION_TYPE_COLOR:
|
||||
color_name = gui_get_color_by_value (*weechat_options[i][j].ptr_int);
|
||||
gui_printf (NULL,
|
||||
" %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
(color_name) ? color_name : _("(unknown)"));
|
||||
break;
|
||||
case OPTION_TYPE_STRING:
|
||||
gui_printf (NULL, " %s = %s\n",
|
||||
weechat_options[i][j].
|
||||
option_name,
|
||||
(*weechat_options[i][j].
|
||||
ptr_string) ?
|
||||
*weechat_options[i][j].
|
||||
ptr_string : "");
|
||||
break;
|
||||
if (!section_displayed)
|
||||
{
|
||||
gui_printf (NULL, "[%s]\n",
|
||||
config_sections[i].section_name);
|
||||
section_displayed = 1;
|
||||
}
|
||||
switch (weechat_options[i][j].option_type)
|
||||
{
|
||||
case OPTION_TYPE_BOOLEAN:
|
||||
gui_printf (NULL, " %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
(*weechat_options[i][j].ptr_int) ?
|
||||
"ON" : "OFF");
|
||||
break;
|
||||
case OPTION_TYPE_INT:
|
||||
gui_printf (NULL,
|
||||
" %s = %d\n",
|
||||
weechat_options[i][j].option_name,
|
||||
*weechat_options[i][j].ptr_int);
|
||||
break;
|
||||
case OPTION_TYPE_INT_WITH_STRING:
|
||||
gui_printf (NULL,
|
||||
" %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
weechat_options[i][j].array_values[*weechat_options[i][j].ptr_int]);
|
||||
break;
|
||||
case OPTION_TYPE_COLOR:
|
||||
color_name = gui_get_color_by_value (*weechat_options[i][j].ptr_int);
|
||||
gui_printf (NULL,
|
||||
" %s = %s\n",
|
||||
weechat_options[i][j].option_name,
|
||||
(color_name) ? color_name : _("(unknown)"));
|
||||
break;
|
||||
case OPTION_TYPE_STRING:
|
||||
gui_printf (NULL, " %s = %s\n",
|
||||
weechat_options[i][j].
|
||||
option_name,
|
||||
(*weechat_options[i][j].
|
||||
ptr_string) ?
|
||||
*weechat_options[i][j].
|
||||
ptr_string : "");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
gui_printf (NULL, "(TODO) \"/set\" command not fully developed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ extern int weechat_cmd_help (int, char **);
|
||||
extern int weechat_cmd_perl (int, char **);
|
||||
extern int weechat_cmd_save (int, char **);
|
||||
extern int weechat_cmd_server (int, char **);
|
||||
extern int weechat_cmd_set (int, char **);
|
||||
extern int weechat_cmd_set (char *);
|
||||
extern int weechat_cmd_unalias (char *);
|
||||
|
||||
#endif /* command.h */
|
||||
|
||||
@@ -97,10 +97,13 @@ wee_log_printf (char *message, ...)
|
||||
|
||||
seconds = time (NULL);
|
||||
date_tmp = localtime (&seconds);
|
||||
fprintf (log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
|
||||
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
|
||||
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
|
||||
buffer);
|
||||
if (date_tmp)
|
||||
fprintf (log_file, "[%04d-%02d-%02d %02d:%02d:%02d] %s",
|
||||
date_tmp->tm_year + 1900, date_tmp->tm_mon + 1, date_tmp->tm_mday,
|
||||
date_tmp->tm_hour, date_tmp->tm_min, date_tmp->tm_sec,
|
||||
buffer);
|
||||
else
|
||||
fprintf (log_file, "[????-??-?? ??:??:??] %s", buffer);
|
||||
fflush (log_file);
|
||||
}
|
||||
|
||||
@@ -195,26 +198,26 @@ wee_parse_args (int argc, char *argv[])
|
||||
|| (strcmp (argv[i], "--config") == 0))
|
||||
{
|
||||
wee_display_config_options ();
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else if ((strcmp (argv[i], "-h") == 0)
|
||||
|| (strcmp (argv[i], "--help") == 0))
|
||||
{
|
||||
printf ("\n" WEE_USAGE1, argv[0]);
|
||||
printf ("%s", WEE_USAGE2);
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else if ((strcmp (argv[i], "-l") == 0)
|
||||
|| (strcmp (argv[i], "--license") == 0))
|
||||
{
|
||||
printf ("\n%s%s", WEE_LICENSE);
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else if ((strcmp (argv[i], "-v") == 0)
|
||||
|| (strcmp (argv[i], "--version") == 0))
|
||||
{
|
||||
printf (PACKAGE_VERSION "\n");
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
else if ((strncasecmp (argv[i], "irc://", 6) == 0))
|
||||
{
|
||||
@@ -278,51 +281,75 @@ wee_create_dir (char *directory)
|
||||
void
|
||||
wee_create_home_dirs ()
|
||||
{
|
||||
char *dir_name;
|
||||
char *ptr_home, *dir_name;
|
||||
int dir_length;
|
||||
|
||||
/* TODO: rewrite this code for Windows version */
|
||||
ptr_home = getenv ("HOME");
|
||||
if (!ptr_home)
|
||||
{
|
||||
fprintf (stderr, _("%s unable to get HOME directory\n"),
|
||||
WEECHAT_ERROR);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
dir_length = strlen (ptr_home) + 10;
|
||||
weechat_home =
|
||||
(char *) malloc ((strlen (getenv ("HOME")) + 10) * sizeof (char));
|
||||
sprintf (weechat_home, "%s%s.weechat", getenv ("HOME"), DIR_SEPARATOR);
|
||||
(char *) malloc (dir_length * sizeof (char));
|
||||
if (!weechat_home)
|
||||
{
|
||||
fprintf (stderr, _("%s not enough memory for home directory\n"),
|
||||
WEECHAT_ERROR);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home,
|
||||
DIR_SEPARATOR);
|
||||
|
||||
/* create home directory "~/.weechat" ; error is fatal */
|
||||
if (!wee_create_dir (weechat_home))
|
||||
exit (1);
|
||||
{
|
||||
fprintf (stderr, _("%s unable to create ~/.weechat directory\n"),
|
||||
WEECHAT_ERROR);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
dir_name = (char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
dir_length = strlen (weechat_home) + 64;
|
||||
dir_name = (char *) malloc (dir_length * sizeof (char));
|
||||
|
||||
#ifdef PLUGIN_PERL
|
||||
/* create "~/.weechat/perl" */
|
||||
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "perl");
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"perl");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/perl/autoload" */
|
||||
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "perl",
|
||||
DIR_SEPARATOR, "autoload");
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "perl", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_PYTHON
|
||||
/* create "~/.weechat/python" */
|
||||
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "python");
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"python");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/python/autoload" */
|
||||
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "python",
|
||||
DIR_SEPARATOR, "autoload");
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "python", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PLUGIN_RUBY
|
||||
/* create "~/.weechat/ruby" */
|
||||
sprintf (dir_name, "%s%s%s", weechat_home, DIR_SEPARATOR, "ruby");
|
||||
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
|
||||
"ruby");
|
||||
if (wee_create_dir (dir_name))
|
||||
{
|
||||
/* create "~/.weechat/ruby/autoload" */
|
||||
sprintf (dir_name, "%s%s%s%s%s", weechat_home, DIR_SEPARATOR, "ruby",
|
||||
DIR_SEPARATOR, "autoload");
|
||||
snprintf (dir_name, dir_length, "%s%s%s%s%s", weechat_home,
|
||||
DIR_SEPARATOR, "ruby", DIR_SEPARATOR, "autoload");
|
||||
wee_create_dir (dir_name);
|
||||
}
|
||||
#endif
|
||||
@@ -352,18 +379,17 @@ wee_init_vars ()
|
||||
void
|
||||
wee_init_log ()
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
sprintf (filename, "%s/" WEECHAT_LOG_NAME, weechat_home);
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
snprintf (filename, filename_length, "%s/" WEECHAT_LOG_NAME, weechat_home);
|
||||
if ((log_file = fopen (filename, "wt")) == NULL)
|
||||
{
|
||||
free (filename);
|
||||
fprintf (stderr,
|
||||
_("%s unable to create/append to log file (~/.weechat/%s)"),
|
||||
WEECHAT_ERROR, WEECHAT_LOG_NAME);
|
||||
}
|
||||
WEECHAT_WARNING, WEECHAT_LOG_NAME);
|
||||
free (filename);
|
||||
}
|
||||
|
||||
@@ -418,7 +444,7 @@ wee_shutdown ()
|
||||
gui_end ();
|
||||
if (log_file)
|
||||
fclose (log_file);
|
||||
exit (0);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -448,12 +474,13 @@ main (int argc, char *argv[])
|
||||
break;
|
||||
case -1: /* config file not found */
|
||||
if (config_create_default () < 0)
|
||||
return 1;
|
||||
config_read ();
|
||||
return EXIT_FAILURE;
|
||||
if (config_read () != 0)
|
||||
return EXIT_FAILURE;
|
||||
break;
|
||||
default: /* other error (fatal) */
|
||||
server_free_all ();
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
gui_init (); /* init WeeChat interface */
|
||||
@@ -466,8 +493,8 @@ main (int argc, char *argv[])
|
||||
|
||||
plugin_end (); /* end plugin interface(s) */
|
||||
server_disconnect_all (); /* disconnect from all servers */
|
||||
config_write (NULL); /* save config file */
|
||||
(void) config_write (NULL); /* save config file */
|
||||
wee_shutdown (); /* quit WeeChat (oh no, why?) */
|
||||
|
||||
return 0; /* make gcc happy (never executed) */
|
||||
return EXIT_SUCCESS; /* make gcc happy (never executed) */
|
||||
}
|
||||
|
||||
@@ -754,15 +754,20 @@ config_default_values ()
|
||||
int
|
||||
config_read ()
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
FILE *file;
|
||||
int section, line_number, i, option_number;
|
||||
int server_found;
|
||||
char line[1024], *ptr_line, *pos, *pos2;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
if (!filename)
|
||||
return -2;
|
||||
snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME,
|
||||
weechat_home, DIR_SEPARATOR);
|
||||
if ((file = fopen (filename, "rt")) == NULL)
|
||||
{
|
||||
gui_printf (NULL, _("%s config file \"%s\" not found.\n"),
|
||||
@@ -955,6 +960,7 @@ config_read ()
|
||||
int
|
||||
config_create_default ()
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
FILE *file;
|
||||
int i, j;
|
||||
@@ -962,9 +968,13 @@ config_create_default ()
|
||||
struct passwd *my_passwd;
|
||||
char *realname, *pos;
|
||||
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
if (!filename)
|
||||
return -2;
|
||||
snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME,
|
||||
weechat_home, DIR_SEPARATOR);
|
||||
if ((file = fopen (filename, "wt")) == NULL)
|
||||
{
|
||||
gui_printf (NULL, _("%s cannot create file \"%s\"\n"),
|
||||
@@ -1111,6 +1121,7 @@ config_create_default ()
|
||||
int
|
||||
config_write (char *config_name)
|
||||
{
|
||||
int filename_length;
|
||||
char *filename;
|
||||
FILE *file;
|
||||
int i, j;
|
||||
@@ -1122,9 +1133,13 @@ config_write (char *config_name)
|
||||
filename = strdup (config_name);
|
||||
else
|
||||
{
|
||||
filename_length = strlen (weechat_home) + 64;
|
||||
filename =
|
||||
(char *) malloc ((strlen (weechat_home) + 64) * sizeof (char));
|
||||
sprintf (filename, "%s%s" WEECHAT_CONFIG_NAME, weechat_home, DIR_SEPARATOR);
|
||||
(char *) malloc (filename_length * sizeof (char));
|
||||
if (!filename)
|
||||
return -2;
|
||||
snprintf (filename, filename_length, "%s%s" WEECHAT_CONFIG_NAME,
|
||||
weechat_home, DIR_SEPARATOR);
|
||||
}
|
||||
|
||||
if ((file = fopen (filename, "wt")) == NULL)
|
||||
|
||||
@@ -203,7 +203,7 @@ extern t_gui_infobar *gui_infobar;
|
||||
/* prototypes */
|
||||
|
||||
/* GUI independent functions */
|
||||
extern t_gui_window *gui_window_new (void *, void *, int /*int, int, int, int*/); /* TODO: add coordinates and size */
|
||||
extern t_gui_window *gui_window_new (/*@null@*/ void *, /*@null@*/ void *, int /*int, int, int, int*/); /* TODO: add coordinates and size */
|
||||
extern void gui_window_clear (t_gui_window *);
|
||||
extern void gui_window_clear_all ();
|
||||
extern void gui_infobar_printf (int, int, char *, ...);
|
||||
@@ -245,7 +245,7 @@ extern void gui_pre_init (int *, char **[]);
|
||||
extern void gui_init ();
|
||||
extern void gui_window_free (t_gui_window *);
|
||||
extern void gui_end ();
|
||||
extern void gui_printf_color_type (t_gui_window *, int, int, char *, ...);
|
||||
extern void gui_printf_color_type (/*@null@*/ t_gui_window *, int, int, char *, ...);
|
||||
extern void gui_main_loop ();
|
||||
|
||||
#endif /* gui.h */
|
||||
|
||||
+19
-11
@@ -183,7 +183,7 @@ irc_cmd_recv_join (t_irc_server *server, char *host, char *arguments)
|
||||
_(" has joined "));
|
||||
gui_printf_color (ptr_channel->window, COLOR_WIN_CHAT_CHANNEL,
|
||||
"%s\n", arguments);
|
||||
nick_new (ptr_channel, host, 0, 0, 0);
|
||||
(void) nick_new (ptr_channel, host, 0, 0, 0);
|
||||
gui_redraw_window_nick (gui_current_window);
|
||||
return 0;
|
||||
}
|
||||
@@ -487,7 +487,7 @@ irc_cmd_recv_nick (t_irc_server *server, char *host, char *arguments)
|
||||
ptr_nick = nick_search (ptr_channel, host);
|
||||
if (ptr_nick)
|
||||
{
|
||||
nick_is_me = (strcmp (ptr_nick->nick, server->nick) == 0);
|
||||
nick_is_me = (strcmp (ptr_nick->nick, server->nick) == 0) ? 1 : 0;
|
||||
nick_change (ptr_channel, ptr_nick, arguments);
|
||||
irc_display_prefix (ptr_channel->window, PREFIX_INFO);
|
||||
if (nick_is_me)
|
||||
@@ -867,15 +867,23 @@ irc_cmd_recv_privmsg (t_irc_server *server, char *host, char *arguments)
|
||||
if (strcmp (pos, "\01VERSION\01") == 0)
|
||||
{
|
||||
buf = (struct utsname *) malloc (sizeof (struct utsname));
|
||||
uname (buf);
|
||||
server_sendf (server,
|
||||
_("NOTICE %s :%sVERSION %s v%s"
|
||||
" compiled on %s, host \"%s\" is running "
|
||||
"%s %s / %s%s"),
|
||||
host, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
|
||||
&buf->nodename, &buf->sysname,
|
||||
&buf->release, &buf->machine, "\01\r\n");
|
||||
free (buf);
|
||||
if (buf && (uname (buf) == 0))
|
||||
{
|
||||
server_sendf (server,
|
||||
_("NOTICE %s :%sVERSION %s v%s"
|
||||
" compiled on %s, host \"%s\" is running "
|
||||
"%s %s / %s%s"),
|
||||
host, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
|
||||
&buf->nodename, &buf->sysname,
|
||||
&buf->release, &buf->machine, "\01\r\n");
|
||||
free (buf);
|
||||
}
|
||||
else
|
||||
server_sendf (server,
|
||||
_("NOTICE %s :%sVERSION %s v%s"
|
||||
" compiled on %s%s"),
|
||||
host, "\01", PACKAGE_NAME, PACKAGE_VERSION, __DATE__,
|
||||
"\01\r\n");
|
||||
irc_display_prefix (server->window, PREFIX_INFO);
|
||||
gui_printf_color (server->window,
|
||||
COLOR_WIN_CHAT, _("Received a "));
|
||||
|
||||
@@ -318,7 +318,7 @@ server_send (t_irc_server * server, char *buffer, int size_buf)
|
||||
* server_sendf: send formatted data to irc server
|
||||
*/
|
||||
|
||||
int
|
||||
void
|
||||
server_sendf (t_irc_server * server, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -326,14 +326,14 @@ server_sendf (t_irc_server * server, char *fmt, ...)
|
||||
int size_buf;
|
||||
|
||||
if (!server)
|
||||
return -1;
|
||||
return;
|
||||
|
||||
va_start (args, fmt);
|
||||
size_buf = vsnprintf (buffer, sizeof (buffer) - 1, fmt, args);
|
||||
va_end (args);
|
||||
|
||||
if ((size_buf == 0) || (strcmp (buffer, "\r\n") == 0))
|
||||
return 0;
|
||||
return;
|
||||
|
||||
buffer[sizeof (buffer) - 1] = '\0';
|
||||
if ((size_buf < 0) || (size_buf > (int) (sizeof (buffer) - 1)))
|
||||
@@ -343,7 +343,9 @@ server_sendf (t_irc_server * server, char *fmt, ...)
|
||||
gui_printf (server->window, "[DEBUG] Sending to server >>> %s\n", buffer);
|
||||
#endif
|
||||
buffer[size_buf - 2] = '\r';
|
||||
return server_send (server, buffer, size_buf);
|
||||
if (server_send (server, buffer, size_buf) <= 0)
|
||||
gui_printf (server->window, _("%s error sending data to IRC server\n"),
|
||||
WEECHAT_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -151,7 +151,7 @@ extern void server_free_all ();
|
||||
extern t_irc_server *server_new (char *, int, int, char *, int, char *, char *,
|
||||
char *, char *, char *, char *, char *, char *);
|
||||
extern int server_send (t_irc_server *, char *, int);
|
||||
extern int server_sendf (t_irc_server *, char *, ...);
|
||||
extern void server_sendf (t_irc_server *, char *, ...);
|
||||
extern void server_recv (t_irc_server *);
|
||||
extern int server_connect ();
|
||||
extern void server_auto_connect (int);
|
||||
@@ -182,7 +182,7 @@ extern int nick_get_max_length (t_irc_channel *);
|
||||
|
||||
/* IRC display (irc-diplay.c) */
|
||||
|
||||
extern void irc_display_prefix (t_gui_window *, char *);
|
||||
extern void irc_display_prefix (/*@null@*/ t_gui_window *, char *);
|
||||
extern void irc_display_nick (t_gui_window *, t_irc_nick *, int, int, int, int);
|
||||
extern void irc_display_mode (t_gui_window *, char *, char, char *, char *,
|
||||
char *, char *);
|
||||
|
||||
@@ -61,14 +61,14 @@ extern t_plugin_script *perl_scripts;
|
||||
|
||||
extern void plugin_init ();
|
||||
extern void plugin_load (int, char *);
|
||||
extern void plugin_unload (int, char *);
|
||||
extern void plugin_unload (int, /*@null@*/ char *);
|
||||
extern t_plugin_handler *plugin_handler_search (t_plugin_handler *, char *);
|
||||
extern void plugin_handler_add (t_plugin_handler **, t_plugin_handler **,
|
||||
int, char *, char *);
|
||||
extern void plugin_handler_free_all_type (t_plugin_handler **,
|
||||
t_plugin_handler **, int);
|
||||
extern void plugin_event_msg (char *, char *);
|
||||
extern int plugin_exec_command (char *, char *);
|
||||
extern int plugin_exec_command (char *, /*@null@*/ char *);
|
||||
extern void plugin_end ();
|
||||
|
||||
#endif /* plugins.h */
|
||||
|
||||
Reference in New Issue
Block a user