gpgme/gpgme/data-compat.c
Marcus Brinkmann 8208786b91 doc/
2003-04-24  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.texi (Error Values): Rename GPGME_No_Passphrase to
	GPGME_Bad_Passphrase.
	* gpgme.texi (Decrypt): Likewise.
	(Decrypt and Verify): Likewise.
	(Creating a Signature): Likewise.
	(Encrypting a Plaintext): Likewise.

	* gpgme.texi (Error Values): Rename GPGME_No_Recipients to
	GPGME_No_UserID and GPGME_Invalid_Recipient to
	GPGME_Invalid_UserID.
	(Encrypting a Plaintext): Likewise.

	* gpgme.texi (Error Values): Remove GPGME_Busy and GPGME_No_Request.
	(Listing Keys): Likewise.
	(Listing Trust Items): Likewise.

gpgme/
2003-04-24  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.h (GpgmeError): Rename GPGME_No_Passphrase to
	GPGME_Bad_Passphrase.
	* passphrase.c (_gpgme_passphrase_status_handler): Use
	GPGME_Bad_Passphrase instead GPGME_No_Passphrase.

	* gpgme.h (GpgmeError): Rename GPGME_No_Recipients to
	GPGME_No_UserID and GPGME_Invalid_Recipient to
	GPGME_Invalid_UserID.
	* encrypt.c (_gpgme_encrypt_status_handler): Use GPGME_No_UserID
	instead GPGME_No_Recipients and GPGME_Invalid_UserID instead
	GPGME_Invalid_Recipient.
	(_gpgme_op_encrypt_start): Likewise.

	* gpgme.h (GpgmeError): Remove GPGME_Busy and GPGME_No_Request.
	* wait-user.c (_gpgme_wait_user_event_cb): Don't clear CTX->pending.
	* wait-private.c (_gpgme_wait_private_event_cb): Likewise.
	* wait-global.c (gpgme_wait): Likewise.
	* verify.c (_gpgme_op_verify_start): Likewise.
	(gpgme_get_sig_status): Don't check pending flag.
	(gpgme_get_sig_string_attr): Likewise.
	(gpgme_get_sig_ulong_attr): Likewise.
	(gpgme_get_sig_key): Likewise.
	* op-support.c (_gpgme_op_reset): Likewise.
	* trustlist.c (gpgme_op_trustlist_start): Don't clear pending flag.
	(gpgme_op_trustlist_next): Don't check or clear pending flag.
	(gpgme_op_trustlist_end): Likewise.
	* sign.c (_gpgme_op_sign_start): Likewise.
	* context.h (struct gpgme_context_s): Remove member PENDING.
	* decrypt.c (_gpgme_decrypt_start): Likewise.
	* delete.c (_gpgme_op_delete_start): Likewise.
	* edit.c (_gpgme_op_edit_start): Likewise.
	* encrypt.c (_gpgme_op_encrypt_start): Likewise.
	* encrypt-sign.c (_gpgme_op_encrypt_sign_start): Likewise.
	* export.c (_gpgme_op_export_start): Likewise.
	* genkey.c (_gpgme_op_genkey_start): Likewise.
	* import.c (_gpgme_op_import_start): Likewise.
	* key.c (gpgme_get_key): Likewise.
	* keylist.c (gpgme_op_keylist_start): Likewise.
	(gpgme_op_keylist_ext_start): Likewise.
	(gpgme_op_keylist_next): Likewise.
	(gpgme_op_keylist_end): Likewise.
	* data-compat.c (gpgme_error_to_errno): Don't convert EBUSY.
2003-04-24 14:33:13 +00:00

190 lines
4.1 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* data-compat.c - Compatibility interfaces for data objects.
Copyright (C) 2002 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 General Public License as published by
the Free Software Foundation; either version 2 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GPGME; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <errno.h>
#include <sys/stat.h>
#include <stdlib.h>
#include "data.h"
#include "util.h"
/* Create a new data buffer filled with LENGTH bytes starting from
OFFSET within the file FNAME or stream STREAM (exactly one must be
non-zero). */
GpgmeError
gpgme_data_new_from_filepart (GpgmeData *dh, const char *fname, FILE *stream,
off_t offset, size_t length)
{
GpgmeError err;
char *buf = NULL;
if (stream && fname)
return GPGME_Invalid_Value;
if (fname)
stream = fopen (fname, "rb");
if (!stream)
return GPGME_File_Error;
if (fseek (stream, offset, SEEK_SET))
goto ferr;
buf = malloc (length);
if (!buf)
goto ferr;
while (fread (buf, length, 1, stream) < 1
&& ferror (stream) && errno == EINTR);
if (ferror (stream))
{
if (buf)
free (buf);
goto ferr;
}
if (fname)
fclose (stream);
err = gpgme_data_new (dh);
if (err)
{
if (buf)
free (buf);
return err;
}
(*dh)->data.mem.buffer = buf;
(*dh)->data.mem.size = length;
(*dh)->data.mem.length = length;
return 0;
ferr:
{
int saved_errno = errno;
if (fname)
fclose (stream);
errno = saved_errno;
return GPGME_File_Error;
}
}
/* Create a new data buffer filled with the content of file FNAME.
COPY must be non-zero (delayed reads are not supported yet). */
GpgmeError
gpgme_data_new_from_file (GpgmeData *dh, const char *fname, int copy)
{
struct stat statbuf;
if (!fname || !copy)
return GPGME_Invalid_Value;
if (stat (fname, &statbuf) < 0)
return GPGME_File_Error;
return gpgme_data_new_from_filepart (dh, fname, NULL, 0, statbuf.st_size);
}
static int
gpgme_error_to_errno (GpgmeError err)
{
switch (err)
{
case GPGME_EOF:
return 0;
case GPGME_Out_Of_Core:
errno = ENOMEM;
return -1;
case GPGME_Invalid_Value:
errno = EINVAL;
return -1;
case GPGME_Not_Implemented:
errno = EOPNOTSUPP;
return -1;
default:
/* XXX Yeah, well. */
errno = EINVAL;
return -1;
}
}
static ssize_t
old_user_read (GpgmeData dh, void *buffer, size_t size)
{
size_t amt;
GpgmeError err = (*dh->data.old_user.cb) (dh->data.old_user.handle,
buffer, size, &amt);
if (err)
return gpgme_error_to_errno (err);
return amt;
}
static off_t
old_user_seek (GpgmeData dh, off_t offset, int whence)
{
GpgmeError err;
if (whence != SEEK_SET || offset)
return EINVAL;
err = (*dh->data.old_user.cb) (dh->data.old_user.handle, NULL, 0, NULL);
if (err)
return gpgme_error_to_errno (err);
return 0;
}
static struct gpgme_data_cbs old_user_cbs =
{
old_user_read,
NULL,
old_user_seek,
NULL
};
/* Create a new data buffer which retrieves the data from the callback
function READ_CB. */
GpgmeError
gpgme_data_new_with_read_cb (GpgmeData *dh,
int (*read_cb) (void *, char *, size_t, size_t *),
void *read_cb_value)
{
GpgmeError err = _gpgme_data_new (dh, &old_user_cbs);
if (err)
return err;
(*dh)->data.old_user.cb = read_cb;
(*dh)->data.old_user.handle = read_cb_value;
return 0;
}
GpgmeError
gpgme_data_rewind (GpgmeData dh)
{
return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
? GPGME_File_Error : 0;
}