static void purple_buddy_icon_data_cache(PurpleStoredImage *img) { const char *dirname; char *path; g_return_if_fail(img != NULL); if (!purple_buddy_icons_is_caching()) return; dirname = purple_buddy_icons_get_cache_dir(); path = g_build_filename(dirname, purple_imgstore_get_filename(img), NULL); if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) { purple_debug_info("buddyicon", "Creating icon cache directory.\n"); if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) { purple_debug_error("buddyicon", "Unable to create directory %s: %s\n", dirname, g_strerror(errno)); } } if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) { purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img), purple_imgstore_get_size(img)); } g_free(path); }
/** * Exports a PEM-formatted X.509 certificate to the specified file. * @param filename Filename to export to. Format will be PEM * @param crt Certificate to export * * @return TRUE if success, otherwise FALSE */ static gboolean x509_export_certificate(const gchar *filename, PurpleCertificate *crt) { gnutls_x509_crt crt_dat; /* GnuTLS cert struct */ int ret; gchar * out_buf; /* Data to output */ size_t out_size; /* Output size */ gboolean success = FALSE; /* Paranoia paranoia paranoia! */ g_return_val_if_fail(filename, FALSE); g_return_val_if_fail(crt, FALSE); g_return_val_if_fail(crt->scheme == &x509_gnutls, FALSE); g_return_val_if_fail(crt->data, FALSE); crt_dat = X509_GET_GNUTLS_DATA(crt); /* Obtain the output size required */ out_size = 0; ret = gnutls_x509_crt_export(crt_dat, GNUTLS_X509_FMT_PEM, NULL, /* Provide no buffer yet */ &out_size /* Put size here */ ); g_return_val_if_fail(ret == GNUTLS_E_SHORT_MEMORY_BUFFER, FALSE); /* Now allocate a buffer and *really* export it */ out_buf = g_new0(gchar, out_size); ret = gnutls_x509_crt_export(crt_dat, GNUTLS_X509_FMT_PEM, out_buf, /* Export to our new buffer */ &out_size /* Put size here */ ); if (ret != 0) { purple_debug_error("gnutls/x509", "Failed to export cert to buffer with code %d\n", ret); g_free(out_buf); return FALSE; } /* Write it out to an actual file */ success = purple_util_write_data_to_file_absolute(filename, out_buf, out_size); g_free(out_buf); g_return_val_if_fail(success, FALSE); return success; }
static void debug_msg_to_file(MsnMessage *msg, gboolean send) { char *tmp; char *dir; char *pload; int c; gsize pload_size; dir = send ? "send" : "recv"; c = send ? m_sc++ : m_rc++; tmp = g_strdup_printf("%s/msntest/%s/%03d", g_get_home_dir(), dir, c); pload = msn_message_gen_payload(msg, &pload_size); if (!purple_util_write_data_to_file_absolute(tmp, pload, pload_size)) { purple_debug_error("msn", "could not save debug file\n"); } g_free(tmp); }
static void debug_part_to_file(MsnSlpMessage *msg, gboolean send) { char *tmp; char *dir; char *data; int c; gsize data_size; 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)) { purple_debug_error("msn", "could not save debug file\n"); } g_free(tmp); }
/*------------------------------------------------------------------------ * Save a new splash-screen for later display. * * @param session The MXit session object * @param splashID The ID of the splash-screen * @param data Splash-screen image data (PNG format) * @param datalen Splash-screen image data size */ void splash_update(struct MXitSession* session, const char* splashId, const char* data, unsigned int datalen, gboolean clickable) { char* dir; char* filename; /* Remove the current splash-screen */ splash_remove(session); /* Save the new splash image */ dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "mxit", purple_user_dir()); 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)) { /* 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_free(dir); g_free(filename); }
static void install_selected_file_cb(gpointer handle, const char *filename) { /* Try to init the selected file. * If it succeeds, try to make a copy of the file in $USERDIR/plugins/. * If the copy succeeds, unload and destroy the plugin in the original * location and init+load the new one. * Select the plugin in the plugin list. */ char *path; PurplePlugin *plugin; g_return_if_fail(plugins.window); plugin = purple_plugin_probe(filename); if (!plugin) { purple_notify_error(handle, _("Error loading plugin"), _("The selected file is not a valid plugin."), _("Please open the debug window and try again to see the exact error message."), NULL); return; } if (g_list_find(gnt_tree_get_rows(GNT_TREE(plugins.tree)), plugin)) { purple_plugin_load(plugin); gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin)); gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin); return; } path = g_build_filename(purple_user_dir(), "plugins", NULL); if (purple_build_dir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0) { char *content = NULL; gsize length = 0; if (g_file_get_contents(filename, &content, &length, NULL)) { 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)) { purple_plugin_destroy(plugin); plugin = purple_plugin_probe(path); if (!plugin) { purple_debug_warning("gntplugin", "This is really strange. %s can be loaded, but %s can't!\n", filename, path); g_unlink(path); plugin = purple_plugin_probe(filename); } } else { } } g_free(content); } g_free(path); purple_plugin_load(plugin); if (plugin->info->type == PURPLE_PLUGIN_LOADER) { GList *cur; for (cur = PURPLE_PLUGIN_LOADER_INFO(plugin)->exts; cur != NULL; cur = cur->next) purple_plugins_probe(cur->data); return; } if (plugin->info->type != PURPLE_PLUGIN_STANDARD || (plugin->info->flags & PURPLE_PLUGIN_FLAG_INVISIBLE) || plugin->error) return; gnt_tree_add_choice(GNT_TREE(plugins.tree), plugin, gnt_tree_create_row(GNT_TREE(plugins.tree), plugin->info->name), NULL, NULL); gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin)); gnt_tree_set_row_flags(GNT_TREE(plugins.tree), plugin, GNT_TEXT_FLAG_BOLD); gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin); }
PurpleXmlNode * purple_xmlnode_from_file(const char *dir,const char *filename, const char *description, const char *process) { gchar *filename_full; GError *error = NULL; gchar *contents = NULL; gsize length; PurpleXmlNode *node = NULL; g_return_val_if_fail(dir != NULL, NULL); purple_debug_misc(process, "Reading file %s from directory %s\n", filename, dir); filename_full = g_build_filename(dir, filename, NULL); if (!g_file_test(filename_full, G_FILE_TEST_EXISTS)) { purple_debug_info(process, "File %s does not exist (this is not " "necessarily an error)\n", filename_full); g_free(filename_full); return NULL; } if (!g_file_get_contents(filename_full, &contents, &length, &error)) { purple_debug_error(process, "Error reading file %s: %s\n", filename_full, error->message); g_error_free(error); } if ((contents != NULL) && (length > 0)) { node = purple_xmlnode_from_str(contents, length); /* If we were unable to parse the file then save its contents to a backup file */ if (node == NULL) { gchar *filename_temp, *filename_temp_full; filename_temp = g_strdup_printf("%s~", filename); filename_temp_full = g_build_filename(dir, filename_temp, NULL); purple_debug_error("util", "Error parsing file %s. Renaming old " "file to %s\n", filename_full, filename_temp); purple_util_write_data_to_file_absolute(filename_temp_full, contents, length); g_free(filename_temp_full); g_free(filename_temp); } g_free(contents); } /* If we could not parse the file then show the user an error message */ if (node == NULL) { gchar *title, *msg; title = g_strdup_printf(_("Error Reading %s"), filename); msg = g_strdup_printf(_("An error was encountered reading your " "%s. The file has not been loaded, and the old file " "has been renamed to %s~."), description, filename_full); purple_notify_error(NULL, NULL, title, msg, NULL); g_free(title); g_free(msg); } g_free(filename_full); return node; }