#ifndef SMAUTH_H #define SMAUTH_H #include #include #ifdef __cplusplus extern "C" { #endif #if defined(_WIN32) || defined(__CYGWIN__) # ifdef SMAUTH_BUILD # define SMAUTH_API __declspec(dllexport) # else # define SMAUTH_API __declspec(dllimport) # endif #else # if defined(__GNUC__) || defined(__clang__) # define SMAUTH_API __attribute__((visibility("default"))) # else # define SMAUTH_API # endif #endif SMAUTH_API const char *smauth_version(void); SMAUTH_API int smauth_abi_version(void); SMAUTH_API const char *smauth_last_error(void); SMAUTH_API void smauth_free(void *ptr); SMAUTH_API int smauth_selftest(void); /* Strict UUID/GUID validator (8-4-4-4-12 hex). Returns 0 if valid, -1 otherwise. */ SMAUTH_API int smauth_is_valid_guid(const char *guid); /* Decode a JWT payload (base64url) into canonical claims JSON: * {"sub":...,"email":...,"iss":...,"exp":N,"iat":N,"isExpired":bool,"isAdmin":bool,"hasValidGuid":bool,"permissions":[...]} * Caller frees with smauth_free(). Returns NULL on malformed JWT. */ SMAUTH_API char *smauth_parse_jwt_claims_json(const char *jwt, int64_t now_epoch); /* Extract sx_token JWT from a Set-Cookie header or callback URL query (?token=... / ?sx_token=...). * Caller frees with smauth_free(). Returns NULL if not found or invalid. */ SMAUTH_API char *smauth_extract_token(const char *header_or_url); /* Validate JWT characters (prevent CR/LF header injection) and format "sx_token=" Cookie value. * Caller frees with smauth_free(). Returns NULL on invalid token. */ SMAUTH_API char *smauth_build_cookie_value(const char *jwt); /* Build transport-agnostic JSON request descriptor for native login POST. * Caller frees with smauth_free(). Returns NULL on invalid email/password/base_url. */ SMAUTH_API char *smauth_build_login_request_json(const char *auth_base_url, const char *email, const char *password); /* Build percent-encoded web login URL: "/login?redirect=". * Caller frees with smauth_free(). */ SMAUTH_API char *smauth_build_web_login_url(const char *auth_base_url, const char *redirect_uri); /* Compute Guest vs Signed-In session policy & per-user endpoints (NEVER hardcodes a personal GUID). * Caller frees with smauth_free(). */ SMAUTH_API char *smauth_session_policy_json(const char *jwt, int64_t now_epoch, const char *dist_base_url, const char *hub_base_url); #ifdef __cplusplus } #endif #endif /* SMAUTH_H */