2001-11-20 05:27:46 +00:00
|
|
|
|
/* assuan-buffer.c - read and send data
|
2003-08-18 19:17:08 +00:00
|
|
|
|
* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
|
2001-11-20 05:27:46 +00:00
|
|
|
|
*
|
2003-02-01 18:53:06 +00:00
|
|
|
|
* This file is part of Assuan.
|
2001-11-20 05:27:46 +00:00
|
|
|
|
*
|
2003-02-01 18:53:06 +00:00
|
|
|
|
* Assuan is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
2001-11-20 05:27:46 +00:00
|
|
|
|
*
|
2003-02-01 18:53:06 +00:00
|
|
|
|
* Assuan is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
2001-11-20 05:27:46 +00:00
|
|
|
|
*
|
2003-02-01 18:53:06 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
2001-11-20 05:27:46 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <stdlib.h>
|
2002-01-22 16:29:12 +00:00
|
|
|
|
#include <string.h>
|
2001-11-20 05:27:46 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include "assuan-defs.h"
|
|
|
|
|
|
|
|
|
|
static int
|
2003-08-18 19:17:08 +00:00
|
|
|
|
writen (ASSUAN_CONTEXT ctx, const char *buffer, size_t length)
|
2001-11-20 05:27:46 +00:00
|
|
|
|
{
|
|
|
|
|
while (length)
|
|
|
|
|
{
|
2005-03-22 09:11:28 +00:00
|
|
|
|
ssize_t nwritten = ctx->io->writefnc (ctx, buffer, length);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
|
|
|
|
|
if (nwritten < 0)
|
|
|
|
|
{
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
return -1; /* write error */
|
|
|
|
|
}
|
|
|
|
|
length -= nwritten;
|
|
|
|
|
buffer += nwritten;
|
|
|
|
|
}
|
|
|
|
|
return 0; /* okay */
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
|
/* Read an entire line. */
|
2001-11-20 05:27:46 +00:00
|
|
|
|
static int
|
2003-08-18 19:17:08 +00:00
|
|
|
|
readline (ASSUAN_CONTEXT ctx, char *buf, size_t buflen,
|
|
|
|
|
int *r_nread, int *eof)
|
2001-11-20 05:27:46 +00:00
|
|
|
|
{
|
|
|
|
|
size_t nleft = buflen;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
*eof = 0;
|
|
|
|
|
*r_nread = 0;
|
|
|
|
|
while (nleft > 0)
|
|
|
|
|
{
|
2005-03-22 09:11:28 +00:00
|
|
|
|
ssize_t n = ctx->io->readfnc (ctx, buf, nleft);
|
2003-02-01 18:53:06 +00:00
|
|
|
|
|
2001-11-20 05:27:46 +00:00
|
|
|
|
if (n < 0)
|
|
|
|
|
{
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
return -1; /* read error */
|
|
|
|
|
}
|
|
|
|
|
else if (!n)
|
|
|
|
|
{
|
|
|
|
|
*eof = 1;
|
|
|
|
|
break; /* allow incomplete lines */
|
|
|
|
|
}
|
|
|
|
|
p = buf;
|
|
|
|
|
nleft -= n;
|
|
|
|
|
buf += n;
|
|
|
|
|
*r_nread += n;
|
2003-08-18 19:17:08 +00:00
|
|
|
|
|
|
|
|
|
p = memrchr (p, '\n', n);
|
|
|
|
|
if (p)
|
2001-11-24 21:22:18 +00:00
|
|
|
|
break; /* at least one full line available - that's enough for now */
|
2001-11-20 05:27:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_assuan_read_line (ASSUAN_CONTEXT ctx)
|
|
|
|
|
{
|
|
|
|
|
char *line = ctx->inbound.line;
|
2003-08-18 19:17:08 +00:00
|
|
|
|
int nread, atticlen;
|
2001-11-20 05:27:46 +00:00
|
|
|
|
int rc;
|
2003-08-18 19:17:08 +00:00
|
|
|
|
char *endp = 0;
|
2001-12-14 01:22:00 +00:00
|
|
|
|
|
2001-11-20 05:27:46 +00:00
|
|
|
|
if (ctx->inbound.eof)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2001-12-14 01:22:00 +00:00
|
|
|
|
atticlen = ctx->inbound.attic.linelen;
|
|
|
|
|
if (atticlen)
|
2001-11-24 21:22:18 +00:00
|
|
|
|
{
|
2001-12-14 01:22:00 +00:00
|
|
|
|
memcpy (line, ctx->inbound.attic.line, atticlen);
|
2001-11-24 21:22:18 +00:00
|
|
|
|
ctx->inbound.attic.linelen = 0;
|
2003-08-18 19:17:08 +00:00
|
|
|
|
|
|
|
|
|
endp = memchr (line, '\n', atticlen);
|
|
|
|
|
if (endp)
|
|
|
|
|
/* Found another line in the attic. */
|
2001-12-14 01:22:00 +00:00
|
|
|
|
{
|
2003-08-18 19:17:08 +00:00
|
|
|
|
rc = 0;
|
2001-12-14 01:22:00 +00:00
|
|
|
|
nread = atticlen;
|
|
|
|
|
atticlen = 0;
|
|
|
|
|
}
|
2001-11-24 21:22:18 +00:00
|
|
|
|
else
|
2003-08-18 19:17:08 +00:00
|
|
|
|
/* There is pending data but not a full line. */
|
|
|
|
|
{
|
2001-12-14 01:22:00 +00:00
|
|
|
|
assert (atticlen < LINELENGTH);
|
2003-08-18 19:17:08 +00:00
|
|
|
|
rc = readline (ctx, line + atticlen,
|
2001-12-14 01:22:00 +00:00
|
|
|
|
LINELENGTH - atticlen, &nread, &ctx->inbound.eof);
|
2001-11-24 21:22:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2003-08-18 19:17:08 +00:00
|
|
|
|
/* No pending data. */
|
|
|
|
|
rc = readline (ctx, line, LINELENGTH,
|
2001-11-24 21:22:18 +00:00
|
|
|
|
&nread, &ctx->inbound.eof);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
if (rc)
|
2002-01-22 16:29:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (ctx->log_fp)
|
2003-08-18 19:17:08 +00:00
|
|
|
|
fprintf (ctx->log_fp, "%s[%p] <- [Error: %s]\n",
|
|
|
|
|
assuan_get_assuan_log_prefix (), ctx, strerror (errno));
|
2002-01-22 16:29:12 +00:00
|
|
|
|
return ASSUAN_Read_Error;
|
|
|
|
|
}
|
2001-11-20 05:27:46 +00:00
|
|
|
|
if (!nread)
|
|
|
|
|
{
|
|
|
|
|
assert (ctx->inbound.eof);
|
2002-01-22 16:29:12 +00:00
|
|
|
|
if (ctx->log_fp)
|
2003-08-18 19:17:08 +00:00
|
|
|
|
fprintf (ctx->log_fp, "%s[%p] <- [EOF]\n",
|
|
|
|
|
assuan_get_assuan_log_prefix (), ctx);
|
|
|
|
|
return -1;
|
2001-11-20 05:27:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-12-13 15:04:36 +00:00
|
|
|
|
ctx->inbound.attic.pending = 0;
|
2001-12-14 01:22:00 +00:00
|
|
|
|
nread += atticlen;
|
2003-08-18 19:17:08 +00:00
|
|
|
|
|
|
|
|
|
if (! endp)
|
|
|
|
|
endp = memchr (line, '\n', nread);
|
|
|
|
|
|
|
|
|
|
if (endp)
|
2001-11-20 05:27:46 +00:00
|
|
|
|
{
|
2003-08-18 19:17:08 +00:00
|
|
|
|
int n = endp - line + 1;
|
|
|
|
|
if (n < nread)
|
|
|
|
|
/* LINE contains more than one line. We copy it to the attic
|
|
|
|
|
now as handlers are allowed to modify the passed
|
|
|
|
|
buffer. */
|
|
|
|
|
{
|
|
|
|
|
int len = nread - n;
|
|
|
|
|
memcpy (ctx->inbound.attic.line, endp + 1, len);
|
|
|
|
|
ctx->inbound.attic.pending = memrchr (endp + 1, '\n', len) ? 1 : 0;
|
|
|
|
|
ctx->inbound.attic.linelen = len;
|
|
|
|
|
}
|
2001-11-20 05:27:46 +00:00
|
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
|
if (endp != line && endp[-1] == '\r')
|
|
|
|
|
endp --;
|
|
|
|
|
*endp = 0;
|
|
|
|
|
|
|
|
|
|
ctx->inbound.linelen = endp - line;
|
|
|
|
|
if (ctx->log_fp)
|
|
|
|
|
{
|
|
|
|
|
fprintf (ctx->log_fp, "%s[%p] <- ",
|
|
|
|
|
assuan_get_assuan_log_prefix (), ctx);
|
|
|
|
|
if (ctx->confidential)
|
|
|
|
|
fputs ("[Confidential data not shown]", ctx->log_fp);
|
|
|
|
|
else
|
|
|
|
|
_assuan_log_print_buffer (ctx->log_fp,
|
|
|
|
|
ctx->inbound.line,
|
|
|
|
|
ctx->inbound.linelen);
|
|
|
|
|
putc ('\n', ctx->log_fp);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ctx->log_fp)
|
|
|
|
|
fprintf (ctx->log_fp, "%s[%p] <- [Invalid line]\n",
|
|
|
|
|
assuan_get_assuan_log_prefix (), ctx);
|
|
|
|
|
*line = 0;
|
|
|
|
|
ctx->inbound.linelen = 0;
|
|
|
|
|
return ctx->inbound.eof ? ASSUAN_Line_Not_Terminated
|
|
|
|
|
: ASSUAN_Line_Too_Long;
|
|
|
|
|
}
|
2001-11-20 05:27:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-13 15:04:36 +00:00
|
|
|
|
/* Read the next line from the client or server and return a pointer
|
2003-02-01 18:53:06 +00:00
|
|
|
|
in *LINE to a buffer holding the line. LINELEN is the length of
|
|
|
|
|
*LINE. The buffer is valid until the next read operation on it.
|
|
|
|
|
The caller may modify the buffer. The buffer is invalid (i.e. must
|
|
|
|
|
not be used) if an error is returned.
|
2001-12-13 15:04:36 +00:00
|
|
|
|
|
2003-02-01 18:53:06 +00:00
|
|
|
|
Returns 0 on success or an assuan error code.
|
2001-12-13 15:04:36 +00:00
|
|
|
|
See also: assuan_pending_line().
|
|
|
|
|
*/
|
|
|
|
|
AssuanError
|
|
|
|
|
assuan_read_line (ASSUAN_CONTEXT ctx, char **line, size_t *linelen)
|
|
|
|
|
{
|
2001-12-13 20:13:34 +00:00
|
|
|
|
AssuanError err;
|
|
|
|
|
|
2001-12-13 15:04:36 +00:00
|
|
|
|
if (!ctx)
|
|
|
|
|
return ASSUAN_Invalid_Value;
|
2001-12-13 20:13:34 +00:00
|
|
|
|
|
|
|
|
|
err = _assuan_read_line (ctx);
|
2001-12-13 15:04:36 +00:00
|
|
|
|
*line = ctx->inbound.line;
|
|
|
|
|
*linelen = ctx->inbound.linelen;
|
2001-12-13 20:13:34 +00:00
|
|
|
|
return err;
|
2001-12-13 15:04:36 +00:00
|
|
|
|
}
|
2001-11-20 05:27:46 +00:00
|
|
|
|
|
|
|
|
|
|
2003-02-01 18:53:06 +00:00
|
|
|
|
/* Return true if a full line is buffered (i.e. an entire line may be
|
|
|
|
|
read without any I/O). */
|
2001-12-13 15:04:36 +00:00
|
|
|
|
int
|
|
|
|
|
assuan_pending_line (ASSUAN_CONTEXT ctx)
|
|
|
|
|
{
|
|
|
|
|
return ctx && ctx->inbound.attic.pending;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AssuanError
|
2003-08-18 19:17:08 +00:00
|
|
|
|
assuan_write_line (ASSUAN_CONTEXT ctx, const char *line)
|
2001-11-20 05:27:46 +00:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
2003-02-01 18:53:06 +00:00
|
|
|
|
size_t len;
|
|
|
|
|
const char *s;
|
|
|
|
|
|
2001-12-13 15:04:36 +00:00
|
|
|
|
if (!ctx)
|
|
|
|
|
return ASSUAN_Invalid_Value;
|
2001-11-20 05:27:46 +00:00
|
|
|
|
|
2003-02-01 18:53:06 +00:00
|
|
|
|
/* Make sure that we never take a LF from the user - this might
|
|
|
|
|
violate the protocol. */
|
|
|
|
|
s = strchr (line, '\n');
|
|
|
|
|
len = s? (s-line) : strlen (line);
|
|
|
|
|
|
2004-06-08 17:48:37 +00:00
|
|
|
|
if (len > LINELENGTH - 2)
|
|
|
|
|
return ASSUAN_Line_Too_Long;
|
|
|
|
|
|
2003-02-01 18:53:06 +00:00
|
|
|
|
/* fixme: we should do some kind of line buffering. */
|
2002-01-22 16:29:12 +00:00
|
|
|
|
if (ctx->log_fp)
|
|
|
|
|
{
|
2003-08-18 19:17:08 +00:00
|
|
|
|
fprintf (ctx->log_fp, "%s[%p] -> ",
|
|
|
|
|
assuan_get_assuan_log_prefix (), ctx);
|
2003-02-01 18:53:06 +00:00
|
|
|
|
if (s)
|
2003-08-18 19:17:08 +00:00
|
|
|
|
fputs ("[supplied line contained a LF]", ctx->log_fp);
|
2002-01-22 16:29:12 +00:00
|
|
|
|
if (ctx->confidential)
|
2003-08-18 19:17:08 +00:00
|
|
|
|
fputs ("[Confidential data not shown]", ctx->log_fp);
|
2002-01-22 16:29:12 +00:00
|
|
|
|
else
|
2003-08-18 19:17:08 +00:00
|
|
|
|
_assuan_log_print_buffer (ctx->log_fp, line, len);
|
2002-01-22 16:29:12 +00:00
|
|
|
|
putc ('\n', ctx->log_fp);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
|
rc = writen (ctx, line, len);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
if (rc)
|
|
|
|
|
rc = ASSUAN_Write_Error;
|
|
|
|
|
if (!rc)
|
|
|
|
|
{
|
2003-08-18 19:17:08 +00:00
|
|
|
|
rc = writen (ctx, "\n", 1);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
if (rc)
|
|
|
|
|
rc = ASSUAN_Write_Error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Write out the data in buffer as datalines with line wrapping and
|
|
|
|
|
percent escaping. This fucntion is used for GNU's custom streams */
|
|
|
|
|
int
|
|
|
|
|
_assuan_cookie_write_data (void *cookie, const char *buffer, size_t size)
|
|
|
|
|
{
|
|
|
|
|
ASSUAN_CONTEXT ctx = cookie;
|
|
|
|
|
char *line;
|
|
|
|
|
size_t linelen;
|
|
|
|
|
|
|
|
|
|
if (ctx->outbound.data.error)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
line = ctx->outbound.data.line;
|
|
|
|
|
linelen = ctx->outbound.data.linelen;
|
|
|
|
|
line += linelen;
|
|
|
|
|
while (size)
|
|
|
|
|
{
|
|
|
|
|
/* insert data line header */
|
|
|
|
|
if (!linelen)
|
|
|
|
|
{
|
|
|
|
|
*line++ = 'D';
|
|
|
|
|
*line++ = ' ';
|
|
|
|
|
linelen += 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* copy data, keep some space for the CRLF and to escape one character */
|
|
|
|
|
while (size && linelen < LINELENGTH-2-2)
|
|
|
|
|
{
|
|
|
|
|
if (*buffer == '%' || *buffer == '\r' || *buffer == '\n')
|
|
|
|
|
{
|
|
|
|
|
sprintf (line, "%%%02X", *(unsigned char*)buffer);
|
|
|
|
|
line += 3;
|
|
|
|
|
linelen += 3;
|
|
|
|
|
buffer++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*line++ = *buffer++;
|
|
|
|
|
linelen++;
|
|
|
|
|
}
|
|
|
|
|
size--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (linelen >= LINELENGTH-2-2)
|
|
|
|
|
{
|
2002-01-22 16:29:12 +00:00
|
|
|
|
if (ctx->log_fp)
|
|
|
|
|
{
|
2003-08-18 19:17:08 +00:00
|
|
|
|
fprintf (ctx->log_fp, "%s[%p] -> ",
|
|
|
|
|
assuan_get_assuan_log_prefix (), ctx);
|
|
|
|
|
|
2002-01-22 16:29:12 +00:00
|
|
|
|
if (ctx->confidential)
|
|
|
|
|
fputs ("[Confidential data not shown]", ctx->log_fp);
|
|
|
|
|
else
|
|
|
|
|
_assuan_log_print_buffer (ctx->log_fp,
|
|
|
|
|
ctx->outbound.data.line,
|
|
|
|
|
linelen);
|
|
|
|
|
putc ('\n', ctx->log_fp);
|
|
|
|
|
}
|
2001-11-20 05:27:46 +00:00
|
|
|
|
*line++ = '\n';
|
|
|
|
|
linelen++;
|
2003-08-18 19:17:08 +00:00
|
|
|
|
if (writen (ctx, ctx->outbound.data.line, linelen))
|
2001-11-20 05:27:46 +00:00
|
|
|
|
{
|
|
|
|
|
ctx->outbound.data.error = ASSUAN_Write_Error;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
line = ctx->outbound.data.line;
|
|
|
|
|
linelen = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx->outbound.data.linelen = linelen;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Write out any buffered data
|
|
|
|
|
This fucntion is used for GNU's custom streams */
|
|
|
|
|
int
|
|
|
|
|
_assuan_cookie_write_flush (void *cookie)
|
|
|
|
|
{
|
|
|
|
|
ASSUAN_CONTEXT ctx = cookie;
|
|
|
|
|
char *line;
|
|
|
|
|
size_t linelen;
|
|
|
|
|
|
|
|
|
|
if (ctx->outbound.data.error)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
line = ctx->outbound.data.line;
|
|
|
|
|
linelen = ctx->outbound.data.linelen;
|
|
|
|
|
line += linelen;
|
|
|
|
|
if (linelen)
|
|
|
|
|
{
|
2002-01-22 16:29:12 +00:00
|
|
|
|
if (ctx->log_fp)
|
2003-08-18 19:17:08 +00:00
|
|
|
|
{
|
|
|
|
|
fprintf (ctx->log_fp, "%s[%p] -> ",
|
|
|
|
|
assuan_get_assuan_log_prefix (), ctx);
|
|
|
|
|
if (ctx->confidential)
|
|
|
|
|
fputs ("[Confidential data not shown]", ctx->log_fp);
|
|
|
|
|
else
|
|
|
|
|
_assuan_log_print_buffer (ctx->log_fp,
|
|
|
|
|
ctx->outbound.data.line, linelen);
|
|
|
|
|
putc ('\n', ctx->log_fp);
|
|
|
|
|
}
|
2001-11-20 05:27:46 +00:00
|
|
|
|
*line++ = '\n';
|
|
|
|
|
linelen++;
|
2003-08-18 19:17:08 +00:00
|
|
|
|
if (writen (ctx, ctx->outbound.data.line, linelen))
|
2001-11-20 05:27:46 +00:00
|
|
|
|
{
|
|
|
|
|
ctx->outbound.data.error = ASSUAN_Write_Error;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
ctx->outbound.data.linelen = 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-13 15:04:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* assuan_send_data:
|
|
|
|
|
* @ctx: An assuan context
|
|
|
|
|
* @buffer: Data to send or NULL to flush
|
|
|
|
|
* @length: length of the data to send/
|
|
|
|
|
*
|
|
|
|
|
* This function may be used by the server or the client to send data
|
|
|
|
|
* lines. The data will be escaped as required by the Assuan protocol
|
|
|
|
|
* and may get buffered until a line is full. To force sending the
|
|
|
|
|
* data out @buffer may be passed as NULL (in which case @length must
|
|
|
|
|
* also be 0); however when used by a client this flush operation does
|
|
|
|
|
* also send the terminating "END" command to terminate the reponse on
|
|
|
|
|
* a INQUIRE response. However, when assuan_transact() is used, this
|
|
|
|
|
* function takes care of sending END itself.
|
|
|
|
|
*
|
|
|
|
|
* Return value: 0 on success or an error code
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
AssuanError
|
|
|
|
|
assuan_send_data (ASSUAN_CONTEXT ctx, const void *buffer, size_t length)
|
|
|
|
|
{
|
|
|
|
|
if (!ctx)
|
|
|
|
|
return ASSUAN_Invalid_Value;
|
|
|
|
|
if (!buffer && length)
|
|
|
|
|
return ASSUAN_Invalid_Value;
|
|
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
|
{ /* flush what we have */
|
|
|
|
|
_assuan_cookie_write_flush (ctx);
|
|
|
|
|
if (ctx->outbound.data.error)
|
|
|
|
|
return ctx->outbound.data.error;
|
|
|
|
|
if (!ctx->is_server)
|
|
|
|
|
return assuan_write_line (ctx, "END");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_assuan_cookie_write_data (ctx, buffer, length);
|
|
|
|
|
if (ctx->outbound.data.error)
|
|
|
|
|
return ctx->outbound.data.error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-08-18 19:17:08 +00:00
|
|
|
|
|
|
|
|
|
AssuanError
|
|
|
|
|
assuan_sendfd (ASSUAN_CONTEXT ctx, int fd)
|
|
|
|
|
{
|
|
|
|
|
if (! ctx->io->sendfd)
|
|
|
|
|
return set_error (ctx, Not_Implemented,
|
|
|
|
|
"server does not support sending and receiving "
|
|
|
|
|
"of file descriptors");
|
|
|
|
|
return ctx->io->sendfd (ctx, fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AssuanError
|
|
|
|
|
assuan_receivefd (ASSUAN_CONTEXT ctx, int *fd)
|
|
|
|
|
{
|
|
|
|
|
if (! ctx->io->receivefd)
|
|
|
|
|
return set_error (ctx, Not_Implemented,
|
|
|
|
|
"server does not support sending and receiving "
|
|
|
|
|
"of file descriptors");
|
|
|
|
|
return ctx->io->receivefd (ctx, fd);
|
|
|
|
|
}
|