mirror of
https://github.com/lakinduakash/linux-wifi-hotspot.git
synced 2024-11-24 21:20:12 +00:00
set and return read values from config file
This commit is contained in:
parent
24862a9798
commit
84a2828f97
@ -7,18 +7,28 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "read_config.h"
|
||||
#include "h_prop.h"
|
||||
|
||||
#define CONFIG_KEY_COUNT 30
|
||||
#define STRING_MAX_LENGTH 100
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
ConfigValues configValues;
|
||||
|
||||
char configs[CONFIG_KEY_COUNT][STRING_MAX_LENGTH];
|
||||
|
||||
int read_config_file() {
|
||||
// std::ifstream is RAII, i.e. no need to call close
|
||||
std::ifstream cFile(CONFIG_FILE);
|
||||
if (cFile.is_open()) {
|
||||
std::string line;
|
||||
|
||||
int i=0;
|
||||
while (getline(cFile, line)) {
|
||||
line.erase(std::remove_if(line.begin(), line.end(), isspace),
|
||||
line.end());
|
||||
@ -27,7 +37,11 @@ int read_config_file() {
|
||||
auto delimiterPos = line.find('=');
|
||||
auto name = line.substr(0, delimiterPos);
|
||||
auto value = line.substr(delimiterPos + 1);
|
||||
|
||||
strcpy(configs[i],value.c_str());
|
||||
setConfigValues(name.c_str(),configs[i]);
|
||||
std::cout << name << " " << value << '\n';
|
||||
++i;
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -36,4 +50,23 @@ int read_config_file() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConfigValues* getConfigValues(){
|
||||
return &configValues;
|
||||
}
|
||||
|
||||
|
||||
static void setConfigValues(const char * key, char *value){
|
||||
|
||||
if( !strcmp ( SSID, key ))
|
||||
configValues.ssid = value;
|
||||
|
||||
if( !strcmp ( PASSPHRASE, key ))
|
||||
configValues.pass = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -5,12 +5,15 @@
|
||||
#ifndef WIHOTSPOT_READ_CONFIG_H
|
||||
#define WIHOTSPOT_READ_CONFIG_H
|
||||
|
||||
#include "h_prop.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int read_config_file();
|
||||
|
||||
static void setConfigValues(const char * key, char *value);
|
||||
ConfigValues* getConfigValues(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user