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