Commit 08ed7d2b authored by jan.koester's avatar jan.koester
Browse files

test

parent 6756a8bf
Loading
Loading
Loading
Loading
Loading
+19 −24
Changes for src/fenrirds.cpp: 19 added lines, 24 removed lines.
Original line number Diff line number Diff line
@@ -623,47 +623,40 @@ namespace fenrirds {
        void getAvatar(libhttppp::HttpRequest &curreq, const int tid, ULONG_PTR args){
            libhttppp::HttpResponse rep;

            AuthBackend *backend=nullptr;

            char domain[255],cuid[255],ext[16];
            if(sscanf(curreq.getRequestURL().c_str(),"/getavatar/%[^/]/%[^.].%s",domain,cuid,ext)<0){
                libhttppp::HttpResponse rep;
                rep.setState(HTTP400);
                rep.setContentType("text/html");
                rep.send(curreq,"bad avatar url",14);
                return;
            }
            char domain[255] = {}, cuid[255] = {}, ext[16] = {};
            sscanf(curreq.getRequestURL().c_str(), "/getavatar/%[^/]/%[^.].%s", domain, cuid, ext);

            /* Everything is best-effort: on ANY failure we fall through to the
             * built-in default below, so the UI never shows a broken image and
             * getAvatar never throws out of the request handler. */
            try {
                AuthBackend *backend = nullptr;
                ::uuid::uuid did;

            if(strcmp(domain,"admin") == 0 ){
                if (strcmp(domain, "admin") == 0)
                    backend = &_AdminBackend;
            }else if(did.parse(domain) == 0 ){
                else if (did.parse(domain) == 0)
                    backend = getDomainBackend(did);
            }else{
                throw AuthBackendError("createUser: could not parse uuid!");
            }

                ::uuid::uuid uid(cuid);

                /* 1. native UserData avatar */
                if (backend) {
                    try {
                        User user;
                        class UserData udat(uid);
                        size_t upos = sizeof(AuthHeader);
            try {
                        user.info(*backend, udat, upos);
                        std::vector<char> img;
                        udat.getAvatar(img);
                        if (!img.empty()) {
                    char ctype[255];
                    snprintf(ctype, 255, "image/%s", ext);
                    rep.setContentType(ctype);
                            rep.setContentType("image/jpeg");
                            rep.send(curreq, img, img.size());
                            return;
                        }
            } catch (AuthBackendError &) {
                    } catch (...) {}
                }

            /* directory user (no native record): serve its thumbnailPhoto */
                /* 2. directory object thumbnailPhoto */
                if (g_AdPlugin && strcmp(domain, "admin") != 0) {
                    std::string dnName;
                    try {
@@ -674,6 +667,7 @@ namespace fenrirds {
                        dnName = ddat.getDomainName();
                    } catch (...) {}
                    if (!dnName.empty()) {
                        try {
                            dsdb::Entry e;
                            std::string err;
                            if (g_AdPlugin->dirGet(dnName, uid, e, err)) {
@@ -684,11 +678,12 @@ namespace fenrirds {
                                    return;
                                }
                            }
                        } catch (...) {}
                    }
                }
            } catch (...) {}

            /* fallback: the built-in default avatar, so the UI never shows a
             * broken image for accounts without a picture */
            /* 3. fallback: the built-in default avatar */
            rep.setContentType("image/webp");
            rep.send(curreq, reinterpret_cast<const char*>(profile_webp), sizeof(profile_webp));
        };