Starts work on https as well as some moving about
I now start the listener in the main.c file rather than proxy given that I didn't feel proxy was the right place if a normal (non-proxied) request came in. webserver.{c,h} and proxy.{c,h} had some changes relating to this. The config changed slightly - we now create a folder in ~/.config/ called yaip. This is where certificates and so on will be stored along with the user configuration I created a helper function to get files inside this directory (it changes based on xdg_config_home) and updated relevant tests. In ssl.{c,h} I have started work. If they don't exist, the tool now creates and stores a key and certificate for the CA that this tool will need to pretend to be. I still need to write tests for this.
This commit is contained in:
parent
6eaad263be
commit
bb62ed3b1f
14 changed files with 366 additions and 100 deletions
37
src/config.c
37
src/config.c
|
@ -34,35 +34,50 @@ char* resolveTilde(const char *path) {
|
|||
*/
|
||||
Config* configDefaults(){
|
||||
Config *conf = malloc( sizeof( Config ) );
|
||||
conf->database = "proxy.sqlite";
|
||||
conf->database = strdup("proxy.sqlite");
|
||||
conf->port = 8080;
|
||||
conf->localConfig = "proxy.conf";
|
||||
conf->userConfig = getDefaultUserConfigLoc();
|
||||
conf->localConfig = strdup("proxy.conf");
|
||||
conf->userConfig = getUserConfigFile("proxy.conf");
|
||||
conf->certfile = getUserConfigFile("cert.pem");
|
||||
conf->keyfile = getUserConfigFile("key.pem");
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
void maybeMakeDir(const char *path){
|
||||
if ( path_exists( path ) ) return;
|
||||
mkdir( path, 0700 );
|
||||
}
|
||||
|
||||
char* getConfigDir(){
|
||||
char *xdg_config_home;
|
||||
if ((xdg_config_home = getenv("XDG_CONFIG_HOME")) == NULL)
|
||||
xdg_config_home = resolveTilde("~/.config");
|
||||
|
||||
char configDir[strlen(xdg_config_home) + 6];
|
||||
memset(configDir, '\0', strlen(xdg_config_home) + 6);
|
||||
|
||||
return xdg_config_home;
|
||||
sprintf( configDir, "%s/yaip", xdg_config_home );
|
||||
|
||||
return strdup(configDir);
|
||||
}
|
||||
|
||||
char* getDefaultUserConfigLoc(){
|
||||
char* getUserConfigFile(char *filename){
|
||||
//This doesn't end in a slash
|
||||
char *configDir = getConfigDir();
|
||||
char configFile[strlen(configDir) + 11];
|
||||
//Make sure our filename doesn't start with a slash
|
||||
while ( filename[0] == '/' ) filename++;
|
||||
// Allocate space for both parts, a slash and a \0
|
||||
char retFile[strlen(configDir) + strlen(filename) + 2];
|
||||
|
||||
memset(configFile, '\0', strlen(configDir) + 11);
|
||||
memset(retFile, '\0', strlen(configDir) + strlen(filename) + 2);
|
||||
|
||||
strcpy( configFile, configDir );
|
||||
sprintf(retFile, "%s/%s", configDir, filename);
|
||||
|
||||
strcat( configFile, "/proxy.conf" );
|
||||
|
||||
return strdup(configFile);
|
||||
return strdup(retFile);
|
||||
}
|
||||
|
||||
|
||||
void setConfig(Config *config, char option[], char value[]){
|
||||
if ( strcmp( option, "database" ) == 0 ){
|
||||
config->database = value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue