--- embedaddon/php/ext/standard/dns_win32.c 2012/02/21 23:48:02 1.1.1.1 +++ embedaddon/php/ext/standard/dns_win32.c 2012/05/29 12:34:43 1.1.1.2 @@ -138,7 +138,7 @@ PHP_FUNCTION(dns_check_record) /* }}} */ /* {{{ php_parserr */ -static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, zval **subarray) +static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, int raw, zval **subarray) { int type; u_long ttl; @@ -158,6 +158,15 @@ static void php_parserr(PDNS_RECORD pRec, int type_to_ array_init(*subarray); add_assoc_string(*subarray, "host", pRec->pName, 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*) &pRec->Data, (uint) pRec->wDataLength, 1); + return; + } + switch (type) { case DNS_TYPE_A: { IN_ADDR ipaddr; @@ -308,9 +317,9 @@ static void php_parserr(PDNS_RECORD pRec, int type_to_ } break; +#if _MSC_VER >= 1500 case DNS_TYPE_NAPTR: { -#if _MSC_VER >= 1500 DNS_NAPTR_DATA * data_naptr = &pRec->Data.Naptr; add_assoc_string(*subarray, "type", "NAPTR", 1); @@ -320,16 +329,17 @@ static void php_parserr(PDNS_RECORD pRec, int type_to_ add_assoc_string(*subarray, "services", data_naptr->pService, 1); add_assoc_string(*subarray, "regex", data_naptr->pRegularExpression, 1); add_assoc_string(*subarray, "replacement", data_naptr->pReplacement, 1); -#endif } break; +#endif default: - break; + /* unkown type */ + zval_ptr_dtor(subarray); + *subarray = NULL; + return; } - add_assoc_string(*subarray, "class", "IN", 1); - add_assoc_long(*subarray, "ttl", ttl); } /* }}} */ @@ -342,8 +352,10 @@ PHP_FUNCTION(dns_get_record) long type_param = PHP_DNS_ANY; zval *authns = NULL, *addtl = NULL; int type, type_to_fetch, 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; } @@ -356,15 +368,31 @@ 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 */ array_init(return_value); - 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++ ) { @@ -373,6 +401,11 @@ PHP_FUNCTION(dns_get_record) 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_TYPE_A : 0; break; @@ -436,7 +469,7 @@ PHP_FUNCTION(dns_get_record) zval *retval = NULL; if (pRec->Flags.S.Section == DnsSectionAnswer) { - php_parserr(pRec, type_to_fetch, store_results, &retval); + php_parserr(pRec, type_to_fetch, store_results, raw, &retval); if (retval != NULL && store_results) { add_next_index_zval(return_value, retval); } @@ -444,7 +477,7 @@ PHP_FUNCTION(dns_get_record) if (authns && pRec->Flags.S.Section == DnsSectionAuthority) { - php_parserr(pRec, type_to_fetch, store_results, &retval); + php_parserr(pRec, type_to_fetch, 1, raw, &retval); if (retval != NULL) { add_next_index_zval(authns, retval); } @@ -459,7 +492,7 @@ PHP_FUNCTION(dns_get_record) # endif #endif if (addtl && pRec->Flags.S.Section == DnsSectionAdditional) { - php_parserr(pRec, type_to_fetch, store_results, &retval); + php_parserr(pRec, type_to_fetch, 1, raw, &retval); if (retval != NULL) { add_next_index_zval(addtl, retval); }