From: Miek Gieben Date: Wed, 14 Dec 2005 15:00:56 +0000 (+0000) Subject: it does something usefull already X-Git-Tag: release-1.1.0~512 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=163f9aa3496a1da22833732eb226e8662c7737ca;p=thirdparty%2Fldns.git it does something usefull already --- diff --git a/examples/ldns-zcat.c b/examples/ldns-zcat.c index 26db2d90..7d28aa2d 100644 --- a/examples/ldns-zcat.c +++ b/examples/ldns-zcat.c @@ -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); }