From d473c3c500a39ce1efdf6902114f899644bcc002 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 9 Feb 2015 00:43:38 -0800 Subject: fix for service_plink() after observing it in the wild --- include/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/network.php') diff --git a/include/network.php b/include/network.php index 366ac0d24..a7127c1a2 100644 --- a/include/network.php +++ b/include/network.php @@ -1531,7 +1531,7 @@ function service_plink($contact, $guid) { $m = parse_url($contact['xchan_url']); if($m) { - $url = $scheme . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : ''); + $url = $m['scheme'] . '://' . $m['host'] . (($m['port']) ? ':' . $m['port'] : ''); } else $url = 'https://' . substr($contact['xchan_addr'],strpos($contact['xchan_addr'],'@')+1); -- cgit v1.2.3 From 8d0377466657a02c2e0bbeacd2af0a181ceda898 Mon Sep 17 00:00:00 2001 From: zottel Date: Mon, 23 Feb 2015 14:53:10 +0100 Subject: make redirections restriction in z_fetch_url() work --- include/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/network.php') diff --git a/include/network.php b/include/network.php index a7127c1a2..6874063ab 100644 --- a/include/network.php +++ b/include/network.php @@ -109,7 +109,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { $url_parsed = @parse_url($newurl); if (isset($url_parsed)) { @curl_close($ch); - return z_fetch_url($newurl,$binary,$redirects++,$opts); + return z_fetch_url($newurl,$binary,++$redirects,$opts); } } -- cgit v1.2.3 From fbbcc10025bdf01c17a80a1b790e1f72dcaa8b2c Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Feb 2015 11:33:16 -0800 Subject: apply fix from 8d03774 to z_post_url also --- include/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/network.php') diff --git a/include/network.php b/include/network.php index 6874063ab..db32396e4 100644 --- a/include/network.php +++ b/include/network.php @@ -239,7 +239,7 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { if($http_code == 303) { return z_fetch_url($newurl,false,$redirects++,$opts); } else { - return z_post_url($newurl,$params,$redirects++,$opts); + return z_post_url($newurl,$params,++$redirects,$opts); } } } -- cgit v1.2.3 From 410f3335a9e97276b3262196f50798ff56624af5 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 4 Mar 2015 15:14:10 -0800 Subject: parse_url: if url returns an image/audio/video file instead of a webpage, return the bbcode for the appropriate content type. This results in two web fetches of the url in question, but the first one is just a HEAD. This way we won't try and download and parse an entire video. TODO: img's are checked to see if they should be zid-ified, but audio/video currently are not. --- include/network.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include/network.php') diff --git a/include/network.php b/include/network.php index db32396e4..5912ad79d 100644 --- a/include/network.php +++ b/include/network.php @@ -19,6 +19,7 @@ function get_capath() { * 'timeout' => int seconds, default system config value or 60 seconds * 'http_auth' => username:password * 'novalidate' => do not validate SSL certs, default is to validate using our CA list + * 'nobody' => only return the header * * @returns array * 'return_code' => HTTP return code or 0 if timeout or failure @@ -51,6 +52,9 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { if(x($opts,'headers')) @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); + if(x($opts,'nobody')) + @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); + if(x($opts,'timeout') && intval($opts['timeout'])) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } @@ -182,6 +186,9 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { if(x($opts,'headers')) @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); + if(x($opts,'nobody')) + @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); + if(x($opts,'timeout') && intval($opts['timeout'])) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } -- cgit v1.2.3 From daed7fbeada3c781a6b5d7c8dd69d35733d93ef1 Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 21 Mar 2015 19:12:43 +0100 Subject: Bugfix und variable initialization. Fixed a wrong perm_is_allowed() parameter, commented some other places where we use variables that are not set and should not work. --- include/network.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include/network.php') diff --git a/include/network.php b/include/network.php index 5912ad79d..6aefc0b30 100644 --- a/include/network.php +++ b/include/network.php @@ -32,8 +32,6 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { $ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => ""); - $a = get_app(); - $ch = @curl_init($url); if(($redirects > 8) || (! $ch)) return false; @@ -71,7 +69,6 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ((x($opts,'novalidate') && intval($opts['novalidate'])) ? false : true)); - $prx = get_config('system','proxy'); if(strlen($prx)) { @curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); @@ -518,6 +515,7 @@ function allowed_email($email) { function avatar_img($email) { + $avatar = array(); $a = get_app(); $avatar['size'] = 175; @@ -527,10 +525,11 @@ function avatar_img($email) { call_hooks('avatar_lookup', $avatar); - if(! $avatar['success']) + if (! $avatar['success']) $avatar['url'] = $a->get_baseurl() . '/' . get_default_profile_photo(); logger('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], LOGGER_DEBUG); + return $avatar['url']; } -- cgit v1.2.3 From d0361582b0b620064aff90bf88f01d1072b308fe Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sun, 22 Mar 2015 00:06:08 +0100 Subject: Correcting reported Doxygen syntax warnings. Fixed wrong Doxygen syntax and add some of the available FIXME to Doxygen documentation. Updated Doxygen configuration to add also all capital letter tags. Adding some more Doxygen documentation. --- include/network.php | 99 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 43 deletions(-) (limited to 'include/network.php') diff --git a/include/network.php b/include/network.php index 6aefc0b30..a0782692e 100644 --- a/include/network.php +++ b/include/network.php @@ -1,33 +1,39 @@ - supply Accept: header with 'accept_content' as the value - * 'timeout' => int seconds, default system config value or 60 seconds - * 'http_auth' => username:password - * 'novalidate' => do not validate SSL certs, default is to validate using our CA list - * 'nobody' => only return the header - * - * @returns array - * 'return_code' => HTTP return code or 0 if timeout or failure - * 'success' => boolean true (if HTTP 2xx result) or false - * 'header' => HTTP headers - * 'body' => fetched content + * @param array $opts (optional parameters) assoziative array with: + * * \b accept_content => supply Accept: header with 'accept_content' as the value + * * \b timeout => int seconds, default system config value or 60 seconds + * * \b http_auth => username:password + * * \b novalidate => do not validate SSL certs, default is to validate using our CA list + * * \b nobody => only return the header + * + * @return array an assoziative array with: + * * \e int \b return_code => HTTP return code or 0 if timeout or failure + * * \e boolean \b success => boolean true (if HTTP 2xx result) or false + * * \e string \b header => HTTP headers + * * \e string \b body => fetched content */ - function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { $ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => ""); @@ -129,14 +135,15 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { if(x($opts,'debug')) { $ret['debug'] = $curl_info; } - + @curl_close($ch); return($ret); } /** - * @function z_post_url + * @brief + * * @param string $url * URL to post * @param mixed $params @@ -151,17 +158,15 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { * 'timeout' => int seconds, default system config value or 60 seconds * 'http_auth' => username:password * 'novalidate' => do not validate SSL certs, default is to validate using our CA list - * - * @returns array - * 'return_code' => HTTP return code or 0 if timeout or failure - * 'success' => boolean true (if HTTP 2xx result) or false - * 'header' => HTTP headers - * 'body' => fetched content + * @return array an assoziative array with: + * * \e int \b return_code => HTTP return code or 0 if timeout or failure + * * \e boolean \b success => boolean true (if HTTP 2xx result) or false + * * \e string \b header => HTTP headers + * * \e string \b body => content + * * \e string \b debug => from curl_info() */ - - function z_post_url($url,$params, $redirects = 0, $opts = array()) { - + $ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => ""); $ch = curl_init($url); @@ -257,24 +262,35 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { logger('z_post_url: debug: ' . print_r($curl_info,true), LOGGER_DATA); } - $ret['body'] = substr($s,strlen($header)); + $ret['body'] = substr($s, strlen($header)); $ret['header'] = $header; if(x($opts,'debug')) { $ret['debug'] = $curl_info; } - curl_close($ch); return($ret); } +/** + * @brief Like z_post_url() but with an application/json HTTP header. + * + * Add a "Content-Type: application/json" HTTP-header to $opts and call z_post_url(). + * + * @see z_post_url() + * + * @param string $url + * @param array $params + * @param number $redirects default 0 + * @param array $opts (optional) curl options + * @return z_post_url() + */ +function z_post_url_json($url, $params, $redirects = 0, $opts = array()) { -function z_post_url_json($url,$params,$redirects = 0, $opts = array()) { + $opts = array_merge($opts, array('headers' => array('Content-Type: application/json'))); - $opts = array_merge($opts,array('headers' => array('Content-Type: application/json'))); return z_post_url($url,json_encode($params),$redirects,$opts); - } @@ -305,22 +321,19 @@ function xml_status($st, $message = '') { } /** - * @function http_status_exit - * - * Send HTTP status header and exit + * @brief Send HTTP status header and exit. + * * @param int $val * integer HTTP status result value * @param string $msg * optional message * @returns (does not return, process is terminated) */ +function http_status_exit($val, $msg = '') { -function http_status_exit($val,$msg = '') { - - $err = ''; - if($val >= 400) + if ($val >= 400) $msg = (($msg) ? $msg : 'Error'); - if($val >= 200 && $val < 300) + if ($val >= 200 && $val < 300) $msg = (($msg) ? $msg : 'OK'); logger('http_status_exit ' . $val . ' ' . $msg); -- cgit v1.2.3