mirror of
https://github.com/sigmasternchen/CFloor
synced 2025-03-15 04:18:55 +00:00
I already did that.
This commit is contained in:
parent
06c7667a0f
commit
428eec9e61
18 changed files with 201 additions and 0 deletions
25
Makefile
Normal file
25
Makefile
Normal file
|
@ -0,0 +1,25 @@
|
|||
CC = gcc
|
||||
CFLAGS = -Wall -Wpedantic
|
||||
LD = gcc
|
||||
LDFLAGS =
|
||||
|
||||
BIN_NAME = cfloor
|
||||
|
||||
all: $(BIN_NAME)
|
||||
|
||||
test: obj/test.o obj/networking.o
|
||||
$(LD) -o $@ $^
|
||||
|
||||
obj/networking.o: src/networking.h src/headers.h
|
||||
|
||||
obj/%.o: src/%.c obj
|
||||
$(CC) -c -o $@ $<
|
||||
|
||||
obj:
|
||||
@mkdir -p obj
|
||||
|
||||
clean:
|
||||
@echo "Cleaning up..."
|
||||
@rm -f obj/*.o
|
||||
@rm -f test
|
||||
@rm -f $(BIN_NAME)
|
0
src/auth.c
Normal file
0
src/auth.c
Normal file
0
src/auth.h
Normal file
0
src/auth.h
Normal file
0
src/cgi.c
Normal file
0
src/cgi.c
Normal file
0
src/cgi.h
Normal file
0
src/cgi.h
Normal file
0
src/config.c
Normal file
0
src/config.c
Normal file
0
src/config.h
Normal file
0
src/config.h
Normal file
0
src/files.c
Normal file
0
src/files.c
Normal file
0
src/files.h
Normal file
0
src/files.h
Normal file
0
src/headers.c
Normal file
0
src/headers.c
Normal file
14
src/headers.h
Normal file
14
src/headers.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef HEADERS_H
|
||||
#define HEADERS_H
|
||||
|
||||
struct header {
|
||||
char* key;
|
||||
char* value;
|
||||
};
|
||||
|
||||
struct headers {
|
||||
int number;
|
||||
struct header* headers;
|
||||
};
|
||||
|
||||
#endif
|
0
src/linked.c
Normal file
0
src/linked.c
Normal file
0
src/linked.h
Normal file
0
src/linked.h
Normal file
7
src/main.c
Normal file
7
src/main.c
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
|
||||
|
||||
int main(int argc, char* argv) {
|
||||
|
||||
|
||||
}
|
34
src/misc.h
Normal file
34
src/misc.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
#include "headers.h"
|
||||
|
||||
enum method {
|
||||
GET, POST, PUT
|
||||
};
|
||||
|
||||
enum httpVersion {
|
||||
HTTP10, HTTP11
|
||||
};
|
||||
|
||||
struct metaData {
|
||||
enum method method;
|
||||
enum httpVersion httpVersion;
|
||||
char* path;
|
||||
char* queryString;
|
||||
};
|
||||
|
||||
struct request {
|
||||
struct metaData metaData;
|
||||
struct headers* headers;
|
||||
int fd;
|
||||
void* _private;
|
||||
};
|
||||
|
||||
struct response {
|
||||
int (*sendHeader)(int statusCode, struct headers headers);
|
||||
};
|
||||
|
||||
typedef void (*handler_t)(struct request request, struct response response);
|
||||
|
||||
#endif
|
44
src/networking.c
Normal file
44
src/networking.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "networking.h"
|
||||
|
||||
struct networkingConfig networkingConfig;
|
||||
|
||||
struct connection connections[MAX_CONNECTIONS];
|
||||
|
||||
static inline struct connection emptyConnection() {
|
||||
return (struct connection) {
|
||||
.used = false,
|
||||
.connectionState = CLOSED,
|
||||
.metaData = {
|
||||
.path = NULL,
|
||||
.queryString = NULL
|
||||
},
|
||||
.headers = {
|
||||
.number = 0,
|
||||
.headers = NULL
|
||||
},
|
||||
.currentHeaderLength = 0,
|
||||
.fd = -1,
|
||||
/*
|
||||
* ignored:
|
||||
* .metaData.method
|
||||
* .metaData.httpVersion
|
||||
* .currentHeader
|
||||
* .timing.*
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
void initNetworking(struct networkingConfig _networkingConfig) {
|
||||
networkingConfig = _networkingConfig;
|
||||
|
||||
for (int i = 0; i < MAX_CONNECTIONS; i++) {
|
||||
connections[i] = emptyConnection();
|
||||
}
|
||||
}
|
||||
|
||||
void newConnection() {
|
||||
|
||||
}
|
60
src/networking.h
Normal file
60
src/networking.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
#ifndef NETWORKING_H
|
||||
#define NETWORKING_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "headers.h"
|
||||
#include "misc.h"
|
||||
|
||||
#define MAX_CONNECTIONS (512)
|
||||
|
||||
#define NR_CONNECTION_STATE (6)
|
||||
enum connectionState {
|
||||
ESTABLISHED = 0,
|
||||
HEADERS_COMPLETE = 1,
|
||||
DATA_COMPLETE = 2,
|
||||
PROCESSING = 3,
|
||||
ABORTED = 4,
|
||||
CLOSED = 5,
|
||||
FREED = 6
|
||||
};
|
||||
|
||||
struct timing {
|
||||
struct timeval states[NR_CONNECTION_STATE];
|
||||
struct timeval lastUpdate;
|
||||
};
|
||||
|
||||
struct connection {
|
||||
bool used;
|
||||
enum connectionState connectionState;
|
||||
struct metaData metaData;
|
||||
struct headers headers;
|
||||
size_t currentHeaderLength;
|
||||
char* currentHeader;
|
||||
int fd;
|
||||
struct timing timing;
|
||||
};
|
||||
|
||||
typedef handler_t (*handlerGetter_t)(struct metaData metaData, const char* host);
|
||||
|
||||
struct bind {
|
||||
const char* address;
|
||||
const char* port;
|
||||
};
|
||||
|
||||
struct binds {
|
||||
int number;
|
||||
struct bind* binds;
|
||||
};
|
||||
|
||||
struct networkingConfig {
|
||||
struct binds binds;
|
||||
long connectionTimeout;
|
||||
struct headers defaultResponse;
|
||||
handlerGetter_t getHandler;
|
||||
};
|
||||
|
||||
void initNetworking(struct networkingConfig networkingConfig);
|
||||
|
||||
#endif
|
17
src/test.c
Normal file
17
src/test.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "networking.h"
|
||||
|
||||
handler_t handlerGetter(struct metaData metaData, const char* host) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv) {
|
||||
initNetworking((struct networkingConfig) {
|
||||
.connectionTimeout = 30000,
|
||||
.defaultResponse = {
|
||||
.number = 0
|
||||
},
|
||||
.getHandler = &handlerGetter
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue