]> git.mxchange.org Git - friendica.git/commitdiff
Move internal recursion-counter to the end of all cur/fetchUrl parameters
authorPhilipp Holzer <admin+github@philipp.info>
Mon, 10 Jun 2019 12:34:54 +0000 (14:34 +0200)
committerPhilipp Holzer <admin+github@philipp.info>
Mon, 10 Jun 2019 12:34:54 +0000 (14:34 +0200)
15 files changed:
mod/dfrn_confirm.php
mod/parse_url.php
src/Content/OEmbed.php
src/Core/Search.php
src/Core/Worker.php
src/Model/APContact.php
src/Module/Magic.php
src/Network/Probe.php
src/Object/Image.php
src/Protocol/ActivityPub.php
src/Protocol/OStatus.php
src/Protocol/PortableContact.php
src/Util/HTTPSignature.php
src/Util/Network.php
src/Worker/OnePoll.php

index 7b1171ba41b9a5571ae6f7ddc4e94271fcf05efc..7da872f0d06a68aeeaf0e29b29cfee84d1e6444e 100644 (file)
@@ -209,7 +209,7 @@ function dfrn_confirm_post(App $a, $handsfree = null)
                 *
                 */
 
-               $res = Network::post($dfrn_confirm, $params, null, $redirects, 120)->getBody();
+               $res = Network::post($dfrn_confirm, $params, null, 120)->getBody();
 
                Logger::log(' Confirm: received data: ' . $res, Logger::DATA);
 
index 7631a5a710b62d07d0f349b2b3b17914debb81a6..6b393932ebc8aa73e176670d6889329a70320fb7 100644 (file)
@@ -70,9 +70,8 @@ function parse_url_content(App $a)
 
        // Check if the URL is an image, video or audio file. If so format
        // the URL with the corresponding BBCode media tag
-       $redirects = 0;
        // Fetch the header of the URL
-       $curlResponse = Network::curl($url, false, $redirects, ['novalidate' => true, 'nobody' => true]);
+       $curlResponse = Network::curl($url, false, ['novalidate' => true, 'nobody' => true]);
 
        if ($curlResponse->isSuccess()) {
                // Convert the header fields into an array
index 7190f1ce0ed39cc8b8433b1497947074e566cd6e..94e95e5f51d234e04b3be242159c4b68cc894158 100644 (file)
@@ -83,8 +83,7 @@ class OEmbed
 
                        if (!in_array($ext, $noexts)) {
                                // try oembed autodiscovery
-                               $redirects = 0;
-                               $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, 'text/*');
+                               $html_text = Network::fetchUrl($embedurl, false, 15, 'text/*');
                                if ($html_text) {
                                        $dom = @DOMDocument::loadHTML($html_text);
                                        if ($dom) {
index 48231f08247a94c1206e8c8f62a774dbc8253f53..e26cc0edc3a55792b682ad397cac11e4d87fafb7 100644 (file)
@@ -107,8 +107,7 @@ class Search extends BaseObject
                        $searchUrl .= '&page=' . $page;
                }
 
-               $red        = 0;
-               $resultJson = Network::fetchUrl($searchUrl, false, $red, 0, 'application/json');
+               $resultJson = Network::fetchUrl($searchUrl, false, 0, 'application/json');
 
                $results = json_decode($resultJson, true);
 
index 0f4a527f6bd21aa95cb9f387ba1f29e5264aab73..548547022476d91c8f75e7c421583467a8176efd 100644 (file)
@@ -983,7 +983,7 @@ class Worker
                }
 
                $url = System::baseUrl()."/worker";
-               Network::fetchUrl($url, false, $redirects, 1);
+               Network::fetchUrl($url, false, 1);
        }
 
        /**
index cf1f9b72313c44baee97083b4b91a3b76255017e..67c714f9afd29d00a211295a0ec5f78c0a0a6838 100644 (file)
@@ -34,7 +34,7 @@ class APContact extends BaseObject
 
                $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
 
-               $curlResult = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']);
+               $curlResult = Network::curl($webfinger, false, ['accept_content' => 'application/jrd+json,application/json']);
                if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
                        return false;
                }
index 491ed31cbd4a4bd0c24036ea45a398325d078251..441fe7f157a33c61609744422dd94385a2cbb3ae 100644 (file)
@@ -85,7 +85,7 @@ class Magic extends BaseModule
                                );
 
                                // Try to get an authentication token from the other instance.
-                               $curlResult = Network::curl($basepath . '/owa', false, $redirects, ['headers' => $headers]);
+                               $curlResult = Network::curl($basepath . '/owa', false, ['headers' => $headers]);
 
                                if ($curlResult->isSuccess()) {
                                        $j = json_decode($curlResult->getBody(), true);
index b0d2630103beaed42328d4aa61cee75a08a3d57f..00c38a4c12c16b383234beb6583bcea71c532c80 100644 (file)
@@ -109,12 +109,11 @@ class Probe
                $url = "http://".$host."/.well-known/host-meta";
 
                $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
-               $redirects = 0;
 
                Logger::log("Probing for ".$host, Logger::DEBUG);
                $xrd = null;
 
-               $curlResult = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+               $curlResult = Network::curl($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
                if ($curlResult->isSuccess()) {
                        $xml = $curlResult->getBody();
                        $xrd = XML::parseString($xml, false);
@@ -122,7 +121,7 @@ class Probe
                }
 
                if (!is_object($xrd)) {
-                       $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
+                       $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
                        if ($curlResult->isTimeout()) {
                                Logger::log("Probing timeout for " . $url, Logger::DEBUG);
                                self::$istimeout = true;
@@ -738,9 +737,8 @@ class Probe
        private static function webfinger($url, $type)
        {
                $xrd_timeout = Config::get('system', 'xrd_timeout', 20);
-               $redirects = 0;
 
-               $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
+               $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
                if ($curlResult->isTimeout()) {
                        self::$istimeout = true;
                        return false;
index 67413e3c0d1e7c5f13d7ae07287f4827ad9c4973..803aa08b38f58b7e28da83ce0506769aea38f766 100644 (file)
@@ -781,7 +781,7 @@ class Image
                $data = Cache::get($url);
 
                if (is_null($data) || !$data || !is_array($data)) {
-                       $img_str = Network::fetchUrl($url, true, $redirects, 4);
+                       $img_str = Network::fetchUrl($url, true, 4);
 
                        if (!$img_str) {
                                return false;
index fa63c44d574bcb9b8f2f6af54707f3cd721f6229..8caf7ac64c97bb8bd88510d8a93f414a03459030 100644 (file)
@@ -74,7 +74,7 @@ class ActivityPub
                        return HTTPSignature::fetch($url, $uid);
                }
 
-               $curlResult = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json, application/ld+json']);
+               $curlResult = Network::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']);
                if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
                        return false;
                }
index 81e5c19db8cc42d73eaf2c5e7adc2f2f74c2cb53..9fa0ff43af73e9120122178142dba54257ee03e4 100644 (file)
@@ -738,7 +738,7 @@ class OStatus
 
                self::$conv_list[$conversation] = true;
 
-               $curlResult = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
+               $curlResult = Network::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']);
 
                if (!$curlResult->isSuccess()) {
                        return;
@@ -931,7 +931,7 @@ class OStatus
                }
 
                $stored = false;
-               $curlResult = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']);
+               $curlResult = Network::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']);
 
                if (!$curlResult->isSuccess()) {
                        return;
index 5345cb22fce2ae182c6f155ab93e518138c08790..60bb844226038c951a01d50f8709e363c2fbc0e7 100644 (file)
@@ -1004,7 +1004,7 @@ class PortableContact
                $server_url = str_replace("http://", "https://", $server_url);
 
                // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
-               $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+               $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]);
 
                // Quit if there is a timeout.
                // But we want to make sure to only quit if we are mostly sure that this server url fits.
@@ -1021,7 +1021,7 @@ class PortableContact
                        $server_url = str_replace("https://", "http://", $server_url);
 
                        // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital
-                       $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]);
+                       $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]);
 
                        // Quit if there is a timeout
                        if ($curlResult->isTimeout()) {
@@ -1624,7 +1624,7 @@ class PortableContact
                        if (!empty($accesstoken)) {
                                $api = 'https://instances.social/api/1.0/instances/list?count=0';
                                $header = ['Authorization: Bearer '.$accesstoken];
-                               $curlResult = Network::curl($api, false, $redirects, ['headers' => $header]);
+                               $curlResult = Network::curl($api, false, ['headers' => $header]);
 
                                if ($curlResult->isSuccess()) {
                                        $servers = json_decode($curlResult->getBody(), true);
index e002d5981cb54f3b78961adc05057df49db0328d..8a058c3b5c7e45d15bd4737daf29dc41b76b5890 100644 (file)
@@ -455,7 +455,7 @@ class HTTPSignature
                $curl_opts = $opts;
                $curl_opts['header'] = $headers;
 
-               $curlResult = Network::curl($request, false, $redirects, $curl_opts);
+               $curlResult = Network::curl($request, false, $curl_opts);
                $return_code = $curlResult->getReturnCode();
 
                Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG);
index 9e71c80171d4ff0180d460e9888ceceb6ebff907..b1d072d7e93a906a5190b2847e2813200c0ec9ba 100644 (file)
@@ -25,17 +25,17 @@ class Network
         * @param string  $url            URL to fetch
         * @param bool    $binary         default false
         *                                TRUE if asked to return binary results (file download)
-        * @param int     $redirects      The recursion counter for internal use - default 0
         * @param int     $timeout        Timeout in seconds, default system config value or 60 seconds
         * @param string  $accept_content supply Accept: header with 'accept_content' as the value
         * @param string  $cookiejar      Path to cookie jar file
+        * @param int     $redirects      The recursion counter for internal use - default 0
         *
         * @return string The fetched content
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function fetchUrl(string $url, bool $binary = false, int &$redirects = 0, int $timeout = 0, string $accept_content = null, string $cookiejar = '')
+       public static function fetchUrl(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
        {
-               $ret = self::fetchUrlFull($url, $binary, $redirects, $timeout, $accept_content, $cookiejar);
+               $ret = self::fetchUrlFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects);
 
                return $ret->getBody();
        }
@@ -50,24 +50,25 @@ class Network
         * @param string  $url            URL to fetch
         * @param bool    $binary         default false
         *                                TRUE if asked to return binary results (file download)
-        * @param int     $redirects      The recursion counter for internal use - default 0
         * @param int     $timeout        Timeout in seconds, default system config value or 60 seconds
         * @param string  $accept_content supply Accept: header with 'accept_content' as the value
         * @param string  $cookiejar      Path to cookie jar file
+        * @param int     $redirects      The recursion counter for internal use - default 0
         *
         * @return CurlResult With all relevant information, 'body' contains the actual fetched content.
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function fetchUrlFull(string $url, bool $binary = false, int &$redirects = 0, int $timeout = 0, string $accept_content = null, string $cookiejar = '')
+       public static function fetchUrlFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0)
        {
                return self::curl(
                        $url,
                        $binary,
-                       $redirects,
-                       ['timeout'=>$timeout,
-                       'accept_content'=>$accept_content,
-                       'cookiejar'=>$cookiejar
-                       ]
+                       [
+                               'timeout'        => $timeout,
+                               'accept_content' => $accept_content,
+                               'cookiejar'      => $cookiejar
+                       ],
+                       $redirects
                );
        }
 
@@ -77,7 +78,6 @@ class Network
         * @param string  $url       URL to fetch
         * @param bool    $binary    default false
         *                           TRUE if asked to return binary results (file download)
-        * @param int     $redirects The recursion counter for internal use - default 0
         * @param array   $opts      (optional parameters) assoziative array with:
         *                           'accept_content' => supply Accept: header with 'accept_content' as the value
         *                           'timeout' => int Timeout in seconds, default system config value or 60 seconds
@@ -86,11 +86,12 @@ class Network
         *                           'nobody' => only return the header
         *                           'cookiejar' => path to cookie jar file
         *                           'header' => header array
+        * @param int     $redirects The recursion counter for internal use - default 0
         *
         * @return CurlResult
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function curl(string $url, bool $binary = false, int &$redirects = 0, array $opts = [])
+       public static function curl(string $url, bool $binary = false, array $opts = [], int &$redirects = 0)
        {
                $stamp1 = microtime(true);
 
@@ -227,7 +228,7 @@ class Network
                        $redirects++;
                        Logger::log('curl: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
                        @curl_close($ch);
-                       return self::curl($curlResponse->getRedirectUrl(), $binary, $redirects, $opts);
+                       return self::curl($curlResponse->getRedirectUrl(), $binary, $opts, $redirects);
                }
 
                @curl_close($ch);
@@ -249,7 +250,7 @@ class Network
         * @return CurlResult The content
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function post(string $url, $params, string $headers = null, int &$redirects = 0, int $timeout = 0)
+       public static function post(string $url, $params, string $headers = null, int $timeout = 0, int &$redirects = 0)
        {
                $stamp1 = microtime(true);
 
index 8f494af53a9afc4130251c0603f06bb9dc52d0ff..a605ee92ed593b4bde77e8b3b4a68da4eccfcd36 100644 (file)
@@ -371,7 +371,7 @@ class OnePoll
                        }
 
                        $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
-                       $curlResult = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]);
+                       $curlResult = Network::curl($contact['poll'], false, ['cookiejar' => $cookiejar]);
                        unlink($cookiejar);
 
                        if ($curlResult->isTimeout()) {