Fix a few 'gcc -fanalyzer' warnings.
[pwmd.git] / src / common.h
blob7e1bf3ceee78ed29de9008bb41dd7dc3691bfa53
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 COMMON_H
19 #define COMMON_H
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <pthread.h>
28 #include "pwmd-error.h"
29 #include <assuan.h>
30 #include <libxml/xmlerror.h>
31 #ifdef HAVE_STDINT_H
32 #include <stdint.h>
33 #endif
34 #include <pwd.h>
35 #include <time.h>
37 #ifdef ENABLE_NLS
38 #ifdef HAVE_LOCALE_H
39 #include <locale.h>
40 #endif
41 #endif
43 #ifdef HAVE_LIMITS_H
44 #include <limits.h>
45 #ifndef LINE_MAX
46 #ifdef _POSIX2_LINE_MAX
47 #define LINE_MAX _POSIX2_LINE_MAX
48 #else
49 #define LINE_MAX 2048
50 #endif
51 #endif
52 #endif
54 #ifndef _
55 #include "gettext.h"
56 #define _(msgid) gettext(msgid)
57 #endif
59 #ifdef WITH_GNUTLS
60 #include "tls.h"
61 #endif
62 #include "status.h"
63 #include "bulk.h"
65 #define CLIENT_STATE_UNKNOWN 0
66 #define CLIENT_STATE_INIT 1
67 #define CLIENT_STATE_IDLE 2
68 #define CLIENT_STATE_COMMAND 3
69 #define CLIENT_STATE_DISCON 4
71 struct client_thread_s
73 pthread_t tid;
74 int fd;
75 char *cmdname;
76 pthread_mutex_t status_mutex;
77 struct status_msg_s *msg_queue;
78 int status_msg_pipe[2];
79 int wrote_status;
80 struct client_s *cl;
81 assuan_peercred_t peer;
82 unsigned state;
83 int eof;
84 time_t conntime;
85 char *name;
86 int send_state; /* OPTION to receive client state msgs. */
87 #ifdef WITH_GNUTLS
88 int timeout;
89 int buffer_timeout;
90 int last_buffer_size;
91 int remote;
92 struct tls_s *tls;
93 char *peeraddr;
94 #endif
97 struct client_s
99 assuan_context_t ctx;
100 int flock_fd;
101 xmlDocPtr doc;
102 xmlErrorPtr xml_error;
103 char *filename;
104 struct client_thread_s *thd;
105 struct crypto_s *crypto;
106 unsigned opts;
107 unsigned flags;
108 char *import_root;
109 long lock_timeout; /* In tenths of a second. */
110 gpg_error_t last_rc;
111 char *last_error; /* ELOOP element path. */
112 unsigned char *crc; /* Of the data file. */
113 int did_cow; /* Have already done a CoW operation. */
114 struct bulk_cmd_s *bulk_p; /* For the command result set in xfer_data(). */
115 #ifdef WITH_GNUTLS
116 int disco; /* Rather than thread->state to avoid lock. */
117 #endif
120 extern pthread_key_t thread_name_key;
121 extern pthread_mutex_t cn_mutex;
122 extern struct slist_s *cn_thread_list;
124 void log_write (const char *fmt, ...);
125 int assuan_log_cb (assuan_context_t ctx, void *data, unsigned cat,
126 const char *msg);
127 gpg_error_t send_error (assuan_context_t ctx, gpg_error_t e);
128 void update_client_state (struct client_s *client, unsigned s);
129 gpg_error_t lock_flock (assuan_context_t ctx, const char *filename, int type,
130 int *fd);
131 void unlock_flock (int *fd);
133 #endif