#ifndef SMCACHE_H #define SMCACHE_H #include #include #ifdef __cplusplus extern "C" { #endif #if defined(_WIN32) || defined(__CYGWIN__) # ifdef SMCACHE_BUILD # define SMCACHE_API __declspec(dllexport) # else # define SMCACHE_API __declspec(dllimport) # endif #else # if defined(__GNUC__) || defined(__clang__) # define SMCACHE_API __attribute__((visibility("default"))) # else # define SMCACHE_API # endif #endif #define SMCACHE_FMT_INVALID 0 #define SMCACHE_FMT_MP4_M4A 1 #define SMCACHE_FMT_MP3_ID3 2 #define SMCACHE_FMT_MPEG_RAW 3 #define SMCACHE_FMT_FLAC 4 #define SMCACHE_FMT_OGG 5 #define SMCACHE_FMT_WAV_AIFF 6 SMCACHE_API const char *smcache_version(void); SMCACHE_API int smcache_abi_version(void); SMCACHE_API const char *smcache_last_error(void); SMCACHE_API void smcache_free(void *ptr); SMCACHE_API int smcache_selftest(void); /* Inspect leading bytes (>= 12). Returns SMCACHE_FMT_* (0 = invalid / HTML / JSON). */ SMCACHE_API int smcache_has_valid_audio_magic(const uint8_t *buf, size_t len); SMCACHE_API const char *smcache_format_name(int fmt); /* Validate file on disk (exists, size >= min_bytes [default 1024 if <=0], valid audio magic). * Returns SMCACHE_FMT_* (>0) if valid, 0 if invalid, -1 on I/O error. */ SMCACHE_API int smcache_validate_file(const char *path, int64_t min_bytes); /* Returns 0 if HTTP status is 2xx (200..299), -1 otherwise. */ SMCACHE_API int smcache_validate_http_status(int status_code); /* Derive a cross-platform safe cache filename from a stream URL (percent-decoded, illegal chars * replaced, traversal blocked). Caller frees with smcache_free(). */ SMCACHE_API char *smcache_safe_filename(const char *stream_url); /* Scan a cache directory, optionally deleting invalid/corrupt files (purge_invalid != 0). * Returns JSON: {"validCount":N,"purgedCount":M,"totalBytes":B,"files":[{"name":...,"bytes":...,"format":...}]} * Caller frees with smcache_free(). */ SMCACHE_API char *smcache_scan_dir_json(const char *dir_path, int purge_invalid); /* Format byte count into human-readable string (e.g. "14.2 MB"). Returns length or -1. */ SMCACHE_API int smcache_format_bytes(int64_t bytes, char *buf, size_t buf_len); #ifdef __cplusplus } #endif #endif /* SMCACHE_H */