From efdac9ed68cf6bd819c4c030335cd5baa4e16de7 Mon Sep 17 00:00:00 2001 From: Teus Benschop Date: Fri, 26 Jan 2024 10:36:00 +0100 Subject: [PATCH] Updates needed for new macOS port https://github.com/bibledit/cloud/issues/920 --- mimetic098/message.h | 4 +- mimetic098/os/file_iterator.cxx | 4 +- mimetic098/os/fileop.cxx | 8 +- mimetic098/os/stdfile.cxx | 4 +- pkgdata/files.txt | 5 - read/save.cpp | 179 ----------------- read/save.h | 32 --- read/update.cpp | 344 -------------------------------- read/update.h | 32 --- 9 files changed, 10 insertions(+), 602 deletions(-) delete mode 100644 read/save.cpp delete mode 100644 read/save.h delete mode 100644 read/update.cpp delete mode 100644 read/update.h diff --git a/mimetic098/message.h b/mimetic098/message.h index 5446909cd..eebd536f8 100644 --- a/mimetic098/message.h +++ b/mimetic098/message.h @@ -14,9 +14,9 @@ #include #include #include -#ifdef HAVE_UNISTD_H +//#ifdef HAVE_UNISTD_H #include -#endif +//#endif namespace mimetic { diff --git a/mimetic098/os/file_iterator.cxx b/mimetic098/os/file_iterator.cxx index 1641c4862..9e1bee780 100644 --- a/mimetic098/os/file_iterator.cxx +++ b/mimetic098/os/file_iterator.cxx @@ -90,9 +90,9 @@ #ifdef HAVE_DIRENT_H #include #endif -#ifdef HAVE_UNISTD_H +//#ifdef HAVE_UNISTD_H #include -#endif +//#endif #ifdef HAVE_SYS_TIME_H #include #endif diff --git a/mimetic098/os/fileop.cxx b/mimetic098/os/fileop.cxx index f9113b840..33a97cd1b 100644 --- a/mimetic098/os/fileop.cxx +++ b/mimetic098/os/fileop.cxx @@ -75,15 +75,15 @@ ***************************************************************************/ #include #include -#ifdef HAVE_UNISTD_H +//#ifdef HAVE_UNISTD_H #include -#endif +//#endif #ifdef HAVE_SYS_TYPES_H #include #endif -#ifdef HAVE_SYS_STAT_H +//#ifdef HAVE_SYS_STAT_H #include -#endif +//#endif using namespace std; diff --git a/mimetic098/os/stdfile.cxx b/mimetic098/os/stdfile.cxx index 7e175647d..eb2e710f8 100644 --- a/mimetic098/os/stdfile.cxx +++ b/mimetic098/os/stdfile.cxx @@ -86,9 +86,9 @@ #ifdef HAVE_DIRENT_H #include #endif -#ifdef HAVE_UNISTD_H +//#ifdef HAVE_UNISTD_H #include -#endif +//#endif using namespace std; diff --git a/pkgdata/files.txt b/pkgdata/files.txt index 9366051a1..897e2ffad 100644 --- a/pkgdata/files.txt +++ b/pkgdata/files.txt @@ -31,11 +31,6 @@ /book /book/books.js /bootstrap -/build -/build/confyLGTNU -/build/confyLGTNU/defines.awk -/build/confyLGTNU/subs1.awk -/build/confyLGTNU/subs.awk /changes /changes/change.html /changes/changes.html diff --git a/read/save.cpp b/read/save.cpp deleted file mode 100644 index 97f0dd195..000000000 --- a/read/save.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - Copyright (©) 2003-2021 Teus Benschop. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - 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. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -string editone2_save_url () -{ - return "editone2/save"; -} - - -bool editone2_save_acl (void * webserver_request) -{ -#ifdef HAVE_INDONESIANCLOUDFREE - return true; -#endif - if (Filter_Roles::access_control (webserver_request, Filter_Roles::translator ())) return true; - bool read, write; - access_a_bible (webserver_request, read, write); - return read; -} - - -string editone2_save (void * webserver_request) -{ - Webserver_Request * request = (Webserver_Request *) webserver_request; - - - // Check on information about where to save the verse. - bool save = (request->post.count ("bible") && request->post.count ("book") && request->post.count ("chapter") && request->post.count ("verse") && request->post.count ("html")); - if (!save) { - return translate("Don't know where to save"); - } - - - string bible = request->post["bible"]; - int book = convert_to_int (request->post["book"]); - int chapter = convert_to_int (request->post["chapter"]); - int verse = convert_to_int (request->post["verse"]); - string html = request->post["html"]; - string checksum = request->post["checksum"]; - string unique_id = request->post ["id"]; - - - // Checksum. - if (Checksum_Logic::get (html) != checksum) { - request->response_code = 409; - return translate ("Checksum error"); - } - - - // Decode html encoded in javascript. - html = filter_url_tag_to_plus (html); - - - // Check there's anything to save at all. - html = filter_string_trim (html); - if (html.empty ()) { - return translate ("Nothing to save"); - } - - - // Check on valid UTF-8. - if (!unicode_string_is_valid (html)) { - return translate ("Cannot save: Needs Unicode"); - } - - - if (!access_bible_book_write (request, "", bible, book)) { - return translate ("No write access"); - } - - - string stylesheet = Database_Config_Bible::getEditorStylesheet (bible); - - - string verse_usfm = editone_logic_html_to_usfm (stylesheet, html); - - - // Collect some data about the changes for this user. - string username = request->session_logic()->currentUser (); -#ifdef HAVE_CLOUD - int oldID = request->database_bibles()->getChapterId (bible, book, chapter); -#endif - string old_chapter_usfm = request->database_bibles()->getChapter (bible, book, chapter); - - - // If the most recent save operation on this chapter - // caused the chapter to be different, email the user, - // suggesting to check if the user's edit came through. - // The rationale is that if Bible text was saved through Send/receive, - // or if another user saved Bible text, - // it's worth to check on this. - // Because the user's editor may not yet have loaded this updated Bible text. - // https://github.com/bibledit/cloud/issues/340 - string loaded_usfm = getLoadedUsfm2 (webserver_request, bible, book, chapter, unique_id); - if (loaded_usfm != old_chapter_usfm) { - bible_logic_recent_save_email (bible, book, chapter, verse, username, loaded_usfm, old_chapter_usfm); - } - - - // Safely store the verse. - string explanation; - string message = usfm_safely_store_verse (request, bible, book, chapter, verse, verse_usfm, explanation, true); - bible_logic_unsafe_save_mail (message, explanation, username, verse_usfm); - // If storing the verse worked out well, there's no message to display. - if (message.empty ()) { - // Get the chapter text now, that is, after the save operation completed. - string new_chapter_usfm = request->database_bibles()->getChapter (bible, book, chapter); - // Check whether the text on disk was changed while the user worked with the older copy. - if (!loaded_usfm.empty () && (loaded_usfm != old_chapter_usfm)) { - // Do a merge for better editing reliability. - vector conflicts; - // Prioritize the USFM already in the chapter. - new_chapter_usfm = filter_merge_run (loaded_usfm, new_chapter_usfm, old_chapter_usfm, true, conflicts); - request->database_bibles()->storeChapter (bible, book, chapter, new_chapter_usfm); - Database_Logs::log (translate ("Merging chapter.")); - } -#ifdef HAVE_CLOUD - // The Cloud stores details of the user's changes. - int newID = request->database_bibles()->getChapterId (bible, book, chapter); - Database_Modifications database_modifications; - database_modifications.recordUserSave (username, bible, book, chapter, oldID, old_chapter_usfm, newID, new_chapter_usfm); - if (sendreceive_git_repository_linked (bible)) { - Database_Git::store_chapter (username, bible, book, chapter, old_chapter_usfm, new_chapter_usfm); - } - rss_logic_schedule_update (username, bible, book, chapter, old_chapter_usfm, new_chapter_usfm); -#endif - - - // Store a copy of the USFM now saved as identical to what's loaded in the editor for later reference. - storeLoadedUsfm2 (webserver_request, bible, book, chapter, unique_id); - - return locale_logic_text_saved (); - } - - - // The message contains information about save failure. - // Send it to the browser for display to the user. - return message; -} diff --git a/read/save.h b/read/save.h deleted file mode 100644 index 81b4b27b3..000000000 --- a/read/save.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (©) 2003-2021 Teus Benschop. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - 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. - */ - - -#ifndef INCLUDED_EDITONE2_SAVE_H -#define INCLUDED_EDITONE2_SAVE_H - - -#include - - -string editone2_save_url (); -bool editone2_save_acl (void * webserver_request); -string editone2_save (void * webserver_request); - - -#endif diff --git a/read/update.cpp b/read/update.cpp deleted file mode 100644 index dba4273c1..000000000 --- a/read/update.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/* - Copyright (©) 2003-2021 Teus Benschop. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - 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. - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -string editone2_update_url () -{ - return "editone2/update"; -} - - -bool editone2_update_acl (void * webserver_request) -{ -#ifdef HAVE_INDONESIANCLOUDFREE - return true; -#endif - if (Filter_Roles::access_control (webserver_request, Filter_Roles::translator ())) return true; - bool read, write; - access_a_bible (webserver_request, read, write); - return read; -} - - -string editone2_update (void * webserver_request) -{ - Webserver_Request * request = (Webserver_Request *) webserver_request; - - - // Whether the update is good to go. - bool good2go = true; - - - // The messages to return. - vector messages; - - - // Check the relevant bits of information. - if (good2go) { - bool parameters_ok = true; - if (!request->post.count ("bible")) parameters_ok = false; - if (!request->post.count ("book")) parameters_ok = false; - if (!request->post.count ("chapter")) parameters_ok = false; - if (!request->post.count ("verse")) parameters_ok = false; - if (!request->post.count ("loaded")) parameters_ok = false; - if (!request->post.count ("edited")) parameters_ok = false; - if (!parameters_ok) { - messages.push_back (translate("Don't know what to update")); - good2go = false; - } - } - - - // Get the relevant bits of information. - string bible; - int book = 0; - int chapter = 0; - int verse = 0; - string loaded_html; - string edited_html; - string checksum1; - string checksum2; - string unique_id; - if (good2go) { - bible = request->post["bible"]; - book = convert_to_int (request->post["book"]); - chapter = convert_to_int (request->post["chapter"]); - verse = convert_to_int (request->post["verse"]); - loaded_html = request->post["loaded"]; - edited_html = request->post["edited"]; - checksum1 = request->post["checksum1"]; - checksum2 = request->post["checksum2"]; - unique_id = request->post ["id"]; - } - - - // Checksums of the loaded and edited html. - if (good2go) { - if (Checksum_Logic::get (loaded_html) != checksum1) { - request->response_code = 409; - messages.push_back (translate ("Checksum error")); - good2go = false; - } - } - if (good2go) { - if (Checksum_Logic::get (edited_html) != checksum2) { - request->response_code = 409; - messages.push_back (translate ("Checksum error")); - good2go = false; - } - } - - - // Decode html encoded in javascript, and clean it. - loaded_html = filter_url_tag_to_plus (loaded_html); - edited_html = filter_url_tag_to_plus (edited_html); - loaded_html = filter_string_trim (loaded_html); - edited_html = filter_string_trim (edited_html); - - // Check on valid UTF-8. - if (good2go) { - if (!unicode_string_is_valid (loaded_html) || !unicode_string_is_valid (edited_html)) { - messages.push_back (translate ("Cannot update: Needs Unicode")); - good2go = false; - } - } - - - bool bible_write_access = false; - if (good2go) { - bible_write_access = access_bible_book_write (request, "", bible, book); - } - - - string stylesheet; - if (good2go) stylesheet = Database_Config_Bible::getEditorStylesheet (bible); - - - // Collect some data about the changes for this user. - string username = request->session_logic()->currentUser (); -#ifdef HAVE_CLOUD - int oldID = 0; - if (good2go) oldID = request->database_bibles()->getChapterId (bible, book, chapter); -#endif - string old_chapter_usfm; - if (good2go) old_chapter_usfm = request->database_bibles()->getChapter (bible, book, chapter); - - - // Determine what (composed) version of USFM to save to the chapter. - // Do a three-way merge to obtain that USFM. - // This needs the loaded USFM as the ancestor, - // the edited USFM as a change-set, - // and the existing USFM as a prioritized change-set. - string loaded_verse_usfm = editone_logic_html_to_usfm (stylesheet, loaded_html); - string edited_verse_usfm = editone_logic_html_to_usfm (stylesheet, edited_html); - string existing_verse_usfm = usfm_get_verse_text_quill (old_chapter_usfm, verse); - existing_verse_usfm = filter_string_trim (existing_verse_usfm); - - // Set a flag if there is a reason to save the editor text, since it was edited. - // This is important because the same routine is used for saving editor text - // as well as updating the editor text. - // So if the text in the editor was not changed, it should not save it, - // as saving the editor text would overwrite saves made by other(s). - bool text_was_edited = (loaded_verse_usfm != edited_verse_usfm); - - - // Do a three-way merge if needed. - // There's a need for this if there were user-edits, - // and if the USFM on the server differs from the USFM loaded in the editor. - // The three-way merge reconciles those differences. - if (good2go && bible_write_access && text_was_edited) { - if (loaded_verse_usfm != existing_verse_usfm) { - vector conflicts; - // Do a merge while giving priority to the USFM already in the chapter. - string merged_verse_usfm = filter_merge_run (loaded_verse_usfm, edited_verse_usfm, existing_verse_usfm, true, conflicts); - // Mail the user if there is a merge anomaly. - bible_logic_optional_merge_irregularity_email (bible, book, chapter, username, loaded_verse_usfm, edited_verse_usfm, merged_verse_usfm); - // Let the merged data now become the edited data (so it gets saved properly). - edited_verse_usfm = merged_verse_usfm; - } - } - - - // Safely store the verse. - string explanation; - string message; - if (good2go && bible_write_access && text_was_edited) { - message = usfm_safely_store_verse (request, bible, book, chapter, verse, edited_verse_usfm, explanation, true); - bible_logic_unsafe_save_mail (message, explanation, username, edited_verse_usfm); - } - - - // The new chapter identifier and new chapter USFM. - int newID = request->database_bibles()->getChapterId (bible, book, chapter); - string new_chapter_usfm; - if (good2go) { - new_chapter_usfm = request->database_bibles()->getChapter (bible, book, chapter); - } - - - if (good2go && bible_write_access && text_was_edited) { - // If storing the verse worked out well, there's no message to display. - if (message.empty ()) { -#ifdef HAVE_CLOUD - // The Cloud stores details of the user's changes. - Database_Modifications database_modifications; - database_modifications.recordUserSave (username, bible, book, chapter, oldID, old_chapter_usfm, newID, new_chapter_usfm); - if (sendreceive_git_repository_linked (bible)) { - Database_Git::store_chapter (username, bible, book, chapter, old_chapter_usfm, new_chapter_usfm); - } - rss_logic_schedule_update (username, bible, book, chapter, old_chapter_usfm, new_chapter_usfm); -#endif - // Feedback to user. - messages.push_back (locale_logic_text_saved ()); - } else { - // Feedback about anomaly to user. - messages.push_back (message); - } - } - - - // If there's no message at all, return at least something to the editor. - if (messages.empty ()) messages.push_back (locale_logic_text_updated()); - - - // The response to send to back to the editor. - string response; - string separator = "#_be_#"; - // The response starts with the save message(s) if any. - // The message(s) contain information about save success or failure. - // Send it to the browser for display to the user. - response.append (filter_string_implode (messages, " | ")); - - - // Add separator and the new chapter identifier to the response. - response.append (separator); - response.append (convert_to_string (newID)); - - - // The main purpose of the following block of code is this: - // To send the differences between what the editor has now and what the server has now. - // The purpose of sending the differences to the editor is this: - // The editor can update its contents, so the editor will have what the server has. - // This is the format to send the changes in: - // insert - position - text - format - // delete - position - if (good2go) { - // Determine the server's current verse content, and the editor's current verse content. - string editor_html (edited_html); - string server_html; - { - string verse_usfm = usfm_get_verse_text_quill (new_chapter_usfm, verse); - editone_logic_editable_html (verse_usfm, stylesheet, server_html); - } - vector positions; - vector sizes; - vector operators; - vector content; - bible_logic_html_to_editor_updates (editor_html, server_html, positions, sizes, operators, content); - // Encode the condensed differences for the response to the Javascript editor. - for (size_t i = 0; i < positions.size(); i++) { - response.append ("#_be_#"); - response.append (convert_to_string (positions[i])); - response.append ("#_be_#"); - string operation = operators[i]; - response.append (operation); - if (operation == bible_logic_insert_operator ()) { - string text = content[i]; - string character = unicode_string_substr (text, 0, 1); - response.append ("#_be_#"); - response.append (character); - size_t length = unicode_string_length (text); - string format = unicode_string_substr (text, 1, length - 1); - response.append ("#_be_#"); - response.append (format); - // Also add the size of the character in UTF-16 format, 2-bytes or 4 bytes, as size 1 or 2. - response.append ("#_be_#"); - response.append (convert_to_string (sizes[i])); - } - else if (operation == bible_logic_delete_operator ()) { - // When deleting a UTF-16 character encoded in 4 bytes, - // then the size in Quilljs is 2 instead of 1. - // So always give the size when deleting a character. - response.append ("#_be_#"); - response.append (convert_to_string (sizes[i])); - } - else if (operation == bible_logic_format_paragraph_operator ()) { - response.append ("#_be_#"); - response.append (content[i]); - } - else if (operation == bible_logic_format_character_operator ()) { - response.append ("#_be_#"); - response.append (content[i]); - } - } - } - - // Things to try out in the C++ and Javacript update routines. - - // Test changing the format of the first paragraph. - - // Test changing the format of the second paragraph. - - // Test changing the format of the last paragraph. - - // Test deleting an entire paragraph. - - // Test adding a character to a formatted word, to see if the character format gets transferred properly. - - // Test that if this editor is the second or higher one in a workspace, - // it is read-only. And updating the editor's contents does not grab focus. - - // Test inserting and updating 4-byte UTF-16 characters like the 😀. - - // Test continued typing during serious network latency. - - // Test using the Cloud together with client devices with send and receive. - - bool write = access_bible_book_write (webserver_request, username, bible, book); - response = Checksum_Logic::send (response, write); - - // Ready. - //this_thread::sleep_for(chrono::seconds(60)); - return response; -} diff --git a/read/update.h b/read/update.h deleted file mode 100644 index 61e69a904..000000000 --- a/read/update.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (©) 2003-2021 Teus Benschop. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - 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. - */ - - -#ifndef INCLUDED_EDITONE2_UPDATE_H -#define INCLUDED_EDITONE2_UPDATE_H - - -#include - - -string editone2_update_url (); -bool editone2_update_acl (void * webserver_request); -string editone2_update (void * webserver_request); - - -#endif