From 9ebced8c82bbbbd8f97b80c03dcbe5fd40fbe4f6 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 2 Nov 2021 14:59:24 +0100 Subject: [PATCH] open_text*: convert to struct mlmmj_list --- include/prepstdreply.h | 4 ++-- src/listcontrol.c | 10 +++++----- src/mlmmj-bounce.c | 2 +- src/mlmmj-process.c | 6 +++--- src/mlmmj-sub.c | 12 ++++++------ src/mlmmj-unsub.c | 8 ++++---- src/prepstdreply.c | 18 +++++++++--------- src/send_digest.c | 2 +- src/send_list.c | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/prepstdreply.h b/include/prepstdreply.h index 458a7d73..b01a764c 100644 --- a/include/prepstdreply.h +++ b/include/prepstdreply.h @@ -54,8 +54,8 @@ void finish_file_lines(file_lines_state *s); char *substitute(const char *line, struct mlmmj_list *list, text *txt); -text *open_text_file(const char *listdir, const char *filename); -text *open_text(const char *listdir, const char *purpose, const char *action, +text *open_text_file(struct mlmmj_list *list, const char *filename); +text *open_text(struct mlmmj_list *list, const char *purpose, const char *action, const char *reason, const char *type, const char *compat); void register_unformatted(text *txt, const char *token, const char *subst); void register_originalmail(text *txt, const char *mailname); diff --git a/src/listcontrol.c b/src/listcontrol.c index 987e989b..f5db3768 100644 --- a/src/listcontrol.c +++ b/src/listcontrol.c @@ -221,7 +221,7 @@ int listcontrol(struct email_container *fromemails, struct mlmmj_list *list, errno = 0; log_error(LOG_ARGS, "A subscribe-digest request was" " denied"); - txt = open_text(list->dir, "deny", "sub", "disabled", + txt = open_text(list, "deny", "sub", "disabled", "digest", "sub-deny-digest"); MY_ASSERT(txt); register_unformatted(txt, "subaddr", @@ -269,7 +269,7 @@ int listcontrol(struct email_container *fromemails, struct mlmmj_list *list, errno = 0; log_error(LOG_ARGS, "A subscribe-nomail request was" " denied"); - txt = open_text(list->dir, "deny", "sub", "disabled", + txt = open_text(list, "deny", "sub", "disabled", "nomail", "sub-deny-nomail"); MY_ASSERT(txt); register_unformatted(txt, "subaddr", @@ -317,7 +317,7 @@ int listcontrol(struct email_container *fromemails, struct mlmmj_list *list, errno = 0; log_error(LOG_ARGS, "A subscribe-both request was" " denied"); - txt = open_text(list->dir, "deny", "sub", "disabled", + txt = open_text(list, "deny", "sub", "disabled", "both", "sub-deny-digest"); MY_ASSERT(txt); register_unformatted(txt, "subaddr", @@ -797,7 +797,7 @@ permit: } log_oper(list->dir, OPLOGFNAME, "%s requested help", fromemails->emaillist[0]); - txt = open_text(list->dir, "help", NULL, NULL, NULL, "listhelp"); + txt = open_text(list, "help", NULL, NULL, NULL, "listhelp"); MY_ASSERT(txt); queuefilename = prepstdreply(txt, list, "$listowner$", fromemails->emaillist[0], NULL); @@ -819,7 +819,7 @@ permit: } log_oper(list->dir, OPLOGFNAME, "%s requested faq", fromemails->emaillist[0]); - txt = open_text(list->dir, "faq", NULL, NULL, NULL, "listfaq"); + txt = open_text(list, "faq", NULL, NULL, NULL, "listfaq"); MY_ASSERT(txt); queuefilename = prepstdreply(txt, list, "$listowner$", fromemails->emaillist[0], NULL); diff --git a/src/mlmmj-bounce.c b/src/mlmmj-bounce.c index f33cbd9c..92a2f9f4 100644 --- a/src/mlmmj-bounce.c +++ b/src/mlmmj-bounce.c @@ -70,7 +70,7 @@ static void do_probe(struct mlmmj_list *list, const char *mlmmjsend, const char } *a = '@'; - txt = open_text(list->dir, "probe", NULL, NULL, NULL, "bounce-probe"); + txt = open_text(list, "probe", NULL, NULL, NULL, "bounce-probe"); MY_ASSERT(txt); register_unformatted(txt, "bouncenumbers", "%bouncenumbers%"); /* DEPRECATED */ fls = init_truncated_file_lines(addr, 0, ':'); diff --git a/src/mlmmj-process.c b/src/mlmmj-process.c index 2946cebf..59f43b86 100644 --- a/src/mlmmj-process.c +++ b/src/mlmmj-process.c @@ -158,7 +158,7 @@ static void newmoderated(struct mlmmj_list *list, const char *mailfilename, from = concatstr(4, list->name, list->delim, "owner@", list->fqdn); to = concatstr(3, list->name, "-moderators@", list->fqdn); /* FIXME JFA: Should this be converted? Why, why not? */ - txt = open_text(list->dir, "moderate", "post", + txt = open_text(list, "moderate", "post", modreason_strs[modreason], NULL, "moderation"); MY_ASSERT(txt); register_unformatted(txt, "subject", subject); @@ -215,7 +215,7 @@ static void newmoderated(struct mlmmj_list *list, const char *mailfilename, /* send mail to poster that the list is moderated */ - txt = open_text(list->dir, "wait", "post", + txt = open_text(list, "wait", "post", modreason_strs[modreason], NULL, "moderation-poster"); MY_ASSERT(txt); register_unformatted(txt, "subject", subject); @@ -445,7 +445,7 @@ send_denymail(struct mlmmj_list *list, const char *mlmmjsend, text *txt; fromaddr = concatstr(4, list->name, list->delim, "bounces-help@", list->fqdn); - txt = open_text(list->dir, "deny", "post", cause, NULL, subcause); + txt = open_text(list, "deny", "post", cause, NULL, subcause); MY_ASSERT(txt); register_unformatted(txt, "subject", subject); register_unformatted(txt, "posteraddr", posteraddr); diff --git a/src/mlmmj-sub.c b/src/mlmmj-sub.c index d23e690e..4f48a19d 100644 --- a/src/mlmmj-sub.c +++ b/src/mlmmj-sub.c @@ -143,7 +143,7 @@ static void moderate_sub(struct mlmmj_list *list, const char *subaddr, mls = init_memory_lines(moderators); myfree(moderators); - txt = open_text(list->dir, + txt = open_text(list, "gatekeep", "sub", subreason_strs[reasonsub], subtype_strs[typesub], "submod-moderator"); @@ -198,7 +198,7 @@ static void moderate_sub(struct mlmmj_list *list, const char *subaddr, myasprintf(&from, "%s%sbounces-help@%s", list->name, list->delim, list->fqdn); - txt = open_text(list->dir, + txt = open_text(list, "wait", "sub", subreason_strs[reasonsub], subtype_strs[typesub], "submod-requester"); @@ -307,7 +307,7 @@ static void confirm_sub(struct mlmmj_list *list, const char *subaddr, break; } - txt = open_text(list->dir, "finish", "sub", + txt = open_text(list, "finish", "sub", subreason_strs[reasonsub], subtype_strs[typesub], listtext); myfree(listtext); @@ -356,7 +356,7 @@ static void notify_sub(struct mlmmj_list *list, const char *subaddr, break; } - txt = open_text(list->dir, "notify", "sub", + txt = open_text(list, "notify", "sub", subreason_strs[reasonsub], subtype_strs[typesub], listtext); myfree(listtext); @@ -447,7 +447,7 @@ static void generate_subconfirm(struct mlmmj_list *list, const char *subaddr, myfree(randomstr); myfree(tmpstr); - txt = open_text(list->dir, "confirm", "sub", + txt = open_text(list, "confirm", "sub", subreason_strs[reasonsub], subtype_strs[typesub], listtext); myfree(listtext); @@ -501,7 +501,7 @@ static void generate_subscribed(struct mlmmj_list *list, const char *subaddr, myasprintf(&fromaddr, "%s%sbounces-help@%s", list->name, list->delim, list->fqdn); - txt = open_text(list->dir, + txt = open_text(list, "deny", "sub", "subbed", subtype_strs[typesub], "sub-subscribed"); MY_ASSERT(txt); diff --git a/src/mlmmj-unsub.c b/src/mlmmj-unsub.c index 3fee1737..ce0a18b0 100644 --- a/src/mlmmj-unsub.c +++ b/src/mlmmj-unsub.c @@ -69,7 +69,7 @@ static void confirm_unsub(struct mlmmj_list *list, const char *subaddr, break; } - txt = open_text(list->dir, "finish", "unsub", + txt = open_text(list, "finish", "unsub", subreason_strs[reasonsub], subtype_strs[typesub], listtext); myfree(listtext); @@ -115,7 +115,7 @@ static void notify_unsub(struct mlmmj_list *list, const char *subaddr, break; } - txt = open_text(list->dir, "notify", "unsub", + txt = open_text(list, "notify", "unsub", subreason_strs[reasonsub], subtype_strs[typesub], listtext); myfree(listtext); @@ -201,7 +201,7 @@ static void generate_unsubconfirm(struct mlmmj_list *list, const char *subaddr, myfree(randomstr); myfree(tmpstr); - txt = open_text(list->dir, "confirm", "unsub", + txt = open_text(list, "confirm", "unsub", subreason_strs[reasonsub], subtype_strs[typesub], listtext); myfree(listtext); @@ -295,7 +295,7 @@ static void generate_notsubscribed(struct mlmmj_list *list, const char *subaddr, myasprintf(&fromaddr, "%s%sbounes-help@%s", list->name, list->delim, list->fqdn); - txt = open_text(list->dir, + txt = open_text(list, "deny", "unsub", "unsubbed", subtype_strs[typesub], "unsub-notsubscribed"); MY_ASSERT(txt); diff --git a/src/prepstdreply.c b/src/prepstdreply.c index 436df648..4639814d 100644 --- a/src/prepstdreply.c +++ b/src/prepstdreply.c @@ -453,7 +453,7 @@ char *substitute(const char *line, struct mlmmj_list *list, text *txt) } -text *open_text_file(const char *listdir, const char *filename) +text *open_text_file(struct mlmmj_list *list, const char *filename) { char *tmp; text *txt; @@ -485,8 +485,8 @@ text *open_text_file(const char *listdir, const char *filename) txt->cond = NULL; txt->skip = NULL; - tmp = concatstr(3, listdir, "/text/", filename); - txt->src->fd = open(tmp, O_RDONLY); + myasprintf(&tmp, "text/%s", filename); + txt->src->fd = openat(list->fd, tmp, O_RDONLY); myfree(tmp); if (txt->src->fd >= 0) return txt; @@ -504,7 +504,7 @@ text *open_text_file(const char *listdir, const char *filename) } -text *open_text(const char *listdir, const char *purpose, const char *action, +text *open_text(struct mlmmj_list *list, const char *purpose, const char *action, const char *reason, const char *type, const char *compat) { size_t filenamelen, len; @@ -514,23 +514,23 @@ text *open_text(const char *listdir, const char *purpose, const char *action, filename = concatstr(7,purpose,"-",action,"-",reason,"-",type); filenamelen = strlen(filename); do { - if ((txt = open_text_file(listdir, filename)) != NULL) break; + if ((txt = open_text_file(list, filename)) != NULL) break; len = type ? strlen(type) : 0; filename[filenamelen-len-1] = '\0'; - if ((txt = open_text_file(listdir, filename)) != NULL) break; + if ((txt = open_text_file(list, filename)) != NULL) break; filename[filenamelen-len-1] = '-'; filenamelen -= len + 1; len = reason ? strlen(reason) : 0; filename[filenamelen-len-1] = '\0'; - if ((txt = open_text_file(listdir, filename)) != NULL) break; + if ((txt = open_text_file(list, filename)) != NULL) break; filename[filenamelen-len-1] = '-'; filenamelen -= len + 1; len = action ? strlen(action) : 0; filename[filenamelen-len-1] = '\0'; - if ((txt = open_text_file(listdir, filename)) != NULL) break; + if ((txt = open_text_file(list, filename)) != NULL) break; filename[filenamelen-len-1] = '-'; filenamelen -= len + 1; - if ((txt = open_text_file(listdir, compat)) != NULL) { + if ((txt = open_text_file(list, compat)) != NULL) { myfree(filename); filename = mystrdup(compat); break; diff --git a/src/send_digest.c b/src/send_digest.c index abdf8956..9a32b23c 100644 --- a/src/send_digest.c +++ b/src/send_digest.c @@ -277,7 +277,7 @@ int send_digest(struct mlmmj_list *list, int firstindex, int lastindex, boundary = random_str(); - txt = open_text_file(list->dir, "digest"); + txt = open_text_file(list, "digest"); if (txt == NULL) { log_error(LOG_ARGS, "Could not open listtext 'digest'"); goto fallback_subject; diff --git a/src/send_list.c b/src/send_list.c index 75bf1836..13b21de9 100644 --- a/src/send_list.c +++ b/src/send_list.c @@ -170,7 +170,7 @@ void send_list(struct mlmmj_list *list, const char *emailaddr, myfree(digestdir); myfree(nomaildir); - txt = open_text(list->dir, "list", NULL, NULL, subtype_strs[SUB_ALL], + txt = open_text(list, "list", NULL, NULL, subtype_strs[SUB_ALL], "listsubs"); MY_ASSERT(txt); register_formatted(txt, "listsubs", -- 2.47.3