Compare commits

...

18 Commits

Author SHA1 Message Date
8ff5b53525 Fixup 2015-04-08 06:27:07 -04:00
77141cb080 Fixup 2015-04-07 20:08:42 -04:00
cff0b31fb9 Fixup 2015-04-07 10:46:43 -04:00
d1bddc468e plugin: Migrate pluginpref to GKeyFile
This removes the fixed length on all settings and
cleans up a lot of code. The fixed buffer functions
have been deprecated but still function.
2015-04-07 10:20:46 -04:00
c86389f99b Fix possible overflow in pluginpref
Closes #1265
2015-04-07 06:38:59 -04:00
66f2f3a84a Improve /AWAY help message
Closes #1343
2015-04-05 00:54:52 -04:00
f8c7ea3672 Fix some text event descriptions 2015-04-04 04:29:39 -04:00
e313a82ab4 sysinfo: Strip trailing space on video card 2015-03-20 05:38:22 -04:00
9024a5c71b Fix typo 2015-03-20 05:37:27 -04:00
f03b6314b4 Remove unused files 2015-03-20 05:36:51 -04:00
ae2e5ab092 Fix conflicting type in header
gsize and size_t are not the same thing
2015-03-20 04:58:00 -04:00
167eb11ea7 Fixup 455fa24d
-Wformat=2 includes format-nonliteral
2015-03-19 17:21:41 -04:00
1cc06f9301 Fixup dc69f24ae
It still has to be in hex...
2015-03-19 16:47:37 -04:00
455fa24d63 configure: Remove a warning
Used everywhere needs to be fixed
2015-03-19 16:36:43 -04:00
dc69f24ae5 Use correct type for colors 2015-03-19 16:30:03 -04:00
b4906f3d23 Fix warnings 2015-03-19 16:06:49 -04:00
4e338a2b70 configure: Clean up testing warnings and add more 2015-03-19 16:04:04 -04:00
98fefcd162 Switch from mozilla-build to msys2. 2015-03-15 19:06:29 -07:00
18 changed files with 324 additions and 366 deletions

View File

@ -608,92 +608,27 @@ AM_CONDITIONAL(WITH_TM, test "x$theme_manager" != "xno")
AM_CONDITIONAL(PLATFORM_OSX, test "x$platform_osx" == "xyes")
dnl *********************************************************************
dnl ** GCC FLAGS ********************************************************
dnl ** CFLAGS ***********************************************************
dnl *********************************************************************
dnl Only use -Wall and -pipe if we have gcc
if test "x$GCC" = "xyes"; then
if test -z "`echo "$CFLAGS" | grep "\-Wall" 2> /dev/null`" ; then
CFLAGS="$CFLAGS -Wall"
fi
dnl these flags might be unwanted
if test x$minimalflags != xyes; then
if test "$system" = "Linux" -o "$system" = "FreeBSD"; then
if test -z "`echo "$CFLAGS" | grep "\-pipe" 2> /dev/null`" ; then
CFLAGS="$CFLAGS -pipe"
fi
fi
if test -z "`echo "$CFLAGS" | grep "\-g " 2> /dev/null`" ; then
CFLAGS="$CFLAGS -g"
fi
fi
dnl these flags might be unwanted
if test x$minimalflags != xyes; then
CC_CHECK_FLAGS_APPEND([CFLAGS], [CFLAGS], [-g])
fi
dnl does this compiler support -Wno-pointer-sign ?
AC_MSG_CHECKING([if $CC accepts -Wno-pointer-sign ])
safe_CFLAGS=$CFLAGS
CFLAGS="-Wno-pointer-sign"
AC_TRY_COMPILE(, [
return 0;
],
[
no_pointer_sign=yes
AC_MSG_RESULT([yes])
], [
no_pointer_sign=no
AC_MSG_RESULT([no])
CC_CHECK_FLAGS_APPEND([CFLAGS], [CFLAGS], [ \
-pipe \
-funsigned-char \
-Wall \
-Wextra \
-Wno-unused-parameter \
-Wno-sign-compare \
-Wno-pointer-sign \
-Wno-missing-field-initializers \
-Wno-unused-result \
-Werror=format-security \
-Werror=declaration-after-statement \
])
CFLAGS=$safe_CFLAGS
if test x$no_pointer_sign = xyes; then
CFLAGS="$CFLAGS -Wno-pointer-sign"
fi
dnl does this compiler support -funsigned-char ?
AC_MSG_CHECKING([if $CC accepts -funsigned-char ])
safe_CFLAGS=$CFLAGS
CFLAGS="-funsigned-char"
AC_TRY_COMPILE(, [
return 0;
],
[
unsigned_char=yes
AC_MSG_RESULT([yes])
], [
unsigned_char=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
if test x$unsigned_char = xyes; then
CFLAGS="$CFLAGS -funsigned-char"
fi
dnl does this compiler support -Wno-unused-result ?
AC_MSG_CHECKING([if $CC accepts -Wno-unused-result ])
safe_CFLAGS=$CFLAGS
CFLAGS="-Wno-unused-result"
AC_TRY_COMPILE(, [
return 0;
],
[
no_unused_result=yes
AC_MSG_RESULT([yes])
], [
no_unused_result=no
AC_MSG_RESULT([no])
])
CFLAGS=$safe_CFLAGS
if test x$no_unused_result = xyes; then
CFLAGS="$CFLAGS -Wno-unused-result"
fi
dnl *********************************************************************
dnl ** FUNCTIONS/LIBS/CFLAGS ********************************************
@ -747,7 +682,6 @@ AC_EGREP_CPP(lookupd, dnl
dnl freebsd needs this
LIBS="$LIBS $INTLLIBS"
CFLAGS="$CFLAGS $CPPFLAGS"
GUI_LIBS="$GUI_LIBS $COMMON_LIBS"

60
m4/ac-check-cflags.m4 Normal file
View File

@ -0,0 +1,60 @@
dnl Macros to check the presence of generic (non-typed) symbols.
dnl Copyright (c) 2006-2008 Diego Pettenò <flameeyes@gmail.com>
dnl Copyright (c) 2006-2008 xine project
dnl Copyright (c) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2, or (at your option)
dnl any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
dnl 02110-1301, USA.
dnl
dnl As a special exception, the copyright owners of the
dnl macro gives unlimited permission to copy, distribute and modify the
dnl configure scripts that are the output of Autoconf when processing the
dnl Macro. You need not follow the terms of the GNU General Public
dnl License when using or distributing such scripts, even though portions
dnl of the text of the Macro appear in them. The GNU General Public
dnl License (GPL) does govern all other use of the material that
dnl constitutes the Autoconf Macro.
dnl
dnl This special exception to the GPL applies to versions of the
dnl Autoconf Macro released by this project. When you make and
dnl distribute a modified version of the Autoconf Macro, you may extend
dnl this special exception to the GPL to apply to your modified version as
dnl well.
dnl Check if FLAG in ENV-VAR is supported by compiler and append it
dnl to WHERE-TO-APPEND variable
dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG])
AC_DEFUN([CC_CHECK_FLAG_APPEND], [
AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2],
AS_TR_SH([cc_cv_$2_$3]),
[eval "AS_TR_SH([cc_save_$2])='${$2}'"
eval "AS_TR_SH([$2])='$3'"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([int a = 0; int main(void) { return a; } ])],
[eval "AS_TR_SH([cc_cv_$2_$3])='yes'"],
[eval "AS_TR_SH([cc_cv_$2_$3])='no'"])
eval "AS_TR_SH([$2])='$cc_save_$2'"])
AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes],
[eval "$1='${$1} $3'"])
])
dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2])
AC_DEFUN([CC_CHECK_FLAGS_APPEND], [
for flag in $3; do
CC_CHECK_FLAG_APPEND($1, $2, $flag)
done
])

View File

@ -1,38 +0,0 @@
# Makefile stub for creating standalone plugin distributions.
plugin_dist: pg_dist pg_dist/config.status
pgi=`cd $(srcdir)/.. && pwd`; cd pg_dist; \
$(MAKE) $(AM_MAKEFLAGS) PLUGIN_INCLUDES=-I$$pgi distcheck dist
pg_dist: pg_distdir pg_dist/configure.in pg_dist/install-sh
cd pg_dist \
&& libtoolize --copy --force --automake \
&& automake --copy --add-missing --foreign \
&& autoconf -l ../$(top_srcdir)
pg_distdir: $(DISTFILES)
test -d pg_dist || mkdir pg_dist
for dfile in $(DISTFILES); do \
test -f $$dfile && cp $$dfile pg_dist \
|| test -f $(srcdir)/$$dfile && cp $(srcdir)/$$dfile pg_dist; done
sed '/Make.plugin/d' < $(srcdir)/Makefile.am > pg_dist/Makefile.am
pg_dist/configure.in: $(srcdir)/../plugin-conf.in
rm -f pg_dist/configure.in
test -f $(srcdir)/config.stub \
&& cat $(srcdir)/config.stub > pg_dist/configure.in || true
cat $(srcdir)/../plugin-conf.in | \
sed 's%@PLUGIN_VERSION@%$(PLUGIN_VERSION)%; \
s%@PLUGIN@%$(PLUGIN)%' >> pg_dist/configure.in
pg_dist/install-sh: pg_distdir
cp $(top_srcdir)/install-sh pg_dist
pg_dist/config.status: pg_dist/configure
cd pg_dist \
&& test -f config.status && $(SHELL) ./config.status --recheck \
|| $(SHELL) ./configure --enable-maintainer-mode
DISTCLEANFILES = pg_dist/* pg_dist
#

View File

@ -1,19 +0,0 @@
AC_INIT(@PLUGIN@-config.h.in)
AM_CONFIG_HEADER(@PLUGIN@-config.h)
AM_INIT_AUTOMAKE(hexchat-@PLUGIN@, @PLUGIN_VERSION@)
AM_MAINTAINER_MODE
AM_DISABLE_STATIC
AM_PROG_LIBTOOL
AC_ARG_WITH(plugin-includes,
[ --with-plugin-includes directory containing hexchat-plugin.h],
PLUGIN_INCLUDES=$enableval)
AC_SUBST(PLUGIN_INCLUDES)
hexchatlibdir=${libdir}/hexchat
AC_SUBST(hexchatlibdir)
AC_OUTPUT(
Makefile
)

View File

@ -390,7 +390,7 @@ static char *read_vga_name (IWbemClassObject *object)
return NULL;
}
return name_utf8;
return g_strchomp (name_utf8);
}
static char *read_hdd_info (IWbemClassObject *object)

View File

@ -32,7 +32,7 @@ src/fe-gtk/joind.c
src/fe-gtk/maingui.c
src/fe-gtk/menu.c
src/fe-gtk/notifygui.c
src/fe-gtk/plugin-notifications.c
src/fe-gtk/plugin-notification.c
src/fe-gtk/plugin-tray.c
src/fe-gtk/plugingui.c
src/fe-gtk/rawlog.c

View File

@ -226,12 +226,12 @@ cfg_put_str (int fh, char *var, char *value)
}
int
cfg_put_color (int fh, int r, int g, int b, char *var)
cfg_put_color (int fh, guint16 r, guint16 g, guint16 b, char *var)
{
char buf[400];
int len;
g_snprintf (buf, sizeof buf, "%s = %04x %04x %04x\n", var, r, g, b);
g_snprintf (buf, sizeof buf, "%s = %04hx %04hx %04hx\n", var, r, g, b);
len = strlen (buf);
return (write (fh, buf, len) == len);
}
@ -251,14 +251,14 @@ cfg_put_int (int fh, int value, char *var)
}
int
cfg_get_color (char *cfg, char *var, int *r, int *g, int *b)
cfg_get_color (char *cfg, char *var, guint16 *r, guint16 *g, guint16 *b)
{
char str[128];
if (!cfg_get_str (cfg, var, str, sizeof (str)))
return 0;
sscanf (str, "%04x %04x %04x", r, g, b);
sscanf (str, "%04hx %04hx %04hx", r, g, b);
return 1;
}

View File

@ -34,8 +34,8 @@ int cfg_get_bool (char *var);
int cfg_get_int_with_result (char *cfg, char *var, int *result);
int cfg_get_int (char *cfg, char *var);
int cfg_put_int (int fh, int value, char *var);
int cfg_get_color (char *cfg, char *var, int *r, int *g, int *b);
int cfg_put_color (int fh, int r, int g, int b, char *var);
int cfg_get_color (char *cfg, char *var, guint16 *r, guint16 *g, guint16 *b);
int cfg_put_color (int fh, guint16 r, guint16 g, guint16 b, char *var);
char *get_xdir (void);
int check_config_dir (void);
void load_default_config (void);

View File

@ -39,6 +39,16 @@
#define HEXCHAT_EAT_PLUGIN 2 /* don't let other plugins see this event */
#define HEXCHAT_EAT_ALL (HEXCHAT_EAT_HEXCHAT|HEXCHAT_EAT_PLUGIN) /* don't let anything see this event */
/* Taken from glib/gmacros.h */
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define HEXCHAT_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
#define HEXCHAT_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
#else
#define HEXCHAT_DEPRECATED_FOR(f)
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -193,6 +203,11 @@ struct _hexchat_plugin
hexchat_event_attrs *(*hexchat_event_attrs_create) (hexchat_plugin *ph);
void (*hexchat_event_attrs_free) (hexchat_plugin *ph,
hexchat_event_attrs *attrs);
char *(*hexchat_pluginpref_get_str_ptr) (hexchat_plugin *ph,
const char *var);
char **(*hexchat_pluginpref_list_keys) (hexchat_plugin *ph);
void (*hexchat_free_array) (hexchat_plugin *ph,
char **arr);
};
#endif
@ -380,16 +395,25 @@ void
hexchat_free (hexchat_plugin *ph,
void *ptr);
void
hexchat_free_array (hexchat_plugin *ph,
char **arr);
int
hexchat_pluginpref_set_str (hexchat_plugin *ph,
const char *var,
const char *value);
HEXCHAT_DEPRECATED_FOR(hexchat_pluginpref_get_str_ptr)
int
hexchat_pluginpref_get_str (hexchat_plugin *ph,
const char *var,
char *dest);
char *
hexchat_pluginpref_get_str_ptr (hexchat_plugin *ph,
const char *var);
int
hexchat_pluginpref_set_int (hexchat_plugin *ph,
const char *var,
@ -402,10 +426,14 @@ int
hexchat_pluginpref_delete (hexchat_plugin *ph,
const char *var);
HEXCHAT_DEPRECATED_FOR(hexchat_pluginpref_list_keys)
int
hexchat_pluginpref_list (hexchat_plugin *ph,
char *dest);
char **
hexchat_pluginpref_list_keys (hexchat_plugin *ph);
#if !defined(PLUGIN_C) && defined(WIN32)
#ifndef HEXCHAT_PLUGIN_HANDLE
#define HEXCHAT_PLUGIN_HANDLE (ph)
@ -445,12 +473,15 @@ hexchat_pluginpref_list (hexchat_plugin *ph,
#define hexchat_send_modes ((HEXCHAT_PLUGIN_HANDLE)->hexchat_send_modes)
#define hexchat_strip ((HEXCHAT_PLUGIN_HANDLE)->hexchat_strip)
#define hexchat_free ((HEXCHAT_PLUGIN_HANDLE)->hexchat_free)
#define hexchat_free_array ((HEXCHAT_PLUGIN_HANDLE)->hexchat_free_array)
#define hexchat_pluginpref_set_str ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_set_str)
#define hexchat_pluginpref_get_str ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_get_str)
#define hexchat_pluginpref_get_str_ptr ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_get_str_ptr)
#define hexchat_pluginpref_set_int ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_set_int)
#define hexchat_pluginpref_get_int ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_get_int)
#define hexchat_pluginpref_delete ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_delete)
#define hexchat_pluginpref_list ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_list)
#define hexchat_pluginpref_list_keys ((HEXCHAT_PLUGIN_HANDLE)->hexchat_pluginpref_list_keys)
#endif
#ifdef __cplusplus

View File

@ -3853,7 +3853,7 @@ const struct commands xc_cmds[] = {
N_("ALLCHANL <cmd>, sends a command to all channels on the current server")},
{"ALLSERV", cmd_allservers, 0, 0, 1,
N_("ALLSERV <cmd>, sends a command to all servers you're in")},
{"AWAY", cmd_away, 1, 0, 1, N_("AWAY [<reason>], sets you away")},
{"AWAY", cmd_away, 1, 0, 1, N_("AWAY [<reason>], sets you away (use /BACK to unset)")},
{"BACK", cmd_back, 1, 0, 1, N_("BACK, sets you back (not away)")},
{"BAN", cmd_ban, 1, 1, 1,
N_("BAN <mask> [<bantype>], bans everyone matching the mask from the current channel. If they are already on the channel this doesn't kick them (needs chanop)")},

View File

@ -27,12 +27,12 @@ static hexchat_plugin *ph;
static GSocketService *service;
static GHashTable *responses;
struct ident_info
typedef struct ident_info
{
GSocketConnection *conn;
gchar *username;
gchar read_buf[16];
} typedef ident_info;
} ident_info;
static int
identd_cleanup_response_cb (gpointer userdata)

View File

@ -120,6 +120,7 @@ static GSList *hook_list = NULL;
extern const struct prefs vars[]; /* cfgfiles.c */
static void pluginpref_save (hexchat_plugin *pl);
/* unload a plugin and remove it from our linked list */
@ -159,6 +160,10 @@ plugin_free (hexchat_plugin *pl, int do_deinit, int allow_refuse)
#endif
xit:
if (pl->keyfile)
{
g_key_file_free (pl->keyfile);
}
if (pl->free_strings)
{
g_free (pl->name);
@ -190,6 +195,7 @@ plugin_list_add (hexchat_context *ctx, char *filename, const char *name,
pl->context = ctx;
pl->name = (char *)name;
pl->desc = (char *)desc;
pl->keyfile = NULL;
pl->version = (char *)version;
pl->deinit_callback = deinit_func;
pl->fake = fake;
@ -278,12 +284,19 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func,
pl->hexchat_send_modes = hexchat_send_modes;
pl->hexchat_strip = hexchat_strip;
pl->hexchat_free = hexchat_free;
pl->hexchat_free_array = hexchat_free_array;
pl->hexchat_pluginpref_set_str = hexchat_pluginpref_set_str;
pl->hexchat_pluginpref_get_str = hexchat_pluginpref_get_str;
pl->hexchat_pluginpref_get_str_ptr = hexchat_pluginpref_get_str_ptr;
pl->hexchat_pluginpref_set_int = hexchat_pluginpref_set_int;
pl->hexchat_pluginpref_get_int = hexchat_pluginpref_get_int;
pl->hexchat_pluginpref_delete = hexchat_pluginpref_delete;
pl->hexchat_pluginpref_list_keys = hexchat_pluginpref_list_keys;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
pl->hexchat_pluginpref_get_str = hexchat_pluginpref_get_str;
pl->hexchat_pluginpref_list = hexchat_pluginpref_list;
G_GNUC_END_IGNORE_DEPRECATIONS
pl->hexchat_hook_server_attrs = hexchat_hook_server_attrs;
pl->hexchat_hook_print_attrs = hexchat_hook_print_attrs;
pl->hexchat_emit_print_attrs = hexchat_emit_print_attrs;
@ -1743,258 +1756,229 @@ hexchat_free (hexchat_plugin *ph, void *ptr)
g_free (ptr);
}
static int
hexchat_pluginpref_set_str_real (hexchat_plugin *pl, const char *var, const char *value, int mode) /* mode: 0 = delete, 1 = save */
void
hexchat_free_array (hexchat_plugin *ph, char **strv)
{
FILE *fpIn;
int fhOut;
int prevSetting;
char *confname;
char *confname_tmp;
char *escaped_value;
char *buffer;
char *buffer_tmp;
char line_buffer[512]; /* the same as in cfg_put_str */
char *line_bufp = line_buffer;
char *canon;
g_strfreev (strv);
}
canon = g_strdup (pl->name);
canonalize_key (canon);
confname = g_strdup_printf ("addon_%s.conf", canon);
g_free (canon);
confname_tmp = g_strdup_printf ("%s.new", confname);
#define DEFAULT_GROUP "DEFAULT"
#define DEFAULT_GROUP_TEXT "[DEFAULT]\n"
#define DEFAULT_GROUP_TEXT_LEN 10
fhOut = hexchat_open_file (confname_tmp, O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
fpIn = hexchat_fopen_file (confname, "r", 0);
static char *
pluginpref_create_filename (hexchat_plugin *pl, const char *extension)
{
char *confname, *tmp, *filename;
if (fhOut == -1) /* unable to save, abort */
tmp = g_strdup (pl->name);
canonalize_key (tmp);
confname = g_strdup_printf ("%s%caddon_%s.%s", get_xdir(), G_DIR_SEPARATOR, tmp, extension);
filename = g_filename_from_utf8 (confname, -1, NULL, NULL, NULL);
g_free (confname);
g_free (tmp);
return filename;
}
/* Migration simply means prepending a valid group
* to the old format, it is otherwise compatable */
static gboolean
pluginpref_migrate_file_real (const char *old_filename, const char *new_filename)
{
char *contents;
gsize len, newlen;
gboolean ret;
/* Just read the entire file, ideally it is fairly small */
if (!g_file_get_contents (old_filename, &contents, &len, NULL))
return FALSE;
/* Avoid duplicating data and just prepend the new group */
newlen = len + DEFAULT_GROUP_TEXT_LEN;
contents = g_realloc_n (contents, newlen, sizeof(char));
memmove (contents + DEFAULT_GROUP_TEXT_LEN, contents, len);
memcpy (contents, DEFAULT_GROUP_TEXT, DEFAULT_GROUP_TEXT_LEN);
ret = g_file_set_contents (new_filename, contents, (gssize)MIN(newlen, G_MAXSSIZE), NULL);
g_free (contents);
return ret;
}
static void
pluginpref_migrate_file (hexchat_plugin *pl, char *filename)
{
char *old_filename;
if (g_file_test (filename, G_FILE_TEST_EXISTS))
return;
old_filename = pluginpref_create_filename (pl, "conf");
if (g_file_test (old_filename, G_FILE_TEST_EXISTS))
{
g_free (confname);
g_free (confname_tmp);
if (fpIn)
fclose (fpIn);
return 0;
}
else if (fpIn == NULL) /* no previous config file, no parsing */
{
if (mode)
if (pluginpref_migrate_file_real (old_filename, filename))
{
escaped_value = g_strescape (value, NULL);
buffer = g_strdup_printf ("%s = %s\n", var, escaped_value);
g_free (escaped_value);
write (fhOut, buffer, strlen (buffer));
g_free (buffer);
close (fhOut);
buffer = g_build_filename (get_xdir (), confname, NULL);
g_free (confname);
buffer_tmp = g_build_filename (get_xdir (), confname_tmp, NULL);
g_free (confname_tmp);
#ifdef WIN32
g_unlink (buffer);
#endif
if (g_rename (buffer_tmp, buffer) == 0)
{
g_free (buffer);
g_free (buffer_tmp);
return 1;
}
else
{
g_free (buffer);
g_free (buffer_tmp);
return 0;
}
}
else
{
/* mode = 0, we want to delete but the config file and thus the given setting does not exist, we're ready */
close (fhOut);
g_free (confname);
g_free (confname_tmp);
return 1;
/* Migration worked, move the old one as a backup incase
* keyfile is invalid and data lost but also to avoid confusion */
char *backup_filename = pluginpref_create_filename (pl, "bak");
g_rename (old_filename, backup_filename);
g_free (backup_filename);
}
}
else /* existing config file, preserve settings and find & replace current var value if any */
g_free (old_filename);
}
static GKeyFile *
pluginpref_load_file (hexchat_plugin *pl)
{
char *filename;
GKeyFile *file;
filename = pluginpref_create_filename (pl, "ini");
if (!filename)
return NULL;
file = g_key_file_new ();
pluginpref_migrate_file (pl, filename);
/* It failing doesn't matter, a new file will just be created */
g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, NULL);
g_free (filename);
return file;
}
#define PLUGINPREF_INIT_KEYFILE(pl,ret) G_STMT_START \
if (!pl->keyfile) \
{ \
if (!(pl->keyfile = pluginpref_load_file (pl))) \
return ret; \
} \
G_STMT_END
static void
pluginpref_save (hexchat_plugin *pl)
{
gchar *data, *filename;
gsize length;
filename = pluginpref_create_filename (pl, "ini");
if (!filename)
return;
if (!(data = g_key_file_to_data (pl->keyfile, &length, NULL)))
{
prevSetting = 0;
while (fscanf (fpIn, " %[^\n]", line_bufp) != EOF) /* read whole lines including whitespaces */
{
buffer_tmp = g_strdup_printf ("%s ", var); /* add one space, this way it works against var - var2 checks too */
if (strncmp (buffer_tmp, line_buffer, strlen (var) + 1) == 0) /* given setting already exists */
{
if (mode) /* overwrite the existing matching setting if we are in save mode */
{
escaped_value = g_strescape (value, NULL);
buffer = g_strdup_printf ("%s = %s\n", var, escaped_value);
g_free (escaped_value);
}
else /* erase the setting in delete mode */
{
buffer = g_strdup ("");
}
prevSetting = 1;
}
else
{
buffer = g_strdup_printf ("%s\n", line_buffer); /* preserve the existing different settings */
}
write (fhOut, buffer, strlen (buffer));
g_free (buffer);
g_free (buffer_tmp);
}
fclose (fpIn);
if (!prevSetting && mode) /* var doesn't exist currently, append if we're in save mode */
{
escaped_value = g_strescape (value, NULL);
buffer = g_strdup_printf ("%s = %s\n", var, escaped_value);
g_free (escaped_value);
write (fhOut, buffer, strlen (buffer));
g_free (buffer);
}
close (fhOut);
buffer = g_build_filename (get_xdir (), confname, NULL);
g_free (confname);
buffer_tmp = g_build_filename (get_xdir (), confname_tmp, NULL);
g_free (confname_tmp);
#ifdef WIN32
g_unlink (buffer);
#endif
if (g_rename (buffer_tmp, buffer) == 0)
{
g_free (buffer);
g_free (buffer_tmp);
return 1;
}
else
{
g_free (buffer);
g_free (buffer_tmp);
return 0;
}
g_free (filename);
return;
}
g_file_set_contents (filename, data, length, NULL);
g_free (data);
g_free (filename);
}
int
hexchat_pluginpref_set_str (hexchat_plugin *pl, const char *var, const char *value)
{
return hexchat_pluginpref_set_str_real (pl, var, value, 1);
PLUGINPREF_INIT_KEYFILE (pl, 0);
g_key_file_set_string (pl->keyfile, DEFAULT_GROUP, var, value);
pluginpref_save (pl);
return 1;
}
static int
hexchat_pluginpref_get_str_real (hexchat_plugin *pl, const char *var, char *dest, int dest_len)
char *
hexchat_pluginpref_get_str_ptr (hexchat_plugin *pl, const char *var)
{
char *confname, *canon, *cfg, *unescaped_value;
char buf[512];
PLUGINPREF_INIT_KEYFILE (pl, 0);
canon = g_strdup (pl->name);
canonalize_key (canon);
confname = g_strdup_printf ("%s%caddon_%s.conf", get_xdir(), G_DIR_SEPARATOR, canon);
g_free (canon);
if (!g_file_get_contents (confname, &cfg, NULL, NULL))
{
g_free (confname);
return 0;
}
g_free (confname);
if (!cfg_get_str (cfg, var, buf, sizeof(buf)))
{
g_free (cfg);
return 0;
}
unescaped_value = g_strcompress (buf);
g_strlcpy (dest, unescaped_value, dest_len);
g_free (unescaped_value);
g_free (cfg);
return 1;
return g_key_file_get_string (pl->keyfile, DEFAULT_GROUP, var, NULL);
}
int
hexchat_pluginpref_get_str (hexchat_plugin *pl, const char *var, char *dest)
{
char *value;
if (!(value = hexchat_pluginpref_get_str_ptr (pl, var)))
return 0;
/* All users of this must ensure dest is >= 512... */
return hexchat_pluginpref_get_str_real (pl, var, dest, 512);
safe_strcpy (dest, value, 512);
g_free (value);
return 1;
}
int
hexchat_pluginpref_set_int (hexchat_plugin *pl, const char *var, int value)
{
char buffer[12];
PLUGINPREF_INIT_KEYFILE (pl, 0);
g_snprintf (buffer, sizeof (buffer), "%d", value);
return hexchat_pluginpref_set_str_real (pl, var, buffer, 1);
g_key_file_set_integer (pl->keyfile, DEFAULT_GROUP, var, value);
pluginpref_save (pl);
return 1;
}
int
hexchat_pluginpref_get_int (hexchat_plugin *pl, const char *var)
{
char buffer[12];
int value;
GError *error = NULL;
if (hexchat_pluginpref_get_str_real (pl, var, buffer, sizeof(buffer)))
{
return atoi (buffer);
}
else
PLUGINPREF_INIT_KEYFILE (pl, -1);
value = g_key_file_get_integer (pl->keyfile, DEFAULT_GROUP, var, &error);
if (error)
{
if (error->code == G_KEY_FILE_ERROR_INVALID_VALUE)
{
g_error_free (error);
return 0; /* This is to duplicate previous behavior of atoi() */
}
g_error_free (error);
return -1;
}
return value;
}
int
hexchat_pluginpref_delete (hexchat_plugin *pl, const char *var)
{
return hexchat_pluginpref_set_str_real (pl, var, 0, 0);
gboolean ret;
PLUGINPREF_INIT_KEYFILE (pl, 0);
ret = g_key_file_remove_key (pl->keyfile, DEFAULT_GROUP, var, NULL);
pluginpref_save (pl);
return ret;
}
char **
hexchat_pluginpref_list_keys (hexchat_plugin *pl)
{
PLUGINPREF_INIT_KEYFILE (pl, NULL);
return g_key_file_get_keys (pl->keyfile, DEFAULT_GROUP, NULL, NULL);
}
int
hexchat_pluginpref_list (hexchat_plugin *pl, char* dest)
{
FILE *fpIn;
char confname[64];
char buffer[512]; /* the same as in cfg_put_str */
char *bufp = buffer;
char *token;
char **keys, *keystr;
token = g_strdup (pl->name);
canonalize_key (token);
sprintf (confname, "addon_%s.conf", token);
g_free (token);
fpIn = hexchat_fopen_file (confname, "r", 0);
if (fpIn == NULL) /* no existing config file, no parsing */
{
if (!(keys = hexchat_pluginpref_list_keys (pl)))
return 0;
}
else /* existing config file, get list of settings */
{
strcpy (dest, ""); /* clean up garbage */
while (fscanf (fpIn, " %[^\n]", bufp) != EOF) /* read whole lines including whitespaces */
{
token = strtok (buffer, "=");
g_strlcat (dest, g_strchomp (token), 4096); /* Dest must not be smaller than this */
g_strlcat (dest, ",", 4096);
}
fclose (fpIn);
}
keystr = g_strjoinv (",", keys);
safe_strcpy (dest, keystr, 4096);
g_strlcat (dest, ",", 4096); /* Must end in , for legacy reasons */
g_free (keystr);
g_strfreev (keys);
return 1;
}

View File

@ -149,6 +149,11 @@ struct _hexchat_plugin
hexchat_event_attrs *(*hexchat_event_attrs_create) (hexchat_plugin *ph);
void (*hexchat_event_attrs_free) (hexchat_plugin *ph,
hexchat_event_attrs *attrs);
char *(*hexchat_pluginpref_get_str_ptr) (hexchat_plugin *ph,
const char *var);
char **(*hexchat_pluginpref_list_keys) (hexchat_plugin *ph);
void (*hexchat_free_array) (hexchat_plugin *ph,
char **arr);
/* PRIVATE FIELDS! */
void *handle; /* from dlopen */
@ -156,6 +161,7 @@ struct _hexchat_plugin
char *name;
char *desc;
char *version;
GKeyFile *keyfile; /* pluginpref */
session *context;
void *deinit_callback; /* pointer to hexchat_plugin_deinit */
unsigned int fake:1; /* fake plugin. Added by hexchat_plugingui_add() */

View File

@ -1127,26 +1127,26 @@ static char * const pevt_chanrmlimit_help[] = {
};
static char * const pevt_chandeop_help[] = {
N_("The nick of the person of did the deop'ing"),
N_("The nick of the person who did the deop'ing"),
N_("The nick of the person who has been deop'ed"),
};
static char * const pevt_chandehop_help[] = {
N_("The nick of the person of did the dehalfop'ing"),
N_("The nick of the person who did the dehalfop'ing"),
N_("The nick of the person who has been dehalfop'ed"),
};
static char * const pevt_chandevoice_help[] = {
N_("The nick of the person of did the devoice'ing"),
N_("The nick of the person who did the devoice'ing"),
N_("The nick of the person who has been devoice'ed"),
};
static char * const pevt_chanunban_help[] = {
N_("The nick of the person of did the unban'ing"),
N_("The nick of the person who did the unban'ing"),
N_("The ban mask"),
};
static char * const pevt_chanunquiet_help[] = {
N_("The nick of the person of did the unquiet'ing"),
N_("The nick of the person who did the unquiet'ing"),
N_("The quiet mask"),
};

View File

@ -246,11 +246,11 @@ expand_homedir (char *file)
if (file[0] == '~')
{
char *slash_pos;
if (file[1] == '\0' || file[1] == '/')
return g_strconcat (g_get_home_dir (), &file[1], NULL);
char *slash_pos;
user = g_strdup(file);
slash_pos = strchr(user, '/');

View File

@ -80,5 +80,5 @@ char *encode_sasl_pass_blowfish (char *user, char *pass, char *data);
char *encode_sasl_pass_aes (char *user, char *pass, char *data);
char *challengeauth_response (char *username, char *password, char *challenge);
size_t strftime_validated (char *dest, size_t destsize, const char *format, const struct tm *time);
size_t strftime_utf8 (char *dest, size_t destsize, const char *format, time_t time);
gsize strftime_utf8 (char *dest, gsize destsize, const char *format, time_t time);
#endif

View File

@ -110,7 +110,7 @@ palette_load (void)
char prefname[256];
struct stat st;
char *cfg;
int red, green, blue;
guint16 red, green, blue;
fh = hexchat_open_file ("colors.conf", O_RDONLY, 0, 0);
if (fh != -1)

View File

@ -4,13 +4,13 @@
<!-- SPECIFY YOUR DEPENDENCY DIRECTORIES HERE -->
<YourDepsPath>c:\mozilla-build\hexchat\gtk</YourDepsPath>
<YourGendefPath>c:\mozilla-build\gendef</YourGendefPath>
<YourMsgfmtPath>c:\mozilla-build\msgfmt</YourMsgfmtPath>
<YourPerlPath>c:\mozilla-build\perl-5.20</YourPerlPath>
<YourPython2Path>c:\mozilla-build\python-2.7</YourPython2Path>
<YourPython3Path>c:\mozilla-build\python-3.4</YourPython3Path>
<YourWinSparklePath>c:\mozilla-build\WinSparkle</YourWinSparklePath>
<YourDepsPath>c:\gtk-build\gtk</YourDepsPath>
<YourGendefPath>c:\gtk-build\gendef</YourGendefPath>
<YourMsgfmtPath>c:\gtk-build\msgfmt</YourMsgfmtPath>
<YourPerlPath>c:\gtk-build\perl-5.20</YourPerlPath>
<YourPython2Path>c:\gtk-build\python-2.7</YourPython2Path>
<YourPython3Path>c:\gtk-build\python-3.4</YourPython3Path>
<YourWinSparklePath>c:\gtk-build\WinSparkle</YourWinSparklePath>
<!-- YOU SHOULDN'T TOUCH ANYTHING BELOW -->