osaf/libs/agents/saf/ntfa/Makefile.am |   1 +
 osaf/libs/agents/saf/ntfa/ntfa.h      |   1 +
 osaf/libs/agents/saf/ntfa/ntfa_api.c  |  53 +++++++++++++++++++++++++++-------
 osaf/libs/agents/saf/ntfa/ntfa_util.c |  30 +++++++++++++------
 osaf/libs/saf/libSaNtf/Makefile.am    |   1 +
 5 files changed, 65 insertions(+), 21 deletions(-)


(1) Fix longdn deallocation followed by Agent(or client) memory owner

(2) Support SA_NTF_VALUE_LDAP_NAME in AdditionalInfo

diff --git a/osaf/libs/agents/saf/ntfa/Makefile.am 
b/osaf/libs/agents/saf/ntfa/Makefile.am
--- a/osaf/libs/agents/saf/ntfa/Makefile.am
+++ b/osaf/libs/agents/saf/ntfa/Makefile.am
@@ -25,6 +25,7 @@ noinst_HEADERS = \
 noinst_LTLIBRARIES = libntfa.la
 
 libntfa_la_CPPFLAGS = \
+       -DSA_EXTENDED_NAME_SOURCE \
        $(AM_CPPFLAGS) \
        -I$(top_srcdir)/osaf/libs/common/ntfsv/include
 
diff --git a/osaf/libs/agents/saf/ntfa/ntfa.h b/osaf/libs/agents/saf/ntfa/ntfa.h
--- a/osaf/libs/agents/saf/ntfa/ntfa.h
+++ b/osaf/libs/agents/saf/ntfa/ntfa.h
@@ -61,6 +61,7 @@ typedef struct ntfa_notification_hdl_rec
        struct ntfa_client_hdl_rec *parent_hdl; /* Back Pointer to the client 
instantiation */
        SaNtfNotificationsT *cbk_notification;
        v_data variable_data;
+       bool is_longdn_agent_owner;
 } ntfa_notification_hdl_rec_t;
 
 /*
diff --git a/osaf/libs/agents/saf/ntfa/ntfa_api.c 
b/osaf/libs/agents/saf/ntfa/ntfa_api.c
--- a/osaf/libs/agents/saf/ntfa/ntfa_api.c
+++ b/osaf/libs/agents/saf/ntfa/ntfa_api.c
@@ -18,7 +18,8 @@
 #include <string.h>
 #include "ntfa.h"
 #include "ntfsv_mem.h"
-
+#include "osaf_extended_name.h"
+#include "saAis.h"
 #define NCS_SAF_MIN_ACCEPT_TIME 10
 #define NTFS_WAIT_TIME 1000
 
@@ -305,8 +306,9 @@ static SaAisErrorT checkHeader(SaNtfNoti
 {
        int i =0;
 
-       if (nh->notificationObject->length >= SA_MAX_NAME_LENGTH || 
nh->notifyingObject->length >= SA_MAX_NAME_LENGTH) {
-               TRACE_1("SaNameT length too big");
+       if (!ntfsv_sanamet_is_valid(nh->notificationObject) ||
+               !ntfsv_sanamet_is_valid(nh->notifyingObject)) {
+               TRACE_1("SaNameT is invaild");
                return SA_AIS_ERR_INVALID_PARAM;
        }
 
@@ -517,12 +519,13 @@ static SaAisErrorT fillSendStruct(SaNtfN
        /* nodificationId set to zero means that this is a new notification */
        /* and not an sync message send from the server. */
        *(notificationHeader->notificationId) = 0;
+       
+       /* If notifyingObject is empty, its default value is notificationObject 
*/
+       if (osaf_is_extended_name_empty(notificationHeader->notifyingObject)) {
+               
osaf_extended_name_lend(osaf_extended_name_borrow(notificationHeader->notificationObject)
+                                                               , 
notificationHeader->notifyingObject);
+       }
 
-       if (notificationHeader->notifyingObject->length == 0) {
-               notificationHeader->notifyingObject->length = 
notificationHeader->notificationObject->length;
-               (void)memcpy(notificationHeader->notifyingObject->value, 
notificationHeader->notificationObject->value,
-                            notificationHeader->notifyingObject->length);
-       }
        return rc;
 }
 
@@ -1204,7 +1207,7 @@ SaAisErrorT saNtfNotificationSend(SaNtfN
                rc = SA_AIS_ERR_BAD_HANDLE;
                goto err_free;
        }
-       
+       notification_hdl_rec->is_longdn_agent_owner = false;
        osafassert(pthread_mutex_lock(&ntfa_cb.cb_lock) == 0);
        client_handle = notification_hdl_rec->parent_hdl->local_hdl;
        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
@@ -1288,6 +1291,32 @@ SaAisErrorT saNtfNotificationSend(SaNtfN
                goto done_give_hdls;
        }
        send_param->variable_data = notification_hdl_rec->variable_data;
+       SaUint16T i = 0;
+       for(i=0 ; i < ntfHeader->numAdditionalInfo ; i++ ) {
+               if (ntfHeader->additionalInfo[i].infoType == 
SA_NTF_VALUE_LDAP_NAME) {
+                       SaNameT *ptr = send_param->variable_data.p_base +
+                                                       
ntfHeader->additionalInfo[i].infoValue.ptrVal.dataOffset;
+                       if (!ntfsv_sanamet_is_valid(ptr)) {
+                               rc = SA_AIS_ERR_INVALID_PARAM;
+                               goto done_give_hdls;
+                       }
+                       if (osaf_is_an_extended_name(ptr)) {
+                               size_t length_to_copy;
+                               void *p;
+                               if 
(ntfHeader->additionalInfo[i].infoValue.ptrVal.dataSize
+                                               < 
(osaf_extended_name_length(ptr) + 2)) {
+                                       LOG_ER("The allocated memory is not 
large enough,"
+                                                       " the object will be 
truncated (%s)"
+                                                       , 
osaf_extended_name_borrow(ptr));
+                                       length_to_copy = 
ntfHeader->additionalInfo[i].infoValue.ptrVal.dataSize - 2;
+                               } else
+                                       length_to_copy = 
osaf_extended_name_length(ptr);
+                               p = send_param->variable_data.p_base +
+                                       
ntfHeader->additionalInfo[i].infoValue.ptrVal.dataOffset + 2;
+                               memcpy(p, osaf_extended_name_borrow(ptr), 
length_to_copy);
+                       }
+               }
+       }
        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
        /* Send a sync MDS message to obtain a notification id */
        mds_rc = ntfa_mds_msg_sync_send(&ntfa_cb, &msg, &o_msg, timeout);
@@ -2267,7 +2296,7 @@ SaAisErrorT saNtfStateChangeNotification
                rc = SA_AIS_ERR_LIBRARY;
        }
        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
-       ntfsv_filter_state_ch_free(new_filter);
+       ntfsv_filter_state_ch_free(new_filter, false);
        TRACE("ERROR, rc = %d!!!", rc);
        goto done_give_hdl;
 }
@@ -2349,7 +2378,7 @@ SaAisErrorT saNtfAlarmNotificationFilter
                rc = SA_AIS_ERR_LIBRARY;
        }
        osafassert(pthread_mutex_unlock(&ntfa_cb.cb_lock) == 0);
-       ntfsv_filter_alarm_free(new_filter);
+       ntfsv_filter_alarm_free(new_filter, false);
        TRACE("ERROR, rc = %d!!!", rc);
        goto done_give_hdl;
 }
@@ -2927,6 +2956,7 @@ SaAisErrorT saNtfNotificationReadNext(Sa
                        rc = SA_AIS_ERR_BAD_HANDLE;
                        goto done_give_hdls;
                }
+               notification_hdl_rec->is_longdn_agent_owner = true;
                rc = ntfsv_v_data_cp(&notification_hdl_rec->variable_data, 
&read_not->variable_data);
                
ncshm_give_hdl(notification->notification.alarmNotification.notificationHandle);
                
ntfsv_copy_ntf_alarm(&notification->notification.alarmNotification, 
&read_not->notification.alarm);
@@ -2960,6 +2990,7 @@ SaAisErrorT saNtfNotificationReadNext(Sa
                        rc = SA_AIS_ERR_BAD_HANDLE;
                        goto done_give_hdls;
                }
+               notification_hdl_rec->is_longdn_agent_owner = true;
                rc = ntfsv_v_data_cp(&notification_hdl_rec->variable_data, 
&read_not->variable_data);
                
ncshm_give_hdl(notification->notification.securityAlarmNotification.notificationHandle);
                
ntfsv_copy_ntf_security_alarm(&notification->notification.securityAlarmNotification,
diff --git a/osaf/libs/agents/saf/ntfa/ntfa_util.c 
b/osaf/libs/agents/saf/ntfa/ntfa_util.c
--- a/osaf/libs/agents/saf/ntfa/ntfa_util.c
+++ b/osaf/libs/agents/saf/ntfa/ntfa_util.c
@@ -165,6 +165,7 @@ static SaAisErrorT ntfa_alloc_callback_n
                        }
                        /* to be able to delelte cbk_notification in 
saNtfNotificationFree */
                        notification_hdl_rec->cbk_notification = notification;
+                       notification_hdl_rec->is_longdn_agent_owner = true;
                        rc = 
ntfsv_v_data_cp(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
                        
ncshm_give_hdl(notification->notification.objectCreateDeleteNotification.notificationHandle);
                        
ntfsv_copy_ntf_obj_cr_del(&notification->notification.objectCreateDeleteNotification,
@@ -197,6 +198,7 @@ static SaAisErrorT ntfa_alloc_callback_n
                        }
                        /* to be able to delelte cbk_notification in 
saNtfNotificationFree */
                        notification_hdl_rec->cbk_notification = notification;
+                       notification_hdl_rec->is_longdn_agent_owner = true;
                        rc = 
ntfsv_v_data_cp(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
                        
ncshm_give_hdl(notification->notification.attributeChangeNotification.notificationHandle);
                        
ntfsv_copy_ntf_attr_change(&notification->notification.attributeChangeNotification,
@@ -229,6 +231,7 @@ static SaAisErrorT ntfa_alloc_callback_n
                        }
                        /* to be able to delelte cbk_notification in 
saNtfNotificationFree */
                        notification_hdl_rec->cbk_notification = notification;
+                       notification_hdl_rec->is_longdn_agent_owner = true;
                        rc = 
ntfsv_v_data_cp(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
                        
ncshm_give_hdl(notification->notification.stateChangeNotification.notificationHandle);
                        
ntfsv_copy_ntf_state_change(&notification->notification.stateChangeNotification,
@@ -260,6 +263,7 @@ static SaAisErrorT ntfa_alloc_callback_n
                        }
                        /* to be able to delelte cbk_notification in 
saNtfNotificationFree */
                        notification_hdl_rec->cbk_notification = notification;
+                       notification_hdl_rec->is_longdn_agent_owner = true;
                        rc = 
ntfsv_v_data_cp(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
                        
ncshm_give_hdl(notification->notification.alarmNotification.notificationHandle);
                        
ntfsv_copy_ntf_alarm(&notification->notification.alarmNotification,
@@ -290,6 +294,7 @@ static SaAisErrorT ntfa_alloc_callback_n
                        }
                        /* to be able to delelte cbk_notification in 
saNtfNotificationFree */
                        notification_hdl_rec->cbk_notification = notification;
+                       notification_hdl_rec->is_longdn_agent_owner = true;
                        rc = 
ntfsv_v_data_cp(&notification_hdl_rec->variable_data, &not_cbk->variable_data);
                        
ncshm_give_hdl(notification->notification.securityAlarmNotification.notificationHandle);
                        
ntfsv_copy_ntf_security_alarm(&notification->notification.securityAlarmNotification,
@@ -1027,24 +1032,29 @@ void ntfa_hdl_rec_destructor(ntfa_notifi
 
        switch (notificationInstance->ntfNotificationType) {
        case SA_NTF_TYPE_ALARM:
-               
ntfsv_free_alarm(&notificationInstance->ntfNotification.ntfAlarmNotification);
+               
ntfsv_free_alarm(&notificationInstance->ntfNotification.ntfAlarmNotification
+                                                       , 
notificationInstance->is_longdn_agent_owner);
                break;
 
        case SA_NTF_TYPE_STATE_CHANGE:
-               
ntfsv_free_state_change(&notificationInstance->ntfNotification.ntfStateChangeNotification);
+               
ntfsv_free_state_change(&notificationInstance->ntfNotification.ntfStateChangeNotification
+                                                       , 
notificationInstance->is_longdn_agent_owner);
                break;
 
        case SA_NTF_TYPE_OBJECT_CREATE_DELETE:
-               
ntfsv_free_obj_create_del(&notificationInstance->ntfNotification.ntfObjectCreateDeleteNotification);
+               
ntfsv_free_obj_create_del(&notificationInstance->ntfNotification.ntfObjectCreateDeleteNotification
+                                                       , 
notificationInstance->is_longdn_agent_owner);
                break;
 
        case SA_NTF_TYPE_ATTRIBUTE_CHANGE:
-               
ntfsv_free_attribute_change(&notificationInstance->ntfNotification.ntfAttributeChangeNotification);
+               
ntfsv_free_attribute_change(&notificationInstance->ntfNotification.ntfAttributeChangeNotification
+                                                       , 
notificationInstance->is_longdn_agent_owner);
 
                break;
 
        case SA_NTF_TYPE_SECURITY_ALARM:
-               
ntfsv_free_security_alarm(&notificationInstance->ntfNotification.ntfSecurityAlarmNotification);
+               
ntfsv_free_security_alarm(&notificationInstance->ntfNotification.ntfSecurityAlarmNotification
+                                                       , 
notificationInstance->is_longdn_agent_owner);
                break;
 
        default:
@@ -1068,19 +1078,19 @@ void ntfa_filter_hdl_rec_destructor(ntfa
 {
        switch (filter_rec->ntfType) {
        case SA_NTF_TYPE_OBJECT_CREATE_DELETE:
-               
ntfsv_filter_obj_cr_del_free(&filter_rec->notificationFilter.objectCreateDeleteNotificationfilter);
+               
ntfsv_filter_obj_cr_del_free(&filter_rec->notificationFilter.objectCreateDeleteNotificationfilter,
 false);
                break;
        case SA_NTF_TYPE_ATTRIBUTE_CHANGE:
-               
ntfsv_filter_attr_ch_free(&filter_rec->notificationFilter.attributeChangeNotificationfilter);
+               
ntfsv_filter_attr_ch_free(&filter_rec->notificationFilter.attributeChangeNotificationfilter,
 false);
                break;
        case SA_NTF_TYPE_STATE_CHANGE:
-               
ntfsv_filter_state_ch_free(&filter_rec->notificationFilter.stateChangeNotificationfilter);
+               
ntfsv_filter_state_ch_free(&filter_rec->notificationFilter.stateChangeNotificationfilter,
 false);
                break;
        case SA_NTF_TYPE_SECURITY_ALARM:
-               
ntfsv_filter_sec_alarm_free(&filter_rec->notificationFilter.securityAlarmNotificationfilter);
+               
ntfsv_filter_sec_alarm_free(&filter_rec->notificationFilter.securityAlarmNotificationfilter,
 false);
                break;
        case SA_NTF_TYPE_ALARM:
-               
ntfsv_filter_alarm_free(&filter_rec->notificationFilter.alarmNotificationfilter);
+               
ntfsv_filter_alarm_free(&filter_rec->notificationFilter.alarmNotificationfilter,
 false);
                break;
        default:
                osafassert(0);
diff --git a/osaf/libs/saf/libSaNtf/Makefile.am 
b/osaf/libs/saf/libSaNtf/Makefile.am
--- a/osaf/libs/saf/libSaNtf/Makefile.am
+++ b/osaf/libs/saf/libSaNtf/Makefile.am
@@ -29,6 +29,7 @@ lib_LTLIBRARIES = libSaNtf.la
 libSaNtf_la_SOURCES = 
 
 libSaNtf_la_CPPFLAGS = \
+       -DSA_EXTENDED_NAME_SOURCE \
        $(AM_CPPFLAGS)
 
 if HAVE_LD_VERSION_SCRIPT

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to