diff options
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/activitypub.c b/activitypub.c index 0d5439d..6127dab 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -437,7 +437,8 @@ void process_tags(snac *snac, const char *content, d_char **n_content, d_char ** | |||
| 437 | 437 | ||
| 438 | /** messages **/ | 438 | /** messages **/ |
| 439 | 439 | ||
| 440 | d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char *object) | 440 | xs_dict *msg_base(snac *snac, const char *type, const char *id, |
| 441 | const char *actor, const char *date, const char *object) | ||
| 441 | /* creates a base ActivityPub message */ | 442 | /* creates a base ActivityPub message */ |
| 442 | { | 443 | { |
| 443 | xs *did = NULL; | 444 | xs *did = NULL; |
| @@ -467,7 +468,7 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char | |||
| 467 | } | 468 | } |
| 468 | } | 469 | } |
| 469 | 470 | ||
| 470 | d_char *msg = xs_dict_new(); | 471 | xs_dict *msg = xs_dict_new(); |
| 471 | 472 | ||
| 472 | msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams"); | 473 | msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams"); |
| 473 | msg = xs_dict_append(msg, "type", type); | 474 | 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, | |||
| 845 | } | 846 | } |
| 846 | 847 | ||
| 847 | 848 | ||
| 849 | xs_dict *msg_ping(snac *user, const char *rcpt) | ||
| 850 | /* creates a Ping message (https://humungus.tedunangst.com/r/honk/v/tip/f/docs/ping.txt) */ | ||
| 851 | { | ||
| 852 | xs_dict *msg = msg_base(user, "Ping", "@dummy", user->actor, NULL, NULL); | ||
| 853 | |||
| 854 | msg = xs_dict_append(msg, "to", rcpt); | ||
| 855 | |||
| 856 | return msg; | ||
| 857 | } | ||
| 858 | |||
| 859 | |||
| 860 | xs_dict *msg_pong(snac *user, const char *rcpt, const char *object) | ||
| 861 | /* creates a Pong message (https://humungus.tedunangst.com/r/honk/v/tip/f/docs/ping.txt) */ | ||
| 862 | { | ||
| 863 | xs_dict *msg = msg_base(user, "Pong", "@dummy", user->actor, NULL, object); | ||
| 864 | |||
| 865 | msg = xs_dict_append(msg, "to", rcpt); | ||
| 866 | |||
| 867 | return msg; | ||
| 868 | } | ||
| 869 | |||
| 870 | |||
| 848 | void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg) | 871 | void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg) |
| 849 | /* notifies the user of relevant events */ | 872 | /* notifies the user of relevant events */ |
| 850 | { | 873 | { |
| @@ -1147,7 +1170,19 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) | |||
| 1147 | snac_debug(snac, 1, xs_fmt("ignored 'Delete' for unknown object %s", object)); | 1170 | snac_debug(snac, 1, xs_fmt("ignored 'Delete' for unknown object %s", object)); |
| 1148 | } | 1171 | } |
| 1149 | else | 1172 | else |
| 1150 | snac_debug(snac, 1, xs_fmt("process_message type '%s' ignored", type)); | 1173 | if (strcmp(type, "Pong") == 0) { |
| 1174 | snac_log(snac, xs_fmt("'Pong' received from %s", actor)); | ||
| 1175 | } | ||
| 1176 | else | ||
| 1177 | if (strcmp(type, "Ping") == 0) { | ||
| 1178 | snac_log(snac, xs_fmt("'Ping' requested from %s", actor)); | ||
| 1179 | |||
| 1180 | xs *rsp = msg_pong(snac, actor, xs_dict_get(msg, "id")); | ||
| 1181 | |||
| 1182 | enqueue_output_by_actor(snac, rsp, actor, 0); | ||
| 1183 | } | ||
| 1184 | else | ||
| 1185 | snac_debug(snac, 1, xs_fmt("process_input_message type '%s' ignored", type)); | ||
| 1151 | 1186 | ||
| 1152 | if (do_notify) { | 1187 | if (do_notify) { |
| 1153 | notify(snac, type, utype, actor, msg); | 1188 | notify(snac, type, utype, actor, msg); |