2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_event_source.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_event_source_t *v1_event_source_create_internal(
|
2020-03-18 17:24:33 +08:00
|
|
|
char *component,
|
|
|
|
|
char *host
|
|
|
|
|
) {
|
|
|
|
|
v1_event_source_t *v1_event_source_local_var = malloc(sizeof(v1_event_source_t));
|
|
|
|
|
if (!v1_event_source_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_event_source_local_var->component = component;
|
|
|
|
|
v1_event_source_local_var->host = host;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_event_source_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return v1_event_source_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_event_source_t *v1_event_source_create(
|
|
|
|
|
char *component,
|
|
|
|
|
char *host
|
|
|
|
|
) {
|
|
|
|
|
return v1_event_source_create_internal (
|
|
|
|
|
component,
|
|
|
|
|
host
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void v1_event_source_free(v1_event_source_t *v1_event_source) {
|
|
|
|
|
if(NULL == v1_event_source){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_event_source->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_event_source_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_event_source->component) {
|
|
|
|
|
free(v1_event_source->component);
|
|
|
|
|
v1_event_source->component = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_event_source->host) {
|
|
|
|
|
free(v1_event_source->host);
|
|
|
|
|
v1_event_source->host = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(v1_event_source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_event_source_convertToJSON(v1_event_source_t *v1_event_source) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_event_source->component
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_event_source->component) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "component", v1_event_source->component) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_event_source->host
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_event_source->host) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "host", v1_event_source->host) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_event_source_t *v1_event_source_parseFromJSON(cJSON *v1_event_sourceJSON){
|
|
|
|
|
|
|
|
|
|
v1_event_source_t *v1_event_source_local_var = NULL;
|
|
|
|
|
|
|
|
|
|
// v1_event_source->component
|
|
|
|
|
cJSON *component = cJSON_GetObjectItemCaseSensitive(v1_event_sourceJSON, "component");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(component)) {
|
|
|
|
|
component = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (component) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(component) && !cJSON_IsNull(component))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_event_source->host
|
|
|
|
|
cJSON *host = cJSON_GetObjectItemCaseSensitive(v1_event_sourceJSON, "host");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(host)) {
|
|
|
|
|
host = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (host) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(host) && !cJSON_IsNull(host))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_event_source_local_var = v1_event_source_create_internal (
|
2022-12-29 10:58:47 +08:00
|
|
|
component && !cJSON_IsNull(component) ? strdup(component->valuestring) : NULL,
|
|
|
|
|
host && !cJSON_IsNull(host) ? strdup(host->valuestring) : NULL
|
2020-03-18 17:24:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_event_source_local_var;
|
|
|
|
|
end:
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|