Mercurial > pidgin
comparison src/protocols/msn/utils.c @ 7134:67f9b43c402a
[gaim-migrate @ 7701]
I think this is the fifth Yahoo authentication method Gaim's seen in its
days. Please tell me if anything stops working.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Fri, 03 Oct 2003 23:01:13 +0000 |
parents | b7e113a59b51 |
children | 06f57183e29f |
comparison
equal
deleted
inserted
replaced
7133:28dd20b5f4cf | 7134:67f9b43c402a |
---|---|
18 * You should have received a copy of the GNU General Public License | 18 * You should have received a copy of the GNU General Public License |
19 * along with this program; if not, write to the Free Software | 19 * along with this program; if not, write to the Free Software |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 */ | 21 */ |
22 #include "msn.h" | 22 #include "msn.h" |
23 | |
24 char * | |
25 msn_url_decode(const char *str) | |
26 { | |
27 static char buf[MSN_BUF_LEN]; | |
28 int i, j = 0; | |
29 char *bum; | |
30 | |
31 g_return_val_if_fail(str != NULL, NULL); | |
32 | |
33 for (i = 0; i < strlen(str); i++) { | |
34 char hex[3]; | |
35 | |
36 if (str[i] != '%') | |
37 buf[j++] = str[i]; | |
38 else { | |
39 strncpy(hex, str + ++i, 2); | |
40 hex[2] = '\0'; | |
41 | |
42 /* i is pointing to the start of the number */ | |
43 i++; | |
44 | |
45 /* | |
46 * Now it's at the end and at the start of the for loop | |
47 * will be at the next character. | |
48 */ | |
49 buf[j++] = strtol(hex, NULL, 16); | |
50 } | |
51 } | |
52 | |
53 buf[j] = '\0'; | |
54 | |
55 if (!g_utf8_validate(buf, -1, (const char **)&bum)) | |
56 *bum = '\0'; | |
57 | |
58 return buf; | |
59 } | |
60 | |
61 char * | |
62 msn_url_encode(const char *str) | |
63 { | |
64 static char buf[MSN_BUF_LEN]; | |
65 int i, j = 0; | |
66 | |
67 g_return_val_if_fail(str != NULL, NULL); | |
68 | |
69 for (i = 0; i < strlen(str); i++) { | |
70 if (isalnum(str[i])) | |
71 buf[j++] = str[i]; | |
72 else { | |
73 sprintf(buf + j, "%%%02x", (unsigned char)str[i]); | |
74 j += 3; | |
75 } | |
76 } | |
77 | |
78 buf[j] = '\0'; | |
79 | |
80 return buf; | |
81 } | |
82 | 23 |
83 void | 24 void |
84 msn_parse_format(const char *mime, char **pre_ret, char **post_ret) | 25 msn_parse_format(const char *mime, char **pre_ret, char **post_ret) |
85 { | 26 { |
86 char *cur; | 27 char *cur; |
144 pre = g_string_append(pre, tag); | 85 pre = g_string_append(pre, tag); |
145 post = g_string_prepend(post, "</FONT>"); | 86 post = g_string_prepend(post, "</FONT>"); |
146 } | 87 } |
147 } | 88 } |
148 | 89 |
149 cur = g_strdup(msn_url_decode(pre->str)); | 90 cur = g_strdup(gaim_url_decode(pre->str)); |
150 g_string_free(pre, TRUE); | 91 g_string_free(pre, TRUE); |
151 | 92 |
152 if (pre_ret != NULL) | 93 if (pre_ret != NULL) |
153 *pre_ret = cur; | 94 *pre_ret = cur; |
154 else | 95 else |
155 g_free(cur); | 96 g_free(cur); |
156 | 97 |
157 cur = g_strdup(msn_url_decode(post->str)); | 98 cur = g_strdup(gaim_url_decode(post->str)); |
158 g_string_free(post, TRUE); | 99 g_string_free(post, TRUE); |
159 | 100 |
160 if (post_ret != NULL) | 101 if (post_ret != NULL) |
161 *post_ret = cur; | 102 *post_ret = cur; |
162 else | 103 else |