annotate libpurple/util.c @ 28091:fd781c98a360

Oops.
author Paul Aurich <paul@darkrain42.org>
date Fri, 31 Jul 2009 04:15:02 +0000
parents 577bf7ea0395
children e1cd44c7c7af da22b6d0151e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * @file util.h Utility Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * @ingroup core
20074
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19680
diff changeset
4 */
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19680
diff changeset
5
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19680
diff changeset
6 /* Purple is the legal property of its developers, whose names are too numerous
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * source distribution.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 * (at your option) any later version.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 * GNU General Public License for more details.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
19680
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19661
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
26 #include "cipher.h"
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include "conversation.h"
15613
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
28 #include "core.h"
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include "debug.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include "notify.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include "prpl.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include "prefs.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 #include "util.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
35 struct _PurpleUtilFetchUrlData
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
36 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
37 PurpleUtilFetchUrlCallback callback;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 void *user_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 struct
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 char *user;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 char *passwd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 char *address;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 int port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 char *page;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48 } website;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 char *url;
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
51 int num_times_redirected;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 gboolean full;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 char *user_agent;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 gboolean http11;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 char *request;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 gsize request_written;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 gboolean include_headers;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
59 gboolean is_ssl;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
60 PurpleSslConnection *ssl_connection;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
61 PurpleProxyConnectData *connect_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 int fd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 guint inpa;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65 gboolean got_headers;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 gboolean has_explicit_data_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 char *webdata;
27521
065294d973b4 This fixes this compile warning:
Stu Tomlinson <stu@nosnilmot.com>
parents: 27486
diff changeset
68 gsize len;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 unsigned long data_len;
23742
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
70 gssize max_len;
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
71 gboolean chunked;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73
18147
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
74 static char *custom_user_dir = NULL;
20091
2ab6b55ffa3d Rename the internal home_dir variable to user_dir to match the function and
Richard Laager <rlaager@wiktel.com>
parents: 20074
diff changeset
75 static char *user_dir = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76
21248
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
77
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
78 PurpleMenuAction *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
79 purple_menu_action_new(const char *label, PurpleCallback callback, gpointer data,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 GList *children)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
82 PurpleMenuAction *act = g_new0(PurpleMenuAction, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 act->label = g_strdup(label);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
84 act->callback = callback;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 act->data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 act->children = children;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 return act;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
91 purple_menu_action_free(PurpleMenuAction *act)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
93 g_return_if_fail(act != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
94
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
95 g_free(act->label);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 g_free(act);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98
21248
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
99 void
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
100 purple_util_init(void)
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
101 {
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
102 /* This does nothing right now. It exists for symmetry with
21248
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
103 * purple_util_uninit() and forwards compatibility. */
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
104 }
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
105
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
106 void
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
107 purple_util_uninit(void)
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
108 {
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
109 /* Free these so we don't have leaks at shutdown. */
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
110
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
111 g_free(custom_user_dir);
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
112 custom_user_dir = NULL;
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
113
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
114 g_free(user_dir);
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
115 user_dir = NULL;
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
116 }
5915ad785ee7 Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents: 20917
diff changeset
117
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 * Base16 Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 gchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
122 purple_base16_encode(const guchar *data, gsize len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 gchar *ascii = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 g_return_val_if_fail(data != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 g_return_val_if_fail(len > 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 ascii = g_malloc(len * 2 + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 for (i = 0; i < len; i++)
26967
8290e36a5a73 A patch from Scott Wolchok to replace snprintf() with g_snprintf() and
Richard Laager <rlaager@wiktel.com>
parents: 26854
diff changeset
133 g_snprintf(&ascii[i * 2], 3, "%02hhx", data[i]);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 return ascii;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 guchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
139 purple_base16_decode(const char *str, gsize *ret_len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
141 int len, i, accumulator = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 guchar *data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
146 len = strlen(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
147
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 g_return_val_if_fail(strlen(str) > 0, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149 g_return_val_if_fail(len % 2 == 0, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 data = g_malloc(len / 2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
152
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 for (i = 0; i < len; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 if ((i % 2) == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 accumulator = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 accumulator <<= 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 if (isdigit(str[i]))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161 accumulator |= str[i] - 48;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 {
16153
6613fb7af427 Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents: 16084
diff changeset
164 switch(tolower(str[i]))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 {
16153
6613fb7af427 Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents: 16084
diff changeset
166 case 'a': accumulator |= 10; break;
6613fb7af427 Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents: 16084
diff changeset
167 case 'b': accumulator |= 11; break;
6613fb7af427 Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents: 16084
diff changeset
168 case 'c': accumulator |= 12; break;
6613fb7af427 Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents: 16084
diff changeset
169 case 'd': accumulator |= 13; break;
6613fb7af427 Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents: 16084
diff changeset
170 case 'e': accumulator |= 14; break;
6613fb7af427 Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents: 16084
diff changeset
171 case 'f': accumulator |= 15; break;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 if (i % 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176 data[(i - 1) / 2] = accumulator;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 if (ret_len != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 *ret_len = len / 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 return data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184
17412
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
185 gchar *
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
186 purple_base16_encode_chunked(const guchar *data, gsize len)
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
187 {
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
188 int i;
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
189 gchar *ascii = NULL;
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
190
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
191 g_return_val_if_fail(data != NULL, NULL);
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
192 g_return_val_if_fail(len > 0, NULL);
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
193
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
194 /* For each byte of input, we need 2 bytes for the hex representation
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
195 * and 1 for the colon.
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
196 * The final colon will be replaced by a terminating NULL
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
197 */
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
198 ascii = g_malloc(len * 3 + 1);
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
199
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
200 for (i = 0; i < len; i++)
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
201 g_snprintf(&ascii[i * 3], 4, "%02hhx:", data[i]);
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
202
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
203 /* Replace the final colon with NULL */
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
204 ascii[len * 3 - 1] = 0;
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
205
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
206 return ascii;
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
207 }
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
208
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17244
diff changeset
209
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 * Base64 Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 static const char alphabet[] =
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 "0123456789+/";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 static const char xdigits[] =
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 "0123456789abcdef";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 gchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
221 purple_base64_encode(const guchar *data, gsize len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 {
27299
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
223 #if GLIB_CHECK_VERSION(2,12,0)
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
224 return g_base64_encode(data, len);
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
225 #else
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 char *out, *rv;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
228 g_return_val_if_fail(data != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
229 g_return_val_if_fail(len > 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
231 rv = out = g_malloc(((len/3)+1)*4 + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
232
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 for (; len >= 3; len -= 3)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 *out++ = alphabet[data[0] >> 2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236 *out++ = alphabet[((data[0] << 4) & 0x30) | (data[1] >> 4)];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
237 *out++ = alphabet[((data[1] << 2) & 0x3c) | (data[2] >> 6)];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 *out++ = alphabet[data[2] & 0x3f];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 data += 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
240 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
241
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 if (len > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
244 unsigned char fragment;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
245
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
246 *out++ = alphabet[data[0] >> 2];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 fragment = (data[0] << 4) & 0x30;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
248
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
249 if (len > 1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250 fragment |= data[1] >> 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
251
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
252 *out++ = alphabet[fragment];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 *out++ = (len < 2) ? '=' : alphabet[(data[1] << 2) & 0x3c];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 *out++ = '=';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
255 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 *out = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
258
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 return rv;
27299
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
260 #endif /* GLIB < 2.12.0 */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 guchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
264 purple_base64_decode(const char *str, gsize *ret_len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 {
27299
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
266 #if GLIB_CHECK_VERSION(2,12,0)
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
267 /*
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
268 * We want to allow ret_len to be NULL for backward compatibility,
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
269 * but g_base64_decode() requires a valid length variable. So if
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
270 * ret_len is NULL then pass in a dummy variable.
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
271 */
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
272 gsize unused;
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
273 return g_base64_decode(str, ret_len != NULL ? ret_len : &unused);
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
274 #else
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 guchar *out = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 char tmp = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277 const char *c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 gint32 tmp2 = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 int len = 0, n = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 c = str;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 while (*c) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 if (*c >= 'A' && *c <= 'Z') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 tmp = *c - 'A';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 } else if (*c >= 'a' && *c <= 'z') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 tmp = 26 + (*c - 'a');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 } else if (*c >= '0' && *c <= 57) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 tmp = 52 + (*c - '0');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 } else if (*c == '+') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 tmp = 62;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 } else if (*c == '/') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295 tmp = 63;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296 } else if (*c == '\r' || *c == '\n') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 } else if (*c == '=') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300 if (n == 3) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301 out = g_realloc(out, len + 2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 out[len] = (guchar)(tmp2 >> 10) & 0xff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 len++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 out[len] = (guchar)(tmp2 >> 2) & 0xff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 len++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 } else if (n == 2) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 out = g_realloc(out, len + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 out[len] = (guchar)(tmp2 >> 4) & 0xff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 len++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 tmp2 = ((tmp2 << 6) | (tmp & 0xff));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 n++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 if (n == 4) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 out = g_realloc(out, len + 3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 out[len] = (guchar)((tmp2 >> 16) & 0xff);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318 len++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 out[len] = (guchar)((tmp2 >> 8) & 0xff);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 len++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 out[len] = (guchar)(tmp2 & 0xff);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 len++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 tmp2 = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 n = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329 out = g_realloc(out, len + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 out[len] = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 if (ret_len != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 *ret_len = len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 return out;
27299
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27219
diff changeset
336 #endif /* GLIB < 2.12.0 */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 * Quoted Printable Functions (see RFC 2045).
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 guchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
343 purple_quotedp_decode(const char *str, gsize *ret_len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 char *n, *new;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 const char *end, *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 n = new = g_malloc(strlen (str) + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 end = str + strlen(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 for (p = str; p < end; p++, n++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 if (*p == '=') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 if (p[1] == '\r' && p[2] == '\n') { /* 5.1 #5 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 n -= 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 p += 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 } else if (p[1] == '\n') { /* fuzzy case for 5.1 #5 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 n -= 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 p += 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 } else if (p[1] && p[2]) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 char *nibble1 = strchr(xdigits, tolower(p[1]));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 char *nibble2 = strchr(xdigits, tolower(p[2]));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 if (nibble1 && nibble2) { /* 5.1 #1 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 *n = ((nibble1 - xdigits) << 4) | (nibble2 - xdigits);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 p += 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 } else { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 *n = *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
368 } else { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 *n = *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
370 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 else if (*p == '_')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 *n = ' ';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 *n = *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 *n = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380 if (ret_len != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381 *ret_len = n - new;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383 /* Resize to take less space */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 /* new = realloc(new, n - new); */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 return (guchar *)new;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 * MIME Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
393 purple_mime_decode_field(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
396 * This is wing's version, partially based on revo/shx's version
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397 * See RFC2047 [which apparently obsoletes RFC1342]
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 typedef enum {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400 state_start, state_equal1, state_question1,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401 state_charset, state_question2,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 state_encoding, state_question3,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 state_encoded_text, state_question4, state_equal2 = state_start
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 } encoded_word_state_t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 encoded_word_state_t state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 const char *cur, *mark;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 const char *charset0 = NULL, *encoding0 = NULL, *encoded_text0 = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 char *n, *new;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 /* token can be any CHAR (supposedly ISO8859-1/ISO2022), not just ASCII */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 #define token_char_p(c) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 (c != ' ' && !iscntrl(c) && !strchr("()<>@,;:\"/[]?.=", c))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 /* But encoded-text must be ASCII; alas, isascii() may not exist */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 #define encoded_text_char_p(c) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 ((c & 0x80) == 0 && c != '?' && c != ' ' && isgraph(c))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 #define RECOVER_MARKED_TEXT strncpy(n, mark, cur - mark + 1); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 n += cur - mark + 1
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423 /* NOTE: Assuming that we need just strlen(str)+1 *may* be wrong.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 * It would be wrong if one byte (in some unknown encoding) could
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425 * expand to >=4 bytes of UTF-8; I don't know if there are such things.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427 n = new = g_malloc(strlen(str) + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429 /* Here we will be looking for encoded words and if they seem to be
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 * valid then decode them.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 * They are of this form: =?charset?encoding?text?=
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434 for (cur = str, mark = NULL; *cur; cur += 1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 switch (state) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436 case state_equal1:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
437 if (*cur == '?') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438 state = state_question1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
441 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
442 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 case state_question1:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 if (token_char_p(*cur)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446 charset0 = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 state = state_charset;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448 } else { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 case state_charset:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 if (*cur == '?') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 state = state_question2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 } else if (!token_char_p(*cur)) { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 case state_question2:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 if (token_char_p(*cur)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463 encoding0 = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 state = state_encoding;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 } else { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470 case state_encoding:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471 if (*cur == '?') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 state = state_question3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 } else if (!token_char_p(*cur)) { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 case state_question3:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479 if (encoded_text_char_p(*cur)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480 encoded_text0 = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 state = state_encoded_text;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 } else if (*cur == '?') { /* empty string */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 encoded_text0 = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 state = state_question4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 } else { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
486 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490 case state_encoded_text:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 if (*cur == '?') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 state = state_question4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 } else if (!encoded_text_char_p(*cur)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
496 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
497 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 case state_question4:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499 if (*cur == '=') { /* Got the whole encoded-word */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500 char *charset = g_strndup(charset0, encoding0 - charset0 - 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501 char *encoding = g_strndup(encoding0, encoded_text0 - encoding0 - 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 char *encoded_text = g_strndup(encoded_text0, cur - encoded_text0 - 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503 guchar *decoded = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504 gsize dec_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 if (g_ascii_strcasecmp(encoding, "Q") == 0)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
506 decoded = purple_quotedp_decode(encoded_text, &dec_len);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507 else if (g_ascii_strcasecmp(encoding, "B") == 0)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
508 decoded = purple_base64_decode(encoded_text, &dec_len);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 decoded = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 if (decoded) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 gsize len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 char *converted = g_convert((const gchar *)decoded, dec_len, "utf-8", charset, NULL, &len, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 if (converted) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 n = strncpy(n, converted, len) + len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517 g_free(converted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519 g_free(decoded);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521 g_free(charset);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 g_free(encoding);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 g_free(encoded_text);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 state = state_equal2; /* Restart the FSM */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525 } else { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 if (*cur == '=') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 mark = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 state = state_equal1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 /* Some unencoded text. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 *n = *cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 n += 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 } /* switch */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 } /* for */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 if (state != state_start) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 RECOVER_MARKED_TEXT;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 *n = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
548 return new;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 * Date/Time Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
556 const char *purple_get_tzoff_str(const struct tm *tm, gboolean iso)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 {
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
558 static char buf[7];
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559 long off;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560 gint8 min;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 gint8 hrs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562 struct tm new_tm = *tm;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 mktime(&new_tm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 if (new_tm.tm_isdst < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 g_return_val_if_reached("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 #ifdef _WIN32
20503
905891855710 3rd time the charm? Fixes #2990, maybe
Ka-Hing Cheung <khc@hxbc.us>
parents: 19499
diff changeset
570 if ((off = wpurple_get_tz_offset()) == -1)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 return "";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573 # ifdef HAVE_TM_GMTOFF
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 off = new_tm.tm_gmtoff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 # else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 # ifdef HAVE_TIMEZONE
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 tzset();
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
578 off = -1 * timezone;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579 # endif /* HAVE_TIMEZONE */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 # endif /* !HAVE_TM_GMTOFF */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 #endif /* _WIN32 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 min = (off / 60) % 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 hrs = ((off / 60) - min) / 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
586 if(iso) {
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
587 if (0 == off) {
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
588 strcpy(buf, "Z");
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
589 } else {
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
590 /* please leave the colons...they're optional for iso, but jabber
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
591 * wants them */
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
592 if(g_snprintf(buf, sizeof(buf), "%+03d:%02d", hrs, ABS(min)) > 6)
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
593 g_return_val_if_reached("");
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
594 }
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
595 } else {
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
596 if (g_snprintf(buf, sizeof(buf), "%+03d%02d", hrs, ABS(min)) > 5)
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
597 g_return_val_if_reached("");
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
598 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 /* Windows doesn't HAVE_STRFTIME_Z_FORMAT, but this seems clearer. -- rlaager */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 #if !defined(HAVE_STRFTIME_Z_FORMAT) || defined(_WIN32)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
605 static size_t purple_internal_strftime(char *s, size_t max, const char *format, const struct tm *tm)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 const char *start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608 const char *c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609 char *fmt = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
611 /* Yes, this is checked in purple_utf8_strftime(),
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 * but better safe than sorry. -- rlaager */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613 g_return_val_if_fail(format != NULL, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 /* This is fairly efficient, and it only gets
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616 * executed on Windows or if the underlying
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 * system doesn't support the %z format string,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 * for strftime() so I think it's good enough.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 * -- rlaager */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 for (c = start = format; *c ; c++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 if (*c != '%')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
626
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627 #ifndef HAVE_STRFTIME_Z_FORMAT
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628 if (*c == 'z')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
629 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
630 char *tmp = g_strdup_printf("%s%.*s%s",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
631 fmt ? fmt : "",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
632 c - start - 1,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633 start,
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
634 purple_get_tzoff_str(tm, FALSE));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
635 g_free(fmt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636 fmt = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 start = c + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641 if (*c == 'Z')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
643 char *tmp = g_strdup_printf("%s%.*s%s",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 fmt ? fmt : "",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645 c - start - 1,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 start,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
647 wpurple_get_timezone_abbreviation(tm));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 g_free(fmt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649 fmt = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 start = c + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
651 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
655 if (fmt != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 size_t ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 if (*start)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
661 char *tmp = g_strconcat(fmt, start, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
662 g_free(fmt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
663 fmt = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
665
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
666 ret = strftime(s, max, fmt, tm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667 g_free(fmt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
672 return strftime(s, max, format, tm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
673 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674 #else /* HAVE_STRFTIME_Z_FORMAT && !_WIN32 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
675 #define purple_internal_strftime strftime
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
676 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
677
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
678 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
679 purple_utf8_strftime(const char *format, const struct tm *tm)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
680 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
681 static char buf[128];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
682 char *locale;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
683 GError *err = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
684 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
685 char *utf8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
686
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
687 g_return_val_if_fail(format != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
688
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
689 if (tm == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
690 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
691 time_t now = time(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
692 tm = localtime(&now);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
693 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
694
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
695 locale = g_locale_from_utf8(format, -1, NULL, NULL, &err);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
696 if (err != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
697 {
19653
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19603
diff changeset
698 purple_debug_error("util", "Format conversion failed in purple_utf8_strftime(): %s\n", err->message);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
699 g_error_free(err);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
700 locale = g_strdup(format);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
701 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
702
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703 /* A return value of 0 is either an error (in
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
704 * which case, the contents of the buffer are
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
705 * undefined) or the empty string (in which
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
706 * case, no harm is done here). */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
707 if ((len = purple_internal_strftime(buf, sizeof(buf), locale, tm)) == 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
708 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
709 g_free(locale);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710 return "";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
711 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
712
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
713 g_free(locale);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
714
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
715 utf8 = g_locale_to_utf8(buf, len, NULL, NULL, &err);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716 if (err != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
717 {
19653
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19603
diff changeset
718 purple_debug_error("util", "Result conversion failed in purple_utf8_strftime(): %s\n", err->message);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
719 g_error_free(err);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
720 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
721 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
722 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
723 purple_strlcpy(buf, utf8);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
724 g_free(utf8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
725 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
726
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
727 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
728 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
729
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
730 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
731 purple_date_format_short(const struct tm *tm)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
732 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
733 return purple_utf8_strftime("%x", tm);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
734 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
735
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
736 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
737 purple_date_format_long(const struct tm *tm)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
738 {
23723
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23709
diff changeset
739 /*
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23709
diff changeset
740 * This string determines how some dates are displayed. The default
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23709
diff changeset
741 * string "%x %X" shows the date then the time. Translators can
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23709
diff changeset
742 * change this to "%X %x" if they want the time to be shown first,
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23709
diff changeset
743 * followed by the date.
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23709
diff changeset
744 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
745 return purple_utf8_strftime(_("%x %X"), tm);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
746 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
747
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
748 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
749 purple_date_format_full(const struct tm *tm)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
750 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
751 return purple_utf8_strftime("%c", tm);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
752 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
753
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
754 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
755 purple_time_format(const struct tm *tm)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
756 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
757 return purple_utf8_strftime("%X", tm);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
758 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
759
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
760 time_t
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
761 purple_time_build(int year, int month, int day, int hour, int min, int sec)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
762 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
763 struct tm tm;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
764
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
765 tm.tm_year = year - 1900;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
766 tm.tm_mon = month - 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
767 tm.tm_mday = day;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
768 tm.tm_hour = hour;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
769 tm.tm_min = min;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
771
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
772 return mktime(&tm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
774
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
775 time_t
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
776 purple_str_to_time(const char *timestamp, gboolean utc,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
777 struct tm *tm, long *tz_off, const char **rest)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
778 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
779 time_t retval = 0;
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
780 static struct tm t;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
781 const char *c = timestamp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
782 int year = 0;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
783 long tzoff = PURPLE_NO_TZ_OFF;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
784
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
785 time(&retval);
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
786 localtime_r(&retval, &t);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
787
23905
b789b54c5bb2 purple_str_to_time() didn't necessarily set "rest" under all circumstances.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23796
diff changeset
788 if (rest != NULL)
b789b54c5bb2 purple_str_to_time() didn't necessarily set "rest" under all circumstances.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23796
diff changeset
789 *rest = NULL;
b789b54c5bb2 purple_str_to_time() didn't necessarily set "rest" under all circumstances.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23796
diff changeset
790
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
791 /* 4 digit year */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
792 if (sscanf(c, "%04d", &year) && year > 1900)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
793 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
794 c += 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
795 if (*c == '-')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
796 c++;
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
797 t.tm_year = year - 1900;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
798 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
799
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
800 /* 2 digit month */
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
801 if (!sscanf(c, "%02d", &t.tm_mon))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
802 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
803 if (rest != NULL && *c != '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
804 *rest = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
805 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
806 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
807 c += 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
808 if (*c == '-' || *c == '/')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
809 c++;
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
810 t.tm_mon -= 1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
811
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
812 /* 2 digit day */
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
813 if (!sscanf(c, "%02d", &t.tm_mday))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
814 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
815 if (rest != NULL && *c != '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
816 *rest = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
817 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
818 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
819 c += 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
820 if (*c == '/')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
821 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
822 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
823
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
824 if (!sscanf(c, "%04d", &t.tm_year))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
825 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
826 if (rest != NULL && *c != '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
827 *rest = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
828 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
829 }
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
830 t.tm_year -= 1900;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
831 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
832 else if (*c == 'T' || *c == '.')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
833 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
834 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
835 /* we have more than a date, keep going */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
836
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
837 /* 2 digit hour */
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
838 if ((sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 && (c = c + 8)) ||
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
839 (sscanf(c, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 && (c = c + 6)))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
840 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
841 gboolean offset_positive = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
842 int tzhrs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
843 int tzmins;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
844
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
845 t.tm_isdst = -1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
846
21611
87387eac4348 Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents: 21580
diff changeset
847 if (*c == '.') {
87387eac4348 Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents: 21580
diff changeset
848 do {
87387eac4348 Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents: 21580
diff changeset
849 c++;
87387eac4348 Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents: 21580
diff changeset
850 } while (*c >= '0' && *c <= '9'); /* dealing with precision we don't care about */
87387eac4348 Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents: 21580
diff changeset
851 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
852 if (*c == '+')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
853 offset_positive = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
854 if (((*c == '+' || *c == '-') && (c = c + 1)) &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
855 ((sscanf(c, "%02d:%02d", &tzhrs, &tzmins) == 2 && (c = c + 5)) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
856 (sscanf(c, "%02d%02d", &tzhrs, &tzmins) == 2 && (c = c + 4))))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
857 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
858 tzoff = tzhrs*60*60 + tzmins*60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
859 if (offset_positive)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
860 tzoff *= -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
861 }
23367
ef4dbd2bb696 Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23250
diff changeset
862 else if ((*c == 'Z') && (c = c + 1))
ef4dbd2bb696 Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23250
diff changeset
863 {
ef4dbd2bb696 Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23250
diff changeset
864 /* 'Z' = Zulu = UTC */
ef4dbd2bb696 Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23250
diff changeset
865 tzoff = 0;
ef4dbd2bb696 Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23250
diff changeset
866 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
867 else if (utc)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
868 {
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
869 static struct tm tmptm;
21612
18fb032a602a Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents: 21611
diff changeset
870 time_t tmp;
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
871 tmp = mktime(&t);
21612
18fb032a602a Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents: 21611
diff changeset
872 /* we care about whether it *was* dst, and the offset, here on this
18fb032a602a Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents: 21611
diff changeset
873 * date, not whether we are currently observing dst locally *now*.
18fb032a602a Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents: 21611
diff changeset
874 * This isn't perfect, because we would need to know in advance the
18fb032a602a Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents: 21611
diff changeset
875 * offset we are trying to work out in advance to be sure this
18fb032a602a Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents: 21611
diff changeset
876 * works for times around dst transitions but it'll have to do. */
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
877 localtime_r(&tmp, &tmptm);
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
878 t.tm_isdst = tmptm.tm_isdst;
21612
18fb032a602a Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents: 21611
diff changeset
879 #ifdef HAVE_TM_GMTOFF
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
880 t.tm_gmtoff = tmptm.tm_gmtoff;
21612
18fb032a602a Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents: 21611
diff changeset
881 #endif
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
882 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
883
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
884 if (rest != NULL && *c != '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
885 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
886 if (*c == ' ')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
887 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
888 if (*c != '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
889 *rest = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
890 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
891
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
892 if (tzoff != PURPLE_NO_TZ_OFF || utc)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
893 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
894 #if defined(_WIN32)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
895 long sys_tzoff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
896 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
897
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
898 #if defined(_WIN32) || defined(HAVE_TM_GMTOFF) || defined (HAVE_TIMEZONE)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
899 if (tzoff == PURPLE_NO_TZ_OFF)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
900 tzoff = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
901 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
902
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
903 #ifdef _WIN32
20503
905891855710 3rd time the charm? Fixes #2990, maybe
Ka-Hing Cheung <khc@hxbc.us>
parents: 19499
diff changeset
904 if ((sys_tzoff = wpurple_get_tz_offset()) == -1)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
905 tzoff = PURPLE_NO_TZ_OFF;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
906 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
907 tzoff += sys_tzoff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
908 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
909 #ifdef HAVE_TM_GMTOFF
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
910 tzoff += t.tm_gmtoff;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
911 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
912 # ifdef HAVE_TIMEZONE
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
913 tzset(); /* making sure */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
914 tzoff -= timezone;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
915 # endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
916 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
917 #endif /* _WIN32 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
918 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
919 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
920 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
921 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
922 if (rest != NULL && *c != '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
923 *rest = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
924 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
925 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
926
22868
8dadddab10ed Fix purple_str_to_time() to not break the returned value when we have given
Richard Laager <rlaager@wiktel.com>
parents: 22837
diff changeset
927 retval = mktime(&t);
8dadddab10ed Fix purple_str_to_time() to not break the returned value when we have given
Richard Laager <rlaager@wiktel.com>
parents: 22837
diff changeset
928
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
929 if (tm != NULL)
21621
b2aa68cdc8b9 I had used memcpy to copy the struct tm to where the caller wants it, but
Stu Tomlinson <stu@nosnilmot.com>
parents: 21613
diff changeset
930 *tm = t;
22868
8dadddab10ed Fix purple_str_to_time() to not break the returned value when we have given
Richard Laager <rlaager@wiktel.com>
parents: 22837
diff changeset
931
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
932 if (tzoff != PURPLE_NO_TZ_OFF)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
933 retval += tzoff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
934
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
935 if (tz_off != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
936 *tz_off = tzoff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
937
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
938 return retval;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
939 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
941 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942 * Markup Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
943 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
944
27475
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
945 /*
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
946 * This function is stolen from glib's gmarkup.c and modified to not
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
947 * replace ' with &apos;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
948 */
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
949 static void append_escaped_text(GString *str,
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
950 const gchar *text, gssize length)
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
951 {
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
952 const gchar *p;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
953 const gchar *end;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
954 gunichar c;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
955
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
956 p = text;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
957 end = text + length;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
958
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
959 while (p != end)
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
960 {
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
961 const gchar *next;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
962 next = g_utf8_next_char (p);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
963
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
964 switch (*p)
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
965 {
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
966 case '&':
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
967 g_string_append (str, "&amp;");
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
968 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
969
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
970 case '<':
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
971 g_string_append (str, "&lt;");
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
972 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
973
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
974 case '>':
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
975 g_string_append (str, "&gt;");
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
976 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
977
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
978 case '"':
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
979 g_string_append (str, "&quot;");
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
980 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
981
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
982 default:
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
983 c = g_utf8_get_char (p);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
984 if ((0x1 <= c && c <= 0x8) ||
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
985 (0xb <= c && c <= 0xc) ||
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
986 (0xe <= c && c <= 0x1f) ||
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
987 (0x7f <= c && c <= 0x84) ||
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
988 (0x86 <= c && c <= 0x9f))
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
989 g_string_append_printf (str, "&#x%x;", c);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
990 else
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
991 g_string_append_len (str, p, next - p);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
992 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
993 }
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
994
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
995 p = next;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
996 }
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
997 }
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
998
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
999 /* This function is stolen from glib's gmarkup.c */
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1000 gchar *purple_markup_escape_text(const gchar *text, gssize length)
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1001 {
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1002 GString *str;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1003
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1004 g_return_val_if_fail(text != NULL, NULL);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1005
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1006 if (length < 0)
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1007 length = strlen(text);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1008
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1009 /* prealloc at least as long as original text */
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1010 str = g_string_sized_new(length);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1011 append_escaped_text(str, text, length);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1012
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1013 return g_string_free(str, FALSE);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1014 }
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27460
diff changeset
1015
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1016 const char *
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1017 purple_markup_unescape_entity(const char *text, int *length)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1018 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1019 const char *pln;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1020 int len, pound;
21794
8f82dc5e0b76 Patch #3848 from Eion Robb: "purple_markup_unescape_entity doesn't escape hexadecimal references", with changes from QuLogic.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21621
diff changeset
1021 char temp[2];
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1022
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1023 if (!text || *text != '&')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1024 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1025
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1026 #define IS_ENTITY(s) (!g_ascii_strncasecmp(text, s, (len = sizeof(s) - 1)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1027
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1028 if(IS_ENTITY("&amp;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1029 pln = "&";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1030 else if(IS_ENTITY("&lt;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1031 pln = "<";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1032 else if(IS_ENTITY("&gt;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1033 pln = ">";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1034 else if(IS_ENTITY("&nbsp;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1035 pln = " ";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1036 else if(IS_ENTITY("&copy;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1037 pln = "\302\251"; /* or use g_unichar_to_utf8(0xa9); */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1038 else if(IS_ENTITY("&quot;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1039 pln = "\"";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1040 else if(IS_ENTITY("&reg;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1041 pln = "\302\256"; /* or use g_unichar_to_utf8(0xae); */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1042 else if(IS_ENTITY("&apos;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1043 pln = "\'";
21794
8f82dc5e0b76 Patch #3848 from Eion Robb: "purple_markup_unescape_entity doesn't escape hexadecimal references", with changes from QuLogic.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21621
diff changeset
1044 else if(*(text+1) == '#' &&
22876
bb1dc0095856 Revert some bits of the earlier patch not related to custom smileys.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22875
diff changeset
1045 (sscanf(text, "&#%u%1[;]", &pound, temp) == 2 ||
bb1dc0095856 Revert some bits of the earlier patch not related to custom smileys.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22875
diff changeset
1046 sscanf(text, "&#x%x%1[;]", &pound, temp) == 2) &&
21794
8f82dc5e0b76 Patch #3848 from Eion Robb: "purple_markup_unescape_entity doesn't escape hexadecimal references", with changes from QuLogic.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21621
diff changeset
1047 pound != 0) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1048 static char buf[7];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1049 int buflen = g_unichar_to_utf8((gunichar)pound, buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1050 buf[buflen] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1051 pln = buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1052
27377
d4c6d2c6fb03 Fix purple_markup_unescape_entity to properly consume '&#x5C;' and similar.
Paul Aurich <paul@darkrain42.org>
parents: 27363
diff changeset
1053 len = (*(text+2) == 'x' ? 3 : 2);
d4c6d2c6fb03 Fix purple_markup_unescape_entity to properly consume '&#x5C;' and similar.
Paul Aurich <paul@darkrain42.org>
parents: 27363
diff changeset
1054 while(isxdigit((gint) text[len])) len++;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1055 if(text[len] == ';') len++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1056 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1057 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1058 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1059
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1060 if (length)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1061 *length = len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1062 return pln;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1063 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1064
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1065 char *
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1066 purple_markup_get_css_property(const gchar *style,
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1067 const gchar *opt)
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1068 {
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1069 const gchar *css_str = style;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1070 const gchar *css_value_start;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1071 const gchar *css_value_end;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1072 gchar *tmp;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1073 gchar *ret;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1074
24364
0f035b8db8df Fix CID #388
Richard Laager <rlaager@wiktel.com>
parents: 24363
diff changeset
1075 g_return_val_if_fail(opt != NULL, NULL);
0f035b8db8df Fix CID #388
Richard Laager <rlaager@wiktel.com>
parents: 24363
diff changeset
1076
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1077 if (!css_str)
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1078 return NULL;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1079
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1080 /* find the CSS property */
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1081 while (1)
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1082 {
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1083 /* skip whitespace characters */
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1084 while (*css_str && g_ascii_isspace(*css_str))
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1085 css_str++;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1086 if (!g_ascii_isalpha(*css_str))
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1087 return NULL;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1088 if (g_ascii_strncasecmp(css_str, opt, strlen(opt)))
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1089 {
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1090 /* go to next css property positioned after the next ';' */
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1091 while (*css_str && *css_str != '"' && *css_str != ';')
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1092 css_str++;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1093 if(*css_str != ';')
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1094 return NULL;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1095 css_str++;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1096 }
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1097 else
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1098 break;
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1099 }
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1100
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1101 /* find the CSS value position in the string */
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1102 css_str += strlen(opt);
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1103 while (*css_str && g_ascii_isspace(*css_str))
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1104 css_str++;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1105 if (*css_str != ':')
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1106 return NULL;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1107 css_str++;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1108 while (*css_str && g_ascii_isspace(*css_str))
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1109 css_str++;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1110 if (*css_str == '\0' || *css_str == '"' || *css_str == ';')
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1111 return NULL;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1112
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1113 /* mark the CSS value */
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1114 css_value_start = css_str;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1115 while (*css_str && *css_str != '"' && *css_str != ';')
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1116 css_str++;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1117 css_value_end = css_str - 1;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1118
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1119 /* Removes trailing whitespace */
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1120 while (css_value_end > css_value_start && g_ascii_isspace(*css_value_end))
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1121 css_value_end--;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1122
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1123 tmp = g_strndup(css_value_start, css_value_end - css_value_start + 1);
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1124 ret = purple_unescape_html(tmp);
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1125 g_free(tmp);
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1126
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1127 return ret;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1128 }
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1129
27094
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1130 gboolean purple_markup_is_rtl(const char *html)
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1131 {
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1132 GData *attributes;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1133 const gchar *start, *end;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1134 gboolean res = FALSE;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1135
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1136 if (purple_markup_find_tag("span", html, &start, &end, &attributes))
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1137 {
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1138 /* tmp is a member of attributes and is free with g_datalist_clear call */
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1139 const char *tmp = g_datalist_get_data(&attributes, "dir");
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1140 if (tmp && !g_ascii_strcasecmp(tmp, "RTL"))
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1141 res = TRUE;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1142 if (!res)
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1143 {
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1144 tmp = g_datalist_get_data(&attributes, "style");
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1145 if (tmp)
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1146 {
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1147 char *tmp2 = purple_markup_get_css_property(tmp, "direction");
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1148 if (tmp2 && !g_ascii_strcasecmp(tmp2, "RTL"))
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1149 res = TRUE;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1150 g_free(tmp2);
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1151 }
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1152
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1153 }
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1154 g_datalist_clear(&attributes);
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1155 }
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1156 return res;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1157 }
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27051
diff changeset
1158
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1159 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1160 purple_markup_find_tag(const char *needle, const char *haystack,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1161 const char **start, const char **end, GData **attributes)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1162 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1163 GData *attribs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1164 const char *cur = haystack;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1165 char *name = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1166 gboolean found = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1167 gboolean in_tag = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1168 gboolean in_attr = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1169 const char *in_quotes = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1170 size_t needlelen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1171
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1172 g_return_val_if_fail( needle != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1173 g_return_val_if_fail( *needle != '\0', FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1174 g_return_val_if_fail( haystack != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1175 g_return_val_if_fail( start != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1176 g_return_val_if_fail( end != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1177 g_return_val_if_fail(attributes != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1178
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1179 needlelen = strlen(needle);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1180 g_datalist_init(&attribs);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1181
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1182 while (*cur && !found) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1183 if (in_tag) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1184 if (in_quotes) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1185 const char *close = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1186
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1187 while (*close && *close != *in_quotes)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1188 close++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1189
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1190 /* if we got the close quote, store the value and carry on from *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1191 * after it. if we ran to the end of the string, point to the NULL *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1192 * and we're outta here */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1193 if (*close) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1194 /* only store a value if we have an attribute name */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1195 if (name) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1196 size_t len = close - cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1197 char *val = g_strndup(cur, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1198
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1199 g_datalist_set_data_full(&attribs, name, val, g_free);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1200 g_free(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1201 name = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1202 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1203
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1204 in_quotes = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1205 cur = close + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1206 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1207 cur = close;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1208 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1209 } else if (in_attr) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1210 const char *close = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1211
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1212 while (*close && *close != '>' && *close != '"' &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1213 *close != '\'' && *close != ' ' && *close != '=')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1214 close++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1215
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1216 /* if we got the equals, store the name of the attribute. if we got
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1217 * the quote, save the attribute and go straight to quote mode.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1218 * otherwise the tag closed or we reached the end of the string,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1219 * so we can get outta here */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1220 switch (*close) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1221 case '"':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1222 case '\'':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1223 in_quotes = close;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1224 case '=':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1225 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1226 size_t len = close - cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1227
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1228 /* don't store a blank attribute name */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1229 if (len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1230 g_free(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1231 name = g_ascii_strdown(cur, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1232 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1233
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1234 in_attr = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1235 cur = close + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1236 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1237 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1238 case ' ':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1239 case '>':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1240 in_attr = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1241 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1242 cur = close;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1243 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1244 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1245 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1246 switch (*cur) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1247 case ' ':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1248 /* swallow extra spaces inside tag */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1249 while (*cur && *cur == ' ') cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1250 in_attr = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1251 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1252 case '>':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1253 found = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1254 *end = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1255 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1256 case '"':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1257 case '\'':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1258 in_quotes = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1259 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1260 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1261 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1262 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1263 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1264 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1265 /* if we hit a < followed by the name of our tag... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1266 if (*cur == '<' && !g_ascii_strncasecmp(cur + 1, needle, needlelen)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1267 *start = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1268 cur = cur + needlelen + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1269
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1270 /* if we're pointing at a space or a >, we found the right tag. if *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1271 * we're not, we've found a longer tag, so we need to skip to the *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1272 * >, but not being distracted by >s inside quotes. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1273 if (*cur == ' ' || *cur == '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1274 in_tag = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1275 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1276 while (*cur && *cur != '"' && *cur != '\'' && *cur != '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1277 if (*cur == '"') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1278 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1279 while (*cur && *cur != '"')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1280 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1281 } else if (*cur == '\'') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1282 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1283 while (*cur && *cur != '\'')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1284 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1285 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1286 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1287 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1288 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1289 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1290 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1291 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1292 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1293 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1294 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1295
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1296 /* clean up any attribute name from a premature termination */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1297 g_free(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1298
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1299 if (found) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1300 *attributes = attribs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1301 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1302 *start = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1303 *end = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1304 *attributes = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1305 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1306
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1307 return found;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1308 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1309
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1310 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1311 purple_markup_extract_info_field(const char *str, int len, PurpleNotifyUserInfo *user_info,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1312 const char *start_token, int skip,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1313 const char *end_token, char check_value,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1314 const char *no_value_token,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1315 const char *display_name, gboolean is_link,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1316 const char *link_prefix,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1317 PurpleInfoFieldFormatCallback format_cb)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1318 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1319 const char *p, *q;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1320
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1321 g_return_val_if_fail(str != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1322 g_return_val_if_fail(user_info != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1323 g_return_val_if_fail(start_token != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1324 g_return_val_if_fail(end_token != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1325 g_return_val_if_fail(display_name != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1326
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1327 p = strstr(str, start_token);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1328
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1329 if (p == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1330 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1331
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1332 p += strlen(start_token) + skip;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1333
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1334 if (p >= str + len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1335 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1336
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1337 if (check_value != '\0' && *p == check_value)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1338 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1339
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1340 q = strstr(p, end_token);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1341
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1342 /* Trim leading blanks */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1343 while (*p != '\n' && g_ascii_isspace(*p)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1344 p += 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1345 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1346
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1347 /* Trim trailing blanks */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1348 while (q > p && g_ascii_isspace(*(q - 1))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1349 q -= 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1350 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1351
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1352 /* Don't bother with null strings */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1353 if (p == q)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1354 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1355
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1356 if (q != NULL && (!no_value_token ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1357 (no_value_token && strncmp(p, no_value_token,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1358 strlen(no_value_token)))))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1359 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1360 GString *dest = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1361
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1362 if (is_link)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1363 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1364 g_string_append(dest, "<a href=\"");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1365
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1366 if (link_prefix)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1367 g_string_append(dest, link_prefix);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1368
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1369 if (format_cb != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1370 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1371 char *reformatted = format_cb(p, q - p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1372 g_string_append(dest, reformatted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1373 g_free(reformatted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1374 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1375 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1376 g_string_append_len(dest, p, q - p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1377 g_string_append(dest, "\">");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1378
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1379 if (link_prefix)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1380 g_string_append(dest, link_prefix);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1381
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1382 g_string_append_len(dest, p, q - p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1383 g_string_append(dest, "</a>");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1384 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1385 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1386 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1387 if (format_cb != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1388 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1389 char *reformatted = format_cb(p, q - p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1390 g_string_append(dest, reformatted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1391 g_free(reformatted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1392 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1393 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1394 g_string_append_len(dest, p, q - p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1395 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1396
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1397 purple_notify_user_info_add_pair(user_info, display_name, dest->str);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1398 g_string_free(dest, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1399
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1400 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1401 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1402
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1403 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1404 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1405
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1406 struct purple_parse_tag {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1407 char *src_tag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1408 char *dest_tag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1409 gboolean ignore;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1410 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1411
27716
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27698
diff changeset
1412 /* NOTE: Do not put `do {} while(0)` around this macro (as this is the method
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27698
diff changeset
1413 recommended in the GCC docs). It contains 'continue's that should
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27698
diff changeset
1414 affect the while-loop in purple_markup_html_to_xhtml and doing the
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27698
diff changeset
1415 above would break that.
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27698
diff changeset
1416 Also, remember to put braces in constructs that require them for
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27698
diff changeset
1417 multiple statements when using this macro. */
27698
3edd01d04004 disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents: 27697
diff changeset
1418 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1419 const char *o = c + strlen("<" x); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1420 const char *p = NULL, *q = NULL, *r = NULL; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1421 GString *innards = g_string_new(""); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1422 while(o && *o) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1423 if(!q && (*o == '\"' || *o == '\'') ) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1424 q = o; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1425 } else if(q) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1426 if(*o == *q) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1427 char *unescaped = g_strndup(q+1, o-q-1); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1428 char *escaped = g_markup_escape_text(unescaped, -1); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1429 g_string_append_printf(innards, "%c%s%c", *q, escaped, *q); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1430 g_free(unescaped); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1431 g_free(escaped); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1432 q = NULL; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1433 } else if(*c == '\\') { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1434 o++; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1435 } \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1436 } else if(*o == '<') { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1437 r = o; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1438 } else if(*o == '>') { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1439 p = o; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1440 break; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1441 } else { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1442 innards = g_string_append_c(innards, *o); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1443 } \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1444 o++; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1445 } \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1446 if(p && !r) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1447 if(*(p-1) != '/') { \
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1448 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1); \
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1449 pt->src_tag = x; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1450 pt->dest_tag = y; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1451 tags = g_list_prepend(tags, pt); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1452 } \
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1453 if(xhtml) { \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1454 xhtml = g_string_append(xhtml, "<" y); \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1455 xhtml = g_string_append(xhtml, innards->str); \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1456 xhtml = g_string_append_c(xhtml, '>'); \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1457 } \
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1458 c = p + 1; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1459 } else { \
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1460 if(xhtml) \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1461 xhtml = g_string_append(xhtml, "&lt;"); \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1462 if(plain) \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1463 plain = g_string_append_c(plain, '<'); \
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1464 c++; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1465 } \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1466 g_string_free(innards, TRUE); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1467 continue; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1468 } \
27696
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1469 if(!g_ascii_strncasecmp(c, "<" x, strlen("<" x)) && \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1470 (*(c+strlen("<" x)) == '>' || \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1471 !g_ascii_strncasecmp(c+strlen("<" x), "/>", 2))) { \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1472 if(xhtml) \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1473 xhtml = g_string_append(xhtml, "<" y); \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1474 c += strlen("<" x); \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1475 if(*c != '/') { \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1476 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1); \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1477 pt->src_tag = x; \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1478 pt->dest_tag = y; \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1479 tags = g_list_prepend(tags, pt); \
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1480 if(xhtml) \
27696
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1481 xhtml = g_string_append_c(xhtml, '>'); \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1482 } else { \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1483 if(xhtml) \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1484 xhtml = g_string_append(xhtml, "/>");\
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1485 } \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1486 c = strchr(c, '>') + 1; \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27665
diff changeset
1487 continue; \
27710
91333c6c16ef 567c0647 introduced an extra backslash at the end of ALLOW_TAG_ALT
Ka-Hing Cheung <khc@hxbc.us>
parents: 27709
diff changeset
1488 }
27716
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27698
diff changeset
1489 /* Don't forget to check the note above for ALLOW_TAG_ALT. */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1490 #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1491 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1492 purple_markup_html_to_xhtml(const char *html, char **xhtml_out,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1493 char **plain_out)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1494 {
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1495 GString *xhtml = NULL;
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1496 GString *plain = NULL;
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1497 GString *url = NULL;
19262
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1498 GString *cdata = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1499 GList *tags = NULL, *tag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1500 const char *c = html;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1501 char quote = '\0';
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1502
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1503 #define CHECK_QUOTE(ptr) if (*(ptr) == '\'' || *(ptr) == '\"') \
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1504 quote = *(ptr++); \
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1505 else \
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1506 quote = '\0';
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1507
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1508 #define VALID_CHAR(ptr) (*(ptr) && *(ptr) != quote && (quote || (*(ptr) != ' ' && *(ptr) != '>')))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1509
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1510 g_return_if_fail(xhtml_out != NULL || plain_out != NULL);
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1511
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1512 if(xhtml_out)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1513 xhtml = g_string_new("");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1514 if(plain_out)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1515 plain = g_string_new("");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1516
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1517 while(c && *c) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1518 if(*c == '<') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1519 if(*(c+1) == '/') { /* closing tag */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1520 tag = tags;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1521 while(tag) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1522 struct purple_parse_tag *pt = tag->data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1523 if(!g_ascii_strncasecmp((c+2), pt->src_tag, strlen(pt->src_tag)) && *(c+strlen(pt->src_tag)+2) == '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1524 c += strlen(pt->src_tag) + 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1525 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1526 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1527 tag = tag->next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1528 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1529 if(tag) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1530 while(tags) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1531 struct purple_parse_tag *pt = tags->data;
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1532 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1533 g_string_append_printf(xhtml, "</%s>", pt->dest_tag);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
1534 if(plain && purple_strequal(pt->src_tag, "a")) {
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1535 /* if this is a link, we have to add the url to the plaintext, too */
21185
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1536 if (cdata && url &&
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1537 (!g_string_equal(cdata, url) && (g_ascii_strncasecmp(url->str, "mailto:", 7) != 0 ||
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1538 g_utf8_collate(url->str + 7, cdata->str) != 0)))
19262
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1539 g_string_append_printf(plain, " <%s>", g_strstrip(url->str));
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1540 if (cdata) {
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1541 g_string_free(cdata, TRUE);
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1542 cdata = NULL;
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1543 }
19408
cc36a5aac908 Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19262
diff changeset
1544
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1545 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1546 if(tags == tag)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1547 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1548 tags = g_list_remove(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1549 g_free(pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1550 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1551 g_free(tag->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1552 tags = g_list_remove(tags, tag->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1553 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1554 /* a closing tag we weren't expecting...
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1555 * we'll let it slide, if it's really a tag...if it's
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1556 * just a </ we'll escape it properly */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1557 const char *end = c+2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1558 while(*end && g_ascii_isalpha(*end))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1559 end++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1560 if(*end == '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1561 c = end+1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1562 } else {
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1563 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1564 xhtml = g_string_append(xhtml, "&lt;");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1565 if(plain)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1566 plain = g_string_append_c(plain, '<');
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1567 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1568 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1569 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1570 } else { /* opening tag */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1571 ALLOW_TAG("blockquote");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1572 ALLOW_TAG("cite");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1573 ALLOW_TAG("div");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1574 ALLOW_TAG("em");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1575 ALLOW_TAG("h1");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1576 ALLOW_TAG("h2");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1577 ALLOW_TAG("h3");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1578 ALLOW_TAG("h4");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1579 ALLOW_TAG("h5");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1580 ALLOW_TAG("h6");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1581 /* we only allow html to start the message */
27698
3edd01d04004 disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents: 27697
diff changeset
1582 if(c == html) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1583 ALLOW_TAG("html");
27698
3edd01d04004 disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents: 27697
diff changeset
1584 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1585 ALLOW_TAG_ALT("i", "em");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1586 ALLOW_TAG_ALT("italic", "em");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1587 ALLOW_TAG("li");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1588 ALLOW_TAG("ol");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1589 ALLOW_TAG("p");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1590 ALLOW_TAG("pre");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1591 ALLOW_TAG("q");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1592 ALLOW_TAG("span");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1593 ALLOW_TAG("ul");
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1594
19408
cc36a5aac908 Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19262
diff changeset
1595
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1596 /* we skip <HR> because it's not legal in XHTML-IM. However,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1597 * we still want to send something sensible, so we put a
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1598 * linebreak in its place. <BR> also needs special handling
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1599 * because putting a </BR> to close it would just be dumb. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1600 if((!g_ascii_strncasecmp(c, "<br", 3)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1601 || !g_ascii_strncasecmp(c, "<hr", 3))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1602 && (*(c+3) == '>' ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1603 !g_ascii_strncasecmp(c+3, "/>", 2) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1604 !g_ascii_strncasecmp(c+3, " />", 3))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1605 c = strchr(c, '>') + 1;
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1606 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1607 xhtml = g_string_append(xhtml, "<br/>");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1608 if(plain && *c != '\n')
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1609 plain = g_string_append_c(plain, '\n');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1610 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1611 }
22191
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1612 if(!g_ascii_strncasecmp(c, "<b>", 3) || !g_ascii_strncasecmp(c, "<bold>", strlen("<bold>")) || !g_ascii_strncasecmp(c, "<strong>", strlen("<strong>"))) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1613 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
22191
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1614 if (*(c+2) == '>')
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1615 pt->src_tag = "b";
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1616 else if (*(c+2) == 'o')
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1617 pt->src_tag = "bold";
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1618 else
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1619 pt->src_tag = "strong";
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1620 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1621 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1622 c = strchr(c, '>') + 1;
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1623 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1624 xhtml = g_string_append(xhtml, "<span style='font-weight: bold;'>");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1625 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1626 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1627 if(!g_ascii_strncasecmp(c, "<u>", 3) || !g_ascii_strncasecmp(c, "<underline>", strlen("<underline>"))) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1628 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1629 pt->src_tag = *(c+2) == '>' ? "u" : "underline";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1630 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1631 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1632 c = strchr(c, '>') + 1;
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1633 if (xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1634 xhtml = g_string_append(xhtml, "<span style='text-decoration: underline;'>");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1635 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1636 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1637 if(!g_ascii_strncasecmp(c, "<s>", 3) || !g_ascii_strncasecmp(c, "<strike>", strlen("<strike>"))) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1638 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1639 pt->src_tag = *(c+2) == '>' ? "s" : "strike";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1640 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1641 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1642 c = strchr(c, '>') + 1;
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1643 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1644 xhtml = g_string_append(xhtml, "<span style='text-decoration: line-through;'>");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1645 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1646 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1647 if(!g_ascii_strncasecmp(c, "<sub>", 5)) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1648 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1649 pt->src_tag = "sub";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1650 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1651 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1652 c = strchr(c, '>') + 1;
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1653 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1654 xhtml = g_string_append(xhtml, "<span style='vertical-align:sub;'>");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1655 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1656 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1657 if(!g_ascii_strncasecmp(c, "<sup>", 5)) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1658 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1659 pt->src_tag = "sup";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1660 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1661 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1662 c = strchr(c, '>') + 1;
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1663 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1664 xhtml = g_string_append(xhtml, "<span style='vertical-align:super;'>");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1665 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1666 }
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1667 if (!g_ascii_strncasecmp(c, "<img", 4) && (*(c+4) == '>' || *(c+4) == ' ')) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1668 const char *p = c + 4;
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1669 GString *src = NULL, *alt = NULL;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1670 while (*p && *p != '>') {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1671 if (!g_ascii_strncasecmp(p, "src=", 4)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1672 const char *q = p + 4;
22837
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22475
diff changeset
1673 if (src)
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22475
diff changeset
1674 g_string_free(src, TRUE);
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1675 src = g_string_new("");
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1676 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1677 while (VALID_CHAR(q)) {
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1678 src = g_string_append_c(src, *q);
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1679 q++;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1680 }
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1681 p = q;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1682 } else if (!g_ascii_strncasecmp(p, "alt=", 4)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1683 const char *q = p + 4;
22837
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22475
diff changeset
1684 if (alt)
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22475
diff changeset
1685 g_string_free(alt, TRUE);
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1686 alt = g_string_new("");
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1687 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1688 while (VALID_CHAR(q)) {
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1689 alt = g_string_append_c(alt, *q);
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1690 q++;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1691 }
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1692 p = q;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1693 } else {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1694 p++;
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1695 }
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1696 }
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1697 if ((c = strchr(p, '>')) != NULL)
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1698 c++;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1699 else
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1700 c = p;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1701 /* src and alt are required! */
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1702 if(src && xhtml)
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1703 g_string_append_printf(xhtml, "<img src='%s' alt='%s' />", g_strstrip(src->str), alt ? alt->str : "");
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1704 if(alt) {
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1705 if(plain)
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1706 plain = g_string_append(plain, alt->str);
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1707 if(!src && xhtml)
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1708 xhtml = g_string_append(xhtml, alt->str);
20969
17ee8c81c99b Only free the GString "alt" if it's non-null. This was causing an
Mark Doliner <mark@kingant.net>
parents: 20961
diff changeset
1709 g_string_free(alt, TRUE);
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1710 }
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1711 g_string_free(src, TRUE);
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1712 continue;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1713 }
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1714 if (!g_ascii_strncasecmp(c, "<a", 2) && (*(c+2) == '>' || *(c+2) == ' ')) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1715 const char *p = c + 2;
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1716 struct purple_parse_tag *pt;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1717 while (*p && *p != '>') {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1718 if (!g_ascii_strncasecmp(p, "href=", 5)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1719 const char *q = p + 5;
20587
45b524709475 Fix some incorrect assertions when G_DEBUG=fatal_warnings is set.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20541
diff changeset
1720 if (url)
45b524709475 Fix some incorrect assertions when G_DEBUG=fatal_warnings is set.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20541
diff changeset
1721 g_string_free(url, TRUE);
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1722 url = g_string_new("");
22837
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22475
diff changeset
1723 if (cdata)
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22475
diff changeset
1724 g_string_free(cdata, TRUE);
19262
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1725 cdata = g_string_new("");
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1726 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1727 while (VALID_CHAR(q)) {
21299
39231317310a Escape any un-escaped entities in purple_markup_html_to_xhtml when parsing
Stu Tomlinson <stu@nosnilmot.com>
parents: 21284
diff changeset
1728 int len;
39231317310a Escape any un-escaped entities in purple_markup_html_to_xhtml when parsing
Stu Tomlinson <stu@nosnilmot.com>
parents: 21284
diff changeset
1729 if ((*q == '&') && (purple_markup_unescape_entity(q, &len) == NULL))
39231317310a Escape any un-escaped entities in purple_markup_html_to_xhtml when parsing
Stu Tomlinson <stu@nosnilmot.com>
parents: 21284
diff changeset
1730 url = g_string_append(url, "&amp;");
39231317310a Escape any un-escaped entities in purple_markup_html_to_xhtml when parsing
Stu Tomlinson <stu@nosnilmot.com>
parents: 21284
diff changeset
1731 else
39231317310a Escape any un-escaped entities in purple_markup_html_to_xhtml when parsing
Stu Tomlinson <stu@nosnilmot.com>
parents: 21284
diff changeset
1732 url = g_string_append_c(url, *q);
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1733 q++;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1734 }
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1735 p = q;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1736 } else {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1737 p++;
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1738 }
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1739 }
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1740 if ((c = strchr(p, '>')) != NULL)
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1741 c++;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1742 else
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1743 c = p;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1744 pt = g_new0(struct purple_parse_tag, 1);
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1745 pt->src_tag = "a";
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1746 pt->dest_tag = "a";
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1747 tags = g_list_prepend(tags, pt);
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1748 if(xhtml)
26963
795606e2f7c6 According to RFC 1738, "'" is a valid character in a URL.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26854
diff changeset
1749 g_string_append_printf(xhtml, "<a href=\"%s\">", url ? g_strstrip(url->str) : "");
18493
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1750 continue;
274a08f56ea6 Per request of rlaager, propagated my xhtml-creator fixes to the main branch. This adds two things: proper <img>-handling and appending URLs to the plain text version like this: <http://www.example.com>.
Andreas Monitzer <pidgin@monitzer.com>
parents: 18397
diff changeset
1751 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1752 if(!g_ascii_strncasecmp(c, "<font", 5) && (*(c+5) == '>' || *(c+5) == ' ')) {
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1753 const char *p = c + 5;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1754 GString *style = g_string_new("");
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1755 struct purple_parse_tag *pt;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1756 while (*p && *p != '>') {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1757 if (!g_ascii_strncasecmp(p, "back=", 5)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1758 const char *q = p + 5;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1759 GString *color = g_string_new("");
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1760 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1761 while (VALID_CHAR(q)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1762 color = g_string_append_c(color, *q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1763 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1764 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1765 g_string_append_printf(style, "background: %s; ", color->str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1766 g_string_free(color, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1767 p = q;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1768 } else if (!g_ascii_strncasecmp(p, "color=", 6)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1769 const char *q = p + 6;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1770 GString *color = g_string_new("");
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1771 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1772 while (VALID_CHAR(q)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1773 color = g_string_append_c(color, *q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1774 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1775 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1776 g_string_append_printf(style, "color: %s; ", color->str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1777 g_string_free(color, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1778 p = q;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1779 } else if (!g_ascii_strncasecmp(p, "face=", 5)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1780 const char *q = p + 5;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1781 GString *face = g_string_new("");
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1782 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1783 while (VALID_CHAR(q)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1784 face = g_string_append_c(face, *q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1785 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1786 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1787 g_string_append_printf(style, "font-family: %s; ", g_strstrip(face->str));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1788 g_string_free(face, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1789 p = q;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1790 } else if (!g_ascii_strncasecmp(p, "size=", 5)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1791 const char *q = p + 5;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1792 int sz;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1793 const char *size = "medium";
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1794 CHECK_QUOTE(q);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1795 sz = atoi(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1796 switch (sz)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1797 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1798 case 1:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1799 size = "xx-small";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1800 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1801 case 2:
24828
3d3376237a7c Change the font size mapping table in purple_markup_html_to_xhtml() to
Mark Doliner <mark@kingant.net>
parents: 24806
diff changeset
1802 size = "small";
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1803 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1804 case 3:
24828
3d3376237a7c Change the font size mapping table in purple_markup_html_to_xhtml() to
Mark Doliner <mark@kingant.net>
parents: 24806
diff changeset
1805 size = "medium";
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1806 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1807 case 4:
24828
3d3376237a7c Change the font size mapping table in purple_markup_html_to_xhtml() to
Mark Doliner <mark@kingant.net>
parents: 24806
diff changeset
1808 size = "large";
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1809 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1810 case 5:
24828
3d3376237a7c Change the font size mapping table in purple_markup_html_to_xhtml() to
Mark Doliner <mark@kingant.net>
parents: 24806
diff changeset
1811 size = "x-large";
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1812 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1813 case 6:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1814 case 7:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1815 size = "xx-large";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1816 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1817 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1818 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1819 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1820 g_string_append_printf(style, "font-size: %s; ", size);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1821 p = q;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1822 } else {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1823 p++;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1824 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1825 }
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1826 if ((c = strchr(p, '>')) != NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1827 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1828 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1829 c = p;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1830 pt = g_new0(struct purple_parse_tag, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1831 pt->src_tag = "font";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1832 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1833 tags = g_list_prepend(tags, pt);
21028
e4cf0506be74 Avoid g_log warnings when there's no xhtml to append to, and remove a
Stu Tomlinson <stu@nosnilmot.com>
parents: 21015
diff changeset
1834 if(style->len && xhtml)
18046
58e28ccf08e6 merge of '9d95292d55daedb7f74c7df323ad2c69d347d384'
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18043 18042
diff changeset
1835 g_string_append_printf(xhtml, "<span style='%s'>", g_strstrip(style->str));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1836 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1837 pt->ignore = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1838 g_string_free(style, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1839 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1840 }
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1841 if (!g_ascii_strncasecmp(c, "<body ", 6)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1842 const char *p = c + 6;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1843 gboolean did_something = FALSE;
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1844 while (*p && *p != '>') {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1845 if (!g_ascii_strncasecmp(p, "bgcolor=", 8)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1846 const char *q = p + 8;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1847 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1848 GString *color = g_string_new("");
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1849 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1850 while (VALID_CHAR(q)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1851 color = g_string_append_c(color, *q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1852 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1853 }
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1854 if (xhtml)
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1855 g_string_append_printf(xhtml, "<span style='background: %s;'>", g_strstrip(color->str));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1856 g_string_free(color, TRUE);
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1857 if ((c = strchr(p, '>')) != NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1858 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1859 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1860 c = p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1861 pt->src_tag = "body";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1862 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1863 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1864 did_something = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1865 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1866 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1867 p++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1868 }
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1869 if (did_something) continue;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1870 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1871 /* this has to come after the special case for bgcolor */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1872 ALLOW_TAG("body");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1873 if(!g_ascii_strncasecmp(c, "<!--", strlen("<!--"))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1874 char *p = strstr(c + strlen("<!--"), "-->");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1875 if(p) {
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1876 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1877 xhtml = g_string_append(xhtml, "<!--");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1878 c += strlen("<!--");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1879 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1880 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1881 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1882
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1883 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1884 xhtml = g_string_append(xhtml, "&lt;");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1885 if(plain)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1886 plain = g_string_append_c(plain, '<');
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1887 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1888 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1889 } else if(*c == '&') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1890 char buf[7];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1891 const char *pln;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1892 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1893
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1894 if ((pln = purple_markup_unescape_entity(c, &len)) == NULL) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1895 len = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1896 g_snprintf(buf, sizeof(buf), "%c", *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1897 pln = buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1898 }
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1899 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1900 xhtml = g_string_append_len(xhtml, c, len);
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1901 if(plain)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1902 plain = g_string_append(plain, pln);
21185
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1903 if(cdata)
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1904 cdata = g_string_append_len(cdata, c, len);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1905 c += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1906 } else {
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1907 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1908 xhtml = g_string_append_c(xhtml, *c);
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1909 if(plain)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1910 plain = g_string_append_c(plain, *c);
19262
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1911 if(cdata)
450090c68351 When converting to xhtml, only add URLs in angle brackets if it doesn't match the cdata. Fixes #2445
Sean Egan <seanegan@gmail.com>
parents: 18600
diff changeset
1912 cdata = g_string_append_c(cdata, *c);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1913 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1914 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1915 }
17706
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1916 if(xhtml) {
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1917 for (tag = tags; tag ; tag = tag->next) {
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1918 struct purple_parse_tag *pt = tag->data;
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1919 if(!pt->ignore)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1920 g_string_append_printf(xhtml, "</%s>", pt->dest_tag);
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17705
diff changeset
1921 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1922 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1923 g_list_free(tags);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1924 if(xhtml_out)
17705
a7a8e4245b33 Remove needless string duplication.
Richard Laager <rlaager@wiktel.com>
parents: 17673
diff changeset
1925 *xhtml_out = g_string_free(xhtml, FALSE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1926 if(plain_out)
17705
a7a8e4245b33 Remove needless string duplication.
Richard Laager <rlaager@wiktel.com>
parents: 17673
diff changeset
1927 *plain_out = g_string_free(plain, FALSE);
18560
481eb37730bf This was crashing for me when writing a system message when logging
Mark Doliner <mark@kingant.net>
parents: 18493
diff changeset
1928 if(url)
481eb37730bf This was crashing for me when writing a system message when logging
Mark Doliner <mark@kingant.net>
parents: 18493
diff changeset
1929 g_string_free(url, TRUE);
21185
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1930 if (cdata)
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1931 g_string_free(cdata, TRUE);
23250
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1932 #undef CHECK_QUOTE
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23144
diff changeset
1933 #undef VALID_CHAR
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1934 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1935
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1936 /* The following are probably reasonable changes:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1937 * - \n should be converted to a normal space
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1938 * - in addition to <br>, <p> and <div> etc. should also be converted into \n
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1939 * - We want to turn </td>#whitespace<td> sequences into a single tab
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1940 * - We want to turn <td> into a single tab (for msn profile "parsing")
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1941 * - We want to turn </tr>#whitespace<tr> sequences into a single \n
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1942 * - <script>...</script> and <style>...</style> should be completely removed
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1943 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1944
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1945 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
1946 purple_markup_strip_html(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1947 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1948 int i, j, k, entlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1949 gboolean visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1950 gboolean closing_td_p = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1951 gchar *str2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1952 const gchar *cdata_close_tag = NULL, *ent;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1953 gchar *href = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1954 int href_st = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1955
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1956 if(!str)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1957 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1958
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1959 str2 = g_strdup(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1960
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1961 for (i = 0, j = 0; str2[i]; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1962 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1963 if (str2[i] == '<')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1964 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1965 if (cdata_close_tag)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1966 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1967 /* Note: Don't even assume any other tag is a tag in CDATA */
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
1968 if (g_ascii_strncasecmp(str2 + i, cdata_close_tag,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1969 strlen(cdata_close_tag)) == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1970 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1971 i += strlen(cdata_close_tag) - 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1972 cdata_close_tag = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1973 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1974 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1975 }
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
1976 else if (g_ascii_strncasecmp(str2 + i, "<td", 3) == 0 && closing_td_p)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1977 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1978 str2[j++] = '\t';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1979 visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1980 }
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
1981 else if (g_ascii_strncasecmp(str2 + i, "</td>", 5) == 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1982 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1983 closing_td_p = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1984 visible = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1985 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1986 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1987 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1988 closing_td_p = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1989 visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1990 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1991
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1992 k = i + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1993
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1994 if(g_ascii_isspace(str2[k]))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1995 visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1996 else if (str2[k])
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1997 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1998 /* Scan until we end the tag either implicitly (closed start
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1999 * tag) or explicitly, using a sloppy method (i.e., < or >
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2000 * inside quoted attributes will screw us up)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2001 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2002 while (str2[k] && str2[k] != '<' && str2[k] != '>')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2003 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2004 k++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2005 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2006
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2007 /* If we've got an <a> tag with an href, save the address
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2008 * to print later. */
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2009 if (g_ascii_strncasecmp(str2 + i, "<a", 2) == 0 &&
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2010 g_ascii_isspace(str2[i+2]))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2011 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2012 int st; /* start of href, inclusive [ */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2013 int end; /* end of href, exclusive ) */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2014 char delim = ' ';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2015 /* Find start of href */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2016 for (st = i + 3; st < k; st++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2017 {
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2018 if (g_ascii_strncasecmp(str2+st, "href=", 5) == 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2019 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2020 st += 5;
16169
49a1fed5ee37 This was causing problems with jabber in finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16153
diff changeset
2021 if (str2[st] == '"' || str2[st] == '\'')
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2022 {
16169
49a1fed5ee37 This was causing problems with jabber in finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16153
diff changeset
2023 delim = str2[st];
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2024 st++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2025 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2026 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2027 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2028 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2029 /* find end of address */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2030 for (end = st; end < k && str2[end] != delim; end++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2031 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2032 /* All the work is done in the loop construct above. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2033 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2034
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2035 /* If there's an address, save it. If there was
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2036 * already one saved, kill it. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2037 if (st < k)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2038 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2039 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2040 g_free(href);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2041 tmp = g_strndup(str2 + st, end - st);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2042 href = purple_unescape_html(tmp);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2043 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2044 href_st = j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2045 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2046 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2047
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2048 /* Replace </a> with an ascii representation of the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2049 * address the link was pointing to. */
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2050 else if (href != NULL && g_ascii_strncasecmp(str2 + i, "</a>", 4) == 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2051 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2052
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2053 size_t hrlen = strlen(href);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2054
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2055 /* Only insert the href if it's different from the CDATA. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2056 if ((hrlen != j - href_st ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2057 strncmp(str2 + href_st, href, hrlen)) &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2058 (hrlen != j - href_st + 7 || /* 7 == strlen("http://") */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2059 strncmp(str2 + href_st, href + 7, hrlen - 7)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2060 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2061 str2[j++] = ' ';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2062 str2[j++] = '(';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2063 g_memmove(str2 + j, href, hrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2064 j += hrlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2065 str2[j++] = ')';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2066 g_free(href);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2067 href = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2068 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2069 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2070
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2071 /* Check for tags which should be mapped to newline */
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2072 else if (g_ascii_strncasecmp(str2 + i, "<p>", 3) == 0
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2073 || g_ascii_strncasecmp(str2 + i, "<tr", 3) == 0
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2074 || g_ascii_strncasecmp(str2 + i, "<br", 3) == 0
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2075 || g_ascii_strncasecmp(str2 + i, "<hr", 3) == 0
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2076 || g_ascii_strncasecmp(str2 + i, "<li", 3) == 0
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2077 || g_ascii_strncasecmp(str2 + i, "<div", 4) == 0
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2078 || g_ascii_strncasecmp(str2 + i, "</table>", 8) == 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2079 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2080 str2[j++] = '\n';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2081 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2082 /* Check for tags which begin CDATA and need to be closed */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2083 #if 0 /* FIXME.. option is end tag optional, we can't handle this right now */
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2084 else if (g_ascii_strncasecmp(str2 + i, "<option", 7) == 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2085 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2086 /* FIXME: We should not do this if the OPTION is SELECT'd */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2087 cdata_close_tag = "</option>";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2088 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2089 #endif
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2090 else if (g_ascii_strncasecmp(str2 + i, "<script", 7) == 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2091 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2092 cdata_close_tag = "</script>";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2093 }
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2094 else if (g_ascii_strncasecmp(str2 + i, "<style", 6) == 0)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2095 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2096 cdata_close_tag = "</style>";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2097 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2098 /* Update the index and continue checking after the tag */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2099 i = (str2[k] == '<' || str2[k] == '\0')? k - 1: k;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2100 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2101 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2102 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2103 else if (cdata_close_tag)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2104 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2105 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2106 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2107 else if (!g_ascii_isspace(str2[i]))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2108 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2109 visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2110 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2111
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
2112 if (str2[i] == '&' && (ent = purple_markup_unescape_entity(str2 + i, &entlen)) != NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2113 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2114 while (*ent)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2115 str2[j++] = *ent++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2116 i += entlen - 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2117 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2118 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2119
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2120 if (visible)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2121 str2[j++] = g_ascii_isspace(str2[i])? ' ': str2[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2122 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2123
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2124 g_free(href);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2125
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2126 str2[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2127
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2128 return str2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2129 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2130
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2131 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2132 badchar(char c)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2133 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2134 switch (c) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2135 case ' ':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2136 case ',':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2137 case '\0':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2138 case '\n':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2139 case '\r':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2140 case '<':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2141 case '>':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2142 case '"':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2143 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2144 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2145 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2146 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2147 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2148
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2149 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2150 badentity(const char *c)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2151 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2152 if (!g_ascii_strncasecmp(c, "&lt;", 4) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2153 !g_ascii_strncasecmp(c, "&gt;", 4) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2154 !g_ascii_strncasecmp(c, "&quot;", 6)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2155 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2156 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2157 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2158 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2159
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2160 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2161 purple_markup_linkify(const char *text)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2162 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2163 const char *c, *t, *q = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2164 char *tmpurlbuf, *url_buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2165 gunichar g;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2166 gboolean inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2167 int inside_paren = 0;
23709
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23583
diff changeset
2168 GString *ret;
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23583
diff changeset
2169
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23583
diff changeset
2170 if (text == NULL)
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23583
diff changeset
2171 return NULL;
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23583
diff changeset
2172
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23583
diff changeset
2173 ret = g_string_new("");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2174
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2175 c = text;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2176 while (*c) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2177
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2178 if(*c == '(' && !inside_html) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2179 inside_paren++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2180 ret = g_string_append_c(ret, *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2181 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2182 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2183
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2184 if(inside_html) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2185 if(*c == '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2186 inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2187 } else if(!q && (*c == '\"' || *c == '\'')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2188 q = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2189 } else if(q) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2190 if(*c == *q)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2191 q = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2192 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2193 } else if(*c == '<') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2194 inside_html = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2195 if (!g_ascii_strncasecmp(c, "<A", 2)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2196 while (1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2197 if (!g_ascii_strncasecmp(c, "/A>", 3)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2198 inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2199 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2200 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2201 ret = g_string_append_c(ret, *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2202 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2203 if (!(*c))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2204 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2205 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2206 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2207 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2208 (!g_ascii_strncasecmp(c, "https://", 8)))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2209 t = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2210 while (1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2211 if (badchar(*t) || badentity(t)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2212
17191
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2213 if ((!g_ascii_strncasecmp(c, "http://", 7) && (t - c == 7)) ||
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2214 (!g_ascii_strncasecmp(c, "https://", 8) && (t - c == 8))) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2215 break;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2216 }
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2217
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2218 if (*(t) == ',' && (*(t + 1) != ' ')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2219 t++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2220 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2221 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2222
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2223 if (*(t - 1) == '.')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2224 t--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2225 if ((*(t - 1) == ')' && (inside_paren > 0))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2226 t--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2227 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2228
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2229 url_buf = g_strndup(c, t - c);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2230 tmpurlbuf = purple_unescape_html(url_buf);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2231 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2232 tmpurlbuf, url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2233 g_free(url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2234 g_free(tmpurlbuf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2235 c = t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2236 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2237 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2238 t++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2239
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2240 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2241 } else if (!g_ascii_strncasecmp(c, "www.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2242 if (c[4] != '.') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2243 t = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2244 while (1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2245 if (badchar(*t) || badentity(t)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2246 if (t - c == 4) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2247 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2248 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2249
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2250 if (*(t) == ',' && (*(t + 1) != ' ')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2251 t++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2252 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2253 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2254
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2255 if (*(t - 1) == '.')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2256 t--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2257 if ((*(t - 1) == ')' && (inside_paren > 0))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2258 t--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2259 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2260 url_buf = g_strndup(c, t - c);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2261 tmpurlbuf = purple_unescape_html(url_buf);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2262 g_string_append_printf(ret,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2263 "<A HREF=\"http://%s\">%s</A>", tmpurlbuf,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2264 url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2265 g_free(url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2266 g_free(tmpurlbuf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2267 c = t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2268 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2269 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2270 t++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2271 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2272 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2273 } else if (!g_ascii_strncasecmp(c, "ftp://", 6) || !g_ascii_strncasecmp(c, "sftp://", 7)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2274 t = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2275 while (1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2276 if (badchar(*t) || badentity(t)) {
17191
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2277
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2278 if ((!g_ascii_strncasecmp(c, "ftp://", 6) && (t - c == 6)) ||
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2279 (!g_ascii_strncasecmp(c, "sftp://", 7) && (t - c == 7))) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2280 break;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2281 }
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2282
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2283 if (*(t - 1) == '.')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2284 t--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2285 if ((*(t - 1) == ')' && (inside_paren > 0))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2286 t--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2287 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2288 url_buf = g_strndup(c, t - c);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2289 tmpurlbuf = purple_unescape_html(url_buf);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2290 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2291 tmpurlbuf, url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2292 g_free(url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2293 g_free(tmpurlbuf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2294 c = t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2295 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2296 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2297 if (!t)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2298 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2299 t++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2300
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2301 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2302 } else if (!g_ascii_strncasecmp(c, "ftp.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2303 if (c[4] != '.') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2304 t = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2305 while (1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2306 if (badchar(*t) || badentity(t)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2307 if (t - c == 4) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2308 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2309 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2310 if (*(t - 1) == '.')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2311 t--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2312 if ((*(t - 1) == ')' && (inside_paren > 0))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2313 t--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2314 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2315 url_buf = g_strndup(c, t - c);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2316 tmpurlbuf = purple_unescape_html(url_buf);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2317 g_string_append_printf(ret,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2318 "<A HREF=\"ftp://%s\">%s</A>", tmpurlbuf,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2319 url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2320 g_free(url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2321 g_free(tmpurlbuf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2322 c = t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2323 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2324 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2325 if (!t)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2326 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2327 t++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2328 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2329 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2330 } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2331 t = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2332 while (1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2333 if (badchar(*t) || badentity(t)) {
17191
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2334 char *d;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2335 if (t - c == 7) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2336 break;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2337 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2338 if (*(t - 1) == '.')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2339 t--;
17191
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2340 if ((d = strstr(c + 7, "?")) != NULL && d < t)
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2341 url_buf = g_strndup(c + 7, d - c - 7);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2342 else
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2343 url_buf = g_strndup(c + 7, t - c - 7);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2344 if (!purple_email_is_valid(url_buf)) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2345 g_free(url_buf);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2346 break;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2347 }
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2348 g_free(url_buf);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2349 url_buf = g_strndup(c, t - c);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2350 tmpurlbuf = purple_unescape_html(url_buf);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2351 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2352 tmpurlbuf, url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2353 g_free(url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2354 g_free(tmpurlbuf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2355 c = t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2356 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2357 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2358 if (!t)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2359 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2360 t++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2361
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2362 }
17191
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2363 } else if ((*c=='x') && (!g_ascii_strncasecmp(c, "xmpp:", 5)) &&
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2364 (c == text || badchar(c[-1]) || badentity(c-1))) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2365 t = c;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2366 while (1) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2367 if (badchar(*t) || badentity(t)) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2368
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2369 if (t - c == 5) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2370 break;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2371 }
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2372
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2373 if (*(t) == ',' && (*(t + 1) != ' ')) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2374 t++;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2375 continue;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2376 }
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2377
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2378 if (*(t - 1) == '.')
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2379 t--;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2380 if ((*(t - 1) == ')' && (inside_paren > 0))) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2381 t--;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2382 }
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2383
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2384 url_buf = g_strndup(c, t - c);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2385 tmpurlbuf = purple_unescape_html(url_buf);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2386 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2387 tmpurlbuf, url_buf);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2388 g_free(url_buf);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2389 g_free(tmpurlbuf);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2390 c = t;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2391 break;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2392 }
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2393 t++;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2394
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17046
diff changeset
2395 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2396 } else if (c != text && (*c == '@')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2397 int flag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2398 GString *gurl_buf = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2399 const char illegal_chars[] = "!@#$%^&*()[]{}/|\\<>\":;\r\n \0";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2400
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2401 if (strchr(illegal_chars,*(c - 1)) || strchr(illegal_chars, *(c + 1)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2402 flag = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2403 else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2404 flag = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2405 gurl_buf = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2406 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2407
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2408 t = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2409 while (flag) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2410 /* iterate backwards grabbing the local part of an email address */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2411 g = g_utf8_get_char(t);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2412 if (badchar(*t) || (g >= 127) || (*t == '(') ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2413 ((*t == ';') && ((t > (text+2) && (!g_ascii_strncasecmp(t - 3, "&lt;", 4) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2414 !g_ascii_strncasecmp(t - 3, "&gt;", 4))) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2415 (t > (text+4) && (!g_ascii_strncasecmp(t - 5, "&quot;", 6)))))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2416 /* local part will already be part of ret, strip it out */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2417 ret = g_string_truncate(ret, ret->len - (c - t));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2418 ret = g_string_append_unichar(ret, g);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2419 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2420 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2421 g_string_prepend_unichar(gurl_buf, g);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2422 t = g_utf8_find_prev_char(text, t);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2423 if (t < text) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2424 ret = g_string_assign(ret, "");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2425 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2426 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2427 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2428 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2429
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2430 t = g_utf8_find_next_char(c, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2431
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2432 while (flag) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2433 /* iterate forwards grabbing the domain part of an email address */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2434 g = g_utf8_get_char(t);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2435 if (badchar(*t) || (g >= 127) || (*t == ')') || badentity(t)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2436 char *d;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2437
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2438 url_buf = g_string_free(gurl_buf, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2439
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2440 /* strip off trailing periods */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2441 if (strlen(url_buf) > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2442 for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2443 *d = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2444 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2445
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2446 tmpurlbuf = purple_unescape_html(url_buf);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2447 if (purple_email_is_valid(tmpurlbuf)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2448 g_string_append_printf(ret, "<A HREF=\"mailto:%s\">%s</A>",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2449 tmpurlbuf, url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2450 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2451 g_string_append(ret, url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2452 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2453 g_free(url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2454 g_free(tmpurlbuf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2455 c = t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2456
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2457 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2458 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2459 g_string_append_unichar(gurl_buf, g);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2460 t = g_utf8_find_next_char(t, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2461 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2462 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2463 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2464
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2465 if(*c == ')' && !inside_html) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2466 inside_paren--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2467 ret = g_string_append_c(ret, *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2468 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2469 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2470
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2471 if (*c == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2472 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2473
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2474 ret = g_string_append_c(ret, *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2475 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2476
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2477 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2478 return g_string_free(ret, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2479 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2480
27350
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2481 char *purple_unescape_html(const char *html)
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2482 {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2483 GString *ret;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2484 const char *c = html;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2485
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2486 if (html == NULL)
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2487 return NULL;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2488
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2489 ret = g_string_new("");
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2490 while (*c) {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2491 int len;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2492 const char *ent;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2493
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2494 if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2495 g_string_append(ret, ent);
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2496 c += len;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2497 } else if (!strncmp(c, "<br>", 4)) {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2498 g_string_append_c(ret, '\n');
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2499 c += 4;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2500 } else {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2501 g_string_append_c(ret, *c);
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2502 c++;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2503 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2504 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2505
27350
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27328
diff changeset
2506 return g_string_free(ret, FALSE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2507 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2508
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2509 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2510 purple_markup_slice(const char *str, guint x, guint y)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2511 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2512 GString *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2513 GQueue *q;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2514 guint z = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2515 gboolean appended = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2516 gunichar c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2517 char *tag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2518
24363
3ef4625689e0 Fix CID #389
Richard Laager <rlaager@wiktel.com>
parents: 24216
diff changeset
2519 g_return_val_if_fail(str != NULL, NULL);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2520 g_return_val_if_fail(x <= y, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2521
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2522 if (x == y)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2523 return g_strdup("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2524
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2525 ret = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2526 q = g_queue_new();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2527
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2528 while (*str && (z < y)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2529 c = g_utf8_get_char(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2530
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2531 if (c == '<') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2532 char *end = strchr(str, '>');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2533
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2534 if (!end) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2535 g_string_free(ret, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2536 while ((tag = g_queue_pop_head(q)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2537 g_free(tag);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2538 g_queue_free(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2539 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2540 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2541
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2542 if (!g_ascii_strncasecmp(str, "<img ", 5)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2543 z += strlen("[Image]");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2544 } else if (!g_ascii_strncasecmp(str, "<br", 3)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2545 z += 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2546 } else if (!g_ascii_strncasecmp(str, "<hr>", 4)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2547 z += strlen("\n---\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2548 } else if (!g_ascii_strncasecmp(str, "</", 2)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2549 /* pop stack */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2550 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2551
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2552 tmp = g_queue_pop_head(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2553 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2554 /* z += 0; */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2555 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2556 /* push it unto the stack */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2557 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2558
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2559 tmp = g_strndup(str, end - str + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2560 g_queue_push_head(q, tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2561 /* z += 0; */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2562 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2563
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2564 if (z >= x) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2565 g_string_append_len(ret, str, end - str + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2566 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2567
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2568 str = end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2569 } else if (c == '&') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2570 char *end = strchr(str, ';');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2571 if (!end) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2572 g_string_free(ret, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2573 while ((tag = g_queue_pop_head(q)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2574 g_free(tag);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2575 g_queue_free(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2576
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2577 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2578 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2579
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2580 if (z >= x)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2581 g_string_append_len(ret, str, end - str + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2582
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2583 z++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2584 str = end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2585 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2586 if (z == x && z > 0 && !appended) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2587 GList *l = q->tail;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2588
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2589 while (l) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2590 tag = l->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2591 g_string_append(ret, tag);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2592 l = l->prev;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2593 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2594 appended = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2595 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2596
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2597 if (z >= x)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2598 g_string_append_unichar(ret, c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2599 z++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2600 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2601
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2602 str = g_utf8_next_char(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2603 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2604
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2605 while ((tag = g_queue_pop_head(q))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2606 char *name;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2607
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2608 name = purple_markup_get_tag_name(tag);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2609 g_string_append_printf(ret, "</%s>", name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2610 g_free(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2611 g_free(tag);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2612 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2613
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2614 g_queue_free(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2615 return g_string_free(ret, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2616 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2617
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2618 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2619 purple_markup_get_tag_name(const char *tag)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2620 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2621 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2622 g_return_val_if_fail(tag != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2623 g_return_val_if_fail(*tag == '<', NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2624
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2625 for (i = 1; tag[i]; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2626 if (tag[i] == '>' || tag[i] == ' ' || tag[i] == '/')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2627 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2628
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2629 return g_strndup(tag+1, i-1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2630 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2631
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2632 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2633 * Path/Filename Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2634 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2635 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2636 purple_home_dir(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2637 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2638 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2639 return g_get_home_dir();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2640 #else
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2641 return wpurple_data_dir();
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2642 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2643 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2644
16367
6a9ae99e7050 Use ~/.purple only, never ~/.gaim. This is a revert of the functional
Richard Laager <rlaager@wiktel.com>
parents: 16169
diff changeset
2645 /* Returns the argument passed to -c IFF it was present, or ~/.purple. */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2646 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2647 purple_user_dir(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2648 {
18147
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2649 if (custom_user_dir != NULL)
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2650 return custom_user_dir;
20091
2ab6b55ffa3d Rename the internal home_dir variable to user_dir to match the function and
Richard Laager <rlaager@wiktel.com>
parents: 20074
diff changeset
2651 else if (!user_dir)
2ab6b55ffa3d Rename the internal home_dir variable to user_dir to match the function and
Richard Laager <rlaager@wiktel.com>
parents: 20074
diff changeset
2652 user_dir = g_build_filename(purple_home_dir(), ".purple", NULL);
2ab6b55ffa3d Rename the internal home_dir variable to user_dir to match the function and
Richard Laager <rlaager@wiktel.com>
parents: 20074
diff changeset
2653
2ab6b55ffa3d Rename the internal home_dir variable to user_dir to match the function and
Richard Laager <rlaager@wiktel.com>
parents: 20074
diff changeset
2654 return user_dir;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2655 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2656
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2657 void purple_util_set_user_dir(const char *dir)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2658 {
18147
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2659 g_free(custom_user_dir);
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2660
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2661 if (dir != NULL && *dir)
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2662 custom_user_dir = g_strdup(dir);
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2663 else
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2664 custom_user_dir = NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2665 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2666
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2667 int purple_build_dir (const char *path, int mode)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2668 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2669 #if GLIB_CHECK_VERSION(2,8,0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2670 return g_mkdir_with_parents(path, mode);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2671 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2672 char *dir, **components, delim[] = { G_DIR_SEPARATOR, '\0' };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2673 int cur, len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2674
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2675 g_return_val_if_fail(path != NULL, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2676
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2677 dir = g_new0(char, strlen(path) + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2678 components = g_strsplit(path, delim, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2679 len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2680 for (cur = 0; components[cur] != NULL; cur++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2681 /* If you don't know what you're doing on both
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2682 * win32 and *NIX, stay the hell away from this code */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2683 if(cur > 1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2684 dir[len++] = G_DIR_SEPARATOR;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2685 strcpy(dir + len, components[cur]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2686 len += strlen(components[cur]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2687 if(cur == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2688 dir[len++] = G_DIR_SEPARATOR;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2689
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2690 if(g_file_test(dir, G_FILE_TEST_IS_DIR)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2691 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2692 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2693 /* allow us to create subdirs on UNC paths
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2694 * (\\machinename\path\to\blah)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2695 * g_file_test() doesn't work on "\\machinename" */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2696 } else if (cur == 2 && dir[0] == '\\' && dir[1] == '\\'
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2697 && components[cur + 1] != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2698 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2699 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2700 } else if(g_file_test(dir, G_FILE_TEST_EXISTS)) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2701 purple_debug_warning("build_dir", "bad path: %s\n", path);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2702 g_strfreev(components);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2703 g_free(dir);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2704 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2705 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2706
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2707 if (g_mkdir(dir, mode) < 0) {
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
2708 purple_debug_warning("build_dir", "mkdir: %s\n", g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2709 g_strfreev(components);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2710 g_free(dir);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2711 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2712 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2713 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2714
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2715 g_strfreev(components);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2716 g_free(dir);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2717 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2718 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2719 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2720
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2721 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2722 * This function is long and beautiful, like my--um, yeah. Anyway,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2723 * it includes lots of error checking so as we don't overwrite
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2724 * people's settings if there is a problem writing the new values.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2725 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2726 gboolean
19408
cc36a5aac908 Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19262
diff changeset
2727 purple_util_write_data_to_file(const char *filename, const char *data, gssize size)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2728 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2729 const char *user_dir = purple_user_dir();
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2730 gchar *filename_full;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2731 gboolean ret = FALSE;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2732
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2733 g_return_val_if_fail(user_dir != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2734
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2735 purple_debug_info("util", "Writing file %s to directory %s\n",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2736 filename, user_dir);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2737
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2738 /* Ensure the user directory exists */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2739 if (!g_file_test(user_dir, G_FILE_TEST_IS_DIR))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2740 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2741 if (g_mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR) == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2742 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2743 purple_debug_error("util", "Error creating directory %s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
2744 user_dir, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2745 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2746 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2747 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2748
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2749 filename_full = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", user_dir, filename);
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2750
20853
1a44d1a17784 purple_util_write_data_to_file_absolute() should take a signed argument for the size as -1 is used to indicate that the string is nul-delimited. This resolves CID 330.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20685
diff changeset
2751 ret = purple_util_write_data_to_file_absolute(filename_full, data, size);
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2752
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2753 g_free(filename_full);
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2754 return ret;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2755 }
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2756
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2757 gboolean
20853
1a44d1a17784 purple_util_write_data_to_file_absolute() should take a signed argument for the size as -1 is used to indicate that the string is nul-delimited. This resolves CID 330.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20685
diff changeset
2758 purple_util_write_data_to_file_absolute(const char *filename_full, const char *data, gssize size)
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2759 {
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2760 gchar *filename_temp;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2761 FILE *file;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2762 size_t real_size, byteswritten;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2763 struct stat st;
21172
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2764 #ifndef HAVE_FILENO
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2765 int fd;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2766 #endif
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2767
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2768 purple_debug_info("util", "Writing file %s\n",
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2769 filename_full);
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2770
20917
aa420b502a6b nosnilmot points out that this is a better way to ensure the size is valid.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20916
diff changeset
2771 g_return_val_if_fail((size >= -1), FALSE);
aa420b502a6b nosnilmot points out that this is a better way to ensure the size is valid.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20916
diff changeset
2772
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2773 filename_temp = g_strdup_printf("%s.save", filename_full);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2774
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2775 /* Remove an old temporary file, if one exists */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2776 if (g_file_test(filename_temp, G_FILE_TEST_EXISTS))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2777 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2778 if (g_unlink(filename_temp) == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2779 {
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2780 purple_debug_error("util", "Error removing old file "
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2781 "%s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
2782 filename_temp, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2783 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2784 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2785
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2786 /* Open file */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2787 file = g_fopen(filename_temp, "wb");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2788 if (file == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2789 {
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2790 purple_debug_error("util", "Error opening file %s for "
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2791 "writing: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
2792 filename_temp, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2793 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2794 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2795 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2796
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2797 /* Write to file */
20917
aa420b502a6b nosnilmot points out that this is a better way to ensure the size is valid.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20916
diff changeset
2798 real_size = (size == -1) ? strlen(data) : (size_t) size;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2799 byteswritten = fwrite(data, 1, real_size, file);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2800
21172
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2801 #ifdef HAVE_FILENO
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2802 /* Apparently XFS (and possibly other filesystems) do not
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2803 * guarantee that file data is flushed before file metadata,
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2804 * so this procedure is insufficient without some flushage. */
21177
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2805 if (fflush(file) < 0) {
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2806 purple_debug_error("util", "Error flushing %s: %s\n",
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2807 filename_temp, g_strerror(errno));
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2808 g_free(filename_temp);
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2809 fclose(file);
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2810 return FALSE;
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2811 }
21172
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2812 if (fsync(fileno(file)) < 0) {
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2813 purple_debug_error("util", "Error syncing file contents for %s: %s\n",
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2814 filename_temp, g_strerror(errno));
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2815 g_free(filename_temp);
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2816 fclose(file);
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2817 return FALSE;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2818 }
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2819 #endif
25415
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25385
diff changeset
2820
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2821 /* Close file */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2822 if (fclose(file) != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2823 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2824 purple_debug_error("util", "Error closing file %s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
2825 filename_temp, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2826 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2827 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2828 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2829
21172
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2830 #ifndef HAVE_FILENO
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2831 /* This is the same effect (we hope) as the HAVE_FILENO block
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2832 * above, but for systems without fileno(). */
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2833 if ((fd = open(filename_temp, O_RDWR)) < 0) {
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2834 purple_debug_error("util", "Error opening file %s for flush: %s\n",
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2835 filename_temp, g_strerror(errno));
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2836 g_free(filename_temp);
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2837 return FALSE;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2838 }
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2839 if (fsync(fd) < 0) {
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2840 purple_debug_error("util", "Error syncing %s: %s\n",
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2841 filename_temp, g_strerror(errno));
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2842 g_free(filename_temp);
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2843 close(fd);
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2844 return FALSE;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2845 }
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2846 if (close(fd) < 0) {
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2847 purple_debug_error("util", "Error closing %s after sync: %s\n",
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2848 filename_temp, g_strerror(errno));
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2849 g_free(filename_temp);
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2850 return FALSE;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2851 }
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2852 #endif
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2853
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2854 /* Ensure the file is the correct size */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2855 if (byteswritten != real_size)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2856 {
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2857 purple_debug_error("util", "Error writing to file %s: Wrote %"
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2858 G_GSIZE_FORMAT " bytes "
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2859 "but should have written %" G_GSIZE_FORMAT
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2860 "; is your disk full?\n",
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2861 filename_temp, byteswritten, real_size);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2862 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2863 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2864 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2865 /* Use stat to be absolutely sure. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2866 if ((g_stat(filename_temp, &st) == -1) || (st.st_size != real_size))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2867 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2868 purple_debug_error("util", "Error writing data to file %s: "
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2869 "Incomplete file written; is your disk "
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2870 "full?\n",
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2871 filename_temp);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2872 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2873 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2874 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2875
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2876 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2877 /* Set file permissions */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2878 if (chmod(filename_temp, S_IRUSR | S_IWUSR) == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2879 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2880 purple_debug_error("util", "Error setting permissions of file %s: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
2881 filename_temp, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2882 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2883 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2884
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2885 /* Rename to the REAL name */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2886 if (g_rename(filename_temp, filename_full) == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2887 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2888 purple_debug_error("util", "Error renaming %s to %s: %s\n",
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2889 filename_temp, filename_full,
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
2890 g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2891 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2892
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2893 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2894
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2895 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2896 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2897
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2898 xmlnode *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2899 purple_util_read_xml_from_file(const char *filename, const char *description)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2900 {
23462
774ef2a2e7f8 added a more generic function to read xml files (and made the util version into a wrapper) so it can be used by the
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents: 23144
diff changeset
2901 return xmlnode_from_file(purple_user_dir(), filename, description, "util");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2902 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2903
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2904 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2905 * Like mkstemp() but returns a file pointer, uses a pre-set template,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2906 * uses the semantics of tempnam() for the directory to use and allocates
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2907 * the space for the filepath.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2908 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2909 * Caller is responsible for closing the file and removing it when done,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2910 * as well as freeing the space pointed-to by "path" with g_free().
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2911 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2912 * Returns NULL on failure and cleans up after itself if so.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2913 */
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2914 static const char *purple_mkstemp_templ = {"purpleXXXXXX"};
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2915
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2916 FILE *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2917 purple_mkstemp(char **fpath, gboolean binary)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2918 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2919 const gchar *tmpdir;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2920 int fd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2921 FILE *fp = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2922
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2923 g_return_val_if_fail(fpath != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2924
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2925 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2926 if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, purple_mkstemp_templ)) != NULL) {
16869
ec79e3ad09a9 _mktmp() sucks, so use g_mkstemp() instead. This probably doesn't have to be done differently for win32 and elsewhere, but I don't want to be changing things right now.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16556
diff changeset
2927 fd = g_mkstemp(*fpath);
ec79e3ad09a9 _mktmp() sucks, so use g_mkstemp() instead. This probably doesn't have to be done differently for win32 and elsewhere, but I don't want to be changing things right now.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16556
diff changeset
2928 if(fd == -1) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2929 purple_debug(PURPLE_DEBUG_ERROR, "purple_mkstemp",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2930 "Couldn't make \"%s\", error: %d\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2931 *fpath, errno);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2932 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2933 if((fp = fdopen(fd, "r+")) == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2934 close(fd);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2935 purple_debug(PURPLE_DEBUG_ERROR, "purple_mkstemp",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2936 "Couldn't fdopen(), error: %d\n", errno);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2937 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2938 }
16869
ec79e3ad09a9 _mktmp() sucks, so use g_mkstemp() instead. This probably doesn't have to be done differently for win32 and elsewhere, but I don't want to be changing things right now.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16556
diff changeset
2939
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2940 if(!fp) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2941 g_free(*fpath);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2942 *fpath = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2943 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2944 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2945 } else {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
2946 purple_debug(PURPLE_DEBUG_ERROR, "purple_mkstemp",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2947 "g_get_tmp_dir() failed!\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2948 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2949
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2950 return fp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2951 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2952
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2953 const char *
16495
b8b2e35ec7c6 Fix purple_util_get_image_extension()'s data param. to be correctly marked as constant.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16483
diff changeset
2954 purple_util_get_image_extension(gconstpointer data, size_t len)
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2955 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2956 g_return_val_if_fail(data != NULL, NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2957 g_return_val_if_fail(len > 0, NULL);
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2958
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2959 if (len >= 4)
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2960 {
17729
0a4238600947 Fixed recognition of the extension of certain JPG files. The 4th character may be anything between e0 and ef; the first 3 should be sufficient for a magic number, though a more 'complete' solution would verify that (e0 <= data[3] <= ef). Also, added recognition of TIF files (magic number: MM or II). Refs #725, which gave examples of several JPGs with (data[3] == e1).
Evan Schoenberg <evan.s@dreskin.net>
parents: 17706
diff changeset
2961 if (!strncmp((char *)data, "GIF8", 4))
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2962 return "gif";
17729
0a4238600947 Fixed recognition of the extension of certain JPG files. The 4th character may be anything between e0 and ef; the first 3 should be sufficient for a magic number, though a more 'complete' solution would verify that (e0 <= data[3] <= ef). Also, added recognition of TIF files (magic number: MM or II). Refs #725, which gave examples of several JPGs with (data[3] == e1).
Evan Schoenberg <evan.s@dreskin.net>
parents: 17706
diff changeset
2963 else if (!strncmp((char *)data, "\xff\xd8\xff", 3)) /* 4th may be e0 through ef */
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2964 return "jpg";
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2965 else if (!strncmp((char *)data, "\x89PNG", 4))
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2966 return "png";
17729
0a4238600947 Fixed recognition of the extension of certain JPG files. The 4th character may be anything between e0 and ef; the first 3 should be sufficient for a magic number, though a more 'complete' solution would verify that (e0 <= data[3] <= ef). Also, added recognition of TIF files (magic number: MM or II). Refs #725, which gave examples of several JPGs with (data[3] == e1).
Evan Schoenberg <evan.s@dreskin.net>
parents: 17706
diff changeset
2967 else if (!strncmp((char *)data, "MM", 2) ||
0a4238600947 Fixed recognition of the extension of certain JPG files. The 4th character may be anything between e0 and ef; the first 3 should be sufficient for a magic number, though a more 'complete' solution would verify that (e0 <= data[3] <= ef). Also, added recognition of TIF files (magic number: MM or II). Refs #725, which gave examples of several JPGs with (data[3] == e1).
Evan Schoenberg <evan.s@dreskin.net>
parents: 17706
diff changeset
2968 !strncmp((char *)data, "II", 2))
0a4238600947 Fixed recognition of the extension of certain JPG files. The 4th character may be anything between e0 and ef; the first 3 should be sufficient for a magic number, though a more 'complete' solution would verify that (e0 <= data[3] <= ef). Also, added recognition of TIF files (magic number: MM or II). Refs #725, which gave examples of several JPGs with (data[3] == e1).
Evan Schoenberg <evan.s@dreskin.net>
parents: 17706
diff changeset
2969 return "tif";
17730
647bfc2b2a7b Where did ekse come from?
Richard Laager <rlaager@wiktel.com>
parents: 17729
diff changeset
2970 else if (!strncmp((char *)data, "BM", 2))
17729
0a4238600947 Fixed recognition of the extension of certain JPG files. The 4th character may be anything between e0 and ef; the first 3 should be sufficient for a magic number, though a more 'complete' solution would verify that (e0 <= data[3] <= ef). Also, added recognition of TIF files (magic number: MM or II). Refs #725, which gave examples of several JPGs with (data[3] == e1).
Evan Schoenberg <evan.s@dreskin.net>
parents: 17706
diff changeset
2971 return "bmp";
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2972 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2973
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2974 return "icon";
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2975 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2976
26263
00c659e55902 Add a note that this function could potentially be faster.
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2977 /*
27486
52298a298260 Update this comment. We talked about using CRC32 on the devel list
Mark Doliner <mark@kingant.net>
parents: 27475
diff changeset
2978 * We thought about using non-cryptographic hashes like CRC32 here.
52298a298260 Update this comment. We talked about using CRC32 on the devel list
Mark Doliner <mark@kingant.net>
parents: 27475
diff changeset
2979 * They would be faster, but we think using something more secure is
52298a298260 Update this comment. We talked about using CRC32 on the devel list
Mark Doliner <mark@kingant.net>
parents: 27475
diff changeset
2980 * important, so that it is more difficult for someone to maliciously
52298a298260 Update this comment. We talked about using CRC32 on the devel list
Mark Doliner <mark@kingant.net>
parents: 27475
diff changeset
2981 * replace one buddy's icon with something else.
26263
00c659e55902 Add a note that this function could potentially be faster.
Mark Doliner <mark@kingant.net>
parents: 25415
diff changeset
2982 */
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2983 char *
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
2984 purple_util_get_image_checksum(gconstpointer image_data, size_t image_len)
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2985 {
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2986 PurpleCipherContext *context;
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2987 gchar digest[41];
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2988
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2989 context = purple_cipher_context_new_by_name("sha1", NULL);
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2990 if (context == NULL)
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2991 {
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2992 purple_debug_error("util", "Could not find sha1 cipher\n");
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2993 g_return_val_if_reached(NULL);
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2994 }
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2995
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2996 /* Hash the image data */
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2997 purple_cipher_context_append(context, image_data, image_len);
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2998 if (!purple_cipher_context_digest_to_str(context, sizeof(digest), digest, NULL))
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
2999 {
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3000 purple_debug_error("util", "Failed to get SHA-1 digest.\n");
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3001 g_return_val_if_reached(NULL);
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3002 }
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3003 purple_cipher_context_destroy(context);
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3004
22874
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
3005 return g_strdup(digest);
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
3006 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
3007
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
3008 char *
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
3009 purple_util_get_image_filename(gconstpointer image_data, size_t image_len)
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
3010 {
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3011 /* Return the filename */
22875
f1475ca224a8 Plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
3012 char *checksum = purple_util_get_image_checksum(image_data, image_len);
f1475ca224a8 Plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
3013 char *filename = g_strdup_printf("%s.%s", checksum,
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3014 purple_util_get_image_extension(image_data, image_len));
22875
f1475ca224a8 Plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
3015 g_free(checksum);
f1475ca224a8 Plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22874
diff changeset
3016 return filename;
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3017 }
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17412
diff changeset
3018
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3019 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3020 purple_program_is_valid(const char *program)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3021 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3022 GError *error = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3023 char **argv;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3024 gchar *progname;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3025 gboolean is_valid = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3026
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3027 g_return_val_if_fail(program != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3028 g_return_val_if_fail(*program != '\0', FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3029
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3030 if (!g_shell_parse_argv(program, NULL, &argv, &error)) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3031 purple_debug(PURPLE_DEBUG_ERROR, "program_is_valid",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3032 "Could not parse program '%s': %s\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3033 program, error->message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3034 g_error_free(error);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3035 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3036 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3037
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3038 if (argv == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3039 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3040 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3041
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3042 progname = g_find_program_in_path(argv[0]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3043 is_valid = (progname != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3044
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3045 g_strfreev(argv);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3046 g_free(progname);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3047
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3048 return is_valid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3049 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3050
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3051
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3052 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3053 purple_running_gnome(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3054 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3055 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3056 gchar *tmp = g_find_program_in_path("gnome-open");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3057
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3058 if (tmp == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3059 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3060 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3061
21580
07588cb48434 Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <stu@nosnilmot.com>
parents: 21299
diff changeset
3062 tmp = (gchar *)g_getenv("GNOME_DESKTOP_SESSION_ID");
07588cb48434 Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <stu@nosnilmot.com>
parents: 21299
diff changeset
3063
07588cb48434 Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <stu@nosnilmot.com>
parents: 21299
diff changeset
3064 return ((tmp != NULL) && (*tmp != '\0'));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3065 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3066 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3067 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3068 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3069
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3070 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3071 purple_running_kde(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3072 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3073 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3074 gchar *tmp = g_find_program_in_path("kfmclient");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3075 const char *session;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3076
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3077 if (tmp == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3078 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3079 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3080
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3081 session = g_getenv("KDE_FULL_SESSION");
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3082 if (purple_strequal(session, "true"))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3083 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3084
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3085 /* If you run Purple from Konsole under !KDE, this will provide a
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3086 * a false positive. Since we do the GNOME checks first, this is
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3087 * only a problem if you're running something !(KDE || GNOME) and
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3088 * you run Purple from Konsole. This really shouldn't be a problem. */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3089 return ((g_getenv("KDEDIR") != NULL) || g_getenv("KDEDIRS") != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3090 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3091 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3092 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3093 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3094
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3095 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3096 purple_running_osx(void)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3097 {
16495
b8b2e35ec7c6 Fix purple_util_get_image_extension()'s data param. to be correctly marked as constant.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16483
diff changeset
3098 #if defined(__APPLE__)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3099 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3100 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3101 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3102 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3103 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3104
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3105 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3106 purple_fd_get_ip(int fd)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3107 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3108 struct sockaddr addr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3109 socklen_t namelen = sizeof(addr);
27524
60d128c6413a No functional change, but my gcc is bitching at me. Fixes this warning,
Stu Tomlinson <stu@nosnilmot.com>
parents: 27521
diff changeset
3110 struct in_addr in;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3111
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3112 g_return_val_if_fail(fd != 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3113
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3114 if (getsockname(fd, &addr, &namelen))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3115 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3116
27524
60d128c6413a No functional change, but my gcc is bitching at me. Fixes this warning,
Stu Tomlinson <stu@nosnilmot.com>
parents: 27521
diff changeset
3117 in = ((struct sockaddr_in *)&addr)->sin_addr;
60d128c6413a No functional change, but my gcc is bitching at me. Fixes this warning,
Stu Tomlinson <stu@nosnilmot.com>
parents: 27521
diff changeset
3118 return g_strdup(inet_ntoa(in));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3119 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3120
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3121
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3122 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3123 * String Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3124 **************************************************************************/
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3125 gboolean
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3126 purple_strequal(const gchar *left, const gchar *right)
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3127 {
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3128 #if GLIB_CHECK_VERSION(2,16,0)
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3129 return (g_strcmp0(left, right) == 0);
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3130 #else
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3131 return ((left == NULL && right == NULL) ||
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3132 (left != NULL && right != NULL && strcmp(left, right) == 0));
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3133 #endif
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3134 }
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3135
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3136 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3137 purple_normalize(const PurpleAccount *account, const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3138 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3139 const char *ret = NULL;
16556
0cd684e34403 sadrul fixed the next but not last crash
Luke Schierer <lschiere@pidgin.im>
parents: 16495
diff changeset
3140 static char buf[BUF_LEN];
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3141
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3142 if (account != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3143 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3144 PurplePlugin *prpl = purple_find_prpl(purple_account_get_protocol_id(account));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3145
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3146 if (prpl != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3147 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3148 PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3149
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3150 if(prpl_info && prpl_info->normalize)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3151 ret = prpl_info->normalize(account, str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3152 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3153 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3154
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3155 if (ret == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3156 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3157 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3158
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3159 tmp = g_utf8_normalize(str, -1, G_NORMALIZE_DEFAULT);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3160 g_snprintf(buf, sizeof(buf), "%s", tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3161 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3162
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3163 ret = buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3164 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3165
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3166 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3167 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3168
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3169 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3170 * You probably don't want to call this directly, it is
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3171 * mainly for use as a PRPL callback function. See the
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3172 * comments in util.h.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3173 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3174 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3175 purple_normalize_nocase(const PurpleAccount *account, const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3176 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3177 static char buf[BUF_LEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3178 char *tmp1, *tmp2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3179
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3180 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3181
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3182 tmp1 = g_utf8_strdown(str, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3183 tmp2 = g_utf8_normalize(tmp1, -1, G_NORMALIZE_DEFAULT);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3184 g_snprintf(buf, sizeof(buf), "%s", tmp2 ? tmp2 : "");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3185 g_free(tmp2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3186 g_free(tmp1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3187
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3188 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3189 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3190
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3191 gchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3192 purple_strdup_withhtml(const gchar *src)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3193 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3194 gulong destsize, i, j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3195 gchar *dest;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3196
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3197 g_return_val_if_fail(src != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3198
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3199 /* New length is (length of src) + (number of \n's * 3) - (number of \r's) + 1 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3200 destsize = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3201 for (i = 0; src[i] != '\0'; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3202 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3203 if (src[i] == '\n')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3204 destsize += 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3205 else if (src[i] != '\r')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3206 destsize++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3207 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3208
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3209 dest = g_malloc(destsize);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3210
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3211 /* Copy stuff, ignoring \r's, because they are dumb */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3212 for (i = 0, j = 0; src[i] != '\0'; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3213 if (src[i] == '\n') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3214 strcpy(&dest[j], "<BR>");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3215 j += 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3216 } else if (src[i] != '\r')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3217 dest[j++] = src[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3218 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3219
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3220 dest[destsize-1] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3221
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3222 return dest;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3223 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3224
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3225 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3226 purple_str_has_prefix(const char *s, const char *p)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3227 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3228 #if GLIB_CHECK_VERSION(2,2,0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3229 return g_str_has_prefix(s, p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3230 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3231 g_return_val_if_fail(s != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3232 g_return_val_if_fail(p != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3233
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3234 return (!strncmp(s, p, strlen(p)));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3235 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3236 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3237
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3238 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3239 purple_str_has_suffix(const char *s, const char *x)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3240 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3241 #if GLIB_CHECK_VERSION(2,2,0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3242 return g_str_has_suffix(s, x);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3243 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3244 int off;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3245
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3246 g_return_val_if_fail(s != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3247 g_return_val_if_fail(x != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3248
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3249 off = strlen(s) - strlen(x);
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
3250 return (off >= 0 && purple_strequal(s + off, x));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3251 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3252 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3253
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3254 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3255 purple_str_add_cr(const char *text)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3256 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3257 char *ret = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3258 int count = 0, j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3259 guint i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3260
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3261 g_return_val_if_fail(text != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3262
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3263 if (text[0] == '\n')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3264 count++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3265 for (i = 1; i < strlen(text); i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3266 if (text[i] == '\n' && text[i - 1] != '\r')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3267 count++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3268
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3269 if (count == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3270 return g_strdup(text);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3271
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3272 ret = g_malloc0(strlen(text) + count + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3273
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3274 i = 0; j = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3275 if (text[i] == '\n')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3276 ret[j++] = '\r';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3277 ret[j++] = text[i++];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3278 for (; i < strlen(text); i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3279 if (text[i] == '\n' && text[i - 1] != '\r')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3280 ret[j++] = '\r';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3281 ret[j++] = text[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3282 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3283
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3284 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3285 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3286
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3287 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3288 purple_str_strip_char(char *text, char thechar)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3289 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3290 int i, j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3291
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3292 g_return_if_fail(text != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3293
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3294 for (i = 0, j = 0; text[i]; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3295 if (text[i] != thechar)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3296 text[j++] = text[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3297
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3298 text[j++] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3299 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3300
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3301 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3302 purple_util_chrreplace(char *string, char delimiter,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3303 char replacement)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3304 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3305 int i = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3306
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3307 g_return_if_fail(string != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3308
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3309 while (string[i] != '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3310 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3311 if (string[i] == delimiter)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3312 string[i] = replacement;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3313 i++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3314 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3315 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3316
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3317 gchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3318 purple_strreplace(const char *string, const char *delimiter,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3319 const char *replacement)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3320 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3321 gchar **split;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3322 gchar *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3323
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3324 g_return_val_if_fail(string != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3325 g_return_val_if_fail(delimiter != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3326 g_return_val_if_fail(replacement != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3327
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3328 split = g_strsplit(string, delimiter, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3329 ret = g_strjoinv(replacement, split);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3330 g_strfreev(split);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3331
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3332 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3333 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3334
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3335 gchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3336 purple_strcasereplace(const char *string, const char *delimiter,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3337 const char *replacement)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3338 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3339 gchar *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3340 int length_del, length_rep, i, j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3341
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3342 g_return_val_if_fail(string != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3343 g_return_val_if_fail(delimiter != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3344 g_return_val_if_fail(replacement != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3345
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3346 length_del = strlen(delimiter);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3347 length_rep = strlen(replacement);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3348
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3349 /* Count how many times the delimiter appears */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3350 i = 0; /* position in the source string */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3351 j = 0; /* number of occurrences of "delimiter" */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3352 while (string[i] != '\0') {
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
3353 if (!g_ascii_strncasecmp(&string[i], delimiter, length_del)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3354 i += length_del;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3355 j += length_rep;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3356 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3357 i++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3358 j++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3359 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3360 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3361
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3362 ret = g_malloc(j+1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3363
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3364 i = 0; /* position in the source string */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3365 j = 0; /* position in the destination string */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3366 while (string[i] != '\0') {
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
3367 if (!g_ascii_strncasecmp(&string[i], delimiter, length_del)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3368 strncpy(&ret[j], replacement, length_rep);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3369 i += length_del;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3370 j += length_rep;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3371 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3372 ret[j] = string[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3373 i++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3374 j++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3375 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3376 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3377
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3378 ret[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3379
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3380 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3381 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3382
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3383 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3384 purple_strcasestr(const char *haystack, const char *needle)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3385 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3386 size_t hlen, nlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3387 const char *tmp, *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3388
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3389 g_return_val_if_fail(haystack != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3390 g_return_val_if_fail(needle != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3391
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3392 hlen = strlen(haystack);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3393 nlen = strlen(needle);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3394 tmp = haystack,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3395 ret = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3396
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3397 g_return_val_if_fail(hlen > 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3398 g_return_val_if_fail(nlen > 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3399
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3400 while (*tmp && !ret) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3401 if (!g_ascii_strncasecmp(needle, tmp, nlen))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3402 ret = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3403 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3404 tmp++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3405 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3406
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3407 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3408 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3409
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3410 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3411 purple_str_size_to_units(size_t size)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3412 {
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 21000
diff changeset
3413 static const char * const size_str[] = { "bytes", "KiB", "MiB", "GiB" };
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3414 float size_mag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3415 int size_index = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3416
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3417 if (size == -1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3418 return g_strdup(_("Calculating..."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3419 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3420 else if (size == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3421 return g_strdup(_("Unknown."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3422 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3423 else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3424 size_mag = (float)size;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3425
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3426 while ((size_index < 3) && (size_mag > 1024)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3427 size_mag /= 1024;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3428 size_index++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3429 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3430
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3431 if (size_index == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3432 return g_strdup_printf("%" G_GSIZE_FORMAT " %s", size, size_str[size_index]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3433 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3434 return g_strdup_printf("%.2f %s", size_mag, size_str[size_index]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3435 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3436 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3437 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3438
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3439 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3440 purple_str_seconds_to_string(guint secs)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3441 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3442 char *ret = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3443 guint days, hrs, mins;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3444
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3445 if (secs < 60)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3446 {
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3447 return g_strdup_printf(dngettext(PACKAGE, "%d second", "%d seconds", secs), secs);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3448 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3449
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3450 days = secs / (60 * 60 * 24);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3451 secs = secs % (60 * 60 * 24);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3452 hrs = secs / (60 * 60);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3453 secs = secs % (60 * 60);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3454 mins = secs / 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3455 secs = secs % 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3456
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3457 if (days > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3458 {
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3459 ret = g_strdup_printf(dngettext(PACKAGE, "%d day", "%d days", days), days);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3460 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3461
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3462 if (hrs > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3463 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3464 if (ret != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3465 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3466 char *tmp = g_strdup_printf(
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3467 dngettext(PACKAGE, "%s, %d hour", "%s, %d hours", hrs),
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3468 ret, hrs);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3469 g_free(ret);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3470 ret = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3471 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3472 else
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3473 ret = g_strdup_printf(dngettext(PACKAGE, "%d hour", "%d hours", hrs), hrs);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3474 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3475
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3476 if (mins > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3477 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3478 if (ret != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3479 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3480 char *tmp = g_strdup_printf(
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3481 dngettext(PACKAGE, "%s, %d minute", "%s, %d minutes", mins),
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3482 ret, mins);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3483 g_free(ret);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3484 ret = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3485 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3486 else
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3487 ret = g_strdup_printf(dngettext(PACKAGE, "%d minute", "%d minutes", mins), mins);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3488 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3489
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3490 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3491 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3492
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3493
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3494 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3495 purple_str_binary_to_ascii(const unsigned char *binary, guint len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3496 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3497 GString *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3498 guint i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3499
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3500 g_return_val_if_fail(len > 0, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3501
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3502 ret = g_string_sized_new(len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3503
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3504 for (i = 0; i < len; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3505 if (binary[i] < 32 || binary[i] > 126)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3506 g_string_append_printf(ret, "\\x%02hhx", binary[i]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3507 else if (binary[i] == '\\')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3508 g_string_append(ret, "\\\\");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3509 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3510 g_string_append_c(ret, binary[i]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3511
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3512 return g_string_free(ret, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3513 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3514
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3515 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3516 * URI/URL Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3517 **************************************************************************/
15613
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3518
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3519 void purple_got_protocol_handler_uri(const char *uri)
15613
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3520 {
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3521 char proto[11];
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3522 const char *tmp, *param_string;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3523 char *cmd;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3524 GHashTable *params = NULL;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3525 int len;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3526 if (!(tmp = strchr(uri, ':')) || tmp == uri) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3527 purple_debug_error("util", "Malformed protocol handler message - missing protocol.\n");
15613
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3528 return;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3529 }
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3530
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3531 len = MIN(sizeof(proto) - 1, (tmp - uri));
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3532
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3533 strncpy(proto, uri, len);
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3534 proto[len] = '\0';
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3535
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3536 tmp++;
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3537 purple_debug_info("util", "Processing message '%s' for protocol '%s'.\n", tmp, proto);
15613
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3538
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3539 if ((param_string = strchr(tmp, '?'))) {
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3540 const char *keyend = NULL, *pairstart;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3541 char *key, *value = NULL;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3542
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3543 cmd = g_strndup(tmp, (param_string - tmp));
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3544 param_string++;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3545
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3546 params = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3547 pairstart = tmp = param_string;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3548
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3549 while (*tmp || *pairstart) {
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3550 if (*tmp == '&' || !(*tmp)) {
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3551 /* If there is no explicit value */
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3552 if (keyend == NULL)
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3553 keyend = tmp;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3554
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3555 if (keyend && keyend != pairstart) {
17048
cc9242ce1435 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@gmail.com>
parents: 17046
diff changeset
3556 char *p;
15613
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3557 key = g_strndup(pairstart, (keyend - pairstart));
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3558 /* If there is an explicit value */
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3559 if (keyend != tmp && keyend != (tmp - 1))
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3560 value = g_strndup(keyend + 1, (tmp - keyend - 1));
17048
cc9242ce1435 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@gmail.com>
parents: 17046
diff changeset
3561 for (p = key; *p; ++p)
cc9242ce1435 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@gmail.com>
parents: 17046
diff changeset
3562 *p = g_ascii_tolower(*p);
15613
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3563 g_hash_table_insert(params, key, value);
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3564 }
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3565 keyend = value = NULL;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3566 pairstart = (*tmp) ? tmp + 1 : tmp;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3567 } else if (*tmp == '=')
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3568 keyend = tmp;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3569
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3570 if (*tmp)
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3571 tmp++;
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3572 }
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3573 } else
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3574 cmd = g_strdup(tmp);
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3575
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3576 purple_signal_emit_return_1(purple_get_core(), "uri-handler", proto, cmd, params);
15613
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3577
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3578 g_free(cmd);
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3579 if (params)
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3580 g_hash_table_destroy(params);
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3581 }
b0471b2a1de9 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 <daniel.atallah@gmail.com>
parents: 15421
diff changeset
3582
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3583 /*
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3584 * TODO: Should probably add a "gboolean *ret_ishttps" parameter that
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3585 * is set to TRUE if this URL is https, otherwise it is set to
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3586 * FALSE. But that change will break the API.
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3587 *
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3588 * This is important for Yahoo! web messenger login. They now
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3589 * force https login, and if you access the web messenger login
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3590 * page via http then it redirects you to the https version, but
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3591 * purple_util_fetch_url() ignores the "https" and attempts to
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3592 * fetch the URL via http again, which gets redirected again.
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3593 */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3594 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3595 purple_url_parse(const char *url, char **ret_host, int *ret_port,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3596 char **ret_path, char **ret_user, char **ret_passwd)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3597 {
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3598 gboolean is_https = FALSE;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3599 char scan_info[255];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3600 char port_str[6];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3601 int f;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3602 const char *at, *slash;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3603 const char *turl;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3604 char host[256], path[256], user[256], passwd[256];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3605 int port = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3606 /* hyphen at end includes it in control set */
21015
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 21000
diff changeset
3607 static const char addr_ctrl[] = "A-Za-z0-9.-";
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 21000
diff changeset
3608 static const char port_ctrl[] = "0-9";
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 21000
diff changeset
3609 static const char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-";
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 21000
diff changeset
3610 static const char user_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
787b3897ba9f Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents: 21000
diff changeset
3611 static const char passwd_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-";
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3612
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3613 g_return_val_if_fail(url != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3614
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3615 if ((turl = purple_strcasestr(url, "http://")) != NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3616 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3617 turl += 7;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3618 url = turl;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3619 }
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3620 else if ((turl = purple_strcasestr(url, "https://")) != NULL)
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3621 {
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3622 is_https = TRUE;
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3623 turl += 8;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3624 url = turl;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3625 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3626
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3627 /* parse out authentication information if supplied */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3628 /* Only care about @ char BEFORE the first / */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3629 at = strchr(url, '@');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3630 slash = strchr(url, '/');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3631 if ((at != NULL) &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3632 (((slash != NULL) && (strlen(at) > strlen(slash))) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3633 (slash == NULL))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3634 g_snprintf(scan_info, sizeof(scan_info),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3635 "%%255[%s]:%%255[%s]^@", user_ctrl, passwd_ctrl);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3636 f = sscanf(url, scan_info, user, passwd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3637
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3638 if (f ==1 ) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3639 /* No passwd, possibly just username supplied */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3640 g_snprintf(scan_info, sizeof(scan_info),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3641 "%%255[%s]^@", user_ctrl);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3642 f = sscanf(url, scan_info, user);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3643 *passwd = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3644 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3645
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3646 url = at+1; /* move pointer after the @ char */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3647 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3648 *user = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3649 *passwd = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3650 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3651
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3652 g_snprintf(scan_info, sizeof(scan_info),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3653 "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, page_ctrl);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3654
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3655 f = sscanf(url, scan_info, host, port_str, path);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3656
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3657 if (f == 1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3658 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3659 g_snprintf(scan_info, sizeof(scan_info),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3660 "%%255[%s]/%%255[%s]",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3661 addr_ctrl, page_ctrl);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3662 f = sscanf(url, scan_info, host, path);
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3663 /* Use the default port */
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3664 if (is_https)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3665 g_snprintf(port_str, sizeof(port_str), "443");
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3666 else
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3667 g_snprintf(port_str, sizeof(port_str), "80");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3668 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3669
23912
7fbc99a1481d purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents: 23905
diff changeset
3670 if (f == 0)
7fbc99a1481d purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents: 23905
diff changeset
3671 *host = '\0';
7fbc99a1481d purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents: 23905
diff changeset
3672
7fbc99a1481d purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents: 23905
diff changeset
3673 if (f <= 1)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3674 *path = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3675
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3676 sscanf(port_str, "%d", &port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3677
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3678 if (ret_host != NULL) *ret_host = g_strdup(host);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3679 if (ret_port != NULL) *ret_port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3680 if (ret_path != NULL) *ret_path = g_strdup(path);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3681 if (ret_user != NULL) *ret_user = g_strdup(user);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3682 if (ret_passwd != NULL) *ret_passwd = g_strdup(passwd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3683
23913
58e3b422e595 Return FALSE from purple_url_parse() if a host could not be determined
Evan Schoenberg <evan.s@dreskin.net>
parents: 23912
diff changeset
3684 return ((*host != '\0') ? TRUE : FALSE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3685 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3686
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3687 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3688 * The arguments to this function are similar to printf.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3689 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3690 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3691 purple_util_fetch_url_error(PurpleUtilFetchUrlData *gfud, const char *format, ...)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3692 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3693 gchar *error_message;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3694 va_list args;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3695
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3696 va_start(args, format);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3697 error_message = g_strdup_vprintf(format, args);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3698 va_end(args);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3699
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3700 gfud->callback(gfud, gfud->user_data, NULL, 0, error_message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3701 g_free(error_message);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3702 purple_util_fetch_url_cancel(gfud);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3703 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3704
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3705 static void url_fetch_connect_cb(gpointer url_data, gint source, const gchar *error_message);
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3706 static void ssl_url_fetch_connect_cb(gpointer data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3707 static void ssl_url_fetch_error_cb(PurpleSslConnection *ssl_connection, PurpleSslErrorType error, gpointer data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3708
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3709 static gboolean
23390
276925996951 Remove a unused variable
Mark Doliner <mark@kingant.net>
parents: 23367
diff changeset
3710 parse_redirect(const char *data, size_t data_len,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3711 PurpleUtilFetchUrlData *gfud)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3712 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3713 gchar *s;
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3714 gchar *new_url, *temp_url, *end;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3715 gboolean full;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3716 int len;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3717
20961
4a8366502f01 When checking for redirects in purple_util_fetch_url(), look for
Mark Doliner <mark@kingant.net>
parents: 20917
diff changeset
3718 if ((s = g_strstr_len(data, data_len, "\nLocation: ")) == NULL)
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3719 /* We're not being redirected */
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3720 return FALSE;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3721
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3722 s += strlen("Location: ");
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3723 end = strchr(s, '\r');
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3724
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3725 /* Just in case :) */
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3726 if (end == NULL)
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3727 end = strchr(s, '\n');
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3728
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3729 if (end == NULL)
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3730 return FALSE;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3731
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3732 len = end - s;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3733
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3734 new_url = g_malloc(len + 1);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3735 strncpy(new_url, s, len);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3736 new_url[len] = '\0';
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3737
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3738 full = gfud->full;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3739
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3740 if (*new_url == '/' || g_strstr_len(new_url, len, "://") == NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3741 {
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3742 temp_url = new_url;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3743
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3744 new_url = g_strdup_printf("%s:%d%s", gfud->website.address,
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3745 gfud->website.port, temp_url);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3746
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3747 g_free(temp_url);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3748
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3749 full = FALSE;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3750 }
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3751
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3752 purple_debug_info("util", "Redirecting to %s\n", new_url);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3753
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3754 gfud->num_times_redirected++;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3755 if (gfud->num_times_redirected >= 5)
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3756 {
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3757 purple_util_fetch_url_error(gfud,
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3758 _("Could not open %s: Redirected too many times"),
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3759 gfud->url);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3760 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3761 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3762
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3763 /*
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3764 * Try again, with this new location. This code is somewhat
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3765 * ugly, but we need to reuse the gfud because whoever called
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3766 * us is holding a reference to it.
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3767 */
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3768 g_free(gfud->url);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3769 gfud->url = new_url;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3770 gfud->full = full;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3771 g_free(gfud->request);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3772 gfud->request = NULL;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3773
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3774 if (gfud->is_ssl) {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3775 gfud->is_ssl = FALSE;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3776 purple_ssl_close(gfud->ssl_connection);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3777 gfud->ssl_connection = NULL;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3778 } else {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3779 purple_input_remove(gfud->inpa);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3780 gfud->inpa = 0;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3781 close(gfud->fd);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3782 gfud->fd = -1;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3783 }
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3784 gfud->request_written = 0;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3785 gfud->len = 0;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3786 gfud->data_len = 0;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3787
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3788 g_free(gfud->website.user);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3789 g_free(gfud->website.passwd);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3790 g_free(gfud->website.address);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3791 g_free(gfud->website.page);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3792 purple_url_parse(new_url, &gfud->website.address, &gfud->website.port,
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3793 &gfud->website.page, &gfud->website.user, &gfud->website.passwd);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3794
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3795 if (purple_strcasestr(new_url, "https://") != NULL) {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3796 gfud->is_ssl = TRUE;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3797 gfud->ssl_connection = purple_ssl_connect(NULL,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3798 gfud->website.address, gfud->website.port,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3799 ssl_url_fetch_connect_cb, ssl_url_fetch_error_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3800 } else {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3801 gfud->connect_data = purple_proxy_connect(NULL, NULL,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3802 gfud->website.address, gfud->website.port,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3803 url_fetch_connect_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3804 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3805
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3806 if (gfud->ssl_connection == NULL && gfud->connect_data == NULL)
17673
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3807 {
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3808 purple_util_fetch_url_error(gfud, _("Unable to connect to %s"),
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3809 gfud->website.address);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3810 }
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3811
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17244
diff changeset
3812 return TRUE;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3813 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3814
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3815 static const char *
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3816 find_header_content(const char *data, size_t data_len, const char *header, size_t header_len)
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3817 {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3818 const char *p = NULL;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3819
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3820 if (header_len <= 0)
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3821 header_len = strlen(header);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3822
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3823 /* Note: data is _not_ nul-terminated. */
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3824 if (data_len > header_len) {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3825 if (header[0] == '\n')
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3826 p = (g_strncasecmp(data, header + 1, header_len - 1) == 0) ? data : NULL;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3827 if (!p)
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3828 p = purple_strcasestr(data, header);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3829 if (p)
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3830 p += header_len;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3831 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3832
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3833 /* If we can find the header at all, try to sscanf it.
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3834 * Response headers should end with at least \r\n, so sscanf is safe,
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3835 * if we make sure that there is indeed a \n in our header.
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3836 */
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3837 if (p && g_strstr_len(p, data_len - (p - data), "\n")) {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3838 return p;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3839 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3840
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3841 return NULL;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3842 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3843
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3844 static size_t
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3845 parse_content_len(const char *data, size_t data_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3846 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3847 size_t content_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3848 const char *p = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3849
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3850 p = find_header_content(data, data_len, "\nContent-Length: ", sizeof("\nContent-Length: ") - 1);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3851 if (p) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3852 sscanf(p, "%" G_GSIZE_FORMAT, &content_len);
22475
3225c99785b8 Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <mark@kingant.net>
parents: 22344
diff changeset
3853 purple_debug_misc("util", "parsed %" G_GSIZE_FORMAT "\n", content_len);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3854 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3855
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3856 return content_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3857 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3858
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3859 static gboolean
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3860 content_is_chunked(const char *data, size_t data_len)
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3861 {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3862 const char *p = find_header_content(data, data_len, "\nTransfer-Encoding: ", sizeof("\nTransfer-Encoding: ") - 1);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3863 if (p && g_strncasecmp(p, "chunked", 7) == 0)
27327
a051f77d86a8 Remove just a tad bit of indirection
Mark Doliner <mark@kingant.net>
parents: 27326
diff changeset
3864 return TRUE;
a051f77d86a8 Remove just a tad bit of indirection
Mark Doliner <mark@kingant.net>
parents: 27326
diff changeset
3865
a051f77d86a8 Remove just a tad bit of indirection
Mark Doliner <mark@kingant.net>
parents: 27326
diff changeset
3866 return FALSE;
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3867 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3868
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3869 /* Process in-place */
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3870 static void
27326
7a4f56967512 Use unsigned lengths here and use %zu when reading into the gsize var
Mark Doliner <mark@kingant.net>
parents: 27305
diff changeset
3871 process_chunked_data(char *data, gsize *len)
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3872 {
27326
7a4f56967512 Use unsigned lengths here and use %zu when reading into the gsize var
Mark Doliner <mark@kingant.net>
parents: 27305
diff changeset
3873 gsize sz;
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3874 gsize newlen = 0;
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3875 char *p = data;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3876 char *s = data;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3877
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3878 while (*s) {
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3879 /* Read the size of this chunk */
27458
70e64287f790 Hey Stu, it should be safe to combine this check, right? It'll make us
Mark Doliner <mark@kingant.net>
parents: 27380
diff changeset
3880 if (sscanf(s, "%" G_GSIZE_MODIFIER "x", &sz) != 1)
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3881 {
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3882 purple_debug_error("util", "Error processing chunked data: "
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3883 "Expected data length, found: %s\n", s);
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3884 break;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3885 }
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3886 if (sz == 0) {
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3887 /* We've reached the last chunk */
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3888 /*
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3889 * TODO: The spec allows "footers" to follow the last chunk.
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3890 * If there is more data after this line then we should
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3891 * treat it like a header.
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3892 */
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3893 break;
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3894 }
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3895
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3896 /* Advance to the start of the data */
27363
e8ac5369d567 Apparently there might be stuff after the semicolon before the \r\n so just
Stu Tomlinson <stu@nosnilmot.com>
parents: 27356
diff changeset
3897 s = strstr(s, "\r\n");
e8ac5369d567 Apparently there might be stuff after the semicolon before the \r\n so just
Stu Tomlinson <stu@nosnilmot.com>
parents: 27356
diff changeset
3898 if (s == NULL)
e8ac5369d567 Apparently there might be stuff after the semicolon before the \r\n so just
Stu Tomlinson <stu@nosnilmot.com>
parents: 27356
diff changeset
3899 break;
e8ac5369d567 Apparently there might be stuff after the semicolon before the \r\n so just
Stu Tomlinson <stu@nosnilmot.com>
parents: 27356
diff changeset
3900 s += 2;
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3901
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3902 if (s + sz > data + *len) {
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3903 purple_debug_error("util", "Error processing chunked data: "
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3904 "Chunk size %" G_GSIZE_FORMAT " bytes was longer "
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3905 "than the data remaining in the buffer (%"
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3906 G_GSIZE_FORMAT " bytes)\n", sz, data + *len - s);
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3907 }
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3908
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3909 /* Move all data overtop of the chunk length that we read in earlier */
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3910 g_memmove(p, s, sz);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3911 p += sz;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3912 s += sz;
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3913 newlen += sz;
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3914 if (*s != '\r' && *(s + 1) != '\n') {
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3915 purple_debug_error("util", "Error processing chunked data: "
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3916 "Expected \\r\\n, found: %s\n", s);
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3917 break;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3918 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3919 s += 2;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3920 }
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3921
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3922 /* NULL terminate the data */
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3923 *p = 0;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3924
27328
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27327
diff changeset
3925 *len = newlen;
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3926 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3927
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3928 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3929 url_fetch_recv_cb(gpointer url_data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3930 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3931 PurpleUtilFetchUrlData *gfud = url_data;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3932 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3933 char buf[4096];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3934 char *data_cursor;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3935 gboolean got_eof = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3936
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3937 /*
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3938 * Read data in a loop until we can't read any more! This is a
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3939 * little confusing because we read using a different function
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3940 * depending on whether the socket is ssl or cleartext.
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3941 */
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3942 while ((gfud->is_ssl && ((len = purple_ssl_read(gfud->ssl_connection, buf, sizeof(buf))) > 0)) ||
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3943 (!gfud->is_ssl && (len = read(source, buf, sizeof(buf))) > 0))
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
3944 {
23742
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
3945 if(gfud->max_len != -1 && (gfud->len + len) > gfud->max_len) {
24006
fa39c801167d Fix a TODO and mark a string translatable now that we're not string frozen.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23913
diff changeset
3946 purple_util_fetch_url_error(gfud, _("Error reading from %s: response too long (%d bytes limit)"),
23742
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
3947 gfud->website.address, gfud->max_len);
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
3948 return;
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
3949 }
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
3950
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3951 /* If we've filled up our buffer, make it bigger */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3952 if((gfud->len + len) >= gfud->data_len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3953 while((gfud->len + len) >= gfud->data_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3954 gfud->data_len += sizeof(buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3955
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3956 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3957 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3958
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3959 data_cursor = gfud->webdata + gfud->len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3960
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3961 gfud->len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3962
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3963 memcpy(data_cursor, buf, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3964
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3965 gfud->webdata[gfud->len] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3966
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3967 if(!gfud->got_headers) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3968 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3969
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3970 /* See if we've reached the end of the headers yet */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3971 if((tmp = strstr(gfud->webdata, "\r\n\r\n"))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3972 char * new_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3973 guint header_len = (tmp + 4 - gfud->webdata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3974 size_t content_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3975
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
3976 purple_debug_misc("util", "Response headers: '%.*s'\n",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3977 header_len, gfud->webdata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3978
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3979 /* See if we can find a redirect. */
23390
276925996951 Remove a unused variable
Mark Doliner <mark@kingant.net>
parents: 23367
diff changeset
3980 if(parse_redirect(gfud->webdata, header_len, gfud))
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3981 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3982
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3983 gfud->got_headers = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3984
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3985 /* No redirect. See if we can find a content length. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3986 content_len = parse_content_len(gfud->webdata, header_len);
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
3987 gfud->chunked = content_is_chunked(gfud->webdata, header_len);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3988
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3989 if(content_len == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3990 /* We'll stick with an initial 8192 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3991 content_len = 8192;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3992 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3993 gfud->has_explicit_data_len = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3994 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3995
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3996
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3997 /* If we're returning the headers too, we don't need to clean them out */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3998 if(gfud->include_headers) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3999 gfud->data_len = content_len + header_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4000 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4001 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4002 size_t body_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4003
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4004 if(gfud->len > (header_len + 1))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4005 body_len = (gfud->len - header_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4006
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4007 content_len = MAX(content_len, body_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4008
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4009 new_data = g_try_malloc(content_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4010 if(new_data == NULL) {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4011 purple_debug_error("util",
22475
3225c99785b8 Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <mark@kingant.net>
parents: 22344
diff changeset
4012 "Failed to allocate %" G_GSIZE_FORMAT " bytes: %s\n",
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
4013 content_len, g_strerror(errno));
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4014 purple_util_fetch_url_error(gfud,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4015 _("Unable to allocate enough memory to hold "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4016 "the contents from %s. The web server may "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4017 "be trying something malicious."),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4018 gfud->website.address);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4019
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4020 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4021 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4022
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4023 /* We may have read part of the body when reading the headers, don't lose it */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4024 if(body_len > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4025 tmp += 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4026 memcpy(new_data, tmp, body_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4027 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4028
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4029 /* Out with the old... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4030 g_free(gfud->webdata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4031
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4032 /* In with the new. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4033 gfud->len = body_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4034 gfud->data_len = content_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4035 gfud->webdata = new_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4036 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4037 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4038 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4039
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4040 if(gfud->has_explicit_data_len && gfud->len >= gfud->data_len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4041 got_eof = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4042 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4043 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4044 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4045
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4046 if(len < 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4047 if(errno == EAGAIN) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4048 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4049 } else {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4050 purple_util_fetch_url_error(gfud, _("Error reading from %s: %s"),
21121
35b4f1dc4c8d replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents: 21028
diff changeset
4051 gfud->website.address, g_strerror(errno));
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4052 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4053 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4054 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4055
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4056 if((len == 0) || got_eof) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4057 gfud->webdata = g_realloc(gfud->webdata, gfud->len + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4058 gfud->webdata[gfud->len] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4059
27302
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
4060 if (!gfud->include_headers && gfud->chunked) {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
4061 /* Process only if we don't want the headers. */
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
4062 process_chunked_data(gfud->webdata, &gfud->len);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
4063 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27219
diff changeset
4064
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4065 gfud->callback(gfud, gfud->user_data, gfud->webdata, gfud->len, NULL);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4066 purple_util_fetch_url_cancel(gfud);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4067 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4068 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4069
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4070 static void ssl_url_fetch_recv_cb(gpointer data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4071 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4072 url_fetch_recv_cb(data, -1, cond);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4073 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4074
27202
9ff4b4cbc4c9 Allow doxygen to pick up the comment for this function. It's
Mark Doliner <mark@kingant.net>
parents: 27106
diff changeset
4075 /**
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4076 * This function is called when the socket is available to be written
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4077 * to.
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4078 *
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4079 * @param source The file descriptor that can be written to. This can
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4080 * be an http connection or it can be the SSL connection of an
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4081 * https request. So be careful what you use it for! If it's
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4082 * an https request then use purple_ssl_write() instead of
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4083 * writing to it directly.
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4084 */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4085 static void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4086 url_fetch_send_cb(gpointer data, gint source, PurpleInputCondition cond)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4087 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4088 PurpleUtilFetchUrlData *gfud;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4089 int len, total_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4090
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4091 gfud = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4092
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4093 if (gfud->request == NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4094 {
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4095 /* Host header is not forbidden in HTTP/1.0 requests, and HTTP/1.1
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4096 * clients must know how to handle the "chunked" transfer encoding.
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4097 * Purple doesn't know how to handle "chunked", so should always send
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4098 * the Host header regardless, to get around some observed problems
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4099 */
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4100 if (gfud->user_agent) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4101 gfud->request = g_strdup_printf(
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4102 "GET %s%s HTTP/%s\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4103 "Connection: close\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4104 "User-Agent: %s\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4105 "Accept: */*\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4106 "Host: %s\r\n\r\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4107 (gfud->full ? "" : "/"),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4108 (gfud->full ? (gfud->url ? gfud->url : "") : (gfud->website.page ? gfud->website.page : "")),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4109 (gfud->http11 ? "1.1" : "1.0"),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4110 (gfud->user_agent ? gfud->user_agent : ""),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4111 (gfud->website.address ? gfud->website.address : ""));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4112 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4113 gfud->request = g_strdup_printf(
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4114 "GET %s%s HTTP/%s\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4115 "Connection: close\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4116 "Accept: */*\r\n"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4117 "Host: %s\r\n\r\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4118 (gfud->full ? "" : "/"),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4119 (gfud->full ? (gfud->url ? gfud->url : "") : (gfud->website.page ? gfud->website.page : "")),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4120 (gfud->http11 ? "1.1" : "1.0"),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4121 (gfud->website.address ? gfud->website.address : ""));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4122 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4123 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4124
27380
e9279f0e551a Convert all uses of PURPLE_UNSAFE_DEBUG to the new API I added.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 27377
diff changeset
4125 if(purple_debug_is_unsafe())
25908
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24828
diff changeset
4126 purple_debug_misc("util", "Request: '%s'\n", gfud->request);
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24828
diff changeset
4127 else
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24828
diff changeset
4128 purple_debug_misc("util", "request constructed\n");
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4129
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4130 total_len = strlen(gfud->request);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4131
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4132 if (gfud->is_ssl)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4133 len = purple_ssl_write(gfud->ssl_connection, gfud->request + gfud->request_written,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4134 total_len - gfud->request_written);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4135 else
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4136 len = write(gfud->fd, gfud->request + gfud->request_written,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4137 total_len - gfud->request_written);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4138
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4139 if (len < 0 && errno == EAGAIN)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4140 return;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4141 else if (len < 0) {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4142 purple_util_fetch_url_error(gfud, _("Error writing to %s: %s"),
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4143 gfud->website.address, g_strerror(errno));
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4144 return;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4145 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4146 gfud->request_written += len;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4147
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4148 if (gfud->request_written < total_len)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4149 return;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4150
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4151 /* We're done writing our request, now start reading the response */
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4152 if (gfud->is_ssl) {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4153 purple_input_remove(gfud->inpa);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4154 gfud->inpa = 0;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4155 purple_ssl_input_add(gfud->ssl_connection, ssl_url_fetch_recv_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4156 } else {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4157 purple_input_remove(gfud->inpa);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4158 gfud->inpa = purple_input_add(gfud->fd, PURPLE_INPUT_READ, url_fetch_recv_cb,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4159 gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4160 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4161 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4162
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4163 static void
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4164 url_fetch_connect_cb(gpointer url_data, gint source, const gchar *error_message)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4165 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4166 PurpleUtilFetchUrlData *gfud;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4167
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4168 gfud = url_data;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4169 gfud->connect_data = NULL;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4170
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4171 if (source == -1)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4172 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4173 purple_util_fetch_url_error(gfud, _("Unable to connect to %s: %s"),
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4174 (gfud->website.address ? gfud->website.address : ""), error_message);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4175 return;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4176 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4177
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4178 gfud->fd = source;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4179
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4180 gfud->inpa = purple_input_add(source, PURPLE_INPUT_WRITE,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4181 url_fetch_send_cb, gfud);
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4182 url_fetch_send_cb(gfud, source, PURPLE_INPUT_WRITE);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4183 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4184
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4185 static void ssl_url_fetch_connect_cb(gpointer data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4186 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4187 PurpleUtilFetchUrlData *gfud;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4188
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4189 gfud = data;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4190
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4191 gfud->inpa = purple_input_add(ssl_connection->fd, PURPLE_INPUT_WRITE,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4192 url_fetch_send_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4193 url_fetch_send_cb(gfud, ssl_connection->fd, PURPLE_INPUT_WRITE);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4194 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4195
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4196 static void ssl_url_fetch_error_cb(PurpleSslConnection *ssl_connection, PurpleSslErrorType error, gpointer data)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4197 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4198 PurpleUtilFetchUrlData *gfud;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4199
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4200 gfud = data;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4201 gfud->ssl_connection = NULL;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4202
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4203 purple_util_fetch_url_error(gfud, _("Unable to connect to %s: %s"),
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4204 (gfud->website.address ? gfud->website.address : ""),
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4205 purple_ssl_strerror(error));
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4206 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4207
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4208 PurpleUtilFetchUrlData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4209 purple_util_fetch_url_request(const char *url, gboolean full,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4210 const char *user_agent, gboolean http11,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4211 const char *request, gboolean include_headers,
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4212 PurpleUtilFetchUrlCallback callback, void *user_data)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4213 {
27051
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4214 return purple_util_fetch_url_request_len_with_account(NULL, url, full,
23742
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4215 user_agent, http11,
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4216 request, include_headers, -1,
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4217 callback, user_data);
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4218 }
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4219
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4220 PurpleUtilFetchUrlData *
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4221 purple_util_fetch_url_request_len(const char *url, gboolean full,
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4222 const char *user_agent, gboolean http11,
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4223 const char *request, gboolean include_headers, gssize max_len,
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4224 PurpleUtilFetchUrlCallback callback, void *user_data)
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4225 {
27051
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4226 return purple_util_fetch_url_request_len_with_account(NULL, url, full,
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4227 user_agent, http11, request, include_headers, max_len, callback,
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4228 user_data);
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4229 }
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4230
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4231 PurpleUtilFetchUrlData *
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4232 purple_util_fetch_url_request_len_with_account(PurpleAccount *account,
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4233 const char *url, gboolean full, const char *user_agent, gboolean http11,
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4234 const char *request, gboolean include_headers, gssize max_len,
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4235 PurpleUtilFetchUrlCallback callback, void *user_data)
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4236 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4237 PurpleUtilFetchUrlData *gfud;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4238
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4239 g_return_val_if_fail(url != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4240 g_return_val_if_fail(callback != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4241
27380
e9279f0e551a Convert all uses of PURPLE_UNSAFE_DEBUG to the new API I added.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 27377
diff changeset
4242 if(purple_debug_is_unsafe())
25908
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24828
diff changeset
4243 purple_debug_info("util",
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24828
diff changeset
4244 "requested to fetch (%s), full=%d, user_agent=(%s), http11=%d\n",
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24828
diff changeset
4245 url, full, user_agent?user_agent:"(null)", http11);
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24828
diff changeset
4246 else
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24828
diff changeset
4247 purple_debug_info("util", "requesting to fetch a URL\n");
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4248
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4249 gfud = g_new0(PurpleUtilFetchUrlData, 1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4250
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4251 gfud->callback = callback;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4252 gfud->user_data = user_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4253 gfud->url = g_strdup(url);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4254 gfud->user_agent = g_strdup(user_agent);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4255 gfud->http11 = http11;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4256 gfud->full = full;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4257 gfud->request = g_strdup(request);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4258 gfud->include_headers = include_headers;
20592
383b9180b2c8 Initialize file-descriptors to -1.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 20587
diff changeset
4259 gfud->fd = -1;
23742
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23723
diff changeset
4260 gfud->max_len = max_len;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4261
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4262 purple_url_parse(url, &gfud->website.address, &gfud->website.port,
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4263 &gfud->website.page, &gfud->website.user, &gfud->website.passwd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4264
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4265 if (purple_strcasestr(url, "https://") != NULL) {
26272
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26263
diff changeset
4266 if (!purple_ssl_is_supported()) {
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26263
diff changeset
4267 purple_util_fetch_url_error(gfud,
27460
6275df9d2d62 Change strings in libpurple/protocols/jabber/auth.c and util.c a little bit
Mark Doliner <mark@kingant.net>
parents: 27458
diff changeset
4268 _("Unable to connect to %s: %s"),
6275df9d2d62 Change strings in libpurple/protocols/jabber/auth.c and util.c a little bit
Mark Doliner <mark@kingant.net>
parents: 27458
diff changeset
4269 gfud->website.address,
6275df9d2d62 Change strings in libpurple/protocols/jabber/auth.c and util.c a little bit
Mark Doliner <mark@kingant.net>
parents: 27458
diff changeset
4270 _("Server requires TLS/SSL, but no TLS/SSL support was found."));
26272
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26263
diff changeset
4271 return NULL;
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26263
diff changeset
4272 }
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26263
diff changeset
4273
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4274 gfud->is_ssl = TRUE;
27051
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4275 gfud->ssl_connection = purple_ssl_connect(account,
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4276 gfud->website.address, gfud->website.port,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4277 ssl_url_fetch_connect_cb, ssl_url_fetch_error_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4278 } else {
27051
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26977
diff changeset
4279 gfud->connect_data = purple_proxy_connect(NULL, account,
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4280 gfud->website.address, gfud->website.port,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4281 url_fetch_connect_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4282 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4283
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4284 if (gfud->ssl_connection == NULL && gfud->connect_data == NULL)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4285 {
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4286 purple_util_fetch_url_error(gfud, _("Unable to connect to %s"),
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4287 gfud->website.address);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4288 return NULL;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4289 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4290
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4291 return gfud;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4292 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4293
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4294 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4295 purple_util_fetch_url_cancel(PurpleUtilFetchUrlData *gfud)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4296 {
24538
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4297 if (gfud->ssl_connection != NULL)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4298 purple_ssl_close(gfud->ssl_connection);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24369
diff changeset
4299
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4300 if (gfud->connect_data != NULL)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4301 purple_proxy_connect_cancel(gfud->connect_data);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4302
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4303 if (gfud->inpa > 0)
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4304 purple_input_remove(gfud->inpa);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4305
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4306 if (gfud->fd >= 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4307 close(gfud->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4308
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4309 g_free(gfud->website.user);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4310 g_free(gfud->website.passwd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4311 g_free(gfud->website.address);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4312 g_free(gfud->website.page);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4313 g_free(gfud->url);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4314 g_free(gfud->user_agent);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4315 g_free(gfud->request);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4316 g_free(gfud->webdata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4317
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4318 g_free(gfud);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4319 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4320
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4321 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4322 purple_url_decode(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4323 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4324 static char buf[BUF_LEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4325 guint i, j = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4326 char *bum;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4327 char hex[3];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4328
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4329 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4330
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4331 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4332 * XXX - This check could be removed and buf could be made
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4333 * dynamically allocated, but this is easier.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4334 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4335 if (strlen(str) >= BUF_LEN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4336 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4337
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4338 for (i = 0; i < strlen(str); i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4339
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4340 if (str[i] != '%')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4341 buf[j++] = str[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4342 else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4343 strncpy(hex, str + ++i, 2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4344 hex[2] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4345
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4346 /* i is pointing to the start of the number */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4347 i++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4348
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4349 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4350 * Now it's at the end and at the start of the for loop
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4351 * will be at the next character.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4352 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4353 buf[j++] = strtol(hex, NULL, 16);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4354 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4355 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4356
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4357 buf[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4358
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4359 if (!g_utf8_validate(buf, -1, (const char **)&bum))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4360 *bum = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4361
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4362 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4363 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4364
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4365 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4366 purple_url_encode(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4367 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4368 const char *iter;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4369 static char buf[BUF_LEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4370 char utf_char[6];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4371 guint i, j = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4372
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4373 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4374 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4375
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4376 iter = str;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4377 for (; *iter && j < (BUF_LEN - 1) ; iter = g_utf8_next_char(iter)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4378 gunichar c = g_utf8_get_char(iter);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4379 /* If the character is an ASCII character and is alphanumeric
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4380 * no need to escape */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4381 if (c < 128 && isalnum(c)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4382 buf[j++] = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4383 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4384 int bytes = g_unichar_to_utf8(c, utf_char);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4385 for (i = 0; i < bytes; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4386 if (j > (BUF_LEN - 4))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4387 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4388 sprintf(buf + j, "%%%02x", utf_char[i] & 0xff);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4389 j += 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4390 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4391 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4392 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4393
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4394 buf[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4395
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4396 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4397 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4398
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4399 /* Originally lifted from
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4400 * http://www.oreillynet.com/pub/a/network/excerpt/spcookbook_chap03/index3.html
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4401 * ... and slightly modified to be a bit more rfc822 compliant
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4402 * ... and modified a bit more to make domain checking rfc1035 compliant
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4403 * with the exception permitted in rfc1101 for domains to start with digit
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4404 * but not completely checking to avoid conflicts with IP addresses
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4405 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4406 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4407 purple_email_is_valid(const char *address)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4408 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4409 const char *c, *domain;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4410 static char *rfc822_specials = "()<>@,;:\\\"[]";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4411
24367
2d677e8fe6d0 Fix CID #385
Richard Laager <rlaager@wiktel.com>
parents: 24366
diff changeset
4412 g_return_val_if_fail(address != NULL, FALSE);
2d677e8fe6d0 Fix CID #385
Richard Laager <rlaager@wiktel.com>
parents: 24366
diff changeset
4413
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4414 /* first we validate the name portion (name@domain) (rfc822)*/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4415 for (c = address; *c; c++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4416 if (*c == '\"' && (c == address || *(c - 1) == '.' || *(c - 1) == '\"')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4417 while (*++c) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4418 if (*c == '\\') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4419 if (*c++ && *c < 127 && *c != '\n' && *c != '\r') continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4420 else return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4421 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4422 if (*c == '\"') break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4423 if (*c < ' ' || *c >= 127) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4424 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4425 if (!*c++) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4426 if (*c == '@') break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4427 if (*c != '.') return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4428 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4429 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4430 if (*c == '@') break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4431 if (*c <= ' ' || *c >= 127) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4432 if (strchr(rfc822_specials, *c)) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4433 }
18600
321658bf0e03 Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <mark@kingant.net>
parents: 18560
diff changeset
4434
321658bf0e03 Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <mark@kingant.net>
parents: 18560
diff changeset
4435 /* It's obviously not an email address if we didn't find an '@' above */
321658bf0e03 Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <mark@kingant.net>
parents: 18560
diff changeset
4436 if (*c == '\0') return FALSE;
321658bf0e03 Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <mark@kingant.net>
parents: 18560
diff changeset
4437
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4438 /* strictly we should return false if (*(c - 1) == '.') too, but I think
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4439 * we should permit user.@domain type addresses - they do work :) */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4440 if (c == address) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4441
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4442 /* next we validate the domain portion (name@domain) (rfc1035 & rfc1011) */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4443 if (!*(domain = ++c)) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4444 do {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4445 if (*c == '.' && (c == domain || *(c - 1) == '.' || *(c - 1) == '-'))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4446 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4447 if (*c == '-' && *(c - 1) == '.') return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4448 if ((*c < '0' && *c != '-' && *c != '.') || (*c > '9' && *c < 'A') ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4449 (*c > 'Z' && *c < 'a') || (*c > 'z')) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4450 } while (*++c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4451
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4452 if (*(c - 1) == '-') return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4453
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4454 return ((c - domain) > 3 ? TRUE : FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4455 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4456
22327
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4457 gboolean
27549
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27545
diff changeset
4458 purple_ipv4_address_is_valid(const char *ip)
22327
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4459 {
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4460 int c, o1, o2, o3, o4;
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4461 char end;
24365
64395aea313c Fix CID #387
Richard Laager <rlaager@wiktel.com>
parents: 24364
diff changeset
4462
64395aea313c Fix CID #387
Richard Laager <rlaager@wiktel.com>
parents: 24364
diff changeset
4463 g_return_val_if_fail(ip != NULL, FALSE);
64395aea313c Fix CID #387
Richard Laager <rlaager@wiktel.com>
parents: 24364
diff changeset
4464
22327
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4465 c = sscanf(ip, "%d.%d.%d.%d%c", &o1, &o2, &o3, &o4, &end);
22344
51e740d3af3b Fixes an error detected by valgrind:
Ka-Hing Cheung <khc@hxbc.us>
parents: 22327
diff changeset
4466 if (c != 4 || o1 < 0 || o1 > 255 || o2 < 0 || o2 > 255 || o3 < 0 || o3 > 255 || o4 < 0 || o4 > 255)
22327
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4467 return FALSE;
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4468 return TRUE;
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4469 }
dc47e908965f Use connect server as FQDN for SASL auth except when it is an IP address.
Stu Tomlinson <stu@nosnilmot.com>
parents: 22191
diff changeset
4470
27545
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4471 gboolean
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4472 purple_ipv6_address_is_valid(const gchar *ip)
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4473 {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4474 const gchar *c;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4475 gboolean double_colon = FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4476 gint chunks = 1;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4477 gint in = 0;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4478
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4479 g_return_val_if_fail(ip != NULL, FALSE);
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4480
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4481 if (*ip == '\0')
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4482 return FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4483
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4484 for (c = ip; *c; ++c) {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4485 if ((*c >= '0' && *c <= '9') ||
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4486 (*c >= 'a' && *c <= 'f') ||
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4487 (*c >= 'A' && *c <= 'F')) {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4488 if (++in > 4)
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4489 /* Only four hex digits per chunk */
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4490 return FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4491 continue;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4492 } else if (*c == ':') {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4493 /* The start of a new chunk */
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4494 ++chunks;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4495 in = 0;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4496 if (*(c + 1) == ':') {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4497 /*
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4498 * '::' indicates a consecutive series of chunks full
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4499 * of zeroes. There can be only one of these per address.
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4500 */
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4501 if (double_colon)
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4502 return FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4503 double_colon = TRUE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4504 }
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4505 } else
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4506 return FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4507 }
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4508
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4509 /*
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4510 * Either we saw a '::' and there were fewer than 8 chunks -or-
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4511 * we didn't see a '::' and saw exactly 8 chunks.
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4512 */
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4513 return (double_colon && chunks < 8) || (!double_colon && chunks == 8);
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4514 }
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27524
diff changeset
4515
27549
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27545
diff changeset
4516 /* TODO 3.0.0: Add ipv6 check, too */
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27545
diff changeset
4517 gboolean
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27545
diff changeset
4518 purple_ip_address_is_valid(const char *ip)
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27545
diff changeset
4519 {
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27545
diff changeset
4520 return purple_ipv4_address_is_valid(ip);
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27545
diff changeset
4521 }
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27545
diff changeset
4522
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4523 /* Stolen from gnome_uri_list_extract_uris */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4524 GList *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4525 purple_uri_list_extract_uris(const gchar *uri_list)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4526 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4527 const gchar *p, *q;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4528 gchar *retval;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4529 GList *result = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4530
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4531 g_return_val_if_fail (uri_list != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4532
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4533 p = uri_list;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4534
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4535 /* We don't actually try to validate the URI according to RFC
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4536 * 2396, or even check for allowed characters - we just ignore
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4537 * comments and trim whitespace off the ends. We also
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4538 * allow LF delimination as well as the specified CRLF.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4539 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4540 while (p) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4541 if (*p != '#') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4542 while (isspace(*p))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4543 p++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4544
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4545 q = p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4546 while (*q && (*q != '\n') && (*q != '\r'))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4547 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4548
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4549 if (q > p) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4550 q--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4551 while (q > p && isspace(*q))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4552 q--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4553
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4554 retval = (gchar*)g_malloc (q - p + 2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4555 strncpy (retval, p, q - p + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4556 retval[q - p + 1] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4557
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4558 result = g_list_prepend (result, retval);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4559 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4560 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4561 p = strchr (p, '\n');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4562 if (p)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4563 p++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4564 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4565
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4566 return g_list_reverse (result);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4567 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4568
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4569
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4570 /* Stolen from gnome_uri_list_extract_filenames */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4571 GList *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4572 purple_uri_list_extract_filenames(const gchar *uri_list)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4573 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4574 GList *tmp_list, *node, *result;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4575
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4576 g_return_val_if_fail (uri_list != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4577
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4578 result = purple_uri_list_extract_uris(uri_list);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4579
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4580 tmp_list = result;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4581 while (tmp_list) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4582 gchar *s = (gchar*)tmp_list->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4583
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4584 node = tmp_list;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4585 tmp_list = tmp_list->next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4586
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4587 if (!strncmp (s, "file:", 5)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4588 node->data = g_filename_from_uri (s, NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4589 /* not sure if this fallback is useful at all */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4590 if (!node->data) node->data = g_strdup (s+5);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4591 } else {
22837
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22475
diff changeset
4592 result = g_list_delete_link(result, node);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4593 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4594 g_free (s);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4595 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4596 return result;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4597 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4598
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4599 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4600 * UTF8 String Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4601 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4602 gchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4603 purple_utf8_try_convert(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4604 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4605 gsize converted;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4606 gchar *utf8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4607
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4608 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4609
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4610 if (g_utf8_validate(str, -1, NULL)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4611 return g_strdup(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4612 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4613
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4614 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4615 if (utf8 != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4616 return utf8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4617
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4618 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4619 if ((utf8 != NULL) && (converted == strlen(str)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4620 return utf8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4621
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4622 g_free(utf8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4623
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4624 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4625 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4626
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4627 #define utf8_first(x) ((x & 0x80) == 0 || (x & 0xe0) == 0xc0 \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4628 || (x & 0xf0) == 0xe0 || (x & 0xf8) == 0xf)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4629 gchar *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4630 purple_utf8_salvage(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4631 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4632 GString *workstr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4633 const char *end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4634
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4635 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4636
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4637 workstr = g_string_sized_new(strlen(str));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4638
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4639 do {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4640 g_utf8_validate(str, -1, &end);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4641 workstr = g_string_append_len(workstr, str, end - str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4642 str = end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4643 if (*str == '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4644 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4645 do {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4646 workstr = g_string_append_c(workstr, '?');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4647 str++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4648 } while (!utf8_first(*str));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4649 } while (*str != '\0');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4650
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4651 return g_string_free(workstr, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4652 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4653
27101
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4654 gchar *
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4655 purple_utf8_strip_unprintables(const gchar *str)
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4656 {
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4657 gchar *workstr, *iter;
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4658
27106
c59918579c3a Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents: 27101
diff changeset
4659 if (str == NULL)
c59918579c3a Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents: 27101
diff changeset
4660 /* Act like g_strdup */
c59918579c3a Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents: 27101
diff changeset
4661 return NULL;
c59918579c3a Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents: 27101
diff changeset
4662
27101
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4663 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL);
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4664
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4665 workstr = iter = g_new(gchar, strlen(str) + 1);
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4666 while (*str) {
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4667 gunichar c = g_utf8_get_char(str);
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4668 const gchar *next = g_utf8_next_char(str);
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4669 size_t len = next - str;
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4670
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4671 if (g_unichar_isprint(c)) {
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4672 memcpy(iter, str, len);
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4673 iter += len;
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4674 }
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4675
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4676 str = next;
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4677 }
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4678
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4679 /* nul-terminate the new string */
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4680 *iter = '\0';
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4681
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4682 return workstr;
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4683 }
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27094
diff changeset
4684
21863
7e833250a0ef Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents: 21862
diff changeset
4685 /*
7e833250a0ef Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents: 21862
diff changeset
4686 * This function is copied from g_strerror() but changed to use
7e833250a0ef Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents: 21862
diff changeset
4687 * gai_strerror().
7e833250a0ef Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents: 21862
diff changeset
4688 */
21862
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4689 G_CONST_RETURN gchar *
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4690 purple_gai_strerror(gint errnum)
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4691 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4692 static GStaticPrivate msg_private = G_STATIC_PRIVATE_INIT;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4693 char *msg;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4694 int saved_errno = errno;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4695
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4696 const char *msg_locale;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4697
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4698 msg_locale = gai_strerror(errnum);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4699 if (g_get_charset(NULL))
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4700 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4701 /* This string is already UTF-8--great! */
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4702 errno = saved_errno;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4703 return msg_locale;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4704 }
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4705 else
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4706 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4707 gchar *msg_utf8 = g_locale_to_utf8(msg_locale, -1, NULL, NULL, NULL);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4708 if (msg_utf8)
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4709 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4710 /* Stick in the quark table so that we can return a static result */
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4711 GQuark msg_quark = g_quark_from_string(msg_utf8);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4712 g_free(msg_utf8);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4713
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4714 msg_utf8 = (gchar *)g_quark_to_string(msg_quark);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4715 errno = saved_errno;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4716 return msg_utf8;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4717 }
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4718 }
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4719
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4720 msg = g_static_private_get(&msg_private);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4721 if (!msg)
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4722 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4723 msg = g_new(gchar, 64);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4724 g_static_private_set(&msg_private, msg, g_free);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4725 }
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4726
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4727 sprintf(msg, "unknown error (%d)", errnum);
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4728
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4729 errno = saved_errno;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4730 return msg;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4731 }
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4732
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4733 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4734 purple_utf8_ncr_encode(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4735 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4736 GString *out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4737
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4738 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4739 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4740
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4741 out = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4742
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4743 for(; *str; str = g_utf8_next_char(str)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4744 gunichar wc = g_utf8_get_char(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4745
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4746 /* super simple check. hopefully not too wrong. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4747 if(wc >= 0x80) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4748 g_string_append_printf(out, "&#%u;", (guint32) wc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4749 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4750 g_string_append_unichar(out, wc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4751 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4752 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4753
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4754 return g_string_free(out, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4755 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4756
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4757
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4758 char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4759 purple_utf8_ncr_decode(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4760 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4761 GString *out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4762 char *buf, *b;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4763
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4764 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4765 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4766
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4767 buf = (char *) str;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4768 out = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4769
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4770 while( (b = strstr(buf, "&#")) ) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4771 gunichar wc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4772 int base = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4773
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4774 /* append everything leading up to the &# */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4775 g_string_append_len(out, buf, b-buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4776
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4777 b += 2; /* skip past the &# */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4778
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4779 /* strtoul will treat 0x prefix as hex, but not just x */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4780 if(*b == 'x' || *b == 'X') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4781 base = 16;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4782 b++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4783 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4784
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4785 /* advances buf to the end of the ncr segment */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4786 wc = (gunichar) strtoul(b, &buf, base);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4787
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4788 /* this mimics the previous impl of ncr_decode */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4789 if(*buf == ';') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4790 g_string_append_unichar(out, wc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4791 buf++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4792 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4793 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4794
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4795 /* append whatever's left */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4796 g_string_append(out, buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4797
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4798 return g_string_free(out, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4799 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4800
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4801
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4802 int
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4803 purple_utf8_strcasecmp(const char *a, const char *b)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4804 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4805 char *a_norm = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4806 char *b_norm = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4807 int ret = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4808
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4809 if(!a && b)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4810 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4811 else if(!b && a)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4812 return 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4813 else if(!a && !b)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4814 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4815
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4816 if(!g_utf8_validate(a, -1, NULL) || !g_utf8_validate(b, -1, NULL))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4817 {
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4818 purple_debug_error("purple_utf8_strcasecmp",
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4819 "One or both parameters are invalid UTF8\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4820 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4821 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4822
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4823 a_norm = g_utf8_casefold(a, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4824 b_norm = g_utf8_casefold(b, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4825 ret = g_utf8_collate(a_norm, b_norm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4826 g_free(a_norm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4827 g_free(b_norm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4828
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4829 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4830 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4831
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4832 /* previously conversation::find_nick() */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4833 gboolean
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4834 purple_utf8_has_word(const char *haystack, const char *needle)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4835 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4836 char *hay, *pin, *p;
24806
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4837 const char *start, *prev_char;
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4838 gunichar before, after;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4839 int n;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4840 gboolean ret = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4841
24806
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4842 start = hay = g_utf8_strdown(haystack, -1);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4843
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4844 pin = g_utf8_strdown(needle, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4845 n = strlen(pin);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4846
24806
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4847 while ((p = strstr(start, pin)) != NULL) {
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4848 prev_char = g_utf8_find_prev_char(hay, p);
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4849 before = -2;
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4850 if (prev_char) {
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4851 before = g_utf8_get_char(prev_char);
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4852 }
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4853 after = g_utf8_get_char_validated(p + n, - 1);
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4854
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4855 if ((p == hay ||
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4856 /* The character before is a reasonable guess for a word boundary
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4857 ("!g_unichar_isalnum()" is not a valid way to determine word
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4858 boundaries, but it is the only reasonable thing to do here),
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4859 and isn't the '&' from a "&amp;" or some such entity*/
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4860 (before != -2 && !g_unichar_isalnum(before) && *(p - 1) != '&'))
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4861 && after != -2 && !g_unichar_isalnum(after)) {
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4862 ret = TRUE;
24806
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4863 break;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4864 }
24806
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24538
diff changeset
4865 start = p + 1;
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4866 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4867
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4868 g_free(pin);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4869 g_free(hay);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4870
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4871 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4872 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4873
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4874 void
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4875 purple_print_utf8_to_console(FILE *filestream, char *message)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4876 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4877 gchar *message_conv;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4878 GError *error = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4879
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4880 /* Try to convert 'message' to user's locale */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4881 message_conv = g_locale_from_utf8(message, -1, NULL, NULL, &error);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4882 if (message_conv != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4883 fputs(message_conv, filestream);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4884 g_free(message_conv);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4885 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4886 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4887 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4888 /* use 'message' as a fallback */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4889 g_warning("%s\n", error->message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4890 g_error_free(error);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4891 fputs(message, filestream);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4892 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4893 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4894
19408
cc36a5aac908 Fix some conversion warnings about using negative values with unsigned types. There are more, but these were easy fixes. You may think that I'm changing the API, but I'm really not - it was just wrong.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 19262
diff changeset
4895 gboolean purple_message_meify(char *message, gssize len)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4896 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4897 char *c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4898 gboolean inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4899
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4900 g_return_val_if_fail(message != NULL, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4901
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4902 if(len == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4903 len = strlen(message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4904
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4905 for (c = message; *c; c++, len--) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4906 if(inside_html) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4907 if(*c == '>')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4908 inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4909 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4910 if(*c == '<')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4911 inside_html = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4912 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4913 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4914 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4915 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4916
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4917 if(*c && !g_ascii_strncasecmp(c, "/me ", 4)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4918 memmove(c, c+4, len-3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4919 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4920 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4921
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4922 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4923 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4924
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4925 char *purple_text_strip_mnemonic(const char *in)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4926 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4927 char *out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4928 char *a;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4929 char *a0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4930 const char *b;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4931
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4932 g_return_val_if_fail(in != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4933
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4934 out = g_malloc(strlen(in)+1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4935 a = out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4936 b = in;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4937
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4938 a0 = a; /* The last non-space char seen so far, or the first char */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4939
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4940 while(*b) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4941 if(*b == '_') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4942 if(a > out && b > in && *(b-1) == '(' && *(b+1) && !(*(b+1) & 0x80) && *(b+2) == ')') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4943 /* Detected CJK style shortcut (Bug 875311) */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4944 a = a0; /* undo the left parenthesis */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4945 b += 3; /* and skip the whole mess */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4946 } else if(*(b+1) == '_') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4947 *(a++) = '_';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4948 b += 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4949 a0 = a;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4950 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4951 b++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4952 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4953 /* We don't want to corrupt the middle of UTF-8 characters */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4954 } else if (!(*b & 0x80)) { /* other 1-byte char */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4955 if (*b != ' ')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4956 a0 = a;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4957 *(a++) = *(b++);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4958 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4959 /* Multibyte utf8 char, don't look for _ inside these */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4960 int n = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4961 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4962 if ((*b & 0xe0) == 0xc0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4963 n = 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4964 } else if ((*b & 0xf0) == 0xe0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4965 n = 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4966 } else if ((*b & 0xf8) == 0xf0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4967 n = 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4968 } else if ((*b & 0xfc) == 0xf8) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4969 n = 5;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4970 } else if ((*b & 0xfe) == 0xfc) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4971 n = 6;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4972 } else { /* Illegal utf8 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4973 n = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4974 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4975 a0 = a; /* unless we want to delete CJK spaces too */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4976 for (i = 0; i < n && *b; i += 1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4977 *(a++) = *(b++);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4978 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4979 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4980 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4981 *a = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4982
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4983 return out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4984 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4985
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4986 const char* purple_unescape_filename(const char *escaped) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4987 return purple_url_decode(escaped);
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4988 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4989
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4990
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4991 /* this is almost identical to purple_url_encode (hence purple_url_decode
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4992 * being used above), but we want to keep certain characters unescaped
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4993 * for compat reasons */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4994 const char *
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
4995 purple_escape_filename(const char *str)
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4996 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4997 const char *iter;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4998 static char buf[BUF_LEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4999 char utf_char[6];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5000 guint i, j = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5001
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5002 g_return_val_if_fail(str != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5003 g_return_val_if_fail(g_utf8_validate(str, -1, NULL), NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5004
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5005 iter = str;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5006 for (; *iter && j < (BUF_LEN - 1) ; iter = g_utf8_next_char(iter)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5007 gunichar c = g_utf8_get_char(iter);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5008 /* If the character is an ASCII character and is alphanumeric,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5009 * or one of the specified values, no need to escape */
17194
51f8dac490d7 If we're operating on ASCII characters only, we should use g_ascii_isalnum.
Richard Laager <rlaager@wiktel.com>
parents: 17191
diff changeset
5010 if (c < 128 && (g_ascii_isalnum(c) || c == '@' || c == '-' ||
15374
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5011 c == '_' || c == '.' || c == '#')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5012 buf[j++] = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5013 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5014 int bytes = g_unichar_to_utf8(c, utf_char);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5015 for (i = 0; i < bytes; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5016 if (j > (BUF_LEN - 4))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5017 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5018 sprintf(buf + j, "%%%02x", utf_char[i] & 0xff);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5019 j += 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5020 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5021 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5022 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5023
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5024 buf[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5025
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5026 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5027 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5028
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
5029 const char *_purple_oscar_convert(const char *act, const char *protocol)
15421
6d8728fd3dda Make sure the pounces, buddy-aliases, savedstatuses etc. saved before the aim/icq split works after the split. The util function _gaim_oscar_convert will be removed at a 'suitable' time in the future.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15399
diff changeset
5030 {
25385
a6e3cb32cdd2 Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <paul@darkrain42.org>
parents: 25381
diff changeset
5031 if (act && purple_strequal(protocol, "prpl-oscar")) {
19603
79d624f7c3ee You can't just look at the first letter of the screen name to determine
Mark Doliner <mark@kingant.net>
parents: 19499
diff changeset
5032 int i;
79d624f7c3ee You can't just look at the first letter of the screen name to determine
Mark Doliner <mark@kingant.net>
parents: 19499
diff changeset
5033 for (i = 0; act[i] != '\0'; i++)
79d624f7c3ee You can't just look at the first letter of the screen name to determine
Mark Doliner <mark@kingant.net>
parents: 19499
diff changeset
5034 if (!isdigit(act[i]))
79d624f7c3ee You can't just look at the first letter of the screen name to determine
Mark Doliner <mark@kingant.net>
parents: 19499
diff changeset
5035 return "prpl-aim";
79d624f7c3ee You can't just look at the first letter of the screen name to determine
Mark Doliner <mark@kingant.net>
parents: 19499
diff changeset
5036 return "prpl-icq";
15421
6d8728fd3dda Make sure the pounces, buddy-aliases, savedstatuses etc. saved before the aim/icq split works after the split. The util function _gaim_oscar_convert will be removed at a 'suitable' time in the future.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15399
diff changeset
5037 }
6d8728fd3dda Make sure the pounces, buddy-aliases, savedstatuses etc. saved before the aim/icq split works after the split. The util function _gaim_oscar_convert will be removed at a 'suitable' time in the future.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15399
diff changeset
5038 return protocol;
6d8728fd3dda Make sure the pounces, buddy-aliases, savedstatuses etc. saved before the aim/icq split works after the split. The util function _gaim_oscar_convert will be removed at a 'suitable' time in the future.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15399
diff changeset
5039 }
6d8728fd3dda Make sure the pounces, buddy-aliases, savedstatuses etc. saved before the aim/icq split works after the split. The util function _gaim_oscar_convert will be removed at a 'suitable' time in the future.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15399
diff changeset
5040
15823
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15784
diff changeset
5041 void purple_restore_default_signal_handlers(void)
15646
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5042 {
15665
95c4dee525f0 Merge fix and build fix for win32
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15664
diff changeset
5043 #ifndef _WIN32
15646
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5044 #ifdef HAVE_SIGNAL_H
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5045 signal(SIGHUP, SIG_DFL); /* 1: terminal line hangup */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5046 signal(SIGINT, SIG_DFL); /* 2: interrupt program */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5047 signal(SIGQUIT, SIG_DFL); /* 3: quit program */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5048 signal(SIGILL, SIG_DFL); /* 4: illegal instruction (not reset when caught) */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5049 signal(SIGTRAP, SIG_DFL); /* 5: trace trap (not reset when caught) */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5050 signal(SIGABRT, SIG_DFL); /* 6: abort program */
15662
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5051
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5052 #ifdef SIGPOLL
16495
b8b2e35ec7c6 Fix purple_util_get_image_extension()'s data param. to be correctly marked as constant.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16483
diff changeset
5053 signal(SIGPOLL, SIG_DFL); /* 7: pollable event (POSIX) */
15662
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5054 #endif /* SIGPOLL */
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5055
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5056 #ifdef SIGEMT
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5057 signal(SIGEMT, SIG_DFL); /* 7: EMT instruction (Non-POSIX) */
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5058 #endif /* SIGEMT */
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5059
15646
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5060 signal(SIGFPE, SIG_DFL); /* 8: floating point exception */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5061 signal(SIGBUS, SIG_DFL); /* 10: bus error */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5062 signal(SIGSEGV, SIG_DFL); /* 11: segmentation violation */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5063 signal(SIGSYS, SIG_DFL); /* 12: bad argument to system call */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5064 signal(SIGPIPE, SIG_DFL); /* 13: write on a pipe with no reader */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5065 signal(SIGALRM, SIG_DFL); /* 14: real-time timer expired */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5066 signal(SIGTERM, SIG_DFL); /* 15: software termination signal */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5067 signal(SIGCHLD, SIG_DFL); /* 20: child status has changed */
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5068 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */
16495
b8b2e35ec7c6 Fix purple_util_get_image_extension()'s data param. to be correctly marked as constant.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16483
diff changeset
5069 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */
15662
80944a182710 SIGEMT is not available on non-POSIX systems; SIGPOLL is present, instead. Thanks to Richard for catching this.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15646
diff changeset
5070 #endif /* HAVE_SIGNAL_H */
15665
95c4dee525f0 Merge fix and build fix for win32
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15664
diff changeset
5071 #endif /* !_WIN32 */
15646
61b42cf81aa4 Restore default signal handlers in fork()'d children. This adds a gaim_restore_default_signal_handlers() utility function since children are made in multiple places.
Evan Schoenberg <evan.s@dreskin.net>
parents: 15613
diff changeset
5072 }
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5073
22089
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5074 static void
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5075 set_status_with_attrs(PurpleStatus *status, ...)
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5076 {
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5077 va_list args;
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5078 va_start(args, status);
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5079 purple_status_set_active_with_attrs(status, TRUE, args);
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5080 va_end(args);
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5081 }
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5082
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5083 void purple_util_set_current_song(const char *title, const char *artist, const char *album)
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5084 {
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5085 GList *list = purple_accounts_get_all();
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5086 for (; list; list = list->next) {
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5087 PurplePresence *presence;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5088 PurpleStatus *tune;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5089 PurpleAccount *account = list->data;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5090 if (!purple_account_get_enabled(account, purple_core_get_ui()))
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5091 continue;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5092
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5093 presence = purple_account_get_presence(account);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5094 tune = purple_presence_get_status(presence, "tune");
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5095 if (!tune)
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5096 continue;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5097 if (title) {
22089
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5098 set_status_with_attrs(tune,
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5099 PURPLE_TUNE_TITLE, title,
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5100 PURPLE_TUNE_ARTIST, artist,
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5101 PURPLE_TUNE_ALBUM, album,
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5102 NULL);
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5103 } else {
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5104 purple_status_set_active(tune, FALSE);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5105 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5106 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5107 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5108
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5109 char * purple_util_format_song_info(const char *title, const char *artist, const char *album, gpointer unused)
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5110 {
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5111 GString *string;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5112 char *esc;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5113
22060
83613550512b Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22000
diff changeset
5114 if (!title || !*title)
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5115 return NULL;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5116
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5117 esc = g_markup_escape_text(title, -1);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5118 string = g_string_new("");
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5119 g_string_append_printf(string, "%s", esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5120 g_free(esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5121
22060
83613550512b Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22000
diff changeset
5122 if (artist && *artist) {
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5123 esc = g_markup_escape_text(artist, -1);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5124 g_string_append_printf(string, _(" - %s"), esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5125 g_free(esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5126 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5127
22060
83613550512b Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22000
diff changeset
5128 if (album && *album) {
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5129 esc = g_markup_escape_text(album, -1);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5130 g_string_append_printf(string, _(" (%s)"), esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5131 g_free(esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5132 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5133
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5134 return g_string_free(string, FALSE);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5135 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5136
23583
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5137 const gchar *
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5138 purple_get_host_name(void)
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5139 {
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5140 #if GLIB_CHECK_VERSION(2,8,0)
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5141 return g_get_host_name();
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5142 #else
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5143 static char hostname[256];
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5144 int ret = gethostname(hostname, sizeof(hostname));
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5145 hostname[sizeof(hostname) - 1] = '\0';
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5146
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5147 if (ret == -1 || hostname[0] == '\0') {
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5148 purple_debug_info("purple_get_host_name: ", "could not find host name");
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5149 return "localhost";
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5150 } else {
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5151 return hostname;
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5152 }
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5153 #endif
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23390
diff changeset
5154 }