]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-sub: share code between sub and unsub
authorBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 28 Oct 2021 09:57:19 +0000 (11:57 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 28 Oct 2021 10:07:26 +0000 (12:07 +0200)
src/mlmmj-sub.c

index f51b1e95db600a211c78783b6343fbae1ab30cd1..2d083319a626ba0f5b684eca22c69804472ad306 100644 (file)
@@ -520,29 +520,14 @@ static void generate_subscribed(struct mlmmj_list *list, const char *subaddr,
 static void subscribe_type(struct mlmmj_list *list,
                char *address, char *mlmmjsend,
                enum subtype typesub, enum subreason reasonsub) {
-       char chstr[2], *subdir;
+       char chstr[2];
+       const char *subdir;
        char *sublockname = NULL;
        int groupwritable = 0, sublockfd,  subfilefd;
        struct stat st;
        int subdirfd = -1;
 
-       switch(typesub) {
-               default:
-               case SUB_NORMAL:
-                       subdir = "subscribers.d";
-                       break;
-               case SUB_DIGEST:
-                       subdir = "digesters.d";
-                       break;
-               case SUB_NOMAIL:
-                       subdir = "nomailsubs.d";
-                       break;
-       }
-
-       subdirfd = openat(list->fd, subdir, O_DIRECTORY|O_CLOEXEC);
-       if (subdirfd == -1)
-               err(EXIT_FAILURE, "Unable to open %s/%s", list->dir, subdir);
-
+       subdirfd = open_subscriber_directory(list, typesub, &subdir);
        if (fstat(subdirfd, &st) == 0) {
                if(st.st_mode & S_IWGRP) {
                        groupwritable = S_IRGRP|S_IWGRP;
@@ -556,7 +541,7 @@ static void subscribe_type(struct mlmmj_list *list,
 
        subfilefd = openat(subdirfd, chstr, O_RDWR|O_CREAT, S_IRUSR | S_IWUSR);
        if (subfilefd == -1) {
-               log_error(LOG_ARGS, "Error opening %s/%s/%s", list->dir, subdir, chstr);
+               log_error(LOG_ARGS, "Error the siubopening %s/%s/%s", list->dir, subdir, chstr);
                err(EXIT_FAILURE, "Error opening %s/%s/%s");
        }