| 2577 | } |
| 2578 | |
| 2579 | static cbm_daemon_runtime_application_status_t application_tool_request( |
| 2580 | cbm_daemon_application_session_t *session, const uint8_t *request, uint32_t request_length, |
| 2581 | uint8_t **response_out, uint32_t *response_length_out) { |
| 2582 | if (!session->context_set || request_length <= APPLICATION_TOOL_HEADER_SIZE) { |
| 2583 | return CBM_DAEMON_RUNTIME_APPLICATION_REJECTED; |
| 2584 | } |
| 2585 | uint32_t tool_length = application_get_u32(request + 1); |
| 2586 | if (tool_length == 0 || tool_length >= request_length - APPLICATION_TOOL_HEADER_SIZE) { |
| 2587 | return CBM_DAEMON_RUNTIME_APPLICATION_REJECTED; |
| 2588 | } |
| 2589 | char *tool = application_text_copy(request + APPLICATION_TOOL_HEADER_SIZE, tool_length); |
| 2590 | uint32_t args_length = request_length - APPLICATION_TOOL_HEADER_SIZE - tool_length; |
| 2591 | char *args = |
| 2592 | application_text_copy(request + APPLICATION_TOOL_HEADER_SIZE + tool_length, args_length); |
| 2593 | if (!tool || !args) { |
| 2594 | free(tool); |
| 2595 | free(args); |
| 2596 | return CBM_DAEMON_RUNTIME_APPLICATION_REJECTED; |
| 2597 | } |
| 2598 | char *response = cbm_mcp_handle_tool(session->mcp, tool, args); |
| 2599 | free(tool); |
| 2600 | free(args); |
| 2601 | if (!response) { |
| 2602 | return CBM_DAEMON_RUNTIME_APPLICATION_HANDLER_ERROR; |
| 2603 | } |
| 2604 | size_t response_length = strlen(response); |
| 2605 | if (response_length > UINT32_MAX) { |
| 2606 | free(response); |
| 2607 | return CBM_DAEMON_RUNTIME_APPLICATION_HANDLER_ERROR; |
| 2608 | } |
| 2609 | *response_out = (uint8_t *)response; |
| 2610 | *response_length_out = (uint32_t)response_length; |
| 2611 | application_refresh_watch(session); |
| 2612 | return CBM_DAEMON_RUNTIME_APPLICATION_OK; |
| 2613 | } |
| 2614 | |
| 2615 | static cbm_daemon_runtime_application_status_t application_set_ui_config( |
| 2616 | cbm_daemon_application_t *application, cbm_daemon_application_session_t *session, |
no test coverage detected