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) {
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);
}