/* URI decode and copy no more than dst_len bytes to dst. * If src string is larger tnat dst buffer, then only dst_len bytes will * be copied but still whole length will be returned. * So if result >= dst_len, you will need to allocate buffer dynamically and * call uri_decode function again. */ unsigned uri_decode(void *dst, unsigned dst_len, const void *src, unsigned src_len) { char *d = dst, *de = d + dst_len; const char *s = src, *se = s + src_len; while (s < se) { if (d >= de) goto skip_rest; if (*s == '%' && s + 2 < se && isxdigit(s[1]) && isxdigit(s[2])) { *d++ = (xdigit2i(s[1]) << 4) | xdigit2i(s[2]); s += 3; } else { *d++ = *s++; } } return d - (char*)dst; skip_rest: while (s < se) { if (*s == '%' && s + 2 < se && isxdigit(s[1]) && isxdigit(s[2])) { d++; s += 3; } else { d++; s++; } } return d - (char*)dst; }
STATIC cmd_result_t cmd_esw_dma_load(int unit, args_t *a) { void *laddr_v; uint8 *laddr; char *cp; if (cmd_esw_dma_get_laddr(unit, a, &laddr_v) != CMD_OK) { return CMD_USAGE; } laddr = (uint8 *)laddr_v; while ((cp = ARG_GET(a)) != NULL) { while (*cp) { if (isspace((int)(*cp))) { cp++; } else { if (!isxdigit((unsigned)*cp) || !isxdigit((unsigned)*(cp+1))) { printk("%s: Invalid character\n", ARG_CMD(a)); return(CMD_FAIL); } *laddr++ = (xdigit2i(*cp) << 4) | xdigit2i(*(cp + 1)); cp += 2; } } } return CMD_OK; }