Mercurial > pidgin.yaz
comparison src/util.c @ 11137:096020ae09a9
[gaim-migrate @ 13201]
Some more deworming. I mean, dewarning.
I also realized that lots of glib uses guchar* instead of guint* for
passing around bits of binary data, so I changed some stuff in util.c
that I'd already changed.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 21 Jul 2005 05:49:48 +0000 |
parents | f2755f58a7da |
children | ee059fe9b362 |
comparison
equal
deleted
inserted
replaced
11136:6270b6ad69a2 | 11137:096020ae09a9 |
---|---|
66 | 66 |
67 /************************************************************************** | 67 /************************************************************************** |
68 * Base16 Functions | 68 * Base16 Functions |
69 **************************************************************************/ | 69 **************************************************************************/ |
70 gchar * | 70 gchar * |
71 gaim_base16_encode(const guint8 *data, gsize len) | 71 gaim_base16_encode(const guchar *data, gsize len) |
72 { | 72 { |
73 int i; | 73 int i; |
74 gchar *ascii = NULL; | 74 gchar *ascii = NULL; |
75 | 75 |
76 g_return_val_if_fail(data != NULL, NULL); | 76 g_return_val_if_fail(data != NULL, NULL); |
82 snprintf(&ascii[i * 2], 3, "%02hhx", data[i]); | 82 snprintf(&ascii[i * 2], 3, "%02hhx", data[i]); |
83 | 83 |
84 return ascii; | 84 return ascii; |
85 } | 85 } |
86 | 86 |
87 guint8 * | 87 guchar * |
88 gaim_base16_decode(const char *str, gsize *ret_len) | 88 gaim_base16_decode(const char *str, gsize *ret_len) |
89 { | 89 { |
90 int len, i, accumulator = 0; | 90 int len, i, accumulator = 0; |
91 guint8 *data; | 91 guchar *data; |
92 | 92 |
93 g_return_val_if_fail(str != NULL, NULL); | 93 g_return_val_if_fail(str != NULL, NULL); |
94 | 94 |
95 len = strlen(str); | 95 len = strlen(str); |
96 | 96 |
140 | 140 |
141 static const char xdigits[] = | 141 static const char xdigits[] = |
142 "0123456789abcdef"; | 142 "0123456789abcdef"; |
143 | 143 |
144 gchar * | 144 gchar * |
145 gaim_base64_encode(const guint8 *data, gsize len) | 145 gaim_base64_encode(const guchar *data, gsize len) |
146 { | 146 { |
147 char *out, *rv; | 147 char *out, *rv; |
148 | 148 |
149 g_return_val_if_fail(data != NULL, NULL); | 149 g_return_val_if_fail(data != NULL, NULL); |
150 g_return_val_if_fail(len > 0, NULL); | 150 g_return_val_if_fail(len > 0, NULL); |
178 *out = '\0'; | 178 *out = '\0'; |
179 | 179 |
180 return rv; | 180 return rv; |
181 } | 181 } |
182 | 182 |
183 guint8 * | 183 guchar * |
184 gaim_base64_decode(const char *str, gsize *ret_len) | 184 gaim_base64_decode(const char *str, gsize *ret_len) |
185 { | 185 { |
186 guint8 *out = NULL; | 186 guchar *out = NULL; |
187 char tmp = 0; | 187 char tmp = 0; |
188 const char *c; | 188 const char *c; |
189 gint32 tmp2 = 0; | 189 gint32 tmp2 = 0; |
190 int len = 0, n = 0; | 190 int len = 0, n = 0; |
191 | 191 |
208 c++; | 208 c++; |
209 continue; | 209 continue; |
210 } else if (*c == '=') { | 210 } else if (*c == '=') { |
211 if (n == 3) { | 211 if (n == 3) { |
212 out = g_realloc(out, len + 2); | 212 out = g_realloc(out, len + 2); |
213 out[len] = (guint8)(tmp2 >> 10) & 0xff; | 213 out[len] = (guchar)(tmp2 >> 10) & 0xff; |
214 len++; | 214 len++; |
215 out[len] = (guint8)(tmp2 >> 2) & 0xff; | 215 out[len] = (guchar)(tmp2 >> 2) & 0xff; |
216 len++; | 216 len++; |
217 } else if (n == 2) { | 217 } else if (n == 2) { |
218 out = g_realloc(out, len + 1); | 218 out = g_realloc(out, len + 1); |
219 out[len] = (guint8)(tmp2 >> 4) & 0xff; | 219 out[len] = (guchar)(tmp2 >> 4) & 0xff; |
220 len++; | 220 len++; |
221 } | 221 } |
222 break; | 222 break; |
223 } | 223 } |
224 tmp2 = ((tmp2 << 6) | (tmp & 0xff)); | 224 tmp2 = ((tmp2 << 6) | (tmp & 0xff)); |
225 n++; | 225 n++; |
226 if (n == 4) { | 226 if (n == 4) { |
227 out = g_realloc(out, len + 3); | 227 out = g_realloc(out, len + 3); |
228 out[len] = (guint8)((tmp2 >> 16) & 0xff); | 228 out[len] = (guchar)((tmp2 >> 16) & 0xff); |
229 len++; | 229 len++; |
230 out[len] = (guint8)((tmp2 >> 8) & 0xff); | 230 out[len] = (guchar)((tmp2 >> 8) & 0xff); |
231 len++; | 231 len++; |
232 out[len] = (guint8)(tmp2 & 0xff); | 232 out[len] = (guchar)(tmp2 & 0xff); |
233 len++; | 233 len++; |
234 tmp2 = 0; | 234 tmp2 = 0; |
235 n = 0; | 235 n = 0; |
236 } | 236 } |
237 c++; | 237 c++; |
247 } | 247 } |
248 | 248 |
249 /************************************************************************** | 249 /************************************************************************** |
250 * Quoted Printable Functions (see RFC 2045). | 250 * Quoted Printable Functions (see RFC 2045). |
251 **************************************************************************/ | 251 **************************************************************************/ |
252 guint8 * | 252 guchar * |
253 gaim_quotedp_decode(const char *str, gsize *ret_len) | 253 gaim_quotedp_decode(const char *str, gsize *ret_len) |
254 { | 254 { |
255 char *n, *new; | 255 char *n, *new; |
256 const char *end, *p; | 256 const char *end, *p; |
257 | 257 |
291 *ret_len = n - new; | 291 *ret_len = n - new; |
292 | 292 |
293 /* Resize to take less space */ | 293 /* Resize to take less space */ |
294 /* new = realloc(new, n - new); */ | 294 /* new = realloc(new, n - new); */ |
295 | 295 |
296 return (guint8 *)new; | 296 return (guchar *)new; |
297 } | 297 } |
298 | 298 |
299 /************************************************************************** | 299 /************************************************************************** |
300 * MIME Functions | 300 * MIME Functions |
301 **************************************************************************/ | 301 **************************************************************************/ |
408 case state_question4: | 408 case state_question4: |
409 if (*cur == '=') { /* Got the whole encoded-word */ | 409 if (*cur == '=') { /* Got the whole encoded-word */ |
410 char *charset = g_strndup(charset0, encoding0 - charset0 - 1); | 410 char *charset = g_strndup(charset0, encoding0 - charset0 - 1); |
411 char *encoding = g_strndup(encoding0, encoded_text0 - encoding0 - 1); | 411 char *encoding = g_strndup(encoding0, encoded_text0 - encoding0 - 1); |
412 char *encoded_text = g_strndup(encoded_text0, cur - encoded_text0 - 1); | 412 char *encoded_text = g_strndup(encoded_text0, cur - encoded_text0 - 1); |
413 guint8 *decoded = NULL; | 413 guchar *decoded = NULL; |
414 gsize dec_len; | 414 gsize dec_len; |
415 if (g_ascii_strcasecmp(encoding, "Q") == 0) | 415 if (g_ascii_strcasecmp(encoding, "Q") == 0) |
416 decoded = gaim_quotedp_decode(encoded_text, &dec_len); | 416 decoded = gaim_quotedp_decode(encoded_text, &dec_len); |
417 else if (g_ascii_strcasecmp(encoding, "B") == 0) | 417 else if (g_ascii_strcasecmp(encoding, "B") == 0) |
418 decoded = gaim_base64_decode(encoded_text, &dec_len); | 418 decoded = gaim_base64_decode(encoded_text, &dec_len); |