From 58bd5631e360277dffa96cbd5dc7e1358cc981f3 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Wed, 19 Feb 2020 17:51:37 +0000 Subject: [PATCH] Starting to change map in HSS to use uinque_ptr. --- srsepc/hdr/hss/hss.h | 4 ++-- srsepc/src/hss/hss.cc | 21 +++++++-------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/srsepc/hdr/hss/hss.h b/srsepc/hdr/hss/hss.h index 4089396a9..6b05a4ecf 100644 --- a/srsepc/hdr/hss/hss.h +++ b/srsepc/hdr/hss/hss.h @@ -87,7 +87,7 @@ private: virtual ~hss(); static hss* m_instance; - std::map m_imsi_to_ue_ctx; + std::map > m_imsi_to_ue_ctx; void gen_rand(uint8_t rand_[16]); bool get_k_amf_opc_sqn(uint64_t imsi, uint8_t* k, uint8_t* amf, uint8_t* opc, uint8_t* sqn); @@ -112,7 +112,7 @@ private: bool set_auth_algo(std::string auth_algo); bool read_db_file(std::string db_file); bool write_db_file(std::string db_file); - bool get_ue_ctx(uint64_t imsi, hss_ue_ctx_t** ue_ctx); + const std::unique_ptr& get_ue_ctx(uint64_t imsi); std::string hex_string(uint8_t* hex, int size); diff --git a/srsepc/src/hss/hss.cc b/srsepc/src/hss/hss.cc index 7e3122b62..2630c553d 100644 --- a/srsepc/src/hss/hss.cc +++ b/srsepc/src/hss/hss.cc @@ -87,13 +87,6 @@ int hss::init(hss_args_t* hss_args, srslte::log_filter* hss_log) void hss::stop() { write_db_file(db_file); - std::map::iterator it = m_imsi_to_ue_ctx.begin(); - while (it != m_imsi_to_ue_ctx.end()) { - m_hss_log->info("Deleting UE context in HSS. IMSI: %015" PRIu64 "\n", it->second->imsi); - m_hss_log->console("Deleting UE context in HSS. IMSI: %015" PRIu64 "\n", it->second->imsi); - delete it->second; - m_imsi_to_ue_ctx.erase(it++); - } return; } @@ -223,7 +216,7 @@ bool hss::write_db_file(std::string db_filename) << "# \n" << "# Note: Lines starting by '#' are ignored and will be overwritten \n"; - std::map::iterator it = m_imsi_to_ue_ctx.begin(); + std::map >::iterator it = m_imsi_to_ue_ctx.begin(); while (it != m_imsi_to_ue_ctx.end()) { m_db_file << it->second->name; m_db_file << ","; @@ -435,13 +428,13 @@ bool hss::gen_auth_info_answer_xor(uint64_t imsi, uint8_t* k_asme, uint8_t* autn bool hss::gen_update_loc_answer(uint64_t imsi, uint8_t* qci) { - std::map::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); + std::map >::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); if (ue_ctx_it == m_imsi_to_ue_ctx.end()) { m_hss_log->info("User not found. IMSI: %015" PRIu64 "\n", imsi); m_hss_log->console("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi); return false; } - hss_ue_ctx_t* ue_ctx = ue_ctx_it->second; + const std::unique_ptr& ue_ctx = ue_ctx_it->second; m_hss_log->info("Found User %015" PRIu64 "\n", imsi); *qci = ue_ctx->qci; return true; @@ -449,13 +442,13 @@ bool hss::gen_update_loc_answer(uint64_t imsi, uint8_t* qci) bool hss::get_k_amf_opc_sqn(uint64_t imsi, uint8_t* k, uint8_t* amf, uint8_t* opc, uint8_t* sqn) { - std::map::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); + std::map >::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); if (ue_ctx_it == m_imsi_to_ue_ctx.end()) { m_hss_log->info("User not found. IMSI: %015" PRIu64 "\n", imsi); m_hss_log->console("User not found at HSS. IMSI: %015" PRIu64 "\n", imsi); return false; } - hss_ue_ctx_t* ue_ctx = ue_ctx_it->second; + const std::unique_ptr& ue_ctx = ue_ctx_it->second; m_hss_log->info("Found User %015" PRIu64 "\n", imsi); memcpy(k, ue_ctx->key, 16); memcpy(amf, ue_ctx->amf, 2); @@ -670,9 +663,9 @@ void hss::gen_rand(uint8_t rand_[16]) return; } -bool hss::get_ue_ctx(uint64_t imsi, hss_ue_ctx_t** ue_ctx) +const std::unique_ptr& hss::get_ue_ctx(uint64_t imsi) { - std::map::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); + std::map >::iterator ue_ctx_it = m_imsi_to_ue_ctx.find(imsi); if (ue_ctx_it == m_imsi_to_ue_ctx.end()) { m_hss_log->info("User not found. IMSI: %015" PRIu64 "\n", imsi); return false;