2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_node_condition.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_node_condition_t *v1_node_condition_create_internal(
|
2020-03-18 17:24:33 +08:00
|
|
|
char *last_heartbeat_time,
|
|
|
|
|
char *last_transition_time,
|
|
|
|
|
char *message,
|
|
|
|
|
char *reason,
|
|
|
|
|
char *status,
|
2022-06-05 18:16:17 +00:00
|
|
|
char *type
|
2020-03-18 17:24:33 +08:00
|
|
|
) {
|
|
|
|
|
v1_node_condition_t *v1_node_condition_local_var = malloc(sizeof(v1_node_condition_t));
|
|
|
|
|
if (!v1_node_condition_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_node_condition_local_var->last_heartbeat_time = last_heartbeat_time;
|
|
|
|
|
v1_node_condition_local_var->last_transition_time = last_transition_time;
|
|
|
|
|
v1_node_condition_local_var->message = message;
|
|
|
|
|
v1_node_condition_local_var->reason = reason;
|
|
|
|
|
v1_node_condition_local_var->status = status;
|
|
|
|
|
v1_node_condition_local_var->type = type;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_node_condition_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return v1_node_condition_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_node_condition_t *v1_node_condition_create(
|
|
|
|
|
char *last_heartbeat_time,
|
|
|
|
|
char *last_transition_time,
|
|
|
|
|
char *message,
|
|
|
|
|
char *reason,
|
|
|
|
|
char *status,
|
|
|
|
|
char *type
|
|
|
|
|
) {
|
|
|
|
|
return v1_node_condition_create_internal (
|
|
|
|
|
last_heartbeat_time,
|
|
|
|
|
last_transition_time,
|
|
|
|
|
message,
|
|
|
|
|
reason,
|
|
|
|
|
status,
|
|
|
|
|
type
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void v1_node_condition_free(v1_node_condition_t *v1_node_condition) {
|
|
|
|
|
if(NULL == v1_node_condition){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_node_condition->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_node_condition_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_node_condition->last_heartbeat_time) {
|
|
|
|
|
free(v1_node_condition->last_heartbeat_time);
|
|
|
|
|
v1_node_condition->last_heartbeat_time = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_node_condition->last_transition_time) {
|
|
|
|
|
free(v1_node_condition->last_transition_time);
|
|
|
|
|
v1_node_condition->last_transition_time = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_node_condition->message) {
|
|
|
|
|
free(v1_node_condition->message);
|
|
|
|
|
v1_node_condition->message = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_node_condition->reason) {
|
|
|
|
|
free(v1_node_condition->reason);
|
|
|
|
|
v1_node_condition->reason = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_node_condition->status) {
|
|
|
|
|
free(v1_node_condition->status);
|
|
|
|
|
v1_node_condition->status = NULL;
|
|
|
|
|
}
|
2022-06-05 18:16:17 +00:00
|
|
|
if (v1_node_condition->type) {
|
|
|
|
|
free(v1_node_condition->type);
|
|
|
|
|
v1_node_condition->type = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(v1_node_condition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_node_condition_convertToJSON(v1_node_condition_t *v1_node_condition) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->last_heartbeat_time
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_node_condition->last_heartbeat_time) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "lastHeartbeatTime", v1_node_condition->last_heartbeat_time) == NULL) {
|
|
|
|
|
goto fail; //Date-Time
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->last_transition_time
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_node_condition->last_transition_time) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "lastTransitionTime", v1_node_condition->last_transition_time) == NULL) {
|
|
|
|
|
goto fail; //Date-Time
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->message
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_node_condition->message) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "message", v1_node_condition->message) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->reason
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_node_condition->reason) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "reason", v1_node_condition->reason) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->status
|
|
|
|
|
if (!v1_node_condition->status) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
if(cJSON_AddStringToObject(item, "status", v1_node_condition->status) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->type
|
2022-06-05 18:16:17 +00:00
|
|
|
if (!v1_node_condition->type) {
|
2022-04-18 09:29:02 +08:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2022-06-05 18:16:17 +00:00
|
|
|
if(cJSON_AddStringToObject(item, "type", v1_node_condition->type) == NULL) {
|
|
|
|
|
goto fail; //String
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_node_condition_t *v1_node_condition_parseFromJSON(cJSON *v1_node_conditionJSON){
|
|
|
|
|
|
|
|
|
|
v1_node_condition_t *v1_node_condition_local_var = NULL;
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->last_heartbeat_time
|
|
|
|
|
cJSON *last_heartbeat_time = cJSON_GetObjectItemCaseSensitive(v1_node_conditionJSON, "lastHeartbeatTime");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(last_heartbeat_time)) {
|
|
|
|
|
last_heartbeat_time = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (last_heartbeat_time) {
|
2022-11-07 10:45:06 +08:00
|
|
|
if(!cJSON_IsString(last_heartbeat_time) && !cJSON_IsNull(last_heartbeat_time))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //DateTime
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->last_transition_time
|
|
|
|
|
cJSON *last_transition_time = cJSON_GetObjectItemCaseSensitive(v1_node_conditionJSON, "lastTransitionTime");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(last_transition_time)) {
|
|
|
|
|
last_transition_time = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (last_transition_time) {
|
2022-11-07 10:45:06 +08:00
|
|
|
if(!cJSON_IsString(last_transition_time) && !cJSON_IsNull(last_transition_time))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //DateTime
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->message
|
|
|
|
|
cJSON *message = cJSON_GetObjectItemCaseSensitive(v1_node_conditionJSON, "message");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(message)) {
|
|
|
|
|
message = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (message) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(message) && !cJSON_IsNull(message))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->reason
|
|
|
|
|
cJSON *reason = cJSON_GetObjectItemCaseSensitive(v1_node_conditionJSON, "reason");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(reason)) {
|
|
|
|
|
reason = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (reason) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(reason) && !cJSON_IsNull(reason))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->status
|
|
|
|
|
cJSON *status = cJSON_GetObjectItemCaseSensitive(v1_node_conditionJSON, "status");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(status)) {
|
|
|
|
|
status = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (!status) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!cJSON_IsString(status))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_node_condition->type
|
|
|
|
|
cJSON *type = cJSON_GetObjectItemCaseSensitive(v1_node_conditionJSON, "type");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(type)) {
|
|
|
|
|
type = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (!type) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!cJSON_IsString(type))
|
|
|
|
|
{
|
2022-06-05 18:16:17 +00:00
|
|
|
goto end; //String
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_node_condition_local_var = v1_node_condition_create_internal (
|
2022-11-07 10:45:06 +08:00
|
|
|
last_heartbeat_time && !cJSON_IsNull(last_heartbeat_time) ? strdup(last_heartbeat_time->valuestring) : NULL,
|
|
|
|
|
last_transition_time && !cJSON_IsNull(last_transition_time) ? strdup(last_transition_time->valuestring) : NULL,
|
2022-12-29 10:58:47 +08:00
|
|
|
message && !cJSON_IsNull(message) ? strdup(message->valuestring) : NULL,
|
|
|
|
|
reason && !cJSON_IsNull(reason) ? strdup(reason->valuestring) : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
strdup(status->valuestring),
|
2022-06-05 18:16:17 +00:00
|
|
|
strdup(type->valuestring)
|
2020-03-18 17:24:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_node_condition_local_var;
|
|
|
|
|
end:
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|