Commit 2cfa9a2e authored by jan.koester's avatar jan.koester
Browse files

change locking

parent 5486981d
Loading
Loading
Loading
Loading
Loading
+1 −14
Changes for src/authdb.cpp: 1 added line, 14 removed lines.
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ namespace authdb {
        }

        void RequestEvent(libhttppp::HttpRequest * curreq, const int tid, ULONG_PTR args){
            AuthBackendLock admlock(_AdminBackend);
            if(curreq->getRequestURL().compare(0,10,"/authdb.js",10)==0){
                libhttppp::HttpResponse rep;
                rep.setState(HTTP200);
@@ -203,10 +204,8 @@ namespace authdb {
                rep.send(curreq,_AuthCss.data(),_AuthCss.size());
                return;
            }else if(_AdminBackend.end()<=sizeof(authdb::AuthHeader)){
                _AdminBackend.lock();
                try{
                    WizzardEvent(curreq,tid,args);
                    _AdminBackend.unlock();
                    return;
                }catch(libhttppp::HTTPException &e){
                    if(e.getErrorType()!=999){
@@ -214,16 +213,12 @@ namespace authdb {
                        rep.setState(HTTP500);
                        rep.setContentType("text/html");
                        rep.send(curreq,e.what(),strlen(e.what()));
                        _AdminBackend.unlock();
                        return;
                    }
                }
                _AdminBackend.unlock();

            }

            if(curreq->getRequestURL().compare(0,9,"/settings",9)==0){
                _AdminBackend.lock();
                try{
                    _AdminInterface.Request(curreq,tid,args);
                }catch(AuthBackendError &e){
@@ -232,11 +227,8 @@ namespace authdb {
                    rep.setContentType("text/html");
                    rep.send(curreq,e.what(),strlen(e.what()));
                }
                _AdminBackend.unlock();
                return;
            }if(curreq->getRequestURL().compare(0,4,"/api",4)==0){
                _AdminBackend.lock();

                DomainBackend db(_AdminBackend);

                AuthBackend *apidb=nullptr;
@@ -249,7 +241,6 @@ namespace authdb {
                    rep.setContentType("text/html");
                    char msg[]={"can't parse url"};
                    rep.send(curreq,msg,sizeof(msg));
                     _AdminBackend.unlock();
                    return;
                }

@@ -261,7 +252,6 @@ namespace authdb {
                    rep.setContentType("text/html");
                    char msg[]={"can't parse domain id"};
                    rep.send(curreq,msg,sizeof(msg));
                     _AdminBackend.unlock();
                    return;
                }

@@ -273,7 +263,6 @@ namespace authdb {
                    }
                    break;
                }
                _AdminBackend.unlock();

                if(apidb){
                    apidb->lock();
@@ -293,7 +282,6 @@ namespace authdb {
                    rep.send(curreq,"uuid not found!",12);
                }
            }else if(curreq->getRequestURL().compare(0,10,"/getavatar",10)==0){
                _AdminBackend.lock();
                try{
                    getAvatar(curreq,tid,args);
                }catch(AuthBackendError &e){
@@ -302,7 +290,6 @@ namespace authdb {
                    rep.setContentType("text/html");
                    rep.send(curreq,e.what(),strlen(e.what()));
                }
                _AdminBackend.unlock();
            }else{
                libhttppp::HttpResponse rep;
                rep.setState(HTTP307);
+8 −0
Changes for src/backend.cpp: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -87,3 +87,11 @@ size_t authdb::AuthBackend::getRevesion(){
void authdb::AuthBackend::newRevesion(){
    _Api->newRevesion();
}

authdb::AuthBackendLock::AuthBackendLock(AuthBackend &lock) : _Lock(lock){
    _Lock.lock();
}

authdb::AuthBackendLock::~AuthBackendLock(){
    _Lock.unlock();
}
+7 −1
Changes for src/backend.h: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -80,5 +80,11 @@ namespace authdb{
        const char                     *_Options;
        const char                     *_Domain;
    };

    class AuthBackendLock{
    public:
        AuthBackendLock(AuthBackend &lock);
        ~AuthBackendLock();
    private:
        AuthBackend &_Lock;
    };
};