Mercurial > pidgin
annotate src/protocols/msn/utils.c @ 5344:fda2d94b9434
[gaim-migrate @ 5720]
Tim Mooney (enchanter) writes:
"configure.ac calls AC_PATH_XTRA and then assumes
$x_libraries will be
set. You can't rely on this, because on platforms
where the libraries and headers are in places that the
development toolchain searches by default, configure
will *NOT* set $x_libraries or $x_includes.
This incorrect assumption causes configure to miss
several X-related tests, and it causes the final link
to fail on platforms like Tru64 UNIX or Solaris
(and likely others)."
as this did not break my compile, i'm going ahead and committing this.
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Sat, 10 May 2003 12:47:17 +0000 |
| parents | 89948fedf782 |
| children | b583de5880bc |
| 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); | |
| 88 guint colorbuf; | |
| 89 char *colors = (char *)(&colorbuf); | |
| 90 | |
| 91 cur = strstr(mime, "FN="); | |
| 92 | |
| 93 if (cur && (*(cur = cur + 3) != ';')) { | |
| 94 ret = g_string_append(ret, "<FONT FACE=\""); | |
| 95 | |
| 96 while (*cur && *cur != ';') { | |
| 97 ret = g_string_append_c(ret, *cur); | |
| 98 cur++; | |
| 99 } | |
| 100 | |
| 101 ret = g_string_append(ret, "\">"); | |
| 102 } | |
| 103 | |
| 104 cur = strstr(mime, "EF="); | |
| 105 | |
| 106 if (cur && (*(cur = cur + 3) != ';')) { | |
| 107 while (*cur && *cur != ';') { | |
| 108 ret = g_string_append_c(ret, '<'); | |
| 109 ret = g_string_append_c(ret, *cur); | |
| 110 ret = g_string_append_c(ret, '>'); | |
| 111 cur++; | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 cur = strstr(mime, "CO="); | |
| 116 | |
| 117 if (cur && (*(cur = cur + 3) != ';')) { | |
| 118 if (sscanf (cur, "%x;", &colorbuf) == 1) { | |
| 119 char tag[64]; | |
| 120 g_snprintf(tag, sizeof(tag), | |
| 121 "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">", | |
| 122 colors[0], colors[1], colors[2]); | |
| 123 | |
| 124 ret = g_string_append(ret, tag); | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 cur = msn_url_decode(ret->str); | |
| 129 g_string_free(ret, TRUE); | |
| 130 | |
| 131 return cur; | |
| 132 } |
