modify function to set path according to virtualhost

This commit is contained in:
prx 2022-08-18 11:05:21 +02:00
parent b18f3a3c7b
commit e2567fcf01
3 changed files with 8 additions and 14 deletions

2
main.c
View File

@ -58,7 +58,7 @@ main(int argc, char **argv)
read_request(request);
split_request(request, hostname, path, query);
//get_hostname(request, hostname, sizeof(hostname));
//get_path(request, path, sizeof(path), virtualhost, hostname);
set_path(request, path, sizeof(path), virtualhost, hostname);
//get_query(path, query, sizeof(query));
/* percent decode */

18
vger.c
View File

@ -399,24 +399,18 @@ get_hostname(const char *request, char *hstnm, size_t hstnmsiz)
}
char *
get_path(const char *request, char *path, size_t pathsiz, int virtualhost, const char *hostname)
set_path(const char *request, char *path, size_t pathsiz, int virtualhost, const char *hostname)
{
char *pos = NULL;
/* path must be relative to chroot */
estrlcpy(path, "./", pathsiz);
char tmp[GEMINI_REQUEST_MAX] = {'\0'};
/* path is in a subdir named hostname */
if (virtualhost) {
estrlcat(path, hostname, pathsiz);
estrlcat(path, "/", pathsiz);
estrlcpy(tmp, hostname, sizeof(tmp));
estrlcat(tmp, "/", sizeof(tmp));
estrlcat(tmp, path, sizeof(tmp));
estrlcpy(path, tmp, pathsiz);
}
/* path is after hostname/ */
pos = strchr(request, '/');
if (pos != NULL) /* append the path. pos +1 to remove leading '/' */
estrlcat(path, pos+1, pathsiz);
return path;
}

2
vger.h
View File

@ -48,7 +48,7 @@ int do_cgi(const char *, const char *, const char *, const char *, const char *
void drop_privileges(const char *, const char *, const char *);
void split_dir_file(char *, char *, size_t, char *, size_t);
char * get_hostname(const char *, char *, size_t);
char * get_path(const char *, char *, size_t, int, const char *);
char * set_path(const char *, char *, size_t, int, const char *);
char * get_query(char *, char *, size_t);
void status(const int, const char *, ...);
void strip_trailing_slash(char *);