Loading CMakeLists.txt +1 −0 Changes for CMakeLists.txt: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -7,5 +7,6 @@ find_package(libcmdplus REQUIRED) find_package(libnetplus REQUIRED) find_package(libhttppp REQUIRED) find_package(libhtmlpp REQUIRED) find_package(json-c REQUIRED) add_subdirectory(src) src/CMakeLists.txt +1 −1 Changes for src/CMakeLists.txt: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ add_executable( authdb ${authdbSrcs} ) target_link_libraries(authdb PUBLIC fback httppp::httppp netplus::netplus confplus::confplus cmdplus::cmdplus htmlpp::htmlpp uuid) target_link_libraries(authdb PUBLIC fback json-c::json-c httppp::httppp netplus::netplus confplus::confplus cmdplus::cmdplus htmlpp::htmlpp uuid) install(TARGETS fback DESTINATION lib) install(TARGETS authdb DESTINATION bin) src/api.cpp +34 −0 Changes for src/api.cpp: 34 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -25,4 +25,38 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <uuid/uuid.h> #include <json-c/json.h> #include "authdb.h" #include "backend.h" #include "api.h" namespace authdb { class Api { public: Api(AuthBackend &admin,libhttppp::HttpRequest* curreq, const int tid, ULONG_PTR args){ libhttppp::HttpResponse rep; std::string loginmsg="{\"error: {\"msg\":\"no client key!\"}}"; rep.setState(HTTP500); rep.setContentType("text/json"); rep.send(curreq,loginmsg.c_str(),loginmsg.length()); } ~Api(){ } private: AuthBackend *_Backend; }; }; authdb::ApiController::ApiController(AuthBackend &admin,libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ Api(admin,curreq,tid,args); } authdb::ApiController::~ApiController(){ } src/api.h +7 −1 Changes for src/api.h: 7 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -25,8 +25,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <httppp/httpd.h> #pragma once namespace authdb { class ApiController { public: ApiController(AuthBackend &admin,libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args); ~ApiController(); }; }; src/authdb.cpp +37 −0 Changes for src/authdb.cpp: 37 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ #include "hash.h" #include "hash/sha512.h" #include "admin.h" #include "api.h" namespace authdb { Loading Loading @@ -196,6 +197,42 @@ namespace authdb { rep.send(curreq,e.what(),strlen(e.what())); } _AdminBackend.unlock(); }if(strncmp("/api",curreq->getRequestURL(),4)==0){ _AdminBackend.lock(); DomainBackend db(_AdminBackend); AuthBackend *apidb=nullptr; char domain[255]; if(sscanf(curreq->getRequestURL(),"/api/%s",domain)<0) return; uuid_t did; if(uuid_parse(domain,did) == 0 ){ apidb=db.data(did); } _AdminBackend.unlock(); if(apidb){ apidb->lock(); try{ ApiController(*apidb,curreq,tid,args); }catch(AuthBackendError &e){ libhttppp::HttpResponse rep; rep.setState(HTTP500); rep.setContentType("text/html"); rep.send(curreq,e.what(),strlen(e.what())); } apidb->unlock(); }else{ libhttppp::HttpResponse rep; rep.setState(HTTP404); rep.setContentType("text/html"); rep.send(curreq,"uuid not found!",12); } }else if(strncmp("/getavatar",curreq->getRequestURL(),9)==0){ _AdminBackend.lock(); try{ Loading Loading
CMakeLists.txt +1 −0 Changes for CMakeLists.txt: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -7,5 +7,6 @@ find_package(libcmdplus REQUIRED) find_package(libnetplus REQUIRED) find_package(libhttppp REQUIRED) find_package(libhtmlpp REQUIRED) find_package(json-c REQUIRED) add_subdirectory(src)
src/CMakeLists.txt +1 −1 Changes for src/CMakeLists.txt: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ add_executable( authdb ${authdbSrcs} ) target_link_libraries(authdb PUBLIC fback httppp::httppp netplus::netplus confplus::confplus cmdplus::cmdplus htmlpp::htmlpp uuid) target_link_libraries(authdb PUBLIC fback json-c::json-c httppp::httppp netplus::netplus confplus::confplus cmdplus::cmdplus htmlpp::htmlpp uuid) install(TARGETS fback DESTINATION lib) install(TARGETS authdb DESTINATION bin)
src/api.cpp +34 −0 Changes for src/api.cpp: 34 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -25,4 +25,38 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <uuid/uuid.h> #include <json-c/json.h> #include "authdb.h" #include "backend.h" #include "api.h" namespace authdb { class Api { public: Api(AuthBackend &admin,libhttppp::HttpRequest* curreq, const int tid, ULONG_PTR args){ libhttppp::HttpResponse rep; std::string loginmsg="{\"error: {\"msg\":\"no client key!\"}}"; rep.setState(HTTP500); rep.setContentType("text/json"); rep.send(curreq,loginmsg.c_str(),loginmsg.length()); } ~Api(){ } private: AuthBackend *_Backend; }; }; authdb::ApiController::ApiController(AuthBackend &admin,libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){ Api(admin,curreq,tid,args); } authdb::ApiController::~ApiController(){ }
src/api.h +7 −1 Changes for src/api.h: 7 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -25,8 +25,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <httppp/httpd.h> #pragma once namespace authdb { class ApiController { public: ApiController(AuthBackend &admin,libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args); ~ApiController(); }; };
src/authdb.cpp +37 −0 Changes for src/authdb.cpp: 37 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ #include "hash.h" #include "hash/sha512.h" #include "admin.h" #include "api.h" namespace authdb { Loading Loading @@ -196,6 +197,42 @@ namespace authdb { rep.send(curreq,e.what(),strlen(e.what())); } _AdminBackend.unlock(); }if(strncmp("/api",curreq->getRequestURL(),4)==0){ _AdminBackend.lock(); DomainBackend db(_AdminBackend); AuthBackend *apidb=nullptr; char domain[255]; if(sscanf(curreq->getRequestURL(),"/api/%s",domain)<0) return; uuid_t did; if(uuid_parse(domain,did) == 0 ){ apidb=db.data(did); } _AdminBackend.unlock(); if(apidb){ apidb->lock(); try{ ApiController(*apidb,curreq,tid,args); }catch(AuthBackendError &e){ libhttppp::HttpResponse rep; rep.setState(HTTP500); rep.setContentType("text/html"); rep.send(curreq,e.what(),strlen(e.what())); } apidb->unlock(); }else{ libhttppp::HttpResponse rep; rep.setState(HTTP404); rep.setContentType("text/html"); rep.send(curreq,"uuid not found!",12); } }else if(strncmp("/getavatar",curreq->getRequestURL(),9)==0){ _AdminBackend.lock(); try{ Loading