1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! Typedefs for virtual function signatures.
use std::ffi::{c_char, c_int, c_uint, c_void};

pub type Wal = crate::ffi::libsql_wal;
use crate::ffi::{libsql_wal_methods, sqlite3, sqlite3_file, sqlite3_vfs, PgHdr};

// WAL methods
pub type XWalLimitFn = extern "C" fn(wal: *mut Wal, limit: i64);
pub type XWalBeginReadTransactionFn = extern "C" fn(wal: *mut Wal, changed: *mut c_int) -> c_int;
pub type XWalEndReadTransaction = extern "C" fn(wal: *mut Wal);
pub type XWalFindFrameFn = extern "C" fn(wal: *mut Wal, pgno: u32, frame: *mut u32) -> c_int;
pub type XWalReadFrameFn =
    extern "C" fn(wal: *mut Wal, frame: u32, n_out: c_int, p_out: *mut u8) -> c_int;
pub type XWalDbsizeFn = extern "C" fn(wal: *mut Wal) -> u32;
pub type XWalBeginWriteTransactionFn = extern "C" fn(wal: *mut Wal) -> c_int;
pub type XWalEndWriteTransactionFn = extern "C" fn(wal: *mut Wal) -> c_int;
pub type XWalSavepointFn = extern "C" fn(wal: *mut Wal, wal_data: *mut u32);
pub type XWalSavePointUndoFn = unsafe extern "C" fn(wal: *mut Wal, wal_data: *mut u32) -> c_int;
pub type XWalCheckpointFn = unsafe extern "C" fn(
    wal: *mut Wal,
    db: *mut sqlite3,
    emode: c_int,
    busy_handler: Option<unsafe extern "C" fn(busy_param: *mut c_void) -> c_int>,
    busy_arg: *mut c_void,
    sync_flags: c_int,
    n_buf: c_int,
    z_buf: *mut u8,
    frames_in_wal: *mut c_int,
    backfilled_frames: *mut c_int,
) -> c_int;
pub type XWalCallbackFn = extern "C" fn(wal: *mut Wal) -> c_int;
pub type XWalExclusiveModeFn = extern "C" fn(wal: *mut Wal, op: c_int) -> c_int;
pub type XWalHeapMemoryFn = extern "C" fn(wal: *mut Wal) -> c_int;
pub type XWalFileFn = extern "C" fn(wal: *mut Wal) -> *mut sqlite3_file;
pub type XWalDbFn = extern "C" fn(wal: *mut Wal, db: *mut sqlite3);
pub type XWalPathNameLenFn = extern "C" fn(orig_len: c_int) -> c_int;
pub type XWalGetPathNameFn = extern "C" fn(buf: *mut c_char, orig: *const c_char, orig_len: c_int);
pub type XWalPreMainDbOpen =
    extern "C" fn(methods: *mut libsql_wal_methods, path: *const c_char) -> c_int;
pub type XWalOpenFn = extern "C" fn(
    vfs: *mut sqlite3_vfs,
    file: *mut sqlite3_file,
    wal_name: *const c_char,
    no_shm_mode: c_int,
    max_size: i64,
    methods: *mut libsql_wal_methods,
    wal: *mut *mut Wal,
) -> c_int;
pub type XWalCloseFn = extern "C" fn(
    wal: *mut Wal,
    db: *mut sqlite3,
    sync_flags: c_int,
    n_buf: c_int,
    z_buf: *mut u8,
) -> c_int;
pub type XWalFrameFn = unsafe extern "C" fn(
    wal: *mut Wal,
    page_size: c_int,
    page_headers: *mut PgHdr,
    size_after: u32,
    is_commit: c_int,
    sync_flags: c_int,
) -> c_int;
pub type XWalUndoFn = unsafe extern "C" fn(
    wal: *mut Wal,
    func: Option<unsafe extern "C" fn(*mut c_void, c_uint) -> c_int>,
    ctx: *mut c_void,
) -> c_int;

// io methods
pub type XAccessFn = unsafe extern "C" fn(
    vfs: *mut sqlite3_vfs,
    name: *const c_char,
    flags: c_int,
    res: *mut c_int,
) -> c_int;
pub type XDeleteFn =
    unsafe extern "C" fn(vfs: *mut sqlite3_vfs, name: *const c_char, sync_dir: c_int) -> c_int;
pub type XFullPathNameFn = unsafe extern "C" fn(
    vfs: *mut sqlite3_vfs,
    name: *const c_char,
    n: c_int,
    out: *mut c_char,
) -> c_int;
pub type XOpenFn = unsafe extern "C" fn(
    vfs: *mut sqlite3_vfs,
    name: *const c_char,
    file: *mut sqlite3_file,
    flags: c_int,
    out_flags: *mut c_int,
) -> c_int;
pub type XDlOpenFn =
    unsafe extern "C" fn(vfs: *mut sqlite3_vfs, name: *const c_char) -> *const c_void;
pub type XDlErrorFn = unsafe extern "C" fn(vfs: *mut sqlite3_vfs, n: c_int, msg: *mut c_char);
pub type XDlSymFn = unsafe extern "C" fn(
    vfs: *mut sqlite3_vfs,
    arg: *mut c_void,
    symbol: *const c_char,
) -> unsafe extern "C" fn();
pub type XDlCloseFn = unsafe extern "C" fn(vfs: *mut sqlite3_vfs, arg: *mut c_void);
pub type XRandomnessFn =
    unsafe extern "C" fn(vfs: *mut sqlite3_vfs, n_bytes: c_int, out: *mut c_char) -> c_int;
pub type XSleepFn = unsafe extern "C" fn(vfs: *mut sqlite3_vfs, ms: c_int) -> c_int;
pub type XCurrentTimeFn = unsafe extern "C" fn(vfs: *mut sqlite3_vfs, time: *mut f64) -> c_int;
pub type XGetLastErrorFn =
    unsafe extern "C" fn(vfs: *mut sqlite3_vfs, n: c_int, buf: *mut c_char) -> c_int;
pub type XCurrentTimeInt64 = unsafe extern "C" fn(vfs: *mut sqlite3_vfs, time: *mut i64) -> c_int;
pub type XCloseFn = unsafe extern "C" fn(file_ptr: *mut sqlite3_file) -> c_int;
pub type XReadFn = unsafe extern "C" fn(
    file_ptr: *mut sqlite3_file,
    buf: *mut c_char,
    n: c_int,
    off: i64,
) -> c_int;
pub type XWriteFn = unsafe extern "C" fn(
    file_ptr: *mut sqlite3_file,
    buf: *const c_char,
    n: c_int,
    off: i64,
) -> c_int;
pub type XTruncateFn = unsafe extern "C" fn(file_ptr: *mut sqlite3_file, size: i64) -> c_int;
pub type XSyncFn = unsafe extern "C" fn(file_ptr: *mut sqlite3_file, flags: c_int) -> c_int;
pub type XFileSizeFn = unsafe extern "C" fn(file_ptr: *mut sqlite3_file, size: *mut i64) -> c_int;
pub type XLockFn = unsafe extern "C" fn(file_ptr: *mut sqlite3_file, lock: c_int) -> c_int;
pub type XUnlockFn = unsafe extern "C" fn(file_ptr: *mut sqlite3_file, lock: c_int) -> c_int;
pub type XCheckReservedLockFn =
    unsafe extern "C" fn(file_ptr: *mut sqlite3_file, res: *mut c_int) -> c_int;
pub type XFileControlFn =
    unsafe extern "C" fn(file_ptr: *mut sqlite3_file, op: c_int, arg: *mut c_void) -> c_int;
pub type XSectorSizeFn = unsafe extern "C" fn(file_ptr: *mut sqlite3_file) -> c_int;
pub type XDeviceCharacteristicsFn = unsafe extern "C" fn(file_ptr: *mut sqlite3_file) -> c_int;