+ // No XML at all, this exchange is messed up really bad.
+ // We shouldn't proceed, because the xml parser might choke,
+ // and $status is going to be zero, which indicates success.
+ // We can hardly call this a success.
+
+ notice( t('Response from remote site was not understood.') . EOL);
+ return;
+ }
+
+ if(strlen($leading_junk) && get_config('system','debugging')) {
+
+ // This might be more common. Mixed error text and some XML.
+ // If we're configured for debugging, show the text. Proceed in either case.
+
+ notice( t('Unexpected response from remote site: ') . EOL . $leading_junk . EOL );
+ }
+
+ $xml = simplexml_load_string($res);
+ $status = (int) $xml->status;
+ $message = unxmlify($xml->message); // human readable text of what may have gone wrong.
+ switch($status) {
+ case 0:
+ notice( t("Confirmation completed successfully.") . EOL);
+ if(strlen($message))
+ notice( t('Remote site reported: ') . $message . EOL);
+ break;
+ case 1:
+ // birthday paradox - generate new dfrn-id and fall through.
+ $new_dfrn_id = random_string();
+ $r = q("UPDATE contact SET `issued-id` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ dbesc($new_dfrn_id),
+ intval($contact_id),
+ intval($uid)
+ );
+
+ case 2:
+ notice( t("Temporary failure. Please wait and try again.") . EOL);
+ if(strlen($message))
+ notice( t('Remote site reported: ') . $message . EOL);
+ break;
+
+
+ case 3:
+ notice( t("Introduction failed or was revoked.") . EOL);
+ if(strlen($message))
+ notice( t('Remote site reported: ') . $message . EOL);
+ break;