X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fo1-interface.git;a=blobdiff_plain;f=ntsimulator%2Fsrc%2Futils%2Futils.c;h=d98dac02672e676d16a8b8f77e1d8fefcc443d25;hp=15bb4260cd3d095049546ea52a2e6928515e0f15;hb=7dbf479029ba8bc528fb61a40ab2647489da28e9;hpb=610985b805c2b5c730bbc247ccbf76dd624792d0 diff --git a/ntsimulator/src/utils/utils.c b/ntsimulator/src/utils/utils.c index 15bb426..d98dac0 100644 --- a/ntsimulator/src/utils/utils.c +++ b/ntsimulator/src/utils/utils.c @@ -455,7 +455,6 @@ void writeConfigFile(char *config) int getFaultNotificationDelayPeriodFromConfigJson(int *period_array, int *count) { char *stringConfig = readConfigFileInString(); - int notificationDelay = 0; if (stringConfig == NULL) { @@ -1304,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; } @@ -1534,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; } @@ -1590,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; } @@ -1757,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; +}