forked from acouzens/open5gs
fix the bug for Real PCF unable to PATCH (#1086)
This commit is contained in:
parent
dde0785375
commit
005cd30e02
|
@ -26,6 +26,7 @@ char *ogs_uridup(bool https, ogs_sockaddr_t *addr, ogs_sbi_header_t *h)
|
|||
char uri[OGS_HUGE_LEN];
|
||||
char *p, *last;
|
||||
int i;
|
||||
char *hostname = NULL;
|
||||
|
||||
ogs_assert(addr);
|
||||
ogs_assert(h);
|
||||
|
@ -39,11 +40,16 @@ char *ogs_uridup(bool https, ogs_sockaddr_t *addr, ogs_sbi_header_t *h)
|
|||
else
|
||||
p = ogs_slprintf(p, last, "http://");
|
||||
|
||||
/* IP address */
|
||||
if (addr->ogs_sa_family == AF_INET6)
|
||||
p = ogs_slprintf(p, last, "[%s]", OGS_ADDR(addr, buf));
|
||||
else
|
||||
p = ogs_slprintf(p, last, "%s", OGS_ADDR(addr, buf));
|
||||
/* Hostname/IP address */
|
||||
hostname = ogs_gethostname(addr);
|
||||
if (hostname) {
|
||||
p = ogs_slprintf(p, last, "%s", hostname);
|
||||
} else {
|
||||
if (addr->ogs_sa_family == AF_INET6)
|
||||
p = ogs_slprintf(p, last, "[%s]", OGS_ADDR(addr, buf));
|
||||
else
|
||||
p = ogs_slprintf(p, last, "%s", OGS_ADDR(addr, buf));
|
||||
}
|
||||
|
||||
/* Port number */
|
||||
if ((https == true && OGS_PORT(addr) == OGS_SBI_HTTPS_PORT)) {
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
#include "any_type.h"
|
||||
|
||||
bool OpenAPI_IsInvalid(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xFF) == OpenAPI_Invalid;
|
||||
}
|
||||
bool OpenAPI_IsFalse(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xFF) == OpenAPI_False;
|
||||
}
|
||||
bool OpenAPI_IsTrue(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xff) == OpenAPI_True;
|
||||
}
|
||||
bool OpenAPI_IsBool(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & (OpenAPI_True | OpenAPI_False)) != 0;
|
||||
}
|
||||
bool OpenAPI_IsNull(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xFF) == OpenAPI_NULL;
|
||||
}
|
||||
bool OpenAPI_IsNumber(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xFF) == OpenAPI_Number;
|
||||
}
|
||||
bool OpenAPI_IsString(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xFF) == OpenAPI_String;
|
||||
}
|
||||
bool OpenAPI_IsArray(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xFF) == OpenAPI_Array;
|
||||
}
|
||||
bool OpenAPI_IsObject(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xFF) == OpenAPI_Object;
|
||||
}
|
||||
bool OpenAPI_IsRaw(const OpenAPI_any_type_t * const item)
|
||||
{
|
||||
if (item == NULL) return false;
|
||||
|
||||
return (item->type & 0xFF) == OpenAPI_Raw;
|
||||
}
|
||||
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_true(void)
|
||||
{
|
||||
return OpenAPI_any_type_create_bool(true);
|
||||
}
|
||||
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_false(void)
|
||||
{
|
||||
return OpenAPI_any_type_create_bool(false);
|
||||
}
|
||||
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_bool(bool boolean)
|
||||
{
|
||||
OpenAPI_any_type_t *any_type = NULL;
|
||||
|
||||
any_type = ogs_calloc(1, sizeof(*any_type));
|
||||
if (any_type) {
|
||||
any_type->type = boolean ? OpenAPI_True : OpenAPI_False;
|
||||
}
|
||||
|
||||
return any_type;
|
||||
}
|
||||
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_number(double num)
|
||||
{
|
||||
OpenAPI_any_type_t *any_type = NULL;
|
||||
|
||||
any_type = ogs_calloc(1, sizeof(*any_type));
|
||||
if (any_type) {
|
||||
any_type->type = OpenAPI_Number;
|
||||
any_type->valuedouble = num;
|
||||
}
|
||||
|
||||
return any_type;
|
||||
}
|
||||
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_string(const char *string)
|
||||
{
|
||||
OpenAPI_any_type_t *any_type = NULL;
|
||||
|
||||
any_type = ogs_calloc(1, sizeof(*any_type));
|
||||
if (any_type) {
|
||||
any_type->type = OpenAPI_String;
|
||||
any_type->valuestring = ogs_strdup(string);
|
||||
}
|
||||
|
||||
return any_type;
|
||||
}
|
||||
|
||||
void OpenAPI_any_type_free(OpenAPI_any_type_t *any_type)
|
||||
{
|
||||
if (any_type) {
|
||||
if (any_type->type == OpenAPI_String) {
|
||||
ogs_free(any_type->valuestring);
|
||||
}
|
||||
ogs_free(any_type);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef OGS_SBI_ANY_TYPE_H
|
||||
#define OGS_SBI_ANY_TYPE_H
|
||||
|
||||
#include "ogs-core.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define OpenAPI_Invalid (0)
|
||||
#define OpenAPI_False (1 << 0)
|
||||
#define OpenAPI_True (1 << 1)
|
||||
#define OpenAPI_NULL (1 << 2)
|
||||
#define OpenAPI_Number (1 << 3)
|
||||
#define OpenAPI_String (1 << 4)
|
||||
#define OpenAPI_Array (1 << 5)
|
||||
#define OpenAPI_Object (1 << 6)
|
||||
#define OpenAPI_Raw (1 << 7) /* raw json */
|
||||
|
||||
#define OpenAPI_IsReference 256
|
||||
#define OpenAPI_StringIsConst 512
|
||||
|
||||
typedef struct OpenAPI_any_type_s OpenAPI_any_type_t;
|
||||
typedef struct OpenAPI_any_type_s {
|
||||
int type;
|
||||
|
||||
char *valuestring;
|
||||
double valuedouble;
|
||||
} OpenAPI_any_type_t;
|
||||
|
||||
bool OpenAPI_IsInvalid(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsFalse(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsTrue(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsBool(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsNull(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsNumber(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsString(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsArray(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsObject(const OpenAPI_any_type_t * const item);
|
||||
bool OpenAPI_IsRaw(const OpenAPI_any_type_t * const item);
|
||||
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_true(void);
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_false(void);
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_bool(bool boolean);
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_number(double num);
|
||||
OpenAPI_any_type_t *OpenAPI_any_type_create_string(const char *string);
|
||||
void OpenAPI_any_type_free(OpenAPI_any_type_t *any_type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OGS_SBI_ANY_TYPE_H */
|
|
@ -8,7 +8,7 @@ OpenAPI_patch_item_t *OpenAPI_patch_item_create(
|
|||
OpenAPI_patch_operation_e op,
|
||||
char *path,
|
||||
char *from,
|
||||
char *value
|
||||
OpenAPI_any_type_t *value
|
||||
)
|
||||
{
|
||||
OpenAPI_patch_item_t *patch_item_local_var = OpenAPI_malloc(sizeof(OpenAPI_patch_item_t));
|
||||
|
@ -28,10 +28,9 @@ void OpenAPI_patch_item_free(OpenAPI_patch_item_t *patch_item)
|
|||
if (NULL == patch_item) {
|
||||
return;
|
||||
}
|
||||
OpenAPI_lnode_t *node;
|
||||
ogs_free(patch_item->path);
|
||||
ogs_free(patch_item->from);
|
||||
ogs_free(patch_item->value);
|
||||
OpenAPI_any_type_free(patch_item->value);
|
||||
ogs_free(patch_item);
|
||||
}
|
||||
|
||||
|
@ -63,10 +62,26 @@ cJSON *OpenAPI_patch_item_convertToJSON(OpenAPI_patch_item_t *patch_item)
|
|||
}
|
||||
|
||||
if (patch_item->value) {
|
||||
if (cJSON_AddStringToObject(item, "value", patch_item->value) == NULL) {
|
||||
ogs_error("OpenAPI_patch_item_convertToJSON() failed [value]");
|
||||
goto end;
|
||||
}
|
||||
if (OpenAPI_IsString(patch_item->value)) {
|
||||
ogs_assert(patch_item->value->valuestring);
|
||||
if (cJSON_AddStringToObject(
|
||||
item, "value", patch_item->value->valuestring) == NULL) {
|
||||
ogs_error("OpenAPI_patch_item_convertToJSON() failed [value]");
|
||||
goto end;
|
||||
}
|
||||
} else if (OpenAPI_IsNumber(patch_item->value)) {
|
||||
if (cJSON_AddNumberToObject(
|
||||
item, "value", patch_item->value->valuedouble) == NULL) {
|
||||
ogs_error("OpenAPI_patch_item_convertToJSON() failed [value]");
|
||||
goto end;
|
||||
}
|
||||
} else if (OpenAPI_IsBool(patch_item->value)) {
|
||||
if (cJSON_AddBoolToObject(
|
||||
item, "value", OpenAPI_IsTrue(patch_item->value))) {
|
||||
ogs_error("OpenAPI_patch_item_convertToJSON() failed [value]");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
|
@ -112,19 +127,24 @@ OpenAPI_patch_item_t *OpenAPI_patch_item_parseFromJSON(cJSON *patch_itemJSON)
|
|||
}
|
||||
|
||||
cJSON *value = cJSON_GetObjectItemCaseSensitive(patch_itemJSON, "value");
|
||||
OpenAPI_any_type_t *any_type_value = NULL;
|
||||
|
||||
if (value) {
|
||||
if (!cJSON_IsString(value)) {
|
||||
ogs_error("OpenAPI_patch_item_parseFromJSON() failed [value]");
|
||||
goto end;
|
||||
}
|
||||
if (cJSON_IsString(value))
|
||||
any_type_value = OpenAPI_any_type_create_string(value->valuestring);
|
||||
if (cJSON_IsNumber(value))
|
||||
any_type_value = OpenAPI_any_type_create_number(value->valuedouble);
|
||||
if (cJSON_IsTrue(value))
|
||||
any_type_value = OpenAPI_any_type_create_true();
|
||||
if (cJSON_IsFalse(value))
|
||||
any_type_value = OpenAPI_any_type_create_false();
|
||||
}
|
||||
|
||||
patch_item_local_var = OpenAPI_patch_item_create (
|
||||
opVariable,
|
||||
ogs_strdup_or_assert(path->valuestring),
|
||||
from ? ogs_strdup_or_assert(from->valuestring) : NULL,
|
||||
value ? ogs_strdup_or_assert(value->valuestring) : NULL
|
||||
any_type_value
|
||||
);
|
||||
|
||||
return patch_item_local_var;
|
|
@ -8,11 +8,11 @@
|
|||
#define _OpenAPI_patch_item_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "../include/binary.h"
|
||||
#include "patch_operation.h"
|
||||
#include "../openapi/external/cJSON.h"
|
||||
#include "../openapi/include/list.h"
|
||||
#include "../openapi/model/patch_operation.h"
|
||||
|
||||
#include "../custom/any_type.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -23,14 +23,14 @@ typedef struct OpenAPI_patch_item_s {
|
|||
OpenAPI_patch_operation_e op;
|
||||
char *path;
|
||||
char *from;
|
||||
char *value;
|
||||
OpenAPI_any_type_t *value;
|
||||
} OpenAPI_patch_item_t;
|
||||
|
||||
OpenAPI_patch_item_t *OpenAPI_patch_item_create(
|
||||
OpenAPI_patch_operation_e op,
|
||||
char *path,
|
||||
char *from,
|
||||
char *value
|
||||
OpenAPI_any_type_t *value
|
||||
);
|
||||
void OpenAPI_patch_item_free(OpenAPI_patch_item_t *patch_item);
|
||||
OpenAPI_patch_item_t *OpenAPI_patch_item_parseFromJSON(cJSON *patch_itemJSON);
|
|
@ -19,8 +19,12 @@ subdir('openapi')
|
|||
|
||||
libsbi_sources = files('''
|
||||
contrib/multipart_parser.c
|
||||
|
||||
custom/any_type.c
|
||||
|
||||
custom/links.c
|
||||
custom/ue_authentication_ctx.c
|
||||
custom/patch_item.c
|
||||
|
||||
yuarel.c
|
||||
conv.c
|
||||
|
|
|
@ -287,7 +287,9 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_update(ogs_sbi_nf_instance_t *nf_instance)
|
|||
memset(&item, 0, sizeof(item));
|
||||
item.op = OpenAPI_patch_operation_replace;
|
||||
item.path = (char *)"/nfStatus";
|
||||
item.value = OpenAPI_nf_status_ToString(OpenAPI_nf_status_REGISTERED);
|
||||
item.value = OpenAPI_any_type_create_string(
|
||||
OpenAPI_nf_status_ToString(OpenAPI_nf_status_REGISTERED));
|
||||
ogs_assert(item.value);
|
||||
|
||||
OpenAPI_list_add(PatchItemList, &item);
|
||||
|
||||
|
@ -296,6 +298,7 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_update(ogs_sbi_nf_instance_t *nf_instance)
|
|||
request = ogs_sbi_build_request(&message);
|
||||
|
||||
OpenAPI_list_free(PatchItemList);
|
||||
OpenAPI_any_type_free(item.value);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "model/nf_group_cond.h"
|
||||
#include "model/smf_info.h"
|
||||
#include "model/problem_details.h"
|
||||
#include "model/patch_item.h"
|
||||
#include "model/subscription_data.h"
|
||||
#include "model/notification_data.h"
|
||||
#include "model/search_result.h"
|
||||
|
@ -74,6 +73,7 @@
|
|||
|
||||
#include "custom/links.h"
|
||||
#include "custom/ue_authentication_ctx.h"
|
||||
#include "custom/patch_item.h"
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
|
|
|
@ -497,7 +497,6 @@ libsbi_openapi_sources = files('''
|
|||
model/partial_record_method_any_of.c
|
||||
model/partial_record_method.c
|
||||
model/partial_success_report.c
|
||||
model/patch_item.c
|
||||
model/patch_operation.c
|
||||
model/patch_result.c
|
||||
model/pc5_flow_bit_rates.c
|
||||
|
|
|
@ -58,11 +58,13 @@ ogs_sbi_request_t *udm_nudr_dr_build_authentication_subscription(
|
|||
memset(&item, 0, sizeof(item));
|
||||
item.op = OpenAPI_patch_operation_replace;
|
||||
item.path = (char *)"/sequenceNumber/sqn";
|
||||
item.value = sqn_string;
|
||||
item.value = OpenAPI_any_type_create_string(sqn_string);
|
||||
ogs_assert(item.value);
|
||||
|
||||
OpenAPI_list_add(PatchItemList, &item);
|
||||
|
||||
message.PatchItemList = PatchItemList;
|
||||
OpenAPI_any_type_free(item.value);
|
||||
}
|
||||
|
||||
request = ogs_sbi_build_request(&message);
|
||||
|
|
|
@ -136,7 +136,11 @@ bool udr_nudr_dr_handle_subscription_authentication(
|
|||
OpenAPI_list_for_each(PatchItemList, node) {
|
||||
if (node->data) {
|
||||
OpenAPI_patch_item_t *patch_item = node->data;
|
||||
sqn_string = patch_item->value;
|
||||
if (OpenAPI_IsString(patch_item->value))
|
||||
sqn_string = patch_item->value->valuestring;
|
||||
else
|
||||
ogs_error("Invalid any-type [%d]",
|
||||
patch_item->value->type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue