-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.c
More file actions
26 lines (25 loc) · 830 Bytes
/
config.c
File metadata and controls
26 lines (25 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "http.h"
#include <stdio.h>
#include <string.h>
int parse_config(const char *filename, ServerConfig *config){
FILE *file = fopen(filename, "r");
if (!file) {
perror("open config");
return -1;
}
config->port = 8080;
strcpy(config->root, "www");
strcpy(config->server_name, "localhost");
config->redirect_code = 0;
config->max_body_size = 1048576;
char row[512];
while(fgets(row, sizeof row, file) != NULL) {
sscanf(row, " listen %d", &config->port);
sscanf(row, " root %255s", config->root);
sscanf(row, " server_name %255s", config->server_name);
sscanf(row, " return %d %511s", &config->redirect_code, config->redirect_url);
sscanf(row, " max_body_size %d", &config->max_body_size);
}
fclose(file);
return 0;
}