Let the CLEARCACHE and CACHETIMEOUT commands work with remote connections.
[pwmd.git] / src / util-misc.h
blob0ec82a1350238c02ee0c55ce8a9e66d781a69ff0
1 /*
2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
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 MISC_H
21 #define MISC_H
23 #include <pthread.h>
24 #include "rcfile.h"
26 #ifdef HAVE_BACKTRACE
27 #include <execinfo.h>
28 #include <syslog.h>
29 #define BACKTRACE_COUNT 20
30 #define BACKTRACE(fn) do { \
31 int n, nptrs; \
32 char **strings; \
33 void *buffer[BACKTRACE_COUNT]; \
34 nptrs = backtrace(buffer, BACKTRACE_COUNT); \
35 strings = backtrace_symbols(buffer, nptrs); \
36 for (n = 0; n < nptrs; n++) \
37 log_write("BACKTRACE: (%s) %i: %s", fn, n, strings[n]); \
38 } while (0)
39 #endif
41 #define log_write0 log_write
43 #define log_write1(...) do { \
44 if (config_get_integer("global", "log_level") >= 1) \
45 log_write(__VA_ARGS__); \
46 } while (0)
48 #define log_write2(...) do { \
49 if (config_get_integer("global", "log_level") >= 2) \
50 log_write(__VA_ARGS__); \
51 } while (0)
53 typedef enum
55 OPTION_TYPE_NOARG,
56 OPTION_TYPE_ARG,
57 OPTION_TYPE_OPTARG,
58 } option_type_t;
60 struct argv_s
62 const char *opt;
63 option_type_t type;
64 gpg_error_t (*func) (void *data, void *value);
67 typedef struct
69 size_t len;
70 void *buf;
71 } membuf_t;
73 char *home_directory;
75 gpg_error_t parse_options (char **line, struct argv_s *args[], void *data);
76 int valid_filename (const char *filename);
77 char *expand_homedir (char *str);
78 char *bin2hex (const unsigned char *data, size_t len);
79 char *plus_escape (const char *fmt, ...);
80 char *strip_texi_and_wrap (const char *str);
81 void free_key (void *data);
82 gpg_error_t create_thread (void *(*cb) (void *), void *data,
83 pthread_t * tid, int detached);
84 void cleanup_mutex_cb (void *arg);
85 void cleanup_fd_cb (void *arg);
86 void cleanup_unlink_cb (void *arg);
87 void cleanup_cancel_cb (void *arg);
88 void cleanup_cache_mutex (void *arg);
89 int valid_keygrip (const unsigned char *data, size_t len);
90 gpg_error_t get_checksum (const char *filename, unsigned char **r_crc,
91 size_t * r_crclen);
92 char *get_username ();
93 char *get_home_dir ();
95 #endif