I have encontered a problem encoding a space ’ ’ char in the function http_contentencode.
I would like to share the solution that i have implemented
in the http.lib i have modified the function as belove:
http_contentencode(char __far *dest, /*const*/char __far *src, int max_dest_len)
{
const static char encodables[] = "<>@%#" ; /* Array of chars we must change */
auto char __far * orig_dest_ptr;
auto char __far * p;
auto int more;
orig_dest_ptr = dest;
--max_dest_len; /* Ensure space for terminating NUL char */
while( max_dest_len > 0 && (*src != '\0') ) {
/* Encoded things are from 'encodables', or non-ASCII-7 chars. */
p = strchr( encodables, *src );
/* Handle '&' specially: */
if( '&' == *src ) {
if( max_dest_len <= 5 ) {
/* ERROR: Not enough space to hold transfer-coded string. */
*dest = '\0';
return NULL;
} else {
_f_strcpy( dest, "&" );
src += 1;
dest += 5;
max_dest_len -= 5;
}
}else if( ' ' == *src ) {
if( max_dest_len <= 3 ) {
/* ERROR: Not enough space to hold transfer-coded string. */
*dest = '\0';
return NULL;
} else {
_f_strcpy( dest, "%20" );
src += 1;
dest += 3;
max_dest_len -= 3;
}
} else
if( NULL == p && (' ' <= *src && *src < '~') ) {
*dest++ = *src++;
max_dest_len--;
} else
if( max_dest_len <= 6 ) {
/* ERROR: Not enough space to hold transfer-coded string. Might need
* 5 chars like "@", or 6 chars "" .
*/
*dest = '\0';
return NULL;
} else {
/* There is room to perform at least one more transfer-coding. */
more = sprintf(dest, "%d;", (unsigned char) *src++);
dest += more;
max_dest_len -= more;
}
}
*dest = '\0';
return( orig_dest_ptr );
} /* end http_contentencode() */