66 lines
2.2 KiB
C

/*
* this is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* this is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*
* (c) Alexander Vdolainen 2007, 2026 <alex@vapaa.xyz>
* subrelay: a minimalistic maillist server based on external IMAPs/SMTPs
*
* pending.h: maintain a pending list of emails
*
*/
#ifndef __PENDING_H__
#define __PENDING_H__
#include <time.h>
#include <ilib/splay.h>
#include <ilib/misc.h>
typedef struct pending_entry {
splay_node_t node;
char token[PENDING_ID_LEN + 1];
char *email;
time_t created_at; /* ttl to compare */
} pending_entry_t;
typedef struct pending_pool {
splay_t tree;
char *filepath;
long ttl_seconds; /* TTL defined for the pending list */
} 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__ */