Yet Another Intercepting Proxy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

64 lines
1.3 KiB

#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;
}