NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
schema.c
Go to the documentation of this file.
1
23
29
30
#include "config.h"
31
#include <sqlite3.h>
32
#include <stddef.h>
33
#include "
private.h
"
34
#include "
mutt/lib.h
"
35
#include "
core/lib.h
"
36
#include "
module_data.h
"
37
43
int
mutt_autocrypt_schema_init
(
void
)
44
{
45
char
*errmsg = NULL;
46
struct
AutocryptModuleData
*mod_data =
neomutt_get_module_data
(
NeoMutt
,
MODULE_ID_AUTOCRYPT
);
47
sqlite3 *db = mod_data->
autocrypt_db
;
48
49
const
char
*schema =
"BEGIN TRANSACTION; "
50
51
"CREATE TABLE account ("
52
"email_addr text primary key not null, "
53
"keyid text, "
54
"keydata text, "
55
"prefer_encrypt int, "
56
"enabled int);"
57
58
"CREATE TABLE peer ("
59
"email_addr text primary key not null, "
60
"last_seen int, "
61
"autocrypt_timestamp int, "
62
"keyid text, "
63
"keydata text, "
64
"prefer_encrypt int, "
65
"gossip_timestamp int, "
66
"gossip_keyid text, "
67
"gossip_keydata text);"
68
69
"CREATE TABLE peer_history ("
70
"peer_email_addr text not null, "
71
"email_msgid text, "
72
"timestamp int, "
73
"keydata text);"
74
75
"CREATE INDEX peer_history_email "
76
"ON peer_history ("
77
"peer_email_addr);"
78
79
"CREATE TABLE gossip_history ("
80
"peer_email_addr text not null, "
81
"sender_email_addr text, "
82
"email_msgid text, "
83
"timestamp int, "
84
"gossip_keydata text);"
85
86
"CREATE INDEX gossip_history_email "
87
"ON gossip_history ("
88
"peer_email_addr);"
89
90
"CREATE TABLE schema ("
91
"version int);"
92
93
"INSERT into schema (version) values (1);"
94
95
"COMMIT TRANSACTION"
;
96
97
if
(sqlite3_exec(db, schema, NULL, NULL, &errmsg) != SQLITE_OK)
98
{
99
mutt_debug
(
LL_DEBUG1
,
"mutt_autocrypt_schema_init() returned %s\n"
, errmsg);
100
sqlite3_free(errmsg);
101
return
-1;
102
}
103
return
0;
104
}
105
111
int
mutt_autocrypt_schema_update
(
void
)
112
{
113
sqlite3_stmt *stmt = NULL;
114
int
rc = -1;
115
struct
AutocryptModuleData
*mod_data =
neomutt_get_module_data
(
NeoMutt
,
MODULE_ID_AUTOCRYPT
);
116
sqlite3 *db = mod_data->
autocrypt_db
;
117
118
if
(sqlite3_prepare_v2(db,
"SELECT version FROM schema;"
, -1, &stmt, NULL) != SQLITE_OK)
119
goto
cleanup;
120
121
if
(sqlite3_step(stmt) != SQLITE_ROW)
122
goto
cleanup;
123
124
int
version = sqlite3_column_int(stmt, 0);
125
126
if
(version > 1)
127
{
128
/* L10N: The autocrypt database keeps track of schema version numbers.
129
This error occurs if the version number is too high.
130
Presumably because this is an old version of NeoMutt and the
131
database was upgraded by a future version. */
132
mutt_error
(
_
(
"Autocrypt database version is too new"
));
133
goto
cleanup;
134
}
135
136
/* TODO: schema version upgrades go here.
137
* Bump one by one, each update inside a transaction. */
138
139
rc = 0;
140
141
cleanup:
142
sqlite3_finalize(stmt);
143
return
rc;
144
}
module_data.h
Autocrypt private Module data.
private.h
Shared constants/structs that are private to Autocrypt.
lib.h
Convenience wrapper for the core headers.
mutt_error
#define mutt_error(...)
Definition
logging2.h:94
mutt_debug
#define mutt_debug(LEVEL,...)
Definition
logging2.h:91
LL_DEBUG1
@ LL_DEBUG1
Log at debug level 1.
Definition
logging2.h:45
MODULE_ID_AUTOCRYPT
@ MODULE_ID_AUTOCRYPT
ModuleAutocrypt, Autocrypt
Definition
module_api.h:50
lib.h
Convenience wrapper for the library headers.
_
#define _(a)
Definition
message.h:28
neomutt_get_module_data
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition
neomutt.c:666
mutt_autocrypt_schema_update
int mutt_autocrypt_schema_update(void)
Update the version number of the Autocrypt database schema.
Definition
schema.c:111
mutt_autocrypt_schema_init
int mutt_autocrypt_schema_init(void)
Set up an Autocrypt database.
Definition
schema.c:43
AutocryptModuleData
Autocrypt private Module data.
Definition
module_data.h:32
AutocryptModuleData::autocrypt_db
sqlite3 * autocrypt_db
Autocrypt database.
Definition
module_data.h:38
NeoMutt
Container for Accounts, Notifications.
Definition
neomutt.h:41