X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ntsimulator%2Fsrc%2Futils%2Futils.c;h=d98dac02672e676d16a8b8f77e1d8fefcc443d25;hb=7dbf479029ba8bc528fb61a40ab2647489da28e9;hp=7d1d2a0cbda1efb27af7336efe738dea8efcd4d6;hpb=a19f893a70c03dee9312e1208301d079409d84ac;p=sim%2Fo1-interface.git diff --git a/ntsimulator/src/utils/utils.c b/ntsimulator/src/utils/utils.c index 7d1d2a0..d98dac0 100644 --- a/ntsimulator/src/utils/utils.c +++ b/ntsimulator/src/utils/utils.c @@ -452,10 +452,9 @@ void writeConfigFile(char *config) } } -int getFaultNotificationDelayPeriodFromConfigJson(void) +int getFaultNotificationDelayPeriodFromConfigJson(int *period_array, int *count) { char *stringConfig = readConfigFileInString(); - int notificationDelay = 0; if (stringConfig == NULL) { @@ -487,18 +486,34 @@ int getFaultNotificationDelayPeriodFromConfigJson(void) } cJSON *faultNotifDelay = cJSON_GetObjectItemCaseSensitive(notifConfig, "fault-notification-delay-period"); - if (!cJSON_IsNumber(faultNotifDelay)) + if (!cJSON_IsArray(faultNotifDelay)) { - printf("Configuration JSON is not as expected: fault-notification-delay-period is not a number"); + printf("Configuration JSON is not as expected: fault-notification-delay-period is not an array."); cJSON_Delete(jsonConfig); return SR_ERR_OPERATION_FAILED; } - notificationDelay = (int)(faultNotifDelay->valuedouble); + cJSON *iterator = NULL; + *count = 0; + int i = 0; + + cJSON_ArrayForEach(iterator, faultNotifDelay) + { + if (cJSON_IsNumber(iterator)) + { + period_array[i++] = iterator->valueint; + } + else + { + printf("Invalid number in array!"); + } + } + + *count = i; cJSON_Delete(jsonConfig); - return notificationDelay; + return SR_ERR_OK; } int getVesHeartbeatPeriodFromConfigJson(void) @@ -1288,6 +1303,17 @@ int writeSkeletonStatusFile() writeStatusFile(status_string); + if (status_string != NULL) + { + free(status_string); + status_string = NULL; + } + + if (statusObject != NULL) + { + cJSON_Delete(statusObject); + } + return SR_ERR_OK; } @@ -1518,7 +1544,16 @@ int writeStatusNotificationCounters(counterAlarms ves_counter, counterAlarms net char *stringStatus = cJSON_PrintUnformatted(jsonStatus); writeStatusFile(stringStatus); - cJSON_Delete(jsonStatus); + if (stringStatus != NULL) + { + free(stringStatus); + stringStatus = NULL; + } + + if (jsonStatus != NULL) + { + cJSON_Delete(jsonStatus); + } return SR_ERR_OK; } @@ -1574,7 +1609,16 @@ int removeDeviceEntryFromStatusFile(char *containerId) char *stringStatus = cJSON_PrintUnformatted(jsonStatus); writeStatusFile(stringStatus); - cJSON_Delete(jsonStatus); + if (stringStatus != NULL) + { + free(stringStatus); + stringStatus = NULL; + } + + if (jsonStatus != NULL) + { + cJSON_Delete(jsonStatus); + } return SR_ERR_OK; } @@ -1741,6 +1785,9 @@ int getDeviceCounters(char *containerId, counterAlarms *ves_counter, counterAlar int array_size = cJSON_GetArraySize(deviceList); + ves_counter->critical = ves_counter->major = ves_counter->minor = ves_counter->warning = ves_counter->normal = 0; + netconf_counter->critical = netconf_counter->major = netconf_counter->minor = netconf_counter->warning = netconf_counter->normal = 0; + for (int i=0; ivaluedouble); + + cJSON_Delete(jsonConfig); + + return num_of_ssh; +} + +int getTlsConnectionsFromConfigJson(void) +{ + char *stringConfig = readConfigFileInString(); + + if (stringConfig == NULL) + { + printf("Could not read JSON configuration file in string."); + return 0; + } + + cJSON *jsonConfig = cJSON_Parse(stringConfig); + if (jsonConfig == NULL) + { + free(stringConfig); + const char *error_ptr = cJSON_GetErrorPtr(); + if (error_ptr != NULL) + { + fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr); + } + return SR_ERR_OPERATION_FAILED; + } + //we don't need the string anymore + free(stringConfig); + stringConfig = NULL; + + cJSON *tlsConnections = cJSON_GetObjectItemCaseSensitive(jsonConfig, "tls-connections"); + if (!cJSON_IsNumber(tlsConnections)) + { + printf("Configuration JSON is not as expected: ssh-connections is not an object"); + cJSON_Delete(jsonConfig); + return SR_ERR_OPERATION_FAILED; + } + + int num_of_tls = (int)(tlsConnections->valuedouble); + + cJSON_Delete(jsonConfig); + + return num_of_tls; +}