Loading client/CMakeLists.txt +1 −1 Changes for client/CMakeLists.txt: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ set_target_properties(client PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) target_link_libraries(client PUBLIC uuidp::uuidp confplus::confplus netplus::netplus json-c::json-c httppp::httppp authdb::authobj) target_link_libraries(client PUBLIC uuidp::uuidp confplus::confplus netplus::netplus json-c::json-c httppp::httppp ) set_target_properties(client PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/include/authdb" Loading client/client.cpp +79 −0 Changes for client/client.cpp: 79 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -469,6 +469,85 @@ void Client::changeUserPw(const std::string& oldpw, const std::string& newpw) { json_object_put(jresponse); } void Client::UserInfo(class UserData& udat) { ensure_http_client(_Con); 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, "clientsession", json_object_new_string(_Con.getClientId().c_str())); json_object_object_add(obj, "usersession", json_object_new_string(_Con.getSessionID().c_str())); json_object_object_add(obj, "userinfo", json_object_new_string("")); json_object_array_add(cmd, obj); json_object_object_add(jresponse, "commands", cmd); size_t outsize = 0; const char* tmp = json_object_to_json_string_length(jresponse, 0, &outsize); std::vector<char> out; out.reserve(outsize); std::copy(tmp, tmp + outsize, std::back_inserter(out)); libhttppp::HttpRequest nreq; nreq.setHeaderData("accept")->push_back("application/json"); nreq.setHeaderData("content-type")->push_back("application/json"); nreq.setRequestURL(_Con._RequestPath.c_str()); std::vector<char> resp(_Con._Client->Post(nreq, out, _Con._MaxTries)); resp.push_back('\0'); json_object_put(jresponse); json_tokener* jtok = json_tokener_new(); json_object* jrequest = json_tokener_parse_ex(jtok, resp.data(), resp.size() - 1); if (!jrequest) { const char* err = json_tokener_error_desc(json_tokener_get_error(jtok)); json_tokener_free(jtok); throw authdb::AuthBackendError(err); } if (json_object_get_type(jrequest) != json_type_array) { json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } int fcount = json_object_array_length(jrequest); for (int i = 0; i < fcount; ++i) { json_object_object_foreach(json_object_array_get_idx(jrequest, i), key, val) { if (strcmp("userinfo", key) == 0) { json_object* jobj = nullptr; if (json_object_object_get_ex(val, "username", &jobj)) { const char* v = json_object_get_string(jobj); if (v) udat.setUserName(v); } if (json_object_object_get_ex(val, "firstname", &jobj)) { const char* v = json_object_get_string(jobj); if (v) udat.setFirstName(v); } if (json_object_object_get_ex(val, "lastname", &jobj)) { const char* v = json_object_get_string(jobj); if (v) udat.setLastName(v); } if (json_object_object_get_ex(val, "mail", &jobj)) { const char* v = json_object_get_string(jobj); if (v) udat.setMail(v); } json_object_put(jrequest); json_tokener_free(jtok); return; } } } json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("UserInfo not found in response")); } void Client::getAvatar(const ::uuid::uuid& did, const ::uuid::uuid& uid, libhttppp::HttpRequest& resq, libhttppp::HttpResponse& resp) { ensure_http_client(_Con); Loading src/api.cpp +40 −0 Changes for src/api.cpp: 40 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -634,6 +634,45 @@ public: } } void UserInfo(json_object *request, json_object *response) { json_object* cmd = get_commands_array_or_throw(request); int fcount = json_object_array_length(cmd); for (int i = 0; i < fcount; ++i) { json_object_object_foreach(json_object_array_get_idx(cmd, i), key, val) { (void)val; if (strcmp(key, "userinfo") == 0) { if (!_SessionData) continue; ::uuid::uuid uid; _SessionData->getUid(uid); class UserData udat(uid.value); User user; size_t ustart = sizeof(AuthHeader); user.info(_Backend, udat, ustart); json_object* respid = json_object_new_object(); json_object_object_add(respid, "username", json_object_new_string(udat.getUsername().c_str())); json_object_object_add(respid, "firstname", json_object_new_string(udat.getFirstname().c_str())); json_object_object_add(respid, "lastname", json_object_new_string(udat.getLastname().c_str())); json_object_object_add(respid, "mail", json_object_new_string(udat.getMail().c_str())); json_object_object_add(respid, "userid", json_object_new_string(uid.c_str())); json_object* out = json_object_new_object(); json_object_object_add(out, "userinfo", respid); json_object_array_add(response, out); return; } } } } void listGroups(json_object *request, json_object *response) { json_object* cmd = get_commands_array_or_throw(request); Loading Loading @@ -741,6 +780,7 @@ public: checkGPO(jrequest, jresponse); addGPO(jrequest, jresponse); SessionInfo(jrequest, jresponse); UserInfo(jrequest, jresponse); remSession(jrequest, jresponse); } Loading Loading
client/CMakeLists.txt +1 −1 Changes for client/CMakeLists.txt: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ set_target_properties(client PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) target_link_libraries(client PUBLIC uuidp::uuidp confplus::confplus netplus::netplus json-c::json-c httppp::httppp authdb::authobj) target_link_libraries(client PUBLIC uuidp::uuidp confplus::confplus netplus::netplus json-c::json-c httppp::httppp ) set_target_properties(client PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/include/authdb" Loading
client/client.cpp +79 −0 Changes for client/client.cpp: 79 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -469,6 +469,85 @@ void Client::changeUserPw(const std::string& oldpw, const std::string& newpw) { json_object_put(jresponse); } void Client::UserInfo(class UserData& udat) { ensure_http_client(_Con); 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, "clientsession", json_object_new_string(_Con.getClientId().c_str())); json_object_object_add(obj, "usersession", json_object_new_string(_Con.getSessionID().c_str())); json_object_object_add(obj, "userinfo", json_object_new_string("")); json_object_array_add(cmd, obj); json_object_object_add(jresponse, "commands", cmd); size_t outsize = 0; const char* tmp = json_object_to_json_string_length(jresponse, 0, &outsize); std::vector<char> out; out.reserve(outsize); std::copy(tmp, tmp + outsize, std::back_inserter(out)); libhttppp::HttpRequest nreq; nreq.setHeaderData("accept")->push_back("application/json"); nreq.setHeaderData("content-type")->push_back("application/json"); nreq.setRequestURL(_Con._RequestPath.c_str()); std::vector<char> resp(_Con._Client->Post(nreq, out, _Con._MaxTries)); resp.push_back('\0'); json_object_put(jresponse); json_tokener* jtok = json_tokener_new(); json_object* jrequest = json_tokener_parse_ex(jtok, resp.data(), resp.size() - 1); if (!jrequest) { const char* err = json_tokener_error_desc(json_tokener_get_error(jtok)); json_tokener_free(jtok); throw authdb::AuthBackendError(err); } if (json_object_get_type(jrequest) != json_type_array) { json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } int fcount = json_object_array_length(jrequest); for (int i = 0; i < fcount; ++i) { json_object_object_foreach(json_object_array_get_idx(jrequest, i), key, val) { if (strcmp("userinfo", key) == 0) { json_object* jobj = nullptr; if (json_object_object_get_ex(val, "username", &jobj)) { const char* v = json_object_get_string(jobj); if (v) udat.setUserName(v); } if (json_object_object_get_ex(val, "firstname", &jobj)) { const char* v = json_object_get_string(jobj); if (v) udat.setFirstName(v); } if (json_object_object_get_ex(val, "lastname", &jobj)) { const char* v = json_object_get_string(jobj); if (v) udat.setLastName(v); } if (json_object_object_get_ex(val, "mail", &jobj)) { const char* v = json_object_get_string(jobj); if (v) udat.setMail(v); } json_object_put(jrequest); json_tokener_free(jtok); return; } } } json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("UserInfo not found in response")); } void Client::getAvatar(const ::uuid::uuid& did, const ::uuid::uuid& uid, libhttppp::HttpRequest& resq, libhttppp::HttpResponse& resp) { ensure_http_client(_Con); Loading
src/api.cpp +40 −0 Changes for src/api.cpp: 40 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -634,6 +634,45 @@ public: } } void UserInfo(json_object *request, json_object *response) { json_object* cmd = get_commands_array_or_throw(request); int fcount = json_object_array_length(cmd); for (int i = 0; i < fcount; ++i) { json_object_object_foreach(json_object_array_get_idx(cmd, i), key, val) { (void)val; if (strcmp(key, "userinfo") == 0) { if (!_SessionData) continue; ::uuid::uuid uid; _SessionData->getUid(uid); class UserData udat(uid.value); User user; size_t ustart = sizeof(AuthHeader); user.info(_Backend, udat, ustart); json_object* respid = json_object_new_object(); json_object_object_add(respid, "username", json_object_new_string(udat.getUsername().c_str())); json_object_object_add(respid, "firstname", json_object_new_string(udat.getFirstname().c_str())); json_object_object_add(respid, "lastname", json_object_new_string(udat.getLastname().c_str())); json_object_object_add(respid, "mail", json_object_new_string(udat.getMail().c_str())); json_object_object_add(respid, "userid", json_object_new_string(uid.c_str())); json_object* out = json_object_new_object(); json_object_object_add(out, "userinfo", respid); json_object_array_add(response, out); return; } } } } void listGroups(json_object *request, json_object *response) { json_object* cmd = get_commands_array_or_throw(request); Loading Loading @@ -741,6 +780,7 @@ public: checkGPO(jrequest, jresponse); addGPO(jrequest, jresponse); SessionInfo(jrequest, jresponse); UserInfo(jrequest, jresponse); remSession(jrequest, jresponse); } Loading