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 path[GEMINI_REQUEST_MAX] = {'\0'};
char query[GEMINI_REQUEST_MAX] = {'\0'}; char query[GEMINI_REQUEST_MAX] = {'\0'};
char chroot_dir[PATH_MAX] = DEFAULT_CHROOT; char chroot_dir[PATH_MAX] = DEFAULT_CHROOT;
char file[FILENAME_MAX] = DEFAULT_INDEX;
char dir[PATH_MAX] = {'\0'};
int option = 0; int option = 0;
int virtualhost = 0; int virtualhost = 0;
@ -18,9 +16,7 @@ main(int argc, char **argv)
* request : contain the whole request from client : gemini://...\r\n * request : contain the whole request from client : gemini://...\r\n
* user : username, used in drop_privileges() * user : username, used in drop_privileges()
* hostname : extracted from hostname. used with virtualhosts and cgi SERVER_NAME * hostname : extracted from hostname. used with virtualhosts and cgi SERVER_NAME
* query : file requested in cgi : gemini://...?query * query : after a ? 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
*/ */
while ((option = getopt(argc, argv, ":d:l:m:u:c:vi")) != -1) { 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 if path available */
check_path(path, sizeof(path), virtualhost, strlen(hostname)); 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 */ /* regular file to stdout */
display_file(file); display_file(path);
stop(EXIT_SUCCESS, NULL); 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 ssize_t
display_file(const char *fname) display_file(const char *path)
{ {
FILE *fd = NULL; FILE *fd = NULL;
const char *file_mime; 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 */ /* no index.gmi, so display autoindex if enabled */
_datasiz += autoindex("."); _datasiz += autoindex(path);
return _datasiz; return _datasiz;
} }
/* open the file requested */ /* open the file requested */
if ((fd = fopen(fname, "r")) != NULL) { if ((fd = fopen(path, "r")) != NULL) {
file_mime = get_file_mime(fname, default_mime); file_mime = get_file_mime(path, default_mime);
if (strcmp(file_mime, "text/gemini") == 0) if (strcmp(file_mime, "text/gemini") == 0)
status(20, "%s; %s", file_mime, lang); status(20, "%s; %s", file_mime, lang);
else 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 void
split_request(const char *request, char *hostname, char *path, char *query) 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 *); void drop_privileges(const char *, const char *, const char *);
char * set_path(char *, size_t, int, const char *); char * set_path(char *, size_t, int, const char *);
void split_request(const char *, char *, char *, 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 status(const int, const char *, ...);
void stop(const int, const char *, ...); void stop(const int, const char *, ...);
int uridecode (char *); int uridecode (char *);