[asterisk-commits] mmichelson: branch group/dns r434153 - in /team/group/dns: include/asterisk/ ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 6 15:58:14 CDT 2015
Author: mmichelson
Date: Mon Apr 6 15:58:12 2015
New Revision: 434153
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=434153
Log:
Move some common parsing functions to the DNS core.
Modified:
team/group/dns/include/asterisk/dns_internal.h
team/group/dns/main/dns_core.c
team/group/dns/main/dns_naptr.c
team/group/dns/main/dns_srv.c
Modified: team/group/dns/include/asterisk/dns_internal.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/include/asterisk/dns_internal.h?view=diff&rev=434153&r1=434152&r2=434153
==============================================================================
--- team/group/dns/include/asterisk/dns_internal.h (original)
+++ team/group/dns/include/asterisk/dns_internal.h Mon Apr 6 15:58:12 2015
@@ -219,3 +219,25 @@
* \param response_size The size of the complete DNS response
*/
char *dns_find_record(const char *record, size_t record_size, const char *response, size_t response_size);
+
+/*!
+ * \brief Parse a 16-bit unsigned value from a DNS record
+ *
+ * \param cur Pointer to the location of the 16-bit value in the DNS record
+ * \param[out] val The parsed 16-bit unsigned integer
+ * \return The number of bytes consumed while parsing
+ */
+int dns_parse_short(unsigned char *cur, uint16_t *val);
+
+/*!
+ * \brief Parse a DNS string from a DNS record
+ *
+ * A DNS string consists of an 8-bit size, followed by the
+ * string value (not NULL-terminated).
+ *
+ * \param cur Pointer to the location of the DNS string
+ * \param[out] size The parsed size of the DNS string
+ * \param[out] val The contained string (not NULL-terminated)
+ * \return The number of bytes consumed while parsing
+ */
+int dns_parse_string(char *cur, uint8_t *size, char **val);
Modified: team/group/dns/main/dns_core.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/main/dns_core.c?view=diff&rev=434153&r1=434152&r2=434153
==============================================================================
--- team/group/dns/main/dns_core.c (original)
+++ team/group/dns/main/dns_core.c Mon Apr 6 15:58:12 2015
@@ -631,3 +631,22 @@
search_base = record_offset + 1;
}
}
+
+int dns_parse_short(unsigned char *cur, uint16_t *val)
+{
+ /* This assignment takes a big-endian 16-bit value and stores it in the
+ * machine's native byte order. Using this method allows us to avoid potential
+ * alignment issues in case the order is not on a short-addressable boundary.
+ * See http://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html for
+ * more information
+ */
+ *val = (cur[1] << 0) | (cur[0] << 8);
+ return sizeof(*val);
+}
+
+int dns_parse_string(char *cur, uint8_t *size, char **val)
+{
+ *size = *cur++;
+ *val = cur;
+ return *size + 1;
+}
Modified: team/group/dns/main/dns_naptr.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/main/dns_naptr.c?view=diff&rev=434153&r1=434152&r2=434153
==============================================================================
--- team/group/dns/main/dns_naptr.c (original)
+++ team/group/dns/main/dns_naptr.c Mon Apr 6 15:58:12 2015
@@ -407,54 +407,31 @@
* See http://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html for
* more information
*/
- order = ((unsigned char)(ptr[1]) << 0) | ((unsigned char)(ptr[0]) << 8);
- ptr += 2;
-
+ ptr += dns_parse_short((unsigned char *) ptr, &order);
if (PAST_END_OF_RECORD) {
return NULL;
}
/* PREFERENCE */
- preference = ((unsigned char) (ptr[1]) << 0) | ((unsigned char)(ptr[0]) << 8);
- ptr += 2;
-
+ ptr += dns_parse_short((unsigned char *) ptr, &preference);
if (PAST_END_OF_RECORD) {
return NULL;
}
/* FLAGS */
- flags_size = *ptr;
- ++ptr;
+ ptr += dns_parse_string(ptr, &flags_size, &flags);
if (PAST_END_OF_RECORD) {
return NULL;
}
- flags = ptr;
- ptr += flags_size;
+ /* SERVICES */
+ ptr += dns_parse_string(ptr, &services_size, &services);
if (PAST_END_OF_RECORD) {
return NULL;
}
- /* SERVICES */
- services_size = *ptr;
- ++ptr;
- if (PAST_END_OF_RECORD) {
- return NULL;
- }
- services = ptr;
- ptr += services_size;
- if (PAST_END_OF_RECORD) {
- return NULL;
- }
-
/* REGEXP */
- regexp_size = *ptr;
- ++ptr;
- if (PAST_END_OF_RECORD) {
- return NULL;
- }
- regexp = ptr;
- ptr += regexp_size;
+ ptr += dns_parse_string(ptr, ®exp_size, ®exp);
if (PAST_END_OF_RECORD) {
return NULL;
}
Modified: team/group/dns/main/dns_srv.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns/main/dns_srv.c?view=diff&rev=434153&r1=434152&r2=434153
==============================================================================
--- team/group/dns/main/dns_srv.c (original)
+++ team/group/dns/main/dns_srv.c Mon Apr 6 15:58:12 2015
@@ -58,25 +58,19 @@
end_of_record = ptr + size;
/* PRIORITY */
- priority = ((unsigned char)(ptr[1]) << 0) | ((unsigned char)(ptr[0]) << 8);
- ptr += 2;
-
+ ptr += dns_parse_short((unsigned char *) ptr, &priority);
if (ptr >= end_of_record) {
return NULL;
}
/* WEIGHT */
- weight = ((unsigned char)(ptr[1]) << 0) | ((unsigned char)(ptr[0]) << 8);
- ptr += 2;
-
+ ptr += dns_parse_short((unsigned char *) ptr, &weight);
if (ptr >= end_of_record) {
return NULL;
}
/* PORT */
- port = ((unsigned char)(ptr[1]) << 0) | ((unsigned char)(ptr[0]) << 8);
- ptr += 2;
-
+ ptr += dns_parse_short((unsigned char *) ptr, &port);
if (ptr >= end_of_record) {
return NULL;
}
More information about the asterisk-commits
mailing list