osaf/tools/safntf/include/ntfclient.h | 3 +- osaf/tools/safntf/ntfread/Makefile.am | 1 + osaf/tools/safntf/ntfread/ntfread.c | 23 ++++++----- osaf/tools/safntf/ntfsend/Makefile.am | 1 + osaf/tools/safntf/ntfsend/ntfsend.c | 29 ++++++-------- osaf/tools/safntf/ntfsubscribe/Makefile.am | 2 + osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c | 4 ++ osaf/tools/safntf/src/Makefile.am | 1 + osaf/tools/safntf/src/ntfclient.c | 54 ++++++++++++-------------- 9 files changed, 61 insertions(+), 57 deletions(-)
(1) Remove ntfs_saname_strdup diff --git a/osaf/tools/safntf/include/ntfclient.h b/osaf/tools/safntf/include/ntfclient.h --- a/osaf/tools/safntf/include/ntfclient.h +++ b/osaf/tools/safntf/include/ntfclient.h @@ -23,7 +23,8 @@ #include <saNtf.h> #include "ntfsv_msg.h" - +#include "ntfsv_mem.h" +#include "osaf_extended_name.h" /* Defines */ #define DEFAULT_FLAG 0x0001 /* #define MAX_NUMBER_OF_STATE_CHANGES 5 */ diff --git a/osaf/tools/safntf/ntfread/Makefile.am b/osaf/tools/safntf/ntfread/Makefile.am --- a/osaf/tools/safntf/ntfread/Makefile.am +++ b/osaf/tools/safntf/ntfread/Makefile.am @@ -23,6 +23,7 @@ bin_PROGRAMS = ntfread ntfread_CPPFLAGS = \ $(AM_CPPFLAGS) \ + -DSA_EXTENDED_NAME_SOURCE \ -I$(top_srcdir)/osaf/tools/safntf/include \ -I$(top_srcdir)/osaf/libs/common/ntfsv/include diff --git a/osaf/tools/safntf/ntfread/ntfread.c b/osaf/tools/safntf/ntfread/ntfread.c --- a/osaf/tools/safntf/ntfread/ntfread.c +++ b/osaf/tools/safntf/ntfread/ntfread.c @@ -67,8 +67,8 @@ static SaUint16T nNyObj = 0; static SaUint16T nCId = 0; static SaNtfEventTypeT eType = 0; -static SaNameT nObj = {0}; -static SaNameT nyObj = {0}; +static SaNameT nObj; +static SaNameT nyObj; static SaNtfClassIdT cId; /* common alarm and security alarm */ @@ -272,6 +272,10 @@ int main(int argc, char *argv[]) { verbose = 0; progname = argv[0]; + if (setenv("SA_ENABLE_EXTENDED_NAMES", "1", 1) != 0) { + LOG_ER("Failed to enable Extended SaNameT"); + exit(EXIT_FAILURE); + } /* Check options */ while (1) { c = getopt_long(argc, argv, "b:c:d:hE:e:i:klN:n:op:s:v", @@ -314,22 +318,19 @@ int main(int argc, char *argv[]) { filterAlarm = false; break; case 'N': - nyObj.length = (SaUint16T)strlen(optarg); - if (SA_MAX_NAME_LENGTH < nyObj.length) { + if (strlen(optarg) > kMaxDnLength) { fprintf(stderr, "notifyingObject too long\n"); exit(EXIT_FAILURE); - } - (void)memcpy(nyObj.value, optarg, nyObj.length); + } + saAisNameLend(optarg, &nyObj); nNyObj = 1; break; case 'n': - nObj.length = (SaUint16T)strlen(optarg); - if (SA_MAX_NAME_LENGTH < nObj.length) { - fprintf(stderr, - "notificationObject too long\n"); + if (strlen(optarg) > kMaxDnLength) { + fprintf(stderr, "notificationObject too long\n"); exit(EXIT_FAILURE); } - (void)memcpy(nObj.value, optarg, nObj.length); + saAisNameLend(optarg, &nObj); nNnObj = 1; break; case 'o': diff --git a/osaf/tools/safntf/ntfsend/Makefile.am b/osaf/tools/safntf/ntfsend/Makefile.am --- a/osaf/tools/safntf/ntfsend/Makefile.am +++ b/osaf/tools/safntf/ntfsend/Makefile.am @@ -23,6 +23,7 @@ bin_PROGRAMS = ntfsend ntfsend_CPPFLAGS = \ $(AM_CPPFLAGS) \ + -DSA_EXTENDED_NAME_SOURCE \ -I$(top_srcdir)/osaf/tools/safntf/include \ -I$(top_srcdir)/osaf/libs/common/ntfsv/include diff --git a/osaf/tools/safntf/ntfsend/ntfsend.c b/osaf/tools/safntf/ntfsend/ntfsend.c --- a/osaf/tools/safntf/ntfsend/ntfsend.c +++ b/osaf/tools/safntf/ntfsend/ntfsend.c @@ -186,12 +186,8 @@ static void fillInDefaultValues(saNotifi (void)strncpy(notificationParams->additionalText, DEFAULT_ADDITIONAL_TEXT, notificationAllocationParams->lengthAdditionalText); - notificationParams->notificationObject.length = strlen(DEFAULT_NOTIFICATION_OBJECT); - (void)memcpy(notificationParams->notificationObject.value, - DEFAULT_NOTIFICATION_OBJECT, notificationParams->notificationObject.length); - notificationParams->notifyingObject.length = strlen(DEFAULT_NOTIFYING_OBJECT); - (void)memcpy(notificationParams->notifyingObject.value, - DEFAULT_NOTIFYING_OBJECT, notificationParams->notifyingObject.length); + saAisNameLend(DEFAULT_NOTIFICATION_OBJECT, ¬ificationParams->notificationObject); + saAisNameLend(DEFAULT_NOTIFYING_OBJECT, ¬ificationParams->notifyingObject); notificationParams->notificationClassId.vendorId = ERICSSON_VENDOR_ID; notificationParams->notificationClassId.majorId = 0; notificationParams->notificationClassId.minorId = 0; @@ -802,6 +798,11 @@ int main(int argc, char *argv[]) {0, 0, 0, 0} }; + if (setenv("SA_ENABLE_EXTENDED_NAMES", "1", 1) != 0) { + LOG_ER("Failed to enable Extended SaNameT"); + exit(EXIT_FAILURE); + } + fillInDefaultValues(&myNotificationAllocationParams, &myNotificationFilterAllocationParams, &myNotificationParams); @@ -831,22 +832,18 @@ int main(int argc, char *argv[]) getVendorId(&myNotificationParams.notificationClassId); break; case 'n': - myNotificationParams.notificationObject.length = (SaUint16T)strlen(optarg); - if (SA_MAX_NAME_LENGTH < myNotificationParams.notificationObject.length) { + if (strlen(optarg) > kMaxDnLength) { fprintf(stderr, "notificationObject too long\n"); exit(EXIT_FAILURE); - } - (void)memcpy(myNotificationParams.notificationObject.value, - optarg, myNotificationParams.notificationObject.length); + } + saAisNameLend(optarg, &myNotificationParams.notificationObject); break; case 'N': - myNotificationParams.notifyingObject.length = (SaUint16T)strlen(optarg); - if (SA_MAX_NAME_LENGTH < myNotificationParams.notifyingObject.length) { + if (strlen(optarg) > kMaxDnLength) { fprintf(stderr, "notifyingObject too long\n"); exit(EXIT_FAILURE); - } - (void)memcpy(myNotificationParams.notifyingObject.value, - optarg, myNotificationParams.notifyingObject.length); + } + saAisNameLend(optarg, &myNotificationParams.notifyingObject); break; case 'e': myNotificationParams.eventType = (SaNtfEventTypeT)atoi(optarg); diff --git a/osaf/tools/safntf/ntfsubscribe/Makefile.am b/osaf/tools/safntf/ntfsubscribe/Makefile.am --- a/osaf/tools/safntf/ntfsubscribe/Makefile.am +++ b/osaf/tools/safntf/ntfsubscribe/Makefile.am @@ -23,6 +23,7 @@ bin_PROGRAMS = ntfsubscribe ntfsubscribe_CPPFLAGS = \ $(AM_CPPFLAGS) \ + -DSA_EXTENDED_NAME_SOURCE \ -I$(top_srcdir)/osaf/tools/safntf/include \ -I$(top_srcdir)/osaf/libs/common/ntfsv/include @@ -34,3 +35,4 @@ ntfsubscribe_LDADD = \ $(top_builddir)/osaf/libs/core/libopensaf_core.la \ $(top_builddir)/osaf/libs/saf/libSaNtf/libSaNtf.la \ $(top_builddir)/osaf/tools/safntf/src/libntfclient.la + diff --git a/osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c b/osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c --- a/osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c +++ b/osaf/tools/safntf/ntfsubscribe/ntfsubscribe.c @@ -283,6 +283,10 @@ int main(int argc, char *argv[]) verbose = 0; progname = argv[0]; + if (setenv("SA_ENABLE_EXTENDED_NAMES", "1", 1) != 0) { + LOG_ER("Failed to enable Extended SaNameT"); + exit(EXIT_FAILURE); + } /* Check options */ while (1) { c = getopt_long(argc, argv, "acosyht:v", long_options, NULL); diff --git a/osaf/tools/safntf/src/Makefile.am b/osaf/tools/safntf/src/Makefile.am --- a/osaf/tools/safntf/src/Makefile.am +++ b/osaf/tools/safntf/src/Makefile.am @@ -22,6 +22,7 @@ noinst_LTLIBRARIES = libntfclient.la libntfclient_la_CPPFLAGS = \ $(AM_CPPFLAGS) \ + -DSA_EXTENDED_NAME_SOURCE \ -I$(top_srcdir)/osaf/libs/saf/include \ -I$(top_srcdir)/osaf/tools/safntf/include \ -I$(top_srcdir)/osaf/libs/common/ntfsv/include diff --git a/osaf/tools/safntf/src/ntfclient.c b/osaf/tools/safntf/src/ntfclient.c --- a/osaf/tools/safntf/src/ntfclient.c +++ b/osaf/tools/safntf/src/ntfclient.c @@ -509,7 +509,7 @@ static void print_attribute_value(SaNtfN const SaUint16T max_size = 20; SaAisErrorT rc; SaUint8T *bin_ptr; - char tmp_str[SA_MAX_NAME_LENGTH+1]; + char* tmp_str; int i; switch ((int)attributeType) { @@ -538,12 +538,11 @@ static void print_attribute_value(SaNtfN (void **)&str_ptr, &data_size); if (rc == SA_AIS_OK) { - if (data_size > (SA_MAX_NAME_LENGTH+1)) { - data_size = SA_MAX_NAME_LENGTH; - } - snprintf(tmp_str,data_size+1,"%s",str_ptr); - printf(" Attribute Value: \"%s\"\n", - tmp_str); + tmp_str = (char*) malloc(data_size + 1); + memcpy(tmp_str, str_ptr, data_size); + tmp_str[data_size] = '\0'; + printf(" Attribute Value: \"%s\"\n", tmp_str); + free(tmp_str); } else fprintf(stderr, "saNtfPtrValGet Error " "%d\n", rc); @@ -635,8 +634,6 @@ static void print_header(const SaNtfNoti SaNtfSubscriptionIdT subscriptionId, SaNtfNotificationTypeT notificationType) { - char tmpObj[SA_MAX_NAME_LENGTH + 1]; - if (verbose) { printf("notificationID = %d\n", (int)*(notificationHeader->notificationId)); @@ -648,25 +645,18 @@ static void print_header(const SaNtfNoti print_event_type(*notificationHeader->eventType, notificationType); if (verbose) - printf("notificationObject.length = %u\n", - notificationHeader->notificationObject->length); + printf("notificationObject.length = %zu\n", + strlen(saAisNameBorrow(notificationHeader->notificationObject))); - strncpy(tmpObj, - (char *)notificationHeader->notificationObject->value, - notificationHeader->notificationObject->length); - tmpObj[notificationHeader->notificationObject->length] = '\0'; - printf("notificationObject = \"%s\"\n", tmpObj); + printf("notificationObject = \"%s\"\n", + saAisNameBorrow(notificationHeader->notificationObject)); + + if (verbose) + printf("notifyingObject.length = %zu\n", + strlen(saAisNameBorrow(notificationHeader->notifyingObject))); - strncpy(tmpObj, - (char *)notificationHeader->notifyingObject->value, - notificationHeader->notifyingObject->length); - tmpObj[notificationHeader->notifyingObject->length] = '\0'; - - if (verbose) - printf("notifyingObject.length = %u\n", - notificationHeader->notifyingObject->length); - - printf("notifyingObject = \"%s\"\n", tmpObj); + printf("notifyingObject = \"%s\"\n", + saAisNameBorrow(notificationHeader->notifyingObject)); /* Notification Class ID in compact dot notation */ if (notificationHeader->notificationClassId->vendorId == @@ -697,7 +687,8 @@ void print_additional_info(SaNtfNotifica const SaNtfNotificationHeaderT * notificationHeader) { int i; - SaNameT *dataPtr; + char *dataPtr; + SaNameT name; SaStringT info_value_str; SaUint16T dataSize; SaAisErrorT rc; @@ -716,8 +707,13 @@ void print_additional_info(SaNtfNotifica (void **)&dataPtr, &dataSize); if (rc == SA_AIS_OK) { - printf(" infoValue = \"%s\"\n", - dataPtr->value); + size_t strLength = dataSize - 2; + char *newStr = (char*)malloc(strLength + 1); + memcpy(newStr, dataPtr + 2, strLength); + newStr[strLength] = '\0'; + saAisNameLend(newStr, &name); + printf(" infoValue = \"%s\"\n", saAisNameBorrow(&name)); + free(newStr); } else fprintf(stderr, "saNtfPtrValGet Error " "%d\n", rc); ------------------------------------------------------------------------------ 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