2020-08-25 19:08:23 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#ifndef DIRL_H
|
|
|
|
#define DIRL_H
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "http.h"
|
|
|
|
|
2020-08-27 22:40:04 +00:00
|
|
|
#define DIRL_HEADER ".header.tpl"
|
2020-08-29 18:36:10 +00:00
|
|
|
#define DIRL_ENTRY ".entry.tpl"
|
2020-08-27 22:40:04 +00:00
|
|
|
#define DIRL_FOOTER ".footer.tpl"
|
2020-08-29 18:36:10 +00:00
|
|
|
#define DIRL_STYLE "style.css"
|
2020-08-27 22:40:04 +00:00
|
|
|
|
2020-08-29 18:36:10 +00:00
|
|
|
/* Default template definitions
|
|
|
|
*
|
|
|
|
* Used if no template files can be found
|
|
|
|
*/
|
|
|
|
#define DIRL_HEADER_DEFAULT \
|
|
|
|
"<!DOCTYPE HTML PUBLIC \" - // W3C//DTD HTML 3.2 Final//EN\">\n" \
|
|
|
|
"<html>\n" \
|
|
|
|
" <head>\n" \
|
|
|
|
" <link rel=\"stylesheet\" href=\"/" DIRL_STYLE "\">\n" \
|
2020-08-30 07:38:02 +00:00
|
|
|
" <title>Index of {uri}</title>\n" \
|
2020-08-29 18:36:10 +00:00
|
|
|
" </head>\n" \
|
|
|
|
" <body>\n" \
|
2020-08-30 07:38:02 +00:00
|
|
|
" <h1>Index of {uri}</h1>\n" \
|
2020-08-30 16:07:23 +00:00
|
|
|
" <p><a href=\"..\">↵ Parent Directory</a></p>\n" \
|
|
|
|
" <hr />\n" \
|
|
|
|
" <table>\n" \
|
|
|
|
" <tr><th>Name</th><th>Modified</th><th>Size</th></tr>"
|
2020-08-29 18:36:10 +00:00
|
|
|
|
|
|
|
#define DIRL_ENTRY_DEFAULT \
|
2020-08-30 16:07:23 +00:00
|
|
|
" <tr>\n" \
|
|
|
|
" <td><a href=\"{entry}\">{entry}{suffix}</a>\n" \
|
|
|
|
" <td>{modified}</td>\n" \
|
|
|
|
" <td>{size}</td>\n" \
|
|
|
|
" </tr>\n"
|
2020-08-29 18:36:10 +00:00
|
|
|
|
|
|
|
#define DIRL_FOOTER_DEFAULT \
|
2020-08-30 16:07:23 +00:00
|
|
|
" </table>\n" \
|
|
|
|
" <hr />\n" \
|
|
|
|
" <p>" \
|
|
|
|
"Served by" \
|
|
|
|
" <a href=\"http://tools.suckless.org/quark/\">quark</a>" \
|
|
|
|
" and" \
|
|
|
|
" <a href=" \
|
|
|
|
"\"https://git.friedl.net/playground/suckless-quark/src/branch/dirlist\">" \
|
|
|
|
"dirl" \
|
|
|
|
"</a>" \
|
|
|
|
"</p>\n" \
|
|
|
|
"</body>\n" \
|
2020-08-29 18:36:10 +00:00
|
|
|
"</html>"
|
2020-08-25 19:08:23 +00:00
|
|
|
|
2020-08-29 18:36:10 +00:00
|
|
|
struct dirl_templ
|
|
|
|
{
|
2020-08-30 06:43:10 +00:00
|
|
|
char* header;
|
|
|
|
char* entry;
|
|
|
|
char* footer;
|
2020-08-25 19:08:23 +00:00
|
|
|
};
|
|
|
|
|
2020-08-29 18:36:10 +00:00
|
|
|
struct dirl_templ
|
|
|
|
dirl_read_templ(const char* path);
|
|
|
|
|
|
|
|
/* Determine if an dirlist entry should be skipped
|
|
|
|
*
|
|
|
|
* Skips:
|
|
|
|
* - hidden files and directories
|
|
|
|
* - special directory entries (., ..)
|
|
|
|
* - header template: DIRL_HEADER
|
|
|
|
* - entry template: DIRL_ENTRY
|
|
|
|
* - footer template: DIRL_FOOTER
|
|
|
|
* - dirlist style: DRIL_STYLE
|
2020-08-25 19:08:23 +00:00
|
|
|
*/
|
2020-08-29 18:36:10 +00:00
|
|
|
int
|
|
|
|
dirl_skip(const char*);
|
|
|
|
|
|
|
|
/* Print header into the response */
|
|
|
|
enum status
|
|
|
|
dirl_header(int, const struct response*, const struct dirl_templ*);
|
|
|
|
|
|
|
|
/* Print entry into the response */
|
|
|
|
enum status
|
2020-08-31 04:42:23 +00:00
|
|
|
dirl_entry(int, const struct dirent*, const struct response*, const struct dirl_templ*);
|
2020-08-27 22:40:04 +00:00
|
|
|
|
2020-08-29 18:36:10 +00:00
|
|
|
/* Print footer into the response */
|
|
|
|
enum status
|
|
|
|
dirl_footer(int, const struct dirl_templ*);
|
2020-08-25 19:08:23 +00:00
|
|
|
|
|
|
|
#endif /* DIRL_H */
|