Fix FSF address (Tobias Mueller, #470445)
[platform/upstream/evolution-data-server.git] / camel / camel-certdb.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  *  Authors: Jeffrey Stedfast <fejj@ximian.com>
4  *
5  *  Copyright 2002 Ximian, Inc. (www.ximian.com)
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU Lesser General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22
23
24 #ifndef __CAMEL_CERTDB_H__
25 #define __CAMEL_CERTDB_H__
26
27 #include <stdio.h>
28 #include <camel/camel-object.h>
29
30 #define CAMEL_CERTDB_TYPE         (camel_certdb_get_type ())
31 #define CAMEL_CERTDB(obj)         (CAMEL_CHECK_CAST (obj, camel_certdb_get_type (), CamelCertDB))
32 #define CAMEL_CERTDB_CLASS(klass) (CAMEL_CHECK_CLASS_CAST (klass, camel_certdb_get_type (), CamelCertDBClass))
33 #define CAMEL_IS_CERTDB(obj)      (CAMEL_CHECK_TYPE (obj, camel_certdb_get_type ()))
34
35 G_BEGIN_DECLS
36
37 typedef struct _CamelCertDB CamelCertDB;
38 typedef struct _CamelCertDBClass CamelCertDBClass;
39
40 enum {
41         CAMEL_CERTDB_DIRTY  = (1 << 0),
42 };
43
44 enum {
45         CAMEL_CERT_STRING_ISSUER,
46         CAMEL_CERT_STRING_SUBJECT,
47         CAMEL_CERT_STRING_HOSTNAME,
48         CAMEL_CERT_STRING_FINGERPRINT,
49 };
50
51 typedef enum {
52         CAMEL_CERT_TRUST_UNKNOWN,
53         CAMEL_CERT_TRUST_NEVER,
54         CAMEL_CERT_TRUST_MARGINAL,
55         CAMEL_CERT_TRUST_FULLY,
56         CAMEL_CERT_TRUST_ULTIMATE,
57 } CamelCertTrust;
58
59 typedef struct {
60         guint32 refcount;
61         
62         char *issuer;
63         char *subject;
64         char *hostname;
65         char *fingerprint;
66         
67         CamelCertTrust trust;
68         GByteArray *rawcert;
69 } CamelCert;
70
71 struct _CamelCertDB {
72         CamelObject parent_object;
73         struct _CamelCertDBPrivate *priv;
74         
75         char *filename;
76         guint32 version;
77         guint32 saved_certs;
78         guint32 flags;
79         
80         guint32 cert_size;
81         
82         struct _EMemChunk *cert_chunks;
83         
84         GPtrArray *certs;
85         GHashTable *cert_hash;
86 };
87
88 struct _CamelCertDBClass {
89         CamelObjectClass parent_class;
90         
91         int (*header_load) (CamelCertDB *certdb, FILE *istream);
92         int (*header_save) (CamelCertDB *certdb, FILE *ostream);
93         
94         CamelCert * (*cert_load) (CamelCertDB *certdb, FILE *istream);
95         int (*cert_save) (CamelCertDB *certdb, CamelCert *cert, FILE *ostream);
96         
97         CamelCert *  (*cert_new) (CamelCertDB *certdb);
98         void        (*cert_free) (CamelCertDB *certdb, CamelCert *cert);
99         
100         const char * (*cert_get_string) (CamelCertDB *certdb, CamelCert *cert, int string);
101         void (*cert_set_string) (CamelCertDB *certdb, CamelCert *cert, int string, const char *value);
102 };
103
104
105 CamelType camel_certdb_get_type (void);
106
107 CamelCertDB *camel_certdb_new (void);
108
109 void camel_certdb_set_default (CamelCertDB *certdb);
110 CamelCertDB *camel_certdb_get_default (void);
111
112 void camel_certdb_set_filename (CamelCertDB *certdb, const char *filename);
113
114 int camel_certdb_load (CamelCertDB *certdb);
115 int camel_certdb_save (CamelCertDB *certdb);
116
117 void camel_certdb_touch (CamelCertDB *certdb);
118
119 CamelCert *camel_certdb_get_cert (CamelCertDB *certdb, const char *fingerprint);
120
121 void camel_certdb_add (CamelCertDB *certdb, CamelCert *cert);
122 void camel_certdb_remove (CamelCertDB *certdb, CamelCert *cert);
123
124 CamelCert *camel_certdb_cert_new (CamelCertDB *certdb);
125 void camel_certdb_cert_ref (CamelCertDB *certdb, CamelCert *cert);
126 void camel_certdb_cert_unref (CamelCertDB *certdb, CamelCert *cert);
127
128 void camel_certdb_clear (CamelCertDB *certdb);
129
130
131 const char *camel_cert_get_string (CamelCertDB *certdb, CamelCert *cert, int string);
132 void camel_cert_set_string (CamelCertDB *certdb, CamelCert *cert, int string, const char *value);
133
134 #define camel_cert_get_issuer(certdb,cert) camel_cert_get_string (certdb, cert, CAMEL_CERT_STRING_ISSUER)
135 #define camel_cert_get_subject(certdb,cert) camel_cert_get_string (certdb, cert, CAMEL_CERT_STRING_SUBJECT)
136 #define camel_cert_get_hostname(certdb,cert) camel_cert_get_string (certdb, cert, CAMEL_CERT_STRING_HOSTNAME)
137 #define camel_cert_get_fingerprint(certdb,cert) camel_cert_get_string (certdb, cert, CAMEL_CERT_STRING_FINGERPRINT)
138
139 #define camel_cert_set_issuer(certdb,cert,issuer) camel_cert_set_string (certdb, cert, CAMEL_CERT_STRING_ISSUER, issuer)
140 #define camel_cert_set_subject(certdb,cert,subject) camel_cert_set_string (certdb, cert, CAMEL_CERT_STRING_SUBJECT, subject)
141 #define camel_cert_set_hostname(certdb,cert,hostname) camel_cert_set_string (certdb, cert, CAMEL_CERT_STRING_HOSTNAME, hostname)
142 #define camel_cert_set_fingerprint(certdb,cert,fingerprint) camel_cert_set_string (certdb, cert, CAMEL_CERT_STRING_FINGERPRINT, fingerprint)
143
144 CamelCertTrust camel_cert_get_trust (CamelCertDB *certdb, CamelCert *cert);
145 void camel_cert_set_trust (CamelCertDB *certdb, CamelCert *cert, CamelCertTrust trust);
146
147 G_END_DECLS
148
149 #endif /* __CAMEL_CERTDB_H__ */