]> granicus.if.org Git - php/commitdiff
Deal with moving to res_nsearch(). dns_search() on OSX lacks an error handler, might...
authorScott MacVicar <scottmac@php.net>
Thu, 6 Aug 2009 04:37:07 +0000 (04:37 +0000)
committerScott MacVicar <scottmac@php.net>
Thu, 6 Aug 2009 04:37:07 +0000 (04:37 +0000)
ext/standard/dns.c
ext/standard/php_dns.h

index 64f5e466bedf7d4edace80f1c1c91b943bfcdf64..08d2ae7970e0b8b7f237f78a7f66ccb29b6bb6d4 100644 (file)
@@ -809,10 +809,14 @@ PHP_FUNCTION(dns_get_record)
 
                        n = php_dns_search(handle, hostname, C_IN, type_to_fetch, answer.qb2, sizeof answer);
 
-                       if (n < 0 ) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "res_nsearch() failed");
-                               zval_dtor(return_value);
+                       if (n < 0) {
+                               if (php_dns_errno(handle) == NO_DATA) {
+                                       php_dns_free_handle(handle);
+                                       continue;
+                               }
+
                                php_dns_free_handle(handle);
+                               zval_dtor(return_value);
                                RETURN_FALSE;
                        }
 
@@ -845,33 +849,33 @@ PHP_FUNCTION(dns_get_record)
                                        add_next_index_zval(return_value, retval);
                                }
                        }
-                       php_dns_free_handle(handle);
-               }
-       }
 
-       if (authns || addtl) {
-               /* List of Authoritative Name Servers
-                * Process when only requesting addtl so that we can skip through the section
-                */
-               while (ns-- > 0 && cp && cp < end) {
-                       zval *retval = NULL;
+                       if (authns || addtl) {
+                               /* List of Authoritative Name Servers
+                                * Process when only requesting addtl so that we can skip through the section
+                                */
+                               while (ns-- > 0 && cp && cp < end) {
+                                       zval *retval = NULL;
 
-                       cp = php_parserr(cp, &answer, DNS_T_ANY, authns != NULL, &retval TSRMLS_CC);
-                       if (retval != NULL) {
-                               add_next_index_zval(authns, retval);
+                                       cp = php_parserr(cp, &answer, DNS_T_ANY, authns != NULL, &retval TSRMLS_CC);
+                                       if (retval != NULL) {
+                                               add_next_index_zval(authns, retval);
+                                       }
+                               }
                        }
-               }
-       }
 
-       if (addtl) {
-               /* Additional records associated with authoritative name servers */
-               while (ar-- > 0 && cp && cp < end) {
-                       zval *retval = NULL;
+                       if (addtl) {
+                               /* Additional records associated with authoritative name servers */
+                               while (ar-- > 0 && cp && cp < end) {
+                                       zval *retval = NULL;
 
-                       cp = php_parserr(cp, &answer, DNS_T_ANY, 1, &retval TSRMLS_CC);
-                       if (retval != NULL) {
-                               add_next_index_zval(addtl, retval);
+                                       cp = php_parserr(cp, &answer, DNS_T_ANY, 1, &retval TSRMLS_CC);
+                                       if (retval != NULL) {
+                                               add_next_index_zval(addtl, retval);
+                                       }
+                               }
                        }
+                       php_dns_free_handle(handle);
                }
        }
 }
index c9a057aaceee9adc65c221f72d62e122befda2d7..7e80004071263e1b6fc627b3ea699ce7afab6989 100644 (file)
                ((int)dns_search(res, dname, class, type, answer, anslen, (struct sockaddr *)&from, &fromsize))
 #define php_dns_free_handle(res) \
                        dns_free(res)
+#define php_dns_errno(_res) \
+                       (NO_DATA)
 
 #elif defined(HAVE_RES_NSEARCH)
 #define php_dns_search(res, dname, class, type, answer, anslen) \
                        res_nsearch(res, dname, class, type, answer, anslen)
-#define php_dns_free_handle(res) \ 
-                       res_nclose(res)
+#define php_dns_free_handle(res) \
+                       res_nclose(res); \
+                       php_dns_free_res(*res)
+
+#define php_dns_errno(res) \
+                       (res->res_h_errno)
 
 #elif defined(HAVE_RES_SEARCH)
 #define php_dns_search(res, dname, class, type, answer, anslen) \
                        res_search(dname, class, type, answer, anslen)
 #define php_dns_free_handle(res) /* noop */
+#define php_dns_errno(res) \
+                       (_res.res_h_errno)
 
 #endif