Commit 91489679 authored by jan.koester's avatar jan.koester
Browse files

add edit to api

parent d7c59697
Loading
Loading
Loading
Loading
Loading
+37 −0
Changes for src/api.cpp: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -317,6 +317,43 @@ namespace authdb {
                            json_object_array_add(response,respid);
                            clientid.clear();
                        }
                    }else if(strcmp(key,"editconnection")==0){
                        uuid clientid;
                        std::string name,secret;
                        int ocount = json_object_object_length(val);
                        for(int ii =0; ii<ocount; ++ii) {
                            json_object_object_foreach(val,okey,oval){
                                 if(strcmp(okey,"clientid")==0){
                                     clientid.parse(json_object_get_string(oval));
                                 }else if(strcmp(okey,"clientname")==0){
                                     name=json_object_get_string(oval);
                                 }else if(strcmp(okey,"clientsecret")==0){
                                     secret=json_object_get_string(oval);
                                 }
                            }
                        }
                        if(!clientid.empty() && (!name.empty() || !secret.empty()) ){
                            class Client clt;
                            class ClientData cdat(clientid);

                            size_t pos=sizeof(AuthHeader);

                            clt.info(_Backend,cdat,pos);

                            if(!name.empty() )
                                cdat.setName(name.c_str());
                            if(!secret.empty() )
                                cdat.setKey(secret.c_str());

                            clt.remove(_Backend,clientid);

                            clt.create(_Backend,&cdat);

                            json_object *respid=json_object_new_object();
                            json_object_object_add(respid,"editclient",json_object_new_string(clientid.c_str()));
                            json_object_array_add(response,respid);
                            clientid.clear();
                        }
                    }
                }
            }