subrelay/include/ilib/pending.h

48 lines
1.6 KiB
C

/* pending.h - Pending subscription state tracker using splay tree */
#ifndef __PENDING_H__
#define __PENDING_H__
#include <time.h>
#include <ilib/splay.h>
#define PENDING_ID_LEN 16
typedef struct pending_entry {
splay_node_t node;
char token[PENDING_ID_LEN + 1]; /* Unique hex string token */
char *email; /* Applicant email address */
time_t created_at; /* Unix timestamp for TTL check */
} pending_entry_t;
typedef struct pending_pool {
splay_t tree;
char *filepath;
long ttl_seconds; /* Default TTL: e.g., 86400 (24h) */
} pending_pool_t;
int pending_pool_init(pending_pool_t *pool, const char *filepath, long ttl_seconds);
void pending_pool_destroy(pending_pool_t *pool);
/*
* Generates a unique token, attaches the email address, and inserts into tree.
* Populates out_token with the generated hex identifier string.
*/
int pending_add(pending_pool_t *pool, const char *email, char *out_token, size_t token_buf_len);
/*
* Looks up a pending token. If found and not expired, returns the associated applicant email.
* If expired, automatically purges the entry and returns NULL.
*/
char *pending_lookup_email(pending_pool_t *pool, const char *token);
/* Explicitly removes a pending token after successful confirmation */
int pending_remove(pending_pool_t *pool, const char *token);
/* Purges stale pending entries exceeding the TTL */
void pending_purge_expired(pending_pool_t *pool);
int pending_load_file(pending_pool_t *pool);
int pending_save_file(pending_pool_t *pool);
#endif /* __PENDING_H__ */