| iMatix home page | << | < | > | >> |
![]() Version 1.91 |
#include "sflhttp.h" char * http_unescape ( char *string, char *result)
Removes HTTP escaping from a string. See http escape() for details of the escaping algorithm. If the result string is NULL, modifies the source string in place, else fills-in the result string. Returns the resulting string. End-of-line sequences (%0A%0D) are stored as a single new-line character, i.e. carriage-returns (%0D) are not stored.
{ /* This lookup table gives us a quick way to convert a hex digit */ /* into a binary value. Note that the index must be [0..127]. */ static char hex_to_bin [128] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0..9 */ 0,10,11,12,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A..F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* */ 0,10,11,12,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* a..f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; /* */ char *target; /* Where we store the result */ ASSERT (string); if (!result) /* If result string is null, */ result = string; /* modify in place */ target = result; while (*string) { if (*string == '%') /* Unescape %xx sequence */ { *target = hex_to_bin [string [1] & 127] * 16 + hex_to_bin [string [2] & 127]; string += 2; /* Bump past two hex digits */ if (*target != '\r') target++; /* We do not store CRs */ } else if (*string == '+') /* Spaces are escaped as '+' */ *target++ = ' '; else *target++ = *string; /* Otherwise just copy */ string++; } *target = '\0'; /* Terminate target string */ return (result); }
| << | < | > | >> |
![]() |