aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cpp4
-rw-r--r--src/Gif.cpp6
-rw-r--r--src/main.cpp56
3 files changed, 9 insertions, 57 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 66b6f71..1295475 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -146,7 +146,7 @@ namespace dchat
sf::Texture *texture = new sf::Texture();
if(texture->loadFromMemory(fileContent.data, fileContent.size))
{
- delete fileContent.data;
+ delete[] fileContent.data;
fileContent.data = nullptr;
texture->setSmooth(true);
texture->generateMipmap();
@@ -167,7 +167,7 @@ namespace dchat
}
} while(offset < fileContent.size);
- delete fileContent.data;
+ delete[] fileContent.data;
fileContent.data = nullptr;
if(foundHtmlContent)
diff --git a/src/Gif.cpp b/src/Gif.cpp
index 69c0be8..afd5b9d 100644
--- a/src/Gif.cpp
+++ b/src/Gif.cpp
@@ -73,7 +73,7 @@ namespace dchat
}
catch(GifLoadException &e)
{
- delete fileContent.data;
+ delete[] fileContent.data;
throw e;
}
}
@@ -89,7 +89,7 @@ namespace dchat
}
catch(GifLoadException &e)
{
- delete fileContent.data;
+ delete[] fileContent.data;
throw e;
}
}
@@ -131,7 +131,7 @@ namespace dchat
Gif::~Gif()
{
gif_finalise(&gif);
- delete fileContent.data;
+ delete[] fileContent.data;
}
sf::Vector2u Gif::getSize() const
diff --git a/src/main.cpp b/src/main.cpp
index 249c5d4..39ccd43 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,39 +25,6 @@ using namespace std;
using namespace dchat;
using namespace TinyProcessLib;
-string createChannelJoinKey(const unique_ptr<odhtdb::DatabaseCreateResponse> &databaseCreateResponse)
-{
- string result;
- result += databaseCreateResponse->getRequestHash()->toString();
- result += "&";
- result += odhtdb::bin2hex((const char*)databaseCreateResponse->getNodeEncryptionKey()->data, databaseCreateResponse->getNodeEncryptionKey()->size);
- return result;
-}
-
-string createJoinKeyFromDatabaseNode(const odhtdb::DatabaseNode &databaseNode)
-{
- string result;
- result += databaseNode.getRequestHash()->toString();
- result += "&";
- result += odhtdb::bin2hex((const char*)databaseNode.getNodeEncryptionKey()->data, databaseNode.getNodeEncryptionKey()->size);
- return result;
-}
-
-odhtdb::DatabaseNode createDatabaseNodeFromJoinKey(const string &joinKey)
-{
- string nodeHashRaw = odhtdb::hex2bin(joinKey.c_str(), 64);
- shared_ptr<odhtdb::Hash> nodeHash = make_shared<odhtdb::Hash>();
- memcpy(nodeHash->getData(), nodeHashRaw.data(), nodeHashRaw.size());
-
- string nodeEncryptionKeyRaw = odhtdb::hex2bin(joinKey.c_str() + 65, 64);
- shared_ptr<odhtdb::OwnedMemory> encryptionKey = make_shared<odhtdb::OwnedMemory>();
- encryptionKey->data = new char[nodeEncryptionKeyRaw.size()];
- memcpy(encryptionKey->data, nodeEncryptionKeyRaw.data(), nodeEncryptionKeyRaw.size());
- encryptionKey->size = nodeEncryptionKeyRaw.size();
-
- return odhtdb::DatabaseNode(encryptionKey, nodeHash);
-}
-
void channelChangeUserNickname(Channel *channel, const StringView data, const odhtdb::Signature::PublicKey &userPublicKey)
{
auto user = channel->getUserByPublicKey(userPublicKey);
@@ -328,6 +295,7 @@ int main(int argc, char **argv)
loggedIn = true;
});
+ // TODO: Use database->addData to change channel name
// Create channel
Command::add("cc", [&database, &channels, &channelMessageMutex, &loggedIn, &localNodeUsers, &currentUsername, &currentPassword](const vector<string> &args)
{
@@ -345,7 +313,7 @@ int main(int argc, char **argv)
}
auto createResponse = database->create();
- printf("Created database '%s', join key: '%s'\n", args[0].c_str(), createChannelJoinKey(createResponse).c_str());
+ printf("Created channel %s\n", createResponse->getRequestHash()->toString().c_str());
User *newLocalUser = new OnlineLocalUser("NoName", *createResponse->getNodeAdminKeyPair());
odhtdb::DatabaseNode databaseNode(createResponse->getNodeEncryptionKey(), createResponse->getRequestHash());
@@ -380,7 +348,7 @@ int main(int argc, char **argv)
auto channelNodeHash = currentChannel->getNodeInfo().getRequestHash();
auto channelEncryptionKey = currentChannel->getNodeInfo().getNodeEncryptionKey();
- shared_ptr<odhtdb::OwnedMemory> encryptionKey = make_shared<odhtdb::OwnedMemory>(new u8[odhtdb::ENCRYPTION_KEY_BYTE_SIZE], odhtdb::ENCRYPTION_KEY_BYTE_SIZE);
+ shared_ptr<odhtdb::OwnedByteArray> encryptionKey = make_shared<odhtdb::OwnedByteArray>(new u8[odhtdb::ENCRYPTION_KEY_BYTE_SIZE], odhtdb::ENCRYPTION_KEY_BYTE_SIZE);
odhtdb::Encryption::generateKey((unsigned char*)encryptionKey->data);
string inviteKey = odhtdb::bin2hex((const char*)channelNodeHash->getData(), channelNodeHash->getSize());
@@ -476,7 +444,7 @@ int main(int argc, char **argv)
}
string encryptionKeyBinRaw = odhtdb::hex2bin(args[0].c_str() + 65, 64);
- shared_ptr<odhtdb::OwnedMemory> encryptionKey = make_shared<odhtdb::OwnedMemory>(new u8[odhtdb::ENCRYPTION_KEY_BYTE_SIZE], odhtdb::ENCRYPTION_KEY_BYTE_SIZE);
+ shared_ptr<odhtdb::OwnedByteArray> encryptionKey = make_shared<odhtdb::OwnedByteArray>(new u8[odhtdb::ENCRYPTION_KEY_BYTE_SIZE], odhtdb::ENCRYPTION_KEY_BYTE_SIZE);
memcpy(encryptionKey->data, encryptionKeyBinRaw.data(), encryptionKeyBinRaw.size());
shared_ptr<odhtdb::Signature::KeyPair> keyPair = make_shared<odhtdb::Signature::KeyPair>();
@@ -676,22 +644,6 @@ int main(int argc, char **argv)
Channel::getCurrent()->addLocalMessage(msg, Channel::getCurrent()->getSystemUser());
});
- // Get channel join key
- Command::add("joinkey", [&offlineChannel](const vector<string> &args)
- {
- Channel *currentChannel = Channel::getCurrent();
- if(!currentChannel || currentChannel == &offlineChannel)
- {
- Channel::getCurrent()->addLocalMessage("You are not inside a channel", Channel::getCurrent()->getSystemUser());
- return;
- }
-
- string response = "Join key: ";
- response += createJoinKeyFromDatabaseNode(currentChannel->getNodeInfo());
- printf("%s\n", response.c_str());
- Channel::getCurrent()->addLocalMessage(response, Channel::getCurrent()->getSystemUser());
- });
-
sf::Event event;
while (window.isOpen())
{