diff options
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r-- | whiteboard.cpp | 16 |
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); } |