entropic_audit.cpp

src/facade/entropic_audit.cpp

@file entropic_audit.cpp @brief C API facade for audit log operations.

Owners: @tvanfossen

entropic_audit_count

ENTROPIC_EXPORT entropic_error_t entropic_audit_count(entropic_handle_t handle, size_t *count)

Get the number of audit log entries this session.

src/facade/entropic_audit.cpp:49

Show on the map →

Called by SCENARIO, TEST_CASE

Calls none

Source · 9 lines
entropic_audit_count(entropic_handle_t handle, size_t* count) {
    if (!handle || !count) {
        return !handle ? ENTROPIC_ERROR_INVALID_HANDLE
                       : ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    *count = handle->audit_logger
        ? handle->audit_logger->entry_count() : 0;
    return ENTROPIC_OK;
}
Activity · 4 steps
lines 50–50◇ if (!handle || !count)lines 51–52return !handle ? ENTROPIC_ERROR_INVALID_HANDLE : ENTROPIC_ERROR_INVALID_ARGUMENT;lines 54–55*count = handle->audit_logger ? handle->audit_logger->entry_count() : 0;lines 56–56return ENTROPIC_OK;
ENTROPIC_EXPORT entropic_error_t entropic_audit_count(entropic_handle_t handle, size_t *count)

Get the number of audit log entries recorded this session.

src/facade/entropic_audit.cpp:49

Show on the map →

Called by SCENARIO

Calls entry_count

Source · 9 lines
entropic_audit_count(entropic_handle_t handle, size_t* count) {
    if (!handle || !count) {
        return !handle ? ENTROPIC_ERROR_INVALID_HANDLE
                       : ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    *count = handle->audit_logger
        ? handle->audit_logger->entry_count() : 0;
    return ENTROPIC_OK;
}
Activity · 4 steps
lines 50–50◇ if (!handle || !count)lines 51–52return !handle ? ENTROPIC_ERROR_INVALID_HANDLE : ENTROPIC_ERROR_INVALID_ARGUMENT;lines 54–55*count = handle->audit_logger ? handle->audit_logger->entry_count() : 0;lines 56–56return ENTROPIC_OK;

Requirements

REQ-API-005 REQ-STOR-008

entropic_audit_flush

ENTROPIC_EXPORT entropic_error_t entropic_audit_flush(entropic_handle_t handle)

Flush the audit logger to disk.

src/facade/entropic_audit.cpp:33

Show on the map →

Called by SCENARIO, TEST_CASE

Calls none

Source · 6 lines
entropic_audit_flush(entropic_handle_t handle) {
    if (!handle) { return ENTROPIC_ERROR_INVALID_HANDLE; }
    if (!handle->audit_logger) { return ENTROPIC_OK; }
    handle->audit_logger->flush();
    return ENTROPIC_OK;
}
Activity · 6 steps
lines 34–34◇ if (!handle)lines 34–34return ENTROPIC_ERROR_INVALID_HANDLE;lines 35–35◇ if (!handle->audit_logger)lines 35–35return ENTROPIC_OK;lines 36–36handle->audit_logger->flush();lines 37–37return ENTROPIC_OK;
ENTROPIC_EXPORT entropic_error_t entropic_audit_flush(entropic_handle_t handle)

Flush the audit logger to disk immediately.

src/facade/entropic_audit.cpp:33

Show on the map →

Called by SCENARIO, TEST_CASE

Calls flush

Source · 6 lines
entropic_audit_flush(entropic_handle_t handle) {
    if (!handle) { return ENTROPIC_ERROR_INVALID_HANDLE; }
    if (!handle->audit_logger) { return ENTROPIC_OK; }
    handle->audit_logger->flush();
    return ENTROPIC_OK;
}
Activity · 6 steps
lines 34–34◇ if (!handle)lines 34–34return ENTROPIC_ERROR_INVALID_HANDLE;lines 35–35◇ if (!handle->audit_logger)lines 35–35return ENTROPIC_OK;lines 36–36handle->audit_logger->flush();lines 37–37return ENTROPIC_OK;

Requirements

REQ-API-005 REQ-STOR-008

entropic_audit_read

ENTROPIC_EXPORT entropic_error_t entropic_audit_read(entropic_handle_t handle, const char *path, const char *, char **result_json)

Read audit log entries from a JSONL file.

src/facade/entropic_audit.cpp:72

Show on the map →

Called by SCENARIO

Calls sanitize_utf8

Source · 32 lines
entropic_audit_read(
    entropic_handle_t handle,
    const char* path,
    const char* /*filter_json*/,
    char** result_json) {
    if (!handle || !path || !result_json) {
        return !handle ? ENTROPIC_ERROR_INVALID_HANDLE
                       : ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    try {
        std::ifstream file(path);
        if (!file.is_open()) { throw std::runtime_error("cannot open"); }
        nlohmann::json arr = nlohmann::json::array();
        std::string line;
        while (std::getline(file, line)) {
            if (line.empty()) { continue; }
            // Issue #3 (v2.1.1): inbound boundary from disk. Audit files
            // written by pre-2.1.1 engine versions (or by future writers
            // that miss a sanitize step) may contain bytes that parse
            // fine but throw on the arr.dump() below. Sanitize before
            // ingestion so the dump cannot fail. See
            // include/entropic/mcp/utf8_sanitize.h for the boundary policy.
            arr.push_back(nlohmann::json::parse(
                entropic::mcp::sanitize_utf8(line)));
        }
        *result_json = strdup(arr.dump().c_str());
        return ENTROPIC_OK;
    } catch (const std::exception& e) {
        handle->last_error = e.what();
        return ENTROPIC_ERROR_IO;
    }
}
Activity · 3 steps
lines 77–77◇ if (!handle || !path || !result_json)lines 78–79return !handle ? ENTROPIC_ERROR_INVALID_HANDLE : ENTROPIC_ERROR_INVALID_ARGUMENT;lines 81–102try { std::ifstream file(path); if (!file.is_open()) { throw std::runtime_error("cannot open"); } nlohmann::json arr = nlohmann::json::array(); std::string line; while (std::getline(file, line)) { if (line.empty()) { continue; } // Issue #3 (v2.1.1): inbound boundary from disk. Audit files // written by pre-2.1.1 engine versions (or by future writers // that miss a sanitize step) may contain bytes that parse // fine but throw on the arr.dump() below. Sanitize before // ingestion so the dump cannot fail. See // include/entropic/mcp/utf8_sanitize.h for the boundary policy. arr.push_back(nlohmann::json::parse( entropic::mcp::sanitize_utf8(line))); } *result_json = strdup(arr.dump().c_str()); return ENTROPIC_OK; } catch (const std::exception& e) { handle->last_error = e.what(); return ENTROPIC_ERROR_IO; }
ENTROPIC_EXPORT entropic_error_t entropic_audit_read(entropic_handle_t handle, const char *path, const char *filter_json, char **result_json)

Read audit log entries from a JSONL file.

src/facade/entropic_audit.cpp:72

Show on the map →

Called by SCENARIO

Calls sanitize_utf8

Source · 32 lines
entropic_audit_read(
    entropic_handle_t handle,
    const char* path,
    const char* /*filter_json*/,
    char** result_json) {
    if (!handle || !path || !result_json) {
        return !handle ? ENTROPIC_ERROR_INVALID_HANDLE
                       : ENTROPIC_ERROR_INVALID_ARGUMENT;
    }
    try {
        std::ifstream file(path);
        if (!file.is_open()) { throw std::runtime_error("cannot open"); }
        nlohmann::json arr = nlohmann::json::array();
        std::string line;
        while (std::getline(file, line)) {
            if (line.empty()) { continue; }
            // Issue #3 (v2.1.1): inbound boundary from disk. Audit files
            // written by pre-2.1.1 engine versions (or by future writers
            // that miss a sanitize step) may contain bytes that parse
            // fine but throw on the arr.dump() below. Sanitize before
            // ingestion so the dump cannot fail. See
            // include/entropic/mcp/utf8_sanitize.h for the boundary policy.
            arr.push_back(nlohmann::json::parse(
                entropic::mcp::sanitize_utf8(line)));
        }
        *result_json = strdup(arr.dump().c_str());
        return ENTROPIC_OK;
    } catch (const std::exception& e) {
        handle->last_error = e.what();
        return ENTROPIC_ERROR_IO;
    }
}
Activity · 3 steps
lines 77–77◇ if (!handle || !path || !result_json)lines 78–79return !handle ? ENTROPIC_ERROR_INVALID_HANDLE : ENTROPIC_ERROR_INVALID_ARGUMENT;lines 81–102try { std::ifstream file(path); if (!file.is_open()) { throw std::runtime_error("cannot open"); } nlohmann::json arr = nlohmann::json::array(); std::string line; while (std::getline(file, line)) { if (line.empty()) { continue; } // Issue #3 (v2.1.1): inbound boundary from disk. Audit files // written by pre-2.1.1 engine versions (or by future writers // that miss a sanitize step) may contain bytes that parse // fine but throw on the arr.dump() below. Sanitize before // ingestion so the dump cannot fail. See // include/entropic/mcp/utf8_sanitize.h for the boundary policy. arr.push_back(nlohmann::json::parse( entropic::mcp::sanitize_utf8(line))); } *result_json = strdup(arr.dump().c_str()); return ENTROPIC_OK; } catch (const std::exception& e) { handle->last_error = e.what(); return ENTROPIC_ERROR_IO; }

Requirements

REQ-ABI-002 REQ-API-005 REQ-API-008 REQ-STOR-008