Add STATUS_MODIFIED.
[pwmd.git] / src / common.h
blob428548d0635cceab370423bfd9bbba0ddfa2712d
1 /*
2 Copyright (C) 2006-2022 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 pthread_mutex_t status_mutex;
76 struct status_msg_s *msg_queue;
77 int status_msg_pipe[2];
78 int wrote_status;
79 struct client_s *cl;
80 assuan_peercred_t peer;
81 unsigned state;
82 int eof;
83 time_t conntime;
84 char *name;
85 int send_state; /* OPTION to receive client state msgs. */
86 #ifdef WITH_GNUTLS
87 int timeout;
88 int buffer_timeout;
89 int last_buffer_size;
90 int remote;
91 struct tls_s *tls;
92 char *peeraddr;
93 #endif
96 struct client_s
98 assuan_context_t ctx;
99 int flock_fd;
100 xmlDocPtr doc;
101 xmlErrorPtr xml_error;
102 char *filename;
103 struct client_thread_s *thd;
104 struct crypto_s *crypto;
105 unsigned opts;
106 unsigned flags;
107 char *import_root;
108 long lock_timeout; /* In tenths of a second. */
109 gpg_error_t last_rc;
110 char *last_error; /* ELOOP element path. */
111 unsigned char *crc; /* Of the data file. */
112 int did_cow; /* Have already done a CoW operation. */
113 struct bulk_cmd_s *bulk_p; /* For the command result set in xfer_data(). */
114 #ifdef WITH_GNUTLS
115 int disco; /* Rather than thread->state to avoid lock. */
116 #endif
119 extern pthread_key_t thread_name_key;
120 extern pthread_mutex_t cn_mutex;
121 extern struct slist_s *cn_thread_list;
123 void log_write (const char *fmt, ...);
124 int assuan_log_cb (assuan_context_t ctx, void *data, unsigned cat,
125 const char *msg);
126 gpg_error_t send_error (assuan_context_t ctx, gpg_error_t e);
127 void update_client_state (struct client_s *client, unsigned s);
128 gpg_error_t lock_flock (assuan_context_t ctx, const char *filename, int type,
129 int *fd);
130 void unlock_flock (int *fd);
132 #endif