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/mfrules.c | |
parent | 00be7622c428f279872f84569f098ce16150f8a8 (diff) |
format files
Diffstat (limited to 'src/mfrules.c')
-rw-r--r-- | src/mfrules.c | 71 |
1 files changed, 38 insertions, 33 deletions
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); |