diff options
Diffstat (limited to 'src/common/plugin.c')
-rw-r--r-- | src/common/plugin.c | 117 |
1 files changed, 59 insertions, 58 deletions
diff --git a/src/common/plugin.c b/src/common/plugin.c index d83b69ff..a397c878 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -161,16 +161,12 @@ plugin_free (hexchat_plugin *pl, int do_deinit, int allow_refuse) xit: if (pl->free_strings) { - if (pl->name) - free (pl->name); - if (pl->desc) - free (pl->desc); - if (pl->version) - free (pl->version); + g_free (pl->name); + g_free (pl->desc); + g_free (pl->version); } - if (pl->filename) - free ((char *)pl->filename); - free (pl); + g_free ((char *)pl->filename); + g_free (pl); plugin_list = g_slist_remove (plugin_list, pl); @@ -188,7 +184,7 @@ plugin_list_add (hexchat_context *ctx, char *filename, const char *name, { hexchat_plugin *pl; - pl = malloc (sizeof (hexchat_plugin)); + pl = g_new (hexchat_plugin, 1); pl->handle = handle; pl->filename = filename; pl->context = ctx; @@ -239,9 +235,7 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func, hexchat_plugin *pl; char *file; - file = NULL; - if (filename) - file = strdup (filename); + file = g_strdup (filename); pl = plugin_list_add (sess, file, file, NULL, NULL, handle, deinit_func, fake, FALSE); @@ -361,15 +355,11 @@ plugin_kill_all (void) #ifdef USE_PLUGIN -/* load a plugin from a filename. Returns: NULL-success or an error string */ - -char * -plugin_load (session *sess, char *filename, char *arg) +GModule * +module_load (char *filename) { void *handle; char *filepart; - hexchat_init_func *init_func; - hexchat_deinit_func *deinit_func; char *pluginpath; /* get the filename without path */ @@ -389,6 +379,18 @@ plugin_load (session *sess, char *filename, char *arg) handle = g_module_open (filename, 0); } + return handle; +} + +/* load a plugin from a filename. Returns: NULL-success or an error string */ + +char * +plugin_load (session *sess, char *filename, char *arg) +{ + GModule *handle = module_load (filename); + hexchat_init_func *init_func; + hexchat_deinit_func *deinit_func; + if (handle == NULL) return (char *)g_module_error (); @@ -596,7 +598,7 @@ xit: if (!hook || hook->type == HOOK_DELETED) { hook_list = g_slist_remove (hook_list, hook); - free (hook); + g_free (hook); } list = next; } @@ -615,13 +617,7 @@ plugin_emit_command (session *sess, char *name, char *word[], char *word_eol[]) hexchat_event_attrs * hexchat_event_attrs_create (hexchat_plugin *ph) { - hexchat_event_attrs *attrs; - - attrs = g_malloc (sizeof (*attrs)); - - attrs->server_time_utc = (time_t) 0; - - return attrs; + return g_new0 (hexchat_event_attrs, 1); } void @@ -671,26 +667,31 @@ plugin_emit_dummy_print (session *sess, char *name) } int -plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval, - int len, char *string) +plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval, gunichar key) { char *word[PDIWORDS]; char keyval_str[16]; char state_str[16]; char len_str[16]; - int i; + char key_str[7]; + int i, len; if (!hook_list) return 0; sprintf (keyval_str, "%u", keyval); sprintf (state_str, "%u", state); + if (!key) + len = 0; + else + len = g_unichar_to_utf8 (key, key_str); + key_str[len] = '\0'; sprintf (len_str, "%d", len); word[0] = "Key Press"; word[1] = keyval_str; word[2] = state_str; - word[3] = string; + word[3] = key_str; word[4] = len_str; for (i = 5; i < PDIWORDS; i++) word[i] = "\000"; @@ -796,15 +797,11 @@ plugin_add_hook (hexchat_plugin *pl, int type, int pri, const char *name, { hexchat_hook *hook; - hook = malloc (sizeof (hexchat_hook)); - memset (hook, 0, sizeof (hexchat_hook)); - + hook = g_new0 (hexchat_hook, 1); hook->type = type; hook->pri = pri; - if (name) - hook->name = strdup (name); - if (help_text) - hook->help_text = strdup (help_text); + hook->name = g_strdup (name); + hook->help_text = g_strdup (help_text); hook->callback = callb; hook->pl = pl; hook->userdata = userdata; @@ -892,10 +889,8 @@ hexchat_unhook (hexchat_plugin *ph, hexchat_hook *hook) hook->type = HOOK_DELETED; /* expunge later */ - if (hook->name) - free (hook->name); /* NULL for timers & fds */ - if (hook->help_text) - free (hook->help_text); /* NULL for non-commands */ + g_free (hook->name); /* NULL for timers & fds */ + g_free (hook->help_text); /* NULL for non-commands */ return hook->userdata; } @@ -988,8 +983,7 @@ hexchat_printf (hexchat_plugin *ph, const char *format, ...) void hexchat_command (hexchat_plugin *ph, const char *command) { - char *conv; - int len = -1; + char *command_utf8; if (!is_session (ph->context)) { @@ -998,9 +992,9 @@ hexchat_command (hexchat_plugin *ph, const char *command) } /* scripts/plugins continue to send non-UTF8... *sigh* */ - conv = text_validate ((char **)&command, &len); - handle_command (ph->context, (char *)command, FALSE); - g_free (conv); + command_utf8 = text_fixup_invalid_utf8 (command, -1, NULL); + handle_command (ph->context, command_utf8, FALSE); + g_free (command_utf8); } void @@ -1263,8 +1257,7 @@ hexchat_list_get (hexchat_plugin *ph, const char *name) { hexchat_list *list; - list = malloc (sizeof (hexchat_list)); - list->pos = NULL; + list = g_new0 (hexchat_list, 1); switch (str_hash (name)) { @@ -1299,7 +1292,7 @@ hexchat_list_get (hexchat_plugin *ph, const char *name) } /* fall through */ default: - free (list); + g_free (list); return NULL; } @@ -1311,7 +1304,7 @@ hexchat_list_free (hexchat_plugin *ph, hexchat_list *xlist) { if (xlist->type == LIST_USERS) g_slist_free (xlist->head); - free (xlist); + g_free (xlist); } int @@ -1531,7 +1524,14 @@ hexchat_list_int (hexchat_plugin *ph, hexchat_list *xlist, const char *name) case 0x34207553: /* address32 */ return ((struct DCC *)data)->addr; case 0x181a6: /* cps */ - return ((struct DCC *)data)->cps; + { + gint64 cps = ((struct DCC *)data)->cps; + if (cps <= INT_MAX) + { + return (int) cps; + } + return INT_MAX; + } case 0x349881: /* port */ return ((struct DCC *)data)->port; case 0x1b254: /* pos */ @@ -1569,7 +1569,7 @@ hexchat_list_int (hexchat_plugin *ph, hexchat_list *xlist, const char *name) case 0x5cfee87: /* flags */ /* used if text_strip is unset */ /* 16 */ tmp <<= 1; - tmp = ((struct session *)data)->text_strip; /* 15 */ + tmp |= ((struct session *)data)->text_strip; /* 15 */ tmp <<= 1; /* used if text_scrollback is unset */ /* 14 */ tmp <<= 1; @@ -1644,8 +1644,8 @@ hexchat_plugingui_add (hexchat_plugin *ph, const char *filename, const char *version, char *reserved) { #ifdef USE_PLUGIN - ph = plugin_list_add (NULL, strdup (filename), strdup (name), strdup (desc), - strdup (version), NULL, NULL, TRUE, TRUE); + ph = plugin_list_add (NULL, g_strdup (filename), g_strdup (name), g_strdup (desc), + g_strdup (version), NULL, NULL, TRUE, TRUE); fe_pluginlist_update (); #endif @@ -1771,6 +1771,8 @@ hexchat_pluginpref_set_str_real (hexchat_plugin *pl, const char *var, const char { g_free (confname); g_free (confname_tmp); + if (fpIn) + fclose (fpIn); return 0; } else if (fpIn == NULL) /* no previous config file, no parsing */ @@ -1819,7 +1821,7 @@ hexchat_pluginpref_set_str_real (hexchat_plugin *pl, const char *var, const char { prevSetting = 0; - while (fscanf (fpIn, " %[^\n]", line_bufp) != EOF) /* read whole lines including whitespaces */ + while (fscanf (fpIn, " %511[^\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 */ @@ -1908,7 +1910,6 @@ hexchat_pluginpref_get_str_real (hexchat_plugin *pl, const char *var, char *dest g_free (confname); return 0; } - g_free (confname); if (!cfg_get_str (cfg, var, buf, sizeof(buf))) @@ -1937,7 +1938,7 @@ hexchat_pluginpref_set_int (hexchat_plugin *pl, const char *var, int value) { char buffer[12]; - snprintf (buffer, sizeof (buffer), "%d", value); + g_snprintf (buffer, sizeof (buffer), "%d", value); return hexchat_pluginpref_set_str_real (pl, var, buffer, 1); } |