58d0f44e03
The function http_send_response() did too much. It not only took the request fields and built them together into a response, it delegated too little and many functions were "hacked" into it, for instance shady directory-changes for vhosts and hand-construction of response structs. The preparations for a rework were already made in previous commits, including a tighter focus on the response-struct itself. Instead of doing everything locally in the http_send_response() function, the new http_prepare_response() only really takes the request-struct and builds a response-struct. The response-struct is expanded such that it's possible to do the data-sending simply with the response-struct itself and not any other magic parameters that just drop out of the function. Another matter are the http_send_status()-calls. Because the aforementioned function is so central, this refactoring has included many areas. Instead of calling http_send_status() in every error-case, which makes little sense now given we first delegate everything through a response struct, errors are just sent as a return value and caught centrally (in serve() in main.c), which centralizes the error handling a bit. It might look a bit strange now and it might not be clear in which direction this is going, but subsequent commits will hopefully give clarity in this regard. Signed-off-by: Laslo Hunhold <dev@frign.de>
60 lines
1.1 KiB
C
60 lines
1.1 KiB
C
/* See LICENSE file for copyright and license details. */
|
|
#ifndef UTIL_H
|
|
#define UTIL_H
|
|
|
|
#include <regex.h>
|
|
#include <stddef.h>
|
|
#include <time.h>
|
|
|
|
#include "arg.h"
|
|
|
|
/* main server struct */
|
|
struct vhost {
|
|
char *chost;
|
|
char *regex;
|
|
char *dir;
|
|
char *prefix;
|
|
regex_t re;
|
|
};
|
|
|
|
struct map {
|
|
char *chost;
|
|
char *from;
|
|
char *to;
|
|
};
|
|
|
|
struct server {
|
|
char *host;
|
|
char *port;
|
|
char *docindex;
|
|
int listdirs;
|
|
struct vhost *vhost;
|
|
size_t vhost_len;
|
|
struct map *map;
|
|
size_t map_len;
|
|
};
|
|
|
|
#undef MIN
|
|
#define MIN(x,y) ((x) < (y) ? (x) : (y))
|
|
#undef MAX
|
|
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
|
#undef LEN
|
|
#define LEN(x) (sizeof (x) / sizeof *(x))
|
|
|
|
extern char *argv0;
|
|
|
|
void warn(const char *, ...);
|
|
void die(const char *, ...);
|
|
|
|
void epledge(const char *, const char *);
|
|
void eunveil(const char *, const char *);
|
|
|
|
int timestamp(char *, size_t, time_t);
|
|
int esnprintf(char *, size_t, const char *, ...);
|
|
int prepend(char *, size_t, const char *);
|
|
void html_escape(const char *, char *, size_t);
|
|
|
|
void *reallocarray(void *, size_t, size_t);
|
|
long long strtonum(const char *, long long, long long, const char **);
|
|
|
|
#endif /* UTIL_H */
|