]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
it does something usefull already
authorMiek Gieben <miekg@NLnetLabs.nl>
Wed, 14 Dec 2005 15:00:56 +0000 (15:00 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Wed, 14 Dec 2005 15:00:56 +0000 (15:00 +0000)
examples/ldns-zcat.c

index 26db2d9079f13744116d487ca76a7bda38b13225..7d28aa2d54a4c3bcfd5ce92120f5c773ffc12800 100644 (file)
@@ -38,8 +38,15 @@ main(int argc, char **argv)
        FILE *fp;
        int c;
        ldns_rdf *origin;
+       size_t i, j;
+       int where;
+       ldns_zone *z;
+       ldns_rr_list *zrr;
+       ldns_rr *current_rr;
+       ldns_rr_list *lastname;
 
        progname = strdup(argv[0]);
+       origin = NULL;
        
        while ((c = getopt(argc, argv, "n:o:")) != -1) {
                switch(c) {
@@ -64,6 +71,64 @@ main(int argc, char **argv)
                usage(stdout, progname);
                exit(EXIT_SUCCESS);
        }
+       
+       for (i = 0; i < argc; i++) {
+               
+               if (0 == i) {
+                       where = FIRST_ZONE;
+               } else if ((argc - 1) == i) {
+                       where = LAST_ZONE;
+               } else {
+                       where = MIDDLE_ZONE;
+               }
+               if (!(fp = fopen(argv[i], "r"))) {
+                       printf("Cannot open file\n");
+                       exit(EXIT_FAILURE);
+               }
+               
+               if (!(z = ldns_zone_new_frm_fp(fp, origin, 0, 0))) {
+                       printf("cannot parse the zone\n");
+                       exit(EXIT_FAILURE);
+               }
+
+               zrr = ldns_zone_rrs(z);
 
+               printf("** READING %s\n", argv[i]);
+
+               for (j = 0; j < ldns_rr_list_rr_count(zrr); j++) {
+
+                       current_rr = ldns_rr_list_rr(zrr, j);
+               
+                       switch(where) {
+                               case FIRST_ZONE:
+                                       /* remove the last RRs with the same name */
+                                       break;
+                               case MIDDLE_ZONE:
+                                       if (ldns_rr_get_type(current_rr) ==
+                                                       LDNS_RR_TYPE_SOA) {
+                                               /* skip this */
+                                               continue;
+                                       }
+                                       
+                                       /* remove 
+                                        * SOA + SOA sig
+                                        * KEY + sig KEYs
+                                        * remove the last RRs with the same name */
+                                       break;
+                               case LAST_ZONE:
+                                       if (ldns_rr_get_type(current_rr) ==
+                                                       LDNS_RR_TYPE_SOA) {
+                                               /* skip this */
+                                               continue;
+                                       }
+                                       /* remove
+                                        * SOA + SOA sig
+                                        * KEY + sig KEYS
+                                        * DONT remove the last record */
+                                       break;
+                       }
+                       ldns_rr_print(stdout, current_rr);
+               }
+       }
         exit(EXIT_SUCCESS);
 }