From bd90f0965333b247a5e50422d0a1d9292dd9fd5a Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 28 Sep 2008 16:26:50 +0000 Subject: Central: Completed steps 10 and 11 Refs #69 --- central/trunk/includes/instadisc.php | 80 +++++++++++++++++++++-------------- central/trunk/xmlrpc.php | 82 +++++++++++++++++++++++++++++++----- 2 files changed, 121 insertions(+), 41 deletions(-) (limited to 'central/trunk') diff --git a/central/trunk/includes/instadisc.php b/central/trunk/includes/instadisc.php index 1c4c968..1f40b7a 100644 --- a/central/trunk/includes/instadisc.php +++ b/central/trunk/includes/instadisc.php @@ -58,41 +58,22 @@ function instaDisc_sendItem($username, $id) $getuser2 = mysql_query($getuser); $getuser3 = mysql_fetch_array($getuser2); - $fp = @fsockopen($getuser3['ip'], 1204, $errno, $errstr); - if ($fp) + if (($getuser3['downloadItemMode'] == 'Push') && ($getuser3['port'] != 0)) { - $verID = rand(1,2147483647); - - $title = str_replace(': ', '__INSTADISC__', $getitem3['title']); - - $out = 'ID: ' . $id . "\r\n"; - $out .= 'Verification: ' . md5($username . ':' . $getuser3['password'] . ':' . $verID) . "\r\n"; - $out .= 'Verification-ID: ' . $verID . "\r\n"; - $out .= 'Subscription: ' . $getitem3['subscription'] . "\r\n"; - $out .= 'Title: ' . $title . "\r\n"; - $out .= 'Author: ' . $getitem3['author'] . "\r\n"; - $out .= 'URL: ' . $getitem3['url'] . "\r\n"; - - $semantics = unserialize($getitem3['semantics']); - foreach ($semantics as $name => $value) - { - $value = str_replace(': ', '__INSTADISC__', $value); - $out .= $name . ': ' . $value . "\r\n"; - } - - if ($getitem3['encryptionID'] != 0) + $fp = @fsockopen($getuser3['ip'], $getuser3['port'], $errno, $errstr); + if ($fp) { - $out .= 'Encryption-ID: ' . $getitem3['encryptionID'] . "\r\n"; - } + $title = str_replace(': ', '__INSTADISC__', $getitem3['title']); - $out .= "\r\n\r\n"; + $out = instaDisc_formItem($username, $id, "\r\n") . "\r\n\r\n"; - fwrite($fp, $out); - fclose($fp); + fwrite($fp, $out); + fclose($fp); - return true; - } else { - return false; + return true; + } else { + return false; + } } } } @@ -111,7 +92,10 @@ function instaDisc_addItem($username, $subscription, $title, $author, $url, $sem $insitem = "INSERT INTO inbox (username, itemID, subscription, title, author, url, semantics, encryptionID) VALUES (\"" . mysql_real_escape_string($username) . "\", " . $itemID . ", \"" . mysql_real_escape_string($subscription) . "\", \"" . mysql_real_escape_string($title) . "\", \"" . mysql_real_escape_string($author) . "\", \"" . mysql_real_escape_string($url) . "\", \"" . mysql_real_escape_string($semantics) . "\"," . $encryptionID . ")"; $insitem2 = mysql_query($insitem); - instaDisc_sendItem($username, $itemID); + if ($getuser3['downloadItemMode'] == 'Push') + { + instaDisc_sendItem($username, $itemID); + } } } @@ -263,4 +247,38 @@ function instaDisc_initalizePort($username) return $port; } +function instaDisc_formItem($username, $id, $ln = "\n") +{ + $getitem = "SELECT * FROM inbox WHERE username = \"" . mysql_real_escape_string($username) . "\" AND itemID = " . $id; + $getitem2 = mysql_query($getitem); + $getitem3 = mysql_fetch_array($getitem2); + if ($getitem3['username'] == $username) + { + $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\""; + $getuser2 = mysql_query($getuser); + $getuser3 = mysql_fetch_array($getuser2); + + $verID = rand(1,2147483647); + + $out = 'ID: ' . $id . $ln; + $out .= 'Verification: ' . md5($username . ':' . $getuser3['password'] . ':' . $verID) . $ln; + $out .= 'Verification-ID: ' . $verID . $ln; + $out .= 'Subscription: ' . $getitem3['subscription'] . $ln; + $out .= 'Title: ' . $title . $ln; + $out .= 'Author: ' . $getitem3['author'] . $ln; + $out .= 'URL: ' . $getitem3['url'] . $ln; + + $semantics = unserialize($getitem3['semantics']); + foreach ($semantics as $name => $value) + { + $value = str_replace(': ', '__INSTADISC__', $value); + $out .= $name . ': ' . $value . $ln; + } + if ($getitem3['encryptionID'] != 0) + { + $out .= 'Encryption-ID: ' . $getitem3['encryptionID'] . $ln; + } + } +} + ?> diff --git a/central/trunk/xmlrpc.php b/central/trunk/xmlrpc.php index 2e3aa62..0e66940 100644 --- a/central/trunk/xmlrpc.php +++ b/central/trunk/xmlrpc.php @@ -44,9 +44,18 @@ function resendItem($username, $verification, $verificationID, $id) $getitem3 = mysql_fetch_array($getitem2); if ($getitem3['itemID'] == $id) { - instaDisc_sendItem($username, $id); + $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\""; + $getuser2 = mysql_query($getuser); + $getuser3 = mysql_fetch_array($getuser2); + if ($getuser3['downloadItemMode'] == 'Push') + { + instaDisc_sendItem($username, $id); - return new xmlrpcresp(new xmlrpcval(0, "int")); + return new xmlrpcresp(new xmlrpcval(0, "int")); + } else if ($getuser3['downloadItemMode'] == 'Pull') + { + return new xmlrpcresp(new xmlrpcval(instaDisc_formItem($username, $id), 'string')); + } } } @@ -57,24 +66,76 @@ function requestRetained($username, $verification, $verificationID) { if (instaDisc_checkVerification($username, $verification, $verificationID, 'users', 'username', 'password')) { - $getitems = "SELECT * FROM inbox WHERE username = \"" . mysql_real_escape_string($username) . "\""; - $getitems2 = mysql_query($getitems); - $i=0; - while ($getitems3[$i] = mysql_fetch_array($getitems2)) + $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\""; + $getuser2 = mysql_query($getuser); + $getuser3 = mysql_fetch_array($getuser2); + if ($getuser3['downloadItemMode'] == 'Push') + { + $getitems = "SELECT * FROM inbox WHERE username = \"" . mysql_real_escape_string($username) . "\""; + $getitems2 = mysql_query($getitems); + $i=0; + while ($getitems3[$i] = mysql_fetch_array($getitems2)) + { + if (!instaDisc_sendItem($username, $getitems3[$i]['itemID'])) + { + return new xmlrpcresp(new xmlrpcval(1, "int")); + } + $i++; + } + + return new xmlrpcresp(new xmlrpcval(0, "int")); + } else if ($getuser3['downloadItemMode'] == 'Pull') { - if (!instaDisc_sendItem($username, $getitems3[$i]['itemID'])) + $getitems = "SELECT * FROM inbox WHERE username = \"" . mysql_real_escape_string($username) . "\" LIMIT 0,2"; + $getitems2 = mysql_query($getitems); + $getitems3 = mysql_fetch_array($getitems2); + $getitems4 = mysql_fetch_array($getitems2); + if ($getitems3['username'] == $username) { - return new xmlrpcresp(new xmlrpcval(1, "int")); + $item = instaDisc_formItem($username, $getitems3['id']); + if ($getitems4['username'] == $username) + { + $item .= 'More: ' . $getitems4['id'] . "\n"; + } + + return new xmlrpcresp(new xmlrpcval($item, 'string')); } - $i++; } + } - return new xmlrpcresp(new xmlrpcval(0, "int")); + return new xmlrpcresp(new xmlrpcval(1, "int")); +} + +function sendItem($username, $verification, $verificationID, $id) +{ + if (instaDisc_checkVerification($username, $verification, $verificationID, 'users', 'username', 'password')) + { + $getuser = "SELECT * FROM users WHERE username = \"" . mysql_real_escape_string($username) . "\""; + $getuser2 = mysql_query($getuser); + $getuser3 = mysql_fetch_array($getuser2); + if ($getuser3['downloadItemMode'] == 'Pull') + { + $getitems = "SELECT * FROM inbox WHERE username = \"" . mysql_real_escape_string($username) . "\" AND itemID > " . ($id-1) . " LIMIT 0,2"; + $getitems2 = mysql_query($getitems); + $getitems3 = mysql_fetch_array($getitems2); + $getitems4 = mysql_fetch_array($getitems2); + if ($getitems3['username'] == $username) + { + $item = instaDisc_formItem($username, $getitems3['id']); + if ($getitems4['username'] == $username) + { + $item .= 'More: ' . $getitems4['id'] . "\n"; + } + + return new xmlrpcresp(new xmlrpcval($item, 'string')); + } + } } return new xmlrpcresp(new xmlrpcval(1, "int")); } + function sendFromUpdate($subscriptionURL, $title, $author, $url, $semantics, $encryptionID) { $getsed = "SELECT * FROM subscriptions WHERE url = \"" . mysql_real_escape_string($subscriptionURL) . "\""; @@ -180,6 +241,7 @@ $s = new xmlrpc_server( array( "InstaDisc.checkRegistration" => array("function" "InstaDisc.deleteItem" => array("function" => "deleteItem"), "InstaDisc.resendItem" => array("function" => "resendItem"), "InstaDisc.requestRetained" => array("function" => "requestRetained"), + "InstaDisc.sendItem" => array("function" => "sendItem"), "InstaDisc.sendFromUpdate" => array("function" => "sendFromUpdate"), "InstaDisc.deleteSubscription" => array("function" => "deleteSubscription"), "InstaDisc.addSubscription" => array("function" => "addSubscription"), -- cgit 1.4.1