ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
sqlite.c File Reference

💾 SQLite rate limiting backend More...

Go to the source code of this file.

Data Structures

struct  sqlite_backend_t
 This is the handoff point for sqlite backend. Callers fill db before passing it on; consumers read the values during the operation and return ownership only where the member contract explicitly says they do. More...

Functions

void * sqlite_backend_create (const char *db_path)
 Create SQLite backend instance.
void sqlite_backend_set_db (void *backend_data, sqlite3 *db)
 Set SQLite database handle for backend.

Variables

const rate_limiter_backend_ops_t sqlite_backend_ops
 SQLite backend operations vtable.

Detailed Description

💾 SQLite rate limiting backend

Persistent implementation for acds discovery server where persistence is needed.

Definition in file sqlite.c.

Function Documentation

◆ sqlite_backend_create()

void * sqlite_backend_create ( const char * db_path)

Create SQLite backend instance.

Parameters
db_pathPath to SQLite database (NULL = in-memory)
Returns
Backend instance or NULL on failure

Definition at line 156 of file sqlite.c.

156 {
157 (void)db_path; // Database is provided externally, not created here
158
159 sqlite_backend_t *backend = malloc(sizeof(sqlite_backend_t));
160 if (!backend) {
161 log_error("Failed to allocate SQLite backend");
162 return NULL;
163 }
164
165 memset(backend, 0, sizeof(*backend));
166
167 // Database handle will be set after creation by ACDS
168 // This is a placeholder backend that will be initialized later
169 log_debug("SQLite rate limiter backend allocated (database will be set externally)");
170 return backend;
171}
#define log_error(...)
Log an ERROR message.
Definition log/log.h:628
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:589
This is the handoff point for sqlite backend. Callers fill db before passing it on; consumers read th...
Definition sqlite.c:22

References log_debug, and log_error.

Referenced by rate_limiter_create_sqlite().

◆ sqlite_backend_set_db()

void sqlite_backend_set_db ( void * backend_data,
sqlite3 * db )

Set SQLite database handle for backend.

Called by ACDS after opening the database.

Definition at line 178 of file sqlite.c.

178 {
179 sqlite_backend_t *backend = (sqlite_backend_t *)backend_data;
180 if (backend) {
181 backend->db = db;
182 }
183}
sqlite3 * db
SQLite database handle.
Definition sqlite.c:23

References sqlite_backend_t::db.

Referenced by rate_limiter_set_sqlite_db().

Variable Documentation

◆ sqlite_backend_ops

const rate_limiter_backend_ops_t sqlite_backend_ops
Initial value:
= {
.check = sqlite_check,
.record = sqlite_record,
.cleanup = sqlite_cleanup,
.destroy = sqlite_destroy,
}

SQLite backend operations vtable.

Definition at line 185 of file sqlite.c.

185 {
186 .check = sqlite_check,
187 .record = sqlite_record,
188 .cleanup = sqlite_cleanup,
189 .destroy = sqlite_destroy,
190};

Referenced by rate_limiter_create_sqlite().