release
[hcoop/zz_old/debian/djbdns.git] / dns_dtda.c
CommitLineData
dc0d77d7
CE
1#include "stralloc.h"
2#include "dns.h"
3
4int dns_domain_todot_cat(stralloc *out,const char *d)
5{
6 char ch;
7 char ch2;
8 unsigned char ch3;
9 char buf[4];
10
11 if (!*d)
12 return stralloc_append(out,".");
13
14 for (;;) {
15 ch = *d++;
16 while (ch--) {
17 ch2 = *d++;
18 if ((ch2 >= 'A') && (ch2 <= 'Z'))
19 ch2 += 32;
20 if (((ch2 >= 'a') && (ch2 <= 'z')) || ((ch2 >= '0') && (ch2 <= '9')) || (ch2 == '-') || (ch2 == '_')) {
21 if (!stralloc_append(out,&ch2)) return 0;
22 }
23 else {
24 ch3 = ch2;
25 buf[3] = '0' + (ch3 & 7); ch3 >>= 3;
26 buf[2] = '0' + (ch3 & 7); ch3 >>= 3;
27 buf[1] = '0' + (ch3 & 7);
28 buf[0] = '\\';
29 if (!stralloc_catb(out,buf,4)) return 0;
30 }
31 }
32 if (!*d) return 1;
33 if (!stralloc_append(out,".")) return 0;
34 }
35}