libpurple/purplepath.c

Thu, 07 Aug 2025 21:32:18 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 07 Aug 2025 21:32:18 -0500
changeset 43300
0604c6839974
parent 42767
8cf1d11b59c1
permissions
-rw-r--r--

Clean up and modernize PurpleImage

Testing Done:
Ran the tests under valgrind and called in the turtles.

Reviewed at https://reviews.imfreedom.org/r/4074/

41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Purple - Internet Messaging Library
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
7 * source distribution.
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
9 * This library is free software; you can redistribute it and/or modify it
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
10 * under the terms of the GNU General Public License as published by the Free
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
11 * Software Foundation; either version 2 of the License, or (at your option)
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
12 * any later version.
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
14 * This library is distributed in the hope that it will be useful, but WITHOUT
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
17 * more details.
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
18 *
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
19 * You should have received a copy of the GNU General Public License along with
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42497
diff changeset
20 * this library; if not, see <https://www.gnu.org/licenses/>.
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
42338
2548eb61acc9 Make sure all internal includes use double quotes
Gary Kramlich <grim@reaperworld.com>
parents: 41867
diff changeset
23 #include "purplepath.h"
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
42338
2548eb61acc9 Make sure all internal includes use double quotes
Gary Kramlich <grim@reaperworld.com>
parents: 41867
diff changeset
25 #include "core.h"
2548eb61acc9 Make sure all internal includes use double quotes
Gary Kramlich <grim@reaperworld.com>
parents: 41867
diff changeset
26 #include "purpleui.h"
41730
f76b8bc39892 Use the id property of PurpleUiInfo as the directory name to use with XDG_CONFIG_HOME
Gary Kramlich <grim@reaperworld.com>
parents: 41680
diff changeset
27
41264
46a289816176 We need to include our win32dep.h file for the path api
Gary Kramlich <grim@reaperworld.com>
parents: 41237
diff changeset
28 #ifdef _WIN32
46a289816176 We need to include our win32dep.h file for the path api
Gary Kramlich <grim@reaperworld.com>
parents: 41237
diff changeset
29 # include "win32/win32dep.h"
46a289816176 We need to include our win32dep.h file for the path api
Gary Kramlich <grim@reaperworld.com>
parents: 41237
diff changeset
30 #endif
46a289816176 We need to include our win32dep.h file for the path api
Gary Kramlich <grim@reaperworld.com>
parents: 41237
diff changeset
31
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 /******************************************************************************
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 * Globals
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 *****************************************************************************/
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 static gchar *custom_user_dir = NULL;
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 static gchar *user_dir = NULL;
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 static gchar *cache_dir = NULL;
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 static gchar *config_dir = NULL;
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 static gchar *data_dir = NULL;
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 /******************************************************************************
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 * Helpers
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 *****************************************************************************/
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 static const gchar *
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 purple_xdg_dir(gchar **xdg_dir, const gchar *xdg_base_dir,
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 const gchar *xdg_type)
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 {
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 if (!*xdg_dir) {
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 if (!custom_user_dir) {
41867
5375c1d58c50 Create PurpleUi that merges PurpleCoreUiOps and PurpleUiInfo
Gary Kramlich <grim@reaperworld.com>
parents: 41730
diff changeset
50 PurpleUi *ui = purple_core_get_ui();
41730
f76b8bc39892 Use the id property of PurpleUiInfo as the directory name to use with XDG_CONFIG_HOME
Gary Kramlich <grim@reaperworld.com>
parents: 41680
diff changeset
51 const gchar *id = NULL;
f76b8bc39892 Use the id property of PurpleUiInfo as the directory name to use with XDG_CONFIG_HOME
Gary Kramlich <grim@reaperworld.com>
parents: 41680
diff changeset
52
41867
5375c1d58c50 Create PurpleUi that merges PurpleCoreUiOps and PurpleUiInfo
Gary Kramlich <grim@reaperworld.com>
parents: 41730
diff changeset
53 id = purple_ui_get_id(ui);
41730
f76b8bc39892 Use the id property of PurpleUiInfo as the directory name to use with XDG_CONFIG_HOME
Gary Kramlich <grim@reaperworld.com>
parents: 41680
diff changeset
54 if(id == NULL) {
f76b8bc39892 Use the id property of PurpleUiInfo as the directory name to use with XDG_CONFIG_HOME
Gary Kramlich <grim@reaperworld.com>
parents: 41680
diff changeset
55 id = "purple";
f76b8bc39892 Use the id property of PurpleUiInfo as the directory name to use with XDG_CONFIG_HOME
Gary Kramlich <grim@reaperworld.com>
parents: 41680
diff changeset
56 }
f76b8bc39892 Use the id property of PurpleUiInfo as the directory name to use with XDG_CONFIG_HOME
Gary Kramlich <grim@reaperworld.com>
parents: 41680
diff changeset
57
f76b8bc39892 Use the id property of PurpleUiInfo as the directory name to use with XDG_CONFIG_HOME
Gary Kramlich <grim@reaperworld.com>
parents: 41680
diff changeset
58 *xdg_dir = g_build_filename(xdg_base_dir, id, NULL);
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 } else {
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 *xdg_dir = g_build_filename(custom_user_dir, xdg_type, NULL);
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 }
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 }
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 return *xdg_dir;
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 }
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 /******************************************************************************
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 * Public API
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 *****************************************************************************/
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 const gchar *
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 purple_cache_dir(void) {
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 return purple_xdg_dir(&cache_dir, g_get_user_cache_dir(), "cache");
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 }
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 const gchar *
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 purple_config_dir(void) {
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 return purple_xdg_dir(&config_dir, g_get_user_config_dir(), "config");
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 }
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 const gchar *
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 purple_data_dir(void) {
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 return purple_xdg_dir(&data_dir, g_get_user_data_dir(), "data");
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 }
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 void
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 purple_util_set_user_dir(const gchar *dir) {
42767
8cf1d11b59c1 Use g_set_str everywhere
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42594
diff changeset
87 if(g_set_str(&custom_user_dir, dir)) {
8cf1d11b59c1 Use g_set_str everywhere
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42594
diff changeset
88 g_clear_pointer(&user_dir, g_free);
8cf1d11b59c1 Use g_set_str everywhere
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42594
diff changeset
89 g_clear_pointer(&cache_dir, g_free);
8cf1d11b59c1 Use g_set_str everywhere
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42594
diff changeset
90 g_clear_pointer(&config_dir, g_free);
8cf1d11b59c1 Use g_set_str everywhere
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42594
diff changeset
91 g_clear_pointer(&data_dir, g_free);
8cf1d11b59c1 Use g_set_str everywhere
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42594
diff changeset
92 }
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 }

mercurial