Just some more fixes to the protocol and the avatar stuff
This commit is contained in:
parent
ee817e81a2
commit
eb0a701590
|
@ -793,7 +793,7 @@ class Probe {
|
||||||
|
|
||||||
if (sizeof($avatar)) {
|
if (sizeof($avatar)) {
|
||||||
ksort($avatar);
|
ksort($avatar);
|
||||||
$data["photo"] = array_pop($avatar);
|
$data["photo"] = self::fix_avatar(array_pop($avatar), $data["baseurl"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dfrn) {
|
if ($dfrn) {
|
||||||
|
@ -964,7 +964,7 @@ class Probe {
|
||||||
$data["nick"] = $feed_data["header"]["author-nick"];
|
$data["nick"] = $feed_data["header"]["author-nick"];
|
||||||
}
|
}
|
||||||
if ($feed_data["header"]["author-avatar"] != "") {
|
if ($feed_data["header"]["author-avatar"] != "") {
|
||||||
$data["photo"] = ostatus::fix_avatar($feed_data["header"]["author-avatar"], $data["url"]);
|
$data["photo"] = self::fix_avatar($feed_data["header"]["author-avatar"], $data["url"]);
|
||||||
}
|
}
|
||||||
if ($feed_data["header"]["author-id"] != "") {
|
if ($feed_data["header"]["author-id"] != "") {
|
||||||
$data["alias"] = $feed_data["header"]["author-id"];
|
$data["alias"] = $feed_data["header"]["author-id"];
|
||||||
|
@ -1223,5 +1223,42 @@ class Probe {
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Mix two paths together to possibly fix missing parts
|
||||||
|
*
|
||||||
|
* @param string $avatar Path to the avatar
|
||||||
|
* @param string $base Another path that is hopefully complete
|
||||||
|
*
|
||||||
|
* @return string fixed avatar path
|
||||||
|
*/
|
||||||
|
public static function fix_avatar($avatar, $base) {
|
||||||
|
$base_parts = parse_url($base);
|
||||||
|
|
||||||
|
// Remove all parts that could create a problem
|
||||||
|
unset($base_parts['path']);
|
||||||
|
unset($base_parts['query']);
|
||||||
|
unset($base_parts['fragment']);
|
||||||
|
|
||||||
|
$avatar_parts = parse_url($avatar);
|
||||||
|
|
||||||
|
// Now we mix them
|
||||||
|
$parts = array_merge($base_parts, $avatar_parts);
|
||||||
|
|
||||||
|
// And put them together again
|
||||||
|
$scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
|
||||||
|
$host = isset($parts['host']) ? $parts['host'] : '';
|
||||||
|
$port = isset($parts['port']) ? ':' . $parts['port'] : '';
|
||||||
|
$path = isset($parts['path']) ? $parts['path'] : '';
|
||||||
|
$query = isset($parts['query']) ? '?' . $parts['query'] : '';
|
||||||
|
$fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
|
||||||
|
|
||||||
|
$fixed = $scheme.$host.$port.$path.$query.$fragment;
|
||||||
|
|
||||||
|
logger('Base: '.$base.' - Avatar: '.$avatar.' - Fixed: '.$fixed, LOGGER_DATA);
|
||||||
|
|
||||||
|
return $fixed;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -636,7 +636,7 @@ class Diaspora {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only some message types have signatures. So we quit here for the other types.
|
// Only some message types have signatures. So we quit here for the other types.
|
||||||
if (!in_array($type, array("comment", "message", "like"))) {
|
if (!in_array($type, array("comment", "like"))) {
|
||||||
return array("fields" => $fields, "relayed" => false);
|
return array("fields" => $fields, "relayed" => false);
|
||||||
}
|
}
|
||||||
// No author_signature? This is a must, so we quit.
|
// No author_signature? This is a must, so we quit.
|
||||||
|
@ -694,7 +694,7 @@ class Diaspora {
|
||||||
*
|
*
|
||||||
* @return array the queried data
|
* @return array the queried data
|
||||||
*/
|
*/
|
||||||
private static function person_by_handle($handle) {
|
public static function person_by_handle($handle) {
|
||||||
|
|
||||||
$r = q("SELECT * FROM `fcontact` WHERE `network` = '%s' AND `addr` = '%s' LIMIT 1",
|
$r = q("SELECT * FROM `fcontact` WHERE `network` = '%s' AND `addr` = '%s' LIMIT 1",
|
||||||
dbesc(NETWORK_DIASPORA),
|
dbesc(NETWORK_DIASPORA),
|
||||||
|
@ -1506,11 +1506,6 @@ class Diaspora {
|
||||||
$msg_text = unxmlify($mesg->text);
|
$msg_text = unxmlify($mesg->text);
|
||||||
$msg_created_at = datetime_convert("UTC", "UTC", notags(unxmlify($mesg->created_at)));
|
$msg_created_at = datetime_convert("UTC", "UTC", notags(unxmlify($mesg->created_at)));
|
||||||
|
|
||||||
/// @todo these fields doesn't seem to be supported by the new protocol
|
|
||||||
$msg_parent_guid = notags(unxmlify($mesg->parent_guid));
|
|
||||||
$msg_parent_author_signature = notags(unxmlify($mesg->parent_author_signature));
|
|
||||||
$msg_author_signature = notags(unxmlify($mesg->author_signature));
|
|
||||||
|
|
||||||
if ($msg_conversation_guid != $guid) {
|
if ($msg_conversation_guid != $guid) {
|
||||||
logger("message conversation guid does not belong to the current conversation.");
|
logger("message conversation guid does not belong to the current conversation.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -1519,42 +1514,8 @@ class Diaspora {
|
||||||
$body = diaspora2bb($msg_text);
|
$body = diaspora2bb($msg_text);
|
||||||
$message_uri = $msg_author.":".$msg_guid;
|
$message_uri = $msg_author.":".$msg_guid;
|
||||||
|
|
||||||
$author_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid;
|
|
||||||
|
|
||||||
$author_signature = base64_decode($msg_author_signature);
|
|
||||||
|
|
||||||
if (strcasecmp($msg_author,$msg["author"]) == 0) {
|
|
||||||
$person = $contact;
|
|
||||||
$key = $msg["key"];
|
|
||||||
} else {
|
|
||||||
$person = self::person_by_handle($msg_author);
|
$person = self::person_by_handle($msg_author);
|
||||||
|
|
||||||
if (is_array($person) && x($person, "pubkey")) {
|
|
||||||
$key = $person["pubkey"];
|
|
||||||
} else {
|
|
||||||
logger("unable to find author details");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rsa_verify($author_signed_data, $author_signature, $key, "sha256")) {
|
|
||||||
logger("verification failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($msg_parent_author_signature) {
|
|
||||||
$owner_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid;
|
|
||||||
|
|
||||||
$parent_author_signature = base64_decode($msg_parent_author_signature);
|
|
||||||
|
|
||||||
$key = $msg["key"];
|
|
||||||
|
|
||||||
if (!rsa_verify($owner_signed_data, $parent_author_signature, $key, "sha256")) {
|
|
||||||
logger("owner verification failed.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$r = q("SELECT `id` FROM `mail` WHERE `uri` = '%s' LIMIT 1",
|
$r = q("SELECT `id` FROM `mail` WHERE `uri` = '%s' LIMIT 1",
|
||||||
dbesc($message_uri)
|
dbesc($message_uri)
|
||||||
);
|
);
|
||||||
|
@ -1826,9 +1787,6 @@ class Diaspora {
|
||||||
$text = unxmlify($data->text);
|
$text = unxmlify($data->text);
|
||||||
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
|
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
|
||||||
|
|
||||||
/// @todo "parent_guid" doesn't seem to be part of the new protocol
|
|
||||||
$parent_guid = notags(unxmlify($data->parent_guid));
|
|
||||||
|
|
||||||
$contact = self::allowed_contact_by_handle($importer, $author, true);
|
$contact = self::allowed_contact_by_handle($importer, $author, true);
|
||||||
if (!$contact) {
|
if (!$contact) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1882,7 +1840,7 @@ class Diaspora {
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
dbesc($message_uri),
|
dbesc($message_uri),
|
||||||
dbesc($author.":".$parent_guid),
|
dbesc($author.":".$conversation["guid"]),
|
||||||
dbesc($created_at)
|
dbesc($created_at)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -29,42 +29,6 @@ class ostatus {
|
||||||
const OSTATUS_DEFAULT_POLL_TIMEFRAME = 1440; // given in minutes
|
const OSTATUS_DEFAULT_POLL_TIMEFRAME = 1440; // given in minutes
|
||||||
const OSTATUS_DEFAULT_POLL_TIMEFRAME_MENTIONS = 14400; // given in minutes
|
const OSTATUS_DEFAULT_POLL_TIMEFRAME_MENTIONS = 14400; // given in minutes
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Mix two paths together to possibly fix missing parts
|
|
||||||
*
|
|
||||||
* @param string $avatar Path to the avatar
|
|
||||||
* @param string $base Another path that is hopefully complete
|
|
||||||
*
|
|
||||||
* @return string fixed avatar path
|
|
||||||
*/
|
|
||||||
public static function fix_avatar($avatar, $base) {
|
|
||||||
$base_parts = parse_url($base);
|
|
||||||
|
|
||||||
// Remove all parts that could create a problem
|
|
||||||
unset($base_parts['path']);
|
|
||||||
unset($base_parts['query']);
|
|
||||||
unset($base_parts['fragment']);
|
|
||||||
|
|
||||||
$avatar_parts = parse_url($avatar);
|
|
||||||
|
|
||||||
// Now we mix them
|
|
||||||
$parts = array_merge($base_parts, $avatar_parts);
|
|
||||||
|
|
||||||
// And put them together again
|
|
||||||
$scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
|
|
||||||
$host = isset($parts['host']) ? $parts['host'] : '';
|
|
||||||
$port = isset($parts['port']) ? ':' . $parts['port'] : '';
|
|
||||||
$path = isset($parts['path']) ? $parts['path'] : '';
|
|
||||||
$query = isset($parts['query']) ? '?' . $parts['query'] : '';
|
|
||||||
$fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
|
|
||||||
|
|
||||||
$fixed = $scheme.$host.$port.$path.$query.$fragment;
|
|
||||||
|
|
||||||
logger('Base: '.$base.' - Avatar: '.$avatar.' - Fixed: '.$fixed, LOGGER_DATA);
|
|
||||||
|
|
||||||
return $fixed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fetches author data
|
* @brief Fetches author data
|
||||||
*
|
*
|
||||||
|
@ -135,7 +99,7 @@ class ostatus {
|
||||||
}
|
}
|
||||||
if (count($avatarlist) > 0) {
|
if (count($avatarlist) > 0) {
|
||||||
krsort($avatarlist);
|
krsort($avatarlist);
|
||||||
$author["author-avatar"] = self::fix_avatar(current($avatarlist), $author["author-link"]);
|
$author["author-avatar"] = Probe::fix_avatar(current($avatarlist), $author["author-link"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
|
$displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
|
||||||
|
@ -1196,7 +1160,7 @@ class ostatus {
|
||||||
$arr["owner-name"] = $single_conv->actor->portablecontacts_net->displayName;
|
$arr["owner-name"] = $single_conv->actor->portablecontacts_net->displayName;
|
||||||
|
|
||||||
$arr["owner-link"] = $actor;
|
$arr["owner-link"] = $actor;
|
||||||
$arr["owner-avatar"] = self::fix_avatar($single_conv->actor->image->url, $arr["owner-link"]);
|
$arr["owner-avatar"] = Probe::fix_avatar($single_conv->actor->image->url, $arr["owner-link"]);
|
||||||
|
|
||||||
$arr["author-name"] = $arr["owner-name"];
|
$arr["author-name"] = $arr["owner-name"];
|
||||||
$arr["author-link"] = $arr["owner-link"];
|
$arr["author-link"] = $arr["owner-link"];
|
||||||
|
@ -1261,7 +1225,7 @@ class ostatus {
|
||||||
$arr["author-name"] = $single_conv->object->actor->contact->displayName;
|
$arr["author-name"] = $single_conv->object->actor->contact->displayName;
|
||||||
}
|
}
|
||||||
$arr["author-link"] = $single_conv->object->actor->url;
|
$arr["author-link"] = $single_conv->object->actor->url;
|
||||||
$arr["author-avatar"] = self::fix_avatar($single_conv->object->actor->image->url, $arr["author-link"]);
|
$arr["author-avatar"] = Probe::fix_avatar($single_conv->object->actor->image->url, $arr["author-link"]);
|
||||||
|
|
||||||
$arr["app"] = $single_conv->object->provider->displayName."#";
|
$arr["app"] = $single_conv->object->provider->displayName."#";
|
||||||
//$arr["verb"] = $single_conv->object->verb;
|
//$arr["verb"] = $single_conv->object->verb;
|
||||||
|
|
Loading…
Reference in a new issue