60 lines
1.7 KiB
C
60 lines
1.7 KiB
C
#ifndef vger_h_INCLUDED
|
|
#define vger_h_INCLUDED
|
|
|
|
/* length of "gemini://" */
|
|
#define GEMINI_PART 9
|
|
|
|
/*
|
|
* number of bytes to read with fgets() : 2014 + 1.
|
|
* fgets() reads at most size-1 (1024 here).
|
|
* See https://gemini.circumlunar.space/docs/specification.html.
|
|
*/
|
|
#define GEMINI_REQUEST_MAX 1025
|
|
|
|
/* max subexpression in regex : 3 + 1 */
|
|
#define SE_MAX 4
|
|
|
|
/* gemini_regex:
|
|
* =============
|
|
* ^gemini://+ : in case of gemini:///
|
|
* 1: hostname
|
|
* ([^/|^\?|^:]*) :
|
|
* catch everything, stop when /, ? or : is found
|
|
* don't catch :port
|
|
* [:[0-9]*]? : skip :1234 (port number) if any
|
|
* / * : skip "/" if any
|
|
* 2: path
|
|
* ([^\?]*) :
|
|
* catch everything and stop at ? if any
|
|
* 3 : query
|
|
* [\?]?(.*)$:
|
|
* catch everything after ? if any
|
|
*/
|
|
static const char *_gemini_regex =
|
|
"^gemini://+([^/|^\?|^:]*)[:[0-9]*]?/*([^\?]*)[\?]?(.*)$";
|
|
|
|
/* global vars */
|
|
static int _retcode = 0;
|
|
static ssize_t _datasiz = 0;
|
|
static char _request[GEMINI_REQUEST_MAX] = {'\0'};
|
|
|
|
/* functions */
|
|
ssize_t autoindex(const char *);
|
|
void cgi(const char *);
|
|
char * read_request(char *);
|
|
void check_path(char *, size_t, const char *, int);
|
|
ssize_t display_file(const char *);
|
|
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_query(char *, char *, size_t);
|
|
char * set_path(char *, size_t, int, const char *);
|
|
void status(const int, const char *, ...);
|
|
void strip_trailing_slash(char *);
|
|
int uridecode (char *);
|
|
void split_request(const char *, char *, char *, char *);
|
|
void stop(const int, const char *, ...);
|
|
|
|
#endif // vger_h_INCLUDED
|
|
|