Mercurial > pidgin
annotate src/protocols/msn/utils.c @ 6322:dd2be7cd66df
[gaim-migrate @ 6821]
This is:
-Alphabetize the translation things in ChangeLog
-Spell Brian Tarricone's name correctly (I hope...)
-A fix for a crash when renaming a group containing a chat, thanks to
javabsp. Me gusta this change.
-Make the rename group dialog use gaim_request_input(). The old dialog
may be a bit prettier, but this one uses the request code, which means
less work for UIs, which rocks.
-Change the TRUE and FALSE defines in aim.h to be more compatible with c++.
Thanks to Zack Rusin for this change.
-Declare aim.h as a C file when it is used in a c++ program. This should
let libfaim be used in C++ programs such as kopete. Thanks again to
Zack Rusin.
-Rename aimutil_itemidx() to aimutil_itemindex(). "idx" is not a standard
abbreviation, and code is written once and read many times--it should be
easily readable.
-Not an automatic laundry folding machine. So I'm going to do that.
(Fold my laundry)
(Not automatically)
(yet)
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Tue, 29 Jul 2003 04:27:31 +0000 |
| parents | 13a37cacd10b |
| children | 8ba58b296cc1 |
| rev | line source |
|---|---|
| 5309 | 1 /** |
|
5312
89948fedf782
[gaim-migrate @ 5684]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
2 * @file utils.c Utility functions |
| 5309 | 3 * |
| 4 * gaim | |
| 5 * | |
| 6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 7 * | |
| 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 | |
| 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 | |
| 83 char * | |
| 84 msn_parse_format(const char *mime) | |
| 85 { | |
| 86 char *cur; | |
| 87 GString *ret = g_string_new(NULL); | |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
88 unsigned int colors[3]; |
| 5309 | 89 |
| 90 cur = strstr(mime, "FN="); | |
| 91 | |
| 92 if (cur && (*(cur = cur + 3) != ';')) { | |
| 93 ret = g_string_append(ret, "<FONT FACE=\""); | |
| 94 | |
| 95 while (*cur && *cur != ';') { | |
| 96 ret = g_string_append_c(ret, *cur); | |
| 97 cur++; | |
| 98 } | |
| 99 | |
| 100 ret = g_string_append(ret, "\">"); | |
| 101 } | |
| 102 | |
| 103 cur = strstr(mime, "EF="); | |
| 104 | |
| 105 if (cur && (*(cur = cur + 3) != ';')) { | |
| 106 while (*cur && *cur != ';') { | |
| 107 ret = g_string_append_c(ret, '<'); | |
| 108 ret = g_string_append_c(ret, *cur); | |
| 109 ret = g_string_append_c(ret, '>'); | |
| 110 cur++; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 cur = strstr(mime, "CO="); | |
| 115 | |
| 116 if (cur && (*(cur = cur + 3) != ';')) { | |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
117 int i; |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
118 |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
119 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
|
120 |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
121 if (i > 0) { |
| 5309 | 122 char tag[64]; |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
123 |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
124 if (i == 1) { |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
125 colors[2] = colors[0]; |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
126 colors[1] = 0; |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
127 colors[0] = 0; |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
128 } |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
129 else if (i == 2) { |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
130 colors[2] = colors[1]; |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
131 colors[1] = colors[0]; |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
132 colors[0] = 0; |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
133 } |
|
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
134 |
| 5309 | 135 g_snprintf(tag, sizeof(tag), |
| 136 "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">", | |
|
6093
13a37cacd10b
[gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents:
5964
diff
changeset
|
137 colors[2], colors[1], colors[0]); |
| 5309 | 138 |
| 139 ret = g_string_append(ret, tag); | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 cur = msn_url_decode(ret->str); | |
| 144 g_string_free(ret, TRUE); | |
| 145 | |
| 146 return cur; | |
| 147 } |
