Commit ec8c6d21 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Fix issue for API server to deal with multipart/related message

parent bd99e507
......@@ -10,8 +10,29 @@
* Do not edit the class manually.
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "IndividualSMContextApi.h"
#include "SmContextReleaseMessage.h"
#include "logger.hpp"
#include "Helpers.h"
extern "C" {
......@@ -55,6 +76,7 @@ void IndividualSMContextApi::setupRoutes() {
void IndividualSMContextApi::release_sm_context_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
//TODO: to be updated as update_sm_context_handler
Logger::smf_api_server().info("Received a Nsmf_PDUSession_UpdateSMContext: PDU Session Release request from AMF");
Logger::smf_api_server().debug("Request body: %s\n",request.body().c_str());
SmContextReleaseMessage smContextReleaseMessage;
......@@ -139,10 +161,12 @@ void IndividualSMContextApi::update_sm_context_handler(const Pistache::Rest::Req
Logger::smf_api_server().info("Received a SM context update request from AMF");
Logger::smf_api_server().debug("Request body: %s\n",request.body().c_str());
SmContextUpdateMessage smContextUpdateMessage;
// Getting the path params
auto smContextRef = request.param(":smContextRef").as<std::string>();
std::size_t found = request.body().find("Content-Type");
std::string boundary_str = request.body().substr(2, found - 4);
Logger::smf_api_server().debug("Boundary: %s", boundary_str.c_str());
SmContextUpdateMessage smContextUpdateMessage;
//step 1. use multipartparser to decode the request
multipartparser_callbacks_init(&g_callbacks);
......@@ -157,19 +181,33 @@ void IndividualSMContextApi::update_sm_context_handler(const Pistache::Rest::Req
multipartparser parser;
init_globals();
multipartparser_init(&parser, BOUNDARY);
if ((multipartparser_execute(&parser, &g_callbacks, request.body().c_str(), strlen(request.body().c_str())) != strlen(request.body().c_str())) or (!g_body_begin_called)){
response.send(Pistache::Http::Code::Bad_Request, "");
return;
multipartparser_init(&parser, reinterpret_cast<const char*>(boundary_str.c_str()));
unsigned int str_len = request.body().length();
unsigned char *data = (unsigned char *)malloc(str_len + 1);
memset(data,0,str_len + 1);
memcpy ((void *)data, (void *)request.body().c_str(),str_len);
//if ((multipartparser_execute(&parser, &g_callbacks, request.body().c_str(), strlen(request.body().c_str())) != strlen(request.body().c_str())) or (!g_body_begin_called)){
if ((multipartparser_execute(&parser, &g_callbacks, reinterpret_cast<const char*>(data), str_len) != strlen(request.body().c_str())) or (!g_body_begin_called)){
Logger::smf_api_server().warn("The received message can not be parsed properly!");
//TODO: fix this issue
//response.send(Pistache::Http::Code::Bad_Request, "");
//return;
}
free(data);
data = nullptr;
uint8_t size = g_parts.size();
Logger::smf_api_server().debug("Number of g_parts %d", g_parts.size());
part p0 = g_parts.front(); g_parts.pop_front();
Logger::smf_api_server().debug("Request body, part 1: \n%s", p0.body.c_str());
Logger::smf_api_server().debug("Request body, part 1: %s", p0.body.c_str());
part p1 = {};
if (g_parts.size() >= 2){
if (size > 1){
p1 = g_parts.front(); g_parts.pop_front();
Logger::smf_api_server().debug("Request body, part 2: \n %s",p1.body.c_str());
Logger::smf_api_server().debug("Request body, part 2: %s (%d bytes)",p1.body.c_str(), p1.body.length());
//part p2 = g_parts.front(); g_parts.pop_front();
//Logger::smf_api_server().debug("Request body, part 3: \n %s",p2.body.c_str());
}
......@@ -180,28 +218,33 @@ void IndividualSMContextApi::update_sm_context_handler(const Pistache::Rest::Req
nlohmann::json::parse(p0.body.c_str()).get_to(smContextUpdateData);
smContextUpdateMessage.setJsonData(smContextUpdateData);
if (g_parts.size() >= 2){
if (size > 1){
if (smContextUpdateData.n2SmInfoIsSet()){
//N2 SM (for Session establishment, or for session modification)
smContextUpdateMessage.setBinaryDataN2SmInformation(p1.body.c_str());
Logger::smf_api_server().debug("N2 SM information is set");
smContextUpdateMessage.setBinaryDataN2SmInformation(p1.body);
}
if (smContextUpdateData.n1SmMsgIsSet()){
//N1 SM (for session modification, UE-initiated)
Logger::smf_api_server().debug("N1 SM message is set");
smContextUpdateMessage.setBinaryDataN1SmMessage(p1.body.c_str());
}
}
// Getting the path params
auto smContextRef = request.param(":smContextRef").as<std::string>();
this->update_sm_context(smContextRef, smContextUpdateMessage, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
Logger::smf_api_server().warn("Error in parsing json, send a msg with a 400 error code to AMF");
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::exception &e) {
//send a 500 error
Logger::smf_api_server().warn("Send a msg with a 500 error code to AMF");
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
}
void IndividualSMContextApi::individual_sm_context_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
......
......@@ -15,6 +15,29 @@
*
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef IndividualSMContextApi_H_
#define IndividualSMContextApi_H_
......@@ -34,7 +57,11 @@
#include "SmContextUpdatedData.h"
#include "SmContextUpdateMessage.h"
#include "SmContextReleaseMessage.h"
#include <string>
#include "SmContextMessage.h"
#include "SmContextCreateError.h"
#include "SmContextCreatedData.h"
namespace oai {
namespace smf_server {
......@@ -48,7 +75,7 @@ public:
virtual ~IndividualSMContextApi() {}
void init();
const std::string base = "/nsmf-pdusession/v1";
const std::string base = "/nsmf-pdusession/v2";
private:
void setupRoutes();
......
......@@ -74,6 +74,11 @@ void SMContextsCollectionApi::post_sm_contexts_handler(const Pistache::Rest::Req
Logger::smf_api_server().info("Received a SM context create request from AMF");
Logger::smf_api_server().debug("Request body: %s\n",request.body().c_str());
std::size_t found = request.body().find("Content-Type");
std::string boundary_str = request.body().substr(2, found - 4);
Logger::smf_api_server().debug("Boundary: %s", boundary_str.c_str());
SmContextMessage smContextMessage;
SmContextCreateData smContextCreateData;
......@@ -90,22 +95,26 @@ void SMContextsCollectionApi::post_sm_contexts_handler(const Pistache::Rest::Req
multipartparser parser;
init_globals();
multipartparser_init(&parser, BOUNDARY);
multipartparser_init(&parser, reinterpret_cast<const char*>(boundary_str.c_str()));
if ((multipartparser_execute(&parser, &g_callbacks, request.body().c_str(), strlen(request.body().c_str())) != strlen(request.body().c_str())) or (!g_body_begin_called)){
response.send(Pistache::Http::Code::Bad_Request, "");
return;
Logger::smf_api_server().warn("The received message can not be parsed properly!");
//TODO: fix this issue
//response.send(Pistache::Http::Code::Bad_Request, "");
//return;
}
Logger::smf_api_server().debug("Number of g_parts %d", g_parts.size());
//at least 2 parts for Json data and N1 (+ N2)
if (g_parts.size() < 2){
response.send(Pistache::Http::Code::Bad_Request, "");
return;
}
part p0 = g_parts.front(); g_parts.pop_front();
Logger::smf_api_server().debug("Request body, part 1: \n%s", p0.body.c_str());
part p1 = g_parts.front(); g_parts.pop_front();
Logger::smf_api_server().debug("Request body, part 2: \n %s",p1.body.c_str());
if (g_parts.size() == 3) {
if (g_parts.size() > 0) {
part p2 = g_parts.front(); g_parts.pop_front();
Logger::smf_api_server().debug("Request body, part 3: \n %s",p2.body.c_str());
}
......@@ -118,6 +127,7 @@ void SMContextsCollectionApi::post_sm_contexts_handler(const Pistache::Rest::Req
this->post_sm_contexts(smContextMessage, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
Logger::smf_api_server().warn("Can not parse the json data!");
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (std::exception &e) {
......
......@@ -15,6 +15,28 @@
*
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef SMContextsCollectionApi_H_
#define SMContextsCollectionApi_H_
......
......@@ -45,6 +45,8 @@ IndividualSMContextApiImpl::IndividualSMContextApiImpl(std::shared_ptr<Pistache:
{ }
void IndividualSMContextApiImpl::release_sm_context(const std::string &smContextRef, const SmContextReleaseMessage &smContextReleaseMessage, Pistache::Http::ResponseWriter &response) {
//TODO: to be updated as update_sm_context_handler
Logger::smf_api_server().info("release_sm_context...");
//handle Nsmf_PDUSession_UpdateSMContext Request
......@@ -92,21 +94,16 @@ void IndividualSMContextApiImpl::update_sm_context(const std::string &smContextR
if (smContextUpdateData.n2SmInfoIsSet()){
//N2 SM (for Session establishment)
std::string n2_sm_information = smContextUpdateMessage.getBinaryDataN2SmInformation();
//std::string n2_sm_information = (smContextUpdateData.getN2SmInfo()).getContentId();
std::string n2_sm_msg_hex;
m_smf_app->convert_string_2_hex(n2_sm_information, n2_sm_msg_hex);
Logger::smf_api_server().debug("smContextMessage, n2 sm information %s", n2_sm_information.c_str());
std::string n2_sm_info_type = smContextUpdateData.getN2SmInfoType();
sm_context_req_msg.set_n2_sm_information(n2_sm_msg_hex);
sm_context_req_msg.set_n2_sm_information(n2_sm_information);
sm_context_req_msg.set_n2_sm_info_type(n2_sm_info_type);
} else if (smContextUpdateData.n1SmMsgIsSet()){
//N1 SM (for session modification)
std::string n1_sm_message = smContextUpdateMessage.getBinaryDataN1SmMessage();
std::string n1_sm_msg_hex;
m_smf_app->convert_string_2_hex(n1_sm_message, n1_sm_msg_hex);
Logger::smf_api_server().debug("smContextMessage, n1 sm message %s", n1_sm_message.c_str());
sm_context_req_msg.set_n1_sm_message(n1_sm_msg_hex);
sm_context_req_msg.set_n1_sm_message(n1_sm_message);
}
//Step 2. TODO: initialize necessary values for sm context req from smContextUpdateData
......
......@@ -15,6 +15,26 @@
*
*
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef INDIVIDUAL_SM_CONTEXT_API_IMPL_H_
#define INDIVIDUAL_SM_CONTEXT_API_IMPL_H_
......
......@@ -15,6 +15,26 @@
*
*
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef SM_CONTEXTS_COLLECTION_API_IMPL_H_
#define SM_CONTEXTS_COLLECTION_API_IMPL_H_
......
......@@ -9,7 +9,26 @@
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "pistache/endpoint.h"
#include "pistache/http.h"
......
......@@ -10,6 +10,27 @@
* Do not edit the class manually.
*/
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "pistache/endpoint.h"
#include "pistache/http.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