Loading client/client.cpp +98 −39 Changes for client/client.cpp: 98 added lines, 39 removed lines. Original line number Diff line number Diff line Loading @@ -22,15 +22,18 @@ * 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. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF DAMAGE. *******************************************************************************/ #include <vector> #include <sstream> #include <algorithm> #include <cstring> #include <json.h> #include <json_object.h> #include <json_types.h> #include <json_tokener.h> #include "client.h" Loading Loading @@ -74,7 +77,6 @@ void authdb::client::ClientConnection::setSessionID(const ::uuid::uuid& sid){ _SessionID=sid; } authdb::client::Client::Client(ClientConnection& clt) : _Con(clt){ if(!_Con._Client){ _Con._Client=new libhttppp::HttpClient(_Con._Url); Loading Loading @@ -107,11 +109,8 @@ bool authdb::client::Client::ClientAuth(){ 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)); libhttppp::HttpRequest nreq; Loading @@ -121,34 +120,43 @@ bool authdb::client::Client::ClientAuth(){ resp.push_back('\0'); // std::cout <<resp.data() <<std::endl; json_object_put(jresponse); json_object_put(cmd); json_object_put(login); json_object_put(userauth); json_object *jrequest; json_tokener*jtok=json_tokener_new(); jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); // Error handling block if(!jrequest){ json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array){ json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } // Process Response 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(key,"connectionid")==0){ _Con._ClientId=json_object_get_string(val); if(!_Con._ClientId.empty()){ json_object_put(jrequest); json_tokener_free(jtok); return true; } } } } json_object_put(jrequest); json_tokener_free(jtok); return false; } Loading @@ -168,11 +176,8 @@ bool authdb::client::Client::UserAuth(){ 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)); libhttppp::HttpRequest nreq; Loading @@ -183,6 +188,9 @@ bool authdb::client::Client::UserAuth(){ resp.push_back('\0'); json_object_put(jresponse); json_object_put(cmd); json_object_put(login); json_object_put(userauth); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -190,11 +198,15 @@ bool authdb::client::Client::UserAuth(){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::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) { Loading @@ -209,6 +221,7 @@ bool authdb::client::Client::UserAuth(){ } } } json_object_put(jrequest); json_tokener_free(jtok); return false; Loading @@ -229,13 +242,9 @@ void authdb::client::Client::SessionInfo(class SessionData& sdat){ 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)); libhttppp::HttpRequest nreq; Loading @@ -245,7 +254,11 @@ void authdb::client::Client::SessionInfo(class SessionData& sdat){ resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(sinfo); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -253,15 +266,19 @@ void authdb::client::Client::SessionInfo(class SessionData& sdat){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ // FIX: jtok cleanup json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array){ // FIX: jrequest and jtok cleanup json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } sdat._uid.clear(); sdat._username.clear(); sdat._did.clear(); sdat.clear(); // Using the helper clear function int fcount = json_object_array_length(jrequest); for(int i =0; i<fcount; ++i) { Loading @@ -280,7 +297,6 @@ void authdb::client::Client::SessionInfo(class SessionData& sdat){ if(sdat._sid.empty()){ throw(authdb::AuthBackendError("Session not found !")); } } bool authdb::client::Client::remSession(){ Loading @@ -297,11 +313,8 @@ bool authdb::client::Client::remSession(){ 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)); Loading @@ -312,7 +325,10 @@ bool authdb::client::Client::remSession(){ resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -320,11 +336,17 @@ bool authdb::client::Client::remSession(){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ // FIX: jtok cleanup json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array) { // FIX: jrequest and jtok cleanup 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) { Loading Loading @@ -363,7 +385,6 @@ void authdb::client::Client::changeUserPw(const std::string& oldpw,const std::st 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)); libhttppp::HttpRequest nreq; Loading @@ -372,6 +393,12 @@ void authdb::client::Client::changeUserPw(const std::string& oldpw,const std::st std::vector<char> resp(_Con._Client->Post(nreq,out)); resp.push_back('\0'); // FIX: Release request objects (jresponse was missing, others fixed) json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(pchange); } void authdb::client::Client::getAvatar(const ::uuid::uuid &did,const ::uuid::uuid& uid,libhttppp::HttpRequest &resq,libhttppp::HttpResponse& resp){ Loading Loading @@ -417,7 +444,10 @@ bool authdb::client::Client::GPOcheck(class ::uuid::uuid gpoid){ resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -425,11 +455,17 @@ bool authdb::client::Client::GPOcheck(class ::uuid::uuid gpoid){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ // FIX: jtok cleanup json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array) { // FIX: jrequest and jtok cleanup json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } bool ret=false; Loading Loading @@ -476,18 +512,23 @@ void authdb::client::Client::addConnection(const std::string &clientname,const s resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(addclt); } void authdb::client::Client::remConnection(const uuid::uuid& clientid){ json_object *jresponse = json_object_new_object(); json_object *cmd=json_object_new_array(); json_object *obj=json_object_new_object(); json_object *addclt=json_object_new_object(); json_object *remclt=json_object_new_object(); // Renamed for clarity json_object_object_add(obj,"usersession", json_object_new_string(_Con.getSessionID().c_str())); json_object_object_add(obj,"remconnection", addclt); json_object_object_add(obj,"remconnection", remclt); json_object_object_add(addclt,"clientid",json_object_new_string(clientid.c_str())); json_object_object_add(remclt,"clientid",json_object_new_string(clientid.c_str())); json_object_array_add(cmd,obj); json_object_object_add(jresponse,"commands",cmd); Loading @@ -496,7 +537,6 @@ void authdb::client::Client::remConnection(const uuid::uuid& clientid){ 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)); libhttppp::HttpRequest nreq; Loading @@ -505,20 +545,26 @@ void authdb::client::Client::remConnection(const uuid::uuid& clientid){ std::vector<char> resp(_Con._Client->Post(nreq,out)); resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(remclt); } void authdb::client::Client::editConnection(const uuid::uuid& clientid,const std::string &clientname,const std::string &cltsecret){ json_object *jresponse = json_object_new_object(); json_object *cmd=json_object_new_array(); json_object *obj=json_object_new_object(); json_object *addclt=json_object_new_object(); json_object *editclt=json_object_new_object(); // Renamed for clarity json_object_object_add(obj,"usersession", json_object_new_string(_Con.getSessionID().c_str())); json_object_object_add(obj,"editconnection", addclt); json_object_object_add(obj,"editconnection", editclt); json_object_object_add(addclt,"clientid",json_object_new_string(clientid.c_str())); json_object_object_add(addclt,"clientname",json_object_new_string(clientname.c_str())); json_object_object_add(addclt,"clientsecret",json_object_new_string(cltsecret.c_str())); json_object_object_add(editclt,"clientid",json_object_new_string(clientid.c_str())); json_object_object_add(editclt,"clientname",json_object_new_string(clientname.c_str())); json_object_object_add(editclt,"clientsecret",json_object_new_string(cltsecret.c_str())); json_object_array_add(cmd,obj); json_object_object_add(jresponse,"commands",cmd); Loading @@ -527,7 +573,6 @@ void authdb::client::Client::editConnection(const uuid::uuid& clientid,const std 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)); libhttppp::HttpRequest nreq; Loading @@ -536,6 +581,12 @@ void authdb::client::Client::editConnection(const uuid::uuid& clientid,const std std::vector<char> resp(_Con._Client->Post(nreq,out)); resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(editclt); } bool authdb::client::Client::GPOexits(class uuid::uuid gpoid){ Loading @@ -555,7 +606,6 @@ bool authdb::client::Client::GPOexits(class uuid::uuid gpoid){ 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)); Loading @@ -566,7 +616,10 @@ bool authdb::client::Client::GPOexits(class uuid::uuid gpoid){ resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -574,11 +627,17 @@ bool authdb::client::Client::GPOexits(class uuid::uuid gpoid){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ // FIX: jtok cleanup json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array) { // FIX: jrequest and jtok cleanup json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } bool ret=false; Loading Loading
client/client.cpp +98 −39 Changes for client/client.cpp: 98 added lines, 39 removed lines. Original line number Diff line number Diff line Loading @@ -22,15 +22,18 @@ * 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. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF DAMAGE. *******************************************************************************/ #include <vector> #include <sstream> #include <algorithm> #include <cstring> #include <json.h> #include <json_object.h> #include <json_types.h> #include <json_tokener.h> #include "client.h" Loading Loading @@ -74,7 +77,6 @@ void authdb::client::ClientConnection::setSessionID(const ::uuid::uuid& sid){ _SessionID=sid; } authdb::client::Client::Client(ClientConnection& clt) : _Con(clt){ if(!_Con._Client){ _Con._Client=new libhttppp::HttpClient(_Con._Url); Loading Loading @@ -107,11 +109,8 @@ bool authdb::client::Client::ClientAuth(){ 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)); libhttppp::HttpRequest nreq; Loading @@ -121,34 +120,43 @@ bool authdb::client::Client::ClientAuth(){ resp.push_back('\0'); // std::cout <<resp.data() <<std::endl; json_object_put(jresponse); json_object_put(cmd); json_object_put(login); json_object_put(userauth); json_object *jrequest; json_tokener*jtok=json_tokener_new(); jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); // Error handling block if(!jrequest){ json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array){ json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } // Process Response 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(key,"connectionid")==0){ _Con._ClientId=json_object_get_string(val); if(!_Con._ClientId.empty()){ json_object_put(jrequest); json_tokener_free(jtok); return true; } } } } json_object_put(jrequest); json_tokener_free(jtok); return false; } Loading @@ -168,11 +176,8 @@ bool authdb::client::Client::UserAuth(){ 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)); libhttppp::HttpRequest nreq; Loading @@ -183,6 +188,9 @@ bool authdb::client::Client::UserAuth(){ resp.push_back('\0'); json_object_put(jresponse); json_object_put(cmd); json_object_put(login); json_object_put(userauth); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -190,11 +198,15 @@ bool authdb::client::Client::UserAuth(){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::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) { Loading @@ -209,6 +221,7 @@ bool authdb::client::Client::UserAuth(){ } } } json_object_put(jrequest); json_tokener_free(jtok); return false; Loading @@ -229,13 +242,9 @@ void authdb::client::Client::SessionInfo(class SessionData& sdat){ 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)); libhttppp::HttpRequest nreq; Loading @@ -245,7 +254,11 @@ void authdb::client::Client::SessionInfo(class SessionData& sdat){ resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(sinfo); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -253,15 +266,19 @@ void authdb::client::Client::SessionInfo(class SessionData& sdat){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ // FIX: jtok cleanup json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array){ // FIX: jrequest and jtok cleanup json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } sdat._uid.clear(); sdat._username.clear(); sdat._did.clear(); sdat.clear(); // Using the helper clear function int fcount = json_object_array_length(jrequest); for(int i =0; i<fcount; ++i) { Loading @@ -280,7 +297,6 @@ void authdb::client::Client::SessionInfo(class SessionData& sdat){ if(sdat._sid.empty()){ throw(authdb::AuthBackendError("Session not found !")); } } bool authdb::client::Client::remSession(){ Loading @@ -297,11 +313,8 @@ bool authdb::client::Client::remSession(){ 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)); Loading @@ -312,7 +325,10 @@ bool authdb::client::Client::remSession(){ resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -320,11 +336,17 @@ bool authdb::client::Client::remSession(){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ // FIX: jtok cleanup json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array) { // FIX: jrequest and jtok cleanup 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) { Loading Loading @@ -363,7 +385,6 @@ void authdb::client::Client::changeUserPw(const std::string& oldpw,const std::st 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)); libhttppp::HttpRequest nreq; Loading @@ -372,6 +393,12 @@ void authdb::client::Client::changeUserPw(const std::string& oldpw,const std::st std::vector<char> resp(_Con._Client->Post(nreq,out)); resp.push_back('\0'); // FIX: Release request objects (jresponse was missing, others fixed) json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(pchange); } void authdb::client::Client::getAvatar(const ::uuid::uuid &did,const ::uuid::uuid& uid,libhttppp::HttpRequest &resq,libhttppp::HttpResponse& resp){ Loading Loading @@ -417,7 +444,10 @@ bool authdb::client::Client::GPOcheck(class ::uuid::uuid gpoid){ resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -425,11 +455,17 @@ bool authdb::client::Client::GPOcheck(class ::uuid::uuid gpoid){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ // FIX: jtok cleanup json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array) { // FIX: jrequest and jtok cleanup json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } bool ret=false; Loading Loading @@ -476,18 +512,23 @@ void authdb::client::Client::addConnection(const std::string &clientname,const s resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(addclt); } void authdb::client::Client::remConnection(const uuid::uuid& clientid){ json_object *jresponse = json_object_new_object(); json_object *cmd=json_object_new_array(); json_object *obj=json_object_new_object(); json_object *addclt=json_object_new_object(); json_object *remclt=json_object_new_object(); // Renamed for clarity json_object_object_add(obj,"usersession", json_object_new_string(_Con.getSessionID().c_str())); json_object_object_add(obj,"remconnection", addclt); json_object_object_add(obj,"remconnection", remclt); json_object_object_add(addclt,"clientid",json_object_new_string(clientid.c_str())); json_object_object_add(remclt,"clientid",json_object_new_string(clientid.c_str())); json_object_array_add(cmd,obj); json_object_object_add(jresponse,"commands",cmd); Loading @@ -496,7 +537,6 @@ void authdb::client::Client::remConnection(const uuid::uuid& clientid){ 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)); libhttppp::HttpRequest nreq; Loading @@ -505,20 +545,26 @@ void authdb::client::Client::remConnection(const uuid::uuid& clientid){ std::vector<char> resp(_Con._Client->Post(nreq,out)); resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(remclt); } void authdb::client::Client::editConnection(const uuid::uuid& clientid,const std::string &clientname,const std::string &cltsecret){ json_object *jresponse = json_object_new_object(); json_object *cmd=json_object_new_array(); json_object *obj=json_object_new_object(); json_object *addclt=json_object_new_object(); json_object *editclt=json_object_new_object(); // Renamed for clarity json_object_object_add(obj,"usersession", json_object_new_string(_Con.getSessionID().c_str())); json_object_object_add(obj,"editconnection", addclt); json_object_object_add(obj,"editconnection", editclt); json_object_object_add(addclt,"clientid",json_object_new_string(clientid.c_str())); json_object_object_add(addclt,"clientname",json_object_new_string(clientname.c_str())); json_object_object_add(addclt,"clientsecret",json_object_new_string(cltsecret.c_str())); json_object_object_add(editclt,"clientid",json_object_new_string(clientid.c_str())); json_object_object_add(editclt,"clientname",json_object_new_string(clientname.c_str())); json_object_object_add(editclt,"clientsecret",json_object_new_string(cltsecret.c_str())); json_object_array_add(cmd,obj); json_object_object_add(jresponse,"commands",cmd); Loading @@ -527,7 +573,6 @@ void authdb::client::Client::editConnection(const uuid::uuid& clientid,const std 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)); libhttppp::HttpRequest nreq; Loading @@ -536,6 +581,12 @@ void authdb::client::Client::editConnection(const uuid::uuid& clientid,const std std::vector<char> resp(_Con._Client->Post(nreq,out)); resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object_put(editclt); } bool authdb::client::Client::GPOexits(class uuid::uuid gpoid){ Loading @@ -555,7 +606,6 @@ bool authdb::client::Client::GPOexits(class uuid::uuid gpoid){ 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)); Loading @@ -566,7 +616,10 @@ bool authdb::client::Client::GPOexits(class uuid::uuid gpoid){ resp.push_back('\0'); // FIX: Release request objects json_object_put(jresponse); json_object_put(cmd); json_object_put(obj); json_object *jrequest; json_tokener*jtok=json_tokener_new(); Loading @@ -574,11 +627,17 @@ bool authdb::client::Client::GPOexits(class uuid::uuid gpoid){ jrequest=json_tokener_parse_ex(jtok,resp.data(),resp.size()); if(!jrequest){ // FIX: jtok cleanup json_tokener_free(jtok); throw authdb::AuthBackendError(json_tokener_error_desc(json_tokener_get_error(jtok))); } if(json_object_get_type(jrequest)!=json_type::json_type_array) if(json_object_get_type(jrequest)!=json_type::json_type_array) { // FIX: jrequest and jtok cleanup json_object_put(jrequest); json_tokener_free(jtok); throw(authdb::AuthBackendError("Invalid Api Commands")); } bool ret=false; Loading