NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
schema.c File Reference

Autocrypt database schema. More...

#include "config.h"
#include <sqlite3.h>
#include <stddef.h>
#include "private.h"
#include "mutt/lib.h"
#include "core/lib.h"
#include "module_data.h"
+ Include dependency graph for schema.c:

Go to the source code of this file.

Functions

int mutt_autocrypt_schema_init (void)
 Set up an Autocrypt database.
 
int mutt_autocrypt_schema_update (void)
 Update the version number of the Autocrypt database schema.
 

Detailed Description

Autocrypt database schema.

Authors
  • Richard Russon
  • Kevin J. McCarthy

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file schema.c.

Function Documentation

◆ mutt_autocrypt_schema_init()

int mutt_autocrypt_schema_init ( void )

Set up an Autocrypt database.

Return values
0Success
-1Error

Definition at line 43 of file schema.c.

44{
45 char *errmsg = NULL;
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}
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
@ MODULE_ID_AUTOCRYPT
ModuleAutocrypt, Autocrypt
Definition module_api.h:50
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
Autocrypt private Module data.
Definition module_data.h:32
sqlite3 * autocrypt_db
Autocrypt database.
Definition module_data.h:38
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_schema_update()

int mutt_autocrypt_schema_update ( void )

Update the version number of the Autocrypt database schema.

Return values
0Success
-1Error

Definition at line 111 of file schema.c.

112{
113 sqlite3_stmt *stmt = NULL;
114 int rc = -1;
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
141cleanup:
142 sqlite3_finalize(stmt);
143 return rc;
144}
#define mutt_error(...)
Definition logging2.h:94
#define _(a)
Definition message.h:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function: