Start implementing JSON-LD to RDF conversion for RsaSignature2017

master
teknomunk 1 year ago
parent 34eb37e362
commit f38e204f07

@ -51,8 +51,10 @@ static bool process_one( int id )
act = ap_activity_from_FILE(f);
if( !act ) {
printf( "No activity\n" );
goto failed;
}
f = NULL;
char* remainder = NULL;
char* iter = strtok_r( &toline[4],",",&remainder);

@ -1 +1 @@
Subproject commit 89205ae198eb90c631eb3d00b836f5d89b3c7f81
Subproject commit 5c5b389508bddffd603124a6f6abfdfb934ce598

@ -25,11 +25,36 @@ static struct json_object_field ap_signature_layout[] = {
{ NULL },
};
static struct json_enum ap_activity_type_enum[] = {
// https://www.w3.org/TR/activitystreams-vocabulary/#h-activity-types
struct json_enum ap_activity_type_enum[] = {
{ "Undo", apat_undo },
{ "Follow", apat_follow },
{ "Delete", apat_delete },
{ "Accept", apat_accept },
{ "Create", apat_create },
{ "TentativeAccept", apat_tentative_accept },
{ "Add", apat_add },
{ "Arrive", apat_arrive },
{ "Ignore", apat_ignore },
{ "Join", apat_join },
{ "Leave", apat_leave },
{ "Like", apat_like },
{ "Offer", apat_offer },
{ "Invite", apat_invite },
{ "Reject", apat_reject },
{ "TentativeReject", apat_tentative_reject },
{ "Remove", apat_remove },
{ "Update", apat_update },
{ "View", apat_view },
{ "Listen", apat_listen },
{ "Read", apat_read },
{ "Move", apat_move },
{ "Travel", apat_travel },
{ "Announce", apat_announce },
{ "Block", apat_block },
{ "Flag", apat_flag },
{ "Dislike", apat_dislike },
{ "Question", apat_question },
{ NULL, 0 },
};
@ -42,7 +67,15 @@ struct ap_activity* ap_activity_new()
}
struct ap_activity* ap_activity_from_FILE( FILE* f )
{
return NULL;
struct ap_activity* act = malloc(sizeof(struct ap_activity));
memset(act,0,sizeof(*act));
if( !json_read_object_layout_from_FILE( f, ap_activity_layout, act ) ) {
ap_activity_free(act);
return NULL;
}
return act;
}
struct ap_activity* ap_activity_dup( struct ap_activity* act )
{

@ -21,6 +21,30 @@ enum ap_activity_type
apat_follow = 2,
apat_delete = 3,
apat_accept = 4,
apat_create = 5,
apat_tentative_accept = 6,
apat_add = 7,
apat_arrive = 8,
apat_ignore = 9,
apat_join = 10,
apat_leave = 11,
apat_like = 12,
apat_offer = 13,
apat_invite = 14,
apat_reject = 15,
apat_tentative_reject = 16,
apat_remove = 17,
apat_update = 18,
apat_view = 19,
apat_listen = 20,
apat_read = 21,
apat_move = 22,
apat_travel = 23,
apat_announce = 24,
apat_block = 25,
apat_flag = 26,
apat_dislike = 27,
apat_question = 28,
};
enum ap_activity_object_type {
apaot_ref = 1,

@ -1,18 +1,74 @@
#define _GNU_SOURCE
#include "rsa_signature_2017.h"
#include "model/ap/activity.h"
#include "rdf/serial.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
extern struct rdf_enum_item ap_activity_type_enum[0];
static char* type_filter( const char* name )
{
char* res;
asprintf( &res, "<https://www.w3.org/ns/activitystreams#%s>", name );
return res;
}
struct rdf_enum types = {
.items = ap_activity_type_enum,
.filter = type_filter,
};
struct rdf_serialize_field serial[];
static struct rdf_serialize_field activity_ref_types[] = {
{ (char*)apaot_ref, offsetof( struct ap_activity, object.ref ), &rdf_string_field },
{ (char*)apaot_activity, offsetof( struct ap_activity, object.ptr ), &rdf_object_field, &serial },
{ NULL },
};
struct rdf_serialize_field serial[] = {
{ "", offsetof( struct ap_activity, id ), &rdf_id_field },
{ "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>", offsetof( struct ap_activity, type ), &rdf_enum_field, &types },
{ "<https://www.w3.org/ns/activitystreams#actor>", offsetof( struct ap_activity, actor ), &rdf_string_field },
{ "<https://www.w3.org/ns/activitystreams#to>", offsetof( struct ap_activity, to ), &rdf_array_of_field, &rdf_string_field },
{ "<https://www.w3.org/ns/activitystreams#cc>", offsetof( struct ap_activity, cc ), &rdf_array_of_field, &rdf_string_field },
{ "<https://www.w3.org/ns/activitystreams#bcc>", offsetof( struct ap_activity, bcc ), &rdf_array_of_field, &rdf_string_field },
{ "<https://www.w3.org/ns/activitystreams#object>", offsetof( struct ap_activity, object.tag ), &rdf_tagged_union_field, activity_ref_types },
{ NULL, sizeof(struct ap_activity) },
};
void debug_emit_quad( struct rdf_serializer* rs, struct rdf_quad* q )
{
printf( "%s %s %s %s\n", q->subject, q->predicate, q->object, q->graph );
free(q->subject);
free(q->predicate);
free(q->object);
free(q->graph);
free(q);
}
void ap_activity_create_rsa_signature_2017( struct ap_activity* act )
{
printf( "ap_activity_create_rsa_signature_2017\n" );
struct rdf_serializer rs;
memset(&rs,0,sizeof(rs));
rs.object = strdup(act->id);
char* subject;
asprintf( &subject, "<%s>", act->id );
rs.subject = subject;
rs.graph = strdup(".");
rs.emit_quad = debug_emit_quad;
rdf_serialize_object( &rs, NULL, act );
printf( "\nRDF:\n" );
rdf_serialize_object( &rs, serial, act );
printf( "\n" );
cleanup:
free((char*)rs.subject);
free((char*)rs.graph);
return;
}

@ -1 +1 @@
Subproject commit 7016057c53d9dc123a474e63ddc171e4ae4855ea
Subproject commit 9e72859052e1fd9191ec7a55498f75a1820d55a1
Loading…
Cancel
Save