summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2022-01-08 15:35:51 -0600
committerGary Kramlich <grim@reaperworld.com>2022-01-08 15:35:51 -0600
commitedea864044592babc5e2deb12fe5245bc82d502f (patch)
tree0516bf613b23b6ffa82a1557dacf5d14cd0d127d
parentcff1361cf090ce807a5e955bdf968d9862a8ea20 (diff)
downloadpidgin-edea864044592babc5e2deb12fe5245bc82d502f.tar.gz
Move the path based functions from util.c to their own file.
This is the first step in cleaning these up and using separate directories for each libpurple based client. Testing Done: Ran with no config directory and added an account. Verified that all of the config files were correctly created. Also ran the unit tests without issue. Reviewed at https://reviews.imfreedom.org/r/1192/
-rw-r--r--libpurple/buddyicon.c2
-rw-r--r--libpurple/core.c1
-rw-r--r--libpurple/media/backend-fs2.c3
-rw-r--r--libpurple/mediamanager.c1
-rw-r--r--libpurple/meson.build2
-rw-r--r--libpurple/prefs.c1
-rw-r--r--libpurple/purplepath.c101
-rw-r--r--libpurple/purplepath.h103
-rw-r--r--libpurple/util.c94
-rw-r--r--libpurple/util.h72
-rw-r--r--po/POTFILES.in1
11 files changed, 217 insertions, 164 deletions
diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
index e832ca0ede..31e4a9e737 100644
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -26,9 +26,9 @@
#include "purpleaccountmanager.h"
#include "purpleconversation.h"
#include "purpleconversationmanager.h"
+#include "purplepath.h"
#include "purpleprivate.h"
#include "purpleprotocolserver.h"
-#include "util.h"
/* NOTE: Instances of this struct are allocated without zeroing the memory, so
* NOTE: be sure to update purple_buddy_icon_new() if you add members. */
diff --git a/libpurple/core.c b/libpurple/core.c
index c682c78e8a..f2bd9d2fcf 100644
--- a/libpurple/core.c
+++ b/libpurple/core.c
@@ -39,6 +39,7 @@
#include "purplecredentialmanager.h"
#include "purplehistorymanager.h"
#include "purplemessage.h"
+#include "purplepath.h"
#include "purpleprivate.h"
#include "savedstatuses.h"
#include "signals.h"
diff --git a/libpurple/media/backend-fs2.c b/libpurple/media/backend-fs2.c
index f0e96e7a09..fb26226e64 100644
--- a/libpurple/media/backend-fs2.c
+++ b/libpurple/media/backend-fs2.c
@@ -30,7 +30,8 @@
#include "debug.h"
#include "network.h"
#include "media-gst.h"
-#include <purplekeyvaluepair.h>
+#include <libpurple/purplepath.h>
+#include <libpurple/purplekeyvaluepair.h>
/* Ignore deprecations of GParameter in FarStream's headers. */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
diff --git a/libpurple/mediamanager.c b/libpurple/mediamanager.c
index ee3a248489..f99d060a15 100644
--- a/libpurple/mediamanager.c
+++ b/libpurple/mediamanager.c
@@ -28,6 +28,7 @@
#include "glibcompat.h"
#include "media.h"
#include "mediamanager.h"
+#include "purplepath.h"
#include "media-gst.h"
#include <media/backend-fs2.h>
diff --git a/libpurple/meson.build b/libpurple/meson.build
index e912a7282a..cc6b81b3ce 100644
--- a/libpurple/meson.build
+++ b/libpurple/meson.build
@@ -61,6 +61,7 @@ purple_coresources = [
'purplemessage.c',
'purplenoopcredentialprovider.c',
'purpleoptions.c',
+ 'purplepath.c',
'purpleplugininfo.c',
'purplepresence.c',
'purpleprotocol.c',
@@ -153,6 +154,7 @@ purple_coreheaders = [
'purplemessage.h',
'purplenoopcredentialprovider.h',
'purpleoptions.h',
+ 'purplepath.h',
'purpleplugininfo.h',
'purplepresence.h',
'purpleprotocol.h',
diff --git a/libpurple/prefs.c b/libpurple/prefs.c
index 368d54ea54..f9cfaafa6d 100644
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -32,6 +32,7 @@
#include "prefs.h"
#include "debug.h"
+#include "purplepath.h"
#include "util.h"
static PurplePrefsUiOps *prefs_ui_ops = NULL;
diff --git a/libpurple/purplepath.c b/libpurple/purplepath.c
new file mode 100644
index 0000000000..9dd715b197
--- /dev/null
+++ b/libpurple/purplepath.c
@@ -0,0 +1,101 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <libpurple/purplepath.h>
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+static gchar *custom_user_dir = NULL;
+static gchar *user_dir = NULL;
+static gchar *cache_dir = NULL;
+static gchar *config_dir = NULL;
+static gchar *data_dir = NULL;
+
+/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static const gchar *
+purple_xdg_dir(gchar **xdg_dir, const gchar *xdg_base_dir,
+ const gchar *xdg_type)
+{
+ if (!*xdg_dir) {
+ if (!custom_user_dir) {
+ *xdg_dir = g_build_filename(xdg_base_dir, "purple", NULL);
+ } else {
+ *xdg_dir = g_build_filename(custom_user_dir, xdg_type, NULL);
+ }
+ }
+
+ return *xdg_dir;
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+const gchar *
+purple_home_dir(void) {
+#ifndef _WIN32
+ return g_get_home_dir();
+#else
+ return wpurple_home_dir();
+#endif
+}
+
+/* Returns the argument passed to -c IFF it was present, or ~/.purple. */
+const gchar *
+purple_user_dir(void) {
+ if(custom_user_dir != NULL) {
+ return custom_user_dir;
+ } else if(!user_dir) {
+ user_dir = g_build_filename(purple_home_dir(), ".purple", NULL);
+ }
+
+ return user_dir;
+}
+
+const gchar *
+purple_cache_dir(void) {
+ return purple_xdg_dir(&cache_dir, g_get_user_cache_dir(), "cache");
+}
+
+const gchar *
+purple_config_dir(void) {
+ return purple_xdg_dir(&config_dir, g_get_user_config_dir(), "config");
+}
+
+const gchar *
+purple_data_dir(void) {
+ return purple_xdg_dir(&data_dir, g_get_user_data_dir(), "data");
+}
+
+void
+purple_util_set_user_dir(const gchar *dir) {
+ g_free(custom_user_dir);
+
+ if(dir != NULL && *dir) {
+ custom_user_dir = g_strdup(dir);
+ } else {
+ custom_user_dir = NULL;
+ }
+
+ g_clear_pointer(&user_dir, g_free);
+ g_clear_pointer(&cache_dir, g_free);
+ g_clear_pointer(&config_dir, g_free);
+ g_clear_pointer(&data_dir, g_free);
+}
diff --git a/libpurple/purplepath.h b/libpurple/purplepath.h
new file mode 100644
index 0000000000..fab053c3cd
--- /dev/null
+++ b/libpurple/purplepath.h
@@ -0,0 +1,103 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#if !defined(PURPLE_GLOBAL_HEADER_INSIDE) && !defined(PURPLE_COMPILATION)
+# error "only <purple.h> may be included directly"
+#endif
+
+#ifndef PURPLE_PATH_H
+#define PURPLE_PATH_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+/**
+ * purple_home_dir:
+ *
+ * Returns the user's home directory.
+ *
+ * See purple_user_dir()
+ *
+ * Returns: The user's home directory.
+ */
+const gchar *purple_home_dir(void);
+
+/**
+ * purple_user_dir:
+ *
+ * Returns the purple settings directory in the user's home directory.
+ * This is usually $HOME/.purple
+ *
+ * See purple_home_dir()
+ *
+ * Returns: The purple settings directory.
+ *
+ * Deprecated: Use purple_cache_dir(), purple_config_dir() or
+ * purple_data_dir() instead.
+ */
+G_DEPRECATED_FOR(purple_cache_dir or purple_config_dir or purple_data_dir)
+const gchar *purple_user_dir(void);
+
+/**
+ * purple_cache_dir:
+ *
+ * Returns the purple cache directory according to XDG Base Directory Specification.
+ * This is usually $HOME/.cache/purple.
+ * If custom user dir was specified then this is cache
+ * sub-directory of DIR argument passed to -c option.
+ *
+ * Returns: The purple cache directory.
+ */
+const gchar *purple_cache_dir(void);
+
+/**
+ * purple_config_dir:
+ *
+ * Returns the purple configuration directory according to XDG Base Directory Specification.
+ * This is usually $HOME/.config/purple.
+ * If custom user dir was specified then this is config
+ * sub-directory of DIR argument passed to -c option.
+ *
+ * Returns: The purple configuration directory.
+ */
+const gchar *purple_config_dir(void);
+
+/**
+ * purple_data_dir:
+ *
+ * Returns the purple data directory according to XDG Base Directory Specification.
+ * This is usually $HOME/.local/share/purple.
+ * If custom user dir was specified then this is data
+ * sub-directory of DIR argument passed to -c option.
+ *
+ * Returns: The purple data directory.
+ */
+const gchar *purple_data_dir(void);
+
+/**
+ * purple_util_set_user_dir:
+ * @dir: The custom settings directory
+ *
+ * Define a custom purple settings directory, overriding the default (user's home directory/.purple)
+ */
+void purple_util_set_user_dir(const gchar *dir);
+
+G_END_DECLS
+
+#endif /* PURPLE_PATH_H */
diff --git a/libpurple/util.c b/libpurple/util.c
index 6a82f282ac..24a6e6fe26 100644
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -29,42 +29,20 @@
#include "prefs.h"
#include "purpleaccountmanager.h"
#include "purpleconversation.h"
+#include "purplepath.h"
#include "purpleprotocol.h"
#include "purpleprotocolclient.h"
#include "util.h"
#include <json-glib/json-glib.h>
-static char *custom_user_dir = NULL;
-static char *user_dir = NULL;
-static gchar *cache_dir = NULL;
-static gchar *config_dir = NULL;
-static gchar *data_dir = NULL;
-
void
-purple_util_init(void)
-{
+purple_util_init(void) {
}
void
-purple_util_uninit(void)
-{
- /* Free these so we don't have leaks at shutdown. */
-
- g_free(custom_user_dir);
- custom_user_dir = NULL;
-
- g_free(user_dir);
- user_dir = NULL;
-
- g_free(cache_dir);
- cache_dir = NULL;
-
- g_free(config_dir);
- config_dir = NULL;
-
- g_free(data_dir);
- data_dir = NULL;
+purple_util_uninit(void) {
+ purple_util_set_user_dir(NULL);
}
/**************************************************************************
@@ -460,70 +438,6 @@ gint purple_time_parse_month(const char *month_abbr)
/**************************************************************************
* Path/Filename Functions
**************************************************************************/
-const char *
-purple_home_dir(void)
-{
-#ifndef _WIN32
- return g_get_home_dir();
-#else
- return wpurple_home_dir();
-#endif
-}
-
-/* Returns the argument passed to -c IFF it was present, or ~/.purple. */
-const char *
-purple_user_dir(void)
-{
- if (custom_user_dir != NULL)
- return custom_user_dir;
- else if (!user_dir)
- user_dir = g_build_filename(purple_home_dir(), ".purple", NULL);
-
- return user_dir;
-}
-
-static const gchar *
-purple_xdg_dir(gchar **xdg_dir, const gchar *xdg_base_dir, const gchar *xdg_type)
-{
- if (!*xdg_dir) {
- if (!custom_user_dir) {
- *xdg_dir = g_build_filename(xdg_base_dir, "purple", NULL);
- } else {
- *xdg_dir = g_build_filename(custom_user_dir, xdg_type, NULL);
- }
- }
-
- return *xdg_dir;
-}
-
-const gchar *
-purple_cache_dir(void)
-{
- return purple_xdg_dir(&cache_dir, g_get_user_cache_dir(), "cache");
-}
-
-const gchar *
-purple_config_dir(void)
-{
- return purple_xdg_dir(&config_dir, g_get_user_config_dir(), "config");
-}
-
-const gchar *
-purple_data_dir(void)
-{
- return purple_xdg_dir(&data_dir, g_get_user_data_dir(), "data");
-}
-
-void purple_util_set_user_dir(const char *dir)
-{
- g_free(custom_user_dir);
-
- if (dir != NULL && *dir)
- custom_user_dir = g_strdup(dir);
- else
- custom_user_dir = NULL;
-}
-
static gboolean
purple_util_write_data_to_file_common(const char *dir, const char *filename, const char *data, gssize size)
{
diff --git a/libpurple/util.h b/libpurple/util.h
index c0efdcac4c..7e1ac92364 100644
--- a/libpurple/util.h
+++ b/libpurple/util.h
@@ -191,78 +191,6 @@ gint purple_time_parse_month(const char *month_abbr);
/**************************************************************************/
/* Path/Filename Functions */
/**************************************************************************/
-
-/**
- * purple_home_dir:
- *
- * Returns the user's home directory.
- *
- * See purple_user_dir()
- *
- * Returns: The user's home directory.
- */
-const gchar *purple_home_dir(void);
-
-/**
- * purple_user_dir:
- *
- * Returns the purple settings directory in the user's home directory.
- * This is usually $HOME/.purple
- *
- * See purple_home_dir()
- *
- * Returns: The purple settings directory.
- *
- * Deprecated: Use purple_cache_dir(), purple_config_dir() or
- * purple_data_dir() instead.
- */
-G_DEPRECATED_FOR(purple_cache_dir or purple_config_dir or purple_data_dir)
-const char *purple_user_dir(void);
-
-/**
- * purple_cache_dir:
- *
- * Returns the purple cache directory according to XDG Base Directory Specification.
- * This is usually $HOME/.cache/purple.
- * If custom user dir was specified then this is cache
- * sub-directory of DIR argument passed to -c option.
- *
- * Returns: The purple cache directory.
- */
-const gchar *purple_cache_dir(void);
-
-/**
- * purple_config_dir:
- *
- * Returns the purple configuration directory according to XDG Base Directory Specification.
- * This is usually $HOME/.config/purple.
- * If custom user dir was specified then this is config
- * sub-directory of DIR argument passed to -c option.
- *
- * Returns: The purple configuration directory.
- */
-const gchar *purple_config_dir(void);
-
-/**
- * purple_data_dir:
- *
- * Returns the purple data directory according to XDG Base Directory Specification.
- * This is usually $HOME/.local/share/purple.
- * If custom user dir was specified then this is data
- * sub-directory of DIR argument passed to -c option.
- *
- * Returns: The purple data directory.
- */
-const gchar *purple_data_dir(void);
-
-/**
- * purple_util_set_user_dir:
- * @dir: The custom settings directory
- *
- * Define a custom purple settings directory, overriding the default (user's home directory/.purple)
- */
-void purple_util_set_user_dir(const char *dir);
-
/**
* purple_util_write_data_to_file:
* @filename: The basename of the file to write in the purple_user_dir.
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5c19a90749..e396f87bac 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -255,6 +255,7 @@ libpurple/purplemarkup.c
libpurple/purplemessage.c
libpurple/purplenoopcredentialprovider.c
libpurple/purpleoptions.c
+libpurple/purplepath.c
libpurple/purplepresence.c
libpurple/purpleplugininfo.c
libpurple/purpleprotocol.c