You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.3 KiB
C

#include "tag.h"
#include "json/layout.h"
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
static struct json_enum ap_activity_tag_enum[] = {
{ "Mention", aptag_mention },
{ "Emoji", aptag_emoji },
{ NULL, 0 },
};
extern struct json_enum ap_object_type_enum[];
#define OBJ_TYPE struct ap_activity_tag
static struct json_object_field tag_icon_layout[] = {
{
.key = "url",
.offset = offsetof( OBJ_TYPE, icon.url ),
.type = &json_field_string,
},
{
.key = "type",
.offset = offsetof( OBJ_TYPE, icon.type ),
.type = &json_field_enum,
.enum_list = ap_object_type_enum,
},
JSON_FIELD_END,
};
static struct json_object_field ap_activity_tag_layout[] = {
JSON_FIELD_STRING( href, false ),
JSON_FIELD_STRING( name, false ),
JSON_FIELD_STRING( id, false ),
JSON_FIELD_DATETIME( updated, false ),
{
.key = "icon",
.offset = 0,
.type = &json_field_object_composite,
.composite_layout = tag_icon_layout,
},
JSON_FIELD_ENUM( type, ap_activity_tag_enum, true ),
JSON_FIELD_END,
};
#undef OBJ_TYPE
void ap_activity_tag_free( struct ap_activity_tag* tag )
{
if( !tag ) { return; }
free(tag->icon.url);
free(tag->href);
free(tag->id);
free(tag->name);
memset(tag,0,sizeof(*tag));
free(tag);
}
JSON_FIELD_TYPE_OBJECT_LAYOUT_WITH_DEFAULTS( ap_activity_tag );