Copyright (C) 2002, 2003, 2004, 2005, 2007 g10 Code GmbH
This file is part of GPGME.
-
+
GPGME 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.
-
+
GPGME 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.
-
+
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
#endif
#include <stdlib.h>
-#include <unistd.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
#include <errno.h>
#include <string.h>
return gpg_error (GPG_ERR_INV_VALUE);
*r_dh = NULL;
+
+ if (_gpgme_selftest)
+ return _gpgme_selftest;
+
dh = calloc (1, sizeof (*dh));
if (!dh)
return gpg_error_from_syserror ();
/* Read up to SIZE bytes into buffer BUFFER from the data object with
the handle DH. Return the number of characters read, 0 on EOF and
-1 on error. If an error occurs, errno is set. */
-ssize_t
+gpgme_ssize_t
gpgme_data_read (gpgme_data_t dh, void *buffer, size_t size)
{
- ssize_t res;
+ gpgme_ssize_t res;
TRACE_BEG2 (DEBUG_DATA, "gpgme_data_read", dh,
"buffer=%p, size=%u", buffer, size);
/* Write up to SIZE bytes from buffer BUFFER to the data object with
the handle DH. Return the number of characters written, or -1 on
error. If an error occurs, errno is set. */
-ssize_t
+gpgme_ssize_t
gpgme_data_write (gpgme_data_t dh, const void *buffer, size_t size)
{
- ssize_t res;
+ gpgme_ssize_t res;
TRACE_BEG2 (DEBUG_DATA, "gpgme_data_write", dh,
"buffer=%p, size=%u", buffer, size);
/* Set the current position from where the next read or write starts
in the data object with the handle DH to OFFSET, relativ to
WHENCE. */
-off_t
-gpgme_data_seek (gpgme_data_t dh, off_t offset, int whence)
+gpgme_off_t
+gpgme_data_seek (gpgme_data_t dh, gpgme_off_t offset, int whence)
{
TRACE_BEG2 (DEBUG_DATA, "gpgme_data_seek", dh,
"offset=%lli, whence=%i", offset, whence);
}
+/* Convenience function to do a gpgme_data_seek (dh, 0, SEEK_SET). */
+gpgme_error_t
+gpgme_data_rewind (gpgme_data_t dh)
+{
+ gpgme_error_t err;
+ TRACE_BEG (DEBUG_DATA, "gpgme_data_rewind", dh);
+
+ err = ((gpgme_data_seek (dh, 0, SEEK_SET) == -1)
+ ? gpg_error_from_syserror () : 0);
+
+ return TRACE_ERR (err);
+}
+
+
/* Release the data object with the handle DH. */
void
gpgme_data_release (gpgme_data_t dh)
"encoding=%i", enc);
if (!dh)
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
- if (enc < 0 || enc > GPGME_DATA_ENCODING_URL0)
+ if (enc < 0 || enc > GPGME_DATA_ENCODING_MIME)
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
dh->encoding = enc;
return TRACE_ERR (0);
return dh->file_name;
}
+
+/* Set a flag for the data object DH. See the manual for details. */
+gpg_error_t
+gpgme_data_set_flag (gpgme_data_t dh, const char *name, const char *value)
+{
+ TRACE_BEG2 (DEBUG_DATA, "gpgme_data_set_flag", dh,
+ "%s=%s", name, value);
+
+ if (!dh)
+ return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
+
+ if (!strcmp (name, "size-hint"))
+ {
+ dh->size_hint= value? _gpgme_string_to_off (value) : 0;
+ }
+ else
+ return gpg_error (GPG_ERR_UNKNOWN_NAME);
+
+ return 0;
+}
+
+
\f
/* Functions to support the wait interface. */
gpgme_data_t dh = (gpgme_data_t) data->handler_value;
char buffer[BUFFER_SIZE];
char *bufp = buffer;
- ssize_t buflen;
+ gpgme_ssize_t buflen;
TRACE_BEG1 (DEBUG_CTX, "_gpgme_data_inbound_handler", dh,
"fd=0x%x", fd);
do
{
- ssize_t amt = gpgme_data_write (dh, bufp, buflen);
+ gpgme_ssize_t amt = gpgme_data_write (dh, bufp, buflen);
if (amt == 0 || (amt < 0 && errno != EINTR))
return TRACE_ERR (gpg_error_from_syserror ());
bufp += amt;
{
struct io_cb_data *data = (struct io_cb_data *) opaque;
gpgme_data_t dh = (gpgme_data_t) data->handler_value;
- ssize_t nwritten;
+ gpgme_ssize_t nwritten;
TRACE_BEG1 (DEBUG_CTX, "_gpgme_data_outbound_handler", dh,
"fd=0x%x", fd);
if (!dh->pending_len)
{
- ssize_t amt = gpgme_data_read (dh, dh->pending, BUFFER_SIZE);
+ gpgme_ssize_t amt = gpgme_data_read (dh, dh->pending, BUFFER_SIZE);
if (amt < 0)
return TRACE_ERR (gpg_error_from_syserror ());
if (amt == 0)
return -1;
return (*dh->cbs->get_fd) (dh);
}
+
+
+/* Get the size-hint value for DH or 0 if not available. */
+gpgme_off_t
+_gpgme_data_get_size_hint (gpgme_data_t dh)
+{
+ return dh ? dh->size_hint : 0;
+}