/soc/2015/mmcc/main: ab74d22a705b: Replace homestyle purple_util...
Michael McConville
mmcconville at mykolab.com
Thu Aug 13 13:05:47 EDT 2015
Changeset: ab74d22a705bc2f7d2d92090e99c90a71b8a51ec
Author: Michael McConville <mmcconville at mykolab.com>
Date: 2015-08-13 12:43 -0400
Branch: default
URL: https://hg.pidgin.im/soc/2015/mmcc/main/rev/ab74d22a705b
Description:
Replace homestyle purple_util_write_data_to_file_absolute() with glib's g_file_set_contents()
diffstat:
finch/gntplugin.c | 5 +-
libpurple/image.c | 13 +-
libpurple/plugins/ssl/ssl-gnutls.c | 10 +-
libpurple/plugins/ssl/ssl-nss.c | 10 +-
libpurple/protocols/gg/gg.c | 6 +-
libpurple/protocols/msn/slplink.c | 6 +-
libpurple/protocols/mxit/formcmds.c | 5 +-
libpurple/protocols/mxit/splashscreen.c | 5 +-
libpurple/util.c | 160 +------------------------------
libpurple/util.h | 20 ----
libpurple/xmlnode.c | 6 +-
pidgin/gtkconv.c | 5 +-
pidgin/gtkutils.c | 6 +-
13 files changed, 63 insertions(+), 194 deletions(-)
diffs (truncated from 529 to 300 lines):
diff --git a/finch/gntplugin.c b/finch/gntplugin.c
--- a/finch/gntplugin.c
+++ b/finch/gntplugin.c
@@ -458,6 +458,7 @@ install_selected_file_cb(gpointer handle
*/
char *path;
PurplePlugin *plugin;
+ GError *err = NULL;
g_return_if_fail(plugins.window);
@@ -484,7 +485,8 @@ install_selected_file_cb(gpointer handle
char *file = g_path_get_basename(filename);
g_free(path);
path = g_build_filename(purple_user_dir(), "plugins", file, NULL);
- if (purple_util_write_data_to_file_absolute(path, content, length)) {
+ g_file_set_contents(path, content, length, &err);
+ if (err != NULL) {
purple_plugin_destroy(plugin);
plugin = purple_plugin_probe(path);
if (!plugin) {
@@ -496,6 +498,7 @@ install_selected_file_cb(gpointer handle
} else {
}
}
+ g_error_free(err);
g_free(content);
}
g_free(path);
diff --git a/libpurple/image.c b/libpurple/image.c
--- a/libpurple/image.c
+++ b/libpurple/image.c
@@ -197,13 +197,15 @@ purple_image_new_from_data(gpointer data
return img;
}
+/* TODO: Should this now return a GError* instead? */
gboolean
purple_image_save(PurpleImage *image, const gchar *path)
{
PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
gconstpointer data;
gsize len;
- gboolean succ;
+ gboolean success;
+ GError *err = NULL;
g_return_val_if_fail(priv != NULL, FALSE);
g_return_val_if_fail(path != NULL, FALSE);
@@ -215,11 +217,14 @@ purple_image_save(PurpleImage *image, co
g_return_val_if_fail(data != NULL, FALSE);
g_return_val_if_fail(len > 0, FALSE);
- succ = purple_util_write_data_to_file_absolute(path, data, len);
- if (succ && priv->path == NULL)
+ g_file_set_contents(path, data, len, &err);
+ success = (err == NULL);
+ if (success && priv->path == NULL) {
priv->path = g_strdup(path);
+ }
+ g_error_free(err);
- return succ;
+ return success;
}
const gchar *
diff --git a/libpurple/plugins/ssl/ssl-gnutls.c b/libpurple/plugins/ssl/ssl-gnutls.c
--- a/libpurple/plugins/ssl/ssl-gnutls.c
+++ b/libpurple/plugins/ssl/ssl-gnutls.c
@@ -884,6 +884,8 @@ x509_importcerts_from_file(const gchar *
* @param crt Certificate to export
*
* @return TRUE if success, otherwise FALSE
+ *
+ * TODO: should this now return a GError* instead?
*/
static gboolean
x509_export_certificate(const gchar *filename, PurpleCertificate *crt)
@@ -892,7 +894,8 @@ x509_export_certificate(const gchar *fil
int ret;
gchar * out_buf; /* Data to output */
size_t out_size; /* Output size */
- gboolean success = FALSE;
+ gboolean success;
+ GError *err = NULL;
/* Paranoia paranoia paranoia! */
g_return_val_if_fail(filename, FALSE);
@@ -925,9 +928,10 @@ x509_export_certificate(const gchar *fil
}
/* Write it out to an actual file */
- success = purple_util_write_data_to_file_absolute(filename,
- out_buf, out_size);
+ g_file_set_contents(filename, out_buf, out_size, &err);
+ success = (err == NULL);
+ g_error_free(err);
g_free(out_buf);
return success;
}
diff --git a/libpurple/plugins/ssl/ssl-nss.c b/libpurple/plugins/ssl/ssl-nss.c
--- a/libpurple/plugins/ssl/ssl-nss.c
+++ b/libpurple/plugins/ssl/ssl-nss.c
@@ -749,7 +749,10 @@ x509_importcerts_from_file(const gchar *
* @return TRUE if success, otherwise FALSE
*/
/* This function should not be so complicated, but NSS doesn't seem to have a
- "convert yon certificate to PEM format" function. */
+ "convert yon certificate to PEM format" function.
+
+ TODO: Should this now return GError* instead?
+ */
static gboolean
x509_export_certificate(const gchar *filename, PurpleCertificate *crt)
{
@@ -758,6 +761,7 @@ x509_export_certificate(const gchar *fil
gchar *b64crt;
gchar *pemcrt;
gboolean ret = FALSE;
+ GError *err = NULL;
g_return_val_if_fail(filename, FALSE);
g_return_val_if_fail(crt, FALSE);
@@ -785,8 +789,10 @@ x509_export_certificate(const gchar *fil
function; hence, we'll let NSPR free it. */
/* Finally, dump the silly thing to a file. */
- ret = purple_util_write_data_to_file_absolute(filename, pemcrt, -1);
+ g_file_set_contents(filename, pemcrt, -1, &err);
+ ret = (err == NULL);
+ g_error_free(err);
g_free(pemcrt);
return ret;
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -114,8 +114,8 @@ uin_t ggp_own_uin(PurpleConnection *gc)
static void ggp_callback_buddylist_save_ok(PurpleConnection *gc, const char *filename)
{
PurpleAccount *account = purple_connection_get_account(gc);
-
char *buddylist = ggp_buddylist_dump(account);
+ GError *err = NULL;
purple_debug_info("gg", "Saving...\n");
purple_debug_info("gg", "file = %s\n", filename);
@@ -127,7 +127,8 @@ static void ggp_callback_buddylist_save_
return;
}
- if (purple_util_write_data_to_file_absolute(filename, buddylist, -1)) {
+ g_file_set_contents(filename, buddylist, -1, &err);
+ if (err == NULL) {
purple_notify_info(account, _("Save Buddylist..."),
_("Buddylist saved successfully!"), NULL,
purple_request_cpar_from_connection(gc));
@@ -140,6 +141,7 @@ static void ggp_callback_buddylist_save_
g_free(primary);
}
+ g_error_free(err);
g_free(buddylist);
}
diff --git a/libpurple/protocols/msn/slplink.c b/libpurple/protocols/msn/slplink.c
--- a/libpurple/protocols/msn/slplink.c
+++ b/libpurple/protocols/msn/slplink.c
@@ -46,15 +46,17 @@ debug_part_to_file(MsnSlpMessage *msg, g
char *data;
int c;
gsize data_size;
+ GError *err = NULL;
dir = send ? "send" : "recv";
c = send ? m_sc++ : m_rc++;
tmp = g_strdup_printf("%s/msntest/%s/%03d", purple_user_dir(), dir, c);
data = msn_slpmsg_serialize(msg, &data_size);
- if (!purple_util_write_data_to_file_absolute(tmp, data, data_size))
- {
+ g_file_set_contents(tmp, data, data_size, &err);
+ if (err != NULL) {
purple_debug_error("msn", "could not save debug file\n");
}
+ g_error_free(err);
g_free(tmp);
}
#endif
diff --git a/libpurple/protocols/mxit/formcmds.c b/libpurple/protocols/mxit/formcmds.c
--- a/libpurple/protocols/mxit/formcmds.c
+++ b/libpurple/protocols/mxit/formcmds.c
@@ -404,6 +404,7 @@ static void command_imagestrip(struct MX
char* escname;
char* escvalidator;
char* filename;
+ GError* err = NULL;
/* base64 decode the image data */
rawimg = purple_base64_decode(tmp, &rawimglen);
@@ -419,8 +420,10 @@ static void command_imagestrip(struct MX
escvalidator = g_strdup(purple_escape_filename(validator));
filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s-%s-%s.png", dir, escfrom, escname, escvalidator);
- purple_util_write_data_to_file_absolute(filename, (char*) rawimg, rawimglen);
+ /* XXX: we never check whether this write succeeds */
+ g_file_set_contents(filename, (char*) rawimg, rawimglen, &err);
+ g_error_free(err);
g_free(dir);
g_free(escfrom);
g_free(escname);
diff --git a/libpurple/protocols/mxit/splashscreen.c b/libpurple/protocols/mxit/splashscreen.c
--- a/libpurple/protocols/mxit/splashscreen.c
+++ b/libpurple/protocols/mxit/splashscreen.c
@@ -115,6 +115,7 @@ void splash_update(struct MXitSession* s
{
char* dir;
char* filename;
+ GError* err = NULL;
/* Remove the current splash-screen */
splash_remove(session);
@@ -124,12 +125,14 @@ void splash_update(struct MXitSession* s
purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR); /* ensure directory exists */
filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s.png", dir, purple_escape_filename(splashId));
- if (purple_util_write_data_to_file_absolute(filename, data, datalen)) {
+ g_file_set_contents(filename, data, datalen, &err);
+ if (err == NULL) {
/* Store new splash-screen ID to settings */
purple_account_set_string(session->acc, MXIT_CONFIG_SPLASHID, splashId);
purple_account_set_bool(session->acc, MXIT_CONFIG_SPLASHCLICK, clickable );
}
+ g_error_free(err);
g_free(dir);
g_free(filename);
}
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -2943,6 +2943,8 @@ int purple_build_dir (const char *path,
* This function is long and beautiful, like my--um, yeah. Anyway,
* it includes lots of error checking so as we don't overwrite
* people's settings if there is a problem writing the new values.
+ *
+ * TODO: We should probably find a glib function to replace this with.
*/
gboolean
purple_util_write_data_to_file(const char *filename, const char *data, gssize size)
@@ -2950,6 +2952,7 @@ purple_util_write_data_to_file(const cha
const char *user_dir = purple_user_dir();
gchar *filename_full;
gboolean ret = FALSE;
+ GError *err = NULL;
g_return_val_if_fail(user_dir != NULL, FALSE);
@@ -2969,163 +2972,14 @@ purple_util_write_data_to_file(const cha
filename_full = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", user_dir, filename);
- ret = purple_util_write_data_to_file_absolute(filename_full, data, size);
-
+ g_file_set_contents(filename_full, data, size, &err);
+ ret = (err == NULL);
+
+ g_error_free(err);
g_free(filename_full);
return ret;
}
-gboolean
-purple_util_write_data_to_file_absolute(const char *filename_full, const char *data, gssize size)
-{
- gchar *filename_temp;
- FILE *file;
- gsize real_size, byteswritten;
- GStatBuf st;
-#ifndef HAVE_FILENO
- int fd;
-#endif
-
- purple_debug_misc("util", "Writing file %s",
- filename_full);
-
- g_return_val_if_fail((size >= -1), FALSE);
-
- filename_temp = g_strdup_printf("%s.save", filename_full);
-
- /* Remove an old temporary file, if one exists */
- if (g_file_test(filename_temp, G_FILE_TEST_EXISTS))
- {
- if (g_unlink(filename_temp) == -1)
- {
- purple_debug_error("util", "Error removing old file "
- "%s: %s\n",
More information about the Commits
mailing list