I have Version 2 of this patch in which I have added validation for 
notificaionType also(got missed in version 1).I will refloat after 
incorporating this comment also.

Thanks
Praveeen

On 18-Sep-14 5:19 PM, Lennart Lund wrote:
> Hi Praveen,
>
> I have one minor comment:
>
> Globally used functions should have a header (actually all functions/methods) 
>  describing what the function do, its parameters (in/out) and the return 
> value. This is missing for the new get_long_long_digit(...) function. I know 
> there are a lot of uncommented functions in the code which is not good but 
> even if we cannot fix all of them we should not add more...
>
> BR
> Lennart
>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]]
>> Sent: den 18 september 2014 12:21
>> To: Lennart Lund; [email protected]
>> Cc: [email protected]
>> Subject: [PATCH 1 of 1] tools/safntf : validate ntfsend options V2 [#1069]
>>
>>   osaf/tools/safntf/include/ntfclient.h |   1 +
>>   osaf/tools/safntf/ntfsend/ntfsend.c   |  36
>> ++++++++++++++++++++++++++++++++--
>>   osaf/tools/safntf/src/ntfclient.c     |  28 +++++++++++++++++++++++++-
>>   3 files changed, 60 insertions(+), 5 deletions(-)
>>
>>
>> Added validation for notificationType also, got missed in V1.
>>
>> This patch adds validation for following attributes:
>> 1)probableCause,
>> 2)eventType
>> 3)perceivedSeverity/severity.
>> 4)eventTime.
>> 5)notificationType.
>>
>> Also ntfsubcribe prints event time in human readable form also.
>>
>> 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
>> @@ -130,5 +130,6 @@ typedef SaUint16T saNotificationFlagsT;
>>   /* used by ntfread and ntfsend */
>>   void getVendorId(SaNtfClassIdT *notificationClassId);
>>   int get_long_digit(char *str, long *val);
>> +int get_long_long_digit(char *str, long long *val);
>>
>>   #endif
>> 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
>> @@ -773,6 +773,7 @@ sendNotification(const saNotificationAll
>>   int main(int argc, char *argv[])
>>   {
>>      long value;
>> +    long long valuell;
>>      char *endptr;
>>      int current_option;
>>      SaBoolT optionFlag = SA_FALSE;
>> @@ -849,12 +850,28 @@ int main(int argc, char *argv[])
>>                              myNotificationParams.eventType =
>> (SaNtfEventTypeT)atoi(optarg);
>>                              /* No default value */
>>                              myNotificationFlags = 0x0000;
>> +                            if ((myNotificationParams.eventType <
>> SA_NTF_ALARM_NOTIFICATIONS_START) ||
>> +
>>      (myNotificationParams.eventType >
>> SA_NTF_ALARM_ENVIRONMENT)) {
>> +                                    fprintf(stderr,"invalid value for
>> eventType\n");
>> +                                    exit(EXIT_FAILURE);
>> +                            }
>> +
>>                              break;
>>                      case 'E':
>> -                            myNotificationParams.eventTime =
>> (SaTimeT)atoll(optarg);
>> +                            if (get_long_long_digit(optarg, &valuell)) {
>> +                                    myNotificationParams.eventTime =
>> valuell;
>> +                            } else {
>> +                                    fprintf(stderr,"invalid input for
>> time\n");
>> +                                    exit(EXIT_FAILURE);
>> +                            }
>>                              break;
>>                      case 'p':
>>                              myNotificationParams.probableCause =
>> (SaNtfProbableCauseT)atoi(optarg);
>> +                            if ((myNotificationParams.probableCause <
>> SA_NTF_ADAPTER_ERROR) ||
>> +
>>      (myNotificationParams.probableCause >
>> SA_NTF_UNSPECIFIED_REASON)) {
>> +                                    fprintf(stderr,"invalid value for
>> probableCause\n");
>> +                                    exit(EXIT_FAILURE);
>> +                            }
>>                              break;
>>                      case 'r':
>>                              if (get_long_digit(optarg, &value)) {
>> @@ -871,10 +888,23 @@ int main(int argc, char *argv[])
>>                      case 's':
>>                              myNotificationParams.perceivedSeverity =
>> (SaNtfSeverityT)atoi(optarg);
>>                              myNotificationParams.severity =
>> (SaNtfSeverityT)atoi(optarg);
>> +                            if ((myNotificationParams.severity <
>> SA_NTF_SEVERITY_CLEARED) ||
>> +
>>      (myNotificationParams.severity > SA_NTF_SEVERITY_CRITICAL)) {
>> +                                    fprintf(stderr,"invalid value for
>> perceivedSeverity/severity\n");
>> +                                    exit(EXIT_FAILURE);
>> +                            }
>>                              break;
>>                      case 'T':
>> -                            value = strtol(optarg, &endptr, 16);
>> -                            myNotificationParams.notificationType =
>> (SaNtfNotificationTypeT)value;
>> +                            value =
>> (SaNtfNotificationTypeT)strtol(optarg, &endptr, 16);
>> +                            if ((value !=
>> SA_NTF_TYPE_OBJECT_CREATE_DELETE) &&
>> +                                            (value !=
>> SA_NTF_TYPE_ATTRIBUTE_CHANGE) &&
>> +                                            (value !=
>> SA_NTF_TYPE_STATE_CHANGE) &&
>> +                                            (value !=
>> SA_NTF_TYPE_ALARM) &&
>> +                                            (value !=
>> SA_NTF_TYPE_SECURITY_ALARM)) {
>> +                                    fprintf(stderr,"invalid value for
>> notificationType\n");
>> +                                    exit(EXIT_FAILURE);
>> +                            }
>> +                            myNotificationParams.notificationType =
>> value;
>>                              break;
>>                      case ':':
>>                              (void)printf("Option -%c requires an
>> argument!!!!\n", optopt);
>> 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
>> @@ -634,6 +634,7 @@ static void print_header(const SaNtfNoti
>>                SaNtfSubscriptionIdT subscriptionId,
>>                SaNtfNotificationTypeT notificationType)
>>   {
>> +    static char time[32];
>>      if (verbose) {
>>              printf("notificationID = %d\n",
>>                     (int)*(notificationHeader->notificationId));
>> @@ -675,8 +676,12 @@ static void print_header(const SaNtfNoti
>>                     notificationHeader->notificationClassId->minorId);
>>      }
>>
>> -    if (verbose)
>> -            printf("eventTime = %lld\n", *notificationHeader-
>>> eventTime);
>> +    if (verbose) {
>> +            time_t time_in_secs = *notificationHeader-
>>> eventTime/SA_TIME_ONE_SECOND;
>> +            /*Print time in human readable form also .*/
>> +            (void)strftime(time, sizeof(time), "%a %b %d %T %Z %Y",
>> localtime(&time_in_secs));
>> +            printf("eventTime = %lld (%s)\n",*notificationHeader-
>>> eventTime, time);
>> +    }
>>
>>      if (notificationHeader->lengthAdditionalText > 0)
>>              printf("additionalText = \"%s\"\n",
>> @@ -1010,3 +1015,22 @@ void getVendorId(SaNtfClassIdT * notific
>>      }
>>      free(p);
>>   }
>> +
>> +int get_long_long_digit(char *str, long long *val)
>> +{
>> +    char *endptr;
>> +    errno = 0;
>> +    *val = strtoll(str, &endptr, 0);
>> +
>> +    if ((errno == ERANGE ) || (errno != 0 && *val == 0)) {
>> +            perror("strtoll");
>> +            return 0;
>> +    }
>> +    if (endptr == str) {
>> +            fprintf(stderr, "No digits were found\n");
>> +            return 0;
>> +    }
>> +    if (*endptr != '\0')    /* other chars than digits */
>> +            return 0;
>> +    return 1;
>> +}

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to