Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:20327 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63994 invoked by uid 1010); 25 Nov 2005 04:07:23 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 63979 invoked from network); 25 Nov 2005 04:07:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Nov 2005 04:07:22 -0000 X-Host-Fingerprint: 212.30.222.207 adsl6-207.simnet.is Received: from ([212.30.222.207:22121] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 5F/71-11378-AFD86834 for ; Thu, 24 Nov 2005 23:07:22 -0500 Message-ID: <5F.71.11378.AFD86834@pb1.pair.com> To: internals@lists.php.net Date: Fri, 25 Nov 2005 04:07:20 +0000 User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050307040003010801040507" X-Posted-By: 212.30.222.207 Subject: get_headers patch From: arnar@8.is (=?ISO-8859-1?Q?Arnar_Mar_Sigur=F0sson?=) --------------050307040003010801040507 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This is a update of the get_headers patch i sent in a long time ago and was ignored. Patch is written with the latest cvs snapshot of 5.1. Hope it makes it way to 5.1.1 Info: mixed get_headers ( string url [, bool format | string header [,resource context]]) 2nd arg can eather be bool or string bool: true returns an numeric indexed array with headers false returns key index array with header name as key string: returns only the header with the same name. passing long will cast E_STRICT but still work the old way 3nd arg is a context to pass header/data to the url. --------------050307040003010801040507 Content-Type: text/plain; name="get_headers.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="get_headers.patch" Index: ext/standard/url.c =================================================================== RCS file: /repository/php-src/ext/standard/url.c,v retrieving revision 1.86.2.1 diff -u -r1.86.2.1 url.c --- ext/standard/url.c 16 Aug 2005 14:20:41 -0000 1.86.2.1 +++ ext/standard/url.c 25 Nov 2005 03:47:30 -0000 @@ -36,6 +36,8 @@ #endif /*APACHE*/ #endif /*_OSD_POSIX*/ +#include "ext/standard/file.h" + /* {{{ free_url */ PHPAPI void php_url_free(php_url *theurl) @@ -624,15 +626,51 @@ { char *url; int url_len; + zval *zcontext = NULL; + zval *format = NULL; php_stream_context *context = NULL; php_stream *stream; zval **prev_val, **hdr = NULL; HashPosition pos; - long format = 0; + char *header = NULL; + int header_len; + int retformat = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &url_len, &format) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zr", &url, &url_len, &format, &zcontext) == FAILURE) { return; } + if (zcontext) { + context = php_stream_context_from_zval(zcontext, 1); + } + if (format) { + switch (Z_TYPE_P(format)) { + case IS_BOOL: + if (Z_LVAL_P(format)) { + retformat = 1; + } + break; + + case IS_STRING: + header = Z_STRVAL_P(format); + header_len = Z_STRLEN_P(format); + break; + + case IS_NULL: + // Use default + break; + + case IS_LONG: + retformat = Z_LVAL_P(format); + php_error_docref(NULL TSRMLS_CC, E_STRICT, "Using long for 2nd parameter is deprecated"); + break; + + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The 2nd parameter should be either a string or bool"); + break; + } + } + + if (!(stream = php_stream_open_wrapper_ex(url, "r", REPORT_ERRORS | STREAM_USE_URL | STREAM_ONLY_GET_HEADERS, NULL, context))) { RETURN_FALSE; @@ -642,7 +680,7 @@ zend_hash_internal_pointer_reset_ex(HASH_OF(stream->wrapperdata), &pos); while (zend_hash_get_current_data_ex(HASH_OF(stream->wrapperdata), (void**)&hdr, &pos) != FAILURE) { - if (!format) { + if (!retformat && header == NULL) { no_name_header: add_next_index_stringl(return_value, Z_STRVAL_PP(hdr), Z_STRLEN_PP(hdr), 1); } else { @@ -656,13 +694,19 @@ while (isspace((int)*(unsigned char *)s)) { s++; } - - if (zend_hash_find(HASH_OF(return_value), Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), (void **) &prev_val) == FAILURE) { - add_assoc_stringl_ex(return_value, Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1); - } else { /* some headers may occur more then once, therefor we need to remake the string into an array */ - convert_to_array(*prev_val); - add_next_index_stringl(*prev_val, s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1); - } + if (header == NULL) { + if (zend_hash_find(HASH_OF(return_value), Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), (void **) &prev_val) == FAILURE) { + add_assoc_stringl_ex(return_value, Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1); + } else { /* some headers may occur more then once, therefor we need to remake the string into an array */ + convert_to_array(*prev_val); + add_next_index_stringl(*prev_val, s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1); + } + } else { + if (!strncmp(header, Z_STRVAL_PP(hdr), header_len)) { + RETVAL_STRING(s,1); + goto done; + } + } *p = c; } else { @@ -671,7 +715,11 @@ } zend_hash_move_forward_ex(HASH_OF(stream->wrapperdata), &pos); } + if (header != NULL) { + RETVAL_FALSE; + } +done: php_stream_close(stream); } /* }}} */ --------------050307040003010801040507--