diff options
| -rw-r--r-- | activitypub.c | 28 | ||||
| -rw-r--r-- | main.c | 31 | ||||
| -rw-r--r-- | snac.h | 1 |
3 files changed, 55 insertions, 5 deletions
diff --git a/activitypub.c b/activitypub.c index d54e5ba..3ea05f5 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -380,6 +380,34 @@ d_char *msg_create(snac *snac, char *object) | |||
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | 382 | ||
| 383 | d_char *msg_follow(snac *snac, char *actor) | ||
| 384 | /* creates a 'Follow' message */ | ||
| 385 | { | ||
| 386 | d_char *actor_o = NULL; | ||
| 387 | d_char *msg = NULL; | ||
| 388 | int status; | ||
| 389 | |||
| 390 | /* request the actor */ | ||
| 391 | status = actor_request(snac, actor, &actor_o); | ||
| 392 | |||
| 393 | if (valid_status(status)) { | ||
| 394 | /* check if the actor is an alias */ | ||
| 395 | char *r_actor = xs_dict_get(actor_o, "id"); | ||
| 396 | |||
| 397 | if (r_actor && strcmp(actor, r_actor) != 0) { | ||
| 398 | snac_log(snac, xs_fmt("actor to follow is an alias %s -> %s", actor, r_actor)); | ||
| 399 | actor = r_actor; | ||
| 400 | } | ||
| 401 | |||
| 402 | msg = msg_base(snac, "Follow", "@dummy", snac->actor, NULL, actor); | ||
| 403 | } | ||
| 404 | else | ||
| 405 | snac_log(snac, xs_fmt("cannot get actor to follow %s %d", actor, status)); | ||
| 406 | |||
| 407 | return msg; | ||
| 408 | } | ||
| 409 | |||
| 410 | |||
| 383 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to) | 411 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to) |
| 384 | /* creates a 'Note' message */ | 412 | /* creates a 'Note' message */ |
| 385 | { | 413 | { |
| @@ -19,13 +19,14 @@ int usage(void) | |||
| 19 | printf("httpd {basedir} Starts the HTTPD daemon\n"); | 19 | printf("httpd {basedir} Starts the HTTPD daemon\n"); |
| 20 | printf("webfinger {basedir} {user} Queries about a @user@host or actor\n"); | 20 | printf("webfinger {basedir} {user} Queries about a @user@host or actor\n"); |
| 21 | printf("queue {basedir} {uid} Processes a user queue\n"); | 21 | printf("queue {basedir} {uid} Processes a user queue\n"); |
| 22 | printf("follow {basedir} {uid} {actor} Follows an actor\n"); | ||
| 23 | |||
| 22 | // printf("check {basedir} [{uid}] Checks the database\n"); | 24 | // printf("check {basedir} [{uid}] Checks the database\n"); |
| 23 | // printf("purge {basedir} [{uid}] Purges old data\n"); | 25 | // printf("purge {basedir} [{uid}] Purges old data\n"); |
| 24 | // printf("adduser {basedir} [{uid}] Adds a new user\n"); | 26 | // printf("adduser {basedir} [{uid}] Adds a new user\n"); |
| 25 | 27 | ||
| 26 | // printf("update {basedir} {uid} Sends a user update to followers\n"); | 28 | // printf("update {basedir} {uid} Sends a user update to followers\n"); |
| 27 | // printf("passwd {basedir} {uid} Sets the password for {uid}\n"); | 29 | // printf("passwd {basedir} {uid} Sets the password for {uid}\n"); |
| 28 | // printf("follow {basedir} {uid} {actor} Follows an actor\n"); | ||
| 29 | // printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); | 30 | // printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); |
| 30 | // printf("mute {basedir} {uid} {actor} Mutes an actor\n"); | 31 | // printf("mute {basedir} {uid} {actor} Mutes an actor\n"); |
| 31 | // printf("unmute {basedir} {uid} {actor} Unmutes an actor\n"); | 32 | // printf("unmute {basedir} {uid} {actor} Unmutes an actor\n"); |
| @@ -124,8 +125,29 @@ int main(int argc, char *argv[]) | |||
| 124 | if (msg != NULL) { | 125 | if (msg != NULL) { |
| 125 | post(&snac, msg); | 126 | post(&snac, msg); |
| 126 | 127 | ||
| 127 | xs *j = xs_json_dumps_pp(msg, 4); | 128 | if (dbglevel) { |
| 128 | printf("%s\n", j); | 129 | xs *j = xs_json_dumps_pp(msg, 4); |
| 130 | printf("%s\n", j); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | return 0; | ||
| 135 | } | ||
| 136 | |||
| 137 | if (strcmp(cmd, "follow") == 0) { | ||
| 138 | xs *msg = msg_follow(&snac, url); | ||
| 139 | |||
| 140 | if (msg != NULL) { | ||
| 141 | char *actor = xs_dict_get(msg, "object"); | ||
| 142 | |||
| 143 | following_add(&snac, actor, msg); | ||
| 144 | |||
| 145 | enqueue_output(&snac, msg, actor, 0); | ||
| 146 | |||
| 147 | if (dbglevel) { | ||
| 148 | xs *j = xs_json_dumps_pp(msg, 4); | ||
| 149 | printf("%s\n", j); | ||
| 150 | } | ||
| 129 | } | 151 | } |
| 130 | 152 | ||
| 131 | return 0; | 153 | return 0; |
| @@ -164,7 +186,6 @@ int main(int argc, char *argv[]) | |||
| 164 | } | 186 | } |
| 165 | 187 | ||
| 166 | if (strcmp(cmd, "note") == 0) { | 188 | if (strcmp(cmd, "note") == 0) { |
| 167 | int status; | ||
| 168 | xs *content = NULL; | 189 | xs *content = NULL; |
| 169 | xs *msg = NULL; | 190 | xs *msg = NULL; |
| 170 | xs *c_msg = NULL; | 191 | xs *c_msg = NULL; |
| @@ -194,7 +215,7 @@ int main(int argc, char *argv[]) | |||
| 194 | 215 | ||
| 195 | c_msg = msg_create(&snac, msg); | 216 | c_msg = msg_create(&snac, msg); |
| 196 | 217 | ||
| 197 | { | 218 | if (dbglevel) { |
| 198 | xs *j = xs_json_dumps_pp(c_msg, 4); | 219 | xs *j = xs_json_dumps_pp(c_msg, 4); |
| 199 | printf("%s\n", j); | 220 | printf("%s\n", j); |
| 200 | } | 221 | } |
| @@ -89,6 +89,7 @@ int webfinger_get_handler(d_char *req, char *q_path, | |||
| 89 | 89 | ||
| 90 | d_char *msg_admiration(snac *snac, char *object, char *type); | 90 | d_char *msg_admiration(snac *snac, char *object, char *type); |
| 91 | d_char *msg_create(snac *snac, char *object); | 91 | d_char *msg_create(snac *snac, char *object); |
| 92 | d_char *msg_follow(snac *snac, char *actor); | ||
| 92 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to); | 93 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to); |
| 93 | 94 | ||
| 94 | int activitypub_request(snac *snac, char *url, d_char **data); | 95 | int activitypub_request(snac *snac, char *url, d_char **data); |