I have made a start

I have done some work on opening a socket and waiting for a connection.
This can be read line by line and I have started a request struct that
it will accept.

Also started on some docs. Not much is yet working. I am going to start
learning µnit for unit tests:

https://nemequ.github.io/munit/
This commit is contained in:
Jonathan Hodgson 2021-12-27 21:43:11 +00:00
parent 4e17e706fa
commit f48a110429
15 changed files with 599 additions and 1 deletions

64
src/config.c Normal file
View file

@ -0,0 +1,64 @@
#include "config.h"
/*
* Checks if the given path exists by calling stat().
*
*/
static bool path_exists(const char *path) {
struct stat buf;
return (stat(path, &buf) == 0);
}
/*
* This function resolves ~ in pathnames.
*/
static char* resolveTilde(const char *path) {
static glob_t globbuf;
int res = glob(path, GLOB_TILDE, NULL, &globbuf);
/* no match, or many wildcard matches are bad */
if (res == GLOB_NOMATCH)
return strdup(path);
else if (res != 0) {
printf("glob() failed\n");
return NULL;
} else {
return strdup(globbuf.gl_pathv[0]);
}
globfree(&globbuf);
}
/*
* Returns a pointer to a config object containing defaults
*/
Config* configDefaults(){
Config *conf = malloc( sizeof( Config ) );
conf->database = "proxy.sqlite";
conf->port = 8080;
conf->localConfig = "proxy.conf";
conf->userConfig = getDefaultUserConfigLoc();
return conf;
}
char* getConfigDir(){
char *xdg_config_home;
if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL)
xdg_config_home = resolveTilde("~/.config");
return xdg_config_home;
}
char* getDefaultUserConfigLoc(){
char *configDir = getConfigDir();
char *configFile[strlen(configDir) + 11];
memset(configFile, '\0', strlen(configDir) + 11);
strcpy( configFile, configDir );
strcat( configFile, configDir );
return configFile;
}