urlencode all filenames, foldernames, username and password

This commit is contained in:
josch
2015-01-16 08:49:23 +01:00
parent 3bff628066
commit f0a55615ae
11 changed files with 117 additions and 27 deletions

View File

@@ -328,3 +328,39 @@ http_post_file(mfhttp * conn, const char *url, FILE * fh,
retval = data_handler(conn, data);
return retval;
}
// we roll our own urlencode function because curl_easy_escape requires a curl
// handle
char *urlencode(const char *inp)
{
char *buf;
char *bufp;
char hex[] = "0123456789abcdef";
// allocating three times the length of the input because in the worst
// case each character must be urlencoded and add a byte for the
// terminating zero
bufp = buf = (char *)malloc(strlen(inp) * 3 + 1);
if (buf == NULL) {
fprintf(stderr, "malloc failed\n");
return NULL;
}
while (*inp) {
if ((*inp >= '0' && *inp <= '9')
|| (*inp >= 'A' && *inp <= 'Z')
|| (*inp >= 'a' && *inp <= 'z')
|| *inp == '-' || *inp == '_' || *inp == '.' || *inp == '~') {
*bufp++ = *inp;
} else {
*bufp++ = '%';
*bufp++ = hex[(*inp >> 4) & 0xf];
*bufp++ = hex[*inp & 0xf];
}
inp++;
}
*bufp = '\0';
return buf;
}

View File

@@ -46,4 +46,6 @@ int http_post_file(mfhttp * conn, const char *url, FILE * fh,
int (*data_handler) (mfhttp * conn, void *data),
void *data);
char *urlencode(const char *input);
#endif