contrib: Add helper to build Android dependencies.
[libpwmd.git] / src / types.h
blob509f28e7b3422d95a04290f33118b2d4a2352b65
1 /*
2 Copyright (C) 2006-2023 Ben Kibbey <bjk@luxsci.net>
4 This file is part of libpwmd.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License version 2.1 as published by the Free Software Foundation.
10 This library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 USA
20 #ifndef TYPES_H
21 #define TYPES_H
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <libpwmd.h>
28 #include <pthread.h>
29 #include <assuan.h>
31 #ifdef WITH_SSH
32 #include "ssh.h"
33 #endif
35 #ifdef WITH_GNUTLS
36 #include "tls.h"
37 #endif
39 #ifdef ENABLE_NLS
40 # ifdef HAVE_LOCALE_H
41 # include <locale.h>
42 # endif
43 #include "gettext.h"
44 #define N_(msgid) dgettext("libpwmd", msgid)
45 #else
46 #define N_(msgid) (msgid)
47 #endif
49 #define N_ARRAY(a) (sizeof(a)/sizeof(a[0]))
51 typedef enum
53 PWMD_IPV6, PWMD_IPV4, PWMD_IP_ANY
54 } pwmd_ip_version_t;
56 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
58 #define TCP_FLAG_DNS_FINISHED 0x01
60 struct tcp_s
62 char *host;
63 unsigned port;
64 gpg_error_t rc;
65 struct addrinfo *addrs;
66 struct addrinfo *addr;
67 pthread_cond_t dns_cond;
68 pthread_mutex_t dns_mutex;
69 unsigned flags;
70 #ifdef WITH_SSH
71 struct ssh_s *ssh;
72 #endif
73 #ifdef WITH_GNUTLS
74 struct tls_s *tls;
75 #endif
77 #endif
79 /* Borrowed from g10code. */
80 #if __WIN64__
81 # define SOCKET2HANDLE(s) ((void *)(s))
82 # define HANDLE2SOCKET(h) ((uintptr_t)(h))
83 #elif __MINGW32__
84 # define SOCKET2HANDLE(s) ((void *)(s))
85 # define HANDLE2SOCKET(h) ((unsigned int)(h))
86 #else
87 # define SOCKET2HANDLE(s) (s)
88 # define HANDLE2SOCKET(h) (h)
89 #endif
91 #define OPT_LOCK_ON_OPEN 0x0001
92 #define OPT_SIGPIPE 0x0002
93 #define OPT_STATE_STATUS 0x0004
95 struct pwm_s
97 assuan_context_t ctx;
98 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
99 struct tcp_s *tcp;
100 #ifdef WITH_GNUTLS
101 int tls_error;
102 #endif
103 #endif
104 #ifdef __MINGW32__
105 SOCKET fh;
106 #endif
107 long lock_timeout;
108 /* Options set with pwmd_setopt(). */
109 pwmd_read_cb_t read_cb;
110 void *read_cb_data;
111 pwmd_write_cb_t write_cb;
112 void *write_cb_data;
113 int user_fd;
114 pwmd_ip_version_t prot;
115 pwmd_knownhost_cb_t kh_cb;
116 void *kh_data;
117 pwmd_passphrase_cb_t passphrase_cb;
118 void *passphrase_data;
119 int needs_passphrase;
120 char *ssh_passphrase;
121 int use_agent;
122 int tls_verify;
123 char *tls_priority;
124 int socket_timeout;
125 assuan_fd_t fd;
126 int cancel;
127 int connected;
128 #ifdef WITH_PINENTRY
129 pid_t pinentry_pid; // for local pinentry timeouts
130 assuan_context_t pctx;
131 #endif
132 char *pinentry_path;
133 char *pinentry_tty;
134 char *pinentry_term;
135 char *pinentry_display;
136 char *pinentry_lcctype;
137 char *pinentry_lcmessages;
138 char *pinentry_error;
139 char *pinentry_prompt;
140 char *pinentry_desc;
141 int pinentry_tries; // local pinentry
142 int pinentry_try; // local pinentry
143 char *passphrase_hint;
144 char *passphrase_info;
145 char *filename;
146 int pinentry_timeout;
147 int current_pinentry_timeout;
148 int disable_pinentry;
149 int local_pinentry;
150 int pinentry_disabled; // for sending the disable command
151 int pin_repeated;
152 pwmd_status_cb_t status_func;
153 void *status_data;
154 pwmd_inquire_cb_t inquire_func;
155 void *inquire_data;
156 size_t inquire_total;
157 size_t inquire_sent;
158 size_t inquire_maxlen;
159 char *bulk_id;
160 size_t data_total; // Used by the XFER status message
161 #ifdef WITH_QUALITY
162 gpg_error_t (*_inquire_func) (void *, const char *);
163 void *_inquire_data;
164 #endif
165 char *name;
166 unsigned opts;
167 int override_inquire;
168 void *user_data;
169 unsigned version; // of pwmd
172 gpg_error_t _assuan_command (pwm_t * pwm, assuan_context_t ctx,
173 char **result, size_t * len, const char *cmd);
174 gpg_error_t _connect_finalize (pwm_t * pwm);
175 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
176 void free_tcp (pwm_t *);
177 gpg_error_t tcp_connect_common (pwm_t * pwm);
178 #endif
180 #endif