Commit 076b8645 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

add support for application/problem+json

parent 088ec1c9
......@@ -191,7 +191,9 @@ void IndividualSMContextApiImpl::update_sm_context(
nlohmann::json json_data = { };
mime_parser parser = { };
std::string body = { };
std::string json_format;
sm_context_response.get_json_format(json_format);
sm_context_response.get_json_data(json_data);
Logger::smf_api_server().debug("Json data %s", json_data.dump().c_str());
......@@ -200,7 +202,8 @@ void IndividualSMContextApiImpl::update_sm_context(
parser.create_multipart_related_content(
body, json_data.dump(), CURL_MIME_BOUNDARY,
sm_context_response.get_n1_sm_message(),
sm_context_response.get_n2_sm_information());
sm_context_response.get_n2_sm_information(),
json_format);
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(
"multipart/related; boundary=" + std::string(CURL_MIME_BOUNDARY)));
......@@ -208,7 +211,8 @@ void IndividualSMContextApiImpl::update_sm_context(
parser.create_multipart_related_content(
body, json_data.dump(), CURL_MIME_BOUNDARY,
sm_context_response.get_n1_sm_message(),
multipart_related_content_part_e::NAS);
multipart_related_content_part_e::NAS,
json_format);
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(
"multipart/related; boundary=" + std::string(CURL_MIME_BOUNDARY)));
......@@ -216,13 +220,14 @@ void IndividualSMContextApiImpl::update_sm_context(
parser.create_multipart_related_content(
body, json_data.dump(), CURL_MIME_BOUNDARY,
sm_context_response.get_n2_sm_information(),
multipart_related_content_part_e::NGAP);
multipart_related_content_part_e::NGAP,
json_format);
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType(
"multipart/related; boundary=" + std::string(CURL_MIME_BOUNDARY)));
} else if (json_data.size() > 0 ){
response.headers().add<Pistache::Http::Header::ContentType>(
Pistache::Http::Mime::MediaType("application/json"));
Pistache::Http::Mime::MediaType(json_format));
body = json_data.dump().c_str();
} else {
response.send(Pistache::Http::Code(sm_context_response.get_http_code()));
......
......@@ -180,9 +180,11 @@ void SMContextsCollectionApiImpl::post_sm_contexts(
response.headers().add < Pistache::Http::Header::Location
> (sm_context_response.get_smf_context_uri()); //Location header
sm_context_response.get_json_data(json_data);
std::string json_format;
sm_context_response.get_json_format(json_format);
if (!json_data.empty()) {
response.headers().add < Pistache::Http::Header::ContentType
> (Pistache::Http::Mime::MediaType("application/json"));
> (Pistache::Http::Mime::MediaType(json_format));
response.send(Pistache::Http::Code(sm_context_response.get_http_code()),
json_data.dump().c_str());
} else {
......
......@@ -392,6 +392,8 @@ void smf_http2_server::create_sm_contexts_handler(
Logger::smf_api_server().debug("Got result for promise ID %d", promise_id);
nlohmann::json json_data = { };
sm_context_response.get_json_data(json_data);
std::string json_format;
sm_context_response.get_json_format(json_format);
//Add header
header_map h;
......@@ -404,7 +406,7 @@ void smf_http2_server::create_sm_contexts_handler(
sm_context_response.get_smf_context_uri().c_str() });
}
//content-type header
h.emplace("content-type", header_value {"application/json"});
h.emplace("content-type", header_value {json_format});
response.write_head(sm_context_response.get_http_code(), h);
response.end(json_data.dump().c_str());
......@@ -506,7 +508,9 @@ void smf_http2_server::update_sm_context_handler(
mime_parser parser = { };
std::string body = { };
header_map h = { };
std::string json_format;
sm_context_response.get_json_format(json_format);
sm_context_response.get_json_data(json_data);
Logger::smf_api_server().debug("Json data %s", json_data.dump().c_str());
......@@ -515,7 +519,8 @@ void smf_http2_server::update_sm_context_handler(
parser.create_multipart_related_content(
body, json_data.dump(), CURL_MIME_BOUNDARY,
sm_context_response.get_n1_sm_message(),
sm_context_response.get_n2_sm_information());
sm_context_response.get_n2_sm_information(),
json_format);
h.emplace(
"content-type",
header_value { "multipart/related; boundary="
......@@ -524,7 +529,8 @@ void smf_http2_server::update_sm_context_handler(
parser.create_multipart_related_content(
body, json_data.dump(), CURL_MIME_BOUNDARY,
sm_context_response.get_n1_sm_message(),
multipart_related_content_part_e::NAS);
multipart_related_content_part_e::NAS,
json_format);
h.emplace(
"content-type",
header_value { "multipart/related; boundary="
......@@ -533,13 +539,14 @@ void smf_http2_server::update_sm_context_handler(
parser.create_multipart_related_content(
body, json_data.dump(), CURL_MIME_BOUNDARY,
sm_context_response.get_n2_sm_information(),
multipart_related_content_part_e::NGAP);
multipart_related_content_part_e::NGAP,
json_format);
h.emplace(
"content-type",
header_value { "multipart/related; boundary="
+ std::string(CURL_MIME_BOUNDARY) });
} else {
h.emplace("content-type", header_value { "application/json" });
h.emplace("content-type", header_value { json_format });
body = json_data.dump().c_str();
}
......
......@@ -205,4 +205,6 @@ constexpr auto CURL_MIME_BOUNDARY = "----Boundary";
//for PFCP
constexpr uint64_t SECONDS_SINCE_FIRST_EPOCH = 2208988800;
#endif
......@@ -103,7 +103,8 @@ void mime_parser::create_multipart_related_content(std::string &body,
const std::string &json_part,
const std::string boundary,
const std::string &n1_message,
const std::string &n2_message) {
const std::string &n2_message,
std::string json_format) {
//TODO: provide Content-Ids as function parameters
......@@ -113,7 +114,7 @@ void mime_parser::create_multipart_related_content(std::string &body,
std::string CRLF = "\r\n";
body.append("--" + boundary + CRLF);
body.append("Content-Type: application/json" + CRLF);
body.append("Content-Type: "+ json_format + CRLF);
body.append(CRLF);
body.append(json_part + CRLF);
......@@ -135,7 +136,8 @@ void mime_parser::create_multipart_related_content(std::string &body,
//------------------------------------------------------------------------------
void mime_parser::create_multipart_related_content(
std::string &body, const std::string &json_part, const std::string boundary,
const std::string &message, const multipart_related_content_part_e content_type) {
const std::string &message, const multipart_related_content_part_e content_type,
std::string json_format) {
//TODO: provide Content-Id as function parameters
//format string as hex
......@@ -143,7 +145,7 @@ void mime_parser::create_multipart_related_content(
std::string CRLF = "\r\n";
body.append("--" + boundary + CRLF);
body.append("Content-Type: application/json" + CRLF);
body.append("Content-Type: " + json_format + CRLF);
body.append(CRLF);
body.append(json_part + CRLF);
......
......@@ -82,7 +82,8 @@ class mime_parser {
const std::string &json_part,
const std::string boundary,
const std::string &n1_message,
const std::string &n2_message);
const std::string &n2_message,
std::string json_format="application/json");
/*
* Create HTTP body content for multipart/related message
......@@ -96,7 +97,8 @@ class mime_parser {
void create_multipart_related_content(
std::string &body, const std::string &json_part,
const std::string boundary, const std::string &message,
const multipart_related_content_part_e content_type);
const multipart_related_content_part_e content_type,
std::string json_format="application/json");
private:
std::vector<mime_part> mime_parts;
......
......@@ -1497,6 +1497,7 @@ void smf_app::trigger_http_response(
nlohmann::json json_data = { };
to_json(json_data, smContextCreateError);
sm_context_response.set_json_data(json_data);
sm_context_response.set_json_format("application/problem+json");
sm_context_response.set_n1_sm_message(n1_sm_msg);
sm_context_response.set_http_code(http_code);
itti_msg->res = sm_context_response;
......@@ -1524,6 +1525,7 @@ void smf_app::trigger_http_response(
nlohmann::json json_data = { };
to_json(json_data, smContextUpdateError);
sm_context_response.set_json_data(json_data);
sm_context_response.set_json_format("application/problem+json");
sm_context_response.set_http_code(http_code);
itti_msg->res = sm_context_response;
int ret = itti_inst->send_msg(itti_msg);
......@@ -1552,6 +1554,7 @@ void smf_app::trigger_http_response(
nlohmann::json json_data = { };
to_json(json_data, smContextUpdateError);
sm_context_response.set_json_data(json_data);
sm_context_response.set_json_format("application/problem+json");
sm_context_response.set_n1_sm_message(n1_sm_msg);
sm_context_response.set_http_code(http_code);
itti_msg->res = sm_context_response;
......
......@@ -280,6 +280,17 @@ void pdu_session_sm_context_response::get_json_data(nlohmann::json &data) const
data = m_json_data;
}
//-----------------------------------------------------------------------------
void pdu_session_sm_context_response::set_json_format(const std::string &format) {
m_json_format = format;
}
//-----------------------------------------------------------------------------
void pdu_session_sm_context_response::get_json_format(std::string &format) const {
format = m_json_format;
}
/*
* class: PDU Session Create SM Context Request
*/
......@@ -569,6 +580,16 @@ void pdu_session_modification_network_requested::get_json_data(nlohmann::json &d
data = m_json_data;
}
//-----------------------------------------------------------------------------
void pdu_session_modification_network_requested::set_json_format(const std::string &format) {
m_json_format = format;
}
//-----------------------------------------------------------------------------
void pdu_session_modification_network_requested::get_json_format(std::string &format) const {
format = m_json_format;
}
//-----------------------------------------------------------------------------
void pdu_session_modification_network_requested::add_qos_flow_context_updated(
const qos_flow_context_updated &flow) {
......
......@@ -226,6 +226,7 @@ class pdu_session_sm_context_response : public pdu_session_msg {
pdu_session_msg(msg_type) {
m_cause = 0;
m_http_code = 0;
m_json_format = "application/json";
}
pdu_session_sm_context_response(pdu_session_msg_type_t msg_type, supi_t supi,
pdu_session_id_t pdi, std::string dnn,
......@@ -234,6 +235,7 @@ class pdu_session_sm_context_response : public pdu_session_msg {
pdu_session_msg(msg_type, supi, pdi, dnn, snssai) {
m_cause = 0;
m_http_code = 0;
m_json_format = "application/json";
}
void set_cause(const uint8_t cause);
......@@ -242,10 +244,13 @@ class pdu_session_sm_context_response : public pdu_session_msg {
uint32_t get_http_code() const;
void set_json_data(const nlohmann::json &data);
void get_json_data(nlohmann::json &data) const;
void set_json_format(const std::string &format);
void get_json_format(std::string &format) const;
private:
uint8_t m_cause;
nlohmann::json m_json_data;
std::string m_json_format;
uint32_t m_http_code;
};
......@@ -442,6 +447,8 @@ class pdu_session_modification_network_requested :
pdu_session_modification_network_requested()
:
pdu_session_sm_context_request(PDU_SESSION_MODIFICATION_SMF_REQUESTED) {
m_json_data = {};
m_json_format = "application/json";
}
void set_amf_url(const std::string &value);
......@@ -451,6 +458,8 @@ class pdu_session_modification_network_requested :
void get_qfis(std::vector<pfcp::qfi_t> &q);
void set_json_data(const nlohmann::json &data);
void get_json_data(nlohmann::json &data) const;
void set_json_format(const std::string &format);
void get_json_format(std::string &format) const;
void add_qos_flow_context_updated(const qos_flow_context_updated &qos_flow);
bool get_qos_flow_context_updated(const pfcp::qfi_t &qfi,
qos_flow_context_updated &qos_flow);
......@@ -460,6 +469,7 @@ class pdu_session_modification_network_requested :
std::vector<pfcp::qfi_t> qfis;
std::map<uint8_t, qos_flow_context_updated> qos_flow_context_updateds;
nlohmann::json m_json_data;
std::string m_json_format;
};
//---------------------------------------------------------------------------------------
......
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