- if (!strlen($handshake_xml) || ($html_code >= 400) || !$html_code) {
- // dead connection - might be a transient event, or this might
- // mean the software was uninstalled or the domain expired.
- // Will keep trying for one month.
- Logger::log("$url appears to be dead - marking for death ");
-
- // set the last-update so we don't keep polling
- $fields = ['failed' => true, 'last-update' => $updated, 'failure_update' => $updated];
- self::updateContact($contact, $fields);
- Contact::markForArchival($contact);
- return false;
- }
-
- if (!strstr($handshake_xml, '<')) {
- Logger::log('response from ' . $url . ' did not contain XML.');
-
- $fields = ['failed' => true, 'last-update' => $updated, 'failure_update' => $updated];
- self::updateContact($contact, $fields);
- Contact::markForArchival($contact);
- return false;
- }
-
- $res = XML::parseString($handshake_xml);
-
- if (!is_object($res)) {
- Logger::info('Unparseable response', ['url' => $url]);
-
- $fields = ['failed' => true, 'last-update' => $updated, 'failure_update' => $updated];
- self::updateContact($contact, $fields);
- Contact::markForArchival($contact);
- return false;
- }
-
- if (intval($res->status) == 1) {
- // we may not be friends anymore. Will keep trying for one month.
- Logger::log("$url replied status 1 - marking for death ");
-
- // set the last-update so we don't keep polling
- $fields = ['failed' => true, 'last-update' => $updated, 'failure_update' => $updated];
- self::updateContact($contact, $fields);
- Contact::markForArchival($contact);
- } elseif ($contact['term-date'] > DBA::NULL_DATETIME) {
- Contact::unmarkForArchival($contact);
- }
-
- if ((intval($res->status) != 0) || !strlen($res->challenge) || !strlen($res->dfrn_id)) {
- // set the last-update so we don't keep polling
- DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
- Logger::log('Contact status is ' . $res->status);
- return false;
- }
-
- if (((float)$res->dfrn_version > 2.21) && ($contact['poco'] == '')) {
- $fields = ['poco' => str_replace('/profile/', '/poco/', $contact['url'])];
- DBA::update('contact', $fields, ['id' => $contact['id']]);
- }
-
- $postvars = [];
-
- $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
- $challenge = hex2bin((string) $res->challenge);
-
- $final_dfrn_id = '';
-
- if ($contact['duplex'] && strlen($contact['prvkey'])) {
- openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']);
- openssl_private_decrypt($challenge, $postvars['challenge'], $contact['prvkey']);