LIST: Fix memory leaks.
[pwmd.git] / src / cache.h
blob98c07d69300fb9ce53d6d0f465189dd4ba6d0964
1 /*
2 Copyright (C) 2006-2021 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 as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 Pwmd is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef CACHE_H
20 #define CACHE_H
22 #include <pthread.h>
23 #include <gpg-error.h>
24 #include <time.h>
25 #include <libxml/tree.h>
27 #include "crypto.h"
29 struct cache_data_s
31 char **pubkey; /* keyid's */
32 char *sigkey; /* signing keyid */
33 void *doc; /* AES-128 encrypted */
34 xmlDocPtr plaintext;
35 unsigned refcount; /* for .plaintext */
36 size_t size;
37 unsigned char *crc; /* Checksum of the data file. */
38 char *filename;
41 #define CACHE_FLAG_LOCKED 0x0001
43 typedef struct
45 char **grip; /* Public keygrips. */
46 char *siggrip; /* Signing keygrip. */
47 char *filename; /* Associated filename. */
48 long timeout; /* cache_timer_thread(). */
49 long reset; /* To reset .timeout. */
50 int defer_clear; /* Another thread wants to clear the cache
51 entry for this file. Prevent resetting the
52 timer until this flag is cleared. */
53 pthread_mutex_t *mutex; /* Data file mutex. */
54 struct cache_data_s *data;
55 unsigned refcount;
56 unsigned flags;
57 } file_cache_t;
59 gpg_error_t cache_kill_scd ();
60 void cache_adjust_timeout ();
61 gpg_error_t cache_set_timeout (const char *, long timeout);
62 gpg_error_t cache_iscached (const char *, int *defer, int agent, int sign);
63 gpg_error_t cache_clear (struct client_s *, const char *, int agent, int force);
64 gpg_error_t cache_add_file (const char *, struct cache_data_s *, long timeout);
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_release_mutex ();
78 void cache_free_data_once (struct cache_data_s *data);
79 gpg_error_t cache_defer_clear (const char *);
80 gpg_error_t cache_encrypt (struct crypto_s *);
81 gpg_error_t cache_decrypt (struct crypto_s *);
82 gpg_error_t cache_clear_agent_keys (const char *, int decrypt, int sign);
83 gpg_error_t cache_agent_command (const char *);
84 gpg_error_t cache_plaintext_get (const char *filename, xmlDocPtr *plain);
85 gpg_error_t cache_plaintext_release (xmlDocPtr *);
86 gpg_error_t cache_plaintext_set (const char *filename, xmlDocPtr doc,
87 int modified);
89 #endif