[SBI] Fixed Invalid S-NSSAI format (#2337)

This commit is contained in:
Sukchan Lee 2023-05-28 21:50:30 +09:00
parent ad86e8f49b
commit 31f95ce2e0
7 changed files with 124 additions and 37 deletions

View file

@ -772,7 +772,7 @@ int ogs_sbi_rfc7231_string(char *date_str, ogs_time_t time)
return OGS_OK;
}
char *ogs_sbi_s_nssai_to_string(ogs_s_nssai_t *s_nssai)
char *ogs_sbi_s_nssai_to_json(ogs_s_nssai_t *s_nssai)
{
cJSON *item = NULL;
OpenAPI_snssai_t sNSSAI;
@ -798,7 +798,7 @@ char *ogs_sbi_s_nssai_to_string(ogs_s_nssai_t *s_nssai)
return v;
}
bool ogs_sbi_s_nssai_from_string(ogs_s_nssai_t *s_nssai, char *str)
bool ogs_sbi_s_nssai_from_json(ogs_s_nssai_t *s_nssai, char *str)
{
bool rc = false;
@ -823,6 +823,70 @@ bool ogs_sbi_s_nssai_from_string(ogs_s_nssai_t *s_nssai, char *str)
return rc;
}
char *ogs_sbi_s_nssai_to_string(ogs_s_nssai_t *s_nssai)
{
ogs_assert(s_nssai);
if (s_nssai->sd.v != OGS_S_NSSAI_NO_SD_VALUE) {
return ogs_msprintf("%d-%06x", s_nssai->sst, s_nssai->sd.v);
} else {
return ogs_msprintf("%d", s_nssai->sst);
}
}
bool ogs_sbi_s_nssai_from_string(ogs_s_nssai_t *s_nssai, char *str)
{
bool rc = false;
char *token, *p, *tofree;
char *sst = NULL;
char *sd = NULL;
ogs_assert(s_nssai);
ogs_assert(str);
tofree = p = ogs_strdup(str);
if (!p) {
ogs_error("ogs_strdup[%s] failed", str);
goto cleanup;
}
token = strsep(&p, "-");
if (!token) {
ogs_error("strsep[%s] failed", str);
goto cleanup;
}
sst = ogs_strdup(token);
if (!sst) {
ogs_error("ogs_strdup[%s:%s] failed", str, token);
goto cleanup;
}
s_nssai->sst = atoi(sst);
s_nssai->sd.v = OGS_S_NSSAI_NO_SD_VALUE;
if (p) {
sd = ogs_strdup(p);
if (!sd) {
ogs_error("ogs_strdup[%s:%s] failed", str, token);
goto cleanup;
}
s_nssai->sd = ogs_uint24_from_string(sd);
}
rc = true;
cleanup:
if (tofree)
ogs_free(tofree);
if (sst)
ogs_free(sst);
if (sd)
ogs_free(sd);
return rc;
}
OpenAPI_plmn_id_t *ogs_sbi_build_plmn_id(ogs_plmn_id_t *plmn_id)
{
OpenAPI_plmn_id_t *PlmnId = NULL;
@ -1257,17 +1321,3 @@ void ogs_sbi_free_qos_data(OpenAPI_qos_data_t *QosData)
ogs_free(QosData);
}
char *ogs_sbi_s_nssai_to_string_plain(ogs_s_nssai_t *s_nssai)
{
ogs_assert(s_nssai);
if (s_nssai->sd.v !=
OGS_S_NSSAI_NO_SD_VALUE) {
return ogs_msprintf("%d%06x",
s_nssai->sst,
s_nssai->sd.v);
} else {
return ogs_msprintf("%d",
s_nssai->sst);
}
}