1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
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
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());
28 #define CACHE_LOCK_DEBUG
29 #define CACHE_UNLOCK_DEBUG
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__); \
36 assuan_write_status(ctx, "LOCKED", N_("Waiting for lock")); \
37 pth_mutex_acquire(&cache_mutex, FALSE, ev); \
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)
47 guchar filename
[16]; // MD5
48 guchar key
[32]; // SHA256/AES256/gcrykeysize
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);