Compare commits
3 Commits
f701eab688
...
9dbc44410d
Author | SHA1 | Date |
---|---|---|
EyitopeIO | 9dbc44410d | |
EyitopeIO | 27ecec60db | |
Fufu Fang | d6d4af0c8c |
|
@ -49,12 +49,12 @@ HTTPDirFS is available in the
|
|||
### Ubuntu
|
||||
Under Ubuntu 22.04 LTS, you need the following packages:
|
||||
|
||||
libgumbo-dev libfuse-dev libssl-dev libcurl4-openssl-dev uuid-dev help2man
|
||||
libgumbo-dev libfuse-dev libssl-dev libcurl4-openssl-dev uuid-dev help2man libexpat1-dev pkg-config
|
||||
|
||||
### Debian 12 "Bookworm"
|
||||
Under Debian 12 "Bookworm" and newer versions, you need the following packages:
|
||||
|
||||
libgumbo-dev libfuse-dev libssl-dev libcurl4-openssl-dev uuid-dev help2man
|
||||
libgumbo-dev libfuse-dev libssl-dev libcurl4-openssl-dev uuid-dev help2man libexpat1-dev pkg-config
|
||||
|
||||
### FreeBSD
|
||||
The following dependencies are required from either pkg or ports:
|
||||
|
|
|
@ -78,7 +78,7 @@ static CURL *Link_to_curl(Link *link)
|
|||
lprintf(error, "%s", curl_easy_strerror(ret));
|
||||
}
|
||||
|
||||
char *escaped_spaces = escape_char(link->f_url, ESCAPED_CHAR_SPACE);
|
||||
char *escaped_spaces = escape_spaces(link->f_url);
|
||||
ret = curl_easy_setopt(curl, CURLOPT_URL,
|
||||
escaped_spaces ? escaped_spaces : link->f_url);
|
||||
if (ret) {
|
||||
|
|
54
src/util.c
54
src/util.c
|
@ -49,55 +49,41 @@ char *path_append(const char *path, const char *filename)
|
|||
return str;
|
||||
}
|
||||
|
||||
char *escape_char(const char *url, const ESCAPE_CHAR c)
|
||||
char *escape_spaces(const char *path)
|
||||
{
|
||||
char escape_me;
|
||||
char space = ' ';
|
||||
|
||||
/* A space, for example, becomes thrice bigger as '%20' after escaping */
|
||||
int how_bigger = 3;
|
||||
|
||||
switch (c) {
|
||||
case ESCAPED_CHAR_SPACE:
|
||||
escape_me = ' ';
|
||||
break;
|
||||
default:
|
||||
lprintf(error, "unknown character to escape: %d\n", c);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!strchr(url, escape_me)) {
|
||||
if (!strchr(path, space)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int len = strnlen(url, MAX_PATH_LEN);
|
||||
|
||||
/* Best case scenario of only one character to escape */
|
||||
if (len + 3 > MAX_PATH_LEN) {
|
||||
lprintf(fatal, "URL too long: %s\n", url);
|
||||
int len = strnlen(path, MAX_PATH_LEN);
|
||||
/* Best case scenario of only one character to escape and
|
||||
* <escaped path array>[MAX_PATH_LEN - 1] is '\0'
|
||||
*/
|
||||
if (len + 3 >= MAX_PATH_LEN - 1) {
|
||||
lprintf(fatal, "path too long: %s\n", path);
|
||||
}
|
||||
|
||||
int replacement_len = 3;
|
||||
const char* replacement = "%20";
|
||||
|
||||
char *escaped = CALLOC(MAX_PATH_LEN, sizeof(char));
|
||||
|
||||
int j = 0, k = 0;
|
||||
int j = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
/* Precaution against writing beyond the buffer, since we do not count
|
||||
* all spaces beforehand to know the exact amount of memory to calloc
|
||||
* for the escaped URL.
|
||||
* for the escaped path.
|
||||
*/
|
||||
if (k > MAX_PATH_LEN) {
|
||||
lprintf(fatal, "URL too long: %s\n", url);
|
||||
if (j >= MAX_PATH_LEN - 1) {
|
||||
lprintf(fatal, "path too long: %s\n", path);
|
||||
}
|
||||
if (url[i] == escape_me) {
|
||||
switch (c) {
|
||||
case ESCAPED_CHAR_SPACE:
|
||||
strncpy(escaped + j, "%20", how_bigger);
|
||||
break;
|
||||
}
|
||||
k = j + how_bigger;
|
||||
j = k;
|
||||
|
||||
if (path[i] == space) {
|
||||
mempcpy(escaped + j, replacement, replacement_len);
|
||||
j += replacement_len;
|
||||
} else {
|
||||
escaped[j++] = url[i];
|
||||
escaped[j++] = path[i];
|
||||
}
|
||||
}
|
||||
return escaped;
|
||||
|
|
17
src/util.h
17
src/util.h
|
@ -9,13 +9,6 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/**
|
||||
* \brief URL characters that can be escaped
|
||||
*/
|
||||
typedef enum {
|
||||
ESCAPED_CHAR_SPACE,
|
||||
} ESCAPE_CHAR;
|
||||
|
||||
/**
|
||||
* \brief append a path
|
||||
* \details This function appends a path with the next level, while taking the
|
||||
|
@ -25,14 +18,12 @@ typedef enum {
|
|||
char *path_append(const char *path, const char *filename);
|
||||
|
||||
/**
|
||||
* \brief escape a single character in a URL
|
||||
* \details This function escapes a character a URL and returns a pointer to
|
||||
* the string with the escaped character. We don't use curl_easy_escape() on
|
||||
* the entire URL because it would break the URL. For example, 'http://a c'
|
||||
* becomes 'http:%2F%2Fa%20c', escaping more characters than we want.
|
||||
* \brief escapes the space character in a path/URL
|
||||
* \details This function escapes the space character in a path, and
|
||||
* returns a pointer to the escaped path.
|
||||
* \note You need to free the char * after use.
|
||||
*/
|
||||
char *escape_char(const char *s, ESCAPE_CHAR c);
|
||||
char *escape_spaces(const char *path);
|
||||
|
||||
/**
|
||||
* \brief division, but rounded to the nearest integer rather than truncating
|
||||
|
|
Loading…
Reference in New Issue