Commit 23101545 authored by Frédéric Leroy's avatar Frédéric Leroy

style(conf2uedata): use bool type for readability

parent 28bf2317
......@@ -28,7 +28,7 @@ int main(int argc, char**argv) {
break;
case 'h':
_display_usage();
return EXIT_SUCCESS;
return true;
break;
default:
break;
......@@ -38,26 +38,26 @@ int main(int argc, char**argv) {
if (output_dir == NULL ) {
printf("No output option found\n");
_display_usage();
return EXIT_FAILURE;
exit(1);
}
if ( conf_file == NULL ) {
printf("No Configuration file is given\n");
_display_usage();
return EXIT_FAILURE;
exit(1);
}
if ( parse_config_file(output_dir, conf_file) == EXIT_FAILURE ) {
exit(EXIT_FAILURE);
if ( parse_config_file(output_dir, conf_file) == false ) {
exit(1);
}
display_data_from_directory(output_dir);
exit(EXIT_SUCCESS);
exit(0);
}
int parse_config_file(const char *output_dir, const char *conf_filename) {
int rc = EXIT_SUCCESS;
bool parse_config_file(const char *output_dir, const char *conf_filename) {
int rc = true;
int ret;
int ue_nb = 0;
config_setting_t *root_setting = NULL;
......@@ -69,7 +69,7 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
networks_t networks;;
ret = get_config_from_file(conf_filename, &cfg);
if (ret == EXIT_FAILURE) {
if (ret == false) {
exit(1);
}
......@@ -79,11 +79,11 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
all_plmn_setting = config_setting_get_member(root_setting, PLMN);
if (all_plmn_setting == NULL) {
printf("NO PLMN SECTION...EXITING...\n");
return (EXIT_FAILURE);
return (false);
}
if ( parse_plmns(all_plmn_setting, &networks) == false ) {
return EXIT_FAILURE;
return false;
}
for (int i = 0; i < ue_nb; i++) {
......@@ -102,25 +102,25 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
ue_setting = config_setting_get_member(root_setting, user);
if (ue_setting == NULL) {
printf("Check UE%d settings\n", i);
return EXIT_FAILURE;
return false;
}
if ( parse_user_plmns_conf(ue_setting, i, &user_plmns, &usim_data_conf.hplmn, networks) == false ) {
return EXIT_FAILURE;
return false;
}
rc = parse_ue_user_data(ue_setting, i, &user_data_conf);
if (rc != EXIT_SUCCESS) {
if (rc != true) {
printf("Problem in USER section for UE%d. EXITING...\n", i);
return EXIT_FAILURE;
return false;
}
gen_user_data(&user_data_conf, &user_data);
write_user_data(output_dir, i, &user_data);
rc = parse_ue_sim_param(ue_setting, i, &usim_data_conf);
if (rc != EXIT_SUCCESS) {
if (rc != true) {
printf("Problem in SIM section for UE%d. EXITING...\n", i);
return EXIT_FAILURE;
return false;
}
gen_usim_data(&usim_data_conf, &usim_data, &user_plmns, networks);
write_usim_data(output_dir, i, &usim_data);
......@@ -135,14 +135,14 @@ int parse_config_file(const char *output_dir, const char *conf_filename) {
free(networks.items);
networks.size=0;
config_destroy(&cfg);
return(EXIT_SUCCESS);
return(true);
}
int get_config_from_file(const char *filename, config_t *config) {
bool get_config_from_file(const char *filename, config_t *config) {
config_init(config);
if (filename == NULL) {
// XXX write error message ?
exit(EXIT_FAILURE);
return(false);
}
/* Read the file. If there is an error, report it and exit. */
......@@ -153,9 +153,9 @@ int get_config_from_file(const char *filename, config_t *config) {
fprintf(stderr, "This is line %d\n", config_error_line(config));
}
config_destroy(config);
return (EXIT_FAILURE);
return (false);
}
return EXIT_SUCCESS;
return true;
}
/*
......
......@@ -8,8 +8,8 @@
#define UE "UE"
int get_config_from_file(const char *filename, config_t *config);
int parse_config_file(const char *output_dir, const char *filename);
bool get_config_from_file(const char *filename, config_t *config);
bool parse_config_file(const char *output_dir, const char *filename);
void _display_usage(void);
......
......@@ -56,16 +56,16 @@ void gen_emm_data(emm_nvdata_t *emm_data, const char *hplmn, const char *msin, i
emm_data->eplmn.n_plmns = ehplmn_count;
}
int write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data) {
bool write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data) {
int rc;
char* filename = make_filename(directory, EMM_NVRAM_FILENAME, user_id);
rc = memory_write(filename, emm_data, sizeof(emm_nvdata_t));
free(filename);
if (rc != RETURNok) {
perror("ERROR\t: memory_write() failed");
exit(EXIT_FAILURE);
exit(false);
}
return(EXIT_SUCCESS);
return(true);
}
int get_msin_parity(const char * msin, const char *mcc, const char *mnc) {
......
......@@ -5,7 +5,7 @@
#include "emmData.h"
void gen_emm_data(emm_nvdata_t *emm_data, const char *hplmn, const char *msin, int ehplmn_count, const networks_t networks);
int write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data);
bool write_emm_data(const char *directory, int user_id, emm_nvdata_t *emm_data);
int get_msin_parity(const char * msin, const char *mcc, const char *mnc);
#endif
#include <string.h>
#include <stdlib.h>
#include "commonDef.h"
#include "memory.h"
#include "fs.h"
#include "conf_user_data.h"
......@@ -8,34 +9,34 @@
int parse_ue_user_data(config_setting_t *ue_setting, int user_id, user_data_conf_t *u) {
config_setting_t *ue_param_setting = NULL;
int rc = EXIT_SUCCESS;
int rc = true;
ue_param_setting = config_setting_get_member(ue_setting, USER);
if (ue_param_setting == NULL) {
printf("Check USER section of UE%d. EXITING...\n", user_id);
return EXIT_FAILURE;
return false;
}
rc = config_setting_lookup_string(ue_param_setting, UE_IMEI, &u->imei);
if (rc != 1) {
printf("Check USER IMEI section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
return false;
}
rc = config_setting_lookup_string(ue_param_setting, MANUFACTURER,
&u->manufacturer);
if (rc != 1) {
printf("Check USER MANUFACTURER for UE%d FULLNAME. Exiting\n", user_id);
return EXIT_FAILURE;
return false;
}
rc = config_setting_lookup_string(ue_param_setting, MODEL, &u->model);
if (rc != 1) {
printf("Check USER MODEL for UE%d FULLNAME. Exiting\n", user_id);
return EXIT_FAILURE;
return false;
}
rc = config_setting_lookup_string(ue_param_setting, PINCODE, &u->pin);
if (rc != 1) {
printf("Check USER PIN for UE%d FULLNAME. Exiting\n", user_id);
return EXIT_FAILURE;
return false;
}
return EXIT_SUCCESS;
return true;
}
void gen_user_data(user_data_conf_t *u, user_nvdata_t *user_data) {
......@@ -55,15 +56,16 @@ void gen_user_data(user_data_conf_t *u, user_nvdata_t *user_data) {
strncpy(user_data->PIN, u->pin, USER_PIN_SIZE);
}
void write_user_data(const char *directory, int user_id, user_nvdata_t *data) {
bool write_user_data(const char *directory, int user_id, user_nvdata_t *data) {
int rc;
char* filename = make_filename(directory, USER_NVRAM_FILENAME, user_id);
rc = memory_write(filename, data, sizeof(user_nvdata_t));
free(filename);
if (rc != EXIT_SUCCESS) {
if (rc != RETURNok) {
perror("ERROR\t: memory_write() failed");
exit(EXIT_FAILURE);
return false;
}
return true;
}
/*
......
#ifndef _CONF_USER_DATA_H
#define _CONF_USER_DATA_H
#include <stdbool.h>
#include <libconfig.h>
#include "userDef.h"
......@@ -18,7 +19,7 @@ typedef struct {
} user_data_conf_t;
void gen_user_data(user_data_conf_t *u, user_nvdata_t *user_data);
void write_user_data(const char *directory, int user_id, user_nvdata_t *data);
bool write_user_data(const char *directory, int user_id, user_nvdata_t *data);
int parse_ue_user_data(config_setting_t *ue_setting, int user_id, user_data_conf_t *u);
int _luhn(const char* cc);
......
......@@ -8,36 +8,36 @@
#include "conf2uedata.h"
#include "conf_usim.h"
int parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u) {
int rc = EXIT_SUCCESS;
bool parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u) {
int rc = true;
config_setting_t *ue_param_setting = NULL;
ue_param_setting = config_setting_get_member(ue_setting, SIM);
if (ue_param_setting == NULL) {
printf("Check SIM section for UE%d. EXITING...\n", user_id);
return EXIT_FAILURE;
return false;
}
rc = config_setting_lookup_string(ue_param_setting, MSIN, &u->msin);
if (rc != 1 || strlen(u->msin) > 10 || strlen(u->msin) < 9) {
printf("Check SIM MSIN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
return false;
}
rc = config_setting_lookup_string(ue_param_setting, USIM_API_K,
&u->usim_api_k);
if (rc != 1) {
printf("Check SIM USIM_API_K section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
return false;
}
rc = config_setting_lookup_string(ue_param_setting, OPC, &u->opc);
if (rc != 1) {
printf("Check SIM OPC section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
return false;
}
rc = config_setting_lookup_string(ue_param_setting, MSISDN, &u->msisdn);
if (rc != 1) {
printf("Check SIM MSISDN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
return false;
}
return EXIT_SUCCESS;
return true;
}
void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data,
......@@ -295,7 +295,7 @@ void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data,
OPC_SIZE);
}
int write_usim_data(const char *directory, int user_id, usim_data_t *usim_data){
bool write_usim_data(const char *directory, int user_id, usim_data_t *usim_data){
int rc;
char *filename = make_filename(directory, USIM_API_NVRAM_FILENAME, user_id);
rc = usim_api_write(filename, usim_data);
......
......@@ -39,8 +39,8 @@ typedef struct {
const char *hplmn;
} usim_data_conf_t;
int parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u);
int write_usim_data(const char *directory, int user_id, usim_data_t *usim_data);
bool parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u);
bool write_usim_data(const char *directory, int user_id, usim_data_t *usim_data);
void gen_usim_data(usim_data_conf_t *u, usim_data_t *usim_data,
const user_plmns_t *user_plmns, const networks_t networks);
......
......@@ -64,7 +64,7 @@ void display_ue_data(const char *filename) {
if (rc != RETURNok) {
perror("ERROR\t: memory_read() failed");
exit(EXIT_FAILURE);
exit(false);
}
/*
......@@ -92,7 +92,7 @@ void display_emm_data(const char *filename) {
rc = memory_read(filename, &data, sizeof(emm_nvdata_t));
if (rc != RETURNok) {
perror("ERROR\t: memory_read() failed ");
exit(EXIT_FAILURE);
exit(false);
}
/*
......@@ -168,7 +168,7 @@ void display_usim_data(const char *filename) {
if (rc != RETURNok) {
perror("ERROR\t: usim_api_read() failed");
exit(EXIT_FAILURE);
exit(2);
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment