Skip to content

Commit

Permalink
Typo. Some more output in dtcreaterecipient. Signal failure when impo…
Browse files Browse the repository at this point in the history
…rtcontacts fails to import identitykey.
  • Loading branch information
bepaald committed Nov 8, 2024
1 parent 242c983 commit 1c469f8
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion autoversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
#ifndef VERSION_H_
#define VERSION_H_

#define VERSIONDATE "20241106.115704"
#define VERSIONDATE "20241108.155451"

#endif
2 changes: 1 addition & 1 deletion main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int main(int argc, char *argv[])
return 1;

if (!dummydb.importFromDesktop(ddb, true /*arg.skipmessagereorder()*/, arg.limittodates(), true /*addincompletedata*/,
true /*importcontacts*/, false /*autolimittodates*/, true /*importstickers*/, arg.setselfid()))
false /*importcontacts*/, false /*autolimittodates*/, true /*importstickers*/, arg.setselfid()))
return 1;

if (!arg.exportdesktophtml().empty())
Expand Down
41 changes: 33 additions & 8 deletions signalbackup/dtcreaterecipient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ long long int SignalBackup::dtCreateRecipient(SqliteDB const &ddb,
std::string const &id, std::string const &phone, std::string const &groupidb64,
std::string const &databasedir,
std::map<std::string, long long int> *recipient_info,
bool *was_warned)
bool create_valid_contacts, bool *was_warned)
{

//std::cout << "Creating new recipient for id: " << id << ", phone: " << phone << std::endl;
std::string printable_uuid(id);
unsigned int offset = (STRING_STARTS_WITH(id, "__signal_group__v2__!") ? STRLEN("__signal_group__v2__!") + 4 :
(STRING_STARTS_WITH(id, "__textsecure_group__!") ? STRLEN("__textsecure_group__!") + 4 : 4));
if (offset < id.size()) [[likely]]
std::replace_if(printable_uuid.begin() + offset, printable_uuid.end(), [](char c){ return c != '-'; }, 'x');
else
printable_uuid = "xxx";
Logger::message("Creating new recipient for id: ", printable_uuid);

SqliteDB::QueryResults res;
if (!ddb.exec("SELECT "
Expand Down Expand Up @@ -162,7 +168,7 @@ long long int SignalBackup::dtCreateRecipient(SqliteDB const &ddb,
{
if (d_verbose) [[unlikely]]
Logger::message("Creating group member...");
member_rid = dtCreateRecipient(ddb, mem("member"), std::string(), std::string(), databasedir, recipient_info, was_warned);
member_rid = dtCreateRecipient(ddb, mem("member"), std::string(), std::string(), databasedir, recipient_info, create_valid_contacts, was_warned);
if (member_rid == -1)
{
Logger::error("Failed to get new groups members uuid.");
Expand Down Expand Up @@ -293,7 +299,7 @@ long long int SignalBackup::dtCreateRecipient(SqliteDB const &ddb,
if (!dtSetAvatar(res("avatar"), res("localKey"), res.valueAsInt(0, "size"), res.valueAsInt(0, "version"), new_rec_id, databasedir))
Logger::warning("Failed to set avatar for new recipient.");

Logger::message("Succesfully created new recipient for group (id: ", new_rec_id, ").");
Logger::message("Successfully created new recipient for group (id: ", new_rec_id, ").");
return new_rec_id; //-1;
}

Expand Down Expand Up @@ -343,6 +349,7 @@ long long int SignalBackup::dtCreateRecipient(SqliteDB const &ddb,
if (new_rid.type() != typeid(long long int))
{
Logger::error("New recipient _id has unexpected type.");
d_database.exec("DELETE FROM recipient WHERE _id = ?", new_rid);
return -1;
}
long long int new_rec_id = std::any_cast<long long int>(new_rid);
Expand All @@ -361,12 +368,30 @@ long long int SignalBackup::dtCreateRecipient(SqliteDB const &ddb,
{"timestamp", res.value(0, "timestamp")},
{"verified", res.value(0, "verified")},
{"nonblocking_approval", res("nonblockingApproval")}}))
Logger::warning("Failed to insert identity key for newly created recipient entry.");
{
if (create_valid_contacts)
{
Logger::error("Failed to insert identity key for newly created recipient entry.");
d_database.exec("DELETE FROM recipient WHERE _id = ?", new_rid);
return -1;
}
else
Logger::warning("Failed to insert identity key for newly created recipient entry.");
}
}
else
Logger::warning("Newly created contact has no UUID");
{
if (create_valid_contacts)
{
Logger::error("Newly created contact has no UUID");
d_database.exec("DELETE FROM recipient WHERE _id = ?", new_rid);
return -1;
}
else
Logger::warning("Newly created contact has no UUID");
}

Logger::message("Succesfully created new recipient (id: ", new_rec_id, ").");
Logger::message("Successfully created new recipient (id: ", new_rec_id, ").");
//d_database.printLineMode("SELECT * FROM recipient WHERE _id = ?", new_rec_id);
return new_rec_id;
}
Expand Down
6 changes: 3 additions & 3 deletions signalbackup/dtsetmessagedeliveryreceipts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

void SignalBackup::dtSetMessageDeliveryReceipts(SqliteDB const &ddb, long long int rowid, std::map<std::string, long long int> *savedmap,
std::string const &databasedir, bool createcontacts, long long int msg_id, bool is_mms,
bool isgroup, bool *warn)
bool isgroup, bool create_valid_contacts, bool *warn)
{
// public static final int STATUS_UNKNOWN = -1;
// public static final int STATUS_UNDELIVERED = 0;
Expand Down Expand Up @@ -78,7 +78,7 @@ void SignalBackup::dtSetMessageDeliveryReceipts(SqliteDB const &ddb, long long i
{
if (createcontacts)
{
if ((member_id = dtCreateRecipient(ddb, status_results.valueAsString(i, "uuid"), std::string(), std::string(), databasedir, savedmap, warn)) == -1)
if ((member_id = dtCreateRecipient(ddb, status_results.valueAsString(i, "uuid"), std::string(), std::string(), databasedir, savedmap, create_valid_contacts, warn)) == -1)
{
Logger::error("Failed to create delivery_receipt member. Skipping");
continue;
Expand Down Expand Up @@ -112,7 +112,7 @@ void SignalBackup::dtSetMessageDeliveryReceipts(SqliteDB const &ddb, long long i
{
if (createcontacts)
{
if ((member_id = dtCreateRecipient(ddb, status_results.valueAsString(i, "uuid"), std::string(), std::string(), databasedir, savedmap, warn)) == -1)
if ((member_id = dtCreateRecipient(ddb, status_results.valueAsString(i, "uuid"), std::string(), std::string(), databasedir, savedmap, create_valid_contacts, warn)) == -1)
{
Logger::error("Failed to create delivery_receipt member. Skipping");
continue;
Expand Down
6 changes: 3 additions & 3 deletions signalbackup/handledtgroupv1migration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
bool SignalBackup::handleDTGroupV1Migration(SqliteDB const &ddb, long long int rowid,
long long int thread_id, long long int timestamp, long long int address,
std::map<std::string, long long int> *recipientmap, bool createcontacts,
std::string const &databasedir, bool *warned_createcontacts)
std::string const &databasedir, bool create_valid_contacts, bool *warned_createcontacts)
{
// get a list of dropped members (I _think_ these are not recipient uuid's but conversationUuid's...)
std::string dropped_members;
Expand Down Expand Up @@ -50,7 +50,7 @@ bool SignalBackup::handleDTGroupV1Migration(SqliteDB const &ddb, long long int r

if (createcontacts)
recid = dtCreateRecipient(ddb, dm_id.valueAsString(0, "rid"), dm_id.valueAsString(0, "rid"), std::string(),
databasedir, recipientmap, warned_createcontacts);
databasedir, recipientmap, create_valid_contacts, warned_createcontacts);
if (recid < 0)
continue;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ bool SignalBackup::handleDTGroupV1Migration(SqliteDB const &ddb, long long int r

if (createcontacts)
recid = dtCreateRecipient(ddb, im_id.valueAsString(0, "rid"), im_id.valueAsString(0, "rid"), std::string(),
databasedir, recipientmap, warned_createcontacts);
databasedir, recipientmap, create_valid_contacts, warned_createcontacts);
if (recid < 0)
continue;
}
Expand Down
23 changes: 13 additions & 10 deletions signalbackup/importfromdesktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@

bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtdb, bool skipmessagereorder,
std::vector<std::string> const &daterangelist, bool createmissingcontacts,
bool createmissingcontacts_nowarn, bool autodates, bool importstickers,
bool createmissingcontacts_valid, bool autodates, bool importstickers,
std::string const &selfphone)
{
if (d_selfid == -1)
Expand Down Expand Up @@ -273,7 +273,7 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd
datewhereclause += ')';
}

bool warned_createcontacts = createmissingcontacts_nowarn;
bool warned_createcontacts = createmissingcontacts_valid; // no warning if explicitly requesting this...

// find out which database is newer
long long int maxdate_desktop_db = dtdb->d_database.getSingleResultAs<long long int>("SELECT MAX(MAX(json_extract(json, '$.received_at_ms')),MAX(received_at)) FROM messages", 0);
Expand Down Expand Up @@ -414,7 +414,7 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd
{
recipientid_for_thread = dtCreateRecipient(dtdb->d_database, person_or_group_id, results_all_conversations.valueAsString(i, "e164"),
results_all_conversations.valueAsString(i, "groupId"), databasedir, &recipientmap,
&warned_createcontacts);
createmissingcontacts_valid, &warned_createcontacts);
if (recipientid_for_thread == -1)
{
Logger::warning("Failed to create missing recipient. Skipping.");
Expand Down Expand Up @@ -613,8 +613,8 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd
if (createmissingcontacts)
{
if ((address = dtCreateRecipient(dtdb->d_database, source_uuid, source_phone,
std::string(), databasedir,
&recipientmap, &warned_createcontacts)) == -1)
std::string(), databasedir, &recipientmap,
createmissingcontacts_valid, &warned_createcontacts)) == -1)
{
Logger::error("Failed to create contact for incoming group message. Skipping");
continue;
Expand Down Expand Up @@ -672,7 +672,7 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd
if (!handleDTGroupV1Migration(dtdb->d_database, rowid, ttid,
results_all_messages_from_conversation.getValueAs<long long int>(j, "sent_at"),
recipientid_for_thread, &recipientmap, createmissingcontacts, databasedir,
&warned_createcontacts))
createmissingcontacts_valid, &warned_createcontacts))
return false;

}
Expand Down Expand Up @@ -1444,7 +1444,7 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd
if (createmissingcontacts)
{
if (dtCreateRecipient(dtdb->d_database, qbrres.valueAsString(0, "qbr_uuid"), std::string(), std::string(),
databasedir, &recipientmap, &warned_createcontacts) == -1)
databasedir, &recipientmap, createmissingcontacts_valid, &warned_createcontacts) == -1)
{
if (d_verbose) [[unlikely]] Logger::message_end();
Logger::warning("Failed to create recipient for quote-mention. Skipping.");
Expand Down Expand Up @@ -1625,7 +1625,8 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd

if (outgoing)
dtSetMessageDeliveryReceipts(dtdb->d_database, rowid, &recipientmap, databasedir, createmissingcontacts,
new_mms_id, true/*mms*/, isgroupconversation, &warned_createcontacts);
new_mms_id, true/*mms*/, isgroupconversation, createmissingcontacts_valid,
&warned_createcontacts);

// insert into reactions
if (d_verbose) [[unlikely]] Logger::message_start("Inserting reactions...");
Expand Down Expand Up @@ -1659,7 +1660,8 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd
{
if (createmissingcontacts)
{
if ((rec_id = dtCreateRecipient(dtdb->d_database, results_mentions("mention_uuid"), std::string(), std::string(), databasedir, &recipientmap, &warned_createcontacts)) == -1)
if ((rec_id = dtCreateRecipient(dtdb->d_database, results_mentions("mention_uuid"), std::string(), std::string(),
databasedir, &recipientmap, createmissingcontacts_valid, &warned_createcontacts)) == -1)
{
if (d_verbose) [[unlikely]] Logger::message_end();
Logger::warning("Failed to create recipient for mention. Skipping.");
Expand Down Expand Up @@ -1721,7 +1723,8 @@ bool SignalBackup::importFromDesktop(std::unique_ptr<DesktopDatabase> const &dtd
// set delivery/read counts
if (outgoing)
dtSetMessageDeliveryReceipts(dtdb->d_database, rowid, &recipientmap, databasedir, createmissingcontacts,
new_sms_id, false/*mms*/, isgroupconversation, &warned_createcontacts);
new_sms_id, false/*mms*/, isgroupconversation, createmissingcontacts_valid,
&warned_createcontacts);

// insert into reactions
insertReactions(new_sms_id, reactions, false, &recipientmap);
Expand Down
7 changes: 4 additions & 3 deletions signalbackup/signalbackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class SignalBackup
bool handleDTExpirationChangeMessage(SqliteDB const &ddb, long long int rowid, long long int ttid, long long int sent_at, long long int address) const;
bool handleDTGroupV1Migration(SqliteDB const &ddb, long long int rowid, long long int thread_id, long long int timestamp,
long long int address, std::map<std::string, long long int> *savedmap,
bool createcontacts, std::string const &databasedir, bool *warn);
bool createcontacts, std::string const &databasedir, bool create_valid_contacts, bool *warn);
void getDTReactions(SqliteDB const &ddb, long long int rowid, long long int numreactions,
std::vector<std::vector<std::string>> *reactions) const;
void insertReactions(long long int message_id, std::vector<std::vector<std::string>> const &reactions, bool mms,
Expand All @@ -400,7 +400,8 @@ class SignalBackup
inline std::string getNameFromUuid(std::string const &uuid) const;
std::string getNameFromRecipientId(long long int id) const;
void dtSetMessageDeliveryReceipts(SqliteDB const &ddb, long long int rowid, std::map<std::string, long long int> *savedmap,
std::string const &databasedir, bool createcontacts, long long int msg_id, bool is_mms, bool isgroup, bool *warn);
std::string const &databasedir, bool createcontacts, long long int msg_id, bool is_mms, bool isgroup,
bool create_valid_contacts, bool *warn);
bool HTMLwriteStart(std::ofstream &file, long long int thread_recipient_id, std::string const &directory,
std::string const &threaddir, bool isgroup, bool isnotetoself, std::set<long long int> const &recipients,
std::map<long long int, RecipientInfo> *recipientinfo,
Expand Down Expand Up @@ -484,7 +485,7 @@ class SignalBackup
bool migrateDatabase(int from, int to) const;
long long int dtCreateRecipient(SqliteDB const &ddb, std::string const &id, std::string const &phone, std::string const &gidb64,
std::string const &databasedir, std::map<std::string, long long int> *recipient_info,
bool *warn);
bool create_valid_contacts, bool *warn);
bool dtUpdateProfile(SqliteDB const &ddb, std::string const &dtid, long long int aid, std::string const &databasedir);
bool dtSetAvatar(std::string const &avatarpath, std::string const &key, int64_t size, int version,
long long int rid, std::string const &databasedir);
Expand Down

0 comments on commit 1c469f8

Please sign in to comment.