1
/* assuan-defs.c - Internal definitions to Assuan
2
* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4
* This file is part of Assuan.
6
* Assuan is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU Lesser General Public License as
8
* published by the Free Software Foundation; either version 2.1 of
9
* the License, or (at your option) any later version.
11
* Assuan is distributed in the hope that it will be useful, but
12
* 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 program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24
#include <sys/types.h>
25
#include <sys/socket.h>
31
#define LINELENGTH ASSUAN_LINELENGTH
36
int (*handler)(ASSUAN_CONTEXT, char *line);
41
/* Routine to read from input_fd. */
42
ssize_t (*read) (ASSUAN_CONTEXT, void *, size_t);
43
/* Routine to write to output_fd. */
44
ssize_t (*write) (ASSUAN_CONTEXT, const void *, size_t);
45
/* Send a file descriptor. */
46
AssuanError (*sendfd) (ASSUAN_CONTEXT, int);
47
/* Receive a file descriptor. */
48
AssuanError (*receivefd) (ASSUAN_CONTEXT, int *);
51
struct assuan_context_s
55
int os_errno; /* last system error number used with certain error codes*/
58
int is_server; /* set if this is context belongs to a server */
61
char *okay_line; /* see assan_set_okay_line() */
63
void *user_pointer; /* for assuan_[gs]et_pointer () */
70
char line[LINELENGTH];
71
int linelen; /* w/o CR, LF - might not be the same as
72
strlen(line) due to embedded nuls. However a nul
73
is always written at this pos */
75
char line[LINELENGTH];
77
int pending; /* i.e. at least one line is available in the attic */
85
char line[LINELENGTH];
91
int pipe_mode; /* We are in pipe mode, i.e. we can handle just one
92
connection and must terminate then */
93
pid_t pid; /* In pipe mode, the pid of the child server process.
94
In socket mode, the pid of the server */
95
int listen_fd; /* The fd we are listening on (used by socket servers) */
96
int connected_fd; /* helper */
98
pid_t client_pid; /* for a socket server the PID of the client or -1
101
/* Used for Unix domain sockets. */
102
struct sockaddr_un myaddr;
103
struct sockaddr_un serveraddr;
104
/* When reading from datagram sockets, we must read an entire
105
message at a time. This means that we have to do our own
106
buffering to be able to get the semantics of read. */
108
/* Offset of start of buffer. */
109
int domainbufferoffset;
110
/* Bytes buffered. */
111
int domainbuffersize;
112
/* Memory allocated. */
113
int domainbufferallocated;
118
void (*deinit_handler)(ASSUAN_CONTEXT);
119
int (*accept_handler)(ASSUAN_CONTEXT);
120
int (*finish_handler)(ASSUAN_CONTEXT);
122
struct cmdtbl_s *cmdtbl;
123
size_t cmdtbl_used; /* used entries */
124
size_t cmdtbl_size; /* allocated size of table */
126
void (*bye_notify_fnc)(ASSUAN_CONTEXT);
127
void (*reset_notify_fnc)(ASSUAN_CONTEXT);
128
void (*cancel_notify_fnc)(ASSUAN_CONTEXT);
129
int (*option_handler_fnc)(ASSUAN_CONTEXT,const char*, const char*);
130
void (*input_notify_fnc)(ASSUAN_CONTEXT, const char *);
131
void (*output_notify_fnc)(ASSUAN_CONTEXT, const char *);
133
int input_fd; /* set by INPUT command */
134
int output_fd; /* set by OUTPUT command */
137
struct assuan_io *io;
140
/*-- assuan-pipe-server.c --*/
141
int _assuan_new_context (ASSUAN_CONTEXT *r_ctx);
142
void _assuan_release_context (ASSUAN_CONTEXT ctx);
144
/*-- assuan-domain-connect.c --*/
145
/* Make a connection to the Unix domain socket NAME and return a new
146
Assuan context in CTX. SERVER_PID is currently not used but may
147
become handy in the future. */
148
AssuanError _assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
152
/*-- assuan-handler.c --*/
153
int _assuan_register_std_commands (ASSUAN_CONTEXT ctx);
155
/*-- assuan-buffer.c --*/
156
int _assuan_read_line (ASSUAN_CONTEXT ctx);
157
int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
158
int _assuan_cookie_write_flush (void *cookie);
160
/*-- assuan-client.c --*/
161
AssuanError _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off);
164
/*-- assuan-util.c --*/
165
void *_assuan_malloc (size_t n);
166
void *_assuan_calloc (size_t n, size_t m);
167
void *_assuan_realloc (void *p, size_t n);
168
void _assuan_free (void *p);
170
#define xtrymalloc(a) _assuan_malloc ((a))
171
#define xtrycalloc(a,b) _assuan_calloc ((a),(b))
172
#define xtryrealloc(a,b) _assuan_realloc((a),(b))
173
#define xfree(a) _assuan_free ((a))
175
#define set_error(c,e,t) assuan_set_error ((c), ASSUAN_ ## e, (t))
177
void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length);
178
void _assuan_log_sanitized_string (const char *string);
180
/*-- assuan-io.c --*/
181
ssize_t _assuan_simple_read (ASSUAN_CONTEXT ctx, void *buffer, size_t size);
182
ssize_t _assuan_simple_write (ASSUAN_CONTEXT ctx, const void *buffer,
185
#ifdef HAVE_FOPENCOOKIE
186
/* We have to implement funopen in terms of glibc's fopencookie. */
187
FILE *funopen(const void *cookie, cookie_read_function_t *readfn,
188
cookie_write_function_t *writefn,
189
cookie_seek_function_t *seekfn,
190
cookie_close_function_t *closefn);
191
#endif /*HAVE_FOPENCOOKIE*/
193
#endif /*ASSUAN_DEFS_H*/