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