remove useless functions

This commit is contained in:
prx 2022-08-18 22:23:59 +02:00
parent 875f167eb9
commit 9d23a48ae2
3 changed files with 8 additions and 35 deletions

15
main.c
View File

@ -9,8 +9,6 @@ main(int argc, char **argv)
char path[GEMINI_REQUEST_MAX] = {'\0'};
char query[GEMINI_REQUEST_MAX] = {'\0'};
char chroot_dir[PATH_MAX] = DEFAULT_CHROOT;
char file[FILENAME_MAX] = DEFAULT_INDEX;
char dir[PATH_MAX] = {'\0'};
int option = 0;
int virtualhost = 0;
@ -18,9 +16,7 @@ main(int argc, char **argv)
* request : contain the whole request from client : gemini://...\r\n
* user : username, used in drop_privileges()
* hostname : extracted from hostname. used with virtualhosts and cgi SERVER_NAME
* query : file requested in cgi : gemini://...?query
* file : file basename to display. Emtpy is a directory has been requested
* dir : directory requested. vger will chdir() in to find file
* query : after a ? in cgi : gemini://...?query
*/
while ((option = getopt(argc, argv, ":d:l:m:u:c:vi")) != -1) {
@ -72,15 +68,8 @@ main(int argc, char **argv)
/* check if path available */
check_path(path, sizeof(path), virtualhost, strlen(hostname));
/* split dir and filename */
split_dir_file(path, dir, sizeof(dir), file, sizeof(file));
/* go to dir */
if (*dir)
echdir(dir);
/* regular file to stdout */
display_file(file);
display_file(path);
stop(EXIT_SUCCESS, NULL);
}

27
vger.c
View File

@ -168,23 +168,23 @@ drop_privileges(const char *user, const char *chroot_dir, const char *cgi_dir)
}
ssize_t
display_file(const char *fname)
display_file(const char *path)
{
FILE *fd = NULL;
const char *file_mime;
/*
* special case : fname empty. The user requested just a dir name
* special case : path ends with "/". The user requested a dir
*/
if ((strlen(fname) == 0) && (doautoidx)) {
if ((path[strlen(path)-1] == '/') && (doautoidx)) {
/* no index.gmi, so display autoindex if enabled */
_datasiz += autoindex(".");
_datasiz += autoindex(path);
return _datasiz;
}
/* open the file requested */
if ((fd = fopen(fname, "r")) != NULL) {
file_mime = get_file_mime(fname, default_mime);
if ((fd = fopen(path, "r")) != NULL) {
file_mime = get_file_mime(path, default_mime);
if (strcmp(file_mime, "text/gemini") == 0)
status(20, "%s; %s", file_mime, lang);
else
@ -424,21 +424,6 @@ check_path(char *path, size_t pathsiz, int virtualhost, size_t hstnm_o)
}
}
void
split_dir_file(char *path, char *dir, size_t dirsiz, char *file, size_t filesiz)
{
char *pos = NULL;
pos = strrchr(path, '/');
if (pos != NULL) {
estrlcpy(file, pos+1, filesiz); /* +1 : not heading / */
pos[0] = '\0'; /* stop path at file */
estrlcpy(dir, path, dirsiz);
} else {
estrlcpy(file, path, filesiz);
}
}
void
split_request(const char *request, char *hostname, char *path, char *query)
{

1
vger.h
View File

@ -48,7 +48,6 @@ int do_cgi(const char *, const char *, const char *, const char *, const char *
void drop_privileges(const char *, const char *, const char *);
char * set_path(char *, size_t, int, const char *);
void split_request(const char *, char *, char *, char *);
void split_dir_file(char *, char *, size_t, char *, size_t);
void status(const int, const char *, ...);
void stop(const int, const char *, ...);
int uridecode (char *);