Mercurial > pidgin
annotate libpurple/util.c @ 30832:eabeba9c823f
Move msn_xfer code to it's own module aiming to simplify slp code.
author | masca@cpw.pidgin.im |
---|---|
date | Tue, 29 Jun 2010 22:18:22 +0000 |
parents | b06f69ada7a5 |
children | 844181ded506 |
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" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
31 #include "prpl.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
32 #include "prefs.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
33 #include "util.h" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
34 |
15822 | 35 struct _PurpleUtilFetchUrlData |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
36 { |
15822 | 37 PurpleUtilFetchUrlCallback callback; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
38 void *user_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
39 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
40 struct |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
41 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
42 char *user; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
43 char *passwd; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
44 char *address; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
45 int port; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
46 char *page; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
47 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
48 } website; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
49 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
50 char *url; |
17450
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
51 int num_times_redirected; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
52 gboolean full; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
53 char *user_agent; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
54 gboolean http11; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
55 char *request; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
56 gsize request_written; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
57 gboolean include_headers; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
58 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
59 gboolean is_ssl; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
60 PurpleSslConnection *ssl_connection; |
15822 | 61 PurpleProxyConnectData *connect_data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
62 int fd; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
63 guint inpa; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
64 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
65 gboolean got_headers; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
66 gboolean has_explicit_data_len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
67 char *webdata; |
27445
065294d973b4
This fixes this compile warning:
Stu Tomlinson <stu@nosnilmot.com>
parents:
27404
diff
changeset
|
68 gsize len; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
69 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
|
70 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
|
71 gboolean chunked; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
72 }; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
73 |
18147
5653692dcf79
Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents:
18129
diff
changeset
|
74 static char *custom_user_dir = NULL; |
20091
2ab6b55ffa3d
Rename the internal home_dir variable to user_dir to match the function and
Richard Laager <rlaager@wiktel.com>
parents:
20074
diff
changeset
|
75 static char *user_dir = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
76 |
21248
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
77 |
15822 | 78 PurpleMenuAction * |
79 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
|
80 GList *children) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
81 { |
15822 | 82 PurpleMenuAction *act = g_new0(PurpleMenuAction, 1); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
83 act->label = g_strdup(label); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
84 act->callback = callback; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
85 act->data = data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
86 act->children = children; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
87 return act; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
88 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
89 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
90 void |
15822 | 91 purple_menu_action_free(PurpleMenuAction *act) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
92 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
93 g_return_if_fail(act != NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
94 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
95 g_free(act->label); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
96 g_free(act); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
97 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
98 |
21248
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
99 void |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
100 purple_util_init(void) |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
101 { |
25924
584063555949
Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents:
25894
diff
changeset
|
102 /* This does nothing right now. It exists for symmetry with |
21248
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
103 * purple_util_uninit() and forwards compatibility. */ |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
104 } |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
105 |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
106 void |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
107 purple_util_uninit(void) |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
108 { |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
109 /* Free these so we don't have leaks at shutdown. */ |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
110 |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
111 g_free(custom_user_dir); |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
112 custom_user_dir = NULL; |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
113 |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
114 g_free(user_dir); |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
115 user_dir = NULL; |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
116 } |
5915ad785ee7
Add and call a purple_util_uninit() to free user_dir and customer_home_dir
Richard Laager <rlaager@wiktel.com>
parents:
20917
diff
changeset
|
117 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
118 /************************************************************************** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
119 * Base16 Functions |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
120 **************************************************************************/ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
121 gchar * |
15822 | 122 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
|
123 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
124 int i; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
125 gchar *ascii = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
126 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
127 g_return_val_if_fail(data != NULL, NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
128 g_return_val_if_fail(len > 0, NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
129 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
130 ascii = g_malloc(len * 2 + 1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
131 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
132 for (i = 0; i < len; i++) |
26885
8290e36a5a73
A patch from Scott Wolchok to replace snprintf() with g_snprintf() and
Richard Laager <rlaager@wiktel.com>
parents:
26772
diff
changeset
|
133 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
|
134 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
135 return ascii; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
136 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
137 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
138 guchar * |
15822 | 139 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
|
140 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
141 int len, i, accumulator = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
142 guchar *data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
143 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
144 g_return_val_if_fail(str != NULL, NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
145 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
146 len = strlen(str); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
147 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
148 g_return_val_if_fail(strlen(str) > 0, 0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
149 g_return_val_if_fail(len % 2 == 0, 0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
150 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
151 data = g_malloc(len / 2); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
152 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
153 for (i = 0; i < len; i++) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
154 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
155 if ((i % 2) == 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
156 accumulator = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
157 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
158 accumulator <<= 4; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
159 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
160 if (isdigit(str[i])) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
161 accumulator |= str[i] - 48; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
162 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
163 { |
16153
6613fb7af427
Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents:
16084
diff
changeset
|
164 switch(tolower(str[i])) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
165 { |
16153
6613fb7af427
Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents:
16084
diff
changeset
|
166 case 'a': accumulator |= 10; break; |
6613fb7af427
Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents:
16084
diff
changeset
|
167 case 'b': accumulator |= 11; break; |
6613fb7af427
Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents:
16084
diff
changeset
|
168 case 'c': accumulator |= 12; break; |
6613fb7af427
Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents:
16084
diff
changeset
|
169 case 'd': accumulator |= 13; break; |
6613fb7af427
Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents:
16084
diff
changeset
|
170 case 'e': accumulator |= 14; break; |
6613fb7af427
Call strtolower() so that we don't have to check against the
Mark Doliner <mark@kingant.net>
parents:
16084
diff
changeset
|
171 case 'f': accumulator |= 15; break; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
172 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
173 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
174 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
175 if (i % 2) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
176 data[(i - 1) / 2] = accumulator; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
177 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
178 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
179 if (ret_len != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
180 *ret_len = len / 2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
181 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
182 return data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
183 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
184 |
17765
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
185 gchar * |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
186 purple_base16_encode_chunked(const guchar *data, gsize len) |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
187 { |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
188 int i; |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
189 gchar *ascii = NULL; |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
190 |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
191 g_return_val_if_fail(data != NULL, NULL); |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
192 g_return_val_if_fail(len > 0, NULL); |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
193 |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
194 /* For each byte of input, we need 2 bytes for the hex representation |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
195 * and 1 for the colon. |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
196 * The final colon will be replaced by a terminating NULL |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
197 */ |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
198 ascii = g_malloc(len * 3 + 1); |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
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 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
|
201 g_snprintf(&ascii[i * 3], 4, "%02hhx:", data[i]); |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
202 |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
203 /* Replace the final colon with NULL */ |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
204 ascii[len * 3 - 1] = 0; |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
205 |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
206 return ascii; |
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 |
ba768014f91f
- Add purple_base16_encode_chunked, which is handy for key fingerprints.
William Ehlhardt <williamehlhardt@gmail.com>
parents:
17195
diff
changeset
|
209 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
210 /************************************************************************** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
211 * Base64 Functions |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
212 **************************************************************************/ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
213 static const char alphabet[] = |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
214 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
215 "0123456789+/"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
216 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
217 static const char xdigits[] = |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
218 "0123456789abcdef"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
219 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
220 gchar * |
15822 | 221 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
|
222 { |
27217
3d92b968d49f
Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents:
27137
diff
changeset
|
223 return g_base64_encode(data, len); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
224 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
225 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
226 guchar * |
15822 | 227 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
|
228 { |
27217
3d92b968d49f
Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents:
27137
diff
changeset
|
229 /* |
3d92b968d49f
Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents:
27137
diff
changeset
|
230 * 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
|
231 * 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
|
232 * 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
|
233 */ |
3d92b968d49f
Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents:
27137
diff
changeset
|
234 gsize unused; |
3d92b968d49f
Use glib's base64 encode and decode functions if they're available.
Mark Doliner <mark@kingant.net>
parents:
27137
diff
changeset
|
235 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
|
236 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
237 |
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 * Quoted Printable Functions (see RFC 2045). |
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 guchar * |
15822 | 242 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
|
243 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
244 char *n, *new; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
245 const char *end, *p; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
246 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
247 n = new = g_malloc(strlen (str) + 1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
248 end = str + strlen(str); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
249 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
250 for (p = str; p < end; p++, n++) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
251 if (*p == '=') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
252 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
|
253 n -= 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
254 p += 2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
255 } 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
|
256 n -= 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
257 p += 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
258 } else if (p[1] && p[2]) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
259 char *nibble1 = strchr(xdigits, tolower(p[1])); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
260 char *nibble2 = strchr(xdigits, tolower(p[2])); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
261 if (nibble1 && nibble2) { /* 5.1 #1 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
262 *n = ((nibble1 - xdigits) << 4) | (nibble2 - xdigits); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
263 p += 2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
264 } else { /* This should never happen */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
265 *n = *p; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
266 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
267 } else { /* This should never happen */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
268 *n = *p; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
269 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
270 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
271 else if (*p == '_') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
272 *n = ' '; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
273 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
274 *n = *p; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
275 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
276 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
277 *n = '\0'; |
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 if (ret_len != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
280 *ret_len = n - new; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
281 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
282 /* Resize to take less space */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
283 /* new = realloc(new, n - new); */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
284 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
285 return (guchar *)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 |
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 * MIME Functions |
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 char * |
15822 | 292 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
|
293 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
294 /* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
295 * 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
|
296 * See RFC2047 [which apparently obsoletes RFC1342] |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
297 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
298 typedef enum { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
299 state_start, state_equal1, state_question1, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
300 state_charset, state_question2, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
301 state_encoding, state_question3, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
302 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
|
303 } encoded_word_state_t; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
304 encoded_word_state_t state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
305 const char *cur, *mark; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
306 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
|
307 GString *new; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
308 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
309 /* 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
|
310 #define token_char_p(c) \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
311 (c != ' ' && !iscntrl(c) && !strchr("()<>@,;:\"/[]?.=", c)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
312 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
313 /* 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
|
314 #define encoded_text_char_p(c) \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
315 ((c & 0x80) == 0 && c != '?' && c != ' ' && isgraph(c)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
316 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
317 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
|
318 |
27907
9358464cdf6a
How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents:
27860
diff
changeset
|
319 new = g_string_new(NULL); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
320 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
321 /* 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
|
322 * valid then decode them. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
323 * 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
|
324 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
325 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
326 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
|
327 switch (state) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
328 case state_equal1: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
329 if (*cur == '?') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
330 state = state_question1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
331 } else { |
27907
9358464cdf6a
How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents:
27860
diff
changeset
|
332 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
|
333 state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
334 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
335 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
336 case state_question1: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
337 if (token_char_p(*cur)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
338 charset0 = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
339 state = state_charset; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
340 } 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
|
341 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
|
342 state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
343 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
344 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
345 case state_charset: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
346 if (*cur == '?') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
347 state = state_question2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
348 } 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
|
349 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
|
350 state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
351 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
352 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
353 case state_question2: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
354 if (token_char_p(*cur)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
355 encoding0 = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
356 state = state_encoding; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
357 } 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
|
358 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
|
359 state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
360 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
361 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
362 case state_encoding: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
363 if (*cur == '?') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
364 state = state_question3; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
365 } 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
|
366 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
|
367 state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
368 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
369 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
370 case state_question3: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
371 if (encoded_text_char_p(*cur)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
372 encoded_text0 = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
373 state = state_encoded_text; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
374 } else if (*cur == '?') { /* empty string */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
375 encoded_text0 = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
376 state = state_question4; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
377 } 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
|
378 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
|
379 state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
380 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
381 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
382 case state_encoded_text: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
383 if (*cur == '?') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
384 state = state_question4; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
385 } 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
|
386 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
|
387 state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
388 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
389 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
390 case state_question4: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
391 if (*cur == '=') { /* Got the whole encoded-word */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
392 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
|
393 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
|
394 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
|
395 guchar *decoded = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
396 gsize dec_len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
397 if (g_ascii_strcasecmp(encoding, "Q") == 0) |
15822 | 398 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
|
399 else if (g_ascii_strcasecmp(encoding, "B") == 0) |
15822 | 400 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
|
401 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
402 decoded = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
403 if (decoded) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
404 gsize len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
405 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
|
406 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
407 if (converted) { |
27907
9358464cdf6a
How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents:
27860
diff
changeset
|
408 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
|
409 g_free(converted); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
410 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
411 g_free(decoded); |
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(charset); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
414 g_free(encoding); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
415 g_free(encoded_text); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
416 state = state_equal2; /* Restart the FSM */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
417 } 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
|
418 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
|
419 state = state_start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
420 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
421 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
422 default: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
423 if (*cur == '=') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
424 mark = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
425 state = state_equal1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
426 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
427 /* 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
|
428 g_string_append_c(new, *cur); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
429 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
430 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
431 } /* switch */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
432 } /* for */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
433 |
27907
9358464cdf6a
How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents:
27860
diff
changeset
|
434 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
|
435 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
|
436 |
9358464cdf6a
How about we just use a GString instead of this ridiculous
Mark Doliner <mark@kingant.net>
parents:
27860
diff
changeset
|
437 return g_string_free(new, FALSE);; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
438 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
439 |
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 * Date/Time Functions |
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 |
18259
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
445 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
|
446 { |
18259
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
447 static char buf[7]; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
448 long off; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
449 gint8 min; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
450 gint8 hrs; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
451 struct tm new_tm = *tm; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
452 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
453 mktime(&new_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 if (new_tm.tm_isdst < 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
456 g_return_val_if_reached(""); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
457 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
458 #ifdef _WIN32 |
20503
905891855710
3rd time the charm? Fixes #2990, maybe
Ka-Hing Cheung <khc@hxbc.us>
parents:
19499
diff
changeset
|
459 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
|
460 return ""; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
461 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
462 # ifdef HAVE_TM_GMTOFF |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
463 off = new_tm.tm_gmtoff; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
464 # else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
465 # ifdef HAVE_TIMEZONE |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
466 tzset(); |
18259
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
467 off = -1 * timezone; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
468 # endif /* HAVE_TIMEZONE */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
469 # endif /* !HAVE_TM_GMTOFF */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
470 #endif /* _WIN32 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
471 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
472 min = (off / 60) % 60; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
473 hrs = ((off / 60) - min) / 60; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
474 |
18259
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
475 if(iso) { |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
476 if (0 == off) { |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
477 strcpy(buf, "Z"); |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
478 } else { |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
479 /* 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
|
480 * wants them */ |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
481 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
|
482 g_return_val_if_reached(""); |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
483 } |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
484 } else { |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
485 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
|
486 g_return_val_if_reached(""); |
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
487 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
488 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
489 return buf; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
492 /* 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
|
493 #if !defined(HAVE_STRFTIME_Z_FORMAT) || defined(_WIN32) |
15822 | 494 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
|
495 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
496 const char *start; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
497 const char *c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
498 char *fmt = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
499 |
15822 | 500 /* 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
|
501 * but better safe than sorry. -- rlaager */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
502 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
|
503 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
504 /* 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
|
505 * executed on Windows or if the underlying |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
506 * 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
|
507 * 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
|
508 * -- rlaager */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
509 for (c = start = format; *c ; c++) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
510 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
511 if (*c != '%') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
512 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
513 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
514 c++; |
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 #ifndef HAVE_STRFTIME_Z_FORMAT |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
517 if (*c == 'z') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
518 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
519 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
|
520 fmt ? fmt : "", |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
521 c - start - 1, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
522 start, |
18259
c5c265dff90c
support replying to XEP-0202 queries
Nathan Walp <nwalp@pidgin.im>
parents:
18147
diff
changeset
|
523 purple_get_tzoff_str(tm, FALSE)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
524 g_free(fmt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
525 fmt = tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
526 start = c + 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
527 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
528 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
529 #ifdef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
530 if (*c == 'Z') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
531 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
532 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
|
533 fmt ? fmt : "", |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
534 c - start - 1, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
535 start, |
15822 | 536 wpurple_get_timezone_abbreviation(tm)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
537 g_free(fmt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
538 fmt = tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
539 start = c + 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
540 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
541 #endif |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
544 if (fmt != NULL) |
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 size_t ret; |
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 if (*start) |
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 char *tmp = g_strconcat(fmt, start, NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
551 g_free(fmt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
552 fmt = tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
553 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
554 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
555 ret = strftime(s, max, fmt, tm); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
556 g_free(fmt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
557 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
558 return ret; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
561 return strftime(s, max, format, tm); |
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 #else /* HAVE_STRFTIME_Z_FORMAT && !_WIN32 */ |
15822 | 564 #define purple_internal_strftime strftime |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
565 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
566 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
567 const char * |
15822 | 568 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
|
569 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
570 static char buf[128]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
571 char *locale; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
572 GError *err = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
573 int len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
574 char *utf8; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
575 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
576 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
|
577 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
578 if (tm == 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 time_t now = time(NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
581 tm = localtime(&now); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
582 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
583 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
584 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
|
585 if (err != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
586 { |
19654
941965d6fd88
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19603
diff
changeset
|
587 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
|
588 g_error_free(err); |
29738
4e5cfb6ad471
util: Fix a crash in purple_utf8_strftime.
Florian Quèze <florian@instantbird.org>
parents:
29641
diff
changeset
|
589 err = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
590 locale = g_strdup(format); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
591 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
592 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
593 /* 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
|
594 * 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
|
595 * undefined) or the empty string (in which |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
596 * case, no harm is done here). */ |
15822 | 597 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
|
598 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
599 g_free(locale); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
600 return ""; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
601 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
602 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
603 g_free(locale); |
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 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
|
606 if (err != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
607 { |
19654
941965d6fd88
Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19603
diff
changeset
|
608 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
|
609 g_error_free(err); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
610 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
611 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
612 { |
15822 | 613 purple_strlcpy(buf, utf8); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
614 g_free(utf8); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
615 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
616 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
617 return buf; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
620 const char * |
15822 | 621 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
|
622 { |
15822 | 623 return purple_utf8_strftime("%x", tm); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
624 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
625 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
626 const char * |
15822 | 627 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
|
628 { |
23666
187a3649f04b
Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents:
23652
diff
changeset
|
629 /* |
187a3649f04b
Add a note for translators, because they probably have no idea what
Mark Doliner <mark@kingant.net>
parents:
23652
diff
changeset
|
630 * 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
|
631 * 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
|
632 * 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
|
633 * 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
|
634 */ |
15822 | 635 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
|
636 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
637 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
638 const char * |
15822 | 639 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
|
640 { |
15822 | 641 return purple_utf8_strftime("%c", tm); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
642 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
643 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
644 const char * |
15822 | 645 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
|
646 { |
15822 | 647 return purple_utf8_strftime("%X", tm); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
648 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
649 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
650 time_t |
15822 | 651 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
|
652 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
653 struct tm tm; |
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 tm.tm_year = year - 1900; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
656 tm.tm_mon = month - 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
657 tm.tm_mday = day; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
658 tm.tm_hour = hour; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
659 tm.tm_min = min; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
660 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
|
661 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
662 return mktime(&tm); |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
665 time_t |
15822 | 666 purple_str_to_time(const char *timestamp, gboolean utc, |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
667 struct tm *tm, long *tz_off, const char **rest) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
668 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
669 time_t retval = 0; |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
670 static struct tm t; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
671 const char *c = timestamp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
672 int year = 0; |
15822 | 673 long tzoff = PURPLE_NO_TZ_OFF; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
674 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
675 time(&retval); |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
676 localtime_r(&retval, &t); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
677 |
23975
b789b54c5bb2
purple_str_to_time() didn't necessarily set "rest" under all circumstances.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
23734
diff
changeset
|
678 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
|
679 *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
|
680 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
681 /* 4 digit year */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
682 if (sscanf(c, "%04d", &year) && year > 1900) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
683 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
684 c += 4; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
685 if (*c == '-') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
686 c++; |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
687 t.tm_year = year - 1900; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
688 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
689 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
690 /* 2 digit month */ |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
691 if (!sscanf(c, "%02d", &t.tm_mon)) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
692 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
693 if (rest != NULL && *c != '\0') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
694 *rest = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
695 return 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
696 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
697 c += 2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
698 if (*c == '-' || *c == '/') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
699 c++; |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
700 t.tm_mon -= 1; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
701 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
702 /* 2 digit day */ |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
703 if (!sscanf(c, "%02d", &t.tm_mday)) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
704 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
705 if (rest != NULL && *c != '\0') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
706 *rest = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
707 return 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
708 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
709 c += 2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
710 if (*c == '/') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
711 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
712 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
713 |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
714 if (!sscanf(c, "%04d", &t.tm_year)) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
715 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
716 if (rest != NULL && *c != '\0') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
717 *rest = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
718 return 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
719 } |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
720 t.tm_year -= 1900; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
721 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
722 else if (*c == 'T' || *c == '.') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
723 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
724 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
725 /* we have more than a date, keep going */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
726 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
727 /* 2 digit hour */ |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
728 if ((sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 && (c = c + 8)) || |
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
729 (sscanf(c, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 && (c = c + 6))) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
730 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
731 gboolean offset_positive = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
732 int tzhrs; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
733 int tzmins; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
734 |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
735 t.tm_isdst = -1; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
736 |
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
|
737 if (*c == '.') { |
87387eac4348
Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents:
21580
diff
changeset
|
738 do { |
87387eac4348
Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents:
21580
diff
changeset
|
739 c++; |
87387eac4348
Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents:
21580
diff
changeset
|
740 } while (*c >= '0' && *c <= '9'); /* dealing with precision we don't care about */ |
87387eac4348
Fix a bug in purple_str_to_time() that could cause it to try reading past
Stu Tomlinson <stu@nosnilmot.com>
parents:
21580
diff
changeset
|
741 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
742 if (*c == '+') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
743 offset_positive = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
744 if (((*c == '+' || *c == '-') && (c = c + 1)) && |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
745 ((sscanf(c, "%02d:%02d", &tzhrs, &tzmins) == 2 && (c = c + 5)) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
746 (sscanf(c, "%02d%02d", &tzhrs, &tzmins) == 2 && (c = c + 4)))) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
747 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
748 tzoff = tzhrs*60*60 + tzmins*60; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
749 if (offset_positive) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
750 tzoff *= -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
751 } |
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
|
752 else if ((*c == 'Z') && (c = c + 1)) |
ef4dbd2bb696
Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23248
diff
changeset
|
753 { |
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
|
754 /* 'Z' = Zulu = UTC */ |
ef4dbd2bb696
Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23248
diff
changeset
|
755 tzoff = 0; |
ef4dbd2bb696
Allow a 'Z' (UTC) TZ in strings passed to purple_str_to_time. Used for
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
23248
diff
changeset
|
756 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
757 else if (utc) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
758 { |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
759 static struct tm tmptm; |
21612
18fb032a602a
Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents:
21611
diff
changeset
|
760 time_t tmp; |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
761 tmp = mktime(&t); |
21612
18fb032a602a
Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents:
21611
diff
changeset
|
762 /* we care about whether it *was* dst, and the offset, here on this |
18fb032a602a
Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents:
21611
diff
changeset
|
763 * date, not whether we are currently observing dst locally *now*. |
18fb032a602a
Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents:
21611
diff
changeset
|
764 * This isn't perfect, because we would need to know in advance the |
18fb032a602a
Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents:
21611
diff
changeset
|
765 * offset we are trying to work out in advance to be sure this |
18fb032a602a
Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents:
21611
diff
changeset
|
766 * works for times around dst transitions but it'll have to do. */ |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
767 localtime_r(&tmp, &tmptm); |
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
768 t.tm_isdst = tmptm.tm_isdst; |
21612
18fb032a602a
Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents:
21611
diff
changeset
|
769 #ifdef HAVE_TM_GMTOFF |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
770 t.tm_gmtoff = tmptm.tm_gmtoff; |
21612
18fb032a602a
Fix the bug in purple_str_to_time() that was causing 'make check' to fail.
Stu Tomlinson <stu@nosnilmot.com>
parents:
21611
diff
changeset
|
771 #endif |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
772 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
773 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
774 if (rest != NULL && *c != '\0') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
775 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
776 if (*c == ' ') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
777 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
778 if (*c != '\0') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
779 *rest = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
780 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
781 |
15822 | 782 if (tzoff != PURPLE_NO_TZ_OFF || utc) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
783 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
784 #if defined(_WIN32) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
785 long sys_tzoff; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
786 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
787 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
788 #if defined(_WIN32) || defined(HAVE_TM_GMTOFF) || defined (HAVE_TIMEZONE) |
15822 | 789 if (tzoff == PURPLE_NO_TZ_OFF) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
790 tzoff = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
791 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
792 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
793 #ifdef _WIN32 |
20503
905891855710
3rd time the charm? Fixes #2990, maybe
Ka-Hing Cheung <khc@hxbc.us>
parents:
19499
diff
changeset
|
794 if ((sys_tzoff = wpurple_get_tz_offset()) == -1) |
15822 | 795 tzoff = PURPLE_NO_TZ_OFF; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
796 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
797 tzoff += sys_tzoff; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
798 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
799 #ifdef HAVE_TM_GMTOFF |
21613
31101e7d275f
'man 3 ctime' says of localtime() (and friends):
Stu Tomlinson <stu@nosnilmot.com>
parents:
21612
diff
changeset
|
800 tzoff += t.tm_gmtoff; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
801 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
802 # ifdef HAVE_TIMEZONE |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
803 tzset(); /* making sure */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
804 tzoff -= timezone; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
805 # endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
806 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
807 #endif /* _WIN32 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
808 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
809 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
810 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
811 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
812 if (rest != NULL && *c != '\0') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
813 *rest = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
814 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
815 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
816 |
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
|
817 retval = mktime(&t); |
8dadddab10ed
Fix purple_str_to_time() to not break the returned value when we have given
Richard Laager <rlaager@wiktel.com>
parents:
22864
diff
changeset
|
818 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
819 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
|
820 *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
|
821 |
15822 | 822 if (tzoff != PURPLE_NO_TZ_OFF) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
823 retval += tzoff; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
824 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
825 if (tz_off != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
826 *tz_off = tzoff; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
827 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
828 return retval; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
829 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
830 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
831 /************************************************************************** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
832 * Markup Functions |
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 |
27393
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
835 /* |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
836 * 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
|
837 * replace ' with ' |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
838 */ |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
839 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
|
840 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
|
841 { |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
842 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
|
843 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
|
844 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
|
845 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
846 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
|
847 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
|
848 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
849 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
|
850 { |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
851 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
|
852 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
|
853 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
854 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
|
855 { |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
856 case '&': |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
857 g_string_append (str, "&"); |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
858 break; |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
859 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
860 case '<': |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
861 g_string_append (str, "<"); |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
862 break; |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
863 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
864 case '>': |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
865 g_string_append (str, ">"); |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
866 break; |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
867 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
868 case '"': |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
869 g_string_append (str, """); |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
870 break; |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
871 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
872 default: |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
873 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
|
874 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
|
875 (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
|
876 (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
|
877 (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
|
878 (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
|
879 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
|
880 else |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
881 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
|
882 break; |
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 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
885 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
|
886 } |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
887 } |
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 /* 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
|
890 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
|
891 { |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
892 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
|
893 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
894 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
|
895 |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
896 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
|
897 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
|
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 /* 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
|
900 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
|
901 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
|
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 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
|
904 } |
57fdb7853fc7
Create a purple_markup_escape_text() function and use it in one place
Mark Doliner <mark@kingant.net>
parents:
27378
diff
changeset
|
905 |
16083
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
906 const char * |
16084 | 907 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
|
908 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
909 const char *pln; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
910 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
|
911 char temp[2]; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
912 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
913 if (!text || *text != '&') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
914 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
915 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
916 #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
|
917 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
918 if(IS_ENTITY("&")) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
919 pln = "&"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
920 else if(IS_ENTITY("<")) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
921 pln = "<"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
922 else if(IS_ENTITY(">")) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
923 pln = ">"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
924 else if(IS_ENTITY(" ")) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
925 pln = " "; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
926 else if(IS_ENTITY("©")) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
927 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
|
928 else if(IS_ENTITY(""")) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
929 pln = "\""; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
930 else if(IS_ENTITY("®")) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
931 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
|
932 else if(IS_ENTITY("'")) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
933 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
|
934 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
|
935 (sscanf(text, "&#%u%1[;]", £, 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
|
936 sscanf(text, "&#x%x%1[;]", £, 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
|
937 pound != 0) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
938 static char buf[7]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
939 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
|
940 buf[buflen] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
941 pln = buf; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
942 |
27295
d4c6d2c6fb03
Fix purple_markup_unescape_entity to properly consume '\' and similar.
Paul Aurich <paul@darkrain42.org>
parents:
27281
diff
changeset
|
943 len = (*(text+2) == 'x' ? 3 : 2); |
d4c6d2c6fb03
Fix purple_markup_unescape_entity to properly consume '\' and similar.
Paul Aurich <paul@darkrain42.org>
parents:
27281
diff
changeset
|
944 while(isxdigit((gint) text[len])) len++; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
945 if(text[len] == ';') len++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
946 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
947 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
948 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
949 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
950 if (length) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
951 *length = len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
952 return pln; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
953 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
954 |
16084 | 955 char * |
956 purple_markup_get_css_property(const gchar *style, | |
957 const gchar *opt) | |
16083
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
958 { |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
959 const gchar *css_str = style; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
960 const gchar *css_value_start; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
961 const gchar *css_value_end; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
962 gchar *tmp; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
963 gchar *ret; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
964 |
24421 | 965 g_return_val_if_fail(opt != NULL, NULL); |
966 | |
16084 | 967 if (!css_str) |
16083
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
968 return NULL; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
969 |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
970 /* find the CSS property */ |
16084 | 971 while (1) |
972 { | |
973 /* skip whitespace characters */ | |
974 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
|
975 css_str++; |
16084 | 976 if (!g_ascii_isalpha(*css_str)) |
16083
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
977 return NULL; |
16084 | 978 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
|
979 { |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
980 /* go to next css property positioned after the next ';' */ |
16084 | 981 while (*css_str && *css_str != '"' && *css_str != ';') |
16083
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
982 css_str++; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
983 if(*css_str != ';') |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
984 return NULL; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
985 css_str++; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
986 } |
16084 | 987 else |
988 break; | |
16083
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
989 } |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
990 |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
991 /* find the CSS value position in the string */ |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
992 css_str += strlen(opt); |
16084 | 993 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
|
994 css_str++; |
16084 | 995 if (*css_str != ':') |
16083
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
996 return NULL; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
997 css_str++; |
16084 | 998 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
|
999 css_str++; |
16084 | 1000 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
|
1001 return NULL; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1002 |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1003 /* mark the CSS value */ |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1004 css_value_start = css_str; |
16084 | 1005 while (*css_str && *css_str != '"' && *css_str != ';') |
16083
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1006 css_str++; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1007 css_value_end = css_str - 1; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1008 |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1009 /* Removes trailing whitespace */ |
16084 | 1010 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
|
1011 css_value_end--; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1012 |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1013 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
|
1014 ret = purple_unescape_html(tmp); |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1015 g_free(tmp); |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1016 |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1017 return ret; |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1018 } |
f2a4b05407d7
Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents:
16063
diff
changeset
|
1019 |
27012
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1020 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
|
1021 { |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1022 GData *attributes; |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1023 const gchar *start, *end; |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1024 gboolean res = FALSE; |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1025 |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1026 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
|
1027 { |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1028 /* 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
|
1029 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
|
1030 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
|
1031 res = TRUE; |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1032 if (!res) |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1033 { |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1034 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
|
1035 if (tmp) |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1036 { |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1037 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
|
1038 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
|
1039 res = TRUE; |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1040 g_free(tmp2); |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1041 } |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1042 |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1043 } |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1044 g_datalist_clear(&attributes); |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1045 } |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1046 return res; |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1047 } |
af4a4ebc6441
Add a utlity function purple_markup_is_rtl
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
26969
diff
changeset
|
1048 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1049 gboolean |
15822 | 1050 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
|
1051 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
|
1052 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1053 GData *attribs; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1054 const char *cur = haystack; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1055 char *name = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1056 gboolean found = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1057 gboolean in_tag = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1058 gboolean in_attr = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1059 const char *in_quotes = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1060 size_t needlelen; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1061 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
1066 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
|
1067 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
|
1068 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1069 needlelen = strlen(needle); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1070 g_datalist_init(&attribs); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1071 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1072 while (*cur && !found) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1073 if (in_tag) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1074 if (in_quotes) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1075 const char *close = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1076 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1077 while (*close && *close != *in_quotes) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1078 close++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1079 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1080 /* 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
|
1081 * 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
|
1082 * and we're outta here */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1083 if (*close) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1084 /* 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
|
1085 if (name) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1086 size_t len = close - cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1087 char *val = g_strndup(cur, len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1088 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1089 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
|
1090 g_free(name); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1091 name = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1092 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1093 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1094 in_quotes = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1095 cur = close + 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1096 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1097 cur = close; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1098 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1099 } else if (in_attr) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1100 const char *close = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1101 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1102 while (*close && *close != '>' && *close != '"' && |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1103 *close != '\'' && *close != ' ' && *close != '=') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1104 close++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1105 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1106 /* 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
|
1107 * 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
|
1108 * 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
|
1109 * so we can get outta here */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1110 switch (*close) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1111 case '"': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1112 case '\'': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1113 in_quotes = close; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1114 case '=': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1115 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1116 size_t len = close - cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1117 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1118 /* don't store a blank attribute name */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1119 if (len) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1120 g_free(name); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1121 name = g_ascii_strdown(cur, len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1122 } |
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 in_attr = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1125 cur = close + 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1126 break; |
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 case ' ': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1129 case '>': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1130 in_attr = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1131 default: |
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 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1134 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1135 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1136 switch (*cur) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1137 case ' ': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1138 /* swallow extra spaces inside tag */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1139 while (*cur && *cur == ' ') cur++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1140 in_attr = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1141 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1142 case '>': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1143 found = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1144 *end = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1145 break; |
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 = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1149 default: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1150 cur++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1151 break; |
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 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1154 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1155 /* 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
|
1156 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
|
1157 *start = cur; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1158 cur = cur + needlelen + 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1159 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1160 /* 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
|
1161 * 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
|
1162 * >, 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
|
1163 if (*cur == ' ' || *cur == '>') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1164 in_tag = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1165 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1166 while (*cur && *cur != '"' && *cur != '\'' && *cur != '>') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1167 if (*cur == '"') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1168 cur++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1169 while (*cur && *cur != '"') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1170 cur++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1171 } else if (*cur == '\'') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1172 cur++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1173 while (*cur && *cur != '\'') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1174 cur++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1175 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1176 cur++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1177 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1178 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1179 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1180 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1181 cur++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1182 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1183 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1184 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1185 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1186 /* 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
|
1187 g_free(name); |
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 if (found) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1190 *attributes = attribs; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1191 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1192 *start = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1193 *end = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1194 *attributes = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1195 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1196 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1197 return found; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1198 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1199 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1200 gboolean |
15822 | 1201 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
|
1202 const char *start_token, int skip, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1203 const char *end_token, char check_value, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1204 const char *no_value_token, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1205 const char *display_name, gboolean is_link, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1206 const char *link_prefix, |
15822 | 1207 PurpleInfoFieldFormatCallback format_cb) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1208 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1209 const char *p, *q; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1210 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1211 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
|
1212 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
|
1213 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
|
1214 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
|
1215 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
|
1216 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1217 p = strstr(str, start_token); |
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 if (p == NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1220 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1221 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1222 p += strlen(start_token) + skip; |
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 (p >= str + len) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1225 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1226 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1227 if (check_value != '\0' && *p == check_value) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1228 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1229 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1230 q = strstr(p, end_token); |
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 /* Trim leading blanks */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1233 while (*p != '\n' && g_ascii_isspace(*p)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1234 p += 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1235 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1236 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1237 /* Trim trailing blanks */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1238 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
|
1239 q -= 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1240 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1241 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1242 /* Don't bother with null strings */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1243 if (p == q) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1244 return FALSE; |
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 if (q != NULL && (!no_value_token || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1247 (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
|
1248 strlen(no_value_token))))) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1249 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1250 GString *dest = g_string_new(""); |
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 if (is_link) |
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 g_string_append(dest, "<a href=\""); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1255 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1256 if (link_prefix) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1257 g_string_append(dest, link_prefix); |
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 (format_cb != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1260 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1261 char *reformatted = format_cb(p, q - p); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1262 g_string_append(dest, reformatted); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1263 g_free(reformatted); |
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 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1266 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
|
1267 g_string_append(dest, "\">"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1268 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1269 if (link_prefix) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1270 g_string_append(dest, link_prefix); |
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 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
|
1273 g_string_append(dest, "</a>"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1274 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1275 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1276 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1277 if (format_cb != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1278 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1279 char *reformatted = format_cb(p, q - p); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1280 g_string_append(dest, reformatted); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1281 g_free(reformatted); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1282 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1283 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1284 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
|
1285 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1286 |
15822 | 1287 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
|
1288 g_string_free(dest, TRUE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1289 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1290 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1291 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1292 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1293 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1294 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1295 |
15822 | 1296 struct purple_parse_tag { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1297 char *src_tag; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1298 char *dest_tag; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1299 gboolean ignore; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1300 }; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1301 |
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
|
1302 /* 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
|
1303 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
|
1304 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
|
1305 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
|
1306 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
|
1307 multiple statements when using this macro. */ |
27622
3edd01d04004
disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents:
27621
diff
changeset
|
1308 #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
|
1309 const char *o = c + strlen("<" x); \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1310 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
|
1311 /* 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
|
1312 * 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
|
1313 * 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
|
1314 * 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
|
1315 */ \ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1316 GString *innards = g_string_new(""); \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1317 while(o && *o) { \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1318 if(!q && (*o == '\"' || *o == '\'') ) { \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1319 q = o; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1320 } 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
|
1321 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
|
1322 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
|
1323 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
|
1324 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
|
1325 g_free(unescaped); \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1326 g_free(escaped); \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1327 q = NULL; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1328 } else if(*c == '\\') { \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1329 o++; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1330 } \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1331 } else if(*o == '<') { \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1332 r = o; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1333 } else if(*o == '>') { \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1334 p = o; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1335 break; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1336 } else { \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1337 innards = g_string_append_c(innards, *o); \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1338 } \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1339 o++; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1340 } \ |
29958
b06f69ada7a5
Add some comments that meant something to me at some point and might
Stu Tomlinson <stu@nosnilmot.com>
parents:
29852
diff
changeset
|
1341 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
|
1342 if(*(p-1) != '/') { \ |
15822 | 1343 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
|
1344 pt->src_tag = x; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1345 pt->dest_tag = y; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1346 tags = g_list_prepend(tags, pt); \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1347 } \ |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1348 if(xhtml) { \ |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1349 xhtml = g_string_append(xhtml, "<" y); \ |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1350 xhtml = g_string_append(xhtml, innards->str); \ |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1351 xhtml = g_string_append_c(xhtml, '>'); \ |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1352 } \ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1353 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
|
1354 } 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
|
1355 if(xhtml) \ |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1356 xhtml = g_string_append(xhtml, "<"); \ |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1357 if(plain) \ |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1358 plain = g_string_append_c(plain, '<'); \ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1359 c++; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1360 } \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1361 g_string_free(innards, TRUE); \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1362 continue; \ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1363 } \ |
27620
c800bdb5ebbc
Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents:
27589
diff
changeset
|
1364 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
|
1365 (*(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
|
1366 !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
|
1367 if(xhtml) \ |
c800bdb5ebbc
Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents:
27589
diff
changeset
|
1368 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
|
1369 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
|
1370 if(*c != '/') { \ |
c800bdb5ebbc
Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents:
27589
diff
changeset
|
1371 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
|
1372 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
|
1373 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
|
1374 tags = g_list_prepend(tags, pt); \ |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1375 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
|
1376 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
|
1377 } else { \ |
c800bdb5ebbc
Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents:
27589
diff
changeset
|
1378 if(xhtml) \ |
c800bdb5ebbc
Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents:
27589
diff
changeset
|
1379 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
|
1380 } \ |
c800bdb5ebbc
Correct the indentation of this macro by removing one level of indentation
Mark Doliner <mark@kingant.net>
parents:
27589
diff
changeset
|
1381 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
|
1382 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
|
1383 } |
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
|
1384 /* 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
|
1385 #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
|
1386 void |
15822 | 1387 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
|
1388 char **plain_out) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1389 { |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1390 GString *xhtml = NULL; |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1391 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
|
1392 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
|
1393 GString *cdata = NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1394 GList *tags = NULL, *tag; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1395 const char *c = html; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1396 char quote = '\0'; |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1397 |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1398 #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
|
1399 quote = *(ptr++); \ |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1400 else \ |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1401 quote = '\0'; |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1402 |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1403 #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
|
1404 |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1405 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
|
1406 |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1407 if(xhtml_out) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1408 xhtml = g_string_new(""); |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1409 if(plain_out) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1410 plain = g_string_new(""); |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1411 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1412 while(c && *c) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1413 if(*c == '<') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1414 if(*(c+1) == '/') { /* closing tag */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1415 tag = tags; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1416 while(tag) { |
15822 | 1417 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
|
1418 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
|
1419 c += strlen(pt->src_tag) + 3; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1420 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1421 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1422 tag = tag->next; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1423 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1424 if(tag) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1425 while(tags) { |
15822 | 1426 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
|
1427 if(xhtml && !pt->ignore) |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1428 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
|
1429 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
|
1430 /* 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
|
1431 if (cdata && url && |
4a0f841e6f26
applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents:
21177
diff
changeset
|
1432 (!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
|
1433 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
|
1434 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
|
1435 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
|
1436 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
|
1437 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
|
1438 } |
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
|
1439 |
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
|
1440 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1441 if(tags == tag) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1442 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1443 tags = g_list_remove(tags, pt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1444 g_free(pt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1445 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1446 g_free(tag->data); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1447 tags = g_list_remove(tags, tag->data); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1448 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1449 /* a closing tag we weren't expecting... |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1450 * 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
|
1451 * just a </ we'll escape it properly */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1452 const char *end = c+2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1453 while(*end && g_ascii_isalpha(*end)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1454 end++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1455 if(*end == '>') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1456 c = end+1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1457 } else { |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1458 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1459 xhtml = g_string_append(xhtml, "<"); |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1460 if(plain) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1461 plain = g_string_append_c(plain, '<'); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1462 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1463 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1464 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1465 } else { /* opening tag */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1466 ALLOW_TAG("blockquote"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1467 ALLOW_TAG("cite"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1468 ALLOW_TAG("div"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1469 ALLOW_TAG("em"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1470 ALLOW_TAG("h1"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1471 ALLOW_TAG("h2"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1472 ALLOW_TAG("h3"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1473 ALLOW_TAG("h4"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1474 ALLOW_TAG("h5"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1475 ALLOW_TAG("h6"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1476 /* we only allow html to start the message */ |
27622
3edd01d04004
disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents:
27621
diff
changeset
|
1477 if(c == html) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1478 ALLOW_TAG("html"); |
27622
3edd01d04004
disapproval of revision '0a9f6836dbe4facb38768025e830328a50c5ddd8'
Mark Doliner <mark@kingant.net>
parents:
27621
diff
changeset
|
1479 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1480 ALLOW_TAG_ALT("i", "em"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1481 ALLOW_TAG_ALT("italic", "em"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1482 ALLOW_TAG("li"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1483 ALLOW_TAG("ol"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1484 ALLOW_TAG("p"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1485 ALLOW_TAG("pre"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1486 ALLOW_TAG("q"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1487 ALLOW_TAG("span"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1488 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
|
1489 |
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
|
1490 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1491 /* 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
|
1492 * 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
|
1493 * 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
|
1494 * 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
|
1495 if((!g_ascii_strncasecmp(c, "<br", 3) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1496 || !g_ascii_strncasecmp(c, "<hr", 3)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1497 && (*(c+3) == '>' || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1498 !g_ascii_strncasecmp(c+3, "/>", 2) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1499 !g_ascii_strncasecmp(c+3, " />", 3))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1500 c = strchr(c, '>') + 1; |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1501 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1502 xhtml = g_string_append(xhtml, "<br/>"); |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1503 if(plain && *c != '\n') |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1504 plain = g_string_append_c(plain, '\n'); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1505 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1506 } |
22191
3634d27ec6f1
Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents:
22089
diff
changeset
|
1507 if(!g_ascii_strncasecmp(c, "<b>", 3) || !g_ascii_strncasecmp(c, "<bold>", strlen("<bold>")) || !g_ascii_strncasecmp(c, "<strong>", strlen("<strong>"))) { |
15822 | 1508 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
|
1509 if (*(c+2) == '>') |
3634d27ec6f1
Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents:
22089
diff
changeset
|
1510 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
|
1511 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
|
1512 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
|
1513 else |
3634d27ec6f1
Change purple_markup_html_to_xhtml() to convert <strong> tags to
Mark Doliner <mark@kingant.net>
parents:
22089
diff
changeset
|
1514 pt->src_tag = "strong"; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1515 pt->dest_tag = "span"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1516 tags = g_list_prepend(tags, pt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1517 c = strchr(c, '>') + 1; |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1518 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1519 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
|
1520 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1521 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1522 if(!g_ascii_strncasecmp(c, "<u>", 3) || !g_ascii_strncasecmp(c, "<underline>", strlen("<underline>"))) { |
15822 | 1523 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
|
1524 pt->src_tag = *(c+2) == '>' ? "u" : "underline"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1525 pt->dest_tag = "span"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1526 tags = g_list_prepend(tags, pt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1527 c = strchr(c, '>') + 1; |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1528 if (xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1529 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
|
1530 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1531 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1532 if(!g_ascii_strncasecmp(c, "<s>", 3) || !g_ascii_strncasecmp(c, "<strike>", strlen("<strike>"))) { |
15822 | 1533 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
|
1534 pt->src_tag = *(c+2) == '>' ? "s" : "strike"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1535 pt->dest_tag = "span"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1536 tags = g_list_prepend(tags, pt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1537 c = strchr(c, '>') + 1; |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1538 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1539 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
|
1540 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1541 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1542 if(!g_ascii_strncasecmp(c, "<sub>", 5)) { |
15822 | 1543 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
|
1544 pt->src_tag = "sub"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1545 pt->dest_tag = "span"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1546 tags = g_list_prepend(tags, pt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1547 c = strchr(c, '>') + 1; |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1548 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1549 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
|
1550 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1551 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1552 if(!g_ascii_strncasecmp(c, "<sup>", 5)) { |
15822 | 1553 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
|
1554 pt->src_tag = "sup"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1555 pt->dest_tag = "span"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1556 tags = g_list_prepend(tags, pt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1557 c = strchr(c, '>') + 1; |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1558 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1559 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
|
1560 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1561 } |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1562 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
|
1563 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
|
1564 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
|
1565 while (*p && *p != '>') { |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1566 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
|
1567 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
|
1568 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
|
1569 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
|
1570 src = g_string_new(""); |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1571 CHECK_QUOTE(q); |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1572 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
|
1573 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
|
1574 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
|
1575 } |
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
|
1576 p = q; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1577 } 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
|
1578 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
|
1579 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
|
1580 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
|
1581 alt = g_string_new(""); |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1582 CHECK_QUOTE(q); |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1583 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
|
1584 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
|
1585 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
|
1586 } |
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
|
1587 p = q; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1588 } else { |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1589 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
|
1590 } |
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
|
1591 } |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1592 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
|
1593 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
|
1594 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
|
1595 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
|
1596 /* 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
|
1597 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
|
1598 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
|
1599 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
|
1600 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
|
1601 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
|
1602 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
|
1603 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
|
1604 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
|
1605 } |
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
|
1606 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
|
1607 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
|
1608 } |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1609 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
|
1610 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
|
1611 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
|
1612 while (*p && *p != '>') { |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1613 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
|
1614 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
|
1615 if (url) |
45b524709475
Fix some incorrect assertions when G_DEBUG=fatal_warnings is set.
Daniel Atallah <daniel.atallah@gmail.com>
parents:
20541
diff
changeset
|
1616 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
|
1617 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
|
1618 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
|
1619 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
|
1620 cdata = g_string_new(""); |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1621 CHECK_QUOTE(q); |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1622 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
|
1623 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
|
1624 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
|
1625 url = g_string_append(url, "&"); |
39231317310a
Escape any un-escaped entities in purple_markup_html_to_xhtml when parsing
Stu Tomlinson <stu@nosnilmot.com>
parents:
21284
diff
changeset
|
1626 else |
39231317310a
Escape any un-escaped entities in purple_markup_html_to_xhtml when parsing
Stu Tomlinson <stu@nosnilmot.com>
parents:
21284
diff
changeset
|
1627 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
|
1628 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
|
1629 } |
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 p = q; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1631 } else { |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1632 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
|
1633 } |
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 } |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1635 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
|
1636 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
|
1637 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
|
1638 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
|
1639 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
|
1640 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
|
1641 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
|
1642 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
|
1643 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
|
1644 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
|
1645 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
|
1646 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1647 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
|
1648 const char *p = c + 5; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1649 GString *style = g_string_new(""); |
15822 | 1650 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
|
1651 while (*p && *p != '>') { |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1652 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
|
1653 const char *q = p + 5; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1654 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
|
1655 CHECK_QUOTE(q); |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1656 while (VALID_CHAR(q)) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1657 color = g_string_append_c(color, *q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1658 q++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1659 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1660 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
|
1661 g_string_free(color, TRUE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1662 p = q; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1663 } 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
|
1664 const char *q = p + 6; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1665 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
|
1666 CHECK_QUOTE(q); |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1667 while (VALID_CHAR(q)) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1668 color = g_string_append_c(color, *q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1669 q++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1670 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1671 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
|
1672 g_string_free(color, TRUE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1673 p = q; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1674 } 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
|
1675 const char *q = p + 5; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1676 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
|
1677 CHECK_QUOTE(q); |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1678 while (VALID_CHAR(q)) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1679 face = g_string_append_c(face, *q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1680 q++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1681 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1682 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
|
1683 g_string_free(face, TRUE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1684 p = q; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1685 } 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
|
1686 const char *q = p + 5; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1687 int sz; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1688 const char *size = "medium"; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1689 CHECK_QUOTE(q); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1690 sz = atoi(q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1691 switch (sz) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1692 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1693 case 1: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1694 size = "xx-small"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1695 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1696 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
|
1697 size = "small"; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1698 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1699 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
|
1700 size = "medium"; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1701 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1702 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
|
1703 size = "large"; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1704 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1705 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
|
1706 size = "x-large"; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1707 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1708 case 6: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1709 case 7: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1710 size = "xx-large"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1711 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1712 default: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1713 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1714 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1715 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
|
1716 p = q; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1717 } else { |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1718 p++; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1719 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1720 } |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1721 if ((c = strchr(p, '>')) != NULL) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1722 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1723 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1724 c = p; |
15822 | 1725 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
|
1726 pt->src_tag = "font"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1727 pt->dest_tag = "span"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1728 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
|
1729 if(style->len && xhtml) |
18046
58e28ccf08e6
merge of '9d95292d55daedb7f74c7df323ad2c69d347d384'
Sadrul Habib Chowdhury <imadil@gmail.com>
diff
changeset
|
1730 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
|
1731 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1732 pt->ignore = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1733 g_string_free(style, TRUE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1734 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1735 } |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1736 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
|
1737 const char *p = c + 6; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1738 gboolean did_something = FALSE; |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1739 while (*p && *p != '>') { |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1740 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
|
1741 const char *q = p + 8; |
15822 | 1742 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
|
1743 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
|
1744 CHECK_QUOTE(q); |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1745 while (VALID_CHAR(q)) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1746 color = g_string_append_c(color, *q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1747 q++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1748 } |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1749 if (xhtml) |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1750 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
|
1751 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
|
1752 if ((c = strchr(p, '>')) != NULL) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1753 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1754 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1755 c = p; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1756 pt->src_tag = "body"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1757 pt->dest_tag = "span"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1758 tags = g_list_prepend(tags, pt); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1759 did_something = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1760 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1761 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1762 p++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1763 } |
23248
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1764 if (did_something) continue; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1765 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1766 /* 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
|
1767 ALLOW_TAG("body"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1768 if(!g_ascii_strncasecmp(c, "<!--", strlen("<!--"))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1769 char *p = strstr(c + strlen("<!--"), "-->"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1770 if(p) { |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1771 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1772 xhtml = g_string_append(xhtml, "<!--"); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1773 c += strlen("<!--"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1774 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1775 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1776 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1777 |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1778 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1779 xhtml = g_string_append(xhtml, "<"); |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1780 if(plain) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1781 plain = g_string_append_c(plain, '<'); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1782 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1783 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1784 } else if(*c == '&') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1785 char buf[7]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1786 const char *pln; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1787 int len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1788 |
16084 | 1789 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
|
1790 len = 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1791 g_snprintf(buf, sizeof(buf), "%c", *c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1792 pln = buf; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1793 } |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1794 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1795 xhtml = g_string_append_len(xhtml, c, len); |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1796 if(plain) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1797 plain = g_string_append(plain, pln); |
21185
4a0f841e6f26
applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents:
21177
diff
changeset
|
1798 if(cdata) |
4a0f841e6f26
applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents:
21177
diff
changeset
|
1799 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
|
1800 c += len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1801 } else { |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1802 if(xhtml) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1803 xhtml = g_string_append_c(xhtml, *c); |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1804 if(plain) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1805 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
|
1806 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
|
1807 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
|
1808 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1809 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1810 } |
17481
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1811 if(xhtml) { |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1812 for (tag = tags; tag ; tag = tag->next) { |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1813 struct purple_parse_tag *pt = tag->data; |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1814 if(!pt->ignore) |
6608a7ab0fd9
In purple_markup_html_to_xhtml:
Richard Laager <rlaager@wiktel.com>
parents:
17480
diff
changeset
|
1815 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
|
1816 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1817 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1818 g_list_free(tags); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1819 if(xhtml_out) |
17480
a7a8e4245b33
Remove needless string duplication.
Richard Laager <rlaager@wiktel.com>
parents:
17450
diff
changeset
|
1820 *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
|
1821 if(plain_out) |
17480
a7a8e4245b33
Remove needless string duplication.
Richard Laager <rlaager@wiktel.com>
parents:
17450
diff
changeset
|
1822 *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
|
1823 if(url) |
481eb37730bf
This was crashing for me when writing a system message when logging
Mark Doliner <mark@kingant.net>
parents:
18493
diff
changeset
|
1824 g_string_free(url, TRUE); |
21185
4a0f841e6f26
applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents:
21177
diff
changeset
|
1825 if (cdata) |
4a0f841e6f26
applied changes from f0cdd16c20f9773e28cd79b36ffcf1c66057e32e
Stu Tomlinson <stu@nosnilmot.com>
parents:
21177
diff
changeset
|
1826 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
|
1827 #undef CHECK_QUOTE |
228d576a7dd7
Modified patch from Dylan Simon (dylex) to improve
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23142
diff
changeset
|
1828 #undef VALID_CHAR |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1829 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1830 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1831 /* The following are probably reasonable changes: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1832 * - \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
|
1833 * - 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
|
1834 * - 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
|
1835 * - 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
|
1836 * - 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
|
1837 * - <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
|
1838 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1839 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1840 char * |
15822 | 1841 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
|
1842 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1843 int i, j, k, entlen; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1844 gboolean visible = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1845 gboolean closing_td_p = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1846 gchar *str2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1847 const gchar *cdata_close_tag = NULL, *ent; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1848 gchar *href = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1849 int href_st = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1850 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1851 if(!str) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1852 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1853 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1854 str2 = g_strdup(str); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1855 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1856 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
|
1857 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1858 if (str2[i] == '<') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1859 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1860 if (cdata_close_tag) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1861 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1862 /* 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
|
1863 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
|
1864 strlen(cdata_close_tag)) == 0) |
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 i += strlen(cdata_close_tag) - 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1867 cdata_close_tag = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1868 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1869 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1870 } |
18397
e122b631a657
Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents:
18259
diff
changeset
|
1871 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
|
1872 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1873 str2[j++] = '\t'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1874 visible = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1875 } |
18397
e122b631a657
Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents:
18259
diff
changeset
|
1876 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
|
1877 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1878 closing_td_p = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1879 visible = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1880 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1881 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1882 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1883 closing_td_p = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1884 visible = TRUE; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1887 k = i + 1; |
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 if(g_ascii_isspace(str2[k])) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1890 visible = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1891 else if (str2[k]) |
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 /* 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
|
1894 * 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
|
1895 * inside quoted attributes will screw us up) |
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 while (str2[k] && str2[k] != '<' && str2[k] != '>') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1898 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1899 k++; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1902 /* 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
|
1903 * 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
|
1904 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
|
1905 g_ascii_isspace(str2[i+2])) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1906 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1907 int st; /* start of href, inclusive [ */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1908 int end; /* end of href, exclusive ) */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1909 char delim = ' '; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1910 /* Find start of href */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1911 for (st = i + 3; st < k; st++) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1912 { |
18397
e122b631a657
Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents:
18259
diff
changeset
|
1913 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
|
1914 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1915 st += 5; |
16169
49a1fed5ee37
This was causing problems with jabber in finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16153
diff
changeset
|
1916 if (str2[st] == '"' || str2[st] == '\'') |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1917 { |
16169
49a1fed5ee37
This was causing problems with jabber in finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16153
diff
changeset
|
1918 delim = str2[st]; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1919 st++; |
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 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1922 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1923 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1924 /* find end of address */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1925 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
|
1926 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1927 /* 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
|
1928 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1929 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1930 /* 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
|
1931 * already one saved, kill it. */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1932 if (st < 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 char *tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1935 g_free(href); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1936 tmp = g_strndup(str2 + st, end - st); |
15822 | 1937 href = purple_unescape_html(tmp); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1938 g_free(tmp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1939 href_st = j; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1940 } |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1943 /* 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
|
1944 * 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
|
1945 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
|
1946 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1947 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1948 size_t hrlen = strlen(href); |
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 /* 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
|
1951 if ((hrlen != j - href_st || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1952 strncmp(str2 + href_st, href, hrlen)) && |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1953 (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
|
1954 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
|
1955 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1956 str2[j++] = ' '; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1957 str2[j++] = '('; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1958 g_memmove(str2 + j, href, hrlen); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1959 j += hrlen; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1960 str2[j++] = ')'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1961 g_free(href); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1962 href = NULL; |
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 |
29641
41142f2bcafb
Ignore some tags at the beginning of a message.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
29359
diff
changeset
|
1966 /* 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
|
1967 * 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
|
1968 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
|
1969 || 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
|
1970 || 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
|
1971 || 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
|
1972 || 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
|
1973 || 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
|
1974 || 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
|
1975 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1976 str2[j++] = '\n'; |
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 /* 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
|
1979 #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
|
1980 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
|
1981 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1982 /* 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
|
1983 cdata_close_tag = "</option>"; |
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 #endif |
18397
e122b631a657
Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents:
18259
diff
changeset
|
1986 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
|
1987 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1988 cdata_close_tag = "</script>"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1989 } |
18397
e122b631a657
Replace some strncasecmp() calls with g_ascii_strncasecmp() as part of the
Nick Hebner <hebnern@gmail.com>
parents:
18259
diff
changeset
|
1990 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
|
1991 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1992 cdata_close_tag = "</style>"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1993 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1994 /* 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
|
1995 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
|
1996 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1997 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1998 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
1999 else if (cdata_close_tag) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2000 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2001 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2002 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2003 else if (!g_ascii_isspace(str2[i])) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2004 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2005 visible = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2006 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2007 |
16084 | 2008 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
|
2009 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2010 while (*ent) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2011 str2[j++] = *ent++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2012 i += entlen - 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2013 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2014 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2015 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2016 if (visible) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2017 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
|
2018 } |
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 g_free(href); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2021 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2022 str2[j] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2023 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2024 return str2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2025 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2026 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2027 static gboolean |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2028 badchar(char c) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2029 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2030 switch (c) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2031 case ' ': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2032 case ',': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2033 case '\0': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2034 case '\n': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2035 case '\r': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2036 case '<': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2037 case '>': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2038 case '"': |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2039 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2040 default: |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2041 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2042 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2043 } |
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 static gboolean |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2046 badentity(const char *c) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2047 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2048 if (!g_ascii_strncasecmp(c, "<", 4) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2049 !g_ascii_strncasecmp(c, ">", 4) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2050 !g_ascii_strncasecmp(c, """, 6)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2051 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2052 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2053 return FALSE; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2056 char * |
15822 | 2057 purple_markup_linkify(const char *text) |
15373
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 const char *c, *t, *q = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2060 char *tmpurlbuf, *url_buf; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2061 gunichar g; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2062 gboolean inside_html = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2063 int inside_paren = 0; |
23652
27eacd38c721
Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents:
23538
diff
changeset
|
2064 GString *ret; |
27eacd38c721
Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents:
23538
diff
changeset
|
2065 |
27eacd38c721
Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents:
23538
diff
changeset
|
2066 if (text == NULL) |
27eacd38c721
Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents:
23538
diff
changeset
|
2067 return NULL; |
27eacd38c721
Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents:
23538
diff
changeset
|
2068 |
27eacd38c721
Add NULL checking to purple_markup_linkify().
Daniel Atallah <daniel.atallah@gmail.com>
parents:
23538
diff
changeset
|
2069 ret = g_string_new(""); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2070 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2071 c = text; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2072 while (*c) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2073 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2074 if(*c == '(' && !inside_html) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2075 inside_paren++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2076 ret = g_string_append_c(ret, *c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2077 c++; |
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 if(inside_html) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2081 if(*c == '>') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2082 inside_html = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2083 } else if(!q && (*c == '\"' || *c == '\'')) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2084 q = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2085 } else if(q) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2086 if(*c == *q) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2087 q = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2088 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2089 } else if(*c == '<') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2090 inside_html = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2091 if (!g_ascii_strncasecmp(c, "<A", 2)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2092 while (1) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2093 if (!g_ascii_strncasecmp(c, "/A>", 3)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2094 inside_html = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2095 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2096 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2097 ret = g_string_append_c(ret, *c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2098 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2099 if (!(*c)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2100 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2101 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2102 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2103 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2104 (!g_ascii_strncasecmp(c, "https://", 8)))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2105 t = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2106 while (1) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2107 if (badchar(*t) || badentity(t)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2108 |
17158 | 2109 if ((!g_ascii_strncasecmp(c, "http://", 7) && (t - c == 7)) || |
2110 (!g_ascii_strncasecmp(c, "https://", 8) && (t - c == 8))) { | |
2111 break; | |
2112 } | |
2113 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2114 if (*(t) == ',' && (*(t + 1) != ' ')) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2115 t++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2116 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2117 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2118 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2119 if (*(t - 1) == '.') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2120 t--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2121 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2122 t--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2123 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2124 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2125 url_buf = g_strndup(c, t - c); |
15822 | 2126 tmpurlbuf = purple_unescape_html(url_buf); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2127 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
|
2128 tmpurlbuf, url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2129 g_free(url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2130 g_free(tmpurlbuf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2131 c = t; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2132 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2133 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2134 t++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2135 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2136 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2137 } else if (!g_ascii_strncasecmp(c, "www.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2138 if (c[4] != '.') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2139 t = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2140 while (1) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2141 if (badchar(*t) || badentity(t)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2142 if (t - c == 4) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2143 break; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2146 if (*(t) == ',' && (*(t + 1) != ' ')) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2147 t++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2148 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2149 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2150 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2151 if (*(t - 1) == '.') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2152 t--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2153 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2154 t--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2155 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2156 url_buf = g_strndup(c, t - c); |
15822 | 2157 tmpurlbuf = purple_unescape_html(url_buf); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2158 g_string_append_printf(ret, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2159 "<A HREF=\"http://%s\">%s</A>", tmpurlbuf, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2160 url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2161 g_free(url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2162 g_free(tmpurlbuf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2163 c = t; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2164 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2165 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2166 t++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2167 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2168 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2169 } else if (!g_ascii_strncasecmp(c, "ftp://", 6) || !g_ascii_strncasecmp(c, "sftp://", 7)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2170 t = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2171 while (1) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2172 if (badchar(*t) || badentity(t)) { |
17158 | 2173 |
2174 if ((!g_ascii_strncasecmp(c, "ftp://", 6) && (t - c == 6)) || | |
2175 (!g_ascii_strncasecmp(c, "sftp://", 7) && (t - c == 7))) { | |
2176 break; | |
2177 } | |
2178 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2179 if (*(t - 1) == '.') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2180 t--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2181 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2182 t--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2183 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2184 url_buf = g_strndup(c, t - c); |
15822 | 2185 tmpurlbuf = purple_unescape_html(url_buf); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2186 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
|
2187 tmpurlbuf, url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2188 g_free(url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2189 g_free(tmpurlbuf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2190 c = t; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2191 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2192 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2193 if (!t) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2194 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2195 t++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2196 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2197 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2198 } else if (!g_ascii_strncasecmp(c, "ftp.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2199 if (c[4] != '.') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2200 t = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2201 while (1) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2202 if (badchar(*t) || badentity(t)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2203 if (t - c == 4) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2204 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2205 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2206 if (*(t - 1) == '.') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2207 t--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2208 if ((*(t - 1) == ')' && (inside_paren > 0))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2209 t--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2210 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2211 url_buf = g_strndup(c, t - c); |
15822 | 2212 tmpurlbuf = purple_unescape_html(url_buf); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2213 g_string_append_printf(ret, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2214 "<A HREF=\"ftp://%s\">%s</A>", tmpurlbuf, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2215 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 if (!t) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2222 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2223 t++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2224 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2225 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2226 } 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
|
2227 t = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2228 while (1) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2229 if (badchar(*t) || badentity(t)) { |
17158 | 2230 char *d; |
2231 if (t - c == 7) { | |
2232 break; | |
2233 } | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2234 if (*(t - 1) == '.') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2235 t--; |
17158 | 2236 if ((d = strstr(c + 7, "?")) != NULL && d < t) |
2237 url_buf = g_strndup(c + 7, d - c - 7); | |
2238 else | |
2239 url_buf = g_strndup(c + 7, t - c - 7); | |
2240 if (!purple_email_is_valid(url_buf)) { | |
2241 g_free(url_buf); | |
2242 break; | |
2243 } | |
2244 g_free(url_buf); | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2245 url_buf = g_strndup(c, t - c); |
15822 | 2246 tmpurlbuf = purple_unescape_html(url_buf); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2247 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
|
2248 tmpurlbuf, url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2249 g_free(url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2250 g_free(tmpurlbuf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2251 c = t; |
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 if (!t) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2255 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2256 t++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2257 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2258 } |
17158 | 2259 } else if ((*c=='x') && (!g_ascii_strncasecmp(c, "xmpp:", 5)) && |
2260 (c == text || badchar(c[-1]) || badentity(c-1))) { | |
2261 t = c; | |
2262 while (1) { | |
2263 if (badchar(*t) || badentity(t)) { | |
2264 | |
2265 if (t - c == 5) { | |
2266 break; | |
2267 } | |
2268 | |
2269 if (*(t) == ',' && (*(t + 1) != ' ')) { | |
2270 t++; | |
2271 continue; | |
2272 } | |
2273 | |
2274 if (*(t - 1) == '.') | |
2275 t--; | |
2276 if ((*(t - 1) == ')' && (inside_paren > 0))) { | |
2277 t--; | |
2278 } | |
2279 | |
2280 url_buf = g_strndup(c, t - c); | |
2281 tmpurlbuf = purple_unescape_html(url_buf); | |
2282 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", | |
2283 tmpurlbuf, url_buf); | |
2284 g_free(url_buf); | |
2285 g_free(tmpurlbuf); | |
2286 c = t; | |
2287 break; | |
2288 } | |
2289 t++; | |
2290 | |
2291 } | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2292 } else if (c != text && (*c == '@')) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2293 int flag; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2294 GString *gurl_buf = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2295 const char illegal_chars[] = "!@#$%^&*()[]{}/|\\<>\":;\r\n \0"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2296 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2297 if (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
|
2298 flag = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2299 else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2300 flag = 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2301 gurl_buf = g_string_new(""); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2302 } |
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 t = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2305 while (flag) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2306 /* 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
|
2307 g = g_utf8_get_char(t); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2308 if (badchar(*t) || (g >= 127) || (*t == '(') || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2309 ((*t == ';') && ((t > (text+2) && (!g_ascii_strncasecmp(t - 3, "<", 4) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2310 !g_ascii_strncasecmp(t - 3, ">", 4))) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2311 (t > (text+4) && (!g_ascii_strncasecmp(t - 5, """, 6)))))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2312 /* 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
|
2313 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
|
2314 ret = g_string_append_unichar(ret, g); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2315 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2316 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2317 g_string_prepend_unichar(gurl_buf, g); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2318 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
|
2319 if (t < text) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2320 ret = g_string_assign(ret, ""); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2321 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2322 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2323 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2324 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2325 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2326 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
|
2327 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2328 while (flag) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2329 /* 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
|
2330 g = g_utf8_get_char(t); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2331 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
|
2332 char *d; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2333 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2334 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
|
2335 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2336 /* strip off trailing periods */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2337 if (strlen(url_buf) > 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2338 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
|
2339 *d = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2340 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2341 |
15822 | 2342 tmpurlbuf = purple_unescape_html(url_buf); |
2343 if (purple_email_is_valid(tmpurlbuf)) { | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2344 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
|
2345 tmpurlbuf, url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2346 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2347 g_string_append(ret, url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2348 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2349 g_free(url_buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2350 g_free(tmpurlbuf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2351 c = t; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2352 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2353 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2354 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2355 g_string_append_unichar(gurl_buf, g); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2356 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
|
2357 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2358 } |
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 if(*c == ')' && !inside_html) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2362 inside_paren--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2363 ret = g_string_append_c(ret, *c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2364 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2365 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2366 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2367 if (*c == 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2368 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2369 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2370 ret = g_string_append_c(ret, *c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2371 c++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2372 |
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 return g_string_free(ret, FALSE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2375 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2376 |
29359
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2377 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
|
2378 { |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2379 GString *ret; |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2380 const char *c = in; |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2381 |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2382 if (in == NULL) |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2383 return NULL; |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2384 |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2385 ret = g_string_new(""); |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2386 while (*c) { |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2387 int len; |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2388 const char *ent; |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2389 |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2390 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
|
2391 g_string_append(ret, ent); |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2392 c += len; |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2393 } else { |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2394 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
|
2395 c++; |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2396 } |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2397 } |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2398 |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2399 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
|
2400 } |
05d727f76ca9
Combine the three purple_unescape_text()s into one.
Paul Aurich <paul@darkrain42.org>
parents:
29348
diff
changeset
|
2401 |
27268
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2402 char *purple_unescape_html(const char *html) |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2403 { |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2404 GString *ret; |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2405 const char *c = html; |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2406 |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2407 if (html == NULL) |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2408 return NULL; |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2409 |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2410 ret = g_string_new(""); |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2411 while (*c) { |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2412 int len; |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2413 const char *ent; |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2414 |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2415 if ((ent = purple_markup_unescape_entity(c, &len)) != NULL) { |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2416 g_string_append(ret, ent); |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2417 c += len; |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2418 } else if (!strncmp(c, "<br>", 4)) { |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2419 g_string_append_c(ret, '\n'); |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2420 c += 4; |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2421 } else { |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2422 g_string_append_c(ret, *c); |
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2423 c++; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2424 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2425 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2426 |
27268
c0075538109b
Formatting changes, no functionality.
Mark Doliner <mark@kingant.net>
parents:
27246
diff
changeset
|
2427 return g_string_free(ret, FALSE); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2428 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2429 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2430 char * |
15822 | 2431 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
|
2432 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2433 GString *ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2434 GQueue *q; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2435 guint z = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2436 gboolean appended = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2437 gunichar c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2438 char *tag; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2439 |
24420 | 2440 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
|
2441 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
|
2442 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2443 if (x == y) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2444 return g_strdup(""); |
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 ret = g_string_new(""); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2447 q = g_queue_new(); |
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 while (*str && (z < y)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2450 c = g_utf8_get_char(str); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2451 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2452 if (c == '<') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2453 char *end = strchr(str, '>'); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2454 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2455 if (!end) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2456 g_string_free(ret, TRUE); |
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 g_free(tag); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2459 g_queue_free(q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2460 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2461 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2462 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2463 if (!g_ascii_strncasecmp(str, "<img ", 5)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2464 z += strlen("[Image]"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2465 } 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
|
2466 z += 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2467 } 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
|
2468 z += strlen("\n---\n"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2469 } else if (!g_ascii_strncasecmp(str, "</", 2)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2470 /* pop stack */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2471 char *tmp; |
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 tmp = g_queue_pop_head(q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2474 g_free(tmp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2475 /* z += 0; */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2476 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2477 /* push it unto the stack */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2478 char *tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2479 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2480 tmp = g_strndup(str, end - str + 1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2481 g_queue_push_head(q, tmp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2482 /* z += 0; */ |
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 if (z >= x) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2486 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
|
2487 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2488 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2489 str = end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2490 } else if (c == '&') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2491 char *end = strchr(str, ';'); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2492 if (!end) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2493 g_string_free(ret, TRUE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2494 while ((tag = g_queue_pop_head(q))) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2495 g_free(tag); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2496 g_queue_free(q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2497 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2498 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2499 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2500 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2501 if (z >= x) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2502 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
|
2503 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2504 z++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2505 str = end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2506 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2507 if (z == x && z > 0 && !appended) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2508 GList *l = q->tail; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2509 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2510 while (l) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2511 tag = l->data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2512 g_string_append(ret, tag); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2513 l = l->prev; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2514 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2515 appended = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2516 } |
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 if (z >= x) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2519 g_string_append_unichar(ret, c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2520 z++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2521 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2522 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2523 str = g_utf8_next_char(str); |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2526 while ((tag = g_queue_pop_head(q))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2527 char *name; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2528 |
15822 | 2529 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
|
2530 g_string_append_printf(ret, "</%s>", name); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2531 g_free(name); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2532 g_free(tag); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2533 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2534 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2535 g_queue_free(q); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2536 return g_string_free(ret, FALSE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2537 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2538 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2539 char * |
15822 | 2540 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
|
2541 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2542 int i; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2543 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
|
2544 g_return_val_if_fail(*tag == '<', NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2545 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2546 for (i = 1; tag[i]; i++) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2547 if (tag[i] == '>' || tag[i] == ' ' || tag[i] == '/') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2548 break; |
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 return g_strndup(tag+1, i-1); |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2553 /************************************************************************** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2554 * Path/Filename Functions |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2555 **************************************************************************/ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2556 const char * |
15822 | 2557 purple_home_dir(void) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2558 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2559 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2560 return g_get_home_dir(); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2561 #else |
15822 | 2562 return wpurple_data_dir(); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2563 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2564 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2565 |
16367
6a9ae99e7050
Use ~/.purple only, never ~/.gaim. This is a revert of the functional
Richard Laager <rlaager@wiktel.com>
parents:
16169
diff
changeset
|
2566 /* 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
|
2567 const char * |
15822 | 2568 purple_user_dir(void) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2569 { |
18147
5653692dcf79
Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents:
18129
diff
changeset
|
2570 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
|
2571 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
|
2572 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
|
2573 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
|
2574 |
2ab6b55ffa3d
Rename the internal home_dir variable to user_dir to match the function and
Richard Laager <rlaager@wiktel.com>
parents:
20074
diff
changeset
|
2575 return user_dir; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2576 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2577 |
15822 | 2578 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
|
2579 { |
18147
5653692dcf79
Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents:
18129
diff
changeset
|
2580 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
|
2581 |
5653692dcf79
Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents:
18129
diff
changeset
|
2582 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
|
2583 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
|
2584 else |
5653692dcf79
Use dynamically allocated strings for the user_dir caching. Do we need to
Richard Laager <rlaager@wiktel.com>
parents:
18129
diff
changeset
|
2585 custom_user_dir = NULL; |
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 |
15822 | 2588 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
|
2589 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2590 return g_mkdir_with_parents(path, mode); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2591 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2592 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2593 /* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2594 * 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
|
2595 * 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
|
2596 * 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
|
2597 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2598 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
|
2599 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
|
2600 { |
15822 | 2601 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
|
2602 gchar *filename_full; |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2603 gboolean ret = FALSE; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2604 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2605 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
|
2606 |
15822 | 2607 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
|
2608 filename, user_dir); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2609 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2610 /* Ensure the user directory exists */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2611 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
|
2612 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2613 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
|
2614 { |
15822 | 2615 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
|
2616 user_dir, g_strerror(errno)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2617 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2618 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2619 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2620 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2621 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
|
2622 |
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
|
2623 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
|
2624 |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2625 g_free(filename_full); |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2626 return ret; |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2627 } |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2628 |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2629 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
|
2630 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
|
2631 { |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2632 gchar *filename_temp; |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2633 FILE *file; |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2634 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
|
2635 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
|
2636 #ifndef HAVE_FILENO |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2637 int fd; |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2638 #endif |
19498
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2639 |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2640 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
|
2641 filename_full); |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2642 |
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
|
2643 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
|
2644 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2645 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
|
2646 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2647 /* 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
|
2648 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
|
2649 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2650 if (g_unlink(filename_temp) == -1) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2651 { |
19498
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2652 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
|
2653 "%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
|
2654 filename_temp, g_strerror(errno)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2655 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2656 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2657 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2658 /* Open file */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2659 file = g_fopen(filename_temp, "wb"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2660 if (file == NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2661 { |
19498
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2662 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
|
2663 "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
|
2664 filename_temp, g_strerror(errno)); |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2669 /* 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
|
2670 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
|
2671 byteswritten = fwrite(data, 1, real_size, file); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2672 |
21172
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2673 #ifdef HAVE_FILENO |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2674 /* 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
|
2675 * 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
|
2676 * 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
|
2677 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
|
2678 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
|
2679 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
|
2680 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
|
2681 fclose(file); |
abc909eeb580
jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents:
21172
diff
changeset
|
2682 return FALSE; |
abc909eeb580
jtb indirectly points out that we need a fflush() before the fsync(),
Ethan Blanton <elb@pidgin.im>
parents:
21172
diff
changeset
|
2683 } |
21172
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2684 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
|
2685 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
|
2686 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
|
2687 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
|
2688 fclose(file); |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2689 return FALSE; |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2690 } |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2691 #endif |
25924
584063555949
Remove trailing whitespace
Mark Doliner <mark@kingant.net>
parents:
25894
diff
changeset
|
2692 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2693 /* Close file */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2694 if (fclose(file) != 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2695 { |
15822 | 2696 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
|
2697 filename_temp, g_strerror(errno)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2698 g_free(filename_temp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2699 return FALSE; |
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 |
21172
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2702 #ifndef HAVE_FILENO |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2703 /* 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
|
2704 * 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
|
2705 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
|
2706 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
|
2707 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
|
2708 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
|
2709 return FALSE; |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2710 } |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2711 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
|
2712 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
|
2713 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
|
2714 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
|
2715 close(fd); |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2716 return FALSE; |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2717 } |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2718 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
|
2719 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
|
2720 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
|
2721 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
|
2722 return FALSE; |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2723 } |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2724 #endif |
33da7f2a30e4
Manually fflush() files written with purple_util_write_data_to_file,
Ethan Blanton <elb@pidgin.im>
parents:
21121
diff
changeset
|
2725 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2726 /* Ensure the file is the correct size */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2727 if (byteswritten != real_size) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2728 { |
19498
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2729 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
|
2730 G_GSIZE_FORMAT " bytes " |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2731 "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
|
2732 "; 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
|
2733 filename_temp, byteswritten, real_size); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2734 g_free(filename_temp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2735 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2736 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2737 /* Use stat to be absolutely sure. */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2738 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
|
2739 { |
15822 | 2740 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
|
2741 "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
|
2742 "full?\n", |
7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
William Ehlhardt <williamehlhardt@gmail.com>
parents:
19262
diff
changeset
|
2743 filename_temp); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2744 g_free(filename_temp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2745 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2746 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2747 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2748 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2749 /* Set file permissions */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2750 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
|
2751 { |
15822 | 2752 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
|
2753 filename_temp, g_strerror(errno)); |
15373
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 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2756 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2757 /* Rename to the REAL name */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2758 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
|
2759 { |
15822 | 2760 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
|
2761 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
|
2762 g_strerror(errno)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2763 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2764 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2765 g_free(filename_temp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2766 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2767 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2768 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2769 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2770 xmlnode * |
15822 | 2771 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
|
2772 { |
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
|
2773 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
|
2774 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2775 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2776 /* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2777 * 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
|
2778 * 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
|
2779 * the space for the filepath. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2780 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2781 * 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
|
2782 * 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
|
2783 * |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2784 * 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
|
2785 */ |
15822 | 2786 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
|
2787 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2788 FILE * |
15822 | 2789 purple_mkstemp(char **fpath, gboolean binary) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2790 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2791 const gchar *tmpdir; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2792 int fd; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2793 FILE *fp = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2794 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2795 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
|
2796 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2797 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) { |
15822 | 2798 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
|
2799 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
|
2800 if(fd == -1) { |
15822 | 2801 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
|
2802 "Couldn't make \"%s\", error: %d\n", |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2803 *fpath, errno); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2804 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2805 if((fp = fdopen(fd, "r+")) == NULL) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2806 close(fd); |
15822 | 2807 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
|
2808 "Couldn't fdopen(), error: %d\n", errno); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2809 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2810 } |
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
|
2811 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2812 if(!fp) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2813 g_free(*fpath); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2814 *fpath = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2815 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2816 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2817 } else { |
15822 | 2818 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
|
2819 "g_get_tmp_dir() failed!\n"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2820 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2821 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2822 return fp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2823 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2824 |
16375
391a79778f89
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents:
16368
diff
changeset
|
2825 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
|
2826 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
|
2827 { |
391a79778f89
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents:
16368
diff
changeset
|
2828 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
|
2829 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
|
2830 |
391a79778f89
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents:
16368
diff
changeset
|
2831 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
|
2832 { |
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
|
2833 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
|
2834 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
|
2835 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
|
2836 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
|
2837 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
|
2838 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
|
2839 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
|
2840 !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
|
2841 return "tif"; |
17492
647bfc2b2a7b
Where did ekse come from?
Richard Laager <rlaager@wiktel.com>
parents:
17491
diff
changeset
|
2842 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
|
2843 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
|
2844 } |
391a79778f89
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents:
16368
diff
changeset
|
2845 |
391a79778f89
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents:
16368
diff
changeset
|
2846 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
|
2847 } |
391a79778f89
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@wiktel.com>
parents:
16368
diff
changeset
|
2848 |
26181
00c659e55902
Add a note that this function could potentially be faster.
Mark Doliner <mark@kingant.net>
parents:
25924
diff
changeset
|
2849 /* |
27404
52298a298260
Update this comment. We talked about using CRC32 on the devel list
Mark Doliner <mark@kingant.net>
parents:
27393
diff
changeset
|
2850 * 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
|
2851 * 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
|
2852 * 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
|
2853 * 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
|
2854 */ |
18039
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2855 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
|
2856 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
|
2857 { |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2858 PurpleCipherContext *context; |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2859 gchar digest[41]; |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2860 |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2861 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
|
2862 if (context == NULL) |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2863 { |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2864 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
|
2865 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
|
2866 } |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2867 |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2868 /* Hash the image data */ |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2869 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
|
2870 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
|
2871 { |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2872 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
|
2873 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
|
2874 } |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2875 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
|
2876 |
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
|
2877 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
|
2878 } |
02eda4bd2b22
Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22191
diff
changeset
|
2879 |
02eda4bd2b22
Apply the custom smiley patches from #1187, from Jorge Villase«Ðo (Masca) and
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22191
diff
changeset
|
2880 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
|
2881 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
|
2882 { |
18039
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2883 /* Return the filename */ |
22312 | 2884 char *checksum = purple_util_get_image_checksum(image_data, image_len); |
2885 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
|
2886 purple_util_get_image_extension(image_data, image_len)); |
22312 | 2887 g_free(checksum); |
2888 return filename; | |
18039
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2889 } |
c588a4a9d287
A patch from David Grohmann (dave1g) to log embedded images.
Richard Laager <rlaager@wiktel.com>
parents:
17765
diff
changeset
|
2890 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2891 gboolean |
15822 | 2892 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
|
2893 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2894 GError *error = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2895 char **argv; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2896 gchar *progname; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2897 gboolean is_valid = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2898 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2899 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
|
2900 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
|
2901 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2902 if (!g_shell_parse_argv(program, NULL, &argv, &error)) { |
15822 | 2903 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
|
2904 "Could not parse program '%s': %s\n", |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2905 program, error->message); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2906 g_error_free(error); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2907 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2908 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2909 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2910 if (argv == NULL) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2911 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2912 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2913 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2914 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
|
2915 is_valid = (progname != NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2916 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2917 g_strfreev(argv); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2918 g_free(progname); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2919 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2920 return is_valid; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2921 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2922 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2923 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2924 gboolean |
15822 | 2925 purple_running_gnome(void) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2926 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2927 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2928 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
|
2929 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2930 if (tmp == NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2931 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2932 g_free(tmp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2933 |
21580
07588cb48434
Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <stu@nosnilmot.com>
parents:
21299
diff
changeset
|
2934 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
|
2935 |
07588cb48434
Allow empty GNOME_DESKTOP_SESSION_ID to "fail" the running_gnome check as
Stu Tomlinson <stu@nosnilmot.com>
parents:
21299
diff
changeset
|
2936 return ((tmp != NULL) && (*tmp != '\0')); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2937 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2938 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2939 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2940 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2941 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2942 gboolean |
15822 | 2943 purple_running_kde(void) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2944 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2945 #ifndef _WIN32 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2946 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
|
2947 const char *session; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2948 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2949 if (tmp == NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2950 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2951 g_free(tmp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2952 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2953 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
|
2954 if (purple_strequal(session, "true")) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2955 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2956 |
15822 | 2957 /* 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
|
2958 * 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
|
2959 * only a problem if you're running something !(KDE || GNOME) and |
15822 | 2960 * 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
|
2961 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
|
2962 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2963 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2964 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2965 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2966 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2967 gboolean |
15822 | 2968 purple_running_osx(void) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2969 { |
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
|
2970 #if defined(__APPLE__) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2971 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2972 #else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2973 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2974 #endif |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2975 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2976 |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2977 typedef union purple_sockaddr { |
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2978 struct sockaddr sa; |
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2979 struct sockaddr_in sa_in; |
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2980 #if defined(AF_INET6) |
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2981 struct sockaddr_in6 sa_in6; |
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2982 #endif |
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2983 struct sockaddr_storage sa_stor; |
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2984 } PurpleSockaddr; |
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2985 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2986 char * |
15822 | 2987 purple_fd_get_ip(int fd) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2988 { |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2989 PurpleSockaddr addr; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2990 socklen_t namelen = sizeof(addr); |
29739
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
2991 int family; |
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 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
|
2994 |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2995 if (getsockname(fd, &(addr.sa), &namelen)) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2996 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
2997 |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
2998 family = addr.sa.sa_family; |
29739
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
2999 |
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
3000 if (family == AF_INET) { |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
3001 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
|
3002 } |
5be4137c4a68
util: Bah, AF_INET6 probably isn't always available
Paul Aurich <paul@darkrain42.org>
parents:
29739
diff
changeset
|
3003 #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
|
3004 else if (family == AF_INET6) { |
29739
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
3005 char host[INET6_ADDRSTRLEN]; |
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
3006 const char *tmp; |
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
3007 |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
3008 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
|
3009 return g_strdup(tmp); |
29740
5be4137c4a68
util: Bah, AF_INET6 probably isn't always available
Paul Aurich <paul@darkrain42.org>
parents:
29739
diff
changeset
|
3010 } |
29739
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
3011 #endif |
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
3012 |
983a04639c2b
util: Make purple_fd_get_ip IPv6-aware
Paul Aurich <paul@darkrain42.org>
parents:
29641
diff
changeset
|
3013 return NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3014 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3015 |
29741
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3016 int |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3017 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
|
3018 { |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
3019 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
|
3020 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
|
3021 |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3022 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
|
3023 |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
3024 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
|
3025 return -1; |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3026 |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
3027 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
|
3028 } |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3029 |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3030 gboolean |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3031 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
|
3032 { |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3033 int family; |
29745
37be7bc87ab2
util: Fix some strict-aliasing issues.
Paul Aurich <paul@darkrain42.org>
parents:
29742
diff
changeset
|
3034 |
29741
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3035 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
|
3036 |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3037 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
|
3038 |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3039 switch (family) { |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3040 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
|
3041 return TRUE; |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3042 #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
|
3043 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
|
3044 { |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3045 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
|
3046 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
|
3047 |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3048 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
|
3049 return FALSE; |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3050 return !val; |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3051 } |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3052 #endif |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3053 default: |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3054 return FALSE; |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3055 } |
35a1cf247168
Add network listen functions that accept a family argument (AF_INET(6?)).
Paul Aurich <paul@darkrain42.org>
parents:
29740
diff
changeset
|
3056 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3057 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3058 /************************************************************************** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3059 * String Functions |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3060 **************************************************************************/ |
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
|
3061 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
|
3062 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
|
3063 { |
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
|
3064 #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
|
3065 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
|
3066 #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
|
3067 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
|
3068 (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
|
3069 #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
|
3070 } |
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
|
3071 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3072 const char * |
15822 | 3073 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
|
3074 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3075 const char *ret = NULL; |
16548
0cd684e34403
sadrul fixed the next but not last crash
Luke Schierer <lschiere@pidgin.im>
parents:
16487
diff
changeset
|
3076 static char buf[BUF_LEN]; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3077 |
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
|
3078 /* 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
|
3079 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
|
3080 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3081 if (account != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3082 { |
15822 | 3083 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
|
3084 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3085 if (prpl != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3086 { |
15822 | 3087 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
|
3088 |
28285
dab0d17dc6c1
Minor cleanup. gc->prpl is guarranteed to be a PurplePlugin with
Mark Doliner <mark@kingant.net>
parents:
28255
diff
changeset
|
3089 if (prpl_info->normalize) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3090 ret = prpl_info->normalize(account, str); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3091 } |
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 if (ret == NULL) |
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 char *tmp; |
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 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
|
3099 g_snprintf(buf, sizeof(buf), "%s", tmp); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3100 g_free(tmp); |
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 ret = buf; |
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 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3106 } |
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 /* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3109 * 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
|
3110 * 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
|
3111 * comments in util.h. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3112 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3113 const char * |
15822 | 3114 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
|
3115 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3116 static char buf[BUF_LEN]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3117 char *tmp1, *tmp2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3118 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3119 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
|
3120 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3121 tmp1 = g_utf8_strdown(str, -1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3122 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
|
3123 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
|
3124 g_free(tmp2); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3125 g_free(tmp1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3126 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3127 return buf; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3130 gchar * |
15822 | 3131 purple_strdup_withhtml(const gchar *src) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3132 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3133 gulong destsize, i, j; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3134 gchar *dest; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3135 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3136 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
|
3137 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3138 /* 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
|
3139 destsize = 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3140 for (i = 0; src[i] != '\0'; i++) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3141 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3142 if (src[i] == '\n') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3143 destsize += 4; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3144 else if (src[i] != '\r') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3145 destsize++; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3148 dest = g_malloc(destsize); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3149 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3150 /* 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
|
3151 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
|
3152 if (src[i] == '\n') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3153 strcpy(&dest[j], "<BR>"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3154 j += 4; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3155 } else if (src[i] != '\r') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3156 dest[j++] = src[i]; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3159 dest[destsize-1] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3160 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3161 return dest; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3162 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3163 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3164 gboolean |
15822 | 3165 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
|
3166 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3167 return g_str_has_prefix(s, p); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3168 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3169 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3170 gboolean |
15822 | 3171 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
|
3172 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3173 return g_str_has_suffix(s, x); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3174 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3175 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3176 char * |
15822 | 3177 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
|
3178 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3179 char *ret = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3180 int count = 0, j; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3181 guint i; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3182 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3183 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
|
3184 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3185 if (text[0] == '\n') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3186 count++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3187 for (i = 1; i < strlen(text); i++) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3188 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
|
3189 count++; |
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 if (count == 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3192 return g_strdup(text); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3193 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3194 ret = g_malloc0(strlen(text) + count + 1); |
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 i = 0; j = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3197 if (text[i] == '\n') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3198 ret[j++] = '\r'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3199 ret[j++] = text[i++]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3200 for (; i < strlen(text); i++) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3201 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
|
3202 ret[j++] = '\r'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3203 ret[j++] = text[i]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3204 } |
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 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3207 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3208 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3209 void |
15822 | 3210 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
|
3211 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3212 int i, j; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3213 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3214 g_return_if_fail(text != NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3215 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3216 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
|
3217 if (text[i] != thechar) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3218 text[j++] = text[i]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3219 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3220 text[j++] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3221 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3222 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3223 void |
15822 | 3224 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
|
3225 char replacement) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3226 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3227 int i = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3228 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3229 g_return_if_fail(string != NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3230 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3231 while (string[i] != '\0') |
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 if (string[i] == delimiter) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3234 string[i] = replacement; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3235 i++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3236 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3237 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3238 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3239 gchar * |
15822 | 3240 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
|
3241 const char *replacement) |
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 gchar **split; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3244 gchar *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(string != 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(delimiter != NULL, NULL); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3248 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
|
3249 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3250 split = g_strsplit(string, delimiter, 0); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3251 ret = g_strjoinv(replacement, split); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3252 g_strfreev(split); |
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 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3255 } |
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 gchar * |
15822 | 3258 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
|
3259 const char *replacement) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3260 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3261 gchar *ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3262 int length_del, length_rep, i, j; |
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 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
|
3265 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
|
3266 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
|
3267 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3268 length_del = strlen(delimiter); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3269 length_rep = strlen(replacement); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3270 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3271 /* Count how many times the delimiter appears */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3272 i = 0; /* position in the source string */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3273 j = 0; /* number of occurrences of "delimiter" */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3274 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
|
3275 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
|
3276 i += length_del; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3277 j += length_rep; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3278 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3279 i++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3280 j++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3281 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3282 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3283 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3284 ret = g_malloc(j+1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3285 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3286 i = 0; /* position in the source string */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3287 j = 0; /* position in the destination string */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3288 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
|
3289 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
|
3290 strncpy(&ret[j], replacement, length_rep); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3291 i += length_del; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3292 j += length_rep; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3293 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3294 ret[j] = string[i]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3295 i++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3296 j++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3297 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3298 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3299 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3300 ret[j] = '\0'; |
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 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3303 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3304 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3305 const char * |
15822 | 3306 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
|
3307 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3308 size_t hlen, nlen; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3309 const char *tmp, *ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3310 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3311 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
|
3312 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
|
3313 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3314 hlen = strlen(haystack); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3315 nlen = strlen(needle); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3316 tmp = haystack, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3317 ret = NULL; |
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 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
|
3320 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
|
3321 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3322 while (*tmp && !ret) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3323 if (!g_ascii_strncasecmp(needle, tmp, nlen)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3324 ret = tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3325 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3326 tmp++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3327 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3328 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3329 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3330 } |
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 char * |
15822 | 3333 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
|
3334 { |
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
|
3335 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
|
3336 float size_mag; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3337 int size_index = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3338 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3339 if (size == -1) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3340 return g_strdup(_("Calculating...")); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3341 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3342 else if (size == 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3343 return g_strdup(_("Unknown.")); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3344 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3345 else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3346 size_mag = (float)size; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3347 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3348 while ((size_index < 3) && (size_mag > 1024)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3349 size_mag /= 1024; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3350 size_index++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3351 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3352 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3353 if (size_index == 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3354 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
|
3355 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3356 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
|
3357 } |
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 } |
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 char * |
15822 | 3362 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
|
3363 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3364 char *ret = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3365 guint days, hrs, mins; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3366 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3367 if (secs < 60) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3368 { |
16063
fa8aeab4ca5a
Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents:
16017
diff
changeset
|
3369 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
|
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 days = secs / (60 * 60 * 24); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3373 secs = secs % (60 * 60 * 24); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3374 hrs = secs / (60 * 60); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3375 secs = secs % (60 * 60); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3376 mins = secs / 60; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3377 secs = secs % 60; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3378 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3379 if (days > 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3380 { |
16063
fa8aeab4ca5a
Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents:
16017
diff
changeset
|
3381 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
|
3382 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3383 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3384 if (hrs > 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3385 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3386 if (ret != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3387 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3388 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
|
3389 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
|
3390 ret, hrs); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3391 g_free(ret); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3392 ret = tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3393 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3394 else |
16063
fa8aeab4ca5a
Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents:
16017
diff
changeset
|
3395 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
|
3396 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3397 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3398 if (mins > 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3399 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3400 if (ret != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3401 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3402 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
|
3403 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
|
3404 ret, mins); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3405 g_free(ret); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3406 ret = tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3407 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3408 else |
16063
fa8aeab4ca5a
Hopefully prevent libpurple causing problems for 3rd party UIs if they also
Stu Tomlinson <stu@nosnilmot.com>
parents:
16017
diff
changeset
|
3409 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
|
3410 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3411 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3412 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3413 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3414 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3415 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3416 char * |
15822 | 3417 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
|
3418 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3419 GString *ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3420 guint i; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3421 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3422 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
|
3423 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3424 ret = g_string_sized_new(len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3425 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3426 for (i = 0; i < len; i++) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3427 if (binary[i] < 32 || binary[i] > 126) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3428 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
|
3429 else if (binary[i] == '\\') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3430 g_string_append(ret, "\\\\"); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3431 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3432 g_string_append_c(ret, binary[i]); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3433 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3434 return g_string_free(ret, FALSE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3435 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3436 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3437 /************************************************************************** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3438 * URI/URL Functions |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3439 **************************************************************************/ |
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
|
3440 |
15822 | 3441 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
|
3442 { |
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 char proto[11]; |
27860
da22b6d0151e
Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents:
27643
diff
changeset
|
3444 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
|
3445 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
|
3446 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
|
3447 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
|
3448 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
|
3449 if (!(tmp = strchr(uri, ':')) || tmp == uri) { |
15822 | 3450 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
|
3451 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
|
3452 } |
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
|
3453 |
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
|
3454 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
|
3455 |
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
|
3456 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
|
3457 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
|
3458 |
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
|
3459 tmp++; |
27860
da22b6d0151e
Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents:
27643
diff
changeset
|
3460 |
da22b6d0151e
Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents:
27643
diff
changeset
|
3461 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
|
3462 delimiter = ';'; |
da22b6d0151e
Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents:
27643
diff
changeset
|
3463 else |
da22b6d0151e
Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents:
27643
diff
changeset
|
3464 delimiter = '&'; |
da22b6d0151e
Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents:
27643
diff
changeset
|
3465 |
da22b6d0151e
Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents:
27643
diff
changeset
|
3466 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
|
3467 |
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
|
3468 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
|
3469 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
|
3470 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
|
3471 |
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
|
3472 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
|
3473 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
|
3474 |
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
|
3475 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
|
3476 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
|
3477 |
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
|
3478 while (*tmp || *pairstart) { |
27860
da22b6d0151e
Add support for XMPP URIs on Windows. Closes #2326.
Paul Aurich <paul@darkrain42.org>
parents:
27643
diff
changeset
|
3479 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
|
3480 /* 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
|
3481 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
|
3482 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
|
3483 |
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
|
3484 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
|
3485 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
|
3486 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
|
3487 /* 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
|
3488 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
|
3489 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
|
3490 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
|
3491 *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
|
3492 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
|
3493 } |
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
|
3494 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
|
3495 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
|
3496 } 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
|
3497 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
|
3498 |
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
|
3499 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
|
3500 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
|
3501 } |
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
|
3502 } 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
|
3503 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
|
3504 |
15822 | 3505 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
|
3506 |
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
|
3507 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
|
3508 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
|
3509 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
|
3510 } |
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
|
3511 |
17450
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3512 /* |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3513 * 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
|
3514 * 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
|
3515 * 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
|
3516 * |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3517 * 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
|
3518 * 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
|
3519 * 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
|
3520 * 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
|
3521 * 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
|
3522 */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3523 gboolean |
15822 | 3524 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
|
3525 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
|
3526 { |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3527 gboolean is_https = FALSE; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3528 char scan_info[255]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3529 char port_str[6]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3530 int f; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3531 const char *at, *slash; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3532 const char *turl; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3533 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
|
3534 int port = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3535 /* hyphen at end includes it in control set */ |
21015
787b3897ba9f
Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents:
21000
diff
changeset
|
3536 static const char addr_ctrl[] = "A-Za-z0-9.-"; |
787b3897ba9f
Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents:
21000
diff
changeset
|
3537 static const char port_ctrl[] = "0-9"; |
787b3897ba9f
Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents:
21000
diff
changeset
|
3538 static const char page_ctrl[] = "A-Za-z0-9.~_/:*!@&%%?=+^-"; |
787b3897ba9f
Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents:
21000
diff
changeset
|
3539 static const char user_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-"; |
787b3897ba9f
Patch from Andrew Gaul to constify a bunch of static variables to reduce
Ka-Hing Cheung <khc@hxbc.us>
parents:
21000
diff
changeset
|
3540 static const char passwd_ctrl[] = "A-Za-z0-9.~_/*!&%%?=+^-"; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3541 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3542 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
|
3543 |
17450
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3544 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
|
3545 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3546 turl += 7; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3547 url = turl; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3548 } |
17450
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3549 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
|
3550 { |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3551 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
|
3552 turl += 8; |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3553 url = turl; |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3554 } |
15373
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 /* parse out authentication information if supplied */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3557 /* Only care about @ char BEFORE the first / */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3558 at = strchr(url, '@'); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3559 slash = strchr(url, '/'); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3560 if ((at != NULL) && |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3561 (((slash != NULL) && (strlen(at) > strlen(slash))) || |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3562 (slash == NULL))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3563 g_snprintf(scan_info, sizeof(scan_info), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3564 "%%255[%s]:%%255[%s]^@", user_ctrl, passwd_ctrl); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3565 f = sscanf(url, scan_info, user, passwd); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3566 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3567 if (f ==1 ) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3568 /* No passwd, possibly just username supplied */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3569 g_snprintf(scan_info, sizeof(scan_info), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3570 "%%255[%s]^@", user_ctrl); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3571 f = sscanf(url, scan_info, user); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3572 *passwd = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3573 } |
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 url = at+1; /* move pointer after the @ char */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3576 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3577 *user = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3578 *passwd = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3579 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3580 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3581 g_snprintf(scan_info, sizeof(scan_info), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3582 "%%255[%s]:%%5[%s]/%%255[%s]", addr_ctrl, port_ctrl, page_ctrl); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3583 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3584 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
|
3585 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3586 if (f == 1) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3587 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3588 g_snprintf(scan_info, sizeof(scan_info), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3589 "%%255[%s]/%%255[%s]", |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3590 addr_ctrl, page_ctrl); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3591 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
|
3592 /* 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
|
3593 if (is_https) |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3594 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
|
3595 else |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3596 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
|
3597 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3598 |
23982
7fbc99a1481d
purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents:
23975
diff
changeset
|
3599 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
|
3600 *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
|
3601 |
7fbc99a1481d
purple_url_parse() now gracefully handles a url which is wholly invalid.
Evan Schoenberg <evan.s@dreskin.net>
parents:
23975
diff
changeset
|
3602 if (f <= 1) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3603 *path = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3604 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3605 sscanf(port_str, "%d", &port); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3606 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3607 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
|
3608 if (ret_port != NULL) *ret_port = port; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3609 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
|
3610 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
|
3611 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
|
3612 |
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
|
3613 return ((*host != '\0') ? TRUE : FALSE); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3614 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3615 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3616 /** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3617 * 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
|
3618 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3619 static void |
15822 | 3620 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
|
3621 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3622 gchar *error_message; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3623 va_list args; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3624 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3625 va_start(args, format); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3626 error_message = g_strdup_vprintf(format, args); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3627 va_end(args); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3628 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3629 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
|
3630 g_free(error_message); |
15822 | 3631 purple_util_fetch_url_cancel(gfud); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3632 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3633 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3634 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
|
3635 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
|
3636 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
|
3637 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3638 static gboolean |
23388 | 3639 parse_redirect(const char *data, size_t data_len, |
15822 | 3640 PurpleUtilFetchUrlData *gfud) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3641 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3642 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
|
3643 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
|
3644 gboolean full; |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3645 int len; |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3646 |
20961
4a8366502f01
When checking for redirects in purple_util_fetch_url(), look for
Mark Doliner <mark@kingant.net>
parents:
20917
diff
changeset
|
3647 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
|
3648 /* 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
|
3649 return FALSE; |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3650 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3651 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
|
3652 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
|
3653 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3654 /* 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
|
3655 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
|
3656 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
|
3657 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3658 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
|
3659 return FALSE; |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3660 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3661 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
|
3662 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3663 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
|
3664 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
|
3665 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
|
3666 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3667 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
|
3668 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3669 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
|
3670 { |
17450
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3671 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
|
3672 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3673 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
|
3674 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
|
3675 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3676 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
|
3677 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3678 full = FALSE; |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3679 } |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3680 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3681 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
|
3682 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3683 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
|
3684 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
|
3685 { |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3686 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
|
3687 _("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
|
3688 gfud->url); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3689 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3690 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3691 |
17450
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3692 /* |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3693 * 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
|
3694 * 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
|
3695 * 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
|
3696 */ |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3697 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
|
3698 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
|
3699 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
|
3700 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
|
3701 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
|
3702 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3703 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
|
3704 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
|
3705 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
|
3706 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
|
3707 } else { |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3708 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
|
3709 gfud->inpa = 0; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3710 close(gfud->fd); |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3711 gfud->fd = -1; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3712 } |
17450
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3713 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
|
3714 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
|
3715 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
|
3716 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3717 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
|
3718 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
|
3719 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
|
3720 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
|
3721 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
|
3722 &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
|
3723 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3724 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
|
3725 gfud->is_ssl = TRUE; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3726 gfud->ssl_connection = purple_ssl_connect(NULL, |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3727 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
|
3728 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
|
3729 } else { |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3730 gfud->connect_data = purple_proxy_connect(NULL, NULL, |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3731 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
|
3732 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
|
3733 } |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3734 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3735 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
|
3736 { |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3737 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
|
3738 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
|
3739 } |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3740 |
3d035cdd103b
Add some notes about why Yahoo! web messenger login doesn't work
Mark Doliner <mark@kingant.net>
parents:
17195
diff
changeset
|
3741 return TRUE; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3742 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3743 |
27220
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3744 static const char * |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3745 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
|
3746 { |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3747 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
|
3748 |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3749 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
|
3750 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
|
3751 |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3752 /* 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
|
3753 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
|
3754 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
|
3755 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
|
3756 if (!p) |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3757 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
|
3758 if (p) |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3759 p += header_len; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3760 } |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3761 |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3762 /* 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
|
3763 * 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
|
3764 * 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
|
3765 */ |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3766 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
|
3767 return p; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3768 } |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3769 |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3770 return NULL; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3771 } |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3772 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3773 static size_t |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3774 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
|
3775 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3776 size_t content_len = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3777 const char *p = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3778 |
27220
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3779 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
|
3780 if (p) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3781 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
|
3782 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
|
3783 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3784 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3785 return content_len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3786 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3787 |
27220
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3788 static gboolean |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3789 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
|
3790 { |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3791 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
|
3792 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
|
3793 return TRUE; |
a051f77d86a8
Remove just a tad bit of indirection
Mark Doliner <mark@kingant.net>
parents:
27244
diff
changeset
|
3794 |
a051f77d86a8
Remove just a tad bit of indirection
Mark Doliner <mark@kingant.net>
parents:
27244
diff
changeset
|
3795 return FALSE; |
27220
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3796 } |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3797 |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3798 /* Process in-place */ |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3799 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
|
3800 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
|
3801 { |
27244
7a4f56967512
Use unsigned lengths here and use %zu when reading into the gsize var
Mark Doliner <mark@kingant.net>
parents:
27223
diff
changeset
|
3802 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
|
3803 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
|
3804 char *p = data; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3805 char *s = data; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3806 |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3807 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
|
3808 /* 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
|
3809 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
|
3810 { |
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3811 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
|
3812 "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
|
3813 break; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3814 } |
27246
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3815 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
|
3816 /* 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
|
3817 /* |
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3818 * 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
|
3819 * 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
|
3820 * 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
|
3821 */ |
27220
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3822 break; |
27246
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3823 } |
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3824 |
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3825 /* 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
|
3826 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
|
3827 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
|
3828 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
|
3829 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
|
3830 |
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3831 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
|
3832 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
|
3833 "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
|
3834 "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
|
3835 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
|
3836 } |
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3837 |
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3838 /* 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
|
3839 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
|
3840 p += sz; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3841 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
|
3842 newlen += sz; |
27220
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3843 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
|
3844 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
|
3845 "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
|
3846 break; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3847 } |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3848 s += 2; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3849 } |
27246
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3850 |
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3851 /* 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
|
3852 *p = 0; |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3853 |
27246
e28b627be482
A few changes to our code to handle chunked transfer-encodings (technically
Mark Doliner <mark@kingant.net>
parents:
27245
diff
changeset
|
3854 *len = newlen; |
27220
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3855 } |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3856 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3857 static void |
15822 | 3858 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
|
3859 { |
15822 | 3860 PurpleUtilFetchUrlData *gfud = url_data; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3861 int len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3862 char buf[4096]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3863 char *data_cursor; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3864 gboolean got_eof = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3865 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3866 /* |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3867 * 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
|
3868 * 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
|
3869 * 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
|
3870 */ |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3871 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
|
3872 (!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
|
3873 { |
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
|
3874 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
|
3875 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
|
3876 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
|
3877 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
|
3878 } |
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
|
3879 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3880 /* 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
|
3881 if((gfud->len + len) >= gfud->data_len) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3882 while((gfud->len + len) >= gfud->data_len) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3883 gfud->data_len += sizeof(buf); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3884 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3885 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
|
3886 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3887 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3888 data_cursor = gfud->webdata + gfud->len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3889 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3890 gfud->len += len; |
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 memcpy(data_cursor, buf, len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3893 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3894 gfud->webdata[gfud->len] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3895 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3896 if(!gfud->got_headers) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3897 char *tmp; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3898 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3899 /* See if we've reached the end of the headers yet */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3900 if((tmp = strstr(gfud->webdata, "\r\n\r\n"))) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3901 char * new_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3902 guint header_len = (tmp + 4 - gfud->webdata); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3903 size_t content_len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3904 |
15822 | 3905 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
|
3906 header_len, gfud->webdata); |
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 /* See if we can find a redirect. */ |
23388 | 3909 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
|
3910 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3911 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3912 gfud->got_headers = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3913 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3914 /* 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
|
3915 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
|
3916 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
|
3917 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3918 if(content_len == 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3919 /* We'll stick with an initial 8192 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3920 content_len = 8192; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3921 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3922 gfud->has_explicit_data_len = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3923 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3924 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3925 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3926 /* If we're returning the headers too, we don't need to clean them out */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3927 if(gfud->include_headers) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3928 gfud->data_len = content_len + header_len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3929 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
|
3930 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3931 size_t body_len = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3932 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3933 if(gfud->len > (header_len + 1)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3934 body_len = (gfud->len - header_len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3935 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3936 content_len = MAX(content_len, body_len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3937 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3938 new_data = g_try_malloc(content_len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3939 if(new_data == NULL) { |
15822 | 3940 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
|
3941 "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
|
3942 content_len, g_strerror(errno)); |
15822 | 3943 purple_util_fetch_url_error(gfud, |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3944 _("Unable to allocate enough memory to hold " |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3945 "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
|
3946 "be trying something malicious."), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3947 gfud->website.address); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3948 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3949 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3950 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3951 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3952 /* We may have read part of the body when reading the headers, don't lose it */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3953 if(body_len > 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3954 tmp += 4; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3955 memcpy(new_data, tmp, body_len); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3956 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3957 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3958 /* Out with the old... */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3959 g_free(gfud->webdata); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3960 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3961 /* In with the new. */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3962 gfud->len = body_len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3963 gfud->data_len = content_len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3964 gfud->webdata = new_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3965 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3966 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3967 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3968 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3969 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
|
3970 got_eof = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3971 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3972 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3973 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3974 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3975 if(len < 0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3976 if(errno == EAGAIN) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3977 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3978 } else { |
15822 | 3979 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
|
3980 gfud->website.address, g_strerror(errno)); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3981 return; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3982 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3983 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3984 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3985 if((len == 0) || got_eof) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3986 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
|
3987 gfud->webdata[gfud->len] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3988 |
27220
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3989 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
|
3990 /* 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
|
3991 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
|
3992 } |
716bd29bdc28
Process the data correctly if the server sends chunked data.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
27137
diff
changeset
|
3993 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3994 gfud->callback(gfud, gfud->user_data, gfud->webdata, gfud->len, NULL); |
15822 | 3995 purple_util_fetch_url_cancel(gfud); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3996 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3997 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
3998 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
3999 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
|
4000 { |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4001 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
|
4002 } |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4003 |
27120
9ff4b4cbc4c9
Allow doxygen to pick up the comment for this function. It's
Mark Doliner <mark@kingant.net>
parents:
27024
diff
changeset
|
4004 /** |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4005 * 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
|
4006 * to. |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4007 * |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4008 * @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
|
4009 * 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
|
4010 * 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
|
4011 * 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
|
4012 * 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
|
4013 */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4014 static void |
15822 | 4015 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
|
4016 { |
15822 | 4017 PurpleUtilFetchUrlData *gfud; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4018 int len, total_len; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4019 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4020 gfud = data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4021 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4022 if (gfud->request == NULL) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4023 { |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4024 /* 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
|
4025 * 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
|
4026 * 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
|
4027 * 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
|
4028 */ |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4029 if (gfud->user_agent) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4030 gfud->request = g_strdup_printf( |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4031 "GET %s%s HTTP/%s\r\n" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4032 "Connection: close\r\n" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4033 "User-Agent: %s\r\n" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4034 "Accept: */*\r\n" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4035 "Host: %s\r\n\r\n", |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4036 (gfud->full ? "" : "/"), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4037 (gfud->full ? (gfud->url ? gfud->url : "") : (gfud->website.page ? gfud->website.page : "")), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4038 (gfud->http11 ? "1.1" : "1.0"), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4039 (gfud->user_agent ? gfud->user_agent : ""), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4040 (gfud->website.address ? gfud->website.address : "")); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4041 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4042 gfud->request = g_strdup_printf( |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4043 "GET %s%s HTTP/%s\r\n" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4044 "Connection: close\r\n" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4045 "Accept: */*\r\n" |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4046 "Host: %s\r\n\r\n", |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4047 (gfud->full ? "" : "/"), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4048 (gfud->full ? (gfud->url ? gfud->url : "") : (gfud->website.page ? gfud->website.page : "")), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4049 (gfud->http11 ? "1.1" : "1.0"), |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4050 (gfud->website.address ? gfud->website.address : "")); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4051 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4052 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4053 |
27298
e9279f0e551a
Convert all uses of PURPLE_UNSAFE_DEBUG to the new API I added.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27295
diff
changeset
|
4054 if(purple_debug_is_unsafe()) |
25623
fb89c9f6e57a
*** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
24863
diff
changeset
|
4055 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
|
4056 else |
fb89c9f6e57a
*** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
24863
diff
changeset
|
4057 purple_debug_misc("util", "request constructed\n"); |
15822 | 4058 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4059 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
|
4060 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4061 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
|
4062 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
|
4063 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
|
4064 else |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4065 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
|
4066 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
|
4067 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4068 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
|
4069 return; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4070 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
|
4071 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
|
4072 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
|
4073 return; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4074 } |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4075 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
|
4076 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4077 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
|
4078 return; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4079 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4080 /* 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
|
4081 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
|
4082 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
|
4083 gfud->inpa = 0; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4084 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
|
4085 } else { |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4086 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
|
4087 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
|
4088 gfud); |
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 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4092 static void |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4093 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
|
4094 { |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4095 PurpleUtilFetchUrlData *gfud; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4096 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4097 gfud = url_data; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4098 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
|
4099 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4100 if (source == -1) |
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 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
|
4103 (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
|
4104 return; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4105 } |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4106 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4107 gfud->fd = source; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4108 |
15822 | 4109 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
|
4110 url_fetch_send_cb, gfud); |
15822 | 4111 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
|
4112 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4113 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4114 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
|
4115 { |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4116 PurpleUtilFetchUrlData *gfud; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4117 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4118 gfud = data; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4119 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4120 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
|
4121 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
|
4122 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
|
4123 } |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4124 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4125 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
|
4126 { |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4127 PurpleUtilFetchUrlData *gfud; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4128 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4129 gfud = data; |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4130 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
|
4131 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4132 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
|
4133 (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
|
4134 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
|
4135 } |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4136 |
15822 | 4137 PurpleUtilFetchUrlData * |
4138 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
|
4139 const char *user_agent, gboolean http11, |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4140 const char *request, gboolean include_headers, |
15822 | 4141 PurpleUtilFetchUrlCallback callback, void *user_data) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4142 { |
26969
f303787f144d
Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26895
diff
changeset
|
4143 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
|
4144 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
|
4145 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
|
4146 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
|
4147 } |
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
|
4148 |
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
|
4149 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
|
4150 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
|
4151 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
|
4152 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
|
4153 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
|
4154 { |
26969
f303787f144d
Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26895
diff
changeset
|
4155 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
|
4156 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
|
4157 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
|
4158 } |
f303787f144d
Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26895
diff
changeset
|
4159 |
f303787f144d
Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26895
diff
changeset
|
4160 PurpleUtilFetchUrlData * |
f303787f144d
Add yet another URL fetching function. This one takes an account as a
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
26895
diff
changeset
|
4161 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
|
4162 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
|
4163 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
|
4164 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
|
4165 { |
15822 | 4166 PurpleUtilFetchUrlData *gfud; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4167 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4168 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
|
4169 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
|
4170 |
27298
e9279f0e551a
Convert all uses of PURPLE_UNSAFE_DEBUG to the new API I added.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27295
diff
changeset
|
4171 if(purple_debug_is_unsafe()) |
25623
fb89c9f6e57a
*** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
24863
diff
changeset
|
4172 purple_debug_info("util", |
fb89c9f6e57a
*** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
24863
diff
changeset
|
4173 "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
|
4174 url, full, user_agent?user_agent:"(null)", http11); |
fb89c9f6e57a
*** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
24863
diff
changeset
|
4175 else |
fb89c9f6e57a
*** Plucked rev c1ede5faf776dc1cc966dabb42c1ef0dbaea31db (rekkanoryo@pidgin.im):
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
24863
diff
changeset
|
4176 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
|
4177 |
15822 | 4178 gfud = g_new0(PurpleUtilFetchUrlData, 1); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4179 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4180 gfud->callback = callback; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4181 gfud->user_data = user_data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4182 gfud->url = g_strdup(url); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4183 gfud->user_agent = g_strdup(user_agent); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4184 gfud->http11 = http11; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4185 gfud->full = full; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4186 gfud->request = g_strdup(request); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4187 gfud->include_headers = include_headers; |
20592
383b9180b2c8
Initialize file-descriptors to -1.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20587
diff
changeset
|
4188 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
|
4189 gfud->max_len = max_len; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4190 |
15822 | 4191 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
|
4192 &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
|
4193 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4194 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
|
4195 if (!purple_ssl_is_supported()) { |
2db8a92b3cde
Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents:
26181
diff
changeset
|
4196 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
|
4197 _("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
|
4198 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
|
4199 _("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
|
4200 return NULL; |
2db8a92b3cde
Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents:
26181
diff
changeset
|
4201 } |
2db8a92b3cde
Add a friendly error message if something uses
Mark Doliner <mark@kingant.net>
parents:
26181
diff
changeset
|
4202 |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4203 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
|
4204 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
|
4205 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
|
4206 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
|
4207 } 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
|
4208 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
|
4209 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
|
4210 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
|
4211 } |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4212 |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4213 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
|
4214 { |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4215 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
|
4216 gfud->website.address); |
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4217 return NULL; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4218 } |
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 return gfud; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4221 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4222 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4223 void |
15822 | 4224 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
|
4225 { |
24592
104f6f755c7e
Make our purple_util_fetch_url_request() function able to handle
Mark Doliner <mark@kingant.net>
parents:
24426
diff
changeset
|
4226 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
|
4227 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
|
4228 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4229 if (gfud->connect_data != NULL) |
15822 | 4230 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
|
4231 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4232 if (gfud->inpa > 0) |
15822 | 4233 purple_input_remove(gfud->inpa); |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4234 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4235 if (gfud->fd >= 0) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4236 close(gfud->fd); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4237 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4238 g_free(gfud->website.user); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4239 g_free(gfud->website.passwd); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4240 g_free(gfud->website.address); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4241 g_free(gfud->website.page); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4242 g_free(gfud->url); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4243 g_free(gfud->user_agent); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4244 g_free(gfud->request); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4245 g_free(gfud->webdata); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4246 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4247 g_free(gfud); |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4250 const char * |
15822 | 4251 purple_url_decode(const char *str) |
15373
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 static char buf[BUF_LEN]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4254 guint i, j = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4255 char *bum; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4256 char hex[3]; |
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 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
|
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 * 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
|
4262 * dynamically allocated, but this is easier. |
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 if (strlen(str) >= BUF_LEN) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4265 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4266 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4267 for (i = 0; i < strlen(str); i++) { |
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 if (str[i] != '%') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4270 buf[j++] = str[i]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4271 else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4272 strncpy(hex, str + ++i, 2); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4273 hex[2] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4274 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4275 /* 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
|
4276 i++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4277 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4278 /* |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4279 * 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
|
4280 * will be at the next character. |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4281 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4282 buf[j++] = strtol(hex, NULL, 16); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4283 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4284 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4285 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4286 buf[j] = '\0'; |
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 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
|
4289 *bum = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4290 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4291 return buf; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4292 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4293 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4294 const char * |
15822 | 4295 purple_url_encode(const char *str) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4296 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4297 const char *iter; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4298 static char buf[BUF_LEN]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4299 char utf_char[6]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4300 guint i, j = 0; |
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 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
|
4303 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
|
4304 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4305 iter = str; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4306 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
|
4307 gunichar c = g_utf8_get_char(iter); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4308 /* 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
|
4309 * 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
|
4310 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
|
4311 buf[j++] = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4312 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4313 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
|
4314 for (i = 0; i < bytes; i++) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4315 if (j > (BUF_LEN - 4)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4316 break; |
28255
79c14adf9669
Change purple_url_encode() to not encode . _ - ~ because it's not
Mark Doliner <mark@kingant.net>
parents:
28153
diff
changeset
|
4317 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
|
4318 j += 3; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4319 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4320 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4321 } |
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 buf[j] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4324 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4325 return buf; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4326 } |
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 /* Originally lifted from |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4329 * 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
|
4330 * ... 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
|
4331 * ... 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
|
4332 * 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
|
4333 * 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
|
4334 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4335 gboolean |
15822 | 4336 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
|
4337 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4338 const char *c, *domain; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4339 static char *rfc822_specials = "()<>@,;:\\\"[]"; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4340 |
24424 | 4341 g_return_val_if_fail(address != NULL, FALSE); |
4342 | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4343 /* 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
|
4344 for (c = address; *c; c++) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4345 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
|
4346 while (*++c) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4347 if (*c == '\\') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4348 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
|
4349 else return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4350 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4351 if (*c == '\"') break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4352 if (*c < ' ' || *c >= 127) return 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 if (!*c++) return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4355 if (*c == '@') break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4356 if (*c != '.') return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4357 continue; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4358 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4359 if (*c == '@') break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4360 if (*c <= ' ' || *c >= 127) return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4361 if (strchr(rfc822_specials, *c)) return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4362 } |
18600
321658bf0e03
Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <mark@kingant.net>
parents:
18560
diff
changeset
|
4363 |
321658bf0e03
Valgrind was showing "Invalid read of size 1" when a string is passed
Mark Doliner <mark@kingant.net>
parents:
18560
diff
changeset
|
4364 /* 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
|
4365 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
|
4366 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4367 /* 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
|
4368 * 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
|
4369 if (c == address) return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4370 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4371 /* 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
|
4372 if (!*(domain = ++c)) return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4373 do { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4374 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
|
4375 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4376 if (*c == '-' && *(c - 1) == '.') return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4377 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
|
4378 (*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
|
4379 } while (*++c); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4380 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4381 if (*(c - 1) == '-') return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4382 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4383 return ((c - domain) > 3 ? TRUE : FALSE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4384 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4385 |
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
|
4386 gboolean |
27473
1d30e9d6de9b
Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents:
27469
diff
changeset
|
4387 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
|
4388 { |
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
|
4389 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
|
4390 char end; |
24422 | 4391 |
4392 g_return_val_if_fail(ip != NULL, FALSE); | |
4393 | |
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
|
4394 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
|
4395 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
|
4396 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
|
4397 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
|
4398 } |
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
|
4399 |
27469
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4400 gboolean |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4401 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
|
4402 { |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4403 const gchar *c; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4404 gboolean double_colon = FALSE; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4405 gint chunks = 1; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4406 gint in = 0; |
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 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
|
4409 |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4410 if (*ip == '\0') |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4411 return FALSE; |
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 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
|
4414 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
|
4415 (*c >= 'a' && *c <= 'f') || |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4416 (*c >= 'A' && *c <= 'F')) { |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4417 if (++in > 4) |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4418 /* 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
|
4419 return FALSE; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4420 continue; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4421 } else if (*c == ':') { |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4422 /* 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
|
4423 ++chunks; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4424 in = 0; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4425 if (*(c + 1) == ':') { |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4426 /* |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4427 * '::' 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
|
4428 * 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
|
4429 */ |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4430 if (double_colon) |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4431 return FALSE; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4432 double_colon = TRUE; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4433 } |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4434 } else |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4435 return FALSE; |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4436 } |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4437 |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4438 /* |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4439 * 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
|
4440 * 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
|
4441 */ |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4442 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
|
4443 } |
8c41a23e6b44
Add purple_ipv6_address_is_valid; guess what it does?
Paul Aurich <paul@darkrain42.org>
parents:
27448
diff
changeset
|
4444 |
27473
1d30e9d6de9b
Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents:
27469
diff
changeset
|
4445 /* 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
|
4446 gboolean |
1d30e9d6de9b
Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents:
27469
diff
changeset
|
4447 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
|
4448 { |
1d30e9d6de9b
Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents:
27469
diff
changeset
|
4449 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
|
4450 } |
1d30e9d6de9b
Added the function in util.h, forgot it here.
Paul Aurich <paul@darkrain42.org>
parents:
27469
diff
changeset
|
4451 |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4452 /* Stolen from gnome_uri_list_extract_uris */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4453 GList * |
15822 | 4454 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
|
4455 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4456 const gchar *p, *q; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4457 gchar *retval; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4458 GList *result = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4459 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4460 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
|
4461 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4462 p = uri_list; |
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 /* 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
|
4465 * 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
|
4466 * 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
|
4467 * 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
|
4468 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4469 while (p) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4470 if (*p != '#') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4471 while (isspace(*p)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4472 p++; |
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 q = p; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4475 while (*q && (*q != '\n') && (*q != '\r')) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4476 q++; |
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 if (q > p) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4479 q--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4480 while (q > p && isspace(*q)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4481 q--; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4482 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4483 retval = (gchar*)g_malloc (q - p + 2); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4484 strncpy (retval, p, q - p + 1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4485 retval[q - p + 1] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4486 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4487 result = g_list_prepend (result, retval); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4488 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4489 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4490 p = strchr (p, '\n'); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4491 if (p) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4492 p++; |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4495 return g_list_reverse (result); |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4499 /* Stolen from gnome_uri_list_extract_filenames */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4500 GList * |
15822 | 4501 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
|
4502 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4503 GList *tmp_list, *node, *result; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4504 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4505 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
|
4506 |
15822 | 4507 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
|
4508 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4509 tmp_list = result; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4510 while (tmp_list) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4511 gchar *s = (gchar*)tmp_list->data; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4512 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4513 node = tmp_list; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4514 tmp_list = tmp_list->next; |
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 if (!strncmp (s, "file:", 5)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4517 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
|
4518 /* 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
|
4519 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
|
4520 } 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
|
4521 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
|
4522 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4523 g_free (s); |
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 return result; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4526 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4527 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4528 /************************************************************************** |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4529 * UTF8 String Functions |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4530 **************************************************************************/ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4531 gchar * |
15822 | 4532 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
|
4533 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4534 gsize converted; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4535 gchar *utf8; |
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 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
|
4538 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4539 if (g_utf8_validate(str, -1, NULL)) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4540 return g_strdup(str); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4541 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4542 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4543 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
|
4544 if (utf8 != NULL) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4545 return utf8; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4546 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4547 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
|
4548 if ((utf8 != NULL) && (converted == strlen(str))) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4549 return utf8; |
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 g_free(utf8); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4552 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4553 return NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4554 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4555 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4556 #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
|
4557 || (x & 0xf0) == 0xe0 || (x & 0xf8) == 0xf) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4558 gchar * |
15822 | 4559 purple_utf8_salvage(const char *str) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4560 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4561 GString *workstr; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4562 const char *end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4563 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4564 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
|
4565 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4566 workstr = g_string_sized_new(strlen(str)); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4567 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4568 do { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4569 g_utf8_validate(str, -1, &end); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4570 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
|
4571 str = end; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4572 if (*str == '\0') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4573 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4574 do { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4575 workstr = g_string_append_c(workstr, '?'); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4576 str++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4577 } while (!utf8_first(*str)); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4578 } while (*str != '\0'); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4579 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4580 return g_string_free(workstr, FALSE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4581 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4582 |
27019
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4583 gchar * |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4584 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
|
4585 { |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4586 gchar *workstr, *iter; |
28107
0a4d0d4cf5df
Add more verbose debugging to purple_utf8_strip_unprintables.
Paul Aurich <paul@darkrain42.org>
parents:
28106
diff
changeset
|
4587 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
|
4588 |
27024
c59918579c3a
Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents:
27019
diff
changeset
|
4589 if (str == NULL) |
c59918579c3a
Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents:
27019
diff
changeset
|
4590 /* 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
|
4591 return NULL; |
c59918579c3a
Strip unprintable UTF-8 characters from buddy list strings. Fixes #8776.
Paul Aurich <paul@darkrain42.org>
parents:
27019
diff
changeset
|
4592 |
28108
6b018d1efc5c
Oops, I think it's either sleep or coffee time.
Paul Aurich <paul@darkrain42.org>
parents:
28107
diff
changeset
|
4593 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
|
4594 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
|
4595 "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
|
4596 str, *bad, *bad); |
0a4d0d4cf5df
Add more verbose debugging to purple_utf8_strip_unprintables.
Paul Aurich <paul@darkrain42.org>
parents:
28106
diff
changeset
|
4597 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
|
4598 } |
27019
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4599 |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4600 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
|
4601 while (*str) { |
5bac51b394e6
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents:
29745
diff
changeset
|
4602 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
|
4603 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
|
4604 /* |
5bac51b394e6
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents:
29745
diff
changeset
|
4605 * 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
|
4606 * [#x10000-#x10FFFF] |
5bac51b394e6
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents:
29745
diff
changeset
|
4607 */ |
5bac51b394e6
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents:
29745
diff
changeset
|
4608 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
|
4609 (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
|
4610 (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
|
4611 (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
|
4612 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
|
4613 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
|
4614 } |
29852
5bac51b394e6
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents:
29745
diff
changeset
|
4615 |
5bac51b394e6
util: Better validation of the allowed character values in XML 1.0
Paul Aurich <paul@darkrain42.org>
parents:
29745
diff
changeset
|
4616 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
|
4617 } |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4618 |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4619 /* 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
|
4620 *iter = '\0'; |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4621 |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4622 return workstr; |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4623 } |
bf9db4c67679
Add purple_utf8_strip_unprintables and use it on outgoing XMPP messages.
Paul Aurich <paul@darkrain42.org>
parents:
27012
diff
changeset
|
4624 |
21863
7e833250a0ef
Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents:
21862
diff
changeset
|
4625 /* |
7e833250a0ef
Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents:
21862
diff
changeset
|
4626 * 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
|
4627 * gai_strerror(). |
7e833250a0ef
Add a comment that I took this from glib
Mark Doliner <mark@kingant.net>
parents:
21862
diff
changeset
|
4628 */ |
21862
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4629 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
|
4630 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
|
4631 { |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4632 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
|
4633 char *msg; |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4634 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
|
4635 |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4636 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
|
4637 |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4638 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
|
4639 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
|
4640 { |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4641 /* 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
|
4642 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
|
4643 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
|
4644 } |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4645 else |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4646 { |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4647 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
|
4648 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
|
4649 { |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4650 /* 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
|
4651 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
|
4652 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
|
4653 |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4654 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
|
4655 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
|
4656 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
|
4657 } |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4658 } |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4659 |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4660 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
|
4661 if (!msg) |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4662 { |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4663 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
|
4664 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
|
4665 } |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4666 |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4667 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
|
4668 |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4669 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
|
4670 return msg; |
ae58ffd5e929
Create a purple_gai_strerror() function similar to g_str_error() which
Mark Doliner <mark@kingant.net>
parents:
21794
diff
changeset
|
4671 } |
15373
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 char * |
15822 | 4674 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
|
4675 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4676 GString *out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4677 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4678 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
|
4679 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
|
4680 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4681 out = g_string_new(""); |
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 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
|
4684 gunichar wc = g_utf8_get_char(str); |
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 /* super simple check. hopefully not too wrong. */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4687 if(wc >= 0x80) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4688 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
|
4689 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4690 g_string_append_unichar(out, wc); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4691 } |
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 return g_string_free(out, FALSE); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4695 } |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4698 char * |
15822 | 4699 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
|
4700 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4701 GString *out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4702 char *buf, *b; |
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 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
|
4705 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
|
4706 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4707 buf = (char *) str; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4708 out = g_string_new(""); |
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 while( (b = strstr(buf, "&#")) ) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4711 gunichar wc; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4712 int base = 0; |
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 /* append everything leading up to the &# */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4715 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
|
4716 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4717 b += 2; /* skip past the &# */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4718 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4719 /* 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
|
4720 if(*b == 'x' || *b == 'X') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4721 base = 16; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4722 b++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4723 } |
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 /* 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
|
4726 wc = (gunichar) strtoul(b, &buf, base); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4727 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4728 /* 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
|
4729 if(*buf == ';') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4730 g_string_append_unichar(out, wc); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4731 buf++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4732 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4733 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4734 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4735 /* append whatever's left */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4736 g_string_append(out, buf); |
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 g_string_free(out, FALSE); |
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 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4742 int |
15822 | 4743 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
|
4744 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4745 char *a_norm = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4746 char *b_norm = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4747 int ret = -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4748 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4749 if(!a && b) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4750 return -1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4751 else if(!b && a) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4752 return 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4753 else if(!a && !b) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4754 return 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4755 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4756 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
|
4757 { |
15822 | 4758 purple_debug_error("purple_utf8_strcasecmp", |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4759 "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
|
4760 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4761 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4762 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4763 a_norm = g_utf8_casefold(a, -1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4764 b_norm = g_utf8_casefold(b, -1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4765 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
|
4766 g_free(a_norm); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4767 g_free(b_norm); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4768 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4769 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4770 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4771 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4772 /* previously conversation::find_nick() */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4773 gboolean |
15822 | 4774 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
|
4775 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4776 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
|
4777 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
|
4778 gunichar before, after; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4779 int n; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4780 gboolean ret = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4781 |
24841
e7b27ee5e7b6
Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents:
24592
diff
changeset
|
4782 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
|
4783 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4784 pin = g_utf8_strdown(needle, -1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4785 n = strlen(pin); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4786 |
24841
e7b27ee5e7b6
Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents:
24592
diff
changeset
|
4787 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
|
4788 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
|
4789 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
|
4790 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
|
4791 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
|
4792 } |
e7b27ee5e7b6
Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents:
24592
diff
changeset
|
4793 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
|
4794 |
e7b27ee5e7b6
Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents:
24592
diff
changeset
|
4795 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
|
4796 /* 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
|
4797 ("!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
|
4798 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
|
4799 and isn't the '&' from a "&" 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
|
4800 (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
|
4801 && after != -2 && !g_unichar_isalnum(after)) { |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4802 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
|
4803 break; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4804 } |
24841
e7b27ee5e7b6
Make purple_utf8_has_word() better about detecting word boundaries (still not
Daniel Atallah <daniel.atallah@gmail.com>
parents:
24592
diff
changeset
|
4805 start = p + 1; |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4806 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4807 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4808 g_free(pin); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4809 g_free(hay); |
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 return ret; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4812 } |
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 void |
15822 | 4815 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
|
4816 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4817 gchar *message_conv; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4818 GError *error = NULL; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4819 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4820 /* 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
|
4821 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
|
4822 if (message_conv != NULL) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4823 fputs(message_conv, filestream); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4824 g_free(message_conv); |
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 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4827 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4828 /* use 'message' as a fallback */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4829 g_warning("%s\n", error->message); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4830 g_error_free(error); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4831 fputs(message, filestream); |
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 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4834 |
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
|
4835 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
|
4836 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4837 char *c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4838 gboolean inside_html = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4839 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4840 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
|
4841 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4842 if(len == -1) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4843 len = strlen(message); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4844 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4845 for (c = message; *c; c++, len--) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4846 if(inside_html) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4847 if(*c == '>') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4848 inside_html = FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4849 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4850 if(*c == '<') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4851 inside_html = TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4852 else |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4853 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4854 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4855 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4856 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4857 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
|
4858 memmove(c, c+4, len-3); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4859 return TRUE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4860 } |
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 return FALSE; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4863 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4864 |
15822 | 4865 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
|
4866 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4867 char *out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4868 char *a; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4869 char *a0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4870 const char *b; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4871 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4872 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
|
4873 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4874 out = g_malloc(strlen(in)+1); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4875 a = out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4876 b = in; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4877 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4878 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
|
4879 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4880 while(*b) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4881 if(*b == '_') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4882 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
|
4883 /* Detected CJK style shortcut (Bug 875311) */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4884 a = a0; /* undo the left parenthesis */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4885 b += 3; /* and skip the whole mess */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4886 } else if(*(b+1) == '_') { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4887 *(a++) = '_'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4888 b += 2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4889 a0 = a; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4890 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4891 b++; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4892 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4893 /* 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
|
4894 } 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
|
4895 if (*b != ' ') |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4896 a0 = a; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4897 *(a++) = *(b++); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4898 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4899 /* 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
|
4900 int n = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4901 int i; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4902 if ((*b & 0xe0) == 0xc0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4903 n = 2; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4904 } else if ((*b & 0xf0) == 0xe0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4905 n = 3; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4906 } else if ((*b & 0xf8) == 0xf0) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4907 n = 4; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4908 } else if ((*b & 0xfc) == 0xf8) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4909 n = 5; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4910 } else if ((*b & 0xfe) == 0xfc) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4911 n = 6; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4912 } else { /* Illegal utf8 */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4913 n = 1; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4914 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4915 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
|
4916 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
|
4917 *(a++) = *(b++); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4918 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4919 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4920 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4921 *a = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4922 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4923 return out; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4924 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4925 |
15822 | 4926 const char* purple_unescape_filename(const char *escaped) { |
4927 return purple_url_decode(escaped); | |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4928 } |
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 |
15822 | 4931 /* 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
|
4932 * 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
|
4933 * for compat reasons */ |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4934 const char * |
15822 | 4935 purple_escape_filename(const char *str) |
15373
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4936 { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4937 const char *iter; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4938 static char buf[BUF_LEN]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4939 char utf_char[6]; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4940 guint i, j = 0; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4941 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4942 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
|
4943 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
|
4944 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4945 iter = str; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4946 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
|
4947 gunichar c = g_utf8_get_char(iter); |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4948 /* 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
|
4949 * 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
|
4950 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
|
4951 c == '_' || c == '.' || c == '#')) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4952 buf[j++] = c; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4953 } else { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4954 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
|
4955 for (i = 0; i < bytes; i++) { |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4956 if (j > (BUF_LEN - 4)) |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4957 break; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4958 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
|
4959 j += 3; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4960 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4961 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4962 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4963 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4964 buf[j] = '\0'; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4965 |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4966 return buf; |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4967 } |
5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff
changeset
|
4968 |
15822 | 4969 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
|
4970 { |
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
|
4971 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
|
4972 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
|
4973 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
|
4974 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
|
4975 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
|
4976 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
|
4977 } |
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
|
4978 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
|
4979 } |
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
|
4980 |
15822 | 4981 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
|
4982 { |
15664
95c4dee525f0
Merge fix and build fix for win32
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15663
diff
changeset
|
4983 #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
|
4984 #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
|
4985 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
|
4986 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
|
4987 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
|
4988 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
|
4989 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
|
4990 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
|
4991 |
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
|
4992 #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
|
4993 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
|
4994 #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
|
4995 |
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
|
4996 #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
|
4997 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
|
4998 #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
|
4999 |
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
|
5000 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
|
5001 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
|
5002 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
|
5003 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
|
5004 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
|
5005 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
|
5006 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
|
5007 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
|
5008 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
|
5009 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
|
5010 #endif /* HAVE_SIGNAL_H */ |
15664
95c4dee525f0
Merge fix and build fix for win32
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15663
diff
changeset
|
5011 #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
|
5012 } |
22000
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5013 |
22089
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5014 static void |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5015 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
|
5016 { |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5017 va_list args; |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5018 va_start(args, status); |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5019 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
|
5020 va_end(args); |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5021 } |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5022 |
22000
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5023 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
|
5024 { |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5025 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
|
5026 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
|
5027 PurplePresence *presence; |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5028 PurpleStatus *tune; |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5029 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
|
5030 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
|
5031 continue; |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5032 |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5033 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
|
5034 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
|
5035 if (!tune) |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5036 continue; |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5037 if (title) { |
22089
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5038 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
|
5039 PURPLE_TUNE_TITLE, title, |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5040 PURPLE_TUNE_ARTIST, artist, |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5041 PURPLE_TUNE_ALBUM, album, |
1e227e2587e6
Make setting 'now listening' actually work, thanks to khc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22060
diff
changeset
|
5042 NULL); |
22000
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5043 } else { |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5044 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
|
5045 } |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5046 } |
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 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
|
5050 { |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5051 GString *string; |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5052 char *esc; |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5053 |
22060
83613550512b
Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22000
diff
changeset
|
5054 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
|
5055 return NULL; |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5056 |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5057 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
|
5058 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
|
5059 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
|
5060 g_free(esc); |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5061 |
22060
83613550512b
Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22000
diff
changeset
|
5062 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
|
5063 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
|
5064 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
|
5065 g_free(esc); |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5066 } |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5067 |
22060
83613550512b
Ignore both NULL and empty strings.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22000
diff
changeset
|
5068 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
|
5069 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
|
5070 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
|
5071 g_free(esc); |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5072 } |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5073 |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5074 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
|
5075 } |
af0426c34c27
Utility functions to set and format song information. Closes #4398.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21863
diff
changeset
|
5076 |
23538
399975ad001c
Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23388
diff
changeset
|
5077 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
|
5078 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
|
5079 { |
399975ad001c
Add purple_get_host_name to get the hostname of the machine.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
23388
diff
changeset
|
5080 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
|
5081 } |
29129
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5082 |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5083 gchar * |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5084 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
|
5085 { |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5086 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
|
5087 |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5088 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
|
5089 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
|
5090 tmp >>= 12; |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5091 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
|
5092 |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5093 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
|
5094 |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5095 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
|
5096 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
|
5097 tmp & 0xFFFF, |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5098 a, |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5099 b, |
ecd2136ff818
Broke out the generation of random UUIDs to its own function
Marcus Lundblad <ml@update.uu.se>
parents:
29110
diff
changeset
|
5100 (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
|
5101 } |