From jelte.jansen at sidn.nl Mon Jun 3 13:43:21 2013 From: jelte.jansen at sidn.nl (Jelte Jansen) Date: Mon, 3 Jun 2013 15:43:21 +0200 Subject: [ldns-users] suggestion for a parse-rrs callback method In-Reply-To: <20130527151731.GA6761@mycre.ws> References: <51A32FDA.2000802@sidn.nl> <20130527151731.GA6761@mycre.ws> Message-ID: <51AC9D79.80608@sidn.nl> On 05/27/2013 05:17 PM, Robert Edmonds wrote: > Jelte Jansen wrote: > > 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++. > OK, I didn't think callbacks are that much more complicated (certainly since the lib-side code is easier), but yeah that makes sense, and using something like an iterator does make it more flexible anyway, and not much harder to do. (BTW nlnetlabs! Move to github! I wanna do pull requests ;)) Proposal 2: #include #include #include #include #define DEBUG 1 // Iterator structure, initialize with ldns_rr_iter_frm_file() // must be cleaned up with ldns_rr_iter_free() when done. // Will parse and return a newly allocated rr on each call to // ldns_rr_iter_next(). The rr must be freed by the caller. typedef struct { FILE* fp; uint32_t ttl; ldns_rdf* prev; ldns_rdf* origin; ldns_status last_status; } ldns_rr_iterator; // Creates an iterator from a FILE pointer // Caller must free it with ldns_rr_iter_free() when done // Todo: Make it take defaults for ttl and origin? ldns_rr_iterator* ldns_rr_iter_frm_file(FILE* in) { ldns_rr_iterator* iter = (ldns_rr_iterator*) malloc(sizeof(ldns_rr_iterator)); iter->fp=in; iter->last_status = LDNS_STATUS_OK; iter->ttl = 3600; iter->prev = NULL; iter->origin = NULL; return iter; } // Parses and returns the next resource records in the iterator. // Returned RR must be freed by the caller // Returns NULL when done, or when a parse error is encountered. // Check the value of the iterators last_status when NULL is returned // to see which case was found. ldns_rr* ldns_rr_iter_next(ldns_rr_iterator* iter) { ldns_rr* rr = NULL; ldns_status status; while (!feof(iter->fp)) { status = ldns_rr_new_frm_fp(&rr, iter->fp, &iter->ttl, &iter->origin, &iter->prev); if (status == LDNS_STATUS_SYNTAX_EMPTY || status == LDNS_STATUS_SYNTAX_TTL || status == LDNS_STATUS_SYNTAX_ORIGIN) { // should there be nothing left after this, we // don't want to report an error to the caller status = LDNS_STATUS_OK; continue; } else { iter->last_status = status; break; } } return rr; } void ldns_rr_iter_free(ldns_rr_iterator* iter) { ldns_rdf_deep_free(iter->prev); ldns_rdf_deep_free(iter->origin); free(iter); } // Example use, int main(int argc, char** argv) { if (argc != 2) { printf("usage: rr_printer \n"); return 1; } char* filename = argv[1]; FILE* in = fopen(filename, "r"); ldns_rr* cur_rr; if (in != NULL) { ldns_rr_iterator* iter = ldns_rr_iter_frm_file(in); while (cur_rr = ldns_rr_iter_next(iter)) { ldns_rr_print(stdout, cur_rr); ldns_rr_free(cur_rr); } if (iter->last_status != LDNS_STATUS_OK) { printf("Error: %s\n", ldns_get_errorstr_by_id(iter->last_status)); } ldns_rr_iter_free(iter); } else { printf("Error opening %s: %s\n", filename, strerror(errno)); return 1; } fclose(in); return 0; } From edmonds at debian.org Mon Jun 3 16:04:38 2013 From: edmonds at debian.org (Robert Edmonds) Date: Mon, 3 Jun 2013 12:04:38 -0400 Subject: [ldns-users] suggestion for a parse-rrs callback method In-Reply-To: <51AC9D79.80608@sidn.nl> References: <51A32FDA.2000802@sidn.nl> <20130527151731.GA6761@mycre.ws> <51AC9D79.80608@sidn.nl> Message-ID: <20130603160438.GA16180@mycre.ws> Jelte Jansen wrote: > OK, I didn't think callbacks are that much more complicated (certainly > since the lib-side code is easier), but yeah that makes sense, and using > something like an iterator does make it more flexible anyway, and not > much harder to do. *in C*, callbacks are not that hard to use. in other languages it is much, much easier to call C code than to have C code call you. e.g., "Unfortunately you can't pass a Go func to C code and have the C code call it. The best you can do is pass a Go func to C code and have the C code turn around and pass the Go func back to a Go function that then calls the func." (https://groups.google.com/forum/#!topic/golang-nuts/PRcvOJqItow) > (BTW nlnetlabs! Move to github! I wanna do pull requests ;)) +1 -- Robert Edmonds edmonds at debian.org From Willem at NLnetLabs.nl Tue Jun 4 08:46:32 2013 From: Willem at NLnetLabs.nl (Willem Toorop) Date: Tue, 04 Jun 2013 10:46:32 +0200 Subject: [ldns-users] suggestion for a parse-rrs callback method In-Reply-To: <20130603160438.GA16180@mycre.ws> References: <51A32FDA.2000802@sidn.nl> <20130527151731.GA6761@mycre.ws> <51AC9D79.80608@sidn.nl> <20130603160438.GA16180@mycre.ws> Message-ID: <51ADA968.6010607@NLnetLabs.nl> Op 03-06-13 18:04, Robert Edmonds schreef: >> (BTW nlnetlabs! Move to github! I wanna do pull requests ;)) > > +1 :) To github wil not happen, but served in a git repository at NLnet Labs... maybe. Is anyone on the list against a move to git? -- Willem From ondrej at sury.org Tue Jun 4 09:11:35 2013 From: ondrej at sury.org (=?UTF-8?B?T25kxZllaiBTdXLDvQ==?=) Date: Tue, 4 Jun 2013 11:11:35 +0200 Subject: [ldns-users] suggestion for a parse-rrs callback method In-Reply-To: <51ADA968.6010607@NLnetLabs.nl> References: <51A32FDA.2000802@sidn.nl> <20130527151731.GA6761@mycre.ws> <51AC9D79.80608@sidn.nl> <20130603160438.GA16180@mycre.ws> <51ADA968.6010607@NLnetLabs.nl> Message-ID: On Tue, Jun 4, 2013 at 10:46 AM, Willem Toorop wrote: > Op 03-06-13 18:04, Robert Edmonds schreef: > >> (BTW nlnetlabs! Move to github! I wanna do pull requests ;)) > > > > +1 > > :) To github wil not happen, but served in a git repository at NLnet > Labs... maybe. Is anyone on the list against a move to git? > I would recommend gitlab (the public flavor). You can check it at: https://gitlab.labs.nic.cz/ I have just installed it over a weekend and we are already enjoying it very much for CZ.NIC Projects. It's not as awesome as github, but the set of features it has just fits perfectly for our deployment and it might fit NLNetLabs as well. (The only horrible thing is that it's written in Ruby, but it plays nice with rest of the system if you use RVM.) O. -- ?Ond?ej Sur? -------------- next part -------------- An HTML attachment was scrubbed... URL: From miek at miek.nl Tue Jun 4 09:12:50 2013 From: miek at miek.nl (Miek Gieben) Date: Tue, 4 Jun 2013 09:12:50 +0000 Subject: [ldns-users] suggestion for a parse-rrs callback method In-Reply-To: <51ADA968.6010607@NLnetLabs.nl> References: <51A32FDA.2000802@sidn.nl> <20130527151731.GA6761@mycre.ws> <51AC9D79.80608@sidn.nl> <20130603160438.GA16180@mycre.ws> <51ADA968.6010607@NLnetLabs.nl> Message-ID: <20130604091250.GA28563@miek.nl> [ Quoting in "Re: [ldns-users] suggestion for a p..." ] > Op 03-06-13 18:04, Robert Edmonds schreef: > >> (BTW nlnetlabs! Move to github! I wanna do pull requests ;)) > > > > +1 > > :) To github wil not happen, but served in a git repository at NLnet > Labs... maybe. Is anyone on the list against a move to git? "anyone on the list against a move to git" uh... no :) the sooner the better. - Grtz, --- Miek Gieben -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: From vladimir.levijev at gmail.com Thu Jun 13 14:07:21 2013 From: vladimir.levijev at gmail.com (Vladimir Levijev) Date: Thu, 13 Jun 2013 17:07:21 +0300 Subject: [ldns-users] Batch API and async Message-ID: Hi, Did I understand it correctly that ldns does not provide batch API? So that if I need to get results of 100 domain names I need to do 100 function calls, i. e. I cannot pass an array of targets. Also, did I understand it correctly that library does not provide a way to do asynchronous calls? So that a ldns function call blocks a program execution until return from that function. Cheers, VL From willem at nlnetlabs.nl Fri Jun 14 08:27:54 2013 From: willem at nlnetlabs.nl (Willem Toorop) Date: Fri, 14 Jun 2013 10:27:54 +0200 Subject: [ldns-users] Batch API and async In-Reply-To: References: Message-ID: <51BAD40A.3010208@nlnetlabs.nl> Op 13-06-13 16:07, Vladimir Levijev schreef: > Hi, Hi Vladimir, > Did I understand it correctly that ldns does not provide batch API? So > that if I need to get results of 100 domain names I need to do 100 > function calls, i. e. I cannot pass an array of targets. That is correct. > Also, did I understand it correctly that library does not provide a > way to do asynchronous calls? So that a ldns function call blocks a > program execution until return from that function. Ldns has rudimentary support for asynchonous calls with the ldns_udp_bgsend and ldns_tcp_bgsend functions. I suggest you have a look at libunbound (http://unbound.net/documentation/libunbound.html) which has an asynchronous interface to a full resolver. Cheers, -- Willem From vladimir.levijev at gmail.com Mon Jun 17 09:08:48 2013 From: vladimir.levijev at gmail.com (Vladimir Levijev) Date: Mon, 17 Jun 2013 12:08:48 +0300 Subject: [ldns-users] Batch API and async In-Reply-To: <51BAD40A.3010208@nlnetlabs.nl> References: <51BAD40A.3010208@nlnetlabs.nl> Message-ID: On 14 June 2013 11:27, Willem Toorop wrote: > Op 13-06-13 16:07, Vladimir Levijev schreef: Hi, >> Did I understand it correctly that ldns does not provide batch API? So >> that if I need to get results of 100 domain names I need to do 100 >> function calls, i. e. I cannot pass an array of targets. > > That is correct. > >> Also, did I understand it correctly that library does not provide a >> way to do asynchronous calls? So that a ldns function call blocks a >> program execution until return from that function. > > Ldns has rudimentary support for asynchonous calls with the > ldns_udp_bgsend and ldns_tcp_bgsend functions. > > I suggest you have a look at libunbound > (http://unbound.net/documentation/libunbound.html) which has an > asynchronous interface to a full resolver. Thanks, looks like libunbound is what we need. I noticed that it uses ldns? Is it the same team working on both projects or if not are the teams working closely? Cheers, VL From willem at nlnetlabs.nl Mon Jun 17 09:13:38 2013 From: willem at nlnetlabs.nl (Willem Toorop) Date: Mon, 17 Jun 2013 11:13:38 +0200 Subject: [ldns-users] Batch API and async In-Reply-To: References: <51BAD40A.3010208@nlnetlabs.nl> Message-ID: <51BED342.3090403@nlnetlabs.nl> Hi Vladimir, Op 17-06-13 11:08, Vladimir Levijev schreef: > Thanks, looks like libunbound is what we need. I noticed that it uses > ldns? Is it the same team working on both projects or if not are the > teams working closely? Both products are from us (NLnet Labs). We all work very closely together as we are in the same office :)! Cheers, -- Willem