Add m4 macros and include m4 in the search path.
[pwmd.git] / src / cache.h
blob1d5f0e9f98f94be4c8970457a86e578c3fb4f602
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Ben Kibbey <bjk@luxsci.net>
6 This file is part of pwmd.
8 Pwmd is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 Pwmd is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef CACHE_H
22 #define CACHE_H
24 #include <pthread.h>
25 #include <gpg-error.h>
26 #include <glib.h>
27 #include <time.h>
29 struct cache_data_s {
30 gpointer pubkey; /* needed for SAVE */
31 gpointer sigkey; /* needed for SAVE */
32 gpointer doc; /* AES-128 encrypted */
33 gsize doclen;
34 guchar *crc; /* Checksum of the data file. */
37 typedef struct {
38 guchar filename[16]; /* MD5 hash. */
39 guchar grip[41]; /* key grip for this file */
40 gint timeout; /* cache_timer_thread(). */
41 gint reset; /* To reset .timeout. */
42 gboolean defer_clear; /* Another thread wants to clear the cache
43 entry for this file. Prevent resetting the
44 timer until this flag is cleared. */
45 pthread_mutex_t *mutex; /* Data file mutex. */
46 struct cache_data_s *data;
47 guint refcount;
48 } file_cache_t;
50 guchar *cache_iv;
51 guchar *cache_key;
52 gsize cache_blocksize;
53 gsize cache_keysize;
55 void cache_adjust_timeout();
56 gpg_error_t cache_set_timeout(const guchar *md5filename, gint timeout);
57 gpg_error_t cache_iscached(const gchar *filename, gboolean *defer);
58 gpg_error_t cache_clear(const guchar *md5filename);
59 gboolean cache_add_file(const guchar *md5file, const guchar *grip,
60 struct cache_data_s *, gint timeout);
61 void cache_deinit();
62 gpg_error_t cache_init();
63 guint cache_file_count();
64 struct cache_data_s *cache_get_data(const guchar *md5file);
65 gpg_error_t cache_set_data(const guchar *md5file, struct cache_data_s *,
66 const guchar *grip);
67 gpg_error_t cache_is_shadowed(const gchar *grip);
68 gpg_error_t cache_lock_mutex(gpointer ctx, const guchar *md5file,
69 glong mutex_timeout, gboolean add, gint timeout);
70 gpg_error_t cache_unlock_mutex(const guchar *md5file, gboolean remove);
71 void cache_lock();
72 void cache_unlock();
73 void free_cache_data_once(struct cache_data_s *data);
74 gpg_error_t cache_defer_clear(const guchar *md5file);
76 #endif