mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2024-11-22 03:55:25 +00:00
Create and Read SSID and PASSPHARE to cinfig file and init getters and setters
This commit is contained in:
parent
9204bc1836
commit
49c9aed7e4
102
src/ui/h_prop.c
102
src/ui/h_prop.c
@ -4,6 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user