NeoMutt  2024-11-14-34-g5aaf0d
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 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 41 of file schema.c.

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}
sqlite3 * AutocryptDB
Handle to the open Autocrypt database.
Definition: db.c:56
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
+ 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 107 of file schema.c.

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}
#define mutt_error(...)
Definition: logging2.h:92
#define _(a)
Definition: message.h:28
+ Here is the caller graph for this function: