summaryrefslogtreecommitdiffhomepage
path: root/whiteboard.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2022-12-03 16:12:14 +0100
committerRoland Reichwein <mail@reichwein.it>2022-12-03 16:12:14 +0100
commit70131428edce8d7c6476a902d015b30b78e5f862 (patch)
treef522c3efc0e9901d59e91da59f36a52e927e9523 /whiteboard.cpp
parentbdf314288794e5ca898db9d07b1553182ea4d7ea (diff)
Version 1.1: Added QR Codev1.1
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r--whiteboard.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/whiteboard.cpp b/whiteboard.cpp
index b3367cf..8df6d73 100644
--- a/whiteboard.cpp
+++ b/whiteboard.cpp
@@ -18,8 +18,11 @@
#include <boost/algorithm/string/trim.hpp>
#include <boost/property_tree/xml_parser.hpp>
+#include <ImageMagick-6/Magick++.h>
+
#include "config.h"
#include "file.h"
+#include "qrcode.h"
namespace pt = boost::property_tree;
using namespace std::string_literals;
@@ -95,6 +98,8 @@ int main(void)
Config config;
data_path = config.getDataPath();
+ Magick::InitializeMagick(NULL); // for qrcode.cpp
+
int result = FCGX_Init();
if (result != 0) { // error on init
fprintf(stderr, "Error: FCGX_Init()\n");
@@ -174,6 +179,17 @@ int main(void)
} else if (command == "newid") {
FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out);
FCGX_PutS(generate_id().c_str(), request.out);
+ } else if (command == "qrcode") {
+ std::string url{xml.get<std::string>("request.url")};
+
+ if (url.size() > 1000)
+ throw std::runtime_error("URL too big");
+
+ std::string pngdata {getQRCode(url)};
+
+ FCGX_PutS("Content-Type: image/png\r\n", request.out);
+ FCGX_FPrintF(request.out, "Content-Length: %d\r\n\r\n", pngdata.size());
+ FCGX_PutStr(pngdata.c_str(), pngdata.size(), request.out);
} else {
throw std::runtime_error("Bad command: "s + command);
}