]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
the TTL is now optional and mnemomics can used (1d1h) etc
authorMiek Gieben <miekg@NLnetLabs.nl>
Thu, 7 Apr 2005 11:03:40 +0000 (11:03 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Thu, 7 Apr 2005 11:03:40 +0000 (11:03 +0000)
rr.c
run-test18.c
util.h

diff --git a/rr.c b/rr.c
index 28f4dc8ae944770479cd02b2f84d29c1ad553d2b..1c4fa2ec334f06635e04f4c01129045ffe68de28 100644 (file)
--- a/rr.c
+++ b/rr.c
@@ -85,9 +85,15 @@ ldns_rr_free(ldns_rr *rr)
 }
 
 /* 
+ * extra spaces are allowed
+ * allow ttl to be optional
+ * allow ttl to be written as 1d3h
  * So the RR should look like. e.g.
  * miek.nl. 3600 IN MX 10 elektron.atoom.net
- * extra spaces are allowed
+ * or
+ * miek.nl. 1h IN MX 10 elektron.atoom.net
+ * or
+ * miek.nl. IN MX 10 elektron.atoom.net
  */
 ldns_rr *
 ldns_rr_new_frm_str(const char *str)
@@ -97,8 +103,11 @@ ldns_rr_new_frm_str(const char *str)
        ldns_rr_type rr_type;
        ldns_buffer *rr_buf;
        ldns_buffer *rd_buf;
+       uint32_t ttl_val;
+       const char *endptr;
        char  *owner; 
        char  *ttl; 
+       ldns_rr_class clas_val;
        char  *clas;
        char  *type;
        char  *rdata;
@@ -120,6 +129,8 @@ ldns_rr_new_frm_str(const char *str)
        rd_buf = MALLOC(ldns_buffer);
        rd = XMALLOC(char, MAX_RDFLEN);
        r_cnt = 0;
+       ttl_val = 0;
+       clas_val = 0;
 
        ldns_buffer_new_frm_data(rr_buf, (char*)str, strlen(str));
        
@@ -130,27 +141,44 @@ ldns_rr_new_frm_str(const char *str)
        if (ldns_bget_token(rr_buf, ttl, "\t ", 21) == -1) {
                return NULL;
        }
-       if (ldns_bget_token(rr_buf, clas, "\t ", 11) == -1) {
-               return NULL;
+       ttl_val = strtottl(ttl, &endptr); /* i'm not using endptr */
+       if (ttl_val == 0) {
+               /* ah, it's not there or something */
+               ttl_val = LDNS_DEFTTL;
+               /* we not ASSUMING the TTL is missing and that
+                * the rest of the RR is still there. That is
+                * CLASS TYPE RDATA 
+                * so ttl value we read is actually the class
+                */
+               clas_val = ldns_get_rr_class_by_name(ttl);
+       } else {
+               if (ldns_bget_token(rr_buf, clas, "\t ", 11) == -1) {
+                       return NULL;
+               }
+               clas_val = ldns_get_rr_class_by_name(clas);
        }
+       /* the rest should still be waiting for us */
+
        if (ldns_bget_token(rr_buf, type, "\t ", 10) == -1) {
                return NULL;
        }
        if (ldns_bget_token(rr_buf, rdata, "\0", MAX_PACKETLEN) == -1) {
                return NULL;
        }
-
        ldns_buffer_new_frm_data(
                        rd_buf, rdata, strlen(rdata));
        ldns_rr_set_owner(new, ldns_dname_new_frm_str(owner));
        FREE(owner);
-       /* ttl might be more complicated, like 2h, or 3d5h */
-       ldns_rr_set_ttl(new, (uint32_t) atoi(ttl));
+
+       ldns_rr_set_ttl(new, ttl_val);
        FREE(ttl);
-       ldns_rr_set_class(new, ldns_get_rr_class_by_name(clas));
+
+       ldns_rr_set_class(new, clas_val);
        FREE(clas);
+
        rr_type = ldns_get_rr_type_by_name(type);
        FREE(type);
+
        desc = ldns_rr_descript((uint16_t)rr_type);
        ldns_rr_set_type(new, rr_type);
 
index eec9ed94d39b8db0d89ed094c846379d594019f4..0823c2fe21357a81088b80599278b7392fe1e0c6 100644 (file)
@@ -66,8 +66,11 @@ main()
        ldns_rr_print(stdout, rr);
        printf("\n");
 
-       printf("it craps on this one\n");
-       rr = ldns_rr_new_frm_str("a.miek.nl.   A    267.271.122.1t");
+       printf("this must work again\n");
+       rr = ldns_rr_new_frm_str("a.miek.nl.   IN     A    127.0.0.1");
+       ldns_rr_print(stdout, rr);
+       printf("\n");
+       rr = ldns_rr_new_frm_str("a.miek.nl.   1D IN     A    127.0.0.1");
        ldns_rr_print(stdout, rr);
        printf("\n");
 
@@ -77,6 +80,8 @@ main()
        printf("\n");
 #endif 
 
+       exit(1);
+
        privkey = ldns_key_new_frm_algorithm(LDNS_SIGN_RSASHA1, 512);
        privkey_dsa = ldns_key_new_frm_algorithm(LDNS_SIGN_DSA, 512);
        if (!privkey || !privkey_dsa) {
diff --git a/util.h b/util.h
index 7a1b1c3c5b00b0a20eeea7e5fe71644783b0e466..56d1fcde3f79772da9c90c7e5204f393e0666003 100644 (file)
--- a/util.h
+++ b/util.h
@@ -165,6 +165,6 @@ char int_to_hexdigit(int ch);
 /**
  * convert TTL string (1d2h, etc.) to a long. 0 on failure? 
  */
-uint32_t strtotll(const char *nptr, const char **endptr);
+uint32_t strtottl(const char *nptr, const char **endptr);
 
 #endif /* !_UTIL_H */