Fix potential memory leak.
[pwmd.git] / src / cache.h
blob739ac428d43a22bba76027410cfa8ebefb07bddf
1 /*
2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
3 2016, 2017
4 Ben Kibbey <bjk@luxsci.net>
6 This file is part of pwmd.
8 Pwmd is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 Pwmd is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef CACHE_H
22 #define CACHE_H
24 #include <pthread.h>
25 #include <gpg-error.h>
26 #include <time.h>
27 #include <libxml/tree.h>
29 #include "crypto.h"
31 struct cache_data_s
33 char **pubkey; /* keyid's */
34 char *sigkey; /* signing keyid */
35 void *doc; /* AES-128 encrypted */
36 xmlDocPtr plaintext;
37 unsigned refcount; /* for .plaintext */
38 size_t size;
39 unsigned char *crc; /* Checksum of the data file. */
40 char *filename;
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 } 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 void cache_deinit ();
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 char *, int *defer);
69 gpg_error_t cache_set_data (const char *, struct cache_data_s *);
70 gpg_error_t cache_lock_mutex (void *ctx, const char *, long mutex_timeout,
71 int add, long timeout);
72 gpg_error_t cache_unlock_mutex (const char *, int remove);
73 void cache_lock ();
74 void cache_unlock ();
75 void cache_release_mutex ();
76 void cache_free_data_once (struct cache_data_s *data);
77 gpg_error_t cache_defer_clear (const char *);
78 gpg_error_t cache_encrypt (struct crypto_s *);
79 gpg_error_t cache_decrypt (struct crypto_s *);
80 gpg_error_t cache_clear_agent_keys (const char *, int decrypt, int sign);
81 gpg_error_t cache_agent_command (const char *);
82 gpg_error_t cache_plaintext_get (const char *filename, xmlDocPtr *plain);
83 gpg_error_t cache_plaintext_release (xmlDocPtr *);
84 gpg_error_t cache_plaintext_set (const char *filename, xmlDocPtr doc,
85 int modified);
87 #endif