Add pwmd_connect_fd() and read/write callbacks.
[libpwmd.git] / src / types.h
blobe786435166a090d65ed3257308dbd3fd8e58d4f8
1 /*
2 Copyright (C) 2006-2016, 2017 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 as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 USA
21 #ifndef TYPES_H
22 #define TYPES_H
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <libpwmd.h>
29 #include <pthread.h>
30 #include <assuan.h>
32 #ifdef WITH_SSH
33 #include "ssh.h"
34 #endif
36 #ifdef WITH_GNUTLS
37 #include "tls.h"
38 #endif
40 #ifdef ENABLE_NLS
41 #ifdef HAVE_SETLOCALE
42 #include <locale.h>
43 #endif
44 #include "gettext.h"
45 #define N_(msgid) dgettext("libpwmd", msgid)
46 #else
47 #define N_(msgid) (msgid)
48 #endif
50 #define N_ARRAY(a) (sizeof(a)/sizeof(a[0]))
52 typedef enum
54 PWMD_IPV6, PWMD_IPV4, PWMD_IP_ANY
55 } pwmd_ip_version_t;
57 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
58 struct tcp_s
60 char *host;
61 unsigned port;
62 int *fd;
63 gpg_error_t rc;
64 struct addrinfo *addrs;
65 struct addrinfo *addr;
66 pthread_cond_t dns_cond;
67 pthread_mutex_t dns_mutex;
68 #ifdef WITH_SSH
69 struct ssh_s *ssh;
70 #endif
71 #ifdef WITH_GNUTLS
72 struct tls_s *tls;
73 #endif
75 #endif
77 #define OPT_LOCK_ON_OPEN 0x0001
78 #define OPT_SIGPIPE 0x0002
80 struct pwm_s
82 assuan_context_t ctx;
83 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
84 struct tcp_s *tcp;
85 #ifdef WITH_GNUTLS
86 int tls_error;
87 #endif
88 #endif
89 /* Options set with pwmd_setopt(). */
90 pwmd_read_cb_t read_cb;
91 void *read_cb_data;
92 pwmd_write_cb_t write_cb;
93 void *write_cb_data;
94 int user_fd;
95 pwmd_ip_version_t prot;
96 pwmd_knownhost_cb_t kh_cb;
97 int needs_passphrase;
98 char *ssh_passphrase;
99 void *kh_data;
100 int use_agent;
101 int tls_verify;
102 char *tls_priority;
103 int socket_timeout;
104 int fd;
105 int cancel;
106 int connected;
107 #ifdef WITH_PINENTRY
108 pid_t pinentry_pid; // for local pinentry timeouts
109 assuan_context_t pctx;
110 #endif
111 char *pinentry_path;
112 char *pinentry_tty;
113 char *pinentry_term;
114 char *pinentry_display;
115 char *pinentry_lcctype;
116 char *pinentry_lcmessages;
117 char *pinentry_error;
118 char *pinentry_prompt;
119 char *pinentry_desc;
120 int pinentry_tries; // local pinentry
121 int pinentry_try; // local pinentry
122 char *passphrase_hint;
123 char *passphrase_info;
124 char *filename;
125 int pinentry_timeout;
126 int current_pinentry_timeout;
127 int disable_pinentry;
128 int local_pinentry;
129 int pinentry_disabled; // for sending the disable command
130 pwmd_status_cb_t status_func;
131 void *status_data;
132 pwmd_inquire_cb_t inquire_func;
133 void *inquire_data;
134 size_t inquire_total;
135 size_t inquire_sent;
136 size_t inquire_maxlen;
137 #ifdef WITH_QUALITY
138 gpg_error_t (*_inquire_func) (void *, const char *);
139 void *_inquire_data;
140 #endif
141 char *name;
142 unsigned opts;
143 int override_inquire;
144 void *user_data;
145 unsigned version; // of pwmd
148 gpg_error_t _assuan_command (pwm_t * pwm, assuan_context_t ctx,
149 char **result, size_t * len, const char *cmd);
150 gpg_error_t _connect_finalize (pwm_t * pwm);
151 #if defined(WITH_SSH) || defined(WITH_GNUTLS)
152 void free_tcp (pwm_t *);
153 gpg_error_t tcp_connect_common (pwm_t * pwm);
154 #endif
156 #endif