Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[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 (C) 1999-2008 Novell, Inc. (www.novell.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 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
24 #error "Only <camel/camel.h> can be included directly."
25 #endif
26
27 #ifndef CAMEL_CERTDB_H
28 #define CAMEL_CERTDB_H
29
30 #include <stdio.h>
31 #include <camel/camel-memchunk.h>
32 #include <camel/camel-object.h>
33
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))
52
53 G_BEGIN_DECLS
54
55 typedef struct _CamelCertDB CamelCertDB;
56 typedef struct _CamelCertDBClass CamelCertDBClass;
57 typedef struct _CamelCertDBPrivate CamelCertDBPrivate;
58
59 typedef enum {
60         CAMEL_CERTDB_DIRTY = 1 << 0
61 } CamelCertDBFlags;
62
63 enum {
64         CAMEL_CERT_STRING_ISSUER,
65         CAMEL_CERT_STRING_SUBJECT,
66         CAMEL_CERT_STRING_HOSTNAME,
67         CAMEL_CERT_STRING_FINGERPRINT
68 };
69
70 typedef enum {
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
77 } CamelCertTrust;
78
79 typedef struct {
80         guint32 refcount;
81
82         gchar *issuer;
83         gchar *subject;
84         gchar *hostname;
85         gchar *fingerprint;
86
87         CamelCertTrust trust;
88         GByteArray *rawcert;
89 } CamelCert;
90
91 /**
92  * CamelCertDBLock:
93  *
94  * Since: 2.32
95  **/
96 typedef enum {
97         CAMEL_CERTDB_DB_LOCK,
98         CAMEL_CERTDB_IO_LOCK,
99         CAMEL_CERTDB_ALLOC_LOCK,
100         CAMEL_CERTDB_REF_LOCK
101 } CamelCertDBLock;
102
103 struct _CamelCertDB {
104         CamelObject parent;
105         CamelCertDBPrivate *priv;
106
107         gchar *filename;
108         guint32 version;
109         guint32 saved_certs;
110         CamelCertDBFlags flags;
111
112         guint32 cert_size;
113
114         CamelMemChunk *cert_chunks;
115
116         GPtrArray *certs;
117         GHashTable *cert_hash;
118 };
119
120 struct _CamelCertDBClass {
121         CamelObjectClass parent_class;
122
123         gint (*header_load) (CamelCertDB *certdb, FILE *istream);
124         gint (*header_save) (CamelCertDB *certdb, FILE *ostream);
125
126         CamelCert * (*cert_load) (CamelCertDB *certdb, FILE *istream);
127         gint (*cert_save) (CamelCertDB *certdb, CamelCert *cert, FILE *ostream);
128
129         CamelCert *  (*cert_new) (CamelCertDB *certdb);
130         void        (*cert_free) (CamelCertDB *certdb, CamelCert *cert);
131
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);
134 };
135
136 GType camel_certdb_get_type (void);
137
138 CamelCertDB *camel_certdb_new (void);
139
140 void camel_certdb_set_default (CamelCertDB *certdb);
141 CamelCertDB *camel_certdb_get_default (void);
142
143 void camel_certdb_set_filename (CamelCertDB *certdb, const gchar *filename);
144
145 gint camel_certdb_load (CamelCertDB *certdb);
146 gint camel_certdb_save (CamelCertDB *certdb);
147
148 void camel_certdb_touch (CamelCertDB *certdb);
149
150 /* The lookup key was changed from fingerprint to hostname to fix bug 606181. */
151
152 /* Get the certificate for the given hostname, if any. */
153 CamelCert *camel_certdb_get_host (CamelCertDB *certdb, const gchar *hostname, const gchar *fingerprint);
154
155 /* Store cert for cert->hostname, replacing any existing certificate for the
156  * same hostname. */
157 void camel_certdb_put (CamelCertDB *certdb, CamelCert *cert);
158
159 /* Remove any user-accepted certificate for the given hostname. */
160 void camel_certdb_remove_host (CamelCertDB *certdb, const gchar *hostname, const gchar *fingerprint);
161
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);
165
166 void camel_certdb_clear (CamelCertDB *certdb);
167
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);
170
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)
175
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)
180
181 CamelCertTrust camel_cert_get_trust (CamelCertDB *certdb, CamelCert *cert);
182 void camel_cert_set_trust (CamelCertDB *certdb, CamelCert *cert, CamelCertTrust trust);
183
184 void camel_certdb_lock   (CamelCertDB *certdb, CamelCertDBLock lock);
185 void camel_certdb_unlock (CamelCertDB *certdb, CamelCertDBLock lock);
186
187 G_END_DECLS
188
189 #endif /* CAMEL_CERTDB_H */