pajoye Tue Jan 6 20:48:21 2009 UTC Added files: (Branch: PHP_5_3) /php-src/ext/standard dns_win32.c
Modified files: /php-src/ext/standard basic_functions.c config.w32 dns.c dns.h Log: - [MFH] - [DOC] add support for all DNS function on Windows - dns_check_record (and its alias checkdnsrr) - dns_get_record - IPV6 specific info not available yet: . AAAA info is available only on vista/2k8 for now . A6 info is not available - dns_get_mx (and its alias getmxrr)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.81&r2=1.725.2.31.2.64.2.82&diff_format=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.81 php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.82 --- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.81 Wed Dec 31 14:30:37 2008 +++ php-src/ext/standard/basic_functions.c Tue Jan 6 20:48:20 2009 @@ -3,7 +3,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2008 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 | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.81 2008/12/31 14:30:37 iliaa Exp $ */ +/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.82 2009/01/06 20:48:20 pajoye Exp $ */ #include "php.h" #include "php_streams.h" @@ -996,13 +996,13 @@ ZEND_END_ARG_INFO() #endif -#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || defined(NETWARE)) +#if defined(PHP_WIN32) || (HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(NETWARE))) ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_check_record, 0, 0, 1) ZEND_ARG_INFO(0, host) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() -# if HAVE_DNS_FUNCS +# if defined(PHP_WIN32) || HAVE_DNS_FUNCS ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_get_record, 1, 0, 1) ZEND_ARG_INFO(0, hostname) ZEND_ARG_INFO(0, type) @@ -1011,15 +1011,17 @@ ZEND_END_ARG_INFO() # endif -# if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND +# if defined(PHP_WIN32) || (HAVE_DN_SKIPNAME && HAVE_DN_EXPAND) ZEND_BEGIN_ARG_INFO_EX(arginfo_dns_get_mx, 0, 0, 2) ZEND_ARG_INFO(0, hostname) ZEND_ARG_INFO(1, mxhosts) /* ARRAY_INFO(1, mxhosts, 1) */ ZEND_ARG_INFO(1, weight) /* ARRAY_INFO(1, weight, 1) */ ZEND_END_ARG_INFO() # endif -#endif /* HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || defined(NETWARE)) */ + +#endif /* defined(PHP_WIN32) || (HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(NETWARE))) */ /* }}} */ + /* {{{ exec.c */ ZEND_BEGIN_ARG_INFO_EX(arginfo_exec, 0, 0, 1) ZEND_ARG_INFO(0, command) @@ -2999,14 +3001,17 @@ PHP_FE(gethostname, arginfo_gethostname) #endif -#if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32) || defined(NETWARE)) +#if defined(PHP_WIN32) || (HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(NETWARE))) + PHP_FE(dns_check_record, arginfo_dns_check_record) PHP_FALIAS(checkdnsrr, dns_check_record, arginfo_dns_check_record) -# if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND + +# if defined(PHP_WIN32) || (HAVE_DN_SKIPNAME && HAVE_DN_EXPAND) PHP_FE(dns_get_mx, arginfo_dns_get_mx) - PHP_FALIAS(getmxrr, dns_get_mx, arginfo_dns_get_mx) + PHP_FALIAS(getmxrr, dns_get_mx, arginfo_dns_get_mx) # endif -# if HAVE_DNS_FUNCS + +# if defined(PHP_WIN32) || HAVE_DNS_FUNCS PHP_FE(dns_get_record, arginfo_dns_get_record) # endif #endif @@ -3034,6 +3039,9 @@ PHP_FE(is_scalar, arginfo_is_scalar) PHP_FE(is_callable, arginfo_is_callable) + /* functions from dl.c */ +// PHP_FE(dl, arginfo_dl) + /* functions from file.c */ PHP_FE(pclose, arginfo_pclose) PHP_FE(popen, arginfo_popen) @@ -3636,8 +3644,8 @@ php_register_url_stream_wrapper("ftp", &php_stream_ftp_wrapper TSRMLS_CC); #endif -#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || defined(NETWARE)) -# if HAVE_DNS_FUNCS +#if defined(PHP_WIN32) || (HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(NETWARE))) +# if defined(PHP_WIN32) || HAVE_DNS_FUNCS PHP_MINIT(dns)(INIT_FUNC_ARGS_PASSTHRU); # endif #endif http://cvs.php.net/viewvc.cgi/php-src/ext/standard/config.w32?r1=1.4.2.2.2.1.2.4&r2=1.4.2.2.2.1.2.5&diff_format=u Index: php-src/ext/standard/config.w32 diff -u php-src/ext/standard/config.w32:1.4.2.2.2.1.2.4 php-src/ext/standard/config.w32:1.4.2.2.2.1.2.5 --- php-src/ext/standard/config.w32:1.4.2.2.2.1.2.4 Mon Jul 28 11:50:34 2008 +++ php-src/ext/standard/config.w32 Tue Jan 6 20:48:20 2009 @@ -1,5 +1,5 @@ // vim:ft=javascript -// $Id: config.w32,v 1.4.2.2.2.1.2.4 2008/07/28 11:50:34 pajoye Exp $ +// $Id: config.w32,v 1.4.2.2.2.1.2.5 2009/01/06 20:48:20 pajoye Exp $ ARG_WITH("config-file-scan-dir", "Dir to check for additional php ini files", ""); @@ -14,7 +14,7 @@ EXTENSION("standard", "array.c base64.c basic_functions.c browscap.c \ crc32.c crypt.c \ crypt_freesec.c crypt_blowfish.c php_crypt_r.c \ - cyr_convert.c datetime.c dir.c dl.c dns.c exec.c \ + cyr_convert.c datetime.c dir.c dl.c dns.c dns_win32.c exec.c \ file.c filestat.c formatted_print.c fsock.c head.c html.c image.c \ info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c microtime.c \ pack.c pageinfo.c quot_print.c rand.c soundex.c \ http://cvs.php.net/viewvc.cgi/php-src/ext/standard/dns.c?r1=1.70.2.7.2.5.2.11&r2=1.70.2.7.2.5.2.12&diff_format=u Index: php-src/ext/standard/dns.c diff -u php-src/ext/standard/dns.c:1.70.2.7.2.5.2.11 php-src/ext/standard/dns.c:1.70.2.7.2.5.2.12 --- php-src/ext/standard/dns.c:1.70.2.7.2.5.2.11 Wed Dec 31 15:48:18 2008 +++ php-src/ext/standard/dns.c Tue Jan 6 20:48:20 2009 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2008 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 | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dns.c,v 1.70.2.7.2.5.2.11 2008/12/31 15:48:18 tony2001 Exp $ */ +/* $Id: dns.c,v 1.70.2.7.2.5.2.12 2009/01/06 20:48:20 pajoye Exp $ */ /* {{{ includes */ #include "php.h" @@ -128,6 +128,10 @@ /* }}} */ #endif +/* TODO: Reimplement the gethostby* functions using the new winxp+ API, in dns_win32.c, then + we can have a dns.c, dns_unix.c and dns_win32.c instead of a messy dns.c full of #ifdef +*/ + /* {{{ proto string gethostbyaddr(string ip_address) Get the Internet host name corresponding to a given IP address */ PHP_FUNCTION(gethostbyaddr) @@ -155,7 +159,6 @@ } /* }}} */ - /* {{{ php_gethostbyaddr */ static char *php_gethostbyaddr(char *ip) { @@ -309,41 +312,6 @@ #if HAVE_DNS_FUNCS -#define PHP_DNS_NUM_TYPES 12 /* Number of DNS Types Supported by PHP currently */ - -#define PHP_DNS_A 0x00000001 -#define PHP_DNS_NS 0x00000002 -#define PHP_DNS_CNAME 0x00000010 -#define PHP_DNS_SOA 0x00000020 -#define PHP_DNS_PTR 0x00000800 -#define PHP_DNS_HINFO 0x00001000 -#define PHP_DNS_MX 0x00004000 -#define PHP_DNS_TXT 0x00008000 -#define PHP_DNS_A6 0x01000000 -#define PHP_DNS_SRV 0x02000000 -#define PHP_DNS_NAPTR 0x04000000 -#define PHP_DNS_AAAA 0x08000000 -#define PHP_DNS_ANY 0x10000000 -#define PHP_DNS_ALL (PHP_DNS_A|PHP_DNS_NS|PHP_DNS_CNAME|PHP_DNS_SOA|PHP_DNS_PTR|PHP_DNS_HINFO|PHP_DNS_MX|PHP_DNS_TXT|PHP_DNS_A6|PHP_DNS_SRV|PHP_DNS_NAPTR|PHP_DNS_AAAA) - -PHP_MINIT_FUNCTION(dns) { - REGISTER_LONG_CONSTANT("DNS_A", PHP_DNS_A, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_NS", PHP_DNS_NS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_CNAME", PHP_DNS_CNAME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_SOA", PHP_DNS_SOA, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_PTR", PHP_DNS_PTR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_HINFO", PHP_DNS_HINFO, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_MX", PHP_DNS_MX, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_TXT", PHP_DNS_TXT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_SRV", PHP_DNS_SRV, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_NAPTR", PHP_DNS_NAPTR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_AAAA", PHP_DNS_AAAA, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_A6", PHP_DNS_A6, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_ANY", PHP_DNS_ANY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_ALL", PHP_DNS_ALL, CONST_CS | CONST_PERSISTENT); - return SUCCESS; -} - #ifndef HFIXEDSZ #define HFIXEDSZ 12 /* fixed data in header <arpa/nameser.h> */ #endif /* HFIXEDSZ */ @@ -917,9 +885,46 @@ } /* }}} */ #endif /* HAVE_DN_SKIPNAME && HAVE_DN_EXPAND */ - #endif /* HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || defined(NETWARE)) */ + +#if HAVE_DNS_FUNCS || defined(PHP_WIN32) +#define PHP_DNS_NUM_TYPES 12 /* Number of DNS Types Supported by PHP currently */ + +#define PHP_DNS_A 0x00000001 +#define PHP_DNS_NS 0x00000002 +#define PHP_DNS_CNAME 0x00000010 +#define PHP_DNS_SOA 0x00000020 +#define PHP_DNS_PTR 0x00000800 +#define PHP_DNS_HINFO 0x00001000 +#define PHP_DNS_MX 0x00004000 +#define PHP_DNS_TXT 0x00008000 +#define PHP_DNS_A6 0x01000000 +#define PHP_DNS_SRV 0x02000000 +#define PHP_DNS_NAPTR 0x04000000 +#define PHP_DNS_AAAA 0x08000000 +#define PHP_DNS_ANY 0x10000000 +#define PHP_DNS_ALL (PHP_DNS_A|PHP_DNS_NS|PHP_DNS_CNAME|PHP_DNS_SOA|PHP_DNS_PTR|PHP_DNS_HINFO|PHP_DNS_MX|PHP_DNS_TXT|PHP_DNS_A6|PHP_DNS_SRV|PHP_DNS_NAPTR|PHP_DNS_AAAA) + +PHP_MINIT_FUNCTION(dns) { + REGISTER_LONG_CONSTANT("DNS_A", PHP_DNS_A, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_NS", PHP_DNS_NS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_CNAME", PHP_DNS_CNAME, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_SOA", PHP_DNS_SOA, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_PTR", PHP_DNS_PTR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_HINFO", PHP_DNS_HINFO, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_MX", PHP_DNS_MX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_TXT", PHP_DNS_TXT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_SRV", PHP_DNS_SRV, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_NAPTR", PHP_DNS_NAPTR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_AAAA", PHP_DNS_AAAA, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_A6", PHP_DNS_A6, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_ANY", PHP_DNS_ANY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DNS_ALL", PHP_DNS_ALL, CONST_CS | CONST_PERSISTENT); + return SUCCESS; +} +#endif /* HAVE_DNS_FUNCS */ + /* * Local variables: * tab-width: 4 http://cvs.php.net/viewvc.cgi/php-src/ext/standard/dns.h?r1=1.19.2.1.2.1.2.3&r2=1.19.2.1.2.1.2.4&diff_format=u Index: php-src/ext/standard/dns.h diff -u php-src/ext/standard/dns.h:1.19.2.1.2.1.2.3 php-src/ext/standard/dns.h:1.19.2.1.2.1.2.4 --- php-src/ext/standard/dns.h:1.19.2.1.2.1.2.3 Wed Dec 31 14:30:37 2008 +++ php-src/ext/standard/dns.h Tue Jan 6 20:48:20 2009 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2009 The PHP Group | + | Copyright (c) 1997-2008 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 | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dns.h,v 1.19.2.1.2.1.2.3 2008/12/31 14:30:37 iliaa Exp $ */ +/* $Id: dns.h,v 1.19.2.1.2.1.2.4 2009/01/06 20:48:20 pajoye Exp $ */ #ifndef DNS_H #define DNS_H @@ -35,21 +35,19 @@ PHP_FUNCTION(gethostname); #endif -#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32)) +#if defined(PHP_WIN32) || (HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(NETWARE))) -PHP_FUNCTION(dns_check_record); -# if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND +# if defined(PHP_WIN32) || (HAVE_DN_SKIPNAME && HAVE_DN_EXPAND) PHP_FUNCTION(dns_get_mx); +PHP_FUNCTION(dns_check_record); # endif -# if HAVE_DNS_FUNCS - +#if defined(PHP_WIN32) || HAVE_DNS_FUNCS PHP_FUNCTION(dns_get_record); - PHP_MINIT_FUNCTION(dns); - # endif -#endif + +#endif /* defined(PHP_WIN32) || (HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(NETWARE))) */ #ifndef INT16SZ #define INT16SZ 2 http://cvs.php.net/viewvc.cgi/php-src/ext/standard/dns_win32.c?view=markup&rev=1.1 Index: php-src/ext/standard/dns_win32.c +++ php-src/ext/standard/dns_win32.c /* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 2008-2009 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 | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | lice...@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Pierre A. Joye <pie...@php.net> | +----------------------------------------------------------------------+ */ #include "php.h" #include <windows.h> #include <Winbase.h > #include <Windns.h> #include "dns.h" #define PHP_DNS_NUM_TYPES 12 /* Number of DNS Types Supported by PHP currently */ #define PHP_DNS_A 0x00000001 #define PHP_DNS_NS 0x00000002 #define PHP_DNS_CNAME 0x00000010 #define PHP_DNS_SOA 0x00000020 #define PHP_DNS_PTR 0x00000800 #define PHP_DNS_HINFO 0x00001000 #define PHP_DNS_MX 0x00004000 #define PHP_DNS_TXT 0x00008000 #define PHP_DNS_A6 0x01000000 #define PHP_DNS_SRV 0x02000000 #define PHP_DNS_NAPTR 0x04000000 #define PHP_DNS_AAAA 0x08000000 #define PHP_DNS_ANY 0x10000000 #define PHP_DNS_ALL (PHP_DNS_A|PHP_DNS_NS|PHP_DNS_CNAME|PHP_DNS_SOA|PHP_DNS_PTR|PHP_DNS_HINFO|PHP_DNS_MX|PHP_DNS_TXT|PHP_DNS_A6|PHP_DNS_SRV|PHP_DNS_NAPTR|PHP_DNS_AAAA) PHP_FUNCTION(dns_get_mx) /* {{{ */ { char *hostname; int hostname_len; zval *mx_list, *weight_list = NULL; DNS_STATUS status; /* Return value of DnsQuery_A() function */ PDNS_RECORD pResult, pRec; /* Pointer to DNS_RECORD structure */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|z", &hostname, &hostname_len, &mx_list, &weight_list) == FAILURE) { return; } status = DnsQuery_A(hostname, DNS_TYPE_MX, DNS_QUERY_STANDARD, NULL, &pResult, NULL); if (status) { RETURN_FALSE; } zval_dtor(mx_list); array_init(mx_list); if (weight_list) { zval_dtor(weight_list); array_init(weight_list); } for (pRec = pResult; pRec; pRec = pRec->pNext) { DNS_SRV_DATA *srv = &pRec->Data.Srv; add_next_index_string(mx_list, pRec->Data.MX.pNameExchange, 1); if (weight_list) { add_next_index_long(weight_list, srv->wPriority); } } /* Free memory allocated for DNS records. */ DnsRecordListFree(pResult, DnsFreeRecordListDeep); RETURN_TRUE; } /* }}} */ /* {{{ proto bool dns_check_record(string host [, string type]) Check DNS records corresponding to a given Internet host name or IP address */ PHP_FUNCTION(dns_check_record) { char *hostname, *rectype = NULL; int hostname_len, rectype_len = 0; int type = DNS_TYPE_MX; DNS_STATUS status; /* Return value of DnsQuery_A() function */ PDNS_RECORD pResult, pRec; /* Pointer to DNS_RECORD structure */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &hostname, &hostname_len, &rectype, &rectype_len) == FAILURE) { return; } if (rectype) { if (!strcasecmp("A", rectype)) type = DNS_TYPE_A; else if (!strcasecmp("NS", rectype)) type = DNS_TYPE_NS; else if (!strcasecmp("MX", rectype)) type = DNS_TYPE_MX; else if (!strcasecmp("PTR", rectype)) type = DNS_TYPE_PTR; else if (!strcasecmp("ANY", rectype)) type = DNS_TYPE_ANY; else if (!strcasecmp("SOA", rectype)) type = DNS_TYPE_SOA; else if (!strcasecmp("TXT", rectype)) type = DNS_TYPE_TEXT; else if (!strcasecmp("CNAME", rectype)) type = DNS_TYPE_CNAME; else if (!strcasecmp("AAAA", rectype)) type = DNS_TYPE_AAAA; else if (!strcasecmp("SRV", rectype)) type = DNS_TYPE_SRV; else if (!strcasecmp("NAPTR", rectype)) type = DNS_TYPE_NAPTR; else if (!strcasecmp("A6", rectype)) type = DNS_TYPE_A6; else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type '%s' not supported", rectype); RETURN_FALSE; } } status = DnsQuery_A(hostname, DNS_TYPE_MX, DNS_QUERY_STANDARD, NULL, &pResult, NULL); if (status) { RETURN_FALSE; } RETURN_TRUE; } /* }}} */ #if 1 /* {{{ php_parserr */ static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, zval **subarray) { int type; u_long ttl; type = pRec->wType; ttl = pRec->dwTtl; if (type_to_fetch != DNS_TYPE_ANY && type != type_to_fetch) { return; } if (!store) { return; } ALLOC_INIT_ZVAL(*subarray); array_init(*subarray); add_assoc_string(*subarray, "host", pRec->pName, 1); switch (type) { case DNS_TYPE_A: { IN_ADDR ipaddr; ipaddr.S_un.S_addr = (pRec->Data.A.IpAddress); add_assoc_string(*subarray, "type", "A", 1); add_assoc_string(*subarray, "ip", inet_ntoa(ipaddr), 1); break; } case DNS_TYPE_MX: add_assoc_string(*subarray, "type", "MX", 1); add_assoc_long(*subarray, "pri", pRec->Data.Srv.wPriority); /* no break; */ case DNS_TYPE_CNAME: if (type == DNS_TYPE_CNAME) { add_assoc_string(*subarray, "type", "CNAME", 1); } /* no break; */ case DNS_TYPE_NS: if (type == DNS_TYPE_NS) { add_assoc_string(*subarray, "type", "NS", 1); } /* no break; */ case DNS_TYPE_PTR: if (type == DNS_TYPE_PTR) { add_assoc_string(*subarray, "type", "PTR", 1); } add_assoc_string(*subarray, "target", pRec->Data.MX.pNameExchange, 1); break; /* Not available on windows, the query is possible but there is no DNS_HINFO_DATA structure */ case DNS_TYPE_HINFO: case DNS_TYPE_TEXT: { int i = 0; DNS_TXT_DATA *data_txt = &pRec->Data.TXT; DWORD count = data_txt->dwStringCount; char *txt, *txt_dst; long txt_len; add_assoc_string(*subarray, "type", "TXT", 1); txt_len = 0; for (i = 0; i < count; i++) { txt_len += strlen(data_txt->pStringArray[i]) + 1; } txt = ecalloc(txt_len * 2, 1); txt_dst = txt; for (i = 0; i < count; i++) { int len = strlen(data_txt->pStringArray[i]); memcpy(txt_dst, data_txt->pStringArray[i], len); txt_dst += len; } add_assoc_string(*subarray, "txt", txt, 0); } break; case DNS_TYPE_SOA: { DNS_SOA_DATA *data_soa = &pRec->Data.Soa; add_assoc_string(*subarray, "type", "SOA", 1); add_assoc_string(*subarray, "mname", data_soa->pNamePrimaryServer, 1); add_assoc_string(*subarray, "rname", data_soa->pNameAdministrator, 1); add_assoc_long(*subarray, "serial", data_soa->dwSerialNo); add_assoc_long(*subarray, "refresh", data_soa->dwRefresh); add_assoc_long(*subarray, "retry", data_soa->dwRetry); add_assoc_long(*subarray, "expire", data_soa->dwExpire); add_assoc_long(*subarray, "minimum-ttl", data_soa->dwDefaultTtl); } break; case DNS_TYPE_AAAA: #if _WIN32_WINNT >= 0x0600 { LPSTR str[MAXHOSTNAMELEN]; DNS_AAAA_DATA *data_aaaa = &pRec->Data.AAAA; add_assoc_string(*subarray, "type", "AAAA", 1); add_assoc_string(*subarray, "ipv6", RtlIpv6AddressToString(data_aaaa->Ip6Address, str), 1); } #endif break; #if 0 /* Not supported yet */ case DNS_TYPE_A6: break; #endif case DNS_TYPE_SRV: { DNS_SRV_DATA *data_srv = &pRec->Data.Srv; add_assoc_string(*subarray, "type", "SRV", 1); add_assoc_long(*subarray, "pri", data_srv->wPriority); add_assoc_long(*subarray, "weight", data_srv->wWeight); add_assoc_long(*subarray, "port", data_srv->wPort); add_assoc_string(*subarray, "target", data_srv->pNameTarget, 1); } break; case DNS_TYPE_NAPTR: { DNS_NAPTR_DATA * data_naptr = &pRec->Data.Naptr; add_assoc_string(*subarray, "type", "NAPTR", 1); add_assoc_long(*subarray, "order", data_naptr->wOrder); add_assoc_long(*subarray, "pref", data_naptr->wPreference); add_assoc_string(*subarray, "flags", data_naptr->pFlags, 1); 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); } break; default: break; } add_assoc_string(*subarray, "class", "IN", 1); add_assoc_long(*subarray, "ttl", ttl); } /* }}} */ #endif /* {{{ proto array|false dns_get_record(string hostname [, int type[, array authns, array addtl]]) Get any Resource Record corresponding to a given Internet host name */ PHP_FUNCTION(dns_get_record) { char *hostname; int hostname_len; long type_param = PHP_DNS_ANY; zval *authns = NULL, *addtl = NULL; int type, type_to_fetch, first_query = 1, store_results = 1; int addtl_recs = 0; IN_ADDR ipaddr; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz!z!", &hostname, &hostname_len, &type_param, &authns, &addtl) == FAILURE) { return; } if (authns) { zval_dtor(authns); array_init(authns); } if (addtl) { zval_dtor(addtl); 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; } /* Initialize the return array */ array_init(return_value); for (type = (type_param == PHP_DNS_ANY ? (PHP_DNS_NUM_TYPES + 1) : 0); type < (addtl_recs ? (PHP_DNS_NUM_TYPES + 2) : PHP_DNS_NUM_TYPES) || first_query; type++ ) { DNS_STATUS status; /* Return value of DnsQuery_A() function */ PDNS_RECORD pResult, pRec; /* Pointer to DNS_RECORD structure */ first_query = 0; switch (type) { case 0: type_to_fetch = type_param&PHP_DNS_A ? DNS_TYPE_A : 0; break; case 1: type_to_fetch = type_param&PHP_DNS_NS ? DNS_TYPE_NS : 0; break; case 2: type_to_fetch = type_param&PHP_DNS_CNAME ? DNS_TYPE_CNAME : 0; break; case 3: type_to_fetch = type_param&PHP_DNS_SOA ? DNS_TYPE_SOA : 0; break; case 4: type_to_fetch = type_param&PHP_DNS_PTR ? DNS_TYPE_PTR : 0; break; case 5: type_to_fetch = type_param&PHP_DNS_HINFO ? DNS_TYPE_HINFO : 0; break; case 6: type_to_fetch = type_param&PHP_DNS_MX ? DNS_TYPE_MX : 0; break; case 7: type_to_fetch = type_param&PHP_DNS_TXT ? DNS_TYPE_TEXT : 0; break; case 8: type_to_fetch = type_param&PHP_DNS_AAAA ? DNS_TYPE_AAAA : 0; break; case 9: type_to_fetch = type_param&PHP_DNS_SRV ? DNS_TYPE_SRV : 0; break; case 10: type_to_fetch = type_param&PHP_DNS_NAPTR ? DNS_TYPE_NAPTR : 0; break; case 11: type_to_fetch = type_param&PHP_DNS_A6 ? DNS_TYPE_A6 : 0; break; case PHP_DNS_NUM_TYPES: store_results = 0; continue; default: case (PHP_DNS_NUM_TYPES + 1): type_to_fetch = DNS_TYPE_ANY; break; } if (type_to_fetch) { status = DnsQuery_A(hostname, type_to_fetch, DNS_QUERY_STANDARD, NULL, &pResult, NULL); if (status) { if (status == DNS_INFO_NO_RECORDS) { continue; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dns Query failed"); zval_dtor(return_value); RETURN_FALSE; } } for (pRec = pResult; pRec; pRec = pRec->pNext) { DNS_SRV_DATA *srv = &pRec->Data.Srv; zval *retval = NULL; if (pRec->Flags.S.Section == DnsSectionAnswer) { php_parserr(pRec, type_to_fetch, store_results, &retval); if (retval != NULL && store_results) { add_next_index_zval(return_value, retval); } } if (authns && pRec->Flags.S.Section == DnsSectionAuthority) { php_parserr(pRec, type_to_fetch, store_results, &retval); if (retval != NULL) { add_next_index_zval(authns, retval); } } /* Stupid typo in PSDK 6.1, WinDNS.h(1258)... */ #ifndef DnsSectionAdditional # ifdef DnsSectionAddtional # define DnsSectionAdditional DnsSectionAddtional # else # define DnsSectionAdditional 3 # endif #endif if (addtl && pRec->Flags.S.Section == DnsSectionAdditional) { php_parserr(pRec, type_to_fetch, store_results, &retval); if (retval != NULL) { add_next_index_zval(addtl, retval); } } } /* Free memory allocated for DNS records. */ DnsRecordListFree(pResult, DnsFreeRecordListDeep); } } } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php