implemented server-side config

This commit is contained in:
Václav Šmejkal 2023-08-26 18:12:26 +02:00
parent c57cc6f068
commit 9e95b283a4
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <curl/curl.h>
@ -31,13 +32,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
void why2_chat_init_config(void)
{
if (access(WHY2_CHAT_CONFIG, R_OK) != 0) //CONFIG DOESN'T EXIST
char *path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{USER}", getenv("USER"));
if (access(path, R_OK) != 0) //CONFIG DOESN'T EXIST
{
char *path = why2_replace(WHY2_CHAT_CONFIG, "{USER}", getenv("USER"));
char *config_dir = why2_replace(WHY2_CHAT_CONFIG_DIR, "{USER}", getenv("USER"));
mkdir(config_dir, 0700);
CURL *curl = curl_easy_init();
FILE *file_buffer = why2_fopen(path, "w+");
curl_easy_setopt(curl, CURLOPT_URL, WHY2_CHAT_CONFIG_URL);
curl_easy_setopt(curl, CURLOPT_URL, WHY2_CHAT_CONFIG_SERVER_URL);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file_buffer);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT);
curl_easy_perform(curl);
@ -45,6 +51,7 @@ void why2_chat_init_config(void)
//CLEANUP
curl_easy_cleanup(curl);
why2_deallocate(path);
why2_deallocate(config_dir);
why2_deallocate(file_buffer);
}
}