Commit 6b252b84 authored by jan.koester's avatar jan.koester
Browse files

test

parent 63e0d9ae
Loading
Loading
Loading
Loading
+45 −0
Changes for src/blogi.cpp: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -332,6 +332,51 @@ void blogi::Blogi::api(libhttppp::HttpRequest& curreq, const int tid){

    // 4. Process commands in external modules/plugins (Only if authentication succeeded)
    if(asuccess){
        // Extract authid from request for plugin delegation
        uuid::uuid authid;
        for (size_t ri = 0; ri < fcount; ++ri) {
            json_object *reqItem = json_object_array_get_idx(jrequest, ri);
            json_object *authObj = nullptr;
            if (json_object_object_get_ex(reqItem, "authid", &authObj)) {
                const char *authIdStr = json_object_get_string(authObj);
                if (authIdStr && authIdStr[0] != '\0')
                    authid = authIdStr;
                break;
            }
        }

        // Route unhandled commands to server plugins (media, etc.)
        for (size_t i = 0; i < fcount; ++i) {
            json_object *single_request = json_object_array_get_idx(jrequest, i);
            // Skip auth commands
            if (json_object_object_get(single_request, "authid") || json_object_object_get(single_request, "login"))
                continue;

            json_object *cmd_obj = nullptr;
            if (!json_object_object_get_ex(single_request, "command", &cmd_obj))
                continue;

            json_object *single_response = json_object_new_object();
            bool handled = false;

            for (const Plugin::PluginData *curplg = BlogiPlg->getFirstPlugin(); curplg; curplg = curplg->getNextPlg()) {
                PluginApi *api = curplg->getInstace();
                if (api) {
                    api->JsonApi(tid, single_request, single_response, authid);
                    if (json_object_object_get(single_response, "status") != nullptr) {
                        handled = true;
                        break;
                    }
                }
            }

            if (!handled) {
                json_object_object_add(single_response, "status", json_object_new_string("error"));
                json_object_object_add(single_response, "message",
                    json_object_new_string("Command not recognized by any plugin."));
            }
            json_object_array_add(jresponse, single_response);
        }
    }

    // 5. Send JSON Response