From: Miek Gieben Date: Tue, 15 Mar 2005 14:53:23 +0000 (+0000) Subject: some easy (not so robust functions) added X-Git-Tag: release-0.50~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf42c91d347064308663bc2f9bca29a93789b648;p=thirdparty%2Fldns.git some easy (not so robust functions) added --- diff --git a/Makefile.in b/Makefile.in index bc7d387a..6da69c2c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -135,10 +135,12 @@ doc: clean: rm -f *.o *.d rm -f $(TESTS) + rm -f $(PROG_TARGETS) rm -rf autom4te.cache/ rm -f config.status rm -f config.log rm -f libldns.a + rm -f tags testclean: rm -f $(TESTS) diff --git a/ldns/rdata.h b/ldns/rdata.h index 03e70903..593877f3 100644 --- a/ldns/rdata.h +++ b/ldns/rdata.h @@ -118,11 +118,13 @@ int ldns_rdf_compare(const ldns_rdf *, const ldns_rdf *); uint8_t ldns_rdf2native_int8(ldns_rdf *); uint16_t ldns_rdf2native_int16(ldns_rdf *); uint32_t ldns_rdf2native_int32(ldns_rdf *); -ldns_rdf * ldns_native2rdf_int8(ldns_rdf_type type, uint8_t value); -ldns_rdf * ldns_native2rdf_int16(ldns_rdf_type type, uint16_t value); -ldns_rdf * ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value); -ldns_rdf * ldns_native2rdf_int16_data(uint16_t size, uint8_t *data); +ldns_rdf *ldns_native2rdf_int8(ldns_rdf_type type, uint8_t value); +ldns_rdf *ldns_native2rdf_int16(ldns_rdf_type type, uint16_t value); +ldns_rdf *ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value); +ldns_rdf *ldns_native2rdf_int16_data(uint16_t size, uint8_t *data); uint32_t ldns_str2period(const char *, const char **); ldns_rdf *ldns_rdf_address_reverse(ldns_rdf *); +ldns_rdf *ldns_rdf_new_frm_fp(ldns_rdf_type type, FILE *fp); + #endif /* !_LDNS_RDATA_H */ diff --git a/ldns/rr.h b/ldns/rr.h index 6d4de124..e911a7cb 100644 --- a/ldns/rr.h +++ b/ldns/rr.h @@ -281,6 +281,9 @@ ldns_rr_list *ldns_rr_list_deep_clone(ldns_rr_list *); void ldns_rr_list2canonical(ldns_rr_list *); void ldns_rr2canonical(ldns_rr *); +ldns_rr * ldns_rr_new_frm_fp(FILE *fp); + + #endif /* _LDNS_RR_H */ diff --git a/rdata.c b/rdata.c index 30561c57..993eacb8 100644 --- a/rdata.c +++ b/rdata.c @@ -407,6 +407,29 @@ ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str) } } +/** + * Create a new rdf from a file containing a string + * \param[in] fp the file pointer to use + * \param[in] t type to use + * \return ldns_rdf* + */ +ldns_rdf * +ldns_rdf_new_frm_fp(ldns_rdf_type type, FILE *fp) +{ + char *line; + + line = XMALLOC(char, MAXLINE_LEN + 1); + if (!line) { + return NULL; + } + + /* read an entire line in from the file */ + if (readword(line, fp, "\n", MAXLINE_LEN) == -1) { + return NULL; + } + return ldns_rdf_new_frm_str(type, (const char*) line); +} + /** * reverse an rdf, only actually usefull for AAAA and A records * the returned rdf has the type LDNS_RDF_TYPE_DNAME! diff --git a/rr.c b/rr.c index cc2a60e4..c2c8a4cf 100644 --- a/rr.c +++ b/rr.c @@ -176,6 +176,28 @@ ldns_rr_new_frm_str(const char *str) } +/** + * Create a new rr from a file containing a string + * \param[in] fp the file pointer to use + * \param[in] t type to use + * \return ldns_rr* + */ +ldns_rr * +ldns_rr_new_frm_fp(FILE *fp) +{ + char *line; + + line = XMALLOC(char, MAXLINE_LEN + 1); + if (!line) { + return NULL; + } + + /* read an entire line in from the file */ + if (readword(line, fp, "\n", MAXLINE_LEN) == -1) { + return NULL; + } + return ldns_rr_new_frm_str((const char*) line); +} /** * \brief set the owner in the rr structure