implemented server-side config
This commit is contained in:
parent
c57cc6f068
commit
9e95b283a4
@ -20,6 +20,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <curl/curl.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)
|
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();
|
CURL *curl = curl_easy_init();
|
||||||
FILE *file_buffer = why2_fopen(path, "w+");
|
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_WRITEDATA, file_buffer);
|
||||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT);
|
curl_easy_setopt(curl, CURLOPT_TIMEOUT, WHY2_CURL_TIMEOUT);
|
||||||
curl_easy_perform(curl);
|
curl_easy_perform(curl);
|
||||||
@ -45,6 +51,7 @@ void why2_chat_init_config(void)
|
|||||||
//CLEANUP
|
//CLEANUP
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
why2_deallocate(path);
|
why2_deallocate(path);
|
||||||
|
why2_deallocate(config_dir);
|
||||||
why2_deallocate(file_buffer);
|
why2_deallocate(file_buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user