/* Returns a new escaped string or NULL in case of error.  */
char* uri_string_escape(const char *str, const char *list)
/* Returns a new escaped string or NULL in case of error.  */
char* uri_string_escape(const char *str, const char *list)
{
	if (len - out <= 3) {
            temp = realloc2n(ret, &len);
	    ret = temp;
	}
	ch = *in;
	if ((ch != '@') && (!IS_UNRESERVED(ch)) && (!strchr(list, ch))) {
	    unsigned char val;
	    ret[out++] = '%';
	    val = ch >> 4;
	    if (val <= 9)
		ret[out++] = '0' + val;
	    else
		ret[out++] = 'A' + val - 0xA;
	    val = ch & 0xF;
	    if (val <= 9)
		ret[out++] = '0' + val;
	    else
		ret[out++] = 'A' + val - 0xA;
	    in++;
	} else {
	    ret[out++] = *in++;
	}
    }
    ret[out] = 0;
    return(ret);
}