Fix a few 'gcc -fanalyzer' warnings.
[pwmd.git] / src / cache.h
blob715e594ef9aa496c002a6a8c7ec5c7d058d79a0e
1 /*
2 Copyright (C) 2006-2023 Ben Kibbey <bjk@luxsci.net>
4 This file is part of pwmd.
6 Pwmd is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 Pwmd 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 Pwmd. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef CACHE_H
19 #define CACHE_H
21 #include <pthread.h>
22 #include <gpg-error.h>
23 #include <libxml/tree.h>
24 #include <time.h>
26 #include "crypto.h"
28 struct cache_data_s
30 char **pubkey; /* keyid's */
31 char *sigkey; /* signing keyid */
32 void *doc; /* AES-128 encrypted */
33 xmlDocPtr plaintext;
34 unsigned refcount; /* for .plaintext */
35 size_t size;
36 unsigned char *crc; /* Checksum of the data file. */
37 char *filename;
40 #define CACHE_FLAG_LOCKED 0x0001
42 typedef struct
44 char **grip; /* Public keygrips. */
45 char *siggrip; /* Signing keygrip. */
46 char *filename; /* Associated filename. */
47 long timeout; /* cache_timer_thread(). */
48 long reset; /* To reset .timeout. */
49 int defer_clear; /* Another thread wants to clear the cache
50 entry for this file. Prevent resetting the
51 timer until this flag is cleared. */
52 pthread_mutex_t *mutex; /* Data file mutex. */
53 struct cache_data_s *data;
54 unsigned refcount;
55 unsigned flags;
56 } file_cache_t;
58 gpg_error_t cache_kill_scd ();
59 void cache_adjust_timeout ();
60 gpg_error_t cache_set_timeout (const char *, long timeout);
61 gpg_error_t cache_iscached (const char *, int *defer, int agent, int sign);
62 gpg_error_t cache_clear (struct client_s *, const char *, int agent, int force);
63 gpg_error_t cache_add_file (const char *, struct cache_data_s *, long timeout,
64 int same_file);
65 void cache_deinit ();
66 gpg_error_t cache_init ();
67 void cache_mutex_init ();
68 unsigned cache_file_count ();
69 gpg_error_t cache_is_shadowed (const char *filename);
70 struct cache_data_s *cache_get_data (const char *, int *defer);
71 gpg_error_t cache_set_data (const char *, struct cache_data_s *);
72 gpg_error_t cache_lock_mutex (void *ctx, const char *, long mutex_timeout,
73 int add, long timeout);
74 gpg_error_t cache_unlock_mutex (const char *, int remove);
75 void cache_lock ();
76 void cache_unlock ();
77 void cache_free_data_once (struct cache_data_s *data);
78 gpg_error_t cache_defer_clear (const char *);
79 gpg_error_t cache_encrypt (struct crypto_s *);
80 gpg_error_t cache_decrypt (struct crypto_s *);
81 gpg_error_t cache_clear_agent_keys (const char *, int decrypt, int sign);
82 gpg_error_t cache_agent_command (const char *);
83 gpg_error_t cache_plaintext_get (const char *filename, xmlDocPtr *plain);
84 gpg_error_t cache_plaintext_release (xmlDocPtr *);
85 gpg_error_t cache_plaintext_set (const char *filename, xmlDocPtr doc,
86 int modified);
88 #endif