mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-14 17:45:04 +00:00
Implemented 'Ping' and 'Pong' activities.
According to https://humungus.tedunangst.com/r/honk/v/tip/f/docs/ping.txt
This commit is contained in:
parent
cd71bd08bf
commit
d3a36218a6
3 changed files with 54 additions and 3 deletions
|
@ -437,7 +437,8 @@ void process_tags(snac *snac, const char *content, d_char **n_content, d_char **
|
|||
|
||||
/** messages **/
|
||||
|
||||
d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char *object)
|
||||
xs_dict *msg_base(snac *snac, const char *type, const char *id,
|
||||
const char *actor, const char *date, const char *object)
|
||||
/* creates a base ActivityPub message */
|
||||
{
|
||||
xs *did = NULL;
|
||||
|
@ -467,7 +468,7 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char
|
|||
}
|
||||
}
|
||||
|
||||
d_char *msg = xs_dict_new();
|
||||
xs_dict *msg = xs_dict_new();
|
||||
|
||||
msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams");
|
||||
msg = xs_dict_append(msg, "type", type);
|
||||
|
@ -845,6 +846,28 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
|
|||
}
|
||||
|
||||
|
||||
xs_dict *msg_ping(snac *user, const char *rcpt)
|
||||
/* creates a Ping message (https://humungus.tedunangst.com/r/honk/v/tip/f/docs/ping.txt) */
|
||||
{
|
||||
xs_dict *msg = msg_base(user, "Ping", "@dummy", user->actor, NULL, NULL);
|
||||
|
||||
msg = xs_dict_append(msg, "to", rcpt);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
xs_dict *msg_pong(snac *user, const char *rcpt, const char *object)
|
||||
/* creates a Pong message (https://humungus.tedunangst.com/r/honk/v/tip/f/docs/ping.txt) */
|
||||
{
|
||||
xs_dict *msg = msg_base(user, "Pong", "@dummy", user->actor, NULL, object);
|
||||
|
||||
msg = xs_dict_append(msg, "to", rcpt);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg)
|
||||
/* notifies the user of relevant events */
|
||||
{
|
||||
|
@ -1147,7 +1170,19 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
|
|||
snac_debug(snac, 1, xs_fmt("ignored 'Delete' for unknown object %s", object));
|
||||
}
|
||||
else
|
||||
snac_debug(snac, 1, xs_fmt("process_message type '%s' ignored", type));
|
||||
if (strcmp(type, "Pong") == 0) {
|
||||
snac_log(snac, xs_fmt("'Pong' received from %s", actor));
|
||||
}
|
||||
else
|
||||
if (strcmp(type, "Ping") == 0) {
|
||||
snac_log(snac, xs_fmt("'Ping' requested from %s", actor));
|
||||
|
||||
xs *rsp = msg_pong(snac, actor, xs_dict_get(msg, "id"));
|
||||
|
||||
enqueue_output_by_actor(snac, rsp, actor, 0);
|
||||
}
|
||||
else
|
||||
snac_debug(snac, 1, xs_fmt("process_input_message type '%s' ignored", type));
|
||||
|
||||
if (do_notify) {
|
||||
notify(snac, type, utype, actor, msg);
|
||||
|
|
14
main.c
14
main.c
|
@ -30,6 +30,7 @@ int usage(void)
|
|||
printf("actor {basedir} {uid} {url} Requests an actor\n");
|
||||
printf("note {basedir} {uid} {'text'} Sends a note to followers\n");
|
||||
printf("resetpwd {basedir} {uid} Resets the password of a user\n");
|
||||
printf("ping {basedir} {uid} {actor} Pings an actor\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -228,6 +229,19 @@ int main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "ping") == 0) {
|
||||
xs *msg = msg_ping(&snac, url);
|
||||
|
||||
enqueue_output_by_actor(&snac, msg, url, 0);
|
||||
|
||||
if (dbglevel) {
|
||||
xs *j = xs_json_dumps_pp(msg, 4);
|
||||
printf("%s\n", msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "request") == 0) {
|
||||
int status;
|
||||
xs *data = NULL;
|
||||
|
|
2
snac.h
2
snac.h
|
@ -203,6 +203,8 @@ d_char *msg_undo(snac *snac, char *object);
|
|||
d_char *msg_delete(snac *snac, char *id);
|
||||
d_char *msg_actor(snac *snac);
|
||||
xs_dict *msg_update(snac *snac, xs_dict *object);
|
||||
xs_dict *msg_ping(snac *user, const char *rcpt);
|
||||
xs_dict *msg_pong(snac *user, const char *rcpt, const char *object);
|
||||
|
||||
int activitypub_request(snac *snac, const char *url, xs_dict **data);
|
||||
int actor_request(snac *snac, const char *actor, xs_dict **data);
|
||||
|
|
Loading…
Reference in a new issue