public static function settings_checksum() { $checksum = ""; $checksum .= Sync_Logic::workbench_checksum(); $checksum = md5($checksum); return $checksum; }
// Straightaway clear the Bible action for this chapter. // This atomic operation enables new edits from the user in this chapter to be recorded straightaway, // even during the time that this chapter is still being sent. // In the face of a slow network at times, this does occur in practise. // Examples have been seen. $database_bibleactions->delete($bible, $book, $chapter); // If old USFM and new USFM differ, and the new USFM is not empty, send it to the server. if ($newusfm != $oldusfm && $newusfm != "") { $checksum = Checksum_Logic::get($oldusfm . $newusfm); // It used to send the old and new USFM in compressed form. // But the server failed to decompress it. // That means that compression is not a good option. // Generate a POST request. $post = array("u" => bin2hex($user), "p" => $hash, "bi" => $bible, "bo" => $book, "ch" => $chapter, "o" => $oldusfm, "n" => $newusfm, "s" => $checksum); $url = "{$address}/sync/bible.php"; $response = Sync_Logic::post($post, $url); if ($response === false) { // Communication error. $communication_errors = true; $database_logs->log("Failure sending Bibles", Filter_Roles::TRANSLATOR_LEVEL); // Restore the Bible action for this chapter. $database_bibleactions->delete($bible, $book, $chapter); $database_bibleactions->record($bible, $book, $chapter, $oldusfm); } else { if ($response != "") { // The first line of the response can contain a message as a string. // This is what the server says to the client in case of an error. // Normally the first line of the response contains a numerical value. // This value is the checksum of the data that the server returns in the subsequent lines. // This data would be the updated USFM for the chapter. $response = explode("\n", $response);
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ require_once "../bootstrap/bootstrap.php"; $database_logs = Database_Logs::getInstance(); $database_config_bible = Database_Config_Bible::getInstance(); $database_config_general = Database_Config_General::getInstance(); $database_config_user = Database_Config_User::getInstance(); $database_users = Database_Users::getInstance(); $session_logic = Session_Logic::getInstance(); $username = Filter_Hex::hex2bin($_POST['u']); $session_logic->setUsername($username); $action = $_POST['a']; if ($action == "total") { $checksum = Sync_Logic::settings_checksum(); $checksum = serialize($checksum); echo $checksum; } else { if ($action == Sync_Logic::WORKBENCH_SETTING) { $urls = $database_config_user->getWorkbenchURLs(); $urls = unserialize($urls); $widths = $database_config_user->getWorkbenchWidths(); $widths = unserialize($widths); $heights = $database_config_user->getWorkbenchHeights(); $heights = unserialize($heights); $setting = array(); $setting['urls'] = $urls; $setting['widths'] = $widths; $setting['heights'] = $heights; echo serialize($setting);
$books = $database_usfmresources->getBooks($resource); $books = serialize($books); echo $books; } else { if ($action == "book") { $checksum = Sync_Logic::usfm_resource_book_checksum($resource, $book); $checksum = serialize($checksum); echo $checksum; } else { if ($action == "chapters") { $chapters = $database_usfmresources->getChapters($resource, $book); $chapters = serialize($chapters); echo $chapters; } else { if ($action == "chapter") { $checksum = Sync_Logic::usfm_resource_chapter_checksum($resource, $book, $chapter); $checksum = serialize($checksum); echo $checksum; } else { if ($action == "get") { $contents = $database_usfmresources->getUsfm($resource, $book, $chapter); $contents = serialize($contents); echo $contents; } } } } } } } }
// Get checksum for the chapter on client and on server. // If both are the same, it means the USFM in both is the same, and we're done. $client_checksum = Checksum_Logic::getChapter($bible, $book, $chapter); $post = array("b" => $bible, "bk" => $book, "c" => $chapter, "a" => "chapter"); $server_checksum = Sync_Logic::post($post, $url); if ($server_checksum === false) { $database_logs->log(Locale_Translate::_("Failure getting checksum:") . " {$bible} {$book_name} {$chapter}", Filter_Roles::TRANSLATOR_LEVEL); continue; } if ($client_checksum == $server_checksum) { continue; } // Different checksums: Get the USFM for the chapter as it is on the server. $database_logs->log(Locale_Translate::_("Getting chapter:") . " {$bible} {$book_name} {$chapter}", Filter_Roles::TRANSLATOR_LEVEL); $post = array("b" => $bible, "bk" => $book, "c" => $chapter, "a" => "get"); $server_usfm = Sync_Logic::post($post, $url); if ($server_usfm === false) { $database_logs->log(Locale_Translate::_("Failure getting chapter:") . " {$bible} {$book_name} {$chapter}", Filter_Roles::TRANSLATOR_LEVEL); continue; } // Verify the checksum of the chapter on the server, to be sure there's no corruption during transmission. $server_usfm = explode("\n", $server_usfm); $checksum = array_shift($server_usfm); $server_usfm = implode("\n", $server_usfm); if (!Checksum_Logic::get($server_usfm) == $checksum) { $database_logs->log(Locale_Translate::_("Checksum error while receiving chapter from server:") . " {$bible} {$book_name} {$chapter}", Filter_Roles::TRANSLATOR_LEVEL); continue; } // Check whether the user on the client has made changes in this chapter since the edits were sent to the server. // If there are none, then the client stores the chapter as it gets it from the server, and is done. $old_usfm = $database_bibleactions->getUsfm($bible, $book, $chapter);
} else { if ($action == "resources") { $resources = $database_offlineresources->names(); $resources = serialize($resources); echo $resources; } else { if ($action == "resource") { $checksum = Sync_Logic::offline_resource_checksum($resource); $checksum = serialize($checksum); echo $checksum; } else { if ($action == "files") { $files = $database_offlineresources->files($resource); $files = serialize($files); echo $files; } else { if ($action == "file") { $checksum = Sync_Logic::offline_resource_file_checksum($resource, $file); $checksum = serialize($checksum); echo $checksum; } else { if ($action == "download") { $contents = $database_offlineresources->load($resource, $file); $contents = serialize($contents); echo $contents; } } } } } }
public function testCreateRange() { $ranges = Sync_Logic::create_range(100000000, 999999999); $standard = array(array(100000000, 189999998), array(189999999, 279999997), array(279999998, 369999996), array(369999997, 459999995), array(459999996, 549999994), array(549999995, 639999993), array(639999994, 729999992), array(729999993, 819999991), array(819999992, 909999990), array(909999991, 999999999)); $this->assertEquals($standard, $ranges); $ranges = Sync_Logic::create_range(100000000, 100000100); $standard = array(array(100000000, 100000009), array(100000010, 100000019), array(100000020, 100000029), array(100000030, 100000039), array(100000040, 100000049), array(100000050, 100000059), array(100000060, 100000069), array(100000070, 100000079), array(100000080, 100000089), array(100000090, 100000100)); $this->assertEquals($standard, $ranges); }