2024-09-13 09:39:33 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifndef __TW_CONFIG_H__
|
|
|
|
#define __TW_CONFIG_H__
|
|
|
|
|
2024-09-14 12:39:39 +00:00
|
|
|
#include "tw_http.h"
|
|
|
|
|
2024-09-13 10:40:53 +00:00
|
|
|
#include <stdint.h>
|
2024-09-14 12:39:39 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
#include <winsock2.h>
|
|
|
|
#define NO_IPV6
|
|
|
|
#else
|
|
|
|
#include <netinet/in.h>
|
2024-09-19 12:40:33 +00:00
|
|
|
#ifdef __HAIKU__
|
|
|
|
#define NO_IPV6
|
|
|
|
#endif
|
2024-09-14 12:39:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NO_IPV6
|
|
|
|
#define SOCKADDR struct sockaddr_in
|
|
|
|
#else
|
|
|
|
#define SOCKADDR struct sockaddr_in6
|
|
|
|
#endif
|
|
|
|
|
2024-09-14 13:25:38 +00:00
|
|
|
#define MAX_PORTS 1024
|
|
|
|
#define MAX_VHOSTS 1024
|
|
|
|
#define MAX_MODULES 1024
|
|
|
|
#define MAX_DIRS 1024
|
|
|
|
#define MAX_MIME 1024
|
|
|
|
#define MAX_ICON 1024
|
2024-09-14 14:09:58 +00:00
|
|
|
#define MAX_INDEX 1024
|
2024-09-16 12:52:47 +00:00
|
|
|
#define MAX_README 8
|
2024-09-13 10:40:53 +00:00
|
|
|
|
2024-09-14 12:39:39 +00:00
|
|
|
enum TW_DIR_TYPE {
|
|
|
|
TW_DIR_ALLOW = 0,
|
|
|
|
TW_DIR_DENY
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tw_dir_entry {
|
|
|
|
char* name;
|
|
|
|
char* dir;
|
|
|
|
int type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tw_mime_entry {
|
|
|
|
char* ext;
|
|
|
|
char* mime;
|
|
|
|
};
|
2024-09-13 13:36:03 +00:00
|
|
|
|
2024-09-14 13:25:38 +00:00
|
|
|
struct tw_icon_entry {
|
|
|
|
char* mime;
|
|
|
|
char* icon;
|
|
|
|
};
|
|
|
|
|
2024-09-13 13:36:03 +00:00
|
|
|
struct tw_config_entry {
|
|
|
|
char* name;
|
|
|
|
int port;
|
|
|
|
char* sslkey;
|
|
|
|
char* sslcert;
|
2024-09-14 00:51:41 +00:00
|
|
|
char* root;
|
2024-09-14 12:39:39 +00:00
|
|
|
struct tw_dir_entry dirs[MAX_DIRS];
|
|
|
|
int dir_count;
|
|
|
|
struct tw_mime_entry mimes[MAX_DIRS];
|
|
|
|
int mime_count;
|
2024-09-14 13:25:38 +00:00
|
|
|
struct tw_icon_entry icons[MAX_DIRS];
|
|
|
|
int icon_count;
|
2024-09-14 14:09:58 +00:00
|
|
|
char* indexes[MAX_INDEX];
|
|
|
|
int index_count;
|
2024-09-16 12:52:47 +00:00
|
|
|
char* readmes[MAX_README];
|
|
|
|
int readme_count;
|
2024-09-13 13:36:03 +00:00
|
|
|
};
|
2024-09-13 10:28:20 +00:00
|
|
|
|
|
|
|
struct tw_config {
|
2024-09-13 10:40:53 +00:00
|
|
|
uint64_t ports[MAX_PORTS + 1]; /* If port & (1 << 32) is non-zero, it is SSL */
|
2024-09-13 13:36:03 +00:00
|
|
|
char hostname[1025];
|
2024-09-13 10:28:20 +00:00
|
|
|
struct tw_config_entry root;
|
2024-09-13 13:36:03 +00:00
|
|
|
struct tw_config_entry vhosts[MAX_VHOSTS];
|
2024-09-14 00:42:40 +00:00
|
|
|
void* modules[MAX_MODULES];
|
|
|
|
int module_count;
|
2024-09-13 13:36:03 +00:00
|
|
|
int vhost_count;
|
2024-09-13 17:41:07 +00:00
|
|
|
char* server_root;
|
2024-09-14 00:42:40 +00:00
|
|
|
char* extension;
|
2024-09-13 10:28:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void tw_config_init(void);
|
2024-09-13 09:39:33 +00:00
|
|
|
int tw_config_read(const char* path);
|
2024-09-13 13:36:03 +00:00
|
|
|
struct tw_config_entry* tw_vhost_match(const char* name, int port);
|
2024-09-14 12:39:39 +00:00
|
|
|
bool tw_permission_allowed(const char* path, SOCKADDR addr, struct tw_http_request req, struct tw_config_entry* vhost);
|
2024-09-13 09:39:33 +00:00
|
|
|
|
|
|
|
#endif
|