2006-09-06 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / g10 / tdbio.h
blob80a70d9f47b6236cdaa4a7ddd542a48fd82f99a0
1 /* tdbio.h - Trust database I/O functions
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 * USA.
22 #ifndef G10_TDBIO_H
23 #define G10_TDBIO_H
25 #include "host2net.h"
27 #define TRUST_RECORD_LEN 40
28 #define SIGS_PER_RECORD ((TRUST_RECORD_LEN-10)/5)
29 #define ITEMS_PER_HTBL_RECORD ((TRUST_RECORD_LEN-2)/4)
30 #define ITEMS_PER_HLST_RECORD ((TRUST_RECORD_LEN-6)/5)
31 #define ITEMS_PER_PREF_RECORD (TRUST_RECORD_LEN-10)
32 #if ITEMS_PER_PREF_RECORD % 2
33 #error ITEMS_PER_PREF_RECORD must be even
34 #endif
35 #define MAX_LIST_SIGS_DEPTH 20
38 #define RECTYPE_VER 1
39 #define RECTYPE_HTBL 10
40 #define RECTYPE_HLST 11
41 #define RECTYPE_TRUST 12
42 #define RECTYPE_VALID 13
43 #define RECTYPE_FREE 254
46 struct trust_record {
47 int rectype;
48 int mark;
49 int dirty; /* for now only used internal by functions */
50 struct trust_record *next; /* help pointer to build lists in memory */
51 ulong recnum;
52 union {
53 struct { /* version record: */
54 byte version; /* should be 3 */
55 byte marginals;
56 byte completes;
57 byte cert_depth;
58 byte trust_model;
59 ulong created; /* timestamp of trustdb creation */
60 ulong nextcheck; /* timestamp of next scheduled check */
61 ulong reserved;
62 ulong reserved2;
63 ulong firstfree;
64 ulong reserved3;
65 ulong trusthashtbl;
66 } ver;
67 struct { /* free record */
68 ulong next;
69 } free;
70 struct {
71 ulong item[ITEMS_PER_HTBL_RECORD];
72 } htbl;
73 struct {
74 ulong next;
75 ulong rnum[ITEMS_PER_HLST_RECORD]; /* of another record */
76 } hlst;
77 struct {
78 byte fingerprint[20];
79 byte ownertrust;
80 byte depth;
81 ulong validlist;
82 byte min_ownertrust;
83 } trust;
84 struct {
85 byte namehash[20];
86 ulong next;
87 byte validity;
88 byte full_count;
89 byte marginal_count;
90 } valid;
91 } r;
93 typedef struct trust_record TRUSTREC;
95 /*-- tdbio.c --*/
96 int tdbio_update_version_record(void);
97 int tdbio_set_dbname( const char *new_dbname, int create );
98 const char *tdbio_get_dbname(void);
99 void tdbio_dump_record( TRUSTREC *rec, FILE *fp );
100 int tdbio_read_record( ulong recnum, TRUSTREC *rec, int expected );
101 int tdbio_write_record( TRUSTREC *rec );
102 int tdbio_db_matches_options(void);
103 byte tdbio_read_model(void);
104 ulong tdbio_read_nextcheck (void);
105 int tdbio_write_nextcheck (ulong stamp);
106 int tdbio_is_dirty(void);
107 int tdbio_sync(void);
108 int tdbio_begin_transaction(void);
109 int tdbio_end_transaction(void);
110 int tdbio_cancel_transaction(void);
111 int tdbio_delete_record( ulong recnum );
112 ulong tdbio_new_recnum(void);
113 int tdbio_search_trust_byfpr(const byte *fingerprint, TRUSTREC *rec );
114 int tdbio_search_trust_bypk(PKT_public_key *pk, TRUSTREC *rec );
116 void tdbio_invalid(void);
118 #endif /*G10_TDBIO_H*/