+int ves_username_changed(char *new_username)
+{
+ char *stringConfiguration = readConfigFileInString();
+
+ if (stringConfiguration == NULL)
+ {
+ printf("Could not read configuration file!\n");
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *jsonConfig = cJSON_Parse(stringConfiguration);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfiguration);
+ 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(stringConfiguration);
+ stringConfiguration = NULL;
+
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *vesUsername = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-username");
+ if (!cJSON_IsString(vesUsername))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-username is not a string");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ //we set the value of the fault-notification-delay-period object
+ cJSON_ReplaceItemInObject(vesDetails, "ves-endpoint-username", cJSON_CreateString(new_username));
+
+ //writing the new JSON to the configuration file
+ stringConfiguration = cJSON_Print(jsonConfig);
+ writeConfigFile(stringConfiguration);
+
+ if (stringConfiguration != NULL)
+ {
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+ }
+
+ cJSON_Delete(jsonConfig);
+
+ return SR_ERR_OK;
+}
+
+int ves_password_changed(char *new_password)
+{
+ char *stringConfiguration = readConfigFileInString();
+
+ if (stringConfiguration == NULL)
+ {
+ printf("Could not read configuration file!\n");
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *jsonConfig = cJSON_Parse(stringConfiguration);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfiguration);
+ 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(stringConfiguration);
+ stringConfiguration = NULL;
+
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *vesPassword = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-password");
+ if (!cJSON_IsString(vesPassword))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-password is not a string");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ //we set the value of the fault-notification-delay-period object
+ cJSON_ReplaceItemInObject(vesDetails, "ves-endpoint-password", cJSON_CreateString(new_password));
+
+ //writing the new JSON to the configuration file
+ stringConfiguration = cJSON_Print(jsonConfig);
+ writeConfigFile(stringConfiguration);
+
+ if (stringConfiguration != NULL)
+ {
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+ }
+
+ cJSON_Delete(jsonConfig);
+
+ return SR_ERR_OK;
+}
+
+int ves_auth_method_changed(char *new_auth_method)
+{
+ char *stringConfiguration = readConfigFileInString();
+
+ if (stringConfiguration == NULL)
+ {
+ printf("Could not read configuration file!\n");
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *jsonConfig = cJSON_Parse(stringConfiguration);
+ if (jsonConfig == NULL)
+ {
+ free(stringConfiguration);
+ 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(stringConfiguration);
+ stringConfiguration = NULL;
+
+ cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
+ if (!cJSON_IsObject(vesDetails))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ cJSON *vesAuthMethod = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-auth-method");
+ if (!cJSON_IsString(vesAuthMethod))
+ {
+ printf("Configuration JSON is not as expected: ves-endpoint-auth-method is not a string");
+ cJSON_Delete(jsonConfig);
+ return SR_ERR_OPERATION_FAILED;
+ }
+
+ //we set the value of the fault-notification-delay-period object
+ cJSON_ReplaceItemInObject(vesDetails, "ves-endpoint-auth-method", cJSON_CreateString(new_auth_method));
+
+ //writing the new JSON to the configuration file
+ stringConfiguration = cJSON_Print(jsonConfig);
+ writeConfigFile(stringConfiguration);
+
+ if (stringConfiguration != NULL)
+ {
+ free(stringConfiguration);
+ stringConfiguration = NULL;
+ }
+
+ cJSON_Delete(jsonConfig);
+
+ return SR_ERR_OK;
+}
+