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.

327 lines
6.1 KiB
C

#pragma once
#include "json/value.h"
#include "json/layout.h"
#include "object/context.h"
#include "object/tag.h"
#include <time.h>
// Reference: https://www.w3.org/TR/activitystreams-vocabulary/
struct ap_object;
struct ap_activity_source
{
char* mime_type;
char* content;
// TODO: add map;
};
enum ap_signature_type
{
apst_rsa_signature_2017 = 1,
};
struct ap_signature
{
int type;
char* creator;
time_t created;
char* value;
};
enum ap_object_type
{
// Activity Types
ap_Undo = 1,
ap_Follow = 2,
ap_Delete = 3,
ap_Accept = 4,
ap_Create = 5,
ap_TentativeAccept = 6,
ap_Add = 7,
ap_Arrive = 8,
ap_Ignore = 9,
ap_Join = 10,
ap_Leave = 11,
ap_Like = 12,
ap_Offer = 13,
ap_Invite = 14,
ap_Reject = 15,
ap_TentativeReject = 16,
ap_Remove = 17,
ap_Update = 18,
ap_View = 19,
ap_Listen = 20,
ap_Read = 21,
ap_Move = 22,
ap_Travel = 23,
ap_Announce = 24,
ap_Block = 25,
ap_Flag = 26,
ap_Dislike = 27,
// Object Types
ap_Note = 100,
ap_Question = 101,
ap_Article = 102,
ap_Audio = 103,
ap_Document = 104,
ap_Event = 105,
ap_Image = 106,
ap_Page = 107,
ap_Place = 108,
ap_Profile = 109,
ap_Relationship = 110,
ap_Tombstone = 111,
ap_Video = 112,
// Actor Types
ap_Person = 200,
ap_Service = 201,
ap_Application = 202,
ap_Group = 203,
ap_Organization = 204,
// Collection Types
ap_OrderedCollection = 301,
ap_OrderedCollectionPage = 302,
ap_Collection = 303,
ap_CollectionPage = 304,
/// Pleroma Types
pleroma_EmojiReact = 28,
/// Musicbox Types
musicbox_Track = 501,
musicbox_Album = 502,
musicbox_Artist = 503,
/// Forge Types (https://forgefed.org/vocabulary.html)
forge_Grant = 601,
forge_Push = 602,
forge_Repository = 603,
forge_TicketTracker = 604,
forge_PatchTracker = 605,
forge_Project = 606,
forge_Team = 607,
forge_Branch = 608,
forge_Commit = 609,
forge_TicketDependency = 610,
forge_Ticket = 611,
/// Schema.org types
schema_PropertyValue = 401, // https://schema.org/PropertyValue
ap_Object = 9001,
};
extern struct json_enum ap_object_type_enum[];
enum ap_activity_object_type {
apaot_ref = 1,
apaot_activity = 2,
apaot_object = 2,
};
struct ap_object_ptr_or_ref
{
int tag;
union {
char* ref;
struct ap_object* ptr;
};
};
struct ap_public_key
{
char* id;
char* owner;
char* public_key;
};
void ap_object_ptr_or_ref_free( struct ap_object_ptr_or_ref* oor );
void ap_object_ptr_or_ref_free_composite( struct ap_object_ptr_or_ref* oor );
void ap_object_ptr_or_ref_force_embedded( struct ap_object_ptr_or_ref* oor );
struct ap_object_vtable
{
const char* type_string;
const char* json_ld_type;
int type;
struct json_layout* layout;
void (*free)( void* ptr );
void* (*alloc)();
struct ap_object_vtable* next;
};
extern struct ap_object_vtable ap_object_vtable;
void register_ap_object_type( struct ap_object_vtable* vtable );
struct ap_object
{
// Model Database fields
int local_id;
struct ap_object_vtable* vtable;
// JSON-LD fields
struct ap_activity_context ap_context;
char* id;
int type;
// Object-specific fields. See https://www.w3.org/TR/activitystreams-vocabulary/#dfn-object
struct {
struct ap_object** items;
int count;
} attachments;
char* attributed_to;
// audience
struct ap_activity_source content;
char* name;
time_t end_time;
// generator
struct ap_object* icon;
struct ap_object* image;
char* in_reply_to;
char* quote_url;
// location
// preview
time_t published;
struct ap_object_ptr_or_ref replies;
// startTime
char* summary;
struct {
struct ap_activity_tag** items;
int count;
} tags;
time_t updated;
struct {
struct ap_object_ptr_or_ref* items;
int count;
} url;
struct {
char** items;
int count;
} to, cc, bcc, bto;
char* media_type;
// duration
// PropertyValue-specific fields
char* value;
// Link-specific fields
char* href;
char* rel;
// Activity-specific fields
char* actor;
struct ap_object_ptr_or_ref object;
char* target;
// result
// origin
// instrument
// Actor-specific fields
char* inbox;
char* outbox;
char* preferred_username;
struct {
char* shared_inbox;
} endpoints;
char* featured;
char* followers;
char* following;
struct {
bool show;
bool accepts_chat_messages;
} capabilities;
//char* avatar;
//char* banner;
struct rich_bool discoverable;
struct rich_bool manually_approves_followers;
struct ap_public_key* public_key;
char* context;
int context_id; // WARNING! Not in layout
bool direct_message;
char* conversation;
struct ap_activity_source source;
bool sensitive;
struct {
char** items;
int count;
} also_known_as;
// Other
char* state;
// Signature
int has_signature;
struct ap_signature signature;
// Collection fields
struct ap_object_ptr_or_ref first;
struct ap_object_ptr_or_ref next;
char* prev;
char* part_of;
int total_items;
struct {
struct ap_object_ptr_or_ref* items;
int count;
} collection_items;
struct {
struct ap_object_ptr_or_ref* items;
int count;
} ordered_items;
// Question fields
struct {
struct ap_object_ptr_or_ref* items;
int count;
} one_of;
struct {
struct ap_object_ptr_or_ref* items;
int count;
} any_of;
time_t closed;
struct json_value extra;
};
// JSON Layout types
struct json_object_field;
extern struct json_field_type ap_object_type;
extern struct json_field_type ap_object_ptr_or_ref_type;
// JSON Layouts
extern struct json_object_field ap_object_layout[];
// Dependency Injection
void ap_object_set_fetch_callback( struct ap_object* (*callback)( const char* uri ) );
struct ap_object* ap_object_fetch( const char* uri );
// Creation and Deletion
struct ap_object* ap_object_new();
struct ap_object* ap_object_dup( struct ap_object* o );
void ap_object_free( struct ap_object* o );
void ap_object_free_composite( struct ap_object* o );
// Seralization/Deserialization
struct ap_object* ap_object_from_FILE( FILE* f );
struct ap_object* ap_object_from_file( const char* filename );
void ap_object_write_to_FILE( struct ap_object* o, FILE* f );
// Context handling
bool ap_object_has_context( struct ap_object* o, const char* ctx );
void ap_object_add_context( struct ap_object* o, const char* ctx );
// Convenience methods
void ap_object_array_append_ref( void* ptr, char* ref );