Unverified Commit da873b4a authored by kharade's avatar kharade

maintain http version of subscription

parent 99c5366b
......@@ -432,7 +432,7 @@ void nrf_app::handle_create_subscription(
// generate a subscription ID
generate_ev_subscription_id(evsub_id);
ss.get()->set_subscription_id(evsub_id);
ss.get()->set_http_version(http_version);
// subscribe to NF status registered
// subscribe_nf_status(evsub_id); // from nrf_app
// subscribe to NF status
......@@ -471,7 +471,7 @@ void nrf_app::handle_create_subscription(
for (auto p : profiles) {
// send notifications
nrf_client_inst->notify_subscribed_event(
p, NOTIFICATION_TYPE_NF_REGISTERED, notification_uris);
p, NOTIFICATION_TYPE_NF_REGISTERED, notification_uris, http_version);
}
}
......@@ -1025,12 +1025,13 @@ void nrf_app::handle_nf_status_registered(const std::string& profile_id) {
find_nf_profile(profile_id, profile);
if (profile.get() != nullptr) {
std::vector<std::string> notification_uris = {};
uint8_t httpVersion = 1;
get_subscription_list(
profile_id, NOTIFICATION_TYPE_NF_REGISTERED, notification_uris);
profile_id, NOTIFICATION_TYPE_NF_REGISTERED, notification_uris, httpVersion);
// send notifications
if (notification_uris.size() > 0)
nrf_client_inst->notify_subscribed_event(
profile, NOTIFICATION_TYPE_NF_REGISTERED, notification_uris);
profile, NOTIFICATION_TYPE_NF_REGISTERED, notification_uris, httpVersion);
else
Logger::nrf_app().debug("\tNo subscription found");
......@@ -1056,13 +1057,14 @@ void nrf_app::handle_nf_status_deregistered(
p.get()->get_nf_instance_id().c_str());
std::vector<std::string> notification_uris = {};
uint8_t http_version = 1;
get_subscription_list(
p.get()->get_nf_instance_id(), NOTIFICATION_TYPE_NF_DEREGISTERED,
notification_uris);
notification_uris, http_version);
// send notifications
if (notification_uris.size() > 0)
nrf_client_inst->notify_subscribed_event(
p, NOTIFICATION_TYPE_NF_DEREGISTERED, notification_uris);
p, NOTIFICATION_TYPE_NF_DEREGISTERED, notification_uris, http_version);
else
Logger::nrf_app().debug("\tNo subscription found");
}
......@@ -1085,14 +1087,15 @@ void nrf_app::handle_nf_status_profile_changed(const std::string& profile_id) {
find_nf_profile(profile_id, profile);
if (profile.get() != nullptr) {
std::vector<std::string> notification_uris = {};
uint8_t http_version = 1;
get_subscription_list(
profile_id, NOTIFICATION_TYPE_NF_PROFILE_CHANGED, notification_uris);
profile_id, NOTIFICATION_TYPE_NF_PROFILE_CHANGED, notification_uris, http_version);
// Notification data includes NF profile (other alternative, includes
// profile_changes)
// send notifications
if (notification_uris.size() > 0)
nrf_client_inst->notify_subscribed_event(
profile, NOTIFICATION_TYPE_NF_PROFILE_CHANGED, notification_uris);
profile, NOTIFICATION_TYPE_NF_PROFILE_CHANGED, notification_uris, http_version);
else
Logger::nrf_app().debug("\tNo subscription found");
} else {
......@@ -1104,7 +1107,7 @@ void nrf_app::handle_nf_status_profile_changed(const std::string& profile_id) {
//------------------------------------------------------------------------------
void nrf_app::get_subscription_list(
const std::string& profile_id, const uint8_t& notification_type,
std::vector<std::string>& uris) const {
std::vector<std::string>& uris, uint8_t& http_version) const {
Logger::nrf_app().info(
"\tGet the list of subscriptions related to this profile, profile id %s",
profile_id.c_str());
......@@ -1123,6 +1126,8 @@ void nrf_app::get_subscription_list(
std::string uri;
s.second.get()->get_notification_uri(uri);
http_version = s.second.get()->get_http_version();
// check notification event type
bool match_notif_type = false;
for (auto i : s.second.get()->get_notif_events()) {
......
......@@ -409,7 +409,7 @@ class nrf_app {
*/
void get_subscription_list(
const std::string& profile_id, const uint8_t& notification_type,
std::vector<std::string>& uris) const;
std::vector<std::string>& uris, uint8_t& http_version) const;
/*
* Verify whether the requester is allowed to discover the NF services
......
......@@ -88,8 +88,8 @@ nrf_client::~nrf_client() {
//------------------------------------------------------------------------------
CURL* nrf_client::curl_create_handle(
const std::string& uri, const std::string& data,
std::string& response_data) {
const std::string& uri, const std::string& data, std::string& response_data,
uint8_t http_version) {
// create handle for a curl request
CURL* curl = curl_easy_init();
......@@ -106,17 +106,26 @@ CURL* nrf_client::curl_create_handle(
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
if (http_version == 2) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
// curl_easy_setopt(curl, CURLOPT_PORT, 8080);
// We use a self-signed test server, skip verification during debugging
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(
curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
}
}
return curl;
}
//------------------------------------------------------------------------------
void nrf_client::send_curl_multi(
const std::string& uri, const std::string& data,
std::string& response_data) {
const std::string& uri, const std::string& data, std::string& response_data,
uint8_t http_version) {
// create a new handle and add to the multi handle
// the curl will actually be sent in perform_curl_multi
CURL* tmp = curl_create_handle(uri, data, response_data);
CURL* tmp = curl_create_handle(uri, data, response_data, http_version);
curl_multi_add_handle(curl_multi, tmp);
handles.push_back(tmp);
}
......@@ -209,9 +218,11 @@ void nrf_client::curl_release_handles() {
//------------------------------------------------------------------------------
void nrf_client::notify_subscribed_event(
const std::shared_ptr<nrf_profile>& profile, const uint8_t& event_type,
const std::vector<std::string>& uris) {
const std::vector<std::string>& uris, uint8_t http_version) {
Logger::nrf_app().debug(
"Send notification for the subscribed event to the subscriptions");
"Send notification for the subscribed event to the subscriptions (HTTP "
"VERSION %d)",
http_version);
std::map<std::string, std::string> responses = {};
// Fill the json part
......@@ -255,7 +266,7 @@ void nrf_client::notify_subscribed_event(
for (auto uri : uris) {
responses[uri] = "";
std::unique_ptr<std::string> httpData(new std::string());
send_curl_multi(uri, body, responses[uri]);
send_curl_multi(uri, body, responses[uri], http_version);
}
perform_curl_multi(
......
......@@ -64,7 +64,7 @@ class nrf_client {
*/
void notify_subscribed_event(
const std::shared_ptr<nrf_profile>& profile, const uint8_t& event_type,
const std::vector<std::string>& uris);
const std::vector<std::string>& uris, uint8_t http_version);
/*
* Create Curl handle for multi curl
......@@ -75,7 +75,7 @@ class nrf_client {
*/
CURL* curl_create_handle(
const std::string& uri, const std::string& data,
std::string& response_data);
std::string& response_data, uint8_t http_version);
/*
* Prepare to send a request using curl multi
......@@ -86,7 +86,7 @@ class nrf_client {
*/
void send_curl_multi(
const std::string& uri, const std::string& data,
std::string& response_data);
std::string& response_data, uint8_t http_version);
/*
* Perform curl multi to actually process the available data
......
......@@ -115,6 +115,16 @@ boost::posix_time::ptime nrf_subscription::get_validity_time() const {
return validity_time;
}
//------------------------------------------------------------------------------
void nrf_subscription::set_http_version(const uint8_t& httpVersion) {
http_version = httpVersion;
}
//------------------------------------------------------------------------------
uint8_t nrf_subscription::get_http_version() const{
return http_version;
}
//------------------------------------------------------------------------------
void nrf_subscription::display() {
Logger::nrf_app().debug("Subscription information");
......
......@@ -157,7 +157,19 @@ class nrf_subscription {
* @return [boost::posix_time::ptime &] validity time
*/
boost::posix_time::ptime get_validity_time() const;
/*
* Set the http_version
* @param [uint8_t&]: http_version: http_version
* @return void
*/
void set_http_version(const uint8_t& http_version);
/*
* Get the http_version
* @param [void]
* @return http_version
*/
uint8_t get_http_version() const;
/*
* Subscribe to be notified when a new NF registered to the NRF
* @param void
......@@ -188,6 +200,7 @@ class nrf_subscription {
nrf_event& m_event_sub;
bs2::connection ev_connection;
boost::posix_time::ptime validity_time;
uint8_t http_version =1;
};
} // namespace app
} // namespace nrf
......
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