# HG changeset patch # User mmj # Date 1082574533 -36000 # Node ID 762570b023941818f3449a9bb0007e33f8442552 # Parent 21ce01de81094d880f297583d5546d97a3f8a7d2 *** empty log message *** diff -r 21ce01de8109 -r 762570b02394 include/getline.h --- a/include/getline.h Thu Apr 22 04:02:09 2004 +1000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -/* Copyright (C) 2002, 2003 Mads Martin Joergensen - * - * $Id$ - * - * This file is redistributable under version 2 of the GNU General - * Public License as described at http://www.gnu.org/licenses/gpl.txt - */ - -#ifndef GET_LINE_H -#define GET_LINE_H - -/* read the next line in infile, returns 0 when no more. */ - -char *get_line(char *buf,int count, int fd); - -#endif /* GET_LINE_H */ diff -r 21ce01de8109 -r 762570b02394 include/readln.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/readln.h Thu Apr 22 05:08:53 2004 +1000 @@ -0,0 +1,14 @@ +/* Copyright (C) 2002, 2003 Mads Martin Joergensen + * + * $Id$ + * + * This file is redistributable under version 2 of the GNU General + * Public License as described at http://www.gnu.org/licenses/gpl.txt + */ + +#ifndef READLN_H +#define READLN_H + +ssize_t readln(int fd, char *buf, size_t bufsize); + +#endif /* READLN_H */ diff -r 21ce01de8109 -r 762570b02394 include/strgen.h --- a/include/strgen.h Thu Apr 22 04:02:09 2004 +1000 +++ b/include/strgen.h Thu Apr 22 05:08:53 2004 +1000 @@ -12,8 +12,6 @@ char *random_str(void); char *random_plus_addr(const char *addr); char *headerstr(const char *headertoken, const char *str); -char *gendirname(const char *listdir, const char *subdir, const char *filename); -char *genfilename(const char *dir, const char *file); char *genlistname(const char *listaddr); char *genlistfqdn(const char *listaddr); char *concatstr(int count, ...); diff -r 21ce01de8109 -r 762570b02394 src/getline.c --- a/src/getline.c Thu Apr 22 04:02:09 2004 +1000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* Copyright (C) 2002, 2003 Mads Martin Joergensen - * - * $Id$ - * - * This file is redistributable under version 2 of the GNU General - * Public License as described at http://www.gnu.org/licenses/gpl.txt - */ - -#include -#include -#include -#include "getline.h" - -char *get_line(char *buf, int count, int infd) -{ - int bufcount = 0; - size_t c; - char ch[1]; - - ch[0] = 0; - while((c = read(infd, ch, 1))) { - if(ch[0] != '\n' && bufcount < count) - buf[bufcount++] = ch[0]; - else { - buf[bufcount] = '\n'; - if(bufcount < count - 1) - buf[bufcount + 1] = 0; - return buf; - } - } - if(ch[0]) { - if(bufcount < count - 1) - buf[bufcount + 1] = 0; - return buf; - } else - return 0; -} diff -r 21ce01de8109 -r 762570b02394 src/listcontrol.c --- a/src/listcontrol.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/listcontrol.c Thu Apr 22 05:08:53 2004 +1000 @@ -71,7 +71,7 @@ confstr = malloc(len); snprintf(confstr, len, "%s", controlstr + 8); free(controlstr); - conffilename = gendirname(listdir, "/subconf/", confstr); + conffilename = concatstr(3, listdir, "/subconf/", confstr); if((tempfile = fopen(conffilename, "r"))) { fgets(tmpstr, READ_BUFSIZE, tempfile); fclose(tempfile); @@ -109,7 +109,7 @@ confstr = malloc(len); snprintf(confstr, len, "%s", controlstr + 10); free(controlstr); - conffilename = gendirname(listdir, "/unsubconf/", confstr); + conffilename = concatstr(3, listdir, "/unsubconf/", confstr); if((tempfile = fopen(conffilename, "r"))) { fgets(tmpstr, READ_BUFSIZE, tempfile); fclose(tempfile); diff -r 21ce01de8109 -r 762570b02394 src/mlmmj-process.c --- a/src/mlmmj-process.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/mlmmj-process.c Thu Apr 22 05:08:53 2004 +1000 @@ -82,10 +82,10 @@ /* get the list address */ getlistaddr(listadr, listdir); - donemailname = gendirname(listdir, "/queue/", random_str()); + donemailname = concatstr(3, listdir, "/queue/", random_str()); donemailfd = open(donemailname, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); while(donemailfd == -1 && errno == EEXIST) { - donemailname = gendirname(listdir, "/queue/", random_str()); + donemailname = concatstr(3, listdir, "/queue/", random_str()); donemailfd = open(donemailname, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); } @@ -103,11 +103,11 @@ exit(EXIT_FAILURE); } - headerfilename = genfilename(listdir, "/customheaders"); + headerfilename = concatstr(2, listdir, "/customheaders"); headerfile = fopen(headerfilename, "r"); free(headerfilename); - footerfilename = genfilename(listdir, "/footer"); + footerfilename = concatstr(2, listdir, "/footer"); footerfile = fopen(footerfilename, "r"); free(footerfilename); diff -r 21ce01de8109 -r 762570b02394 src/mlmmj-recieve.c --- a/src/mlmmj-recieve.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/mlmmj-recieve.c Thu Apr 22 05:08:53 2004 +1000 @@ -69,12 +69,13 @@ /* get the list address */ getlistaddr(listadr, listdir); - infilename = gendirname(listdir, "/incoming/", random_str()); + infilename = concatstr(3, listdir, "/incoming/", random_str()); mailfd = open(infilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); while(mailfd == -1 && errno == EEXIST) { free(infilename); - infilename = gendirname(listdir, "/incoming/", random_str()); - mailfd = open(infilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); + infilename = concatstr(3, listdir, "/incoming/", random_str()); + mailfd = open(infilename, O_RDWR|O_CREAT|O_EXCL, + S_IRUSR|S_IWUSR); } if(mailfd == -1) { diff -r 21ce01de8109 -r 762570b02394 src/mlmmj-send.c --- a/src/mlmmj-send.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/mlmmj-send.c Thu Apr 22 05:08:53 2004 +1000 @@ -225,7 +225,7 @@ * subscribers list. Choeger? */ if(listdir[0] != '1') { - subfilename = genfilename(listdir, "/subscribers"); + subfilename = concatstr(2, listdir, "/subscribers"); if((subfile = fopen(subfilename, "r")) == NULL) { log_error("Could not open subscriberfile:"); exit(EXIT_FAILURE); diff -r 21ce01de8109 -r 762570b02394 src/mlmmj-subscribe.c --- a/src/mlmmj-subscribe.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/mlmmj-subscribe.c Thu Apr 22 05:08:53 2004 +1000 @@ -44,7 +44,7 @@ char *listname; char *listfqdn; - subtextfilename = genfilename(listdir, "/text/sub-ok"); + subtextfilename = concatstr(2, listdir, "/text/sub-ok"); if((subtextfile = fopen(subtextfilename, "r")) == NULL) { log_error("Could not open text/sub-confirm\n"); @@ -57,7 +57,7 @@ listfqdn = genlistfqdn(listaddr); randomstr = random_str(); - queuefilename = gendirname(listdir, "/queue/", randomstr); + queuefilename = concatstr(3, listdir, "/queue/", randomstr); printf("%s\n", queuefilename); @@ -141,7 +141,7 @@ listname = genlistname(listaddr); listfqdn = genlistfqdn(listaddr); randomstr = random_plus_addr(subaddr); - confirmfilename = gendirname(listdir, "/subconf/", randomstr); + confirmfilename = concatstr(3, listdir, "/subconf/", randomstr); if((subconffile = fopen(confirmfilename, "w")) == NULL) { log_error(confirmfilename); @@ -168,7 +168,7 @@ snprintf(fromaddr, len, "%s-bounces+confsub-%s@%s", listname, randomstr, listfqdn); - subtextfilename = genfilename(listdir, "/text/sub-confirm"); + subtextfilename = concatstr(2, listdir, "/text/sub-confirm"); if((subtextfile = fopen(subtextfilename, "r")) == NULL) { log_error("Could not open text/sub-confirm\n"); @@ -178,7 +178,7 @@ } free(subtextfilename); - queuefilename = gendirname(listdir, "/queue/", randomstr); + queuefilename = concatstr(3, listdir, "/queue/", randomstr); printf("%s\n", queuefilename); @@ -298,7 +298,7 @@ exit(EXIT_SUCCESS); /* XXX is this success? */ } - subfilename = genfilename(listdir, "/subscribers"); + subfilename = concatstr(2, listdir, "/subscribers"); subfilefd = open(subfilename, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(subfilefd == -1) { diff -r 21ce01de8109 -r 762570b02394 src/mlmmj-unsubscribe.c --- a/src/mlmmj-unsubscribe.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/mlmmj-unsubscribe.c Thu Apr 22 05:08:53 2004 +1000 @@ -20,7 +20,7 @@ #include "mlmmj-subscribe.h" #include "mylocking.h" #include "wrappers.h" -#include "getline.h" +#include "readln.h" #include "getlistaddr.h" #include "subscriberfuncs.h" #include "strgen.h" @@ -45,7 +45,7 @@ char *listname; char *listfqdn; - subtextfilename = genfilename(listdir, "/text/unsub-ok"); + subtextfilename = concatstr(2, listdir, "/text/unsub-ok"); if((subtextfile = fopen(subtextfilename, "r")) == NULL) { log_error("Could not open text/unsub-ok\n"); @@ -58,7 +58,7 @@ listfqdn = genlistfqdn(listaddr); randomstr = random_str(); - queuefilename = gendirname(listdir, "/queue/", randomstr); + queuefilename = concatstr(3, listdir, "/queue/", randomstr); printf("%s\n", queuefilename); @@ -142,7 +142,7 @@ listname = genlistname(listaddr); listfqdn = genlistfqdn(listaddr); randomstr = random_plus_addr(subaddr); - confirmfilename = gendirname(listdir, "/unsubconf/", randomstr); + confirmfilename = concatstr(3, listdir, "/unsubconf/", randomstr); if((subconffile = fopen(confirmfilename, "w")) == NULL) { log_error(confirmfilename); @@ -169,7 +169,7 @@ snprintf(fromaddr, len, "%s-bounces+confunsub-%s@%s", listname, randomstr, listfqdn); - subtextfilename = genfilename(listdir, "/text/unsub-confirm"); + subtextfilename = concatstr(2, listdir, "/text/unsub-confirm"); if((subtextfile = fopen(subtextfilename, "r")) == NULL) { log_error("Could not open text/unsub-confirm\n"); @@ -179,7 +179,7 @@ } free(subtextfilename); - queuefilename = gendirname(listdir, "/queue/", randomstr); + queuefilename = concatstr(3, listdir, "/queue/", randomstr); printf("%s\n", queuefilename); @@ -236,16 +236,18 @@ void unsubscribe(int subreadfd, int subwritefd, const char *address) { - char buf[READ_BUFSIZE]; - char *bufres; + char buf[4096]; lseek(subreadfd, 0, SEEK_SET); lseek(subwritefd, 0, SEEK_SET); - while((bufres = get_line(buf, READ_BUFSIZE, subreadfd))) { - if((strncasecmp(buf, address, strlen(address))) != 0) + /* XXX: readln only guarantees to have read a complete line + * when the last char is a newline, so a check should be made + */ + while(readln(subreadfd, buf, sizeof(buf)) > 0) + if(strncasecmp(buf, address, strlen(address)) != 0) writen(subwritefd, buf, strlen(buf)); - } + ftruncate(subwritefd, lseek(subwritefd, 0, SEEK_CUR)); } @@ -309,7 +311,7 @@ /* get the list address */ getlistaddr(listaddr, listdir); - subreadname = genfilename(listdir, "/subscribers"); + subreadname = concatstr(2, listdir, "/subscribers"); subread = open(subreadname, O_RDWR); if(subread == -1) { diff -r 21ce01de8109 -r 762570b02394 src/readln.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/readln.c Thu Apr 22 05:08:53 2004 +1000 @@ -0,0 +1,42 @@ +/* Copyright (C) 2002, 2003 Mads Martin Joergensen + * + * $Id$ + * + * This file is redistributable under version 2 of the GNU General + * Public License as described at http://www.gnu.org/licenses/gpl.txt + */ + +#include +#include +#include +#include "readln.h" + +/*! Read a line from filedescriptor fd. If bufsize-1 have been read and no + * newline was found, zero terminate it and return. We can only guarantee to + * have finished reading a line if there's a newline as the last char in the + * buffer 'buf + */ +ssize_t readln(int fd, char *buf, size_t bufsize) +{ + ssize_t len = 0, rlen = 0; + + do { + rlen = read(fd, buf + len, bufsize - len - 1); + if(rlen < 0) { + if(errno == EINTR) + continue; + else + return -1; + } else { + if(rlen == 0) { + buf[len] = '\0'; + return len; + } + } + len += rlen; + } while(buf[len - 1] != '\n'); + + buf[len] = '\0'; + + return len; +} diff -r 21ce01de8109 -r 762570b02394 src/send_help.c --- a/src/send_help.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/send_help.c Thu Apr 22 05:08:53 2004 +1000 @@ -40,7 +40,7 @@ getlistaddr(listaddr, listdir); - helpfilename = genfilename(listdir, "/text/listhelp"); + helpfilename = concatstr(2, listdir, "/text/listhelp"); if((helpfile = fopen(helpfilename, "r")) == NULL) { log_error("Could not open text/help\n"); @@ -54,7 +54,7 @@ listfqdn = genlistfqdn(listaddr); randomstr = random_str(); - queuefilename = gendirname(listdir, "/queue/", randomstr); + queuefilename = concatstr(3, listdir, "/queue/", randomstr); printf("%s\n", queuefilename); if((queuefile = fopen(queuefilename, "w")) == NULL) { diff -r 21ce01de8109 -r 762570b02394 src/strgen.c --- a/src/strgen.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/strgen.c Thu Apr 22 05:08:53 2004 +1000 @@ -54,26 +54,6 @@ return dest; } -char *gendirname(const char *listdir, const char *subdir, const char *filename) -{ - size_t len = strlen(listdir) + strlen(subdir) + strlen(filename) + 1; - char *dest = malloc(len); - - snprintf(dest, len, "%s%s%s", listdir, subdir, filename); - - return dest; -} - -char *genfilename(const char *dir, const char *file) -{ - size_t len = strlen(dir) + strlen(file) + 1; - char *dest = malloc(len); - - snprintf(dest, len, "%s%s", dir, file); - - return dest; -} - char *genlistname(const char *listaddr) { size_t len; diff -r 21ce01de8109 -r 762570b02394 src/subscriberfuncs.c --- a/src/subscriberfuncs.c Thu Apr 22 04:02:09 2004 +1000 +++ b/src/subscriberfuncs.c Thu Apr 22 05:08:53 2004 +1000 @@ -12,13 +12,13 @@ #include "mlmmj.h" #include "subscriberfuncs.h" -#include "getline.h" +#include "readln.h" int find_subscriber(int subfilefd, const char *address) { char buf[READ_BUFSIZE]; - while (get_line(buf, sizeof(buf), subfilefd)) { + while (readln(subfilefd, buf, sizeof(buf))) { while (buf[0] && isspace(buf[strlen(buf)-1])) buf[strlen(buf)-1] = '\0'; if (strcasecmp(buf, address) == 0)