From 0533f48261e00de94330bd48e826513c8ebea780 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 29 Apr 2018 11:25:02 +0000 Subject: [PATCH] fixed bug in address parsing; contact removing improvements FossilOrigin-Name: a14ae09c9c63e5d03f8a15000ff09ac47f79319fcbf348b59eeffdc8d6c9bd9c --- accobj.d | 19 ++++++++++++------- bioacid.d | 7 ++++++- tkclist.d | 6 ++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/accobj.d b/accobj.d index 53d4e4f..ef6d0a0 100644 --- a/accobj.d +++ b/accobj.d @@ -53,15 +53,15 @@ __gshared Contact activeContact; private bool decodeHexStringInto (ubyte[] dest, const(char)[] str) { dest[] = 0; int dpos = 0; - foreach (char ch; str) { - if (ch <= ' ') continue; + foreach (immutable char ch; str) { + if (ch <= ' ' || ch == '_' || ch == '.' || ch == ':') continue; int dig = -1; if (ch >= '0' && ch <= '9') dig = ch-'0'; else if (ch >= 'A' && ch <= 'F') dig = ch-'A'+10; else if (ch >= 'a' && ch <= 'f') dig = ch-'a'+10; else return false; if (dpos >= dest.length*2) return false; - if (dpos%2 == 0) dest[dpos/2] = cast(ubyte)(dig<<16); else dest[dpos/2] |= cast(ubyte)dig; + if (dpos%2 == 0) dest[dpos/2] = cast(ubyte)(dig<<4); else dest[dpos/2] |= cast(ubyte)dig; ++dpos; } return (dpos == dest.length*2); @@ -208,8 +208,8 @@ private: auto dn = diskFileName.dirName; if (dn.length == 0 || dn == "/") return; // just in case conwriteln("removing dir <", dn, ">"); - //rmdirRecurse(dn); - rename(dn, "_"~dn); + rmdirRecurse(dn); + //rename(dn, "_"~dn); diskFileName = null; mDirty = false; } catch (Exception e) {} @@ -1148,15 +1148,20 @@ public: } // returns `false` on any error - bool removeContact (Contact ct) nothrow { + bool removeContact (Contact ct) { if (ct is null || !isOnline) return false; // check if this is our contact bool found = false; foreach (Contact cc; contacts.byValue) if (cc is ct) { found = true; break; } if (!found) return false; - if (!toxCoreRemoveFriend(toxpk, ct.info.pubkey)) return false; + toxCoreRemoveFriend(toxpk, ct.info.pubkey); ct.removeData(); contacts.remove(ct.info.pubkey); + //HACK! + if (clist !is null) { + if (clist.isActiveContact(ct.info.pubkey)) clist.resetActiveItem(); + clist.buildAccount(this); + } /* ct.kind = ContactInfo.Kind.KillFuckDie; ct.markDirty(); diff --git a/bioacid.d b/bioacid.d index 4d104df..39ba262 100644 --- a/bioacid.d +++ b/bioacid.d @@ -313,6 +313,7 @@ void main (string[] args) { "/accept -- accept friend request\n"~ "/kfd -- remove friend, block any further requests\n"~ "/status -- set account status"~ + "/pubkey -- get contact public key"~ "", systimeNow); } else if (cmd == "accept") { if (toxCoreAddFriend(activeContact.acc.toxpk, activeContact.info.pubkey)) { @@ -327,6 +328,8 @@ void main (string[] args) { addTextToLog(activeContact.acc, activeContact, LogFile.Msg.Kind.Notification, false, "KILL! FUCK! DIE!", systimeNow); activeContact.kind = ContactInfo.Kind.KillFuckDie; activeContact.save(); + } else if (cmd == "remove") { + acc.removeContact(activeContact); } else if (cmd == "friend") { if (!isValidAddr(activeContact.info.fraddr)) { conwriteln("invalid address"); return; } string msg = getWord(); @@ -339,6 +342,8 @@ void main (string[] args) { if (!toxCoreSetStatusMessage(activeContact.acc.toxpk, msg)) { conwriteln("ERROR: cannot set status message"); return; } activeContact.acc.info.statusmsg = msg; try { activeContact.acc.save(); } catch (Exception e) { conwriteln("ERROR saving account: ", e.msg); } + } else if (cmd == "pubkey") { + addTextToLog(activeContact.acc, activeContact, LogFile.Msg.Kind.Notification, false, tox_hex(activeContact.info.pubkey), systimeNow); } else { addTextToLog(activeContact.acc, activeContact, LogFile.Msg.Kind.Notification, false, "wut?!", systimeNow); } @@ -357,7 +362,7 @@ void main (string[] args) { ToxAddr fraddr = decodeAddrStr(addr); if (!isValidAddr(fraddr)) { conwriteln("invalid address: '", addr, "'"); return; } string msg = getWord(); - if (msg.length == 0) { conwriteln("address: '", addr, "'; please, specify message!"); return; } + if (msg.length == 0) { conwriteln("address: '", tox_hex(fraddr), "'; please, specify message!"); return; } if (msg.length > tox_max_friend_request_length()) { conwriteln("address: '", addr, "'; message too long"); return; } //if (!toxCoreSendFriendRequest(acc.toxpk, fraddr, msg)) { conwriteln("address: '", addr, "'; error sending friend request"); if (!acc.sendFriendRequest(fraddr, msg)) { conwriteln("address: '", addr, "'; error sending friend request"); return; } diff --git a/tkclist.d b/tkclist.d index a32fafd..cfc8808 100644 --- a/tkclist.d +++ b/tkclist.d @@ -468,6 +468,12 @@ public: activeItemIndex = idx; } + final bool isActiveContact (in ref PubKey pk) const nothrow @trusted { + if (mActiveItem < 0 || mActiveItem >= items.length) return false; + if (auto ct = cast(const(ListItemContact))items[mActiveItem]) return (ct.ct.info.pubkey[] == pk[]); + return false; + } + // if called with `null` ct, deactivate void delegate (Contact ct) onActivateContactCB; -- 2.11.4.GIT