From 49c9aed7e4eb425d6e2348f36390e97186f1591d Mon Sep 17 00:00:00 2001 From: lakinduakash Date: Sun, 14 Apr 2019 00:50:13 +0530 Subject: [PATCH] Create and Read SSID and PASSPHARE to cinfig file and init getters and setters --- src/ui/h_prop.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++-- src/ui/h_prop.h | 7 +++- 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/ui/h_prop.c b/src/ui/h_prop.c index 542bb26..3f4b5ea 100644 --- a/src/ui/h_prop.c +++ b/src/ui/h_prop.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "h_prop.h" @@ -11,14 +12,16 @@ #define BUFSIZE 1024 -#define SUDO "sudo" +#define SUDO "pkexec --user root" #define CREATE_AP "create_ap" + char cmd[BUFSIZE]; -const char* SSID; -const char* PASS; +const char* g_ssid=NULL; +const char* g_pass=NULL; +config_t cfg; static int parse_output(char *cmd) { @@ -55,6 +58,99 @@ char *build_command(char *iface_src, char *iface_dest, char *ssid, char *pass) { int startShell(char *cmd) { parse_output(cmd); + return 0; } +int create_config(char* file){ + + config_t cfg; + config_setting_t *root, *setting, *group, *array; + int i; + + config_init(&cfg); + root = config_root_setting(&cfg); + + /* Add some settings to the configuration. */ + + + setting = config_setting_add(root, SSID, CONFIG_TYPE_STRING); + config_setting_set_string(setting, "myssid"); + + setting = config_setting_add(root, PASSPHRASE, CONFIG_TYPE_STRING); + config_setting_set_string(setting, "123456789"); + + /* Write out the new configuration. */ + if(! config_write_file(&cfg, CONFIG_FILE)) + { + fprintf(stderr, "Error while writing file.\n"); + config_destroy(&cfg); + return(EXIT_FAILURE); + } + + fprintf(stderr, "New configuration successfully written to: %s\n", + CONFIG_FILE); + + config_destroy(&cfg); + return(EXIT_SUCCESS); +} + + +int init_read_wh_config(){ + + + config_init(&cfg); + + if (!config_read_file(&cfg, CONFIG_FILE)) { + fprintf(stderr, "%s:%d - %s\n", + config_error_file(&cfg), + config_error_line(&cfg), + config_error_text(&cfg)); + config_destroy(&cfg); + return(EXIT_FAILURE); + } + + + if (config_lookup_string(&cfg, SSID, &g_ssid)) + printf("SSID: %s", g_ssid); + else + printf("SSID is not defined\n"); + + if (config_lookup_string(&cfg, PASSPHRASE, &g_pass)) + printf("PASS: %s", g_pass); + else + printf("PASS is not defined\n"); + + + + + + //config_destroy(cfg); + return 0; + + +} + + + +void set_ssid(const char* ssid){ + + g_ssid=ssid; +} + +const char* get_ssid(){ + + return g_ssid; +} + + +void set_pass(const char* pass){ + + g_pass=pass; +} + + +const char* get_pass(){ + + return g_pass; +} diff --git a/src/ui/h_prop.h b/src/ui/h_prop.h index 82e28f5..4ede8d6 100644 --- a/src/ui/h_prop.h +++ b/src/ui/h_prop.h @@ -47,6 +47,11 @@ int create_config(char *); int init_read_wh_config(void); -const char *print_test(); + +void set_ssid(const char* ssid); +const char* get_ssid(void); + +void set_pass(const char* pass); +const char* get_pass(void); #endif //WIHOTSPOT_H_PROP_H