diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-16 05:29:39 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | c0574f16ca7960a3301230ba36ba96148818e229 (patch) | |
tree | 120eb7a3346adb772c6df015dfd8257e418eb5dd /src | |
parent | aa07b493ac6259e3ed0c42b60fca1f84ee09799f (diff) |
Add method to get user groups
Diffstat (limited to 'src')
-rw-r--r-- | src/Database.cpp | 5 | ||||
-rw-r--r-- | src/DatabaseStorage.cpp | 14 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/Database.cpp b/src/Database.cpp index 82cb21e..241d9a5 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -665,4 +665,9 @@ namespace odhtdb { return databaseStorage.getStoredUserNodeDataDecrypted(username, password); } + + vector<OwnedMemory> Database::getUserGroups(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const + { + return databaseStorage.getUserGroups(nodeHash, userPublicKey); + } } diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp index 3140c96..ed190e8 100644 --- a/src/DatabaseStorage.cpp +++ b/src/DatabaseStorage.cpp @@ -1025,6 +1025,20 @@ namespace odhtdb fileOverwrite(remoteNodesFilePath, DataView(remoteNodePacker.serializer.getBuffer().data(), remoteNodePacker.serializer.getBuffer().size())); } + vector<OwnedMemory> DatabaseStorage::getUserGroups(const Hash &nodeHash, const Signature::PublicKey &userPublicKey) const + { + vector<OwnedMemory> result; + SqlQuery query(sqliteDb, "SELECT groupId FROM NodeUserGroupAssoc WHERE node = ? AND userPublicKey = ?", { DataView(nodeHash.getData(), nodeHash.getSize()), DataView((void*)userPublicKey.getData(), userPublicKey.getSize()) }); + while(query.next()) + { + const DataView groupIdRaw = query.getBlob(0); + OwnedMemory groupId(new u8[groupIdRaw.size], groupIdRaw.size); + memcpy(groupId.data, groupIdRaw.data, groupIdRaw.size); + result.emplace_back(move(groupId)); + } + return result; + } + bool DatabaseStorage::decryptNodeData(const Hash &nodeHash, const shared_ptr<OwnedMemory> decryptionKey) { sqlite3_reset(selectNodeStmt); |