api: return allocated string in hook_info callback and function info_get

v2.8-utf8proc
Sébastien Helleu 2019-04-12 21:29:39 +02:00
parent c80dc2a5ca
commit 3d95217745
54 changed files with 724 additions and 526 deletions

View File

@ -23,6 +23,7 @@ New features::
* core: use seconds by default in /repeat interval, allow unit for the interval
* core: allow text in addition to a command in command /repeat
* core: add option "addreplace" in command /filter (issue #1055, issue #1312)
* api: return allocated string in hook_info callback and function info_get
* api: replace argument "keep_eol" by "flags" in function string_split (issue #1322)
* api: add function command_options (issue #928)
* api: add function string_match_list

View File

@ -20,6 +20,17 @@ https://weechat.org/files/changelog/ChangeLog-devel.html[ChangeLog]
[[v2.5]]
== Version 2.5 (under dev)
[[v2.5_hook_info_allocated_string]]
=== Allocated string in hook info and function info_get
The hook info callback now returns an allocated string, which must be freed
after use (in previous versions, a pointer to a static string was returned).
Consequently, the function info_get returns an allocated string, which must
be freed after use.
This affects only C code, no changes are required in scripts.
[[v2.5_xfer_option_speed_limit]]
=== Speed limit option for DCC files

View File

@ -11267,7 +11267,7 @@ weechat.hook_modifier_exec("my_modifier", my_data, my_string)
==== hook_info
_Updated in 1.5._
_Updated in 1.5, 2.5._
Hook an information (callback takes and returns a string).
@ -11278,10 +11278,10 @@ Prototype:
struct t_hook *weechat_hook_info (const char *info_name,
const char *description,
const char *args_description,
const char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
const void *callback_pointer,
void *callback_data);
----
@ -11307,16 +11307,20 @@ Return value:
* pointer to new hook, NULL if error occurred
[NOTE]
With WeeChat ≥ 2.5, the callback returns an allocated string
(with WeeChat ≤ 2.4, it was a pointer to a static string).
C example:
[source,C]
----
const char *
char *
my_info_cb (const void *pointer, void *data, const char *info_name,
const char *arguments)
{
/* ... */
return pointer_to_string;
return strdup ("some_info");
}
/* add info "my_info" */
@ -14589,13 +14593,15 @@ Functions to get infos.
==== info_get
_Updated in 2.5._
Return info, as string, from WeeChat or a plugin.
Prototype:
[source,C]
----
const char *weechat_info_get (const char *info_name, const char *arguments);
char *weechat_info_get (const char *info_name, const char *arguments);
----
Arguments:
@ -14608,6 +14614,10 @@ Return value:
* string with info asked, NULL if an error occurred
[NOTE]
With WeeChat ≥ 2.5, the value returned is an allocated string
(with WeeChat ≤ 2.4, it was a pointer to a static string).
Infos:
include::autogen/plugin_api/infos.adoc[]
@ -14616,11 +14626,19 @@ C example:
[source,C]
----
char *version = weechat_info_get ("version", NULL);
char *date = weechat_info_get ("date", NULL);
weechat_printf (NULL, "Current WeeChat version is: %s (compiled on %s)",
weechat_info_get ("version", NULL),
weechat_info_get ("date", NULL));
weechat_printf (NULL, "WeeChat home is: %s",
weechat_info_get ("weechat_dir", NULL));
version, date);
if (version)
free (version);
if (date)
free (date);
char *weechat_dir = weechat_info_get ("weechat_dir", NULL);
weechat_printf (NULL, "WeeChat home is: %s", weechat_dir);
if (weechat_dir)
free (weechat_dir);
----
Script (Python):

View File

@ -11507,7 +11507,7 @@ weechat.hook_modifier_exec("mon_modifier", mes_donnees, ma_chaine)
==== hook_info
_Mis à jour dans la 1.5._
_Mis à jour dans la 1.5, 2.5._
Accrocher une information (la fonction de rappel prend et retourne une chaîne).
@ -11518,10 +11518,10 @@ Prototype :
struct t_hook *weechat_hook_info (const char *info_name,
const char *description,
const char *args_description,
const char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
const void *callback_pointer,
void *callback_data);
----
@ -11551,16 +11551,20 @@ Valeur de retour :
* pointeur vers le nouveau "hook", NULL en cas d'erreur
[NOTE]
Avec WeeChat ≥ 2.5, la fonction de rappel renvoie une chaîne allouée
(avec WeeChat ≤ 2.4, il s'agissait d'un pointeur vers une chaîne statique).
Exemple en C :
[source,C]
----
const char *
char *
my_info_cb (const void *pointer, void *data, const char *info_name,
const char *arguments)
{
/* ... */
return pointeur_vers_chaine;
return strdup ("some_info");
}
/* ajoute l'information "mon_info" */
@ -14904,13 +14908,15 @@ Fonctions pour obtenir des informations.
==== info_get
_Mis à jour dans la 2.5._
Retourner une information, sous forme de chaîne, de WeeChat ou d'une extension.
Prototype :
[source,C]
----
const char *weechat_info_get (const char *info_name, const char *arguments);
char *weechat_info_get (const char *info_name, const char *arguments);
----
Paramètres :
@ -14923,6 +14929,10 @@ Valeur de retour :
* chaîne avec l'information demandée, NULL en cas d'erreur
[NOTE]
Avec WeeChat ≥ 2.5, la valeur retournée est une chaîne allouée
(avec WeeChat ≤ 2.4, il s'agissait d'un pointeur vers une chaîne statique).
Infos :
include::autogen/plugin_api/infos.adoc[]
@ -14931,11 +14941,19 @@ Exemple en C :
[source,C]
----
char *version = weechat_info_get ("version", NULL);
char *date = weechat_info_get ("date", NULL);
weechat_printf (NULL, "La version de WeeChat est : %s (compilée le %s)",
weechat_info_get ("version", NULL),
weechat_info_get ("date", NULL));
weechat_printf (NULL, "Le répertoire de WeeChat est : %s",
weechat_info_get ("weechat_dir", NULL));
version, date);
if (version)
free (version);
if (date)
free (date);
weechat_dir = weechat_info_get ("weechat_dir", NULL);
weechat_printf (NULL, "Le répertoire de WeeChat est : %s", weechat_dir);
if (weechat_dir)
free (weechat_dir);
----
Script (Python) :

View File

@ -11723,7 +11723,7 @@ weechat.hook_modifier_exec("my_modifier", my_data, my_string)
==== hook_info
// TRANSLATION MISSING
_Updated in 1.5._
_Updated in 1.5, 2.5._
Hook su una informazione (la callback prende e restituisce una stringa).
@ -11734,10 +11734,10 @@ Prototipo:
struct t_hook *weechat_hook_info (const char *info_name,
const char *description,
const char *args_description,
const char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
const void *callback_pointer,
void *callback_data);
----
@ -11766,16 +11766,21 @@ Valore restituito:
* puntatore al nuovo hook, NULL in caso di errore
// TRANSLATION MISSING
[NOTE]
With WeeChat ≥ 2.5, the callback returns an allocated string
(with WeeChat ≤ 2.4, it was a pointer to a static string).
Esempio in C:
[source,C]
----
const char *
char *
my_info_cb (const void *pointer, void *data, const char *info_name,
const char *arguments)
{
/* ... */
return pointer_to_string;
return strdup ("some_info");
}
/* aggiunge informazione "my_info" */
@ -15180,13 +15185,16 @@ Funzioni per ottenere info.
==== info_get
// TRANSLATION MISSING
_Updated in 2.5._
Restituisce la info, come stringa, da WeeChat o da un plugin.
Prototipo:
[source,C]
----
const char *weechat_info_get (const char *info_name, const char *arguments);
char *weechat_info_get (const char *info_name, const char *arguments);
----
Argomenti:
@ -15200,6 +15208,11 @@ Valore restituito:
* stringa con l'informazione richiesta, NULL in caso di errore
// TRANSLATION MISSING
[NOTE]
With WeeChat ≥ 2.5, the value returned is an allocated string
(with WeeChat ≤ 2.4, it was a pointer to a static string).
// TRANSLATION MISSING
Infos:
@ -15209,11 +15222,19 @@ Esempio in C:
[source,C]
----
char *version = weechat_info_get ("version", NULL);
char *date = weechat_info_get ("date", NULL);
weechat_printf (NULL, "Current WeeChat version is: %s (compiled on %s)",
weechat_info_get ("version", NULL),
weechat_info_get ("date", NULL));
weechat_printf (NULL, "WeeChat home is: %s",
weechat_info_get ("weechat_dir", NULL));
version, date);
if (version)
free (version);
if (date)
free (date);
char *weechat_dir = weechat_info_get ("weechat_dir", NULL);
weechat_printf (NULL, "WeeChat home is: %s", weechat_dir);
if (weechat_dir)
free (weechat_dir);
----
Script (Python):

View File

@ -11229,7 +11229,7 @@ weechat.hook_modifier_exec("my_modifier", my_data, my_string)
==== hook_info
_WeeChat バージョン 1.5 で更新。_
_WeeChat バージョン 1.5, 2.5 で更新。_
インフォをフック (コールバックを呼び出し、文字列を返す)。
@ -11240,10 +11240,10 @@ _WeeChat バージョン 1.5 で更新。_
struct t_hook *weechat_hook_info (const char *info_name,
const char *description,
const char *args_description,
const char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
const void *callback_pointer,
void *callback_data);
----
@ -11269,16 +11269,21 @@ struct t_hook *weechat_hook_info (const char *info_name,
* 新しいフックへのポインタ、エラーが起きた場合は NULL
// TRANSLATION MISSING
[NOTE]
With WeeChat ≥ 2.5, the callback returns an allocated string
(with WeeChat ≤ 2.4, it was a pointer to a static string).
C 言語での使用例:
[source,C]
----
const char *
char *
my_info_cb (const void *pointer, void *data, const char *info_name,
const char *arguments)
{
/* ... */
return pointer_to_string;
return strdup ("some_info");
}
/* add info "my_info" */
@ -14549,13 +14554,15 @@ else
==== info_get
_WeeChat バージョン 2.5 で更新。_
文字列型で WeeChat またはプラグインからのインフォを返す。
プロトタイプ:
[source,C]
----
const char *weechat_info_get (const char *info_name, const char *arguments);
char *weechat_info_get (const char *info_name, const char *arguments);
----
引数:
@ -14568,6 +14575,11 @@ const char *weechat_info_get (const char *info_name, const char *arguments);
* 指定したインフォを含む文字列、エラーが起きた場合は NULL
// TRANSLATION MISSING
[NOTE]
With WeeChat ≥ 2.5, the value returned is an allocated string
(with WeeChat ≤ 2.4, it was a pointer to a static string).
インフォ:
include::autogen/plugin_api/infos.adoc[]
@ -14576,11 +14588,19 @@ C 言語での使用例:
[source,C]
----
char *version = weechat_info_get ("version", NULL);
char *date = weechat_info_get ("date", NULL);
weechat_printf (NULL, "Current WeeChat version is: %s (compiled on %s)",
weechat_info_get ("version", NULL),
weechat_info_get ("date", NULL));
weechat_printf (NULL, "WeeChat home is: %s",
weechat_info_get ("weechat_dir", NULL));
version, date);
if (version)
free (version);
if (date)
free (date);
char *weechat_dir = weechat_info_get ("weechat_dir", NULL);
weechat_printf (NULL, "WeeChat home is: %s", weechat_dir);
if (weechat_dir)
free (weechat_dir);
----
スクリプト (Python) での使用例:

View File

@ -83,14 +83,16 @@ hook_info (struct t_weechat_plugin *plugin, const char *info_name,
/*
* Gets info (as string) via info hook.
*
* Note: result must be freed after use.
*/
const char *
char *
hook_info_get (struct t_weechat_plugin *plugin, const char *info_name,
const char *arguments)
{
struct t_hook *ptr_hook, *next_hook;
const char *value;
char *value;
/* make C compiler happy */
(void) plugin;

View File

@ -25,9 +25,9 @@ struct t_infolist_item;
#define HOOK_INFO(hook, var) (((struct t_hook_info *)hook->hook_data)->var)
typedef const char *(t_hook_callback_info)(const void *pointer, void *data,
const char *info_name,
const char *arguments);
typedef char *(t_hook_callback_info)(const void *pointer, void *data,
const char *info_name,
const char *arguments);
struct t_hook_info
{
@ -44,9 +44,9 @@ extern struct t_hook *hook_info (struct t_weechat_plugin *plugin,
t_hook_callback_info *callback,
const void *callback_pointer,
void *callback_data);
extern const char *hook_info_get (struct t_weechat_plugin *plugin,
const char *info_name,
const char *arguments);
extern char *hook_info_get (struct t_weechat_plugin *plugin,
const char *info_name,
const char *arguments);
extern void hook_info_free_data (struct t_hook *hook);
extern int hook_info_add_to_infolist (struct t_infolist_item *item,
struct t_hook *hook);

View File

@ -520,7 +520,7 @@ eval_replace_vars_cb (void *data, const char *text)
/* 10. info */
if (strncmp (text, "info:", 5) == 0)
{
ptr_value = NULL;
value = NULL;
ptr_arguments = strchr (text + 5, ',');
if (ptr_arguments)
{
@ -531,10 +531,10 @@ eval_replace_vars_cb (void *data, const char *text)
info_name = strdup (text + 5);
if (info_name)
{
ptr_value = hook_info_get (NULL, info_name, ptr_arguments);
value = hook_info_get (NULL, info_name, ptr_arguments);
free (info_name);
}
return strdup ((ptr_value) ? ptr_value : "");
return (value) ? value : strdup ("");
}
/* 11. current date/time */

View File

@ -50,8 +50,8 @@ struct t_config_option *charset_default_encode = NULL;
struct t_config_section *charset_config_section_decode = NULL;
struct t_config_section *charset_config_section_encode = NULL;
const char *charset_terminal = NULL;
const char *charset_internal = NULL;
char *charset_terminal = NULL;
char *charset_internal = NULL;
/*
@ -641,5 +641,10 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
weechat_config_free (charset_config_file);
if (charset_terminal)
free (charset_terminal);
if (charset_internal)
free (charset_internal);
return WEECHAT_RC_OK;
}

View File

@ -20,6 +20,7 @@
*/
#include <stdlib.h>
#include <string.h>
#include "../weechat-plugin.h"
#include "fifo.h"
@ -29,7 +30,7 @@
* Returns FIFO info "fifo_filename".
*/
const char *
char *
fifo_info_info_fifo_filename_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -40,7 +41,7 @@ fifo_info_info_fifo_filename_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return fifo_filename;
return (fifo_filename) ? strdup (fifo_filename) : NULL;
}
/*

View File

@ -1522,7 +1522,7 @@ fset_option_config_cb (const void *pointer,
const char *option,
const char *value)
{
const char *ptr_info;
char *info;
/* make C compiler happy */
(void) pointer;
@ -1534,9 +1534,14 @@ fset_option_config_cb (const void *pointer,
return WEECHAT_RC_OK;
/* do nothing if WeeChat is upgrading */
ptr_info = weechat_info_get ("weechat_upgrading", NULL);
if (ptr_info && (strcmp (ptr_info, "1") == 0))
info = weechat_info_get ("weechat_upgrading", NULL);
if (info && (strcmp (info, "1") == 0))
{
free (info);
return WEECHAT_RC_OK;
}
if (info)
free (info);
/*
* we limit the number of options to display with the timer; for example

View File

@ -57,8 +57,6 @@
plugin_script_str2ptr (weechat_guile_plugin, \
GUILE_CURRENT_SCRIPT_NAME, \
guile_function_name, __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&guile_data, __string);
#define API_SCM_TO_STRING(__str) \
weechat_guile_api_scm_to_string(__str, \
guile_strings, &guile_num_strings)
@ -2940,14 +2938,14 @@ weechat_guile_api_hook_modifier_exec (SCM modifier, SCM modifier_data,
API_RETURN_STRING_FREE(result);
}
const char *
char *
weechat_guile_api_hook_info_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' }, *result;
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
@ -2959,12 +2957,10 @@ weechat_guile_api_hook_info_cb (const void *pointer, void *data,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
result = (char *)weechat_guile_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
return API_STATIC_STRING(result);
return (char *)weechat_guile_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
}
return NULL;
@ -4107,7 +4103,7 @@ weechat_guile_api_command_options (SCM buffer, SCM command, SCM options)
SCM
weechat_guile_api_info_get (SCM info_name, SCM arguments)
{
const char *result;
char *result;
SCM return_value;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
@ -4117,7 +4113,7 @@ weechat_guile_api_info_get (SCM info_name, SCM arguments)
result = weechat_info_get (API_SCM_TO_STRING(info_name),
API_SCM_TO_STRING(arguments));
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
SCM

View File

@ -59,7 +59,6 @@ int guile_eval_mode = 0;
int guile_eval_send_input = 0;
int guile_eval_exec_commands = 0;
struct t_gui_buffer *guile_eval_buffer = NULL;
char *guile_eval_output = NULL;
#define GUILE_EVAL_SCRIPT \
"(weechat:register \"" WEECHAT_SCRIPT_EVAL_NAME "\" \"\" \"1.0\" " \
"\"" WEECHAT_LICENSE "\" \"Evaluation of source code\" " \
@ -968,23 +967,23 @@ weechat_guile_hdata_cb (const void *pointer, void *data,
* Returns guile info "guile_eval".
*/
const char *
char *
weechat_guile_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *output;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
weechat_guile_eval (NULL, 0, 0, (arguments) ? arguments : "");
if (guile_eval_output)
free (guile_eval_output);
guile_eval_output = strdup (*guile_buffer_output);
output = strdup (*guile_buffer_output);
weechat_string_dyn_copy (guile_buffer_output, NULL);
return guile_eval_output;
return output;
}
/*
@ -1272,8 +1271,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (guile_action_autoload_list)
free (guile_action_autoload_list);
weechat_string_dyn_free (guile_buffer_output, 1);
if (guile_eval_output)
free (guile_eval_output);
return WEECHAT_RC_OK;
}

View File

@ -408,8 +408,7 @@ irc_color_encode (const char *string, int keep_colors)
int
irc_color_convert_rgb2irc (int rgb)
{
char str_color[64], *error;
const char *info_color;
char str_color[64], *error, *info_color;
long number;
snprintf (str_color, sizeof (str_color),
@ -419,16 +418,23 @@ irc_color_convert_rgb2irc (int rgb)
info_color = weechat_info_get ("color_rgb2term", str_color);
if (!info_color || !info_color[0])
{
if (info_color)
free (info_color);
return -1;
}
error = NULL;
number = strtol (info_color, &error, 10);
if (!error || error[0]
|| (number < 0) || (number >= IRC_COLOR_TERM2IRC_NUM_COLORS))
{
free (info_color);
return -1;
}
free (info_color);
return irc_color_term2irc[number];
}
@ -441,20 +447,28 @@ irc_color_convert_rgb2irc (int rgb)
int
irc_color_convert_term2irc (int color)
{
char str_color[64], *error;
const char *info_color;
char str_color[64], *error, *info_color;
long number;
snprintf (str_color, sizeof (str_color), "%d", color);
info_color = weechat_info_get ("color_term2rgb", str_color);
if (!info_color || !info_color[0])
{
if (info_color)
free (info_color);
return -1;
}
error = NULL;
number = strtol (info_color, &error, 10);
if (!error || error[0] || (number < 0) || (number > 0xFFFFFF))
{
free (info_color);
return -1;
}
free (info_color);
return irc_color_convert_rgb2irc (number);
}
@ -740,6 +754,7 @@ char *
irc_color_decode_ansi (const char *string, int keep_colors)
{
struct t_irc_color_ansi_state ansi_state;
char *ansi_regex;
/* allocate/compile regex if needed (first call) */
if (!irc_color_regex_ansi)
@ -747,14 +762,19 @@ irc_color_decode_ansi (const char *string, int keep_colors)
irc_color_regex_ansi = malloc (sizeof (*irc_color_regex_ansi));
if (!irc_color_regex_ansi)
return NULL;
ansi_regex = weechat_info_get ("color_ansi_regex", NULL);
if (weechat_string_regcomp (irc_color_regex_ansi,
weechat_info_get ("color_ansi_regex", NULL),
ansi_regex,
REG_EXTENDED) != 0)
{
if (ansi_regex)
free (ansi_regex);
free (irc_color_regex_ansi);
irc_color_regex_ansi = NULL;
return NULL;
}
if (ansi_regex)
free (ansi_regex);
}
ansi_state.keep_colors = keep_colors;

View File

@ -213,7 +213,7 @@ irc_config_compute_nick_colors ()
{
if (ptr_nick->color)
free (ptr_nick->color);
ptr_nick->color = strdup (irc_nick_find_color (ptr_nick->name));
ptr_nick->color = irc_nick_find_color (ptr_nick->name);
}
}
if (ptr_channel->pv_remote_nick_color)

View File

@ -328,8 +328,7 @@ irc_ctcp_reply_to_nick (struct t_irc_server *server,
char *
irc_ctcp_replace_variables (struct t_irc_server *server, const char *format)
{
char *res, *temp, *username, *realname;
const char *info;
char *res, *temp, *username, *realname, *info, *info2;
time_t now;
struct tm *local_time;
char buf[4096];
@ -354,6 +353,8 @@ irc_ctcp_replace_variables (struct t_irc_server *server, const char *format)
info = weechat_info_get ("version_git", "");
temp = weechat_string_replace (res, "$git", info);
free (res);
if (info)
free (info);
if (!temp)
return NULL;
res = temp;
@ -365,13 +366,18 @@ irc_ctcp_replace_variables (struct t_irc_server *server, const char *format)
* 0.4.0-dev (git: v0.3.9-104-g7eb5cc4)
*/
info = weechat_info_get ("version_git", "");
info2 = weechat_info_get ("version", "");
snprintf (buf, sizeof (buf), "%s%s%s%s",
weechat_info_get ("version", ""),
info2,
(info && info[0]) ? " (git: " : "",
(info && info[0]) ? info : "",
(info && info[0]) ? ")" : "");
temp = weechat_string_replace (res, "$versiongit", buf);
free (res);
if (info)
free (info);
if (info2)
free (info2);
if (!temp)
return NULL;
res = temp;
@ -384,6 +390,8 @@ irc_ctcp_replace_variables (struct t_irc_server *server, const char *format)
info = weechat_info_get ("version", "");
temp = weechat_string_replace (res, "$version", info);
free (res);
if (info)
free (info);
if (!temp)
return NULL;
res = temp;
@ -395,6 +403,8 @@ irc_ctcp_replace_variables (struct t_irc_server *server, const char *format)
info = weechat_info_get ("date", "");
temp = weechat_string_replace (res, "$compilation", info);
free (res);
if (info)
free (info);
if (!temp)
return NULL;
res = temp;
@ -430,6 +440,8 @@ irc_ctcp_replace_variables (struct t_irc_server *server, const char *format)
info = weechat_info_get ("weechat_site", "");
temp = weechat_string_replace (res, "$site", info);
free (res);
if (info)
free (info);
if (!temp)
return NULL;
res = temp;
@ -441,6 +453,8 @@ irc_ctcp_replace_variables (struct t_irc_server *server, const char *format)
info = weechat_info_get ("weechat_site_download", "");
temp = weechat_string_replace (res, "$download", info);
free (res);
if (info)
free (info);
if (!temp)
return NULL;
res = temp;
@ -974,7 +988,7 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
const char *nick, const char *remote_nick, char *arguments,
char *message)
{
char *pos_end, *pos_space, *pos_args;
char *pos_end, *pos_space, *pos_args, *nick_color;
const char *reply;
char *decoded_reply;
struct t_irc_channel *ptr_channel;
@ -1014,6 +1028,12 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
irc_channel_nick_speaking_time_remove_old (channel);
irc_channel_nick_speaking_time_add (server, channel, nick,
time (NULL));
if (ptr_nick)
nick_color = strdup (ptr_nick->color);
else if (nick)
nick_color = irc_nick_find_color (nick);
else
nick_color = strdup (IRC_COLOR_CHAT_NICK);
weechat_printf_date_tags (
channel->buffer,
date,
@ -1026,11 +1046,13 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date, const char *command,
"%s%s%s%s%s%s%s",
weechat_prefix ("action"),
irc_nick_mode_for_display (server, ptr_nick, 0),
(ptr_nick) ? ptr_nick->color : ((nick) ? irc_nick_find_color (nick) : IRC_COLOR_CHAT_NICK),
nick_color,
nick,
(pos_args) ? IRC_COLOR_RESET : "",
(pos_args) ? " " : "",
(pos_args) ? pos_args : "");
if (nick_color)
free (nick_color);
}
else
{

View File

@ -64,14 +64,13 @@ irc_info_create_string_with_pointer (char **string, void *pointer)
* Returns IRC info "irc_is_channel".
*/
const char *
char *
irc_info_info_irc_is_channel_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *pos_comma, *server;
const char *pos_channel;
static char str_true[2] = "1";
struct t_irc_server *ptr_server;
/* make C compiler happy */
@ -92,37 +91,36 @@ irc_info_info_irc_is_channel_cb (const void *pointer, void *data,
free (server);
}
}
if (irc_channel_is_channel (ptr_server, pos_channel))
return str_true;
return NULL;
return (irc_channel_is_channel (ptr_server, pos_channel)) ?
strdup ("1") : NULL;
}
/*
* Returns IRC info "irc_is_nick".
*/
const char *
char *
irc_info_info_irc_is_nick_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char str_true[2] = "1";
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
if (arguments && arguments[0] && irc_nick_is_nick (arguments))
return str_true;
return NULL;
if (!arguments || !arguments[0])
return NULL;
return (irc_nick_is_nick (arguments)) ? strdup ("1") : NULL;
}
/*
* Returns IRC info "irc_nick".
*/
const char *
char *
irc_info_info_irc_nick_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -138,35 +136,40 @@ irc_info_info_irc_nick_cb (const void *pointer, void *data,
return NULL;
ptr_server = irc_server_search (arguments);
if (ptr_server)
return ptr_server->nick;
return NULL;
return (ptr_server && ptr_server->nick) ?
strdup (ptr_server->nick) : NULL;
}
/*
* Returns IRC info "irc_nick_from_host".
*/
const char *
char *
irc_info_info_irc_nick_from_host_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
const char *ptr_host;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
return (arguments && arguments[0]) ?
irc_message_get_nick_from_host (arguments) : NULL;
if (!arguments || !arguments[0])
return NULL;
ptr_host = irc_message_get_nick_from_host (arguments);
return (ptr_host) ? strdup (ptr_host) : NULL;
}
/*
* Returns IRC info "irc_nick_color".
*/
const char *
char *
irc_info_info_irc_nick_color_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -176,15 +179,17 @@ irc_info_info_irc_nick_color_cb (const void *pointer, void *data,
(void) data;
(void) info_name;
return (arguments && arguments[0]) ?
irc_nick_find_color (arguments) : NULL;
if (!arguments || !arguments[0])
return NULL;
return irc_nick_find_color (arguments);
}
/*
* Returns IRC info "irc_nick_color_name".
*/
const char *
char *
irc_info_info_irc_nick_color_name_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -194,15 +199,17 @@ irc_info_info_irc_nick_color_name_cb (const void *pointer, void *data,
(void) data;
(void) info_name;
return (arguments && arguments[0]) ?
irc_nick_find_color_name (arguments) : NULL;
if (!arguments || !arguments[0])
return NULL;
return irc_nick_find_color_name (arguments);
}
/*
* Returns IRC info "irc_buffer".
*/
const char *
char *
irc_info_info_irc_buffer_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -281,14 +288,18 @@ irc_info_info_irc_buffer_cb (const void *pointer, void *data,
{
irc_info_create_string_with_pointer (&ptr_channel->buffer_as_string,
ptr_channel->buffer);
return ptr_channel->buffer_as_string;
return (ptr_channel->buffer_as_string) ?
strdup (ptr_channel->buffer_as_string) : NULL;
}
if (ptr_server)
{
irc_info_create_string_with_pointer (&ptr_server->buffer_as_string,
ptr_server->buffer);
return ptr_server->buffer_as_string;
return (ptr_server->buffer_as_string) ?
strdup (ptr_server->buffer_as_string) : NULL;
}
return NULL;
}
@ -296,14 +307,13 @@ irc_info_info_irc_buffer_cb (const void *pointer, void *data,
* Returns IRC info "irc_server_isupport".
*/
const char *
char *
irc_info_info_irc_server_isupport_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *pos_comma, *server;
const char *isupport_value;
static char str_true[2] = "1";
struct t_irc_server *ptr_server;
/* make C compiler happy */
@ -326,14 +336,15 @@ irc_info_info_irc_server_isupport_cb (const void *pointer, void *data,
}
}
}
return (isupport_value) ? str_true : NULL;
return (isupport_value) ? strdup ("1") : NULL;
}
/*
* Returns IRC info "irc_server_isupport_value".
*/
const char *
char *
irc_info_info_irc_server_isupport_value_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -362,7 +373,8 @@ irc_info_info_irc_server_isupport_value_cb (const void *pointer, void *data,
}
}
}
return isupport_value;
return (isupport_value) ? strdup (isupport_value) : NULL;
}
/*

View File

@ -98,7 +98,7 @@ irc_nick_is_nick (const char *string)
* Returns a WeeChat color code (that can be used for display).
*/
const char *
char *
irc_nick_find_color (const char *nickname)
{
return weechat_info_get ("nick_color", nickname);
@ -110,7 +110,7 @@ irc_nick_find_color (const char *nickname)
* Returns the name of a color (for example: "green").
*/
const char *
char *
irc_nick_find_color_name (const char *nickname)
{
return weechat_info_get ("nick_color_name", nickname);
@ -309,7 +309,7 @@ irc_nick_get_prefix_color_name (struct t_irc_server *server, char prefix)
* Gets nick color for nicklist.
*/
const char *
char *
irc_nick_get_color_for_nicklist (struct t_irc_server *server,
struct t_irc_nick *nick)
{
@ -318,17 +318,17 @@ irc_nick_get_color_for_nicklist (struct t_irc_server *server,
static char *nick_color_away = "weechat.color.nicklist_away";
if (nick->away)
return nick_color_away;
return strdup (nick_color_away);
if (weechat_config_boolean (irc_config_look_color_nicks_in_nicklist))
{
if (irc_server_strcasecmp (server, nick->name, server->nick) == 0)
return nick_color_self;
return strdup (nick_color_self);
else
return irc_nick_find_color_name (nick->name);
}
return nick_color_bar_fg;
return strdup (nick_color_bar_fg);
}
/*
@ -341,14 +341,18 @@ irc_nick_nicklist_add (struct t_irc_server *server,
struct t_irc_nick *nick)
{
struct t_gui_nick_group *ptr_group;
char *color;
ptr_group = irc_nick_get_nicklist_group (server, channel->buffer, nick);
color = irc_nick_get_color_for_nicklist (server, nick);
weechat_nicklist_add_nick (channel->buffer, ptr_group,
nick->name,
irc_nick_get_color_for_nicklist (server, nick),
color,
nick->prefix,
irc_nick_get_prefix_color_name (server, nick->prefix[0]),
1);
if (color)
free (color);
}
/*
@ -425,6 +429,7 @@ irc_nick_nicklist_set_color_all ()
struct t_irc_server *ptr_server;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
char *color;
for (ptr_server = irc_servers; ptr_server;
ptr_server = ptr_server->next_server)
@ -435,9 +440,10 @@ irc_nick_nicklist_set_color_all ()
for (ptr_nick = ptr_channel->nicks; ptr_nick;
ptr_nick = ptr_nick->next_nick)
{
irc_nick_nicklist_set (ptr_channel, ptr_nick, "color",
irc_nick_get_color_for_nicklist (ptr_server,
ptr_nick));
color = irc_nick_get_color_for_nicklist (ptr_server, ptr_nick);
irc_nick_nicklist_set (ptr_channel, ptr_nick, "color", color);
if (color)
free (color);
}
}
}
@ -517,7 +523,7 @@ irc_nick_new (struct t_irc_server *server, struct t_irc_channel *channel,
if (irc_server_strcasecmp (server, new_nick->name, server->nick) == 0)
new_nick->color = strdup (IRC_COLOR_CHAT_NICK_SELF);
else
new_nick->color = strdup (irc_nick_find_color (new_nick->name));
new_nick->color = irc_nick_find_color (new_nick->name);
/* add nick to end of list */
new_nick->prev_nick = channel->last_nick;
@ -566,7 +572,7 @@ irc_nick_change (struct t_irc_server *server, struct t_irc_channel *channel,
if (nick_is_me)
nick->color = strdup (IRC_COLOR_CHAT_NICK_SELF);
else
nick->color = strdup (irc_nick_find_color (nick->name));
nick->color = irc_nick_find_color (nick->name);
/* add nick in nicklist */
irc_nick_nicklist_add (server, channel, nick);
@ -749,11 +755,15 @@ void
irc_nick_set_away (struct t_irc_server *server, struct t_irc_channel *channel,
struct t_irc_nick *nick, int is_away)
{
char *color;
if (is_away != nick->away)
{
nick->away = is_away;
irc_nick_nicklist_set (channel, nick, "color",
irc_nick_get_color_for_nicklist (server, nick));
color = irc_nick_get_color_for_nicklist (server, nick);
irc_nick_nicklist_set (channel, nick, "color", color);
if (color)
free (color);
}
}
@ -820,12 +830,25 @@ irc_nick_as_prefix (struct t_irc_server *server, struct t_irc_nick *nick,
const char *nickname, const char *force_color)
{
static char result[256];
char *color;
if (force_color)
color = strdup (force_color);
else if (nick)
color = strdup (nick->color);
else if (nickname)
color = irc_nick_find_color (nickname);
else
color = strdup (IRC_COLOR_CHAT_NICK);
snprintf (result, sizeof (result), "%s%s%s\t",
irc_nick_mode_for_display (server, nick, 1),
(force_color) ? force_color : ((nick) ? nick->color : ((nickname) ? irc_nick_find_color (nickname) : IRC_COLOR_CHAT_NICK)),
color,
(nick) ? nick->name : nickname);
if (color)
free (color);
return result;
}
@ -837,6 +860,10 @@ const char *
irc_nick_color_for_msg (struct t_irc_server *server, int server_message,
struct t_irc_nick *nick, const char *nickname)
{
static char color[16][64];
static int index_color = 0;
char *color_found;
if (server_message
&& !weechat_config_boolean (irc_config_look_color_nicks_in_server_messages))
{
@ -853,7 +880,14 @@ irc_nick_color_for_msg (struct t_irc_server *server, int server_message,
{
return IRC_COLOR_CHAT_NICK_SELF;
}
return irc_nick_find_color (nickname);
color_found = irc_nick_find_color (nickname);
index_color = (index_color + 1) % 16;
snprintf (color[index_color], sizeof (color[index_color]),
"%s",
color_found);
if (color_found)
free (color_found);
return color[index_color];
}
return IRC_COLOR_CHAT_NICK;
@ -869,7 +903,7 @@ irc_nick_color_for_pv (struct t_irc_channel *channel, const char *nickname)
if (weechat_config_boolean (irc_config_look_color_pv_nick_like_channel))
{
if (!channel->pv_remote_nick_color)
channel->pv_remote_nick_color = strdup (irc_nick_find_color (nickname));
channel->pv_remote_nick_color = irc_nick_find_color (nickname);
if (channel->pv_remote_nick_color)
return channel->pv_remote_nick_color;
}

View File

@ -48,8 +48,8 @@ struct t_irc_nick
extern int irc_nick_valid (struct t_irc_channel *channel,
struct t_irc_nick *nick);
extern int irc_nick_is_nick (const char *string);
extern const char *irc_nick_find_color (const char *nickname);
extern const char *irc_nick_find_color_name (const char *nickname);
extern char *irc_nick_find_color (const char *nickname);
extern char *irc_nick_find_color_name (const char *nickname);
extern int irc_nick_is_op (struct t_irc_server *server,
struct t_irc_nick *nick);
extern int irc_nick_has_prefix_mode (struct t_irc_server *server,

View File

@ -2169,6 +2169,7 @@ IRC_PROTOCOL_CALLBACK(pong)
IRC_PROTOCOL_CALLBACK(privmsg)
{
char *pos_args, *pos_target, str_tags[1024], *str_color, status_msg[2];
char *color;
const char *remote_nick, *pv_tags;
int is_channel, nick_is_me;
struct t_irc_channel *ptr_channel;
@ -2246,8 +2247,10 @@ IRC_PROTOCOL_CALLBACK(privmsg)
else
{
/* standard message (to "#channel") */
str_color = irc_color_for_tags (
irc_nick_find_color_name ((ptr_nick) ? ptr_nick->name : nick));
color = irc_nick_find_color_name ((ptr_nick) ? ptr_nick->name : nick);
str_color = irc_color_for_tags (color);
if (color)
free (color);
snprintf (str_tags, sizeof (str_tags),
"notify_message,prefix_nick_%s",
(str_color) ? str_color : "default");
@ -2318,8 +2321,10 @@ IRC_PROTOCOL_CALLBACK(privmsg)
{
if (weechat_config_boolean (irc_config_look_color_pv_nick_like_channel))
{
str_color = irc_color_for_tags (
irc_nick_find_color_name (nick));
color = irc_nick_find_color_name (nick);
str_color = irc_color_for_tags (color);
if (color)
free (color);
}
else
{
@ -4667,7 +4672,7 @@ IRC_PROTOCOL_CALLBACK(352)
IRC_PROTOCOL_CALLBACK(353)
{
char *pos_channel, *pos_nick, *pos_nick_orig, *pos_host, *nickname;
char *prefixes, *str_nicks;
char *prefixes, *str_nicks, *color;
int args, i, length;
struct t_irc_channel *ptr_channel;
@ -4764,7 +4769,12 @@ IRC_PROTOCOL_CALLBACK(353)
if (irc_server_strcasecmp (server, nickname, server->nick) == 0)
strcat (str_nicks, IRC_COLOR_CHAT_NICK_SELF);
else
strcat (str_nicks, irc_nick_find_color (nickname));
{
color = irc_nick_find_color (nickname);
strcat (str_nicks, color);
if (color)
free (color);
}
}
else
strcat (str_nicks, IRC_COLOR_RESET);
@ -4956,7 +4966,7 @@ IRC_PROTOCOL_CALLBACK(366)
struct t_infolist *infolist;
struct t_config_option *ptr_option;
int num_nicks, num_op, num_halfop, num_voice, num_normal, length, i;
char *string, str_nicks_count[2048];
char *string, str_nicks_count[2048], *color;
const char *prefix, *prefix_color, *nickname;
IRC_PROTOCOL_MIN_ARGS(5);
@ -5029,7 +5039,12 @@ IRC_PROTOCOL_CALLBACK(366)
if (irc_server_strcasecmp (server, nickname, server->nick) == 0)
strcat (string, IRC_COLOR_CHAT_NICK_SELF);
else
strcat (string, irc_nick_find_color (nickname));
{
color = irc_nick_find_color (nickname);
strcat (string, color);
if (color)
free (color);
}
}
else
strcat (string, IRC_COLOR_RESET);

View File

@ -96,8 +96,7 @@ irc_sasl_mechanism_plain (const char *sasl_username, const char *sasl_password)
char *
irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key)
{
const char *weechat_dir;
char *key_path1, *key_path2, *content;
char *weechat_dir, *key_path1, *key_path2, *content;
if (!sasl_key)
return NULL;
@ -122,6 +121,8 @@ irc_sasl_get_key_content (struct t_irc_server *server, const char *sasl_key)
(key_path2) ? key_path2 : ((key_path1) ? key_path1 : sasl_key));
}
if (weechat_dir)
free (weechat_dir);
if (key_path1)
free (key_path1);
if (key_path2)

View File

@ -1228,9 +1228,9 @@ irc_server_get_default_msg (const char *default_msg,
struct t_irc_server *server,
const char *channel_name)
{
const char *version;
char *version;
struct t_hashtable *extra_vars;
char *msg;
char *msg, *res;
/*
* "%v" for version is deprecated since WeeChat 1.6, where
@ -1240,8 +1240,11 @@ irc_server_get_default_msg (const char *default_msg,
if (strstr (default_msg, "%v") && !strstr (default_msg, "${"))
{
version = weechat_info_get ("version", "");
return weechat_string_replace (default_msg, "%v",
(version) ? version : "");
res = weechat_string_replace (default_msg, "%v",
(version) ? version : "");
if (version)
free (version);
return res;
}
extra_vars = weechat_hashtable_new (32,
@ -4344,7 +4347,8 @@ irc_server_gnutls_callback (const void *pointer, void *data,
unsigned int i, cert_list_len, status;
time_t cert_time;
char *cert_path0, *cert_path1, *cert_path2, *cert_str, *fingerprint_eval;
const char *weechat_dir, *ptr_fingerprint;
char *weechat_dir;
const char *ptr_fingerprint;
int rc, ret, fingerprint_match, hostname_match, cert_temp_init;
#if LIBGNUTLS_VERSION_NUMBER >= 0x010706 /* 1.7.6 */
gnutls_datum_t cinfo;
@ -4368,6 +4372,7 @@ irc_server_gnutls_callback (const void *pointer, void *data,
cert_list = NULL;
cert_list_len = 0;
fingerprint_eval = NULL;
weechat_dir = NULL;
if (action == WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT)
{
@ -4702,7 +4707,8 @@ end:
if (cert_temp_init)
gnutls_x509_crt_deinit (cert_temp);
if (weechat_dir)
free (weechat_dir);
if (fingerprint_eval)
free (fingerprint_eval);

View File

@ -95,8 +95,6 @@ extern "C"
plugin_script_str2ptr (weechat_js_plugin, \
JS_CURRENT_SCRIPT_NAME, \
js_function_name.c_str(), __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&js_data, __string);
#define API_RETURN_OK return v8::True();
#define API_RETURN_ERROR return v8::False();
#define API_RETURN_EMPTY \
@ -2847,14 +2845,14 @@ API_FUNC(hook_modifier_exec)
API_RETURN_STRING_FREE(result);
}
const char *
char *
weechat_js_api_hook_info_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' }, *result;
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
@ -2866,12 +2864,10 @@ weechat_js_api_hook_info_cb (const void *pointer, void *data,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
result = (char *)weechat_js_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
return API_STATIC_STRING(result);
return (char *)weechat_js_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
}
return NULL;
@ -4014,7 +4010,7 @@ API_FUNC(info_get)
result = weechat_info_get (*info_name, *arguments);
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
API_FUNC(info_get_hashtable)

View File

@ -56,7 +56,6 @@ int js_eval_mode = 0;
int js_eval_send_input = 0;
int js_eval_exec_commands = 0;
struct t_gui_buffer *js_eval_buffer = NULL;
char *js_eval_output = NULL;
struct t_plugin_script *js_scripts = NULL;
struct t_plugin_script *last_js_script = NULL;
@ -756,12 +755,12 @@ weechat_js_hdata_cb (const void *pointer, void *data,
* Returns javascript info "javascript_eval".
*/
const char *
char *
weechat_js_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static const char *not_implemented = "not yet implemented";
const char *not_implemented = "not yet implemented";
/* make C compiler happy */
(void) pointer;
@ -769,7 +768,7 @@ weechat_js_info_eval_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return not_implemented;
return strdup (not_implemented);
}
/*
@ -977,8 +976,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (js_action_autoload_list)
free (js_action_autoload_list);
/* weechat_string_dyn_free (js_buffer_output, 1); */
if (js_eval_output)
free (js_eval_output);
return WEECHAT_RC_OK;
}

View File

@ -297,8 +297,7 @@ logger_get_mask_for_buffer (struct t_gui_buffer *buffer)
char *
logger_get_mask_expanded (struct t_gui_buffer *buffer, const char *mask)
{
char *mask2, *mask3, *mask4, *mask5, *mask6, *mask7;
const char *dir_separator;
char *mask2, *mask3, *mask4, *mask5, *mask6, *mask7, *dir_separator;
int length;
time_t seconds;
struct tm *date_tmp;
@ -374,6 +373,7 @@ logger_get_mask_expanded (struct t_gui_buffer *buffer, const char *mask)
}
end:
free (dir_separator);
if (mask2)
free (mask2);
if (mask3)
@ -397,9 +397,8 @@ end:
char *
logger_get_filename (struct t_gui_buffer *buffer)
{
char *res, *mask_expanded, *file_path;
char *res, *mask_expanded, *file_path, *dir_separator, *weechat_dir;
const char *mask;
const char *dir_separator, *weechat_dir;
int length;
res = NULL;
@ -411,7 +410,10 @@ logger_get_filename (struct t_gui_buffer *buffer)
return NULL;
weechat_dir = weechat_info_get ("weechat_dir", "");
if (!weechat_dir)
{
free (dir_separator);
return NULL;
}
/* get filename mask for buffer */
mask = logger_get_mask_for_buffer (buffer);
@ -423,6 +425,8 @@ logger_get_filename (struct t_gui_buffer *buffer)
"\"%s\", logging is disabled for this buffer"),
weechat_prefix ("error"), LOGGER_PLUGIN_NAME,
weechat_buffer_get_string (buffer, "name"));
free (dir_separator);
free (weechat_dir);
return NULL;
}
@ -447,6 +451,8 @@ logger_get_filename (struct t_gui_buffer *buffer)
}
end:
free (dir_separator);
free (weechat_dir);
if (mask_expanded)
free (mask_expanded);
if (file_path)
@ -463,7 +469,7 @@ void
logger_set_log_filename (struct t_logger_buffer *logger_buffer)
{
char *log_filename, *pos_last_sep;
const char *dir_separator;
char *dir_separator;
struct t_logger_buffer *ptr_logger_buffer;
/* get log filename for buffer */
@ -505,6 +511,7 @@ logger_set_log_filename (struct t_logger_buffer *logger_buffer)
weechat_mkdir_parents (log_filename, 0700);
pos_last_sep[0] = dir_separator[0];
}
free (dir_separator);
}
/* set log filename */
@ -519,14 +526,11 @@ void
logger_write_line (struct t_logger_buffer *logger_buffer,
const char *format, ...)
{
char *message, buf_time[256], buf_beginning[1024];
const char *charset;
char *message, buf_time[256], buf_beginning[1024], *charset;
time_t seconds;
struct tm *date_tmp;
int log_level;
charset = weechat_info_get ("charset_terminal", "");
if (!logger_buffer->log_file)
{
log_level = logger_get_level_for_buffer (logger_buffer->buffer);
@ -583,10 +587,13 @@ logger_write_line (struct t_logger_buffer *logger_buffer,
snprintf (buf_beginning, sizeof (buf_beginning),
_("%s\t**** Beginning of log ****"),
buf_time);
charset = weechat_info_get ("charset_terminal", "");
message = (charset) ?
weechat_iconv_from_internal (charset, buf_beginning) : NULL;
fprintf (logger_buffer->log_file,
"%s\n", (message) ? message : buf_beginning);
if (charset)
free (charset);
if (message)
free (message);
logger_buffer->flush_needed = 1;
@ -597,10 +604,13 @@ logger_write_line (struct t_logger_buffer *logger_buffer,
weechat_va_format (format);
if (vbuffer)
{
charset = weechat_info_get ("charset_terminal", "");
message = (charset) ?
weechat_iconv_from_internal (charset, vbuffer) : NULL;
fprintf (logger_buffer->log_file,
"%s\n", (message) ? message : vbuffer);
if (charset)
free (charset);
if (message)
free (message);
logger_buffer->flush_needed = 1;
@ -893,15 +903,12 @@ logger_backlog_check_conditions (struct t_gui_buffer *buffer)
void
logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines)
{
const char *charset;
struct t_logger_line *last_lines, *ptr_lines;
char *pos_message, *pos_tab, *error, *message;
char *charset, *pos_message, *pos_tab, *error, *message;
time_t datetime, time_now;
struct tm tm_line;
int num_lines;
charset = weechat_info_get ("charset_terminal", "");
weechat_buffer_set (buffer, "print_hooks_enabled", "0");
num_lines = 0;
@ -932,8 +939,11 @@ logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines)
}
pos_message = (pos_message && (datetime != 0)) ?
pos_message + 1 : ptr_lines->data;
charset = weechat_info_get ("charset_terminal", "");
message = (charset) ?
weechat_iconv_to_internal (charset, pos_message) : strdup (pos_message);
if (charset)
free (charset);
if (message)
{
pos_tab = strchr (message, '\t');

View File

@ -67,8 +67,6 @@
plugin_script_str2ptr (weechat_lua_plugin, \
LUA_CURRENT_SCRIPT_NAME, \
lua_function_name, __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&lua_data, __string);
#define API_RETURN_OK \
{ \
lua_pushinteger (L, 1); \
@ -3082,14 +3080,14 @@ API_FUNC(hook_modifier_exec)
API_RETURN_STRING_FREE(result);
}
const char *
char *
weechat_lua_api_hook_info_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' }, *result;
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
@ -3101,12 +3099,10 @@ weechat_lua_api_hook_info_cb (const void *pointer, void *data,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
result = (char *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
return API_STATIC_STRING(result);
return (char *)weechat_lua_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
}
return NULL;
@ -4343,7 +4339,8 @@ API_FUNC(command_options)
API_FUNC(info_get)
{
const char *info_name, *arguments, *result;
const char *info_name, *arguments;
char *result;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
if (lua_gettop (L) < 2)
@ -4354,7 +4351,7 @@ API_FUNC(info_get)
result = weechat_info_get (info_name, arguments);
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
API_FUNC(info_get_hashtable)

View File

@ -57,7 +57,6 @@ int lua_eval_mode = 0;
int lua_eval_send_input = 0;
int lua_eval_exec_commands = 0;
struct t_gui_buffer *lua_eval_buffer = NULL;
char *lua_eval_output = NULL;
#if LUA_VERSION_NUM >= 502
#define LUA_LOAD "load"
#else
@ -1071,23 +1070,23 @@ weechat_lua_hdata_cb (const void *pointer, void *data,
* Returns lua info "lua_eval".
*/
const char *
char *
weechat_lua_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *output;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
weechat_lua_eval (NULL, 0, 0, (arguments) ? arguments : "");
if (lua_eval_output)
free (lua_eval_output);
lua_eval_output = strdup (*lua_buffer_output);
output = strdup (*lua_buffer_output);
weechat_string_dyn_copy (lua_buffer_output, NULL);
return lua_eval_output;
return output;
}
/*
@ -1303,8 +1302,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (lua_action_autoload_list)
free (lua_action_autoload_list);
weechat_string_dyn_free (lua_buffer_output, 1);
if (lua_eval_output)
free (lua_eval_output);
return WEECHAT_RC_OK;
}

View File

@ -60,8 +60,6 @@
plugin_script_str2ptr (weechat_perl_plugin, \
PERL_CURRENT_SCRIPT_NAME, \
perl_function_name, __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&perl_data, __string);
#define API_RETURN_OK XSRETURN_YES
#define API_RETURN_ERROR XSRETURN_NO
#define API_RETURN_EMPTY XSRETURN_EMPTY
@ -2986,14 +2984,14 @@ API_FUNC(hook_modifier_exec)
API_RETURN_STRING_FREE(result);
}
const char *
char *
weechat_perl_api_hook_info_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' }, *result;
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
@ -3005,12 +3003,10 @@ weechat_perl_api_hook_info_cb (const void *pointer, void *data,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
result = (char *)weechat_perl_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
return API_STATIC_STRING(result);
return (char *)weechat_perl_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
}
return NULL;
@ -4264,8 +4260,7 @@ API_FUNC(command_options)
API_FUNC(info_get)
{
char *info_name, *arguments;
const char *result;
char *info_name, *arguments, *result;
dXSARGS;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
@ -4277,7 +4272,7 @@ API_FUNC(info_get)
result = weechat_info_get (info_name, arguments);
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
API_FUNC(info_get_hashtable)

View File

@ -54,7 +54,6 @@ int perl_eval_mode = 0;
int perl_eval_send_input = 0;
int perl_eval_exec_commands = 0;
struct t_gui_buffer *perl_eval_buffer = NULL;
char *perl_eval_output = NULL;
#define PERL_EVAL_SCRIPT \
"sub script_perl_eval {\n" \
" eval \"$_[0]\";\n" \
@ -1053,23 +1052,23 @@ weechat_perl_hdata_cb (const void *pointer, void *data,
* Returns perl info "perl_eval".
*/
const char *
char *
weechat_perl_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *output;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
weechat_perl_eval (NULL, 0, 0, (arguments) ? arguments : "");
if (perl_eval_output)
free (perl_eval_output);
perl_eval_output = strdup (*perl_buffer_output);
output = strdup (*perl_buffer_output);
weechat_string_dyn_copy (perl_buffer_output, NULL);
return perl_eval_output;
return output;
}
/*
@ -1358,8 +1357,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (perl_action_autoload_list)
free (perl_action_autoload_list);
weechat_string_dyn_free (perl_buffer_output, 1);
if (perl_eval_output)
free (perl_eval_output);
return WEECHAT_RC_OK;
}

View File

@ -67,8 +67,6 @@
plugin_script_str2ptr (weechat_php_plugin, \
PHP_CURRENT_SCRIPT_NAME, \
php_function_name, __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&php_data, __string);
#define API_RETURN_OK RETURN_LONG((long)1)
#define API_RETURN_ERROR RETURN_LONG((long)0)
#define API_RETURN_EMPTY RETURN_NULL()
@ -2889,7 +2887,7 @@ API_FUNC(hook_modifier_exec)
API_RETURN_STRING_FREE(result);
}
static const char *
static char *
weechat_php_api_hook_info_cb (const void *pointer,
void *data,
const char *info_name,
@ -2904,7 +2902,7 @@ weechat_php_api_hook_info_cb (const void *pointer,
weechat_php_cb (pointer, data, func_argv, "sss",
WEECHAT_SCRIPT_EXEC_STRING, &rc);
return API_STATIC_STRING(rc);
return rc;
}
API_FUNC(hook_info)
@ -4181,8 +4179,7 @@ API_FUNC(command_options)
API_FUNC(info_get)
{
zend_string *z_info_name, *z_arguments;
char *info_name, *arguments;
const char *result;
char *info_name, *arguments, *result;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SS", &z_info_name,
@ -4194,7 +4191,7 @@ API_FUNC(info_get)
result = weechat_info_get ((const char *)info_name,
(const char *)arguments);
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
API_FUNC(info_get_hashtable)

View File

@ -65,7 +65,6 @@ int php_eval_mode = 0;
int php_eval_send_input = 0;
int php_eval_exec_commands = 0;
struct t_gui_buffer *php_eval_buffer = NULL;
char *php_eval_output = NULL;
struct t_plugin_script *php_scripts = NULL;
struct t_plugin_script *last_php_script = NULL;
@ -1062,12 +1061,12 @@ weechat_php_hdata_cb (const void *pointer, void *data,
* Returns PHP info "php_eval".
*/
const char *
char *
weechat_php_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static const char *not_implemented = "not yet implemented";
const char *not_implemented = "not yet implemented";
/* make C compiler happy */
(void) pointer;
@ -1075,7 +1074,7 @@ weechat_php_info_eval_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return not_implemented;
return strdup (not_implemented);
}
/*
@ -1351,8 +1350,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (php_action_autoload_list)
free (php_action_autoload_list);
/* weechat_string_dyn_free (php_buffer_output, 1); */
if (php_eval_output)
free (php_eval_output);
return WEECHAT_RC_OK;
}

View File

@ -60,30 +60,33 @@
* Returns WeeChat info "version".
*/
const char *
char *
plugin_api_info_version_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
const char *version;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
(void) arguments;
return version_get_version ();
version = version_get_version ();
return (version) ? strdup (version) : NULL;
}
/*
* Returns WeeChat info "version_number".
*/
const char *
char *
plugin_api_info_version_number_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char version_number[32] = { '\0' };
char version_number[32];
/* make C compiler happy */
(void) pointer;
@ -91,60 +94,63 @@ plugin_api_info_version_number_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
if (!version_number[0])
{
snprintf (version_number, sizeof (version_number), "%d",
util_version_number (version_get_version ()));
}
return version_number;
snprintf (version_number, sizeof (version_number), "%d",
util_version_number (version_get_version ()));
return strdup (version_number);
}
/*
* Returns WeeChat info "version_git".
*/
const char *
char *
plugin_api_info_version_git_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
const char *version;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
(void) arguments;
return version_get_git ();
version = version_get_git ();
return (version) ? strdup (version) : NULL;
}
/*
* Returns WeeChat info "date".
*/
const char *
char *
plugin_api_info_date_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
const char *version;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
(void) arguments;
return version_get_compilation_date_time ();
version = version_get_compilation_date_time ();
return (version) ? strdup (version) : NULL;
}
/*
* Returns WeeChat info "pid".
*/
const char *
char *
plugin_api_info_pid_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32];
/* make C compiler happy */
(void) pointer;
@ -153,14 +159,14 @@ plugin_api_info_pid_cb (const void *pointer, void *data,
(void) arguments;
snprintf (value, sizeof (value), "%d", (int)getpid ());
return value;
return strdup (value);
}
/*
* Returns WeeChat info "dir_separator".
*/
const char *
char *
plugin_api_info_dir_separator_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -171,19 +177,19 @@ plugin_api_info_dir_separator_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return DIR_SEPARATOR;
return strdup (DIR_SEPARATOR);
}
/*
* Returns WeeChat info "weechat_dir".
*/
const char *
char *
plugin_api_info_weechat_dir_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char weechat_dir_absolute_path[PATH_MAX] = { '\0' };
char weechat_dir_absolute_path[PATH_MAX];
/* make C compiler happy */
(void) pointer;
@ -191,20 +197,18 @@ plugin_api_info_weechat_dir_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
if (!weechat_dir_absolute_path[0])
{
if (!realpath (weechat_home, weechat_dir_absolute_path))
return NULL;
}
return (weechat_dir_absolute_path[0]) ?
weechat_dir_absolute_path : weechat_home;
if (!realpath (weechat_home, weechat_dir_absolute_path))
return NULL;
return strdup ((weechat_dir_absolute_path[0]) ?
weechat_dir_absolute_path : weechat_home);
}
/*
* Returns WeeChat info "weechat_libdir".
*/
const char *
char *
plugin_api_info_weechat_libdir_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -215,14 +219,14 @@ plugin_api_info_weechat_libdir_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return WEECHAT_LIBDIR;
return strdup (WEECHAT_LIBDIR);
}
/*
* Returns WeeChat info "weechat_sharedir".
*/
const char *
char *
plugin_api_info_weechat_sharedir_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -233,14 +237,14 @@ plugin_api_info_weechat_sharedir_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return WEECHAT_SHAREDIR;
return strdup (WEECHAT_SHAREDIR);
}
/*
* Returns WeeChat info "weechat_localedir".
*/
const char *
char *
plugin_api_info_weechat_localedir_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -251,14 +255,14 @@ plugin_api_info_weechat_localedir_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return LOCALEDIR;
return strdup (LOCALEDIR);
}
/*
* Returns WeeChat info "weechat_site".
*/
const char *
char *
plugin_api_info_weechat_site_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -269,14 +273,14 @@ plugin_api_info_weechat_site_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return WEECHAT_WEBSITE;
return strdup (WEECHAT_WEBSITE);
}
/*
* Returns WeeChat info "weechat_site_download".
*/
const char *
char *
plugin_api_info_weechat_site_download_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -287,19 +291,19 @@ plugin_api_info_weechat_site_download_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return WEECHAT_WEBSITE_DOWNLOAD;
return strdup (WEECHAT_WEBSITE_DOWNLOAD);
}
/*
* Returns WeeChat info "weechat_upgrading".
*/
const char *
char *
plugin_api_info_weechat_upgrading_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32];
/* make C compiler happy */
(void) pointer;
@ -308,14 +312,14 @@ plugin_api_info_weechat_upgrading_cb (const void *pointer, void *data,
(void) arguments;
snprintf (value, sizeof (value), "%d", weechat_upgrading);
return value;
return strdup (value);
}
/*
* Returns WeeChat info "charset_terminal".
*/
const char *
char *
plugin_api_info_charset_terminal_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -326,14 +330,14 @@ plugin_api_info_charset_terminal_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return weechat_local_charset;
return (weechat_local_charset) ? strdup (weechat_local_charset) : NULL;
}
/*
* Returns WeeChat info "charset_internal".
*/
const char *
char *
plugin_api_info_charset_internal_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -344,38 +348,41 @@ plugin_api_info_charset_internal_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return WEECHAT_INTERNAL_CHARSET;
return strdup (WEECHAT_INTERNAL_CHARSET);
}
/*
* Returns WeeChat info "locale".
*/
const char *
char *
plugin_api_info_locale_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *locale;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
(void) arguments;
return setlocale (LC_MESSAGES, NULL);
locale = setlocale (LC_MESSAGES, NULL);
return (locale) ? strdup (locale) : NULL;
}
/*
* Returns WeeChat info "inactivity".
*/
const char *
char *
plugin_api_info_inactivity_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
time_t inactivity;
static char value[32];
char value[32];
/* make C compiler happy */
(void) pointer;
@ -387,20 +394,22 @@ plugin_api_info_inactivity_cb (const void *pointer, void *data,
inactivity = 0;
else
inactivity = time (NULL) - gui_key_last_activity_time;
snprintf (value, sizeof (value), "%lld", (long long)inactivity);
return value;
return strdup (value);
}
/*
* Returns WeeChat info "filters_enabled".
*/
const char *
char *
plugin_api_info_filters_enabled_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32];
/* make C compiler happy */
(void) pointer;
@ -409,19 +418,19 @@ plugin_api_info_filters_enabled_cb (const void *pointer, void *data,
(void) arguments;
snprintf (value, sizeof (value), "%d", gui_filters_enabled);
return value;
return strdup (value);
}
/*
* Returns WeeChat info "cursor_mode".
*/
const char *
char *
plugin_api_info_cursor_mode_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32];
/* make C compiler happy */
(void) pointer;
@ -430,19 +439,19 @@ plugin_api_info_cursor_mode_cb (const void *pointer, void *data,
(void) arguments;
snprintf (value, sizeof (value), "%d", gui_cursor_mode);
return value;
return strdup (value);
}
/*
* Returns WeeChat info "term_width".
*/
const char *
char *
plugin_api_info_term_width_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32];
/* make C compiler happy */
(void) pointer;
@ -451,19 +460,19 @@ plugin_api_info_term_width_cb (const void *pointer, void *data,
(void) arguments;
snprintf (value, sizeof (value), "%d", gui_window_get_width ());
return value;
return strdup (value);
}
/*
* Returns WeeChat info "term_height".
*/
const char *
char *
plugin_api_info_term_height_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32];
/* make C compiler happy */
(void) pointer;
@ -472,14 +481,14 @@ plugin_api_info_term_height_cb (const void *pointer, void *data,
(void) arguments;
snprintf (value, sizeof (value), "%d", gui_window_get_height ());
return value;
return strdup (value);
}
/*
* Returns WeeChat info "color_ansi_regex".
*/
const char *
char *
plugin_api_info_color_ansi_regex_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -490,19 +499,19 @@ plugin_api_info_color_ansi_regex_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return GUI_COLOR_REGEX_ANSI_DECODE;
return strdup (GUI_COLOR_REGEX_ANSI_DECODE);
}
/*
* Returns WeeChat info "color_term2rgb".
*/
const char *
char *
plugin_api_info_color_term2rgb_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32];
/* make C compiler happy */
(void) pointer;
@ -515,21 +524,20 @@ plugin_api_info_color_term2rgb_cb (const void *pointer, void *data,
snprintf (value, sizeof (value),
"%d",
gui_color_convert_term_to_rgb (atoi (arguments)));
return value;
return strdup (value);
}
/*
* Returns WeeChat info "color_rgb2term".
*/
const char *
char *
plugin_api_info_color_rgb2term_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32], *pos, *color;
int rgb, limit;
char *pos, *color;
/* make C compiler happy */
(void) pointer;
@ -554,57 +562,64 @@ plugin_api_info_color_rgb2term_cb (const void *pointer, void *data,
{
rgb = atoi (arguments);
}
snprintf (value, sizeof (value),
"%d",
gui_color_convert_rgb_to_term (rgb, limit));
return value;
return strdup (value);
}
/*
* Returns nick color code for a nickname.
*/
const char *
char *
plugin_api_info_nick_color_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
const char *ptr_color;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
return gui_nick_find_color (arguments);
ptr_color = gui_nick_find_color (arguments);
return (ptr_color) ? strdup (ptr_color) : NULL;
}
/*
* Returns nick color name for a nickname.
*/
const char *
char *
plugin_api_info_nick_color_name_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
const char *ptr_color;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
return gui_nick_find_color_name (arguments);
ptr_color = gui_nick_find_color_name (arguments);
return (ptr_color) ? strdup (ptr_color) : NULL;
}
/*
* Returns WeeChat info "uptime".
*/
const char *
char *
plugin_api_info_uptime_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char value[32];
time_t total_seconds;
int days, hours, minutes, seconds;
@ -619,7 +634,7 @@ plugin_api_info_uptime_cb (const void *pointer, void *data,
util_get_uptime (NULL, &days, &hours, &minutes, &seconds);
snprintf (value, sizeof (value), "%d:%02d:%02d:%02d",
days, hours, minutes, seconds);
return value;
return strdup (value);
}
if (strcmp (arguments, "days") == 0)
@ -627,7 +642,7 @@ plugin_api_info_uptime_cb (const void *pointer, void *data,
/* return the number of days */
util_get_uptime (NULL, &days, NULL, NULL, NULL);
snprintf (value, sizeof (value), "%d", days);
return value;
return strdup (value);
}
if (strcmp (arguments, "seconds") == 0)
@ -635,7 +650,7 @@ plugin_api_info_uptime_cb (const void *pointer, void *data,
/* return the number of seconds */
util_get_uptime (&total_seconds, NULL, NULL, NULL, NULL);
snprintf (value, sizeof (value), "%lld", (long long)total_seconds);
return value;
return strdup (value);
}
return NULL;
@ -648,14 +663,13 @@ plugin_api_info_uptime_cb (const void *pointer, void *data,
* Arguments: "secret,timestamp,digits" (timestamp and digits are optional).
*/
const char *
char *
plugin_api_info_totp_generate_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[32];
char **argv, *ptr_secret, *error, *totp;
int argc, digits, length;
int argc, digits;
long number;
time_t totp_time;
@ -703,14 +717,9 @@ plugin_api_info_totp_generate_cb (const void *pointer, void *data,
if (!totp)
goto error;
length = snprintf (value, sizeof (value), "%s", totp);
if (length != digits)
goto error;
string_free_split (argv);
free (totp);
return value;
return totp;
error:
if (argv)
@ -727,13 +736,12 @@ error:
* Arguments: "secret,otp,timestamp,window" (timestamp and window are optional).
*/
const char *
char *
plugin_api_info_totp_validate_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char value[16];
char **argv, *ptr_secret, *ptr_otp, *error;
char value[16], **argv, *ptr_secret, *ptr_otp, *error;
int argc, window, rc;
long number;
time_t totp_time;
@ -784,7 +792,7 @@ plugin_api_info_totp_validate_cb (const void *pointer, void *data,
string_free_split (argv);
return value;
return strdup (value);
error:
if (argv)

View File

@ -1001,10 +1001,10 @@ plugin_script_api_hook_info (struct t_weechat_plugin *weechat_plugin,
const char *info_name,
const char *description,
const char *args_description,
const char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
const char *function,
const char *data)
{

View File

@ -289,10 +289,10 @@ extern struct t_hook *plugin_script_api_hook_info (struct t_weechat_plugin *weec
const char *info_name,
const char *description,
const char *args_description,
const char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
const char *function,
const char *data);
extern struct t_hook *plugin_script_api_hook_info_hashtable (struct t_weechat_plugin *weechat_plugin,

View File

@ -89,12 +89,13 @@ plugin_script_signal_debug_libs_cb (const void *pointer, void *data,
* Callback for info "xxx_interpreter".
*/
const char *
char *
plugin_script_info_interpreter_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_weechat_plugin *weechat_plugin;
const char *ptr_interpreter;
/* make C compiler happy */
(void) data;
@ -103,20 +104,22 @@ plugin_script_info_interpreter_cb (const void *pointer, void *data,
weechat_plugin = (struct t_weechat_plugin *)pointer;
return weechat_hashtable_get (weechat_plugin->variables,
"interpreter_name");
ptr_interpreter = weechat_hashtable_get (weechat_plugin->variables,
"interpreter_name");
return (ptr_interpreter) ? strdup (ptr_interpreter) : NULL;
}
/*
* Callback for info "xxx_version".
*/
const char *
char *
plugin_script_info_version_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_weechat_plugin *weechat_plugin;
const char *ptr_version;
/* make C compiler happy */
(void) data;
@ -125,8 +128,9 @@ plugin_script_info_version_cb (const void *pointer, void *data,
weechat_plugin = (struct t_weechat_plugin *)pointer;
return weechat_hashtable_get (weechat_plugin->variables,
"interpreter_version");
ptr_version = weechat_hashtable_get (weechat_plugin->variables,
"interpreter_version");
return (ptr_version) ? strdup (ptr_version) : NULL;
}
/*
@ -171,13 +175,6 @@ plugin_script_init (struct t_weechat_plugin *weechat_plugin,
char *action_signals[] = { "install", "remove", "autoload", NULL };
int i, auto_load_scripts;
/* initialize static strings */
plugin_data->index_static_string = 0;
for (i = 0; i < WEECHAT_SCRIPT_STATIC_STRINGS; i++)
{
plugin_data->static_string[i] = NULL;
}
/* initialize script configuration file (file: "<language>.conf") */
plugin_script_config_init (weechat_plugin, plugin_data);
@ -394,29 +391,6 @@ invalid:
return NULL;
}
/*
* Gets a "static string": a string allocated that will be freed later
* (or when the plugin is unloaded).
*
* The "string" argument must have been allocated by free (or strdup, ...)
* and will be automatically freed later.
*/
char *
plugin_script_get_static_string (struct t_plugin_script_data *plugin_data,
char *string)
{
plugin_data->index_static_string = (plugin_data->index_static_string + 1) %
WEECHAT_SCRIPT_STATIC_STRINGS;
if (plugin_data->static_string[plugin_data->index_static_string])
free (plugin_data->static_string[plugin_data->index_static_string]);
plugin_data->static_string[plugin_data->index_static_string] = string;
return plugin_data->static_string[plugin_data->index_static_string];
}
/*
* Builds concatenated function name and data (both are strings).
* The result will be sent to callbacks.
@ -487,8 +461,7 @@ plugin_script_auto_load (struct t_weechat_plugin *weechat_plugin,
void (*callback)(void *data,
const char *filename))
{
const char *dir_home;
char *dir_name;
char *dir_home, *dir_name;
int dir_length;
/* build directory, adding WeeChat home */
@ -498,12 +471,16 @@ plugin_script_auto_load (struct t_weechat_plugin *weechat_plugin,
dir_length = strlen (dir_home) + strlen (weechat_plugin->name) + 16;
dir_name = malloc (dir_length);
if (!dir_name)
{
free (dir_home);
return;
}
snprintf (dir_name, dir_length,
"%s/%s/autoload", dir_home, weechat_plugin->name);
weechat_exec_on_files (dir_name, 0, 0, callback, NULL);
free (dir_home);
free (dir_name);
}
@ -565,8 +542,7 @@ char *
plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
const char *filename)
{
char *final_name;
const char *dir_home, *dir_system;
char *final_name, *dir_home, *dir_system;
int length;
struct stat st;
@ -586,7 +562,10 @@ plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
"%s/%s/autoload/%s",
dir_home, weechat_plugin->name, filename);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
free (dir_home);
return final_name;
}
free (final_name);
}
@ -599,7 +578,10 @@ plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
snprintf (final_name, length,
"%s/%s/%s", dir_home, weechat_plugin->name, filename);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
free (dir_home);
return final_name;
}
free (final_name);
}
@ -611,9 +593,13 @@ plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
snprintf (final_name, length,
"%s/%s", dir_home, filename);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
free (dir_home);
return final_name;
}
free (final_name);
}
free (dir_home);
}
/* try WeeChat system dir */
@ -628,9 +614,13 @@ plugin_script_search_path (struct t_weechat_plugin *weechat_plugin,
snprintf (final_name,length,
"%s/%s/%s", dir_system, weechat_plugin->name, filename);
if ((stat (final_name, &st) == 0) && (st.st_size > 0))
{
free (dir_system);
return final_name;
}
free (final_name);
}
free (dir_system);
}
return strdup (filename);
@ -1228,8 +1218,7 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
char **list)
{
char **argv, *name, *ptr_base_name, *base_name, *new_path, *autoload_path;
char *symlink_path, str_signal[128], *ptr_list;
const char *dir_home, *dir_separator;
char *symlink_path, str_signal[128], *ptr_list, *dir_home, *dir_separator;
int argc, i, length, rc, autoload, existing_script, script_loaded;
struct t_plugin_script *ptr_script;
@ -1330,6 +1319,8 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
free (symlink_path);
}
free (autoload_path);
if (dir_separator)
free (dir_separator);
}
}
@ -1356,6 +1347,8 @@ plugin_script_action_install (struct t_weechat_plugin *weechat_plugin,
free (new_path);
}
free (base_name);
if (dir_home)
free (dir_home);
}
free (name);
}
@ -1449,8 +1442,7 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
char **list)
{
char **argv, *name, *ptr_base_name, *base_name, *autoload_path;
char *symlink_path, *ptr_list;
const char *dir_home, *dir_separator;
char *symlink_path, *ptr_list, *dir_home, *dir_separator;
int argc, i, length, rc, autoload;
if (!*list)
@ -1523,6 +1515,8 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
(void) rc;
free (symlink_path);
}
if (dir_separator)
free (dir_separator);
}
else
{
@ -1531,6 +1525,8 @@ plugin_script_action_autoload (struct t_weechat_plugin *weechat_plugin,
free (autoload_path);
}
free (base_name);
if (dir_home)
free (dir_home);
}
free (name);
}
@ -1784,7 +1780,7 @@ void
plugin_script_end (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script_data *plugin_data)
{
int scripts_loaded, i;
int scripts_loaded;
/* unload all scripts */
scripts_loaded = (*(plugin_data->scripts)) ? 1 : 0;
@ -1798,16 +1794,6 @@ plugin_script_end (struct t_weechat_plugin *weechat_plugin,
/* write config file (file: "<language>.conf") */
weechat_config_write (*(plugin_data->config_file));
weechat_config_free (*(plugin_data->config_file));
/* free static strings */
for (i = 0; i < WEECHAT_SCRIPT_STATIC_STRINGS; i++)
{
if (plugin_data->static_string[i])
{
free (plugin_data->static_string[i]);
plugin_data->static_string[i] = NULL;
}
}
}
/*

View File

@ -33,8 +33,6 @@ enum t_weechat_script_exec_type
#define WEECHAT_SCRIPT_HASHTABLE_DEFAULT_SIZE 16
#define WEECHAT_SCRIPT_STATIC_STRINGS 32
#define WEECHAT_SCRIPT_EVAL_NAME "__eval__"
#define WEECHAT_SCRIPT_MSG_NOT_INIT(__current_script, \
@ -80,8 +78,6 @@ struct t_plugin_script_data
struct t_config_option **config_look_eval_keep_context;
struct t_plugin_script **scripts;
struct t_plugin_script **last_script;
char *static_string[WEECHAT_SCRIPT_STATIC_STRINGS];
int index_static_string;
/* callbacks */
int (*callback_command) (const void *pointer, void *data,
@ -94,10 +90,10 @@ struct t_plugin_script_data
struct t_hdata *(*callback_hdata) (const void *pointer,
void *data,
const char *hdata_name);
const char *(*callback_info_eval) (const void *pointer,
void *data,
const char *info_name,
const char *arguments);
char *(*callback_info_eval) (const void *pointer,
void *data,
const char *info_name,
const char *arguments);
struct t_infolist *(*callback_infolist) (const void *pointer,
void *data,
const char *infolist_name,
@ -129,8 +125,6 @@ extern void *plugin_script_str2ptr (struct t_weechat_plugin *weechat_plugin,
const char *script_name,
const char *function_name,
const char *pointer_str);
extern char *plugin_script_get_static_string (struct t_plugin_script_data *plugin_data,
char *string);
extern char *plugin_script_build_function_and_data (const char *function,
const char *data);
extern void plugin_script_get_function_and_data (void *callback_data,

View File

@ -59,8 +59,6 @@
plugin_script_str2ptr (weechat_python_plugin, \
PYTHON_CURRENT_SCRIPT_NAME, \
python_function_name, __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&python_data, __string);
#define API_RETURN_OK return PyLong_FromLong((long)1)
#define API_RETURN_ERROR return PyLong_FromLong ((long)0)
#define API_RETURN_EMPTY \
@ -3024,14 +3022,14 @@ API_FUNC(hook_modifier_exec)
API_RETURN_STRING_FREE(result);
}
const char *
char *
weechat_python_api_hook_info_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' }, *result;
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
@ -3043,12 +3041,10 @@ weechat_python_api_hook_info_cb (const void *pointer, void *data,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
result = (char *)weechat_python_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
return API_STATIC_STRING(result);
return (char *)weechat_python_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
}
return NULL;
@ -4278,8 +4274,8 @@ API_FUNC(command_options)
API_FUNC(info_get)
{
char *info_name, *arguments;
const char *result;
char *info_name, *arguments, *result;
PyObject *return_value;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
info_name = NULL;
@ -4289,7 +4285,7 @@ API_FUNC(info_get)
result = weechat_info_get (info_name, arguments);
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
API_FUNC(info_get_hashtable)

View File

@ -57,7 +57,6 @@ int python_eval_mode = 0;
int python_eval_send_input = 0;
int python_eval_exec_commands = 0;
struct t_gui_buffer *python_eval_buffer = NULL;
char *python_eval_output = NULL;
#define PYTHON_EVAL_SCRIPT \
"import weechat\n" \
"\n" \
@ -144,8 +143,7 @@ char *python_action_autoload_list = NULL;
char *
weechat_python_get_python2_bin ()
{
const char *dir_separator;
char *py2_bin, *path, **paths, bin[4096];
char *dir_separator, *py2_bin, *path, **paths, bin[4096];
char *versions[] = { "2.7", "2.6", "2.5", "2.4", "2.3", "2.2", "2", NULL };
int num_paths, i, j, rc;
struct stat stat_buf;
@ -185,6 +183,9 @@ weechat_python_get_python2_bin ()
}
}
if (dir_separator)
free (dir_separator);
if (!py2_bin)
py2_bin = strdup ("python");
@ -753,7 +754,7 @@ weechat_python_load (const char *filename, const char *code)
#endif /* PY_MAJOR_VERSION >= 3 */
FILE *fp;
PyObject *python_path, *path, *module_main, *globals, *rc;
const char *weechat_home;
char *weechat_home;
char *str_home;
int len;
@ -842,6 +843,7 @@ weechat_python_load (const char *filename, const char *code)
}
free (str_home);
}
free (weechat_home);
}
weechat_python_set_output ();
@ -1332,7 +1334,7 @@ weechat_python_hdata_cb (const void *pointer, void *data,
* Returns python info "python2_bin".
*/
const char *
char *
weechat_python_info_python2_bin_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -1355,30 +1357,30 @@ weechat_python_info_python2_bin_cb (const void *pointer, void *data,
python2_bin = weechat_python_get_python2_bin ();
}
}
return python2_bin;
return (python2_bin) ? strdup (python2_bin) : NULL;
}
/*
* Returns python info "python_eval".
*/
const char *
char *
weechat_python_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *output;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
weechat_python_eval (NULL, 0, 0, (arguments) ? arguments : "");
if (python_eval_output)
free (python_eval_output);
python_eval_output = strdup (*python_buffer_output);
output = strdup (*python_buffer_output);
weechat_string_dyn_copy (python_buffer_output, NULL);
return python_eval_output;
return output;
}
/*
@ -1658,8 +1660,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (python_action_autoload_list)
free (python_action_autoload_list);
weechat_string_dyn_free (python_buffer_output, 1);
if (python_eval_output)
free (python_eval_output);
return WEECHAT_RC_OK;
}

View File

@ -1322,11 +1322,12 @@ relay_irc_recv_command_capab (struct t_relay_client *client,
void
relay_irc_recv (struct t_relay_client *client, const char *data)
{
char str_time[128], str_signal[128], str_server_channel[256];
char str_command[128], *target, **irc_argv, **irc_argv_eol, *pos, *password;
char str_time[128], str_signal[128], str_server_channel[256], *nick;
char *version, str_command[128], *target, **irc_argv, **irc_argv_eol;
char *pos, *password, *irc_is_channel, *info;
const char *irc_command, *irc_channel, *irc_args, *irc_args2;
int irc_argc, redirect_msg;
const char *nick, *irc_is_channel, *isupport, *info, *pos_password;
const char *isupport, *pos_password;
struct t_hashtable *hash_parsed, *hash_redirect;
struct t_infolist *infolist_server;
@ -1512,7 +1513,10 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
free (RELAY_IRC_DATA(client, nick));
RELAY_IRC_DATA(client, nick) = strdup (nick);
}
if (nick)
free (nick);
version = weechat_info_get ("version", NULL);
relay_irc_sendf (client,
":%s 001 %s :Welcome to the Internet "
"Relay Chat Network %s!%s@proxy",
@ -1525,7 +1529,7 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
"weechat-relay-irc, running version %s",
RELAY_IRC_DATA(client, address),
RELAY_IRC_DATA(client, nick),
weechat_info_get ("version", NULL));
version);
snprintf (str_time, sizeof (str_time), "%s",
ctime (&client->listen_start_time));
if (str_time[0])
@ -1540,7 +1544,9 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
RELAY_IRC_DATA(client, address),
RELAY_IRC_DATA(client, nick),
RELAY_IRC_DATA(client, address),
weechat_info_get ("version", NULL));
version);
if (version)
free (version);
infolist_server = weechat_infolist_get ("irc_server", NULL,
client->protocol_args);
if (infolist_server)
@ -1651,6 +1657,8 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
"/query %s %s",
irc_channel, irc_args2);
}
if (irc_is_channel)
free (irc_is_channel);
}
else if (!relay_irc_command_ignored (irc_command))
{
@ -1721,6 +1729,8 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
"mode_user");
}
}
if (info)
free (info);
}
}
else if (weechat_strcasecmp (irc_command, "ison") == 0)

View File

@ -32,14 +32,13 @@
* Returns relay info "relay_client_count".
*/
const char *
char *
relay_info_info_relay_client_count_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static char str_count[32];
char str_count[32], **items;
const char *ptr_count;
char **items;
int count, protocol, status, num_items;
struct t_relay_client *ptr_client;
@ -110,7 +109,7 @@ end:
if (items)
weechat_string_free_split (items);
return ptr_count;
return (ptr_count) ? strdup (ptr_count) : NULL;
}
/*

View File

@ -52,7 +52,7 @@ void
relay_network_set_ssl_cert_key (int verbose)
{
#ifdef HAVE_GNUTLS
char *certkey_path, *certkey_path2;
char *certkey_path, *certkey_path2, *weechat_dir;
int ret;
gnutls_certificate_free_credentials (relay_gnutls_x509_cred);
@ -63,9 +63,11 @@ relay_network_set_ssl_cert_key (int verbose)
certkey_path = weechat_string_expand_home (weechat_config_string (relay_config_network_ssl_cert_key));
if (certkey_path)
{
weechat_dir = weechat_info_get ("weechat_dir", NULL);
certkey_path2 = weechat_string_replace (certkey_path, "%h",
weechat_info_get ("weechat_dir",
NULL));
weechat_dir);
if (weechat_dir)
free (weechat_dir);
if (certkey_path2)
{
ret = gnutls_certificate_set_x509_key_file (relay_gnutls_x509_cred,

View File

@ -169,8 +169,7 @@ relay_weechat_protocol_is_sync (struct t_relay_client *ptr_client,
RELAY_WEECHAT_PROTOCOL_CALLBACK(init)
{
char **options, *pos, *password, *totp_secret, *info_totp_args;
const char *info_totp;
char **options, *pos, *password, *totp_secret, *info_totp_args, *info_totp;
int i, compression, length;
RELAY_WEECHAT_PROTOCOL_MIN_ARGS(1);
@ -217,6 +216,8 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(init)
info_totp = weechat_info_get ("totp_validate", info_totp_args);
if (info_totp && (strcmp (info_totp, "1") == 0))
RELAY_WEECHAT_DATA(client, totp_ok) = 1;
if (info_totp)
free (info_totp);
free (info_totp_args);
}
free (totp_secret);
@ -290,7 +291,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(hdata)
RELAY_WEECHAT_PROTOCOL_CALLBACK(info)
{
struct t_relay_weechat_msg *msg;
const char *info;
char *info;
RELAY_WEECHAT_PROTOCOL_MIN_ARGS(1);
@ -304,6 +305,8 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(info)
relay_weechat_msg_add_string (msg, info);
relay_weechat_msg_send (client, msg);
relay_weechat_msg_free (msg);
if (info)
free (info);
}
return WEECHAT_RC_OK;

View File

@ -57,8 +57,6 @@
plugin_script_str2ptr (weechat_ruby_plugin, \
RUBY_CURRENT_SCRIPT_NAME, \
ruby_function_name, __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&ruby_data, __string);
#define API_RETURN_OK return INT2FIX (1)
#define API_RETURN_ERROR return INT2FIX (0)
#define API_RETURN_EMPTY return Qnil
@ -3598,14 +3596,14 @@ weechat_ruby_api_hook_modifier_exec (VALUE class, VALUE modifier,
API_RETURN_STRING_FREE(result);
}
const char *
char *
weechat_ruby_api_hook_info_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' }, *result;
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
@ -3617,12 +3615,10 @@ weechat_ruby_api_hook_info_cb (const void *pointer, void *data,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
result = (char *)weechat_ruby_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
return API_STATIC_STRING(result);
return (char *)weechat_ruby_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
}
return NULL;
@ -5156,8 +5152,8 @@ weechat_ruby_api_command_options (VALUE class, VALUE buffer, VALUE command,
static VALUE
weechat_ruby_api_info_get (VALUE class, VALUE info_name, VALUE arguments)
{
char *c_info_name, *c_arguments;
const char *result;
char *c_info_name, *c_arguments, *result;
VALUE return_value;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
if (NIL_P (info_name) || NIL_P (arguments))
@ -5171,7 +5167,7 @@ weechat_ruby_api_info_get (VALUE class, VALUE info_name, VALUE arguments)
result = weechat_info_get (c_info_name, c_arguments);
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
static VALUE

View File

@ -79,7 +79,6 @@ int ruby_eval_mode = 0;
int ruby_eval_send_input = 0;
int ruby_eval_exec_commands = 0;
struct t_gui_buffer *ruby_eval_buffer = NULL;
char *ruby_eval_output = NULL;
#define RUBY_EVAL_SCRIPT \
"def weechat_init\n" \
" Weechat.register('" WEECHAT_SCRIPT_EVAL_NAME "', '', '1.0', " \
@ -1111,23 +1110,23 @@ weechat_ruby_hdata_cb (const void *pointer, void *data,
* Returns ruby info "ruby_eval".
*/
const char *
char *
weechat_ruby_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
char *output;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
weechat_ruby_eval (NULL, 0, 0, (arguments) ? arguments : "");
if (ruby_eval_output)
free (ruby_eval_output);
ruby_eval_output = strdup (*ruby_buffer_output);
output = strdup (*ruby_buffer_output);
weechat_string_dyn_copy (ruby_buffer_output, NULL);
return ruby_eval_output;
return output;
}
/*
@ -1449,8 +1448,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (ruby_action_autoload_list)
free (ruby_action_autoload_list);
weechat_string_dyn_free (ruby_buffer_output, 1);
if (ruby_eval_output)
free (ruby_eval_output);
return WEECHAT_RC_OK;
}

View File

@ -189,8 +189,7 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
const char *weechat_home;
char *directory;
char *weechat_home, *directory;
int length, i;
void *pointers[2];
@ -228,6 +227,9 @@ script_completion_scripts_files_cb (const void *pointer, void *data,
free (directory);
}
if (weechat_home)
free (weechat_home);
return WEECHAT_RC_OK;
}

View File

@ -96,7 +96,8 @@ struct t_config_option *script_config_scripts_url;
const char *
script_config_get_diff_command ()
{
const char *diff_command, *dir_separator;
const char *diff_command;
char *dir_separator;
static char result[64];
struct stat st;
char *path, **paths, bin[4096];
@ -135,6 +136,8 @@ script_config_get_diff_command ()
weechat_string_free_split (paths);
}
}
if (dir_separator)
free (dir_separator);
if (!result[0])
snprintf (result, sizeof (result), "diff");
return result;

View File

@ -166,8 +166,7 @@ script_repo_search_by_name_ext (const char *name_with_extension)
char *
script_repo_get_filename_loaded (struct t_script_repo *script)
{
const char *weechat_home;
char *filename, resolved_path[PATH_MAX];
char *weechat_home, *filename, resolved_path[PATH_MAX];
int length;
struct stat st;
@ -175,7 +174,11 @@ script_repo_get_filename_loaded (struct t_script_repo *script)
length = strlen (weechat_home) + strlen (script->name_with_extension) + 64;
filename = malloc (length);
if (!filename)
{
if (weechat_home)
free (weechat_home);
return NULL;
}
snprintf (filename, length, "%s/%s/autoload/%s",
weechat_home,
@ -193,6 +196,9 @@ script_repo_get_filename_loaded (struct t_script_repo *script)
}
}
if (weechat_home)
free (weechat_home);
if (!filename[0])
{
free (filename);
@ -801,8 +807,8 @@ script_repo_sha512sum_file (const char *filename)
void
script_repo_update_status (struct t_script_repo *script)
{
const char *weechat_home, *version;
char *filename, *sha512sum;
const char *version;
char *weechat_home, *filename, *sha512sum;
struct stat st;
int length;
struct t_script_repo *ptr_script;
@ -841,6 +847,9 @@ script_repo_update_status (struct t_script_repo *script)
free (filename);
}
if (weechat_home)
free (weechat_home);
/* check if script is held */
if (script_repo_script_is_held (script))
script->status |= SCRIPT_STATUS_HELD;
@ -1140,8 +1149,8 @@ script_repo_file_read (int quiet)
{
char *filename, *ptr_line, line[4096], *pos, *pos2, *pos3;
char *name, *value1, *value2, *value3, *value, *error;
char *locale, *locale_language;
const char *version, *ptr_locale, *ptr_desc;
char *info_locale, *locale, *locale_language, *version;
const char *ptr_desc;
gzFile file;
struct t_script_repo *script;
int version_number, version_ok, script_ok, length;
@ -1166,6 +1175,8 @@ script_repo_file_read (int quiet)
version = weechat_info_get ("version", NULL);
version_number = weechat_util_version_number (version);
if (version)
free (version);
filename = script_config_get_xml_filename ();
if (!filename)
@ -1195,14 +1206,15 @@ script_repo_file_read (int quiet)
*/
locale = NULL;
locale_language = NULL;
ptr_locale = weechat_info_get ("locale", NULL);
if (ptr_locale)
info_locale = weechat_info_get ("locale", NULL);
if (info_locale)
{
pos = strchr (ptr_locale, '.');
pos = strchr (info_locale, '.');
if (pos)
locale = weechat_strndup (ptr_locale, pos - ptr_locale);
locale = weechat_strndup (info_locale, pos - info_locale);
else
locale = strdup (ptr_locale);
locale = strdup (info_locale);
free (info_locale);
}
if (locale)
{
@ -1406,10 +1418,13 @@ script_repo_file_read (int quiet)
if (scripts_repo && !quiet)
{
version = weechat_info_get ("version", NULL);
weechat_printf (NULL,
_("%s: %d scripts for WeeChat %s"),
SCRIPT_PLUGIN_NAME, script_repo_count,
weechat_info_get ("version", NULL));
version);
if (version)
free (version);
}
if (!scripts_repo)

View File

@ -31,7 +31,7 @@
* Returns spell info "spell_dict".
*/
const char *
char *
spell_info_info_spell_dict_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
@ -39,13 +39,15 @@ spell_info_info_spell_dict_cb (const void *pointer, void *data,
int rc;
unsigned long value;
struct t_gui_buffer *buffer;
const char *buffer_full_name;
const char *buffer_full_name, *ptr_dict;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) info_name;
ptr_dict = NULL;
if (!arguments)
return NULL;
@ -67,9 +69,9 @@ spell_info_info_spell_dict_cb (const void *pointer, void *data,
buffer_full_name = arguments;
if (buffer_full_name)
return spell_get_dict_with_buffer_name (buffer_full_name);
ptr_dict = spell_get_dict_with_buffer_name (buffer_full_name);
return NULL;
return (ptr_dict) ? strdup (ptr_dict) : NULL;
}
/*

View File

@ -68,8 +68,6 @@
plugin_script_str2ptr (weechat_tcl_plugin, \
TCL_CURRENT_SCRIPT_NAME, \
tcl_function_name, __string)
#define API_STATIC_STRING(__string) \
plugin_script_get_static_string(&tcl_data, __string);
#define API_RETURN_OK \
{ \
objp = Tcl_GetObjResult (interp); \
@ -3284,14 +3282,14 @@ API_FUNC(hook_modifier_exec)
API_RETURN_STRING_FREE(result);
}
const char *
char *
weechat_tcl_api_hook_info_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
struct t_plugin_script *script;
void *func_argv[3];
char empty_arg[1] = { '\0' }, *result;
char empty_arg[1] = { '\0' };
const char *ptr_function, *ptr_data;
script = (struct t_plugin_script *)pointer;
@ -3303,12 +3301,10 @@ weechat_tcl_api_hook_info_cb (const void *pointer, void *data,
func_argv[1] = (info_name) ? (char *)info_name : empty_arg;
func_argv[2] = (arguments) ? (char *)arguments : empty_arg;
result = (char *)weechat_tcl_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
return API_STATIC_STRING(result);
return (char *)weechat_tcl_exec (script,
WEECHAT_SCRIPT_EXEC_STRING,
ptr_function,
"sss", func_argv);
}
return NULL;
@ -4631,7 +4627,7 @@ API_FUNC(command_options)
API_FUNC(info_get)
{
Tcl_Obj *objp;
const char *result;
char *result;
int i;
API_INIT_FUNC(1, "info_get", API_RETURN_EMPTY);
@ -4641,7 +4637,7 @@ API_FUNC(info_get)
result = weechat_info_get (Tcl_GetStringFromObj (objv[1], &i),
Tcl_GetStringFromObj (objv[2], &i));
API_RETURN_STRING(result);
API_RETURN_STRING_FREE(result);
}
API_FUNC(info_get_hashtable)

View File

@ -57,7 +57,6 @@ int tcl_eval_mode = 0;
int tcl_eval_send_input = 0;
int tcl_eval_exec_commands = 0;
struct t_gui_buffer *tcl_eval_buffer = NULL;
char *tcl_eval_output = NULL;
struct t_plugin_script *tcl_scripts = NULL;
struct t_plugin_script *last_tcl_script = NULL;
@ -760,12 +759,12 @@ weechat_tcl_hdata_cb (const void *pointer, void *data,
* Returns tcl info "tcl_eval".
*/
const char *
char *
weechat_tcl_info_eval_cb (const void *pointer, void *data,
const char *info_name,
const char *arguments)
{
static const char *not_implemented = "not yet implemented";
const char *not_implemented = "not yet implemented";
/* make C compiler happy */
(void) pointer;
@ -773,7 +772,7 @@ weechat_tcl_info_eval_cb (const void *pointer, void *data,
(void) info_name;
(void) arguments;
return not_implemented;
return strdup (not_implemented);
}
/*
@ -984,8 +983,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
if (tcl_action_autoload_list)
free (tcl_action_autoload_list);
/* weechat_string_dyn_free (tcl_buffer_output, 1); */
if (tcl_eval_output)
free (tcl_eval_output);
return WEECHAT_RC_OK;
}

View File

@ -806,10 +806,10 @@ struct t_weechat_plugin
const char *info_name,
const char *description,
const char *args_description,
const char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
char *(*callback)(const void *pointer,
void *data,
const char *info_name,
const char *arguments),
const void *callback_pointer,
void *callback_data);
struct t_hook *(*hook_info_hashtable) (struct t_weechat_plugin *plugin,
@ -1003,9 +1003,8 @@ struct t_weechat_plugin
socklen_t address_length);
/* infos */
const char *(*info_get) (struct t_weechat_plugin *plugin,
const char *info_name,
const char *arguments);
char *(*info_get) (struct t_weechat_plugin *plugin, const char *info_name,
const char *arguments);
struct t_hashtable *(*info_get_hashtable) (struct t_weechat_plugin *plugin,
const char *info_name,
struct t_hashtable *hashtable);

View File

@ -80,8 +80,7 @@ xfer_file_resume (struct t_xfer *xfer, const char *filename)
void
xfer_file_find_filename (struct t_xfer *xfer)
{
const char *dir_separator;
char *path, *filename2;
char *dir_separator, *path, *filename2;
int length;
if (!XFER_IS_FILE(xfer->type))
@ -106,7 +105,11 @@ xfer_file_find_filename (struct t_xfer *xfer)
dir_separator = weechat_info_get ("dir_separator", "");
if (dir_separator
&& (xfer->local_filename[strlen (xfer->local_filename) - 1] != dir_separator[0]))
{
strcat (xfer->local_filename, dir_separator);
}
if (dir_separator)
free (dir_separator);
if (weechat_config_boolean (xfer_config_file_use_nick_in_filename))
{
strcat (xfer->local_filename, xfer->remote_nick);

View File

@ -644,8 +644,8 @@ xfer_new (const char *plugin_name, const char *plugin_id,
const char *local_filename)
{
struct t_xfer *new_xfer;
const char *ptr_color, *ptr_crc32;
char str_address[NI_MAXHOST];
const char *ptr_crc32;
char str_address[NI_MAXHOST], *color;
int rc;
new_xfer = xfer_alloc ();
@ -669,8 +669,10 @@ xfer_new (const char *plugin_name, const char *plugin_id,
new_xfer->type = type;
new_xfer->protocol = protocol;
new_xfer->remote_nick = strdup (remote_nick);
ptr_color = weechat_info_get ("irc_nick_color_name", remote_nick);
new_xfer->remote_nick_color = (ptr_color) ? strdup (ptr_color) : NULL;
color = weechat_info_get ("irc_nick_color_name", remote_nick);
new_xfer->remote_nick_color = (color) ? strdup (color) : NULL;
if (color)
free (color);
new_xfer->local_nick = (local_nick) ? strdup (local_nick) : NULL;
new_xfer->charset_modifier = (charset_modifier) ? strdup (charset_modifier) : NULL;
if (XFER_IS_FILE(type))