[ldns-users] suggestion for a parse-rrs callback method

Willem Toorop Willem at NLnetLabs.nl
Mon May 27 17:28:52 UTC 2013


I am actually thinking along these lines (iterators and other more
interface oriented (and less data centric) approaches) for some time
now. I guess the parser is a good place to start out with as some of the
example tools would benefit right away! For example ldns-verify-zone
wouldn't have to read in the complete zone just to check the apex!.

-- Willem

Op 27-05-13 17:17, Robert Edmonds schreef:
> Jelte Jansen wrote:
>> So what would be very useful is a general construct to define a
>> function that is called for every RR in a given file stream, e.g. a
>> callback that gets an RR and probably a callback-specific void*
>> 'state' object. Said construct would keep track of the state
>> involved in 'real' parsing so that I don't have to repeat the same
>> code over and over again.
>> Ideally, the calling program would then just have to define its
>> callback, open the file, and call the ldns parser code, and be done
>> with it, e.g. in the case of ldns I'd want something like:
>> // Callback to print the RR, no state.
>> int printer(ldns_rr* rr, void* state) {
>> 	ldns_rr_print(stdout, rr);
>> 	return 0;
>> }
>> in = fopen("my.zone", "r");
>> if (in != NULL) {
>> 	ldns_parse_rr_stream(in, printer, NULL);
>> 	fclose(in);
>> }
> this seems like a very simple iterator pattern.  why complicate it with
> a callback?  e.g.,
>     in = fopen("my.zone", "r");
>     if (in != NULL) {
>         ldns_rr *rr;
>         ldns_rr_iter *iter = ldns_parse_rr_iter_frm_fp(in);
>         while ((rr = ldns_rr_iter_next(iter)) != NULL)
>             ldns_rr_print(stdout, rr);
>         ldns_rr_iter_free(iter);
>     }
> this makes the interface much easier to call in languages that are not C
> or C++.

More information about the ldns-users mailing list