From: mmj Date: Wed, 26 May 2004 23:27:32 +0000 (+1000) Subject: add: int is_subbed(const char *listdir, const char *address) for use X-Git-Tag: RELEASE_1_0_0~220 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88b7a6878f12c495b6342cd08ea89ae2179f7924;p=thirdparty%2Fmlmmj.git add: int is_subbed(const char *listdir, const char *address) for use in mlmmj-bounce --- diff --git a/src/subscriberfuncs.c b/src/subscriberfuncs.c index 8e678dbe..0e040c70 100644 --- a/src/subscriberfuncs.c +++ b/src/subscriberfuncs.c @@ -14,12 +14,15 @@ #include #include #include +#include +#include #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; +}