Revert last. It is still wrong.
[gnupg.git] / util / assuan-defs.h
blob67c4e13cecad9e6f4354bd0d385c3c25aa7f9751
1 /* assuan-defs.c - Internal definitions to Assuan
2 * Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
3 * Copyright (C) 2005 Free Software Foundation, Inc.
5 * This file is part of Assuan.
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.
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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
23 /* Please note that this is a stripped down and modified version of
24 the orginal Assuan code from libassuan. */
27 #ifndef ASSUAN_DEFS_H
28 #define ASSUAN_DEFS_H
30 #include <sys/types.h>
31 #ifndef HAVE_W32_SYSTEM
32 #include <sys/socket.h>
33 #include <sys/un.h>
34 #else
35 #include <windows.h>
36 #endif
37 #include <unistd.h>
39 #include "assuan.h"
40 #include "memory.h"
42 #ifndef HAVE_W32_SYSTEM
43 #define DIRSEP_C '/'
44 #else
45 #define DIRSEP_C '\\'
46 #endif
48 #ifdef HAVE_W32_SYSTEM
49 #define AF_LOCAL AF_UNIX
50 /* We need to prefix the structure with a sockaddr_in header so we can
51 use it later for sendto and recvfrom. */
52 struct sockaddr_un
54 short sun_family;
55 unsigned short sun_port;
56 struct in_addr sun_addr;
57 char sun_path[108-2-4]; /* Path name. */
60 /* Not needed anymore because the current mingw32 defines this in
61 sys/types.h */
62 /* typedef int ssize_t; */
64 /* Missing W32 functions */
65 int putc_unlocked (int c, FILE *stream);
66 void * memrchr (const void *block, int c, size_t size);
67 char * stpcpy (char *dest, const char *src);
68 #endif
70 #define LINELENGTH ASSUAN_LINELENGTH
72 struct cmdtbl_s
74 const char *name;
75 int (*handler)(assuan_context_t, char *line);
78 struct assuan_io
80 /* Routine to read from input_fd. */
81 ssize_t (*readfnc) (assuan_context_t, void *, size_t);
82 /* Routine to write to output_fd. */
83 ssize_t (*writefnc) (assuan_context_t, const void *, size_t);
84 /* Send a file descriptor. */
85 assuan_error_t (*sendfd) (assuan_context_t, int);
86 /* Receive a file descriptor. */
87 assuan_error_t (*receivefd) (assuan_context_t, int *);
88 };
90 struct assuan_context_s
92 assuan_error_t err_no;
93 const char *err_str;
94 int os_errno; /* last system error number used with certain error codes*/
96 int confidential;
97 int is_server; /* set if this is context belongs to a server */
98 int in_inquire;
99 char *hello_line;
100 char *okay_line; /* see assan_set_okay_line() */
102 void *user_pointer; /* for assuan_[gs]et_pointer () */
104 FILE *log_fp;
106 struct {
107 int fd;
108 int eof;
109 char line[LINELENGTH];
110 int linelen; /* w/o CR, LF - might not be the same as
111 strlen(line) due to embedded nuls. However a nul
112 is always written at this pos */
113 struct {
114 char line[LINELENGTH];
115 int linelen ;
116 int pending; /* i.e. at least one line is available in the attic */
117 } attic;
118 } inbound;
120 struct {
121 int fd;
122 struct {
123 FILE *fp;
124 char line[LINELENGTH];
125 int linelen;
126 int error;
127 } data;
128 } outbound;
130 int pipe_mode; /* We are in pipe mode, i.e. we can handle just one
131 connection and must terminate then */
132 pid_t pid; /* The the pid of the peer. */
133 int listen_fd; /* The fd we are listening on (used by socket servers) */
134 int connected_fd; /* helper */
136 /* Used for Unix domain sockets. */
137 struct sockaddr_un myaddr;
138 struct sockaddr_un serveraddr;
139 /* When reading from datagram sockets, we must read an entire
140 message at a time. This means that we have to do our own
141 buffering to be able to get the semantics of read. */
142 void *domainbuffer;
143 /* Offset of start of buffer. */
144 int domainbufferoffset;
145 /* Bytes buffered. */
146 int domainbuffersize;
147 /* Memory allocated. */
148 int domainbufferallocated;
150 int *pendingfds;
151 int pendingfdscount;
153 void (*deinit_handler)(assuan_context_t);
154 int (*accept_handler)(assuan_context_t);
155 int (*finish_handler)(assuan_context_t);
157 struct cmdtbl_s *cmdtbl;
158 size_t cmdtbl_used; /* used entries */
159 size_t cmdtbl_size; /* allocated size of table */
161 void (*bye_notify_fnc)(assuan_context_t);
162 void (*reset_notify_fnc)(assuan_context_t);
163 void (*cancel_notify_fnc)(assuan_context_t);
164 int (*option_handler_fnc)(assuan_context_t,const char*, const char*);
165 void (*input_notify_fnc)(assuan_context_t, const char *);
166 void (*output_notify_fnc)(assuan_context_t, const char *);
168 int input_fd; /* set by INPUT command */
169 int output_fd; /* set by OUTPUT command */
171 /* io routines. */
172 struct assuan_io *io;
175 /*-- assuan-pipe-server.c --*/
176 int _assuan_new_context (assuan_context_t *r_ctx);
177 void _assuan_release_context (assuan_context_t ctx);
179 /*-- assuan-domain-connect.c --*/
180 /* Make a connection to the Unix domain socket NAME and return a new
181 Assuan context in CTX. SERVER_PID is currently not used but may
182 become handy in the future. */
183 assuan_error_t _assuan_domain_init (assuan_context_t *r_ctx,
184 int rendezvousfd,
185 pid_t peer);
187 /*-- assuan-handler.c --*/
188 int _assuan_register_std_commands (assuan_context_t ctx);
190 /*-- assuan-buffer.c --*/
191 int _assuan_read_line (assuan_context_t ctx);
192 int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
193 int _assuan_cookie_write_flush (void *cookie);
194 assuan_error_t _assuan_write_line (assuan_context_t ctx, const char *prefix,
195 const char *line, size_t len);
197 /*-- assuan-client.c --*/
198 assuan_error_t _assuan_read_from_server (assuan_context_t ctx, int *okay, int *off);
201 /*-- assuan-util.c --*/
203 #define set_error(c,e,t) assuan_set_error ((c), ASSUAN_ ## e, (t))
205 void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length);
206 void _assuan_log_sanitized_string (const char *string);
208 #ifdef HAVE_W32_SYSTEM
209 const char *_assuan_w32_strerror (int ec);
210 #define w32_strerror(e) _assuan_w32_strerror ((e))
211 #endif /*HAVE_W32_SYSTEM*/
214 /*-- assuan-logging.c --*/
215 void _assuan_set_default_log_stream (FILE *fp);
217 void _assuan_log_printf (const char *format, ...)
218 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
219 __attribute__ ((format (printf,1,2)))
220 #endif
223 /*-- assuan-io.c --*/
224 ssize_t _assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size);
225 ssize_t _assuan_simple_write (assuan_context_t ctx, const void *buffer,
226 size_t size);
228 /*-- assuan-socket.c --*/
229 int _assuan_close (int fd);
230 int _assuan_sock_new (int domain, int type, int proto);
231 int _assuan_sock_connect (int sockfd, struct sockaddr *addr, int addrlen);
233 #ifdef HAVE_FOPENCOOKIE
234 /* We have to implement funopen in terms of glibc's fopencookie. */
235 FILE *_assuan_funopen(void *cookie,
236 cookie_read_function_t *readfn,
237 cookie_write_function_t *writefn,
238 cookie_seek_function_t *seekfn,
239 cookie_close_function_t *closefn);
240 #define funopen(a,r,w,s,c) _assuan_funopen ((a), (r), (w), (s), (c))
241 #endif /*HAVE_FOPENCOOKIE*/
243 #endif /*ASSUAN_DEFS_H*/