]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
re-do the parser. This is the lowlevel framework.
authorMiek Gieben <miekg@NLnetLabs.nl>
Thu, 31 Mar 2005 12:27:30 +0000 (12:27 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Thu, 31 Mar 2005 12:27:30 +0000 (12:27 +0000)
Next up: incorperate this in the rr_frm_str function and see
what other changes are needed

Makefile.in
dnssec.c
ldns/ldns.h
ldns/parse.h [new file with mode: 0644]
parse.c [new file with mode: 0644]
run-test18.c
run-test19.c [new file with mode: 0644]

index b4fa2471c5e62ceb95e072f8309690a96d6ae280..4be727f8094e73a56203d4d1693203ddc349ccfa 100644 (file)
@@ -26,7 +26,7 @@ LINTFLAGS     = +quiet -weak -warnposix -unrecog -Din_addr_t=uint32_t -Du_int=unsign
 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        \
@@ -43,13 +43,14 @@ LIBDNS_HEADERS      =       ldns/error.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)
@@ -92,6 +93,8 @@ run-test11:   run-test11.o $(LIBDNS_OBJECTS) $(LIBOBJS)
                $(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
index 5b20946e0ef6386c0c0e5221fb3fba84793a78a5..8e00ebe6b34c4328705a0187966cd4c3b79bfda6 100644 (file)
--- a/dnssec.c
+++ b/dnssec.c
@@ -948,6 +948,7 @@ ldns_sign_public_rsasha1(ldns_buffer *to_sign, RSA *key)
        ldns_rdf *sigdata_rdf;
        ldns_buffer *b64sig;
 
+       siglen = 0;
        b64sig = ldns_buffer_new(MAX_PACKETLEN);
        if (!b64sig) {
                return NULL;
index eb85fc1426b48ebf5d41bc1730f62d49a298db49..df54e5f084a693655ac5397b3c936e5df291df9d 100644 (file)
@@ -26,5 +26,6 @@
 #include <ldns/dnssec.h>
 #include <ldns/keys.h>
 #include <ldns/rr_functions.h>
+#include <ldns/parse.h>
 
 #endif /* _LDNS_H */
diff --git a/ldns/parse.h b/ldns/parse.h
new file mode 100644 (file)
index 0000000..56ea1b9
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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_ */
diff --git a/parse.c b/parse.c
new file mode 100644 (file)
index 0000000..cfc8ba6
--- /dev/null
+++ b/parse.c
@@ -0,0 +1,139 @@
+/*
+ * 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;
+       }
+       
+}
index e7bb7fab2e69ccb1a94658f13f4264fcca79a333..fbaf41789a88bcdd93db53af9fd1270a6b30df81 100644 (file)
@@ -84,8 +84,6 @@ main()
 
        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));
diff --git a/run-test19.c b/run-test19.c
new file mode 100644 (file)
index 0000000..184a293
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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;
+}