Loading src/api.cpp +68 −0 Changes for src/api.cpp: 68 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include <json-c/json.h> #include <json-c/json_types.h> #include <json-c/json_object.h> #include "hash.h" #include "hash/sha512.h" Loading Loading @@ -102,6 +103,73 @@ namespace authdb { } } void addGPO(json_object *request,json_object *response){ json_object *cmd=json_object_object_get(request,"commands"); if(!cmd) throw(AuthBackendError("Invalid Api Commands")); 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) { if(strcmp(key,"gpoadd")==0){ std::string name,desc; bool dflt=false; std::vector<uuid> members; int ocount = json_object_object_length(val); for(int ii =0; ii<ocount; ++ii) { json_object_object_foreach(val,okey,oval){ if(strcmp(okey,"gponame")==0){ name=json_object_get_string(oval); }else if(strcmp(okey,"gpodesc")==0){ desc=json_object_get_string(oval); }else if(strcmp(okey,"gpodefault")==0){ dflt=json_object_get_boolean(oval); }else if(strcmp(okey,"gpomembers")==0){ for(int iii=0; i < json_object_array_length(oval); ++iii){ members.emplace_back(json_object_get_string(json_object_array_get_idx(oval,iii))); } } } } if(name.empty() || desc.empty()){ continue; } json_object *respid=json_object_new_object(); json_object *value=json_object_new_object(); uuid id; id.generate(); class GpoData gdat(id); gdat.setName(name.c_str()); gdat.setDesc(desc.c_str()); gdat.setGpoValue(dflt); gdat.setAllowed(members); class Gpo gpo; gpo.create(_Backend,&gdat); int ret=-1; if(gpo.exits(_Backend,id,nullptr,ret)){ json_object_object_add(value,id.c_str(),json_object_new_boolean(true)); }else{ json_object_object_add(value,id.c_str(),json_object_new_boolean(false)); } json_object_object_add(respid,"gpoadd",value); json_object_array_add(response,respid); } } } } const SessionData *checkUser(json_object *request,json_object *response){ json_object *cmd=json_object_object_get(request,"commands"); Loading Loading
src/api.cpp +68 −0 Changes for src/api.cpp: 68 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include <json-c/json.h> #include <json-c/json_types.h> #include <json-c/json_object.h> #include "hash.h" #include "hash/sha512.h" Loading Loading @@ -102,6 +103,73 @@ namespace authdb { } } void addGPO(json_object *request,json_object *response){ json_object *cmd=json_object_object_get(request,"commands"); if(!cmd) throw(AuthBackendError("Invalid Api Commands")); 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) { if(strcmp(key,"gpoadd")==0){ std::string name,desc; bool dflt=false; std::vector<uuid> members; int ocount = json_object_object_length(val); for(int ii =0; ii<ocount; ++ii) { json_object_object_foreach(val,okey,oval){ if(strcmp(okey,"gponame")==0){ name=json_object_get_string(oval); }else if(strcmp(okey,"gpodesc")==0){ desc=json_object_get_string(oval); }else if(strcmp(okey,"gpodefault")==0){ dflt=json_object_get_boolean(oval); }else if(strcmp(okey,"gpomembers")==0){ for(int iii=0; i < json_object_array_length(oval); ++iii){ members.emplace_back(json_object_get_string(json_object_array_get_idx(oval,iii))); } } } } if(name.empty() || desc.empty()){ continue; } json_object *respid=json_object_new_object(); json_object *value=json_object_new_object(); uuid id; id.generate(); class GpoData gdat(id); gdat.setName(name.c_str()); gdat.setDesc(desc.c_str()); gdat.setGpoValue(dflt); gdat.setAllowed(members); class Gpo gpo; gpo.create(_Backend,&gdat); int ret=-1; if(gpo.exits(_Backend,id,nullptr,ret)){ json_object_object_add(value,id.c_str(),json_object_new_boolean(true)); }else{ json_object_object_add(value,id.c_str(),json_object_new_boolean(false)); } json_object_object_add(respid,"gpoadd",value); json_object_array_add(response,respid); } } } } const SessionData *checkUser(json_object *request,json_object *response){ json_object *cmd=json_object_object_get(request,"commands"); Loading