Tue, 27 Jan 2004 04:46:05 +0000
[gaim-migrate @ 8884]
Committing one of shx's MSN patches, which splits off the Nexus connection
code into nexus.[ch] and cleans it up a bit.
committer: Christian Hammond <chipx86@chipx86.com>
| 5309 | 1 | /** |
| 5312 | 2 | * @file utils.c Utility functions |
| 5309 | 3 | * |
| 4 | * gaim | |
| 5 | * | |
| 6 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
|
6701
7e2db9273748
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
6359
diff
changeset
|
7 | * |
| 5309 | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 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 | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
| 22 | #include "msn.h" | |
| 23 | ||
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
24 | void |
|
c3347685b9ef
[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 | 26 | { |
| 27 | char *cur; | |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
28 | GString *pre = g_string_new(NULL); |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
29 | GString *post = g_string_new(NULL); |
|
6093
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
30 | unsigned int colors[3]; |
| 5309 | 31 | |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
32 | if (pre_ret != NULL) *pre_ret = NULL; |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
33 | if (post_ret != NULL) *post_ret = NULL; |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
34 | |
| 5309 | 35 | cur = strstr(mime, "FN="); |
| 36 | ||
| 37 | if (cur && (*(cur = cur + 3) != ';')) { | |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
38 | pre = g_string_append(pre, "<FONT FACE=\""); |
| 5309 | 39 | |
| 40 | while (*cur && *cur != ';') { | |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
41 | pre = g_string_append_c(pre, *cur); |
| 5309 | 42 | cur++; |
| 43 | } | |
| 44 | ||
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
45 | pre = g_string_append(pre, "\">"); |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
46 | post = g_string_prepend(post, "</FONT>"); |
| 5309 | 47 | } |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
48 | |
| 5309 | 49 | cur = strstr(mime, "EF="); |
| 50 | ||
| 51 | if (cur && (*(cur = cur + 3) != ';')) { | |
| 52 | while (*cur && *cur != ';') { | |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
53 | pre = g_string_append_c(pre, '<'); |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
54 | pre = g_string_append_c(pre, *cur); |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
55 | pre = g_string_append_c(pre, '>'); |
| 5309 | 56 | cur++; |
| 57 | } | |
| 58 | } | |
| 59 | ||
| 60 | cur = strstr(mime, "CO="); | |
| 61 | ||
| 62 | if (cur && (*(cur = cur + 3) != ';')) { | |
|
6093
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
63 | int i; |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
64 | |
|
2095841fde03
[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]); |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
66 | |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
67 | if (i > 0) { |
| 5309 | 68 | char tag[64]; |
|
6093
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
69 | |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
70 | if (i == 1) { |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
71 | colors[2] = colors[0]; |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
72 | colors[1] = 0; |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
73 | colors[0] = 0; |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
74 | } |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
75 | else if (i == 2) { |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
76 | colors[2] = colors[1]; |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
77 | colors[1] = colors[0]; |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
78 | colors[0] = 0; |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
79 | } |
|
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
80 | |
| 5309 | 81 | g_snprintf(tag, sizeof(tag), |
| 82 | "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">", | |
|
6093
2095841fde03
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
83 | colors[2], colors[1], colors[0]); |
| 5309 | 84 | |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
85 | pre = g_string_append(pre, tag); |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
86 | post = g_string_prepend(post, "</FONT>"); |
| 5309 | 87 | } |
| 88 | } | |
| 89 | ||
| 7134 | 90 | cur = g_strdup(gaim_url_decode(pre->str)); |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
91 | g_string_free(pre, TRUE); |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
92 | |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
93 | if (pre_ret != NULL) |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
94 | *pre_ret = cur; |
|
6359
5b1705ffdd55
[gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents:
6358
diff
changeset
|
95 | else |
|
5b1705ffdd55
[gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents:
6358
diff
changeset
|
96 | g_free(cur); |
| 5309 | 97 | |
| 7134 | 98 | cur = g_strdup(gaim_url_decode(post->str)); |
|
6358
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
99 | g_string_free(post, TRUE); |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
100 | |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
101 | if (post_ret != NULL) |
|
c3347685b9ef
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6093
diff
changeset
|
102 | *post_ret = cur; |
|
6359
5b1705ffdd55
[gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents:
6358
diff
changeset
|
103 | else |
|
5b1705ffdd55
[gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents:
6358
diff
changeset
|
104 | g_free(cur); |
| 5309 | 105 | } |