Mercurial > hg > mlmmj
changeset 109:e4ae5f67cb9e
add: int is_subbed(const char *listdir, const char *address) for use
in mlmmj-bounce
author | mmj |
---|---|
date | Thu, 27 May 2004 09:27:32 +1000 |
parents | 51a1695e9d4b |
children | 6bbaadfb1c43 |
files | src/subscriberfuncs.c |
diffstat | 1 files changed, 52 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/subscriberfuncs.c Thu May 27 09:25:57 2004 +1000 +++ b/src/subscriberfuncs.c Thu May 27 09:27:32 2004 +1000 @@ -14,12 +14,15 @@ #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 @@ 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; +}