From 033935c19406c8468ed75fdd15a3a532f4e25319 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Tue, 12 Oct 2010 20:29:04 -0700 Subject: [PATCH] cleanup to ensure protocol version is passed properly. We will need it if/when any incompatible protocol changes are introduced. --- include/items.php | 8 ++++---- include/poller.php | 11 +++++++---- mod/dfrn_confirm.php | 2 +- mod/dfrn_notify.php | 14 +++++++++++++- mod/dfrn_poll.php | 29 ++++++++++++++++++----------- mod/dfrn_request.php | 2 +- 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/include/items.php b/include/items.php index ab2fd644a1..7958c78c36 100644 --- a/include/items.php +++ b/include/items.php @@ -517,10 +517,10 @@ function dfrn_deliver($contact,$atom,$debugging = false) { if($contact['duplex'] && $contact['issued-id']) $idtosend = '1:' . $orig_id; - $url = $contact['notify'] . '?dfrn_id=' . $idtosend; + $url = $contact['notify'] . '?dfrn_id=' . $idtosend . '&dfrn_version=' . DFRN_PROTOCOL_VERSION ; if($debugging) - echo "URL: $url"; + echo "URL: $url\n"; $xml = fetch_url($url); @@ -560,8 +560,8 @@ function dfrn_deliver($contact,$atom,$debugging = false) { return 3; } - $postvars['dfrn_id'] = $idtosend; - + $postvars['dfrn_id'] = $idtosend; + $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) { $postvars['data'] = $atom; diff --git a/include/poller.php b/include/poller.php index ff141484bb..bf2803b637 100644 --- a/include/poller.php +++ b/include/poller.php @@ -94,12 +94,15 @@ if(intval($contact['duplex']) && $contact['issued-id']) $idtosend = '1:' . $orig_id; - $url = $contact['poll'] . '?dfrn_id=' . $idtosend . '&type=data&last_update=' . $last_update ; + $url = $contact['poll'] . '?dfrn_id=' . $idtosend + . '&dfrn_version=' . DFRN_PROTOCOL_VERSION + . '&type=data&last_update=' . $last_update ; + $xml = fetch_url($url); if($debugging) { - echo "URL: " . $url . "\r\n"; - echo "XML: " . $xml . "\r\n"; + echo "URL: " . $url . "\n"; + echo "XML: " . $xml . "\n"; } if(! $xml) { @@ -154,7 +157,7 @@ } $postvars['dfrn_id'] = $idtosend; - + $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $xml = post_url($contact['poll'],$postvars); diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 265a62b888..3df36182e1 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -109,7 +109,7 @@ function dfrn_confirm_post(&$a) { $params['public_key'] = bin2hex(openssl_encrypt($public_key,'AES-256-CBC',$src_aes_key)); } - $params['dfrn_version'] = '2.0'; + $params['dfrn_version'] = DFRN_PROTOCOL_VERSION ; if($duplex == 1) $params['duplex'] = 1; diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 4a23da5050..5779b68d2a 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -7,6 +7,7 @@ require_once('include/items.php'); function dfrn_notify_post(&$a) { $dfrn_id = notags(trim($_POST['dfrn_id'])); + $dfrn_version = (float) $_POST['dfrn_version']; $challenge = notags(trim($_POST['challenge'])); $data = $_POST['data']; @@ -374,6 +375,8 @@ function dfrn_notify_content(&$a) { // If this is a duplex communication, ours will be the opposite. $dfrn_id = notags(trim($_GET['dfrn_id'])); + $dfrn_version = (float) $_GET['dfrn_version']; + $direction = (-1); if(strpos($dfrn_id,':') == 1) { @@ -435,7 +438,16 @@ function dfrn_notify_content(&$a) { $challenge = bin2hex($challenge); $encrypted_id = bin2hex($encrypted_id); - echo '' . $status . '2.0' . $encrypted_id . '' . $challenge . '' . "\r\n" ; + header("Content-type: text/xml"); + + echo '' . "\r\n" + . '' . "\r\n" + . "\t" . '' . $status . '' . "\r\n" + . "\t" . '' . DFRN_PROTOCOL_VERSION . '' . "\r\n" + . "\t" . '' . $encrypted_id . '' . "\r\n" + . "\t" . '' . $challenge . '' . "\r\n" + . '' . "\r\n" ; + killme(); } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index a65f6555d3..f5a7619834 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -14,7 +14,7 @@ function dfrn_poll_init(&$a) { $type = $_GET['type']; if(x($_GET,'last_update')) $last_update = $_GET['last_update']; - $dfrn_version = ((x($_GET,'dfrn_version')) ? $_GET['dfrn_version'] : '1.0'); + $dfrn_version = (float) $_GET['dfrn_version'] ; $destination_url = ((x($_GET,'destination_url')) ? $_GET['destination_url'] : ''); @@ -115,11 +115,12 @@ function dfrn_poll_init(&$a) { function dfrn_poll_post(&$a) { - $dfrn_id = $_POST['dfrn_id']; - $challenge = $_POST['challenge']; - $url = $_POST['url']; + $dfrn_id = $_POST['dfrn_id']; + $challenge = $_POST['challenge']; + $url = $_POST['url']; + $dfrn_version = (float) $_POST['dfrn_version']; - $direction = (-1); + $direction = (-1); if(strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); @@ -199,7 +200,7 @@ function dfrn_poll_post(&$a) { "; killme(); - return; // NOTREACHED + // NOTREACHED } else { $o = get_feed_for($a,$dfrn_id, $a->argv[1], $last_update, $direction); @@ -222,6 +223,8 @@ function dfrn_poll_content(&$a) { if(x($_GET,'last_update')) $last_update = $_GET['last_update']; + $dfrn_version = (float) $_GET['dfrn_version']; + $direction = (-1); if(strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); @@ -293,11 +296,15 @@ function dfrn_poll_content(&$a) { else { $status = 1; } - - echo '' .$status . '2.0' . $encrypted_id . '' - . '' . $challenge . '' . "\r\n" ; - session_write_close(); - exit; + header("Content-type: text/xml"); + echo '' . "\r\n" + . '' . "\r\n" + . "\t" . '' .$status . '' . "\r\n" + . "\t" . '' . DFRN_PROTOCOL_VERSION . '' . "\r\n" + . "\t" . '' . $encrypted_id . '' . "\r\n" + . "\t" . '' . $challenge . '' . "\r\n" + . '' . "\r\n" ; + killme(); } } diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index f6a85fbabb..3c16e2560a 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -197,7 +197,7 @@ function dfrn_request_post(&$a) { } - if($network == 'dfrn') { + if($network === 'dfrn') { $ret = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", intval($uid), dbesc($url)