Mon, 08 Oct 2001 01:12:02 +0000
[gaim-migrate @ 2460]
i hope this works
| 2086 | 1 | /* |
| 2 | * libyay | |
| 3 | * | |
| 4 | * Copyright (C) 2001 Eric Warmenhoven <warmenhoven@yahoo.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | * | |
| 20 | */ | |
| 21 | ||
| 22 | #include "internal.h" | |
| 23 | #include <ctype.h> | |
|
2154
7d4835b44b85
[gaim-migrate @ 2164]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
24 | #include <string.h> |
| 2086 | 25 | |
| 26 | char *yahoo_urlencode(const char *str) | |
| 27 | { | |
| 28 | int len; | |
| 29 | char *ret; | |
| 30 | const char *s; | |
| 31 | char *r; | |
| 32 | ||
| 33 | if ((len = strlen(str)) == 0) | |
| 34 | return NULL; | |
| 35 | ||
| 36 | ret = g_malloc(len * 3 + 1); | |
| 37 | if (!ret) | |
| 38 | return NULL; | |
| 39 | ||
| 40 | for (s = str, r = ret; *s; s++) { | |
| 41 | if (isdigit(*s) || isalpha(*s) || *s == '_') | |
| 42 | *r++ = *s; | |
| 43 | else { | |
| 44 | int tmp = *s / 16; | |
| 45 | *r++ = '%'; | |
| 46 | *r++ = (tmp < 10) ? (tmp + '0') : (tmp - 10 + 'A'); | |
| 47 | tmp = *s % 16; | |
| 48 | *r++ = (tmp < 10) ? (tmp + '0') : (tmp - 10 + 'A'); | |
| 49 | } | |
| 50 | } | |
| 51 | ||
| 52 | *r = '\0'; | |
| 53 | ||
| 54 | return ret; | |
| 55 | } | |
| 56 | ||
| 57 | int yahoo_makeint(guchar *buf) | |
| 58 | { | |
| 59 | return ((buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0]); | |
| 60 | } | |
| 61 | ||
| 62 | void yahoo_storeint(guchar *buf, guint data) | |
| 63 | { | |
| 64 | int i; | |
| 65 | for (i = 0; i < 4; i++) { | |
| 66 | buf[i] = data % 256; | |
| 67 | data >>= 8; | |
| 68 | } | |
| 69 | } |