libpurple/util.c

Mon, 12 Aug 2024 00:57:02 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 12 Aug 2024 00:57:02 -0500
changeset 42855
87999e4cdb55
parent 42849
6a6794c918a4
child 42874
c53e5e1ff6b1
permissions
-rw-r--r--

Remove PurpleProtocolClient

Nothing is using this anymore so we can get rid of it.

Testing Done:
Called in the turtles.

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

42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42473
diff changeset
1 /*
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42473
diff changeset
2 * Purple - Internet Messaging Library
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42473
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42473
diff changeset
4 *
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42473
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: 42473
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
8046
c581b20a47d6 [gaim-migrate @ 8730]
Sean Egan <seanegan@pidgin.im>
parents: 8026
diff changeset
7 * source distribution.
1
efe077a7e70d [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.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: 42473
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: 42473
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: 42473
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: 42473
diff changeset
12 * any later version.
1
efe077a7e70d [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.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: 42473
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: 42473
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: 42473
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: 42473
diff changeset
17 * more details.
1
efe077a7e70d [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42473
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: 42473
diff changeset
20 * this library; if not, see <https://www.gnu.org/licenses/>.
1
efe077a7e70d [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 */
40441
f23c7e772667 Make sure we're not including the gettext macros in header files and deal with the repercussions of that.
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
22
42410
563e7a17c220 Fix possible clash of config headers
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42307
diff changeset
23 #include <purpleconfig.h>
41039
f108e108784e Revert RR 903
Gary Kramlich <grim@reaperworld.com>
parents: 41033
diff changeset
24
40441
f23c7e772667 Make sure we're not including the gettext macros in header files and deal with the repercussions of that.
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
25 #include <glib/gi18n-lib.h>
f23c7e772667 Make sure we're not including the gettext macros in header files and deal with the repercussions of that.
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
26
41682
289867067994 Clean up a bunch of stuff in internal.h
Gary Kramlich <grim@reaperworld.com>
parents: 41673
diff changeset
27 #include <ctype.h>
289867067994 Clean up a bunch of stuff in internal.h
Gary Kramlich <grim@reaperworld.com>
parents: 41673
diff changeset
28
40439
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 40350
diff changeset
29 #include "purpleprivate.h"
3630
caa952062dc2 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
30
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
31 #include "core.h"
5872
754c63f29b77 [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5826
diff changeset
32 #include "debug.h"
5545
a8b1a1262402 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5532
diff changeset
33 #include "prefs.h"
41181
e859c41d8996 Create the PurpleAccountManager API
Gary Kramlich <grim@reaperworld.com>
parents: 41155
diff changeset
34 #include "purpleaccountmanager.h"
40853
d3518ff99fa7 rename conversation.[ch] to purpleconversation.[ch] and split PurpleConversationUiOps out to its own file to avoid circular include issues.
Gary Kramlich <grim@reaperworld.com>
parents: 40804
diff changeset
35 #include "purpleconversation.h"
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents: 41236
diff changeset
36 #include "purplepath.h"
41155
922c9e70900c Rename protocol.[ch] to purpleprotocol.[ch]
Gary Kramlich <grim@reaperworld.com>
parents: 41039
diff changeset
37 #include "purpleprotocol.h"
42725
ceb13f1de2d2 Remove PurpleBuddy
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
38 #include "signals.h"
7094
8f9588491993 [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
39 #include "util.h"
8f9588491993 [gaim-migrate @ 7659]
Christian Hammond <chipx86@chipx86.com>
parents: 7078
diff changeset
40
42434
622b4989d073 Fix some Windows build header issues
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42410
diff changeset
41 #ifdef _WIN32
622b4989d073 Fix some Windows build header issues
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42410
diff changeset
42 # include "win32/libc_interface.h"
622b4989d073 Fix some Windows build header issues
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42410
diff changeset
43 #endif
622b4989d073 Fix some Windows build header issues
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42410
diff changeset
44
33538
cbeb76707f12 Better implementation of purple_escape_js
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33537
diff changeset
45 #include <json-glib/json-glib.h>
cbeb76707f12 Better implementation of purple_escape_js
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33537
diff changeset
46
42280
e29c71fb13e9 Remove internal.h
Gary Kramlich <grim@reaperworld.com>
parents: 42260
diff changeset
47 #define BUF_LEN 2048
e29c71fb13e9 Remove internal.h
Gary Kramlich <grim@reaperworld.com>
parents: 42260
diff changeset
48
21238
cd326828c870 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@pidgin.im>
parents: 20992
diff changeset
49 void
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents: 41236
diff changeset
50 purple_util_init(void) {
21238
cd326828c870 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@pidgin.im>
parents: 20992
diff changeset
51 }
cd326828c870 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@pidgin.im>
parents: 20992
diff changeset
52
cd326828c870 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@pidgin.im>
parents: 20992
diff changeset
53 void
41237
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents: 41236
diff changeset
54 purple_util_uninit(void) {
5098e0dd3a09 Move the path based functions from util.c to their own file.
Gary Kramlich <grim@reaperworld.com>
parents: 41236
diff changeset
55 purple_util_set_user_dir(NULL);
21238
cd326828c870 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@pidgin.im>
parents: 20992
diff changeset
56 }
cd326828c870 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@pidgin.im>
parents: 20992
diff changeset
57
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
58 /**************************************************************************
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
59 * Path/Filename Functions
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
60 **************************************************************************/
38870
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
61 static gboolean
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
62 purple_util_write_data_to_file_common(const char *dir, const char *filename, const char *data, gssize size)
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
63 {
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
64 gchar *filename_full;
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
65 gboolean ret = FALSE;
38872
af422a3fb924 Add purple_util_write_data_to_*_file declarations
qarkai <qarkai@gmail.com>
parents: 38871
diff changeset
66
38870
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
67 g_return_val_if_fail(dir != NULL, FALSE);
38872
af422a3fb924 Add purple_util_write_data_to_*_file declarations
qarkai <qarkai@gmail.com>
parents: 38871
diff changeset
68
38870
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
69 purple_debug_misc("util", "Writing file %s to directory %s",
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
70 filename, dir);
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
71
38874
0fc4ba7fa2be Make XDG dir structure inside custom user dir
qarkai <qarkai@gmail.com>
parents: 38872
diff changeset
72 /* Ensure the directory exists */
38870
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
73 if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
74 {
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
75 if (g_mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
76 {
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
77 purple_debug_error("util", "Error creating directory %s: %s\n",
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
78 dir, g_strerror(errno));
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
79 return FALSE;
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
80 }
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
81 }
38872
af422a3fb924 Add purple_util_write_data_to_*_file declarations
qarkai <qarkai@gmail.com>
parents: 38871
diff changeset
82
38899
73b49f76016a Some fixes
qarkai <qarkai@gmail.com>
parents: 38893
diff changeset
83 filename_full = g_build_filename(dir, filename, NULL);
40656
0d388fcfd3bf Remove one more purple_util_write_data_to_file_absolute.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40637
diff changeset
84 ret = g_file_set_contents(filename_full, data, size, NULL);
0d388fcfd3bf Remove one more purple_util_write_data_to_file_absolute.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40637
diff changeset
85 g_free(filename_full);
38872
af422a3fb924 Add purple_util_write_data_to_*_file declarations
qarkai <qarkai@gmail.com>
parents: 38871
diff changeset
86
38870
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
87 return ret;
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
88 }
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
89
10414
6b10b76933e1 [gaim-migrate @ 11664]
Mark Doliner <markdoliner@pidgin.im>
parents: 10372
diff changeset
90 gboolean
38870
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
91 purple_util_write_data_to_config_file(const char *filename, const char *data, gssize size)
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
92 {
38881
25cb836b9cec Use proper directories for writing data.
Arkadiy Illarionov <qarkai@gmail.com>
parents: 38874
diff changeset
93 const char *config_dir = purple_config_dir();
38870
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
94 gboolean ret = purple_util_write_data_to_file_common(config_dir, filename, data, size);
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
95
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
96 return ret;
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
97 }
575e41bfc15e Migrate certificates, icons, logs to XDG dirs
qarkai <qarkai@gmail.com>
parents: 38051
diff changeset
98
38877
4e9c691a1d2d Add functions for reading XML files from XDG dirs
qarkai <qarkai@gmail.com>
parents: 38876
diff changeset
99 PurpleXmlNode *
4e9c691a1d2d Add functions for reading XML files from XDG dirs
qarkai <qarkai@gmail.com>
parents: 38876
diff changeset
100 purple_util_read_xml_from_config_file(const char *filename, const char *description)
4e9c691a1d2d Add functions for reading XML files from XDG dirs
qarkai <qarkai@gmail.com>
parents: 38876
diff changeset
101 {
4e9c691a1d2d Add functions for reading XML files from XDG dirs
qarkai <qarkai@gmail.com>
parents: 38876
diff changeset
102 return purple_xmlnode_from_file(purple_config_dir(), filename, description, "util");
4e9c691a1d2d Add functions for reading XML files from XDG dirs
qarkai <qarkai@gmail.com>
parents: 38876
diff changeset
103 }
4e9c691a1d2d Add functions for reading XML files from XDG dirs
qarkai <qarkai@gmail.com>
parents: 38876
diff changeset
104
11878
4c2661df91bb [gaim-migrate @ 14169]
Sean Egan <seanegan@pidgin.im>
parents: 11780
diff changeset
105 gboolean
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
106 purple_running_gnome(void)
11878
4c2661df91bb [gaim-migrate @ 14169]
Sean Egan <seanegan@pidgin.im>
parents: 11780
diff changeset
107 {
13616
7cf0f845d2d6 [gaim-migrate @ 16001]
Daniel Atallah <datallah@pidgin.im>
parents: 13614
diff changeset
108 #ifndef _WIN32
38043
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
109 gchar *tmp = g_find_program_in_path("gvfs-open");
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
110
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
111 if (tmp == NULL) {
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
112 tmp = g_find_program_in_path("gnome-open");
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
113
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
114 if (tmp == NULL) {
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
115 return FALSE;
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
116 }
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
117 }
3549ff786eab util: Fix purple_running_gnome() to check for gvfs-open too
Mike Ruprecht <cmaiku@gmail.com>
parents: 37160
diff changeset
118
12483
38fc67810cdb [gaim-migrate @ 14795]
Richard Laager <rlaager@pidgin.im>
parents: 12110
diff changeset
119 g_free(tmp);
38fc67810cdb [gaim-migrate @ 14795]
Richard Laager <rlaager@pidgin.im>
parents: 12110
diff changeset
120
21665
a1a724a89a03 Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21468
diff changeset
121 tmp = (gchar *)g_getenv("GNOME_DESKTOP_SESSION_ID");
a1a724a89a03 Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21468
diff changeset
122
a1a724a89a03 Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21468
diff changeset
123 return ((tmp != NULL) && (*tmp != '\0'));
13616
7cf0f845d2d6 [gaim-migrate @ 16001]
Daniel Atallah <datallah@pidgin.im>
parents: 13614
diff changeset
124 #else
7cf0f845d2d6 [gaim-migrate @ 16001]
Daniel Atallah <datallah@pidgin.im>
parents: 13614
diff changeset
125 return FALSE;
7cf0f845d2d6 [gaim-migrate @ 16001]
Daniel Atallah <datallah@pidgin.im>
parents: 13614
diff changeset
126 #endif
12483
38fc67810cdb [gaim-migrate @ 14795]
Richard Laager <rlaager@pidgin.im>
parents: 12110
diff changeset
127 }
38fc67810cdb [gaim-migrate @ 14795]
Richard Laager <rlaager@pidgin.im>
parents: 12110
diff changeset
128
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
129 /**************************************************************************
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
130 * String Functions
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
131 **************************************************************************/
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
132 void
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
133 purple_str_strip_char(char *text, char thechar)
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
134 {
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
135 int i, j;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
136
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
137 g_return_if_fail(text != NULL);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
138
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
139 for (i = 0, j = 0; text[i]; i++)
11920
be80617ec59b [gaim-migrate @ 14211]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 11878
diff changeset
140 if (text[i] != thechar)
11142
3ed4fc774b87 [gaim-migrate @ 13206]
Mark Doliner <markdoliner@pidgin.im>
parents: 11137
diff changeset
141 text[j++] = text[i];
3ed4fc774b87 [gaim-migrate @ 13206]
Mark Doliner <markdoliner@pidgin.im>
parents: 11137
diff changeset
142
30702
8a1938367841 These are dead increments.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30515
diff changeset
143 text[j] = '\0';
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
144 }
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
145
8341
dc43b1acfc1a [gaim-migrate @ 9065]
Mark Doliner <markdoliner@pidgin.im>
parents: 8163
diff changeset
146 gchar *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
147 purple_strreplace(const char *string, const char *delimiter,
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
148 const char *replacement)
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
149 {
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
150 gchar **split;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
151 gchar *ret;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
152
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
153 g_return_val_if_fail(string != NULL, NULL);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
154 g_return_val_if_fail(delimiter != NULL, NULL);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
155 g_return_val_if_fail(replacement != NULL, NULL);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
156
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
157 split = g_strsplit(string, delimiter, 0);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
158 ret = g_strjoinv(replacement, split);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
159 g_strfreev(split);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
160
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
161 return ret;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
162 }
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
163
34145
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
164 void
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
165 purple_str_wipe(gchar *str)
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
166 {
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
167 if (str == NULL)
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
168 return;
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
169 memset(str, 0, strlen(str));
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
170 g_free(str);
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
171 }
fa72f1e5cd77 Some polishing on files modified on this branch (mostly formatting)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33824
diff changeset
172
42060
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
173 gboolean
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
174 purple_strmatches(const char *pattern, const char *str) {
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
175 char *normal_pattern = NULL;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
176 char *normal_str = NULL;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
177 char *cmp_pattern = NULL;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
178 char *cmp_str = NULL;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
179 char *idx_pattern = NULL;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
180 char *idx_str = NULL;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
181
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
182 g_return_val_if_fail(pattern != NULL, FALSE);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
183
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
184 /* Short circuit on NULL and empty string. */
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
185 if(purple_strempty(str)) {
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
186 return FALSE;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
187 }
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
188
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
189 normal_pattern = g_utf8_normalize(pattern, -1, G_NORMALIZE_ALL);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
190 cmp_pattern = g_utf8_casefold(normal_pattern, -1);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
191 g_free(normal_pattern);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
192
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
193 normal_str = g_utf8_normalize(str, -1, G_NORMALIZE_ALL);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
194 cmp_str = g_utf8_casefold(normal_str, -1);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
195 g_free(normal_str);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
196
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
197 idx_pattern = cmp_pattern;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
198 idx_str = cmp_str;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
199
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
200 /* I know while(TRUE)'s suck, but the alternative would be a multi-line for
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
201 * loop that wouldn't have the additional comments, which is much better
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
202 * IMHO. -- GK 2023-01-24.
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
203 */
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
204 while(TRUE) {
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
205 gunichar character = g_utf8_get_char(idx_pattern);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
206
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
207 /* If we've reached the end of the pattern, we're done. */
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
208 if(character == 0) {
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
209 break;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
210 }
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
211
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
212 idx_str = g_utf8_strchr(idx_str, -1, character);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
213 if(idx_str == NULL) {
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
214 g_free(cmp_pattern);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
215 g_free(cmp_str);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
216
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
217 return FALSE;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
218 }
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
219
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
220 /* We found the current character in pattern, so move to the next. */
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
221 idx_pattern = g_utf8_next_char(idx_pattern);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
222
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
223 /* move idx_str to the next character as well, because the current
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
224 * character has already been matched.
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
225 */
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
226 idx_str = g_utf8_next_char(idx_str);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
227 };
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
228
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
229 g_free(cmp_pattern);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
230 g_free(cmp_str);
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
231
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
232 return TRUE;
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
233 }
d55b605fdafb Add purple_strmatches and move purple_person_matches and purple_contact_info_matches to it
Gary Kramlich <grim@reaperworld.com>
parents: 41882
diff changeset
234
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
235 /**************************************************************************
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
236 * URI/URL Functions
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
237 **************************************************************************/
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
238
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
239 void purple_got_protocol_handler_uri(const char *uri)
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
240 {
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
241 char proto[11];
28136
a3b6446eb2c4 Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <darkrain42@pidgin.im>
parents: 27902
diff changeset
242 char delimiter;
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
243 const char *tmp, *param_string;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
244 char *cmd;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
245 GHashTable *params = NULL;
34304
faf0414a8b51 Fix most of libpurple warnings about -Wsign-compare
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34297
diff changeset
246 gsize len;
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
247 if (!(tmp = strchr(uri, ':')) || tmp == uri) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
248 purple_debug_error("util", "Malformed protocol handler message - missing protocol.\n");
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
249 return;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
250 }
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
251
36256
a437550a9308 Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36037
diff changeset
252 len = MIN(sizeof(proto) - 1, (gsize)(tmp - uri));
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
253
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
254 strncpy(proto, uri, len);
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
255 proto[len] = '\0';
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
256
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
257 tmp++;
28136
a3b6446eb2c4 Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <darkrain42@pidgin.im>
parents: 27902
diff changeset
258
38256
035f00c4fd87 Replace misused g_str_equal() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 38229
diff changeset
259 if (purple_strequal(proto, "xmpp"))
28136
a3b6446eb2c4 Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <darkrain42@pidgin.im>
parents: 27902
diff changeset
260 delimiter = ';';
a3b6446eb2c4 Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <darkrain42@pidgin.im>
parents: 27902
diff changeset
261 else
a3b6446eb2c4 Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <darkrain42@pidgin.im>
parents: 27902
diff changeset
262 delimiter = '&';
a3b6446eb2c4 Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <darkrain42@pidgin.im>
parents: 27902
diff changeset
263
a3b6446eb2c4 Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <darkrain42@pidgin.im>
parents: 27902
diff changeset
264 purple_debug_info("util", "Processing message '%s' for protocol '%s' using delimiter '%c'.\n", tmp, proto, delimiter);
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
265
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
266 if ((param_string = strchr(tmp, '?'))) {
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
267 const char *keyend = NULL, *pairstart;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
268 char *key, *value = NULL;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
269
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
270 cmd = g_strndup(tmp, (param_string - tmp));
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
271 param_string++;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
272
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
273 params = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
274 pairstart = tmp = param_string;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
275
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
276 while (*tmp || *pairstart) {
28136
a3b6446eb2c4 Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <darkrain42@pidgin.im>
parents: 27902
diff changeset
277 if (*tmp == delimiter || !(*tmp)) {
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
278 /* If there is no explicit value */
35382
1b75f8a4129c Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35298
diff changeset
279 if (keyend == NULL) {
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
280 keyend = tmp;
35382
1b75f8a4129c Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35298
diff changeset
281 }
1b75f8a4129c Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35298
diff changeset
282 /* without these brackets, clang won't
1b75f8a4129c Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35298
diff changeset
283 * recognize tmp as a non-NULL
1b75f8a4129c Fix some clang static analysis warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35298
diff changeset
284 */
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
285
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
286 if (keyend && keyend != pairstart) {
17145
463085404f54 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@pidgin.im>
parents: 17143
diff changeset
287 char *p;
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
288 key = g_strndup(pairstart, (keyend - pairstart));
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
289 /* If there is an explicit value */
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
290 if (keyend != tmp && keyend != (tmp - 1))
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
291 value = g_strndup(keyend + 1, (tmp - keyend - 1));
17145
463085404f54 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@pidgin.im>
parents: 17143
diff changeset
292 for (p = key; *p; ++p)
463085404f54 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@pidgin.im>
parents: 17143
diff changeset
293 *p = g_ascii_tolower(*p);
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
294 g_hash_table_insert(params, key, value);
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
295 }
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
296 keyend = value = NULL;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
297 pairstart = (*tmp) ? tmp + 1 : tmp;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
298 } else if (*tmp == '=')
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
299 keyend = tmp;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
300
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
301 if (*tmp)
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
302 tmp++;
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
303 }
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
304 } else
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
305 cmd = g_strdup(tmp);
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
306
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
307 purple_signal_emit_return_1(purple_get_core(), "uri-handler", proto, cmd, params);
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
308
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
309 g_free(cmd);
42172
7c2d151b410d Use g_clear_* helpers where useful
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42164
diff changeset
310 g_clear_pointer(&params, g_hash_table_destroy);
15678
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
311 }
7434ef155a3a Core support for external protocol URIs. The actual handling of the URIs will be in the prpls and other plugins. This commit only includes the win32 method of actually passing in a URI - the dbus implementation still needs to be written.
Daniel Atallah <datallah@pidgin.im>
parents: 15482
diff changeset
312
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
313 /* Originally lifted from
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
314 * http://www.oreillynet.com/pub/a/network/excerpt/spcookbook_chap03/index3.html
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
315 * ... and slightly modified to be a bit more rfc822 compliant
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
316 * ... and modified a bit more to make domain checking rfc1035 compliant
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
317 * with the exception permitted in rfc1101 for domains to start with digit
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
318 * but not completely checking to avoid conflicts with IP addresses
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
319 */
9045
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
320 gboolean
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
321 purple_email_is_valid(const char *address)
9045
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
322 {
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
323 const char *c, *domain;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
324 static char *rfc822_specials = "()<>@,;:\\\"[]";
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
325
24645
da3a357c07c1 Fix CID #385
Richard Laager <rlaager@pidgin.im>
parents: 24644
diff changeset
326 g_return_val_if_fail(address != NULL, FALSE);
da3a357c07c1 Fix CID #385
Richard Laager <rlaager@pidgin.im>
parents: 24644
diff changeset
327
30444
d871c3fd6637 Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 30437
diff changeset
328 if (*address == '.') return FALSE;
d871c3fd6637 Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 30437
diff changeset
329
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
330 /* first we validate the name portion (name@domain) (rfc822)*/
9045
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
331 for (c = address; *c; c++) {
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
332 if (*c == '\"' && (c == address || *(c - 1) == '.' || *(c - 1) == '\"')) {
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
333 while (*++c) {
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
334 if (*c == '\\') {
38922
9f05d7f41a53 purple_email_is_valid: fix out of bounds read
dx <dx@dxzone.com.ar>
parents: 38737
diff changeset
335 if (*c++ && *c < 127 && *c > 0 && *c != '\n' && *c != '\r') continue;
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
336 else return FALSE;
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
337 }
9045
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
338 if (*c == '\"') break;
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
339 if (*c < ' ' || *c >= 127) return FALSE;
9045
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
340 }
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
341 if (!*c++) return FALSE;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
342 if (*c == '@') break;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
343 if (*c != '.') return FALSE;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
344 continue;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
345 }
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
346 if (*c == '@') break;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
347 if (*c <= ' ' || *c >= 127) return FALSE;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
348 if (strchr(rfc822_specials, *c)) return FALSE;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
349 }
18871
078df6ae587a Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <markdoliner@pidgin.im>
parents: 18813
diff changeset
350
078df6ae587a Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <markdoliner@pidgin.im>
parents: 18813
diff changeset
351 /* It's obviously not an email address if we didn't find an '@' above */
078df6ae587a Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <markdoliner@pidgin.im>
parents: 18813
diff changeset
352 if (*c == '\0') return FALSE;
078df6ae587a Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <markdoliner@pidgin.im>
parents: 18813
diff changeset
353
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
354 /* strictly we should return false if (*(c - 1) == '.') too, but I think
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
355 * we should permit user.@domain type addresses - they do work :) */
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
356 if (c == address) return FALSE;
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
357
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
358 /* next we validate the domain portion (name@domain) (rfc1035 & rfc1011) */
9045
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
359 if (!*(domain = ++c)) return FALSE;
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
360 do {
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
361 if (*c == '.' && (c == domain || *(c - 1) == '.' || *(c - 1) == '-'))
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
362 return FALSE;
30444
d871c3fd6637 Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 30437
diff changeset
363 if (*c == '-' && (*(c - 1) == '.' || *(c - 1) == '@')) return FALSE;
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
364 if ((*c < '0' && *c != '-' && *c != '.') || (*c > '9' && *c < 'A') ||
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
365 (*c > 'Z' && *c < 'a') || (*c > 'z')) return FALSE;
9045
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
366 } while (*++c);
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
367
9054
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
368 if (*(c - 1) == '-') return FALSE;
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
369
481fddb7dc5a [gaim-migrate @ 9830]
Tim Ringenbach <marv@pidgin.im>
parents: 9045
diff changeset
370 return ((c - domain) > 3 ? TRUE : FALSE);
9045
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
371 }
c665ceb89b85 [gaim-migrate @ 9821]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8976
diff changeset
372
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
373 /**************************************************************************
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
374 * UTF8 String Functions
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
375 **************************************************************************/
9642
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
376 gchar *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
377 purple_utf8_try_convert(const char *str)
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
378 {
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
379 gsize converted;
9642
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
380 gchar *utf8;
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
381
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
382 g_return_val_if_fail(str != NULL, NULL);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
383
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
384 if (g_utf8_validate(str, -1, NULL)) {
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
385 return g_strdup(str);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
386 }
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
387
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
388 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL);
9642
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
389 if (utf8 != NULL)
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
390 return utf8;
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
391
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
392 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL);
9642
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
393 if ((utf8 != NULL) && (converted == strlen(str)))
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
394 return utf8;
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
395
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 14002
diff changeset
396 g_free(utf8);
9642
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
397
ec0b88cf9161 [gaim-migrate @ 10490]
Mark Doliner <markdoliner@pidgin.im>
parents: 9427
diff changeset
398 return NULL;
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
399 }
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
400
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
401 int
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
402 purple_utf8_strcasecmp(const char *a, const char *b)
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
403 {
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
404 char *a_norm = NULL;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
405 char *b_norm = NULL;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
406 int ret = -1;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
407
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
408 if(!a && b)
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
409 return -1;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
410 else if(!b && a)
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
411 return 1;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
412 else if(!a && !b)
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
413 return 0;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
414
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
415 if(!g_utf8_validate(a, -1, NULL) || !g_utf8_validate(b, -1, NULL))
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
416 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
417 purple_debug_error("purple_utf8_strcasecmp",
7108
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
418 "One or both parameters are invalid UTF8\n");
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
419 return ret;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
420 }
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
421
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
422 a_norm = g_utf8_casefold(a, -1);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
423 b_norm = g_utf8_casefold(b, -1);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
424 ret = g_utf8_collate(a_norm, b_norm);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
425 g_free(a_norm);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
426 g_free(b_norm);
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
427
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
428 return ret;
82655fa54acb [gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents: 7107
diff changeset
429 }
7162
dfd30c70acde [gaim-migrate @ 7729]
Nathan Walp <nwalp@pidgin.im>
parents: 7134
diff changeset
430
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
431 /* this is almost identical to purple_url_encode (hence purple_url_decode
9926
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
432 * being used above), but we want to keep certain characters unescaped
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
433 * for compat reasons */
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
434 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15845
diff changeset
435 purple_escape_filename(const char *str)
9926
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
436 {
10700
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
437 const char *iter;
9926
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
438 static char buf[BUF_LEN];
10700
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
439 char utf_char[6];
9926
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
440 guint i, j = 0;
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
441
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
442 g_return_val_if_fail(str != NULL, NULL);
10700
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
443 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL);
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
444
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
445 iter = str;
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
446 for (; *iter && j < (BUF_LEN - 1) ; iter = g_utf8_next_char(iter)) {
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
447 gunichar c = g_utf8_get_char(iter);
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
448 /* If the character is an ASCII character and is alphanumeric,
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
449 * or one of the specified values, no need to escape */
17261
65aa3164dcce If we're operating on ASCII characters only, we should use g_ascii_isalnum.
Richard Laager <rlaager@pidgin.im>
parents: 17254
diff changeset
450 if (c < 128 && (g_ascii_isalnum(c) || c == '@' || c == '-' ||
10700
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
451 c == '_' || c == '.' || c == '#')) {
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
452 buf[j++] = c;
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
453 } else {
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
454 int bytes = g_unichar_to_utf8(c, utf_char);
36256
a437550a9308 Remove -Wno-sign-compare and backport fixes from default.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36037
diff changeset
455 for (i = 0; (int)i < bytes; i++) {
10700
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
456 if (j > (BUF_LEN - 4))
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
457 break;
36037
e2ef692ff10a Fix outstaning Coverity bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36030
diff changeset
458 if (i >= sizeof(utf_char)) {
e2ef692ff10a Fix outstaning Coverity bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36030
diff changeset
459 g_warn_if_reached();
e2ef692ff10a Fix outstaning Coverity bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36030
diff changeset
460 break;
e2ef692ff10a Fix outstaning Coverity bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36030
diff changeset
461 }
10700
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
462 sprintf(buf + j, "%%%02x", utf_char[i] & 0xff);
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
463 j += 3;
93f5099b2775 [gaim-migrate @ 12273]
Daniel Atallah <datallah@pidgin.im>
parents: 10636
diff changeset
464 }
9926
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
465 }
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
466 }
30414
b334269e9ecf Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30413
diff changeset
467 #ifdef _WIN32
b334269e9ecf Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30413
diff changeset
468 /* File/Directory names in windows cannot end in periods/spaces.
b334269e9ecf Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30413
diff changeset
469 * http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
b334269e9ecf Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30413
diff changeset
470 */
b334269e9ecf Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30413
diff changeset
471 while (j > 0 && (buf[j - 1] == '.' || buf[j - 1] == ' '))
b334269e9ecf Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30413
diff changeset
472 j--;
b334269e9ecf Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 30413
diff changeset
473 #endif
9926
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
474 buf[j] = '\0';
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
475
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
476 return buf;
9957e01fd88a [gaim-migrate @ 10818]
Nathan Walp <nwalp@pidgin.im>
parents: 9916
diff changeset
477 }

mercurial