]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
add: int is_subbed(const char *listdir, const char *address) for use
authormmj <none@none>
Wed, 26 May 2004 23:27:32 +0000 (09:27 +1000)
committermmj <none@none>
Wed, 26 May 2004 23:27:32 +0000 (09:27 +1000)
in mlmmj-bounce

src/subscriberfuncs.c

index 8e678dbe726a34b92401d2deb4bbbd13893e4d30..0e040c7030a40d80fc4164a0a90c6281efbc7bcc 100644 (file)
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <unistd.h>
+#include <dirent.h>
+#include <fcntl.h>
 
 #include "mlmmj.h"
 #include "subscriberfuncs.h"
 #include "mygetline.h"
 #include "log_error.h"
 #include "wrappers.h"
+#include "strgen.h"
 
 off_t find_subscriber(int fd, const char *address)
 {
@@ -67,3 +70,52 @@ off_t find_subscriber(int fd, const char *address)
        munmap(start, st.st_size);
        return (off_t)-1;
 }
+
+int is_subbed(const char *listdir, const char *address)
+{
+       int retval = 1, subread;
+       char *subddirname, *subreadname;
+       off_t suboff;
+       DIR *subddir;
+       struct dirent *dp;
+
+       subddirname = concatstr(2, listdir, "/subscribers.d/");
+       if((subddir = opendir(subddirname)) == NULL) {
+               log_error(LOG_ARGS, "Could not opendir(%s)", subddirname);
+               free(subddirname);
+               exit(EXIT_FAILURE);
+       }
+
+       free(subddirname);
+
+       while((dp = readdir(subddir)) != NULL) {
+               if(!strcmp(dp->d_name, "."))
+                       continue;
+               if(!strcmp(dp->d_name, ".."))
+                       continue;
+
+               subreadname = concatstr(3, listdir, "/subscribers.d/",
+                               dp->d_name);
+               subread = open(subreadname, O_RDONLY);
+               if(subread < 0) {
+                       log_error(LOG_ARGS, "Could not open '%s'",
+                                       subreadname);
+                       free(subreadname);
+                       continue;
+               }
+
+               suboff = find_subscriber(subread, address);
+               close(subread);
+               free(subreadname);
+
+               if(suboff == -1) {
+                       continue;
+               } else {
+                       retval = 0;
+                       break;
+               }
+       }
+       closedir(subddir);
+
+       return retval;
+}