Version 3.0.12.
[pwmd.git] / src / cache.h
blob9fb37749ad829b49c028fa9d43287ac8ae6e3785
1 /*
2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
3 Ben Kibbey <bjk@luxsci.net>
5 This file is part of pwmd.
7 Pwmd is free software: you can redistribute it and/or modify
8 it under the terms of the GNU 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 Pwmd 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 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef CACHE_H
21 #define CACHE_H
23 #include <pthread.h>
24 #include <gpg-error.h>
25 #include <time.h>
27 struct cache_data_s
29 void *pubkey; /* needed for SAVE */
30 void *sigkey; /* needed for SAVE */
31 void *doc; /* AES-128 encrypted */
32 size_t doclen;
33 void *key; /* When use_agent == 0, hashed. */
34 size_t keylen;
35 unsigned char *crc; /* Checksum of the data file. */
38 typedef struct
40 unsigned char filename[16]; /* MD5 hash. */
41 unsigned char grip[41]; /* key grip for this file */
42 int timeout; /* cache_timer_thread(). */
43 int reset; /* To reset .timeout. */
44 int defer_clear; /* Another thread wants to clear the cache
45 entry for this file. Prevent resetting the
46 timer until this flag is cleared. */
47 pthread_mutex_t *mutex; /* Data file mutex. */
48 struct cache_data_s *data;
49 unsigned refcount;
50 } file_cache_t;
52 unsigned char *cache_iv;
53 unsigned char *cache_key;
54 size_t cache_blocksize;
55 size_t cache_keysize;
57 void cache_adjust_timeout ();
58 gpg_error_t cache_set_timeout (const unsigned char *md5filename, int timeout);
59 gpg_error_t cache_iscached (const char *filename, int *defer);
60 gpg_error_t cache_clear (const unsigned char *md5filename);
61 gpg_error_t cache_add_file (const unsigned char *md5file,
62 const unsigned char *grip, struct cache_data_s *,
63 int timeout);
64 void cache_deinit (int atfork);
65 gpg_error_t cache_init ();
66 void cache_mutex_init ();
67 unsigned cache_file_count ();
68 struct cache_data_s *cache_get_data (const unsigned char *md5file);
69 struct cache_data_s *cache_get_data_filename (const char *file);
70 gpg_error_t cache_set_data (const unsigned char *md5file,
71 struct cache_data_s *, const unsigned char *grip);
72 gpg_error_t cache_is_shadowed (const char *grip);
73 gpg_error_t cache_lock_mutex (void *ctx, const unsigned char *md5file,
74 long mutex_timeout, int add, int timeout);
75 gpg_error_t cache_unlock_mutex (const unsigned char *md5file, int remove);
76 void cache_lock ();
77 void cache_unlock ();
78 void free_cache_data_once (struct cache_data_s *data);
79 gpg_error_t cache_defer_clear (const unsigned char *md5file);
81 #endif