7 static int doit(stralloc
*work
,const char *rule
)
11 unsigned int prefixlen
;
14 if ((ch
!= '?') && (ch
!= '=') && (ch
!= '*') && (ch
!= '-')) return 1;
15 colon
= str_chr(rule
,':');
16 if (!rule
[colon
]) return 1;
18 if (work
->len
< colon
) return 1;
19 prefixlen
= work
->len
- colon
;
20 if ((ch
== '=') && prefixlen
) return 1;
21 if (case_diffb(rule
,colon
,work
->s
+ prefixlen
)) return 1;
23 if (byte_chr(work
->s
,prefixlen
,'.') < prefixlen
) return 1;
24 if (byte_chr(work
->s
,prefixlen
,'[') < prefixlen
) return 1;
25 if (byte_chr(work
->s
,prefixlen
,']') < prefixlen
) return 1;
28 work
->len
= prefixlen
;
29 if (ch
== '-') work
->len
= 0;
30 return stralloc_cats(work
,rule
+ colon
+ 1);
33 int dns_ip4_qualify_rules(stralloc
*out
,stralloc
*fqdn
,const stralloc
*in
,const stralloc
*rules
)
40 if (!stralloc_copy(fqdn
,in
)) return -1;
42 for (j
= i
= 0;j
< rules
->len
;++j
)
44 if (!doit(fqdn
,rules
->s
+ i
)) return -1;
49 plus
= byte_chr(fqdn
->s
,fqdnlen
,'+');
51 return dns_ip4(out
,fqdn
);
55 j
= byte_chr(fqdn
->s
+ i
,fqdnlen
- i
,'+');
56 byte_copy(fqdn
->s
+ plus
,j
,fqdn
->s
+ i
);
58 if (dns_ip4(out
,fqdn
) == -1) return -1;
59 if (out
->len
) return 0;
61 if (i
>= fqdnlen
) return 0;
66 int dns_ip4_qualify(stralloc
*out
,stralloc
*fqdn
,const stralloc
*in
)
68 static stralloc rules
;
69 if (dns_resolvconfrewrite(&rules
) == -1) return -1;
70 return dns_ip4_qualify_rules(out
,fqdn
,in
,&rules
);