From a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f Mon Sep 17 00:00:00 2001 From: Jannis Hoffmann Date: Wed, 3 Jul 2024 15:52:39 +0200 Subject: format files --- src/mfrules.c | 71 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 33 deletions(-) (limited to 'src/mfrules.c') diff --git a/src/mfrules.c b/src/mfrules.c index 9c6240f..be32422 100644 --- a/src/mfrules.c +++ b/src/mfrules.c @@ -1,12 +1,13 @@ -#include "alloc.h" -#include "stralloc.h" -#include "open.h" -#include "cdbread.h" -#include "case.h" #include "mfrules.h" -#include "str.h" + +#include "alloc.h" #include "byte.h" +#include "case.h" +#include "cdbread.h" #include "close.h" +#include "open.h" +#include "str.h" +#include "stralloc.h" /* return -9: problems reading cdb */ /* return -1: key matches; data not */ @@ -29,9 +30,9 @@ static int mffind(char *mf) int mflen; int delta; - switch (cdb_find(&cdb,key.s,key.len)) { + switch (cdb_find(&cdb, key.s, key.len)) { case -1: return -9; - case 0: return 0; + case 0: return 0; } datalen = cdb_datalen(&cdb); @@ -40,61 +41,65 @@ static int mffind(char *mf) if (!datalen) return 1; mflen = str_len(mf); - if (cdb_read(&cdb,data,datalen,cdb_datapos(&cdb)) == -1) { + if (cdb_read(&cdb, data, datalen, cdb_datapos(&cdb)) == -1) { alloc_free(data); return -9; } - x = data; dlen = datalen - 1; /* trailing separator */ - + x = data; + dlen = datalen - 1; /* trailing separator */ + while (dlen > 0) { - plus = byte_rchr(data,dlen,'+'); + plus = byte_rchr(data, dlen, '+'); x = data + plus + 1; len = dlen - plus; delta = (mflen > len) ? mflen - len : 0; - if (!byte_diff(x,len,mf + delta)) { alloc_free(data); return 2; } + if (!byte_diff(x, len, mf + delta)) { + alloc_free(data); + return 2; + } dlen = plus - 1; } alloc_free(data); return -1; -} +} -int mfsearch(char *ip,char *host,char *info,char *mf) +int mfsearch(char *ip, char *host, char *info, char *mf) { int r; if (info) { - if (!stralloc_copys(&key,info)) return -9; + if (!stralloc_copys(&key, info)) return -9; r = mffind(mf); if (r < -1 || r > 0) return r; - if (!stralloc_cats(&key,"@")) return -9; - if (!stralloc_cats(&key,ip)) return -9; + if (!stralloc_cats(&key, "@")) return -9; + if (!stralloc_cats(&key, ip)) return -9; r = mffind(mf); if (r < -1 || r > 0) return r; if (host) { - if (!stralloc_copys(&key,info)) return -9; - if (!stralloc_cats(&key,"@=")) return -9; - if (!stralloc_cats(&key,host)) return -9; + if (!stralloc_copys(&key, info)) return -9; + if (!stralloc_cats(&key, "@=")) return -9; + if (!stralloc_cats(&key, host)) return -9; r = mffind(mf); if (r < -1 || r > 0) return r; } } - if (!stralloc_copys(&key,ip)) return -9; + if (!stralloc_copys(&key, ip)) return -9; r = mffind(mf); if (r < -1 || r > 0) return r; if (host) { - if (!stralloc_copys(&key,"=")) return -9; - if (!stralloc_cats(&key,host)) return -9; + if (!stralloc_copys(&key, "=")) return -9; + if (!stralloc_cats(&key, host)) return -9; r = mffind(mf); if (r < -1 || r > 0) return r; } - if (!stralloc_copys(&key,ip)) return -9; /* IPv6 */ + if (!stralloc_copys(&key, ip)) return -9; /* IPv6 */ while (key.len > 0) { if (ip[key.len - 1] == ':') { r = mffind(mf); @@ -103,7 +108,7 @@ int mfsearch(char *ip,char *host,char *info,char *mf) --key.len; } - if (!stralloc_copys(&key,ip)) return -9; /* IPv4 */ + if (!stralloc_copys(&key, ip)) return -9; /* IPv4 */ while (key.len > 0) { if (ip[key.len - 1] == '.') { r = mffind(mf); @@ -115,30 +120,30 @@ int mfsearch(char *ip,char *host,char *info,char *mf) if (host) { while (*host) { if (*host == '.') { - if (!stralloc_copys(&key,"=")) return -9; - if (!stralloc_cats(&key,host)) return -9; + if (!stralloc_copys(&key, "=")) return -9; + if (!stralloc_cats(&key, host)) return -9; r = mffind(mf); if (r < -1 || r > 0) return r; } ++host; } - if (!stralloc_copys(&key,"=")) return -9; + if (!stralloc_copys(&key, "=")) return -9; r = mffind(mf); if (r < -1 || r > 0) return r; } key.len = 0; -/* return mffind(mf); */ + /* return mffind(mf); */ return -1; } -int mfrules(int fd,char *ip,char *host,char *info,char *mf) +int mfrules(int fd, char *ip, char *host, char *info, char *mf) { int r; - cdb_init(&cdb,fd); + cdb_init(&cdb, fd); case_lowers(mf); - r = mfsearch(ip,host,info,mf); + r = mfsearch(ip, host, info, mf); cdb_free(&cdb); close(fd); -- cgit v1.2.3