summaryrefslogtreecommitdiffhomepage
path: root/whiteboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r--whiteboard.cpp41
1 files changed, 3 insertions, 38 deletions
diff --git a/whiteboard.cpp b/whiteboard.cpp
index 75472ba..6466635 100644
--- a/whiteboard.cpp
+++ b/whiteboard.cpp
@@ -14,7 +14,6 @@
#include <functional>
#include <filesystem>
#include <mutex>
-#include <random>
#include <regex>
#include <string>
#include <thread>
@@ -56,6 +55,7 @@ Whiteboard::Whiteboard():
{
}
+// contents of cleanup thread; looping
void Whiteboard::storage_cleanup()
{
while(true) {
@@ -67,38 +67,6 @@ void Whiteboard::storage_cleanup()
}
}
-uint32_t Whiteboard::checksum32(const std::string& s)
-{
- uint32_t result{0};
- for (unsigned int i = 0; i < s.size(); i++) {
- result = ((result >> 1) | ((result & 1) << 31)) ^ (s[i] & 0xFF);
- }
- return result & 0x7FFFFFFF;
-}
-
-std::string Whiteboard::generate_id()
-{
- static std::random_device r;
- static std::default_random_engine e1(r());
- static std::uniform_int_distribution<int> uniform_dist(0, 35);
-
- // limit tries
- for (int j = 0; j < 100000; j++) {
- std::string result;
- for (int i = 0; i < 6; i++) {
- char c{static_cast<char>('0' + uniform_dist(e1))};
- if (c > '9')
- c = c - '9' + 'a';
- result.push_back(c);
- }
-
- if (!m_storage.exists(result))
- return result;
- }
-
- return "endofcodes";
-}
-
// the actual main() for testability
int Whiteboard::run(int argc, char* argv[])
{
@@ -179,11 +147,8 @@ int Whiteboard::run(int argc, char* argv[])
std::string checksum_s {xml.get<std::string>("request.checksum")};
uint32_t checksum{static_cast<uint32_t>(stoul(checksum_s))};
- //std::cout << "Checksum JS: " << checksum_s << std::endl;
- //std::cout << "Checksum C++: " << checksum32(filedata) << std::endl;
-
std::string filedata {m_storage.getDocument(id)};
- if (checksum != checksum32(filedata)) {
+ if (checksum != m_storage.checksum32(filedata)) {
//std::cout << "Sending change..." << std::endl;
FCGX_PutS("Content-Type: application/octet-stream\r\n", request.out);
FCGX_FPrintF(request.out, "Content-Length: %d\r\n\r\n", filedata.size());
@@ -195,7 +160,7 @@ int Whiteboard::run(int argc, char* argv[])
}
} else if (command == "newid") {
FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
- FCGX_PutS(generate_id().c_str(), request.out);
+ FCGX_PutS(m_storage.generate_id().c_str(), request.out);
} else if (command == "qrcode") {
std::string url{xml.get<std::string>("request.url")};