7static stralloc work = {0};
9static int doit(
char *rule)
16 if ((ch !=
'?') && (ch !=
'=') && (ch !=
'*') && (ch !=
'-'))
return 1;
17 colon = str_chr(rule,
':');
18 if (!rule[colon])
return 1;
19 if (work.len < colon)
return 1;
21 prefixlen = work.len - colon;
22 if ((ch ==
'=') && prefixlen)
return 1;
23 if (case_diffb(rule,colon,work.s + prefixlen))
return 1;
26 if (byte_chr(work.s,prefixlen,
'.') < prefixlen)
return 1;
27 if (byte_chr(work.s,prefixlen,
'[') < prefixlen)
return 1;
28 if (byte_chr(work.s,prefixlen,
']') < prefixlen)
return 1;
32 if (ch ==
'-') work.len = 0;
34 return stralloc_cats(&work,rule + colon + 1);
37static int appendwork(stralloc *
out,stralloc *rules)
42 for (j = i = 0;j < rules->len;++j)
44 if (!doit(rules->s + i))
return 0;
47 return stralloc_cat(
out,&work);
50static int appendaddr(stralloc *
out,
char *in,
unsigned int len,stralloc *rules)
54 at = byte_chr(in,len,
'@');
55 if (!at)
if (len <= 1)
return 1;
56 if (!stralloc_catb(
out,in,at))
return 0;
57 if (!stralloc_append(
out,
"@"))
return 0;
59 if (!stralloc_copyb(&work,in + at,len - at))
return 0;
60 return appendwork(
out,rules);
65 if (!stralloc_copys(
out,
""))
return 0;
66 if (!stralloc_copyb(&work,in,len))
return 0;
67 return appendwork(
out,rules);
72 if (!stralloc_copys(
out,
""))
return 0;
73 return appendaddr(
out,in,len,rules);
81 if (!stralloc_copys(
out,
""))
return 0;
82 for (j = i = 0;j < len;++j)
85 if (!stralloc_append(
out,
"+"))
return 0;
86 if (!appendaddr(
out,in + i + 1,j - i - 1,rules))
return 0;
87 if (!stralloc_0(
out))
return 0;
90 if (!stralloc_catb(
out,in + i,j - i + 1))
return 0;
int rewritehost_addr(stralloc *out, char *in, unsigned int len, stralloc *rules)
int rewritehost(stralloc *out, char *in, unsigned int len, stralloc *rules)
int rewritehost_list(stralloc *out, char *in, unsigned int len, stralloc *rules)