1 /* assuan-listen.c - Wait for a connection (server)
2 * Copyright (C) 2001, 2002, 2004 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, see <http://www.gnu.org/licenses/>.
27 #include "assuan-defs.h"
30 assuan_set_hello_line (assuan_context_t ctx
, const char *line
)
33 return _assuan_error (ASSUAN_Invalid_Value
);
36 xfree (ctx
->hello_line
);
37 ctx
->hello_line
= NULL
;
41 char *buf
= xtrymalloc (3+strlen(line
)+1);
43 return _assuan_error (ASSUAN_Out_Of_Core
);
44 if (strchr (line
, '\n'))
51 xfree (ctx
->hello_line
);
52 ctx
->hello_line
= buf
;
62 * Cancel any existing connection and wait for a connection from a
63 * client. The initial handshake is performed which may include an
64 * initial authentication or encryption negotiation.
66 * Return value: 0 on success or an error if the connection could for
67 * some reason not be established.
70 assuan_accept (assuan_context_t ctx
)
76 return _assuan_error (ASSUAN_Invalid_Value
);
78 if (ctx
->pipe_mode
> 1)
79 return -1; /* second invocation for pipemode -> terminate */
80 ctx
->finish_handler (ctx
);
82 rc
= ctx
->accept_handler (ctx
);
88 if (p
&& (pend
= strchr (p
, '\n')))
89 { /* This is a multi line hello. Send all but the last line as
93 rc
= _assuan_write_line (ctx
, "# ", p
, pend
- p
);
97 pend
= strchr (p
, '\n');
100 rc
= _assuan_write_line (ctx
, "OK ", p
, strlen (p
));
103 rc
= assuan_write_line (ctx
, p
);
105 rc
= assuan_write_line (ctx
, "OK Pleased to meet you");
118 assuan_get_input_fd (assuan_context_t ctx
)
120 return ctx
? ctx
->input_fd
: ASSUAN_INVALID_FD
;
125 assuan_get_output_fd (assuan_context_t ctx
)
127 return ctx
? ctx
->output_fd
: ASSUAN_INVALID_FD
;
131 /* Close the fd descriptor set by the command INPUT FD=n. We handle
132 this fd inside assuan so that we can do some initial checks */
134 assuan_close_input_fd (assuan_context_t ctx
)
136 if (!ctx
|| ctx
->input_fd
== ASSUAN_INVALID_FD
)
137 return _assuan_error (ASSUAN_Invalid_Value
);
138 _assuan_close (ctx
->input_fd
);
139 ctx
->input_fd
= ASSUAN_INVALID_FD
;
143 /* Close the fd descriptor set by the command OUTPUT FD=n. We handle
144 this fd inside assuan so that we can do some initial checks */
146 assuan_close_output_fd (assuan_context_t ctx
)
148 if (!ctx
|| ctx
->output_fd
== ASSUAN_INVALID_FD
)
149 return _assuan_error (ASSUAN_Invalid_Value
);
151 _assuan_close (ctx
->output_fd
);
152 ctx
->output_fd
= ASSUAN_INVALID_FD
;