mirror of
https://github.com/friendica/friendica
synced 2024-11-18 11:43:41 +00:00
Suppress XML logging of errors
This commit is contained in:
parent
ebb96faedd
commit
f521689ced
7 changed files with 32 additions and 24 deletions
|
@ -747,7 +747,7 @@ class GServer
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$xrd = XML::parseString($curlResult->getBody(), false);
|
$xrd = XML::parseString($curlResult->getBody());
|
||||||
if (!is_object($xrd)) {
|
if (!is_object($xrd)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -796,13 +796,13 @@ class GServer
|
||||||
DBA::close($gcontacts);
|
DBA::close($gcontacts);
|
||||||
|
|
||||||
$apcontacts = DBA::select('apcontact', ['url'], ['baseurl' => [$url, $serverdata['nurl']]]);
|
$apcontacts = DBA::select('apcontact', ['url'], ['baseurl' => [$url, $serverdata['nurl']]]);
|
||||||
while ($gcontact = DBA::fetch($gcontacts)) {
|
while ($apcontact = DBA::fetch($apcontacts)) {
|
||||||
$contacts[Strings::normaliseLink($apcontact['url'])] = $apcontact['url'];
|
$contacts[Strings::normaliseLink($apcontact['url'])] = $apcontact['url'];
|
||||||
}
|
}
|
||||||
DBA::close($apcontacts);
|
DBA::close($apcontacts);
|
||||||
|
|
||||||
$pcontacts = DBA::select('contact', ['url', 'nurl'], ['uid' => 0, 'baseurl' => [$url, $serverdata['nurl']]]);
|
$pcontacts = DBA::select('contact', ['url', 'nurl'], ['uid' => 0, 'baseurl' => [$url, $serverdata['nurl']]]);
|
||||||
while ($gcontact = DBA::fetch($gcontacts)) {
|
while ($pcontact = DBA::fetch($pcontacts)) {
|
||||||
$contacts[$pcontact['nurl']] = $pcontact['url'];
|
$contacts[$pcontact['nurl']] = $pcontact['url'];
|
||||||
}
|
}
|
||||||
DBA::close($pcontacts);
|
DBA::close($pcontacts);
|
||||||
|
|
|
@ -1249,8 +1249,8 @@ class Item
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$xo = XML::parseString($item["object"], false);
|
$xo = XML::parseString($item["object"]);
|
||||||
$xt = XML::parseString($item["target"], false);
|
$xt = XML::parseString($item["target"]);
|
||||||
|
|
||||||
if ($xt->type != Activity\ObjectType::NOTE) {
|
if ($xt->type != Activity\ObjectType::NOTE) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -160,7 +160,7 @@ class Probe
|
||||||
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
|
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
|
||||||
if ($curlResult->isSuccess()) {
|
if ($curlResult->isSuccess()) {
|
||||||
$xml = $curlResult->getBody();
|
$xml = $curlResult->getBody();
|
||||||
$xrd = XML::parseString($xml, false);
|
$xrd = XML::parseString($xml, true);
|
||||||
if (!empty($url)) {
|
if (!empty($url)) {
|
||||||
$host_url = 'https://' . $host;
|
$host_url = 'https://' . $host;
|
||||||
} else {
|
} else {
|
||||||
|
@ -185,7 +185,7 @@ class Probe
|
||||||
}
|
}
|
||||||
|
|
||||||
$xml = $curlResult->getBody();
|
$xml = $curlResult->getBody();
|
||||||
$xrd = XML::parseString($xml, false);
|
$xrd = XML::parseString($xml, true);
|
||||||
$host_url = 'http://'.$host;
|
$host_url = 'http://'.$host;
|
||||||
}
|
}
|
||||||
if (!is_object($xrd)) {
|
if (!is_object($xrd)) {
|
||||||
|
@ -936,7 +936,7 @@ class Probe
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it is not JSON, maybe it is XML
|
// If it is not JSON, maybe it is XML
|
||||||
$xrd = XML::parseString($data, false);
|
$xrd = XML::parseString($data, true);
|
||||||
if (!is_object($xrd)) {
|
if (!is_object($xrd)) {
|
||||||
Logger::log("No webfinger data retrievable for ".$url, Logger::DEBUG);
|
Logger::log("No webfinger data retrievable for ".$url, Logger::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1406,8 +1406,8 @@ class Transmitter
|
||||||
*/
|
*/
|
||||||
private static function createAddTag($item, $data)
|
private static function createAddTag($item, $data)
|
||||||
{
|
{
|
||||||
$object = XML::parseString($item['object'], false);
|
$object = XML::parseString($item['object']);
|
||||||
$target = XML::parseString($item["target"], false);
|
$target = XML::parseString($item["target"]);
|
||||||
|
|
||||||
$data['diaspora:guid'] = $item['guid'];
|
$data['diaspora:guid'] = $item['guid'];
|
||||||
$data['actor'] = $item['author-link'];
|
$data['actor'] = $item['author-link'];
|
||||||
|
|
|
@ -805,7 +805,7 @@ class DFRN
|
||||||
if ($activity) {
|
if ($activity) {
|
||||||
$entry = $doc->createElement($element);
|
$entry = $doc->createElement($element);
|
||||||
|
|
||||||
$r = XML::parseString($activity, false);
|
$r = XML::parseString($activity);
|
||||||
if (!$r) {
|
if (!$r) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -831,7 +831,7 @@ class DFRN
|
||||||
$r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
|
$r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
|
||||||
|
|
||||||
// XML does need a single element as root element so we add a dummy element here
|
// XML does need a single element as root element so we add a dummy element here
|
||||||
$data = XML::parseString("<dummy>" . $r->link . "</dummy>", false);
|
$data = XML::parseString("<dummy>" . $r->link . "</dummy>");
|
||||||
if (is_object($data)) {
|
if (is_object($data)) {
|
||||||
foreach ($data->link as $link) {
|
foreach ($data->link as $link) {
|
||||||
$attributes = [];
|
$attributes = [];
|
||||||
|
@ -2101,7 +2101,7 @@ class DFRN
|
||||||
if (!$verb) {
|
if (!$verb) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$xo = XML::parseString($item["object"], false);
|
$xo = XML::parseString($item["object"]);
|
||||||
|
|
||||||
if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) {
|
if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) {
|
||||||
// somebody was poked/prodded. Was it me?
|
// somebody was poked/prodded. Was it me?
|
||||||
|
@ -2224,8 +2224,8 @@ class DFRN
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity\ObjectType::TAGTERM)) {
|
if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity\ObjectType::TAGTERM)) {
|
||||||
$xo = XML::parseString($item["object"], false);
|
$xo = XML::parseString($item["object"]);
|
||||||
$xt = XML::parseString($item["target"], false);
|
$xt = XML::parseString($item["target"]);
|
||||||
|
|
||||||
if ($xt->type == Activity\ObjectType::NOTE) {
|
if ($xt->type == Activity\ObjectType::NOTE) {
|
||||||
$item_tag = Item::selectFirst(['id', 'uri-id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
|
$item_tag = Item::selectFirst(['id', 'uri-id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
|
||||||
|
@ -2413,7 +2413,7 @@ class DFRN
|
||||||
$item["object"] = self::transformActivity($xpath, $object, "object");
|
$item["object"] = self::transformActivity($xpath, $object, "object");
|
||||||
|
|
||||||
if (trim($item["object"]) != "") {
|
if (trim($item["object"]) != "") {
|
||||||
$r = XML::parseString($item["object"], false);
|
$r = XML::parseString($item["object"]);
|
||||||
if (isset($r->type)) {
|
if (isset($r->type)) {
|
||||||
$item["object-type"] = $r->type;
|
$item["object-type"] = $r->type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,7 @@ class Diaspora
|
||||||
*/
|
*/
|
||||||
private static function verifyMagicEnvelope($envelope)
|
private static function verifyMagicEnvelope($envelope)
|
||||||
{
|
{
|
||||||
$basedom = XML::parseString($envelope);
|
$basedom = XML::parseString($envelope, true);
|
||||||
|
|
||||||
if (!is_object($basedom)) {
|
if (!is_object($basedom)) {
|
||||||
Logger::log("Envelope is no XML file");
|
Logger::log("Envelope is no XML file");
|
||||||
|
@ -451,7 +451,7 @@ class Diaspora
|
||||||
$xml = $raw;
|
$xml = $raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
$basedom = XML::parseString($xml);
|
$basedom = XML::parseString($xml, true);
|
||||||
|
|
||||||
if (!is_object($basedom)) {
|
if (!is_object($basedom)) {
|
||||||
Logger::log('Received data does not seem to be an XML. Discarding. '.$xml);
|
Logger::log('Received data does not seem to be an XML. Discarding. '.$xml);
|
||||||
|
|
|
@ -433,18 +433,26 @@ class XML
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function parseString($s, $strict = true)
|
/**
|
||||||
|
* Parse XML string
|
||||||
|
*
|
||||||
|
* @param string $s
|
||||||
|
* @param boolean $suppress_log
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
|
public static function parseString(string $s, bool $suppress_log = false)
|
||||||
{
|
{
|
||||||
// the "strict" parameter is deactivated
|
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
|
|
||||||
$x = @simplexml_load_string($s);
|
$x = @simplexml_load_string($s);
|
||||||
if (!$x) {
|
if (!$x) {
|
||||||
|
if (!$suppress_log) {
|
||||||
Logger::error('Error(s) while parsing XML string.', ['callstack' => System::callstack()]);
|
Logger::error('Error(s) while parsing XML string.', ['callstack' => System::callstack()]);
|
||||||
foreach (libxml_get_errors() as $err) {
|
foreach (libxml_get_errors() as $err) {
|
||||||
Logger::info('libxml error', ['code' => $err->code, 'position' => $err->line . ":" . $err->column, 'message' => $err->message]);
|
Logger::info('libxml error', ['code' => $err->code, 'position' => $err->line . ":" . $err->column, 'message' => $err->message]);
|
||||||
}
|
}
|
||||||
Logger::debug('Erroring XML string', ['xml' => $s]);
|
Logger::debug('Erroring XML string', ['xml' => $s]);
|
||||||
|
}
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
}
|
}
|
||||||
return $x;
|
return $x;
|
||||||
|
|
Loading…
Reference in a new issue