deprecate a->get_curl_code() and $a->get_curl_headers()
This commit is contained in:
parent
3163731a3d
commit
bd33e0486d
20
boot.php
20
boot.php
@ -989,26 +989,6 @@ class App {
|
||||
)) . $this->page['htmlhead'];
|
||||
}
|
||||
|
||||
// The following curl functions will go away once we've converted
|
||||
// all instances of (fetch|post)_url() to z_(fetch|post)_url()
|
||||
|
||||
function set_curl_code($code) {
|
||||
$this->curl_code = $code;
|
||||
}
|
||||
|
||||
function get_curl_code() {
|
||||
return $this->curl_code;
|
||||
}
|
||||
|
||||
function set_curl_headers($headers) {
|
||||
$this->curl_headers = $headers;
|
||||
}
|
||||
|
||||
function get_curl_headers() {
|
||||
return $this->curl_headers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* register template engine class
|
||||
* if $name is "", is used class static property $class::$name
|
||||
|
@ -2579,198 +2579,6 @@ function mail_store($arr) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
$idtosend = $orig_id = (($contact['dfrn_id']) ? $contact['dfrn_id'] : $contact['issued_id']);
|
||||
|
||||
if($contact['duplex'] && $contact['dfrn_id'])
|
||||
$idtosend = '0:' . $orig_id;
|
||||
if($contact['duplex'] && $contact['issued_id'])
|
||||
$idtosend = '1:' . $orig_id;
|
||||
|
||||
$rino = ((function_exists('mcrypt_encrypt')) ? 1 : 0);
|
||||
|
||||
$rino_enable = get_config('system','rino_encrypt');
|
||||
|
||||
if(! $rino_enable)
|
||||
$rino = 0;
|
||||
|
||||
// $ssl_val = intval(get_config('system','ssl_policy'));
|
||||
// $ssl_policy = '';
|
||||
|
||||
// switch($ssl_val){
|
||||
// case SSL_POLICY_FULL:
|
||||
// $ssl_policy = 'full';
|
||||
// break;
|
||||
// case SSL_POLICY_SELFSIGN:
|
||||
// $ssl_policy = 'self';
|
||||
// break;
|
||||
// case SSL_POLICY_NONE:
|
||||
// default:
|
||||
// $ssl_policy = 'none';
|
||||
// break;
|
||||
// }
|
||||
|
||||
$url = $contact['notify'] . '&dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . (($rino) ? '&rino=1' : '');
|
||||
|
||||
logger('dfrn_deliver: ' . $url);
|
||||
|
||||
$xml = fetch_url($url);
|
||||
|
||||
$curl_stat = $a->get_curl_code();
|
||||
if(! $curl_stat)
|
||||
return(-1); // timed out
|
||||
|
||||
logger('dfrn_deliver: ' . $xml, LOGGER_DATA);
|
||||
|
||||
if(! $xml)
|
||||
return 3;
|
||||
|
||||
if(strpos($xml,'<?xml') === false) {
|
||||
logger('dfrn_deliver: no valid XML returned');
|
||||
logger('dfrn_deliver: returned XML: ' . $xml, LOGGER_DATA);
|
||||
return 3;
|
||||
}
|
||||
|
||||
$res = parse_xml_string($xml);
|
||||
|
||||
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
|
||||
return (($res->status) ? $res->status : 3);
|
||||
|
||||
$postvars = array();
|
||||
$sent_dfrn_id = hex2bin((string) $res->dfrn_id);
|
||||
$challenge = hex2bin((string) $res->challenge);
|
||||
$perm = (($res->perm) ? $res->perm : null);
|
||||
$dfrn_version = (float) (($res->dfrn_version) ? $res->dfrn_version : 2.0);
|
||||
$rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
|
||||
$page = (($owner['page-flags'] == PAGE_COMMUNITY) ? 1 : 0);
|
||||
|
||||
if($owner['page-flags'] == PAGE_PRVGROUP)
|
||||
$page = 2;
|
||||
|
||||
$final_dfrn_id = '';
|
||||
|
||||
if($perm) {
|
||||
if((($perm == 'rw') && (! intval($contact['writable'])))
|
||||
|| (($perm == 'r') && (intval($contact['writable'])))) {
|
||||
q("update contact set writable = %d where id = %d limit 1",
|
||||
intval(($perm == 'rw') ? 1 : 0),
|
||||
intval($contact['id'])
|
||||
);
|
||||
$contact['writable'] = (string) 1 - intval($contact['writable']);
|
||||
}
|
||||
}
|
||||
|
||||
if(($contact['duplex'] && strlen($contact['pubkey']))
|
||||
|| ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
|
||||
|| ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) {
|
||||
openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
|
||||
openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']);
|
||||
}
|
||||
else {
|
||||
openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
|
||||
openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
|
||||
}
|
||||
|
||||
$final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
|
||||
|
||||
if(strpos($final_dfrn_id,':') == 1)
|
||||
$final_dfrn_id = substr($final_dfrn_id,2);
|
||||
|
||||
if($final_dfrn_id != $orig_id) {
|
||||
logger('dfrn_deliver: wrong dfrn_id.');
|
||||
// did not decode properly - cannot trust this site
|
||||
return 3;
|
||||
}
|
||||
|
||||
$postvars['dfrn_id'] = $idtosend;
|
||||
$postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
|
||||
if($dissolve)
|
||||
$postvars['dissolve'] = '1';
|
||||
|
||||
|
||||
if((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
|
||||
$postvars['data'] = $atom;
|
||||
$postvars['perm'] = 'rw';
|
||||
}
|
||||
else {
|
||||
$postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
|
||||
$postvars['perm'] = 'r';
|
||||
}
|
||||
|
||||
// $postvars['ssl_policy'] = $ssl_policy;
|
||||
|
||||
if($page)
|
||||
$postvars['page'] = $page;
|
||||
|
||||
if($rino && $rino_allowed && (! $dissolve)) {
|
||||
$key = substr(random_string(),0,16);
|
||||
$data = bin2hex(aes_encrypt($postvars['data'],$key));
|
||||
$postvars['data'] = $data;
|
||||
logger('rino: sent key = ' . $key, LOGGER_DEBUG);
|
||||
|
||||
|
||||
if($dfrn_version >= 2.1) {
|
||||
if(($contact['duplex'] && strlen($contact['pubkey']))
|
||||
|| ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey']))
|
||||
|| ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey']))) {
|
||||
|
||||
openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
|
||||
}
|
||||
else {
|
||||
openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
|
||||
openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
|
||||
}
|
||||
else {
|
||||
openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
|
||||
}
|
||||
}
|
||||
|
||||
logger('md5 rawkey ' . md5($postvars['key']));
|
||||
|
||||
$postvars['key'] = bin2hex($postvars['key']);
|
||||
}
|
||||
|
||||
logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars,true), LOGGER_DATA);
|
||||
|
||||
$xml = post_url($contact['notify'],$postvars);
|
||||
|
||||
logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA);
|
||||
|
||||
$curl_stat = $a->get_curl_code();
|
||||
if((! $curl_stat) || (! strlen($xml)))
|
||||
return(-1); // timed out
|
||||
|
||||
if(($curl_stat == 503) && (stristr($a->get_curl_headers(),'retry-after')))
|
||||
return(-1);
|
||||
|
||||
if(strpos($xml,'<?xml') === false) {
|
||||
logger('dfrn_deliver: phase 2: no valid XML returned');
|
||||
logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
|
||||
return 3;
|
||||
}
|
||||
|
||||
if($contact['term_date'] != '0000-00-00 00:00:00') {
|
||||
logger("dfrn_deliver: $url back from the dead - removing mark for death");
|
||||
require_once('include/Contact.php');
|
||||
unmark_for_death($contact);
|
||||
}
|
||||
|
||||
$res = parse_xml_string($xml);
|
||||
|
||||
return $res->status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* consume_feed - process atom feed and update anything/everything we might need to update
|
||||
|
@ -65,7 +65,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
||||
if($binary)
|
||||
@curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
|
||||
|
||||
$a->set_curl_code(0);
|
||||
// $a->set_curl_code(0);
|
||||
|
||||
// don't let curl abort the entire application
|
||||
// if it throws any errors.
|
||||
@ -101,10 +101,10 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_curl_code($http_code);
|
||||
// $a->set_curl_code($http_code);
|
||||
|
||||
$body = substr($s,strlen($header));
|
||||
$a->set_curl_headers($header);
|
||||
// $a->set_curl_headers($header);
|
||||
@curl_close($ch);
|
||||
return($body);
|
||||
}
|
||||
@ -156,7 +156,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
|
||||
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr);
|
||||
}
|
||||
|
||||
$a->set_curl_code(0);
|
||||
// $a->set_curl_code(0);
|
||||
|
||||
// don't let curl abort the entire application
|
||||
// if it throws any errors.
|
||||
@ -195,10 +195,10 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
$a->set_curl_code($http_code);
|
||||
// $a->set_curl_code($http_code);
|
||||
$body = substr($s,strlen($header));
|
||||
|
||||
$a->set_curl_headers($header);
|
||||
// $a->set_curl_headers($header);
|
||||
|
||||
curl_close($ch);
|
||||
return($body);
|
||||
@ -586,175 +586,6 @@ function webfinger($s, $debug = false) {
|
||||
}
|
||||
|
||||
|
||||
function lrdd($uri, $debug = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
// default priority is host priority, host-meta first
|
||||
|
||||
$priority = 'host';
|
||||
|
||||
// All we have is an email address. Resource-priority is irrelevant
|
||||
// because our URI isn't directly resolvable.
|
||||
|
||||
if(strstr($uri,'@')) {
|
||||
return(webfinger($uri));
|
||||
}
|
||||
|
||||
// get the host meta file
|
||||
|
||||
$host = @parse_url($uri);
|
||||
|
||||
if($host) {
|
||||
$url = ((x($host,'scheme')) ? $host['scheme'] : 'http') . '://';
|
||||
$url .= $host['host'] . '/.well-known/host-meta' ;
|
||||
}
|
||||
else
|
||||
return array();
|
||||
|
||||
logger('lrdd: constructed url: ' . $url);
|
||||
|
||||
$xml = fetch_url($url);
|
||||
$headers = $a->get_curl_headers();
|
||||
|
||||
if (! $xml)
|
||||
return array();
|
||||
|
||||
logger('lrdd: host_meta: ' . $xml, LOGGER_DATA);
|
||||
|
||||
if(! stristr($xml,'<xrd'))
|
||||
return array();
|
||||
|
||||
$h = parse_xml_string($xml);
|
||||
if(! $h)
|
||||
return array();
|
||||
|
||||
$arr = convert_xml_element_to_array($h);
|
||||
|
||||
if(isset($arr['xrd']['property'])) {
|
||||
$property = $arr['crd']['property'];
|
||||
if(! isset($property[0]))
|
||||
$properties = array($property);
|
||||
else
|
||||
$properties = $property;
|
||||
foreach($properties as $prop)
|
||||
if((string) $prop['@attributes'] === 'http://lrdd.net/priority/resource')
|
||||
$priority = 'resource';
|
||||
}
|
||||
|
||||
// save the links in case we need them
|
||||
|
||||
$links = array();
|
||||
|
||||
if(isset($arr['xrd']['link'])) {
|
||||
$link = $arr['xrd']['link'];
|
||||
if(! isset($link[0]))
|
||||
$links = array($link);
|
||||
else
|
||||
$links = $link;
|
||||
}
|
||||
|
||||
// do we have a template or href?
|
||||
|
||||
if(count($links)) {
|
||||
foreach($links as $link) {
|
||||
if($link['@attributes']['rel'] && attribute_contains($link['@attributes']['rel'],'lrdd')) {
|
||||
if(x($link['@attributes'],'template'))
|
||||
$tpl = $link['@attributes']['template'];
|
||||
elseif(x($link['@attributes'],'href'))
|
||||
$href = $link['@attributes']['href'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((! isset($tpl)) || (! strpos($tpl,'{uri}')))
|
||||
$tpl = '';
|
||||
|
||||
if($priority === 'host') {
|
||||
if(strlen($tpl))
|
||||
$pxrd = str_replace('{uri}', urlencode($uri), $tpl);
|
||||
elseif(isset($href))
|
||||
$pxrd = $href;
|
||||
if(isset($pxrd)) {
|
||||
logger('lrdd: (host priority) pxrd: ' . $pxrd);
|
||||
$links = fetch_xrd_links($pxrd);
|
||||
return $links;
|
||||
}
|
||||
|
||||
$lines = explode("\n",$headers);
|
||||
if(count($lines)) {
|
||||
foreach($lines as $line) {
|
||||
if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) {
|
||||
return(fetch_xrd_links($matches[1]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// priority 'resource'
|
||||
|
||||
|
||||
$html = fetch_url($uri);
|
||||
$headers = $a->get_curl_headers();
|
||||
logger('lrdd: headers=' . $headers, LOGGER_DEBUG);
|
||||
|
||||
// don't try and parse raw xml as html
|
||||
if(! strstr($html,'<?xml')) {
|
||||
require_once('library/HTML5/Parser.php');
|
||||
|
||||
try {
|
||||
$dom = HTML5_Parser::parse($html);
|
||||
} catch (DOMException $e) {
|
||||
logger('lrdd: parse error: ' . $e);
|
||||
}
|
||||
|
||||
if(isset($dom) && $dom) {
|
||||
$items = $dom->getElementsByTagName('link');
|
||||
foreach($items as $item) {
|
||||
$x = $item->getAttribute('rel');
|
||||
if($x == "lrdd") {
|
||||
$pagelink = $item->getAttribute('href');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($pagelink))
|
||||
return(fetch_xrd_links($pagelink));
|
||||
|
||||
// next look in HTTP headers
|
||||
|
||||
$lines = explode("\n",$headers);
|
||||
if(count($lines)) {
|
||||
foreach($lines as $line) {
|
||||
// TODO alter the following regex to support multiple relations (space separated)
|
||||
if((stristr($line,'link:')) && preg_match('/<([^>].*)>.*rel\=[\'\"]lrdd[\'\"]/',$line,$matches)) {
|
||||
$pagelink = $matches[1];
|
||||
break;
|
||||
}
|
||||
// don't try and run feeds through the html5 parser
|
||||
if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
|
||||
return array();
|
||||
if(stristr($html,'<rss') || stristr($html,'<feed'))
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($pagelink))
|
||||
return(fetch_xrd_links($pagelink));
|
||||
|
||||
// If we haven't found any links, return the host xrd links (which we have already fetched)
|
||||
|
||||
if(isset($links))
|
||||
return $links;
|
||||
|
||||
return array();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Given a host name, locate the LRDD template from that
|
||||
@ -1085,19 +916,20 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
|
||||
$scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[2]);
|
||||
else
|
||||
$scaled = $mtch[2];
|
||||
$i = fetch_url($scaled);
|
||||
$i = z_fetch_url($scaled);
|
||||
|
||||
|
||||
$cache = get_config('system','itemcache');
|
||||
if (($cache != '') and is_dir($cache)) {
|
||||
$cachefile = $cache."/".hash("md5", $scaled);
|
||||
file_put_contents($cachefile, $i);
|
||||
file_put_contents($cachefile, $i['body']);
|
||||
}
|
||||
|
||||
// guess mimetype from headers or filename
|
||||
$type = guess_image_type($mtch[2],true);
|
||||
$type = guess_image_type($mtch[2],$i['header']);
|
||||
|
||||
if($i) {
|
||||
$ph = photo_factory($i, $type);
|
||||
if($i['success']) {
|
||||
$ph = photo_factory($i['body'], $type);
|
||||
if($ph->is_valid()) {
|
||||
$orig_width = $ph->getWidth();
|
||||
$orig_height = $ph->getHeight();
|
||||
|
@ -473,19 +473,19 @@ abstract class photo_driver {
|
||||
* @arg $fromcurl boolean Check Content-Type header from curl request
|
||||
*/
|
||||
|
||||
function guess_image_type($filename, $fromcurl=false) {
|
||||
function guess_image_type($filename, $headers = '') {
|
||||
logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG);
|
||||
$type = null;
|
||||
if ($fromcurl) {
|
||||
if ($headers) {
|
||||
$a = get_app();
|
||||
$headers=array();
|
||||
$h = explode("\n",$a->get_curl_headers());
|
||||
$hdrs=array();
|
||||
$h = explode("\n",$headers);
|
||||
foreach ($h as $l) {
|
||||
list($k,$v) = array_map("trim", explode(":", trim($l), 2));
|
||||
$headers[$k] = $v;
|
||||
$hdrs[$k] = $v;
|
||||
}
|
||||
if (array_key_exists('Content-Type', $headers))
|
||||
$type = $headers['Content-Type'];
|
||||
if (array_key_exists('Content-Type', $hdrs))
|
||||
$type = $hdrs['Content-Type'];
|
||||
}
|
||||
if (is_null($type)){
|
||||
// FIXME!!!!
|
||||
|
@ -1 +1 @@
|
||||
2013-11-30.513
|
||||
2013-12-01.514
|
||||
|
Reference in New Issue
Block a user