ack, code review only/Thanks HansN
On 01/25/2016 05:35 AM, Gary Lee wrote:
> osaf/services/saf/amf/amfd/util.cc | 205
> ++++++++++++++++++++++--------------
> 1 files changed, 126 insertions(+), 79 deletions(-)
>
>
> diff --git a/osaf/services/saf/amf/amfd/util.cc
> b/osaf/services/saf/amf/amfd/util.cc
> --- a/osaf/services/saf/amf/amfd/util.cc
> +++ b/osaf/services/saf/amf/amfd/util.cc
> @@ -24,6 +24,7 @@
>
> ******************************************************************************
> */
>
> +#include <algorithm>
> #include <vector>
> #include <string.h>
>
> @@ -361,16 +362,18 @@
> AVD_AVND *node = su->get_node_ptr();
>
> TRACE_ENTER2("%s '%s'", (term_state == true) ? "Terminate" :
> "Instantiate",
> - su->name.value);
> + su->name.c_str());
>
> /* prepare the node update message. */
> d2n_msg = new AVSV_DND_MSG();
> +
> + const SaNameTWrapper su_name(su->name);
>
> /* prepare the SU presence state change notification message */
> d2n_msg->msg_type = AVSV_D2N_PRESENCE_SU_MSG;
> d2n_msg->msg_info.d2n_prsc_su.msg_id = ++(node->snd_msg_id);
> d2n_msg->msg_info.d2n_prsc_su.node_id = node->node_info.nodeId;
> - d2n_msg->msg_info.d2n_prsc_su.su_name = su->name;
> + d2n_msg->msg_info.d2n_prsc_su.su_name = su_name;
> d2n_msg->msg_info.d2n_prsc_su.term_state = term_state;
>
> TRACE("Sending %u to %x", AVSV_D2N_PRESENCE_SU_MSG,
> node->node_info.nodeId);
> @@ -472,8 +475,9 @@
> static void reg_su_msg_init_su_info(AVD_DND_MSG *su_msg, const AVD_SU *su)
> {
> AVSV_SU_INFO_MSG *su_info = new AVSV_SU_INFO_MSG();
> + const SaNameTWrapper su_name(su->name);
>
> - su_info->name = su->name;
> + su_info->name = su_name;
> su_info->comp_restart_max = su->sg_of_su->saAmfSGCompRestartMax;
> su_info->comp_restart_prob = su->sg_of_su->saAmfSGCompRestartProb;
> su_info->su_restart_max = su->sg_of_su->saAmfSGSuRestartMax;
> @@ -508,7 +512,7 @@
> AVD_SU *su = nullptr;
> uint32_t rc = NCSCC_RC_SUCCESS;
>
> - TRACE_ENTER2("%s", avnd->node_name);
> + TRACE_ENTER2("%s", avnd->node_name.c_str());
>
> AVD_DND_MSG *su_msg = new AVSV_DND_MSG();
> su_msg->msg_type = AVSV_D2N_REG_SU_MSG;
> @@ -557,11 +561,11 @@
> * free messages and return error.
> */
>
> - TRACE("Sending AVSV_D2N_REG_SU_MSG to %s", avnd->node_name);
> + TRACE("Sending AVSV_D2N_REG_SU_MSG to %s", avnd->node_name.c_str());
>
> if (avd_d2n_msg_snd(cb, avnd, su_msg) == NCSCC_RC_FAILURE) {
> --(avnd->snd_msg_id);
> - LOG_ER("%s: snd to %s failed", __FUNCTION__, avnd->node_name);
> + LOG_ER("%s: snd to %s failed", __FUNCTION__,
> avnd->node_name.c_str());
> d2n_msg_free(su_msg);
> rc = NCSCC_RC_FAILURE;
> goto done;
> @@ -680,8 +684,10 @@
> const AVD_COMP *comp)
> {
> SaNameT dn;
> - avsv_create_association_class_dn(&csi->cstype->name,
> - &comp->comp_type->name, "safSupportedCsType", &dn);
> + const SaNameTWrapper cstype_name(csi->cstype->name);
> + const SaNameTWrapper comp_type_name(comp->comp_type->name);
> + avsv_create_association_class_dn(cstype_name,
> + comp_type_name, "safSupportedCsType", &dn);
> AVD_CTCS_TYPE *ctcs_type = ctcstype_db->find(Amf::to_string(&dn));
> return ctcs_type->saAmfCtCompCapability;
> }
> @@ -733,10 +739,17 @@
>
> /* prepare the SU SI message. */
> susi_msg = new AVSV_DND_MSG();
> + const SaNameTWrapper su_name(su->name);
> + SaNameTWrapper csi_name("");
> + SaNameTWrapper si_name("");
> +
> + if (susi != AVD_SU_SI_REL_NULL) {
> + si_name.set(susi->si->name);
> + }
>
> susi_msg->msg_type = AVSV_D2N_INFO_SU_SI_ASSIGN_MSG;
> susi_msg->msg_info.d2n_su_si_assign.node_id = avnd->node_info.nodeId;
> - susi_msg->msg_info.d2n_su_si_assign.su_name = su->name;
> + susi_msg->msg_info.d2n_su_si_assign.su_name = su_name;
> susi_msg->msg_info.d2n_su_si_assign.msg_act = actn;
>
> if (true == single_csi) {
> @@ -748,7 +761,7 @@
> /* Means we need to delete only this SU SI assignment
> for
> * this SU.
> */
> - susi_msg->msg_info.d2n_su_si_assign.si_name =
> susi->si->name;
> + susi_msg->msg_info.d2n_su_si_assign.si_name = si_name;
>
> /* For only these options fill the comp CSI values. */
> if (true == single_csi) {
> @@ -758,7 +771,8 @@
> compcsi_info = new AVSV_SUSI_ASGN();
>
> compcsi_info->comp_name =
> l_compcsi->comp->comp_info.name;
> - compcsi_info->csi_name = l_compcsi->csi->name;
> + csi_name.set(l_compcsi->csi->name);
> + compcsi_info->csi_name = csi_name;
> susi_msg->msg_info.d2n_su_si_assign.num_assigns
> = 1;
> susi_msg->msg_info.d2n_su_si_assign.list =
> compcsi_info;
> }
> @@ -813,7 +827,7 @@
> /* for modifications of a SU SI fill the SI name.
> */
>
> - susi_msg->msg_info.d2n_su_si_assign.si_name =
> susi->si->name;
> + susi_msg->msg_info.d2n_su_si_assign.si_name = si_name;
> susi_msg->msg_info.d2n_su_si_assign.ha_state =
> susi->state;
>
> l_susi = susi;
> @@ -837,7 +851,7 @@
> /* for new assignments of a SU SI fill the SI name.
> */
>
> - susi_msg->msg_info.d2n_su_si_assign.si_name = susi->si->name;
> + susi_msg->msg_info.d2n_su_si_assign.si_name = si_name;
> susi_msg->msg_info.d2n_su_si_assign.ha_state = susi->state;
> susi_msg->msg_info.d2n_su_si_assign.si_rank =
> susi->si->saAmfSIRank;
>
> @@ -902,7 +916,8 @@
> compcsi_info = new AVSV_SUSI_ASGN();
>
> compcsi_info->comp_name =
> l_compcsi->comp->comp_info.name;
> - compcsi_info->csi_name = l_compcsi->csi->name;
> + csi_name.set(l_compcsi->csi->name);
> + compcsi_info->csi_name = csi_name;
> compcsi_info->csi_rank = l_compcsi->csi->rank;
> compcsi_info->active_comp_dsc = trans_dsc;
> compcsi_info->capability =
> @@ -1108,12 +1123,12 @@
> **************************************************************************/
> uint32_t avd_snd_pg_upd_msg(AVD_CL_CB *cb,
> AVD_AVND *node,
> - AVD_COMP_CSI_REL *comp_csi,
> SaAmfProtectionGroupChangesT change, SaNameT *csi_name)
> + AVD_COMP_CSI_REL *comp_csi,
> SaAmfProtectionGroupChangesT change, const std::string& csi_name)
> {
> AVD_DND_MSG *pg_msg = 0;
> uint32_t rc = NCSCC_RC_SUCCESS;
> AVSV_D2N_PG_UPD_MSG_INFO *pg_msg_info = 0;
> -
> + SaNameTWrapper temp_csi_name("");
> TRACE_ENTER();
>
> /* alloc the update msg */
> @@ -1124,16 +1139,18 @@
> /* populate the msg */
> pg_msg->msg_type = AVSV_D2N_PG_UPD_MSG;
> pg_msg_info->node_id = node->node_info.nodeId;
> - pg_msg_info->is_csi_del = (csi_name) ? true : false;
> + pg_msg_info->is_csi_del = (csi_name.empty() == false) ? true : false;
> if (false == pg_msg_info->is_csi_del) {
> - pg_msg_info->csi_name = comp_csi->csi->name;
> + temp_csi_name.set(comp_csi->csi->name);
> + pg_msg_info->csi_name = temp_csi_name;
> pg_msg_info->mem.member.compName =
> comp_csi->comp->comp_info.name;
> pg_msg_info->mem.member.haState = comp_csi->susi->state;
> pg_msg_info->mem.member.rank = comp_csi->comp->su->saAmfSURank;
> pg_msg_info->mem.change = change;
> - } else
> - pg_msg_info->csi_name = *csi_name;
> -
> + } else {
> + temp_csi_name.set(csi_name);
> + pg_msg_info->csi_name = temp_csi_name;
> + }
> /* send the msg to avnd */
> TRACE("Sending %u to %x", AVSV_D2N_PG_UPD_MSG, node->node_info.nodeId);
>
> @@ -1425,7 +1442,7 @@
> for (std::map<uint32_t, AVD_AVND *>::const_iterator it =
> node_id_db->begin();
> it != node_id_db->end(); it++) {
> AVD_AVND *node = it->second;
> - fprintf(f, " dn: %s\n", node->name.value);
> + fprintf(f, " dn: %s\n", node->name.c_str());
> fprintf(f, " saAmfNodeAdminState: %s\n",
> avd_adm_state_name[node->saAmfNodeAdminState]);
> fprintf(f, " saAmfNodeOperState: %s\n",
> @@ -1442,7 +1459,7 @@
> for (std::map<std::string, AVD_APP*>::const_iterator it =
> app_db->begin();
> it != app_db->end(); it++) {
> const AVD_APP *app = it->second;
> - fprintf(f, " dn: %s\n", app->name.value);
> + fprintf(f, " dn: %s\n", app->name.c_str());
> fprintf(f, " saAmfApplicationAdminState: %s\n",
>
> avd_adm_state_name[app->saAmfApplicationAdminState]);
> fprintf(f, " saAmfApplicationCurrNumSGs: %u\n",
> @@ -1453,9 +1470,9 @@
> for (std::map<std::string, AVD_SI*>::const_iterator it = si_db->begin();
> it != si_db->end(); it++) {
> si = it->second;
> - fprintf(f, " dn: %s\n", si->name.value);
> + fprintf(f, " dn: %s\n", si->name.c_str());
> fprintf(f, " saAmfSIProtectedbySG: %s\n",
> - si->saAmfSIProtectedbySG.value);
> + si->saAmfSIProtectedbySG.c_str());
> fprintf(f, " saAmfSIAdminState: %s\n",
> avd_adm_state_name[si->saAmfSIAdminState]);
> fprintf(f, " saAmfSIAssignmentState: %s\n",
> @@ -1470,7 +1487,7 @@
> fprintf(f, " alarm_sent: %u\n", si->alarm_sent);
> fprintf(f, " assigned_to_sus:\n");
> for (susi = si->list_of_sisu; susi; susi = susi->si_next) {
> - fprintf(f, " dn: %s\n", susi->su->name.value);
> + fprintf(f, " dn: %s\n", susi->su->name.c_str());
> fprintf(f, " hastate: %s\n",
> avd_ha_state[susi->state]);
> fprintf(f, " fsm: %u\n", susi->fsm);
> }
> @@ -1480,12 +1497,12 @@
> for (std::map<std::string, AVD_CSI*>::const_iterator it =
> csi_db->begin();
> it != csi_db->end(); it++) {
> csi = it->second;
> - fprintf(f, " dn: %s\n", csi->name.value);
> + fprintf(f, " dn: %s\n", csi->name.c_str());
> fprintf(f, " rank: %u\n", csi->rank);
> fprintf(f, " depends:\n");
> AVD_CSI_DEPS *dep;
> for (dep = csi->saAmfCSIDependencies; dep; dep =
> dep->csi_dep_next)
> - fprintf(f, " %s", dep->csi_dep_name_value.value);
> + fprintf(f, " %s", dep->csi_dep_name_value.c_str());
> if (csi->saAmfCSIDependencies)
> fprintf(f, "\n");
> fprintf(f, " assigned_to_components:\n");
> @@ -1499,7 +1516,7 @@
> for (std::map<std::string, AVD_SG*>::const_iterator it = sg_db->begin();
> it != sg_db->end(); it++) {
> const AVD_SG *sg = it->second;
> - fprintf(f, " dn: %s\n", sg->name.value);
> + fprintf(f, " dn: %s\n", sg->name.c_str());
> fprintf(f, " saAmfSGAdminState: %s\n",
> avd_adm_state_name[sg->saAmfSGAdminState]);
> fprintf(f, " saAmfSGNumCurrAssignedSUs: %u\n",
> @@ -1516,7 +1533,7 @@
> for (std::map<std::string, AVD_SU*>::const_iterator it = su_db->begin();
> it != su_db->end(); it++) {
> const AVD_SU *su = it->second;
> - fprintf(f, " dn: %s\n", su->name.value);
> + fprintf(f, " dn: %s\n", su->name.c_str());
> fprintf(f, " saAmfSUPreInstantiable: %u\n",
> su->saAmfSUPreInstantiable);
> fprintf(f, " saAmfSUOperState: %s\n",
> avd_oper_state_name[su->saAmfSUOperState]);
> @@ -1526,7 +1543,7 @@
>
> avd_readiness_state_name[su->saAmfSuReadinessState]);
> fprintf(f, " saAmfSUPresenceState: %s\n",
> avd_pres_state_name[su->saAmfSUPresenceState]);
> - fprintf(f, " saAmfSUHostedByNode: %s\n",
> su->saAmfSUHostedByNode.value);
> + fprintf(f, " saAmfSUHostedByNode: %s\n",
> su->saAmfSUHostedByNode.c_str());
> fprintf(f, " saAmfSUNumCurrActiveSIs: %u\n",
> su->saAmfSUNumCurrActiveSIs);
> fprintf(f, " saAmfSUNumCurrStandbySIs: %u\n",
> su->saAmfSUNumCurrStandbySIs);
> fprintf(f, " saAmfSURestartCount: %u\n",
> su->saAmfSURestartCount);
> @@ -1534,7 +1551,7 @@
> fprintf(f, " su_switch: %u\n", su->su_switch);
> fprintf(f, " assigned_SIs:\n");
> for (susi = su->list_of_susi; susi != nullptr; susi =
> susi->su_next) {
> - fprintf(f, " dn: %s\n", susi->si->name.value);
> + fprintf(f, " dn: %s\n", susi->si->name.c_str());
> fprintf(f, " hastate: %s\n",
> avd_ha_state[susi->state]);
> fprintf(f, " fsm: %u\n", susi->fsm);
> }
> @@ -1552,15 +1569,15 @@
> fprintf(f, " saAmfCompPresenceState: %s\n",
>
> avd_pres_state_name[comp->saAmfCompPresenceState]);
> fprintf(f, " saAmfCompRestartCount: %u\n",
> comp->saAmfCompRestartCount);
> - if (comp->saAmfCompCurrProxyName.length)
> - fprintf(f, " saAmfCompCurrProxyName: %s\n",
> comp->saAmfCompCurrProxyName.value);
> + if (comp->saAmfCompCurrProxyName.empty() == false)
> + fprintf(f, " saAmfCompCurrProxyName: %s\n",
> comp->saAmfCompCurrProxyName.c_str());
> }
>
> fprintf(f, "Node Groups:\n");
> for (std::map<std::string, AVD_AMF_NG*>::const_iterator it =
> nodegroup_db->begin();
> it != nodegroup_db->end(); it++) {
> AVD_AMF_NG *ng = it->second;
> - fprintf(f, " dn: %s\n", ng->name.value);
> + fprintf(f, " dn: %s\n", ng->name.c_str());
> fprintf(f, " saAmfNGAdminState:
> %s\n",avd_adm_state_name[ng->saAmfNGAdminState]);
> }
>
> @@ -1577,20 +1594,21 @@
> *
> * @return int
> */
> -int avd_admin_op_msg_snd(const SaNameT *dn, AVSV_AMF_CLASS_ID class_id,
> +int avd_admin_op_msg_snd(const std::string& dn, AVSV_AMF_CLASS_ID class_id,
> SaAmfAdminOperationIdT opId, AVD_AVND *node)
> {
> AVD_CL_CB *cb = (AVD_CL_CB *)avd_cb;
> AVD_DND_MSG *d2n_msg;
> unsigned int rc = NCSCC_RC_SUCCESS;
> + const SaNameTWrapper temp_dn(dn);
>
> - TRACE_ENTER2(" '%s' %u", dn->value, opId);
> + TRACE_ENTER2(" '%s' %u", dn.c_str(), opId);
>
> d2n_msg = new AVSV_DND_MSG();
>
> d2n_msg->msg_type = AVSV_D2N_ADMIN_OP_REQ_MSG;
> d2n_msg->msg_info.d2n_admin_op_req_info.msg_id = ++(node->snd_msg_id);
> - d2n_msg->msg_info.d2n_admin_op_req_info.dn = *dn;
> + d2n_msg->msg_info.d2n_admin_op_req_info.dn = temp_dn;
> d2n_msg->msg_info.d2n_admin_op_req_info.class_id = class_id;
> d2n_msg->msg_info.d2n_admin_op_req_info.oper_id = opId;
>
> @@ -1612,22 +1630,24 @@
> *
> * @param dn
> */
> -const char* avd_getparent(const char* dn)
> +std::string avd_getparent(const std::string& dn)
> {
> - const char* parent = dn;
> - const char* tmp_parent;
> + std::string::size_type start_pos;
> + std::string::size_type parent_pos;
>
> /* Check if there exist any escaped RDN in the DN */
> - tmp_parent = strrchr(dn, '\\');
> - if (tmp_parent != nullptr) {
> - parent = tmp_parent + 2;
> + start_pos = dn.find_last_of('\\');
> + if (start_pos == std::string::npos) {
> + start_pos = 0;
> + } else {
> + ++start_pos;
> + if (dn[start_pos] == ',') {
> + ++start_pos;
> + }
> }
> -
> - if ((parent = strchr((char*)parent, ',')) != nullptr) {
> - parent++;
> - }
> -
> - return parent;
> +
> + parent_pos = dn.find(',', start_pos);
> + return dn.substr(parent_pos + 1);
> }
>
> /**
> @@ -1636,17 +1656,18 @@
> *
> * @return bool
> */
> -bool object_exist_in_imm(const SaNameT *dn)
> +bool object_exist_in_imm(const std::string& dn)
> {
> bool rc = false;
> + const SaNameTWrapper temp_dn(dn);
> SaImmAccessorHandleT accessorHandle;
> const SaImmAttrValuesT_2 **attributes;
> SaImmAttrNameT attributeNames[] =
> {const_cast<SaImmAttrNameT>("SaImmAttrClassName"), nullptr};
>
> immutil_saImmOmAccessorInitialize(avd_cb->immOmHandle, &accessorHandle);
>
> - if (immutil_saImmOmAccessorGet_2(accessorHandle, dn, attributeNames,
> -
> (SaImmAttrValuesT_2 ***)&attributes) == SA_AIS_OK)
> + if (immutil_saImmOmAccessorGet_2(accessorHandle, temp_dn,
> attributeNames,
> + (SaImmAttrValuesT_2 ***)&attributes) == SA_AIS_OK)
> rc = true;
>
> immutil_saImmOmAccessorFinalize(accessorHandle);
> @@ -1874,45 +1895,71 @@
>
> /**
> * Gets child DN from an association DN
> - * "safDepend=safSi=SC2-NoRed\,safApp=OpenSAF,safSi=SC-2N,safApp=OpenSAF"
> + * "safDepend=safSi=SC2-NoRed\\,safApp=OpenSAF,safSi=SC-2N,safApp=OpenSAF"
> + * child DN is "safSi=SC2-NoRed,safApp=OpenSAF"
> * @param ass_dn association DN [in]
> * @param child_dn [out]
> * @return 0 at success
> */
> - int get_child_dn_from_ass_dn(const SaNameT *ass_dn, SaNameT *child_dn)
> + int get_child_dn_from_ass_dn(const std::string& ass_dn, std::string&
> child_dn)
> {
> - SaNameT _ass_dn = *ass_dn;
> -
> + std::string::size_type comma_pos;
> + std::string::size_type equal_pos;
> +
> /* find first comma and step past it */
> - char *p = strchr((char *)_ass_dn.value, ',');
> - if (p == nullptr)
> + comma_pos = ass_dn.find(',');
> + if (comma_pos == std::string::npos)
> return -1;
>
> - p++;
> -
> /* find second comma, an error if not found */
> - p = strchr(p, ',');
> - if (p == nullptr)
> + comma_pos = ass_dn.find(',', comma_pos + 1);
> + if (comma_pos == std::string::npos)
> return -1;
>
> - *p = '\0'; /* null terminate at comma before parent */
> -
> /* Skip past the RDN tag */
> - p = strchr((char *)_ass_dn.value, '=');
> - if (p == nullptr)
> + equal_pos = ass_dn.find('=');
> + if (equal_pos == std::string::npos)
> return -1;
>
> - p++;
> -
> /* copy and skip back slash */
> - int i = 0;
> - while (*p) {
> - if (*p != '\\')
> - child_dn->value[i++] = *p;
> - p++;
> - }
> -
> - child_dn->value[i] = '\0';
> - child_dn->length = i;
> - return 0;
> + child_dn = ass_dn.substr(equal_pos + 1, comma_pos - equal_pos - 1);
> + child_dn.erase(std::remove(child_dn.begin(), child_dn.end(), '\\'),
> child_dn.end());
> +
> + return 0;
> }
> +
> +int get_parent_dn_from_ass_dn(const std::string& ass_dn, std::string&
> parent_dn)
> +{
> + std::string::size_type comma_pos;
> +
> + /* find first comma and step past it */
> + comma_pos = ass_dn.find(',');
> + if (comma_pos == std::string::npos)
> + return -1;
> +
> + /* find second comma and step past it */
> + comma_pos = ass_dn.find(',', comma_pos + 1);
> + if (comma_pos == std::string::npos)
> + return -1;
> +
> + parent_dn = ass_dn.substr(comma_pos + 1);
> +
> + return 0;
> +}
> +
> +/**
> + * Initialize a DN by searching for needle in haystack
> + * @param haystack
> + * @param dn
> + * @param needle
> + */
> +void avsv_sanamet_init(const std::string& haystack, std::string& dn, const
> char *needle)
> +{
> + TRACE_ENTER();
> +
> + std::string::size_type pos = haystack.find(needle);
> + dn = haystack.substr(pos);
> + TRACE("dn %s", dn.c_str());
> +
> + TRACE_LEAVE();
> +}
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel