2003-06-06  Marcus Brinkmann  <marcus@g10code.de>

	* gpgme.texi: Change error codes to GPG_ERR_* variants.
	(Error Handling): Rewritten.

gpgme/
2003-06-05  Marcus Brinkmann  <marcus@g10code.de>

	Everywhere: Use libgpg-error error codes.

	* Makefile.am (EXTRA_DIST): Remove mkerrors.
	(BUILT_SOURCES): Remove errors.c.
	(MOSTLYCLEANFILES): Likewise.
	(libgpgme_la_SOURCES): Likewise.  Add error.c.
	(errors.c): Remove target.
	* mkerrors: File removed.
	* error.c: New file.

	* gpgme.h (gpgme_error_t): Change to type gpg_error_t.
	(gpgme_err_code_t, gpgme_err_source_t): New types.
	(gpgme_err_code, gpgme_err_source, gpgme_error, gpgme_err_make):
	New static inline functions.
	(gpgme_strsource, gpgme_err_code_from_errno,
	gpgme_err_code_to_errno, gpgme_err_make_from_errno,
	gpgme_error_from_errno): New prototypes.

tests/
2003-06-06  Marcus Brinkmann  <marcus@g10code.de>

	Everywhere: Use libgpg-error error codes.

	* gpg/Makefile.am (noinst_HEADERS): New variable.
	* gpg/t-support.h: New file.
	* gpgsm/Makefile.am (noinst_HEADERS): New variable.
	* gpgsm/t-support.h: New file.
This commit is contained in:
Marcus Brinkmann 2003-06-05 23:20:29 +00:00
parent 8f8c78d534
commit 02536bb72b
69 changed files with 1621 additions and 1721 deletions

View File

@ -1,3 +1,8 @@
2003-06-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Check for libgpg-error. Define
GPG_ERR_SOURCE_DEFAULT.
2003-05-26 Marcus Brinkmann <marcus@g10code.de> 2003-05-26 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (NEED_GPG_VERSION): Bump up to 1.2.2. * configure.ac (NEED_GPG_VERSION): Bump up to 1.2.2.

71
NEWS
View File

@ -18,6 +18,13 @@ Noteworthy changes in version 0.4.1 (unreleased)
afterwards by calling one of the result functions. This unifies the afterwards by calling one of the result functions. This unifies the
synchronous and the asynchronous interface. synchronous and the asynchronous interface.
The error values have been completely replaced by a more
sophisticated model that allows GPGME to transparently and accurately
report all errors from the other GnuPG components, irregardless of
process boundaries. This is achieved by using the library
libgpg-errors, which is shared by all GnuPG components. This library
is now required for GPGME.
The results of all operations are now provided by pointers to C The results of all operations are now provided by pointers to C
structs rather than by XML structs or in other ways. structs rather than by XML structs or in other ways.
@ -26,20 +33,19 @@ Noteworthy changes in version 0.4.1 (unreleased)
Backward compatibility is provided where it was possible without too Backward compatibility is provided where it was possible without too
much effort and did not collide with the overall sanitization effort. much effort and did not collide with the overall sanitization effort.
However, it is recommended to update to the new interfaces soon, so However, this is only for ease of transition. NO DEPRECATED FUNCTION
the compatibility interfaces can be phased out quickly. OR DATA TYPE IS CONSIDERED A PART OF THE API OR ABI AND WILL BE
Recommendations how to replace deprecated or removed functionality can DROPPED IN THE FUTURE WITHOUT CHANGING THE SONAME OF THE LIBRARY.
be found within the description of each change. Recommendations how to replace deprecated or removed functionality
can be found within the description of each change.
What follows are all changes to the interface and behaviour of GPGME What follows are all changes to the interface and behaviour of GPGME
in detail. in detail.
* If gpgme.h is included in sources compiled by GCC 3.1 or later, * If gpgme.h is included in sources compiled by GCC 3.1 or later,
deprecated attributes will warn about use of obsolete functions and deprecated attributes will warn about use of obsolete functions and
typedefs. The use of obsolete error values will appear as the use type definitions. You can suppress these warnings by passing
of an obsolete type _gpgme_deprecated_error_t. You can suppress -Wno-deprecated-declarations to the gcc command.
these warnings by passing -Wno-deprecated-declarations to the gcc
command.
* The following types have been renamed. The old types are still * The following types have been renamed. The old types are still
available as aliases, but they are deprecated now: available as aliases, but they are deprecated now:
@ -70,6 +76,17 @@ Noteworthy changes in version 0.4.1 (unreleased)
GpgmeTrustItem gpgme_trust_item_t GpgmeTrustItem gpgme_trust_item_t
GpgmeStatusCode gpgme_status_code_t GpgmeStatusCode gpgme_status_code_t
* gpgme_error_t is now identical to gpg_error_t, the error type
provided by libgpg-error. More about using libgpg-error with GPGME
can be found in the manual. All error symbols have been removed!
* All functions and types in libgpg-error have been wrapped in GPGME.
The new types are gpgme_err_code_t and gpgme_err_source_t. The new
functions are gpgme_err_code, gpgme_err_source, gpgme_error,
gpgme_err_make, gpgme_error_from_errno, gpgme_err_make_from_errno,
gpgme_err_code_from_errno, gpgme_err_code_to_errno,
gpgme_strsource.
* GPGME_ATTR_IS_SECRET is not anymore representable as a string. * GPGME_ATTR_IS_SECRET is not anymore representable as a string.
* GnuPG 1.2.2 is required. The progress callback is now also invoked * GnuPG 1.2.2 is required. The progress callback is now also invoked
@ -89,7 +106,7 @@ Noteworthy changes in version 0.4.1 (unreleased)
The return type has been changed to gpgme_error_t value. This The return type has been changed to gpgme_error_t value. This
allowed to remove the gpgme_cancel function; just return allowed to remove the gpgme_cancel function; just return
GPGME_Canceled in the passphrase callback directly. the error code GPG_ERR_CANCELED in the passphrase callback directly.
* gpgme_edit_cb_t has been changed to take a file descriptor argument. * gpgme_edit_cb_t has been changed to take a file descriptor argument.
The user is expected to write the response to the file descriptor, The user is expected to write the response to the file descriptor,
@ -145,13 +162,10 @@ Noteworthy changes in version 0.4.1 (unreleased)
* The new function gpgme_get_protocol_name can be used to convert a * The new function gpgme_get_protocol_name can be used to convert a
gpgme_protocol_t value into a string. gpgme_protocol_t value into a string.
* The status of a context operation is not checked anymore, so the * The status of a context operation is not checked anymore. Starting
errors GPGME_Busy and GPGME_No_Request can not occur anymore. a new operation will silently cancel the previous one. Calling a
function that requires you to have started an operation before without
* For clarity and better reusability, the error codes doing so is undefined.
GPGME_No_Recipients, GPGME_Invalid_Recipient and
GPGME_No_Passphrase have been renamed to GPGME_No_UserID,
GPGME_Invalid_UserID and GPGME_Bad_Passphrase resp.
* The FPR argument to gpgme_op_genkey was removed. Instead, use the * The FPR argument to gpgme_op_genkey was removed. Instead, use the
gpgme_op_genkey_result function to retrieve a gpgme_genkey_result_t gpgme_op_genkey_result function to retrieve a gpgme_genkey_result_t
@ -227,8 +241,7 @@ Noteworthy changes in version 0.4.1 (unreleased)
interface, the generic gpgme_get_op_info interface is not useful interface, the generic gpgme_get_op_info interface is not useful
anymore and dropped. anymore and dropped.
* The error values GPGME_Invalid_Type and GPGME_Invalid_Mode can not * The type and mode of data objects is not available anymore.
occur anymore and are thus deprecated.
* Interface changes relative to the 0.4.0 release: * Interface changes relative to the 0.4.0 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -283,6 +296,18 @@ gpgme_data_release_cb_t NEW
gpgme_data_cbs_t NEW gpgme_data_cbs_t NEW
gpgme_trust_item_t NEW gpgme_trust_item_t NEW
gpgme_status_code_t NEW gpgme_status_code_t NEW
GPGME_{some error code} REMOVED! Use GPG_ERR_* from libgpg-error.
gpgme_err_code_t NEW
gpgme_err_source_t NEW
gpgme_err_code NEW
gpgme_err_source NEW
gpgme_error NEW
gpgme_err_make NEW
gpgme_error_from_errno NEW
gpgme_err_make_from_errno NEW
gpgme_err_code_from_errno NEW
gpgme_err_code_to_errno NEW
gpgme_strsource NEW
gpgme_io_cb_t CHANGED: Return type from void to GpgmeError. gpgme_io_cb_t CHANGED: Return type from void to GpgmeError.
gpgme_event_io_t CHANGED: New event type (all numbers changed). gpgme_event_io_t CHANGED: New event type (all numbers changed).
gpgme_passphrase_cb_t CHANGED: Desc decomposed, write directly to FD. gpgme_passphrase_cb_t CHANGED: Desc decomposed, write directly to FD.
@ -318,14 +343,6 @@ gpgme_engine_info_t NEW
gpgme_get_engine_info CHANGED: Return info structure instead XML. gpgme_get_engine_info CHANGED: Return info structure instead XML.
gpgme_get_protocol_name NEW gpgme_get_protocol_name NEW
gpgme_cancel REMOVED: Return error in callback directly. gpgme_cancel REMOVED: Return error in callback directly.
GPGME_Busy DEPRECATED: Not in use.
GPGME_No_Request DEPRECATED: Not in use.
GPGME_No_Recipients DEPRECATED: Use GPGME_No_UserID.
GPGME_No_UserID NEW
GPGME_Invalid_Recipient DEPRECATED: Use GPGME_Invalid_UserID.
GPGME_Invalid_UserID NEW
GPGME_No_Passphrase DEPRECATED: Use GPGME_Bad_Passphrase.
GPGME_Bad_Passphrase NEW
gpgme_op_genkey CHANGED: FPR argument dropped. gpgme_op_genkey CHANGED: FPR argument dropped.
gpgme_op_genkey_result NEW gpgme_op_genkey_result NEW
gpgme_genkey_result_t NEW gpgme_genkey_result_t NEW
@ -372,8 +389,6 @@ gpgme_key_get_as_xml REMOVED
gpgme_key_list_result_t NEW gpgme_key_list_result_t NEW
gpgme_op_keylist_result NEW gpgme_op_keylist_result NEW
gpgme_get_op_info REMOVED gpgme_get_op_info REMOVED
GPGME_Invalid_Type DEPRECATED
GPGME_Invalid_Mode DEPRECATED
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Noteworthy changes in version 0.4.0 (2002-12-23) Noteworthy changes in version 0.4.0 (2002-12-23)

11
TODO
View File

@ -1,7 +1,13 @@
Hey Emacs, this is -*- outline -*- mode! Hey Emacs, this is -*- outline -*- mode!
* Before release:
** Change gpgme_invalid_user_id_t to gpgme_invalid_key_t.
** Remove arg_error from rungpg.c
** Make sure that notation value allocation has no leak at error
** Make sure POSIX I/O functions set errno properly
** gpgme-config must include info about libgpg-error.
* ABI's to break: * ABI's to break:
** Use libgpg-error.
** Compatibility interfaces that can be removed in future versions: ** Compatibility interfaces that can be removed in future versions:
*** gpgme_data_new_from_filepart *** gpgme_data_new_from_filepart
*** gpgme_data_new_from_file *** gpgme_data_new_from_file
@ -91,7 +97,8 @@ Hey Emacs, this is -*- outline -*- mode!
* Error Values * Error Values
** Map ASSUAN/GpgSM ERR error values in a better way than is done now. !! ** Map ASSUAN/GpgSM ERR error values in a better way than is done now. !!
** Verify (and document) if Read_Error, Write_Error, Pipe_Error set errno. ** Some error values should identify the source more correctly (mostly error
values derived from status messages).
* Tests * Tests
** Write a fake gpg-agent so that we can supply known passphrases to ** Write a fake gpg-agent so that we can supply known passphrases to

View File

@ -164,14 +164,13 @@ if test "$ac_cv_func_vasprintf" != yes; then
GNUPG_CHECK_VA_COPY GNUPG_CHECK_VA_COPY
fi fi
# Note: fopencokie is only a dummy stub and not used. # Note: fopencokie is only a dummy stub and not used.
# However some code in assuan/ links against it. # However some code in assuan/ links against it.
AC_REPLACE_FUNCS(fopencookie) AC_REPLACE_FUNCS(fopencookie)
AC_CHECK_LIB(gpg-error, strerror)
AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME,
[The default error source for GPGME.])
dnl dnl
dnl Checks for system services dnl Checks for system services
dnl dnl

View File

@ -1,3 +1,8 @@
2003-06-06 Marcus Brinkmann <marcus@g10code.de>
* gpgme.texi: Change error codes to GPG_ERR_* variants.
(Error Handling): Rewritten.
2003-05-29 Marcus Brinkmann <marcus@g10code.de> 2003-05-29 Marcus Brinkmann <marcus@g10code.de>
* gpgme.texi (Exporting Keys): Change and document prototypes. * gpgme.texi (Exporting Keys): Change and document prototypes.

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,23 @@
2003-06-05 Marcus Brinkmann <marcus@g10code.de>
Everywhere: Use libgpg-error error codes.
* Makefile.am (EXTRA_DIST): Remove mkerrors.
(BUILT_SOURCES): Remove errors.c.
(MOSTLYCLEANFILES): Likewise.
(libgpgme_la_SOURCES): Likewise. Add error.c.
(errors.c): Remove target.
* mkerrors: File removed.
* error.c: New file.
* gpgme.h (gpgme_error_t): Change to type gpg_error_t.
(gpgme_err_code_t, gpgme_err_source_t): New types.
(gpgme_err_code, gpgme_err_source, gpgme_error, gpgme_err_make):
New static inline functions.
(gpgme_strsource, gpgme_err_code_from_errno,
gpgme_err_code_to_errno, gpgme_err_make_from_errno,
gpgme_error_from_errno): New prototypes.
2003-05-29 Marcus Brinkmann <marcus@g10code.de> 2003-05-29 Marcus Brinkmann <marcus@g10code.de>
* gpgme.h (gpgme_op_export_start): Change second arg to const char *. * gpgme.h (gpgme_op_export_start): Change second arg to const char *.

View File

@ -19,9 +19,9 @@
## Process this file with automake to produce Makefile.in ## Process this file with automake to produce Makefile.in
EXTRA_DIST = gpgme-config.in gpgme.m4 mkerrors mkstatus libgpgme.vers EXTRA_DIST = gpgme-config.in gpgme.m4 mkstatus libgpgme.vers
BUILT_SOURCES = errors.c status-table.h BUILT_SOURCES = status-table.h
MOSTLYCLEANFILES = errors.c status-table.h MOSTLYCLEANFILES = status-table.h
bin_SCRIPTS = gpgme-config bin_SCRIPTS = gpgme-config
m4datadir = $(datadir)/aclocal m4datadir = $(datadir)/aclocal
m4data_DATA = gpgme.m4 m4data_DATA = gpgme.m4
@ -81,16 +81,12 @@ libgpgme_la_SOURCES = \
import.c export.c genkey.c delete.c edit.c \ import.c export.c genkey.c delete.c edit.c \
engine.h engine-backend.h engine.c rungpg.c status-table.h \ engine.h engine-backend.h engine.c rungpg.c status-table.h \
${gpgsm_components} sema.h io.h ${system_components} \ ${gpgsm_components} sema.h io.h ${system_components} \
debug.c debug.h gpgme.c version.c errors.c debug.c debug.h gpgme.c version.c error.c
libgpgme_la_DEPENDENCIES = ${assuan_libobjs} @LTLIBOBJS@ \ libgpgme_la_DEPENDENCIES = ${assuan_libobjs} @LTLIBOBJS@ \
$(srcdir)/libgpgme.vers $(srcdir)/libgpgme.vers
libgpgme_la_LIBADD = ${assuan_libobjs} @LTLIBOBJS@ libgpgme_la_LIBADD = ${assuan_libobjs} @LTLIBOBJS@
errors.c : gpgme.h
$(srcdir)/mkerrors < $(srcdir)/gpgme.h > errors.c
status-table.h : gpgme.h status-table.h : gpgme.h
$(srcdir)/mkstatus < $(srcdir)/gpgme.h > status-table.h $(srcdir)/mkstatus < $(srcdir)/gpgme.h > status-table.h

View File

@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "util.h" #include "util.h"
@ -72,7 +73,7 @@ _gpgme_decode_c_string (const char *src, char **destp, int len)
if (len) if (len)
{ {
if (len < strlen (src) + 1) if (len < strlen (src) + 1)
return GPGME_General_Error; return gpg_error (GPG_ERR_INTERNAL);
dest = *destp; dest = *destp;
} }
@ -82,7 +83,7 @@ _gpgme_decode_c_string (const char *src, char **destp, int len)
string. */ string. */
dest = malloc (strlen (src) + 1); dest = malloc (strlen (src) + 1);
if (!dest) if (!dest)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
*destp = dest; *destp = dest;
} }
@ -175,7 +176,7 @@ _gpgme_decode_percent_string (const char *src, char **destp, int len)
if (len) if (len)
{ {
if (len < strlen (src) + 1) if (len < strlen (src) + 1)
return GPGME_General_Error; return gpg_error (GPG_ERR_INTERNAL);
dest = *destp; dest = *destp;
} }
@ -185,7 +186,7 @@ _gpgme_decode_percent_string (const char *src, char **destp, int len)
string. */ string. */
dest = malloc (strlen (src) + 1); dest = malloc (strlen (src) + 1);
if (!dest) if (!dest)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
*destp = dest; *destp = dest;
} }
@ -238,84 +239,84 @@ static struct
gpgme_error_t err; gpgme_error_t err;
} gnupg_errors[] = } gnupg_errors[] =
{ {
{ "EOF", GPGME_EOF }, { "EOF", GPG_ERR_EOF },
{ "No_Error", GPGME_No_Error }, { "No_Error", GPG_ERR_NO_ERROR },
{ "General_Error", GPGME_General_Error }, { "General_Error", GPG_ERR_GENERAL },
{ "Out_Of_Core", GPGME_Out_Of_Core }, { "Out_Of_Core", GPG_ERR_ENOMEM },
{ "Invalid_Value", GPGME_Invalid_Value }, { "Invalid_Value", GPG_ERR_INV_VALUE },
{ "IO_Error", GPGME_General_Error }, { "IO_Error", GPG_ERR_GENERAL },
{ "Resource_Limit", GPGME_General_Error }, { "Resource_Limit", GPG_ERR_RESOURCE_LIMIT },
{ "Internal_Error", GPGME_General_Error }, { "Internal_Error", GPG_ERR_INTERNAL },
{ "Bad_Certificate", GPGME_Invalid_Key }, { "Bad_Certificate", GPG_ERR_BAD_CERT },
{ "Bad_Certificate_Chain", GPGME_General_Error }, { "Bad_Certificate_Chain", GPG_ERR_BAD_CERT_CHAIN},
{ "Missing_Certificate", GPGME_No_Public_Key }, { "Missing_Certificate", GPG_ERR_MISSING_CERT },
{ "No_Data", GPGME_No_Data }, { "No_Data", GPG_ERR_NO_DATA },
{ "Bad_Signature", GPGME_Bad_Signature }, { "Bad_Signature", GPG_ERR_BAD_SIGNATURE },
{ "Not_Implemented", GPGME_Not_Implemented }, { "Not_Implemented", GPG_ERR_NOT_IMPLEMENTED },
{ "Conflict", GPGME_Conflict }, { "Conflict", GPG_ERR_CONFLICT },
{ "Bug", GPGME_General_Error }, { "Bug", GPG_ERR_BUG },
{ "Read_Error", GPGME_General_Error }, { "Read_Error", GPG_ERR_GENERAL },
{ "Write_Error", GPGME_General_Error }, { "Write_Error", GPG_ERR_GENERAL },
{ "Invalid_Line", GPGME_General_Error }, { "Invalid_Line", GPG_ERR_GENERAL },
{ "Incomplete_Line", GPGME_General_Error }, { "Incomplete_Line", GPG_ERR_INCOMPLETE_LINE },
{ "Invalid_Response", GPGME_General_Error }, { "Invalid_Response", GPG_ERR_INV_RESPONSE },
{ "Agent_Error", GPGME_General_Error }, { "Agent_Error", GPG_ERR_AGENT },
{ "No_Public_Key", GPGME_No_Public_Key }, { "No_Public_Key", GPG_ERR_NO_PUBKEY },
{ "No_Secret_Key", GPGME_No_Secret_Key }, { "No_Secret_Key", GPG_ERR_NO_SECKEY },
{ "File_Open_Error", GPGME_General_Error }, { "File_Open_Error", GPG_ERR_GENERAL },
{ "File_Create_Error", GPGME_General_Error }, { "File_Create_Error", GPG_ERR_GENERAL },
{ "File_Error", GPGME_General_Error }, { "File_Error", GPG_ERR_GENERAL },
{ "Not_Supported", GPGME_General_Error }, { "Not_Supported", GPG_ERR_NOT_SUPPORTED },
{ "Invalid_Data", GPGME_General_Error }, { "Invalid_Data", GPG_ERR_INV_DATA },
{ "Assuan_Server_Fault", GPGME_General_Error }, { "Assuan_Server_Fault", GPG_ERR_ASSUAN_SERVER_FAULT },
{ "Assuan_Error", GPGME_General_Error }, { "Assuan_Error", GPG_ERR_ASSUAN },
{ "Invalid_Session_Key", GPGME_General_Error }, { "Invalid_Session_Key", GPG_ERR_INV_SESSION_KEY },
{ "Invalid_Sexp", GPGME_General_Error }, { "Invalid_Sexp", GPG_ERR_INV_SEXP },
{ "Unsupported_Algorithm", GPGME_Unsupported_Algorithm }, { "Unsupported_Algorithm", GPG_ERR_UNSUPPORTED_ALGORITHM },
{ "No_PIN_Entry", GPGME_Invalid_Engine }, { "No_PIN_Entry", GPG_ERR_NO_PIN_ENTRY },
{ "PIN_Entry_Error", GPGME_Invalid_Engine }, { "PIN_Entry_Error", GPG_ERR_NO_PIN_ENTRY },
{ "Bad_PIN", GPGME_Bad_Passphrase }, { "Bad_PIN", GPG_ERR_BAD_PIN },
{ "Bad_Passphrase", GPGME_Bad_Passphrase }, { "Bad_Passphrase", GPG_ERR_BAD_PASSPHRASE },
{ "Invalid_Name", GPGME_General_Error }, { "Invalid_Name", GPG_ERR_INV_NAME },
{ "Bad_Public_Key", GPGME_General_Error }, { "Bad_Public_Key", GPG_ERR_BAD_PUBKEY },
{ "Bad_Secret_Key", GPGME_General_Error }, { "Bad_Secret_Key", GPG_ERR_BAD_SECKEY },
{ "Bad_Data", GPGME_General_Error }, { "Bad_Data", GPG_ERR_BAD_DATA },
{ "Invalid_Parameter", GPGME_General_Error }, { "Invalid_Parameter", GPG_ERR_INV_PARAMETER },
{ "Tribute_to_D_A", GPGME_General_Error }, { "Tribute_to_D_A", GPG_ERR_TRIBUTE_TO_D_A },
{ "No_Dirmngr", GPGME_Invalid_Engine }, { "No_Dirmngr", GPG_ERR_NO_DIRMNGR },
{ "Dirmngr_Error", GPGME_General_Error }, { "Dirmngr_Error", GPG_ERR_DIRMNGR },
{ "Certificate_Revoked", GPGME_Key_Revoked }, { "Certificate_Revoked", GPG_ERR_CERT_REVOKED },
{ "No_CRL_Known", GPGME_No_CRL_Known }, { "No_CRL_Known", GPG_ERR_NO_CRL_KNOWN },
{ "CRL_Too_Old", GPGME_CRL_Too_Old }, { "CRL_Too_Old", GPG_ERR_CRL_TOO_OLD },
{ "Line_Too_Long", GPGME_General_Error }, { "Line_Too_Long", GPG_ERR_LINE_TOO_LONG },
{ "Not_Trusted", GPGME_Key_Not_Trusted }, { "Not_Trusted", GPG_ERR_NOT_TRUSTED },
{ "Canceled", GPGME_Canceled }, { "Canceled", GPG_ERR_CANCELED },
{ "Bad_CA_Certificate", GPGME_General_Error }, { "Bad_CA_Certificate", GPG_ERR_BAD_CA_CERT },
{ "Certificate_Expired", GPGME_Key_Expired }, { "Certificate_Expired", GPG_ERR_CERT_EXPIRED },
{ "Certificate_Too_Young", GPGME_Invalid_Key }, { "Certificate_Too_Young", GPG_ERR_CERT_TOO_YOUNG },
{ "Unsupported_Certificate", GPGME_General_Error }, { "Unsupported_Certificate", GPG_ERR_UNSUPPORTED_CERT },
{ "Unknown_Sexp", GPGME_General_Error }, { "Unknown_Sexp", GPG_ERR_UNKNOWN_SEXP },
{ "Unsupported_Protection", GPGME_General_Error }, { "Unsupported_Protection", GPG_ERR_UNSUPPORTED_PROTECTION },
{ "Corrupted_Protection", GPGME_General_Error }, { "Corrupted_Protection", GPG_ERR_CORRUPTED_PROTECTION },
{ "Ambiguous_Name", GPGME_Ambiguous_Specification }, { "Ambiguous_Name", GPG_ERR_AMBIGUOUS_NAME },
{ "Card_Error", GPGME_General_Error }, { "Card_Error", GPG_ERR_CARD },
{ "Card_Reset", GPGME_General_Error }, { "Card_Reset", GPG_ERR_CARD_RESET },
{ "Card_Removed", GPGME_General_Error }, { "Card_Removed", GPG_ERR_CARD_REMOVED },
{ "Invalid_Card", GPGME_General_Error }, { "Invalid_Card", GPG_ERR_INV_CARD },
{ "Card_Not_Present", GPGME_General_Error }, { "Card_Not_Present", GPG_ERR_CARD_NOT_PRESENT },
{ "No_PKCS15_App", GPGME_General_Error }, { "No_PKCS15_App", GPG_ERR_NO_PKCS15_APP },
{ "Not_Confirmed", GPGME_General_Error }, { "Not_Confirmed", GPG_ERR_NOT_CONFIRMED },
{ "Configuration_Error", GPGME_General_Error }, { "Configuration_Error", GPG_ERR_CONFIGURATION },
{ "No_Policy_Match", GPGME_Policy_Mismatch }, { "No_Policy_Match", GPG_ERR_NO_POLICY_MATCH },
{ "Invalid_Index", GPGME_General_Error }, { "Invalid_Index", GPG_ERR_INV_INDEX },
{ "Invalid_Id", GPGME_General_Error }, { "Invalid_Id", GPG_ERR_INV_ID },
{ "No_Scdaemon", GPGME_Invalid_Engine }, { "No_Scdaemon", GPG_ERR_NO_SCDAEMON },
{ "Scdaemon_Error", GPGME_General_Error }, { "Scdaemon_Error", GPG_ERR_SCDAEMON },
{ "Unsupported_Protocol", GPGME_General_Error }, { "Unsupported_Protocol", GPG_ERR_UNSUPPORTED_PROTOCOL },
{ "Bad_PIN_Method", GPGME_General_Error }, { "Bad_PIN_Method", GPG_ERR_BAD_PIN_METHOD },
{ "Card_Not_Initialized", GPGME_General_Error }, { "Card_Not_Initialized", GPG_ERR_CARD_NOT_INITIALIZED },
{ "Unsupported_Operation", GPGME_General_Error }, { "Unsupported_Operation", GPG_ERR_UNSUPPORTED_OPERATION },
{ "Wrong_Key_Usage", GPGME_Wrong_Key_Usage } { "Wrong_Key_Usage", GPG_ERR_WRONG_KEY_USAGE }
}; };
@ -326,7 +327,7 @@ _gpgme_map_gnupg_error (char *err)
for (i = 0; i < DIM (gnupg_errors); i++) for (i = 0; i < DIM (gnupg_errors); i++)
if (!strcmp (gnupg_errors[i].name, err)) if (!strcmp (gnupg_errors[i].name, err))
return gnupg_errors[i].err; return gpg_err_make (GPG_ERR_SOURCE_GPG, gnupg_errors[i].err);
return GPGME_General_Error; return gpg_err_make (GPG_ERR_SOURCE_GPG, GPG_ERR_GENERAL);
} }

View File

@ -1,5 +1,5 @@
/* data-compat.c - Compatibility interfaces for data objects. /* data-compat.c - Compatibility interfaces for data objects.
Copyright (C) 2002 g10 Code GmbH Copyright (C) 2002, 2003 g10 Code GmbH
This file is part of GPGME. This file is part of GPGME.
@ -40,27 +40,40 @@ gpgme_data_new_from_filepart (gpgme_data_t *dh, const char *fname,
char *buf = NULL; char *buf = NULL;
if (stream && fname) if (stream && fname)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (fname) if (fname)
stream = fopen (fname, "rb"); stream = fopen (fname, "rb");
if (!stream) if (!stream)
return GPGME_File_Error; return gpg_error_from_errno (errno);
if (fseek (stream, offset, SEEK_SET)) if (fseek (stream, offset, SEEK_SET))
goto ferr; {
int saved_errno = errno;
if (fname)
fclose (stream);
return gpg_error_from_errno (saved_errno);
}
buf = malloc (length); buf = malloc (length);
if (!buf) if (!buf)
goto ferr; {
int saved_errno = errno;
if (fname)
fclose (stream);
return gpg_error_from_errno (saved_errno);
}
while (fread (buf, length, 1, stream) < 1 while (fread (buf, length, 1, stream) < 1
&& ferror (stream) && errno == EINTR); && ferror (stream) && errno == EINTR);
if (ferror (stream)) if (ferror (stream))
{ {
int saved_errno = errno;
if (buf) if (buf)
free (buf); free (buf);
goto ferr; if (fname)
fclose (stream);
return gpg_error_from_errno (saved_errno);
} }
if (fname) if (fname)
@ -78,15 +91,6 @@ gpgme_data_new_from_filepart (gpgme_data_t *dh, const char *fname,
(*dh)->data.mem.size = length; (*dh)->data.mem.size = length;
(*dh)->data.mem.length = length; (*dh)->data.mem.length = length;
return 0; return 0;
ferr:
{
int saved_errno = errno;
if (fname)
fclose (stream);
errno = saved_errno;
return GPGME_File_Error;
}
} }
@ -98,10 +102,10 @@ gpgme_data_new_from_file (gpgme_data_t *dh, const char *fname, int copy)
struct stat statbuf; struct stat statbuf;
if (!fname || !copy) if (!fname || !copy)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (stat (fname, &statbuf) < 0) if (stat (fname, &statbuf) < 0)
return GPGME_File_Error; return gpg_error_from_errno (errno);
return gpgme_data_new_from_filepart (dh, fname, NULL, 0, statbuf.st_size); return gpgme_data_new_from_filepart (dh, fname, NULL, 0, statbuf.st_size);
} }
@ -110,26 +114,32 @@ gpgme_data_new_from_file (gpgme_data_t *dh, const char *fname, int copy)
static int static int
gpgme_error_to_errno (gpgme_error_t err) gpgme_error_to_errno (gpgme_error_t err)
{ {
switch (err) int no = gpg_err_code_to_errno (err);
if (no)
{ {
case GPGME_EOF: errno = no;
return 0;
case GPGME_Out_Of_Core:
errno = ENOMEM;
return -1; return -1;
case GPGME_Invalid_Value: }
switch (gpg_err_code (err))
{
case GPG_ERR_EOF:
return 0;
case GPG_ERR_INV_VALUE:
errno = EINVAL; errno = EINVAL;
return -1; return -1;
case GPGME_Not_Implemented: case GPG_ERR_NOT_SUPPORTED:
errno = EOPNOTSUPP; errno = EOPNOTSUPP;
return -1; return -1;
default: default:
/* XXX Yeah, well. */ /* FIXME: Yeah, well. */
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
} }
static ssize_t static ssize_t
old_user_read (gpgme_data_t dh, void *buffer, size_t size) old_user_read (gpgme_data_t dh, void *buffer, size_t size)
{ {
@ -185,5 +195,5 @@ gpgme_error_t
gpgme_data_rewind (gpgme_data_t dh) gpgme_data_rewind (gpgme_data_t dh)
{ {
return (gpgme_data_seek (dh, 0, SEEK_SET) == -1) return (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
? GPGME_File_Error : 0; ? gpg_error_from_errno (errno) : 0;
} }

View File

@ -39,12 +39,12 @@ _gpgme_data_new (gpgme_data_t *r_dh, struct _gpgme_data_cbs *cbs)
gpgme_data_t dh; gpgme_data_t dh;
if (!r_dh) if (!r_dh)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
*r_dh = NULL; *r_dh = NULL;
dh = calloc (1, sizeof (*dh)); dh = calloc (1, sizeof (*dh));
if (!dh) if (!dh)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
dh->cbs = cbs; dh->cbs = cbs;
@ -149,9 +149,9 @@ gpgme_error_t
gpgme_data_set_encoding (gpgme_data_t dh, gpgme_data_encoding_t enc) gpgme_data_set_encoding (gpgme_data_t dh, gpgme_data_encoding_t enc)
{ {
if (!dh) if (!dh)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (enc < 0 || enc > GPGME_DATA_ENCODING_ARMOR) if (enc < 0 || enc > GPGME_DATA_ENCODING_ARMOR)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
dh->encoding = enc; dh->encoding = enc;
return 0; return 0;
} }
@ -169,7 +169,7 @@ _gpgme_data_inbound_handler (void *opaque, int fd)
buflen = read (fd, buffer, BUFFER_SIZE); buflen = read (fd, buffer, BUFFER_SIZE);
if (buflen < 0) if (buflen < 0)
return GPGME_File_Error; return gpg_error_from_errno (errno);
if (buflen == 0) if (buflen == 0)
{ {
_gpgme_io_close (fd); _gpgme_io_close (fd);
@ -180,7 +180,7 @@ _gpgme_data_inbound_handler (void *opaque, int fd)
{ {
ssize_t amt = gpgme_data_write (dh, bufp, buflen); ssize_t amt = gpgme_data_write (dh, bufp, buflen);
if (amt == 0 || (amt < 0 && errno != EINTR)) if (amt == 0 || (amt < 0 && errno != EINTR))
return GPGME_File_Error; return gpg_error_from_errno (errno);
bufp += amt; bufp += amt;
buflen -= amt; buflen -= amt;
} }
@ -199,7 +199,7 @@ _gpgme_data_outbound_handler (void *opaque, int fd)
{ {
ssize_t amt = gpgme_data_read (dh, dh->pending, BUFFER_SIZE); ssize_t amt = gpgme_data_read (dh, dh->pending, BUFFER_SIZE);
if (amt < 0) if (amt < 0)
return GPGME_File_Error; return gpg_error_from_errno (errno);
if (amt == 0) if (amt == 0)
{ {
_gpgme_io_close (fd); _gpgme_io_close (fd);
@ -213,7 +213,7 @@ _gpgme_data_outbound_handler (void *opaque, int fd)
return 0; return 0;
if (nwritten <= 0) if (nwritten <= 0)
return GPGME_File_Error; return gpg_error_from_errno (errno);
if (nwritten < dh->pending_len) if (nwritten < dh->pending_len)
memmove (dh->pending, dh->pending + nwritten, dh->pending_len - nwritten); memmove (dh->pending, dh->pending + nwritten, dh->pending_len - nwritten);

View File

@ -55,9 +55,9 @@ decrypt_verify_start (gpgme_ctx_t ctx, int synchronous,
return err; return err;
if (!cipher) if (!cipher)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
if (!plain) if (!plain)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (ctx->passphrase_cb) if (ctx->passphrase_cb)
{ {

View File

@ -23,6 +23,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "util.h" #include "util.h"
@ -86,10 +87,12 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
switch (code) switch (code)
{ {
case GPGME_STATUS_EOF: case GPGME_STATUS_EOF:
/* FIXME: These error values should probably be attributed to
the underlying crypto engine (as error source). */
if (opd->failed) if (opd->failed)
return GPGME_Decryption_Failed; return gpg_error (GPG_ERR_DECRYPT_FAILED);
else if (!opd->okay) else if (!opd->okay)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
break; break;
case GPGME_STATUS_DECRYPTION_OKAY: case GPGME_STATUS_DECRYPTION_OKAY:
@ -126,7 +129,7 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
{ {
opd->result.unsupported_algorithm = strdup (args); opd->result.unsupported_algorithm = strdup (args);
if (!opd->result.unsupported_algorithm) if (!opd->result.unsupported_algorithm)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
} }
} }
@ -175,9 +178,9 @@ decrypt_start (gpgme_ctx_t ctx, int synchronous,
return err; return err;
if (!cipher) if (!cipher)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
if (!plain) if (!plain)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (err) if (err)
return err; return err;

View File

@ -46,7 +46,7 @@ delete_status_handler (void *priv, gpgme_status_code_t code, char *args)
errno = 0; errno = 0;
problem = strtol (args, &tail, 0); problem = strtol (args, &tail, 0);
if (errno || (*tail && *tail != ' ')) if (errno || (*tail && *tail != ' '))
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
switch (problem) switch (problem)
{ {
@ -54,16 +54,16 @@ delete_status_handler (void *priv, gpgme_status_code_t code, char *args)
break; break;
case DELETE_No_Such_Key: case DELETE_No_Such_Key:
return GPGME_Invalid_Key; return gpg_error (GPG_ERR_NO_PUBKEY);
case DELETE_Must_Delete_Secret_Key: case DELETE_Must_Delete_Secret_Key:
return GPGME_Conflict; return gpg_error (GPG_ERR_CONFLICT);
case DELETE_Ambiguous_Specification: case DELETE_Ambiguous_Specification:
return GPGME_Ambiguous_Specification; return gpg_error (GPG_ERR_AMBIGUOUS_NAME);
default: default:
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
} }
} }
return 0; return 0;

View File

@ -105,7 +105,7 @@ edit_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t key,
return err; return err;
if (!fnc || !out) if (!fnc || !out)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, sizeof (*opd), NULL); err = _gpgme_op_data_lookup (ctx, OPDATA_EDIT, &hook, sizeof (*opd), NULL);
opd = hook; opd = hook;

View File

@ -48,9 +48,9 @@ encrypt_sign_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t recp[],
return err; return err;
if (!plain) if (!plain)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
if (!cipher || !recp) if (!cipher || !recp)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = _gpgme_op_encrypt_init_result (ctx); err = _gpgme_op_encrypt_init_result (ctx);
if (err) if (err)

View File

@ -91,7 +91,7 @@ _gpgme_encrypt_status_handler (void *priv, gpgme_status_code_t code,
{ {
case GPGME_STATUS_EOF: case GPGME_STATUS_EOF:
if (opd->result.invalid_recipients) if (opd->result.invalid_recipients)
return GPGME_Invalid_Key; return gpg_error (GPG_ERR_UNUSABLE_PUBKEY);
break; break;
case GPGME_STATUS_INV_RECP: case GPGME_STATUS_INV_RECP:
@ -104,7 +104,7 @@ _gpgme_encrypt_status_handler (void *priv, gpgme_status_code_t code,
case GPGME_STATUS_NO_RECP: case GPGME_STATUS_NO_RECP:
/* Should not happen, because we require at least one recipient. */ /* Should not happen, because we require at least one recipient. */
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
default: default:
break; break;
@ -167,11 +167,11 @@ encrypt_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t recp[],
symmetric = 1; symmetric = 1;
if (!plain) if (!plain)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
if (!cipher) if (!cipher)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (recp && ! *recp) if (recp && ! *recp)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (symmetric && ctx->passphrase_cb) if (symmetric && ctx->passphrase_cb)
{ {

View File

@ -29,6 +29,7 @@
#include <unistd.h> #include <unistd.h>
#include <locale.h> #include <locale.h>
#include <fcntl.h> /* FIXME */ #include <fcntl.h> /* FIXME */
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "util.h" #include "util.h"
@ -151,100 +152,119 @@ close_notify_handler (int fd, void *opaque)
static gpgme_error_t static gpgme_error_t
map_assuan_error (AssuanError err) map_assuan_error (AssuanError err)
{ {
/* New code will use gpg_error_t values. */
if (gpg_err_source (err))
return (gpgme_error_t) err;
/* Legacy code will use old values. */
switch (err) switch (err)
{ {
case ASSUAN_No_Error: case ASSUAN_No_Error:
return GPGME_No_Error; return gpg_error (GPG_ERR_NO_ERROR);
case ASSUAN_General_Error: case ASSUAN_General_Error:
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
case ASSUAN_Out_Of_Core: case ASSUAN_Out_Of_Core:
return GPGME_Out_Of_Core; return gpg_error (GPG_ERR_ENOMEM);
case ASSUAN_Invalid_Value: case ASSUAN_Invalid_Value:
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
case ASSUAN_Read_Error:
return GPGME_Read_Error;
case ASSUAN_Write_Error:
return GPGME_Write_Error;
case ASSUAN_Timeout: case ASSUAN_Timeout:
return gpg_error (GPG_ERR_ETIMEDOUT);
case ASSUAN_Read_Error:
return gpg_error (GPG_ERR_GENERAL);
case ASSUAN_Write_Error:
return gpg_error (GPG_ERR_GENERAL);
case ASSUAN_Problem_Starting_Server: case ASSUAN_Problem_Starting_Server:
case ASSUAN_Not_A_Server: case ASSUAN_Not_A_Server:
case ASSUAN_Not_A_Client: case ASSUAN_Not_A_Client:
case ASSUAN_Nested_Commands: case ASSUAN_Nested_Commands:
case ASSUAN_Invalid_Response:
case ASSUAN_No_Data_Callback: case ASSUAN_No_Data_Callback:
case ASSUAN_No_Inquire_Callback: case ASSUAN_No_Inquire_Callback:
case ASSUAN_Connect_Failed: case ASSUAN_Connect_Failed:
case ASSUAN_Accept_Failed: case ASSUAN_Accept_Failed:
return GPGME_General_Error;
/* The following error codes are meant as status codes. */
case ASSUAN_Not_Implemented:
return GPGME_Not_Implemented;
case ASSUAN_Canceled:
return GPGME_Canceled;
case ASSUAN_Unsupported_Algorithm:
return GPGME_Not_Implemented; /* XXX Argh. */
case ASSUAN_No_Data_Available:
return GPGME_EOF;
/* These are errors internal to GPGME. */
case ASSUAN_No_Input:
case ASSUAN_No_Output:
case ASSUAN_Invalid_Command: case ASSUAN_Invalid_Command:
case ASSUAN_Unknown_Command: case ASSUAN_Unknown_Command:
case ASSUAN_Syntax_Error: case ASSUAN_Syntax_Error:
case ASSUAN_Parameter_Error: case ASSUAN_Parameter_Error:
case ASSUAN_Parameter_Conflict: case ASSUAN_Parameter_Conflict:
case ASSUAN_Line_Too_Long: case ASSUAN_No_Input:
case ASSUAN_Line_Not_Terminated: case ASSUAN_No_Output:
case ASSUAN_Invalid_Data: case ASSUAN_No_Data_Available:
case ASSUAN_Unexpected_Command:
case ASSUAN_Too_Much_Data: case ASSUAN_Too_Much_Data:
case ASSUAN_Inquire_Unknown: case ASSUAN_Inquire_Unknown:
case ASSUAN_Inquire_Error: case ASSUAN_Inquire_Error:
case ASSUAN_Invalid_Option: case ASSUAN_Invalid_Option:
case ASSUAN_Invalid_Index:
case ASSUAN_Unexpected_Status: case ASSUAN_Unexpected_Status:
case ASSUAN_Unexpected_Data: case ASSUAN_Unexpected_Data:
case ASSUAN_Invalid_Status: case ASSUAN_Invalid_Status:
case ASSUAN_Not_Confirmed: return gpg_error (GPG_ERR_ASSUAN);
return GPGME_General_Error;
/* These are errors in the server. */ case ASSUAN_Invalid_Response:
case ASSUAN_Server_Fault: return gpg_error (GPG_ERR_INV_RESPONSE);
case ASSUAN_Not_Implemented:
return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
case ASSUAN_Line_Too_Long:
return gpg_error (GPG_ERR_LINE_TOO_LONG);
case ASSUAN_Line_Not_Terminated:
return gpg_error (GPG_ERR_INCOMPLETE_LINE);
case ASSUAN_Canceled:
return gpg_error (GPG_ERR_CANCELED);
case ASSUAN_Unsupported_Algorithm:
return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM);
case ASSUAN_Server_Resource_Problem: case ASSUAN_Server_Resource_Problem:
return gpg_error (GPG_ERR_RESOURCE_LIMIT);
case ASSUAN_Server_IO_Error: case ASSUAN_Server_IO_Error:
return gpg_error (GPG_ERR_GENERAL);
case ASSUAN_Server_Bug: case ASSUAN_Server_Bug:
case ASSUAN_No_Agent: return gpg_error (GPG_ERR_BUG);
case ASSUAN_Agent_Error: case ASSUAN_Invalid_Data:
return GPGME_Invalid_Engine; /* XXX: Need something more useful. */ return gpg_error (GPG_ERR_INV_DATA);
case ASSUAN_Invalid_Index:
return gpg_error (GPG_ERR_INV_INDEX);
case ASSUAN_Not_Confirmed:
return gpg_error (GPG_ERR_NOT_CONFIRMED);
case ASSUAN_Bad_Certificate: case ASSUAN_Bad_Certificate:
return gpg_error (GPG_ERR_BAD_CERT);
case ASSUAN_Bad_Certificate_Chain: case ASSUAN_Bad_Certificate_Chain:
return gpg_error (GPG_ERR_BAD_CERT_CHAIN);
case ASSUAN_Missing_Certificate: case ASSUAN_Missing_Certificate:
case ASSUAN_No_Public_Key: return gpg_error (GPG_ERR_MISSING_CERT);
case ASSUAN_No_Secret_Key:
case ASSUAN_Invalid_Name:
case ASSUAN_Card_Error: /* XXX: Oh well. */
case ASSUAN_Invalid_Card: /* XXX: Oh well. */
case ASSUAN_No_PKCS15_App: /* XXX: Oh well. */
case ASSUAN_Card_Not_Present: /* XXX: Oh well. */
case ASSUAN_Invalid_Id: /* XXX: Oh well. */
return GPGME_Invalid_Key;
case ASSUAN_Bad_Signature: case ASSUAN_Bad_Signature:
return GPGME_Invalid_Key; /* XXX: This is wrong. */ return gpg_error (GPG_ERR_BAD_SIGNATURE);
case ASSUAN_No_Agent:
return gpg_error (GPG_ERR_NO_AGENT);
case ASSUAN_Agent_Error:
return gpg_error (GPG_ERR_AGENT);
case ASSUAN_No_Public_Key:
return gpg_error (GPG_ERR_NO_PUBKEY);
case ASSUAN_No_Secret_Key:
return gpg_error (GPG_ERR_NO_SECKEY);
case ASSUAN_Invalid_Name:
return gpg_error (GPG_ERR_INV_NAME);
case ASSUAN_Cert_Revoked: case ASSUAN_Cert_Revoked:
return gpg_error (GPG_ERR_CERT_REVOKED);
case ASSUAN_No_CRL_For_Cert: case ASSUAN_No_CRL_For_Cert:
return gpg_error (GPG_ERR_NO_CRL_KNOWN);
case ASSUAN_CRL_Too_Old: case ASSUAN_CRL_Too_Old:
return gpg_error (GPG_ERR_CRL_TOO_OLD);
case ASSUAN_Not_Trusted: case ASSUAN_Not_Trusted:
return GPGME_Invalid_Key; /* XXX Some more details would be good. */ return gpg_error (GPG_ERR_NOT_TRUSTED);
case ASSUAN_Card_Error:
return gpg_error (GPG_ERR_CARD);
case ASSUAN_Invalid_Card:
return gpg_error (GPG_ERR_INV_CARD);
case ASSUAN_No_PKCS15_App:
return gpg_error (GPG_ERR_NO_PKCS15_APP);
case ASSUAN_Card_Not_Present:
return gpg_error (GPG_ERR_CARD_NOT_PRESENT);
case ASSUAN_Invalid_Id:
return gpg_error (GPG_ERR_INV_ID);
default: default:
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
} }
} }
@ -292,10 +312,7 @@ gpgsm_new (void **engine)
gpgsm = calloc (1, sizeof *gpgsm); gpgsm = calloc (1, sizeof *gpgsm);
if (!gpgsm) if (!gpgsm)
{ return gpg_error_from_errno (errno);
err = GPGME_Out_Of_Core;
return err;
}
gpgsm->status_cb.fd = -1; gpgsm->status_cb.fd = -1;
gpgsm->status_cb.tag = 0; gpgsm->status_cb.tag = 0;
@ -325,7 +342,7 @@ gpgsm_new (void **engine)
if (_gpgme_io_pipe (fds, 0) < 0) if (_gpgme_io_pipe (fds, 0) < 0)
{ {
err = GPGME_Pipe_Error; err = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
gpgsm->input_cb.fd = fds[1]; gpgsm->input_cb.fd = fds[1];
@ -334,7 +351,7 @@ gpgsm_new (void **engine)
if (_gpgme_io_pipe (fds, 1) < 0) if (_gpgme_io_pipe (fds, 1) < 0)
{ {
err = GPGME_Pipe_Error; err = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
gpgsm->output_cb.fd = fds[0]; gpgsm->output_cb.fd = fds[0];
@ -343,7 +360,7 @@ gpgsm_new (void **engine)
if (_gpgme_io_pipe (fds, 0) < 0) if (_gpgme_io_pipe (fds, 0) < 0)
{ {
err = GPGME_Pipe_Error; err = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
gpgsm->message_cb.fd = fds[1]; gpgsm->message_cb.fd = fds[1];
@ -369,7 +386,7 @@ gpgsm_new (void **engine)
fdlist, DIM (fdlist)); fdlist, DIM (fdlist));
if (nfds < 1) if (nfds < 1)
{ {
err = GPGME_General_Error; /* FIXME */ err = gpg_error (GPG_ERR_GENERAL); /* FIXME */
goto leave; goto leave;
} }
/* We duplicate the file descriptor, so we can close it without /* We duplicate the file descriptor, so we can close it without
@ -380,7 +397,7 @@ gpgsm_new (void **engine)
gpgsm->status_cb.fd = dup (fdlist[0]); gpgsm->status_cb.fd = dup (fdlist[0]);
if (gpgsm->status_cb.fd < 0) if (gpgsm->status_cb.fd < 0)
{ {
err = GPGME_General_Error; /* FIXME */ err = gpg_error (GPG_ERR_GENERAL); /* FIXME */
goto leave; goto leave;
} }
gpgsm->status_cb.dir = 1; gpgsm->status_cb.dir = 1;
@ -391,7 +408,7 @@ gpgsm_new (void **engine)
{ {
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0) if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{ {
err = GPGME_Out_Of_Core; err = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
@ -408,7 +425,7 @@ gpgsm_new (void **engine)
{ {
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0) if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{ {
err = GPGME_Out_Of_Core; err = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
@ -425,7 +442,7 @@ gpgsm_new (void **engine)
{ {
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0) if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{ {
err = GPGME_Out_Of_Core; err = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL,
@ -444,7 +461,7 @@ gpgsm_new (void **engine)
old_lc = strdup (old_lc); old_lc = strdup (old_lc);
if (!old_lc) if (!old_lc)
{ {
err = GPGME_Out_Of_Core; err = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
} }
@ -452,7 +469,7 @@ gpgsm_new (void **engine)
if (dft_lc) if (dft_lc)
{ {
if (asprintf (&optstr, "OPTION lc-ctype=%s", dft_lc) < 0) if (asprintf (&optstr, "OPTION lc-ctype=%s", dft_lc) < 0)
err = GPGME_Out_Of_Core; err = gpg_error_from_errno (errno);
else else
{ {
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL,
@ -470,14 +487,13 @@ gpgsm_new (void **engine)
if (err) if (err)
goto leave; goto leave;
old_lc = setlocale (LC_MESSAGES, NULL); old_lc = setlocale (LC_MESSAGES, NULL);
if (old_lc) if (old_lc)
{ {
old_lc = strdup (old_lc); old_lc = strdup (old_lc);
if (!old_lc) if (!old_lc)
{ {
err = GPGME_Out_Of_Core; err = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
} }
@ -485,7 +501,7 @@ gpgsm_new (void **engine)
if (dft_lc) if (dft_lc)
{ {
if (asprintf (&optstr, "OPTION lc-messages=%s", dft_lc) < 0) if (asprintf (&optstr, "OPTION lc-messages=%s", dft_lc) < 0)
err = GPGME_Out_Of_Core; err = gpg_error_from_errno (errno);
else else
{ {
err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL,
@ -514,7 +530,7 @@ gpgsm_new (void **engine)
|| _gpgme_io_set_close_notify (gpgsm->message_cb.fd, || _gpgme_io_set_close_notify (gpgsm->message_cb.fd,
close_notify_handler, gpgsm))) close_notify_handler, gpgsm)))
{ {
err = GPGME_General_Error; err = gpg_error (GPG_ERR_GENERAL);
goto leave; goto leave;
} }
@ -587,10 +603,10 @@ gpgsm_assuan_simple_command (ASSUAN_CONTEXT ctx, char *cmd,
if (r >= 0 && status_fnc) if (r >= 0 && status_fnc)
status_fnc (status_fnc_value, r, rest); status_fnc (status_fnc_value, r, rest);
else else
err = GPGME_General_Error; err = gpg_error (GPG_ERR_GENERAL);
} }
else else
err = GPGME_General_Error; err = gpg_error (GPG_ERR_GENERAL);
} }
while (!err); while (!err);
@ -679,7 +695,7 @@ status_handler (void *opaque, int fd)
if (line[3] == ' ') if (line[3] == ' ')
err = map_assuan_error (atoi (&line[4])); err = map_assuan_error (atoi (&line[4]));
else else
err = GPGME_General_Error; err = gpg_error (GPG_ERR_GENERAL);
} }
else if (linelen >= 2 else if (linelen >= 2
&& line[0] == 'O' && line[1] == 'K' && line[0] == 'O' && line[1] == 'K'
@ -724,7 +740,7 @@ status_handler (void *opaque, int fd)
unsigned char *newline = realloc (*aline, unsigned char *newline = realloc (*aline,
*alinelen + linelen + 1); *alinelen + linelen + 1);
if (!newline) if (!newline)
err = GPGME_Out_Of_Core; err = gpg_error_from_errno (errno);
else else
{ {
*aline = newline; *aline = newline;
@ -850,17 +866,17 @@ gpgsm_decrypt (void *engine, gpgme_data_t ciph, gpgme_data_t plain)
gpgme_error_t err; gpgme_error_t err;
if (!gpgsm) if (!gpgsm)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
gpgsm->input_cb.data = ciph; gpgsm->input_cb.data = ciph;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server,
map_input_enc (gpgsm->input_cb.data)); map_input_enc (gpgsm->input_cb.data));
if (err) if (err)
return GPGME_General_Error; /* FIXME */ return gpg_error (GPG_ERR_GENERAL); /* FIXME */
gpgsm->output_cb.data = plain; gpgsm->output_cb.data = plain;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, 0); err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, 0);
if (err) if (err)
return GPGME_General_Error; /* FIXME */ return gpg_error (GPG_ERR_GENERAL); /* FIXME */
_gpgme_io_close (gpgsm->message_cb.fd); _gpgme_io_close (gpgsm->message_cb.fd);
err = start (engine, "DECRYPT"); err = start (engine, "DECRYPT");
@ -879,7 +895,7 @@ gpgsm_delete (void *engine, gpgme_key_t key, int allow_secret)
int length = 8; /* "DELKEYS " */ int length = 8; /* "DELKEYS " */
if (!fpr) if (!fpr)
return GPGME_Invalid_Key; return gpg_error (GPG_ERR_INV_VALUE);
while (*linep) while (*linep)
{ {
@ -892,7 +908,7 @@ gpgsm_delete (void *engine, gpgme_key_t key, int allow_secret)
line = malloc (length); line = malloc (length);
if (!line) if (!line)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
strcpy (line, "DELKEYS "); strcpy (line, "DELKEYS ");
linep = &line[8]; linep = &line[8];
@ -948,7 +964,7 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */ linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */
line = malloc (10 + 40 + 1); line = malloc (10 + 40 + 1);
if (!line) if (!line)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
strcpy (line, "RECIPIENT "); strcpy (line, "RECIPIENT ");
while (!err && recp[i]) while (!err && recp[i])
{ {
@ -967,8 +983,9 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
char *newline = realloc (line, newlen); char *newline = realloc (line, newlen);
if (! newline) if (! newline)
{ {
int saved_errno = errno;
free (line); free (line);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
line = newline; line = newline;
linelen = newlen; linelen = newlen;
@ -977,7 +994,8 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
err = gpgsm_assuan_simple_command (ctx, line, gpgsm->status.fnc, err = gpgsm_assuan_simple_command (ctx, line, gpgsm->status.fnc,
gpgsm->status.fnc_value); gpgsm->status.fnc_value);
if (err == GPGME_Invalid_Key) /* FIXME: This requires more work. */
if (gpg_err_code (err) == GPG_ERR_NO_PUBKEY)
invalid_recipients++; invalid_recipients++;
else if (err) else if (err)
{ {
@ -987,7 +1005,8 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
i++; i++;
} }
free (line); free (line);
return invalid_recipients ? GPGME_Invalid_Key : 0; return gpg_error (invalid_recipients
? GPG_ERR_UNUSABLE_PUBKEY : GPG_ERR_NO_ERROR);
} }
@ -999,9 +1018,9 @@ gpgsm_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
gpgme_error_t err; gpgme_error_t err;
if (!gpgsm) if (!gpgsm)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!recp) if (!recp)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
gpgsm->input_cb.data = plain; gpgsm->input_cb.data = plain;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server,
@ -1033,14 +1052,14 @@ gpgsm_export (void *engine, const char *pattern, unsigned int reserved,
char *cmd; char *cmd;
if (!gpgsm || reserved) if (!gpgsm || reserved)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!pattern) if (!pattern)
pattern = ""; pattern = "";
cmd = malloc (7 + strlen (pattern) + 1); cmd = malloc (7 + strlen (pattern) + 1);
if (!cmd) if (!cmd)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
strcpy (cmd, "EXPORT "); strcpy (cmd, "EXPORT ");
strcpy (&cmd[7], pattern); strcpy (&cmd[7], pattern);
@ -1070,7 +1089,7 @@ gpgsm_export_ext (void *engine, const char *pattern[], unsigned int reserved,
char *linep; char *linep;
if (!gpgsm || reserved) if (!gpgsm || reserved)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (pattern && *pattern) if (pattern && *pattern)
{ {
@ -1094,7 +1113,7 @@ gpgsm_export_ext (void *engine, const char *pattern[], unsigned int reserved,
} }
line = malloc (length); line = malloc (length);
if (!line) if (!line)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
strcpy (line, "EXPORT "); strcpy (line, "EXPORT ");
linep = &line[7]; linep = &line[7];
@ -1157,7 +1176,7 @@ gpgsm_genkey (void *engine, gpgme_data_t help_data, int use_armor,
gpgme_error_t err; gpgme_error_t err;
if (!gpgsm || !pubkey || seckey) if (!gpgsm || !pubkey || seckey)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
gpgsm->input_cb.data = help_data; gpgsm->input_cb.data = help_data;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server,
@ -1183,7 +1202,7 @@ gpgsm_import (void *engine, gpgme_data_t keydata)
gpgme_error_t err; gpgme_error_t err;
if (!gpgsm) if (!gpgsm)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
gpgsm->input_cb.data = keydata; gpgsm->input_cb.data = keydata;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server,
@ -1216,7 +1235,7 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only,
pattern = ""; pattern = "";
if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0) if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL);
free (line); free (line);
if (err) if (err)
@ -1225,7 +1244,7 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only,
/* Length is "LISTSECRETKEYS " + p + '\0'. */ /* Length is "LISTSECRETKEYS " + p + '\0'. */
line = malloc (15 + strlen (pattern) + 1); line = malloc (15 + strlen (pattern) + 1);
if (!line) if (!line)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
if (secret_only) if (secret_only)
{ {
strcpy (line, "LISTSECRETKEYS "); strcpy (line, "LISTSECRETKEYS ");
@ -1260,7 +1279,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
int list_mode = 0; int list_mode = 0;
if (reserved) if (reserved)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (mode & GPGME_KEYLIST_MODE_LOCAL) if (mode & GPGME_KEYLIST_MODE_LOCAL)
list_mode |= 1; list_mode |= 1;
@ -1268,7 +1287,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
list_mode |= 2; list_mode |= 2;
if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0) if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL); err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, line, NULL, NULL);
free (line); free (line);
if (err) if (err)
@ -1296,7 +1315,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only,
} }
line = malloc (length); line = malloc (length);
if (!line) if (!line)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
if (secret_only) if (secret_only)
{ {
strcpy (line, "LISTSECRETKEYS "); strcpy (line, "LISTSECRETKEYS ");
@ -1366,10 +1385,10 @@ gpgsm_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
gpgme_key_t key; gpgme_key_t key;
if (!gpgsm) if (!gpgsm)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0) if (asprintf (&assuan_cmd, "OPTION include-certs %i", include_certs) < 0)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd, NULL,NULL); err = gpgsm_assuan_simple_command (gpgsm->assuan_ctx, assuan_cmd, NULL,NULL);
free (assuan_cmd); free (assuan_cmd);
if (err) if (err)
@ -1393,7 +1412,7 @@ gpgsm_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
NULL, NULL); NULL, NULL);
} }
else else
err = GPGME_Invalid_Key; err = gpg_error (GPG_ERR_INV_VALUE);
gpgme_key_unref (key); gpgme_key_unref (key);
if (err) if (err)
return err; return err;
@ -1417,14 +1436,6 @@ gpgsm_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
} }
static gpgme_error_t
gpgsm_trustlist (void *engine, const char *pattern)
{
/* FIXME */
return GPGME_Not_Implemented;
}
static gpgme_error_t static gpgme_error_t
gpgsm_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text, gpgsm_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
gpgme_data_t plaintext) gpgme_data_t plaintext)
@ -1433,7 +1444,7 @@ gpgsm_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
gpgme_error_t err; gpgme_error_t err;
if (!gpgsm) if (!gpgsm)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
gpgsm->input_cb.data = sig; gpgsm->input_cb.data = sig;
err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server,
@ -1531,7 +1542,7 @@ struct engine_ops _gpgme_engine_ops_gpgsm =
gpgsm_keylist, gpgsm_keylist,
gpgsm_keylist_ext, gpgsm_keylist_ext,
gpgsm_sign, gpgsm_sign,
gpgsm_trustlist, NULL, /* trustlist */
gpgsm_verify, gpgsm_verify,
gpgsm_set_io_cbs, gpgsm_set_io_cbs,
gpgsm_io_event gpgsm_io_event

View File

@ -23,6 +23,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "util.h" #include "util.h"
@ -99,7 +100,7 @@ gpgme_engine_check_version (gpgme_protocol_t proto)
{ {
return _gpgme_compare_versions (engine_get_version (proto), return _gpgme_compare_versions (engine_get_version (proto),
engine_get_req_version (proto)) engine_get_req_version (proto))
? 0 : GPGME_Invalid_Engine; ? 0 : gpg_error (GPG_ERR_INV_ENGINE);
} }
@ -130,6 +131,8 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
*lastp = malloc (sizeof (*engine_info)); *lastp = malloc (sizeof (*engine_info));
if (!*lastp) if (!*lastp)
{ {
int saved_errno = errno;
while (engine_info) while (engine_info)
{ {
gpgme_engine_info_t next_info = engine_info->next; gpgme_engine_info_t next_info = engine_info->next;
@ -137,7 +140,7 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
engine_info = next_info; engine_info = next_info;
} }
UNLOCK (engine_info_lock); UNLOCK (engine_info_lock);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
(*lastp)->protocol = proto_list[proto]; (*lastp)->protocol = proto_list[proto];
@ -162,19 +165,19 @@ _gpgme_engine_new (gpgme_protocol_t proto, engine_t *r_engine)
const char *version; const char *version;
if (proto > DIM (engine_ops)) if (proto > DIM (engine_ops))
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine_ops[proto]) if (!engine_ops[proto])
return GPGME_Invalid_Engine; return gpg_error (GPG_ERR_INV_ENGINE);
file_name = engine_get_file_name (proto); file_name = engine_get_file_name (proto);
version = engine_get_version (proto); version = engine_get_version (proto);
if (!file_name || !version) if (!file_name || !version)
return GPGME_Invalid_Engine; return gpg_error (GPG_ERR_INV_ENGINE);
engine = calloc (1, sizeof *engine); engine = calloc (1, sizeof *engine);
if (!engine) if (!engine)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
engine->ops = engine_ops[proto]; engine->ops = engine_ops[proto];
if (engine_ops[proto]->new) if (engine_ops[proto]->new)
@ -225,10 +228,10 @@ _gpgme_engine_set_command_handler (engine_t engine,
gpgme_data_t linked_data) gpgme_data_t linked_data)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->set_command_handler) if (!engine->ops->set_command_handler)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->set_command_handler) (engine->engine, return (*engine->ops->set_command_handler) (engine->engine,
fnc, fnc_value, linked_data); fnc, fnc_value, linked_data);
@ -240,10 +243,10 @@ _gpgme_engine_set_colon_line_handler (engine_t engine,
void *fnc_value) void *fnc_value)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->set_colon_line_handler) if (!engine->ops->set_colon_line_handler)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->set_colon_line_handler) (engine->engine, return (*engine->ops->set_colon_line_handler) (engine->engine,
fnc, fnc_value); fnc, fnc_value);
@ -254,10 +257,10 @@ _gpgme_engine_op_decrypt (engine_t engine, gpgme_data_t ciph,
gpgme_data_t plain) gpgme_data_t plain)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->decrypt) if (!engine->ops->decrypt)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->decrypt) (engine->engine, ciph, plain); return (*engine->ops->decrypt) (engine->engine, ciph, plain);
} }
@ -267,10 +270,10 @@ _gpgme_engine_op_delete (engine_t engine, gpgme_key_t key,
int allow_secret) int allow_secret)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->delete) if (!engine->ops->delete)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->delete) (engine->engine, key, allow_secret); return (*engine->ops->delete) (engine->engine, key, allow_secret);
} }
@ -281,10 +284,10 @@ _gpgme_engine_op_edit (engine_t engine, gpgme_key_t key, gpgme_data_t out,
gpgme_ctx_t ctx /* FIXME */) gpgme_ctx_t ctx /* FIXME */)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->edit) if (!engine->ops->edit)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->edit) (engine->engine, key, out, ctx); return (*engine->ops->edit) (engine->engine, key, out, ctx);
} }
@ -296,10 +299,10 @@ _gpgme_engine_op_encrypt (engine_t engine, gpgme_key_t recp[],
gpgme_data_t plain, gpgme_data_t ciph, int use_armor) gpgme_data_t plain, gpgme_data_t ciph, int use_armor)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->encrypt) if (!engine->ops->encrypt)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->encrypt) (engine->engine, recp, flags, plain, ciph, return (*engine->ops->encrypt) (engine->engine, recp, flags, plain, ciph,
use_armor); use_armor);
@ -313,10 +316,10 @@ _gpgme_engine_op_encrypt_sign (engine_t engine, gpgme_key_t recp[],
int use_armor, gpgme_ctx_t ctx /* FIXME */) int use_armor, gpgme_ctx_t ctx /* FIXME */)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->encrypt_sign) if (!engine->ops->encrypt_sign)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->encrypt_sign) (engine->engine, recp, flags, return (*engine->ops->encrypt_sign) (engine->engine, recp, flags,
plain, ciph, use_armor, ctx); plain, ciph, use_armor, ctx);
@ -329,10 +332,10 @@ _gpgme_engine_op_export (engine_t engine, const char *pattern,
int use_armor) int use_armor)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->export) if (!engine->ops->export)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->export) (engine->engine, pattern, reserved, return (*engine->ops->export) (engine->engine, pattern, reserved,
keydata, use_armor); keydata, use_armor);
@ -345,10 +348,10 @@ _gpgme_engine_op_export_ext (engine_t engine, const char *pattern[],
int use_armor) int use_armor)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->export_ext) if (!engine->ops->export_ext)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->export_ext) (engine->engine, pattern, reserved, return (*engine->ops->export_ext) (engine->engine, pattern, reserved,
keydata, use_armor); keydata, use_armor);
@ -361,10 +364,10 @@ _gpgme_engine_op_genkey (engine_t engine, gpgme_data_t help_data,
gpgme_data_t seckey) gpgme_data_t seckey)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->genkey) if (!engine->ops->genkey)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->genkey) (engine->engine, help_data, use_armor, return (*engine->ops->genkey) (engine->engine, help_data, use_armor,
pubkey, seckey); pubkey, seckey);
@ -375,10 +378,10 @@ gpgme_error_t
_gpgme_engine_op_import (engine_t engine, gpgme_data_t keydata) _gpgme_engine_op_import (engine_t engine, gpgme_data_t keydata)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->import) if (!engine->ops->import)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->import) (engine->engine, keydata); return (*engine->ops->import) (engine->engine, keydata);
} }
@ -389,10 +392,10 @@ _gpgme_engine_op_keylist (engine_t engine, const char *pattern,
int secret_only, gpgme_keylist_mode_t mode) int secret_only, gpgme_keylist_mode_t mode)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->keylist) if (!engine->ops->keylist)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->keylist) (engine->engine, pattern, secret_only, mode); return (*engine->ops->keylist) (engine->engine, pattern, secret_only, mode);
} }
@ -404,10 +407,10 @@ _gpgme_engine_op_keylist_ext (engine_t engine, const char *pattern[],
gpgme_keylist_mode_t mode) gpgme_keylist_mode_t mode)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->keylist_ext) if (!engine->ops->keylist_ext)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->keylist_ext) (engine->engine, pattern, secret_only, return (*engine->ops->keylist_ext) (engine->engine, pattern, secret_only,
reserved, mode); reserved, mode);
@ -421,10 +424,10 @@ _gpgme_engine_op_sign (engine_t engine, gpgme_data_t in, gpgme_data_t out,
gpgme_ctx_t ctx /* FIXME */) gpgme_ctx_t ctx /* FIXME */)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->sign) if (!engine->ops->sign)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->sign) (engine->engine, in, out, mode, use_armor, return (*engine->ops->sign) (engine->engine, in, out, mode, use_armor,
use_textmode, include_certs, ctx); use_textmode, include_certs, ctx);
@ -435,10 +438,10 @@ gpgme_error_t
_gpgme_engine_op_trustlist (engine_t engine, const char *pattern) _gpgme_engine_op_trustlist (engine_t engine, const char *pattern)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->trustlist) if (!engine->ops->trustlist)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->trustlist) (engine->engine, pattern); return (*engine->ops->trustlist) (engine->engine, pattern);
} }
@ -449,10 +452,10 @@ _gpgme_engine_op_verify (engine_t engine, gpgme_data_t sig,
gpgme_data_t signed_text, gpgme_data_t plaintext) gpgme_data_t signed_text, gpgme_data_t plaintext)
{ {
if (!engine) if (!engine)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!engine->ops->verify) if (!engine->ops->verify)
return GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return (*engine->ops->verify) (engine->engine, sig, signed_text, plaintext); return (*engine->ops->verify) (engine->engine, sig, signed_text, plaintext);
} }

77
gpgme/error.c Normal file
View File

@ -0,0 +1,77 @@
/* error.c - Error handling for GPGME.
Copyright (C) 2003 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 <gpgme.h>
/* Return a pointer to a string containing a description of the error
code in the error value ERR. */
const char *
gpgme_strerror (gpgme_error_t err)
{
return gpg_strerror (err);
}
/* Return a pointer to a string containing a description of the error
source in the error value ERR. */
const char *
gpgme_strsource (gpgme_error_t err)
{
return gpg_strsource (err);
}
/* Retrieve the error code for the system error ERR. This returns
GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
this). */
gpgme_err_code_t
gpgme_err_code_from_errno (int err)
{
return gpg_err_code_from_errno (err);
}
/* Retrieve the system error for the error code CODE. This returns 0
if CODE is not a system error code. */
int
gpgme_err_code_to_errno (gpgme_err_code_t code)
{
return gpg_err_code_from_errno (code);
}
/* Return an error value with the error source SOURCE and the system
error ERR. */
gpgme_error_t
gpgme_err_make_from_errno (gpg_err_source_t source, int err)
{
return gpg_err_make_from_errno (source, err);
}
/* Return an error value with the system error ERR. */
gpgme_err_code_t
gpgme_error_from_errno (int err)
{
return gpgme_error (gpg_err_code_from_errno (err));
}

View File

@ -41,7 +41,7 @@ export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern,
gpgme_error_t err; gpgme_error_t err;
if (!keydata) if (!keydata)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = _gpgme_op_reset (ctx, synchronous); err = _gpgme_op_reset (ctx, synchronous);
if (err) if (err)
@ -82,7 +82,7 @@ export_ext_start (gpgme_ctx_t ctx, int synchronous, const char *pattern[],
gpgme_error_t err; gpgme_error_t err;
if (!keydata) if (!keydata)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = _gpgme_op_reset (ctx, synchronous); err = _gpgme_op_reset (ctx, synchronous);
if (err) if (err)

View File

@ -23,6 +23,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "context.h" #include "context.h"
@ -99,7 +100,7 @@ genkey_status_handler (void *priv, gpgme_status_code_t code, char *args)
free (opd->result.fpr); free (opd->result.fpr);
opd->result.fpr = strdup (&args[2]); opd->result.fpr = strdup (&args[2]);
if (!opd->result.fpr) if (!opd->result.fpr)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
} }
break; break;
@ -107,7 +108,7 @@ genkey_status_handler (void *priv, gpgme_status_code_t code, char *args)
case GPGME_STATUS_EOF: case GPGME_STATUS_EOF:
/* FIXME: Should return some more useful error value. */ /* FIXME: Should return some more useful error value. */
if (!opd->result.primary && !opd->result.sub) if (!opd->result.primary && !opd->result.sub)
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
break; break;
default: default:
@ -127,16 +128,16 @@ get_key_parameter (const char *parms, gpgme_data_t *key_parameter)
/* Extract the key parameter from the XML structure. */ /* Extract the key parameter from the XML structure. */
parms = strstr (parms, "<GnupgKeyParms "); parms = strstr (parms, "<GnupgKeyParms ");
if (!parms) if (!parms)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
content = strchr (parms, '>'); content = strchr (parms, '>');
if (!content) if (!content)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
content++; content++;
attrib = strstr (parms, "format=\"internal\""); attrib = strstr (parms, "format=\"internal\"");
if (!attrib || attrib >= content) if (!attrib || attrib >= content)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
endtag = strstr (content, "</GnupgKeyParms>"); endtag = strstr (content, "</GnupgKeyParms>");
/* FIXME: Check that there are no control statements inside. */ /* FIXME: Check that there are no control statements inside. */

View File

@ -25,6 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"
@ -40,7 +41,7 @@ gpgme_new (gpgme_ctx_t *r_ctx)
ctx = calloc (1, sizeof *ctx); ctx = calloc (1, sizeof *ctx);
if (!ctx) if (!ctx)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
ctx->keylist_mode = GPGME_KEYLIST_MODE_LOCAL; ctx->keylist_mode = GPGME_KEYLIST_MODE_LOCAL;
ctx->include_certs = 1; ctx->include_certs = 1;
ctx->protocol = GPGME_PROTOCOL_OpenPGP; ctx->protocol = GPGME_PROTOCOL_OpenPGP;
@ -85,7 +86,7 @@ gpgme_error_t
gpgme_set_protocol (gpgme_ctx_t ctx, gpgme_protocol_t protocol) gpgme_set_protocol (gpgme_ctx_t ctx, gpgme_protocol_t protocol)
{ {
if (protocol != GPGME_PROTOCOL_OpenPGP && protocol != GPGME_PROTOCOL_CMS) if (protocol != GPGME_PROTOCOL_OpenPGP && protocol != GPGME_PROTOCOL_CMS)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
ctx->protocol = protocol; ctx->protocol = protocol;
return 0; return 0;
@ -180,7 +181,7 @@ gpgme_set_keylist_mode (gpgme_ctx_t ctx, gpgme_keylist_mode_t mode)
if (!((mode & GPGME_KEYLIST_MODE_LOCAL) if (!((mode & GPGME_KEYLIST_MODE_LOCAL)
|| (mode & GPGME_KEYLIST_MODE_EXTERN) || (mode & GPGME_KEYLIST_MODE_EXTERN)
|| (mode & GPGME_KEYLIST_MODE_SIGS))) || (mode & GPGME_KEYLIST_MODE_SIGS)))
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
ctx->keylist_mode = mode; ctx->keylist_mode = mode;
return 0; return 0;

View File

@ -38,6 +38,8 @@ extern "C" {
#endif #endif
#endif #endif
#include <gpg-error.h>
/* Check for compiler features. */ /* Check for compiler features. */
#if __GNUC__ #if __GNUC__
@ -76,74 +78,75 @@ struct gpgme_data;
typedef struct gpgme_data *gpgme_data_t; typedef struct gpgme_data *gpgme_data_t;
/* Public data types provided by GPGME. */ /* Wrappers for the libgpg-error library. */
/* The error numbers used by GPGME. */ typedef gpg_error_t gpgme_error_t;
typedef enum typedef gpg_err_code_t gpgme_err_code_t;
typedef gpg_err_source_t gpgme_err_source_t;
static __inline__ gpgme_error_t
gpgme_err_make (gpgme_err_source_t source, gpgme_err_code_t code)
{ {
GPGME_EOF = -1, return gpg_err_make (source, code);
GPGME_No_Error = 0x0000,
GPGME_General_Error = 0x0001,
GPGME_Out_Of_Core = 0x0002,
GPGME_Invalid_Value = 0x0003,
GPGME_Exec_Error = 0x0004,
GPGME_Too_Many_Procs = 0x0005,
GPGME_Pipe_Error = 0x0006,
GPGME_No_Data = 0x0007,
GPGME_Conflict = 0x0008,
GPGME_Not_Implemented = 0x0009,
GPGME_Read_Error = 0x000a,
GPGME_Write_Error = 0x000b,
GPGME_File_Error = 0x000c, /* errno is set in this case. */
GPGME_Decryption_Failed = 0x000d,
GPGME_Bad_Passphrase = 0x000e,
GPGME_Canceled = 0x000f,
GPGME_Invalid_Key = 0x0010,
GPGME_Invalid_Engine = 0x0011,
GPGME_No_UserID = 0x0012,
GPGME_Invalid_UserID = 0x0013,
/* Reasons for invalid user id. */
GPGME_Unknown_Reason = 0x0100,
GPGME_Not_Found = 0x0101,
GPGME_Ambiguous_Specification = 0x0102,
GPGME_Wrong_Key_Usage = 0x0103,
GPGME_Key_Revoked = 0x0104,
GPGME_Key_Expired = 0x0105,
GPGME_No_CRL_Known = 0x0106,
GPGME_CRL_Too_Old = 0x0107,
GPGME_Policy_Mismatch = 0x0108,
GPGME_No_Secret_Key = 0x0109,
GPGME_Key_Not_Trusted = 0x010a,
/* Import problems. */
GPGME_Issuer_Missing = 0x0200,
GPGME_Chain_Too_Long = 0x0201,
/* Verification problems. */
GPGME_Unsupported_Algorithm = 0x0300,
GPGME_Sig_Expired = 0x0301,
GPGME_Bad_Signature = 0x0302,
GPGME_No_Public_Key = 0x0303,
/* Deprecated, see below. */
GPGME_x_Busy = -2,
GPGME_x_No_Request = -3,
GPGME_x_Invalid_Type = -4,
GPGME_x_Invalid_Mode = -5
} }
gpgme_error_t;
typedef gpgme_error_t _gpgme_deprecated_error_t _GPGME_DEPRECATED;
#define GPGME_Busy ((_gpgme_deprecated_error_t) GPGME_x_Busy) /* The user can define GPG_ERR_SOURCE_DEFAULT before including this
#define GPGME_No_Request ((_gpgme_deprecated_error_t) GPGME_x_No_Request) file to specify a default source for gpg_error. */
#define GPGME_Invalid_Type ((_gpgme_deprecated_error_t) GPGME_x_Invalid_Type) #ifndef GPGME_ERR_SOURCE_DEFAULT
#define GPGME_Invalid_Mode ((_gpgme_deprecated_error_t) GPGME_x_Invalid_Mode) #define GPGME_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1
#define GPGME_No_Recipients ((_gpgme_deprecated_error_t) GPGME_No_UserID) #endif
#define GPGME_Invalid_Recipients \
((_gpgme_deprecated_error_t) GPGME_Invalid_UserID) static __inline__ gpgme_error_t
#define GPGME_No_Passphrase ((_gpgme_deprecated_error_t) GPGME_Bad_Passphrase) gpgme_error (gpgme_err_code_t code)
{
return gpgme_err_make (GPGME_ERR_SOURCE_DEFAULT, code);
}
static __inline__ gpgme_err_code_t
gpgme_err_code (gpgme_error_t err)
{
return gpg_err_code (err);
}
static __inline__ gpgme_err_source_t
gpgme_err_source (gpgme_error_t err)
{
return gpg_err_source (err);
}
/* Return a pointer to a string containing a description of the error
code in the error value ERR. */
const char *gpgme_strerror (gpgme_error_t err);
/* Return a pointer to a string containing a description of the error
source in the error value ERR. */
const char *gpgme_strsource (gpgme_error_t err);
/* Retrieve the error code for the system error ERR. This returns
GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
this). */
gpgme_err_code_t gpgme_err_code_from_errno (int err);
/* Retrieve the system error for the error code CODE. This returns 0
if CODE is not a system error code. */
int gpgme_err_code_to_errno (gpgme_err_code_t code);
/* Return an error value with the error source SOURCE and the system
error ERR. */
gpgme_error_t gpgme_err_make_from_errno (gpg_err_source_t source, int err);
/* Return an error value with the system error ERR. */
gpgme_err_code_t gpg_error_from_errno (int err);
/* The possible encoding mode of gpgme_data_t objects. */ /* The possible encoding mode of gpgme_data_t objects. */
@ -1425,9 +1428,6 @@ const char *gpgme_check_version (const char *req_version);
/* Retrieve information about the backend engines. */ /* Retrieve information about the backend engines. */
gpgme_error_t gpgme_get_engine_info (gpgme_engine_info_t *engine_info); gpgme_error_t gpgme_get_engine_info (gpgme_engine_info_t *engine_info);
/* Return a string describing ERR. */
const char *gpgme_strerror (gpgme_error_t err);
/* Engine support functions. */ /* Engine support functions. */

View File

@ -82,7 +82,7 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
import = malloc (sizeof (*import)); import = malloc (sizeof (*import));
if (!import) if (!import)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
import->next = NULL; import->next = NULL;
errno = 0; errno = 0;
@ -91,7 +91,7 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (import); free (import);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -102,26 +102,26 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
case 0: case 0:
case 4: case 4:
default: default:
import->result = GPGME_Unknown_Reason; import->result = gpg_error (GPG_ERR_GENERAL);
break; break;
case 1: case 1:
import->result = GPGME_Invalid_Key; import->result = gpg_error (GPG_ERR_BAD_CERT);
break; break;
case 2: case 2:
import->result = GPGME_Issuer_Missing; import->result = gpg_error (GPG_ERR_MISSING_CERT);
break; break;
case 3: case 3:
import->result = GPGME_Chain_Too_Long; import->result = gpg_error (GPG_ERR_BAD_CERT_CHAIN);
break; break;
} }
import->status = 0; import->status = 0;
} }
else else
{ {
import->result = GPGME_No_Error; import->result = gpg_error (GPG_ERR_NO_ERROR);
import->status = nr; import->status = nr;
} }
@ -134,8 +134,9 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
import->fpr = strdup (args); import->fpr = strdup (args);
if (!import->fpr) if (!import->fpr)
{ {
int saved_errno = errno;
free (import); free (import);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
*import_status = import; *import_status = import;
@ -155,7 +156,7 @@ parse_import_res (char *args, gpgme_import_result_t result)
(x) = strtol (args, &tail, 0); \ (x) = strtol (args, &tail, 0); \
if (errno || args == tail || *tail != ' ') \ if (errno || args == tail || *tail != ' ') \
/* The crypto backend does not behave. */ \ /* The crypto backend does not behave. */ \
return GPGME_General_Error; \ return gpg_error (GPG_ERR_INV_ENGINE); \
args = tail; args = tail;
PARSE_NEXT (result->considered); PARSE_NEXT (result->considered);
@ -232,7 +233,7 @@ _gpgme_op_import_start (gpgme_ctx_t ctx, int synchronous, gpgme_data_t keydata)
opd->lastp = &opd->result.imports; opd->lastp = &opd->result.imports;
if (!keydata) if (!keydata)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
_gpgme_engine_set_status_handler (ctx->engine, import_status_handler, ctx); _gpgme_engine_set_status_handler (ctx->engine, import_status_handler, ctx);

View File

@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "util.h" #include "util.h"
#include "ops.h" #include "ops.h"
@ -43,7 +44,7 @@ _gpgme_key_new (gpgme_key_t *r_key)
key = calloc (1, sizeof *key); key = calloc (1, sizeof *key);
if (!key) if (!key)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
key->_refs = 1; key->_refs = 1;
*r_key = key; *r_key = key;
@ -58,7 +59,7 @@ _gpgme_key_add_subkey (gpgme_key_t key, gpgme_subkey_t *r_subkey)
subkey = calloc (1, sizeof *subkey); subkey = calloc (1, sizeof *subkey);
if (!subkey) if (!subkey)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
subkey->keyid = subkey->_keyid; subkey->keyid = subkey->_keyid;
subkey->_keyid[16] = '\0'; subkey->_keyid[16] = '\0';
@ -212,7 +213,7 @@ _gpgme_key_append_name (gpgme_key_t key, char *src)
size, so that we are able to store the parsed stuff there too. */ size, so that we are able to store the parsed stuff there too. */
uid = malloc (sizeof (*uid) + 2 * src_len + 3); uid = malloc (sizeof (*uid) + 2 * src_len + 3);
if (!uid) if (!uid)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
memset (uid, 0, sizeof *uid); memset (uid, 0, sizeof *uid);
uid->uid = ((char *) uid) + sizeof (*uid); uid->uid = ((char *) uid) + sizeof (*uid);

View File

@ -27,6 +27,7 @@
#include <time.h> #include <time.h>
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "util.h" #include "util.h"
@ -479,7 +480,7 @@ keylist_colon_handler (void *priv, char *line)
{ {
key->issuer_serial = strdup (field[7]); key->issuer_serial = strdup (field[7]);
if (!key->issuer_serial) if (!key->issuer_serial)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
/* Field 9 has the ownertrust. */ /* Field 9 has the ownertrust. */
@ -490,7 +491,7 @@ keylist_colon_handler (void *priv, char *line)
but GPGSM stores the issuer name. */ but GPGSM stores the issuer name. */
if (fields >= 10 && (rectype == RT_CRT || rectype == RT_CRS)) if (fields >= 10 && (rectype == RT_CRT || rectype == RT_CRS))
if (_gpgme_decode_c_string (field[9], &key->issuer_name, 0)) if (_gpgme_decode_c_string (field[9], &key->issuer_name, 0))
return GPGME_Out_Of_Core; return gpg_error (GPG_ERR_ENOMEM); /* FIXME */
/* Field 11 has the signature class. */ /* Field 11 has the signature class. */
@ -558,7 +559,7 @@ keylist_colon_handler (void *priv, char *line)
if (fields >= 10) if (fields >= 10)
{ {
if (_gpgme_key_append_name (key, field[9])) if (_gpgme_key_append_name (key, field[9]))
return GPGME_Out_Of_Core; return gpg_error_from_errno (GPG_ERR_ENOMEM); /* FIXME */
else else
{ {
if (field[1]) if (field[1])
@ -574,7 +575,7 @@ keylist_colon_handler (void *priv, char *line)
{ {
key->subkeys->fpr = strdup (field[9]); key->subkeys->fpr = strdup (field[9]);
if (!key->subkeys->fpr) if (!key->subkeys->fpr)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
/* Field 13 has the gpgsm chain ID (take only the first one). */ /* Field 13 has the gpgsm chain ID (take only the first one). */
@ -582,7 +583,7 @@ keylist_colon_handler (void *priv, char *line)
{ {
key->chain_id = strdup (field[12]); key->chain_id = strdup (field[12]);
if (!key->chain_id) if (!key->chain_id)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
break; break;
@ -595,30 +596,30 @@ keylist_colon_handler (void *priv, char *line)
assert (opd->tmp_uid == key->_last_uid); assert (opd->tmp_uid == key->_last_uid);
keysig = _gpgme_key_add_sig (key, (fields >= 10) ? field[9] : NULL); keysig = _gpgme_key_add_sig (key, (fields >= 10) ? field[9] : NULL);
if (!keysig) if (!keysig)
return GPGME_Out_Of_Core; return gpg_error (GPG_ERR_ENOMEM); /* FIXME */
/* Field 2 has the calculated trust ('!', '-', '?', '%'). */ /* Field 2 has the calculated trust ('!', '-', '?', '%'). */
if (fields >= 2) if (fields >= 2)
switch (field[1][0]) switch (field[1][0])
{ {
case '!': case '!':
keysig->status = GPGME_No_Error; keysig->status = gpg_error (GPG_ERR_NO_ERROR);
break; break;
case '-': case '-':
keysig->status = GPGME_Bad_Signature; keysig->status = gpg_error (GPG_ERR_BAD_SIGNATURE);
break; break;
case '?': case '?':
keysig->status = GPGME_No_Public_Key; keysig->status = gpg_error (GPG_ERR_NO_PUBKEY);
break; break;
case '%': case '%':
keysig->status = GPGME_General_Error; keysig->status = gpg_error (GPG_ERR_GENERAL);
break; break;
default: default:
keysig->status = GPGME_No_Error; keysig->status = gpg_error (GPG_ERR_NO_ERROR);
break; break;
} }
@ -779,10 +780,10 @@ gpgme_op_keylist_next (gpgme_ctx_t ctx, gpgme_key_t *r_key)
op_data_t opd; op_data_t opd;
if (!ctx || !r_key) if (!ctx || !r_key)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
*r_key = NULL; *r_key = NULL;
if (!ctx) if (!ctx)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = _gpgme_op_data_lookup (ctx, OPDATA_KEYLIST, &hook, -1, NULL); err = _gpgme_op_data_lookup (ctx, OPDATA_KEYLIST, &hook, -1, NULL);
opd = hook; opd = hook;
@ -796,7 +797,7 @@ gpgme_op_keylist_next (gpgme_ctx_t ctx, gpgme_key_t *r_key)
return err; return err;
if (!opd->key_cond) if (!opd->key_cond)
return GPGME_EOF; return gpg_error (GPG_ERR_EOF);
opd->key_cond = 0; opd->key_cond = 0;
assert (opd->key_queue); assert (opd->key_queue);
@ -817,7 +818,7 @@ gpgme_error_t
gpgme_op_keylist_end (gpgme_ctx_t ctx) gpgme_op_keylist_end (gpgme_ctx_t ctx)
{ {
if (!ctx) if (!ctx)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
return 0; return 0;
} }
@ -833,10 +834,10 @@ gpgme_get_key (gpgme_ctx_t ctx, const char *fpr, gpgme_key_t *r_key,
gpgme_error_t err; gpgme_error_t err;
if (!ctx || !r_key) if (!ctx || !r_key)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (strlen (fpr) < 16) /* We have at least a key ID. */ if (strlen (fpr) < 16) /* We have at least a key ID. */
return GPGME_Invalid_Key; return gpg_error (GPG_ERR_INV_VALUE);
/* FIXME: We use our own context because we have to avoid the user's /* FIXME: We use our own context because we have to avoid the user's
I/O callback handlers. */ I/O callback handlers. */

View File

@ -1,84 +0,0 @@
#!/bin/sh
# mkerrors - Extract error strings from gpgme.h
# and create C source for gpgme_strerror
# Copyright (C) 2000 Werner Koch (dd9jn)
# Copyright (C) 2001 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
cat <<EOF
/* Generated automatically by mkerrors */
/* Do not edit! */
#include <stdio.h>
#include "gpgme.h"
/**
* gpgme_strerror:
* @err: Error code
*
* This function returns a textual representaion of the given
* errocode. If this is an unknown value, a string with the value
* is returned (which is hold in a static buffer).
*
* Return value: String with the error description.
**/
const char *
gpgme_strerror (gpgme_error_t err)
{
const char *s;
static char buf[25];
switch (err) {
EOF
awk '
/GPGME_No_Error/ { okay=1 }
!okay {next}
/}/ { exit 0 }
/GPGME_[A-Za-z_]*/ { print_code($1) }
function print_code( s )
{
printf " case %s: s=\"", s ;
gsub(/_/, " ", s );
printf "%s\"; break;\n", substr(s,7);
}
'
cat <<EOF
default: sprintf (buf, "ec=%d", err ); s=buf; break;
}
return s;
}
EOF

View File

@ -46,7 +46,7 @@ _gpgme_op_data_lookup (gpgme_ctx_t ctx, ctx_op_data_id_t type, void **hook,
data = calloc (1, sizeof (struct ctx_op_data) + size); data = calloc (1, sizeof (struct ctx_op_data) + size);
if (!data) if (!data)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
data->next = ctx->op_data; data->next = ctx->op_data;
data->type = type; data->type = type;
data->cleanup = cleanup; data->cleanup = cleanup;
@ -71,8 +71,11 @@ _gpgme_op_reset (gpgme_ctx_t ctx, int type)
_gpgme_release_result (ctx); _gpgme_release_result (ctx);
/* Create an engine object. */ /* Create an engine object. */
if (ctx->engine)
{
_gpgme_engine_release (ctx->engine); _gpgme_engine_release (ctx->engine);
ctx->engine = NULL; ctx->engine = NULL;
}
err = _gpgme_engine_new (ctx->protocol, &ctx->engine); err = _gpgme_engine_new (ctx->protocol, &ctx->engine);
if (err) if (err)
return err; return err;
@ -118,7 +121,7 @@ _gpgme_parse_inv_userid (char *args, gpgme_invalid_user_id_t *userid)
inv_userid = malloc (sizeof (*inv_userid)); inv_userid = malloc (sizeof (*inv_userid));
if (!inv_userid) if (!inv_userid)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
inv_userid->next = NULL; inv_userid->next = NULL;
errno = 0; errno = 0;
reason = strtol (args, &tail, 0); reason = strtol (args, &tail, 0);
@ -126,54 +129,55 @@ _gpgme_parse_inv_userid (char *args, gpgme_invalid_user_id_t *userid)
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (inv_userid); free (inv_userid);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
switch (reason) switch (reason)
{ {
default: default:
case 0: case 0:
inv_userid->reason = GPGME_Unknown_Reason; inv_userid->reason = gpg_error (GPG_ERR_GENERAL);
break; break;
case 1: case 1:
inv_userid->reason = GPGME_Not_Found; inv_userid->reason = gpg_error (GPG_ERR_NO_PUBKEY);
break; break;
case 2: case 2:
inv_userid->reason = GPGME_Ambiguous_Specification; /* FIXME: Ambiguous specification. */
inv_userid->reason = gpg_error (GPG_ERR_AMBIGUOUS_NAME);
break; break;
case 3: case 3:
inv_userid->reason = GPGME_Wrong_Key_Usage; inv_userid->reason = gpg_error (GPG_ERR_WRONG_KEY_USAGE);
break; break;
case 4: case 4:
inv_userid->reason = GPGME_Key_Revoked; inv_userid->reason = gpg_error (GPG_ERR_CERT_REVOKED);
break; break;
case 5: case 5:
inv_userid->reason = GPGME_Key_Expired; inv_userid->reason = gpg_error (GPG_ERR_CERT_EXPIRED);
break; break;
case 6: case 6:
inv_userid->reason = GPGME_No_CRL_Known; inv_userid->reason = gpg_error (GPG_ERR_NO_CRL_KNOWN);
break; break;
case 7: case 7:
inv_userid->reason = GPGME_CRL_Too_Old; inv_userid->reason = gpg_error (GPG_ERR_CRL_TOO_OLD);
break; break;
case 8: case 8:
inv_userid->reason = GPGME_Policy_Mismatch; inv_userid->reason = gpg_error (GPG_ERR_NO_POLICY_MATCH);
break; break;
case 9: case 9:
inv_userid->reason = GPGME_No_Secret_Key; inv_userid->reason = gpg_error (GPG_ERR_NO_SECKEY);
break; break;
case 10: case 10:
inv_userid->reason = GPGME_Key_Not_Trusted; inv_userid->reason = gpg_error (GPG_ERR_PUBKEY_NOT_TRUSTED);
break; break;
} }
@ -184,8 +188,9 @@ _gpgme_parse_inv_userid (char *args, gpgme_invalid_user_id_t *userid)
inv_userid->id = strdup (tail); inv_userid->id = strdup (tail);
if (!inv_userid->id) if (!inv_userid->id)
{ {
int saved_errno = errno;
free (inv_userid); free (inv_userid);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
} }
else else

View File

@ -25,6 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "context.h" #include "context.h"
@ -76,7 +77,7 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code,
if (opd->uid_hint) if (opd->uid_hint)
free (opd->uid_hint); free (opd->uid_hint);
if (!(opd->uid_hint = strdup (args))) if (!(opd->uid_hint = strdup (args)))
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
break; break;
case GPGME_STATUS_BAD_PASSPHRASE: case GPGME_STATUS_BAD_PASSPHRASE:
@ -95,7 +96,7 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code,
free (opd->passphrase_info); free (opd->passphrase_info);
opd->passphrase_info = strdup (args); opd->passphrase_info = strdup (args);
if (!opd->passphrase_info) if (!opd->passphrase_info)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
break; break;
case GPGME_STATUS_MISSING_PASSPHRASE: case GPGME_STATUS_MISSING_PASSPHRASE:
@ -104,7 +105,7 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code,
case GPGME_STATUS_EOF: case GPGME_STATUS_EOF:
if (opd->no_passphrase || opd->bad_passphrase) if (opd->no_passphrase || opd->bad_passphrase)
return GPGME_Bad_Passphrase; return gpg_error (GPG_ERR_BAD_PASSPHRASE);
break; break;
default: default:

View File

@ -23,6 +23,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"
@ -44,7 +45,7 @@ _gpgme_progress_status_handler (void *priv, gpgme_status_code_t code,
args_cpy = strdup (args); args_cpy = strdup (args);
if (!args_cpy) if (!args_cpy)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
p = strchr (args_cpy, ' '); p = strchr (args_cpy, ' ');
if (p) if (p)

View File

@ -193,7 +193,7 @@ add_arg (engine_gpg_t gpg, const char *arg)
if (!a) if (!a)
{ {
gpg->arg_error = 1; gpg->arg_error = 1;
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
a->next = NULL; a->next = NULL;
a->data = NULL; a->data = NULL;
@ -216,7 +216,7 @@ add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound)
if (!a) if (!a)
{ {
gpg->arg_error = 1; gpg->arg_error = 1;
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
a->next = NULL; a->next = NULL;
a->data = data; a->data = data;
@ -335,16 +335,13 @@ static gpgme_error_t
gpg_new (void **engine) gpg_new (void **engine)
{ {
engine_gpg_t gpg; engine_gpg_t gpg;
int rc = 0; gpgme_error_t rc = 0;
gpg = calloc (1, sizeof *gpg); gpg = calloc (1, sizeof *gpg);
if (!gpg) if (!gpg)
{ return gpg_error_from_errno (errno);
rc = GPGME_Out_Of_Core;
goto leave;
}
gpg->argtail = &gpg->arglist;
gpg->argtail = &gpg->arglist;
gpg->status.fd[0] = -1; gpg->status.fd[0] = -1;
gpg->status.fd[1] = -1; gpg->status.fd[1] = -1;
gpg->colon.fd[0] = -1; gpg->colon.fd[0] = -1;
@ -360,14 +357,14 @@ gpg_new (void **engine)
gpg->status.buffer = malloc (gpg->status.bufsize); gpg->status.buffer = malloc (gpg->status.bufsize);
if (!gpg->status.buffer) if (!gpg->status.buffer)
{ {
rc = GPGME_Out_Of_Core; rc = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
/* In any case we need a status pipe - create it right here and /* In any case we need a status pipe - create it right here and
don't handle it with our generic gpgme_data_t mechanism. */ don't handle it with our generic gpgme_data_t mechanism. */
if (_gpgme_io_pipe (gpg->status.fd, 1) == -1) if (_gpgme_io_pipe (gpg->status.fd, 1) == -1)
{ {
rc = GPGME_Pipe_Error; rc = gpg_error_from_errno (errno);
goto leave; goto leave;
} }
if (_gpgme_io_set_close_notify (gpg->status.fd[0], if (_gpgme_io_set_close_notify (gpg->status.fd[0],
@ -375,7 +372,7 @@ gpg_new (void **engine)
|| _gpgme_io_set_close_notify (gpg->status.fd[1], || _gpgme_io_set_close_notify (gpg->status.fd[1],
close_notify_handler, gpg)) close_notify_handler, gpg))
{ {
rc = GPGME_General_Error; rc = gpg_error (GPG_ERR_GENERAL);
goto leave; goto leave;
} }
gpg->status.eof = 0; gpg->status.eof = 0;
@ -422,18 +419,19 @@ gpg_set_colon_line_handler (void *engine, engine_colon_line_handler_t fnc,
gpg->colon.readpos = 0; gpg->colon.readpos = 0;
gpg->colon.buffer = malloc (gpg->colon.bufsize); gpg->colon.buffer = malloc (gpg->colon.bufsize);
if (!gpg->colon.buffer) if (!gpg->colon.buffer)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1) if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1)
{ {
int saved_errno = errno;
free (gpg->colon.buffer); free (gpg->colon.buffer);
gpg->colon.buffer = NULL; gpg->colon.buffer = NULL;
return GPGME_Pipe_Error; return gpg_error_from_errno (saved_errno);
} }
if (_gpgme_io_set_close_notify (gpg->colon.fd[0], close_notify_handler, gpg) if (_gpgme_io_set_close_notify (gpg->colon.fd[0], close_notify_handler, gpg)
|| _gpgme_io_set_close_notify (gpg->colon.fd[1], || _gpgme_io_set_close_notify (gpg->colon.fd[1],
close_notify_handler, gpg)) close_notify_handler, gpg))
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
gpg->colon.eof = 0; gpg->colon.eof = 0;
gpg->colon.fnc = fnc; gpg->colon.fnc = fnc;
gpg->colon.fnc_value = fnc_value; gpg->colon.fnc_value = fnc_value;
@ -547,21 +545,23 @@ build_argv (engine_gpg_t gpg)
argv = calloc (argc + 1, sizeof *argv); argv = calloc (argc + 1, sizeof *argv);
if (!argv) if (!argv)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
fd_data_map = calloc (datac + 1, sizeof *fd_data_map); fd_data_map = calloc (datac + 1, sizeof *fd_data_map);
if (!fd_data_map) if (!fd_data_map)
{ {
int saved_errno = errno;
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
argc = datac = 0; argc = datac = 0;
argv[argc] = strdup ("gpg"); /* argv[0] */ argv[argc] = strdup ("gpg"); /* argv[0] */
if (!argv[argc]) if (!argv[argc])
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
argc++; argc++;
if (need_special) if (need_special)
@ -569,9 +569,10 @@ build_argv (engine_gpg_t gpg)
argv[argc] = strdup ("--enable-special-filenames"); argv[argc] = strdup ("--enable-special-filenames");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
argc++; argc++;
} }
@ -580,9 +581,10 @@ build_argv (engine_gpg_t gpg)
argv[argc] = strdup ("--use-agent"); argv[argc] = strdup ("--use-agent");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
argc++; argc++;
} }
@ -591,26 +593,29 @@ build_argv (engine_gpg_t gpg)
argv[argc] = strdup ("--batch"); argv[argc] = strdup ("--batch");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
argc++; argc++;
} }
argv[argc] = strdup ("--comment"); argv[argc] = strdup ("--comment");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
argc++; argc++;
argv[argc] = strdup (""); argv[argc] = strdup ("");
if (!argv[argc]) if (!argv[argc])
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
argc++; argc++;
for (a = gpg->arglist; a; a = a->next) for (a = gpg->arglist; a; a = a->next)
@ -627,9 +632,10 @@ build_argv (engine_gpg_t gpg)
if (_gpgme_io_pipe (fds, fd_data_map[datac].inbound ? 1 : 0) if (_gpgme_io_pipe (fds, fd_data_map[datac].inbound ? 1 : 0)
== -1) == -1)
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Pipe_Error; return gpg_error (saved_errno);
} }
if (_gpgme_io_set_close_notify (fds[0], if (_gpgme_io_set_close_notify (fds[0],
close_notify_handler, gpg) close_notify_handler, gpg)
@ -637,7 +643,7 @@ build_argv (engine_gpg_t gpg)
close_notify_handler, close_notify_handler,
gpg)) gpg))
{ {
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
} }
/* If the data_type is FD, we have to do a dup2 here. */ /* If the data_type is FD, we have to do a dup2 here. */
if (fd_data_map[datac].inbound) if (fd_data_map[datac].inbound)
@ -674,9 +680,10 @@ build_argv (engine_gpg_t gpg)
argv[argc] = malloc (25); argv[argc] = malloc (25);
if (!argv[argc]) if (!argv[argc])
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
sprintf (argv[argc], sprintf (argv[argc],
a->print_fd ? "%d" : "-&%d", a->print_fd ? "%d" : "-&%d",
@ -690,9 +697,10 @@ build_argv (engine_gpg_t gpg)
argv[argc] = strdup (a->arg); argv[argc] = strdup (a->arg);
if (!argv[argc]) if (!argv[argc])
{ {
int saved_errno = errno;
free (fd_data_map); free (fd_data_map);
free_argv (argv); free_argv (argv);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
argc++; argc++;
} }
@ -753,13 +761,13 @@ read_status (engine_gpg_t gpg)
bufsize += 1024; bufsize += 1024;
buffer = realloc (buffer, bufsize); buffer = realloc (buffer, bufsize);
if (!buffer) if (!buffer)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
nread = _gpgme_io_read (gpg->status.fd[0], nread = _gpgme_io_read (gpg->status.fd[0],
buffer + readpos, bufsize-readpos); buffer + readpos, bufsize-readpos);
if (nread == -1) if (nread == -1)
return GPGME_Read_Error; return gpg_error_from_errno (errno);
if (!nread) if (!nread)
{ {
@ -810,7 +818,7 @@ read_status (engine_gpg_t gpg)
free (gpg->cmd.keyword); free (gpg->cmd.keyword);
gpg->cmd.keyword = strdup (rest); gpg->cmd.keyword = strdup (rest);
if (!gpg->cmd.keyword) if (!gpg->cmd.keyword)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
/* This should be the last thing we have /* This should be the last thing we have
received and the next thing will be that received and the next thing will be that
the command handler does its action. */ the command handler does its action. */
@ -927,12 +935,12 @@ read_colon_line (engine_gpg_t gpg)
bufsize += 1024; bufsize += 1024;
buffer = realloc (buffer, bufsize); buffer = realloc (buffer, bufsize);
if (!buffer) if (!buffer)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
nread = _gpgme_io_read (gpg->colon.fd[0], buffer+readpos, bufsize-readpos); nread = _gpgme_io_read (gpg->colon.fd[0], buffer+readpos, bufsize-readpos);
if (nread == -1) if (nread == -1)
return GPGME_Read_Error; return gpg_error_from_errno (errno);
if (!nread) if (!nread)
{ {
@ -1009,20 +1017,21 @@ static gpgme_error_t
start (engine_gpg_t gpg) start (engine_gpg_t gpg)
{ {
gpgme_error_t rc; gpgme_error_t rc;
int saved_errno;
int i, n; int i, n;
int status; int status;
struct spawn_fd_item_s *fd_child_list, *fd_parent_list; struct spawn_fd_item_s *fd_child_list, *fd_parent_list;
if (!gpg) if (!gpg)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (! _gpgme_get_gpg_path ()) if (! _gpgme_get_gpg_path ())
return GPGME_Invalid_Engine; return gpg_error (GPG_ERR_INV_ENGINE);
/* Kludge, so that we don't need to check the return code of all the /* Kludge, so that we don't need to check the return code of all the
add_arg (). We bail out here instead. */ add_arg (). We bail out here instead. */
if (gpg->arg_error) if (gpg->arg_error)
return GPGME_Out_Of_Core; return gpg_error (GPG_ERR_ENOMEM);
rc = build_argv (gpg); rc = build_argv (gpg);
if (rc) if (rc)
@ -1033,7 +1042,7 @@ start (engine_gpg_t gpg)
n++; n++;
fd_child_list = calloc (n + n, sizeof *fd_child_list); fd_child_list = calloc (n + n, sizeof *fd_child_list);
if (!fd_child_list) if (!fd_child_list)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
fd_parent_list = fd_child_list + n; fd_parent_list = fd_child_list + n;
/* build the fd list for the child */ /* build the fd list for the child */
@ -1081,9 +1090,10 @@ start (engine_gpg_t gpg)
status = _gpgme_io_spawn (_gpgme_get_gpg_path (), status = _gpgme_io_spawn (_gpgme_get_gpg_path (),
gpg->argv, fd_child_list, fd_parent_list); gpg->argv, fd_child_list, fd_parent_list);
saved_errno = errno;
free (fd_child_list); free (fd_child_list);
if (status == -1) if (status == -1)
return GPGME_Exec_Error; return gpg_error_from_errno (errno);
/*_gpgme_register_term_handler ( closure, closure_value, pid );*/ /*_gpgme_register_term_handler ( closure, closure_value, pid );*/
@ -1169,7 +1179,7 @@ gpg_delete (void *engine, gpgme_key_t key, int allow_secret)
if (!err) if (!err)
{ {
if (!key->subkeys || !key->subkeys->fpr) if (!key->subkeys || !key->subkeys->fpr)
err = GPGME_Invalid_Key; return gpg_error (GPG_ERR_INV_VALUE);
else else
err = add_arg (gpg, key->subkeys->fpr); err = add_arg (gpg, key->subkeys->fpr);
} }
@ -1224,7 +1234,7 @@ gpg_edit (void *engine, gpgme_key_t key, gpgme_data_t out,
{ {
const char *s = key->subkeys ? key->subkeys->fpr : NULL; const char *s = key->subkeys ? key->subkeys->fpr : NULL;
if (!s) if (!s)
err = GPGME_Invalid_Key; err = gpg_error (GPG_ERR_INV_VALUE);
else else
err = add_arg (gpg, s); err = add_arg (gpg, s);
} }
@ -1244,7 +1254,7 @@ append_args_from_recipients (engine_gpg_t gpg, gpgme_key_t recp[])
while (recp[i]) while (recp[i])
{ {
if (!recp[i]->subkeys || !recp[i]->subkeys->fpr) if (!recp[i]->subkeys || !recp[i]->subkeys->fpr)
err = GPGME_Invalid_Key; err = gpg_error (GPG_ERR_INV_VALUE);
if (!err) if (!err)
err = add_arg (gpg, "-r"); err = add_arg (gpg, "-r");
if (!err) if (!err)
@ -1353,7 +1363,7 @@ gpg_export (void *engine, const char *pattern, unsigned int reserved,
gpgme_error_t err; gpgme_error_t err;
if (reserved) if (reserved)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = add_arg (gpg, "--export"); err = add_arg (gpg, "--export");
if (!err && use_armor) if (!err && use_armor)
@ -1381,7 +1391,7 @@ gpg_export_ext (void *engine, const char *pattern[], unsigned int reserved,
gpgme_error_t err; gpgme_error_t err;
if (reserved) if (reserved)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = add_arg (gpg, "--export"); err = add_arg (gpg, "--export");
if (!err && use_armor) if (!err && use_armor)
@ -1412,14 +1422,14 @@ gpg_genkey (void *engine, gpgme_data_t help_data, int use_armor,
gpgme_error_t err; gpgme_error_t err;
if (!gpg) if (!gpg)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
/* We need a special mechanism to get the fd of a pipe here, so that /* We need a special mechanism to get the fd of a pipe here, so that
we can use this for the %pubring and %secring parameters. We we can use this for the %pubring and %secring parameters. We
don't have this yet, so we implement only the adding to the don't have this yet, so we implement only the adding to the
standard keyrings. */ standard keyrings. */
if (pubkey || seckey) if (pubkey || seckey)
return err = GPGME_Not_Implemented; return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
err = add_arg (gpg, "--gen-key"); err = add_arg (gpg, "--gen-key");
if (!err && use_armor) if (!err && use_armor)
@ -1491,7 +1501,7 @@ gpg_keylist_ext (void *engine, const char *pattern[], int secret_only,
gpgme_error_t err; gpgme_error_t err;
if (reserved) if (reserved)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = add_arg (gpg, "--with-colons"); err = add_arg (gpg, "--with-colons");
if (!err) if (!err)

View File

@ -93,7 +93,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
sig = malloc (sizeof (*sig)); sig = malloc (sizeof (*sig));
if (!sig) if (!sig)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
sig->next = NULL; sig->next = NULL;
switch (*args) switch (*args)
@ -113,14 +113,14 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
default: default:
/* The backend engine is not behaving. */ /* The backend engine is not behaving. */
free (sig); free (sig);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
args++; args++;
if (*args != ' ') if (*args != ' ')
{ {
free (sig); free (sig);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
errno = 0; errno = 0;
@ -129,7 +129,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); free (sig);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -138,7 +138,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); free (sig);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -147,7 +147,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); free (sig);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
@ -156,7 +156,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); free (sig);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
args = tail; args = tail;
while (*args == ' ') while (*args == ' ')
@ -166,7 +166,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
{ {
/* The crypto backend does not behave. */ /* The crypto backend does not behave. */
free (sig); free (sig);
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
tail = strchr (args, ' '); tail = strchr (args, ' ');
@ -176,8 +176,9 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
sig->fpr = strdup (args); sig->fpr = strdup (args);
if (!sig->fpr) if (!sig->fpr)
{ {
int saved_errno = errno;
free (sig); free (sig);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
*sigp = sig; *sigp = sig;
return 0; return 0;
@ -221,7 +222,7 @@ _gpgme_sign_status_handler (void *priv, gpgme_status_code_t code, char *args)
case GPGME_STATUS_EOF: case GPGME_STATUS_EOF:
if (opd->result.invalid_signers) if (opd->result.invalid_signers)
return GPGME_Invalid_UserID; return gpg_error (GPG_ERR_INV_USER_ID);
break; break;
default: default:
@ -273,12 +274,12 @@ sign_start (gpgme_ctx_t ctx, int synchronous, gpgme_data_t plain,
if (mode != GPGME_SIG_MODE_NORMAL && mode != GPGME_SIG_MODE_DETACH if (mode != GPGME_SIG_MODE_NORMAL && mode != GPGME_SIG_MODE_DETACH
&& mode != GPGME_SIG_MODE_CLEAR) && mode != GPGME_SIG_MODE_CLEAR)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (!plain) if (!plain)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
if (!sig) if (!sig)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (ctx->passphrase_cb) if (ctx->passphrase_cb)
{ {

View File

@ -25,6 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"
@ -53,7 +54,7 @@ gpgme_error_t
gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key) gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key)
{ {
if (!ctx || !key) if (!ctx || !key)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
if (ctx->signers_len == ctx->signers_size) if (ctx->signers_len == ctx->signers_size)
{ {
@ -63,7 +64,7 @@ gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key)
newarr = realloc (ctx->signers, n * sizeof (*newarr)); newarr = realloc (ctx->signers, n * sizeof (*newarr));
if (!newarr) if (!newarr)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
for (j = ctx->signers_size; j < n; j++) for (j = ctx->signers_size; j < n; j++)
newarr[j] = NULL; newarr[j] = NULL;
ctx->signers = newarr; ctx->signers = newarr;

View File

@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "util.h" #include "util.h"
#include "ops.h" #include "ops.h"
@ -44,7 +45,7 @@ _gpgme_trust_item_new (gpgme_trust_item_t *r_item)
item = calloc (1, sizeof *item); item = calloc (1, sizeof *item);
if (!item) if (!item)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
item->_refs = 1; item->_refs = 1;
item->keyid = item->_keyid; item->keyid = item->_keyid;
item->_keyid[16] = '\0'; item->_keyid[16] = '\0';

View File

@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "util.h" #include "util.h"
@ -106,9 +107,11 @@ trustlist_colon_handler (void *priv, char *line)
break; break;
case 9: /* user ID */ case 9: /* user ID */
item->name = strdup (p); item->name = strdup (p);
if (!item->name) { if (!item->name)
{
int saved_errno = errno;
gpgme_trust_item_unref (item); gpgme_trust_item_unref (item);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
break; break;
} }
@ -170,7 +173,7 @@ gpgme_op_trustlist_start (gpgme_ctx_t ctx, const char *pattern, int max_level)
op_data_t opd; op_data_t opd;
if (!pattern || !*pattern) if (!pattern || !*pattern)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = _gpgme_op_reset (ctx, 2); err = _gpgme_op_reset (ctx, 2);
if (err) if (err)
@ -202,10 +205,10 @@ gpgme_op_trustlist_next (gpgme_ctx_t ctx, gpgme_trust_item_t *r_item)
struct trust_queue_item_s *q; struct trust_queue_item_s *q;
if (!r_item) if (!r_item)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
*r_item = NULL; *r_item = NULL;
if (!ctx) if (!ctx)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
err = _gpgme_op_data_lookup (ctx, OPDATA_TRUSTLIST, &hook, -1, NULL); err = _gpgme_op_data_lookup (ctx, OPDATA_TRUSTLIST, &hook, -1, NULL);
opd = hook; opd = hook;
@ -218,7 +221,7 @@ gpgme_op_trustlist_next (gpgme_ctx_t ctx, gpgme_trust_item_t *r_item)
if (err) if (err)
return err; return err;
if (!opd->trust_cond) if (!opd->trust_cond)
return GPGME_EOF; return gpg_error (GPG_ERR_EOF);
opd->trust_cond = 0; opd->trust_cond = 0;
assert (opd->trust_queue); assert (opd->trust_queue);
} }
@ -236,7 +239,7 @@ gpgme_error_t
gpgme_op_trustlist_end (gpgme_ctx_t ctx) gpgme_op_trustlist_end (gpgme_ctx_t ctx)
{ {
if (!ctx) if (!ctx)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
return 0; return 0;
} }

View File

@ -94,38 +94,38 @@ calc_sig_summary (gpgme_signature_t sig)
if (sig->validity == GPGME_VALIDITY_FULL if (sig->validity == GPGME_VALIDITY_FULL
|| sig->validity == GPGME_VALIDITY_ULTIMATE) || sig->validity == GPGME_VALIDITY_ULTIMATE)
{ {
if (sig->status == GPGME_No_Error if (gpg_err_code (sig->status) == GPG_ERR_NO_ERROR
|| sig->status == GPGME_Sig_Expired || gpg_err_code (sig->status) == GPG_ERR_SIG_EXPIRED
|| sig->status == GPGME_Key_Expired) || gpg_err_code (sig->status) == GPG_ERR_KEY_EXPIRED)
sum |= GPGME_SIGSUM_GREEN; sum |= GPGME_SIGSUM_GREEN;
} }
else if (sig->validity == GPGME_VALIDITY_NEVER) else if (sig->validity == GPGME_VALIDITY_NEVER)
{ {
if (sig->status == GPGME_No_Error if (gpg_err_code (sig->status) == GPG_ERR_NO_ERROR
|| sig->status == GPGME_Sig_Expired || gpg_err_code (sig->status) == GPG_ERR_SIG_EXPIRED
|| sig->status == GPGME_Key_Expired) || gpg_err_code (sig->status) == GPG_ERR_KEY_EXPIRED)
sum |= GPGME_SIGSUM_RED; sum |= GPGME_SIGSUM_RED;
} }
else if (sig->status == GPGME_Bad_Signature) else if (gpg_err_code (sig->status) == GPG_ERR_BAD_SIGNATURE)
sum |= GPGME_SIGSUM_RED; sum |= GPGME_SIGSUM_RED;
/* FIXME: handle the case when key and message are expired. */ /* FIXME: handle the case when key and message are expired. */
switch (sig->status) switch (gpg_err_code (sig->status))
{ {
case GPGME_Sig_Expired: case GPG_ERR_SIG_EXPIRED:
sum |= GPGME_SIGSUM_SIG_EXPIRED; sum |= GPGME_SIGSUM_SIG_EXPIRED;
break; break;
case GPGME_Key_Expired: case GPG_ERR_KEY_EXPIRED:
sum |= GPGME_SIGSUM_KEY_EXPIRED; sum |= GPGME_SIGSUM_KEY_EXPIRED;
break; break;
case GPGME_No_Public_Key: case GPG_ERR_NO_PUBKEY:
sum |= GPGME_SIGSUM_KEY_MISSING; sum |= GPGME_SIGSUM_KEY_MISSING;
break; break;
case GPGME_Bad_Signature: case GPG_ERR_BAD_SIGNATURE:
case GPGME_No_Error: case GPG_ERR_NO_ERROR:
break; break;
default: default:
@ -159,29 +159,30 @@ parse_new_sig (op_data_t opd, gpgme_status_code_t code, char *args)
sig = calloc (1, sizeof (*sig)); sig = calloc (1, sizeof (*sig));
if (!sig) if (!sig)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
if (!opd->result.signatures) if (!opd->result.signatures)
opd->result.signatures = sig; opd->result.signatures = sig;
if (opd->current_sig) if (opd->current_sig)
opd->current_sig->next = sig; opd->current_sig->next = sig;
opd->current_sig = sig; opd->current_sig = sig;
/* FIXME: We should set the source of the state. */
switch (code) switch (code)
{ {
case GPGME_STATUS_GOODSIG: case GPGME_STATUS_GOODSIG:
sig->status = GPGME_No_Error; sig->status = gpg_error (GPG_ERR_NO_ERROR);
break; break;
case GPGME_STATUS_EXPSIG: case GPGME_STATUS_EXPSIG:
sig->status = GPGME_Sig_Expired; sig->status = gpg_error (GPG_ERR_SIG_EXPIRED);
break; break;
case GPGME_STATUS_EXPKEYSIG: case GPGME_STATUS_EXPKEYSIG:
sig->status = GPGME_Key_Expired; sig->status = gpg_error (GPG_ERR_KEY_EXPIRED);
break; break;
case GPGME_STATUS_BADSIG: case GPGME_STATUS_BADSIG:
sig->status = GPGME_Bad_Signature; sig->status = gpg_error (GPG_ERR_BAD_SIGNATURE);
break; break;
case GPGME_STATUS_ERRSIG: case GPGME_STATUS_ERRSIG:
@ -202,31 +203,31 @@ parse_new_sig (op_data_t opd, gpgme_status_code_t code, char *args)
switch (end[0]) switch (end[0])
{ {
case '4': case '4':
sig->status = GPGME_Unsupported_Algorithm; sig->status = gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM);
break; break;
case 9: case 9:
sig->status = GPGME_No_Public_Key; sig->status = gpg_error (GPG_ERR_NO_PUBKEY);
break; break;
default: default:
sig->status = GPGME_General_Error; sig->status = gpg_error (GPG_ERR_GENERAL);
} }
} }
} }
else else
sig->status = GPGME_General_Error; sig->status = gpg_error (GPG_ERR_GENERAL);
break; break;
default: default:
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
} }
if (*args) if (*args)
{ {
sig->fpr = strdup (args); sig->fpr = strdup (args);
if (!sig->fpr) if (!sig->fpr)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
return 0; return 0;
} }
@ -245,13 +246,13 @@ parse_valid_sig (gpgme_signature_t sig, char *args)
if (!*args) if (!*args)
/* We require at least the fingerprint. */ /* We require at least the fingerprint. */
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
if (sig->fpr) if (sig->fpr)
free (sig->fpr); free (sig->fpr);
sig->fpr = strdup (args); sig->fpr = strdup (args);
if (!sig->fpr) if (!sig->fpr)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
end = strchr (end, ' '); end = strchr (end, ' ');
if (end) if (end)
@ -260,12 +261,12 @@ parse_valid_sig (gpgme_signature_t sig, char *args)
errno = 0; errno = 0;
sig->timestamp = strtol (end, &tail, 0); sig->timestamp = strtol (end, &tail, 0);
if (errno || end == tail || (*tail && *tail != ' ')) if (errno || end == tail || (*tail && *tail != ' '))
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
end = tail; end = tail;
sig->exp_timestamp = strtol (end, &tail, 0); sig->exp_timestamp = strtol (end, &tail, 0);
if (errno || end == tail || (*tail && *tail != ' ')) if (errno || end == tail || (*tail && *tail != ' '))
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
} }
return 0; return 0;
} }
@ -294,11 +295,11 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args)
if (notation) if (notation)
/* There is another notation name without data for the /* There is another notation name without data for the
previous one. The crypto backend misbehaves. */ previous one. The crypto backend misbehaves. */
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
notation = malloc (sizeof (*sig)); notation = malloc (sizeof (*sig));
if (!notation) if (!notation)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
notation->next = NULL; notation->next = NULL;
if (code == GPGME_STATUS_NOTATION_NAME) if (code == GPGME_STATUS_NOTATION_NAME)
@ -308,8 +309,9 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args)
notation->name = malloc (len); notation->name = malloc (len);
if (!notation->name) if (!notation->name)
{ {
int saved_errno = errno;
free (notation); free (notation);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
err = _gpgme_decode_percent_string (args, &notation->name, len); err = _gpgme_decode_percent_string (args, &notation->name, len);
if (err) if (err)
@ -325,8 +327,9 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args)
notation->value = malloc (len); notation->value = malloc (len);
if (!notation->value) if (!notation->value)
{ {
int saved_errno = errno;
free (notation); free (notation);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
err = _gpgme_decode_percent_string (args, &notation->value, len); err = _gpgme_decode_percent_string (args, &notation->value, len);
if (err) if (err)
@ -349,20 +352,20 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args)
if (!notation || !notation->name) if (!notation || !notation->name)
/* There is notation data without a previous notation /* There is notation data without a previous notation
name. The crypto backend misbehaves. */ name. The crypto backend misbehaves. */
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
if (!notation->value) if (!notation->value)
{ {
dest = notation->value = malloc (len); dest = notation->value = malloc (len);
if (!dest) if (!dest)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
} }
else else
{ {
int cur_len = strlen (notation->value); int cur_len = strlen (notation->value);
dest = realloc (notation->value, len + strlen (notation->value)); dest = realloc (notation->value, len + strlen (notation->value));
if (!dest) if (!dest)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
notation->value = dest; notation->value = dest;
dest += cur_len; dest += cur_len;
} }
@ -372,7 +375,7 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args)
return err; return err;
} }
else else
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
return 0; return 0;
} }
@ -432,13 +435,14 @@ parse_error (gpgme_signature_t sig, char *args)
where = args; where = args;
} }
else else
return GPGME_General_Error; return gpg_error (GPG_ERR_INV_ENGINE);
err = _gpgme_map_gnupg_error (which); err = _gpgme_map_gnupg_error (which);
if (!strcmp (where, "verify.findkey")) if (!strcmp (where, "verify.findkey"))
sig->status = err; sig->status = err;
else if (!strcmp (where, "verify.keyusage") && err == GPGME_Wrong_Key_Usage) else if (!strcmp (where, "verify.keyusage")
&& gpg_err_code (err) == GPG_ERR_WRONG_KEY_USAGE)
sig->wrong_key_usage = 1; sig->wrong_key_usage = 1;
return 0; return 0;
@ -473,34 +477,37 @@ _gpgme_verify_status_handler (void *priv, gpgme_status_code_t code, char *args)
return parse_new_sig (opd, code, args); return parse_new_sig (opd, code, args);
case GPGME_STATUS_VALIDSIG: case GPGME_STATUS_VALIDSIG:
return sig ? parse_valid_sig (sig, args) : GPGME_General_Error; return sig ? parse_valid_sig (sig, args)
: gpg_error (GPG_ERR_INV_ENGINE);
case GPGME_STATUS_NODATA: case GPGME_STATUS_NODATA:
if (!sig) if (!sig)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
sig->status = GPGME_No_Data; sig->status = gpg_error (GPG_ERR_NO_DATA);
break; break;
case GPGME_STATUS_UNEXPECTED: case GPGME_STATUS_UNEXPECTED:
if (!sig) if (!sig)
return GPGME_General_Error; return gpg_error (GPG_ERR_GENERAL);
sig->status = GPGME_No_Data; sig->status = gpg_error (GPG_ERR_NO_DATA);
break; break;
case GPGME_STATUS_NOTATION_NAME: case GPGME_STATUS_NOTATION_NAME:
case GPGME_STATUS_NOTATION_DATA: case GPGME_STATUS_NOTATION_DATA:
case GPGME_STATUS_POLICY_URL: case GPGME_STATUS_POLICY_URL:
return sig ? parse_notation (sig, code, args) : GPGME_General_Error; return sig ? parse_notation (sig, code, args)
: gpg_error (GPG_ERR_INV_ENGINE);
case GPGME_STATUS_TRUST_UNDEFINED: case GPGME_STATUS_TRUST_UNDEFINED:
case GPGME_STATUS_TRUST_NEVER: case GPGME_STATUS_TRUST_NEVER:
case GPGME_STATUS_TRUST_MARGINAL: case GPGME_STATUS_TRUST_MARGINAL:
case GPGME_STATUS_TRUST_FULLY: case GPGME_STATUS_TRUST_FULLY:
case GPGME_STATUS_TRUST_ULTIMATE: case GPGME_STATUS_TRUST_ULTIMATE:
return sig ? parse_trust (sig, code, args) : GPGME_General_Error; return sig ? parse_trust (sig, code, args)
: gpg_error (GPG_ERR_INV_ENGINE);
case GPGME_STATUS_ERROR: case GPGME_STATUS_ERROR:
return sig ? parse_error (sig, args) : GPGME_General_Error; return sig ? parse_error (sig, args) : gpg_error (GPG_ERR_INV_ENGINE);
case GPGME_STATUS_EOF: case GPGME_STATUS_EOF:
if (sig) if (sig)
@ -550,9 +557,9 @@ verify_start (gpgme_ctx_t ctx, int synchronous, gpgme_data_t sig,
_gpgme_engine_set_status_handler (ctx->engine, verify_status_handler, ctx); _gpgme_engine_set_status_handler (ctx->engine, verify_status_handler, ctx);
if (!sig) if (!sig)
return GPGME_No_Data; return gpg_error (GPG_ERR_NO_DATA);
if (!signed_text && !plaintext) if (!signed_text && !plaintext)
return GPGME_Invalid_Value; return gpg_error (GPG_ERR_INV_VALUE);
return _gpgme_engine_op_verify (ctx->engine, sig, signed_text, plaintext); return _gpgme_engine_op_verify (ctx->engine, sig, signed_text, plaintext);
} }
@ -602,7 +609,7 @@ gpgme_get_sig_key (gpgme_ctx_t ctx, int idx, gpgme_key_t *r_key)
idx--; idx--;
} }
if (!sig || idx) if (!sig || idx)
return GPGME_EOF; return gpg_error (GPG_ERR_EOF);
return gpgme_get_key (ctx, sig->fpr, r_key, 0); return gpgme_get_key (ctx, sig->fpr, r_key, 0);
} }
@ -631,29 +638,29 @@ const char *gpgme_get_sig_status (gpgme_ctx_t ctx, int idx,
if (r_stat) if (r_stat)
{ {
switch (sig->status) switch (gpg_err_code (sig->status))
{ {
case GPGME_No_Error: case GPG_ERR_NO_ERROR:
*r_stat = GPGME_SIG_STAT_GOOD; *r_stat = GPGME_SIG_STAT_GOOD;
break; break;
case GPGME_Bad_Signature: case GPG_ERR_BAD_SIGNATURE:
*r_stat = GPGME_SIG_STAT_BAD; *r_stat = GPGME_SIG_STAT_BAD;
break; break;
case GPGME_No_Public_Key: case GPG_ERR_NO_PUBKEY:
*r_stat = GPGME_SIG_STAT_NOKEY; *r_stat = GPGME_SIG_STAT_NOKEY;
break; break;
case GPGME_No_Data: case GPG_ERR_NO_DATA:
*r_stat = GPGME_SIG_STAT_NOSIG; *r_stat = GPGME_SIG_STAT_NOSIG;
break; break;
case GPGME_Sig_Expired: case GPG_ERR_SIG_EXPIRED:
*r_stat = GPGME_SIG_STAT_GOOD_EXP; *r_stat = GPGME_SIG_STAT_GOOD_EXP;
break; break;
case GPGME_Key_Expired: case GPG_ERR_KEY_EXPIRED:
*r_stat = GPGME_SIG_STAT_GOOD_EXPKEY; *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY;
break; break;
@ -701,24 +708,24 @@ unsigned long gpgme_get_sig_ulong_attr (gpgme_ctx_t ctx, int idx,
return (unsigned long) sig->validity; return (unsigned long) sig->validity;
case GPGME_ATTR_SIG_STATUS: case GPGME_ATTR_SIG_STATUS:
switch (sig->status) switch (gpg_err_code (sig->status))
{ {
case GPGME_No_Error: case GPG_ERR_NO_ERROR:
return GPGME_SIG_STAT_GOOD; return GPGME_SIG_STAT_GOOD;
case GPGME_Bad_Signature: case GPG_ERR_BAD_SIGNATURE:
return GPGME_SIG_STAT_BAD; return GPGME_SIG_STAT_BAD;
case GPGME_No_Public_Key: case GPG_ERR_NO_PUBKEY:
return GPGME_SIG_STAT_NOKEY; return GPGME_SIG_STAT_NOKEY;
case GPGME_No_Data: case GPG_ERR_NO_DATA:
return GPGME_SIG_STAT_NOSIG; return GPGME_SIG_STAT_NOSIG;
case GPGME_Sig_Expired: case GPG_ERR_SIG_EXPIRED:
return GPGME_SIG_STAT_GOOD_EXP; return GPGME_SIG_STAT_GOOD_EXP;
case GPGME_Key_Expired: case GPG_ERR_KEY_EXPIRED:
return GPGME_SIG_STAT_GOOD_EXPKEY; return GPGME_SIG_STAT_GOOD_EXPKEY;
default: default:

View File

@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "sema.h" #include "sema.h"
@ -92,7 +93,7 @@ ctx_active (gpgme_ctx_t ctx)
{ {
struct ctx_list_item *li = malloc (sizeof (struct ctx_list_item)); struct ctx_list_item *li = malloc (sizeof (struct ctx_list_item));
if (!li) if (!li)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
li->ctx = ctx; li->ctx = ctx;
LOCK (ctx_list_lock); LOCK (ctx_list_lock);
@ -266,9 +267,10 @@ gpgme_wait (gpgme_ctx_t ctx, gpgme_error_t *status, int hang)
fdt.fds = malloc (i * sizeof (struct io_select_fd_s)); fdt.fds = malloc (i * sizeof (struct io_select_fd_s));
if (!fdt.fds) if (!fdt.fds)
{ {
int saved_errno = errno;
UNLOCK (ctx_list_lock); UNLOCK (ctx_list_lock);
if (status) if (status)
*status = GPGME_Out_Of_Core; *status = gpg_error_from_errno (saved_errno);
return NULL; return NULL;
} }
fdt.size = i; fdt.size = i;
@ -284,9 +286,10 @@ gpgme_wait (gpgme_ctx_t ctx, gpgme_error_t *status, int hang)
nr = _gpgme_io_select (fdt.fds, fdt.size, 0); nr = _gpgme_io_select (fdt.fds, fdt.size, 0);
if (nr < 0) if (nr < 0)
{ {
int saved_errno = errno;
free (fdt.fds); free (fdt.fds);
if (status) if (status)
*status = GPGME_File_Error; *status = gpg_error_from_errno (saved_errno);
return NULL; return NULL;
} }

View File

@ -22,6 +22,7 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "gpgme.h" #include "gpgme.h"
#include "context.h" #include "context.h"
@ -86,7 +87,7 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond)
signal it. */ signal it. */
int idx; int idx;
err = GPGME_File_Error; err = gpg_error_from_errno (errno);
for (idx = 0; idx < ctx->fdt.size; idx++) for (idx = 0; idx < ctx->fdt.size; idx++)
if (ctx->fdt.fds[idx].fd != -1) if (ctx->fdt.fds[idx].fd != -1)
_gpgme_io_close (ctx->fdt.fds[idx].fd); _gpgme_io_close (ctx->fdt.fds[idx].fd);

View File

@ -70,7 +70,7 @@ fd_table_put (fd_table_t fdt, int fd, int dir, void *opaque, int *idx)
new_fds = realloc (fdt->fds, (fdt->size + FDT_ALLOCSIZE) new_fds = realloc (fdt->fds, (fdt->size + FDT_ALLOCSIZE)
* sizeof (*new_fds)); * sizeof (*new_fds));
if (!new_fds) if (!new_fds)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
fdt->fds = new_fds; fdt->fds = new_fds;
fdt->size += FDT_ALLOCSIZE; fdt->size += FDT_ALLOCSIZE;
@ -111,15 +111,16 @@ _gpgme_add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc,
tag = malloc (sizeof *tag); tag = malloc (sizeof *tag);
if (!tag) if (!tag)
return GPGME_Out_Of_Core; return gpg_error_from_errno (errno);
tag->ctx = ctx; tag->ctx = ctx;
/* Allocate a structure to hold information about the handler. */ /* Allocate a structure to hold information about the handler. */
item = calloc (1, sizeof *item); item = calloc (1, sizeof *item);
if (!item) if (!item)
{ {
int saved_errno = errno;
free (tag); free (tag);
return GPGME_Out_Of_Core; return gpg_error_from_errno (saved_errno);
} }
item->ctx = ctx; item->ctx = ctx;
item->dir = dir; item->dir = dir;

View File

@ -1,3 +1,12 @@
2003-06-06 Marcus Brinkmann <marcus@g10code.de>
Everywhere: Use libgpg-error error codes.
* gpg/Makefile.am (noinst_HEADERS): New variable.
* gpg/t-support.h: New file.
* gpgsm/Makefile.am (noinst_HEADERS): New variable.
* gpgsm/t-support.h: New file.
2003-05-29 Marcus Brinkmann <marcus@g10code.de> 2003-05-29 Marcus Brinkmann <marcus@g10code.de>
* gpg/t-encrypt-sym.c (main): Adapt to new syntax. * gpg/t-encrypt-sym.c (main): Adapt to new syntax.

View File

@ -24,6 +24,7 @@ GPG = @GPG@
TESTS_ENVIRONMENT = GNUPGHOME=. GPG_AGENT_INFO= TESTS_ENVIRONMENT = GNUPGHOME=. GPG_AGENT_INFO=
# The keylist tests must come after the import and the edit test. # The keylist tests must come after the import and the edit test.
noinst_HEADERS = t-support.h
TESTS = t-encrypt t-encrypt-sym t-encrypt-sign t-sign t-signers \ TESTS = t-encrypt t-encrypt-sym t-encrypt-sign t-sign t-signers \
t-decrypt t-verify t-decrypt-verify \ t-decrypt t-verify t-decrypt-verify \
t-export t-import t-trustlist t-eventloop t-edit \ t-export t-import t-trustlist t-eventloop t-edit \

View File

@ -26,68 +26,9 @@
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
static gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
}
static char *
make_filename (const char *fname)
{
const char *srcdir = getenv ("srcdir");
char *buf;
if (!srcdir)
srcdir = ".";
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
if (!buf)
{
fprintf (stderr, "%s:%d: could not allocate string: %s\n",
__FILE__, __LINE__, strerror (errno));
exit (1);
}
strcpy (buf, srcdir);
strcat (buf, "/");
strcat (buf, fname);
return buf;
}
static void static void
check_verify_result (gpgme_verify_result_t result, int summary, char *fpr, check_verify_result (gpgme_verify_result_t result, int summary, char *fpr,
gpgme_error_t status) gpgme_error_t status)
@ -113,7 +54,7 @@ check_verify_result (gpgme_verify_result_t result, int summary, char *fpr,
__FILE__, __LINE__, sig->fpr); __FILE__, __LINE__, sig->fpr);
exit (1); exit (1);
} }
if (sig->status != status) if (gpg_err_code (sig->status) != status)
{ {
fprintf (stderr, "%s:%i: Unexpected signature status: %s\n", fprintf (stderr, "%s:%i: Unexpected signature status: %s\n",
__FILE__, __LINE__, gpgme_strerror (sig->status)); __FILE__, __LINE__, gpgme_strerror (sig->status));
@ -137,7 +78,7 @@ check_verify_result (gpgme_verify_result_t result, int summary, char *fpr,
__FILE__, __LINE__, sig->validity); __FILE__, __LINE__, sig->validity);
exit (1); exit (1);
} }
if (sig->validity_reason != GPGME_No_Error) if (gpg_err_code (sig->validity_reason) != GPG_ERR_NO_ERROR)
{ {
fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n", fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n",
__FILE__, __LINE__, gpgme_strerror (sig->validity_reason)); __FILE__, __LINE__, gpgme_strerror (sig->validity_reason));
@ -182,7 +123,7 @@ main (int argc, char *argv[])
verify_result = gpgme_op_verify_result (ctx); verify_result = gpgme_op_verify_result (ctx);
check_verify_result (verify_result, 0, check_verify_result (verify_result, 0,
"A0FF4590BB6122EDEF6E3C542D727CC768697734", "A0FF4590BB6122EDEF6E3C542D727CC768697734",
GPGME_No_Error); GPG_ERR_NO_ERROR);
gpgme_data_release (in); gpgme_data_release (in);
gpgme_data_release (out); gpgme_data_release (out);

View File

@ -1,4 +1,4 @@
/* t-decrypt.c - regression test /* t-decrypt.c - Regression test.
Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2003 g10 Code GmbH Copyright (C) 2001, 2003 g10 Code GmbH
@ -26,67 +26,9 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
static gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
}
static char *
make_filename (const char *fname)
{
const char *srcdir = getenv ("srcdir");
char *buf;
if (!srcdir)
srcdir = ".";
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
if (!buf)
{
fprintf (stderr, "%s:%d: could not allocate string: %s\n",
__FILE__, __LINE__, strerror (errno));
exit (1);
}
strcpy (buf, srcdir);
strcat (buf, "/");
strcat (buf, fname);
return buf;
}
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {

View File

@ -1,23 +1,22 @@
/* t-edit.c - regression test /* t-edit.c - Regression test.
* Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001, 2002, 2003 g10 Code GmbH Copyright (C) 2001, 2002, 2003 g10 Code GmbH
*
* This file is part of GPGME. This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify GPGME is free software; you can redistribute it and/or modify it
* it under the terms of the GNU General Public License as published by under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, GPGME is distributed in the hope that it will be useful, but
* but WITHOUT ANY WARRANTY; without even the implied warranty of WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* GNU General Public License for more details. General Public License for more details.
*
* You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software along with GPGME; if not, write to the Free Software Foundation,
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -25,23 +24,13 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include <gpgme.h> #include <gpgme.h>
struct passphrase_cb_info_s { #include "t-support.h"
gpgme_ctx_t c;
int did_it;
};
#define fail_if_err(a) do { if(a) { int my_errno = errno; \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror(a)); \
if ((a) == GPGME_File_Error) \
fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \
exit (1); } \
} while(0)
static void static void
flush_data (gpgme_data_t dh) flush_data (gpgme_data_t dh)
{ {
@ -50,20 +39,11 @@ flush_data (gpgme_data_t dh)
ret = gpgme_data_seek (dh, 0, SEEK_SET); ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret) if (ret)
fail_if_err (GPGME_File_Error); fail_if_err (gpg_error_from_errno (errno));
while ((ret = gpgme_data_read (dh, buf, 100)) > 0) while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
fwrite (buf, ret, 1, stdout); fwrite (buf, ret, 1, stdout);
if (ret < 0) if (ret < 0)
fail_if_err (GPGME_File_Error); fail_if_err (gpg_error_from_errno (errno));
}
static gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
} }
@ -130,24 +110,17 @@ main (int argc, char **argv)
gpgme_error_t err; gpgme_error_t err;
gpgme_data_t out = NULL; gpgme_data_t out = NULL;
gpgme_key_t key = NULL; gpgme_key_t key = NULL;
struct passphrase_cb_info_s info;
const char *pattern = "Alpha"; const char *pattern = "Alpha";
char *p; char *agent_info;
do
{
err = gpgme_new (&ctx); err = gpgme_new (&ctx);
fail_if_err (err); fail_if_err (err);
err = gpgme_data_new (&out); err = gpgme_data_new (&out);
fail_if_err (err); fail_if_err (err);
p = getenv("GPG_AGENT_INFO"); agent_info = getenv("GPG_AGENT_INFO");
if (!(p && strchr (p, ':'))) if (!(agent_info && strchr (agent_info, ':')))
{ gpgme_set_passphrase_cb (ctx, passphrase_cb, 0);
memset (&info, 0, sizeof info);
info.c = ctx;
gpgme_set_passphrase_cb (ctx, passphrase_cb, &info);
}
err = gpgme_op_keylist_start (ctx, pattern, 0); err = gpgme_op_keylist_start (ctx, pattern, 0);
fail_if_err (err); fail_if_err (err);
@ -165,8 +138,6 @@ main (int argc, char **argv)
gpgme_data_release (out); gpgme_data_release (out);
gpgme_key_unref (key); gpgme_key_unref (key);
gpgme_release (ctx); gpgme_release (ctx);
}
while (argc > 1 && !strcmp( argv[1], "--loop"));
return 0; return 0;
} }

View File

@ -25,45 +25,9 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
static gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
}
static void static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{ {

View File

@ -1,4 +1,4 @@
/* t-encrypt-sym.c - regression test /* t-encrypt-sym.c - Regression test.
Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2003 g10 Code GmbH Copyright (C) 2001, 2003 g10 Code GmbH
@ -26,46 +26,11 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
char buf[100];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
static gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
}
int int
main (int argc, char **argv) main (int argc, char *argv[])
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t err; gpgme_error_t err;

View File

@ -24,38 +24,11 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
int int
main (int argc, char **argv) main (int argc, char *argv[])
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t err; gpgme_error_t err;

View File

@ -27,35 +27,9 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
char buf[100];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
/* Stripped down version of gpgme/wait.c. */ /* Stripped down version of gpgme/wait.c. */
struct op_result struct op_result
@ -96,7 +70,7 @@ add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc, void *fnc_data,
} }
} }
if (i == FDLIST_MAX) if (i == FDLIST_MAX)
return GPGME_General_Error; return gpg_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_GENERAL);
*r_tag = &fds[i]; *r_tag = &fds[i];
return 0; return 0;
} }

View File

@ -25,35 +25,9 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
char buf[100];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {

View File

@ -24,20 +24,11 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
/* True if progress function printed something on the screen. */ /* True if progress function printed something on the screen. */
int progress_called; static int progress_called;
static void static void
progress (void *self, const char *what, int type, int current, int total) progress (void *self, const char *what, int type, int current, int total)

View File

@ -25,38 +25,9 @@
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static char *
mk_fname (const char *fname)
{
const char *srcdir = getenv ("srcdir");
char *buf;
if (!srcdir)
srcdir = ".";
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
if (!buf)
exit (8);
strcpy (buf, srcdir);
strcat (buf, "/");
strcat (buf, fname);
return buf;
}
void void
check_result (gpgme_import_result_t result, char *fpr, int secret) check_result (gpgme_import_result_t result, char *fpr, int secret)
{ {
@ -223,14 +194,14 @@ check_result (gpgme_import_result_t result, char *fpr, int secret)
int int
main (int argc, char **argv) main (int argc, char *argv[])
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t err; gpgme_error_t err;
gpgme_data_t in; gpgme_data_t in;
gpgme_import_result_t result; gpgme_import_result_t result;
const char *pubkey_1_asc = mk_fname ("pubkey-1.asc"); const char *pubkey_1_asc = make_filename ("pubkey-1.asc");
const char *seckey_1_asc = mk_fname ("seckey-1.asc"); const char *seckey_1_asc = make_filename ("seckey-1.asc");
err = gpgme_new (&ctx); err = gpgme_new (&ctx);
fail_if_err (err); fail_if_err (err);

View File

@ -24,20 +24,9 @@
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
struct struct
{ {
char *fpr; char *fpr;
@ -74,6 +63,7 @@ keys[] =
{ NULL } { NULL }
}; };
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
@ -611,7 +601,7 @@ main (int argc, char **argv)
gpgme_key_unref (key); gpgme_key_unref (key);
i++; i++;
} }
if (err != GPGME_EOF) if (gpg_err_code (err) != GPG_ERR_EOF)
fail_if_err (err); fail_if_err (err);
err = gpgme_op_keylist_end (ctx); err = gpgme_op_keylist_end (ctx);
fail_if_err (err); fail_if_err (err);

View File

@ -24,20 +24,9 @@
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
struct struct
{ {
char *fpr; char *fpr;
@ -514,7 +503,7 @@ main (int argc, char **argv)
gpgme_key_unref (key); gpgme_key_unref (key);
i++; i++;
} }
if (err != GPGME_EOF) if (gpg_err_code (err) != GPG_ERR_EOF)
fail_if_err (err); fail_if_err (err);
err = gpgme_op_keylist_end (ctx); err = gpgme_op_keylist_end (ctx);
fail_if_err (err); fail_if_err (err);

View File

@ -25,45 +25,9 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
static gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
}
static void static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{ {

View File

@ -25,45 +25,9 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
static gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
}
static void static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{ {

81
tests/gpg/t-support.h Normal file
View File

@ -0,0 +1,81 @@
/* t-support.h - Helper routines for regression tests.
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2002, 2003 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. */
#include <unistd.h>
#include <errno.h>
#include <gpgme.h>
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: %s: %s\n", \
__FILE__, __LINE__, gpgme_strsource (err), \
gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (gpgme_error_from_errno (errno));
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (gpgme_error_from_errno (errno));
}
gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
}
char *
make_filename (const char *fname)
{
const char *srcdir = getenv ("srcdir");
char *buf;
if (!srcdir)
srcdir = ".";
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
if (!buf)
exit (8);
strcpy (buf, srcdir);
strcat (buf, "/");
strcat (buf, fname);
return buf;
}

View File

@ -24,20 +24,9 @@
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
@ -58,7 +47,7 @@ main (int argc, char *argv[])
item->validity, item->name); item->validity, item->name);
gpgme_trust_item_unref (item); gpgme_trust_item_unref (item);
} }
if (err != GPGME_EOF) if (gpg_err_code (err) != GPG_ERR_EOF)
fail_if_err (err); fail_if_err (err);
gpgme_release (ctx); gpgme_release (ctx);

View File

@ -24,18 +24,7 @@
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static const char test_text1[] = "Just GNU it!\n"; static const char test_text1[] = "Just GNU it!\n";
@ -106,10 +95,10 @@ check_result (gpgme_verify_result_t result, int summary, char *fpr,
__FILE__, __LINE__, sig->fpr); __FILE__, __LINE__, sig->fpr);
exit (1); exit (1);
} }
if (sig->status != status) if (gpg_err_code (sig->status) != status)
{ {
fprintf (stderr, "%s:%i: Unexpected signature status: %s\n", fprintf (stderr, "%s:%i: Unexpected signature status: %s\n",
__FILE__, __LINE__, gpgme_strerror (sig->status)); __FILE__, __LINE__, gpg_strerror (sig->status));
exit (1); exit (1);
} }
if (notation) if (notation)
@ -145,7 +134,7 @@ check_result (gpgme_verify_result_t result, int summary, char *fpr,
__FILE__, __LINE__, sig->validity); __FILE__, __LINE__, sig->validity);
exit (1); exit (1);
} }
if (sig->validity_reason != GPGME_No_Error) if (gpg_err_code (sig->validity_reason) != GPG_ERR_NO_ERROR)
{ {
fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n", fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n",
__FILE__, __LINE__, gpgme_strerror (sig->validity_reason)); __FILE__, __LINE__, gpgme_strerror (sig->validity_reason));
@ -174,7 +163,7 @@ main (int argc, char *argv[])
fail_if_err (err); fail_if_err (err);
result = gpgme_op_verify_result (ctx); result = gpgme_op_verify_result (ctx);
check_result (result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", check_result (result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
GPGME_No_Error, 1); GPG_ERR_NO_ERROR, 1);
/* Checking a manipulated message. */ /* Checking a manipulated message. */
gpgme_data_release (text); gpgme_data_release (text);
@ -185,7 +174,7 @@ main (int argc, char *argv[])
fail_if_err (err); fail_if_err (err);
result = gpgme_op_verify_result (ctx); result = gpgme_op_verify_result (ctx);
check_result (result, GPGME_SIGSUM_RED, "2D727CC768697734", check_result (result, GPGME_SIGSUM_RED, "2D727CC768697734",
GPGME_Bad_Signature, 0); GPG_ERR_BAD_SIGNATURE, 0);
/* Checking a normal signature. */ /* Checking a normal signature. */
gpgme_data_release (sig); gpgme_data_release (sig);
@ -198,7 +187,7 @@ main (int argc, char *argv[])
fail_if_err (err); fail_if_err (err);
result = gpgme_op_verify_result (ctx); result = gpgme_op_verify_result (ctx);
check_result (result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", check_result (result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
GPGME_No_Error, 0); GPG_ERR_NO_ERROR, 0);
gpgme_data_release (sig); gpgme_data_release (sig);
gpgme_data_release (text); gpgme_data_release (text);

View File

@ -23,9 +23,11 @@ GPGSM = @GPGSM@
TESTS_ENVIRONMENT = GNUPGHOME=. TESTS_ENVIRONMENT = GNUPGHOME=.
noinst_HEADERS = t-support.h
TESTS = t-import t-keylist t-encrypt t-verify t-decrypt t-sign t-export TESTS = t-import t-keylist t-encrypt t-verify t-decrypt t-sign t-export
EXTRA_DIST = cert_dfn_pca01.der cert_dfn_pca15.der cert_g10code_test1.der $(key_id) EXTRA_DIST = cert_dfn_pca01.der cert_dfn_pca15.der cert_g10code_test1.der \
$(key_id)
INCLUDES = -I$(top_srcdir)/gpgme INCLUDES = -I$(top_srcdir)/gpgme

View File

@ -24,6 +24,7 @@
#include <errno.h> #include <errno.h>
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
static const char test_text1[] = "Hallo Leute!\n"; static const char test_text1[] = "Hallo Leute!\n";
@ -39,30 +40,6 @@ static const char test_cip1[] =
"BAiiytWtOSmqnwAA\n" "BAiiytWtOSmqnwAA\n"
"-----END CMS OBJECT-----\n"; "-----END CMS OBJECT-----\n";
#define fail_if_err(a) do { if(a) { int my_errno = errno; \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror(a)); \
if ((a) == GPGME_File_Error) \
fprintf (stderr, "\terrno=`%s'\n", strerror (my_errno)); \
exit (1); } \
} while(0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
int int
main (int argc, char *argv[]) main (int argc, char *argv[])

View File

@ -24,35 +24,7 @@
#include <gpgme.h> #include <gpgme.h>
#define fail_if_err(err) \ #include "t-support.h"
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
int int
main (int argc, char **argv) main (int argc, char **argv)

View File

@ -24,34 +24,7 @@
#include <assert.h> #include <assert.h>
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
char buf[100];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
int int

View File

@ -24,35 +24,7 @@
#include <errno.h> #include <errno.h>
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
/* True if progress function printed something on the screen. */ /* True if progress function printed something on the screen. */
@ -79,7 +51,7 @@ progress (void *self, const char *what, int type, int current, int total)
int int
main (int argc, char **argv) main (int argc, char *argv[])
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t err; gpgme_error_t err;

View File

@ -335,7 +335,7 @@ main (int argc, char **argv)
gpgme_key_unref (key); gpgme_key_unref (key);
i++; i++;
} }
if (err != GPGME_EOF) if (gpg_err_code (err) != GPG_ERR_EOF)
fail_if_err (err); fail_if_err (err);
err = gpgme_op_keylist_end (ctx); err = gpgme_op_keylist_end (ctx);
fail_if_err (err); fail_if_err (err);

View File

@ -23,35 +23,7 @@
#include <string.h> #include <string.h>
#include <gpgme.h> #include <gpgme.h>
#include "t-support.h"
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
__FILE__, __LINE__, gpgme_strerror (err)); \
exit (1); \
} \
} \
while (0)
static void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (GPGME_File_Error);
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (GPGME_File_Error);
}
static void static void
@ -102,7 +74,7 @@ check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
int int
main (int argc, char **argv) main (int argc, char *argv[])
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t err; gpgme_error_t err;

81
tests/gpgsm/t-support.h Normal file
View File

@ -0,0 +1,81 @@
/* t-support.h - Helper routines for regression tests.
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2002, 2003 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. */
#include <unistd.h>
#include <errno.h>
#include <gpgme.h>
#define fail_if_err(err) \
do \
{ \
if (err) \
{ \
fprintf (stderr, "%s:%d: %s: %s\n", \
__FILE__, __LINE__, gpg_strsource (err), \
gpg_strerror (err)); \
exit (1); \
} \
} \
while (0)
void
print_data (gpgme_data_t dh)
{
#define BUF_SIZE 512
char buf[BUF_SIZE + 1];
int ret;
ret = gpgme_data_seek (dh, 0, SEEK_SET);
if (ret)
fail_if_err (gpg_error_from_errno (errno));
while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
fwrite (buf, ret, 1, stdout);
if (ret < 0)
fail_if_err (gpg_error_from_errno (errno));
}
gpgme_error_t
passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
int last_was_bad, int fd)
{
write (fd, "abc\n", 4);
return 0;
}
char *
make_filename (const char *fname)
{
const char *srcdir = getenv ("srcdir");
char *buf;
if (!srcdir)
srcdir = ".";
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
if (!buf)
exit (8);
strcpy (buf, srcdir);
strcat (buf, "/");
strcat (buf, fname);
return buf;
}

View File

@ -78,7 +78,7 @@ check_result (gpgme_verify_result_t result, int summary, char *fpr,
__FILE__, __LINE__, sig->fpr); __FILE__, __LINE__, sig->fpr);
exit (1); exit (1);
} }
if (sig->status != status) if (gpg_err_code (sig->status) != status)
{ {
fprintf (stderr, "%s:%i: Unexpected signature status: %s\n", fprintf (stderr, "%s:%i: Unexpected signature status: %s\n",
__FILE__, __LINE__, gpgme_strerror (sig->status)); __FILE__, __LINE__, gpgme_strerror (sig->status));
@ -102,7 +102,7 @@ check_result (gpgme_verify_result_t result, int summary, char *fpr,
__FILE__, __LINE__, sig->validity); __FILE__, __LINE__, sig->validity);
exit (1); exit (1);
} }
if (sig->validity_reason != GPGME_No_Error) if (gpg_err_code (sig->validity_reason) != GPG_ERR_NO_ERROR)
{ {
fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n", fprintf (stderr, "%s:%i: Unexpected validity reason: %s\n",
__FILE__, __LINE__, gpgme_strerror (sig->validity_reason)); __FILE__, __LINE__, gpgme_strerror (sig->validity_reason));
@ -133,7 +133,7 @@ main (int argc, char **argv)
result = gpgme_op_verify_result (ctx); result = gpgme_op_verify_result (ctx);
check_result (result, GPGME_SIGSUM_VALID | GPGME_SIGSUM_GREEN, check_result (result, GPGME_SIGSUM_VALID | GPGME_SIGSUM_GREEN,
"3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E", "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E",
GPGME_No_Error, GPGME_VALIDITY_FULL); GPG_ERR_NO_ERROR, GPGME_VALIDITY_FULL);
/* Checking a manipulated message. */ /* Checking a manipulated message. */
gpgme_data_release (text); gpgme_data_release (text);
@ -145,7 +145,7 @@ main (int argc, char **argv)
result = gpgme_op_verify_result (ctx); result = gpgme_op_verify_result (ctx);
check_result (result, GPGME_SIGSUM_RED, check_result (result, GPGME_SIGSUM_RED,
"3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E", "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E",
GPGME_Bad_Signature, GPGME_VALIDITY_UNKNOWN); GPG_ERR_BAD_SIGNATURE, GPGME_VALIDITY_UNKNOWN);
gpgme_release (ctx); gpgme_release (ctx);
return 0; return 0;

View File

@ -157,7 +157,7 @@ write_test (round_t round, gpgme_data_t data)
amt = gpgme_data_write (data, text, strlen (text)); amt = gpgme_data_write (data, text, strlen (text));
if (amt != strlen (text)) if (amt != strlen (text))
fail_if_err (GPGME_File_Error); fail_if_err (gpg_error_from_errno (errno));
gpgme_data_seek (data, 0, SEEK_SET); gpgme_data_seek (data, 0, SEEK_SET);
@ -191,7 +191,7 @@ main (int argc, char **argv)
const char *text_filename = make_filename ("t-data-1.txt"); const char *text_filename = make_filename ("t-data-1.txt");
const char *longer_text_filename = make_filename ("t-data-2.txt"); const char *longer_text_filename = make_filename ("t-data-2.txt");
const char *missing_filename = "this-file-surely-does-not-exist"; const char *missing_filename = "this-file-surely-does-not-exist";
gpgme_error_t err = GPGME_No_Error; gpgme_error_t err = 0;
gpgme_data_t data; gpgme_data_t data;
while (++round) while (++round)
@ -231,7 +231,8 @@ main (int argc, char **argv)
case TEST_INOUT_MEM_FROM_FILE_NO_COPY: case TEST_INOUT_MEM_FROM_FILE_NO_COPY:
err = gpgme_data_new_from_file (&data, text_filename, 0); err = gpgme_data_new_from_file (&data, text_filename, 0);
/* This is not implemented yet. */ /* This is not implemented yet. */
if (err == GPGME_Not_Implemented || err == GPGME_Invalid_Value) if (gpg_err_code (err) == GPG_ERR_NOT_IMPLEMENTED
|| gpg_err_code (err) == GPG_ERR_INV_VALUE)
continue; continue;
break; break;
case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME: case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME: