all: common.a
common.a: $(OBJS)
- ar rcs $@ $(OBJS)
+ $(AR) rcs $@ $(OBJS)
.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
char* tmp = result;
result = cm_strcat(tmp, va_arg(args, char*));
free(tmp);
+ } else if(log[i] == 'd') {
+ int a = va_arg(args, int);
+ char buf[128];
+ sprintf(buf, "%d", a);
+ char* tmp = result;
+ result = cm_strcat(tmp, buf);
+ free(tmp);
}
} else {
cbuf[0] = log[i];
char* cm_strdup(const char* str) { return cm_strcat(str, ""); }
-char* cm_trimstart(const char* str){
+char* cm_trimstart(const char* str) {
int i;
- for(i = 0; str[i] != 0; i++){
- if(str[i] != ' ' && str[i] != '\t'){
+ for(i = 0; str[i] != 0; i++) {
+ if(str[i] != ' ' && str[i] != '\t') {
return cm_strdup(str + i);
}
}
return cm_strdup("");
}
-char* cm_trimend(const char* str){
+char* cm_trimend(const char* str) {
char* s = cm_strdup(str);
int i;
- for(i = strlen(s) - 1; i >= 0; i--){
- if(s[i] != '\t' && s[i] != ' '){
+ for(i = strlen(s) - 1; i >= 0; i--) {
+ if(s[i] != '\t' && s[i] != ' ') {
s[i + 1] = 0;
break;
}
return s;
}
-char* cm_trim(const char* str){
+char* cm_trim(const char* str) {
char* tmp = cm_trimstart(str);
char* s = cm_trimend(tmp);
free(tmp);
return s;
}
-char** cm_split(const char* str, const char* by){
+char** cm_split(const char* str, const char* by) {
int i;
char** r = malloc(sizeof(*r));
r[0] = NULL;
cbuf[1] = 0;
bool dq = false;
bool sq = false;
- for(i = 0;; i++){
+ for(i = 0;; i++) {
int j;
bool has = false;
- for(j = 0; by[j] != 0; j++){
- if(by[j] == str[i]){
+ for(j = 0; by[j] != 0; j++) {
+ if(by[j] == str[i]) {
has = true;
break;
}
}
- if(!(dq || sq) && (has || str[i] == 0)){
- if(strlen(b) > 0){
+ if(!(dq || sq) && (has || str[i] == 0)) {
+ if(strlen(b) > 0) {
char** old = r;
int j;
- for(j = 0; old[j] != NULL; j++);
+ for(j = 0; old[j] != NULL; j++)
+ ;
r = malloc(sizeof(*r) * (j + 2));
for(j = 0; old[j] != NULL; j++) r[j] = old[j];
r[j] = b;
b = malloc(1);
b[0] = 0;
if(str[i] == 0) break;
- }else{
- if(str[i] == '"' && !sq){
+ } else {
+ if(str[i] == '"' && !sq) {
dq = !dq;
- }else if(str[i] == '\'' && !dq){
+ } else if(str[i] == '\'' && !dq) {
sq = !sq;
- }else{
+ } else {
cbuf[0] = str[i];
char* tmp = b;
b = cm_strcat(tmp, cbuf);
return r;
}
-bool cm_strcaseequ(const char* a, const char* b){
+bool cm_strcaseequ(const char* a, const char* b) {
if(a == NULL) return false;
if(b == NULL) return false;
if(strlen(a) != strlen(b)) return false;
int i;
- for(i = 0; a[i] != 0; i++){
+ for(i = 0; a[i] != 0; i++) {
if(tolower(a[i]) != tolower(b[i])) return false;
}
return true;
$(MAKE) -C $@ $(FLAGS)
format:
- clang-format --verbose -i `find . -name "*.c" -or -name "*.h"`
+ clang-format --verbose -i `find ./Server ./Common -name "*.c" -or -name "*.h"`
clean:
$(MAKE) -C ./Server $(FLAGS) clean
CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common
LDFLAGS =
LIBS =
+EXEC =
--- /dev/null
+# $Id$
+
+CC = x86_64-w64-mingw32-gcc
+AR = x86_64-w64-mingw32-ar
+CFLAGS = -g -std=c99 -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -I $(PWD)/openssl/include
+LDFLAGS = -L $(PWD)/openssl/lib
+LIBS =
+EXEC = .exe
all: tewi$(EXEC)
tewi$(EXEC): $(OBJS) ../Common/common.a
- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) ../Common/common.a
+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) ../Common/common.a -lssl -lcrypto
.c.o:
$(CC) $(CFLAGS) -c -o $@ $<
#include <cm_string.h>
#include <cm_log.h>
-int tw_config_read(const char* path){
+struct tw_config config;
+
+void tw_config_init(void) {}
+
+int tw_config_read(const char* path) {
cm_log("Config", "Reading %s", path);
char cbuf[2];
cbuf[1] = 0;
+ int ln = 0;
FILE* f = fopen(path, "r");
- if(f != NULL){
+ if(f != NULL) {
char* line = malloc(1);
line[0] = 0;
- while(1){
+ int stop = 0;
+ char* vhost = NULL;
+ while(stop == 0) {
int c = fread(cbuf, 1, 1, f);
- if(cbuf[0] == '\n' || c <= 0){
+ if(cbuf[0] == '\n' || c <= 0) {
+ ln++;
char* l = cm_trim(line);
- if(strlen(l) > 0 && l[0] != '#'){
+ if(strlen(l) > 0 && l[0] != '#') {
char** r = cm_split(l, " \t");
int i;
- if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")){
- for(i = 1; r[i] != NULL; i++){
- if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")){
- for(i = 0; r[i] != NULL; i++) free(r[i]);
- free(r);
- free(line);
- free(l);
- fclose(f);
- return 1;
+ if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")) {
+ for(i = 1; r[i] != NULL; i++) {
+ if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")) {
+ stop = 1;
+ break;
+ }
+ }
+ } else if(cm_strcaseequ(r[0], "BeginVirtualHost")) {
+ if(vhost != NULL) {
+ cm_log("Config", "Already in virtual host section");
+ stop = 1;
+ } else {
+ if(r[1] == NULL) {
+ cm_log("Config", "Missing virtual host");
+ stop = 1;
+ } else {
+ vhost = cm_strdup(r[1]);
}
}
+ } else if(cm_strcaseequ(r[0], "EndVirtualHost")) {
+ if(vhost == NULL) {
+ cm_log("Config", "Not in virtual host section");
+ stop = 1;
+ } else {
+ free(vhost);
+ vhost = NULL;
+ }
+ } else {
+ if(r[0] != NULL) {
+ cm_log("Config", "Unknown directive `%s' at line %d", r[0], ln);
+ }
+ stop = 1;
}
for(i = 0; r[i] != NULL; i++) free(r[i]);
free(r);
line = malloc(1);
line[0] = 0;
if(c <= 0) break;
- }else if(cbuf[0] != '\r'){
+ } else if(cbuf[0] != '\r') {
char* tmp = line;
line = cm_strcat(tmp, cbuf);
free(tmp);
}
free(line);
fclose(f);
- return 0;
- }else{
+ return stop;
+ } else {
cm_log("Config", "Could not open the file");
return 1;
}
#include <stdbool.h>
#include <string.h>
+#include <openssl/opensslv.h>
+
#include <cm_log.h>
#include "tw_config.h"
if(strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
if(!cm_do_log) {
cm_do_log = true;
- cm_log("", "This is Tewi HTTPd, version %s", tw_get_version());
+ cm_log("", "This is Tewi HTTPd, version %s, using %s", tw_get_version(), OPENSSL_VERSION_TEXT);
} else {
cm_do_log = true;
}
- } else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0){
+ } else if(strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-C") == 0) {
i++;
- if(argv[i] == NULL){
+ if(argv[i] == NULL) {
fprintf(stderr, "Missing argument\n");
return 1;
}
}
}
}
- if(tw_config_read(config) != 0){
+ tw_config_init();
+ if(tw_config_read(config) != 0) {
fprintf(stderr, "Could not read the config\n");
return 1;
}
#ifndef __TW_CONFIG_H__
#define __TW_CONFIG_H__
+struct tw_config_entry {};
+
+struct tw_config {
+ struct tw_config_entry root;
+};
+
+void tw_config_init(void);
int tw_config_read(const char* path);
#endif