2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "apiregistration_v1_service_reference.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static apiregistration_v1_service_reference_t *apiregistration_v1_service_reference_create_internal(
|
2020-03-18 17:24:33 +08:00
|
|
|
char *name,
|
2021-01-05 15:42:34 +08:00
|
|
|
char *_namespace,
|
2020-03-18 17:24:33 +08:00
|
|
|
int port
|
|
|
|
|
) {
|
|
|
|
|
apiregistration_v1_service_reference_t *apiregistration_v1_service_reference_local_var = malloc(sizeof(apiregistration_v1_service_reference_t));
|
|
|
|
|
if (!apiregistration_v1_service_reference_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
apiregistration_v1_service_reference_local_var->name = name;
|
2021-01-05 15:42:34 +08:00
|
|
|
apiregistration_v1_service_reference_local_var->_namespace = _namespace;
|
2020-03-18 17:24:33 +08:00
|
|
|
apiregistration_v1_service_reference_local_var->port = port;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
apiregistration_v1_service_reference_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return apiregistration_v1_service_reference_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) apiregistration_v1_service_reference_t *apiregistration_v1_service_reference_create(
|
|
|
|
|
char *name,
|
|
|
|
|
char *_namespace,
|
|
|
|
|
int port
|
|
|
|
|
) {
|
|
|
|
|
return apiregistration_v1_service_reference_create_internal (
|
|
|
|
|
name,
|
|
|
|
|
_namespace,
|
|
|
|
|
port
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void apiregistration_v1_service_reference_free(apiregistration_v1_service_reference_t *apiregistration_v1_service_reference) {
|
|
|
|
|
if(NULL == apiregistration_v1_service_reference){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(apiregistration_v1_service_reference->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "apiregistration_v1_service_reference_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (apiregistration_v1_service_reference->name) {
|
|
|
|
|
free(apiregistration_v1_service_reference->name);
|
|
|
|
|
apiregistration_v1_service_reference->name = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (apiregistration_v1_service_reference->_namespace) {
|
|
|
|
|
free(apiregistration_v1_service_reference->_namespace);
|
|
|
|
|
apiregistration_v1_service_reference->_namespace = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(apiregistration_v1_service_reference);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *apiregistration_v1_service_reference_convertToJSON(apiregistration_v1_service_reference_t *apiregistration_v1_service_reference) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// apiregistration_v1_service_reference->name
|
2022-04-18 09:29:02 +08:00
|
|
|
if(apiregistration_v1_service_reference->name) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "name", apiregistration_v1_service_reference->name) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
2021-01-05 15:42:34 +08:00
|
|
|
// apiregistration_v1_service_reference->_namespace
|
2022-04-18 09:29:02 +08:00
|
|
|
if(apiregistration_v1_service_reference->_namespace) {
|
2021-01-05 15:42:34 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "namespace", apiregistration_v1_service_reference->_namespace) == NULL) {
|
2020-03-18 17:24:33 +08:00
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// apiregistration_v1_service_reference->port
|
2022-04-18 09:29:02 +08:00
|
|
|
if(apiregistration_v1_service_reference->port) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddNumberToObject(item, "port", apiregistration_v1_service_reference->port) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apiregistration_v1_service_reference_t *apiregistration_v1_service_reference_parseFromJSON(cJSON *apiregistration_v1_service_referenceJSON){
|
|
|
|
|
|
|
|
|
|
apiregistration_v1_service_reference_t *apiregistration_v1_service_reference_local_var = NULL;
|
|
|
|
|
|
|
|
|
|
// apiregistration_v1_service_reference->name
|
|
|
|
|
cJSON *name = cJSON_GetObjectItemCaseSensitive(apiregistration_v1_service_referenceJSON, "name");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(name)) {
|
|
|
|
|
name = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (name) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(name) && !cJSON_IsNull(name))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 15:42:34 +08:00
|
|
|
// apiregistration_v1_service_reference->_namespace
|
|
|
|
|
cJSON *_namespace = cJSON_GetObjectItemCaseSensitive(apiregistration_v1_service_referenceJSON, "namespace");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(_namespace)) {
|
|
|
|
|
_namespace = NULL;
|
|
|
|
|
}
|
2021-01-05 15:42:34 +08:00
|
|
|
if (_namespace) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(_namespace) && !cJSON_IsNull(_namespace))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// apiregistration_v1_service_reference->port
|
|
|
|
|
cJSON *port = cJSON_GetObjectItemCaseSensitive(apiregistration_v1_service_referenceJSON, "port");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(port)) {
|
|
|
|
|
port = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (port) {
|
|
|
|
|
if(!cJSON_IsNumber(port))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
apiregistration_v1_service_reference_local_var = apiregistration_v1_service_reference_create_internal (
|
2022-12-29 10:58:47 +08:00
|
|
|
name && !cJSON_IsNull(name) ? strdup(name->valuestring) : NULL,
|
|
|
|
|
_namespace && !cJSON_IsNull(_namespace) ? strdup(_namespace->valuestring) : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
port ? port->valuedouble : 0
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return apiregistration_v1_service_reference_local_var;
|
|
|
|
|
end:
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|