summaryrefslogtreecommitdiff
path: root/ext/standard/dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/dns.c')
-rw-r--r--ext/standard/dns.c62
1 files changed, 49 insertions, 13 deletions
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
index 7bf7ccac85..53483ff58b 100644
--- a/ext/standard/dns.c
+++ b/ext/standard/dns.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2013 The PHP Group |
+ | Copyright (c) 1997-2012 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -413,7 +413,7 @@ PHP_FUNCTION(dns_check_record)
#if HAVE_FULL_DNS_FUNCS
/* {{{ php_parserr */
-static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int store, zval **subarray)
+static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int store, int raw, zval **subarray)
{
u_short type, class, dlen;
u_long ttl;
@@ -449,6 +449,16 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int
array_init(*subarray);
add_assoc_string(*subarray, "host", name, 1);
+ add_assoc_string(*subarray, "class", "IN", 1);
+ add_assoc_long(*subarray, "ttl", ttl);
+
+ if (raw) {
+ add_assoc_long(*subarray, "type", type);
+ add_assoc_stringl(*subarray, "data", (char*) cp, (uint) dlen, 1);
+ cp += dlen;
+ return cp;
+ }
+
switch (type) {
case DNS_T_A:
add_assoc_string(*subarray, "type", "A", 1);
@@ -689,12 +699,12 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int
add_assoc_string(*subarray, "replacement", name, 1);
break;
default:
+ zval_ptr_dtor(subarray);
+ *subarray = NULL;
cp += dlen;
+ break;
}
- add_assoc_string(*subarray, "class", "IN", 1);
- add_assoc_long(*subarray, "ttl", ttl);
-
return cp;
}
/* }}} */
@@ -721,8 +731,10 @@ PHP_FUNCTION(dns_get_record)
u_char *cp = NULL, *end = NULL;
int n, qd, an, ns = 0, ar = 0;
int type, first_query = 1, store_results = 1;
+ zend_bool raw = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lzz", &hostname, &hostname_len, &type_param, &authns, &addtl) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz!z!b",
+ &hostname, &hostname_len, &type_param, &authns, &addtl, &raw) == FAILURE) {
return;
}
@@ -735,9 +747,17 @@ PHP_FUNCTION(dns_get_record)
array_init(addtl);
}
- if (type_param & ~PHP_DNS_ALL && type_param != PHP_DNS_ANY) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type '%ld' not supported", type_param);
- RETURN_FALSE;
+ if (!raw) {
+ if ((type_param & ~PHP_DNS_ALL) && (type_param != PHP_DNS_ANY)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type '%ld' not supported", type_param);
+ RETURN_FALSE;
+ }
+ } else {
+ if ((type_param < 1) || (type_param > 0xFFFF)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,
+ "Numeric DNS record type must be between 1 and 65535, '%ld' given", type_param);
+ RETURN_FALSE;
+ }
}
/* Initialize the return array */
@@ -748,13 +768,29 @@ PHP_FUNCTION(dns_get_record)
* store_results is used to skip storing the results retrieved in step
* NUMTYPES+1 when results were already fetched.
* - In case of PHP_DNS_ANY we use the directly fetch DNS_T_ANY. (step NUMTYPES+1 )
+ * - In case of raw mode, we query only the requestd type instead of looping type by type
+ * before going with the additional info stuff.
*/
- for (type = (type_param == PHP_DNS_ANY ? (PHP_DNS_NUM_TYPES + 1) : 0);
+
+ if (raw) {
+ type = -1;
+ } else if (type_param == PHP_DNS_ANY) {
+ type = PHP_DNS_NUM_TYPES + 1;
+ } else {
+ type = 0;
+ }
+
+ for ( ;
type < (addtl ? (PHP_DNS_NUM_TYPES + 2) : PHP_DNS_NUM_TYPES) || first_query;
type++
) {
first_query = 0;
switch (type) {
+ case -1: /* raw */
+ type_to_fetch = type_param;
+ /* skip over the rest and go directly to additional records */
+ type = PHP_DNS_NUM_TYPES - 1;
+ break;
case 0:
type_to_fetch = type_param&PHP_DNS_A ? DNS_T_A : 0;
break;
@@ -848,7 +884,7 @@ PHP_FUNCTION(dns_get_record)
while (an-- && cp && cp < end) {
zval *retval;
- cp = php_parserr(cp, &answer, type_to_fetch, store_results, &retval);
+ cp = php_parserr(cp, &answer, type_to_fetch, store_results, raw, &retval);
if (retval != NULL && store_results) {
add_next_index_zval(return_value, retval);
}
@@ -861,7 +897,7 @@ PHP_FUNCTION(dns_get_record)
while (ns-- > 0 && cp && cp < end) {
zval *retval = NULL;
- cp = php_parserr(cp, &answer, DNS_T_ANY, authns != NULL, &retval);
+ cp = php_parserr(cp, &answer, DNS_T_ANY, authns != NULL, raw, &retval);
if (retval != NULL) {
add_next_index_zval(authns, retval);
}
@@ -873,7 +909,7 @@ PHP_FUNCTION(dns_get_record)
while (ar-- > 0 && cp && cp < end) {
zval *retval = NULL;
- cp = php_parserr(cp, &answer, DNS_T_ANY, 1, &retval);
+ cp = php_parserr(cp, &answer, DNS_T_ANY, 1, raw, &retval);
if (retval != NULL) {
add_next_index_zval(addtl, retval);
}