diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
commit | a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch) | |
tree | b88cc7a8457658d67e0321718556ac807f6bccf3 /src/qmail-mfrules.c | |
parent | 00be7622c428f279872f84569f098ce16150f8a8 (diff) |
format files
Diffstat (limited to 'src/qmail-mfrules.c')
-rw-r--r-- | src/qmail-mfrules.c | 130 |
1 files changed, 71 insertions, 59 deletions
diff --git a/src/qmail-mfrules.c b/src/qmail-mfrules.c index e8cfc94..7247cf7 100644 --- a/src/qmail-mfrules.c +++ b/src/qmail-mfrules.c @@ -1,22 +1,25 @@ #include <sys/stat.h> -#include <stdio.h> // rename -#include "logmsg.h" -#include "stralloc.h" -#include "buffer.h" -#include "getln.h" -#include "exit.h" #include <unistd.h> -#include "open.h" -#include "auto_qmail.h" + +#include <stdio.h> // rename + +#include "buffer.h" +#include "byte.h" +#include "case.h" #include "cdbmake.h" +#include "exit.h" #include "fmt.h" +#include "getln.h" +#include "logmsg.h" +#include "open.h" #include "scan.h" -#include "byte.h" -#include "case.h" +#include "stralloc.h" + +#include "auto_qmail.h" #define WHO "qmail-mfrules" -int rename(const char *,const char *); // stdio.h +int rename(const char *, const char *); // stdio.h stralloc address = {0}; stralloc data = {0}; @@ -34,30 +37,30 @@ struct cdb_make cdb; void die_nomem() { - logmsg(WHO,112,FATAL,"out of memory"); + logmsg(WHO, 112, FATAL, "out of memory"); } void die_parse() { if (!stralloc_0(&line)) die_nomem(); - logmsg(WHO,100,ERROR,B("unable to parse this line: ",line.s)); + logmsg(WHO, 100, ERROR, B("unable to parse this line: ", line.s)); } void die_read() { - logmsg(WHO,111,ERROR,"unable to read control/mailfromrules"); + logmsg(WHO, 111, ERROR, "unable to read control/mailfromrules"); } void die_write() { - logmsg(WHO,111,ERROR,"unable to write to control/mailfromrules.tmp"); + logmsg(WHO, 111, ERROR, "unable to write to control/mailfromrules.tmp"); } char strnum[FMT_ULONG]; stralloc sanum = {0}; -void getnum(char *buf,int len,unsigned long *u) +void getnum(char *buf, int len, unsigned long *u) { - if (!stralloc_copyb(&sanum,buf,len)) die_nomem(); + if (!stralloc_copyb(&sanum, buf, len)) die_nomem(); if (!stralloc_0(&sanum)) die_nomem(); - if (sanum.s[scan_ulong(sanum.s,u)]) die_parse(); + if (sanum.s[scan_ulong(sanum.s, u)]) die_parse(); } void doaddressdata() @@ -68,26 +71,29 @@ void doaddressdata() unsigned long bot; unsigned long top; - if (byte_chr(address.s,address.len,'=') == address.len) - if (byte_chr(address.s,address.len,'@') == address.len) { - i = byte_chr(address.s,address.len,'-'); + if (byte_chr(address.s, address.len, '=') == address.len) + if (byte_chr(address.s, address.len, '@') == address.len) { + i = byte_chr(address.s, address.len, '-'); if (i < address.len) { - left = byte_rchr(address.s,i,'.'); - if (left == i) left = 0; else ++left; + left = byte_rchr(address.s, i, '.'); + if (left == i) + left = 0; + else + ++left; ++i; - right = i + byte_chr(address.s + i,address.len - i,'.'); - - getnum(address.s + left,i - 1 - left,&bot); - getnum(address.s + i,right - i,&top); + right = i + byte_chr(address.s + i, address.len - i, '.'); + + getnum(address.s + left, i - 1 - left, &bot); + getnum(address.s + i, right - i, &top); if (top > 255) top = 255; while (bot <= top) { - if (!stralloc_copyb(&key,address.s,left)) die_nomem(); - if (!stralloc_catb(&key,strnum,fmt_ulong(strnum,bot))) die_nomem(); - if (!stralloc_catb(&key,address.s + right,address.len - right)) die_nomem(); - case_lowerb(key.s,key.len); - if (cdb_make_add(&cdb,key.s,key.len,data.s,data.len) == -1) die_write(); + if (!stralloc_copyb(&key, address.s, left)) die_nomem(); + if (!stralloc_catb(&key, strnum, fmt_ulong(strnum, bot))) die_nomem(); + if (!stralloc_catb(&key, address.s + right, address.len - right)) die_nomem(); + case_lowerb(key.s, key.len); + if (cdb_make_add(&cdb, key.s, key.len, data.s, data.len) == -1) die_write(); ++bot; } @@ -95,9 +101,9 @@ void doaddressdata() } } - case_lowerb(address.s,address.len); - case_lowerb(data.s,data.len); - if (cdb_make_add(&cdb,address.s,address.len,data.s,data.len) == -1) die_write(); + case_lowerb(address.s, address.len); + case_lowerb(data.s, data.len); + if (cdb_make_add(&cdb, address.s, address.len, data.s, data.len) == -1) die_write(); } int main() @@ -109,23 +115,23 @@ int main() char ch; umask(033); - if (chdir(auto_qmail) == -1) - logmsg(WHO,111,ERROR,B("unable to chdir to: ",auto_qmail)); + if (chdir(auto_qmail) == -1) logmsg(WHO, 111, ERROR, B("unable to chdir to: ", auto_qmail)); fd = open_read("control/mailfromrules"); if (fd == -1) die_read(); - buffer_init(&bi,read,fd,inbuf,sizeof(inbuf)); + buffer_init(&bi, read, fd, inbuf, sizeof(inbuf)); fdtemp = open_trunc("control/mailfromrules.tmp"); if (fdtemp == -1) die_write(); - if (cdb_make_start(&cdb,fdtemp) == -1) die_write(); + if (cdb_make_start(&cdb, fdtemp) == -1) die_write(); while (match) { - if (getln(&bi,&line,&match,'\n') != 0) die_read(); + if (getln(&bi, &line, &match, '\n') != 0) die_read(); - x = line.s; len = line.len; + x = line.s; + len = line.len; if (!len) break; if (x[0] == '#') continue; @@ -133,32 +139,38 @@ int main() while (len) { ch = x[len - 1]; - if (ch != '\n') if (ch != ' ') if (ch != '\t') break; + if (ch != '\n') + if (ch != ' ') + if (ch != '\t') break; --len; } line.len = len; /* for die_parse() */ - amper = byte_chr(x,len,'&'); + amper = byte_chr(x, len, '&'); if (!amper) die_parse(); - if (amper) if (amper == len || amper < 2) die_parse(); + if (amper) + if (amper == len || amper < 2) die_parse(); - if (!stralloc_copyb(&address,x,amper)) die_nomem(); - if (!stralloc_copys(&data,"")) die_nomem(); + if (!stralloc_copyb(&address, x, amper)) die_nomem(); + if (!stralloc_copys(&data, "")) die_nomem(); - x = line.s + amper + 1; len = line.len - amper - 1; + x = line.s + amper + 1; + len = line.len - amper - 1; while (len) { - if (len < 3) die_parse(); /* input checks */ - if ( *x == ',' || *x == ' ' || *x == '\t') die_parse(); - i = byte_chr(x,len,','); /* &addr1,addr2,.. */ + if (len < 3) die_parse(); /* input checks */ + if (*x == ',' || *x == ' ' || *x == '\t') die_parse(); + i = byte_chr(x, len, ','); /* &addr1,addr2,.. */ if (i > 0 && i < len) { - if (!stralloc_catb(&data,"+",1)) die_nomem(); - if (!stralloc_catb(&data,x,i)) die_nomem(); - x += i + 1; len -= i + 1; } - else { - if (!stralloc_catb(&data,"+",1)) die_nomem(); - if (!stralloc_catb(&data,x,len)) die_nomem(); - len = 0; } + if (!stralloc_catb(&data, "+", 1)) die_nomem(); + if (!stralloc_catb(&data, x, i)) die_nomem(); + x += i + 1; + len -= i + 1; + } else { + if (!stralloc_catb(&data, "+", 1)) die_nomem(); + if (!stralloc_catb(&data, x, len)) die_nomem(); + len = 0; + } } doaddressdata(); } @@ -166,8 +178,8 @@ int main() if (cdb_make_finish(&cdb) == -1) die_write(); if (fsync(fdtemp) == -1) die_write(); if (close(fdtemp) == -1) die_write(); /* NFS stupidity */ - if (rename("control/mailfromrules.tmp","control/mailfromrules.cdb") == -1) - logmsg(WHO,111,ERROR,"unable to move control/mailfromrules.tmp to control/mailfromrules.cdb"); + if (rename("control/mailfromrules.tmp", "control/mailfromrules.cdb") == -1) + logmsg(WHO, 111, ERROR, "unable to move control/mailfromrules.tmp to control/mailfromrules.cdb"); _exit(0); } |