// decode a url string e.g "hello%20joe" or "hello+joe" becomes "hello joe" void EtherCard::urlDecode (char *urlbuf) { char c; char *dst = urlbuf; while ((c = *urlbuf) != 0) { if (c == '+') c = ' '; if (c == '%') { c = *++urlbuf; c = (h2int(c) << 4) | h2int(*++urlbuf); } *dst++ = c; urlbuf++; } *dst = '\0'; }
// decode a url string e.g "hello%20joe" or "hello+joe" becomes "hello joe" void urldecode(char *urlbuf) { char c; char *dst; dst=urlbuf; while ((c = *urlbuf)) { if (c == '+') c = ' '; if (c == '%') { urlbuf++; c = *urlbuf; urlbuf++; c = (h2int(c) << 4) | h2int(*urlbuf); } *dst = c; dst++; urlbuf++; } *dst = '\0'; }
/* * decode_path: decode encoded path name. * * i) path encoded path name * r) decoded path name */ char * decode_path(const unsigned char *path) { STATIC_STRBUF(sb); const unsigned char *p; if (strchr((const char *)path, '%') == NULL) return (char *)path; strbuf_clear(sb); for (p = path; *p; p++) { if (*p == '%') { unsigned char c1, c2; c1 = *++p; c2 = *++p; if (outofrange(c1) || outofrange(c2)) die("decode_path: unexpected character. (%%%c%c)", c1, c2); strbuf_putc(sb, h2int(c1) * 16 + h2int(c2)); } else strbuf_putc(sb, *p); } return strbuf_value(sb); }