summaryrefslogtreecommitdiff
path: root/src/fileserv.h
blob: cf72b39a6ea726c1ef6942e3cc6e5c346d6e2d86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* This file is part of fileserv.
   Copyright (C) 2017-2018 Sergey Poznyakoff

   Fileserv is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   Fileserv is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with fileserv.  If not, see <http://www.gnu.org/licenses/>. */
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdarg.h>
#include <regex.h>
#include <sys/queue.h>

#ifndef SIZE_T_MAX
# define SIZE_T_MAX ((size_t)-1)
#endif

extern char const *progname;
extern char *config_file;
extern char *pidfile;
extern char *index_css;
extern char *tmpdir;
extern char *forwarded_header;
extern char *mime_types_file;
extern char *user;
extern char *group;
extern char *address;
extern char *index_css;
extern int verbose;

void error(char const *fmt, ...);
void info(char const *fmt, ...);
void syslog_enable(void);
int set_log_facility(char const *arg);

void fileserv_logger(void *arg, const char *fmt, va_list ap);

void xmalloc_fail(void);
void *xmalloc(size_t s);
void *xcalloc(size_t nmemb, size_t size);
void *xrealloc(void *ptr, size_t size);
void *xnrealloc(void *ptr, size_t nmemb, size_t size);
char *xstrdup(char const *str);

void runas(char const *runas_user, char const *runas_group);

#if HAVE_LIBWRAP
int fileserv_acl(void *cls, const struct sockaddr *addr, socklen_t addrlen);
#else
# define fileserv_acl NULL
#endif

void pidfile_remove(void);
void pidfile_create(void);
void pidfile_check(void);

void urimap_add(char *arg);

typedef struct fileserv_config {
	int follow:1;            /* Follow symbolic links */
	int listing:1;           /* Show directory listing, if a directory
				    is requested and no index file exists */
	int list_unreadable:1;   /* List unreadable files */
	
	char **index_files_v;    /* Names of index files */
	size_t index_files_c;    /* Number of index files */
	size_t index_files_n;    /* Index of the first allocated index file */
	
	regex_t *hidden_files_rxv;
	size_t hidden_files_rxc;
	size_t hidden_files_rxn;
} CONFIG;

enum {
	CTXNONE = 0,
	CTXGLOB = 0x01,
	CTXDIR  = 0x02
};

void readconfig(void);

CONFIG *dirconfig(char const *path, size_t prefix_len);
int config_parse(const char *file, CONFIG *conf, int ctx);
CONFIG *config_init(void);
CONFIG *config_clone(CONFIG const *source);
void config_free(CONFIG *conf);

char *catfile_n(char const *dir, size_t len, char const *file);
char *catfile(char const *dir, char const *file);

typedef enum {
	ISC_NAME,
	ISC_TIME,
	ISC_SIZE,
	ISC_DESC
} INDEX_SORT_COL;

typedef enum {
	ISO_ASC,
	ISO_DESC
} INDEX_SORT_ORD;

int directory_index(int fd,
		    CONFIG const *conf, char const *uri, char const *path,
		    INDEX_SORT_COL col, INDEX_SORT_ORD ord);

INDEX_SORT_COL index_sort_col_from_arg(int c);
int index_sort_col_to_arg(INDEX_SORT_COL c);
INDEX_SORT_ORD index_sort_ord_from_arg(int c);
int index_sort_ord_to_arg(INDEX_SORT_ORD c);

int filename_is_special(char const *name);
int filename_is_hidden(char const *name, CONFIG const *conf);
int filename_is_valid(char const *name);

int parse_template_string(char const *str);
int parse_template_file(char const *file_name);

void trusted_ip_add(char const *s);
struct MHD_Connection;
char *get_remote_ip(struct MHD_Connection *conn);

typedef struct icon {
	char *name;
	char *src;
	char *alt;
	TAILQ_ENTRY(icon) link;
} ICON;

ICON const *icon_by_mime(char const *type);
void add_icon_by_mime(char const *type, char const *src, char const *alt);
ICON const *icon_by_name(char const *name);
void add_icon_by_name(char const *name, char const *src, char const *alt);
ICON const *icon_by_type(char const *type);
void add_icon_by_type(char const *name, char const *src, char const *alt);

Return to:

Send suggestions and report system problems to the System administrator.