Deleted the type argument from object_get_my_md5() and object_get().

It was never used.
This commit is contained in:
default 2023-02-05 17:45:00 +01:00
parent bad9f3a8c6
commit 71a7569467
4 changed files with 19 additions and 30 deletions

View File

@ -469,7 +469,7 @@ d_char *msg_admiration(snac *snac, char *object, char *type)
/* call the object */ /* call the object */
timeline_request(snac, &object, &wrk); timeline_request(snac, &object, &wrk);
if (valid_status(object_get(object, &a_msg, NULL))) { if (valid_status(object_get(object, &a_msg))) {
xs *rcpts = xs_list_new(); xs *rcpts = xs_list_new();
msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object); 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
/* demand this thing */ /* demand this thing */
timeline_request(snac, &in_reply_to, &wrk); timeline_request(snac, &in_reply_to, &wrk);
if (valid_status(object_get(in_reply_to, &p_msg, NULL))) { if (valid_status(object_get(in_reply_to, &p_msg))) {
/* add this author as recipient */ /* add this author as recipient */
char *a, *v; char *a, *v;
@ -977,7 +977,7 @@ int process_input_message(snac *snac, char *msg, char *req)
timeline_request(snac, &object, &wrk); timeline_request(snac, &object, &wrk);
if (valid_status(object_get(object, &a_msg, NULL))) { if (valid_status(object_get(object, &a_msg))) {
char *who = xs_dict_get(a_msg, "attributedTo"); char *who = xs_dict_get(a_msg, "attributedTo");
if (who && !is_muted(snac, who)) { if (who && !is_muted(snac, who)) {
@ -1262,7 +1262,7 @@ int activitypub_get_handler(d_char *req, char *q_path,
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *i = NULL; xs *i = NULL;
if (valid_status(object_get_by_md5(v, &i, NULL))) { if (valid_status(object_get_by_md5(v, &i))) {
char *type = xs_dict_get(i, "type"); char *type = xs_dict_get(i, "type");
char *id = xs_dict_get(i, "id"); char *id = xs_dict_get(i, "id");
@ -1287,7 +1287,7 @@ int activitypub_get_handler(d_char *req, char *q_path,
if (xs_startswith(p_path, "p/")) { if (xs_startswith(p_path, "p/")) {
xs *id = xs_fmt("%s/%s", snac.actor, p_path); xs *id = xs_fmt("%s/%s", snac.actor, p_path);
status = object_get(id, &msg, NULL); status = object_get(id, &msg);
} }
else else
status = 404; status = 404;

29
data.c
View File

@ -466,7 +466,7 @@ int object_here(char *id)
} }
int object_get_by_md5(const char *md5, d_char **obj, const char *type) int object_get_by_md5(const char *md5, xs_dict **obj)
/* returns a stored object, optionally of the requested type */ /* returns a stored object, optionally of the requested type */
{ {
int status = 404; int status = 404;
@ -481,19 +481,8 @@ int object_get_by_md5(const char *md5, d_char **obj, const char *type)
*obj = xs_json_loads(j); *obj = xs_json_loads(j);
if (*obj) { if (*obj)
status = 200; status = 200;
/* specific type requested? */
if (!xs_is_null(type)) {
char *v = xs_dict_get(*obj, "type");
if (xs_is_null(v) || strcmp(v, type) != 0) {
status = 404;
*obj = xs_free(*obj);
}
}
}
} }
else else
*obj = NULL; *obj = NULL;
@ -502,11 +491,11 @@ int object_get_by_md5(const char *md5, d_char **obj, const char *type)
} }
int object_get(const char *id, d_char **obj, const char *type) int object_get(const char *id, xs_dict **obj)
/* returns a stored object, optionally of the requested type */ /* returns a stored object, optionally of the requested type */
{ {
xs *md5 = xs_md5_hex(id, strlen(id)); xs *md5 = xs_md5_hex(id, strlen(id));
return object_get_by_md5(md5, obj, type); return object_get_by_md5(md5, obj);
} }
@ -803,7 +792,7 @@ d_char *follower_list(snac *snac)
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *a_obj = NULL; xs *a_obj = NULL;
if (valid_status(object_get_by_md5(v, &a_obj, NULL))) { if (valid_status(object_get_by_md5(v, &a_obj))) {
char *actor = xs_dict_get(a_obj, "id"); char *actor = xs_dict_get(a_obj, "id");
if (!xs_is_null(actor)) if (!xs_is_null(actor))
@ -827,7 +816,7 @@ double timeline_mtime(snac *snac)
int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg)
/* gets a message from the timeline */ /* gets a message from the timeline */
{ {
return object_get_by_md5(md5, msg, NULL); return object_get_by_md5(md5, msg);
} }
@ -851,7 +840,7 @@ void timeline_update_indexes(snac *snac, const char *id)
if (xs_startswith(id, snac->actor)) { if (xs_startswith(id, snac->actor)) {
xs *msg = NULL; xs *msg = NULL;
if (valid_status(object_get(id, &msg, NULL))) { if (valid_status(object_get(id, &msg))) {
/* if its ours and is public, also store in public */ /* if its ours and is public, also store in public */
if (is_msg_public(snac, msg)) if (is_msg_public(snac, msg))
object_user_cache_add(snac, id, "public"); object_user_cache_add(snac, id, "public");
@ -1138,7 +1127,7 @@ void hide(snac *snac, const char *id)
xs *co = NULL; xs *co = NULL;
/* resolve to get the id */ /* resolve to get the id */
if (valid_status(object_get_by_md5(v, &co, NULL))) { if (valid_status(object_get_by_md5(v, &co))) {
if ((v = xs_dict_get(co, "id")) != NULL) if ((v = xs_dict_get(co, "id")) != NULL)
hide(snac, v); hide(snac, v);
} }
@ -1178,7 +1167,7 @@ int actor_get(snac *snac, const char *actor, d_char **data)
} }
/* read the object */ /* read the object */
if (!valid_status(status = object_get(actor, &d, NULL))) if (!valid_status(status = object_get(actor, &d)))
return status; return status;
if (data) if (data)

6
html.c
View File

@ -655,7 +655,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, cons
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
} }
else else
if (valid_status(object_get_by_md5(p, &actor_r, NULL))) { if (valid_status(object_get_by_md5(p, &actor_r))) {
char *name; char *name;
if ((name = xs_dict_get(actor_r, "name")) == NULL) 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 *
xs *id = xs_fmt("%s/%s", snac.actor, p_path); xs *id = xs_fmt("%s/%s", snac.actor, p_path);
xs *msg = NULL; xs *msg = NULL;
if (valid_status(object_get(id, &msg, NULL))) { if (valid_status(object_get(id, &msg))) {
xs *md5 = xs_md5_hex(id, strlen(id)); xs *md5 = xs_md5_hex(id, strlen(id));
xs *list = xs_list_new(); xs *list = xs_list_new();
@ -1416,7 +1416,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
/* an edition of a previous message */ /* an edition of a previous message */
xs *p_msg = NULL; xs *p_msg = NULL;
if (valid_status(object_get(edit_id, &p_msg, NULL))) { if (valid_status(object_get(edit_id, &p_msg))) {
/* copy relevant fields from previous version */ /* copy relevant fields from previous version */
char *fields[] = { "id", "context", "url", "published", char *fields[] = { "id", "context", "url", "published",
"to", "inReplyTo", NULL }; "to", "inReplyTo", NULL };

4
snac.h
View File

@ -65,8 +65,8 @@ int object_add(const char *id, d_char *obj);
int object_add_ow(const char *id, d_char *obj); int object_add_ow(const char *id, d_char *obj);
int object_here_by_md5(char *id); int object_here_by_md5(char *id);
int object_here(char *id); int object_here(char *id);
int object_get_by_md5(const char *md5, d_char **obj, const char *type); int object_get_by_md5(const char *md5, xs_dict **obj);
int object_get(const char *id, d_char **obj, const char *type); int object_get(const char *id, xs_dict **obj);
int object_del(const char *id); int object_del(const char *id);
int object_del_if_unref(const char *id); int object_del_if_unref(const char *id);
int object_admire(const char *id, const char *actor, int like); int object_admire(const char *id, const char *actor, int like);