mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-10 03:50:38 +03:00
Simplified is_msg_public().
This commit is contained in:
parent
e74ae0f589
commit
29b12498dd
@ -279,46 +279,13 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
int is_msg_public(snac *snac, xs_dict *msg)
|
||||||
d_char *inbox_list(snac *snac, char *msg)
|
|
||||||
/* returns the list of inboxes that are recipients of this message */
|
|
||||||
{
|
|
||||||
xs *rcpts = recipient_list(snac, msg, 1);
|
|
||||||
xs_set inboxes;
|
|
||||||
char *p, *v;
|
|
||||||
|
|
||||||
xs_set_init(&inboxes);
|
|
||||||
|
|
||||||
p = rcpts;
|
|
||||||
while (xs_list_iter(&p, &v)) {
|
|
||||||
xs *inbox;
|
|
||||||
|
|
||||||
if ((inbox = get_actor_inbox(snac, v)) != NULL) {
|
|
||||||
/* add the inbox if it's not already there */
|
|
||||||
xs_set_add(&inboxes, inbox);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
snac_log(snac, xs_fmt("cannot find inbox for %s", v));
|
|
||||||
}
|
|
||||||
|
|
||||||
return xs_set_result(&inboxes);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int is_msg_public(snac *snac, char *msg)
|
|
||||||
/* checks if a message is public */
|
/* checks if a message is public */
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
xs *rcpts = recipient_list(snac, msg, 0);
|
xs *rcpts = recipient_list(snac, msg, 0);
|
||||||
char *p, *v;
|
|
||||||
|
|
||||||
p = rcpts;
|
return xs_list_in(rcpts, public_address) != -1;
|
||||||
while (!ret && xs_list_iter(&p, &v)) {
|
|
||||||
if (strcmp(v, public_address) == 0)
|
|
||||||
ret = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
31
data.c
31
data.c
@ -1375,7 +1375,7 @@ void inbox_add(const char *inbox)
|
|||||||
xs *fn = xs_fmt("%s/inbox/%s", srv_basedir, md5);
|
xs *fn = xs_fmt("%s/inbox/%s", srv_basedir, md5);
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
if ((f = fopen(fn, "w")) != NULL) {
|
if (strlen(inbox) < 256 && (f = fopen(fn, "w")) != NULL) {
|
||||||
pthread_mutex_lock(&data_mutex);
|
pthread_mutex_lock(&data_mutex);
|
||||||
|
|
||||||
fprintf(f, "%s\n", inbox);
|
fprintf(f, "%s\n", inbox);
|
||||||
@ -1397,15 +1397,36 @@ void inbox_add_by_actor(const xs_dict *actor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
xs_list *inbox_list(void)
|
xs_list *inbox_list(void)
|
||||||
/* returns the collected inboxes as a list */
|
/* returns the collected inboxes as a list */
|
||||||
{
|
{
|
||||||
xs_list *l = xs_list_new();
|
xs_list *ibl = xs_list_new();
|
||||||
|
xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir);
|
||||||
|
xs *files = xs_glob(spec, 0, 0);
|
||||||
|
xs_list *p = files;
|
||||||
|
xs_val *v;
|
||||||
|
|
||||||
return l;
|
while (xs_list_iter(&p, &v)) {
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
if ((f = fopen(v, "r")) != NULL) {
|
||||||
|
char line[256];
|
||||||
|
|
||||||
|
if (fgets(line, sizeof(line), f)) {
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
int i = strlen(line);
|
||||||
|
|
||||||
|
if (i) {
|
||||||
|
line[i - 1] = '\0';
|
||||||
|
ibl = xs_list_append(ibl, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ibl;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/** the queue **/
|
/** the queue **/
|
||||||
|
3
snac.h
3
snac.h
@ -134,6 +134,7 @@ d_char *history_list(snac *snac);
|
|||||||
|
|
||||||
void inbox_add(const char *inbox);
|
void inbox_add(const char *inbox);
|
||||||
void inbox_add_by_actor(const xs_dict *actor);
|
void inbox_add_by_actor(const xs_dict *actor);
|
||||||
|
xs_list *inbox_list(void);
|
||||||
|
|
||||||
void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries);
|
void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries);
|
||||||
void enqueue_output_raw(const char *keyid, const char *seckey,
|
void enqueue_output_raw(const char *keyid, const char *seckey,
|
||||||
@ -193,7 +194,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg,
|
|||||||
xs_val **payload, int *p_size, int timeout);
|
xs_val **payload, int *p_size, int timeout);
|
||||||
d_char *get_actor_inbox(snac *snac, char *actor);
|
d_char *get_actor_inbox(snac *snac, char *actor);
|
||||||
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout);
|
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout);
|
||||||
int is_msg_public(snac *snac, char *msg);
|
int is_msg_public(snac *snac, xs_dict *msg);
|
||||||
|
|
||||||
int process_user_queue(snac *snac);
|
int process_user_queue(snac *snac);
|
||||||
void process_queue_item(xs_dict *q_item);
|
void process_queue_item(xs_dict *q_item);
|
||||||
|
Loading…
Reference in New Issue
Block a user