Mercurial > pidgin
annotate src/protocols/msn/utils.c @ 6109:0922bb7a7bbc
[gaim-migrate @ 6571]
Make attempting to sign on to an account twice not crash Gaim, and make
the prompt for password request window only open once at max. I might
change this in a few minutes, but this works, and I wanted to commit it
before I break something.
Move the gaim_request_input() call for "Please enter your password" to
connection.c instead of gtkconn.c. There is no need for this to be in
gtkconn.c, and doing it in core means less work for UIs.
Make closing a notify window call the cancel action.
Set the titles for request windows, when given.
Remove a bit of odd, un-needed code from main.c (hitting "enter" in the
password field was calling doenter which called dologin. Now it just
calls dologin).
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sun, 13 Jul 2003 18:33:25 +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 } |
