├── tests ├── return ├── php_curlTest.php └── Cert.pem ├── .gitignore ├── codecov.yml ├── .github └── FUNDING.yml ├── bootstrap.php ├── phpunit.xml.dist ├── .travis.yml ├── composer.json ├── README.md ├── src └── curl.php └── LICENSE /tests/return: -------------------------------------------------------------------------------- 1 | Hello world 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /composer.lock 2 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | # https://docs.codecov.io/docs/ignoring-paths 2 | ignore: 3 | - "tests" 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [yakeing] 2 | custom: ['https://github.com/yakeing/Documentation/blob/main/Sponsor/README.md'] 3 | -------------------------------------------------------------------------------- /bootstrap.php: -------------------------------------------------------------------------------- 1 | add('php_curl', __DIR__ . '/src'); 4 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./tests 6 | 7 | 8 | 9 | 10 | ./src 11 | 12 | ./vendor 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | dist: trusty 3 | sudo: false 4 | php: 5 | - 5.6 6 | - 7.0 7 | - 7.1 8 | #- 7.2 9 | - 7.3 10 | 11 | matrix: 12 | fast_finish: true 13 | 14 | before_install: 15 | #- phpenv config-rm xdebug.ini 16 | - travis_retry composer self-update && composer install --no-interaction --prefer-source --dev 17 | - tar -zcf /tmp/Core.tar.gz src 18 | 19 | script: 20 | - phpunit --stderr 21 | 22 | after_success: 23 | - bash <(curl -s https://codecov.io/bash) 24 | - cat coverage.xml 25 | 26 | deploy: 27 | provider: releases 28 | api_key: 29 | secure: ${GITHUB_TOKEN} 30 | file_glob: true 31 | file: /tmp/Core.tar.gz 32 | skip_cleanup: true 33 | on: 34 | tags: true 35 | 36 | branches: 37 | except: 38 | - /^untagged/ 39 | 40 | after_script: 41 | - pwd 42 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yakeing/php_curl", 3 | "description": "php curl class", 4 | "keywords": ["post", "CURL", "http", "get"], 5 | "homepage": "https://github.com/yakeing/php_curl", 6 | "type": "symfony-bundle", 7 | "license": "MPL-2.0", 8 | "authors": [ 9 | { 10 | "name": "yakeing", 11 | "homepage": "http://weibo.com/yakeing" 12 | } 13 | ], 14 | "autoload": { 15 | "psr-4": { 16 | "php_curl\\": "src/" 17 | } 18 | }, 19 | "require": { 20 | "php": ">=5.6", 21 | "ext-curl": "*" 22 | }, 23 | "require-dev": { 24 | "phpunit/phpunit": "5.7" 25 | }, 26 | "extra":{ 27 | "branch-alias":{ 28 | "dev-master": "2.x-dev" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/php_curlTest.php: -------------------------------------------------------------------------------- 1 | 10, 12 | 'CookieSet' => '_gat=1;', 13 | 'Referer' => 'https://github.com/', 14 | 'Encoding' => 'gzip', 15 | 'UserAgent' => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36' 16 | ); 17 | $this->assertTrue($curl->GET($url, $Par)); 18 | $this->assertEquals(200, $curl->StatusCode); 19 | $this->assertEquals('Hello world', trim($curl->Body)); 20 | return array($curl, $Par); 21 | } 22 | 23 | /** 24 | * @depends testGet 25 | */ 26 | public function testHeaderCallback(array $args){ 27 | list($curl, $Par) = $args; 28 | $url = "https://raw.githubusercontent.com/yakeing/php_curl/master/tests/return"; 29 | $this->assertTrue($curl->HEAD($url, $Par)); 30 | return array($curl, $Par); 31 | } 32 | /** 33 | * @depends testHeaderCallback 34 | */ 35 | public function testPost(array $args){ 36 | list($curl, $Par) = $args; 37 | $url = "https://api.github.com/_private/browser/errors"; 38 | $Header = array('Expect:', 'Content-Type: application/json; charset=utf-8'); 39 | $Vars = '{"bucket":"github-js-reports","error":{"columnNumber":null,"fileName":null,"lineNumber":null,"message":"ReportingObserverError","stack":"Error: ReportingObserverError"},"url":"https://github.com/about"}'; 40 | $Par['CurlOpt'] = array(CURLOPT_FRESH_CONNECT => true); 41 | $Par['CookieSet'] = array('_gat'=>1); 42 | $Par['LocationQuantity'] = 2; //(HTTP 301/302) 43 | $Par['Certificate'] = dirname(__FILE__).'/Cert.pem'; 44 | $this->assertTrue($curl->POST($url, $Vars, $Par, $Header)); 45 | $this->assertEquals(200, $curl->StatusCode); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Curl 2 | 3 | Curl is an open source file transfer tool that uses URL syntax to work on the command line, where the basic functions of curl are encapsulated, such as COOKIES / encrypted transport / HTTP authentication / analog forms / upload files, etc. 4 | 5 | ### Travis CI badge 6 | 7 | [![Travis-ci](https://api.travis-ci.com/yakeing/php_curl.svg?branch=main)](https://travis-ci.com/yakeing/php_curl) 8 | 9 | ### codecov badge 10 | 11 | [![codecov](https://codecov.io/gh/yakeing/php_curl/branch/main/graph/badge.svg)](https://codecov.io/gh/yakeing/php_curl) 12 | 13 | ### Github badge 14 | 15 | [![Downloads](https://4.vercel.app/github/downloads/yakeing/php_curl?icon=github)](../../) 16 | [![Size](https://4.vercel.app/github/size/yakeing/php_curl?icon=github)](src) 17 | [![tag](https://4.vercel.app/github/tag/yakeing/php_curl?icon=github)](../../releases) 18 | [![license](https://4.vercel.app/static/license/555/MPL-2.0/fe7d37?icon=github)](LICENSE) 19 | [![languages](https://4.vercel.app/static/language/555/PHP/34abef?icon=github)](../../search?l=php) 20 | 21 | ### Installation 22 | 23 | Use [Composer](https://getcomposer.org) to install the library. 24 | Of course, You can go to [Packagist](https://packagist.org/packages/yakeing/php_curl) to view. 25 | 26 | ``` 27 | 28 |    $ composer require yakeing/php_curl 29 | 30 | ``` 31 | 32 | ### init 33 | 34 | - [x] example 35 | ```php 36 | $Curl = new curl(); 37 | $curl->Encoding = 'gzip'; 38 | $Curl->Timeout = 10; 39 | ``` 40 | 41 | ### GET 42 | 43 | - [x] example 44 | ```php 45 | $Url = 'https://github.com/yakeing'; 46 | $Header = array( 47 | 'User-Agent: Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.28' 48 | ); 49 | $Curl->Get($Url, $Header); 50 | ``` 51 | 52 | ### POST 53 | 54 | - [x] example 55 | ```php 56 | $Url = 'https://github.com/yakeing'; 57 | $Vars = array( 58 | 'user'=>'admin', 59 | 'upload'=>new CURLFile(realpath('image.jpg')) //php 5.5 Edition 60 | ); 61 | $curl->UserAgent = 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.28'; 62 | $Curl->Post($Url, $Vars, $Header); 63 | ``` 64 | 65 | [Sponsor](https://github.com/yakeing/Documentation/blob/master/Sponsor/README.md) 66 | --- 67 | 68 | If you've got value from any of the content which I have created, then I would very much appreciate your support by payment donate. 69 | 70 | [![Sponsor](https://4.vercel.app/static/Sponsor/EA4AAA?icon=heart)](https://github.com/yakeing/Documentation/blob/master/Sponsor/README.md) 71 | 72 | Author 73 | --- 74 | 75 | weibo: [yakeing](https://weibo.com/yakeing) 76 | 77 | twitter: [yakeing](https://twitter.com/yakeing) 78 | -------------------------------------------------------------------------------- /tests/Cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIGXTCCBUWgAwIBAgIQAzcKtii/mNK7zeHCeX1GNDANBgkqhkiG9w0BAQsFADBw 3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 4 | d3cuZGlnaWNlcnQuY29tMS8wLQYDVQQDEyZEaWdpQ2VydCBTSEEyIEhpZ2ggQXNz 5 | dXJhbmNlIFNlcnZlciBDQTAeFw0xOTA3MDgwMDAwMDBaFw0yMDA3MTYxMjAwMDBa 6 | MGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDY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IwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm 74 | +9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW 75 | PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM 76 | xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB 77 | Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3 78 | hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg 79 | EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF 80 | MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA 81 | FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec 82 | nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z 83 | eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF 84 | hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2 85 | Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe 86 | vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep 87 | +OkuE6N36B9K 88 | -----END CERTIFICATE----- 89 | -------------------------------------------------------------------------------- /src/curl.php: -------------------------------------------------------------------------------- 1 | curl_file_create(''img.jpg','image/jpeg','pic.jpg')); 14 | * $post = array('upload'=>new CURLFile(realpath('img.jpg'))); php 5.5 Edition 15 | * 16 | * from-data == array() 17 | * x-www-form-urlencoded == key=value 18 | * HTTP/1.1 100 Continue = CURLOPT_HTTPHEADER = array( 'Expect:' ) 19 | */ 20 | namespace php_curl; 21 | class curl{ 22 | public $Headers = array(); 23 | public $Body = ''; 24 | public $StatusCode = 0; 25 | public $UrlPut = ''; //最后一个有效发送地址 26 | public $HeadersPut = ''; //发送的头部 put Headers 27 | public $Cookie = array(); //返回 Cookie 28 | public $Error = ''; //返回 Error 29 | 30 | private $HeadOut = false; //只输出头部(需要打开回调函数) 31 | //Constructor 32 | public function __construct(){ 33 | if(function_exists('curl')){ 34 | throw new Exception('Curl not defined'); 35 | } 36 | } //END __construct 37 | 38 | //Initialization Param 39 | private function Init($Par){ 40 | if(isset($Par['HeadOut']) && $Par['HeadOut'] === true){ 41 | $Par['HeaderCallback'] = true; 42 | $this->HeadOut = true; 43 | }else{ 44 | $this->HeadOut = false; 45 | } 46 | $Param = array( 47 | 'CurlOpt' => array(), //自定义 Curl 选项 48 | 'CookieSet' => array(), //设置 Cookie 49 | 'Timeout' => 5, //运行时间S秒 50 | 'Referer' => '', //伪装来源 51 | 'Certificate' => '', //Base64编码pem格式的CA证书 52 | 'HeadersOn' => false, //输出头部信息 53 | 'HeaderCallback' => false, //回调函数(返回头部) 54 | 'LocationQuantity' => 0, //自动重定向次数(HTTP 301/302) 55 | 'Encoding' => 'deflate, gzip', //压缩 1.identity、2.deflate, gzip 56 | 'UserAgent' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html )' 57 | ); 58 | foreach($Param as $key => $value){ 59 | if(isset($Par[$key])){ 60 | $Param[$key] = $Par[$key]; 61 | } 62 | } 63 | return $Param; 64 | } //NDE Init 65 | 66 | //Get Network Resources 67 | public function GET($Url, $Par = array(), $Header = array()){ 68 | return $this->Method($Url, NULL, $Par, $Header, 'GET'); 69 | } //NDE GET 70 | 71 | //Get HEAD 72 | public function HEAD($Url, $Par = array(), $Header = array()){ 73 | $Par['HeadOut'] = true; 74 | $ret = $this->Method($Url, NULL, $Par, $Header, 'GET'); 75 | return ($this->StatusCode == 200); 76 | } //NDE HEAD 77 | 78 | //Delete 79 | public function DELETE($Url, $Par = array(), $Header = array()){ 80 | return $this->Method($Url, NULL, $Par, $Header, 'DELETE'); 81 | } //NDE DELETE 82 | 83 | //Send Data Packet 84 | public function POST($Url, $Vars, $Par = array(), $Header = array()){ 85 | return $this->Method($Url, $Vars, $Par, $Header, 'POST'); 86 | } //END POST 87 | 88 | //Send Data Packet (idempotent) 89 | public function PUT($Url, $Vars, $Par = array(), $Header = array()){ 90 | return $this->Method($Url, $Vars, $Par, $Header, 'PUT'); 91 | } //END PUT 92 | 93 | //Send Data Packet 94 | public function Method($Url, $Vars, $Par, $Header, $Method){ 95 | $Param = $this->Init($Par); 96 | $Options = $this->Options($Url, $Param, $Header); 97 | if($Method != 'GET'){ 98 | if($Method == 'POST'){ 99 | $Options[CURLOPT_POST] = true; 100 | }else{ 101 | $Options[CURLOPT_CUSTOMREQUEST] = strtoupper($Method); 102 | } 103 | if(isset($Vars)){ 104 | $Options[CURLOPT_POSTFIELDS] = $Vars; 105 | } 106 | } 107 | //$Options[CURLOPT_HTTPGET] = true; //default setting GET 108 | return $this->Http($Options); 109 | } //END Method 110 | 111 | //Curl Options 112 | private function Options($Url, $Param, $Header){ 113 | $Options = array( 114 | CURLOPT_URL => $Url, //Destination address(URL) 115 | CURLOPT_USERAGENT => $Param['UserAgent'], //Customer UA mark 116 | CURLOPT_TIMEOUT => $Param['Timeout'], //Running time (sec) 117 | CURLOPT_CONNECTTIMEOUT => $Param['Timeout'], //Connection time (sec) 118 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, //http 1.1 Edition 119 | CURLOPT_RETURNTRANSFER => true, //Return file stream 120 | //CURLOPT_COOKIESESSION => true, //session cookie 121 | CURLINFO_HEADER_OUT => true //Request for trace handle 122 | ); 123 | //Closing Body will not be able to receive cookie information 124 | //$Options[CURLOPT_NOBODY] = true; 125 | if(!empty($Header)){//Set header information 126 | $Options[CURLOPT_HTTPHEADER] = $Header; 127 | } 128 | if(strrpos($Url, 'https://') === 0){//https mode 129 | if(empty($Param['Certificate'])){ 130 | $Options[CURLOPT_SSL_VERIFYPEER] = false;//https peer’s certificate OFF 131 | $Options[CURLOPT_SSL_VERIFYHOST] = false;//No inspection certificate 132 | }else{ 133 | $Options[CURLOPT_SSL_VERIFYPEER] = true;//Validation of peer’s certificate 134 | $Options[CURLOPT_SSL_VERIFYHOST] = 2;//Does the Certificate Common Name match the hostname (Strict certification) 135 | $Options[CURLOPT_CAINFO] = $Param['Certificate'];//Certificate address 136 | } 137 | } 138 | if(is_int($Param['LocationQuantity']) && $Param['LocationQuantity'] > 0){//redirection (HTTP 301/302) 139 | $Options[CURLOPT_FOLLOWLOCATION] = true;//Open redirection 140 | $Options[CURLOPT_AUTOREFERER] = true;//Redirection automatically sets Referer information 141 | $Options[CURLOPT_MAXREDIRS] = $Param['LocationQuantity']; //Redirection times 142 | } 143 | if(!empty($Param['CookieSet'])){//Cookie information 144 | if(is_array($Param['CookieSet'])){ 145 | $cookie = ''; 146 | foreach ($Param['CookieSet'] as $key => $value) { 147 | $cookie .= $key.'='.$value.';'; 148 | } 149 | }else{ //is_string($Param['CookieSet']) 150 | $cookie = $Param['CookieSet']; 151 | } 152 | $Options[CURLOPT_COOKIE] = $cookie; 153 | } 154 | if(!empty($Param['Referer'])){//Camouflage source 155 | $Options[CURLOPT_REFERER] = $Param['Referer']; 156 | } 157 | if(!empty($Param['Encoding'])){//compress 158 | $Options[CURLOPT_ENCODING] = $Param['Encoding']; 159 | } 160 | if($Param['HeadersOn'] === true){//Back header 161 | $Options[CURLOPT_HEADER] = true; 162 | } 163 | if($Param['HeaderCallback'] === true){//callback (Get header) 164 | $Options[CURLOPT_HEADERFUNCTION] = array($this, 'CurlHeaderCallback'); 165 | } 166 | if(count($Param['CurlOpt'])>0){//Add or change Curl Options 167 | $Options = array_replace($Options, $Param['CurlOpt']); 168 | } 169 | return $Options; 170 | } //END Options 171 | 172 | // Curl Header Callback 173 | private function CurlHeaderCallback($ch, $header){ 174 | $i = strpos($header, ':'); 175 | if(!empty($i)){ 176 | $key = str_replace('-', '_', strtolower(substr($header, 0, $i))); 177 | $value = trim(substr($header, $i + 2)); 178 | if($key == 'set_cookie'){ 179 | list($k, $v) = explode('=', strstr($value, ';', true), 2); 180 | $this->Cookie[$k] = $v; 181 | }else{ 182 | $this->Headers[$key] = $value; 183 | } 184 | }else if(!empty(trim($header))){ 185 | $this->Headers['HTTP'][] = $header; 186 | }else if($this->HeadOut){ 187 | return 0; 188 | } 189 | return strlen($header); 190 | } //END CurlHeaderCallback 191 | 192 | //initialize variable Packet 193 | private function InitializeVariable(){ 194 | $this->StatusCode = 0; 195 | $this->Headers = $this->Cookie = array(); 196 | $this->Body = $this->UrlPut = $this->HeadersPut = $this->Error = ''; 197 | } //END InitializeVariable 198 | 199 | //Establish Communication Connection 200 | private function Http($options){ 201 | $this->InitializeVariable(); 202 | $ch = curl_init(); 203 | curl_setopt_array($ch, $options); 204 | $ResUlt = curl_exec($ch); 205 | //Gets the size of the header 206 | $Header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 207 | //Gets the last valid URL 208 | $this->UrlPut = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); 209 | //Send header request 210 | $this->HeadersPut = curl_getinfo($ch, CURLINFO_HEADER_OUT ); 211 | //Get the last valid code 212 | $this->StatusCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); 213 | //Get Content-Type value 214 | //$ContentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE ); 215 | if($ResUlt === false || curl_errno($ch) !== 0){ 216 | $this->Error = curl_error($ch); 217 | curl_close($ch); 218 | return false; 219 | }else{ 220 | $this->Body = $ResUlt; 221 | curl_close($ch); 222 | return true; 223 | } 224 | } //END Http 225 | } 226 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | --------------------------------------------------------------------------------