diff --git a/src/dnslib/descriptor.c b/src/dnslib/descriptor.c index 91e2cd16aa6323cbfa60d5dc91f7e75a9ca7ccea..d06b9ee0b1a7b86842866770e9927f6034b5ea49 100644 --- a/src/dnslib/descriptor.c +++ b/src/dnslib/descriptor.c @@ -19,7 +19,7 @@ enum desclen { DNSLIB_RRTYPE_DESCRIPTORS_LENGTH = 101 }; /* Taken from RFC 1035, section 3.2.4. */ -static lookup_table_type dns_rrclasses[] = { +static dnslib_lookup_table_t dns_rrclasses[] = { { DNSLIB_CLASS_IN, "IN" }, /* the Internet */ { DNSLIB_CLASS_CS, "CS" }, /* the CSNET class (Obsolete) */ { DNSLIB_CLASS_CH, "CH" }, /* the CHAOS class */ @@ -251,7 +251,7 @@ static dnslib_rrtype_descriptor_t dnslib_rrtype_descriptors[DNSLIB_RRTYPE_DESCRI { DNSLIB_RDATA_WF_SHORT, DNSLIB_RDATA_WF_BYTE, DNSLIB_RDATA_WF_BYTE, DNSLIB_RDATA_WF_BINARY } },*/ }; -lookup_table_type *lookup_by_name( lookup_table_type *table, const char *name ) +dnslib_lookup_table_t *dnslib_lookup_by_name( dnslib_lookup_table_t *table, const char *name ) { while (table->name != NULL) { if (strcasecmp(name, table->name) == 0) @@ -262,7 +262,7 @@ lookup_table_type *lookup_by_name( lookup_table_type *table, const char *name ) return NULL; } -lookup_table_type *lookup_by_id( lookup_table_type *table, int id ) +dnslib_lookup_table_t *dnslib_lookup_by_id( dnslib_lookup_table_t *table, int id ) { while (table->name != NULL) { if (table->id == id) @@ -273,7 +273,18 @@ lookup_table_type *lookup_by_id( lookup_table_type *table, int id ) return NULL; } -size_t strlcpy( char *dst, const char *src, size_t siz ) +/*! + * \brief Strlcpy - safe string copy function, based on FreeBSD implementation. + * + * http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/ + * + * \param dst Destination string. + * \param src Source string. + * \param siz How many characters to copy - 1. + * + * \return strlen(src), if retval >= siz, truncation occurred. + */ +size_t dnslib_strlcpy( char *dst, const char *src, size_t siz ) { char *d = dst; const char *s = src; @@ -330,7 +341,7 @@ dnslib_rrtype_descriptor_t *rrtype_descriptor_by_name( const char *name ) return NULL; } -const char *rrtype_to_string( uint16_t rrtype ) +const char *dnslib_rrtype_to_string( uint16_t rrtype ) { static char buf[20]; dnslib_rrtype_descriptor_t *descriptor = @@ -343,7 +354,7 @@ const char *rrtype_to_string( uint16_t rrtype ) } } -uint16_t rrtype_from_string( const char *name ) +uint16_t dnslib_rrtype_from_string( const char *name ) { char *end; long rrtype; @@ -373,26 +384,26 @@ uint16_t rrtype_from_string( const char *name ) return (uint16_t) rrtype; } -const char *rrclass_to_string(uint16_t rrclass) +const char *dnslib_rrclass_to_string(uint16_t rrclass) { static char buf[20]; - lookup_table_type *entry = lookup_by_id(dns_rrclasses, rrclass); + dnslib_lookup_table_t *entry = dnslib_lookup_by_id(dns_rrclasses, rrclass); if (entry) { assert(strlen(entry->name) < sizeof(buf)); //XXX check it using other way - strlcpy(buf, entry->name, sizeof(buf)); + dnslib_strlcpy(buf, entry->name, sizeof(buf)); } else { snprintf(buf, sizeof(buf), "CLASS%d", (int) rrclass); } return buf; } -uint16_t rrclass_from_string(const char *name) +uint16_t dnslib_rrclass_from_string(const char *name) { char *end; long rrclass; - lookup_table_type *entry; + dnslib_lookup_table_t *entry; - entry = lookup_by_name(dns_rrclasses, name); + entry = dnslib_lookup_by_name(dns_rrclasses, name); if (entry) { return (uint16_t) entry->id; } diff --git a/src/dnslib/descriptor.h b/src/dnslib/descriptor.h index 465a9a3592e65b1f6b4825e7fb849495ecff123b..3de2d2f75749450b8698639555a83ddbc43a5c5e 100644 --- a/src/dnslib/descriptor.h +++ b/src/dnslib/descriptor.h @@ -28,12 +28,13 @@ enum mxrdtln /*! * \brief A general purpose lookup table. */ -typedef struct lookup_table lookup_table_type; -struct lookup_table { +struct dnslib_lookup_table { int id; const char *name; }; +typedef struct dnslib_lookup_table dnslib_lookup_table_t; + /*! * \brief Enum containing RR class codes. */ @@ -168,19 +169,6 @@ struct dnslib_rrtype_descriptor */ typedef struct dnslib_rrtype_descriptor dnslib_rrtype_descriptor_t; -/*! - * \brief Strlcpy - safe string copy function, based on FreeBSD implementation. - * - * http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/ - * - * \param dst Destination string. - * \param src Source string. - * \param siz How many characters to copy - 1. - * - * \return strlen(src), if retval >= siz, truncation occurred. - */ -size_t strlcpy( char *dst, const char *src, size_t siz ); - /*! * \brief Gets RR descriptor for given RR type. * @@ -199,7 +187,7 @@ dnslib_rrtype_descriptor_t *dnslib_rrtype_descriptor_by_type( uint16_t type ); * \return RR descriptor for given name, NULL descriptor if * unknown type. */ -dnslib_rrtype_descriptor_t *rrtype_descriptor_by_name( const char *name ); +dnslib_rrtype_descriptor_t *dnslib_rrtype_descriptor_by_name( const char *name ); /*! * \brief Converts numeric type representation to mnemonic string. @@ -208,7 +196,7 @@ dnslib_rrtype_descriptor_t *rrtype_descriptor_by_name( const char *name ); * * \return Mnemonic string if found, str(TYPE[rrtype]) otherwise. */ -const char *rrtype_to_string( uint16_t rrtype ); +const char *dnslib_rrtype_to_string( uint16_t rrtype ); /*! * \brief Converts mnemonic string representation of a type to numeric one. @@ -217,7 +205,7 @@ const char *rrtype_to_string( uint16_t rrtype ); * * \return Correct code if found, 0 otherwise. */ -uint16_t rrtype_from_string( const char *name ); +uint16_t dnslib_rrtype_from_string( const char *name ); /*! * \brief Converts numeric class representation to string one. @@ -227,7 +215,7 @@ uint16_t rrtype_from_string( const char *name ); * \return String represenation of class if found, * str(CLASS[rrclass]) otherwise. */ -const char *rrclass_to_string( uint16_t rrclass ); +const char *dnslib_rrclass_to_string( uint16_t rrclass ); /*! * \brief Converts string representation of a class to numeric one. @@ -236,7 +224,7 @@ const char *rrclass_to_string( uint16_t rrclass ); * * \return Correct code if found, 0 otherwise. */ -uint16_t rrclass_from_string( const char *name ); +uint16_t dnslib_rrclass_from_string( const char *name ); #endif diff --git a/src/tests/dnslib/dnslib_dname_tests.c b/src/tests/dnslib/dnslib_dname_tests.c index 5eb74008e38fe0b1c473e83645e8b60b007c015d..52f616e406988e803fd9864949a1ef07c489139a 100644 --- a/src/tests/dnslib/dnslib_dname_tests.c +++ b/src/tests/dnslib/dnslib_dname_tests.c @@ -241,7 +241,7 @@ static int dnslib_dname_tests_run(int argc, char *argv[]) ok(test_dname_to_str(), "dname: convert to str"); - ok(test_faulty_data(), "dname: faulty data test"); + lives_ok(test_faulty_data();, "dname: faulty data test"); endskip; /* !res_str || !res_wire */