annotate src/protocols/msn/utils.c @ 7834:99ffabc6ce73

[gaim-migrate @ 8487] This patch from Mike Hearn should fix HTTP proxy support for MSN, and provides another step toward the MSN HTTP access method working. The HTTP proxy may need testing from other people, but looks like it shouldn't give any problems. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 12 Dec 2003 00:14:40 +0000
parents 67f9b43c402a
children 06f57183e29f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
5312
89948fedf782 [gaim-migrate @ 5684]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
2 * @file utils.c Utility functions
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 * gaim
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
6701
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6359
diff changeset
7 *
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * (at your option) any later version.
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * GNU General Public License for more details.
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 #include "msn.h"
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
24 void
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
25 msn_parse_format(const char *mime, char **pre_ret, char **post_ret)
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27 char *cur;
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
28 GString *pre = g_string_new(NULL);
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
29 GString *post = g_string_new(NULL);
6093
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
30 unsigned int colors[3];
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
32 if (pre_ret != NULL) *pre_ret = NULL;
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
33 if (post_ret != NULL) *post_ret = NULL;
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
34
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 cur = strstr(mime, "FN=");
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 if (cur && (*(cur = cur + 3) != ';')) {
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
38 pre = g_string_append(pre, "<FONT FACE=\"");
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40 while (*cur && *cur != ';') {
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
41 pre = g_string_append_c(pre, *cur);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
42 cur++;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
43 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
44
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
45 pre = g_string_append(pre, "\">");
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
46 post = g_string_prepend(post, "</FONT>");
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
47 }
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
48
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
49 cur = strstr(mime, "EF=");
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51 if (cur && (*(cur = cur + 3) != ';')) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
52 while (*cur && *cur != ';') {
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
53 pre = g_string_append_c(pre, '<');
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
54 pre = g_string_append_c(pre, *cur);
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
55 pre = g_string_append_c(pre, '>');
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
56 cur++;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
57 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
58 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60 cur = strstr(mime, "CO=");
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
61
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
62 if (cur && (*(cur = cur + 3) != ';')) {
6093
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
63 int i;
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
64
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
65 i = sscanf(cur, "%02x%02x%02x;", &colors[0], &colors[1], &colors[2]);
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
66
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
67 if (i > 0) {
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68 char tag[64];
6093
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
69
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
70 if (i == 1) {
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
71 colors[2] = colors[0];
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
72 colors[1] = 0;
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
73 colors[0] = 0;
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
74 }
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
75 else if (i == 2) {
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
76 colors[2] = colors[1];
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
77 colors[1] = colors[0];
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
78 colors[0] = 0;
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
79 }
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
80
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
81 g_snprintf(tag, sizeof(tag),
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82 "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">",
6093
13a37cacd10b [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
83 colors[2], colors[1], colors[0]);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
85 pre = g_string_append(pre, tag);
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
86 post = g_string_prepend(post, "</FONT>");
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89
7134
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 6701
diff changeset
90 cur = g_strdup(gaim_url_decode(pre->str));
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
91 g_string_free(pre, TRUE);
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
92
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
93 if (pre_ret != NULL)
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
94 *pre_ret = cur;
6359
dfde69e105ae [gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents: 6358
diff changeset
95 else
dfde69e105ae [gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents: 6358
diff changeset
96 g_free(cur);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97
7134
67f9b43c402a [gaim-migrate @ 7701]
Sean Egan <seanegan@gmail.com>
parents: 6701
diff changeset
98 cur = g_strdup(gaim_url_decode(post->str));
6358
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
99 g_string_free(post, TRUE);
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
100
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
101 if (post_ret != NULL)
8ba58b296cc1 [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
102 *post_ret = cur;
6359
dfde69e105ae [gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents: 6358
diff changeset
103 else
dfde69e105ae [gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents: 6358
diff changeset
104 g_free(cur);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105 }