osaf/libs/agents/saf/clma/clma_api.c   |  85 ++++++++++++++++++++++++---------
 osaf/libs/agents/saf/clma/clma_util.c  |  14 +++++
 osaf/libs/common/clmsv/clmsv_enc_dec.c |  32 ++++++++----
 3 files changed, 96 insertions(+), 35 deletions(-)


Add support for long RDN to support RDN values longer than 64 bytes

diff --git a/osaf/libs/agents/saf/clma/clma_api.c 
b/osaf/libs/agents/saf/clma/clma_api.c
--- a/osaf/libs/agents/saf/clma/clma_api.c
+++ b/osaf/libs/agents/saf/clma/clma_api.c
@@ -31,6 +31,7 @@
 
 #include "clma.h"
 #include "ncs_main_papi.h"
+#include "osaf_extended_name.h"
 
 #define CLMS_WAIT_TIME 1000
 #define CLM_API_MIN_TIMEOUT 10 /* ten milli seconds */
@@ -84,10 +85,7 @@ void clma_fill_node_from_node4(SaClmClus
        clusterNode->nodeAddress.length = clusterNode_4.nodeAddress.length;
        (void)memcpy(clusterNode->nodeAddress.value, 
clusterNode_4.nodeAddress.value, clusterNode->nodeAddress.length);
        clusterNode->nodeName.length = clusterNode_4.nodeName.length;
-       (void)memcpy(clusterNode->nodeName.value, clusterNode_4.nodeName.value, 
clusterNode->nodeName.length);
-       clusterNode->nodeName.value[clusterNode->nodeName.length <
-               SA_MAX_NAME_LENGTH ? clusterNode->nodeName.length :
-                       SA_MAX_NAME_LENGTH - 1] = '\0';
+       
osaf_extended_name_alloc(osaf_extended_name_borrow(&clusterNode_4.nodeName), 
&clusterNode->nodeName);
        clusterNode->member = clusterNode_4.member;
        clusterNode->bootTimestamp = clusterNode_4.bootTimestamp;
        clusterNode->initialViewNumber = clusterNode_4.initialViewNumber;
@@ -119,8 +117,17 @@ static SaAisErrorT clma_validate_flags_b
 
        /* validate the notify buffer */
        if ((flags & SA_TRACK_CURRENT) && buf && buf->notification) {
+               uint32_t i;
+
                if (!buf->numberOfItems)
                        return SA_AIS_ERR_INVALID_PARAM;
+
+               // Check that nodeName is not longer than 255
+               for(i=0; i<buf->numberOfItems; i++) {
+                       
if(osaf_extended_name_length(&buf->notification[i].clusterNode.nodeName) >= 
SA_MAX_NAME_LENGTH) {
+                               return SA_AIS_ERR_INVALID_PARAM;
+                       }
+               }
        }
 
        /* Validate if flag is TRACK_CURRENT and no callback and no buffer 
provided */
@@ -160,10 +167,24 @@ static SaAisErrorT clma_validate_flags_b
 
        /* validate the notify buffer */
        if ((flags & SA_TRACK_CURRENT) && buf && buf->notification) {
+               uint32_t i;
+
                if (!buf->numberOfItems) {
                        TRACE_LEAVE();
                        return SA_AIS_ERR_INVALID_PARAM;
                }
+
+               // Check that nodeName and EE are not longer than 255
+               for(i=0; i<buf->numberOfItems; i++) {
+                       
if(osaf_extended_name_length(&buf->notification[i].clusterNode.nodeName) >= 
SA_MAX_NAME_LENGTH) {
+                               TRACE_LEAVE();
+                               return SA_AIS_ERR_INVALID_PARAM;
+                       }
+                       
if(osaf_extended_name_length(&buf->notification[i].clusterNode.executionEnvironment)
 >= SA_MAX_NAME_LENGTH) {
+                               TRACE_LEAVE();
+                               return SA_AIS_ERR_INVALID_PARAM;
+                       }
+               }
        }
 
        /* Validate if flag is TRACK_CURRENT and no callback and no buffer 
provided */
@@ -228,16 +249,18 @@ static SaAisErrorT clma_fill_cluster_ntf
                return SA_AIS_ERR_NO_MEMORY;
 
        if (buf_4->notification != NULL &&
-           (buf_4->numberOfItems >= 
msg_rsp->info.api_resp_info.param.track.notify_info->numberOfItems)) {
+                       (buf_4->numberOfItems >= 
msg_rsp->info.api_resp_info.param.track.notify_info->numberOfItems)) {
                /* Overwrite the numberOfItems and copy it to buffer */
                buf_4->numberOfItems = 
msg_rsp->info.api_resp_info.param.track.notify_info->numberOfItems;
                buf_4->viewNumber = 
msg_rsp->info.api_resp_info.param.track.notify_info->viewNumber;
 
                memset(buf_4->notification, 0, 
sizeof(SaClmClusterNotificationT_4) * buf_4->numberOfItems);
                memcpy(buf_4->notification, 
msg_rsp->info.api_resp_info.param.track.notify_info->notification,
-                      sizeof(SaClmClusterNotificationT_4) * 
buf_4->numberOfItems);
-        } else if(buf_4->notification != NULL &&
-               (buf_4->numberOfItems < 
msg_rsp->info.api_resp_info.param.track.notify_info->numberOfItems)) {
+                               sizeof(SaClmClusterNotificationT_4) * 
buf_4->numberOfItems);
+
+               /* TODO: Code for copying long DNs for nodeName and EE when 
full long DN support is implemented. */
+       } else if(buf_4->notification != NULL &&
+                       (buf_4->numberOfItems < 
msg_rsp->info.api_resp_info.param.track.notify_info->numberOfItems)) {
                return SA_AIS_ERR_NO_SPACE;
        } else {
                /* we need to ignore the numberOfItems and allocate the space
@@ -250,6 +273,7 @@ static SaAisErrorT clma_fill_cluster_ntf
                memcpy(buf_4->notification, 
msg_rsp->info.api_resp_info.param.track.notify_info->notification,
                       sizeof(SaClmClusterNotificationT_4) * 
buf_4->numberOfItems);
 
+               /* TODO: Code for copying long DNs for nodeName and EE when 
full long DN support is implemented. */
        }
        return SA_AIS_OK;
 }
@@ -470,10 +494,8 @@ void clma_fill_clusterbuf_from_buf_4(SaC
                (void)memcpy(buf->notification[i].clusterNode.nodeAddress.value,
                             
buf_4->notification[i].clusterNode.nodeAddress.value,
                             
buf->notification[i].clusterNode.nodeAddress.length);
-               buf->notification[i].clusterNode.nodeName.length = 
buf_4->notification[i].clusterNode.nodeName.length;
-               (void)memcpy(buf->notification[i].clusterNode.nodeName.value,
-                            buf_4->notification[i].clusterNode.nodeName.value,
-                            buf->notification[i].clusterNode.nodeName.length);
+               
osaf_extended_name_alloc(osaf_extended_name_borrow(&buf_4->notification[i].clusterNode.nodeName),
+                               &buf->notification[i].clusterNode.nodeName);
                buf->notification[i].clusterNode.member = 
buf_4->notification[i].clusterNode.member;
                buf->notification[i].clusterNode.bootTimestamp = 
buf_4->notification[i].clusterNode.bootTimestamp;
                buf->notification[i].clusterNode.initialViewNumber =
@@ -1311,11 +1333,11 @@ static SaAisErrorT clmaclusternodeget(Sa
                }
        }
 
-        if((hdl_rec->is_configured == false) && 
(!clma_validate_version(hdl_rec->version))) {
-                TRACE("Node is unconfigured");
-                rc = SA_AIS_ERR_UNAVAILABLE;
-                goto done_give_hdl; 
-        }
+       if((hdl_rec->is_configured == false) && 
(!clma_validate_version(hdl_rec->version))) {
+               TRACE("Node is unconfigured");
+               rc = SA_AIS_ERR_UNAVAILABLE;
+               goto done_give_hdl;
+       }
 
        if((hdl_rec->is_member == false) && 
(!clma_validate_version(hdl_rec->version))) { 
                TRACE("Node is not a member");
@@ -1351,12 +1373,25 @@ static SaAisErrorT clmaclusternodeget(Sa
        } else
                rc = SA_AIS_ERR_NO_RESOURCES;
 
+       if (rc == SA_AIS_OK
+                       && 
osaf_extended_name_length(&o_msg->info.api_resp_info.param.node_get.nodeName) 
>= SA_MAX_NAME_LENGTH) {
+               TRACE("nodeName is longer than 255");
+               rc = SA_AIS_ERR_NO_RESOURCES;
+       }
+
        if (rc == SA_AIS_OK) {
                if (clma_validate_version(hdl_rec->version)) {
                        clma_fill_node_from_node4(cluster_node, 
o_msg->info.api_resp_info.param.node_get);
-               } else {
+               } else 
if(osaf_extended_name_length(&o_msg->info.api_resp_info.param.node_get.executionEnvironment)
 < SA_MAX_NAME_LENGTH) {
                        memset(cluster_node_4, 0, sizeof(SaClmClusterNodeT_4));
                        memcpy(cluster_node_4, 
&o_msg->info.api_resp_info.param.node_get, sizeof(SaClmClusterNodeT_4));
+                       /* TODO: When full long DN support is implemented, 
remove comment to ensure that long DN is safely copied.
+                        * Now it's overhead for copying the same data. */
+                       
//osaf_extended_name_alloc(osaf_extended_name_borrow(&o_msg->info.api_resp_info.param.node_get.nodeName),
 &cluster_node_4->nodeName);
+                       
//osaf_extended_name_alloc(osaf_extended_name_borrow(&o_msg->info.api_resp_info.param.node_get.executionEnvironment),
 &cluster_node_4->executionEnvironment);
+               } else {
+                       TRACE("executionEnvironment is longer than 255");
+                       rc = SA_AIS_ERR_NO_RESOURCES;
                }
        }
 
@@ -1512,11 +1547,15 @@ SaAisErrorT saClmClusterNotificationFree
                goto done_give_hdl;
        }
 
-        if((hdl_rec->is_configured == false) && 
(!clma_validate_version(hdl_rec->version))) {
-                TRACE("Node is unconfigured");
-                rc = SA_AIS_ERR_UNAVAILABLE;
-                goto done_give_hdl; 
-        }
+       if((hdl_rec->is_configured == false) && 
(!clma_validate_version(hdl_rec->version))) {
+               TRACE("Node is unconfigured");
+               rc = SA_AIS_ERR_UNAVAILABLE;
+               goto done_give_hdl;
+       }
+
+       // Free allocated memory for long DN
+       osaf_extended_name_free(&notification->clusterNode.nodeName);
+       
osaf_extended_name_free(&notification->clusterNode.executionEnvironment);
 
        free(notification);
 
diff --git a/osaf/libs/agents/saf/clma/clma_util.c 
b/osaf/libs/agents/saf/clma/clma_util.c
--- a/osaf/libs/agents/saf/clma/clma_util.c
+++ b/osaf/libs/agents/saf/clma/clma_util.c
@@ -659,6 +659,13 @@ void clma_msg_destroy(CLMSV_MSG * msg)
 
        if (msg->evt_type == CLMSV_CLMS_TO_CLMA_API_RESP_MSG) {
                if (msg->info.api_resp_info.type == CLMSV_TRACK_CURRENT_RESP) {
+                       /* TODO: if long DN longer than 255 characters is fully 
implemented
+                        * then freeing of each SaNameT in notification list 
must be done
+                        * 
msg->info.api_resp_info.param.track.notify_info->notification->clusterNode.nodeName
+                        * and
+                        * 
msg->info.api_resp_info.param.track.notify_info->notification->clusterNode.executionEnvironment
+                        * must be done here
+                        */
                        if 
(msg->info.api_resp_info.param.track.notify_info->numberOfItems)
                                
free(msg->info.api_resp_info.param.track.notify_info->notification);
 
@@ -666,6 +673,13 @@ void clma_msg_destroy(CLMSV_MSG * msg)
                }
        } else if (msg->evt_type == CLMSV_CLMS_TO_CLMA_CBK_MSG) {
                if (msg->info.cbk_info.type == CLMSV_TRACK_CBK) {
+                       /* TODO: if long DN longer than 255 characters is fully 
implemented
+                        * then freeing of each SaNameT in notification list
+                        * 
msg->info.cbk_info.param.track.buf_info.notification->clusterNode.nodeName
+                        * and
+                        * 
msg->info.cbk_info.param.track.buf_info.notification->clusterNode.executionEnvironment
+                        * must be done here
+                        */
                        if 
(msg->info.cbk_info.param.track.buf_info.numberOfItems)
                                
free(msg->info.cbk_info.param.track.buf_info.notification);
 
diff --git a/osaf/libs/common/clmsv/clmsv_enc_dec.c 
b/osaf/libs/common/clmsv/clmsv_enc_dec.c
--- a/osaf/libs/common/clmsv/clmsv_enc_dec.c
+++ b/osaf/libs/common/clmsv/clmsv_enc_dec.c
@@ -17,26 +17,32 @@
 #include <ncsencdec_pub.h>
 #include "clmsv_enc_dec.h"
 #include "clmsv_msg.h"
+#include "osaf_extended_name.h"
 
 uint32_t clmsv_decodeSaNameT(NCS_UBAID *uba, SaNameT *name)
 {
        uint8_t local_data[2];
        uint8_t *p8 = NULL;
        uint32_t total_bytes = 0;
+       uint16_t length;
+       char valueBuffer[256];
+       char *value = valueBuffer;
 
        p8 = ncs_dec_flatten_space(uba, local_data, 2);
-       name->length = ncs_decode_16bit(&p8);
-       if (name->length > SA_MAX_NAME_LENGTH) {
-               LOG_ER("SaNameT length too long: %hd", name->length);
+       length = ncs_decode_16bit(&p8);
+       if (!osaf_is_extended_names_enabled() && length >= SA_MAX_NAME_LENGTH) {
+               LOG_ER("SaNameT length too long: %hd", length);
                /* this should not happen */
                osafassert(0);
        }
+       if(length >= SA_MAX_NAME_LENGTH) {
+               value = (char *)calloc(1, length + 1);
+       }
        ncs_dec_skip_space(uba, 2);
        total_bytes += 2;
-       ncs_decode_n_octets_from_uba(uba, name->value, (uint32_t)name->length);
-       name->value[name->length < SA_MAX_NAME_LENGTH ? name->length :
-               SA_MAX_NAME_LENGTH - 1] = '\0';
-       total_bytes += name->length;
+       ncs_decode_n_octets_from_uba(uba, (uint8_t *)value, (uint32_t)length);
+       osaf_extended_name_lend(value, name);
+       total_bytes += length;
        return total_bytes;
 }
 
@@ -63,7 +69,6 @@ uint32_t clmsv_decodeNodeAddressT(NCS_UB
        ncs_decode_n_octets_from_uba(uba, nodeAddress->value, 
(uint32_t)nodeAddress->length);
        total_bytes += nodeAddress->length;
        return total_bytes;
-
 }
 
 uint32_t clmsv_encodeSaNameT(NCS_UBAID *uba, SaNameT *name)
@@ -71,20 +76,23 @@ uint32_t clmsv_encodeSaNameT(NCS_UBAID *
        TRACE_ENTER();
        uint8_t *p8 = NULL;
        uint32_t total_bytes = 0;
+       size_t length;
+
        p8 = ncs_enc_reserve_space(uba, 2);
        if (!p8) {
                TRACE("p8 NULL!!!");
                return 0;
        }
-       if (name->length > SA_MAX_NAME_LENGTH) {
+       if (!osaf_is_extended_names_enabled() && name->length >= 
SA_MAX_NAME_LENGTH) {
                LOG_ER("SaNameT length too long %hd", name->length);
                osafassert(0);
        }
-       ncs_encode_16bit(&p8, name->length);
+       length = osaf_extended_name_length(name);
+       ncs_encode_16bit(&p8, length);
        ncs_enc_claim_space(uba, 2);
        total_bytes += 2;
-       ncs_encode_n_octets_in_uba(uba, name->value, (uint32_t)name->length);
-       total_bytes += (uint32_t)name->length;
+       ncs_encode_n_octets_in_uba(uba, (uint8_t 
*)osaf_extended_name_borrow(name), length);
+       total_bytes += (uint32_t)length;
        TRACE_LEAVE();
        return total_bytes;
 }

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to