annotate libpurple/util.c @ 32652:8ba7c2b732a8

Hide some Facebook settings hacks for now.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 13 Feb 2011 01:36:45 +0000
parents c61d3e5ec1da
children 1e1b598c725e 73b005a20d06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
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: 19681
diff changeset
4 */
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19681
diff changeset
5
6bf32c9e15a7 remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@gmail.com>
parents: 19681
diff changeset
6 /* Purple is the legal property of its developers, whose names are too numerous
15373
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
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19662
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
15373
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: 17765
diff changeset
26 #include "cipher.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include "conversation.h"
15612
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: 15420
diff changeset
28 #include "core.h"
15373
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"
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
31 #include "ntlm.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32 #include "prpl.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 #include "prefs.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 #include "util.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
36 struct _PurpleUtilFetchUrlData
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
38 PurpleUtilFetchUrlCallback callback;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
39 void *user_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
41 struct
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
43 char *user;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
44 char *passwd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
45 char *address;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
46 int port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 char *page;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 } website;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 char *url;
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
52 int num_times_redirected;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 gboolean full;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 char *user_agent;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
55 gboolean http11;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56 char *request;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 gsize request_written;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58 gboolean include_headers;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
60 gboolean is_ssl;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
61 PurpleSslConnection *ssl_connection;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
62 PurpleProxyConnectData *connect_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63 int fd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
64 guint inpa;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
65
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
66 gboolean got_headers;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 gboolean has_explicit_data_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
68 char *webdata;
27445
065294d973b4 This fixes this compile warning:
Stu Tomlinson <stu@nosnilmot.com>
parents: 27404
diff changeset
69 gsize len;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 unsigned long data_len;
23684
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
71 gssize max_len;
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
72 gboolean chunked;
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
73 PurpleAccount *account;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75
18147
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
76 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
77 static char *user_dir = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78
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
79
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
80 PurpleMenuAction *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
81 purple_menu_action_new(const char *label, PurpleCallback callback, gpointer data,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 GList *children)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
84 PurpleMenuAction *act = g_new0(PurpleMenuAction, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
85 act->label = g_strdup(label);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
86 act->callback = callback;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
87 act->data = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
88 act->children = children;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
89 return act;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
90 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
91
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
93 purple_menu_action_free(PurpleMenuAction *act)
15373
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_return_if_fail(act != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 g_free(act->label);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98 g_free(act);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100
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
101 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
102 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
103 {
25924
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25894
diff changeset
104 /* 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
105 * 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
106 }
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
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 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
109 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
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 /* 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
112
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 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
114 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
115
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 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
117 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
118 }
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
119
15373
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 * Base16 Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 gchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
124 purple_base16_encode(const guchar *data, gsize len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 gchar *ascii = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 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
130 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
131
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 ascii = g_malloc(len * 2 + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 for (i = 0; i < len; i++)
26885
8290e36a5a73 A patch from Scott Wolchok to replace snprintf() with g_snprintf() and
Richard Laager <rlaager@wiktel.com>
parents: 26772
diff changeset
135 g_snprintf(&ascii[i * 2], 3, "%02hhx", data[i]);
15373
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 return ascii;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 guchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
141 purple_base16_decode(const char *str, gsize *ret_len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 int len, i, accumulator = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
144 guchar *data;
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 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
147
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
148 len = strlen(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
149
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
150 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
151 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
152
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 data = g_malloc(len / 2);
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 for (i = 0; i < len; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
156 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 if ((i % 2) == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
158 accumulator = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 accumulator <<= 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
162 if (isdigit(str[i]))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 accumulator |= str[i] - 48;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164 else
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 switch(tolower(str[i]))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 {
16153
6613fb7af427 Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents: 16084
diff changeset
168 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
169 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
170 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
171 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
172 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
173 case 'f': accumulator |= 15; break;
15373
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 if (i % 2)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 data[(i - 1) / 2] = accumulator;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 if (ret_len != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 *ret_len = len / 2;
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 return data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186
17765
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
187 gchar *
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
188 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: 17195
diff changeset
189 {
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
190 int i;
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
191 gchar *ascii = NULL;
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
192
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
193 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: 17195
diff changeset
194 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: 17195
diff changeset
195
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
196 /* 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: 17195
diff changeset
197 * and 1 for the colon.
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
198 * 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: 17195
diff changeset
199 */
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
200 ascii = g_malloc(len * 3 + 1);
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
201
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
202 for (i = 0; i < len; i++)
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
203 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: 17195
diff changeset
204
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
205 /* Replace the final colon with NULL */
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
206 ascii[len * 3 - 1] = 0;
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
207
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
208 return ascii;
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
209 }
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
210
ba768014f91f - Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents: 17195
diff changeset
211
15373
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 * Base64 Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 static const char alphabet[] =
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 "0123456789+/";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 static const char xdigits[] =
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 "0123456789abcdef";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 gchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
223 purple_base64_encode(const guchar *data, gsize len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224 {
27217
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27137
diff changeset
225 return g_base64_encode(data, len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 }
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 guchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
229 purple_base64_decode(const char *str, gsize *ret_len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
230 {
27217
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27137
diff changeset
231 /*
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27137
diff changeset
232 * 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: 27137
diff changeset
233 * 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: 27137
diff changeset
234 * 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: 27137
diff changeset
235 */
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27137
diff changeset
236 gsize unused;
3d92b968d49f Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents: 27137
diff changeset
237 return g_base64_decode(str, ret_len != NULL ? ret_len : &unused);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239
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 * Quoted Printable Functions (see RFC 2045).
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
242 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
243 guchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
244 purple_quotedp_decode(const char *str, gsize *ret_len)
15373
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 char *n, *new;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
247 const char *end, *p;
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 n = new = g_malloc(strlen (str) + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
250 end = str + strlen(str);
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 for (p = str; p < end; p++, n++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
253 if (*p == '=') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
254 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
255 n -= 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
256 p += 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
257 } 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
258 n -= 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
259 p += 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
260 } else if (p[1] && p[2]) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
261 char *nibble1 = strchr(xdigits, tolower(p[1]));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
262 char *nibble2 = strchr(xdigits, tolower(p[2]));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 if (nibble1 && nibble2) { /* 5.1 #1 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264 *n = ((nibble1 - xdigits) << 4) | (nibble2 - xdigits);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 p += 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 } else { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267 *n = *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 } else { /* This should never happen */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 *n = *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 else if (*p == '_')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
274 *n = ' ';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 *n = *p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
277 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
279 *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 if (ret_len != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282 *ret_len = n - new;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 /* Resize to take less space */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 /* new = realloc(new, n - new); */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 return (guchar *)new;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
291 * MIME Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
293 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
294 purple_mime_decode_field(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
295 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
296 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297 * 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
298 * See RFC2047 [which apparently obsoletes RFC1342]
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300 typedef enum {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301 state_start, state_equal1, state_question1,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 state_charset, state_question2,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 state_encoding, state_question3,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 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
305 } encoded_word_state_t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 encoded_word_state_t state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 const char *cur, *mark;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 const char *charset0 = NULL, *encoding0 = NULL, *encoded_text0 = NULL;
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
309 GString *new;
15373
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 /* 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
312 #define token_char_p(c) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 (c != ' ' && !iscntrl(c) && !strchr("()<>@,;:\"/[]?.=", c))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 /* 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
316 #define encoded_text_char_p(c) \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 ((c & 0x80) == 0 && c != '?' && c != ' ' && isgraph(c))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 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
320
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
321 new = g_string_new(NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 /* 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
324 * valid then decode them.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325 * 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
326 */
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 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
329 switch (state) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 case state_equal1:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331 if (*cur == '?') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 state = state_question1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 } else {
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
334 g_string_append_len(new, mark, cur - mark + 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 case state_question1:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 if (token_char_p(*cur)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 charset0 = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
341 state = state_charset;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 } else { /* This should never happen */
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
343 g_string_append_len(new, mark, cur - mark + 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 case state_charset:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 if (*cur == '?') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 state = state_question2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 } else if (!token_char_p(*cur)) { /* This should never happen */
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
351 g_string_append_len(new, mark, cur - mark + 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
355 case state_question2:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 if (token_char_p(*cur)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 encoding0 = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 state = state_encoding;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359 } else { /* This should never happen */
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
360 g_string_append_len(new, mark, cur - mark + 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 case state_encoding:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365 if (*cur == '?') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 state = state_question3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 } else if (!token_char_p(*cur)) { /* This should never happen */
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
368 g_string_append_len(new, mark, cur - mark + 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 state = state_start;
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 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
372 case state_question3:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 if (encoded_text_char_p(*cur)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374 encoded_text0 = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375 state = state_encoded_text;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 } else if (*cur == '?') { /* empty string */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377 encoded_text0 = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378 state = state_question4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 } else { /* This should never happen */
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
380 g_string_append_len(new, mark, cur - mark + 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381 state = state_start;
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 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 case state_encoded_text:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385 if (*cur == '?') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 state = state_question4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 } else if (!encoded_text_char_p(*cur)) {
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
388 g_string_append_len(new, mark, cur - mark + 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 state = state_start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 case state_question4:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 if (*cur == '=') { /* Got the whole encoded-word */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
394 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
395 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
396 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
397 guchar *decoded = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 gsize dec_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 if (g_ascii_strcasecmp(encoding, "Q") == 0)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
400 decoded = purple_quotedp_decode(encoded_text, &dec_len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401 else if (g_ascii_strcasecmp(encoding, "B") == 0)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
402 decoded = purple_base64_decode(encoded_text, &dec_len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 decoded = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 if (decoded) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406 gsize len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 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
408
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 if (converted) {
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
410 g_string_append_len(new, converted, len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 g_free(converted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
413 g_free(decoded);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 g_free(charset);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416 g_free(encoding);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417 g_free(encoded_text);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 state = state_equal2; /* Restart the FSM */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 } else { /* This should never happen */
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
420 g_string_append_len(new, mark, cur - mark + 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421 state = state_start;
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 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425 if (*cur == '=') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
426 mark = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427 state = state_equal1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429 /* Some unencoded text. */
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
430 g_string_append_c(new, *cur);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
431 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433 } /* switch */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434 } /* for */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435
27907
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
436 if (state != state_start)
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
437 g_string_append_len(new, mark, cur - mark + 1);
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
438
9358464cdf6a How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents: 27860
diff changeset
439 return g_string_free(new, FALSE);;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
441
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 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 * Date/Time Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
447 const char *purple_get_tzoff_str(const struct tm *tm, gboolean iso)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
448 {
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
449 static char buf[7];
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 long off;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451 gint8 min;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 gint8 hrs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 struct tm new_tm = *tm;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 mktime(&new_tm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 if (new_tm.tm_isdst < 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 g_return_val_if_reached("");
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 #ifdef _WIN32
20503
905891855710 3rd time the charm? Fixes #2990, maybe
Ka-Hing Cheung <khc@hxbc.us>
parents: 19499
diff changeset
461 if ((off = wpurple_get_tz_offset()) == -1)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 return "";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 # ifdef HAVE_TM_GMTOFF
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465 off = new_tm.tm_gmtoff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
466 # else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 # ifdef HAVE_TIMEZONE
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 tzset();
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
469 off = -1 * timezone;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470 # endif /* HAVE_TIMEZONE */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471 # endif /* !HAVE_TM_GMTOFF */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 #endif /* _WIN32 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 min = (off / 60) % 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 hrs = ((off / 60) - min) / 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
477 if(iso) {
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
478 if (0 == off) {
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
479 strcpy(buf, "Z");
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
480 } else {
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
481 /* 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
482 * wants them */
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
483 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
484 g_return_val_if_reached("");
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
485 }
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
486 } else {
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
487 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
488 g_return_val_if_reached("");
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
489 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494 /* 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
495 #if !defined(HAVE_STRFTIME_Z_FORMAT) || defined(_WIN32)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
496 static size_t purple_internal_strftime(char *s, size_t max, const char *format, const struct tm *tm)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
497 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
498 const char *start;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
499 const char *c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
500 char *fmt = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
501
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
502 /* Yes, this is checked in purple_utf8_strftime(),
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503 * but better safe than sorry. -- rlaager */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504 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
505
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 /* 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
507 * executed on Windows or if the underlying
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508 * 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
509 * 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
510 * -- rlaager */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 for (c = start = format; *c ; c++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 if (*c != '%')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518 #ifndef HAVE_STRFTIME_Z_FORMAT
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519 if (*c == 'z')
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 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
522 fmt ? fmt : "",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 c - start - 1,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 start,
18259
c5c265dff90c support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents: 18147
diff changeset
525 purple_get_tzoff_str(tm, FALSE));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 g_free(fmt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 fmt = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 start = c + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 #ifdef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
532 if (*c == 'Z')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 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
535 fmt ? fmt : "",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 c - start - 1,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 start,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
538 wpurple_get_timezone_abbreviation(tm));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 g_free(fmt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 fmt = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541 start = c + 1;
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 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 }
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 if (fmt != NULL)
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 size_t ret;
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 if (*start)
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 char *tmp = g_strconcat(fmt, start, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 g_free(fmt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 fmt = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
556
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 ret = strftime(s, max, fmt, tm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
558 g_free(fmt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
559
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 return strftime(s, max, format, tm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 #else /* HAVE_STRFTIME_Z_FORMAT && !_WIN32 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
566 #define purple_internal_strftime strftime
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 #endif
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 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
570 purple_utf8_strftime(const char *format, const struct tm *tm)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 static char buf[128];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573 char *locale;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 GError *err = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576 char *utf8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 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
579
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 if (tm == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
581 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
582 time_t now = time(NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
583 tm = localtime(&now);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
584 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
585
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
586 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
587 if (err != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
588 {
19654
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19603
diff changeset
589 purple_debug_error("util", "Format conversion failed in purple_utf8_strftime(): %s\n", err->message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
590 g_error_free(err);
29738
4e5cfb6ad471 util: Fix a crash in purple_utf8_strftime.
Florian Quèze <florian@instantbird.org>
parents: 29641
diff changeset
591 err = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592 locale = g_strdup(format);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595 /* 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
596 * 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
597 * undefined) or the empty string (in which
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 * case, no harm is done here). */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
599 if ((len = purple_internal_strftime(buf, sizeof(buf), locale, tm)) == 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 g_free(locale);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602 return "";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 g_free(locale);
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 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
608 if (err != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
609 {
19654
941965d6fd88 Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19603
diff changeset
610 purple_debug_error("util", "Result conversion failed in purple_utf8_strftime(): %s\n", err->message);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 g_error_free(err);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
615 purple_strlcpy(buf, utf8);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616 g_free(utf8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 }
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 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
623 purple_date_format_short(const struct tm *tm)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
625 return purple_utf8_strftime("%x", tm);
15373
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
629 purple_date_format_long(const struct tm *tm)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
630 {
23666
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23652
diff changeset
631 /*
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23652
diff changeset
632 * 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: 23652
diff changeset
633 * 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: 23652
diff changeset
634 * 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: 23652
diff changeset
635 * followed by the date.
187a3649f04b Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents: 23652
diff changeset
636 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
637 return purple_utf8_strftime(_("%x %X"), tm);
15373
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
641 purple_date_format_full(const struct tm *tm)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
643 return purple_utf8_strftime("%c", tm);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
647 purple_time_format(const struct tm *tm)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
649 return purple_utf8_strftime("%X", tm);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 }
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 time_t
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
653 purple_time_build(int year, int month, int day, int hour, int min, int sec)
15373
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 struct tm tm;
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 tm.tm_year = year - 1900;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658 tm.tm_mon = month - 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 tm.tm_mday = day;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660 tm.tm_hour = hour;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
661 tm.tm_min = min;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
662 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
663
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 return mktime(&tm);
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
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
667 /* originally taken from GLib trunk 1-6-11 */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
668 /* originally licensed as LGPL 2+ */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
669 static time_t
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
670 mktime_utc(struct tm *tm)
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
671 {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
672 time_t retval;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
673
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
674 #ifndef HAVE_TIMEGM
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
675 static const gint days_before[] =
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
676 {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
677 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
678 };
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
679 #endif
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
680
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
681 #ifndef HAVE_TIMEGM
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
682 if (tm->tm_mon < 0 || tm->tm_mon > 11)
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
683 return (time_t) -1;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
684
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
685 retval = (tm->tm_year - 70) * 365;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
686 retval += (tm->tm_year - 68) / 4;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
687 retval += days_before[tm->tm_mon] + tm->tm_mday - 1;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
688
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
689 if (tm->tm_year % 4 == 0 && tm->tm_mon < 2)
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
690 retval -= 1;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
691
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
692 retval = ((((retval * 24) + tm->tm_hour) * 60) + tm->tm_min) * 60 + tm->tm_sec;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
693 #else
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
694 retval = timegm (tm);
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
695 #endif /* !HAVE_TIMEGM */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
696
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
697 return retval;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
698 }
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
699
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
700 time_t
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
701 purple_str_to_time(const char *timestamp, gboolean utc,
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
702 struct tm *tm, long *tz_off, const char **rest)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
703 {
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
704 struct tm t;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
705 const gchar *str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
706 gint year = 0;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
707 long tzoff = PURPLE_NO_TZ_OFF;
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
708 time_t retval;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
709 gboolean mktime_with_utc = TRUE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
710
23975
b789b54c5bb2 purple_str_to_time() didn't necessarily set "rest" under all circumstances.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23734
diff changeset
711 if (rest != NULL)
b789b54c5bb2 purple_str_to_time() didn't necessarily set "rest" under all circumstances.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23734
diff changeset
712 *rest = NULL;
b789b54c5bb2 purple_str_to_time() didn't necessarily set "rest" under all circumstances.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23734
diff changeset
713
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
714 g_return_val_if_fail(timestamp != NULL, 0);
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
715
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
716 str = timestamp;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
717
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
718 /* Strip leading whitespace */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
719 while (g_ascii_isspace(*str))
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
720 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
721
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
722 if (*str == '\0') {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
723 if (rest != NULL && *str != '\0')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
724 *rest = str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
725
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
726 return 0;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
727 }
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
728
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
729 if (!g_ascii_isdigit(*str) && *str != '-' && *str != '+') {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
730 if (rest != NULL && *str != '\0')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
731 *rest = str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
732
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
733 return 0;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
734 }
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
735
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
736 /* 4 digit year */
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
737 if (sscanf(str, "%04d", &year) && year >= 1900) {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
738 str += 4;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
739
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
740 if (*str == '-' || *str == '/')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
741 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
742
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
743 t.tm_year = year - 1900;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
744 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
745
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
746 /* 2 digit month */
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
747 if (!sscanf(str, "%02d", &t.tm_mon)) {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
748 if (rest != NULL && *str != '\0')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
749 *rest = str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
750
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
751 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
752 }
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
753
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
754 str += 2;
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
755 t.tm_mon -= 1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
756
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
757 if (*str == '-' || *str == '/')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
758 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
759
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
760 /* 2 digit day */
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
761 if (!sscanf(str, "%02d", &t.tm_mday)) {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
762 if (rest != NULL && *str != '\0')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
763 *rest = str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
764
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
765 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
766 }
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
767
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
768 str += 2;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
769
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
770 /* Grab the year off the end if there's still stuff */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
771 if (*str == '/' || *str == '-') {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
772 /* But make sure we don't read the year twice */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
773 if (year >= 1900) {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
774 if (rest != NULL && *str != '\0')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
775 *rest = str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
776
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
777 return 0;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
778 }
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
779
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
780 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
781
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
782 if (!sscanf(str, "%04d", &t.tm_year)) {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
783 if (rest != NULL && *str != '\0')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
784 *rest = str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
785
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
786 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
787 }
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
788
21613
31101e7d275f 'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents: 21612
diff changeset
789 t.tm_year -= 1900;
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
790 } else if (*str == 'T' || *str == '.') {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
791 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
792
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
793 /* Continue grabbing the hours/minutes/seconds */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
794 if ((sscanf(str, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 &&
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
795 (str += 8)) ||
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
796 (sscanf(str, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 &&
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
797 (str += 6)))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
798 {
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
799 gint sign, tzhrs, tzmins;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
800
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
801 if (*str == '.') {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
802 /* Cut off those pesky micro-seconds */
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
803 do {
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
804 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
805 } while (*str >= '0' && *str <= '9');
23365
ef4dbd2bb696 Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23248
diff changeset
806 }
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
807
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
808 sign = (*str == '+') ? -1 : 1;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
809
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
810 /* Process the timezone */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
811 if (*str == '+' || *str == '-') {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
812 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
813
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
814 if (((sscanf(str, "%02d:%02d", &tzhrs, &tzmins) == 2 && (str += 5)) ||
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
815 (sscanf(str, "%02d%02d", &tzhrs, &tzmins) == 2 && (str += 4))))
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
816 {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
817 tzoff = tzhrs * 60 * 60 + tzmins * 60;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
818 tzoff *= sign;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
819 } else {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
820 if (rest != NULL && *str != '\0')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
821 *rest = str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
822
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
823 return 0;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
824 }
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
825 } else if (*str == 'Z') {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
826 /* 'Z' = Zulu = UTC */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
827 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
828 utc = TRUE;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
829 } else if (!utc) {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
830 /* Local Time */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
831 t.tm_isdst = -1;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
832 mktime_with_utc = FALSE;
15373
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
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
835 if (utc)
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
836 tzoff = 0;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
837 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
838 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
839
31123
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
840 if (rest != NULL && *str != '\0') {
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
841 /* Strip trailing whitespace */
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
842 while (g_ascii_isspace(*str))
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
843 str++;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
844
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
845 if (*str != '\0')
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
846 *rest = str;
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
847 }
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
848
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
849 if (mktime_with_utc)
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
850 retval = mktime_utc(&t);
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
851 else
c61d3e5ec1da Fix purple_str_to_time(). Fixes #13131.
morshed.nader@gmail.com
parents: 31086
diff changeset
852 retval = mktime(&t);
22896
8dadddab10ed Fix purple_str_to_time() to not break the returned value when we have given
Richard Laager <rlaager@wiktel.com>
parents: 22864
diff changeset
853
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
854 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
855 *tm = t;
22896
8dadddab10ed Fix purple_str_to_time() to not break the returned value when we have given
Richard Laager <rlaager@wiktel.com>
parents: 22864
diff changeset
856
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
857 if (tzoff != PURPLE_NO_TZ_OFF)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
858 retval += tzoff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
859
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
860 if (tz_off != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
861 *tz_off = tzoff;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
862
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
863 return retval;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
864 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
865
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
866 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
867 * Markup Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
868 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
869
27393
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
870 /*
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
871 * 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: 27378
diff changeset
872 * replace ' with &apos;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
873 */
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
874 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: 27378
diff changeset
875 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: 27378
diff changeset
876 {
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
877 const gchar *p;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
878 const gchar *end;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
879 gunichar c;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
880
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
881 p = text;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
882 end = text + length;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
883
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
884 while (p != end)
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
885 {
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
886 const gchar *next;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
887 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: 27378
diff changeset
888
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
889 switch (*p)
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
890 {
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
891 case '&':
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
892 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: 27378
diff changeset
893 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
894
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
895 case '<':
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
896 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: 27378
diff changeset
897 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
898
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
899 case '>':
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
900 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: 27378
diff changeset
901 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
902
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
903 case '"':
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
904 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: 27378
diff changeset
905 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
906
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
907 default:
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
908 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: 27378
diff changeset
909 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: 27378
diff changeset
910 (0xb <= c && c <= 0xc) ||
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
911 (0xe <= c && c <= 0x1f) ||
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
912 (0x7f <= c && c <= 0x84) ||
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
913 (0x86 <= c && c <= 0x9f))
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
914 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: 27378
diff changeset
915 else
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
916 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: 27378
diff changeset
917 break;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
918 }
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
919
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
920 p = next;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
921 }
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
922 }
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
923
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
924 /* 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: 27378
diff changeset
925 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: 27378
diff changeset
926 {
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
927 GString *str;
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
928
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
929 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: 27378
diff changeset
930
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
931 if (length < 0)
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
932 length = strlen(text);
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
933
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
934 /* 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: 27378
diff changeset
935 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: 27378
diff changeset
936 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: 27378
diff changeset
937
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
938 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: 27378
diff changeset
939 }
57fdb7853fc7 Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents: 27378
diff changeset
940
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
941 const char *
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
942 purple_markup_unescape_entity(const char *text, int *length)
15373
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 const char *pln;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
945 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
946 char temp[2];
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
947
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
948 if (!text || *text != '&')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
949 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
950
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
951 #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
952
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
953 if(IS_ENTITY("&amp;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
954 pln = "&";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
955 else if(IS_ENTITY("&lt;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
956 pln = "<";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
957 else if(IS_ENTITY("&gt;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
958 pln = ">";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
959 else if(IS_ENTITY("&nbsp;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
960 pln = " ";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
961 else if(IS_ENTITY("&copy;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
962 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
963 else if(IS_ENTITY("&quot;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
964 pln = "\"";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
965 else if(IS_ENTITY("&reg;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
966 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
967 else if(IS_ENTITY("&apos;"))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
968 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
969 else if(*(text+1) == '#' &&
22313
bb1dc0095856 Revert some bits of the earlier patch not related to custom smileys.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22312
diff changeset
970 (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: 22312
diff changeset
971 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
972 pound != 0) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
973 static char buf[7];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
974 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
975 buf[buflen] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
976 pln = buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
977
27295
d4c6d2c6fb03 Fix purple_markup_unescape_entity to properly consume '&#x5C;' and similar.
Paul Aurich <paul@darkrain42.org>
parents: 27281
diff changeset
978 len = (*(text+2) == 'x' ? 3 : 2);
d4c6d2c6fb03 Fix purple_markup_unescape_entity to properly consume '&#x5C;' and similar.
Paul Aurich <paul@darkrain42.org>
parents: 27281
diff changeset
979 while(isxdigit((gint) text[len])) len++;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
980 if(text[len] == ';') len++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
981 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
982 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
983 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
984
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
985 if (length)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
986 *length = len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
987 return pln;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
988 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
989
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
990 char *
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
991 purple_markup_get_css_property(const gchar *style,
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
992 const gchar *opt)
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
993 {
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
994 const gchar *css_str = style;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
995 const gchar *css_value_start;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
996 const gchar *css_value_end;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
997 gchar *tmp;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
998 gchar *ret;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
999
24421
0f035b8db8df Fix CID #388
Richard Laager <rlaager@wiktel.com>
parents: 24420
diff changeset
1000 g_return_val_if_fail(opt != NULL, NULL);
0f035b8db8df Fix CID #388
Richard Laager <rlaager@wiktel.com>
parents: 24420
diff changeset
1001
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1002 if (!css_str)
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1003 return NULL;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1004
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1005 /* find the CSS property */
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1006 while (1)
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1007 {
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1008 /* skip whitespace characters */
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1009 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
1010 css_str++;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1011 if (!g_ascii_isalpha(*css_str))
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1012 return NULL;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1013 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
1014 {
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1015 /* go to next css property positioned after the next ';' */
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1016 while (*css_str && *css_str != '"' && *css_str != ';')
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1017 css_str++;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1018 if(*css_str != ';')
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1019 return NULL;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1020 css_str++;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1021 }
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1022 else
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1023 break;
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1024 }
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1025
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1026 /* find the CSS value position in the string */
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1027 css_str += strlen(opt);
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1028 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
1029 css_str++;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1030 if (*css_str != ':')
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1031 return NULL;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1032 css_str++;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1033 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
1034 css_str++;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1035 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
1036 return NULL;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1037
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1038 /* mark the CSS value */
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1039 css_value_start = css_str;
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1040 while (*css_str && *css_str != '"' && *css_str != ';')
16083
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1041 css_str++;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1042 css_value_end = css_str - 1;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1043
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1044 /* Removes trailing whitespace */
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1045 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
1046 css_value_end--;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1047
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1048 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
1049 ret = purple_unescape_html(tmp);
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1050 g_free(tmp);
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1051
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1052 return ret;
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1053 }
f2a4b05407d7 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 16063
diff changeset
1054
27012
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1055 gboolean purple_markup_is_rtl(const char *html)
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1056 {
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1057 GData *attributes;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1058 const gchar *start, *end;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1059 gboolean res = FALSE;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1060
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1061 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: 26969
diff changeset
1062 {
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1063 /* 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: 26969
diff changeset
1064 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: 26969
diff changeset
1065 if (tmp && !g_ascii_strcasecmp(tmp, "RTL"))
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1066 res = TRUE;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1067 if (!res)
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1068 {
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1069 tmp = g_datalist_get_data(&attributes, "style");
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1070 if (tmp)
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1071 {
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1072 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: 26969
diff changeset
1073 if (tmp2 && !g_ascii_strcasecmp(tmp2, "RTL"))
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1074 res = TRUE;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1075 g_free(tmp2);
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1076 }
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1077
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1078 }
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1079 g_datalist_clear(&attributes);
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1080 }
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1081 return res;
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1082 }
af4a4ebc6441 Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26969
diff changeset
1083
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1084 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1085 purple_markup_find_tag(const char *needle, const char *haystack,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1086 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
1087 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1088 GData *attribs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1089 const char *cur = haystack;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1090 char *name = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1091 gboolean found = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1092 gboolean in_tag = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1093 gboolean in_attr = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1094 const char *in_quotes = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1095 size_t needlelen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1096
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1097 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
1098 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
1099 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
1100 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
1101 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
1102 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
1103
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1104 needlelen = strlen(needle);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1105 g_datalist_init(&attribs);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1106
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1107 while (*cur && !found) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1108 if (in_tag) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1109 if (in_quotes) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1110 const char *close = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1111
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1112 while (*close && *close != *in_quotes)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1113 close++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1114
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1115 /* 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
1116 * 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
1117 * and we're outta here */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1118 if (*close) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1119 /* 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
1120 if (name) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1121 size_t len = close - cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1122 char *val = g_strndup(cur, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1123
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1124 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
1125 g_free(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1126 name = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1127 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1128
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1129 in_quotes = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1130 cur = close + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1131 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1132 cur = close;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1133 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1134 } else if (in_attr) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1135 const char *close = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1136
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1137 while (*close && *close != '>' && *close != '"' &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1138 *close != '\'' && *close != ' ' && *close != '=')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1139 close++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1140
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1141 /* 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
1142 * 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
1143 * 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
1144 * so we can get outta here */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1145 switch (*close) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1146 case '"':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1147 case '\'':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1148 in_quotes = close;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1149 case '=':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1150 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1151 size_t len = close - cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1152
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1153 /* don't store a blank attribute name */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1154 if (len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1155 g_free(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1156 name = g_ascii_strdown(cur, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1157 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1158
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1159 in_attr = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1160 cur = close + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1161 break;
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 case ' ':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1164 case '>':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1165 in_attr = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1166 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1167 cur = close;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1168 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1169 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1170 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1171 switch (*cur) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1172 case ' ':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1173 /* swallow extra spaces inside tag */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1174 while (*cur && *cur == ' ') cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1175 in_attr = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1176 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1177 case '>':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1178 found = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1179 *end = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1180 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1181 case '"':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1182 case '\'':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1183 in_quotes = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1184 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1185 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1186 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1187 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1188 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1189 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1190 /* 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
1191 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
1192 *start = cur;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1193 cur = cur + needlelen + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1194
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1195 /* 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
1196 * 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
1197 * >, 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
1198 if (*cur == ' ' || *cur == '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1199 in_tag = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1200 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1201 while (*cur && *cur != '"' && *cur != '\'' && *cur != '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1202 if (*cur == '"') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1203 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1204 while (*cur && *cur != '"')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1205 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1206 } else if (*cur == '\'') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1207 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1208 while (*cur && *cur != '\'')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1209 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1210 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1211 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1212 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1213 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1214 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1215 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1216 cur++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1217 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1218 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1219 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1220
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1221 /* 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
1222 g_free(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1223
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1224 if (found) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1225 *attributes = attribs;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1226 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1227 *start = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1228 *end = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1229 *attributes = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1230 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1231
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1232 return found;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1235 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1236 purple_markup_extract_info_field(const char *str, int len, PurpleNotifyUserInfo *user_info,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1237 const char *start_token, int skip,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1238 const char *end_token, char check_value,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1239 const char *no_value_token,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1240 const char *display_name, gboolean is_link,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1241 const char *link_prefix,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1242 PurpleInfoFieldFormatCallback format_cb)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1243 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1244 const char *p, *q;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1245
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1246 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
1247 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
1248 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
1249 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
1250 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
1251
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1252 p = strstr(str, start_token);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1253
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1254 if (p == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1255 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1256
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1257 p += strlen(start_token) + skip;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1258
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1259 if (p >= str + len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1260 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1261
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1262 if (check_value != '\0' && *p == check_value)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1263 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1264
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1265 q = strstr(p, end_token);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1266
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1267 /* Trim leading blanks */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1268 while (*p != '\n' && g_ascii_isspace(*p)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1269 p += 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1270 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1271
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1272 /* Trim trailing blanks */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1273 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
1274 q -= 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1275 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1276
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1277 /* Don't bother with null strings */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1278 if (p == q)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1279 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1280
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1281 if (q != NULL && (!no_value_token ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1282 (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
1283 strlen(no_value_token)))))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1284 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1285 GString *dest = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1286
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1287 if (is_link)
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 g_string_append(dest, "<a href=\"");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1290
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1291 if (link_prefix)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1292 g_string_append(dest, link_prefix);
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 if (format_cb != NULL)
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 char *reformatted = format_cb(p, q - p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1297 g_string_append(dest, reformatted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1298 g_free(reformatted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1299 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1300 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1301 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
1302 g_string_append(dest, "\">");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1303
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1304 if (link_prefix)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1305 g_string_append(dest, link_prefix);
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 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
1308 g_string_append(dest, "</a>");
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 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1311 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1312 if (format_cb != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1313 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1314 char *reformatted = format_cb(p, q - p);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1315 g_string_append(dest, reformatted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1316 g_free(reformatted);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1317 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1318 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1319 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
1320 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1321
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1322 purple_notify_user_info_add_pair(user_info, display_name, dest->str);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1323 g_string_free(dest, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1324
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1325 return TRUE;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1328 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1329 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1330
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1331 struct purple_parse_tag {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1332 char *src_tag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1333 char *dest_tag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1334 gboolean ignore;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1335 };
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1336
27641
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27622
diff changeset
1337 /* 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: 27622
diff changeset
1338 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: 27622
diff changeset
1339 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: 27622
diff changeset
1340 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: 27622
diff changeset
1341 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: 27622
diff changeset
1342 multiple statements when using this macro. */
27622
3edd01d04004 disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents: 27621
diff changeset
1343 #define ALLOW_TAG_ALT(x, y) if(!g_ascii_strncasecmp(c, "<" x " ", strlen("<" x " "))) { \
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1344 const char *o = c + strlen("<" x); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1345 const char *p = NULL, *q = NULL, *r = NULL; \
29958
b06f69ada7a5 Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents: 29852
diff changeset
1346 /* o = iterating over full tag \
b06f69ada7a5 Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents: 29852
diff changeset
1347 * p = > (end of tag) \
b06f69ada7a5 Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents: 29852
diff changeset
1348 * q = start of quoted bit \
b06f69ada7a5 Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents: 29852
diff changeset
1349 * r = < inside tag \
b06f69ada7a5 Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents: 29852
diff changeset
1350 */ \
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1351 GString *innards = g_string_new(""); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1352 while(o && *o) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1353 if(!q && (*o == '\"' || *o == '\'') ) { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1354 q = o; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1355 } else if(q) { \
29958
b06f69ada7a5 Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents: 29852
diff changeset
1356 if(*o == *q) { /* end of quoted bit */ \
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1357 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
1358 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
1359 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
1360 g_free(unescaped); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1361 g_free(escaped); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1362 q = NULL; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1363 } else if(*c == '\\') { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1364 o++; \
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 } else if(*o == '<') { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1367 r = o; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1368 } else if(*o == '>') { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1369 p = o; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1370 break; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1371 } else { \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1372 innards = g_string_append_c(innards, *o); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1373 } \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1374 o++; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1375 } \
29958
b06f69ada7a5 Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents: 29852
diff changeset
1376 if(p && !r) { /* got an end of tag and no other < earlier */\
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1377 if(*(p-1) != '/') { \
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1378 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1); \
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1379 pt->src_tag = x; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1380 pt->dest_tag = y; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1381 tags = g_list_prepend(tags, pt); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1382 } \
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1383 if(xhtml) { \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1384 xhtml = g_string_append(xhtml, "<" y); \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1385 xhtml = g_string_append(xhtml, innards->str); \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1386 xhtml = g_string_append_c(xhtml, '>'); \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1387 } \
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1388 c = p + 1; \
29958
b06f69ada7a5 Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents: 29852
diff changeset
1389 } else { /* got end of tag with earlier < *or* didn't get anything */ \
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1390 if(xhtml) \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1391 xhtml = g_string_append(xhtml, "&lt;"); \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1392 if(plain) \
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1393 plain = g_string_append_c(plain, '<'); \
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1394 c++; \
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 g_string_free(innards, TRUE); \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1397 continue; \
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1398 } \
27620
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1399 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: 27589
diff changeset
1400 (*(c+strlen("<" x)) == '>' || \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1401 !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: 27589
diff changeset
1402 if(xhtml) \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1403 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: 27589
diff changeset
1404 c += strlen("<" x); \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1405 if(*c != '/') { \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1406 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: 27589
diff changeset
1407 pt->src_tag = x; \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1408 pt->dest_tag = y; \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1409 tags = g_list_prepend(tags, pt); \
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1410 if(xhtml) \
27620
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1411 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: 27589
diff changeset
1412 } else { \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1413 if(xhtml) \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1414 xhtml = g_string_append(xhtml, "/>");\
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1415 } \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1416 c = strchr(c, '>') + 1; \
c800bdb5ebbc Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents: 27589
diff changeset
1417 continue; \
27634
91333c6c16ef 567c0647 introduced an extra backslash at the end of ALLOW_TAG_ALT
Ka-Hing Cheung <khc@hxbc.us>
parents: 27633
diff changeset
1418 }
27641
1316f2b180be Make a note about these ALLOW_TAG* macros so people don't do stuff like
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27622
diff changeset
1419 /* Don't forget to check the note above for ALLOW_TAG_ALT. */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1420 #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
1421 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1422 purple_markup_html_to_xhtml(const char *html, char **xhtml_out,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1423 char **plain_out)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1424 {
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1425 GString *xhtml = NULL;
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1426 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
1427 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
1428 GString *cdata = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1429 GList *tags = NULL, *tag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1430 const char *c = html;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1431 char quote = '\0';
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1432
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1433 #define CHECK_QUOTE(ptr) if (*(ptr) == '\'' || *(ptr) == '\"') \
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1434 quote = *(ptr++); \
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1435 else \
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1436 quote = '\0';
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1437
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1438 #define VALID_CHAR(ptr) (*(ptr) && *(ptr) != quote && (quote || (*(ptr) != ' ' && *(ptr) != '>')))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1439
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1440 g_return_if_fail(xhtml_out != NULL || plain_out != NULL);
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1441
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1442 if(xhtml_out)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1443 xhtml = g_string_new("");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1444 if(plain_out)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1445 plain = g_string_new("");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1446
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1447 while(c && *c) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1448 if(*c == '<') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1449 if(*(c+1) == '/') { /* closing tag */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1450 tag = tags;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1451 while(tag) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1452 struct purple_parse_tag *pt = tag->data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1453 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
1454 c += strlen(pt->src_tag) + 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1455 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1456 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1457 tag = tag->next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1458 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1459 if(tag) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1460 while(tags) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1461 struct purple_parse_tag *pt = tags->data;
28906
68bc7c617fa0 Fix a corner case where purple_markup_html_to_xhtml generated malformed XHTML.
Paul Aurich <paul@darkrain42.org>
parents: 28285
diff changeset
1462 if(xhtml && !pt->ignore)
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1463 g_string_append_printf(xhtml, "</%s>", pt->dest_tag);
25894
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: 25890
diff changeset
1464 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
1465 /* 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
1466 if (cdata && url &&
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1467 (!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
1468 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
1469 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
1470 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
1471 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
1472 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
1473 }
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
1474
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
1475 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1476 if(tags == tag)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1477 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1478 tags = g_list_remove(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1479 g_free(pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1480 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1481 g_free(tag->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1482 tags = g_list_remove(tags, tag->data);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1483 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1484 /* a closing tag we weren't expecting...
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1485 * 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
1486 * just a </ we'll escape it properly */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1487 const char *end = c+2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1488 while(*end && g_ascii_isalpha(*end))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1489 end++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1490 if(*end == '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1491 c = end+1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1492 } else {
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1493 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1494 xhtml = g_string_append(xhtml, "&lt;");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1495 if(plain)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1496 plain = g_string_append_c(plain, '<');
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1497 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1498 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1499 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1500 } else { /* opening tag */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1501 ALLOW_TAG("blockquote");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1502 ALLOW_TAG("cite");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1503 ALLOW_TAG("div");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1504 ALLOW_TAG("em");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1505 ALLOW_TAG("h1");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1506 ALLOW_TAG("h2");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1507 ALLOW_TAG("h3");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1508 ALLOW_TAG("h4");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1509 ALLOW_TAG("h5");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1510 ALLOW_TAG("h6");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1511 /* we only allow html to start the message */
27622
3edd01d04004 disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents: 27621
diff changeset
1512 if(c == html) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1513 ALLOW_TAG("html");
27622
3edd01d04004 disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents: 27621
diff changeset
1514 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1515 ALLOW_TAG_ALT("i", "em");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1516 ALLOW_TAG_ALT("italic", "em");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1517 ALLOW_TAG("li");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1518 ALLOW_TAG("ol");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1519 ALLOW_TAG("p");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1520 ALLOW_TAG("pre");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1521 ALLOW_TAG("q");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1522 ALLOW_TAG("span");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1523 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
1524
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
1525
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1526 /* 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
1527 * 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
1528 * 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
1529 * 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
1530 if((!g_ascii_strncasecmp(c, "<br", 3)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1531 || !g_ascii_strncasecmp(c, "<hr", 3))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1532 && (*(c+3) == '>' ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1533 !g_ascii_strncasecmp(c+3, "/>", 2) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1534 !g_ascii_strncasecmp(c+3, " />", 3))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1535 c = strchr(c, '>') + 1;
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1536 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1537 xhtml = g_string_append(xhtml, "<br/>");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1538 if(plain && *c != '\n')
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1539 plain = g_string_append_c(plain, '\n');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1540 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1541 }
22191
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1542 if(!g_ascii_strncasecmp(c, "<b>", 3) || !g_ascii_strncasecmp(c, "<bold>", strlen("<bold>")) || !g_ascii_strncasecmp(c, "<strong>", strlen("<strong>"))) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1543 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
1544 if (*(c+2) == '>')
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1545 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
1546 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
1547 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
1548 else
3634d27ec6f1 Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents: 22089
diff changeset
1549 pt->src_tag = "strong";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1550 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1551 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1552 c = strchr(c, '>') + 1;
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1553 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1554 xhtml = g_string_append(xhtml, "<span style='font-weight: bold;'>");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1555 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1556 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1557 if(!g_ascii_strncasecmp(c, "<u>", 3) || !g_ascii_strncasecmp(c, "<underline>", strlen("<underline>"))) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1558 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1559 pt->src_tag = *(c+2) == '>' ? "u" : "underline";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1560 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1561 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1562 c = strchr(c, '>') + 1;
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1563 if (xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1564 xhtml = g_string_append(xhtml, "<span style='text-decoration: underline;'>");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1565 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1566 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1567 if(!g_ascii_strncasecmp(c, "<s>", 3) || !g_ascii_strncasecmp(c, "<strike>", strlen("<strike>"))) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1568 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1569 pt->src_tag = *(c+2) == '>' ? "s" : "strike";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1570 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1571 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1572 c = strchr(c, '>') + 1;
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1573 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1574 xhtml = g_string_append(xhtml, "<span style='text-decoration: line-through;'>");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1575 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1576 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1577 if(!g_ascii_strncasecmp(c, "<sub>", 5)) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1578 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1579 pt->src_tag = "sub";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1580 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1581 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1582 c = strchr(c, '>') + 1;
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1583 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1584 xhtml = g_string_append(xhtml, "<span style='vertical-align:sub;'>");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1585 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1586 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1587 if(!g_ascii_strncasecmp(c, "<sup>", 5)) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1588 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1589 pt->src_tag = "sup";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1590 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1591 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1592 c = strchr(c, '>') + 1;
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1593 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1594 xhtml = g_string_append(xhtml, "<span style='vertical-align:super;'>");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1595 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1596 }
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1597 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: 23142
diff changeset
1598 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
1599 GString *src = NULL, *alt = NULL;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1600 while (*p && *p != '>') {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1601 if (!g_ascii_strncasecmp(p, "src=", 4)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1602 const char *q = p + 4;
22864
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1603 if (src)
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1604 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
1605 src = g_string_new("");
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1606 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1607 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
1608 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
1609 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
1610 }
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
1611 p = q;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1612 } else if (!g_ascii_strncasecmp(p, "alt=", 4)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1613 const char *q = p + 4;
22864
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1614 if (alt)
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1615 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
1616 alt = g_string_new("");
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1617 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1618 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
1619 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
1620 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
1621 }
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
1622 p = q;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1623 } else {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1624 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
1625 }
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
1626 }
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1627 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
1628 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
1629 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
1630 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
1631 /* 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
1632 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
1633 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
1634 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
1635 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
1636 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
1637 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
1638 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
1639 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
1640 }
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
1641 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
1642 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
1643 }
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1644 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: 23142
diff changeset
1645 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
1646 struct purple_parse_tag *pt;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1647 while (*p && *p != '>') {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1648 if (!g_ascii_strncasecmp(p, "href=", 5)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1649 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
1650 if (url)
45b524709475 Fix some incorrect assertions when G_DEBUG=fatal_warnings is set.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 20541
diff changeset
1651 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
1652 url = g_string_new("");
22864
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1653 if (cdata)
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
1654 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
1655 cdata = g_string_new("");
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1656 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1657 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
1658 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
1659 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
1660 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
1661 else
39231317310a Escape any un-escaped entities in purple_markup_html_to_xhtml when parsing
Stu Tomlinson <stu@nosnilmot.com>
parents: 21284
diff changeset
1662 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
1663 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
1664 }
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
1665 p = q;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1666 } else {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1667 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
1668 }
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 }
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1670 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
1671 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
1672 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
1673 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
1674 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
1675 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
1676 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
1677 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
1678 if(xhtml)
26881
795606e2f7c6 According to RFC 1738, "'" is a valid character in a URL.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 26772
diff changeset
1679 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
1680 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
1681 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1682 if(!g_ascii_strncasecmp(c, "<font", 5) && (*(c+5) == '>' || *(c+5) == ' ')) {
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1683 const char *p = c + 5;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1684 GString *style = g_string_new("");
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1685 struct purple_parse_tag *pt;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1686 while (*p && *p != '>') {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1687 if (!g_ascii_strncasecmp(p, "back=", 5)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1688 const char *q = p + 5;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1689 GString *color = g_string_new("");
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1690 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1691 while (VALID_CHAR(q)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1692 color = g_string_append_c(color, *q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1693 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1694 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1695 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
1696 g_string_free(color, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1697 p = q;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1698 } else if (!g_ascii_strncasecmp(p, "color=", 6)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1699 const char *q = p + 6;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1700 GString *color = g_string_new("");
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1701 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1702 while (VALID_CHAR(q)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1703 color = g_string_append_c(color, *q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1704 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1705 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1706 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
1707 g_string_free(color, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1708 p = q;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1709 } else if (!g_ascii_strncasecmp(p, "face=", 5)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1710 const char *q = p + 5;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1711 GString *face = g_string_new("");
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1712 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1713 while (VALID_CHAR(q)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1714 face = g_string_append_c(face, *q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1715 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1716 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1717 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
1718 g_string_free(face, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1719 p = q;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1720 } else if (!g_ascii_strncasecmp(p, "size=", 5)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1721 const char *q = p + 5;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1722 int sz;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1723 const char *size = "medium";
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1724 CHECK_QUOTE(q);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1725 sz = atoi(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1726 switch (sz)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1727 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1728 case 1:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1729 size = "xx-small";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1730 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1731 case 2:
24863
3d3376237a7c Change the font size mapping table in purple_markup_html_to_xhtml() to
Mark Doliner <mark@kingant.net>
parents: 24841
diff changeset
1732 size = "small";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1733 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1734 case 3:
24863
3d3376237a7c Change the font size mapping table in purple_markup_html_to_xhtml() to
Mark Doliner <mark@kingant.net>
parents: 24841
diff changeset
1735 size = "medium";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1736 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1737 case 4:
24863
3d3376237a7c Change the font size mapping table in purple_markup_html_to_xhtml() to
Mark Doliner <mark@kingant.net>
parents: 24841
diff changeset
1738 size = "large";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1739 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1740 case 5:
24863
3d3376237a7c Change the font size mapping table in purple_markup_html_to_xhtml() to
Mark Doliner <mark@kingant.net>
parents: 24841
diff changeset
1741 size = "x-large";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1742 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1743 case 6:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1744 case 7:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1745 size = "xx-large";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1746 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1747 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1748 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1749 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1750 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
1751 p = q;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1752 } else {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1753 p++;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1754 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1755 }
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1756 if ((c = strchr(p, '>')) != NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1757 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1758 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1759 c = p;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1760 pt = g_new0(struct purple_parse_tag, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1761 pt->src_tag = "font";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1762 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1763 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
1764 if(style->len && xhtml)
18046
58e28ccf08e6 merge of '9d95292d55daedb7f74c7df323ad2c69d347d384'
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18043 18042
diff changeset
1765 g_string_append_printf(xhtml, "<span style='%s'>", g_strstrip(style->str));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1766 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1767 pt->ignore = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1768 g_string_free(style, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1769 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1770 }
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1771 if (!g_ascii_strncasecmp(c, "<body ", 6)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1772 const char *p = c + 6;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1773 gboolean did_something = FALSE;
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1774 while (*p && *p != '>') {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1775 if (!g_ascii_strncasecmp(p, "bgcolor=", 8)) {
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1776 const char *q = p + 8;
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1777 struct purple_parse_tag *pt = g_new0(struct purple_parse_tag, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1778 GString *color = g_string_new("");
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1779 CHECK_QUOTE(q);
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1780 while (VALID_CHAR(q)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1781 color = g_string_append_c(color, *q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1782 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1783 }
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1784 if (xhtml)
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1785 g_string_append_printf(xhtml, "<span style='background: %s;'>", g_strstrip(color->str));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1786 g_string_free(color, TRUE);
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1787 if ((c = strchr(p, '>')) != NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1788 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1789 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1790 c = p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1791 pt->src_tag = "body";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1792 pt->dest_tag = "span";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1793 tags = g_list_prepend(tags, pt);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1794 did_something = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1795 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1796 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1797 p++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1798 }
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1799 if (did_something) continue;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1800 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1801 /* 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
1802 ALLOW_TAG("body");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1803 if(!g_ascii_strncasecmp(c, "<!--", strlen("<!--"))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1804 char *p = strstr(c + strlen("<!--"), "-->");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1805 if(p) {
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1806 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1807 xhtml = g_string_append(xhtml, "<!--");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1808 c += strlen("<!--");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1809 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1810 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1811 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1812
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1813 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1814 xhtml = g_string_append(xhtml, "&lt;");
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1815 if(plain)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1816 plain = g_string_append_c(plain, '<');
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1817 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1818 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1819 } else if(*c == '&') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1820 char buf[7];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1821 const char *pln;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1822 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1823
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
1824 if ((pln = purple_markup_unescape_entity(c, &len)) == NULL) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1825 len = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1826 g_snprintf(buf, sizeof(buf), "%c", *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1827 pln = buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1828 }
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1829 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1830 xhtml = g_string_append_len(xhtml, c, len);
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1831 if(plain)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1832 plain = g_string_append(plain, pln);
21185
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1833 if(cdata)
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1834 cdata = g_string_append_len(cdata, c, len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1835 c += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1836 } else {
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1837 if(xhtml)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1838 xhtml = g_string_append_c(xhtml, *c);
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1839 if(plain)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1840 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
1841 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
1842 cdata = g_string_append_c(cdata, *c);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1843 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1844 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1845 }
17481
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1846 if(xhtml) {
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1847 for (tag = tags; tag ; tag = tag->next) {
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1848 struct purple_parse_tag *pt = tag->data;
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1849 if(!pt->ignore)
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1850 g_string_append_printf(xhtml, "</%s>", pt->dest_tag);
6608a7ab0fd9 In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents: 17480
diff changeset
1851 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1852 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1853 g_list_free(tags);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1854 if(xhtml_out)
17480
a7a8e4245b33 Remove needless string duplication.
Richard Laager <rlaager@wiktel.com>
parents: 17450
diff changeset
1855 *xhtml_out = g_string_free(xhtml, FALSE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1856 if(plain_out)
17480
a7a8e4245b33 Remove needless string duplication.
Richard Laager <rlaager@wiktel.com>
parents: 17450
diff changeset
1857 *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
1858 if(url)
481eb37730bf This was crashing for me when writing a system message when logging
Mark Doliner <mark@kingant.net>
parents: 18493
diff changeset
1859 g_string_free(url, TRUE);
21185
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1860 if (cdata)
4a0f841e6f26 applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents: 21177
diff changeset
1861 g_string_free(cdata, TRUE);
23248
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1862 #undef CHECK_QUOTE
228d576a7dd7 Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23142
diff changeset
1863 #undef VALID_CHAR
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1864 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1865
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1866 /* The following are probably reasonable changes:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1867 * - \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
1868 * - 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
1869 * - 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
1870 * - 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
1871 * - 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
1872 * - <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
1873 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1874
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1875 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1876 purple_markup_strip_html(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1877 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1878 int i, j, k, entlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1879 gboolean visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1880 gboolean closing_td_p = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1881 gchar *str2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1882 const gchar *cdata_close_tag = NULL, *ent;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1883 gchar *href = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1884 int href_st = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1885
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1886 if(!str)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1887 return NULL;
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 str2 = g_strdup(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1890
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1891 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
1892 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1893 if (str2[i] == '<')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1894 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1895 if (cdata_close_tag)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1896 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1897 /* 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
1898 if (g_ascii_strncasecmp(str2 + i, cdata_close_tag,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1899 strlen(cdata_close_tag)) == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1900 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1901 i += strlen(cdata_close_tag) - 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1902 cdata_close_tag = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1903 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1904 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1905 }
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
1906 else if (g_ascii_strncasecmp(str2 + i, "<td", 3) == 0 && closing_td_p)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1907 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1908 str2[j++] = '\t';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1909 visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1910 }
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
1911 else if (g_ascii_strncasecmp(str2 + i, "</td>", 5) == 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1912 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1913 closing_td_p = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1914 visible = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1915 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1916 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1917 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1918 closing_td_p = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1919 visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1920 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1921
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1922 k = i + 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1923
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1924 if(g_ascii_isspace(str2[k]))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1925 visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1926 else if (str2[k])
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1927 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1928 /* 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
1929 * 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
1930 * inside quoted attributes will screw us up)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1931 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1932 while (str2[k] && str2[k] != '<' && str2[k] != '>')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1933 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1934 k++;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1937 /* 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
1938 * 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
1939 if (g_ascii_strncasecmp(str2 + i, "<a", 2) == 0 &&
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1940 g_ascii_isspace(str2[i+2]))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1941 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1942 int st; /* start of href, inclusive [ */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1943 int end; /* end of href, exclusive ) */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1944 char delim = ' ';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1945 /* Find start of href */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1946 for (st = i + 3; st < k; st++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1947 {
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
1948 if (g_ascii_strncasecmp(str2+st, "href=", 5) == 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1949 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1950 st += 5;
16169
49a1fed5ee37 This was causing problems with jabber in finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16153
diff changeset
1951 if (str2[st] == '"' || str2[st] == '\'')
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1952 {
16169
49a1fed5ee37 This was causing problems with jabber in finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16153
diff changeset
1953 delim = str2[st];
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1954 st++;
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 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1957 }
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 /* find end of address */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1960 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
1961 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1962 /* 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
1963 }
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 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
1966 * already one saved, kill it. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1967 if (st < k)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1968 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1969 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1970 g_free(href);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1971 tmp = g_strndup(str2 + st, end - st);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
1972 href = purple_unescape_html(tmp);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1973 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1974 href_st = j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1975 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1976 }
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 /* 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
1979 * 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
1980 else if (href != NULL && g_ascii_strncasecmp(str2 + i, "</a>", 4) == 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1981 {
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 size_t hrlen = strlen(href);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1984
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1985 /* 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
1986 if ((hrlen != j - href_st ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1987 strncmp(str2 + href_st, href, hrlen)) &&
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1988 (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
1989 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
1990 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1991 str2[j++] = ' ';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1992 str2[j++] = '(';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1993 g_memmove(str2 + j, href, hrlen);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1994 j += hrlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1995 str2[j++] = ')';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1996 g_free(href);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1997 href = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1998 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1999 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2000
29641
41142f2bcafb Ignore some tags at the beginning of a message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29359
diff changeset
2001 /* Check for tags which should be mapped to newline (but ignore some of
41142f2bcafb Ignore some tags at the beginning of a message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29359
diff changeset
2002 * the tags at the beginning of the text) */
41142f2bcafb Ignore some tags at the beginning of a message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29359
diff changeset
2003 else if ((j && (g_ascii_strncasecmp(str2 + i, "<p>", 3) == 0
41142f2bcafb Ignore some tags at the beginning of a message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29359
diff changeset
2004 || g_ascii_strncasecmp(str2 + i, "<tr", 3) == 0
41142f2bcafb Ignore some tags at the beginning of a message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29359
diff changeset
2005 || g_ascii_strncasecmp(str2 + i, "<hr", 3) == 0
41142f2bcafb Ignore some tags at the beginning of a message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29359
diff changeset
2006 || g_ascii_strncasecmp(str2 + i, "<li", 3) == 0
41142f2bcafb Ignore some tags at the beginning of a message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29359
diff changeset
2007 || g_ascii_strncasecmp(str2 + i, "<div", 4) == 0))
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2008 || 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
2009 || g_ascii_strncasecmp(str2 + i, "</table>", 8) == 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2010 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2011 str2[j++] = '\n';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2012 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2013 /* 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
2014 #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
2015 else if (g_ascii_strncasecmp(str2 + i, "<option", 7) == 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2016 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2017 /* 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
2018 cdata_close_tag = "</option>";
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 #endif
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2021 else if (g_ascii_strncasecmp(str2 + i, "<script", 7) == 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2022 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2023 cdata_close_tag = "</script>";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2024 }
18397
e122b631a657 Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents: 18259
diff changeset
2025 else if (g_ascii_strncasecmp(str2 + i, "<style", 6) == 0)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2026 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2027 cdata_close_tag = "</style>";
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 /* 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
2030 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
2031 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2032 }
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 else if (cdata_close_tag)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2035 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2036 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2037 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2038 else if (!g_ascii_isspace(str2[i]))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2039 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2040 visible = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2041 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2042
16084
a5a831a5f186 Patch cleanups:
Richard Laager <rlaager@wiktel.com>
parents: 16083
diff changeset
2043 if (str2[i] == '&' && (ent = purple_markup_unescape_entity(str2 + i, &entlen)) != NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2044 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2045 while (*ent)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2046 str2[j++] = *ent++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2047 i += entlen - 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2048 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2049 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2050
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2051 if (visible)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2052 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
2053 }
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 g_free(href);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2056
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2057 str2[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2058
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2059 return str2;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2062 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2063 badchar(char c)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2064 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2065 switch (c) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2066 case ' ':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2067 case ',':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2068 case '\0':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2069 case '\n':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2070 case '\r':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2071 case '<':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2072 case '>':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2073 case '"':
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2074 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2075 default:
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2076 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2077 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2078 }
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 static gboolean
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2081 badentity(const char *c)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2082 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2083 if (!g_ascii_strncasecmp(c, "&lt;", 4) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2084 !g_ascii_strncasecmp(c, "&gt;", 4) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2085 !g_ascii_strncasecmp(c, "&quot;", 6)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2086 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2087 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2088 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2089 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2090
30158
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2091 static const char *
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2092 process_link(GString *ret,
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2093 const char *start, const char *c,
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2094 int matchlen,
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2095 const char *urlprefix,
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2096 int inside_paren)
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2097 {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2098 char *url_buf, *tmpurlbuf;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2099 const char *t;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2100
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2101 for (t = c;; t++) {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2102 if (!badchar(*t) && !badentity(t))
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2103 continue;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2104
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2105 if (t - c == matchlen)
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2106 break;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2107
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2108 if (*t == ',' && *(t + 1) != ' ') {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2109 continue;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2110 }
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2111
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2112 if (t > start && *(t - 1) == '.')
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2113 t--;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2114 if (t > start && *(t - 1) == ')' && inside_paren > 0)
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2115 t--;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2116
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2117 url_buf = g_strndup(c, t - c);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2118 tmpurlbuf = purple_unescape_html(url_buf);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2119 g_string_append_printf(ret, "<A HREF=\"%s%s\">%s</A>",
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2120 urlprefix,
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2121 tmpurlbuf, url_buf);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2122 g_free(tmpurlbuf);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2123 g_free(url_buf);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2124 return t;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2125 }
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2126
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2127 return c;
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2128 }
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2129
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2130 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2131 purple_markup_linkify(const char *text)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2132 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2133 const char *c, *t, *q = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2134 char *tmpurlbuf, *url_buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2135 gunichar g;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2136 gboolean inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2137 int inside_paren = 0;
23652
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23538
diff changeset
2138 GString *ret;
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23538
diff changeset
2139
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23538
diff changeset
2140 if (text == NULL)
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23538
diff changeset
2141 return NULL;
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23538
diff changeset
2142
27eacd38c721 Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23538
diff changeset
2143 ret = g_string_new("");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2144
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2145 c = text;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2146 while (*c) {
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 if(*c == '(' && !inside_html) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2149 inside_paren++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2150 ret = g_string_append_c(ret, *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2151 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2152 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2153
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2154 if(inside_html) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2155 if(*c == '>') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2156 inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2157 } else if(!q && (*c == '\"' || *c == '\'')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2158 q = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2159 } else if(q) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2160 if(*c == *q)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2161 q = NULL;
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 } else if(*c == '<') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2164 inside_html = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2165 if (!g_ascii_strncasecmp(c, "<A", 2)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2166 while (1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2167 if (!g_ascii_strncasecmp(c, "/A>", 3)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2168 inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2169 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2170 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2171 ret = g_string_append_c(ret, *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2172 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2173 if (!(*c))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2174 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2175 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2176 }
30158
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2177 } else if (!g_ascii_strncasecmp(c, "http://", 7)) {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2178 c = process_link(ret, text, c, 7, "", inside_paren);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2179 } else if (!g_ascii_strncasecmp(c, "https://", 8)) {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2180 c = process_link(ret, text, c, 8, "", inside_paren);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2181 } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2182 c = process_link(ret, text, c, 6, "", inside_paren);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2183 } else if (!g_ascii_strncasecmp(c, "sftp://", 7)) {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2184 c = process_link(ret, text, c, 7, "", inside_paren);
30159
f06be7aff71c Linkify file://
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30158
diff changeset
2185 } else if (!g_ascii_strncasecmp(c, "file://", 7)) {
f06be7aff71c Linkify file://
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30158
diff changeset
2186 c = process_link(ret, text, c, 7, "", inside_paren);
30158
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2187 } else if (!g_ascii_strncasecmp(c, "www.", 4) && c[4] != '.' && (c == text || badchar(c[-1]) || badentity(c-1))) {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2188 c = process_link(ret, text, c, 4, "http://", inside_paren);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2189 } else if (!g_ascii_strncasecmp(c, "ftp.", 4) && c[4] != '.' && (c == text || badchar(c[-1]) || badentity(c-1))) {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2190 c = process_link(ret, text, c, 4, "ftp://", inside_paren);
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2191 } else if (!g_ascii_strncasecmp(c, "xmpp:", 5) && (c == text || badchar(c[-1]) || badentity(c-1))) {
844181ded506 Remove code duplications, and some invalid memory reads.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 29958
diff changeset
2192 c = process_link(ret, text, c, 5, "", inside_paren);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2193 } 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
2194 t = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2195 while (1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2196 if (badchar(*t) || badentity(t)) {
17158
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2197 char *d;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2198 if (t - c == 7) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2199 break;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2200 }
30160
7f021333e41f Prevent an invalid read when a message starts with 'mailto:'.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30159
diff changeset
2201 if (t > text && *(t - 1) == '.')
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2202 t--;
17158
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2203 if ((d = strstr(c + 7, "?")) != NULL && d < t)
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2204 url_buf = g_strndup(c + 7, d - c - 7);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2205 else
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2206 url_buf = g_strndup(c + 7, t - c - 7);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2207 if (!purple_email_is_valid(url_buf)) {
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2208 g_free(url_buf);
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2209 break;
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2210 }
fdd52f7651c7 Linkify xmpp: URIs
Stu Tomlinson <stu@nosnilmot.com>
parents: 17035
diff changeset
2211 g_free(url_buf);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2212 url_buf = g_strndup(c, t - c);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2213 tmpurlbuf = purple_unescape_html(url_buf);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2214 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
2215 tmpurlbuf, url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2216 g_free(url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2217 g_free(tmpurlbuf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2218 c = t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2219 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2220 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2221 t++;
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 } else if (c != text && (*c == '@')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2224 int flag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2225 GString *gurl_buf = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2226 const char illegal_chars[] = "!@#$%^&*()[]{}/|\\<>\":;\r\n \0";
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 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
2229 flag = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2230 else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2231 flag = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2232 gurl_buf = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2233 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2234
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2235 t = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2236 while (flag) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2237 /* 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
2238 g = g_utf8_get_char(t);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2239 if (badchar(*t) || (g >= 127) || (*t == '(') ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2240 ((*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
2241 !g_ascii_strncasecmp(t - 3, "&gt;", 4))) ||
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2242 (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
2243 /* 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
2244 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
2245 ret = g_string_append_unichar(ret, g);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2246 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2247 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2248 g_string_prepend_unichar(gurl_buf, g);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2249 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
2250 if (t < text) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2251 ret = g_string_assign(ret, "");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2252 break;
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2256
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2257 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
2258
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2259 while (flag) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2260 /* 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
2261 g = g_utf8_get_char(t);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2262 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
2263 char *d;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2264
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2265 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
2266
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2267 /* strip off trailing periods */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2268 if (strlen(url_buf) > 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2269 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
2270 *d = '\0';
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
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2273 tmpurlbuf = purple_unescape_html(url_buf);
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2274 if (purple_email_is_valid(tmpurlbuf)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2275 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
2276 tmpurlbuf, url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2277 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2278 g_string_append(ret, url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2279 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2280 g_free(url_buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2281 g_free(tmpurlbuf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2282 c = t;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2283
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2284 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2285 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2286 g_string_append_unichar(gurl_buf, g);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2287 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
2288 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2289 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2290 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2291
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2292 if(*c == ')' && !inside_html) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2293 inside_paren--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2294 ret = g_string_append_c(ret, *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2295 c++;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2298 if (*c == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2299 break;
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 ret = g_string_append_c(ret, *c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2302 c++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2303
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2304 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2305 return g_string_free(ret, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2306 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2307
29359
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2308 char *purple_unescape_text(const char *in)
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2309 {
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2310 GString *ret;
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2311 const char *c = in;
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2312
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2313 if (in == NULL)
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2314 return NULL;
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2315
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2316 ret = g_string_new("");
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2317 while (*c) {
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2318 int len;
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2319 const char *ent;
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2320
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2321 if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2322 g_string_append(ret, ent);
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2323 c += len;
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2324 } else {
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2325 g_string_append_c(ret, *c);
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2326 c++;
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2327 }
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2328 }
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2329
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2330 return g_string_free(ret, FALSE);
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2331 }
05d727f76ca9 Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents: 29348
diff changeset
2332
27268
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2333 char *purple_unescape_html(const char *html)
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2334 {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2335 GString *ret;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2336 const char *c = html;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2337
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2338 if (html == NULL)
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2339 return NULL;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2340
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2341 ret = g_string_new("");
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2342 while (*c) {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2343 int len;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2344 const char *ent;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2345
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2346 if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2347 g_string_append(ret, ent);
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2348 c += len;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2349 } else if (!strncmp(c, "<br>", 4)) {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2350 g_string_append_c(ret, '\n');
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2351 c += 4;
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2352 } else {
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2353 g_string_append_c(ret, *c);
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2354 c++;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2355 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2356 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2357
27268
c0075538109b Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents: 27246
diff changeset
2358 return g_string_free(ret, FALSE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2359 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2360
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2361 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2362 purple_markup_slice(const char *str, guint x, guint y)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2363 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2364 GString *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2365 GQueue *q;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2366 guint z = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2367 gboolean appended = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2368 gunichar c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2369 char *tag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2370
24420
3ef4625689e0 Fix CID #389
Richard Laager <rlaager@wiktel.com>
parents: 24274
diff changeset
2371 g_return_val_if_fail(str != NULL, NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2372 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
2373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2374 if (x == y)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2375 return g_strdup("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2376
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2377 ret = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2378 q = g_queue_new();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2379
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2380 while (*str && (z < y)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2381 c = g_utf8_get_char(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2382
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2383 if (c == '<') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2384 char *end = strchr(str, '>');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2385
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2386 if (!end) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2387 g_string_free(ret, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2388 while ((tag = g_queue_pop_head(q)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2389 g_free(tag);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2390 g_queue_free(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2391 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2392 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2393
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2394 if (!g_ascii_strncasecmp(str, "<img ", 5)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2395 z += strlen("[Image]");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2396 } 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
2397 z += 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2398 } 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
2399 z += strlen("\n---\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2400 } else if (!g_ascii_strncasecmp(str, "</", 2)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2401 /* pop stack */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2402 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2403
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2404 tmp = g_queue_pop_head(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2405 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2406 /* z += 0; */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2407 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2408 /* push it unto the stack */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2409 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2410
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2411 tmp = g_strndup(str, end - str + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2412 g_queue_push_head(q, tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2413 /* z += 0; */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2414 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2415
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2416 if (z >= x) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2417 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
2418 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2419
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2420 str = end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2421 } else if (c == '&') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2422 char *end = strchr(str, ';');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2423 if (!end) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2424 g_string_free(ret, TRUE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2425 while ((tag = g_queue_pop_head(q)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2426 g_free(tag);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2427 g_queue_free(q);
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 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2430 }
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 if (z >= x)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2433 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
2434
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2435 z++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2436 str = end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2437 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2438 if (z == x && z > 0 && !appended) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2439 GList *l = q->tail;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2440
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2441 while (l) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2442 tag = l->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2443 g_string_append(ret, tag);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2444 l = l->prev;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2445 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2446 appended = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2447 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2448
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2449 if (z >= x)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2450 g_string_append_unichar(ret, c);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2451 z++;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2454 str = g_utf8_next_char(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2455 }
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 while ((tag = g_queue_pop_head(q))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2458 char *name;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2459
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2460 name = purple_markup_get_tag_name(tag);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2461 g_string_append_printf(ret, "</%s>", name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2462 g_free(name);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2463 g_free(tag);
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2466 g_queue_free(q);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2467 return g_string_free(ret, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2468 }
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 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2471 purple_markup_get_tag_name(const char *tag)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2472 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2473 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2474 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
2475 g_return_val_if_fail(*tag == '<', NULL);
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 for (i = 1; tag[i]; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2478 if (tag[i] == '>' || tag[i] == ' ' || tag[i] == '/')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2479 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2480
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2481 return g_strndup(tag+1, i-1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2482 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2483
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2484 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2485 * Path/Filename Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2486 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2487 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2488 purple_home_dir(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2489 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2490 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2491 return g_get_home_dir();
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2492 #else
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2493 return wpurple_data_dir();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2494 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2495 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2496
16367
6a9ae99e7050 Use ~/.purple only, never ~/.gaim. This is a revert of the functional
Richard Laager <rlaager@wiktel.com>
parents: 16169
diff changeset
2497 /* Returns the argument passed to -c IFF it was present, or ~/.purple. */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2498 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2499 purple_user_dir(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2500 {
18147
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2501 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
2502 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
2503 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
2504 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
2505
2ab6b55ffa3d Rename the internal home_dir variable to user_dir to match the function and
Richard Laager <rlaager@wiktel.com>
parents: 20074
diff changeset
2506 return user_dir;
15373
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
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2509 void purple_util_set_user_dir(const char *dir)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2510 {
18147
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2511 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
2512
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2513 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
2514 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
2515 else
5653692dcf79 Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents: 18129
diff changeset
2516 custom_user_dir = NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2517 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2518
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2519 int purple_build_dir (const char *path, int mode)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2520 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2521 return g_mkdir_with_parents(path, mode);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2522 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2523
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 * 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
2526 * 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
2527 * 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
2528 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2529 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
2530 purple_util_write_data_to_file(const char *filename, const char *data, gssize size)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2531 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2532 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
2533 gchar *filename_full;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2534 gboolean ret = FALSE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2535
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2536 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
2537
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2538 purple_debug_info("util", "Writing file %s to directory %s\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2539 filename, user_dir);
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 /* Ensure the user directory exists */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2542 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
2543 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2544 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
2545 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2546 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
2547 user_dir, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2548 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2549 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2550 }
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 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
2553
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
2554 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
2555
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2556 g_free(filename_full);
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2557 return ret;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2558 }
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2559
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2560 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
2561 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
2562 {
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2563 gchar *filename_temp;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2564 FILE *file;
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2565 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
2566 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
2567 #ifndef HAVE_FILENO
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2568 int fd;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2569 #endif
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2570
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2571 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
2572 filename_full);
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2573
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
2574 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
2575
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2576 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
2577
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2578 /* 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
2579 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
2580 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2581 if (g_unlink(filename_temp) == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2582 {
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2583 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
2584 "%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
2585 filename_temp, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2586 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2587 }
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 /* Open file */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2590 file = g_fopen(filename_temp, "wb");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2591 if (file == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2592 {
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2593 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
2594 "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
2595 filename_temp, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2596 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2597 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2598 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2599
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2600 /* 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
2601 real_size = (size == -1) ? strlen(data) : (size_t) size;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2602 byteswritten = fwrite(data, 1, real_size, file);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2603
21172
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2604 #ifdef HAVE_FILENO
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2605 /* 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
2606 * 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
2607 * 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
2608 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
2609 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
2610 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
2611 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
2612 fclose(file);
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2613 return FALSE;
abc909eeb580 jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents: 21172
diff changeset
2614 }
21172
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2615 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
2616 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
2617 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
2618 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
2619 fclose(file);
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2620 return FALSE;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2621 }
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2622 #endif
25924
584063555949 Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents: 25894
diff changeset
2623
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2624 /* Close file */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2625 if (fclose(file) != 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2626 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2627 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
2628 filename_temp, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2629 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2630 return FALSE;
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
21172
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2633 #ifndef HAVE_FILENO
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2634 /* 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
2635 * 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
2636 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
2637 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
2638 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
2639 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
2640 return FALSE;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2641 }
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2642 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
2643 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
2644 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
2645 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
2646 close(fd);
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2647 return FALSE;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2648 }
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2649 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
2650 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
2651 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
2652 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
2653 return FALSE;
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2654 }
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2655 #endif
33da7f2a30e4 Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents: 21121
diff changeset
2656
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2657 /* Ensure the file is the correct size */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2658 if (byteswritten != real_size)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2659 {
19498
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2660 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
2661 G_GSIZE_FORMAT " bytes "
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2662 "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
2663 "; 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
2664 filename_temp, byteswritten, real_size);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2665 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2666 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2667 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2668 /* Use stat to be absolutely sure. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2669 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
2670 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2671 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
2672 "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
2673 "full?\n",
7589b218f89a - Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents: 19262
diff changeset
2674 filename_temp);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2675 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2676 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2677 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2678
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2679 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2680 /* Set file permissions */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2681 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
2682 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2683 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
2684 filename_temp, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2685 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2686 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2687
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2688 /* Rename to the REAL name */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2689 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
2690 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2691 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
2692 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
2693 g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2694 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2695
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2696 g_free(filename_temp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2697
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2698 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2699 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2700
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2701 xmlnode *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2702 purple_util_read_xml_from_file(const char *filename, const char *description)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2703 {
25086
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: 23142
diff changeset
2704 return xmlnode_from_file(purple_user_dir(), filename, description, "util");
15373
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 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2708 * 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
2709 * 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
2710 * the space for the filepath.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2711 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2712 * 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
2713 * 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
2714 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2715 * 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
2716 */
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2717 static const char *purple_mkstemp_templ = {"purpleXXXXXX"};
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2718
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2719 FILE *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2720 purple_mkstemp(char **fpath, gboolean binary)
15373
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 const gchar *tmpdir;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2723 int fd;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2724 FILE *fp = NULL;
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 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
2727
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2728 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2729 if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, purple_mkstemp_templ)) != NULL) {
16858
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: 16548
diff changeset
2730 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: 16548
diff changeset
2731 if(fd == -1) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2732 purple_debug(PURPLE_DEBUG_ERROR, "purple_mkstemp",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2733 "Couldn't make \"%s\", error: %d\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2734 *fpath, errno);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2735 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2736 if((fp = fdopen(fd, "r+")) == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2737 close(fd);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2738 purple_debug(PURPLE_DEBUG_ERROR, "purple_mkstemp",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2739 "Couldn't fdopen(), error: %d\n", errno);
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 }
16858
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: 16548
diff changeset
2742
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2743 if(!fp) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2744 g_free(*fpath);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2745 *fpath = NULL;
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 } else {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2749 purple_debug(PURPLE_DEBUG_ERROR, "purple_mkstemp",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2750 "g_get_tmp_dir() failed!\n");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2751 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2752
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2753 return fp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2754 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2755
16375
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2756 const char *
16487
b8b2e35ec7c6 Fix purple_util_get_image_extension()'s data param. to be correctly marked as constant.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16475
diff changeset
2757 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
2758 {
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2759 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
2760 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
2761
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2762 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
2763 {
17491
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: 17481
diff changeset
2764 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
2765 return "gif";
17491
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: 17481
diff changeset
2766 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
2767 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
2768 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
2769 return "png";
17491
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: 17481
diff changeset
2770 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: 17481
diff changeset
2771 !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: 17481
diff changeset
2772 return "tif";
17492
647bfc2b2a7b Where did ekse come from?
Richard Laager <rlaager@wiktel.com>
parents: 17491
diff changeset
2773 else if (!strncmp((char *)data, "BM", 2))
17491
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: 17481
diff changeset
2774 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
2775 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2776
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2777 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
2778 }
391a79778f89 Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents: 16368
diff changeset
2779
26181
00c659e55902 Add a note that this function could potentially be faster.
Mark Doliner <mark@kingant.net>
parents: 25924
diff changeset
2780 /*
27404
52298a298260 Update this comment. We talked about using CRC32 on the devel list
Mark Doliner <mark@kingant.net>
parents: 27393
diff changeset
2781 * 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: 27393
diff changeset
2782 * 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: 27393
diff changeset
2783 * 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: 27393
diff changeset
2784 * replace one buddy's icon with something else.
26181
00c659e55902 Add a note that this function could potentially be faster.
Mark Doliner <mark@kingant.net>
parents: 25924
diff changeset
2785 */
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2786 char *
22311
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
2787 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: 17765
diff changeset
2788 {
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2789 PurpleCipherContext *context;
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2790 gchar digest[41];
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2791
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2792 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: 17765
diff changeset
2793 if (context == NULL)
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2794 {
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2795 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: 17765
diff changeset
2796 g_return_val_if_reached(NULL);
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2797 }
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2798
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2799 /* Hash the image data */
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2800 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: 17765
diff changeset
2801 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: 17765
diff changeset
2802 {
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2803 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: 17765
diff changeset
2804 g_return_val_if_reached(NULL);
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2805 }
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2806 purple_cipher_context_destroy(context);
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2807
22311
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
2808 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
2809 }
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
2810
02eda4bd2b22 Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22191
diff changeset
2811 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
2812 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
2813 {
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2814 /* Return the filename */
22312
f1475ca224a8 Plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22311
diff changeset
2815 char *checksum = purple_util_get_image_checksum(image_data, image_len);
f1475ca224a8 Plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22311
diff changeset
2816 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: 17765
diff changeset
2817 purple_util_get_image_extension(image_data, image_len));
22312
f1475ca224a8 Plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22311
diff changeset
2818 g_free(checksum);
f1475ca224a8 Plug a leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22311
diff changeset
2819 return filename;
18039
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2820 }
c588a4a9d287 A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents: 17765
diff changeset
2821
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2822 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2823 purple_program_is_valid(const char *program)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2824 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2825 GError *error = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2826 char **argv;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2827 gchar *progname;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2828 gboolean is_valid = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2829
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2830 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
2831 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
2832
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2833 if (!g_shell_parse_argv(program, NULL, &argv, &error)) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2834 purple_debug(PURPLE_DEBUG_ERROR, "program_is_valid",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2835 "Could not parse program '%s': %s\n",
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2836 program, error->message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2837 g_error_free(error);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2838 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2839 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2840
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2841 if (argv == NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2842 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2843 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2844
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2845 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
2846 is_valid = (progname != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2847
30555
839f3d63acab Useful snippet of debugging that helped me out.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 30426
diff changeset
2848 if(purple_debug_is_verbose())
839f3d63acab Useful snippet of debugging that helped me out.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 30426
diff changeset
2849 purple_debug_info("program_is_valid", "Tested program %s. %s.\n", program,
839f3d63acab Useful snippet of debugging that helped me out.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 30426
diff changeset
2850 is_valid ? "Valid" : "Invalid");
839f3d63acab Useful snippet of debugging that helped me out.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 30426
diff changeset
2851
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2852 g_strfreev(argv);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2853 g_free(progname);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2854
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2855 return is_valid;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2856 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2857
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2858
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2859 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2860 purple_running_gnome(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2861 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2862 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2863 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
2864
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2865 if (tmp == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2866 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2867 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2868
21580
07588cb48434 Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <stu@nosnilmot.com>
parents: 21299
diff changeset
2869 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
2870
07588cb48434 Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <stu@nosnilmot.com>
parents: 21299
diff changeset
2871 return ((tmp != NULL) && (*tmp != '\0'));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2872 #else
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 #endif
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2877 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2878 purple_running_kde(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2879 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2880 #ifndef _WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2881 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
2882 const char *session;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2883
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2884 if (tmp == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2885 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2886 g_free(tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2887
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2888 session = g_getenv("KDE_FULL_SESSION");
25894
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: 25890
diff changeset
2889 if (purple_strequal(session, "true"))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2890 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2891
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2892 /* If you run Purple from Konsole under !KDE, this will provide a
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2893 * 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
2894 * only a problem if you're running something !(KDE || GNOME) and
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2895 * you run Purple from Konsole. This really shouldn't be a problem. */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2896 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
2897 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2898 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2899 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2900 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2901
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2902 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2903 purple_running_osx(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2904 {
16487
b8b2e35ec7c6 Fix purple_util_get_image_extension()'s data param. to be correctly marked as constant.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16475
diff changeset
2905 #if defined(__APPLE__)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2906 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2907 #else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2908 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2909 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2910 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2911
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2912 typedef union purple_sockaddr {
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2913 struct sockaddr sa;
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2914 struct sockaddr_in sa_in;
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2915 #if defined(AF_INET6)
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2916 struct sockaddr_in6 sa_in6;
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2917 #endif
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2918 struct sockaddr_storage sa_stor;
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2919 } PurpleSockaddr;
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2920
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2921 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
2922 purple_fd_get_ip(int fd)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2923 {
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2924 PurpleSockaddr addr;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2925 socklen_t namelen = sizeof(addr);
29739
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2926 int family;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2927
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2928 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
2929
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2930 if (getsockname(fd, &(addr.sa), &namelen))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2931 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2932
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2933 family = addr.sa.sa_family;
29739
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2934
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2935 if (family == AF_INET) {
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2936 return g_strdup(inet_ntoa(addr.sa_in.sin_addr));
29740
5be4137c4a68 util: Bah, AF_INET6 probably isn't always available
Paul Aurich <paul@darkrain42.org>
parents: 29739
diff changeset
2937 }
5be4137c4a68 util: Bah, AF_INET6 probably isn't always available
Paul Aurich <paul@darkrain42.org>
parents: 29739
diff changeset
2938 #if defined(AF_INET6) && defined(HAVE_INET_NTOP)
5be4137c4a68 util: Bah, AF_INET6 probably isn't always available
Paul Aurich <paul@darkrain42.org>
parents: 29739
diff changeset
2939 else if (family == AF_INET6) {
29739
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2940 char host[INET6_ADDRSTRLEN];
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2941 const char *tmp;
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2942
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2943 tmp = inet_ntop(family, &(addr.sa_in6.sin6_addr), host, sizeof(host));
29739
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2944 return g_strdup(tmp);
29740
5be4137c4a68 util: Bah, AF_INET6 probably isn't always available
Paul Aurich <paul@darkrain42.org>
parents: 29739
diff changeset
2945 }
29739
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2946 #endif
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2947
983a04639c2b util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents: 29641
diff changeset
2948 return NULL;
15373
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
29741
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2951 int
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2952 purple_socket_get_family(int fd)
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2953 {
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2954 PurpleSockaddr addr;
29741
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2955 socklen_t len = sizeof(addr);
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2956
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2957 g_return_val_if_fail(fd >= 0, -1);
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2958
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2959 if (getsockname(fd, &(addr.sa), &len))
29741
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2960 return -1;
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2961
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2962 return addr.sa.sa_family;
29741
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2963 }
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2964
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2965 gboolean
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2966 purple_socket_speaks_ipv4(int fd)
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2967 {
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2968 int family;
29745
37be7bc87ab2 util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents: 29742
diff changeset
2969
29741
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2970 g_return_val_if_fail(fd >= 0, FALSE);
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2971
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2972 family = purple_socket_get_family(fd);
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2973
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2974 switch (family) {
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2975 case AF_INET:
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2976 return TRUE;
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2977 #if defined(IPV6_V6ONLY)
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2978 case AF_INET6:
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2979 {
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2980 int val = 0;
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2981 guint len = sizeof(val);
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2982
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2983 if (getsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, &len) != 0)
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2984 return FALSE;
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2985 return !val;
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2986 }
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2987 #endif
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2988 default:
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2989 return FALSE;
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2990 }
35a1cf247168 Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents: 29740
diff changeset
2991 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2992
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2993 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2994 * String Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2995 **************************************************************************/
25894
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: 25890
diff changeset
2996 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: 25890
diff changeset
2997 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: 25890
diff changeset
2998 {
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: 25890
diff changeset
2999 #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: 25890
diff changeset
3000 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: 25890
diff changeset
3001 #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: 25890
diff changeset
3002 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: 25890
diff changeset
3003 (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: 25890
diff changeset
3004 #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: 25890
diff changeset
3005 }
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: 25890
diff changeset
3006
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3007 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3008 purple_normalize(const PurpleAccount *account, const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3009 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3010 const char *ret = NULL;
16548
0cd684e34403 sadrul fixed the next but not last crash
Luke Schierer <lschiere@pidgin.im>
parents: 16487
diff changeset
3011 static char buf[BUF_LEN];
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3012
28123
5901b1dd8d07 As darkrain pointed out this isnt caused by that certain bug in glib. My mistake. Recomment, and change how I test str to be NULL and return NULL.
Sulabh Mahajan <sulabh@soc.pidgin.im>
parents: 28120
diff changeset
3013 /* This should prevent a crash if purple_normalize gets called with NULL str, see #10115 */
5901b1dd8d07 As darkrain pointed out this isnt caused by that certain bug in glib. My mistake. Recomment, and change how I test str to be NULL and return NULL.
Sulabh Mahajan <sulabh@soc.pidgin.im>
parents: 28120
diff changeset
3014 g_return_val_if_fail(str != NULL, "");
28120
862467b37ee6 g_utf8_normalize() for glib ver < 2.15.0 causes a crash when an invalid utf8 string is passed to it (http://bugzilla.gnome.org/show_bug.cgi?id=501997).
Sulabh Mahajan <sulabh@soc.pidgin.im>
parents: 28108
diff changeset
3015
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3016 if (account != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3017 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3018 PurplePlugin *prpl = purple_find_prpl(purple_account_get_protocol_id(account));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3019
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3020 if (prpl != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3021 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3022 PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3023
28285
dab0d17dc6c1 Minor cleanup. gc->prpl is guarranteed to be a PurplePlugin with
Mark Doliner <mark@kingant.net>
parents: 28255
diff changeset
3024 if (prpl_info->normalize)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3025 ret = prpl_info->normalize(account, str);
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3028
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3029 if (ret == NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3030 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3031 char *tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3032
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3033 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
3034 g_snprintf(buf, sizeof(buf), "%s", tmp);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3035 g_free(tmp);
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 ret = buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3038 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3039
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3040 return ret;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3043 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3044 * 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
3045 * 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
3046 * comments in util.h.
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 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3049 purple_normalize_nocase(const PurpleAccount *account, const char *str)
15373
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 static char buf[BUF_LEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3052 char *tmp1, *tmp2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3053
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3054 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
3055
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3056 tmp1 = g_utf8_strdown(str, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3057 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
3058 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
3059 g_free(tmp2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3060 g_free(tmp1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3061
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3062 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3063 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3064
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3065 gchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3066 purple_strdup_withhtml(const gchar *src)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3067 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3068 gulong destsize, i, j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3069 gchar *dest;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3070
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3071 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
3072
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3073 /* 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
3074 destsize = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3075 for (i = 0; src[i] != '\0'; i++)
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 (src[i] == '\n')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3078 destsize += 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3079 else if (src[i] != '\r')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3080 destsize++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3081 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3082
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3083 dest = g_malloc(destsize);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3084
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3085 /* 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
3086 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
3087 if (src[i] == '\n') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3088 strcpy(&dest[j], "<BR>");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3089 j += 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3090 } else if (src[i] != '\r')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3091 dest[j++] = src[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3092 }
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 dest[destsize-1] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3095
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3096 return dest;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3097 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3098
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3099 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3100 purple_str_has_prefix(const char *s, const char *p)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3101 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3102 return g_str_has_prefix(s, p);
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 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3106 purple_str_has_suffix(const char *s, const char *x)
15373
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 return g_str_has_suffix(s, x);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3109 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3110
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3111 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3112 purple_str_add_cr(const char *text)
15373
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 char *ret = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3115 int count = 0, j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3116 guint i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3117
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3118 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
3119
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3120 if (text[0] == '\n')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3121 count++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3122 for (i = 1; i < strlen(text); i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3123 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
3124 count++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3125
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3126 if (count == 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3127 return g_strdup(text);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3128
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3129 ret = g_malloc0(strlen(text) + count + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3130
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3131 i = 0; j = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3132 if (text[i] == '\n')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3133 ret[j++] = '\r';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3134 ret[j++] = text[i++];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3135 for (; i < strlen(text); i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3136 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
3137 ret[j++] = '\r';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3138 ret[j++] = text[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3139 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3140
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3141 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3142 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3143
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3144 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3145 purple_str_strip_char(char *text, char thechar)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3146 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3147 int i, j;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3148
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3149 g_return_if_fail(text != NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3150
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3151 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
3152 if (text[i] != thechar)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3153 text[j++] = text[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3154
30426
c60c9c95bb00 These are dead increments.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 30263
diff changeset
3155 text[j] = '\0';
15373
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3158 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3159 purple_util_chrreplace(char *string, char delimiter,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3160 char replacement)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3161 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3162 int i = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3163
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3164 g_return_if_fail(string != NULL);
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 while (string[i] != '\0')
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 if (string[i] == delimiter)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3169 string[i] = replacement;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3170 i++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3171 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3172 }
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 gchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3175 purple_strreplace(const char *string, const char *delimiter,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3176 const char *replacement)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3177 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3178 gchar **split;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3179 gchar *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3180
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3181 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
3182 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
3183 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
3184
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3185 split = g_strsplit(string, delimiter, 0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3186 ret = g_strjoinv(replacement, split);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3187 g_strfreev(split);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3188
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3189 return ret;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3192 gchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3193 purple_strcasereplace(const char *string, const char *delimiter,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3194 const char *replacement)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3195 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3196 gchar *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3197 int length_del, length_rep, i, j;
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 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
3200 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
3201 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
3202
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3203 length_del = strlen(delimiter);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3204 length_rep = strlen(replacement);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3205
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3206 /* Count how many times the delimiter appears */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3207 i = 0; /* position in the source string */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3208 j = 0; /* number of occurrences of "delimiter" */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3209 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
3210 if (!g_ascii_strncasecmp(&string[i], delimiter, length_del)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3211 i += length_del;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3212 j += length_rep;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3213 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3214 i++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3215 j++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3216 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3217 }
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 ret = g_malloc(j+1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3220
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3221 i = 0; /* position in the source string */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3222 j = 0; /* position in the destination string */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3223 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
3224 if (!g_ascii_strncasecmp(&string[i], delimiter, length_del)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3225 strncpy(&ret[j], replacement, length_rep);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3226 i += length_del;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3227 j += length_rep;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3228 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3229 ret[j] = string[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3230 i++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3231 j++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3232 }
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3235 ret[j] = '\0';
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 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3238 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3239
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3240 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3241 purple_strcasestr(const char *haystack, const char *needle)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3242 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3243 size_t hlen, nlen;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3244 const char *tmp, *ret;
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(haystack != NULL, NULL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3247 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
3248
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3249 hlen = strlen(haystack);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3250 nlen = strlen(needle);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3251 tmp = haystack,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3252 ret = NULL;
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 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
3255 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
3256
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3257 while (*tmp && !ret) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3258 if (!g_ascii_strncasecmp(needle, tmp, nlen))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3259 ret = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3260 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3261 tmp++;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3264 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3265 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3266
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3267 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3268 purple_str_size_to_units(size_t size)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3269 {
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
3270 static const char * const size_str[] = { "bytes", "KiB", "MiB", "GiB" };
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3271 float size_mag;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3272 int size_index = 0;
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 if (size == -1) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3275 return g_strdup(_("Calculating..."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3276 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3277 else if (size == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3278 return g_strdup(_("Unknown."));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3279 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3280 else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3281 size_mag = (float)size;
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 while ((size_index < 3) && (size_mag > 1024)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3284 size_mag /= 1024;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3285 size_index++;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3288 if (size_index == 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3289 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
3290 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3291 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
3292 }
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3295
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3296 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3297 purple_str_seconds_to_string(guint secs)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3298 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3299 char *ret = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3300 guint days, hrs, mins;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3301
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3302 if (secs < 60)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3303 {
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3304 return g_strdup_printf(dngettext(PACKAGE, "%d second", "%d seconds", secs), secs);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3305 }
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 days = secs / (60 * 60 * 24);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3308 secs = secs % (60 * 60 * 24);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3309 hrs = secs / (60 * 60);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3310 secs = secs % (60 * 60);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3311 mins = secs / 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3312 secs = secs % 60;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3313
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3314 if (days > 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3315 {
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3316 ret = g_strdup_printf(dngettext(PACKAGE, "%d day", "%d days", days), days);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3317 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3318
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3319 if (hrs > 0)
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 if (ret != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3322 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3323 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
3324 dngettext(PACKAGE, "%s, %d hour", "%s, %d hours", hrs),
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3325 ret, hrs);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3326 g_free(ret);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3327 ret = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3328 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3329 else
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3330 ret = g_strdup_printf(dngettext(PACKAGE, "%d hour", "%d hours", hrs), hrs);
15373
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3333 if (mins > 0)
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 if (ret != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3336 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3337 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
3338 dngettext(PACKAGE, "%s, %d minute", "%s, %d minutes", mins),
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3339 ret, mins);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3340 g_free(ret);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3341 ret = tmp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3342 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3343 else
16063
fa8aeab4ca5a Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents: 16017
diff changeset
3344 ret = g_strdup_printf(dngettext(PACKAGE, "%d minute", "%d minutes", mins), mins);
15373
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3347 return ret;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3350
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3351 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3352 purple_str_binary_to_ascii(const unsigned char *binary, guint len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3353 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3354 GString *ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3355 guint i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3356
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3357 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
3358
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3359 ret = g_string_sized_new(len);
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 for (i = 0; i < len; i++)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3362 if (binary[i] < 32 || binary[i] > 126)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3363 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
3364 else if (binary[i] == '\\')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3365 g_string_append(ret, "\\\\");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3366 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3367 g_string_append_c(ret, binary[i]);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3368
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3369 return g_string_free(ret, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3370 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3371
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3372 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3373 * URI/URL Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3374 **************************************************************************/
15612
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: 15420
diff changeset
3375
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3376 void purple_got_protocol_handler_uri(const char *uri)
15612
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: 15420
diff changeset
3377 {
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: 15420
diff changeset
3378 char proto[11];
27860
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3379 char delimiter;
15612
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: 15420
diff changeset
3380 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: 15420
diff changeset
3381 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: 15420
diff changeset
3382 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: 15420
diff changeset
3383 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: 15420
diff changeset
3384 if (!(tmp = strchr(uri, ':')) || tmp == uri) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3385 purple_debug_error("util", "Malformed protocol handler message - missing protocol.\n");
15612
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: 15420
diff changeset
3386 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: 15420
diff changeset
3387 }
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: 15420
diff changeset
3388
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: 15420
diff changeset
3389 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: 15420
diff changeset
3390
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: 15420
diff changeset
3391 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: 15420
diff changeset
3392 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: 15420
diff changeset
3393
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: 15420
diff changeset
3394 tmp++;
27860
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3395
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3396 if (g_str_equal(proto, "xmpp"))
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3397 delimiter = ';';
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3398 else
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3399 delimiter = '&';
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3400
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3401 purple_debug_info("util", "Processing message '%s' for protocol '%s' using delimiter '%c'.\n", tmp, proto, delimiter);
15612
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: 15420
diff changeset
3402
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: 15420
diff changeset
3403 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: 15420
diff changeset
3404 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: 15420
diff changeset
3405 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: 15420
diff changeset
3406
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: 15420
diff changeset
3407 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: 15420
diff changeset
3408 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: 15420
diff changeset
3409
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: 15420
diff changeset
3410 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: 15420
diff changeset
3411 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: 15420
diff changeset
3412
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: 15420
diff changeset
3413 while (*tmp || *pairstart) {
27860
da22b6d0151e Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents: 27643
diff changeset
3414 if (*tmp == delimiter || !(*tmp)) {
15612
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: 15420
diff changeset
3415 /* 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: 15420
diff changeset
3416 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: 15420
diff changeset
3417 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: 15420
diff changeset
3418
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: 15420
diff changeset
3419 if (keyend && keyend != pairstart) {
17037
cc9242ce1435 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@gmail.com>
parents: 17035
diff changeset
3420 char *p;
15612
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: 15420
diff changeset
3421 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: 15420
diff changeset
3422 /* 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: 15420
diff changeset
3423 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: 15420
diff changeset
3424 value = g_strndup(keyend + 1, (tmp - keyend - 1));
17037
cc9242ce1435 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@gmail.com>
parents: 17035
diff changeset
3425 for (p = key; *p; ++p)
cc9242ce1435 Patch #756 from EvilSporkMan. Use Datallah's url handling for Dbus
Sean Egan <seanegan@gmail.com>
parents: 17035
diff changeset
3426 *p = g_ascii_tolower(*p);
15612
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: 15420
diff changeset
3427 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: 15420
diff changeset
3428 }
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: 15420
diff changeset
3429 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: 15420
diff changeset
3430 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: 15420
diff changeset
3431 } 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: 15420
diff changeset
3432 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: 15420
diff changeset
3433
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: 15420
diff changeset
3434 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: 15420
diff changeset
3435 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: 15420
diff changeset
3436 }
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: 15420
diff changeset
3437 } 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: 15420
diff changeset
3438 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: 15420
diff changeset
3439
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3440 purple_signal_emit_return_1(purple_get_core(), "uri-handler", proto, cmd, params);
15612
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: 15420
diff changeset
3441
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: 15420
diff changeset
3442 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: 15420
diff changeset
3443 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: 15420
diff changeset
3444 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: 15420
diff changeset
3445 }
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: 15420
diff changeset
3446
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3447 /*
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3448 * 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: 17195
diff changeset
3449 * 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: 17195
diff changeset
3450 * 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: 17195
diff changeset
3451 *
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3452 * 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: 17195
diff changeset
3453 * 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: 17195
diff changeset
3454 * 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: 17195
diff changeset
3455 * 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: 17195
diff changeset
3456 * 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: 17195
diff changeset
3457 */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3458 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3459 purple_url_parse(const char *url, char **ret_host, int *ret_port,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3460 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
3461 {
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3462 gboolean is_https = FALSE;
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3463 const char * scan_info;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3464 char port_str[6];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3465 int f;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3466 const char *at, *slash;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3467 const char *turl;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3468 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
3469 int port = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3470 /* hyphen at end includes it in control set */
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3471
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3472 #define ADDR_CTRL "A-Za-z0-9.-"
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3473 #define PORT_CTRL "0-9"
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3474 #define PAGE_CTRL "A-Za-z0-9.~_/:*!@&%%?=+^-"
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3475 #define USER_CTRL "A-Za-z0-9.~_/*!&%%?=+^-"
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3476 #define PASSWD_CTRL "A-Za-z0-9.~_/*!&%%?=+^-"
15373
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 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
3479
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3480 if ((turl = purple_strcasestr(url, "http://")) != NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3481 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3482 turl += 7;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3483 url = turl;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3484 }
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3485 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: 17195
diff changeset
3486 {
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3487 is_https = TRUE;
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3488 turl += 8;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3489 url = turl;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3490 }
15373
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 /* parse out authentication information if supplied */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3493 /* Only care about @ char BEFORE the first / */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3494 at = strchr(url, '@');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3495 slash = strchr(url, '/');
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3496 f = 0;
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3497 if (at && (!slash || at < slash)) {
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3498 scan_info = "%255[" USER_CTRL "]:%255[" PASSWD_CTRL "]^@";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3499 f = sscanf(url, scan_info, user, passwd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3500
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3501 if (f == 1) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3502 /* No passwd, possibly just username supplied */
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3503 scan_info = "%255[" USER_CTRL "]^@";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3504 f = sscanf(url, scan_info, user);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3505 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3506
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3507 url = at+1; /* move pointer after the @ char */
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3508 }
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3509
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3510 if (f < 1) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3511 *user = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3512 *passwd = '\0';
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3513 } else if (f == 1)
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3514 *passwd = '\0';
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3515
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3516 scan_info = "%255[" ADDR_CTRL "]:%5[" PORT_CTRL "]/%255[" PAGE_CTRL "]";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3517 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
3518
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3519 if (f == 1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3520 {
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3521 scan_info = "%255[" ADDR_CTRL "]/%255[" PAGE_CTRL "]";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3522 f = sscanf(url, scan_info, host, path);
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3523 /* Use the default port */
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3524 if (is_https)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3525 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: 24426
diff changeset
3526 else
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3527 g_snprintf(port_str, sizeof(port_str), "80");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3528 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3529
23982
7fbc99a1481d purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents: 23975
diff changeset
3530 if (f == 0)
7fbc99a1481d purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents: 23975
diff changeset
3531 *host = '\0';
7fbc99a1481d purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents: 23975
diff changeset
3532
7fbc99a1481d purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents: 23975
diff changeset
3533 if (f <= 1)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3534 *path = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3535
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3536 sscanf(port_str, "%d", &port);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3537
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3538 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
3539 if (ret_port != NULL) *ret_port = port;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3540 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
3541 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
3542 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
3543
23983
58e3b422e595 Return FALSE from purple_url_parse() if a host could not be determined
Evan Schoenberg <evan.s@dreskin.net>
parents: 23982
diff changeset
3544 return ((*host != '\0') ? TRUE : FALSE);
30263
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3545
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3546 #undef ADDR_CTRL
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3547 #undef PORT_CTRL
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3548 #undef PAGE_CTRL
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3549 #undef USER_CTRL
1f44f0144ff8 Get rid of a few unnecessary strlen/g_snprintf's.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30191
diff changeset
3550 #undef PASSWD_CTRL
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3551 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3552
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3553 /**
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3554 * 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
3555 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3556 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3557 purple_util_fetch_url_error(PurpleUtilFetchUrlData *gfud, const char *format, ...)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3558 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3559 gchar *error_message;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3560 va_list args;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3561
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3562 va_start(args, format);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3563 error_message = g_strdup_vprintf(format, args);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3564 va_end(args);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3565
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3566 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
3567 g_free(error_message);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3568 purple_util_fetch_url_cancel(gfud);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3569 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3570
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3571 static void url_fetch_connect_cb(gpointer url_data, gint source, const gchar *error_message);
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3572 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: 24426
diff changeset
3573 static void ssl_url_fetch_error_cb(PurpleSslConnection *ssl_connection, PurpleSslErrorType error, gpointer data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3574
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3575 static gboolean
23388
276925996951 Remove a unused variable
Mark Doliner <mark@kingant.net>
parents: 23365
diff changeset
3576 parse_redirect(const char *data, size_t data_len,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3577 PurpleUtilFetchUrlData *gfud)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3578 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3579 gchar *s;
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3580 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: 17195
diff changeset
3581 gboolean full;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3582 int len;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3583
20961
4a8366502f01 When checking for redirects in purple_util_fetch_url(), look for
Mark Doliner <mark@kingant.net>
parents: 20917
diff changeset
3584 if ((s = g_strstr_len(data, data_len, "\nLocation: ")) == NULL)
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3585 /* We're not being redirected */
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3586 return FALSE;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3587
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3588 s += strlen("Location: ");
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3589 end = strchr(s, '\r');
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3590
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3591 /* Just in case :) */
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3592 if (end == NULL)
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3593 end = strchr(s, '\n');
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3594
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3595 if (end == NULL)
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3596 return FALSE;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3597
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3598 len = end - s;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3599
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3600 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: 17195
diff changeset
3601 strncpy(new_url, s, len);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3602 new_url[len] = '\0';
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3603
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3604 full = gfud->full;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3605
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3606 if (*new_url == '/' || g_strstr_len(new_url, len, "://") == NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3607 {
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3608 temp_url = new_url;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3609
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3610 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: 17195
diff changeset
3611 gfud->website.port, temp_url);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3612
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3613 g_free(temp_url);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3614
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3615 full = FALSE;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3616 }
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3617
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3618 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: 17195
diff changeset
3619
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3620 gfud->num_times_redirected++;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3621 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: 17195
diff changeset
3622 {
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3623 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: 17195
diff changeset
3624 _("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: 17195
diff changeset
3625 gfud->url);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3626 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3627 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3628
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3629 /*
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3630 * 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: 17195
diff changeset
3631 * 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: 17195
diff changeset
3632 * 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: 17195
diff changeset
3633 */
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3634 g_free(gfud->url);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3635 gfud->url = new_url;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3636 gfud->full = full;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3637 g_free(gfud->request);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3638 gfud->request = NULL;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3639
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3640 if (gfud->is_ssl) {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3641 gfud->is_ssl = FALSE;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3642 purple_ssl_close(gfud->ssl_connection);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3643 gfud->ssl_connection = NULL;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3644 } else {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3645 purple_input_remove(gfud->inpa);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3646 gfud->inpa = 0;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3647 close(gfud->fd);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3648 gfud->fd = -1;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3649 }
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3650 gfud->request_written = 0;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3651 gfud->len = 0;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3652 gfud->data_len = 0;
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3653
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3654 g_free(gfud->website.user);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3655 g_free(gfud->website.passwd);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3656 g_free(gfud->website.address);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3657 g_free(gfud->website.page);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3658 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: 17195
diff changeset
3659 &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: 17195
diff changeset
3660
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3661 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: 24426
diff changeset
3662 gfud->is_ssl = TRUE;
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3663 gfud->ssl_connection = purple_ssl_connect(gfud->account,
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3664 gfud->website.address, gfud->website.port,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3665 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: 24426
diff changeset
3666 } else {
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3667 gfud->connect_data = purple_proxy_connect(NULL, gfud->account,
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3668 gfud->website.address, gfud->website.port,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3669 url_fetch_connect_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3670 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3671
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3672 if (gfud->ssl_connection == NULL && gfud->connect_data == NULL)
17450
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3673 {
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3674 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: 17195
diff changeset
3675 gfud->website.address);
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3676 }
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3677
3d035cdd103b Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents: 17195
diff changeset
3678 return TRUE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3679 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3680
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3681 static const char *
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3682 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: 27137
diff changeset
3683 {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3684 const char *p = NULL;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3685
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3686 if (header_len <= 0)
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3687 header_len = strlen(header);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3688
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3689 /* Note: data is _not_ nul-terminated. */
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3690 if (data_len > header_len) {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3691 if (header[0] == '\n')
27936
703b20fa6c5c g_strncasecmp is deprecated. I thought I removed these already. Anyway, I
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27907
diff changeset
3692 p = (g_ascii_strncasecmp(data, header + 1, header_len - 1) == 0) ? data : NULL;
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3693 if (!p)
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3694 p = purple_strcasestr(data, header);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3695 if (p)
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3696 p += header_len;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3697 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3698
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3699 /* 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: 27137
diff changeset
3700 * 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: 27137
diff changeset
3701 * 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: 27137
diff changeset
3702 */
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3703 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: 27137
diff changeset
3704 return p;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3705 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3706
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3707 return NULL;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3708 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3709
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3710 static size_t
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3711 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
3712 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3713 size_t content_len = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3714 const char *p = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3715
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3716 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: 27137
diff changeset
3717 if (p) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3718 sscanf(p, "%" G_GSIZE_FORMAT, &content_len);
22486
3225c99785b8 Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <mark@kingant.net>
parents: 22354
diff changeset
3719 purple_debug_misc("util", "parsed %" G_GSIZE_FORMAT "\n", content_len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3720 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3721
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3722 return content_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3723 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3724
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3725 static gboolean
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3726 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: 27137
diff changeset
3727 {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3728 const char *p = find_header_content(data, data_len, "\nTransfer-Encoding: ", sizeof("\nTransfer-Encoding: ") - 1);
27936
703b20fa6c5c g_strncasecmp is deprecated. I thought I removed these already. Anyway, I
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27907
diff changeset
3729 if (p && g_ascii_strncasecmp(p, "chunked", 7) == 0)
27245
a051f77d86a8 Remove just a tad bit of indirection
Mark Doliner <mark@kingant.net>
parents: 27244
diff changeset
3730 return TRUE;
a051f77d86a8 Remove just a tad bit of indirection
Mark Doliner <mark@kingant.net>
parents: 27244
diff changeset
3731
a051f77d86a8 Remove just a tad bit of indirection
Mark Doliner <mark@kingant.net>
parents: 27244
diff changeset
3732 return FALSE;
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3733 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3734
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3735 /* Process in-place */
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3736 static void
27244
7a4f56967512 Use unsigned lengths here and use %zu when reading into the gsize var
Mark Doliner <mark@kingant.net>
parents: 27223
diff changeset
3737 process_chunked_data(char *data, gsize *len)
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3738 {
27244
7a4f56967512 Use unsigned lengths here and use %zu when reading into the gsize var
Mark Doliner <mark@kingant.net>
parents: 27223
diff changeset
3739 gsize sz;
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3740 gsize newlen = 0;
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3741 char *p = data;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3742 char *s = data;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3743
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3744 while (*s) {
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3745 /* Read the size of this chunk */
27376
70e64287f790 Hey Stu, it should be safe to combine this check, right? It'll make us
Mark Doliner <mark@kingant.net>
parents: 27298
diff changeset
3746 if (sscanf(s, "%" G_GSIZE_MODIFIER "x", &sz) != 1)
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3747 {
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3748 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: 27245
diff changeset
3749 "Expected data length, found: %s\n", s);
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3750 break;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3751 }
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3752 if (sz == 0) {
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3753 /* 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: 27245
diff changeset
3754 /*
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3755 * 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: 27245
diff changeset
3756 * 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: 27245
diff changeset
3757 * treat it like a header.
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3758 */
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3759 break;
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3760 }
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3761
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3762 /* Advance to the start of the data */
27281
e8ac5369d567 Apparently there might be stuff after the semicolon before the \r\n so just
Stu Tomlinson <stu@nosnilmot.com>
parents: 27274
diff changeset
3763 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: 27274
diff changeset
3764 if (s == NULL)
e8ac5369d567 Apparently there might be stuff after the semicolon before the \r\n so just
Stu Tomlinson <stu@nosnilmot.com>
parents: 27274
diff changeset
3765 break;
e8ac5369d567 Apparently there might be stuff after the semicolon before the \r\n so just
Stu Tomlinson <stu@nosnilmot.com>
parents: 27274
diff changeset
3766 s += 2;
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3767
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3768 if (s + sz > data + *len) {
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3769 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: 27245
diff changeset
3770 "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: 27245
diff changeset
3771 "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: 27245
diff changeset
3772 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: 27245
diff changeset
3773 }
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3774
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3775 /* Move all data overtop of the chunk length that we read in earlier */
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3776 g_memmove(p, s, sz);
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3777 p += sz;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3778 s += sz;
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3779 newlen += sz;
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3780 if (*s != '\r' && *(s + 1) != '\n') {
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3781 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: 27245
diff changeset
3782 "Expected \\r\\n, found: %s\n", s);
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3783 break;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3784 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3785 s += 2;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3786 }
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3787
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3788 /* NULL terminate the data */
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3789 *p = 0;
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3790
27246
e28b627be482 A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents: 27245
diff changeset
3791 *len = newlen;
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3792 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3793
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3794 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3795 url_fetch_recv_cb(gpointer url_data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3796 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3797 PurpleUtilFetchUrlData *gfud = url_data;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3798 int len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3799 char buf[4096];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3800 char *data_cursor;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3801 gboolean got_eof = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3802
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3803 /*
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3804 * 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: 24426
diff changeset
3805 * 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: 24426
diff changeset
3806 * 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: 24426
diff changeset
3807 */
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3808 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: 24426
diff changeset
3809 (!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: 24426
diff changeset
3810 {
23684
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
3811 if(gfud->max_len != -1 && (gfud->len + len) > gfud->max_len) {
24075
fa39c801167d Fix a TODO and mark a string translatable now that we're not string frozen.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23983
diff changeset
3812 purple_util_fetch_url_error(gfud, _("Error reading from %s: response too long (%d bytes limit)"),
23684
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
3813 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: 23666
diff changeset
3814 return;
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
3815 }
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
3816
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3817 /* 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
3818 if((gfud->len + len) >= gfud->data_len) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3819 while((gfud->len + len) >= gfud->data_len)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3820 gfud->data_len += sizeof(buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3821
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3822 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
3823 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3824
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3825 data_cursor = gfud->webdata + gfud->len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3826
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3827 gfud->len += len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3828
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3829 memcpy(data_cursor, buf, len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3830
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3831 gfud->webdata[gfud->len] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3832
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3833 if(!gfud->got_headers) {
30920
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3834 char *end_of_headers;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3835
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3836 /* See if we've reached the end of the headers yet */
30920
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3837 end_of_headers = strstr(gfud->webdata, "\r\n\r\n");
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3838 if (end_of_headers) {
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3839 char *new_data;
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3840 guint header_len = (end_of_headers + 4 - gfud->webdata);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3841 size_t content_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3842
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3843 purple_debug_misc("util", "Response headers: '%.*s'\n",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3844 header_len, gfud->webdata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3845
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3846 /* See if we can find a redirect. */
23388
276925996951 Remove a unused variable
Mark Doliner <mark@kingant.net>
parents: 23365
diff changeset
3847 if(parse_redirect(gfud->webdata, header_len, gfud))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3848 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3849
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3850 gfud->got_headers = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3851
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3852 /* 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
3853 content_len = parse_content_len(gfud->webdata, header_len);
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3854 gfud->chunked = content_is_chunked(gfud->webdata, header_len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3855
30920
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3856 if (content_len == 0) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3857 /* We'll stick with an initial 8192 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3858 content_len = 8192;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3859 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3860 gfud->has_explicit_data_len = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3861 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3862
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3863
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3864 /* If we're returning the headers too, we don't need to clean them out */
30920
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3865 if (gfud->include_headers) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3866 gfud->data_len = content_len + header_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3867 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
3868 } else {
30920
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3869 size_t body_len = gfud->len - header_len;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3870
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3871 content_len = MAX(content_len, body_len);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3872
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3873 new_data = g_try_malloc(content_len);
30920
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3874 if (new_data == NULL) {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3875 purple_debug_error("util",
22486
3225c99785b8 Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <mark@kingant.net>
parents: 22354
diff changeset
3876 "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
3877 content_len, g_strerror(errno));
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3878 purple_util_fetch_url_error(gfud,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3879 _("Unable to allocate enough memory to hold "
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3880 "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
3881 "be trying something malicious."),
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3882 gfud->website.address);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3883
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3884 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3885 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3886
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3887 /* We may have read part of the body when reading the headers, don't lose it */
30920
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3888 if (body_len > 0) {
65ef833303b0 Minor cleanup. Should be no functionality change, just a variable
Mark Doliner <mark@kingant.net>
parents: 30919
diff changeset
3889 memcpy(new_data, end_of_headers + 4, body_len);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3890 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3891
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3892 /* Out with the old... */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3893 g_free(gfud->webdata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3894
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3895 /* In with the new. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3896 gfud->len = body_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3897 gfud->data_len = content_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3898 gfud->webdata = new_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3899 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3900 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3901 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3902
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3903 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
3904 got_eof = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3905 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3906 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3907 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3908
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3909 if(len < 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3910 if(errno == EAGAIN) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3911 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3912 } else {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3913 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
3914 gfud->website.address, g_strerror(errno));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3915 return;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3916 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3917 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3918
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3919 if((len == 0) || got_eof) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3920 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
3921 gfud->webdata[gfud->len] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3922
27220
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3923 if (!gfud->include_headers && gfud->chunked) {
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3924 /* 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: 27137
diff changeset
3925 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: 27137
diff changeset
3926 }
716bd29bdc28 Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 27137
diff changeset
3927
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3928 gfud->callback(gfud, gfud->user_data, gfud->webdata, gfud->len, NULL);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3929 purple_util_fetch_url_cancel(gfud);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3930 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3931 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3932
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3933 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: 24426
diff changeset
3934 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3935 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: 24426
diff changeset
3936 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3937
27120
9ff4b4cbc4c9 Allow doxygen to pick up the comment for this function. It's
Mark Doliner <mark@kingant.net>
parents: 27024
diff changeset
3938 /**
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3939 * 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: 24426
diff changeset
3940 * to.
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3941 *
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3942 * @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: 24426
diff changeset
3943 * 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: 24426
diff changeset
3944 * 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: 24426
diff changeset
3945 * 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: 24426
diff changeset
3946 * writing to it directly.
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3947 */
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3948 static void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3949 url_fetch_send_cb(gpointer data, gint source, PurpleInputCondition cond)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3950 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
3951 PurpleUtilFetchUrlData *gfud;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3952 int len, total_len;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3953
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3954 gfud = data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3955
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3956 if (gfud->request == NULL) {
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3957
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3958 PurpleProxyInfo *gpi = purple_proxy_get_setup(gfud->account);
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3959 GString *request_str = g_string_new(NULL);
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3960
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3961 g_string_append_printf(request_str, "GET %s%s HTTP/%s\r\n"
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3962 "Connection: close\r\n",
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3963 (gfud->full ? "" : "/"),
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3964 (gfud->full ? (gfud->url ? gfud->url : "") : (gfud->website.page ? gfud->website.page : "")),
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3965 (gfud->http11 ? "1.1" : "1.0"));
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3966
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3967 if (gfud->user_agent)
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3968 g_string_append_printf(request_str, "User-Agent: %s\r\n", gfud->user_agent);
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3969
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
3970 /* 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: 24426
diff changeset
3971 * 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: 24426
diff changeset
3972 * 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: 24426
diff changeset
3973 * 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: 24426
diff changeset
3974 */
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3975 g_string_append_printf(request_str, "Accept: */*\r\n"
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3976 "Host: %s\r\n",
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3977 (gfud->website.address ? gfud->website.address : ""));
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3978
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3979 if (purple_proxy_info_get_username(gpi) != NULL
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3980 && (purple_proxy_info_get_type(gpi) == PURPLE_PROXY_USE_ENVVAR
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3981 || purple_proxy_info_get_type(gpi) == PURPLE_PROXY_HTTP)) {
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3982 /* This chunk of code was copied from proxy.c http_start_connect_tunneling()
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3983 * This is really a temporary hack - we need a more complete proxy handling solution,
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3984 * so I didn't think it was worthwhile to refactor for reuse
31086
a8cc50c2279f Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents: 30920
diff changeset
3985 */
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3986 char *t1, *t2, *ntlm_type1;
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3987 char hostname[256];
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3988 int ret;
31086
a8cc50c2279f Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents: 30920
diff changeset
3989
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3990 ret = gethostname(hostname, sizeof(hostname));
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3991 hostname[sizeof(hostname) - 1] = '\0';
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3992 if (ret < 0 || hostname[0] == '\0') {
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3993 purple_debug_warning("util", "proxy - gethostname() failed -- is your hostname set?");
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3994 strcpy(hostname, "localhost");
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3995 }
31086
a8cc50c2279f Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents: 30920
diff changeset
3996
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3997 t1 = g_strdup_printf("%s:%s",
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3998 purple_proxy_info_get_username(gpi),
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
3999 purple_proxy_info_get_password(gpi) ?
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4000 purple_proxy_info_get_password(gpi) : "");
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4001 t2 = purple_base64_encode((const guchar *)t1, strlen(t1));
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4002 g_free(t1);
31086
a8cc50c2279f Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents: 30920
diff changeset
4003
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4004 ntlm_type1 = purple_ntlm_gen_type1(hostname, "");
31086
a8cc50c2279f Remove trailing whitespace
Richard Laager <rlaager@wiktel.com>
parents: 30920
diff changeset
4005
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4006 g_string_append_printf(request_str,
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4007 "Proxy-Authorization: Basic %s\r\n"
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4008 "Proxy-Authorization: NTLM %s\r\n"
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4009 "Proxy-Connection: Keep-Alive\r\n",
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4010 t2, ntlm_type1);
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4011 g_free(ntlm_type1);
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4012 g_free(t2);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4013 }
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4014
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4015 g_string_append(request_str, "\r\n");
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4016
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4017 gfud->request = g_string_free(request_str, FALSE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4018 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4019
27298
e9279f0e551a Convert all uses of PURPLE_UNSAFE_DEBUG to the new API I added.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 27295
diff changeset
4020 if(purple_debug_is_unsafe())
25623
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24863
diff changeset
4021 purple_debug_misc("util", "Request: '%s'\n", gfud->request);
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24863
diff changeset
4022 else
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24863
diff changeset
4023 purple_debug_misc("util", "request constructed\n");
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4024
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4025 total_len = strlen(gfud->request);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4026
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4027 if (gfud->is_ssl)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4028 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: 24426
diff changeset
4029 total_len - gfud->request_written);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4030 else
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4031 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: 24426
diff changeset
4032 total_len - gfud->request_written);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4033
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4034 if (len < 0 && errno == EAGAIN)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4035 return;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4036 else if (len < 0) {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4037 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: 24426
diff changeset
4038 gfud->website.address, g_strerror(errno));
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4039 return;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4040 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4041 gfud->request_written += len;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4042
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4043 if (gfud->request_written < total_len)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4044 return;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4045
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4046 /* 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: 24426
diff changeset
4047 if (gfud->is_ssl) {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4048 purple_input_remove(gfud->inpa);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4049 gfud->inpa = 0;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4050 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: 24426
diff changeset
4051 } else {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4052 purple_input_remove(gfud->inpa);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4053 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: 24426
diff changeset
4054 gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4055 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4056 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4057
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4058 static void
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4059 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: 24426
diff changeset
4060 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4061 PurpleUtilFetchUrlData *gfud;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4062
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4063 gfud = url_data;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4064 gfud->connect_data = NULL;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4065
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4066 if (source == -1)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4067 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4068 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: 24426
diff changeset
4069 (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: 24426
diff changeset
4070 return;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4071 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4072
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4073 gfud->fd = source;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4074
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4075 gfud->inpa = purple_input_add(source, PURPLE_INPUT_WRITE,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4076 url_fetch_send_cb, gfud);
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4077 url_fetch_send_cb(gfud, source, PURPLE_INPUT_WRITE);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4078 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4079
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4080 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: 24426
diff changeset
4081 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4082 PurpleUtilFetchUrlData *gfud;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4083
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4084 gfud = data;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4085
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4086 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: 24426
diff changeset
4087 url_fetch_send_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4088 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: 24426
diff changeset
4089 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4090
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4091 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: 24426
diff changeset
4092 {
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4093 PurpleUtilFetchUrlData *gfud;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4094
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4095 gfud = data;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4096 gfud->ssl_connection = NULL;
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4097
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4098 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: 24426
diff changeset
4099 (gfud->website.address ? gfud->website.address : ""),
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4100 purple_ssl_strerror(error));
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4101 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4102
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4103 PurpleUtilFetchUrlData *
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4104 purple_util_fetch_url_request(const char *url, gboolean full,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4105 const char *user_agent, gboolean http11,
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4106 const char *request, gboolean include_headers,
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4107 PurpleUtilFetchUrlCallback callback, void *user_data)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4108 {
26969
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26895
diff changeset
4109 return purple_util_fetch_url_request_len_with_account(NULL, url, full,
23684
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
4110 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: 23666
diff changeset
4111 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: 23666
diff changeset
4112 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: 23666
diff changeset
4113 }
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
4114
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
4115 PurpleUtilFetchUrlData *
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
4116 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: 23666
diff changeset
4117 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: 23666
diff changeset
4118 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: 23666
diff changeset
4119 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: 23666
diff changeset
4120 {
26969
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26895
diff changeset
4121 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: 26895
diff changeset
4122 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: 26895
diff changeset
4123 user_data);
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26895
diff changeset
4124 }
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26895
diff changeset
4125
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26895
diff changeset
4126 PurpleUtilFetchUrlData *
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26895
diff changeset
4127 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: 26895
diff changeset
4128 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: 26895
diff changeset
4129 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: 26895
diff changeset
4130 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: 26895
diff changeset
4131 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4132 PurpleUtilFetchUrlData *gfud;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4133
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4134 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
4135 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
4136
27298
e9279f0e551a Convert all uses of PURPLE_UNSAFE_DEBUG to the new API I added.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 27295
diff changeset
4137 if(purple_debug_is_unsafe())
25623
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24863
diff changeset
4138 purple_debug_info("util",
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24863
diff changeset
4139 "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: 24863
diff changeset
4140 url, full, user_agent?user_agent:"(null)", http11);
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24863
diff changeset
4141 else
fb89c9f6e57a *** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 24863
diff changeset
4142 purple_debug_info("util", "requesting to fetch a URL\n");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4143
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4144 gfud = g_new0(PurpleUtilFetchUrlData, 1);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4145
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4146 gfud->callback = callback;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4147 gfud->user_data = user_data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4148 gfud->url = g_strdup(url);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4149 gfud->user_agent = g_strdup(user_agent);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4150 gfud->http11 = http11;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4151 gfud->full = full;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4152 gfud->request = g_strdup(request);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4153 gfud->include_headers = include_headers;
20592
383b9180b2c8 Initialize file-descriptors to -1.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 20587
diff changeset
4154 gfud->fd = -1;
23684
de8f2d3e538a Add temporary purple_util_fetch_url_request_len and purple_util_fetch_url_len
Daniel Atallah <daniel.atallah@gmail.com>
parents: 23666
diff changeset
4155 gfud->max_len = max_len;
30187
a414593d0a78 Attempt to improve handling of HTTP requests on port 80 when there is a HTTP
Daniel Atallah <daniel.atallah@gmail.com>
parents: 30161
diff changeset
4156 gfud->account = account;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4157
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4158 purple_url_parse(url, &gfud->website.address, &gfud->website.port,
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4159 &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
4160
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4161 if (purple_strcasestr(url, "https://") != NULL) {
26190
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26181
diff changeset
4162 if (!purple_ssl_is_supported()) {
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26181
diff changeset
4163 purple_util_fetch_url_error(gfud,
27378
6275df9d2d62 Change strings in libpurple/protocols/jabber/auth.c and util.c a little bit
Mark Doliner <mark@kingant.net>
parents: 27376
diff changeset
4164 _("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: 27376
diff changeset
4165 gfud->website.address,
6275df9d2d62 Change strings in libpurple/protocols/jabber/auth.c and util.c a little bit
Mark Doliner <mark@kingant.net>
parents: 27376
diff changeset
4166 _("Server requires TLS/SSL, but no TLS/SSL support was found."));
26190
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26181
diff changeset
4167 return NULL;
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26181
diff changeset
4168 }
2db8a92b3cde Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents: 26181
diff changeset
4169
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4170 gfud->is_ssl = TRUE;
26969
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26895
diff changeset
4171 gfud->ssl_connection = purple_ssl_connect(account,
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4172 gfud->website.address, gfud->website.port,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4173 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: 24426
diff changeset
4174 } else {
26969
f303787f144d Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 26895
diff changeset
4175 gfud->connect_data = purple_proxy_connect(NULL, account,
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4176 gfud->website.address, gfud->website.port,
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4177 url_fetch_connect_cb, gfud);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4178 }
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4179
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4180 if (gfud->ssl_connection == NULL && gfud->connect_data == NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4181 {
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4182 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: 24426
diff changeset
4183 gfud->website.address);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4184 return NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4185 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4186
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4187 return gfud;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4188 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4189
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4190 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4191 purple_util_fetch_url_cancel(PurpleUtilFetchUrlData *gfud)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4192 {
24592
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4193 if (gfud->ssl_connection != NULL)
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4194 purple_ssl_close(gfud->ssl_connection);
104f6f755c7e Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents: 24426
diff changeset
4195
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4196 if (gfud->connect_data != NULL)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4197 purple_proxy_connect_cancel(gfud->connect_data);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4198
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4199 if (gfud->inpa > 0)
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4200 purple_input_remove(gfud->inpa);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4201
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4202 if (gfud->fd >= 0)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4203 close(gfud->fd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4204
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4205 g_free(gfud->website.user);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4206 g_free(gfud->website.passwd);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4207 g_free(gfud->website.address);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4208 g_free(gfud->website.page);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4209 g_free(gfud->url);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4210 g_free(gfud->user_agent);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4211 g_free(gfud->request);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4212 g_free(gfud->webdata);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4213
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4214 g_free(gfud);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4215 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4216
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4217 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4218 purple_url_decode(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4219 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4220 static char buf[BUF_LEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4221 guint i, j = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4222 char *bum;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4223 char hex[3];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4224
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4225 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
4226
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4227 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4228 * 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
4229 * dynamically allocated, but this is easier.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4230 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4231 if (strlen(str) >= BUF_LEN)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4232 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4233
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4234 for (i = 0; i < strlen(str); i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4235
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4236 if (str[i] != '%')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4237 buf[j++] = str[i];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4238 else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4239 strncpy(hex, str + ++i, 2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4240 hex[2] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4241
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4242 /* 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
4243 i++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4244
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4245 /*
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4246 * 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
4247 * will be at the next character.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4248 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4249 buf[j++] = strtol(hex, NULL, 16);
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4252
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4253 buf[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4254
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4255 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
4256 *bum = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4257
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4258 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4259 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4260
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4261 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4262 purple_url_encode(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4263 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4264 const char *iter;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4265 static char buf[BUF_LEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4266 char utf_char[6];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4267 guint i, j = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4268
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4269 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
4270 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
4271
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4272 iter = str;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4273 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
4274 gunichar c = g_utf8_get_char(iter);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4275 /* 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
4276 * no need to escape */
28255
79c14adf9669 Change purple_url_encode() to not encode . _ - ~ because it's not
Mark Doliner <mark@kingant.net>
parents: 28153
diff changeset
4277 if (c < 128 && (isalnum(c) || c == '-' || c == '.' || c == '_' || c == '~')) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4278 buf[j++] = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4279 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4280 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
4281 for (i = 0; i < bytes; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4282 if (j > (BUF_LEN - 4))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4283 break;
28255
79c14adf9669 Change purple_url_encode() to not encode . _ - ~ because it's not
Mark Doliner <mark@kingant.net>
parents: 28153
diff changeset
4284 sprintf(buf + j, "%%%02X", utf_char[i] & 0xff);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4285 j += 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4286 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4287 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4288 }
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 buf[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4291
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4292 return buf;
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
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4295 /* Originally lifted from
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4296 * 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
4297 * ... 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
4298 * ... 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
4299 * 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
4300 * 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
4301 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4302 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4303 purple_email_is_valid(const char *address)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4304 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4305 const char *c, *domain;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4306 static char *rfc822_specials = "()<>@,;:\\\"[]";
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4307
24424
2d677e8fe6d0 Fix CID #385
Richard Laager <rlaager@wiktel.com>
parents: 24423
diff changeset
4308 g_return_val_if_fail(address != NULL, FALSE);
2d677e8fe6d0 Fix CID #385
Richard Laager <rlaager@wiktel.com>
parents: 24423
diff changeset
4309
30191
b8782b02330d Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <stu@nosnilmot.com>
parents: 30187
diff changeset
4310 if (*address == '.') return FALSE;
b8782b02330d Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <stu@nosnilmot.com>
parents: 30187
diff changeset
4311
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4312 /* 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
4313 for (c = address; *c; c++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4314 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
4315 while (*++c) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4316 if (*c == '\\') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4317 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
4318 else return FALSE;
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 if (*c == '\"') break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4321 if (*c < ' ' || *c >= 127) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4322 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4323 if (!*c++) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4324 if (*c == '@') break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4325 if (*c != '.') return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4326 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4327 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4328 if (*c == '@') break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4329 if (*c <= ' ' || *c >= 127) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4330 if (strchr(rfc822_specials, *c)) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4331 }
18600
321658bf0e03 Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <mark@kingant.net>
parents: 18560
diff changeset
4332
321658bf0e03 Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <mark@kingant.net>
parents: 18560
diff changeset
4333 /* 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
4334 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
4335
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4336 /* 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
4337 * 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
4338 if (c == address) return FALSE;
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 /* 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
4341 if (!*(domain = ++c)) return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4342 do {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4343 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
4344 return FALSE;
30191
b8782b02330d Catch some more invalid email addresses, thanks to Mark for additional
Stu Tomlinson <stu@nosnilmot.com>
parents: 30187
diff changeset
4345 if (*c == '-' && (*(c - 1) == '.' || *(c - 1) == '@')) return FALSE;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4346 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
4347 (*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
4348 } while (*++c);
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 if (*(c - 1) == '-') return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4351
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4352 return ((c - domain) > 3 ? TRUE : FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4353 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4354
22337
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
4355 gboolean
27473
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27469
diff changeset
4356 purple_ipv4_address_is_valid(const char *ip)
22337
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
4357 {
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
4358 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
4359 char end;
24422
64395aea313c Fix CID #387
Richard Laager <rlaager@wiktel.com>
parents: 24421
diff changeset
4360
64395aea313c Fix CID #387
Richard Laager <rlaager@wiktel.com>
parents: 24421
diff changeset
4361 g_return_val_if_fail(ip != NULL, FALSE);
64395aea313c Fix CID #387
Richard Laager <rlaager@wiktel.com>
parents: 24421
diff changeset
4362
22337
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
4363 c = sscanf(ip, "%d.%d.%d.%d%c", &o1, &o2, &o3, &o4, &end);
22354
51e740d3af3b Fixes an error detected by valgrind:
Ka-Hing Cheung <khc@hxbc.us>
parents: 22337
diff changeset
4364 if (c != 4 || o1 < 0 || o1 > 255 || o2 < 0 || o2 > 255 || o3 < 0 || o3 > 255 || o4 < 0 || o4 > 255)
22337
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
4365 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
4366 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
4367 }
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
4368
27469
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4369 gboolean
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4370 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: 27448
diff changeset
4371 {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4372 const gchar *c;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4373 gboolean double_colon = FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4374 gint chunks = 1;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4375 gint in = 0;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4376
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4377 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: 27448
diff changeset
4378
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4379 if (*ip == '\0')
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4380 return FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4381
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4382 for (c = ip; *c; ++c) {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4383 if ((*c >= '0' && *c <= '9') ||
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4384 (*c >= 'a' && *c <= 'f') ||
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4385 (*c >= 'A' && *c <= 'F')) {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4386 if (++in > 4)
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4387 /* Only four hex digits per chunk */
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4388 return FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4389 continue;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4390 } else if (*c == ':') {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4391 /* The start of a new chunk */
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4392 ++chunks;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4393 in = 0;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4394 if (*(c + 1) == ':') {
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4395 /*
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4396 * '::' indicates a consecutive series of chunks full
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4397 * 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: 27448
diff changeset
4398 */
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4399 if (double_colon)
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4400 return FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4401 double_colon = TRUE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4402 }
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4403 } else
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4404 return FALSE;
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4405 }
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4406
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4407 /*
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4408 * 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: 27448
diff changeset
4409 * 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: 27448
diff changeset
4410 */
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4411 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: 27448
diff changeset
4412 }
8c41a23e6b44 Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents: 27448
diff changeset
4413
27473
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27469
diff changeset
4414 /* TODO 3.0.0: Add ipv6 check, too */
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27469
diff changeset
4415 gboolean
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27469
diff changeset
4416 purple_ip_address_is_valid(const char *ip)
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27469
diff changeset
4417 {
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27469
diff changeset
4418 return purple_ipv4_address_is_valid(ip);
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27469
diff changeset
4419 }
1d30e9d6de9b Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents: 27469
diff changeset
4420
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4421 /* Stolen from gnome_uri_list_extract_uris */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4422 GList *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4423 purple_uri_list_extract_uris(const gchar *uri_list)
15373
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 const gchar *p, *q;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4426 gchar *retval;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4427 GList *result = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4428
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4429 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
4430
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4431 p = uri_list;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4432
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4433 /* 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
4434 * 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
4435 * 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
4436 * 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
4437 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4438 while (p) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4439 if (*p != '#') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4440 while (isspace(*p))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4441 p++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4442
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4443 q = p;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4444 while (*q && (*q != '\n') && (*q != '\r'))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4445 q++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4446
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4447 if (q > p) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4448 q--;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4449 while (q > p && isspace(*q))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4450 q--;
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 retval = (gchar*)g_malloc (q - p + 2);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4453 strncpy (retval, p, q - p + 1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4454 retval[q - p + 1] = '\0';
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 result = g_list_prepend (result, retval);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4457 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4458 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4459 p = strchr (p, '\n');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4460 if (p)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4461 p++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4462 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4463
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4464 return g_list_reverse (result);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4465 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4466
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4467
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4468 /* Stolen from gnome_uri_list_extract_filenames */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4469 GList *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4470 purple_uri_list_extract_filenames(const gchar *uri_list)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4471 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4472 GList *tmp_list, *node, *result;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4473
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4474 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
4475
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4476 result = purple_uri_list_extract_uris(uri_list);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4477
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4478 tmp_list = result;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4479 while (tmp_list) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4480 gchar *s = (gchar*)tmp_list->data;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4481
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4482 node = tmp_list;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4483 tmp_list = tmp_list->next;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4484
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4485 if (!strncmp (s, "file:", 5)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4486 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
4487 /* 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
4488 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
4489 } else {
22864
7d4fcb142572 Fix some potential leakage in the craziness called purple_markup_html_to_xhtml().
Daniel Atallah <daniel.atallah@gmail.com>
parents: 22486
diff changeset
4490 result = g_list_delete_link(result, node);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4491 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4492 g_free (s);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4493 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4494 return result;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4495 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4496
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4497 /**************************************************************************
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4498 * UTF8 String Functions
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4499 **************************************************************************/
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4500 gchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4501 purple_utf8_try_convert(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4502 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4503 gsize converted;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4504 gchar *utf8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4505
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4506 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
4507
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4508 if (g_utf8_validate(str, -1, NULL)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4509 return g_strdup(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4510 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4511
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4512 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
4513 if (utf8 != NULL)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4514 return utf8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4515
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4516 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
4517 if ((utf8 != NULL) && (converted == strlen(str)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4518 return utf8;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4519
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4520 g_free(utf8);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4521
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4522 return NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4523 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4524
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4525 #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
4526 || (x & 0xf0) == 0xe0 || (x & 0xf8) == 0xf)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4527 gchar *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4528 purple_utf8_salvage(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4529 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4530 GString *workstr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4531 const char *end;
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 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
4534
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4535 workstr = g_string_sized_new(strlen(str));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4536
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4537 do {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4538 g_utf8_validate(str, -1, &end);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4539 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
4540 str = end;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4541 if (*str == '\0')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4542 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4543 do {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4544 workstr = g_string_append_c(workstr, '?');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4545 str++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4546 } while (!utf8_first(*str));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4547 } while (*str != '\0');
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 return g_string_free(workstr, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4550 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4551
27019
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4552 gchar *
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4553 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: 27012
diff changeset
4554 {
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4555 gchar *workstr, *iter;
28107
0a4d0d4cf5df Add more verbose debugging to purple_utf8_strip_unprintables.
Paul Aurich <paul@darkrain42.org>
parents: 28106
diff changeset
4556 const gchar *bad;
27019
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4557
27024
c59918579c3a Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents: 27019
diff changeset
4558 if (str == NULL)
c59918579c3a Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents: 27019
diff changeset
4559 /* Act like g_strdup */
c59918579c3a Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents: 27019
diff changeset
4560 return NULL;
c59918579c3a Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents: 27019
diff changeset
4561
28108
6b018d1efc5c Oops, I think it's either sleep or coffee time.
Paul Aurich <paul@darkrain42.org>
parents: 28107
diff changeset
4562 if (!g_utf8_validate(str, -1, &bad)) {
28107
0a4d0d4cf5df Add more verbose debugging to purple_utf8_strip_unprintables.
Paul Aurich <paul@darkrain42.org>
parents: 28106
diff changeset
4563 purple_debug_error("util", "purple_utf8_strip_unprintables(%s) failed; "
0a4d0d4cf5df Add more verbose debugging to purple_utf8_strip_unprintables.
Paul Aurich <paul@darkrain42.org>
parents: 28106
diff changeset
4564 "first bad character was %02x (%c)\n",
0a4d0d4cf5df Add more verbose debugging to purple_utf8_strip_unprintables.
Paul Aurich <paul@darkrain42.org>
parents: 28106
diff changeset
4565 str, *bad, *bad);
0a4d0d4cf5df Add more verbose debugging to purple_utf8_strip_unprintables.
Paul Aurich <paul@darkrain42.org>
parents: 28106
diff changeset
4566 g_return_val_if_reached(NULL);
0a4d0d4cf5df Add more verbose debugging to purple_utf8_strip_unprintables.
Paul Aurich <paul@darkrain42.org>
parents: 28106
diff changeset
4567 }
27019
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4568
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4569 workstr = iter = g_new(gchar, strlen(str) + 1);
29852
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4570 while (*str) {
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4571 gunichar ch = g_utf8_get_char(str);
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4572 gchar *next = g_utf8_next_char(str);
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4573 /*
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4574 * Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] |
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4575 * [#x10000-#x10FFFF]
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4576 */
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4577 if ((ch == '\t' || ch == '\n' || ch == '\r') ||
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4578 (ch >= 0x20 && ch <= 0xD7FF) ||
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4579 (ch >= 0xE000 && ch <= 0xFFFD) ||
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4580 (ch >= 0x10000 && ch <= 0x10FFFF)) {
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4581 memcpy(iter, str, next - str);
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4582 iter += (next - str);
27019
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4583 }
29852
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4584
5bac51b394e6 util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents: 29745
diff changeset
4585 str = next;
27019
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4586 }
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4587
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4588 /* nul-terminate the new string */
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4589 *iter = '\0';
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4590
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4591 return workstr;
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4592 }
bf9db4c67679 Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents: 27012
diff changeset
4593
21863
7e833250a0ef Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents: 21862
diff changeset
4594 /*
7e833250a0ef Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents: 21862
diff changeset
4595 * 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
4596 * gai_strerror().
7e833250a0ef Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents: 21862
diff changeset
4597 */
21862
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4598 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
4599 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
4600 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4601 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
4602 char *msg;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4603 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
4604
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4605 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
4606
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4607 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
4608 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
4609 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4610 /* 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
4611 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
4612 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
4613 }
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4614 else
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4615 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4616 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
4617 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
4618 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4619 /* 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
4620 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
4621 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
4622
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4623 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
4624 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
4625 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
4626 }
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4627 }
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4628
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4629 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
4630 if (!msg)
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4631 {
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4632 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
4633 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
4634 }
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4635
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4636 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
4637
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4638 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
4639 return msg;
ae58ffd5e929 Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents: 21794
diff changeset
4640 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4641
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4642 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4643 purple_utf8_ncr_encode(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4644 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4645 GString *out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4646
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4647 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
4648 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
4649
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4650 out = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4651
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4652 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
4653 gunichar wc = g_utf8_get_char(str);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4654
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4655 /* super simple check. hopefully not too wrong. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4656 if(wc >= 0x80) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4657 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
4658 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4659 g_string_append_unichar(out, wc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4660 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4661 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4662
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4663 return g_string_free(out, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4664 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4665
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4666
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4667 char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4668 purple_utf8_ncr_decode(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4669 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4670 GString *out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4671 char *buf, *b;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4672
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4673 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
4674 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
4675
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4676 buf = (char *) str;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4677 out = g_string_new("");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4678
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4679 while( (b = strstr(buf, "&#")) ) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4680 gunichar wc;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4681 int base = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4682
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4683 /* append everything leading up to the &# */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4684 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
4685
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4686 b += 2; /* skip past the &# */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4687
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4688 /* 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
4689 if(*b == 'x' || *b == 'X') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4690 base = 16;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4691 b++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4692 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4693
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4694 /* 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
4695 wc = (gunichar) strtoul(b, &buf, base);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4696
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4697 /* 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
4698 if(*buf == ';') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4699 g_string_append_unichar(out, wc);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4700 buf++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4701 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4702 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4703
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4704 /* append whatever's left */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4705 g_string_append(out, buf);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4706
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4707 return g_string_free(out, FALSE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4708 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4709
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4710
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4711 int
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4712 purple_utf8_strcasecmp(const char *a, const char *b)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4713 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4714 char *a_norm = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4715 char *b_norm = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4716 int ret = -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4717
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4718 if(!a && b)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4719 return -1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4720 else if(!b && a)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4721 return 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4722 else if(!a && !b)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4723 return 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4724
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4725 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
4726 {
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4727 purple_debug_error("purple_utf8_strcasecmp",
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4728 "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
4729 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4730 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4731
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4732 a_norm = g_utf8_casefold(a, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4733 b_norm = g_utf8_casefold(b, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4734 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
4735 g_free(a_norm);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4736 g_free(b_norm);
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 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4739 }
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 /* previously conversation::find_nick() */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4742 gboolean
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4743 purple_utf8_has_word(const char *haystack, const char *needle)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4744 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4745 char *hay, *pin, *p;
24841
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4746 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: 24592
diff changeset
4747 gunichar before, after;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4748 int n;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4749 gboolean ret = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4750
24841
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4751 start = hay = g_utf8_strdown(haystack, -1);
15373
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 pin = g_utf8_strdown(needle, -1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4754 n = strlen(pin);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4755
24841
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4756 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: 24592
diff changeset
4757 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: 24592
diff changeset
4758 before = -2;
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4759 if (prev_char) {
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4760 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: 24592
diff changeset
4761 }
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4762 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: 24592
diff changeset
4763
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4764 if ((p == hay ||
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4765 /* 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: 24592
diff changeset
4766 ("!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: 24592
diff changeset
4767 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: 24592
diff changeset
4768 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: 24592
diff changeset
4769 (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: 24592
diff changeset
4770 && after != -2 && !g_unichar_isalnum(after)) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4771 ret = TRUE;
24841
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4772 break;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4773 }
24841
e7b27ee5e7b6 Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents: 24592
diff changeset
4774 start = p + 1;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4775 }
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 g_free(pin);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4778 g_free(hay);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4779
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4780 return ret;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4781 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4782
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4783 void
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4784 purple_print_utf8_to_console(FILE *filestream, char *message)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4785 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4786 gchar *message_conv;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4787 GError *error = NULL;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4788
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4789 /* 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
4790 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
4791 if (message_conv != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4792 fputs(message_conv, filestream);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4793 g_free(message_conv);
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 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4796 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4797 /* use 'message' as a fallback */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4798 g_warning("%s\n", error->message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4799 g_error_free(error);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4800 fputs(message, filestream);
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4803
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
4804 gboolean purple_message_meify(char *message, gssize len)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4805 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4806 char *c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4807 gboolean inside_html = FALSE;
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 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
4810
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4811 if(len == -1)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4812 len = strlen(message);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4813
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4814 for (c = message; *c; c++, len--) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4815 if(inside_html) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4816 if(*c == '>')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4817 inside_html = FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4818 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4819 if(*c == '<')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4820 inside_html = TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4821 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4822 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4823 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4824 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4825
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4826 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
4827 memmove(c, c+4, len-3);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4828 return TRUE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4829 }
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 return FALSE;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4832 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4833
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4834 char *purple_text_strip_mnemonic(const char *in)
15373
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 *out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4837 char *a;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4838 char *a0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4839 const char *b;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4840
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4841 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
4842
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4843 out = g_malloc(strlen(in)+1);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4844 a = out;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4845 b = in;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4846
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4847 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
4848
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4849 while(*b) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4850 if(*b == '_') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4851 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
4852 /* Detected CJK style shortcut (Bug 875311) */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4853 a = a0; /* undo the left parenthesis */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4854 b += 3; /* and skip the whole mess */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4855 } else if(*(b+1) == '_') {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4856 *(a++) = '_';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4857 b += 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4858 a0 = a;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4859 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4860 b++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4861 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4862 /* 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
4863 } 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
4864 if (*b != ' ')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4865 a0 = a;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4866 *(a++) = *(b++);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4867 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4868 /* 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
4869 int n = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4870 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4871 if ((*b & 0xe0) == 0xc0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4872 n = 2;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4873 } else if ((*b & 0xf0) == 0xe0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4874 n = 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4875 } else if ((*b & 0xf8) == 0xf0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4876 n = 4;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4877 } else if ((*b & 0xfc) == 0xf8) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4878 n = 5;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4879 } else if ((*b & 0xfe) == 0xfc) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4880 n = 6;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4881 } else { /* Illegal utf8 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4882 n = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4883 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4884 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
4885 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
4886 *(a++) = *(b++);
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 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4889 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4890 *a = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4891
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4892 return out;
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
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4895 const char* purple_unescape_filename(const char *escaped) {
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4896 return purple_url_decode(escaped);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4897 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4898
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4899
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4900 /* this is almost identical to purple_url_encode (hence purple_url_decode
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4901 * 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
4902 * for compat reasons */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4903 const char *
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4904 purple_escape_filename(const char *str)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4905 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4906 const char *iter;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4907 static char buf[BUF_LEN];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4908 char utf_char[6];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4909 guint i, j = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4910
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4911 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
4912 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
4913
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4914 iter = str;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4915 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
4916 gunichar c = g_utf8_get_char(iter);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4917 /* 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
4918 * or one of the specified values, no need to escape */
17161
51f8dac490d7 If we're operating on ASCII characters only, we should use g_ascii_isalnum.
Richard Laager <rlaager@wiktel.com>
parents: 17158
diff changeset
4919 if (c < 128 && (g_ascii_isalnum(c) || c == '@' || c == '-' ||
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4920 c == '_' || c == '.' || c == '#')) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4921 buf[j++] = c;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4922 } else {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4923 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
4924 for (i = 0; i < bytes; i++) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4925 if (j > (BUF_LEN - 4))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4926 break;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4927 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
4928 j += 3;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4929 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4930 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4931 }
30161
626480462902 Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30160
diff changeset
4932 #ifdef _WIN32
626480462902 Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30160
diff changeset
4933 /* File/Directory names in windows cannot end in periods/spaces.
626480462902 Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30160
diff changeset
4934 * http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx
626480462902 Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30160
diff changeset
4935 */
626480462902 Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30160
diff changeset
4936 while (j > 0 && (buf[j - 1] == '.' || buf[j - 1] == ' '))
626480462902 Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30160
diff changeset
4937 j--;
626480462902 Apparently file/directory names in windows cannot end in periods/spaces.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 30160
diff changeset
4938 #endif
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4939 buf[j] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4940
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4941 return buf;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4942 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4943
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4944 const char *_purple_oscar_convert(const char *act, const char *protocol)
15420
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: 15398
diff changeset
4945 {
25894
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: 25890
diff changeset
4946 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
4947 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
4948 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
4949 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
4950 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
4951 return "prpl-icq";
15420
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: 15398
diff changeset
4952 }
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: 15398
diff changeset
4953 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: 15398
diff changeset
4954 }
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: 15398
diff changeset
4955
15822
32c366eeeb99 sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@gmail.com>
parents: 15783
diff changeset
4956 void purple_restore_default_signal_handlers(void)
15645
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: 15612
diff changeset
4957 {
15664
95c4dee525f0 Merge fix and build fix for win32
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15663
diff changeset
4958 #ifndef _WIN32
15645
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: 15612
diff changeset
4959 #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: 15612
diff changeset
4960 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: 15612
diff changeset
4961 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: 15612
diff changeset
4962 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: 15612
diff changeset
4963 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: 15612
diff changeset
4964 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: 15612
diff changeset
4965 signal(SIGABRT, SIG_DFL); /* 6: abort program */
15661
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: 15645
diff changeset
4966
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: 15645
diff changeset
4967 #ifdef SIGPOLL
16487
b8b2e35ec7c6 Fix purple_util_get_image_extension()'s data param. to be correctly marked as constant.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16475
diff changeset
4968 signal(SIGPOLL, SIG_DFL); /* 7: pollable event (POSIX) */
15661
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: 15645
diff changeset
4969 #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: 15645
diff changeset
4970
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: 15645
diff changeset
4971 #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: 15645
diff changeset
4972 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: 15645
diff changeset
4973 #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: 15645
diff changeset
4974
15645
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: 15612
diff changeset
4975 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: 15612
diff changeset
4976 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: 15612
diff changeset
4977 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: 15612
diff changeset
4978 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: 15612
diff changeset
4979 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: 15612
diff changeset
4980 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: 15612
diff changeset
4981 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: 15612
diff changeset
4982 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: 15612
diff changeset
4983 signal(SIGXCPU, SIG_DFL); /* 24: exceeded CPU time limit */
16487
b8b2e35ec7c6 Fix purple_util_get_image_extension()'s data param. to be correctly marked as constant.
Daniel Atallah <daniel.atallah@gmail.com>
parents: 16475
diff changeset
4984 signal(SIGXFSZ, SIG_DFL); /* 25: exceeded file size limit */
15661
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: 15645
diff changeset
4985 #endif /* HAVE_SIGNAL_H */
15664
95c4dee525f0 Merge fix and build fix for win32
Daniel Atallah <daniel.atallah@gmail.com>
parents: 15663
diff changeset
4986 #endif /* !_WIN32 */
15645
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: 15612
diff changeset
4987 }
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
4988
22089
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
4989 static void
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
4990 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
4991 {
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
4992 va_list args;
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
4993 va_start(args, status);
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
4994 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
4995 va_end(args);
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
4996 }
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
4997
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
4998 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
4999 {
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5000 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
5001 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
5002 PurplePresence *presence;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5003 PurpleStatus *tune;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5004 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
5005 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
5006 continue;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5007
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5008 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
5009 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
5010 if (!tune)
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5011 continue;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5012 if (title) {
22089
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5013 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
5014 PURPLE_TUNE_TITLE, title,
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5015 PURPLE_TUNE_ARTIST, artist,
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5016 PURPLE_TUNE_ALBUM, album,
1e227e2587e6 Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22060
diff changeset
5017 NULL);
22000
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5018 } else {
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5019 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
5020 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5021 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5022 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5023
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5024 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
5025 {
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5026 GString *string;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5027 char *esc;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5028
22060
83613550512b Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22000
diff changeset
5029 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
5030 return NULL;
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5031
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5032 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
5033 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
5034 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
5035 g_free(esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5036
22060
83613550512b Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22000
diff changeset
5037 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
5038 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
5039 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
5040 g_free(esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5041 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5042
22060
83613550512b Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22000
diff changeset
5043 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
5044 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
5045 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
5046 g_free(esc);
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5047 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5048
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5049 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
5050 }
af0426c34c27 Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21863
diff changeset
5051
23538
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23388
diff changeset
5052 const gchar *
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23388
diff changeset
5053 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: 23388
diff changeset
5054 {
399975ad001c Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23388
diff changeset
5055 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: 23388
diff changeset
5056 }
29129
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5057
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5058 gchar *
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5059 purple_uuid_random(void)
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5060 {
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5061 guint32 tmp, a, b;
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5062
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5063 tmp = g_random_int();
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5064 a = 0x4000 | (tmp & 0xFFF); /* 0x4000 to 0x4FFF */
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5065 tmp >>= 12;
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5066 b = ((1 << 3) << 12) | (tmp & 0x3FFF); /* 0x8000 to 0xBFFF */
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5067
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5068 tmp = g_random_int();
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5069
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5070 return g_strdup_printf("%08x-%04x-%04x-%04x-%04x%08x",
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5071 g_random_int(),
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5072 tmp & 0xFFFF,
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5073 a,
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5074 b,
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5075 (tmp >> 16) & 0xFFFF, g_random_int());
ecd2136ff818 Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents: 29110
diff changeset
5076 }