summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activitypub.c10
-rw-r--r--data.c29
-rw-r--r--html.c6
-rw-r--r--snac.h4
4 files changed, 19 insertions, 30 deletions
diff --git a/activitypub.c b/activitypub.c
index 4f0e246..42558f4 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -469,7 +469,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type)
469 /* call the object */ 469 /* call the object */
470 timeline_request(snac, &object, &wrk); 470 timeline_request(snac, &object, &wrk);
471 471
472 if (valid_status(object_get(object, &a_msg, NULL))) { 472 if (valid_status(object_get(object, &a_msg))) {
473 xs *rcpts = xs_list_new(); 473 xs *rcpts = xs_list_new();
474 474
475 msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object); 475 msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object);
@@ -664,7 +664,7 @@ xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, xs_str *in_reply_t
664 /* demand this thing */ 664 /* demand this thing */
665 timeline_request(snac, &in_reply_to, &wrk); 665 timeline_request(snac, &in_reply_to, &wrk);
666 666
667 if (valid_status(object_get(in_reply_to, &p_msg, NULL))) { 667 if (valid_status(object_get(in_reply_to, &p_msg))) {
668 /* add this author as recipient */ 668 /* add this author as recipient */
669 char *a, *v; 669 char *a, *v;
670 670
@@ -977,7 +977,7 @@ int process_input_message(snac *snac, char *msg, char *req)
977 977
978 timeline_request(snac, &object, &wrk); 978 timeline_request(snac, &object, &wrk);
979 979
980 if (valid_status(object_get(object, &a_msg, NULL))) { 980 if (valid_status(object_get(object, &a_msg))) {
981 char *who = xs_dict_get(a_msg, "attributedTo"); 981 char *who = xs_dict_get(a_msg, "attributedTo");
982 982
983 if (who && !is_muted(snac, who)) { 983 if (who && !is_muted(snac, who)) {
@@ -1262,7 +1262,7 @@ int activitypub_get_handler(d_char *req, char *q_path,
1262 while (xs_list_iter(&p, &v)) { 1262 while (xs_list_iter(&p, &v)) {
1263 xs *i = NULL; 1263 xs *i = NULL;
1264 1264
1265 if (valid_status(object_get_by_md5(v, &i, NULL))) { 1265 if (valid_status(object_get_by_md5(v, &i))) {
1266 char *type = xs_dict_get(i, "type"); 1266 char *type = xs_dict_get(i, "type");
1267 char *id = xs_dict_get(i, "id"); 1267 char *id = xs_dict_get(i, "id");
1268 1268
@@ -1287,7 +1287,7 @@ int activitypub_get_handler(d_char *req, char *q_path,
1287 if (xs_startswith(p_path, "p/")) { 1287 if (xs_startswith(p_path, "p/")) {
1288 xs *id = xs_fmt("%s/%s", snac.actor, p_path); 1288 xs *id = xs_fmt("%s/%s", snac.actor, p_path);
1289 1289
1290 status = object_get(id, &msg, NULL); 1290 status = object_get(id, &msg);
1291 } 1291 }
1292 else 1292 else
1293 status = 404; 1293 status = 404;
diff --git a/data.c b/data.c
index a826b0a..6c3408f 100644
--- a/data.c
+++ b/data.c
@@ -466,7 +466,7 @@ int object_here(char *id)
466} 466}
467 467
468 468
469int object_get_by_md5(const char *md5, d_char **obj, const char *type) 469int object_get_by_md5(const char *md5, xs_dict **obj)
470/* returns a stored object, optionally of the requested type */ 470/* returns a stored object, optionally of the requested type */
471{ 471{
472 int status = 404; 472 int status = 404;
@@ -481,19 +481,8 @@ int object_get_by_md5(const char *md5, d_char **obj, const char *type)
481 481
482 *obj = xs_json_loads(j); 482 *obj = xs_json_loads(j);
483 483
484 if (*obj) { 484 if (*obj)
485 status = 200; 485 status = 200;
486
487 /* specific type requested? */
488 if (!xs_is_null(type)) {
489 char *v = xs_dict_get(*obj, "type");
490
491 if (xs_is_null(v) || strcmp(v, type) != 0) {
492 status = 404;
493 *obj = xs_free(*obj);
494 }
495 }
496 }
497 } 486 }
498 else 487 else
499 *obj = NULL; 488 *obj = NULL;
@@ -502,11 +491,11 @@ int object_get_by_md5(const char *md5, d_char **obj, const char *type)
502} 491}
503 492
504 493
505int object_get(const char *id, d_char **obj, const char *type) 494int object_get(const char *id, xs_dict **obj)
506/* returns a stored object, optionally of the requested type */ 495/* returns a stored object, optionally of the requested type */
507{ 496{
508 xs *md5 = xs_md5_hex(id, strlen(id)); 497 xs *md5 = xs_md5_hex(id, strlen(id));
509 return object_get_by_md5(md5, obj, type); 498 return object_get_by_md5(md5, obj);
510} 499}
511 500
512 501
@@ -803,7 +792,7 @@ d_char *follower_list(snac *snac)
803 while (xs_list_iter(&p, &v)) { 792 while (xs_list_iter(&p, &v)) {
804 xs *a_obj = NULL; 793 xs *a_obj = NULL;
805 794
806 if (valid_status(object_get_by_md5(v, &a_obj, NULL))) { 795 if (valid_status(object_get_by_md5(v, &a_obj))) {
807 char *actor = xs_dict_get(a_obj, "id"); 796 char *actor = xs_dict_get(a_obj, "id");
808 797
809 if (!xs_is_null(actor)) 798 if (!xs_is_null(actor))
@@ -827,7 +816,7 @@ double timeline_mtime(snac *snac)
827int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) 816int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
828/* gets a message from the timeline */ 817/* gets a message from the timeline */
829{ 818{
830 return object_get_by_md5(md5, msg, NULL); 819 return object_get_by_md5(md5, msg);
831} 820}
832 821
833 822
@@ -851,7 +840,7 @@ void timeline_update_indexes(snac *snac, const char *id)
851 if (xs_startswith(id, snac->actor)) { 840 if (xs_startswith(id, snac->actor)) {
852 xs *msg = NULL; 841 xs *msg = NULL;
853 842
854 if (valid_status(object_get(id, &msg, NULL))) { 843 if (valid_status(object_get(id, &msg))) {
855 /* if its ours and is public, also store in public */ 844 /* if its ours and is public, also store in public */
856 if (is_msg_public(snac, msg)) 845 if (is_msg_public(snac, msg))
857 object_user_cache_add(snac, id, "public"); 846 object_user_cache_add(snac, id, "public");
@@ -1138,7 +1127,7 @@ void hide(snac *snac, const char *id)
1138 xs *co = NULL; 1127 xs *co = NULL;
1139 1128
1140 /* resolve to get the id */ 1129 /* resolve to get the id */
1141 if (valid_status(object_get_by_md5(v, &co, NULL))) { 1130 if (valid_status(object_get_by_md5(v, &co))) {
1142 if ((v = xs_dict_get(co, "id")) != NULL) 1131 if ((v = xs_dict_get(co, "id")) != NULL)
1143 hide(snac, v); 1132 hide(snac, v);
1144 } 1133 }
@@ -1178,7 +1167,7 @@ int actor_get(snac *snac, const char *actor, d_char **data)
1178 } 1167 }
1179 1168
1180 /* read the object */ 1169 /* read the object */
1181 if (!valid_status(status = object_get(actor, &d, NULL))) 1170 if (!valid_status(status = object_get(actor, &d)))
1182 return status; 1171 return status;
1183 1172
1184 if (data) 1173 if (data)
diff --git a/html.c b/html.c
index 893db2e..f163921 100644
--- a/html.c
+++ b/html.c
@@ -655,7 +655,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, cons
655 s = xs_str_cat(s, s1); 655 s = xs_str_cat(s, s1);
656 } 656 }
657 else 657 else
658 if (valid_status(object_get_by_md5(p, &actor_r, NULL))) { 658 if (valid_status(object_get_by_md5(p, &actor_r))) {
659 char *name; 659 char *name;
660 660
661 if ((name = xs_dict_get(actor_r, "name")) == NULL) 661 if ((name = xs_dict_get(actor_r, "name")) == NULL)
@@ -1190,7 +1190,7 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
1190 xs *id = xs_fmt("%s/%s", snac.actor, p_path); 1190 xs *id = xs_fmt("%s/%s", snac.actor, p_path);
1191 xs *msg = NULL; 1191 xs *msg = NULL;
1192 1192
1193 if (valid_status(object_get(id, &msg, NULL))) { 1193 if (valid_status(object_get(id, &msg))) {
1194 xs *md5 = xs_md5_hex(id, strlen(id)); 1194 xs *md5 = xs_md5_hex(id, strlen(id));
1195 xs *list = xs_list_new(); 1195 xs *list = xs_list_new();
1196 1196
@@ -1416,7 +1416,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
1416 /* an edition of a previous message */ 1416 /* an edition of a previous message */
1417 xs *p_msg = NULL; 1417 xs *p_msg = NULL;
1418 1418
1419 if (valid_status(object_get(edit_id, &p_msg, NULL))) { 1419 if (valid_status(object_get(edit_id, &p_msg))) {
1420 /* copy relevant fields from previous version */ 1420 /* copy relevant fields from previous version */
1421 char *fields[] = { "id", "context", "url", "published", 1421 char *fields[] = { "id", "context", "url", "published",
1422 "to", "inReplyTo", NULL }; 1422 "to", "inReplyTo", NULL };
diff --git a/snac.h b/snac.h
index 9ebb532..8617e32 100644
--- a/snac.h
+++ b/snac.h
@@ -65,8 +65,8 @@ int object_add(const char *id, d_char *obj);
65int object_add_ow(const char *id, d_char *obj); 65int object_add_ow(const char *id, d_char *obj);
66int object_here_by_md5(char *id); 66int object_here_by_md5(char *id);
67int object_here(char *id); 67int object_here(char *id);
68int object_get_by_md5(const char *md5, d_char **obj, const char *type); 68int object_get_by_md5(const char *md5, xs_dict **obj);
69int object_get(const char *id, d_char **obj, const char *type); 69int object_get(const char *id, xs_dict **obj);
70int object_del(const char *id); 70int object_del(const char *id);
71int object_del_if_unref(const char *id); 71int object_del_if_unref(const char *id);
72int object_admire(const char *id, const char *actor, int like); 72int object_admire(const char *id, const char *actor, int like);