1 /*
2  * Part of DNS zone file validator `validns`.
3  *
4  * Copyright 2011-2014 Anton Berezin <tobez@tobez.org>
5  * Modified BSD license.
6  * (See LICENSE file in the distribution.)
7  *
8  */
9 #include <sys/types.h>
10 #include <string.h>
11 #include <stdio.h>
12 #include <netinet/in.h>
13 #include <arpa/inet.h>
14 
15 #include "common.h"
16 #include "textparse.h"
17 #include "mempool.h"
18 #include "carp.h"
19 #include "rr.h"
20 
hinfo_parse(char * name,long ttl,int type,char * s)21 static struct rr *hinfo_parse(char *name, long ttl, int type, char *s)
22 {
23 	struct rr_hinfo *rr = getmem(sizeof(*rr));
24 
25 	rr->cpu = extract_text(&s, "CPU");
26 	if (rr->cpu.length < 0)
27 		return NULL;
28 	if (rr->cpu.length > 255)
29 		return bitch("CPU string is too long");
30 
31 	rr->os = extract_text(&s, "OS");
32 	if (rr->os.length < 0)
33 		return NULL;
34 	if (rr->os.length > 255)
35 		return bitch("OS string is too long");
36 
37 	if (*s) {
38 		return bitch("garbage after valid HINFO data");
39 	}
40 
41 	return store_record(type, name, ttl, rr);
42 }
43 
hinfo_human(struct rr * rrv)44 static char* hinfo_human(struct rr *rrv)
45 {
46 	RRCAST(hinfo);
47     char s[1024];
48 
49     snprintf(s, 1024, "\"%s\" \"%s\"", rr->cpu.data, rr->os.data);
50     return quickstrdup_temp(s);
51 }
52 
hinfo_wirerdata(struct rr * rrv)53 static struct binary_data hinfo_wirerdata(struct rr *rrv)
54 {
55 	RRCAST(hinfo);
56 
57     return compose_binary_data("bb", 1, rr->cpu, rr->os);
58 }
59 
60 struct rr_methods hinfo_methods = { hinfo_parse, hinfo_human, hinfo_wirerdata, NULL, NULL };
61