NeoMutt  2024-04-25-85-g27bab4
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
schema.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <sqlite3.h>
32#include <stddef.h>
33#include "private.h"
34#include "mutt/lib.h"
35
42{
43 char *errmsg = NULL;
44
45 const char *schema = "BEGIN TRANSACTION; "
46
47 "CREATE TABLE account ("
48 "email_addr text primary key not null, "
49 "keyid text, "
50 "keydata text, "
51 "prefer_encrypt int, "
52 "enabled int);"
53
54 "CREATE TABLE peer ("
55 "email_addr text primary key not null, "
56 "last_seen int, "
57 "autocrypt_timestamp int, "
58 "keyid text, "
59 "keydata text, "
60 "prefer_encrypt int, "
61 "gossip_timestamp int, "
62 "gossip_keyid text, "
63 "gossip_keydata text);"
64
65 "CREATE TABLE peer_history ("
66 "peer_email_addr text not null, "
67 "email_msgid text, "
68 "timestamp int, "
69 "keydata text);"
70
71 "CREATE INDEX peer_history_email "
72 "ON peer_history ("
73 "peer_email_addr);"
74
75 "CREATE TABLE gossip_history ("
76 "peer_email_addr text not null, "
77 "sender_email_addr text, "
78 "email_msgid text, "
79 "timestamp int, "
80 "gossip_keydata text);"
81
82 "CREATE INDEX gossip_history_email "
83 "ON gossip_history ("
84 "peer_email_addr);"
85
86 "CREATE TABLE schema ("
87 "version int);"
88
89 "INSERT into schema (version) values (1);"
90
91 "COMMIT TRANSACTION";
92
93 if (sqlite3_exec(AutocryptDB, schema, NULL, NULL, &errmsg) != SQLITE_OK)
94 {
95 mutt_debug(LL_DEBUG1, "mutt_autocrypt_schema_init() returned %s\n", errmsg);
96 sqlite3_free(errmsg);
97 return -1;
98 }
99 return 0;
100}
101
108{
109 sqlite3_stmt *stmt = NULL;
110 int rc = -1;
111
112 if (sqlite3_prepare_v2(AutocryptDB, "SELECT version FROM schema;", -1, &stmt, NULL) != SQLITE_OK)
113 goto cleanup;
114
115 if (sqlite3_step(stmt) != SQLITE_ROW)
116 goto cleanup;
117
118 int version = sqlite3_column_int(stmt, 0);
119
120 if (version > 1)
121 {
122 /* L10N: The autocrypt database keeps track of schema version numbers.
123 This error occurs if the version number is too high.
124 Presumably because this is an old version of NeoMutt and the
125 database was upgraded by a future version. */
126 mutt_error(_("Autocrypt database version is too new"));
127 goto cleanup;
128 }
129
130 /* TODO: schema version upgrades go here.
131 * Bump one by one, each update inside a transaction. */
132
133 rc = 0;
134
135cleanup:
136 sqlite3_finalize(stmt);
137 return rc;
138}
sqlite3 * AutocryptDB
Handle to the open Autocrypt database.
Definition: db.c:56
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
int mutt_autocrypt_schema_update(void)
Update the version number of the Autocrypt database schema.
Definition: schema.c:107
int mutt_autocrypt_schema_init(void)
Set up an Autocrypt database.
Definition: schema.c:41
GUI display the mailboxes in a side panel.