ServerController/ServerController.c
2025-05-28 19:48:23 -04:00

54 lines
983 B
C

#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <microhttpd.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <signal.h>
#include <stdlib.h>
#define CONFIG "config.cfg"
#define SECRETS ".secrets"
const int PORT;
void sigintHandler(int signal){
printf("Handled sigint\n");
exit(0);
}
void error(char *msg){
write(0, msg, strlen(msg));
exit(1);
}
void readConfig(){
FILE *file = fopen("config.cfg", "r");
char buf[1024];
while (fgets(buf, 1024, file) != NULL){
printf("Line: \n%s\n", buf);
char *newbuf = calloc(1024, 1);
for (int i = 0; i < 1024; i++){
if (buf[i] == '#') break;
else newbuf[i] = buf[i];
}
printf("Newbuf: %s\n", newbuf);
char buf1[512];
char buf2[512];
if (sscanf(newbuf, "%s %s", buf1, buf2) == 2){
printf("Values: %s %s\n", buf1, buf2);
}
free(newbuf);
}
}
int main(){
signal(SIGINT, sigintHandler);
readConfig();
return 0;
}