diff options
author | nirav <nirav@teisuu.com> | 2019-03-21 16:34:24 +0530 |
---|---|---|
committer | Dandelion <nirav@teisuu.com> | 2019-03-21 16:50:20 +0530 |
commit | 4b27c1a348d8de036dabd5525452f5b9ad08a32b (patch) | |
tree | f70c35351dc357d4297f985607fce9221ced96f0 /src/config.c | |
parent | c608bcc3dfab2abe7b66c10f8556086b2d45b3a3 (diff) | |
download | ap_client-4b27c1a348d8de036dabd5525452f5b9ad08a32b.tar.gz ap_client-4b27c1a348d8de036dabd5525452f5b9ad08a32b.zip |
Use g_threads, add builder ui for timeline
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 46 |
1 files changed, 42 insertions, 4 deletions
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; } |