1/* assuan.h - Definitions for the Assuan IPC library             -*- c -*-
2 * Copyright (C) 2001-2013 Free Software Foundation, Inc.
3 * Copyright (C) 2001-2021 g10 Code GmbH
4 *
5 * This file is part of Assuan.
6 *
7 * Assuan is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * Assuan is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
19 * SPDX-License-Identifier: LGPL-2.1-or-later
20 *
21 * @configure_input@
22 */
23
24/* Compile time configuration:
25 *
26 * #define _ASSUAN_NO_SOCKET_WRAPPER
27 *
28 * Do not include the definitions for the socket wrapper feature.
29 */
30
31#ifndef ASSUAN_H
32#define ASSUAN_H
33
34#include <stdio.h>
35@include:sys/types.h@
36@include:unistd.h@
37#include <stdarg.h>
38
39#ifndef _ASSUAN_NO_SOCKET_WRAPPER
40@include:includes@
41#endif /*!_ASSUAN_NO_SOCKET_WRAPPER*/
42
43@include:types@
44
45#include <gpg-error.h>
46
47#ifdef __cplusplus
48extern "C"
49{
50#if 0
51}
52#endif
53#endif
54
55/* The version of this header should match the one of the library.  Do
56 * not use this symbol in your application; use assuan_check_version
57 * instead.  */
58#define ASSUAN_VERSION @version@
59
60/* The version number of this header.  It may be used to handle minor
61 * API incompatibilities.  */
62#define ASSUAN_VERSION_NUMBER @version-number@
63
64
65/* Check for compiler features.  */
66#if __GNUC__
67#define _ASSUAN_GCC_VERSION (__GNUC__ * 10000 \
68                            + __GNUC_MINOR__ * 100 \
69                            + __GNUC_PATCHLEVEL__)
70
71#if _ASSUAN_GCC_VERSION > 30100
72#define _ASSUAN_DEPRECATED  __attribute__ ((__deprecated__))
73#endif
74#endif
75#ifndef _ASSUAN_DEPRECATED
76#define _ASSUAN_DEPRECATED
77#endif
78
79
80#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */
81
82struct assuan_context_s;
83typedef struct assuan_context_s *assuan_context_t;
84@include:fd-t@
85
86assuan_fd_t assuan_fdopen (int fd);
87
88@include:sock-nonce@
89
90
91/*
92 * Global interface.
93 */
94
95struct assuan_malloc_hooks
96{
97  void *(*malloc) (size_t cnt);
98  void *(*realloc) (void *ptr, size_t cnt);
99  void (*free) (void *ptr);
100};
101typedef struct assuan_malloc_hooks *assuan_malloc_hooks_t;
102
103/* Categories for log messages.  */
104#define ASSUAN_LOG_INIT 1
105#define ASSUAN_LOG_CTX 2
106#define ASSUAN_LOG_ENGINE 3
107#define ASSUAN_LOG_DATA 4
108#define ASSUAN_LOG_SYSIO 5
109#define ASSUAN_LOG_CONTROL 8
110
111/* If MSG is NULL, return true/false depending on if this category is
112 * logged.  This is used to probe before expensive log message
113 * generation (buffer dumps).  */
114typedef int (*assuan_log_cb_t) (assuan_context_t ctx, void *hook,
115				unsigned int cat, const char *msg);
116
117/* Return or check the version number.  */
118const char *assuan_check_version (const char *req_version);
119
120/* Set the default gpg error source.  */
121void assuan_set_gpg_err_source (gpg_err_source_t errsource);
122
123/* Get the default gpg error source.  */
124gpg_err_source_t assuan_get_gpg_err_source (void);
125
126
127/* Set the default malloc hooks.  */
128void assuan_set_malloc_hooks (assuan_malloc_hooks_t malloc_hooks);
129
130/* Get the default malloc hooks.  */
131assuan_malloc_hooks_t assuan_get_malloc_hooks (void);
132
133
134/* Set the default log callback handler.  */
135void assuan_set_log_cb (assuan_log_cb_t log_cb, void *log_cb_data);
136
137/* Get the default log callback handler.  */
138void assuan_get_log_cb (assuan_log_cb_t *log_cb, void **log_cb_data);
139
140
141/* Create a new Assuan context.  The initial parameters are all needed
142 * in the creation of the context.  */
143gpg_error_t assuan_new_ext (assuan_context_t *ctx, gpg_err_source_t errsource,
144			    assuan_malloc_hooks_t malloc_hooks,
145			    assuan_log_cb_t log_cb, void *log_cb_data);
146
147/* Create a new context with default arguments.  */
148gpg_error_t assuan_new (assuan_context_t *ctx);
149
150/* Release all resources associated with the given context.  */
151void assuan_release (assuan_context_t ctx);
152
153/* Release the memory at PTR using the allocation handler of the
154 * context CTX.  This is a convenience function.  */
155void assuan_free (assuan_context_t ctx, void *ptr);
156
157
158/* Set user-data in a context.  */
159void assuan_set_pointer (assuan_context_t ctx, void *pointer);
160
161/* Get user-data in a context.  */
162void *assuan_get_pointer (assuan_context_t ctx);
163
164
165/* Definitions of flags for assuan_set_flag().  */
166typedef unsigned int assuan_flag_t;
167
168/* When using a pipe server, by default Assuan will wait for the
169 * forked process to die in assuan_release.  In certain cases this
170 * is not desirable.  By setting this flag, the waitpid will be
171 * skipped and the caller is responsible to cleanup a forked
172 * process. */
173#define ASSUAN_NO_WAITPID 1
174
175/* This flag indicates whether Assuan logging is in confidential mode.
176   You can use assuan_{begin,end}_condidential to change the mode.  */
177#define ASSUAN_CONFIDENTIAL 2
178
179/* This flag suppresses fix up of signal handlers for pipes.  */
180#define ASSUAN_NO_FIXSIGNALS 3
181
182/* This flag changes assuan_transact to return comment lines via the
183 * status callback.  The default is to skip comment lines.  */
184#define ASSUAN_CONVEY_COMMENTS 4
185
186/* This flag disables logging for one context.  */
187#define ASSUAN_NO_LOGGING 5
188
189/* This flag forces a connection close.  */
190#define ASSUAN_FORCE_CLOSE 6
191
192
193/* For context CTX, set the flag FLAG to VALUE.  Values for flags
194 * are usually 1 or 0 but certain flags might allow for other values;
195 * see the description of the type assuan_flag_t for details.  */
196void assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value);
197
198/* Return the VALUE of FLAG in context CTX.  */
199int assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag);
200
201/* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 1).  */
202void assuan_begin_confidential (assuan_context_t ctx);
203
204/* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 0).  */
205void assuan_end_confidential (assuan_context_t ctx);
206
207
208/* Direction values for assuan_set_io_monitor.  */
209#define ASSUAN_IO_FROM_PEER 0
210#define ASSUAN_IO_TO_PEER 1
211
212/* Return flags of I/O monitor.  */
213#define ASSUAN_IO_MONITOR_NOLOG 1
214#define ASSUAN_IO_MONITOR_IGNORE 2
215
216/* The IO monitor gets to see all I/O on the context, and can return
217 * ASSUAN_IO_MONITOR_* bits to control actions on it.  */
218typedef unsigned int (*assuan_io_monitor_t) (assuan_context_t ctx, void *hook,
219					     int inout, const char *line,
220					     size_t linelen);
221
222/* Set the IO monitor function.  */
223void assuan_set_io_monitor (assuan_context_t ctx,
224			    assuan_io_monitor_t io_monitor, void *hook_data);
225
226/* The system hooks.  See assuan_set_system_hooks et al. */
227#define ASSUAN_SYSTEM_HOOKS_VERSION 2
228#define ASSUAN_SPAWN_DETACHED 128
229struct assuan_system_hooks
230{
231  /* Always set to ASSUAN_SYTEM_HOOKS_VERSION.  */
232  int version;
233
234  /* Sleep for the given number of microseconds.  */
235  void (*usleep) (assuan_context_t ctx, unsigned int usec);
236
237  /* Create a pipe with an inheritable end.  */
238  int (*pipe) (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx);
239
240 /* Close the given file descriptor, created with _assuan_pipe or one
241   of the socket functions.  */
242  int (*close) (assuan_context_t ctx, assuan_fd_t fd);
243
244
245  ssize_t (*read) (assuan_context_t ctx, assuan_fd_t fd, void *buffer,
246		   size_t size);
247  ssize_t (*write) (assuan_context_t ctx, assuan_fd_t fd,
248		    const void *buffer, size_t size);
249
250  int (*recvmsg) (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg,
251		  int flags);
252  int (*sendmsg) (assuan_context_t ctx, assuan_fd_t fd,
253		  const assuan_msghdr_t msg, int flags);
254
255  /* If NAME is NULL, don't exec, just fork.  FD_CHILD_LIST is
256     modified to reflect the value of the FD in the peer process (on
257     Windows).  */
258  int (*spawn) (assuan_context_t ctx, pid_t *r_pid, const char *name,
259		const char **argv,
260		assuan_fd_t fd_in, assuan_fd_t fd_out,
261		assuan_fd_t *fd_child_list,
262		void (*atfork) (void *opaque, int reserved),
263		void *atforkvalue, unsigned int flags);
264
265  /* If action is 0, like waitpid.  If action is 1, just release the PID?  */
266  pid_t (*waitpid) (assuan_context_t ctx, pid_t pid,
267		    int action, int *status, int options);
268  int (*socketpair) (assuan_context_t ctx, int _namespace, int style,
269		     int protocol, assuan_fd_t filedes[2]);
270  int (*socket) (assuan_context_t ctx, int _namespace, int style, int protocol);
271  int (*connect) (assuan_context_t ctx, int sock, struct sockaddr *addr, socklen_t length);
272};
273typedef struct assuan_system_hooks *assuan_system_hooks_t;
274
275
276
277/*
278 * Configuration of the default log handler.
279 */
280
281/* Set the prefix to be used at the start of a line emitted by assuan
282 * on the log stream.  The default is the empty string.  Note, that
283 * this function is not thread-safe and should in general be used
284 * right at startup. */
285void assuan_set_assuan_log_prefix (const char *text);
286
287/* Return a prefix to be used at the start of a line emitted by assuan
288 * on the log stream.  The default implementation returns the empty
289 * string, i.e. "".  */
290const char *assuan_get_assuan_log_prefix (void);
291
292/* Global default log stream.  */
293void assuan_set_assuan_log_stream (FILE *fp);
294
295/* Set the per context log stream for the default log handler.  */
296void assuan_set_log_stream (assuan_context_t ctx, FILE *fp);
297
298
299/* The type for assuan command handlers.  */
300typedef gpg_error_t (*assuan_handler_t) (assuan_context_t, char *);
301
302/*-- assuan-handler.c --*/
303gpg_error_t assuan_register_command (assuan_context_t ctx,
304				     const char *cmd_string,
305				     assuan_handler_t handler,
306                                     const char *help_string);
307gpg_error_t assuan_register_pre_cmd_notify (assuan_context_t ctx,
308                                          gpg_error_t (*fnc)(assuan_context_t,
309                                                             const char *cmd));
310
311gpg_error_t assuan_register_post_cmd_notify (assuan_context_t ctx,
312					     void (*fnc)(assuan_context_t,
313                                                         gpg_error_t));
314gpg_error_t assuan_register_bye_notify (assuan_context_t ctx,
315					assuan_handler_t handler);
316gpg_error_t assuan_register_reset_notify (assuan_context_t ctx,
317					  assuan_handler_t handler);
318gpg_error_t assuan_register_cancel_notify (assuan_context_t ctx,
319					   assuan_handler_t handler);
320gpg_error_t assuan_register_input_notify (assuan_context_t ctx,
321					  assuan_handler_t handler);
322gpg_error_t assuan_register_output_notify (assuan_context_t ctx,
323					   assuan_handler_t handler);
324
325gpg_error_t assuan_register_option_handler (assuan_context_t ctx,
326					    gpg_error_t (*fnc)(assuan_context_t,
327							       const char*,
328                                                               const char*));
329
330gpg_error_t assuan_process (assuan_context_t ctx);
331gpg_error_t assuan_process_next (assuan_context_t ctx, int *done);
332gpg_error_t assuan_process_done (assuan_context_t ctx, gpg_error_t rc);
333int assuan_get_active_fds (assuan_context_t ctx, int what,
334                           assuan_fd_t *fdarray, int fdarraysize);
335
336const char *assuan_get_command_name (assuan_context_t ctx);
337
338FILE *assuan_get_data_fp (assuan_context_t ctx);
339gpg_error_t assuan_set_okay_line (assuan_context_t ctx, const char *line);
340gpg_error_t assuan_write_status (assuan_context_t ctx,
341				 const char *keyword, const char *text);
342
343/* Negotiate a file descriptor.  If LINE contains "FD=N", returns N
344 * assuming a local file descriptor.  If LINE contains "FD" reads a
345 * file descriptor via CTX and stores it in *RDF (the CTX must be
346 * capable of passing file descriptors).  Under Windows the returned
347 * FD is a libc-type one.  */
348gpg_error_t assuan_command_parse_fd (assuan_context_t ctx, char *line,
349                                        assuan_fd_t *rfd);
350
351
352/*-- assuan-listen.c --*/
353gpg_error_t assuan_set_hello_line (assuan_context_t ctx, const char *line);
354gpg_error_t assuan_accept (assuan_context_t ctx);
355assuan_fd_t assuan_get_input_fd (assuan_context_t ctx);
356assuan_fd_t assuan_get_output_fd (assuan_context_t ctx);
357gpg_error_t assuan_close_input_fd (assuan_context_t ctx);
358gpg_error_t assuan_close_output_fd (assuan_context_t ctx);
359
360
361/*-- assuan-pipe-server.c --*/
362gpg_error_t assuan_init_pipe_server (assuan_context_t ctx,
363				     assuan_fd_t filedes[2]);
364
365/*-- assuan-socket-server.c --*/
366#define ASSUAN_SOCKET_SERVER_FDPASSING 1
367#define ASSUAN_SOCKET_SERVER_ACCEPTED 2
368gpg_error_t assuan_init_socket_server (assuan_context_t ctx,
369				       assuan_fd_t listen_fd,
370				       unsigned int flags);
371void assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce);
372
373/*-- assuan-pipe-connect.c --*/
374#define ASSUAN_PIPE_CONNECT_FDPASSING 1
375#define ASSUAN_PIPE_CONNECT_DETACHED 128
376gpg_error_t assuan_pipe_connect (assuan_context_t ctx,
377				 const char *name,
378				 const char *argv[],
379				 assuan_fd_t *fd_child_list,
380				 void (*atfork) (void *, int),
381				 void *atforkvalue,
382				 unsigned int flags);
383
384/*-- assuan-socket-connect.c --*/
385#define ASSUAN_SOCKET_CONNECT_FDPASSING 1
386gpg_error_t assuan_socket_connect (assuan_context_t ctx, const char *name,
387				   pid_t server_pid, unsigned int flags);
388
389/*-- assuan-socket-connect.c --*/
390gpg_error_t assuan_socket_connect_fd (assuan_context_t ctx, int fd,
391				   unsigned int flags);
392
393/*-- context.c --*/
394pid_t assuan_get_pid (assuan_context_t ctx);
395struct _assuan_peercred
396{
397#ifdef _WIN32
398  /* Empty struct not allowed on some compilers, so, put this (not valid).  */
399  pid_t pid;
400#else
401  pid_t pid;
402  uid_t uid;
403  gid_t gid;
404#endif
405};
406typedef struct _assuan_peercred *assuan_peercred_t;
407
408gpg_error_t assuan_get_peercred (assuan_context_t ctx,
409				 assuan_peercred_t *peercred);
410
411
412
413/*
414 * Client interface.
415 */
416
417/* Client response codes.  */
418#define ASSUAN_RESPONSE_ERROR 0
419#define ASSUAN_RESPONSE_OK 1
420#define ASSUAN_RESPONSE_DATA 2
421#define ASSUAN_RESPONSE_INQUIRE 3
422#define ASSUAN_RESPONSE_STATUS 4
423#define ASSUAN_RESPONSE_END 5
424#define ASSUAN_RESPONSE_COMMENT 6
425typedef int assuan_response_t;
426
427/* This already de-escapes data lines.  */
428gpg_error_t assuan_client_read_response (assuan_context_t ctx,
429					 char **line, int *linelen);
430
431gpg_error_t assuan_client_parse_response (assuan_context_t ctx,
432					  char *line, int linelen,
433					  assuan_response_t *response,
434					  int *off);
435
436/*-- assuan-client.c --*/
437gpg_error_t
438assuan_transact (assuan_context_t ctx,
439                 const char *command,
440                 gpg_error_t (*data_cb)(void *, const void *, size_t),
441                 void *data_cb_arg,
442                 gpg_error_t (*inquire_cb)(void*, const char *),
443                 void *inquire_cb_arg,
444                 gpg_error_t (*status_cb)(void*, const char *),
445                 void *status_cb_arg);
446
447
448/*-- assuan-inquire.c --*/
449gpg_error_t assuan_inquire (assuan_context_t ctx, const char *keyword,
450                               unsigned char **r_buffer, size_t *r_length,
451                               size_t maxlen);
452gpg_error_t assuan_inquire_ext (assuan_context_t ctx, const char *keyword,
453				size_t maxlen,
454				gpg_error_t (*cb) (void *cb_data,
455						   gpg_error_t rc,
456						   unsigned char *buf,
457						   size_t buf_len),
458				void *cb_data);
459/*-- assuan-buffer.c --*/
460gpg_error_t assuan_read_line (assuan_context_t ctx,
461                              char **line, size_t *linelen);
462int assuan_pending_line (assuan_context_t ctx);
463gpg_error_t assuan_write_line (assuan_context_t ctx, const char *line);
464gpg_error_t assuan_send_data (assuan_context_t ctx,
465                              const void *buffer, size_t length);
466
467/* The file descriptor must be pending before assuan_receivefd is
468 * called.  This means that assuan_sendfd should be called *before* the
469 * trigger is sent (normally via assuan_write_line ("INPUT FD")).  */
470gpg_error_t assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd);
471gpg_error_t assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd);
472
473
474/*-- assuan-util.c --*/
475gpg_error_t assuan_set_error (assuan_context_t ctx, gpg_error_t err,
476			      const char *text);
477
478
479
480/*-- assuan-socket.c --*/
481
482/* This flag is used with assuan_sock_connect_byname to
483 * connect via SOCKS.  */
484#define ASSUAN_SOCK_SOCKS   1
485
486/* This flag is used with assuan_sock_connect_byname to force a
487   connection via Tor even if the socket subsystem has not been
488   swicthed into Tor mode.  This flags overrides ASSUAN_SOCK_SOCKS. */
489#define ASSUAN_SOCK_TOR     2
490
491/* These are socket wrapper functions to support an emulation of Unix
492 * domain sockets on Windows.  */
493gpg_error_t assuan_sock_init (void);
494void assuan_sock_deinit (void);
495int assuan_sock_close (assuan_fd_t fd);
496assuan_fd_t assuan_sock_new (int domain, int type, int proto);
497int assuan_sock_set_flag (assuan_fd_t sockfd, const char *name, int value);
498int assuan_sock_get_flag (assuan_fd_t sockfd, const char *name, int *r_value);
499int assuan_sock_connect (assuan_fd_t sockfd,
500                         struct sockaddr *addr, int addrlen);
501assuan_fd_t assuan_sock_connect_byname (const char *host, unsigned short port,
502                                        int reserved,
503                                        const char *credentials,
504                                        unsigned int flags);
505int assuan_sock_bind (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen);
506int assuan_sock_set_sockaddr_un (const char *fname, struct sockaddr *addr,
507                                 int *r_redirected);
508int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen,
509                           assuan_sock_nonce_t *nonce);
510int assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce);
511void assuan_sock_set_system_hooks (assuan_system_hooks_t system_hooks);
512
513
514/* Set the default system callbacks.  This is irreversible.  */
515void assuan_set_system_hooks (assuan_system_hooks_t system_hooks);
516
517/* Set the per context system callbacks.  This is irreversible.  */
518void assuan_ctx_set_system_hooks (assuan_context_t ctx,
519				  assuan_system_hooks_t system_hooks);
520
521/* Change the system hooks for the socket interface.
522 * This is not thread-safe.  */
523void assuan_sock_set_system_hooks (assuan_system_hooks_t system_hooks);
524
525void __assuan_usleep (assuan_context_t ctx, unsigned int usec);
526int __assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx);
527int __assuan_close (assuan_context_t ctx, assuan_fd_t fd);
528int __assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name,
529		    const char **argv, assuan_fd_t fd_in, assuan_fd_t fd_out,
530		    assuan_fd_t *fd_child_list,
531		    void (*atfork) (void *opaque, int reserved),
532		    void *atforkvalue, unsigned int flags);
533int __assuan_socketpair (assuan_context_t ctx, int _namespace, int style,
534			 int protocol, assuan_fd_t filedes[2]);
535int __assuan_socket (assuan_context_t ctx, int _namespace, int style, int protocol);
536int __assuan_connect (assuan_context_t ctx, int sock, struct sockaddr *addr, socklen_t length);
537ssize_t __assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size);
538ssize_t __assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer, size_t size);
539int __assuan_recvmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, int flags);
540int __assuan_sendmsg (assuan_context_t ctx, assuan_fd_t fd, const assuan_msghdr_t msg, int flags);
541pid_t __assuan_waitpid (assuan_context_t ctx, pid_t pid, int nowait, int *status, int options);
542
543/* Standard system hooks for the legacy GNU Pth.  */
544#define ASSUAN_SYSTEM_PTH_IMPL						\
545  static void _assuan_pth_usleep (assuan_context_t ctx, unsigned int usec) \
546  { (void) ctx; pth_usleep (usec); }					\
547  static ssize_t _assuan_pth_read (assuan_context_t ctx, assuan_fd_t fd, \
548				void *buffer, size_t size)		\
549  { (void) ctx; return pth_read (fd, buffer, size); }			\
550  static ssize_t _assuan_pth_write (assuan_context_t ctx, assuan_fd_t fd, \
551				 const void *buffer, size_t size)	\
552  { (void) ctx; return pth_write (fd, buffer, size); }			\
553@include:sys-pth-impl@
554  static pid_t _assuan_pth_waitpid (assuan_context_t ctx, pid_t pid,     \
555				   int nowait, int *status, int options) \
556  { (void) ctx;                                                         \
557     if (!nowait) return pth_waitpid (pid, status, options);            \
558      else return 0; }							\
559									\
560  struct assuan_system_hooks _assuan_system_pth =			\
561    { ASSUAN_SYSTEM_HOOKS_VERSION, _assuan_pth_usleep, __assuan_pipe,	\
562      __assuan_close, _assuan_pth_read, _assuan_pth_write,		\
563      _assuan_pth_recvmsg, _assuan_pth_sendmsg,				\
564      __assuan_spawn, _assuan_pth_waitpid, __assuan_socketpair,		\
565      __assuan_socket, __assuan_connect }
566
567extern struct assuan_system_hooks _assuan_system_pth;
568#define ASSUAN_SYSTEM_PTH &_assuan_system_pth
569
570/* Standard system hooks for nPth.  */
571#define ASSUAN_SYSTEM_NPTH_IMPL						\
572  static void _assuan_npth_usleep (assuan_context_t ctx, unsigned int usec) \
573  { npth_unprotect();				                        \
574    __assuan_usleep (ctx, usec);					\
575    npth_protect(); }							\
576  static ssize_t _assuan_npth_read (assuan_context_t ctx, assuan_fd_t fd, \
577				    void *buffer, size_t size)		\
578  { ssize_t res; (void) ctx; npth_unprotect();				\
579    res = __assuan_read (ctx, fd, buffer, size);			\
580    npth_protect(); return res; }					\
581  static ssize_t _assuan_npth_write (assuan_context_t ctx, assuan_fd_t fd, \
582				     const void *buffer, size_t size)	\
583  { ssize_t res; (void) ctx; npth_unprotect();				\
584    res = __assuan_write (ctx, fd, buffer, size);			\
585    npth_protect(); return res; }					\
586  static int _assuan_npth_recvmsg (assuan_context_t ctx, assuan_fd_t fd, \
587				  assuan_msghdr_t msg, int flags)	\
588  { int res; (void) ctx; npth_unprotect();				\
589    res = __assuan_recvmsg (ctx, fd, msg, flags);			\
590    npth_protect(); return res; }					\
591  static int _assuan_npth_sendmsg (assuan_context_t ctx, assuan_fd_t fd, \
592				  const assuan_msghdr_t msg, int flags) \
593  { int res; (void) ctx; npth_unprotect();				\
594    res = __assuan_sendmsg (ctx, fd, msg, flags);			\
595    npth_protect(); return res; }					\
596  static pid_t _assuan_npth_waitpid (assuan_context_t ctx, pid_t pid,	\
597				     int nowait, int *status, int options) \
598  { pid_t res; (void) ctx; npth_unprotect();				\
599    res = __assuan_waitpid (ctx, pid, nowait, status, options);		\
600    npth_protect(); return res; }					\
601  static int _assuan_npth_connect (assuan_context_t ctx, int sock,	\
602				   struct sockaddr *addr, socklen_t len)\
603  { int res; npth_unprotect();						\
604    res = __assuan_connect (ctx, sock, addr, len);			\
605    npth_protect(); return res; }					\
606  static int _assuan_npth_close (assuan_context_t ctx, assuan_fd_t fd)	\
607  { int res; npth_unprotect();						\
608    res = __assuan_close (ctx, fd);					\
609    npth_protect(); return res; }					\
610									\
611  struct assuan_system_hooks _assuan_system_npth =			\
612    { ASSUAN_SYSTEM_HOOKS_VERSION, _assuan_npth_usleep, __assuan_pipe,	\
613      _assuan_npth_close, _assuan_npth_read, _assuan_npth_write,	\
614      _assuan_npth_recvmsg, _assuan_npth_sendmsg,			\
615      __assuan_spawn, _assuan_npth_waitpid, __assuan_socketpair,	\
616      __assuan_socket, _assuan_npth_connect }
617
618extern struct assuan_system_hooks _assuan_system_npth;
619#define ASSUAN_SYSTEM_NPTH &_assuan_system_npth
620
621@include:w32ce-add@
622
623#ifdef __cplusplus
624}
625#endif
626#endif /* ASSUAN_H */
627