Loading client/client.cpp +38 −0 Changes for client/client.cpp: 38 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -182,12 +182,50 @@ bool authdb::client::Client::UserAuth(){ if(strcmp(key,"sessionid")==0){ _Con._SessionID=json_object_get_string(val); if(!_Con._SessionID.empty()){ json_object_put(jrequest); json_tokener_free(jtok); return true; } } } } json_object_put(jrequest); json_tokener_free(jtok); return false; } #include <iostream> void authdb::client::Client::SessionInfo(class SessionData& sdat){ json_object *jresponse = json_object_new_object(); json_object *cmd=json_object_new_array(); json_object *obj=json_object_new_object(); json_object_object_add(obj,"usersession", json_object_new_string(_Con.getSessionID().c_str())); json_object_object_add(obj,"sessioninfo",json_object_new_string("")); json_object_array_add(cmd,obj); json_object_object_add(jresponse,"commands",cmd); size_t outsize=0; std::vector<char> out; const char *tmp=json_object_to_json_string_length(jresponse,0,&outsize); std::copy(tmp,tmp+outsize,std::back_inserter(out)); std::cout << tmp << std::endl; std::vector<char> resp(_Con._Client->Post(_Con._Url.getPath(),"text/json",out)); resp.push_back('\0'); std::cout << resp.data() << std::endl; json_object_put(jresponse); json_object *jrequest; json_tokener*jtok=json_tokener_new(); jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); } client/client.h +6 −16 Changes for client/client.h: 6 added lines, 16 removed lines. Original line number Diff line number Diff line Loading @@ -69,28 +69,18 @@ namespace authdb { bool UserAuth(); bool ClientAuth(); class Connection { public: void add(const std::string &clientname,const std::string &cltsecret); void rem(const std::string &clientname); bool check(const std::string &clientname); } CCon; void addConnection(const std::string &clientname,const std::string &cltsecret); void remConnection(const std::string &clientname); class Session { void info(class SessionData &sdat); }; void SessionInfo(class SessionData &sdat); class GPO { public: bool check(class uuid gpoid); } CGPO; bool GPOcheck(class uuid gpoid); class User { void info(class UserData &udat); }; void UserInfo(class UserData &udat); private: ClientConnection &_Con; friend class Session; }; }; }; client/examples/CMakeLists.txt +4 −0 Changes for client/examples/CMakeLists.txt: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -5,3 +5,7 @@ target_link_libraries(userlogin PRIVATE client-static) add_executable(clientlogin clientlogin.cpp) target_link_libraries(clientlogin PRIVATE client-static) add_executable(sessinfo sessinfo.cpp) target_link_libraries(sessinfo PRIVATE client-static) client/examples/sessinfo.cpp 0 → 100644 +50 −0 Changes for client/examples/sessinfo.cpp: 50 added lines, 0 removed lines. Original line number Diff line number Diff line /******************************************************************************* * Copyright (c) 2025, Jan Koester jan.koester@gmx.net * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <iostream> #include "../client.h" int main(int argc, char *argv[]){ authdb::client::ClientConnection con; con.setUrl(argv[1]); con.setUsername(argv[2]); con.setUserPassword(argv[3]); authdb::client::Client clt(con); if(clt.UserAuth()){ std::cout << "Sucessfully login !" << std::endl; } class authdb::SessionData sdat; clt.SessionInfo(sdat); std::cout << sdat.getUsername() << std::endl; return -1; } src/api.cpp +1 −1 Changes for src/api.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -405,7 +405,7 @@ namespace authdb { _SessionData=userLogin(jrequest,jresponse); } if(_SessionData->empty()){ if(!_SessionData){ const char *ret=json_object_to_json_string(jresponse); rep.setState(HTTP401); rep.setContentType("text/json"); Loading Loading
client/client.cpp +38 −0 Changes for client/client.cpp: 38 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -182,12 +182,50 @@ bool authdb::client::Client::UserAuth(){ if(strcmp(key,"sessionid")==0){ _Con._SessionID=json_object_get_string(val); if(!_Con._SessionID.empty()){ json_object_put(jrequest); json_tokener_free(jtok); return true; } } } } json_object_put(jrequest); json_tokener_free(jtok); return false; } #include <iostream> void authdb::client::Client::SessionInfo(class SessionData& sdat){ json_object *jresponse = json_object_new_object(); json_object *cmd=json_object_new_array(); json_object *obj=json_object_new_object(); json_object_object_add(obj,"usersession", json_object_new_string(_Con.getSessionID().c_str())); json_object_object_add(obj,"sessioninfo",json_object_new_string("")); json_object_array_add(cmd,obj); json_object_object_add(jresponse,"commands",cmd); size_t outsize=0; std::vector<char> out; const char *tmp=json_object_to_json_string_length(jresponse,0,&outsize); std::copy(tmp,tmp+outsize,std::back_inserter(out)); std::cout << tmp << std::endl; std::vector<char> resp(_Con._Client->Post(_Con._Url.getPath(),"text/json",out)); resp.push_back('\0'); std::cout << resp.data() << std::endl; json_object_put(jresponse); json_object *jrequest; json_tokener*jtok=json_tokener_new(); jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); }
client/client.h +6 −16 Changes for client/client.h: 6 added lines, 16 removed lines. Original line number Diff line number Diff line Loading @@ -69,28 +69,18 @@ namespace authdb { bool UserAuth(); bool ClientAuth(); class Connection { public: void add(const std::string &clientname,const std::string &cltsecret); void rem(const std::string &clientname); bool check(const std::string &clientname); } CCon; void addConnection(const std::string &clientname,const std::string &cltsecret); void remConnection(const std::string &clientname); class Session { void info(class SessionData &sdat); }; void SessionInfo(class SessionData &sdat); class GPO { public: bool check(class uuid gpoid); } CGPO; bool GPOcheck(class uuid gpoid); class User { void info(class UserData &udat); }; void UserInfo(class UserData &udat); private: ClientConnection &_Con; friend class Session; }; }; };
client/examples/CMakeLists.txt +4 −0 Changes for client/examples/CMakeLists.txt: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -5,3 +5,7 @@ target_link_libraries(userlogin PRIVATE client-static) add_executable(clientlogin clientlogin.cpp) target_link_libraries(clientlogin PRIVATE client-static) add_executable(sessinfo sessinfo.cpp) target_link_libraries(sessinfo PRIVATE client-static)
client/examples/sessinfo.cpp 0 → 100644 +50 −0 Changes for client/examples/sessinfo.cpp: 50 added lines, 0 removed lines. Original line number Diff line number Diff line /******************************************************************************* * Copyright (c) 2025, Jan Koester jan.koester@gmx.net * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <iostream> #include "../client.h" int main(int argc, char *argv[]){ authdb::client::ClientConnection con; con.setUrl(argv[1]); con.setUsername(argv[2]); con.setUserPassword(argv[3]); authdb::client::Client clt(con); if(clt.UserAuth()){ std::cout << "Sucessfully login !" << std::endl; } class authdb::SessionData sdat; clt.SessionInfo(sdat); std::cout << sdat.getUsername() << std::endl; return -1; }
src/api.cpp +1 −1 Changes for src/api.cpp: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -405,7 +405,7 @@ namespace authdb { _SessionData=userLogin(jrequest,jresponse); } if(_SessionData->empty()){ if(!_SessionData){ const char *ret=json_object_to_json_string(jresponse); rep.setState(HTTP401); rep.setContentType("text/json"); Loading