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,
23 /* Please note that this is a stripped down and modified version of
24 the orginal Assuan code from libassuan. */
30 #include <sys/types.h>
31 #ifndef HAVE_W32_SYSTEM
32 #include <sys/socket.h>
42 #ifndef HAVE_W32_SYSTEM
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. */
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
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
);
70 #define LINELENGTH ASSUAN_LINELENGTH
75 int (*handler
)(assuan_context_t
, char *line
);
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 *);
90 struct assuan_context_s
92 assuan_error_t err_no
;
94 int os_errno
; /* last system error number used with certain error codes*/
97 int is_server
; /* set if this is context belongs to a server */
100 char *okay_line
; /* see assan_set_okay_line() */
102 void *user_pointer
; /* for assuan_[gs]et_pointer () */
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 */
114 char line
[LINELENGTH
];
116 int pending
; /* i.e. at least one line is available in the attic */
124 char line
[LINELENGTH
];
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. */
143 /* Offset of start of buffer. */
144 int domainbufferoffset
;
145 /* Bytes buffered. */
146 int domainbuffersize
;
147 /* Memory allocated. */
148 int domainbufferallocated
;
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 */
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
,
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)))
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
,
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*/