- Timestamp:
- 2011/09/09 15:29:59 (13 years ago)
- Location:
- branches/version-2_11-dev
- Files:
-
- 3 added
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/class/pages/admin/LC_Page_Admin_Home.php
r20970 r21237 25 25 // {{{ requires 26 26 require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; 27 require_once DATA_REALDIR . 'module/ Request.php';27 require_once DATA_REALDIR . 'module/HTTP/Request.php'; 28 28 29 29 /** -
branches/version-2_11-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_ZipInstall.php
r20970 r21237 24 24 // {{{ requires 25 25 require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; 26 require_once DATA_REALDIR . 'module/ Request.php';26 require_once DATA_REALDIR . 'module/HTTP/Request.php'; 27 27 28 28 /** CSV ファイルの最大行数 */ … … 368 368 function lfDownloadZipFileFromJp() { 369 369 // Proxy経由を可能とする。 370 // TODO Proxyの設定は「DATA_REALDIR . 'module/ Request.php'」内の「function HTTP_Request」へ記述する。いずれは、外部設定としたい。370 // TODO Proxyの設定は「DATA_REALDIR . 'module/HTTP/Request.php'」内の「function HTTP_Request」へ記述する。いずれは、外部設定としたい。 371 371 $req = new HTTP_Request(); 372 372 -
branches/version-2_11-dev/data/class/pages/upgrade/LC_Page_Upgrade_Base.php
r20970 r21237 4 4 require_once CLASS_REALDIR . 'pages/upgrade/helper/LC_Upgrade_Helper_Log.php'; 5 5 require_once CLASS_REALDIR . 'pages/upgrade/helper/LC_Upgrade_Helper_Json.php'; 6 require_once DATA_REALDIR . 'module/ Request.php';6 require_once DATA_REALDIR . 'module/HTTP/Request.php'; 7 7 8 8 /** -
branches/version-2_11-dev/data/class/util/SC_Utils.php
r21204 r21237 1286 1286 // 指定したURLに対してPOSTでデータを送信する 1287 1287 function sfSendPostData($url, $arrData, $arrOkCode = array()){ 1288 require_once DATA_REALDIR . 'module/ Request.php';1288 require_once DATA_REALDIR . 'module/HTTP/Request.php'; 1289 1289 1290 1290 // 送信インスタンス生成 -
branches/version-2_11-dev/data/module/HTTP/Request.php
r20116 r21237 1 1 <?php 2 // +-----------------------------------------------------------------------+ 3 // | Copyright (c) 2002-2003, Richard Heyes | 4 // | All rights reserved. | 5 // | | 6 // | Redistribution and use in source and binary forms, with or without | 7 // | modification, are permitted provided that the following conditions | 8 // | are met: | 9 // | | 10 // | o Redistributions of source code must retain the above copyright | 11 // | notice, this list of conditions and the following disclaimer. | 12 // | o Redistributions in binary form must reproduce the above copyright | 13 // | notice, this list of conditions and the following disclaimer in the | 14 // | documentation and/or other materials provided with the distribution.| 15 // | o The names of the authors may not be used to endorse or promote | 16 // | products derived from this software without specific prior written | 17 // | permission. | 18 // | | 19 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 20 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 21 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 22 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 23 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 24 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 // | | 31 // +-----------------------------------------------------------------------+ 32 // | Author: Richard Heyes <richard@phpguru.org> | 33 // +-----------------------------------------------------------------------+ 34 // 35 // $Id$ 36 // 37 // HTTP_Request Class 38 // 39 // Simple example, (Fetches yahoo.com and displays it): 40 // 41 // $a = &new HTTP_Request('http://www.yahoo.com/'); 42 // $a->sendRequest(); 43 // echo $a->getResponseBody(); 44 // 45 46 if(!defined('REQUEST_PHP_DIR')) { 47 $REQUEST_PHP_DIR = realpath(dirname( __FILE__)); 48 define("REQUEST_PHP_DIR", $REQUEST_PHP_DIR); 49 } 50 51 require_once REQUEST_PHP_DIR . '/PEAR.php'; 52 require_once REQUEST_PHP_DIR . '/Net/Socket.php'; 53 require_once REQUEST_PHP_DIR . '/Net/URL.php'; 54 2 /** 3 * Class for performing HTTP requests 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: 8 * 9 * Copyright (c) 2002-2007, Richard Heyes 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * o Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * o Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * o The names of the authors may not be used to endorse or promote 22 * products derived from this software without specific prior written 23 * permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * @category HTTP 38 * @package HTTP_Request 39 * @author Richard Heyes <richard@phpguru.org> 40 * @author Alexey Borzov <avb@php.net> 41 * @copyright 2002-2007 Richard Heyes 42 * @license http://opensource.org/licenses/bsd-license.php New BSD License 43 * @version CVS: $Id$ 44 * @link http://pear.php.net/package/HTTP_Request/ 45 */ 46 47 /** 48 * PEAR and PEAR_Error classes (for error handling) 49 */ 50 require_once 'PEAR.php'; 51 /** 52 * Socket class 53 */ 54 require_once 'Net/Socket.php'; 55 /** 56 * URL handling class 57 */ 58 require_once 'Net/URL.php'; 59 60 /**#@+ 61 * Constants for HTTP request methods 62 */ 55 63 define('HTTP_REQUEST_METHOD_GET', 'GET', true); 56 64 define('HTTP_REQUEST_METHOD_HEAD', 'HEAD', true); … … 60 68 define('HTTP_REQUEST_METHOD_OPTIONS', 'OPTIONS', true); 61 69 define('HTTP_REQUEST_METHOD_TRACE', 'TRACE', true); 62 70 /**#@-*/ 71 72 /**#@+ 73 * Constants for HTTP request error codes 74 */ 75 define('HTTP_REQUEST_ERROR_FILE', 1); 76 define('HTTP_REQUEST_ERROR_URL', 2); 77 define('HTTP_REQUEST_ERROR_PROXY', 4); 78 define('HTTP_REQUEST_ERROR_REDIRECTS', 8); 79 define('HTTP_REQUEST_ERROR_RESPONSE', 16); 80 define('HTTP_REQUEST_ERROR_GZIP_METHOD', 32); 81 define('HTTP_REQUEST_ERROR_GZIP_READ', 64); 82 define('HTTP_REQUEST_ERROR_GZIP_DATA', 128); 83 define('HTTP_REQUEST_ERROR_GZIP_CRC', 256); 84 /**#@-*/ 85 86 /**#@+ 87 * Constants for HTTP protocol versions 88 */ 63 89 define('HTTP_REQUEST_HTTP_VER_1_0', '1.0', true); 64 90 define('HTTP_REQUEST_HTTP_VER_1_1', '1.1', true); 65 66 class HTTP_Request { 67 91 /**#@-*/ 92 93 if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) { 94 /** 95 * Whether string functions are overloaded by their mbstring equivalents 96 */ 97 define('HTTP_REQUEST_MBSTRING', true); 98 } else { 99 /** 100 * @ignore 101 */ 102 define('HTTP_REQUEST_MBSTRING', false); 103 } 104 105 /** 106 * Class for performing HTTP requests 107 * 108 * Simple example (fetches yahoo.com and displays it): 109 * <code> 110 * $a = &new HTTP_Request('http://www.yahoo.com/'); 111 * $a->sendRequest(); 112 * echo $a->getResponseBody(); 113 * </code> 114 * 115 * @category HTTP 116 * @package HTTP_Request 117 * @author Richard Heyes <richard@phpguru.org> 118 * @author Alexey Borzov <avb@php.net> 119 * @version Release: 1.4.4 120 */ 121 class HTTP_Request 122 { 123 /**#@+ 124 * @access private 125 */ 68 126 /** 69 127 * Instance of Net_URL 70 * @var objectNet_URL128 * @var Net_URL 71 129 */ 72 130 var $_url; … … 95 153 */ 96 154 var $_user; 97 155 98 156 /** 99 157 * Basic Auth Password … … 104 162 /** 105 163 * Socket object 106 * @var objectNet_Socket164 * @var Net_Socket 107 165 */ 108 166 var $_sock; 109 167 110 168 /** 111 169 * Proxy server … … 113 171 */ 114 172 var $_proxy_host; 115 173 116 174 /** 117 175 * Proxy port … … 119 177 */ 120 178 var $_proxy_port; 121 179 122 180 /** 123 181 * Proxy username … … 125 183 */ 126 184 var $_proxy_user; 127 185 128 186 /** 129 187 * Proxy password … … 139 197 140 198 /** 141 * Request body 199 * Request body 142 200 * @var string 143 201 */ … … 151 209 152 210 /** 153 * Files to post 211 * Methods having defined semantics for request body 212 * 213 * Content-Length header (indicating that the body follows, section 4.3 of 214 * RFC 2616) will be sent for these methods even if no body was added 215 * 216 * @var array 217 */ 218 var $_bodyRequired = array('POST', 'PUT'); 219 220 /** 221 * Files to post 154 222 * @var array 155 223 */ … … 161 229 */ 162 230 var $_timeout; 163 231 164 232 /** 165 233 * HTTP_Response object 166 * @var objectHTTP_Response234 * @var HTTP_Response 167 235 */ 168 236 var $_response; 169 237 170 238 /** 171 239 * Whether to allow redirects … … 173 241 */ 174 242 var $_allowRedirects; 175 243 176 244 /** 177 245 * Maximum redirects allowed … … 179 247 */ 180 248 var $_maxRedirects; 181 249 182 250 /** 183 251 * Current number of redirects … … 199 267 200 268 /** 201 * Whether to save response body in response object property 269 * Whether to save response body in response object property 202 270 * @var bool 203 271 */ … … 215 283 */ 216 284 var $_socketOptions = null; 285 /**#@-*/ 217 286 218 287 /** … … 273 342 274 343 // Default useragent 275 //$this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )');344 $this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )'); 276 345 277 346 // We don't do keep-alives by default … … 289 358 290 359 // Use gzip encoding if possible 291 // Avoid gzip encoding if using multibyte functions (see #1781) 292 if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib') && 293 0 == (2 & ini_get('mbstring.func_overload'))) { 294 360 if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib')) { 295 361 $this->addHeader('Accept-Encoding', 'gzip'); 296 362 } 297 363 } 298 364 299 365 /** 300 366 * Generates a Host header for HTTP/1.1 requests … … 313 379 } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) { 314 380 $host = $this->_url->host . ':' . $this->_url->port; 315 381 316 382 } else { 317 383 $host = $this->_url->host; … … 320 386 return $host; 321 387 } 322 388 323 389 /** 324 390 * Resets the object to its initial state (DEPRECATED). … … 357 423 if (empty($this->_url->path)) { 358 424 $this->_url->path = '/'; 359 } 360 } 361 362 /** 363 * Returns the current request URL 425 } 426 } 427 428 /** 429 * Returns the current request URL 364 430 * 365 431 * @return string Current request URL 366 432 * @access public 367 433 */ 368 function getUrl( $url)434 function getUrl() 369 435 { 370 436 return empty($this->_url)? '': $this->_url->getUrl(); … … 464 530 { 465 531 $this->_url->addQueryString($name, $value, $preencoded); 466 } 467 532 } 533 468 534 /** 469 535 * Sets the querystring to literally what you supply … … 494 560 } 495 561 } 496 497 function addPostDataArray($array, $preencoded = false)498 {499 foreach($array as $key => $val){500 $this->addPostData($key, $val, $preencoded);501 }502 }503 562 504 563 /** 505 564 * Recursively applies the callback function to the value 506 * 565 * 507 566 * @param mixed Callback function 508 567 * @param mixed Value to process … … 524 583 525 584 /** 526 * Adds a file to upload 527 * 528 * This also changes content-type to 'multipart/form-data' for proper upload 529 * 585 * Adds a file to form-based file upload 586 * 587 * Used to emulate file upload via a HTML form. The method also sets 588 * Content-Type of HTTP request to 'multipart/form-data'. 589 * 590 * If you just want to send the contents of a file as the body of HTTP 591 * request you should use setBody() method. 592 * 530 593 * @access public 531 594 * @param string name of file-upload field … … 538 601 { 539 602 if (!is_array($fileName) && !is_readable($fileName)) { 540 return PEAR::raiseError("File '{$fileName}' is not readable" );603 return PEAR::raiseError("File '{$fileName}' is not readable", HTTP_REQUEST_ERROR_FILE); 541 604 } elseif (is_array($fileName)) { 542 605 foreach ($fileName as $name) { 543 606 if (!is_readable($name)) { 544 return PEAR::raiseError("File '{$name}' is not readable" );607 return PEAR::raiseError("File '{$name}' is not readable", HTTP_REQUEST_ERROR_FILE); 545 608 } 546 609 } … … 579 642 580 643 /** 581 * Clears any postdata that has been added (DEPRECATED). 582 * 644 * Clears any postdata that has been added (DEPRECATED). 645 * 583 646 * Useful for multiple request scenarios. 584 647 * … … 593 656 /** 594 657 * Appends a cookie to "Cookie:" header 595 * 658 * 596 659 * @param string $name cookie name 597 660 * @param string $value cookie value … … 603 666 $this->addHeader('Cookie', $cookies . $name . '=' . $value); 604 667 } 605 606 /** 607 * Clears any cookies that have been added (DEPRECATED). 608 * 668 669 /** 670 * Clears any cookies that have been added (DEPRECATED). 671 * 609 672 * Useful for multiple request scenarios 610 673 * … … 628 691 { 629 692 if (!is_a($this->_url, 'Net_URL')) { 630 return PEAR::raiseError('No URL given .');693 return PEAR::raiseError('No URL given', HTTP_REQUEST_ERROR_URL); 631 694 } 632 695 … … 634 697 $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port; 635 698 636 // 4.3.0 supports SSL connections using OpenSSL. The function test determines 637 // we running on at least 4.3.0 638 if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) { 639 if (isset($this->_proxy_host)) { 640 return PEAR::raiseError('HTTPS proxies are not supported.'); 699 if (strcasecmp($this->_url->protocol, 'https') == 0) { 700 // Bug #14127, don't try connecting to HTTPS sites without OpenSSL 701 if (version_compare(PHP_VERSION, '4.3.0', '<') || !extension_loaded('openssl')) { 702 return PEAR::raiseError('Need PHP 4.3.0 or later with OpenSSL support for https:// requests', 703 HTTP_REQUEST_ERROR_URL); 704 } elseif (isset($this->_proxy_host)) { 705 return PEAR::raiseError('HTTPS proxies are not supported', HTTP_REQUEST_ERROR_PROXY); 641 706 } 642 707 $host = 'ssl://' . $host; … … 647 712 ini_set('magic_quotes_runtime', false); 648 713 649 // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive 714 // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive 650 715 // connection token to a proxy server... 651 716 if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) && … … 663 728 // There is a connected socket in the "static" property? 664 729 if ($keepAlive && !empty($sockets[$sockKey]) && 665 !empty($sockets[$sockKey]->fp)) 730 !empty($sockets[$sockKey]->fp)) 666 731 { 667 732 $this->_sock =& $sockets[$sockKey]; … … 722 787 AND !empty($this->_response->_headers['location'])) { 723 788 724 789 725 790 $redirect = $this->_response->_headers['location']; 726 791 … … 732 797 } elseif ($redirect{0} == '/') { 733 798 $this->_url->path = $redirect; 734 799 735 800 // Relative path 736 801 } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') { … … 742 807 $redirect = Net_URL::resolvePath($redirect); 743 808 $this->_url->path = $redirect; 744 809 745 810 // Filename, no path 746 811 } else { … … 758 823 // Too many redirects 759 824 } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) { 760 return PEAR::raiseError('Too many redirects' );825 return PEAR::raiseError('Too many redirects', HTTP_REQUEST_ERROR_REDIRECTS); 761 826 } 762 827 … … 789 854 790 855 /** 856 * Returns the response reason phrase 857 * 858 * @access public 859 * @return mixed Response reason phrase, false if not set 860 */ 861 function getResponseReason() 862 { 863 return isset($this->_response->_reason) ? $this->_response->_reason : false; 864 } 865 866 /** 791 867 * Returns either the named header or all if no name given 792 868 * … … 819 895 /** 820 896 * Returns cookies set in response 821 * 897 * 822 898 * @access public 823 899 * @return mixed array of response cookies, false if none are present … … 846 922 $url = $host . $port . $path; 847 923 924 if (!strlen($url)) { 925 $url = '/'; 926 } 927 848 928 $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n"; 849 929 850 930 if (in_array($this->_method, $this->_bodyDisallowed) || 851 ( empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method ||931 (0 == strlen($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method || 852 932 (empty($this->_postData) && empty($this->_postFiles))))) 853 933 { … … 871 951 } 872 952 873 // No post data or wrong method, so simply add a final CRLF 874 if (in_array($this->_method, $this->_bodyDisallowed) || 875 (HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_body))) { 953 // Method does not allow a body, simply add a final CRLF 954 if (in_array($this->_method, $this->_bodyDisallowed)) { 876 955 877 956 $request .= "\r\n"; 878 957 879 958 // Post data if it's an array 880 } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && 959 } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && 881 960 (!empty($this->_postData) || !empty($this->_postFiles))) { 882 961 … … 884 963 if (!isset($boundary)) { 885 964 $postdata = implode('&', array_map( 886 create_function('$a', 'return $a[0] . \'=\' . $a[1];'), 965 create_function('$a', 'return $a[0] . \'=\' . $a[1];'), 887 966 $this->_flattenArray('', $this->_postData) 888 967 )); … … 907 986 } 908 987 foreach ($value['name'] as $key => $filename) { 909 $fp = fopen($filename, 'r'); 910 $data = fread($fp, filesize($filename)); 911 fclose($fp); 988 $fp = fopen($filename, 'r'); 912 989 $basename = basename($filename); 913 990 $type = is_array($value['type'])? @$value['type'][$key]: $value['type']; … … 916 993 $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"'; 917 994 $postdata .= "\r\nContent-Type: " . $type; 918 $postdata .= "\r\n\r\n" . $data . "\r\n"; 995 $postdata .= "\r\n\r\n" . fread($fp, filesize($filename)) . "\r\n"; 996 fclose($fp); 919 997 } 920 998 } 921 999 $postdata .= '--' . $boundary . "--\r\n"; 922 1000 } 923 $request .= 'Content-Length: ' . strlen($postdata) . "\r\n\r\n"; 1001 $request .= 'Content-Length: ' . 1002 (HTTP_REQUEST_MBSTRING? mb_strlen($postdata, 'iso-8859-1'): strlen($postdata)) . 1003 "\r\n\r\n"; 924 1004 $request .= $postdata; 925 1005 926 1006 // Explicitly set request body 927 } elseif (!empty($this->_body)) { 928 929 $request .= 'Content-Length: ' . strlen($this->_body) . "\r\n\r\n"; 1007 } elseif (0 < strlen($this->_body)) { 1008 1009 $request .= 'Content-Length: ' . 1010 (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) . 1011 "\r\n\r\n"; 930 1012 $request .= $this->_body; 931 } 932 1013 1014 // No body: send a Content-Length header nonetheless (request #12900), 1015 // but do that only for methods that require a body (bug #14740) 1016 } else { 1017 1018 if (in_array($this->_method, $this->_bodyRequired)) { 1019 $request .= "Content-Length: 0\r\n"; 1020 } 1021 $request .= "\r\n"; 1022 } 1023 933 1024 return $request; 934 1025 } … … 941 1032 * @param mixed item's values 942 1033 * @return array array with the following items: array('item name', 'item value'); 1034 * @access private 943 1035 */ 944 1036 function _flattenArray($name, $values) … … 966 1058 * Adds a Listener to the list of listeners that are notified of 967 1059 * the object's events 968 * 969 * @param object HTTP_Request_Listener instance to attach 970 * @return boolean whether the listener was successfully attached 971 * @access public 972 */ 973 function attach(&$listener) 974 { 975 if (!is_a($listener, 'HTTP_Request_Listener')) { 976 return false; 977 } 978 $this->_listeners[$listener->getId()] =& $listener; 979 return true; 980 } 981 982 983 /** 984 * Removes a Listener from the list of listeners 985 * 986 * @param object HTTP_Request_Listener instance to detach 987 * @return boolean whether the listener was successfully detached 988 * @access public 989 */ 990 function detach(&$listener) 991 { 992 if (!is_a($listener, 'HTTP_Request_Listener') || 993 !isset($this->_listeners[$listener->getId()])) { 994 return false; 995 } 996 unset($this->_listeners[$listener->getId()]); 997 return true; 998 } 999 1000 1001 /** 1002 * Notifies all registered listeners of an event. 1003 * 1060 * 1004 1061 * Events sent by HTTP_Request object 1005 1062 * - 'connect': on connection to server 1006 1063 * - 'sentRequest': after the request was sent 1007 1064 * - 'disconnect': on disconnection from server 1008 * 1065 * 1009 1066 * Events sent by HTTP_Response object 1010 1067 * - 'gotHeaders': after receiving response headers (headers are passed in $data) … … 1012 1069 * - 'gzTick': on receiving a gzip-encoded part of response body (ditto) 1013 1070 * - 'gotBody': after receiving the response body (passes the decoded body in $data if it was gzipped) 1014 * 1071 * 1072 * @param HTTP_Request_Listener listener to attach 1073 * @return boolean whether the listener was successfully attached 1074 * @access public 1075 */ 1076 function attach(&$listener) 1077 { 1078 if (!is_a($listener, 'HTTP_Request_Listener')) { 1079 return false; 1080 } 1081 $this->_listeners[$listener->getId()] =& $listener; 1082 return true; 1083 } 1084 1085 1086 /** 1087 * Removes a Listener from the list of listeners 1088 * 1089 * @param HTTP_Request_Listener listener to detach 1090 * @return boolean whether the listener was successfully detached 1091 * @access public 1092 */ 1093 function detach(&$listener) 1094 { 1095 if (!is_a($listener, 'HTTP_Request_Listener') || 1096 !isset($this->_listeners[$listener->getId()])) { 1097 return false; 1098 } 1099 unset($this->_listeners[$listener->getId()]); 1100 return true; 1101 } 1102 1103 1104 /** 1105 * Notifies all registered listeners of an event. 1106 * 1015 1107 * @param string Event name 1016 1108 * @param mixed Additional data 1017 1109 * @access private 1110 * @see HTTP_Request::attach() 1018 1111 */ 1019 1112 function _notify($event, $data = null) … … 1027 1120 1028 1121 /** 1029 * Response class to complement the Request class 1030 */ 1122 * Response class to complement the Request class 1123 * 1124 * @category HTTP 1125 * @package HTTP_Request 1126 * @author Richard Heyes <richard@phpguru.org> 1127 * @author Alexey Borzov <avb@php.net> 1128 * @version Release: 1.4.4 1129 */ 1031 1130 class HTTP_Response 1032 1131 { 1033 1132 /** 1034 1133 * Socket object 1035 * @var object1134 * @var Net_Socket 1036 1135 */ 1037 1136 var $_sock; … … 1042 1141 */ 1043 1142 var $_protocol; 1044 1143 1045 1144 /** 1046 1145 * Return code … … 1048 1147 */ 1049 1148 var $_code; 1050 1149 1150 /** 1151 * Response reason phrase 1152 * @var string 1153 */ 1154 var $_reason; 1155 1051 1156 /** 1052 1157 * Response headers … … 1056 1161 1057 1162 /** 1058 * Cookies set in response 1163 * Cookies set in response 1059 1164 * @var array 1060 1165 */ … … 1088 1193 * Constructor 1089 1194 * 1090 * @param object Net_Socket socket to read the response from 1091 * @param array listeners attached to request 1092 * @return mixed PEAR Error on error, true otherwise 1195 * @param Net_Socket socket to read the response from 1196 * @param array listeners attached to request 1093 1197 */ 1094 1198 function HTTP_Response(&$sock, &$listeners) … … 1101 1205 /** 1102 1206 * Processes a HTTP response 1103 * 1104 * This extracts response code, headers, cookies and decodes body if it 1207 * 1208 * This extracts response code, headers, cookies and decodes body if it 1105 1209 * was encoded in some way 1106 1210 * … … 1118 1222 do { 1119 1223 $line = $this->_sock->readLine(); 1120 if ( sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) {1121 return PEAR::raiseError('Malformed response .');1224 if (!preg_match('!^(HTTP/\d\.\d) (\d{3})(?: (.+))?!', $line, $s)) { 1225 return PEAR::raiseError('Malformed response', HTTP_REQUEST_ERROR_RESPONSE); 1122 1226 } else { 1123 $this->_protocol = 'HTTP/' . $http_version; 1124 $this->_code = intval($returncode); 1227 $this->_protocol = $s[1]; 1228 $this->_code = intval($s[2]); 1229 $this->_reason = empty($s[3])? null: $s[3]; 1125 1230 } 1126 1231 while ('' !== ($header = $this->_sock->readLine())) { … … 1132 1237 1133 1238 // RFC 2616, section 4.4: 1134 // 1. Any response message which "MUST NOT" include a message-body ... 1135 // is always terminated by the first empty line after the header fields 1239 // 1. Any response message which "MUST NOT" include a message-body ... 1240 // is always terminated by the first empty line after the header fields 1136 1241 // 3. ... If a message is received with both a 1137 1242 // Transfer-Encoding header field and a Content-Length header field, 1138 1243 // the latter MUST be ignored. 1139 $canHaveBody = $canHaveBody && $this->_code >= 200 && 1244 $canHaveBody = $canHaveBody && $this->_code >= 200 && 1140 1245 $this->_code != 204 && $this->_code != 304; 1141 1246 … … 1144 1249 $gzipped = isset($this->_headers['content-encoding']) && ('gzip' == $this->_headers['content-encoding']); 1145 1250 $hasBody = false; 1146 if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || 1251 if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || 1147 1252 0 != $this->_headers['content-length'])) 1148 1253 { … … 1159 1264 } else { 1160 1265 $data = $this->_sock->read(min(4096, $this->_toRead)); 1161 $this->_toRead -= strlen($data);1266 $this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); 1162 1267 } 1163 if ('' == $data ) {1268 if ('' == $data && (!$this->_chunkLength || $this->_sock->eof())) { 1164 1269 break; 1165 1270 } else { … … 1204 1309 $headername = strtolower($headername); 1205 1310 $headervalue = ltrim($headervalue); 1206 1311 1207 1312 if ('set-cookie' != $headername) { 1208 1313 if (isset($this->_headers[$headername])) { … … 1270 1375 /** 1271 1376 * Read a part of response body encoded with chunked Transfer-Encoding 1272 * 1377 * 1273 1378 * @access private 1274 1379 * @return string … … 1280 1385 $line = $this->_sock->readLine(); 1281 1386 if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) { 1282 $this->_chunkLength = hexdec($matches[1]); 1387 $this->_chunkLength = hexdec($matches[1]); 1283 1388 // Chunk with zero length indicates the end 1284 1389 if (0 == $this->_chunkLength) { … … 1291 1396 } 1292 1397 $data = $this->_sock->read($this->_chunkLength); 1293 $this->_chunkLength -= strlen($data);1398 $this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data); 1294 1399 if (0 == $this->_chunkLength) { 1295 1400 $this->_sock->readLine(); // Trailing CRLF … … 1301 1406 /** 1302 1407 * Notifies all registered listeners of an event. 1303 * 1408 * 1304 1409 * @param string Event name 1305 1410 * @param mixed Additional data … … 1320 1425 * The real decoding work is done by gzinflate() built-in function, this 1321 1426 * method only parses the header and checks data for compliance with 1322 * RFC 1952 1427 * RFC 1952 1323 1428 * 1324 1429 * @access private … … 1328 1433 function _decodeGzip($data) 1329 1434 { 1435 if (HTTP_REQUEST_MBSTRING) { 1436 $oldEncoding = mb_internal_encoding(); 1437 mb_internal_encoding('iso-8859-1'); 1438 } 1330 1439 $length = strlen($data); 1331 1440 // If it doesn't look like gzip-encoded data, don't bother … … 1335 1444 $method = ord(substr($data, 2, 1)); 1336 1445 if (8 != $method) { 1337 return PEAR::raiseError('_decodeGzip(): unknown compression method' );1446 return PEAR::raiseError('_decodeGzip(): unknown compression method', HTTP_REQUEST_ERROR_GZIP_METHOD); 1338 1447 } 1339 1448 $flags = ord(substr($data, 3, 1)); 1340 1449 if ($flags & 224) { 1341 return PEAR::raiseError('_decodeGzip(): reserved bits are set' );1450 return PEAR::raiseError('_decodeGzip(): reserved bits are set', HTTP_REQUEST_ERROR_GZIP_DATA); 1342 1451 } 1343 1452 … … 1347 1456 if ($flags & 4) { 1348 1457 if ($length - $headerLength - 2 < 8) { 1349 return PEAR::raiseError('_decodeGzip(): data too short' );1458 return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); 1350 1459 } 1351 1460 $extraLength = unpack('v', substr($data, 10, 2)); 1352 1461 if ($length - $headerLength - 2 - $extraLength[1] < 8) { 1353 return PEAR::raiseError('_decodeGzip(): data too short' );1462 return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); 1354 1463 } 1355 1464 $headerLength += $extraLength[1] + 2; … … 1358 1467 if ($flags & 8) { 1359 1468 if ($length - $headerLength - 1 < 8) { 1360 return PEAR::raiseError('_decodeGzip(): data too short' );1469 return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); 1361 1470 } 1362 1471 $filenameLength = strpos(substr($data, $headerLength), chr(0)); 1363 1472 if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) { 1364 return PEAR::raiseError('_decodeGzip(): data too short' );1473 return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); 1365 1474 } 1366 1475 $headerLength += $filenameLength + 1; … … 1369 1478 if ($flags & 16) { 1370 1479 if ($length - $headerLength - 1 < 8) { 1371 return PEAR::raiseError('_decodeGzip(): data too short' );1480 return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); 1372 1481 } 1373 1482 $commentLength = strpos(substr($data, $headerLength), chr(0)); 1374 1483 if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) { 1375 return PEAR::raiseError('_decodeGzip(): data too short' );1484 return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); 1376 1485 } 1377 1486 $headerLength += $commentLength + 1; … … 1380 1489 if ($flags & 1) { 1381 1490 if ($length - $headerLength - 2 < 8) { 1382 return PEAR::raiseError('_decodeGzip(): data too short' );1491 return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); 1383 1492 } 1384 1493 $crcReal = 0xffff & crc32(substr($data, 0, $headerLength)); 1385 1494 $crcStored = unpack('v', substr($data, $headerLength, 2)); 1386 1495 if ($crcReal != $crcStored[1]) { 1387 return PEAR::raiseError('_decodeGzip(): header CRC check failed' );1496 return PEAR::raiseError('_decodeGzip(): header CRC check failed', HTTP_REQUEST_ERROR_GZIP_CRC); 1388 1497 } 1389 1498 $headerLength += 2; … … 1395 1504 1396 1505 // finally, call the gzinflate() function 1397 $unpacked = @gzinflate(substr($data, $headerLength, -8), $dataSize); 1506 // don't pass $dataSize to gzinflate, see bugs #13135, #14370 1507 $unpacked = gzinflate(substr($data, $headerLength, -8)); 1398 1508 if (false === $unpacked) { 1399 return PEAR::raiseError('_decodeGzip(): gzinflate() call failed' );1509 return PEAR::raiseError('_decodeGzip(): gzinflate() call failed', HTTP_REQUEST_ERROR_GZIP_READ); 1400 1510 } elseif ($dataSize != strlen($unpacked)) { 1401 return PEAR::raiseError('_decodeGzip(): data size check failed'); 1402 } elseif ($dataCrc != crc32($unpacked)) { 1403 return PEAR::raiseError('_decodeGzip(): data CRC check failed'); 1511 return PEAR::raiseError('_decodeGzip(): data size check failed', HTTP_REQUEST_ERROR_GZIP_READ); 1512 } elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) { 1513 return PEAR::raiseError('_decodeGzip(): data CRC check failed', HTTP_REQUEST_ERROR_GZIP_CRC); 1514 } 1515 if (HTTP_REQUEST_MBSTRING) { 1516 mb_internal_encoding($oldEncoding); 1404 1517 } 1405 1518 return $unpacked; -
branches/version-2_11-dev/data/module/Net/URL.php
r20116 r21237 37 37 // Net_URL Class 38 38 39 39 40 class Net_URL 40 41 { 42 var $options = array('encode_query_keys' => false); 41 43 /** 42 44 * Full url … … 122 124 function __construct($url = null, $useBrackets = true) 123 125 { 126 $this->url = $url; 127 $this->useBrackets = $useBrackets; 128 129 $this->initialize(); 130 } 131 132 function initialize() 133 { 124 134 $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS']; 125 135 126 $this->useBrackets = $useBrackets;127 $this->url = $url;128 136 $this->user = ''; 129 137 $this->pass = ''; … … 135 143 136 144 // Only use defaults if not an absolute URL given 137 if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) { 138 139 $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http'); 145 if (!preg_match('/^[a-z0-9]+:\/\//i', $this->url)) { 146 $this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http'); 140 147 141 148 /** 142 149 * Figure out host/port 143 150 */ 144 if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) { 151 if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) && 152 preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) 153 { 145 154 $host = $matches[1]; 146 155 if (!empty($matches[3])) { … … 161 170 162 171 // Parse the url and store the various parts 163 if (!empty($ url)) {164 $urlinfo = parse_url($ url);172 if (!empty($this->url)) { 173 $urlinfo = parse_url($this->url); 165 174 166 175 // Default querystring … … 201 210 } 202 211 } 203 204 212 /** 205 213 * Returns full url … … 224 232 225 233 /** 226 * Adds a querystring item 234 * Adds or updates a querystring item (URL parameter). 235 * Automatically encodes parameters with rawurlencode() if $preencoded 236 * is false. 237 * You can pass an array to $value, it gets mapped via [] in the URL if 238 * $this->useBrackets is activated. 227 239 * 228 240 * @param string $name Name of item … … 233 245 function addQueryString($name, $value, $preencoded = false) 234 246 { 247 if ($this->getOption('encode_query_keys')) { 248 $name = rawurlencode($name); 249 } 250 235 251 if ($preencoded) { 236 252 $this->querystring[$name] = $value; … … 248 264 function removeQueryString($name) 249 265 { 266 if ($this->getOption('encode_query_keys')) { 267 $name = rawurlencode($name); 268 } 269 250 270 if (isset($this->querystring[$name])) { 251 271 unset($this->querystring[$name]); … … 274 294 if (!empty($this->querystring)) { 275 295 foreach ($this->querystring as $name => $value) { 296 // Encode var name 297 $name = rawurlencode($name); 298 276 299 if (is_array($value)) { 277 300 foreach ($value as $k => $v) { … … 312 335 $key = $part; 313 336 } 314 if (substr($key, -2) == '[]') { 315 $key = substr($key, 0, -2); 316 if (@!is_array($return[$key])) { 317 $return[$key] = array(); 337 338 if (!$this->getOption('encode_query_keys')) { 339 $key = rawurldecode($key); 340 } 341 342 if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) { 343 $key = $matches[1]; 344 $idx = $matches[2]; 345 346 // Ensure is an array 347 if (empty($return[$key]) || !is_array($return[$key])) { 348 $return[$key] = array(); 349 } 350 351 // Add data 352 if ($idx === '') { 318 353 $return[$key][] = $value; 319 354 } else { 320 $return[$key][ ] = $value;355 $return[$key][$idx] = $value; 321 356 } 322 357 } elseif (!$this->useBrackets AND !empty($return[$key])) { … … 341 376 * This method can also be called statically. 342 377 * 343 * @param string $ urlURL path to resolve378 * @param string $path URL path to resolve 344 379 * @return string The result 345 380 */ … … 404 439 { 405 440 $this->protocol = $protocol; 406 $this->port = is_null($port) ? $this->getStandardPort() : $port; 441 $this->port = is_null($port) ? $this->getStandardPort($protocol) : $port; 442 } 443 444 /** 445 * Set an option 446 * 447 * This function set an option 448 * to be used thorough the script. 449 * 450 * @access public 451 * @param string $optionName The optionname to set 452 * @param string $value The value of this option. 453 */ 454 function setOption($optionName, $value) 455 { 456 if (!array_key_exists($optionName, $this->options)) { 457 return false; 458 } 459 460 $this->options[$optionName] = $value; 461 $this->initialize(); 462 } 463 464 /** 465 * Get an option 466 * 467 * This function gets an option 468 * from the $this->options array 469 * and return it's value. 470 * 471 * @access public 472 * @param string $opionName The name of the option to retrieve 473 * @see $this->options 474 */ 475 function getOption($optionName) 476 { 477 if (!isset($this->options[$optionName])) { 478 return false; 479 } 480 481 return $this->options[$optionName]; 407 482 } 408 483 -
branches/version-2_11-dev/html/install/index.php
r21185 r21237 32 32 33 33 $ownDir = realpath(dirname(__FILE__)) . '/'; 34 require_once DATA_REALDIR . 'module/ Request.php';34 require_once DATA_REALDIR . 'module/HTTP/Request.php'; 35 35 36 36 if(!defined("ADMIN_DIR")){
Note: See TracChangeset
for help on using the changeset viewer.