(net_http) Refactor

This commit is contained in:
twinaphex 2020-07-05 00:51:41 +02:00
parent 9edd265bf4
commit d5bdec3f60

View File

@ -89,33 +89,27 @@ struct http_connection_t
struct http_socket_state_t sock_state;
};
/* TODO/FIXME - static globals */
static char urlencode_lut[256];
static bool urlencode_lut_inited = false;
void urlencode_lut_init(void)
{
unsigned i;
urlencode_lut_inited = true;
for (i = 0; i < 256; i++)
{
urlencode_lut[i] = isalnum(i) || i == '*' || i == '-' || i == '.' || i == '_' || i == '/' ? i : 0;
}
}
/* URL Encode a string
caller is responsible for deleting the destination buffer */
void net_http_urlencode(char **dest, const char *source)
{
char *enc = NULL;
/* TODO/FIXME - static local globals */
static char urlencode_lut[256];
static bool urlencode_lut_inited = false;
char *enc = NULL;
/* Assume every character will be encoded, so we need 3 times the space. */
size_t len = strlen(source) * 3 + 1;
size_t count = len;
size_t len = strlen(source) * 3 + 1;
size_t count = len;
if (!urlencode_lut_inited)
urlencode_lut_init();
{
unsigned i;
for (i = 0; i < 256; i++)
urlencode_lut[i] = isalnum(i) || i == '*' || i == '-' || i == '.' || i == '_' || i == '/' ? i : 0;
urlencode_lut_inited = true;
}
enc = (char*)calloc(1, len);
*dest = enc;