Assuan now returns an error code from the inquire callback so this
[pwmd.git] / src / cache.h
blobf8e206ddb52dff19c3f5ddc2b7d02a16a7e5d40d
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2006-2007 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef CACHE_H
20 #define CACHE_H
22 #include <pth.h>
24 #ifdef DEBUG
25 #define CACHE_LOCK_DEBUG log_write(N_("LOCK %s tid=%p"), __FUNCTION__, pth_self());
26 #define CACHE_UNLOCK_DEBUG log_write(N_("UNLOCK %s tid=%p"), __FUNCTION__, pth_self());
27 #else
28 #define CACHE_LOCK_DEBUG
29 #define CACHE_UNLOCK_DEBUG
30 #endif
32 #define CACHE_TRYLOCK(ctx, ev) if (pth_mutex_acquire(&cache_mutex, TRUE, ev) == FALSE) {\
33 if (errno == EBUSY) { \
34 log_write(N_("%s(): cache mutex LOCKED"), __FUNCTION__); \
35 if (ctx) \
36 assuan_write_status(ctx, "LOCKED", N_("Waiting for lock")); \
37 pth_mutex_acquire(&cache_mutex, FALSE, ev); \
38 } \
39 else \
40 log_write("%s(%i): %s", __FUNCTION__, __LINE__, strerror(errno)); \
43 #define CACHE_LOCK(ctx, ev) CACHE_LOCK_DEBUG CACHE_TRYLOCK(ctx, ev)
44 #define CACHE_UNLOCK CACHE_UNLOCK_DEBUG pth_mutex_release(&cache_mutex)
46 typedef struct {
47 guchar filename[16]; // MD5
48 guchar key[32]; // SHA256/AES256/gcrykeysize
49 gboolean used;
50 glong timeout;
51 glong reset;
52 } file_cache_t;
54 void *key_cache;
55 glong cache_size;
56 pth_mutex_t cache_mutex;
58 void cache_adjust_timer(void);
59 gboolean cache_set_timeout(const guchar *md5filename, glong timeout);
60 gboolean cache_reset_timeout(const guchar *md5filename, glong timeout);
61 gboolean cache_iscached(const guchar *md5filename);
62 gboolean cache_clear(const guchar *md5filename, gint which);
63 gboolean cache_add_file(const guchar *md5file, const guchar *shakey);
64 gboolean cache_get_key(const guchar *md5file, guchar *shakey);
65 gboolean cache_update_key(const guchar *md5filename, const guchar *shakey);
66 gint cache_file_count(void);
67 gboolean cache_has_file(const guchar *md5file);
68 void send_cache_status_all(void);
70 #endif