From 4b27c1a348d8de036dabd5525452f5b9ad08a32b Mon Sep 17 00:00:00 2001 From: nirav Date: Thu, 21 Mar 2019 16:34:24 +0530 Subject: Use g_threads, add builder ui for timeline --- src/config.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index ca2d48e..211e953 100644 --- a/src/config.c +++ b/src/config.c @@ -18,6 +18,44 @@ struct config _config; const struct config *config = (const struct config *)&_config; +int read_local_credentials() +{ + if (!(config->access_token) || !*(config->access_token) || + !(config->instance_url) || !*(config->instance_url)) { + log_msg(LOG_WARNING, "read_local_credentials", + "access_token not found"); + return -1; + } + return 0; +} + +bool is_logged_in() +{ + if (config->access_token) + return true; + return false; +} + +const char *get_access_token() +{ + return (const char *)config->access_token; +} + +const char *get_instance_url() +{ + return (const char *)config->instance_url; +} + +bool is_registered() +{ + if (!(_config.client_id) || !*(_config.client_id) || + !(_config.client_secret) || !*(_config.client_secret) || + !(_config.instance_url) || !*(_config.instance_url)) { + return false; + } + return true; +} + char *get_config_path() { char *home = getenv("HOME"); @@ -38,7 +76,7 @@ void config_load() char *path = get_config_path(); root = json_load_file(path, 0, &error); if (!root) { - log_msg(LOG_WARNING, "load_config", "json parse error: line %d: %s", + log_msg(LOG_WARNING, "config_load", "json parse error: line %d: %s", error.line, error.text); free(path); return; @@ -46,7 +84,7 @@ void config_load() free(path); if (!json_is_object(root)) { - log_msg(LOG_WARNING, "load_config", "json root is not object"); + log_msg(LOG_WARNING, "config_load", "json root is not object"); json_decref(root); return; } @@ -96,14 +134,14 @@ int config_save() if (stat(dir, &st)) { if (mkdir(dir, S_IRWXU)) { free(config_path); - log_msg(LOG_WARNING, "load_config", "failed to create config dir"); + log_msg(LOG_WARNING, "config_save", "failed to create config dir"); return -1; } } free(config_path); if (json_dump_file(root, get_config_path(), 0)) { - log_msg(LOG_WARNING, "load_config", "unable to save json"); + log_msg(LOG_WARNING, "config_save", "unable to save json"); json_decref(root); return -1; } -- cgit v1.2.3