LIBDNS_SOURCES = rdata.c util.c rr.c packet.c wire2host.c \
host2str.c buffer.c str2host.c resolver.c \
net.c host2wire.c dname.c dnssec.c keys.c \
- higher.c rr_functions.c
+ higher.c rr_functions.c parse.c
LIBDNS_HEADERS = ldns/error.h \
ldns/packet.h \
ldns/prototype.h \
ldns/dnssec.h \
ldns/keys.h \
ldns/higher.h \
+ ldns/parse.h \
util.h
PROG_SOURCES = mx.c
PROG_TARGETS = $(PROG_SOURCES:.c=)
LIBDNS_OBJECTS = $(LIBDNS_SOURCES:.c=.o)
-TEST_SOURCES = run-test7.c run-test11.c run-test18.c
+TEST_SOURCES = run-test7.c run-test11.c run-test18.c run-test19.c
#ALL_SOURCES = $(TEST_SOURCES) $(LIBDNS_SOURCES) $(PROG_SOURCES)
ALL_SOURCES = $(LIBDNS_SOURCES) $(PROG_SOURCES)
$(LINK) ${LIBS} -o $@ $+
run-test18: run-test18.o $(LIBDNS_OBJECTS) $(LIBOBJS)
$(LINK) ${LIBS} -lssl -o $@ $+
+run-test19: run-test19.o $(LIBDNS_OBJECTS) $(LIBOBJS)
+ $(LINK) ${LIBS} -lssl -o $@ $+
doc:
doxygen libdns.doxygen
ldns_rdf *sigdata_rdf;
ldns_buffer *b64sig;
+ siglen = 0;
b64sig = ldns_buffer_new(MAX_PACKETLEN);
if (!b64sig) {
return NULL;
#include <ldns/dnssec.h>
#include <ldns/keys.h>
#include <ldns/rr_functions.h>
+#include <ldns/parse.h>
#endif /* _LDNS_H */
--- /dev/null
+/*
+ * parse.h
+ *
+ * a Net::DNS like library for C
+ * LibDNS Team @ NLnet Labs
+ * (c) NLnet Labs, 2005
+ * See the file LICENSE for the license
+ */
+
+#ifndef _PARSE_H_
+#define _PARSE_H_
+
+#include <ldns/common.h>
+
+
+#define MAXTOKEN_LEN 1024
+#define LDNS_EAT_SPACE true
+
+
+/* what we can parse */
+enum ldns_enum_parse
+{
+ LDNS_SPACE_STR, /* str with spaces */
+ LDNS_STR, /* str without spaces */
+ LDNS_QUOTE_STR, /* str with \ in it */
+ LDNS_QUOTE_SPACE_STR /* str with \ in it and spaces */
+};
+typedef enum ldns_enum_parse ldns_parse;
+
+/*
+ * get a token/char from the stream F
+ * return 0 on error of EOF of F
+ * return >0 length of what is read.
+ * This function deals with ( and ) in the stream
+ * and ignore \n when it finds them
+ */
+size_t ldns_get_token(FILE *f, char *token, bool eat_space);
+
+/*
+ * get the next string and supply the type we want
+ * return 0 on error, otherwise the length
+ */
+size_t ldns_get_str(FILE *f, char *word, ldns_parse type);
+
+#endif /* _PARSE_H_ */
--- /dev/null
+/*
+ * a generic (simple) parser. Use to parse rr's, private key
+ * information and /etc/resolv.conf files
+ *
+ * a Net::DNS like library for C
+ * LibDNS Team @ NLnet Labs
+ * (c) NLnet Labs, 2005
+ * See the file LICENSE for the license
+ */
+
+
+#include <config.h>
+
+#include <limits.h>
+#include <strings.h>
+
+#include <ldns/parse.h>
+
+#include <ldns/rr.h>
+#include <ldns/dns.h>
+#include "util.h"
+
+
+
+
+/*
+ * get the next string and supply the type we
+ * want
+ */
+size_t
+ldns_get_str(FILE *f, char *word, ldns_parse type)
+{
+ size_t i;
+
+ i = 0;
+ switch (type) {
+ case LDNS_SPACE_STR:
+ i = ldns_get_token(f, word, LDNS_EAT_SPACE);
+ return i;
+ case LDNS_STR:
+ i = ldns_get_token(f, word, false);
+ return i;
+ case LDNS_QUOTE_STR:
+ i = ldns_get_token(f, word, false);
+ break;
+ case LDNS_QUOTE_SPACE_STR:
+ i = ldns_get_token(f, word, LDNS_EAT_SPACE);
+ break;
+ }
+ /* only reach this spot if the str was quoted */
+ /* mangle the quoted string and return what we got */
+ return i;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*
+ * get a token/char from the stream F
+ * return 0 on error of EOF of F
+ * return >0 length of what is read.
+ * This function deals with ( and ) in the stream
+ * and ignore \n when it finds them
+ */
+size_t
+ldns_get_token(FILE *f, char *token, bool eat_space)
+{
+ int c;
+ int p; /* 0 -> no parenthese seen, >0 nr of ( seen */
+ char *t;
+ uint8_t i;
+
+ p = 0;
+ i = 0;
+ t = token;
+ while ((c = getc(f)) != EOF) {
+ if (c == '(') {
+ p++;
+ continue;
+ }
+
+ if (c == ')') {
+ p--;
+ continue;
+ }
+
+ if (p < 0) {
+ /* more ) then ( */
+ token = NULL;
+ return 0;
+ }
+
+ if (c == '\n' && p != 0) {
+ /* in parentheses */
+ continue;
+ }
+
+ if (isspace(c)) {
+ if (isblank(c) && eat_space) {
+ /* ordered to keep eating */
+ *t++ = c;
+ i++;
+ continue;
+ }
+ goto tokenread;
+ }
+
+ *t++ = c;
+ i++;
+ }
+
+tokenread:
+ if (p != 0 || c == EOF) {
+ /* ( count doesn't match ) count or EOF reached */
+ token = NULL;
+ return 0;
+ } else {
+ *t = '\0';
+ return i;
+ }
+
+}
ldns_rr_list_print(stdout, signatures);
- return 0;
- /* END */
printf("Now we are going to verify\n");
printf("\n[%d]\n", ldns_verify(rrs, signatures, dnskeys));
--- /dev/null
+/*
+ * mx is a small programs that prints out the mx records
+ * for a particulary domain
+ */
+
+#include <stdio.h>
+#include <config.h>
+#include <ldns/ldns.h>
+
+int
+usage(FILE *fp, char *prog) {
+ fprintf(fp, "%s keygen\n", prog);
+ fprintf(fp, " generate a DNSKEY RR \n");
+ return 0;
+}
+
+int
+main()
+{
+ FILE *f;
+ char *tok;
+ size_t b;
+
+ if (!(f = fopen("blaat", "r"))) {
+ exit(1);
+ }
+
+ tok = XMALLOC(char, 1024);
+
+ while ((b = ldns_get_str(f, tok, true)) != 0) {
+ fprintf(stdout, "%d: %s\n", (int)b, tok);
+ }
+
+
+ fclose(f);
+ return 0;
+}