1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
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.
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.
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.
23 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
24 #error "Only <camel/camel.h> can be included directly."
27 #ifndef CAMEL_CERTDB_H
28 #define CAMEL_CERTDB_H
31 #include <camel/camel-memchunk.h>
32 #include <camel/camel-object.h>
34 /* Standard GObject macros */
35 #define CAMEL_TYPE_CERTDB \
36 (camel_certdb_get_type ())
37 #define CAMEL_CERTDB(obj) \
38 (G_TYPE_CHECK_INSTANCE_CAST \
39 ((obj), CAMEL_TYPE_CERTDB, CamelCertDB))
40 #define CAMEL_CERTDB_CLASS(cls) \
41 (G_TYPE_CHECK_CLASS_CAST \
42 ((cls), CAMEL_TYPE_CERTDB, CamelCertDBClass))
43 #define CAMEL_IS_CERTDB(obj) \
44 (G_TYPE_CHECK_INSTANCE_TYPE \
45 ((obj), CAMEL_TYPE_CERTDB))
46 #define CAMEL_IS_CERTDB_CLASS(cls) \
47 (G_TYPE_CHECK_CLASS_TYPE \
48 ((cls), CAMEL_TYPE_CERTDB))
49 #define CAMEL_CERTDB_GET_CLASS(obj) \
50 (G_TYPE_INSTANCE_GET_CLASS \
51 ((obj), CAMEL_TYPE_CERTDB, CamelCertDBClass))
55 typedef struct _CamelCertDB CamelCertDB;
56 typedef struct _CamelCertDBClass CamelCertDBClass;
57 typedef struct _CamelCertDBPrivate CamelCertDBPrivate;
60 CAMEL_CERTDB_DIRTY = 1 << 0
64 CAMEL_CERT_STRING_ISSUER,
65 CAMEL_CERT_STRING_SUBJECT,
66 CAMEL_CERT_STRING_HOSTNAME,
67 CAMEL_CERT_STRING_FINGERPRINT
71 CAMEL_CERT_TRUST_UNKNOWN,
72 CAMEL_CERT_TRUST_NEVER,
73 CAMEL_CERT_TRUST_MARGINAL,
74 CAMEL_CERT_TRUST_FULLY,
75 CAMEL_CERT_TRUST_ULTIMATE,
76 CAMEL_CERT_TRUST_TEMPORARY
99 CAMEL_CERTDB_ALLOC_LOCK,
100 CAMEL_CERTDB_REF_LOCK
103 struct _CamelCertDB {
105 CamelCertDBPrivate *priv;
110 CamelCertDBFlags flags;
114 CamelMemChunk *cert_chunks;
117 GHashTable *cert_hash;
120 struct _CamelCertDBClass {
121 CamelObjectClass parent_class;
123 gint (*header_load) (CamelCertDB *certdb, FILE *istream);
124 gint (*header_save) (CamelCertDB *certdb, FILE *ostream);
126 CamelCert * (*cert_load) (CamelCertDB *certdb, FILE *istream);
127 gint (*cert_save) (CamelCertDB *certdb, CamelCert *cert, FILE *ostream);
129 CamelCert * (*cert_new) (CamelCertDB *certdb);
130 void (*cert_free) (CamelCertDB *certdb, CamelCert *cert);
132 const gchar * (*cert_get_string) (CamelCertDB *certdb, CamelCert *cert, gint string);
133 void (*cert_set_string) (CamelCertDB *certdb, CamelCert *cert, gint string, const gchar *value);
136 GType camel_certdb_get_type (void);
138 CamelCertDB *camel_certdb_new (void);
140 void camel_certdb_set_default (CamelCertDB *certdb);
141 CamelCertDB *camel_certdb_get_default (void);
143 void camel_certdb_set_filename (CamelCertDB *certdb, const gchar *filename);
145 gint camel_certdb_load (CamelCertDB *certdb);
146 gint camel_certdb_save (CamelCertDB *certdb);
148 void camel_certdb_touch (CamelCertDB *certdb);
150 /* The lookup key was changed from fingerprint to hostname to fix bug 606181. */
152 /* Get the certificate for the given hostname, if any. */
153 CamelCert *camel_certdb_get_host (CamelCertDB *certdb, const gchar *hostname, const gchar *fingerprint);
155 /* Store cert for cert->hostname, replacing any existing certificate for the
157 void camel_certdb_put (CamelCertDB *certdb, CamelCert *cert);
159 /* Remove any user-accepted certificate for the given hostname. */
160 void camel_certdb_remove_host (CamelCertDB *certdb, const gchar *hostname, const gchar *fingerprint);
162 CamelCert *camel_certdb_cert_new (CamelCertDB *certdb);
163 void camel_certdb_cert_ref (CamelCertDB *certdb, CamelCert *cert);
164 void camel_certdb_cert_unref (CamelCertDB *certdb, CamelCert *cert);
166 void camel_certdb_clear (CamelCertDB *certdb);
168 const gchar *camel_cert_get_string (CamelCertDB *certdb, CamelCert *cert, gint string);
169 void camel_cert_set_string (CamelCertDB *certdb, CamelCert *cert, gint string, const gchar *value);
171 #define camel_cert_get_issuer(certdb,cert) camel_cert_get_string (certdb, cert, CAMEL_CERT_STRING_ISSUER)
172 #define camel_cert_get_subject(certdb,cert) camel_cert_get_string (certdb, cert, CAMEL_CERT_STRING_SUBJECT)
173 #define camel_cert_get_hostname(certdb,cert) camel_cert_get_string (certdb, cert, CAMEL_CERT_STRING_HOSTNAME)
174 #define camel_cert_get_fingerprint(certdb,cert) camel_cert_get_string (certdb, cert, CAMEL_CERT_STRING_FINGERPRINT)
176 #define camel_cert_set_issuer(certdb,cert,issuer) camel_cert_set_string (certdb, cert, CAMEL_CERT_STRING_ISSUER, issuer)
177 #define camel_cert_set_subject(certdb,cert,subject) camel_cert_set_string (certdb, cert, CAMEL_CERT_STRING_SUBJECT, subject)
178 #define camel_cert_set_hostname(certdb,cert,hostname) camel_cert_set_string (certdb, cert, CAMEL_CERT_STRING_HOSTNAME, hostname)
179 #define camel_cert_set_fingerprint(certdb,cert,fingerprint) camel_cert_set_string (certdb, cert, CAMEL_CERT_STRING_FINGERPRINT, fingerprint)
181 CamelCertTrust camel_cert_get_trust (CamelCertDB *certdb, CamelCert *cert);
182 void camel_cert_set_trust (CamelCertDB *certdb, CamelCert *cert, CamelCertTrust trust);
184 void camel_certdb_lock (CamelCertDB *certdb, CamelCertDBLock lock);
185 void camel_certdb_unlock (CamelCertDB *certdb, CamelCertDBLock lock);
189 #endif /* CAMEL_CERTDB_H */