From dd2c85b1b053faaaec04afc6f1e3df29b7a713aa Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sun, 12 Mar 2023 22:40:20 +0900 Subject: [PATCH] [SBI] Conforms standard in Subscription API(#2152) POST requests to {apiRoot}/nnrf-nfm/v1/subscriptions return a HTTP Location header in 201 respose in the form {apiRoot}/nnrf-nfm/v1/subscriptions/{subscriptionID} --- lib/sbi/nnrf-handler.c | 40 ++++++++++++++++++++++++++++++++++++---- src/nrf/nnrf-handler.c | 20 +++++++++++++++++++- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/lib/sbi/nnrf-handler.c b/lib/sbi/nnrf-handler.c index 6683e3c46..30f8d2e7c 100644 --- a/lib/sbi/nnrf-handler.c +++ b/lib/sbi/nnrf-handler.c @@ -535,12 +535,44 @@ void ogs_nnrf_nfm_handle_nf_status_subscribe( return; } - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); + if (recvmsg->http.location) { + int rv; + ogs_sbi_message_t message; + ogs_sbi_header_t header; + + memset(&header, 0, sizeof(header)); + header.uri = recvmsg->http.location; + + rv = ogs_sbi_parse_header(&message, &header); + if (rv != OGS_OK) { + ogs_error("Cannot parse http.location [%s]", + recvmsg->http.location); + return; + } + + if (!message.h.resource.component[1]) { + ogs_error("No Subscription ID [%s]", recvmsg->http.location); + ogs_sbi_header_free(&header); + return; + } + + ogs_sbi_subscription_data_set_id( + subscription_data, message.h.resource.component[1]); + + ogs_sbi_header_free(&header); + + } else if (SubscriptionData->subscription_id) { + /* + * For compatibility with v2.5.x and lower versions + * + * Deprecated : It will be removed soon. + */ + ogs_sbi_subscription_data_set_id( + subscription_data, SubscriptionData->subscription_id); + } else { + ogs_error("No Subscription ID"); return; } - ogs_sbi_subscription_data_set_id( - subscription_data, SubscriptionData->subscription_id); /* SBI Features */ if (SubscriptionData->nrf_supported_features) { diff --git a/src/nrf/nnrf-handler.c b/src/nrf/nnrf-handler.c index d89afca8d..eea2f96b7 100644 --- a/src/nrf/nnrf-handler.c +++ b/src/nrf/nnrf-handler.c @@ -188,6 +188,9 @@ bool nrf_nnrf_handle_nf_status_subscribe( OpenAPI_uri_scheme_e scheme = OpenAPI_uri_scheme_NULL; ogs_sockaddr_t *addr = NULL; + ogs_sbi_server_t *server = NULL; + ogs_sbi_header_t header; + ogs_uuid_t uuid; char id[OGS_UUID_FORMATTED_LENGTH + 1]; @@ -321,13 +324,28 @@ bool nrf_nnrf_handle_nf_status_subscribe( SubscriptionData->validity_time, subscription_data->time.validity_duration); - recvmsg->http.location = recvmsg->h.uri; + /* Location */ + server = ogs_sbi_server_from_stream(stream); + ogs_assert(server); + + memset(&header, 0, sizeof(header)); + header.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; + header.api.version = (char *)OGS_SBI_API_V1; + header.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS; + header.resource.component[1] = subscription_data->id; + + recvmsg->http.location = ogs_sbi_server_uri(server, &header); + status = OGS_SBI_HTTP_STATUS_CREATED; response = ogs_sbi_build_response(recvmsg, status); ogs_assert(response); ogs_assert(true == ogs_sbi_server_send_response(stream, response)); + if (recvmsg->http.location) + ogs_free(recvmsg->http.location); + return true; }