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

refactor(conf2uedata): add parse_Xplmn() to read *plmns

parent 5c8410c5
...@@ -227,11 +227,10 @@ int parse_plmns(config_setting_t *all_plmn_setting) { ...@@ -227,11 +227,10 @@ int parse_plmns(config_setting_t *all_plmn_setting) {
} }
int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char **h) { int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char **h) {
int rc = EXIT_SUCCESS; int nb_errors = 0;
const char *hplmn; const char *hplmn;
config_setting_t *setting = NULL;
rc = config_setting_lookup_string(ue_setting, HPLMN, h); if ( config_setting_lookup_string(ue_setting, HPLMN, h) != 1 ) {
if (rc != 1) {
printf("Check HPLMN section for UE%d. Exiting\n", user_id); printf("Check HPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -241,147 +240,41 @@ int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char ** ...@@ -241,147 +240,41 @@ int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char **
user_id); user_id);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
setting = config_setting_get_member(ue_setting, UCPLMN);
if (setting == NULL) { if ( parse_Xplmn(ue_setting, UCPLMN, user_id, &ucplmn_nb, &ucplmn) == EXIT_FAILURE )
printf("Check UCPLMN section for UE%d. Exiting\n", user_id); nb_errors++;
return EXIT_FAILURE; if ( parse_Xplmn(ue_setting, OPLMN, user_id, &oplmn_nb, &oplmn) == EXIT_FAILURE )
} nb_errors++;
rc = fill_ucplmn(setting, user_id); if ( parse_Xplmn(ue_setting, OCPLMN, user_id, &ocplmn_nb, &ocplmn) == EXIT_FAILURE )
if (rc != EXIT_SUCCESS) { nb_errors++;
printf("Check UCPLMN section for UE%d. Exiting\n", user_id); if ( parse_Xplmn(ue_setting, FPLMN, user_id, &fplmn_nb, &fplmn) == EXIT_FAILURE )
return EXIT_FAILURE; nb_errors++;
} if ( parse_Xplmn(ue_setting, EHPLMN, user_id, &ehplmn_nb, &ehplmn) == EXIT_FAILURE )
setting = config_setting_get_member(ue_setting, OPLMN); nb_errors++;
if (setting == NULL) {
printf("Check OPLMN section for UE%d. Exiting\n", user_id); if ( nb_errors > 0 )
return EXIT_FAILURE;
}
rc = fill_oplmn(setting, user_id);
if (rc != EXIT_SUCCESS) {
printf("Check OPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
setting = config_setting_get_member(ue_setting, OCPLMN);
if (setting == NULL) {
printf("Check OCPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
rc = fill_ocplmn(setting, user_id);
if (rc != EXIT_SUCCESS) {
printf("Check OCPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
setting = config_setting_get_member(ue_setting, FPLMN);
if (setting == NULL) {
printf("Check FPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
rc = fill_fplmn(setting, user_id);
if (rc != EXIT_SUCCESS) {
printf("Check FPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
setting = config_setting_get_member(ue_setting, EHPLMN);
if (setting == NULL) {
printf("Check EHPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
rc = fill_ehplmn(setting, user_id);
if (rc != EXIT_SUCCESS) {
printf("Check EHPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE; return EXIT_FAILURE;
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
int fill_ucplmn(config_setting_t* setting, int user_id) { int parse_Xplmn(config_setting_t *ue_setting, const char *section,
int rc; int user_id, int *plmns_count, int **plmns ) {
ucplmn_nb = config_setting_length(setting);
ucplmn = malloc(ucplmn_nb * sizeof(int));
for (int i = 0; i < ucplmn_nb; i++) {
const char *mccmnc = config_setting_get_string_elem(setting, i);
if (mccmnc == NULL) {
printf("Check UCPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
rc = get_plmn_index(mccmnc);
if (rc == -1) {
printf("The PLMN %s is not defined in PLMN section. Exiting...\n",
mccmnc);
return EXIT_FAILURE;
}
ucplmn[i] = rc;
}
return EXIT_SUCCESS;
}
int fill_oplmn(config_setting_t* setting, int user_id) {
int rc;
oplmn_nb = config_setting_length(setting);
oplmn = malloc(oplmn_nb * sizeof(int));
for (int i = 0; i < oplmn_nb; i++) {
const char *mccmnc = config_setting_get_string_elem(setting, i);
if (mccmnc == NULL) {
printf("Check OPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
rc = get_plmn_index(mccmnc);
if (rc == -1) {
printf("The PLMN %s is not defined in PLMN section. Exiting...\n",
mccmnc);
return EXIT_FAILURE;
}
oplmn[i] = rc;
}
return EXIT_SUCCESS;
}
int fill_ocplmn(config_setting_t* setting, int user_id) {
int rc;
ocplmn_nb = config_setting_length(setting);
ocplmn = malloc(ocplmn_nb * sizeof(int));
for (int i = 0; i < ocplmn_nb; i++) {
const char *mccmnc = config_setting_get_string_elem(setting, i);
if (mccmnc == NULL) {
printf("Check OCPLMN section for UE%d. Exiting\n", user_id);
return EXIT_FAILURE;
}
rc = get_plmn_index(mccmnc);
if (rc == -1) {
printf("The PLMN %s is not defined in PLMN section. Exiting...\n",
mccmnc);
return EXIT_FAILURE;
}
ocplmn[i] = rc;
}
return EXIT_SUCCESS;
}
int fill_fplmn(config_setting_t* setting, int user_id) {
int rc; int rc;
fplmn_nb = config_setting_length(setting); int item_count;
fplmn = malloc(fplmn_nb * sizeof(int)); config_setting_t *setting;
for (int i = 0; i < fplmn_nb; i++) {
const char *mccmnc = config_setting_get_string_elem(setting, i); setting = config_setting_get_member(ue_setting, section);
if (mccmnc == NULL) { if (setting == NULL) {
printf("Check FPLMN section for UE%d. Exiting\n", user_id); printf("Check %s section for UE%d. Exiting\n", section, user_id);
return EXIT_FAILURE; return EXIT_FAILURE;
}
rc = get_plmn_index(mccmnc);
if (rc == -1) {
printf("The PLMN %s is not defined in PLMN section. Exiting...\n",
mccmnc);
return EXIT_FAILURE;
}
fplmn[i] = rc;
} }
return EXIT_SUCCESS;
} item_count = config_setting_length(setting);
int fill_ehplmn(config_setting_t* setting, int user_id) { int *datas = malloc(item_count * sizeof(int));
int rc; for (int i = 0; i < item_count; i++) {
ehplmn_nb = config_setting_length(setting);
ehplmn = malloc(ehplmn_nb * sizeof(int));
for (int i = 0; i < ehplmn_nb; i++) {
const char *mccmnc = config_setting_get_string_elem(setting, i); const char *mccmnc = config_setting_get_string_elem(setting, i);
if (mccmnc == NULL) { if (mccmnc == NULL) {
printf("Check EHPLMN section for UE%d. Exiting\n", user_id); printf("Check %s section for UE%d. Exiting\n", section, user_id);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
rc = get_plmn_index(mccmnc); rc = get_plmn_index(mccmnc);
...@@ -390,8 +283,11 @@ int fill_ehplmn(config_setting_t* setting, int user_id) { ...@@ -390,8 +283,11 @@ int fill_ehplmn(config_setting_t* setting, int user_id) {
mccmnc); mccmnc);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
ehplmn[i] = rc; datas[i] = rc;
} }
*plmns_count = item_count;
*plmns = datas;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
......
...@@ -69,10 +69,8 @@ int parse_plmn_param(config_setting_t *plmn_setting, int index); ...@@ -69,10 +69,8 @@ int parse_plmn_param(config_setting_t *plmn_setting, int index);
int parse_plmns(config_setting_t *all_plmn_setting); int parse_plmns(config_setting_t *all_plmn_setting);
int get_plmn_index(const char * mccmnc); int get_plmn_index(const char * mccmnc);
int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char **hplmn); int parse_ue_plmn_param(config_setting_t *ue_setting, int user_id, const char **hplmn);
int fill_ucplmn(config_setting_t* setting, int use_id); int parse_Xplmn(config_setting_t *ue_setting, const char *section,
int fill_oplmn(config_setting_t* setting, int use_id); int user_id, int *plmns_count, int **plmns );
int fill_ocplmn(config_setting_t* setting, int use_id);
int fill_fplmn(config_setting_t* setting, int use_id);
int fill_ehplmn(config_setting_t* setting, int use_id);
#endif // _CONF2UEDATA_H #endif // _CONF2UEDATA_H
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