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
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
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
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
Requirements
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
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
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
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
Requirements
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
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
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
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;
}
}