From 02536bb72b884dceeaadda9364860f0649450e2e Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 5 Jun 2003 23:20:29 +0000 Subject: [PATCH] doc/ 2003-06-06 Marcus Brinkmann * gpgme.texi: Change error codes to GPG_ERR_* variants. (Error Handling): Rewritten. gpgme/ 2003-06-05 Marcus Brinkmann 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 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. --- ChangeLog | 5 + NEWS | 71 +-- TODO | 11 +- configure.ac | 7 +- doc/ChangeLog | 5 + doc/gpgme.texi | 890 +++++++++++++++++++++-------------- gpgme/ChangeLog | 20 + gpgme/Makefile.am | 12 +- gpgme/conversion.c | 169 +++---- gpgme/data-compat.c | 62 ++- gpgme/data.c | 16 +- gpgme/decrypt-verify.c | 4 +- gpgme/decrypt.c | 13 +- gpgme/delete.c | 10 +- gpgme/edit.c | 2 +- gpgme/encrypt-sign.c | 4 +- gpgme/encrypt.c | 10 +- gpgme/engine-gpgsm.c | 231 ++++----- gpgme/engine.c | 81 ++-- gpgme/error.c | 77 +++ gpgme/export.c | 4 +- gpgme/genkey.c | 11 +- gpgme/gpgme.c | 7 +- gpgme/gpgme.h | 130 ++--- gpgme/import.c | 21 +- gpgme/key.c | 7 +- gpgme/keylist.c | 35 +- gpgme/mkerrors | 84 ---- gpgme/op-support.c | 39 +- gpgme/passphrase.c | 7 +- gpgme/progress.c | 3 +- gpgme/rungpg.c | 98 ++-- gpgme/sign.c | 27 +- gpgme/signers.c | 5 +- gpgme/trust-item.c | 3 +- gpgme/trustlist.c | 21 +- gpgme/verify.c | 137 +++--- gpgme/wait-global.c | 9 +- gpgme/wait-private.c | 3 +- gpgme/wait.c | 7 +- tests/ChangeLog | 9 + tests/gpg/Makefile.am | 1 + tests/gpg/t-decrypt-verify.c | 69 +-- tests/gpg/t-decrypt.c | 64 +-- tests/gpg/t-edit.c | 119 ++--- tests/gpg/t-encrypt-sign.c | 40 +- tests/gpg/t-encrypt-sym.c | 43 +- tests/gpg/t-encrypt.c | 33 +- tests/gpg/t-eventloop.c | 32 +- tests/gpg/t-export.c | 30 +- tests/gpg/t-genkey.c | 15 +- tests/gpg/t-import.c | 39 +- tests/gpg/t-keylist-sig.c | 18 +- tests/gpg/t-keylist.c | 17 +- tests/gpg/t-sign.c | 40 +- tests/gpg/t-signers.c | 40 +- tests/gpg/t-support.h | 81 ++++ tests/gpg/t-trustlist.c | 19 +- tests/gpg/t-verify.c | 25 +- tests/gpgsm/Makefile.am | 4 +- tests/gpgsm/t-decrypt.c | 25 +- tests/gpgsm/t-encrypt.c | 30 +- tests/gpgsm/t-export.c | 29 +- tests/gpgsm/t-genkey.c | 32 +- tests/gpgsm/t-keylist.c | 2 +- tests/gpgsm/t-sign.c | 32 +- tests/gpgsm/t-support.h | 81 ++++ tests/gpgsm/t-verify.c | 8 +- tests/t-data.c | 7 +- 69 files changed, 1621 insertions(+), 1721 deletions(-) create mode 100644 gpgme/error.c delete mode 100755 gpgme/mkerrors create mode 100644 tests/gpg/t-support.h create mode 100644 tests/gpgsm/t-support.h diff --git a/ChangeLog b/ChangeLog index b08dd553..58c69f7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-06-06 Marcus Brinkmann + + * configure.ac: Check for libgpg-error. Define + GPG_ERR_SOURCE_DEFAULT. + 2003-05-26 Marcus Brinkmann * configure.ac (NEED_GPG_VERSION): Bump up to 1.2.2. diff --git a/NEWS b/NEWS index a89e881e..5ad3e811 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,13 @@ Noteworthy changes in version 0.4.1 (unreleased) afterwards by calling one of the result functions. This unifies the 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 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 much effort and did not collide with the overall sanitization effort. - However, it is recommended to update to the new interfaces soon, so - the compatibility interfaces can be phased out quickly. - Recommendations how to replace deprecated or removed functionality can - be found within the description of each change. + However, this is only for ease of transition. NO DEPRECATED FUNCTION + OR DATA TYPE IS CONSIDERED A PART OF THE API OR ABI AND WILL BE + DROPPED IN THE FUTURE WITHOUT CHANGING THE SONAME OF THE LIBRARY. + 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 in detail. * If gpgme.h is included in sources compiled by GCC 3.1 or later, deprecated attributes will warn about use of obsolete functions and - typedefs. The use of obsolete error values will appear as the use - of an obsolete type _gpgme_deprecated_error_t. You can suppress - these warnings by passing -Wno-deprecated-declarations to the gcc - command. + type definitions. You can suppress these warnings by passing + -Wno-deprecated-declarations to the gcc command. * The following types have been renamed. The old types are still 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 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. * 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 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. 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 gpgme_protocol_t value into a string. - * The status of a context operation is not checked anymore, so the - errors GPGME_Busy and GPGME_No_Request can not occur anymore. - - * For clarity and better reusability, the error codes - 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 status of a context operation is not checked anymore. Starting + a new operation will silently cancel the previous one. Calling a + function that requires you to have started an operation before without + doing so is undefined. * The FPR argument to gpgme_op_genkey was removed. Instead, use the 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 anymore and dropped. - * The error values GPGME_Invalid_Type and GPGME_Invalid_Mode can not - occur anymore and are thus deprecated. + * The type and mode of data objects is not available anymore. * 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_trust_item_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_event_io_t CHANGED: New event type (all numbers changed). 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_protocol_name NEW 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_result NEW gpgme_genkey_result_t NEW @@ -372,8 +389,6 @@ gpgme_key_get_as_xml REMOVED gpgme_key_list_result_t NEW gpgme_op_keylist_result NEW gpgme_get_op_info REMOVED -GPGME_Invalid_Type DEPRECATED -GPGME_Invalid_Mode DEPRECATED ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 0.4.0 (2002-12-23) diff --git a/TODO b/TODO index 3f4d1f23..a57665db 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,13 @@ 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: -** Use libgpg-error. ** Compatibility interfaces that can be removed in future versions: *** gpgme_data_new_from_filepart *** gpgme_data_new_from_file @@ -91,7 +97,8 @@ Hey Emacs, this is -*- outline -*- mode! * Error Values ** 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 ** Write a fake gpg-agent so that we can supply known passphrases to diff --git a/configure.ac b/configure.ac index 863f3d10..51f02f05 100644 --- a/configure.ac +++ b/configure.ac @@ -164,14 +164,13 @@ if test "$ac_cv_func_vasprintf" != yes; then GNUPG_CHECK_VA_COPY fi - - # Note: fopencokie is only a dummy stub and not used. # However some code in assuan/ links against it. 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 Checks for system services dnl diff --git a/doc/ChangeLog b/doc/ChangeLog index 0eee29d3..5e239e76 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2003-06-06 Marcus Brinkmann + + * gpgme.texi: Change error codes to GPG_ERR_* variants. + (Error Handling): Rewritten. + 2003-05-29 Marcus Brinkmann * gpgme.texi (Exporting Keys): Change and document prototypes. diff --git a/doc/gpgme.texi b/doc/gpgme.texi index c388d365..39dfffb3 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -122,7 +122,9 @@ Algorithms Error Handling -* Error Values:: A list of all error values used. +* Error Values:: The error value and what it means. +* Error Codes:: A list of important error codes. +* Error Sources:: A list of important error sources. * Error Strings:: How to get a descriptive string from a value. Exchanging Data @@ -212,9 +214,9 @@ Using External Event Loops `GnuPG Made Easy' (@acronym{GPGME}) is a C language library that allows to add support for cryptography to a program. It is designed -to make access to crypto engines like GnuPG or GpgSM easier for -applications. @acronym{GPGME} provides a high-level crypto API for -encryption, decryption, signing, signature verification and key +to make access to public key crypto engines like GnuPG or GpgSM easier +for applications. @acronym{GPGME} provides a high-level crypto API +for encryption, decryption, signing, signature verification and key management. @acronym{GPGME} uses GnuPG and GpgSM as its backends to support @@ -343,6 +345,10 @@ Because @acronym{GPGME} links to the Assuan library, linking to @acronym{GPGME} will also use the @code{assuan_*} and @code{_assuan_*} name space indirectly. +Because @acronym{GPGME} makes use of the GPG Error library, using +@acronym{GPGME} will also use the @code{gpg_err*} and @code{GPG_ERR_*} +name space directly. + @node Building the Source @section Building the Source @@ -367,9 +373,9 @@ example shows how it can be used at the command line: gcc -c foo.c `gpgme-config --cflags` @end example -Adding the output of @samp{gpgme-config --cflags} to the compilers -command line will ensure that the compiler can find the @acronym{GPGME} header -file. +Adding the output of @samp{gpgme-config --cflags} to the compiler +command line will ensure that the compiler can find the +@acronym{GPGME} header file. A similar problem occurs when linking the program with the library. Again, the compiler has to find the library files. For this to work, @@ -398,8 +404,8 @@ gcc -o foo foo.c `gpgme-config --cflags --libs` @cindex automake @cindex autoconf -It is much easier if you use GNU Automake instead writing your own -Makefiles. If you do that you don't have to worry about finding and +It is much easier if you use GNU Automake instead of writing your own +Makefiles. If you do that you do not have to worry about finding and invoking the @command{gpgme-config} script at all. @acronym{GPGME} provides an extension to Automake that does all the work for you. @@ -476,7 +482,8 @@ conditions to worry about: @acronym{GPGME} supports the thread libraries pthread and GNU Pth. The support for this has to be enabled at compile time. @acronym{GPGME} will automatically detect the location in which the -thread libraries are installed and activate the support for them. +thread libraries are installed and activate the support for them at +build time. Support for other thread libraries is very easy to add. Please contact us if you have the need. @@ -490,10 +497,10 @@ both pthread and GNU Pth, @acronym{GPGME} will use the pthread support. This feature requires weak symbol support. @item -If you link your program statically to @acronym{GPGME}, there is -currently no easy way to make sure that @acronym{GPGME} detects the -presence of the thread library. This will be solved in a future -version. +If you link your program statically to @acronym{GPGME}, or your system +does not support weak symbols, there is currently no easy way to make +sure that @acronym{GPGME} detects the presence of the thread library. +This will be solved in a future version. @item The function @code{gpgme_check_version} must be called before any @@ -566,7 +573,7 @@ does not implement them. Rather it uses backends (also called engines) which implement the protocol. @acronym{GPGME} uses inter-process communication to pass data back and forth between the application and the backend, but the details of the communication -protocol and invocation of the backends is completely hidden by the +protocol and invocation of the backend is completely hidden by the interface. All complexity is handled by @acronym{GPGME}. Where an exchange of information between the application and the backend is necessary, @acronym{GPGME} provides the necessary callback function @@ -581,6 +588,7 @@ are supported: @table @code @item GPGME_PROTOCOL_OpenPGP This specifies the OpenPGP protocol. + @item GPGME_PROTOCOL_CMS This specifies the Cryptographic Message Syntax. @end table @@ -610,8 +618,8 @@ The function @code{gpgme_engine_check_version} verifies that the engine implementing the protocol @var{PROTOCOL} is installed in the expected path and meets the version requirement of @acronym{GPGME}. -This function returns @code{GPGME_No_Error} if the engine is available -and @code{GPGME_Invalid_Engine} if it is not. +This function returns the error code @code{GPG_ERR_NO_ERROR} if the +engine is available and @code{GPG_ERR_INV_ENGINE} if it is not. @end deftypefun @@ -622,8 +630,8 @@ and @code{GPGME_Invalid_Engine} if it is not. @deftp {Data type} {gpgme_engine_info_t} @tindex gpgme_protocol_t The @code{gpgme_engine_info_t} type specifies a pointer to a structure -describing a crypto backend engine. The structure contains the -following elements: +describing a crypto engine. The structure contains the following +elements: @table @code @item gpgme_engine_info_t next @@ -631,7 +639,7 @@ This is a pointer to the next engine info structure in the linked list, or @code{NULL} if this is the last element. @item gpgme_protocol_t protocol -This is the protocol for which the crypo engine is used. You can +This is the protocol for which the crypto engine is used. You can convert this to a string with @code{gpgme_get_protocol_name} for printing. @@ -657,19 +665,17 @@ reserved for future use, so always check before you use it. @deftypefun gpgme_error_t gpgme_get_engine_info (gpgme_engine_info_t *info) The function @code{gpgme_get_engine_info} returns a linked list of engine info structures in @var{info}. Each info structure describes -one configured crypto backend engine. +one configured backend. The memory for the info structures is allocated the first time this function is invoked, and must not be freed by the caller. -This function returns @code{GPGME_No_Error} if successful, and -@code{GPGME_Out_Of_Core} if not enough memory is available for the -operation. +This function returns the error code @code{GPG_ERR_NO_ERROR} if +successful, and a system error if the memory could not be allocated. @end deftypefun -Here is the example how you can provide more diagnostics if you -receive an error message which indicates that the crypto engine is -invalid. +Here is an example how you can provide more diagnostics if you receive +an error message which indicates that the crypto engine is invalid. @example gpgme_ctx_t ctx; @@ -677,7 +683,7 @@ gpgme_error_t err; [...] -if (err == GPGME_Invalid_Engine) +if (gpgme_err_code (err) == GPG_ERR_INV_ENGINE) @{ gpgme_engine_info_t info; err = gpgme_get_engine_info (&info); @@ -851,173 +857,365 @@ operation, but the result of an operation that failed properly. For example, if you try to decrypt a tempered message, the decryption will fail. Another error value actually means that the end of a data buffer or list has been reached. The following descriptions explain -what each error message means in general. Some error values have -specific meanings if returned by a specific function. Such cases are +for many error codes what they mean usually. Some error values have +specific meanings if returned by a certain functions. Such cases are described in the documentation of those functions. +@acronym{GPGME} uses the @code{libgpg-error} library. This allows to +share the error codes with other components of the GnuPG system, and +thus pass error values transparently from the crypto engine, or some +helper application of the crypto engine, to the user. This way no +information is lost. As a consequence, @acronym{GPGME} does not use +its own identifiers for error codes, but uses those provided by +@code{libgpg-error}. They usually start with @code{GPG_ERR_}. + +However, @acronym{GPGME} does provide aliases for the functions +defined in libgpg-error, which might be preferred for name space +consistency. + @menu -* Error Values:: A list of all error values used. +* Error Values:: The error value and what it means. +* Error Sources:: A list of important error sources. +* Error Codes:: A list of important error codes. * Error Strings:: How to get a descriptive string from a value. @end menu @node Error Values @section Error Values -@cindex error values, list of +@cindex error values +@cindex error codes +@cindex error sources -@deftp {Data type} {enum gpgme_error_t} -@tindex gpgme_error_t -The @code{gpgme_error_t} type specifies the set of all error values that -are used by @acronym{GPGME}. Possible values are: +@deftp {Data type} {gpgme_err_code_t} +The @code{gpgme_err_code_t} type is an alias for the @code{libgpg-error} +type @code{gpg_err_code_t}. The error code indicates the type of an +error, or the reason why an operation failed. + +A list of important error codes can be found in the next section. +@end deftp + +@deftp {Data type} {gpgme_err_source_t} +The @code{gpgme_err_source_t} type is an alias for the +@code{libgpg-error} type @code{gpg_err_source_t}. The error source +has not a precisely defined meaning. Sometimes it is the place where +the error happened, sometimes it is the place where an error was +encoded into an error value. Usually the error source will give an +indication to where to look for the problem. This is not always true, +but it is attempted to achieve this goal. + +A list of important error sources can be found in the next section. +@end deftp + +@deftp {Data type} {gpgme_error_t} +The @code{gpgme_error_t} type is an alias for the @code{libgpg-error} +type @code{gpg_error_t}. An error value like this has always two +components, an error code and an error source. Both together form the +error value. + +Thus, the error value can not be directly compared against an error +code, but the accessor functions described below must be used. +However, it is guaranteed that only 0 is used to indicate success +(@code{GPG_ERR_NO_ERROR}), and that in this case all other parts of +the error value are set to 0, too. + +Note that in @acronym{GPGME}, the error source is used purely for +diagnostical purposes. Only the error code should be checked to test +for a certain outcome of a function. The manual only documents the +error code part of an error value. The error source is left +unspecified and might be anything. +@end deftp + +@deftypefun {static __inline__ gpgme_err_code_t} gpgme_err_code (@w{gpgme_error_t @var{err}}) +The static inline function @code{gpgme_err_code} returns the +@code{gpgme_err_code_t} component of the error value @var{err}. This +function must be used to extract the error code from an error value in +order to compare it with the @code{GPG_ERR_*} error code macros. +@end deftypefun + +@deftypefun {static __inline__ gpgme_err_source_t} gpgme_err_source (@w{gpgme_error_t @var{err}}) +The static inline function @code{gpgme_err_source} returns the +@code{gpgme_err_source_t} component of the error value @var{err}. This +function must be used to extract the error source from an error value in +order to compare it with the @code{GPG_ERR_SOURCE_*} error source macros. +@end deftypefun + +@deftypefun {static __inline__ gpgme_error_t} gpgme_err_make (@w{gpgme_err_source_t @var{source}}, @w{gpgme_err_code_t @var{code}}) +The static inline function @code{gpgme_err_make} returns the error +value consisting of the error source @var{source} and the error code +@var{code}. + +This function can be used in callback functions to construct an error +value to return it to the library. +@end deftypefun + +@deftypefun {static __inline__ gpgme_error_t} gpgme_error (@w{gpgme_err_code_t @var{code}}) +The static inline function @code{gpgme_error} returns the error value +consisting of the default error source and the error code @var{code}. + +For @acronym{GPGME} applications, the default error source is +@code{GPG_ERR_SOURCE_USER_1}. You can define +@code{GPGME_ERR_SOURCE_DEFAULT} before including @file{gpgme.h} to +change this default. + +This function can be used in callback functions to construct an error +value to return it to the library. +@end deftypefun + +The @code{libgpg-error} library provides error codes for all system +error numbers it knows about. If @var{err} is an unknown error +number, the error code @code{GPG_ERR_UNKNOWN_ERRNO} is used. The +following functions can be used to construct error values from system +errnor numbers. + +@deftypefun {gpgme_error_t} gpgme_err_make_from_errno (@w{gpgme_err_source_t @var{source}}, @w{int @var{err}}) +The function @code{gpgme_err_make_from_errno} is like +@code{gpgme_err_make}, but it takes a system error like @code{errno} +instead of a @code{gpgme_err_code_t} error code. +@end deftypefun + +@deftypefun {gpgme_error_t} gpgme_error_from_errno (@w{int @var{err}}) +The function @code{gpgme_error_from_errno} is like @code{gpgme_error}, +but it takes a system error like @code{errno} instead of a +@code{gpgme_err_code_t} error code. +@end deftypefun + +Sometimes you might want to map system error numbers to error codes +directly, or map an error code representing a system error back to the +system error number. The following functions can be used to do that. + +@deftypefun {gpgme_err_code_t} gpgme_err_code_from_errno (@w{int @var{err}}) +The function @code{gpgme_err_code_from_errno} returns the error code +for the system error @var{err}. If @var{err} is not a known system +error, the function returns @code{GPG_ERR_UNKNOWN_ERRNO}. +@end deftypefun + +@deftypefun {int} gpgme_err_code_to_errno (@w{gpgme_err_code_t @var{err}}) +The function @code{gpgme_err_code_to_errno} returns the system error +for the error code @var{err}. If @var{err} is not an error code +representing a system error, or if this system error is not defined on +this system, the function returns @code{0}. +@end deftypefun + + +@node Error Sources +@section Error Sources +@cindex error codes, list of + +The library @code{libgpg-error} defines an error source for every +component of the GnuPG system. The error source part of an error +value is not well defined. As such it is mainly useful to improve the +diagnostic error message for the user. + +If the error code part of an error value is @code{0}, the whole error +value will be @code{0}. In this case the error source part is of +course @code{GPG_ERR_SOURCE_UNKNOWN}. + +The list of error sources that might occur in applications using +@acronym{GPGME} is: @table @code -@item GPGME_EOF +@item GPG_ERR_SOURCE_UNKNOWN +The error source is not known. The value of this error source is +@code{0}. + +@item GPG_ERR_SOURCE_GPGME +The error source is @acronym{GPGME} itself. This is the default for +errors that occur in the @acronym{GPGME} library. + +@item GPG_ERR_SOURCE_GPG +The error source is GnuPG, which is the crypto engine used for the +OpenPGP protocol. + +@item GPG_ERR_SOURCE_GPGSM +The error source is GPGSM, which is the crypto engine used for the +OpenPGP protocol. + +@item GPG_ERR_SOURCE_GCRYPT +The error source is @code{libgcrypt}, which is used by crypto engines +to perform cryptographic operations. + +@item GPG_ERR_SOURCE_GPGAGENT +The error source is @command{gpg-agent}, which is used by crypto +engines to perform operations with the secret key. + +@item GPG_ERR_SOURCE_PINENTRY +The error source is @command{pinentry}, which is used by +@command{gpg-agent} to query the passphrase to unlock a secret key. + +@item GPG_ERR_SOURCE_SCD +The error source is the SmartCard Daemon, which is used by +@command{gpg-agent} to delegate operations with the secret key to a +SmartCard. + +@item GPG_ERR_SOURCE_KEYBOX +The error source is @code{libkbx}, a library used by the crypto +engines to manage local keyrings. + +@item GPG_ERR_SOURCE_USER_1 +@item GPG_ERR_SOURCE_USER_2 +@item GPG_ERR_SOURCE_USER_3 +@item GPG_ERR_SOURCE_USER_4 +These error sources are not used by any GnuPG component and can be +used by other software. For example, applications using +@acronym{GPGME} can use them to mark error values coming from callback +handlers. Thus @code{GPG_ERR_SOURCE_USER_1} is the default for errors +created with @code{gpgme_error} and @code{gpgme_error_from_errno}, +unless you define @code{GPGME_ERR_SOURCE_DEFAULT} before including +@file{gpgme.h}. +@end table + + +@node Error Codes +@section Error Codes +@cindex error codes, list of + +The library @code{libgpg-error} defines many error values. Most of +them are not used by @code{GPGME} directly, but might be returned by +@acronym{GPGME} because it received them from the crypto engine. The +below list only includes such error codes that have a specific meaning +in @code{GPGME}, or which are so common that you should know about +them. + +@table @code +@item GPG_ERR_EOF This value indicates the end of a list, buffer or file. -@item GPGME_No_Error -This value indicates success. The value of this error is @code{0}. +@item GPG_ERR_NO_ERROR +This value indicates success. The value of this error code is +@code{0}. Also, it is guaranteed that an error value made from the +error code @code{0} will be @code{0} itself (as a whole). This means +that the error source information is lost for this error code, +however, as this error code indicates that no error occured, this is +generally not a problem. -@item GPGME_General_Error +@item GPG_ERR_GENERAL This value means that something went wrong, but either there is not enough information about the problem to return a more useful error value, or there is no separate error value for this type of problem. -@item GPGME_Out_Of_Core +@item GPG_ERR_ENOMEM This value means that an out-of-memory condition occurred. -@item GPGME_Invalid_Value +@item GPG_ERR_E... +System errors are mapped to GPG_ERR_FOO where FOO is the symbol for +the system error. + +@item GPG_ERR_INV_VALUE This value means that some user provided data was out of range. This -can also refer to objects. For example, if an empty @code{gpgme_data_t} -object was expected, but one containing data was provided, this error -value is returned. +can also refer to objects. For example, if an empty +@code{gpgme_data_t} object was expected, but one containing data was +provided, this error value is returned. -@item GPGME_Exec_Error -This value means that an error occurred when trying to spawn a child -process. +@item GPG_ERR_UNUSABLE_PUBKEY +This value means that some recipients for a message were invalid. -@item GPGME_Too_Many_Procs -This value means that there are too many active backend processes. +@item GPG_ERR_UNUSABLE_SECKEY +This value means that some signers were invalid. -@item GPGME_Pipe_Error -This value means that the creation of a pipe failed. +@item GPG_ERR_NO_DATA +This value means that a @code{gpgme_data_t} object which was expected +to have content was found empty. -@item GPGME_No_UserID -This value means that no valid recipients for a message have been set. - -@item GPGME_Invalid_UserID -This value means that some, but not all, recipients for a message have -been invalid. - -@item GPGME_No_Data -This value means that a @code{gpgme_data_t} object which was expected to -have content was found empty. - -@item GPGME_Conflict +@item GPG_ERR_CONFLICT This value means that a conflict of some sort occurred. -@item GPGME_Not_Implemented +@item GPG_ERR_NOT_IMPLEMENTED This value indicates that the specific function (or operation) is not implemented. This error should never happen. It can only occur if you use certain values or configuration options which do not work, but for which we think that they should work at some later time. -@item GPGME_Read_Error -This value means that an I/O read operation failed. - -@item GPGME_Write_Error -This value means that an I/O write operation failed. - -@item GPGME_File_Error -This value means that a file I/O operation failed. The value of -@var{errno} contains the system error value. - -@item GPGME_Decryption_Failed +@item GPG_ERR_DECRYPT_FAILED This value indicates that a decryption operation was unsuccessful. -@item GPGME_Bad_Passphrase +@item GPG_ERR_BAD_PASSPHRASE This value means that the user did not provide a correct passphrase when requested. -@item GPGME_Canceled +@item GPG_ERR_CANCELED This value means that the operation was canceled. -@item GPGME_Invalid_Key -This value means that a key was invalid. - -@item GPGME_Invalid_Engine +@item GPG_ERR_INV_ENGINE This value means that the engine that implements the desired protocol is currently not available. This can either be because the sources were configured to exclude support for this engine, or because the engine is not installed properly. -@item GPGME_Unknown_Reason -This value indicates that a user ID was invalid but the exact reason -is not specified. - -@item GPGME_Not_Found -This value indicates that a user ID was not found. - -@item GPGME_Ambiguous_Specification +@item GPG_ERR_AMBIGUOUS_NAME This value indicates that a user ID did not specify a unique key. -@item GPGME_Wrong_Key_Usage +@item GPG_ERR_WRONG_KEY_USAGE This value indicates that a key is not used appropriately. -@item GPGME_Key_Revoked -This value indicates that a key was revoced. +@item GPG_ERR_CERT_REVOKED +This value indicates that a key signature was revoced. -@item GPGME_Key_Expired -This value indicates that a key was expired. +@item GPG_ERR_CERT_EXPIRED +This value indicates that a key signature expired. -@item GPGME_No_CRL_Known +@item GPG_ERR_NO_CRL_KNOWN This value indicates that no certificate revocation list is known for the certificate. -@item GPGME_Policy_Mismatch +@item GPG_ERR_NO_POLICY_MATCH This value indicates that a policy issue occured. -@item GPGME_No_Secret_Key +@item GPG_ERR_NO_SECKEY This value indicates that no secret key for the user ID is available. -@item GPGME_Key_Not_Trusted -This value indicates that the key with the user ID is not trusted. +@item GPG_ERR_MISSING_CERT +This value indicates that a key could not be imported because the +issuer certificate is missing. -@item GPGME_Issuer_Missing -This value indicates that a key could not be imported because there is -no issuer - -@item GPGME_Chain_Too_Long +@item GPG_ERR_BAD_CERT_CHAIN This value indicates that a key could not be imported because its -certificate chain is too long. +certificate chain is not good, for example it could be too long. -@item GPGME_Unsupported_Algorithm +@item GPG_ERR_UNSUPPORTED_ALGORITHM This value means a verification failed because the cryptographic algorithm is not supported by the crypto backend. -@item GPGME_Sig_Expired -This value means a verification failed because the signature expired. - -@item GPGME_Bad_Signature +@item GPG_ERR_BAD_SIGNATURE This value means a verification failed because the signature is bad. -@item GPGME_No_Public_Key +@item GPG_ERR_NO_PUBKEY This value means a verification failed because the public key is not available. +@item GPG_ERR_USER_1 +@item GPG_ERR_USER_2 +@item ... +@item GPG_ERR_USER_16 +These error codes are not used by any GnuPG component and can be +freely used by other software. Applications using @acronym{GPGME} +might use them to mark specific errors returned by callback handlers +if no suitable error codes (including the system errors) for +these errors exist already. @end table -@end deftp @node Error Strings @section Error Strings @cindex error values, printing of +@cindex error codes, printing of +@cindex error sources, printing of @cindex error strings @deftypefun {const char *} gpgme_strerror (@w{gpgme_error_t @var{err}}) The function @code{gpgme_strerror} returns a pointer to a statically -allocated string containing a description of the error with the error -value @var{err}. This string can be used to output a diagnostic -message to the user. +allocated string containing a description of the error code contained +in the error value @var{err}. This string can be used to output a +diagnostic message to the user. +@end deftypefun + + +@deftypefun {const char *} gpgme_strsource (@w{gpgme_error_t @var{err}}) +The function @code{gpgme_strerror} returns a pointer to a statically +allocated string containing a description of the error source +contained in the error value @var{err}. This string can be used to +output a diagnostic message to the user. +@end deftypefun The following example illustrates the use of @code{gpgme_strerror}: @@ -1026,12 +1224,11 @@ gpgme_ctx_t ctx; gpgme_error_t err = gpgme_new (&ctx); if (err) @{ - fprintf (stderr, "%s: creating GpgME context failed: %s\n", - argv[0], gpgme_strerror (err)); + fprintf (stderr, "%s: creating GpgME context failed: %s: %s\n", + argv[0], gpgme_strsource (err), gpgme_strerror (err)); exit (1); @} @end example -@end deftypefun @node Exchanging Data @@ -1088,10 +1285,10 @@ The function @code{gpgme_data_new} creates a new @code{gpgme_data_t} object and returns a handle for it in @var{dh}. The data object is memory based and initially empty. -The function returns @code{GPGME_No_Error} if the data object was -successfully created, @code{GPGME_Invalid_Value} if @var{dh} is not a -valid pointer, and @code{GPGME_Out_Of_Core} if not enough memory is -available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +data object was successfully created, @code{GPG_ERR_INV_VALUE} if +@var{dh} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not +enough memory is available. @end deftypefun @deftypefun gpgme_error_t gpgme_data_new_from_mem (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{buffer}}, @w{size_t @var{size}}, @w{int @var{copy}}) @@ -1104,10 +1301,10 @@ If @var{copy} is not zero, a private copy of the data is made. If needed, and the user has to ensure that the buffer remains valid for the whole life span of the data object. -The function returns @code{GPGME_No_Error} if the data object was -successfully created, @code{GPGME_Invalid_Value} if @var{dh} or -@var{buffer} is not a valid pointer, and @code{GPGME_Out_Of_Core} if -not enough memory is available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +data object was successfully created, @code{GPG_ERR_INV_VALUE} if +@var{dh} or @var{buffer} is not a valid pointer, and +@code{GPG_ERR_ENOMEM} if not enough memory is available. @end deftypefun @deftypefun gpgme_error_t gpgme_data_new_from_file (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{int @var{copy}}) @@ -1121,11 +1318,11 @@ mode supported currently. Later, a value of zero for @var{copy} might cause all reads to be delayed until the data is needed, but this is not yet implemented. -The function returns @code{GPGME_No_Error} if the data object was -successfully created, @code{GPGME_Invalid_Value} if @var{dh} or -@var{filename} is not a valid pointer, @code{GPGME_File_Error} if an -I/O operation fails, @code{GPGME_Not_Implemented} if @var{code} is -zero, and @code{GPGME_Out_Of_Core} if not enough memory is available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +data object was successfully created, @code{GPG_ERR_INV_VALUE} if +@var{dh} or @var{filename} is not a valid pointer, +@code{GPG_ERR_NOT_IMPLEMENTED} if @var{code} is zero, and +@code{GPG_ERR_ENOMEM} if not enough memory is available. @end deftypefun @deftypefun gpgme_error_t gpgme_data_new_from_filepart (@w{gpgme_data_t *@var{dh}}, @w{const char *@var{filename}}, @w{FILE *@var{fp}}, @w{off_t @var{offset}}, @w{size_t @var{length}}) @@ -1138,11 +1335,10 @@ must be zero. The argument that is not zero specifies the file from which @var{length} bytes are read into the data object, starting from @var{offset}. -The function returns @code{GPGME_No_Error} if the data object was -successfully created, @code{GPGME_Invalid_Value} if @var{dh} and -exactly one of @var{filename} and @var{fp} is not a valid pointer, -@code{GPGME_File_Error} if an I/O operation fails, and -@code{GPGME_Out_Of_Core} if not enough memory is available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +data object was successfully created, @code{GPG_ERR_INV_VALUE} if +@var{dh} and exactly one of @var{filename} and @var{fp} is not a valid +pointer, and @code{GPG_ERR_ENOMEM} if not enough memory is available. @end deftypefun @@ -1163,9 +1359,9 @@ When using the data object as an input buffer, the function might read a bit more from the file descriptor than is actually needed by the crypto engine in the desired operation because of internal buffering. -The function returns @code{GPGME_No_Error} if the data object was -successfully created, and @code{GPGME_Out_Of_Core} if not enough -memory is available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +data object was successfully created, and @code{GPG_ERR_ENOMEM} if not +enough memory is available. @end deftypefun @deftypefun gpgme_error_t gpgme_data_new_from_stream (@w{gpgme_data_t *@var{dh}}, @w{FILE *@var{stream}}) @@ -1178,9 +1374,9 @@ When using the data object as an input buffer, the function might read a bit more from the stream than is actually needed by the crypto engine in the desired operation because of internal buffering. -The function returns @code{GPGME_No_Error} if the data object was -successfully created, and @code{GPGME_Out_Of_Core} if not enough -memory is available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +data object was successfully created, and @code{GPG_ERR_ENOMEM} if not +enough memory is available. @end deftypefun @@ -1268,9 +1464,9 @@ to operate on the data object. The handle @var{handle} is passed as first argument to the callback functions. This can be used to identify this data object. -The function returns @code{GPGME_No_Error} if the data object was -successfully created, and @code{GPGME_Out_Of_Core} if not enough -memory is available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +data object was successfully created, and @code{GPG_ERR_ENOMEM} if not +enough memory is available. @end deftypefun The following interface is deprecated and only provided for backward @@ -1294,10 +1490,10 @@ return with an error code of @code{-1} and set @var{nread} to read pointer if it is invoked with @var{buffer} and @var{nread} being @code{NULL} and @var{count} being @code{0}. -The function returns @code{GPGME_No_Error} if the data object was -successfully created, @code{GPGME_Invalid_Value} if @var{dh} or -@var{readfunc} is not a valid pointer, and @code{GPGME_Out_Of_Core} if -not enough memory is available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +data object was successfully created, @code{GPG_ERR_INV_VALUE} if +@var{dh} or @var{readfunc} is not a valid pointer, and +@code{GPG_ERR_ENOMEM} if not enough memory is available. @end deftypefun @@ -1335,7 +1531,7 @@ from the data object with the handle @var{dh} into the space starting at @var{buffer}. If no error occurs, the actual amount read is returned. If the end of -the data object is reached, the function returns @code{GPGME_EOF} and +the data object is reached, the function returns @code{GPG_ERR_EOF} and sets @var{nread} to zero. In all other cases, the function returns -1 and sets @var{errno}. @@ -1350,11 +1546,6 @@ The function returns the number of bytes actually written, or -1 if an error occurs. If an error occurs, @var{errno} is set. @end deftypefun -/* Set the current position from where the next read or write starts - in the data object with the handle DH to OFFSET, relativ to - WHENCE. */ -off_t gpgme_data_seek (gpgme_data_t dh, off_t offset, int whence); - @deftypefun off_t gpgme_data_seek (@w{gpgme_data_t @var{dh}}, @w{off_t *@var{offset}}, @w{int @var{whence}}) The function @code{gpgme_data_seek} changes the current read/write position. @@ -1396,7 +1587,7 @@ The function @code{gpgme_data_rewind} is equivalent to: @example return (gpgme_data_seek (dh, 0, SEEK_SET) == -1) - ? mk_error (File_Error) : 0; + ? gpgme_error_from_errno (errno) : 0; @end example @end deftypefun @@ -1480,10 +1671,10 @@ cryptographic operations. The function @code{gpgme_data_new} creates a new @code{gpgme_ctx_t} object and returns a handle for it in @var{ctx}. -The function returns @code{GPGME_No_Error} if the context was -successfully created, @code{GPGME_Invalid_Value} if @var{ctx} is not a -valid pointer, and @code{GPGME_Out_Of_Core} if not enough memory is -available. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +context was successfully created, @code{GPG_ERR_INV_VALUE} if +@var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if not +enough memory is available. @end deftypefun @@ -1527,9 +1718,9 @@ Setting the protocol with @code{gpgme_set_protocol} does not check if the crypto engine for that protocol is available and installed correctly. @xref{Engine Version Check}. -The function returns @code{GPGME_No_Error} if the protocol could be -set successfully, and @code{GPGME_Invalid_Value} if @var{protocol} is -not a valid protocol. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +protocol could be set successfully, and @code{GPG_ERR_INV_VALUE} if +@var{protocol} is not a valid protocol. @end deftypefun @deftypefun gpgme_protocol_t gpgme_get_protocol (@w{gpgme_ctx_t @var{ctx}}) @@ -1614,8 +1805,8 @@ from the sender's certificate. The number @code{n} must be positive. Values of @var{nr_of_certs} smaller than -2 are undefined. -This option is only relevant to the CMS crypto engine, and ignored -by all other engines. +This option is only relevant to the CMS crypto engine, and ignored by +all other engines. @end deftypefun @deftypefun int gpgme_get_include_certs (@w{gpgme_ctx_t @var{ctx}}) @@ -1661,9 +1852,9 @@ appropriate bits, and then using that calulcated value in the bits in the mode value intact (in particular those that are not used in the current version of the library). -The function returns @code{GPGME_No_Error} if the mode could be set -correctly, and @code{GPGME_Invalid_Value} if @var{ctx} is not a valid -pointer or @var{mode} is not a valid mode. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +mode could be set correctly, and @code{GPG_ERR_INV_VALUE} if @var{ctx} +is not a valid pointer or @var{mode} is not a valid mode. @end deftypefun @@ -1707,9 +1898,9 @@ to the file descriptor @var{fd}. If the user does not return 0 indicating success, the user must at least write a newline character before returning from the callback. -If an error occurs, return the corresponding @code{gpgme_error_t} value. -You can use @code{GPGME_Canceled} to abort the operation. Otherwise, -return @code{0}. +If an error occurs, return the corresponding @code{gpgme_error_t} +value. You can use the error code @code{GPG_ERR_CANCELED} to abort +the operation. Otherwise, return @code{0}. @end deftp @deftypefun void gpgme_set_passphrase_cb (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_passphrase_cb_t @var{passfunc}}, @w{void *@var{hook_value}}) @@ -1796,12 +1987,12 @@ respective keys that should be used for the operation. The following section describes how such keys can be selected and manipulated. @deftp {Data type} gpgme_sub_key_t -The @code{gpgme_sub_key_t} type is a pointer to a subkey structure. Sub -keys are one component of a @code{gpgme_key_t} object. In fact, subkeys -are those parts that contains the real information about the +The @code{gpgme_sub_key_t} type is a pointer to a subkey structure. +Sub keys are one component of a @code{gpgme_key_t} object. In fact, +subkeys are those parts that contains the real information about the individual cryptographic keys that belong to the same key object. One -@code{gpgme_key_t} can contain several subkeys. The first subkey in the -linked list is also called the primary key. +@code{gpgme_key_t} can contain several subkeys. The first subkey in +the linked list is also called the primary key. The subkey structure has the following members: @@ -2055,12 +2246,12 @@ If @var{secret_only} is not @code{0}, the list is restricted to secret keys only. The context will be busy until either all keys are received (and -@code{gpgme_op_keylist_next} returns @code{GPGME_EOF}), or +@code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or @code{gpgme_op_keylist_end} is called to finish the operation. -The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a -valid pointer, and passes through any errors that are reported by the -crypto engine support routines. +The function returns the error code @code{GPG_ERR_INV_VALUE} if +@var{ctx} is not a valid pointer, and passes through any errors that +are reported by the crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_keylist_ext_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{int @var{secret_only}}, @w{int @var{reserved}}) @@ -2080,12 +2271,12 @@ keys only. The value of @var{reserved} must be @code{0}. The context will be busy until either all keys are received (and -@code{gpgme_op_keylist_next} returns @code{GPGME_EOF}), or +@code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}), or @code{gpgme_op_keylist_end} is called to finish the operation. -The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a -valid pointer, and passes through any errors that are reported by the -crypto engine support routines. +The function returns the error code @code{GPG_ERR_INV_VALUE} if +@var{ctx} is not a valid pointer, and passes through any errors that +are reported by the crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_keylist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t *@var{r_key}}) @@ -2098,11 +2289,11 @@ This is the only way to get at @code{gpgme_key_t} objects in @acronym{GPGME}. If the last key in the list has already been returned, -@code{gpgme_op_keylist_next} returns @code{GPGME_EOF}. +@code{gpgme_op_keylist_next} returns @code{GPG_ERR_EOF}. -The function returns @code{GPGME_Invalid_Value} if @var{ctx} or -@var{r_key} is not a valid pointer, and @code{GPGME_Out_Of_Core} if -there is not enough memory for the operation. +The function returns the error code @code{GPG_ERR_INV_VALUE} if +@var{ctx} or @var{r_key} is not a valid pointer, and +@code{GPG_ERR_ENOMEM} if there is not enough memory for the operation. @end deftypefun @deftypefun gpgme_error_t gpgme_op_keylist_end (@w{gpgme_ctx_t @var{ctx}}) @@ -2113,9 +2304,9 @@ After the operation completed successfully, the result of the key listing operation can be retrieved with @code{gpgme_op_keylist_result}. -The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a -valid pointer, and @code{GPGME_Out_Of_Core} if at some time during the -operation there was not enough memory available. +The function returns the error code @code{GPG_ERR_INV_VALUE} if +@var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some +time during the operation there was not enough memory available. @end deftypefun The following example illustrates how all keys containing a certain @@ -2129,8 +2320,11 @@ gpgme_error_t err = gpgme_new (&ctx); if (!err) @{ err = gpgme_op_keylist_start (ctx, "g10code", 0); - while (!err && (err = gpgme_op_keylist_next (ctx, &key)) != GPGME_EOF) + while (!err) @{ + err = gpgme_op_keylist_next (ctx, &key); + if (err) + break; printf ("%s: %s <%s>\n", gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, 0, 0), gpgme_key_get_string_attr (key, GPGME_ATTR_NAME, 0, 0), @@ -2139,7 +2333,7 @@ if (!err) @} gpgme_release (ctx); @} -if (err) +if (gpg_err_code (err) != GPG_ERR_EOF) @{ fprintf (stderr, "%s: can not list keys: %s\n", argv[0], gpgme_strerror (err)); @@ -2163,11 +2357,12 @@ less than the desired keys could be listed. @deftypefun gpgme_keylist_result_t gpgme_op_keylist_result (@w{gpgme_ctx_t @var{ctx}}) The function @code{gpgme_op_keylist_result} returns a -@code{gpgme_keylist_result_t} pointer to a structure holding the result of -a @code{gpgme_op_keylist_*} operation. The pointer is only valid if -the last operation on the context was a key listing operation, and if -this operation finished successfully. The returned pointer is only -valid until the next operation is started on the context. +@code{gpgme_keylist_result_t} pointer to a structure holding the +result of a @code{gpgme_op_keylist_*} operation. The pointer is only +valid if the last operation on the context was a key listing +operation, and if this operation finished successfully. The returned +pointer is only valid until the next operation is started on the +context. @end deftypefun In a simple program, for which a blocking operation is acceptable, the @@ -2182,13 +2377,13 @@ If @var{secret} is true, get the secret key. The currently active keylist mode is used to retrieve the key. If the key is not found in the keyring, @code{gpgme_get_key} returns -@code{GPGME_No_Error} and *@var{r_key} will be set to @code{NULL}. +the error code @code{GPG_ERR_NO_ERROR} and *@var{r_key} will be set to +@code{NULL}. -The function returns @code{GPGME_Invalid_Value} if @var{ctx} or -@var{r_key} is not a valid pointer, @code{GPGME_Invalid_Key} if -@var{fpr} is not a fingerprint or key ID, @code{GPGME_Out_Of_Core} if -at some time during the operation there was not enough memory -available. +The function returns the error code @code{GPG_ERR_INV_VALUE} if +@var{ctx} or @var{r_key} is not a valid pointer or @var{fpr} is not a +fingerprint or key ID, and @code{GPG_ERR_ENOMEM} if at some time +during the operation there was not enough memory available. @end deftypefun @@ -2393,8 +2588,8 @@ returned. The argument @var{reserved} is reserved for later use and should be @code{NULL}. The function returns @code{0} if the attribute can't be returned as a -number, @var{key} is not a valid pointer, @var{idx} out of range, -or @var{reserved} not @code{NULL}. +number, @var{key} is not a valid pointer, @var{idx} out of range, or +@var{reserved} not @code{NULL}. @end deftypefun @@ -2590,11 +2785,11 @@ statements are not allowed. After the operation completed successfully, the result can be retrieved with @code{gpgme_op_genkey_result}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, @code{GPGME_Invalid_Value} if @var{parms} is not -a valid XML string, @code{GPGME_Not_Supported} if @var{public} or -@var{secret} is not valid, and @code{GPGME_General_Error} if no key -was created by the backend. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, @code{GPG_ERR_INV_VALUE} if +@var{parms} is not a valid XML string, @code{GPG_ERR_NOT_SUPPORTED} if +@var{public} or @var{secret} is not valid, and @code{GPG_ERR_GENERAL} +if no key was created by the backend. @end deftypefun @deftypefun gpgme_error_t gpgme_op_genkey_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{parms}}, @w{gpgme_data_t @var{public}}, @w{gpgme_data_t @var{secret}}) @@ -2602,10 +2797,11 @@ The function @code{gpgme_op_genkey_start} initiates a @code{gpgme_op_genkey} operation. It can be completed by calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, @code{GPGME_Invalid_Value} if @var{parms} is not -a valid XML string, and @code{GPGME_Not_Supported} if @var{public} or -@var{secret} is not @code{NULL}. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, @code{GPG_ERR_INV_VALUE} if +@var{parms} is not a valid XML string, and +@code{GPG_ERR_NOT_SUPPORTED} if @var{public} or @var{secret} is not +@code{NULL}. @end deftypefun @deftp {Data type} {gpgme_genkey_result_t} @@ -2660,10 +2856,10 @@ is used to limit the list to all keys matching the pattern. @var{reserved} is reserved for future use and must be @code{0}. -The function returns @code{GPGME_No_Error} if the operation completed -successfully, @code{GPGME_Invalid_Value} if @var{keydata} is not a -valid empty data buffer, and passes through any errors that are -reported by the crypto engine support routines. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation completed successfully, @code{GPG_ERR_INV_VALUE} if +@var{keydata} is not a valid empty data buffer, and passes through any +errors that are reported by the crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_export_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}}) @@ -2671,9 +2867,9 @@ The function @code{gpgme_op_export_start} initiates a @code{gpgme_op_export} operation. It can be completed by calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, and @code{GPGME_Invalid_Value} if @var{keydata} -is not a valid empty data buffer. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, and @code{GPG_ERR_INV_VALUE} +if @var{keydata} is not a valid empty data buffer. @end deftypefun @deftypefun gpgme_error_t gpgme_op_export_ext (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}}) @@ -2689,10 +2885,10 @@ at least one of the patterns verbatim. @var{reserved} is reserved for future use and must be @code{0}. -The function returns @code{GPGME_No_Error} if the operation completed -successfully, @code{GPGME_Invalid_Value} if @var{keydata} is not a -valid empty data buffer, and passes through any errors that are -reported by the crypto engine support routines. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation completed successfully, @code{GPG_ERR_INV_VALUE} if +@var{keydata} is not a valid empty data buffer, and passes through any +errors that are reported by the crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_export_ext_start (@w{gpgme_ctx_t @var{ctx}}, @w{const char *@var{pattern}[]}, @w{unsigned int @var{reserved}}, @w{gpgme_data_t @var{keydata}}) @@ -2700,9 +2896,9 @@ The function @code{gpgme_op_export_ext_start} initiates a @code{gpgme_op_export_ext} operation. It can be completed by calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, and @code{GPGME_Invalid_Value} if @var{keydata} -is not a valid empty data buffer. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, and @code{GPG_ERR_INV_VALUE} +if @var{keydata} is not a valid empty data buffer. @end deftypefun @@ -2720,10 +2916,10 @@ but the details are specific to the crypto engine. After the operation completed successfully, the result can be retrieved with @code{gpgme_op_import_result}. -The function returns @code{GPGME_No_Error} if the import was completed -successfully, @code{GPGME_Invalid_Value} if @var{keydata} if @var{ctx} -or @var{keydata} is not a valid pointer, and @code{GPGME_No_Data} if -@var{keydata} is an empty data buffer. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +import was completed successfully, @code{GPG_ERR_INV_VALUE} if +@var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer, +and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer. @end deftypefun @deftypefun gpgme_error_t gpgme_op_import_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{keydata}}) @@ -2731,10 +2927,10 @@ The function @code{gpgme_op_import_start} initiates a @code{gpgme_op_import} operation. It can be completed by calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the import could be -started successfully, @code{GPGME_Invalid_Value} if @var{keydata} if -@var{ctx} or @var{keydata} is not a valid pointer, and -@code{GPGME_No_Data} if @var{keydata} is an empty data buffer. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +import could be started successfully, @code{GPG_ERR_INV_VALUE} if +@var{keydata} if @var{ctx} or @var{keydata} is not a valid pointer, +and @code{GPG_ERR_NO_DATA} if @var{keydata} is an empty data buffer. @end deftypefun @deftp {Data type} {gpgme_import_status_t} @@ -2753,7 +2949,8 @@ This is the fingerprint of the key that was considered. @item gpgme_error_t result If the import was not successful, this is the error value that caused -the import to fail. Otherwise it is @code{GPGME_No_Error}. +the import to fail. Otherwise the error code is +@code{GPG_ERR_NO_ERROR}. @item unsigned int status This is a bit-wise OR of the following flags that give more @@ -2834,9 +3031,9 @@ about the keys for which an import was attempted. @deftypefun gpgme_import_result_t gpgme_op_import_result (@w{gpgme_ctx_t @var{ctx}}) The function @code{gpgme_op_import_result} returns a -@code{gpgme_import_result_t} pointer to a structure holding the result of -a @code{gpgme_op_import} operation. The pointer is only valid if the -last operation on the context was a @code{gpgme_op_import} or +@code{gpgme_import_result_t} pointer to a structure holding the result +of a @code{gpgme_op_import} operation. The pointer is only valid if +the last operation on the context was a @code{gpgme_op_import} or @code{gpgme_op_import_start} operation, and if this operation finished successfully. The returned pointer is only valid until the next operation is started on the context. @@ -2871,12 +3068,13 @@ key ring of the crypto engine used by @var{ctx}. If @var{allow_secret} is @code{0}, only public keys are deleted, otherwise secret keys are deleted as well, if that is supported. -The function returns @code{GPGME_No_Error} if the key was deleted -successfully, @code{GPGME_Invalid_Value} if @var{ctx} or @var{key} is -not a valid pointer, @code{GPGME_Invalid_Key} if @var{key} could not -be found in the keyring, @code{GPGME_Ambiguous_Specification} if the -key was not specified unambiguously, and @code{GPGME_Conflict} if the -secret key for @var{key} is available, but @var{allow_secret} is zero. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the key +was deleted successfully, @code{GPG_ERR_INV_VALUE} if @var{ctx} or +@var{key} is not a valid pointer, @code{GPG_ERR_NO_PUBKEY} if +@var{key} could not be found in the keyring, +@code{GPG_ERR_AMBIGUOUS_NAME} if the key was not specified +unambiguously, and @code{GPG_ERR_CONFLICT} if the secret key for +@var{key} is available, but @var{allow_secret} is zero. @end deftypefun @deftypefun gpgme_error_t gpgme_op_delete_start (@w{gpgme_ctx_t @var{ctx}}, @w{const gpgme_key_t @var{key}}, @w{int @var{allow_secret}}) @@ -2884,9 +3082,9 @@ The function @code{gpgme_op_delete_start} initiates a @code{gpgme_op_delete} operation. It can be completed by calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation was -started successfully, and @code{GPGME_Invalid_Value} if @var{ctx} or -@var{key} is not a valid pointer. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation was started successfully, and @code{GPG_ERR_INV_VALUE} if +@var{ctx} or @var{key} is not a valid pointer. @end deftypefun @@ -2946,12 +3144,12 @@ can not be the empty string. The argument @var{max_level} is currently ignored. The context will be busy until either all trust items are received -(and @code{gpgme_op_trustlist_next} returns @code{GPGME_EOF}), or +(and @code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}), or @code{gpgme_op_trustlist_end} is called to finish the operation. -The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a -valid pointer, and passes through any errors that are reported by the -crypto engine support routines. +The function returns the error code @code{GPG_ERR_INV_VALUE} if +@var{ctx} is not a valid pointer, and passes through any errors that +are reported by the crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_trustlist_next (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_trust_item_t *@var{r_item}}) @@ -2964,10 +3162,10 @@ This is the only way to get at @code{gpgme_trust_item_t} objects in @acronym{GPGME}. If the last trust item in the list has already been returned, -@code{gpgme_op_trustlist_next} returns @code{GPGME_EOF}. +@code{gpgme_op_trustlist_next} returns @code{GPG_ERR_EOF}. -The function returns @code{GPGME_Invalid_Value} if @var{ctx} or -@var{r_item} is not a valid pointer, and @code{GPGME_Out_Of_Core} if +The function returns the error code @code{GPG_ERR_INV_VALUE} if @var{ctx} or +@var{r_item} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if there is not enough memory for the operation. @end deftypefun @@ -2975,9 +3173,9 @@ there is not enough memory for the operation. The function @code{gpgme_op_trustlist_next} ends a pending key list operation in the context @var{ctx}. -The function returns @code{GPGME_Invalid_Value} if @var{ctx} is not a -valid pointer, and @code{GPGME_Out_Of_Core} if at some time during the -operation there was not enough memory available. +The function returns the error code @code{GPG_ERR_INV_VALUE} if +@var{ctx} is not a valid pointer, and @code{GPG_ERR_ENOMEM} if at some +time during the operation there was not enough memory available. @end deftypefun @@ -3095,12 +3293,12 @@ The function @code{gpgme_op_decrypt} decrypts the ciphertext in the data object @var{cipher} and stores it into the data object @var{plain}. -The function returns @code{GPGME_No_Error} if the ciphertext could be -decrypted successfully, @code{GPGME_Invalid_Value} if @var{ctx}, -@var{cipher} or @var{plain} is not a valid pointer, -@code{GPGME_No_Data} if @var{cipher} does not contain any data to -decrypt, @code{GPGME_Decryption_Failed} if @var{cipher} is not a valid -cipher text, @code{GPGME_Bad_Passphrase} if the passphrase for the +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE} +if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer, +@code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to +decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid +cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the secret key could not be retrieved, and passes through any errors that are reported by the crypto engine support routines. @end deftypefun @@ -3110,9 +3308,9 @@ The function @code{gpgme_op_decrypt_start} initiates a @code{gpgme_op_decrypt} operation. It can be completed by calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, and @code{GPGME_Invalid_Value} if @var{cipher} -or @var{plain} is not a valid pointer. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, and @code{GPG_ERR_INV_VALUE} +if @var{cipher} or @var{plain} is not a valid pointer. @end deftypefun @deftp {Data type} {gpgme_decrypt_result_t} @@ -3160,12 +3358,12 @@ verification. The results of the individual signature verifications can be retrieved with @code{gpgme_op_verify_result}. -The function returns @code{GPGME_No_Error} if the operation could be -completed successfully, @code{GPGME_Invalid_Value} if @var{ctx}, -@var{sig}, @var{plain} or @var{r_stat} is not a valid pointer, -@code{GPGME_No_Data} if @var{sig} does not contain any data to verify, -and passes through any errors that are reported by the crypto engine -support routines. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be completed successfully, @code{GPG_ERR_INV_VALUE} if +@var{ctx}, @var{sig}, @var{plain} or @var{r_stat} is not a valid +pointer, @code{GPG_ERR_NO_DATA} if @var{sig} does not contain any data +to verify, and passes through any errors that are reported by the +crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_verify_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_data_t @var{signed_text}}, @w{gpgme_data_t @var{plain}}) @@ -3173,11 +3371,11 @@ The function @code{gpgme_op_verify_start} initiates a @code{gpgme_op_verify} operation. It can be completed by calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, @code{GPGME_Invalid_Value} if @var{ctx}, -@var{sig}, @var{plain} or @var{r_stat} is not a valid pointer, and -@code{GPGME_No_Data} if @var{sig} or @var{plain} does not contain any -data to verify. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, @code{GPG_ERR_INV_VALUE} if +@var{ctx}, @var{sig}, @var{plain} or @var{r_stat} is not a valid +pointer, and @code{GPG_ERR_NO_DATA} if @var{sig} or @var{plain} does +not contain any data to verify. @end deftypefun @deftp {Data type} {gpgme_sig_notation_t} @@ -3265,30 +3463,30 @@ This is the status of the signature. In particular, the following status codes are of interest: @table @code - @item GPGME_No_Error + @item GPG_ERR_NO_ERROR This status indicates that the signature is valid. For the combined result this status means that all signatures are valid. - @item GPGME_Sig_Expired + @item GPG_ERR_SIG_EXPIRED This status indicates that the signature is valid but expired. For the combined result this status means that all signatures are valid and expired. - @item GPGME_Key_Expired + @item GPG_ERR_KEY_EXPIRED This status indicates that the signature is valid but the key used to verify the signature has expired. For the combined result this status means that all signatures are valid and all keys are expired. - @item GPGME_Bad_Signature + @item GPG_ERR_BAD_SIGNATURE This status indicates that the signature is invalid. For the combined result this status means that all signatures are invalid. - @item GPGME_No_Public_Key + @item GPG_ERR_NO_PUBKEY This status indicates that the signature could not be verified due to a missing key. For the combined result this status means that all signatures could not be checked due to missing keys. - @item GPGME_General_Error + @item GPG_ERR_GENERAL This status indicates that there was some other error which prevented the signature verification. @end table @@ -3410,27 +3608,27 @@ The function @code{gpgme_get_sig_status} is equivalent to: @{ switch (sig->status) @{ - case GPGME_No_Error: + case GPG_ERR_NO_ERROR: *r_stat = GPGME_SIG_STAT_GOOD; break; - case GPGME_Bad_Signature: + case GPG_ERR_BAD_SIGNATURE: *r_stat = GPGME_SIG_STAT_BAD; break; - case GPGME_No_Public_Key: + case GPG_ERR_NO_PUBKEY: *r_stat = GPGME_SIG_STAT_NOKEY; break; - case GPGME_No_Data: + case GPG_ERR_NO_DATA: *r_stat = GPGME_SIG_STAT_NOSIG; break; - case GPGME_Sig_Expired: + case GPG_ERR_SIG_EXPIRED: *r_stat = GPGME_SIG_STAT_GOOD_EXP; break; - case GPGME_Key_Expired: + case GPG_ERR_KEY_EXPIRED: *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY; break; @@ -3513,22 +3711,22 @@ The function @code{gpgme_get_sig_ulong_attr} is equivalent to: case GPGME_ATTR_SIG_STATUS: switch (sig->status) @{ - case GPGME_No_Error: + case GPG_ERR_NO_ERROR: return GPGME_SIG_STAT_GOOD; - case GPGME_Bad_Signature: + case GPG_ERR_BAD_SIGNATURE: return GPGME_SIG_STAT_BAD; - case GPGME_No_Public_Key: + case GPG_ERR_NO_PUBKEY: return GPGME_SIG_STAT_NOKEY; - case GPGME_No_Data: + case GPG_ERR_NO_DATA: return GPGME_SIG_STAT_NOSIG; - case GPGME_Sig_Expired: + case GPG_ERR_SIG_EXPIRED: return GPGME_SIG_STAT_GOOD_EXP; - case GPGME_Key_Expired: + case GPG_ERR_KEY_EXPIRED: return GPGME_SIG_STAT_GOOD_EXPKEY; default: @@ -3561,7 +3759,7 @@ The function @code{gpgme_get_sig_key} is equivalent to: idx--; @} if (!sig || idx) - return GPGME_EOF; + return gpg_error (GPG_ERR_EOF); return gpgme_get_key (ctx, sig->fpr, r_key, 0, 0); @end example @@ -3585,14 +3783,14 @@ After the operation completed, @code{gpgme_op_get_sig_status} and @code{gpgme_op_get_sig_key} can be used to retrieve more information about the signatures. -The function returns @code{GPGME_No_Error} if the ciphertext could be -decrypted successfully, @code{GPGME_Invalid_Value} if @var{ctx}, -@var{cipher}, @var{plain} or @var{r_stat} is not a valid pointer, -@code{GPGME_No_Data} if @var{cipher} does not contain any data to -decrypt, @code{GPGME_Decryption_Failed} if @var{cipher} is not a valid -cipher text, @code{GPGME_Bad_Passphrase} if the passphrase for the -secret key could not be retrieved, and passes through any errors that -are reported by the crypto engine support routines. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +ciphertext could be decrypted successfully, @code{GPG_ERR_INV_VALUE} +if @var{ctx}, @var{cipher}, @var{plain} or @var{r_stat} is not a valid +pointer, @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any +data to decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not +a valid cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase +for the secret key could not be retrieved, and passes through any +errors that are reported by the crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_decrypt_verify (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{cipher}}, @w{gpgme_data_t @var{plain}}) @@ -3601,11 +3799,11 @@ The function @code{gpgme_op_decrypt_verify_start} initiates a calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, @code{GPGME_Invalid_Value} if @var{ctx}, -@var{cipher}, @var{plain} or @var{r_stat} is not a valid pointer, and -@code{GPGME_No_Data} if @var{cipher} does not contain any data to -decrypt. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, @code{GPG_ERR_INV_VALUE} if +@var{ctx}, @var{cipher}, @var{plain} or @var{r_stat} is not a valid +pointer, and @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain +any data to decrypt. @end deftypefun @@ -3691,13 +3889,13 @@ If an S/MIME signed message is created using the CMS crypto engine, the number of certificates to include in the message can be specified with @code{gpgme_set_include_certs}. @xref{Included Certificates}. -The function returns @code{GPGME_No_Error} if the signature could be -created successfully, @code{GPGME_Invalid_Value} if @var{ctx}, -@var{plain} or @var{sig} is not a valid pointer, @code{GPGME_No_Data} -if the signature could not be created, @code{GPGME_Bad_Passphrase} if -the passphrase for the secret key could not be retrieved, and passes -through any errors that are reported by the crypto engine support -routines. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +signature could be created successfully, @code{GPG_ERR_INV_VALUE} if +@var{ctx}, @var{plain} or @var{sig} is not a valid pointer, +@code{GPG_ERR_NO_DATA} if the signature could not be created, +@code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the secret key +could not be retrieved, and passes through any errors that are +reported by the crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_sign_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{sig}}, @w{gpgme_sig_mode_t @var{mode}}) @@ -3705,8 +3903,8 @@ The function @code{gpgme_op_sign_start} initiates a @code{gpgme_op_sign} operation. It can be completed by calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, and @code{GPGME_Invalid_Value} if @var{ctx}, +The function returns the error code @code{GPG_ERR_NO_ERROR} if the operation could be +started successfully, and @code{GPG_ERR_INV_VALUE} if @var{ctx}, @var{plain} or @var{sig} is not a valid pointer. @end deftypefun @@ -3808,9 +4006,9 @@ have a high enough validity in the keyring. This flag should be used with care; in general it is not a good idea to use any untrusted keys. @end table -If @code{GPGME_Invalid_Key} is returned, some recipients in @var{recp} -are invalid, but not all. In this case the plaintext might be -encrypted for all valid recipients and returned in @var{cipher} (if +If @code{GPG_ERR_UNUSABLE_PUBKEY} is returned, some recipients in +@var{recp} are invalid, but not all. In this case the plaintext might +be encrypted for all valid recipients and returned in @var{cipher} (if this happens depends on the crypto engine). More information about the invalid recipients is available with @code{gpgme_op_encrypt_result}. @@ -3822,13 +4020,13 @@ crypto backend needs to retrieve a passphrase from the user. Symmetric encryption is currently only supported for the OpenPGP crypto backend. -The function returns @code{GPGME_No_Error} if the ciphertext could be -created successfully, @code{GPGME_Invalid_Value} if @var{ctx}, -@var{recp}, @var{plain} or @var{cipher} is not a valid pointer, -@code{GPGME_Invalid_Key} if @var{recp} contains some invalid -recipients, @code{GPGME_Bad_Passphrase} if the passphrase for the -secret key could not be retrieved, and passes through any errors that -are reported by the crypto engine support routines. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +ciphertext could be created successfully, @code{GPG_ERR_INV_VALUE} if +@var{ctx}, @var{recp}, @var{plain} or @var{cipher} is not a valid +pointer, @code{GPG_ERR_UNUSABLE_PUBKEY} if @var{recp} contains some +invalid recipients, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase +for the secret key could not be retrieved, and passes through any +errors that are reported by the crypto engine support routines. @end deftypefun @deftypefun gpgme_error_t gpgme_op_encrypt_start (@w{gpgme_ctx_t @var{ctx}}, @w{gpgme_key_t @var{recp}[]}, @w{gpgme_encrypt_flags_t @var{flags}}, @w{gpgme_data_t @var{plain}}, @w{gpgme_data_t @var{cipher}}) @@ -3840,11 +4038,11 @@ References to the keys only need to be held for the duration of this call. The user can release its references to the keys after this function returns, even if the operation is not yet finished. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, @code{GPGME_Invalid_Value} if @var{ctx}, -@var{rset}, @var{plain} or @var{cipher} is not a valid pointer, and -@code{GPGME_No_UserID} if @var{rset} does not contain any valid -recipients. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, @code{GPG_ERR_INV_VALUE} if +@var{ctx}, @var{rset}, @var{plain} or @var{cipher} is not a valid +pointer, and @code{GPG_ERR_UNUSABLE_PUBKEY} if @var{rset} does not +contain any valid recipients. @end deftypefun @deftp {Data type} {gpgme_encrypt_result_t} @@ -3888,9 +4086,10 @@ The function @code{gpgme_op_encrypt_sign_start} initiates a calling @code{gpgme_wait} on the context. @xref{Waiting For Completion}. -The function returns @code{GPGME_No_Error} if the operation could be -started successfully, and @code{GPGME_Invalid_Value} if @var{ctx}, -@var{rset}, @var{plain} or @var{cipher} is not a valid pointer. +The function returns the error code @code{GPG_ERR_NO_ERROR} if the +operation could be started successfully, and @code{GPG_ERR_INV_VALUE} +if @var{ctx}, @var{rset}, @var{plain} or @var{cipher} is not a valid +pointer. @end deftypefun @@ -4230,7 +4429,7 @@ add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc, void *fnc_data, @} pthread_mutex_unlock (&loop->lock); if (i == MAX_FDS) - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); *r_tag = &fds[i]; return 0; @} @@ -4249,13 +4448,12 @@ void event_io_cb (void *data, gpgme_event_io_t type, void *type_data) @{ struct op_result *result = data; - gpgme_error_t *err = data; /* We don't support list operations here. */ if (type == GPGME_EVENT_DONE) @{ result->done = 1; - result->err = *data; + result->err = *type_data; @} @} @end example @@ -4367,7 +4565,8 @@ main (int argc, char *argv[]) @} if (err) @{ - fprintf (stderr, "gpgme error: %s\n", gpgme_strerror (err)); + fprintf (stderr, "gpgme error: %s: %s\n", + gpgme_strsource (err), gpgme_strerror (err)); exit (1); @} @@ -4379,7 +4578,8 @@ main (int argc, char *argv[]) @} if (!result.err) @{ - fprintf (stderr, "verification failed: %s\n", gpgme_strerror (result.err)); + fprintf (stderr, "verification failed: %s: %s\n", + gpgme_strsource (result.err), gpgme_strerror (result.err)); exit (1); @} /* Evaluate STATUS. */ diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index e06afb02..a3b2d3f6 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,23 @@ +2003-06-05 Marcus Brinkmann + + 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 * gpgme.h (gpgme_op_export_start): Change second arg to const char *. diff --git a/gpgme/Makefile.am b/gpgme/Makefile.am index b4181797..9f61fc1b 100644 --- a/gpgme/Makefile.am +++ b/gpgme/Makefile.am @@ -19,9 +19,9 @@ ## Process this file with automake to produce Makefile.in -EXTRA_DIST = gpgme-config.in gpgme.m4 mkerrors mkstatus libgpgme.vers -BUILT_SOURCES = errors.c status-table.h -MOSTLYCLEANFILES = errors.c status-table.h +EXTRA_DIST = gpgme-config.in gpgme.m4 mkstatus libgpgme.vers +BUILT_SOURCES = status-table.h +MOSTLYCLEANFILES = status-table.h bin_SCRIPTS = gpgme-config m4datadir = $(datadir)/aclocal m4data_DATA = gpgme.m4 @@ -81,16 +81,12 @@ libgpgme_la_SOURCES = \ import.c export.c genkey.c delete.c edit.c \ engine.h engine-backend.h engine.c rungpg.c status-table.h \ ${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@ \ $(srcdir)/libgpgme.vers libgpgme_la_LIBADD = ${assuan_libobjs} @LTLIBOBJS@ -errors.c : gpgme.h - $(srcdir)/mkerrors < $(srcdir)/gpgme.h > errors.c - status-table.h : gpgme.h $(srcdir)/mkstatus < $(srcdir)/gpgme.h > status-table.h - diff --git a/gpgme/conversion.c b/gpgme/conversion.c index 117df528..c98f3776 100644 --- a/gpgme/conversion.c +++ b/gpgme/conversion.c @@ -24,6 +24,7 @@ #include #include +#include #include "gpgme.h" #include "util.h" @@ -72,7 +73,7 @@ _gpgme_decode_c_string (const char *src, char **destp, int len) if (len) { if (len < strlen (src) + 1) - return GPGME_General_Error; + return gpg_error (GPG_ERR_INTERNAL); dest = *destp; } @@ -82,7 +83,7 @@ _gpgme_decode_c_string (const char *src, char **destp, int len) string. */ dest = malloc (strlen (src) + 1); if (!dest) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); *destp = dest; } @@ -175,7 +176,7 @@ _gpgme_decode_percent_string (const char *src, char **destp, int len) if (len) { if (len < strlen (src) + 1) - return GPGME_General_Error; + return gpg_error (GPG_ERR_INTERNAL); dest = *destp; } @@ -185,7 +186,7 @@ _gpgme_decode_percent_string (const char *src, char **destp, int len) string. */ dest = malloc (strlen (src) + 1); if (!dest) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); *destp = dest; } @@ -238,84 +239,84 @@ static struct gpgme_error_t err; } gnupg_errors[] = { - { "EOF", GPGME_EOF }, - { "No_Error", GPGME_No_Error }, - { "General_Error", GPGME_General_Error }, - { "Out_Of_Core", GPGME_Out_Of_Core }, - { "Invalid_Value", GPGME_Invalid_Value }, - { "IO_Error", GPGME_General_Error }, - { "Resource_Limit", GPGME_General_Error }, - { "Internal_Error", GPGME_General_Error }, - { "Bad_Certificate", GPGME_Invalid_Key }, - { "Bad_Certificate_Chain", GPGME_General_Error }, - { "Missing_Certificate", GPGME_No_Public_Key }, - { "No_Data", GPGME_No_Data }, - { "Bad_Signature", GPGME_Bad_Signature }, - { "Not_Implemented", GPGME_Not_Implemented }, - { "Conflict", GPGME_Conflict }, - { "Bug", GPGME_General_Error }, - { "Read_Error", GPGME_General_Error }, - { "Write_Error", GPGME_General_Error }, - { "Invalid_Line", GPGME_General_Error }, - { "Incomplete_Line", GPGME_General_Error }, - { "Invalid_Response", GPGME_General_Error }, - { "Agent_Error", GPGME_General_Error }, - { "No_Public_Key", GPGME_No_Public_Key }, - { "No_Secret_Key", GPGME_No_Secret_Key }, - { "File_Open_Error", GPGME_General_Error }, - { "File_Create_Error", GPGME_General_Error }, - { "File_Error", GPGME_General_Error }, - { "Not_Supported", GPGME_General_Error }, - { "Invalid_Data", GPGME_General_Error }, - { "Assuan_Server_Fault", GPGME_General_Error }, - { "Assuan_Error", GPGME_General_Error }, - { "Invalid_Session_Key", GPGME_General_Error }, - { "Invalid_Sexp", GPGME_General_Error }, - { "Unsupported_Algorithm", GPGME_Unsupported_Algorithm }, - { "No_PIN_Entry", GPGME_Invalid_Engine }, - { "PIN_Entry_Error", GPGME_Invalid_Engine }, - { "Bad_PIN", GPGME_Bad_Passphrase }, - { "Bad_Passphrase", GPGME_Bad_Passphrase }, - { "Invalid_Name", GPGME_General_Error }, - { "Bad_Public_Key", GPGME_General_Error }, - { "Bad_Secret_Key", GPGME_General_Error }, - { "Bad_Data", GPGME_General_Error }, - { "Invalid_Parameter", GPGME_General_Error }, - { "Tribute_to_D_A", GPGME_General_Error }, - { "No_Dirmngr", GPGME_Invalid_Engine }, - { "Dirmngr_Error", GPGME_General_Error }, - { "Certificate_Revoked", GPGME_Key_Revoked }, - { "No_CRL_Known", GPGME_No_CRL_Known }, - { "CRL_Too_Old", GPGME_CRL_Too_Old }, - { "Line_Too_Long", GPGME_General_Error }, - { "Not_Trusted", GPGME_Key_Not_Trusted }, - { "Canceled", GPGME_Canceled }, - { "Bad_CA_Certificate", GPGME_General_Error }, - { "Certificate_Expired", GPGME_Key_Expired }, - { "Certificate_Too_Young", GPGME_Invalid_Key }, - { "Unsupported_Certificate", GPGME_General_Error }, - { "Unknown_Sexp", GPGME_General_Error }, - { "Unsupported_Protection", GPGME_General_Error }, - { "Corrupted_Protection", GPGME_General_Error }, - { "Ambiguous_Name", GPGME_Ambiguous_Specification }, - { "Card_Error", GPGME_General_Error }, - { "Card_Reset", GPGME_General_Error }, - { "Card_Removed", GPGME_General_Error }, - { "Invalid_Card", GPGME_General_Error }, - { "Card_Not_Present", GPGME_General_Error }, - { "No_PKCS15_App", GPGME_General_Error }, - { "Not_Confirmed", GPGME_General_Error }, - { "Configuration_Error", GPGME_General_Error }, - { "No_Policy_Match", GPGME_Policy_Mismatch }, - { "Invalid_Index", GPGME_General_Error }, - { "Invalid_Id", GPGME_General_Error }, - { "No_Scdaemon", GPGME_Invalid_Engine }, - { "Scdaemon_Error", GPGME_General_Error }, - { "Unsupported_Protocol", GPGME_General_Error }, - { "Bad_PIN_Method", GPGME_General_Error }, - { "Card_Not_Initialized", GPGME_General_Error }, - { "Unsupported_Operation", GPGME_General_Error }, - { "Wrong_Key_Usage", GPGME_Wrong_Key_Usage } + { "EOF", GPG_ERR_EOF }, + { "No_Error", GPG_ERR_NO_ERROR }, + { "General_Error", GPG_ERR_GENERAL }, + { "Out_Of_Core", GPG_ERR_ENOMEM }, + { "Invalid_Value", GPG_ERR_INV_VALUE }, + { "IO_Error", GPG_ERR_GENERAL }, + { "Resource_Limit", GPG_ERR_RESOURCE_LIMIT }, + { "Internal_Error", GPG_ERR_INTERNAL }, + { "Bad_Certificate", GPG_ERR_BAD_CERT }, + { "Bad_Certificate_Chain", GPG_ERR_BAD_CERT_CHAIN}, + { "Missing_Certificate", GPG_ERR_MISSING_CERT }, + { "No_Data", GPG_ERR_NO_DATA }, + { "Bad_Signature", GPG_ERR_BAD_SIGNATURE }, + { "Not_Implemented", GPG_ERR_NOT_IMPLEMENTED }, + { "Conflict", GPG_ERR_CONFLICT }, + { "Bug", GPG_ERR_BUG }, + { "Read_Error", GPG_ERR_GENERAL }, + { "Write_Error", GPG_ERR_GENERAL }, + { "Invalid_Line", GPG_ERR_GENERAL }, + { "Incomplete_Line", GPG_ERR_INCOMPLETE_LINE }, + { "Invalid_Response", GPG_ERR_INV_RESPONSE }, + { "Agent_Error", GPG_ERR_AGENT }, + { "No_Public_Key", GPG_ERR_NO_PUBKEY }, + { "No_Secret_Key", GPG_ERR_NO_SECKEY }, + { "File_Open_Error", GPG_ERR_GENERAL }, + { "File_Create_Error", GPG_ERR_GENERAL }, + { "File_Error", GPG_ERR_GENERAL }, + { "Not_Supported", GPG_ERR_NOT_SUPPORTED }, + { "Invalid_Data", GPG_ERR_INV_DATA }, + { "Assuan_Server_Fault", GPG_ERR_ASSUAN_SERVER_FAULT }, + { "Assuan_Error", GPG_ERR_ASSUAN }, + { "Invalid_Session_Key", GPG_ERR_INV_SESSION_KEY }, + { "Invalid_Sexp", GPG_ERR_INV_SEXP }, + { "Unsupported_Algorithm", GPG_ERR_UNSUPPORTED_ALGORITHM }, + { "No_PIN_Entry", GPG_ERR_NO_PIN_ENTRY }, + { "PIN_Entry_Error", GPG_ERR_NO_PIN_ENTRY }, + { "Bad_PIN", GPG_ERR_BAD_PIN }, + { "Bad_Passphrase", GPG_ERR_BAD_PASSPHRASE }, + { "Invalid_Name", GPG_ERR_INV_NAME }, + { "Bad_Public_Key", GPG_ERR_BAD_PUBKEY }, + { "Bad_Secret_Key", GPG_ERR_BAD_SECKEY }, + { "Bad_Data", GPG_ERR_BAD_DATA }, + { "Invalid_Parameter", GPG_ERR_INV_PARAMETER }, + { "Tribute_to_D_A", GPG_ERR_TRIBUTE_TO_D_A }, + { "No_Dirmngr", GPG_ERR_NO_DIRMNGR }, + { "Dirmngr_Error", GPG_ERR_DIRMNGR }, + { "Certificate_Revoked", GPG_ERR_CERT_REVOKED }, + { "No_CRL_Known", GPG_ERR_NO_CRL_KNOWN }, + { "CRL_Too_Old", GPG_ERR_CRL_TOO_OLD }, + { "Line_Too_Long", GPG_ERR_LINE_TOO_LONG }, + { "Not_Trusted", GPG_ERR_NOT_TRUSTED }, + { "Canceled", GPG_ERR_CANCELED }, + { "Bad_CA_Certificate", GPG_ERR_BAD_CA_CERT }, + { "Certificate_Expired", GPG_ERR_CERT_EXPIRED }, + { "Certificate_Too_Young", GPG_ERR_CERT_TOO_YOUNG }, + { "Unsupported_Certificate", GPG_ERR_UNSUPPORTED_CERT }, + { "Unknown_Sexp", GPG_ERR_UNKNOWN_SEXP }, + { "Unsupported_Protection", GPG_ERR_UNSUPPORTED_PROTECTION }, + { "Corrupted_Protection", GPG_ERR_CORRUPTED_PROTECTION }, + { "Ambiguous_Name", GPG_ERR_AMBIGUOUS_NAME }, + { "Card_Error", GPG_ERR_CARD }, + { "Card_Reset", GPG_ERR_CARD_RESET }, + { "Card_Removed", GPG_ERR_CARD_REMOVED }, + { "Invalid_Card", GPG_ERR_INV_CARD }, + { "Card_Not_Present", GPG_ERR_CARD_NOT_PRESENT }, + { "No_PKCS15_App", GPG_ERR_NO_PKCS15_APP }, + { "Not_Confirmed", GPG_ERR_NOT_CONFIRMED }, + { "Configuration_Error", GPG_ERR_CONFIGURATION }, + { "No_Policy_Match", GPG_ERR_NO_POLICY_MATCH }, + { "Invalid_Index", GPG_ERR_INV_INDEX }, + { "Invalid_Id", GPG_ERR_INV_ID }, + { "No_Scdaemon", GPG_ERR_NO_SCDAEMON }, + { "Scdaemon_Error", GPG_ERR_SCDAEMON }, + { "Unsupported_Protocol", GPG_ERR_UNSUPPORTED_PROTOCOL }, + { "Bad_PIN_Method", GPG_ERR_BAD_PIN_METHOD }, + { "Card_Not_Initialized", GPG_ERR_CARD_NOT_INITIALIZED }, + { "Unsupported_Operation", GPG_ERR_UNSUPPORTED_OPERATION }, + { "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++) 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); } diff --git a/gpgme/data-compat.c b/gpgme/data-compat.c index f3d57dd4..6dc44c32 100644 --- a/gpgme/data-compat.c +++ b/gpgme/data-compat.c @@ -1,5 +1,5 @@ /* 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. @@ -40,27 +40,40 @@ gpgme_data_new_from_filepart (gpgme_data_t *dh, const char *fname, char *buf = NULL; if (stream && fname) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (fname) stream = fopen (fname, "rb"); if (!stream) - return GPGME_File_Error; + return gpg_error_from_errno (errno); 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); 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 && ferror (stream) && errno == EINTR); if (ferror (stream)) { + int saved_errno = errno; if (buf) free (buf); - goto ferr; + if (fname) + fclose (stream); + return gpg_error_from_errno (saved_errno); } 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.length = length; 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; if (!fname || !copy) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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); } @@ -110,26 +114,32 @@ gpgme_data_new_from_file (gpgme_data_t *dh, const char *fname, int copy) static int gpgme_error_to_errno (gpgme_error_t err) { - switch (err) + int no = gpg_err_code_to_errno (err); + + if (no) { - case GPGME_EOF: - return 0; - case GPGME_Out_Of_Core: - errno = ENOMEM; + errno = no; return -1; - case GPGME_Invalid_Value: + } + + switch (gpg_err_code (err)) + { + case GPG_ERR_EOF: + return 0; + case GPG_ERR_INV_VALUE: errno = EINVAL; return -1; - case GPGME_Not_Implemented: + case GPG_ERR_NOT_SUPPORTED: errno = EOPNOTSUPP; return -1; default: - /* XXX Yeah, well. */ + /* FIXME: Yeah, well. */ errno = EINVAL; return -1; } } + static ssize_t 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) { return (gpgme_data_seek (dh, 0, SEEK_SET) == -1) - ? GPGME_File_Error : 0; + ? gpg_error_from_errno (errno) : 0; } diff --git a/gpgme/data.c b/gpgme/data.c index c10e89c1..80a3fb4b 100644 --- a/gpgme/data.c +++ b/gpgme/data.c @@ -39,12 +39,12 @@ _gpgme_data_new (gpgme_data_t *r_dh, struct _gpgme_data_cbs *cbs) gpgme_data_t dh; if (!r_dh) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); *r_dh = NULL; dh = calloc (1, sizeof (*dh)); if (!dh) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); dh->cbs = cbs; @@ -149,9 +149,9 @@ gpgme_error_t gpgme_data_set_encoding (gpgme_data_t dh, gpgme_data_encoding_t enc) { if (!dh) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (enc < 0 || enc > GPGME_DATA_ENCODING_ARMOR) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); dh->encoding = enc; return 0; } @@ -169,7 +169,7 @@ _gpgme_data_inbound_handler (void *opaque, int fd) buflen = read (fd, buffer, BUFFER_SIZE); if (buflen < 0) - return GPGME_File_Error; + return gpg_error_from_errno (errno); if (buflen == 0) { _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); if (amt == 0 || (amt < 0 && errno != EINTR)) - return GPGME_File_Error; + return gpg_error_from_errno (errno); bufp += 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); if (amt < 0) - return GPGME_File_Error; + return gpg_error_from_errno (errno); if (amt == 0) { _gpgme_io_close (fd); @@ -213,7 +213,7 @@ _gpgme_data_outbound_handler (void *opaque, int fd) return 0; if (nwritten <= 0) - return GPGME_File_Error; + return gpg_error_from_errno (errno); if (nwritten < dh->pending_len) memmove (dh->pending, dh->pending + nwritten, dh->pending_len - nwritten); diff --git a/gpgme/decrypt-verify.c b/gpgme/decrypt-verify.c index a9745059..916cda68 100644 --- a/gpgme/decrypt-verify.c +++ b/gpgme/decrypt-verify.c @@ -55,9 +55,9 @@ decrypt_verify_start (gpgme_ctx_t ctx, int synchronous, return err; if (!cipher) - return GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); if (!plain) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (ctx->passphrase_cb) { diff --git a/gpgme/decrypt.c b/gpgme/decrypt.c index ec98ccd0..e503b266 100644 --- a/gpgme/decrypt.c +++ b/gpgme/decrypt.c @@ -23,6 +23,7 @@ #endif #include #include +#include #include "gpgme.h" #include "util.h" @@ -86,10 +87,12 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code, switch (code) { case GPGME_STATUS_EOF: + /* FIXME: These error values should probably be attributed to + the underlying crypto engine (as error source). */ if (opd->failed) - return GPGME_Decryption_Failed; + return gpg_error (GPG_ERR_DECRYPT_FAILED); else if (!opd->okay) - return GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); break; 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); 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; if (!cipher) - return GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); if (!plain) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (err) return err; diff --git a/gpgme/delete.c b/gpgme/delete.c index 3eca4ecd..30dd4500 100644 --- a/gpgme/delete.c +++ b/gpgme/delete.c @@ -46,7 +46,7 @@ delete_status_handler (void *priv, gpgme_status_code_t code, char *args) errno = 0; problem = strtol (args, &tail, 0); if (errno || (*tail && *tail != ' ')) - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); switch (problem) { @@ -54,16 +54,16 @@ delete_status_handler (void *priv, gpgme_status_code_t code, char *args) break; case DELETE_No_Such_Key: - return GPGME_Invalid_Key; + return gpg_error (GPG_ERR_NO_PUBKEY); case DELETE_Must_Delete_Secret_Key: - return GPGME_Conflict; + return gpg_error (GPG_ERR_CONFLICT); case DELETE_Ambiguous_Specification: - return GPGME_Ambiguous_Specification; + return gpg_error (GPG_ERR_AMBIGUOUS_NAME); default: - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); } } return 0; diff --git a/gpgme/edit.c b/gpgme/edit.c index 023bbe07..5ea68b81 100644 --- a/gpgme/edit.c +++ b/gpgme/edit.c @@ -105,7 +105,7 @@ edit_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t key, return err; 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); opd = hook; diff --git a/gpgme/encrypt-sign.c b/gpgme/encrypt-sign.c index 12dffd2d..8afb1f16 100644 --- a/gpgme/encrypt-sign.c +++ b/gpgme/encrypt-sign.c @@ -48,9 +48,9 @@ encrypt_sign_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t recp[], return err; if (!plain) - return GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); if (!cipher || !recp) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = _gpgme_op_encrypt_init_result (ctx); if (err) diff --git a/gpgme/encrypt.c b/gpgme/encrypt.c index b12850bc..50c13d98 100644 --- a/gpgme/encrypt.c +++ b/gpgme/encrypt.c @@ -91,7 +91,7 @@ _gpgme_encrypt_status_handler (void *priv, gpgme_status_code_t code, { case GPGME_STATUS_EOF: if (opd->result.invalid_recipients) - return GPGME_Invalid_Key; + return gpg_error (GPG_ERR_UNUSABLE_PUBKEY); break; 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: /* Should not happen, because we require at least one recipient. */ - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); default: break; @@ -167,11 +167,11 @@ encrypt_start (gpgme_ctx_t ctx, int synchronous, gpgme_key_t recp[], symmetric = 1; if (!plain) - return GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); if (!cipher) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (recp && ! *recp) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (symmetric && ctx->passphrase_cb) { diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c index ddfdc427..9e17f687 100644 --- a/gpgme/engine-gpgsm.c +++ b/gpgme/engine-gpgsm.c @@ -29,6 +29,7 @@ #include #include #include /* FIXME */ +#include #include "gpgme.h" #include "util.h" @@ -151,100 +152,119 @@ close_notify_handler (int fd, void *opaque) static gpgme_error_t 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) { case ASSUAN_No_Error: - return GPGME_No_Error; + return gpg_error (GPG_ERR_NO_ERROR); case ASSUAN_General_Error: - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); case ASSUAN_Out_Of_Core: - return GPGME_Out_Of_Core; + return gpg_error (GPG_ERR_ENOMEM); case ASSUAN_Invalid_Value: - return GPGME_Invalid_Value; - case ASSUAN_Read_Error: - return GPGME_Read_Error; - case ASSUAN_Write_Error: - return GPGME_Write_Error; - + return gpg_error (GPG_ERR_INV_VALUE); 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_Not_A_Server: case ASSUAN_Not_A_Client: case ASSUAN_Nested_Commands: - case ASSUAN_Invalid_Response: case ASSUAN_No_Data_Callback: case ASSUAN_No_Inquire_Callback: case ASSUAN_Connect_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_Unknown_Command: case ASSUAN_Syntax_Error: case ASSUAN_Parameter_Error: case ASSUAN_Parameter_Conflict: - case ASSUAN_Line_Too_Long: - case ASSUAN_Line_Not_Terminated: - case ASSUAN_Invalid_Data: - case ASSUAN_Unexpected_Command: + case ASSUAN_No_Input: + case ASSUAN_No_Output: + case ASSUAN_No_Data_Available: case ASSUAN_Too_Much_Data: case ASSUAN_Inquire_Unknown: case ASSUAN_Inquire_Error: case ASSUAN_Invalid_Option: - case ASSUAN_Invalid_Index: case ASSUAN_Unexpected_Status: case ASSUAN_Unexpected_Data: case ASSUAN_Invalid_Status: - case ASSUAN_Not_Confirmed: - return GPGME_General_Error; + return gpg_error (GPG_ERR_ASSUAN); - /* These are errors in the server. */ - case ASSUAN_Server_Fault: + case ASSUAN_Invalid_Response: + 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: + return gpg_error (GPG_ERR_RESOURCE_LIMIT); case ASSUAN_Server_IO_Error: + return gpg_error (GPG_ERR_GENERAL); case ASSUAN_Server_Bug: - case ASSUAN_No_Agent: - case ASSUAN_Agent_Error: - return GPGME_Invalid_Engine; /* XXX: Need something more useful. */ - + return gpg_error (GPG_ERR_BUG); + case ASSUAN_Invalid_Data: + 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: + return gpg_error (GPG_ERR_BAD_CERT); case ASSUAN_Bad_Certificate_Chain: + return gpg_error (GPG_ERR_BAD_CERT_CHAIN); case ASSUAN_Missing_Certificate: - case ASSUAN_No_Public_Key: - 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; - + return gpg_error (GPG_ERR_MISSING_CERT); 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: + return gpg_error (GPG_ERR_CERT_REVOKED); case ASSUAN_No_CRL_For_Cert: + return gpg_error (GPG_ERR_NO_CRL_KNOWN); case ASSUAN_CRL_Too_Old: + return gpg_error (GPG_ERR_CRL_TOO_OLD); 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: - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); } } @@ -292,10 +312,7 @@ gpgsm_new (void **engine) gpgsm = calloc (1, sizeof *gpgsm); if (!gpgsm) - { - err = GPGME_Out_Of_Core; - return err; - } + return gpg_error_from_errno (errno); gpgsm->status_cb.fd = -1; gpgsm->status_cb.tag = 0; @@ -325,7 +342,7 @@ gpgsm_new (void **engine) if (_gpgme_io_pipe (fds, 0) < 0) { - err = GPGME_Pipe_Error; + err = gpg_error_from_errno (errno); goto leave; } gpgsm->input_cb.fd = fds[1]; @@ -334,7 +351,7 @@ gpgsm_new (void **engine) if (_gpgme_io_pipe (fds, 1) < 0) { - err = GPGME_Pipe_Error; + err = gpg_error_from_errno (errno); goto leave; } gpgsm->output_cb.fd = fds[0]; @@ -343,7 +360,7 @@ gpgsm_new (void **engine) if (_gpgme_io_pipe (fds, 0) < 0) { - err = GPGME_Pipe_Error; + err = gpg_error_from_errno (errno); goto leave; } gpgsm->message_cb.fd = fds[1]; @@ -369,7 +386,7 @@ gpgsm_new (void **engine) fdlist, DIM (fdlist)); if (nfds < 1) { - err = GPGME_General_Error; /* FIXME */ + err = gpg_error (GPG_ERR_GENERAL); /* FIXME */ goto leave; } /* 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]); if (gpgsm->status_cb.fd < 0) { - err = GPGME_General_Error; /* FIXME */ + err = gpg_error (GPG_ERR_GENERAL); /* FIXME */ goto leave; } gpgsm->status_cb.dir = 1; @@ -391,7 +408,7 @@ gpgsm_new (void **engine) { if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0) { - err = GPGME_Out_Of_Core; + err = gpg_error_from_errno (errno); goto leave; } 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) { - err = GPGME_Out_Of_Core; + err = gpg_error_from_errno (errno); goto leave; } 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) { - err = GPGME_Out_Of_Core; + err = gpg_error_from_errno (errno); goto leave; } err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, NULL, @@ -444,7 +461,7 @@ gpgsm_new (void **engine) old_lc = strdup (old_lc); if (!old_lc) { - err = GPGME_Out_Of_Core; + err = gpg_error_from_errno (errno); goto leave; } } @@ -452,7 +469,7 @@ gpgsm_new (void **engine) if (dft_lc) { if (asprintf (&optstr, "OPTION lc-ctype=%s", dft_lc) < 0) - err = GPGME_Out_Of_Core; + err = gpg_error_from_errno (errno); else { err = assuan_transact (gpgsm->assuan_ctx, optstr, NULL, NULL, @@ -470,14 +487,13 @@ gpgsm_new (void **engine) if (err) goto leave; - old_lc = setlocale (LC_MESSAGES, NULL); if (old_lc) { old_lc = strdup (old_lc); if (!old_lc) { - err = GPGME_Out_Of_Core; + err = gpg_error_from_errno (errno); goto leave; } } @@ -485,7 +501,7 @@ gpgsm_new (void **engine) if (dft_lc) { if (asprintf (&optstr, "OPTION lc-messages=%s", dft_lc) < 0) - err = GPGME_Out_Of_Core; + err = gpg_error_from_errno (errno); else { 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, close_notify_handler, gpgsm))) { - err = GPGME_General_Error; + err = gpg_error (GPG_ERR_GENERAL); goto leave; } @@ -587,10 +603,10 @@ gpgsm_assuan_simple_command (ASSUAN_CONTEXT ctx, char *cmd, if (r >= 0 && status_fnc) status_fnc (status_fnc_value, r, rest); else - err = GPGME_General_Error; + err = gpg_error (GPG_ERR_GENERAL); } else - err = GPGME_General_Error; + err = gpg_error (GPG_ERR_GENERAL); } while (!err); @@ -679,7 +695,7 @@ status_handler (void *opaque, int fd) if (line[3] == ' ') err = map_assuan_error (atoi (&line[4])); else - err = GPGME_General_Error; + err = gpg_error (GPG_ERR_GENERAL); } else if (linelen >= 2 && line[0] == 'O' && line[1] == 'K' @@ -724,7 +740,7 @@ status_handler (void *opaque, int fd) unsigned char *newline = realloc (*aline, *alinelen + linelen + 1); if (!newline) - err = GPGME_Out_Of_Core; + err = gpg_error_from_errno (errno); else { *aline = newline; @@ -850,17 +866,17 @@ gpgsm_decrypt (void *engine, gpgme_data_t ciph, gpgme_data_t plain) gpgme_error_t err; if (!gpgsm) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); gpgsm->input_cb.data = ciph; err = gpgsm_set_fd (gpgsm->assuan_ctx, "INPUT", gpgsm->input_fd_server, map_input_enc (gpgsm->input_cb.data)); if (err) - return GPGME_General_Error; /* FIXME */ + return gpg_error (GPG_ERR_GENERAL); /* FIXME */ gpgsm->output_cb.data = plain; err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, 0); if (err) - return GPGME_General_Error; /* FIXME */ + return gpg_error (GPG_ERR_GENERAL); /* FIXME */ _gpgme_io_close (gpgsm->message_cb.fd); err = start (engine, "DECRYPT"); @@ -879,7 +895,7 @@ gpgsm_delete (void *engine, gpgme_key_t key, int allow_secret) int length = 8; /* "DELKEYS " */ if (!fpr) - return GPGME_Invalid_Key; + return gpg_error (GPG_ERR_INV_VALUE); while (*linep) { @@ -892,7 +908,7 @@ gpgsm_delete (void *engine, gpgme_key_t key, int allow_secret) line = malloc (length); if (!line) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); strcpy (line, "DELKEYS "); linep = &line[8]; @@ -948,7 +964,7 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[]) linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */ line = malloc (10 + 40 + 1); if (!line) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); strcpy (line, "RECIPIENT "); while (!err && recp[i]) { @@ -967,8 +983,9 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[]) char *newline = realloc (line, newlen); if (! newline) { + int saved_errno = errno; free (line); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } line = newline; 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, 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++; else if (err) { @@ -987,7 +1005,8 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[]) i++; } 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; if (!gpgsm) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!recp) - return GPGME_Not_Implemented; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); gpgsm->input_cb.data = plain; 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; if (!gpgsm || reserved) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!pattern) pattern = ""; cmd = malloc (7 + strlen (pattern) + 1); if (!cmd) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); strcpy (cmd, "EXPORT "); strcpy (&cmd[7], pattern); @@ -1070,7 +1089,7 @@ gpgsm_export_ext (void *engine, const char *pattern[], unsigned int reserved, char *linep; if (!gpgsm || reserved) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (pattern && *pattern) { @@ -1094,7 +1113,7 @@ gpgsm_export_ext (void *engine, const char *pattern[], unsigned int reserved, } line = malloc (length); if (!line) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); strcpy (line, "EXPORT "); linep = &line[7]; @@ -1157,7 +1176,7 @@ gpgsm_genkey (void *engine, gpgme_data_t help_data, int use_armor, gpgme_error_t err; if (!gpgsm || !pubkey || seckey) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); gpgsm->input_cb.data = help_data; 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; if (!gpgsm) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); gpgsm->input_cb.data = keydata; 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 = ""; 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); free (line); if (err) @@ -1225,7 +1244,7 @@ gpgsm_keylist (void *engine, const char *pattern, int secret_only, /* Length is "LISTSECRETKEYS " + p + '\0'. */ line = malloc (15 + strlen (pattern) + 1); if (!line) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); if (secret_only) { strcpy (line, "LISTSECRETKEYS "); @@ -1260,7 +1279,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only, int list_mode = 0; if (reserved) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (mode & GPGME_KEYLIST_MODE_LOCAL) list_mode |= 1; @@ -1268,7 +1287,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only, list_mode |= 2; 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); free (line); if (err) @@ -1296,7 +1315,7 @@ gpgsm_keylist_ext (void *engine, const char *pattern[], int secret_only, } line = malloc (length); if (!line) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); if (secret_only) { strcpy (line, "LISTSECRETKEYS "); @@ -1366,10 +1385,10 @@ gpgsm_sign (void *engine, gpgme_data_t in, gpgme_data_t out, gpgme_key_t key; if (!gpgsm) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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); free (assuan_cmd); if (err) @@ -1393,7 +1412,7 @@ gpgsm_sign (void *engine, gpgme_data_t in, gpgme_data_t out, NULL, NULL); } else - err = GPGME_Invalid_Key; + err = gpg_error (GPG_ERR_INV_VALUE); gpgme_key_unref (key); if (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 gpgsm_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text, 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; if (!gpgsm) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); gpgsm->input_cb.data = sig; 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_ext, gpgsm_sign, - gpgsm_trustlist, + NULL, /* trustlist */ gpgsm_verify, gpgsm_set_io_cbs, gpgsm_io_event diff --git a/gpgme/engine.c b/gpgme/engine.c index 347c3025..afb831d4 100644 --- a/gpgme/engine.c +++ b/gpgme/engine.c @@ -23,6 +23,7 @@ #endif #include #include +#include #include "gpgme.h" #include "util.h" @@ -99,7 +100,7 @@ gpgme_engine_check_version (gpgme_protocol_t proto) { return _gpgme_compare_versions (engine_get_version (proto), engine_get_req_version (proto)) - ? 0 : GPGME_Invalid_Engine; + ? 0 : gpg_error (GPG_ERR_INV_ENGINE); } @@ -117,7 +118,7 @@ gpgme_get_engine_info (gpgme_engine_info_t *info) { gpgme_engine_info_t *lastp = &engine_info; gpgme_protocol_t proto_list[] = { GPGME_PROTOCOL_OpenPGP, - GPGME_PROTOCOL_CMS }; + GPGME_PROTOCOL_CMS }; int proto; for (proto = 0; proto < DIM (proto_list); proto++) @@ -130,6 +131,8 @@ gpgme_get_engine_info (gpgme_engine_info_t *info) *lastp = malloc (sizeof (*engine_info)); if (!*lastp) { + int saved_errno = errno; + while (engine_info) { 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; } UNLOCK (engine_info_lock); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } (*lastp)->protocol = proto_list[proto]; @@ -162,19 +165,19 @@ _gpgme_engine_new (gpgme_protocol_t proto, engine_t *r_engine) const char *version; if (proto > DIM (engine_ops)) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!engine_ops[proto]) - return GPGME_Invalid_Engine; + return gpg_error (GPG_ERR_INV_ENGINE); file_name = engine_get_file_name (proto); version = engine_get_version (proto); if (!file_name || !version) - return GPGME_Invalid_Engine; + return gpg_error (GPG_ERR_INV_ENGINE); engine = calloc (1, sizeof *engine); if (!engine) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); engine->ops = engine_ops[proto]; if (engine_ops[proto]->new) @@ -225,10 +228,10 @@ _gpgme_engine_set_command_handler (engine_t engine, gpgme_data_t linked_data) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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, fnc, fnc_value, linked_data); @@ -240,10 +243,10 @@ _gpgme_engine_set_colon_line_handler (engine_t engine, void *fnc_value) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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, fnc, fnc_value); @@ -254,10 +257,10 @@ _gpgme_engine_op_decrypt (engine_t engine, gpgme_data_t ciph, gpgme_data_t plain) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!engine->ops->decrypt) - return GPGME_Not_Implemented; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); 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) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!engine->ops->delete) - return GPGME_Not_Implemented; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); 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 */) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!engine->ops->edit) - return GPGME_Not_Implemented; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); 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) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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, 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 */) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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, plain, ciph, use_armor, ctx); @@ -329,10 +332,10 @@ _gpgme_engine_op_export (engine_t engine, const char *pattern, int use_armor) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!engine->ops->export) - return GPGME_Not_Implemented; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); return (*engine->ops->export) (engine->engine, pattern, reserved, keydata, use_armor); @@ -345,10 +348,10 @@ _gpgme_engine_op_export_ext (engine_t engine, const char *pattern[], int use_armor) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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, keydata, use_armor); @@ -361,10 +364,10 @@ _gpgme_engine_op_genkey (engine_t engine, gpgme_data_t help_data, gpgme_data_t seckey) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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, pubkey, seckey); @@ -375,10 +378,10 @@ gpgme_error_t _gpgme_engine_op_import (engine_t engine, gpgme_data_t keydata) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!engine->ops->import) - return GPGME_Not_Implemented; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); 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) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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); } @@ -404,10 +407,10 @@ _gpgme_engine_op_keylist_ext (engine_t engine, const char *pattern[], gpgme_keylist_mode_t mode) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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, 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 */) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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, use_textmode, include_certs, ctx); @@ -435,10 +438,10 @@ gpgme_error_t _gpgme_engine_op_trustlist (engine_t engine, const char *pattern) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!engine->ops->trustlist) - return GPGME_Not_Implemented; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); 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) { if (!engine) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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); } diff --git a/gpgme/error.c b/gpgme/error.c new file mode 100644 index 00000000..f3c38b1f --- /dev/null +++ b/gpgme/error.c @@ -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 +#endif + +#include + +/* 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)); +} diff --git a/gpgme/export.c b/gpgme/export.c index a5e8e501..59c68964 100644 --- a/gpgme/export.c +++ b/gpgme/export.c @@ -41,7 +41,7 @@ export_start (gpgme_ctx_t ctx, int synchronous, const char *pattern, gpgme_error_t err; if (!keydata) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = _gpgme_op_reset (ctx, synchronous); if (err) @@ -82,7 +82,7 @@ export_ext_start (gpgme_ctx_t ctx, int synchronous, const char *pattern[], gpgme_error_t err; if (!keydata) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = _gpgme_op_reset (ctx, synchronous); if (err) diff --git a/gpgme/genkey.c b/gpgme/genkey.c index 0d5c52f9..9353213a 100644 --- a/gpgme/genkey.c +++ b/gpgme/genkey.c @@ -23,6 +23,7 @@ #endif #include #include +#include #include "gpgme.h" #include "context.h" @@ -99,7 +100,7 @@ genkey_status_handler (void *priv, gpgme_status_code_t code, char *args) free (opd->result.fpr); opd->result.fpr = strdup (&args[2]); if (!opd->result.fpr) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); } } break; @@ -107,7 +108,7 @@ genkey_status_handler (void *priv, gpgme_status_code_t code, char *args) case GPGME_STATUS_EOF: /* FIXME: Should return some more useful error value. */ if (!opd->result.primary && !opd->result.sub) - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); break; default: @@ -127,16 +128,16 @@ get_key_parameter (const char *parms, gpgme_data_t *key_parameter) /* Extract the key parameter from the XML structure. */ parms = strstr (parms, "'); if (!content) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); content++; attrib = strstr (parms, "format=\"internal\""); if (!attrib || attrib >= content) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); endtag = strstr (content, ""); /* FIXME: Check that there are no control statements inside. */ diff --git a/gpgme/gpgme.c b/gpgme/gpgme.c index d5b2f139..3143d938 100644 --- a/gpgme/gpgme.c +++ b/gpgme/gpgme.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "util.h" #include "context.h" @@ -40,7 +41,7 @@ gpgme_new (gpgme_ctx_t *r_ctx) ctx = calloc (1, sizeof *ctx); if (!ctx) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); ctx->keylist_mode = GPGME_KEYLIST_MODE_LOCAL; ctx->include_certs = 1; ctx->protocol = GPGME_PROTOCOL_OpenPGP; @@ -85,7 +86,7 @@ gpgme_error_t gpgme_set_protocol (gpgme_ctx_t ctx, gpgme_protocol_t protocol) { if (protocol != GPGME_PROTOCOL_OpenPGP && protocol != GPGME_PROTOCOL_CMS) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); ctx->protocol = protocol; 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) || (mode & GPGME_KEYLIST_MODE_EXTERN) || (mode & GPGME_KEYLIST_MODE_SIGS))) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); ctx->keylist_mode = mode; return 0; diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index 0ef83ea6..c4612b87 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -38,6 +38,8 @@ extern "C" { #endif #endif +#include + /* Check for compiler features. */ #if __GNUC__ @@ -76,74 +78,75 @@ struct gpgme_data; 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 enum - { - GPGME_EOF = -1, - 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, +typedef gpg_error_t gpgme_error_t; +typedef gpg_err_code_t gpgme_err_code_t; +typedef gpg_err_source_t gpgme_err_source_t; - /* 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, +static __inline__ gpgme_error_t +gpgme_err_make (gpgme_err_source_t source, gpgme_err_code_t code) +{ + return gpg_err_make (source, code); +} - /* 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; +/* The user can define GPG_ERR_SOURCE_DEFAULT before including this + file to specify a default source for gpg_error. */ +#ifndef GPGME_ERR_SOURCE_DEFAULT +#define GPGME_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_USER_1 +#endif -#define GPGME_Busy ((_gpgme_deprecated_error_t) GPGME_x_Busy) -#define GPGME_No_Request ((_gpgme_deprecated_error_t) GPGME_x_No_Request) -#define GPGME_Invalid_Type ((_gpgme_deprecated_error_t) GPGME_x_Invalid_Type) -#define GPGME_Invalid_Mode ((_gpgme_deprecated_error_t) GPGME_x_Invalid_Mode) -#define GPGME_No_Recipients ((_gpgme_deprecated_error_t) GPGME_No_UserID) -#define GPGME_Invalid_Recipients \ - ((_gpgme_deprecated_error_t) GPGME_Invalid_UserID) -#define GPGME_No_Passphrase ((_gpgme_deprecated_error_t) GPGME_Bad_Passphrase) +static __inline__ gpgme_error_t +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. */ @@ -1425,9 +1428,6 @@ const char *gpgme_check_version (const char *req_version); /* Retrieve information about the backend engines. */ 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. */ diff --git a/gpgme/import.c b/gpgme/import.c index ba5a65de..46ae72e5 100644 --- a/gpgme/import.c +++ b/gpgme/import.c @@ -82,7 +82,7 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem) import = malloc (sizeof (*import)); if (!import) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); import->next = NULL; errno = 0; @@ -91,7 +91,7 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem) { /* The crypto backend does not behave. */ free (import); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } args = tail; @@ -102,26 +102,26 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem) case 0: case 4: default: - import->result = GPGME_Unknown_Reason; + import->result = gpg_error (GPG_ERR_GENERAL); break; case 1: - import->result = GPGME_Invalid_Key; + import->result = gpg_error (GPG_ERR_BAD_CERT); break; case 2: - import->result = GPGME_Issuer_Missing; + import->result = gpg_error (GPG_ERR_MISSING_CERT); break; case 3: - import->result = GPGME_Chain_Too_Long; + import->result = gpg_error (GPG_ERR_BAD_CERT_CHAIN); break; } import->status = 0; } else { - import->result = GPGME_No_Error; + import->result = gpg_error (GPG_ERR_NO_ERROR); import->status = nr; } @@ -134,8 +134,9 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem) import->fpr = strdup (args); if (!import->fpr) { + int saved_errno = errno; free (import); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } *import_status = import; @@ -155,7 +156,7 @@ parse_import_res (char *args, gpgme_import_result_t result) (x) = strtol (args, &tail, 0); \ if (errno || args == tail || *tail != ' ') \ /* The crypto backend does not behave. */ \ - return GPGME_General_Error; \ + return gpg_error (GPG_ERR_INV_ENGINE); \ args = tail; 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; if (!keydata) - return GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); _gpgme_engine_set_status_handler (ctx->engine, import_status_handler, ctx); diff --git a/gpgme/key.c b/gpgme/key.c index c5157f83..3c0d7360 100644 --- a/gpgme/key.c +++ b/gpgme/key.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "util.h" #include "ops.h" @@ -43,7 +44,7 @@ _gpgme_key_new (gpgme_key_t *r_key) key = calloc (1, sizeof *key); if (!key) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); key->_refs = 1; *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); if (!subkey) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); subkey->keyid = subkey->_keyid; 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. */ uid = malloc (sizeof (*uid) + 2 * src_len + 3); if (!uid) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); memset (uid, 0, sizeof *uid); uid->uid = ((char *) uid) + sizeof (*uid); diff --git a/gpgme/keylist.c b/gpgme/keylist.c index 0d2c6017..6bd6833f 100644 --- a/gpgme/keylist.c +++ b/gpgme/keylist.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "gpgme.h" #include "util.h" @@ -479,7 +480,7 @@ keylist_colon_handler (void *priv, char *line) { key->issuer_serial = strdup (field[7]); if (!key->issuer_serial) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); } /* Field 9 has the ownertrust. */ @@ -490,7 +491,7 @@ keylist_colon_handler (void *priv, char *line) but GPGSM stores the issuer name. */ if (fields >= 10 && (rectype == RT_CRT || rectype == RT_CRS)) 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. */ @@ -558,7 +559,7 @@ keylist_colon_handler (void *priv, char *line) if (fields >= 10) { if (_gpgme_key_append_name (key, field[9])) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (GPG_ERR_ENOMEM); /* FIXME */ else { if (field[1]) @@ -574,7 +575,7 @@ keylist_colon_handler (void *priv, char *line) { key->subkeys->fpr = strdup (field[9]); 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). */ @@ -582,7 +583,7 @@ keylist_colon_handler (void *priv, char *line) { key->chain_id = strdup (field[12]); if (!key->chain_id) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); } break; @@ -595,30 +596,30 @@ keylist_colon_handler (void *priv, char *line) assert (opd->tmp_uid == key->_last_uid); keysig = _gpgme_key_add_sig (key, (fields >= 10) ? field[9] : NULL); if (!keysig) - return GPGME_Out_Of_Core; + return gpg_error (GPG_ERR_ENOMEM); /* FIXME */ /* Field 2 has the calculated trust ('!', '-', '?', '%'). */ if (fields >= 2) switch (field[1][0]) { case '!': - keysig->status = GPGME_No_Error; + keysig->status = gpg_error (GPG_ERR_NO_ERROR); break; case '-': - keysig->status = GPGME_Bad_Signature; + keysig->status = gpg_error (GPG_ERR_BAD_SIGNATURE); break; case '?': - keysig->status = GPGME_No_Public_Key; + keysig->status = gpg_error (GPG_ERR_NO_PUBKEY); break; case '%': - keysig->status = GPGME_General_Error; + keysig->status = gpg_error (GPG_ERR_GENERAL); break; default: - keysig->status = GPGME_No_Error; + keysig->status = gpg_error (GPG_ERR_NO_ERROR); break; } @@ -779,10 +780,10 @@ gpgme_op_keylist_next (gpgme_ctx_t ctx, gpgme_key_t *r_key) op_data_t opd; if (!ctx || !r_key) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); *r_key = NULL; if (!ctx) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = _gpgme_op_data_lookup (ctx, OPDATA_KEYLIST, &hook, -1, NULL); opd = hook; @@ -796,7 +797,7 @@ gpgme_op_keylist_next (gpgme_ctx_t ctx, gpgme_key_t *r_key) return err; if (!opd->key_cond) - return GPGME_EOF; + return gpg_error (GPG_ERR_EOF); opd->key_cond = 0; assert (opd->key_queue); @@ -817,7 +818,7 @@ gpgme_error_t gpgme_op_keylist_end (gpgme_ctx_t ctx) { if (!ctx) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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; 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. */ - 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 I/O callback handlers. */ diff --git a/gpgme/mkerrors b/gpgme/mkerrors deleted file mode 100755 index 4cccfbe0..00000000 --- a/gpgme/mkerrors +++ /dev/null @@ -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 < -#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 <next = ctx->op_data; data->type = type; data->cleanup = cleanup; @@ -71,8 +71,11 @@ _gpgme_op_reset (gpgme_ctx_t ctx, int type) _gpgme_release_result (ctx); /* Create an engine object. */ - _gpgme_engine_release (ctx->engine); - ctx->engine = NULL; + if (ctx->engine) + { + _gpgme_engine_release (ctx->engine); + ctx->engine = NULL; + } err = _gpgme_engine_new (ctx->protocol, &ctx->engine); if (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)); if (!inv_userid) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); inv_userid->next = NULL; errno = 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. */ free (inv_userid); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } switch (reason) { default: case 0: - inv_userid->reason = GPGME_Unknown_Reason; + inv_userid->reason = gpg_error (GPG_ERR_GENERAL); break; case 1: - inv_userid->reason = GPGME_Not_Found; + inv_userid->reason = gpg_error (GPG_ERR_NO_PUBKEY); break; case 2: - inv_userid->reason = GPGME_Ambiguous_Specification; + /* FIXME: Ambiguous specification. */ + inv_userid->reason = gpg_error (GPG_ERR_AMBIGUOUS_NAME); break; case 3: - inv_userid->reason = GPGME_Wrong_Key_Usage; + inv_userid->reason = gpg_error (GPG_ERR_WRONG_KEY_USAGE); break; case 4: - inv_userid->reason = GPGME_Key_Revoked; + inv_userid->reason = gpg_error (GPG_ERR_CERT_REVOKED); break; case 5: - inv_userid->reason = GPGME_Key_Expired; + inv_userid->reason = gpg_error (GPG_ERR_CERT_EXPIRED); break; case 6: - inv_userid->reason = GPGME_No_CRL_Known; + inv_userid->reason = gpg_error (GPG_ERR_NO_CRL_KNOWN); break; case 7: - inv_userid->reason = GPGME_CRL_Too_Old; + inv_userid->reason = gpg_error (GPG_ERR_CRL_TOO_OLD); break; case 8: - inv_userid->reason = GPGME_Policy_Mismatch; + inv_userid->reason = gpg_error (GPG_ERR_NO_POLICY_MATCH); break; case 9: - inv_userid->reason = GPGME_No_Secret_Key; + inv_userid->reason = gpg_error (GPG_ERR_NO_SECKEY); break; case 10: - inv_userid->reason = GPGME_Key_Not_Trusted; + inv_userid->reason = gpg_error (GPG_ERR_PUBKEY_NOT_TRUSTED); break; } @@ -184,8 +188,9 @@ _gpgme_parse_inv_userid (char *args, gpgme_invalid_user_id_t *userid) inv_userid->id = strdup (tail); if (!inv_userid->id) { + int saved_errno = errno; free (inv_userid); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } } else diff --git a/gpgme/passphrase.c b/gpgme/passphrase.c index e852e5cb..9fa6a130 100644 --- a/gpgme/passphrase.c +++ b/gpgme/passphrase.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "gpgme.h" #include "context.h" @@ -76,7 +77,7 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code, if (opd->uid_hint) free (opd->uid_hint); if (!(opd->uid_hint = strdup (args))) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); break; case GPGME_STATUS_BAD_PASSPHRASE: @@ -95,7 +96,7 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code, free (opd->passphrase_info); opd->passphrase_info = strdup (args); if (!opd->passphrase_info) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); break; case GPGME_STATUS_MISSING_PASSPHRASE: @@ -104,7 +105,7 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code, case GPGME_STATUS_EOF: if (opd->no_passphrase || opd->bad_passphrase) - return GPGME_Bad_Passphrase; + return gpg_error (GPG_ERR_BAD_PASSPHRASE); break; default: diff --git a/gpgme/progress.c b/gpgme/progress.c index f18fc6e1..eb40421e 100644 --- a/gpgme/progress.c +++ b/gpgme/progress.c @@ -23,6 +23,7 @@ #endif #include #include +#include #include "util.h" #include "context.h" @@ -44,7 +45,7 @@ _gpgme_progress_status_handler (void *priv, gpgme_status_code_t code, args_cpy = strdup (args); if (!args_cpy) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); p = strchr (args_cpy, ' '); if (p) diff --git a/gpgme/rungpg.c b/gpgme/rungpg.c index 62a03f42..9f992b77 100644 --- a/gpgme/rungpg.c +++ b/gpgme/rungpg.c @@ -193,7 +193,7 @@ add_arg (engine_gpg_t gpg, const char *arg) if (!a) { gpg->arg_error = 1; - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); } a->next = 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) { gpg->arg_error = 1; - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); } a->next = NULL; a->data = data; @@ -335,16 +335,13 @@ static gpgme_error_t gpg_new (void **engine) { engine_gpg_t gpg; - int rc = 0; + gpgme_error_t rc = 0; gpg = calloc (1, sizeof *gpg); if (!gpg) - { - rc = GPGME_Out_Of_Core; - goto leave; - } - gpg->argtail = &gpg->arglist; + return gpg_error_from_errno (errno); + gpg->argtail = &gpg->arglist; gpg->status.fd[0] = -1; gpg->status.fd[1] = -1; gpg->colon.fd[0] = -1; @@ -360,14 +357,14 @@ gpg_new (void **engine) gpg->status.buffer = malloc (gpg->status.bufsize); if (!gpg->status.buffer) { - rc = GPGME_Out_Of_Core; + rc = gpg_error_from_errno (errno); goto leave; } /* In any case we need a status pipe - create it right here and don't handle it with our generic gpgme_data_t mechanism. */ if (_gpgme_io_pipe (gpg->status.fd, 1) == -1) { - rc = GPGME_Pipe_Error; + rc = gpg_error_from_errno (errno); goto leave; } 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], close_notify_handler, gpg)) { - rc = GPGME_General_Error; + rc = gpg_error (GPG_ERR_GENERAL); goto leave; } 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.buffer = malloc (gpg->colon.bufsize); if (!gpg->colon.buffer) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1) { + int saved_errno = errno; free (gpg->colon.buffer); 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) || _gpgme_io_set_close_notify (gpg->colon.fd[1], close_notify_handler, gpg)) - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); gpg->colon.eof = 0; gpg->colon.fnc = fnc; gpg->colon.fnc_value = fnc_value; @@ -547,21 +545,23 @@ build_argv (engine_gpg_t gpg) argv = calloc (argc + 1, sizeof *argv); if (!argv) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); fd_data_map = calloc (datac + 1, sizeof *fd_data_map); if (!fd_data_map) { + int saved_errno = errno; free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } argc = datac = 0; argv[argc] = strdup ("gpg"); /* argv[0] */ if (!argv[argc]) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } argc++; if (need_special) @@ -569,9 +569,10 @@ build_argv (engine_gpg_t gpg) argv[argc] = strdup ("--enable-special-filenames"); if (!argv[argc]) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } argc++; } @@ -580,9 +581,10 @@ build_argv (engine_gpg_t gpg) argv[argc] = strdup ("--use-agent"); if (!argv[argc]) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } argc++; } @@ -591,26 +593,29 @@ build_argv (engine_gpg_t gpg) argv[argc] = strdup ("--batch"); if (!argv[argc]) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } argc++; } argv[argc] = strdup ("--comment"); if (!argv[argc]) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } argc++; argv[argc] = strdup (""); if (!argv[argc]) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } argc++; 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) == -1) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Pipe_Error; + return gpg_error (saved_errno); } if (_gpgme_io_set_close_notify (fds[0], close_notify_handler, gpg) @@ -637,7 +643,7 @@ build_argv (engine_gpg_t gpg) close_notify_handler, 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 (fd_data_map[datac].inbound) @@ -674,9 +680,10 @@ build_argv (engine_gpg_t gpg) argv[argc] = malloc (25); if (!argv[argc]) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } sprintf (argv[argc], a->print_fd ? "%d" : "-&%d", @@ -690,9 +697,10 @@ build_argv (engine_gpg_t gpg) argv[argc] = strdup (a->arg); if (!argv[argc]) { + int saved_errno = errno; free (fd_data_map); free_argv (argv); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } argc++; } @@ -753,13 +761,13 @@ read_status (engine_gpg_t gpg) bufsize += 1024; buffer = realloc (buffer, bufsize); if (!buffer) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); } nread = _gpgme_io_read (gpg->status.fd[0], buffer + readpos, bufsize-readpos); if (nread == -1) - return GPGME_Read_Error; + return gpg_error_from_errno (errno); if (!nread) { @@ -810,7 +818,7 @@ read_status (engine_gpg_t gpg) free (gpg->cmd.keyword); gpg->cmd.keyword = strdup (rest); if (!gpg->cmd.keyword) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); /* This should be the last thing we have received and the next thing will be that the command handler does its action. */ @@ -927,12 +935,12 @@ read_colon_line (engine_gpg_t gpg) bufsize += 1024; buffer = realloc (buffer, bufsize); 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); if (nread == -1) - return GPGME_Read_Error; + return gpg_error_from_errno (errno); if (!nread) { @@ -1009,20 +1017,21 @@ static gpgme_error_t start (engine_gpg_t gpg) { gpgme_error_t rc; + int saved_errno; int i, n; int status; struct spawn_fd_item_s *fd_child_list, *fd_parent_list; if (!gpg) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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 add_arg (). We bail out here instead. */ if (gpg->arg_error) - return GPGME_Out_Of_Core; + return gpg_error (GPG_ERR_ENOMEM); rc = build_argv (gpg); if (rc) @@ -1033,7 +1042,7 @@ start (engine_gpg_t gpg) n++; fd_child_list = calloc (n + n, sizeof *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; /* build the fd list for the child */ @@ -1081,9 +1090,10 @@ start (engine_gpg_t gpg) status = _gpgme_io_spawn (_gpgme_get_gpg_path (), gpg->argv, fd_child_list, fd_parent_list); + saved_errno = errno; free (fd_child_list); if (status == -1) - return GPGME_Exec_Error; + return gpg_error_from_errno (errno); /*_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 (!key->subkeys || !key->subkeys->fpr) - err = GPGME_Invalid_Key; + return gpg_error (GPG_ERR_INV_VALUE); else 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; if (!s) - err = GPGME_Invalid_Key; + err = gpg_error (GPG_ERR_INV_VALUE); else err = add_arg (gpg, s); } @@ -1244,7 +1254,7 @@ append_args_from_recipients (engine_gpg_t gpg, gpgme_key_t recp[]) while (recp[i]) { if (!recp[i]->subkeys || !recp[i]->subkeys->fpr) - err = GPGME_Invalid_Key; + err = gpg_error (GPG_ERR_INV_VALUE); if (!err) err = add_arg (gpg, "-r"); if (!err) @@ -1353,7 +1363,7 @@ gpg_export (void *engine, const char *pattern, unsigned int reserved, gpgme_error_t err; if (reserved) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = add_arg (gpg, "--export"); if (!err && use_armor) @@ -1381,7 +1391,7 @@ gpg_export_ext (void *engine, const char *pattern[], unsigned int reserved, gpgme_error_t err; if (reserved) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = add_arg (gpg, "--export"); if (!err && use_armor) @@ -1412,14 +1422,14 @@ gpg_genkey (void *engine, gpgme_data_t help_data, int use_armor, gpgme_error_t err; 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 can use this for the %pubring and %secring parameters. We don't have this yet, so we implement only the adding to the standard keyrings. */ if (pubkey || seckey) - return err = GPGME_Not_Implemented; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); err = add_arg (gpg, "--gen-key"); if (!err && use_armor) @@ -1491,7 +1501,7 @@ gpg_keylist_ext (void *engine, const char *pattern[], int secret_only, gpgme_error_t err; if (reserved) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = add_arg (gpg, "--with-colons"); if (!err) diff --git a/gpgme/sign.c b/gpgme/sign.c index ce02c031..1dc24bcc 100644 --- a/gpgme/sign.c +++ b/gpgme/sign.c @@ -93,7 +93,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp) sig = malloc (sizeof (*sig)); if (!sig) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); sig->next = NULL; switch (*args) @@ -113,14 +113,14 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp) default: /* The backend engine is not behaving. */ free (sig); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } args++; if (*args != ' ') { free (sig); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } errno = 0; @@ -129,7 +129,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp) { /* The crypto backend does not behave. */ free (sig); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } args = tail; @@ -138,7 +138,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp) { /* The crypto backend does not behave. */ free (sig); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } args = tail; @@ -147,7 +147,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp) { /* The crypto backend does not behave. */ free (sig); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } args = tail; @@ -156,7 +156,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp) { /* The crypto backend does not behave. */ free (sig); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } args = tail; while (*args == ' ') @@ -166,7 +166,7 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp) { /* The crypto backend does not behave. */ free (sig); - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } tail = strchr (args, ' '); @@ -176,8 +176,9 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp) sig->fpr = strdup (args); if (!sig->fpr) { + int saved_errno = errno; free (sig); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } *sigp = sig; return 0; @@ -221,7 +222,7 @@ _gpgme_sign_status_handler (void *priv, gpgme_status_code_t code, char *args) case GPGME_STATUS_EOF: if (opd->result.invalid_signers) - return GPGME_Invalid_UserID; + return gpg_error (GPG_ERR_INV_USER_ID); break; 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 && mode != GPGME_SIG_MODE_CLEAR) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (!plain) - return GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); if (!sig) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); if (ctx->passphrase_cb) { diff --git a/gpgme/signers.c b/gpgme/signers.c index 5dcfc481..203c6727 100644 --- a/gpgme/signers.c +++ b/gpgme/signers.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "util.h" #include "context.h" @@ -53,7 +54,7 @@ gpgme_error_t gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key) { if (!ctx || !key) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); 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)); if (!newarr) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); for (j = ctx->signers_size; j < n; j++) newarr[j] = NULL; ctx->signers = newarr; diff --git a/gpgme/trust-item.c b/gpgme/trust-item.c index 49cc0105..bc60df42 100644 --- a/gpgme/trust-item.c +++ b/gpgme/trust-item.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "util.h" #include "ops.h" @@ -44,7 +45,7 @@ _gpgme_trust_item_new (gpgme_trust_item_t *r_item) item = calloc (1, sizeof *item); if (!item) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); item->_refs = 1; item->keyid = item->_keyid; item->_keyid[16] = '\0'; diff --git a/gpgme/trustlist.c b/gpgme/trustlist.c index a5a29158..942cc53b 100644 --- a/gpgme/trustlist.c +++ b/gpgme/trustlist.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "gpgme.h" #include "util.h" @@ -106,10 +107,12 @@ trustlist_colon_handler (void *priv, char *line) break; case 9: /* user ID */ item->name = strdup (p); - if (!item->name) { - gpgme_trust_item_unref (item); - return GPGME_Out_Of_Core; - } + if (!item->name) + { + int saved_errno = errno; + gpgme_trust_item_unref (item); + return gpg_error_from_errno (saved_errno); + } break; } } @@ -170,7 +173,7 @@ gpgme_op_trustlist_start (gpgme_ctx_t ctx, const char *pattern, int max_level) op_data_t opd; if (!pattern || !*pattern) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = _gpgme_op_reset (ctx, 2); 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; if (!r_item) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); *r_item = NULL; if (!ctx) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); err = _gpgme_op_data_lookup (ctx, OPDATA_TRUSTLIST, &hook, -1, NULL); opd = hook; @@ -218,7 +221,7 @@ gpgme_op_trustlist_next (gpgme_ctx_t ctx, gpgme_trust_item_t *r_item) if (err) return err; if (!opd->trust_cond) - return GPGME_EOF; + return gpg_error (GPG_ERR_EOF); opd->trust_cond = 0; assert (opd->trust_queue); } @@ -236,7 +239,7 @@ gpgme_error_t gpgme_op_trustlist_end (gpgme_ctx_t ctx) { if (!ctx) - return GPGME_Invalid_Value; + return gpg_error (GPG_ERR_INV_VALUE); return 0; } diff --git a/gpgme/verify.c b/gpgme/verify.c index b84e5b47..a358772d 100644 --- a/gpgme/verify.c +++ b/gpgme/verify.c @@ -94,38 +94,38 @@ calc_sig_summary (gpgme_signature_t sig) if (sig->validity == GPGME_VALIDITY_FULL || sig->validity == GPGME_VALIDITY_ULTIMATE) { - if (sig->status == GPGME_No_Error - || sig->status == GPGME_Sig_Expired - || sig->status == GPGME_Key_Expired) + if (gpg_err_code (sig->status) == GPG_ERR_NO_ERROR + || gpg_err_code (sig->status) == GPG_ERR_SIG_EXPIRED + || gpg_err_code (sig->status) == GPG_ERR_KEY_EXPIRED) sum |= GPGME_SIGSUM_GREEN; } else if (sig->validity == GPGME_VALIDITY_NEVER) { - if (sig->status == GPGME_No_Error - || sig->status == GPGME_Sig_Expired - || sig->status == GPGME_Key_Expired) + if (gpg_err_code (sig->status) == GPG_ERR_NO_ERROR + || gpg_err_code (sig->status) == GPG_ERR_SIG_EXPIRED + || gpg_err_code (sig->status) == GPG_ERR_KEY_EXPIRED) 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; /* 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; break; - case GPGME_Key_Expired: + case GPG_ERR_KEY_EXPIRED: sum |= GPGME_SIGSUM_KEY_EXPIRED; break; - case GPGME_No_Public_Key: + case GPG_ERR_NO_PUBKEY: sum |= GPGME_SIGSUM_KEY_MISSING; break; - case GPGME_Bad_Signature: - case GPGME_No_Error: + case GPG_ERR_BAD_SIGNATURE: + case GPG_ERR_NO_ERROR: break; default: @@ -159,29 +159,30 @@ parse_new_sig (op_data_t opd, gpgme_status_code_t code, char *args) sig = calloc (1, sizeof (*sig)); if (!sig) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); if (!opd->result.signatures) opd->result.signatures = sig; if (opd->current_sig) opd->current_sig->next = sig; opd->current_sig = sig; + /* FIXME: We should set the source of the state. */ switch (code) { case GPGME_STATUS_GOODSIG: - sig->status = GPGME_No_Error; + sig->status = gpg_error (GPG_ERR_NO_ERROR); break; case GPGME_STATUS_EXPSIG: - sig->status = GPGME_Sig_Expired; + sig->status = gpg_error (GPG_ERR_SIG_EXPIRED); break; case GPGME_STATUS_EXPKEYSIG: - sig->status = GPGME_Key_Expired; + sig->status = gpg_error (GPG_ERR_KEY_EXPIRED); break; case GPGME_STATUS_BADSIG: - sig->status = GPGME_Bad_Signature; + sig->status = gpg_error (GPG_ERR_BAD_SIGNATURE); break; 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]) { case '4': - sig->status = GPGME_Unsupported_Algorithm; + sig->status = gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); break; - + case 9: - sig->status = GPGME_No_Public_Key; + sig->status = gpg_error (GPG_ERR_NO_PUBKEY); break; - + default: - sig->status = GPGME_General_Error; + sig->status = gpg_error (GPG_ERR_GENERAL); } } } else - sig->status = GPGME_General_Error; + sig->status = gpg_error (GPG_ERR_GENERAL); break; default: - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); } if (*args) { sig->fpr = strdup (args); if (!sig->fpr) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); } return 0; } @@ -245,13 +246,13 @@ parse_valid_sig (gpgme_signature_t sig, char *args) if (!*args) /* We require at least the fingerprint. */ - return GPGME_General_Error; + return gpg_error (GPG_ERR_GENERAL); if (sig->fpr) free (sig->fpr); sig->fpr = strdup (args); if (!sig->fpr) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); end = strchr (end, ' '); if (end) @@ -260,12 +261,12 @@ parse_valid_sig (gpgme_signature_t sig, char *args) errno = 0; sig->timestamp = strtol (end, &tail, 0); if (errno || end == tail || (*tail && *tail != ' ')) - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); end = tail; sig->exp_timestamp = strtol (end, &tail, 0); if (errno || end == tail || (*tail && *tail != ' ')) - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); } return 0; } @@ -294,11 +295,11 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args) if (notation) /* There is another notation name without data for the previous one. The crypto backend misbehaves. */ - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); notation = malloc (sizeof (*sig)); if (!notation) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); notation->next = NULL; 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); if (!notation->name) { + int saved_errno = errno; free (notation); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } err = _gpgme_decode_percent_string (args, ¬ation->name, len); if (err) @@ -325,8 +327,9 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args) notation->value = malloc (len); if (!notation->value) { + int saved_errno = errno; free (notation); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } err = _gpgme_decode_percent_string (args, ¬ation->value, len); if (err) @@ -349,20 +352,20 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args) if (!notation || !notation->name) /* There is notation data without a previous notation name. The crypto backend misbehaves. */ - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); if (!notation->value) { dest = notation->value = malloc (len); if (!dest) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); } else { int cur_len = strlen (notation->value); dest = realloc (notation->value, len + strlen (notation->value)); if (!dest) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); notation->value = dest; dest += cur_len; } @@ -372,7 +375,7 @@ parse_notation (gpgme_signature_t sig, gpgme_status_code_t code, char *args) return err; } else - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); return 0; } @@ -432,13 +435,14 @@ parse_error (gpgme_signature_t sig, char *args) where = args; } else - return GPGME_General_Error; + return gpg_error (GPG_ERR_INV_ENGINE); err = _gpgme_map_gnupg_error (which); if (!strcmp (where, "verify.findkey")) 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; 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); 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: if (!sig) - return GPGME_No_Data; - sig->status = GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); + sig->status = gpg_error (GPG_ERR_NO_DATA); break; case GPGME_STATUS_UNEXPECTED: if (!sig) - return GPGME_General_Error; - sig->status = GPGME_No_Data; + return gpg_error (GPG_ERR_GENERAL); + sig->status = gpg_error (GPG_ERR_NO_DATA); break; case GPGME_STATUS_NOTATION_NAME: case GPGME_STATUS_NOTATION_DATA: 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_NEVER: case GPGME_STATUS_TRUST_MARGINAL: case GPGME_STATUS_TRUST_FULLY: 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: - 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: 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); if (!sig) - return GPGME_No_Data; + return gpg_error (GPG_ERR_NO_DATA); 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); } @@ -602,7 +609,7 @@ gpgme_get_sig_key (gpgme_ctx_t ctx, int idx, gpgme_key_t *r_key) idx--; } if (!sig || idx) - return GPGME_EOF; + return gpg_error (GPG_ERR_EOF); 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) { - switch (sig->status) + switch (gpg_err_code (sig->status)) { - case GPGME_No_Error: + case GPG_ERR_NO_ERROR: *r_stat = GPGME_SIG_STAT_GOOD; break; - case GPGME_Bad_Signature: + case GPG_ERR_BAD_SIGNATURE: *r_stat = GPGME_SIG_STAT_BAD; break; - case GPGME_No_Public_Key: + case GPG_ERR_NO_PUBKEY: *r_stat = GPGME_SIG_STAT_NOKEY; break; - case GPGME_No_Data: + case GPG_ERR_NO_DATA: *r_stat = GPGME_SIG_STAT_NOSIG; break; - case GPGME_Sig_Expired: + case GPG_ERR_SIG_EXPIRED: *r_stat = GPGME_SIG_STAT_GOOD_EXP; break; - case GPGME_Key_Expired: + case GPG_ERR_KEY_EXPIRED: *r_stat = GPGME_SIG_STAT_GOOD_EXPKEY; break; @@ -701,24 +708,24 @@ unsigned long gpgme_get_sig_ulong_attr (gpgme_ctx_t ctx, int idx, return (unsigned long) sig->validity; 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; - case GPGME_Bad_Signature: + case GPG_ERR_BAD_SIGNATURE: return GPGME_SIG_STAT_BAD; - case GPGME_No_Public_Key: + case GPG_ERR_NO_PUBKEY: return GPGME_SIG_STAT_NOKEY; - case GPGME_No_Data: + case GPG_ERR_NO_DATA: return GPGME_SIG_STAT_NOSIG; - case GPGME_Sig_Expired: + case GPG_ERR_SIG_EXPIRED: return GPGME_SIG_STAT_GOOD_EXP; - case GPGME_Key_Expired: + case GPG_ERR_KEY_EXPIRED: return GPGME_SIG_STAT_GOOD_EXPKEY; default: diff --git a/gpgme/wait-global.c b/gpgme/wait-global.c index 76dbc2d7..992446e6 100644 --- a/gpgme/wait-global.c +++ b/gpgme/wait-global.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "gpgme.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)); if (!li) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); li->ctx = ctx; 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)); if (!fdt.fds) { + int saved_errno = errno; UNLOCK (ctx_list_lock); if (status) - *status = GPGME_Out_Of_Core; + *status = gpg_error_from_errno (saved_errno); return NULL; } 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); if (nr < 0) { + int saved_errno = errno; free (fdt.fds); if (status) - *status = GPGME_File_Error; + *status = gpg_error_from_errno (saved_errno); return NULL; } diff --git a/gpgme/wait-private.c b/gpgme/wait-private.c index 9d7681d0..b5a049bf 100644 --- a/gpgme/wait-private.c +++ b/gpgme/wait-private.c @@ -22,6 +22,7 @@ #include #endif #include +#include #include "gpgme.h" #include "context.h" @@ -86,7 +87,7 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond) signal it. */ int idx; - err = GPGME_File_Error; + err = gpg_error_from_errno (errno); for (idx = 0; idx < ctx->fdt.size; idx++) if (ctx->fdt.fds[idx].fd != -1) _gpgme_io_close (ctx->fdt.fds[idx].fd); diff --git a/gpgme/wait.c b/gpgme/wait.c index 28c60003..53d89901 100644 --- a/gpgme/wait.c +++ b/gpgme/wait.c @@ -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) * sizeof (*new_fds)); if (!new_fds) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); fdt->fds = new_fds; 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); if (!tag) - return GPGME_Out_Of_Core; + return gpg_error_from_errno (errno); tag->ctx = ctx; /* Allocate a structure to hold information about the handler. */ item = calloc (1, sizeof *item); if (!item) { + int saved_errno = errno; free (tag); - return GPGME_Out_Of_Core; + return gpg_error_from_errno (saved_errno); } item->ctx = ctx; item->dir = dir; diff --git a/tests/ChangeLog b/tests/ChangeLog index 0d45e9ff..335560ed 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2003-06-06 Marcus Brinkmann + + 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 * gpg/t-encrypt-sym.c (main): Adapt to new syntax. diff --git a/tests/gpg/Makefile.am b/tests/gpg/Makefile.am index 370778c3..319f0d1a 100644 --- a/tests/gpg/Makefile.am +++ b/tests/gpg/Makefile.am @@ -24,6 +24,7 @@ GPG = @GPG@ TESTS_ENVIRONMENT = GNUPGHOME=. GPG_AGENT_INFO= # 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 \ t-decrypt t-verify t-decrypt-verify \ t-export t-import t-trustlist t-eventloop t-edit \ diff --git a/tests/gpg/t-decrypt-verify.c b/tests/gpg/t-decrypt-verify.c index c89f7f47..9f45fffd 100644 --- a/tests/gpg/t-decrypt-verify.c +++ b/tests/gpg/t-decrypt-verify.c @@ -26,68 +26,9 @@ #include +#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 check_verify_result (gpgme_verify_result_t result, int summary, char *fpr, gpgme_error_t status) @@ -113,7 +54,7 @@ check_verify_result (gpgme_verify_result_t result, int summary, char *fpr, __FILE__, __LINE__, sig->fpr); exit (1); } - if (sig->status != status) + if (gpg_err_code (sig->status) != status) { fprintf (stderr, "%s:%i: Unexpected signature status: %s\n", __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); 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", __FILE__, __LINE__, gpgme_strerror (sig->validity_reason)); @@ -182,7 +123,7 @@ main (int argc, char *argv[]) verify_result = gpgme_op_verify_result (ctx); check_verify_result (verify_result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", - GPGME_No_Error); + GPG_ERR_NO_ERROR); gpgme_data_release (in); gpgme_data_release (out); diff --git a/tests/gpg/t-decrypt.c b/tests/gpg/t-decrypt.c index 7b406a76..8c18d783 100644 --- a/tests/gpg/t-decrypt.c +++ b/tests/gpg/t-decrypt.c @@ -1,4 +1,4 @@ -/* t-decrypt.c - regression test +/* t-decrypt.c - Regression test. Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2001, 2003 g10 Code GmbH @@ -26,67 +26,9 @@ #include -#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; -} - +#include "t-support.h" + int main (int argc, char *argv[]) { diff --git a/tests/gpg/t-edit.c b/tests/gpg/t-edit.c index 9238503e..d2d2e1b8 100644 --- a/tests/gpg/t-edit.c +++ b/tests/gpg/t-edit.c @@ -1,23 +1,22 @@ -/* t-edit.c - regression test - * 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ +/* t-edit.c - Regression test. + 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 #include @@ -25,23 +24,13 @@ #include #include #include +#include #include -struct passphrase_cb_info_s { - 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) +#include "t-support.h" + static void flush_data (gpgme_data_t dh) { @@ -50,20 +39,11 @@ flush_data (gpgme_data_t dh) ret = gpgme_data_seek (dh, 0, SEEK_SET); 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) 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; + fail_if_err (gpg_error_from_errno (errno)); } @@ -130,43 +110,34 @@ main (int argc, char **argv) gpgme_error_t err; gpgme_data_t out = NULL; gpgme_key_t key = NULL; - struct passphrase_cb_info_s info; const char *pattern = "Alpha"; - char *p; + char *agent_info; - do - { - err = gpgme_new (&ctx); - fail_if_err (err); - err = gpgme_data_new (&out); - fail_if_err (err); + err = gpgme_new (&ctx); + fail_if_err (err); + err = gpgme_data_new (&out); + fail_if_err (err); - p = getenv("GPG_AGENT_INFO"); - if (!(p && strchr (p, ':'))) - { - memset (&info, 0, sizeof info); - info.c = ctx; - gpgme_set_passphrase_cb (ctx, passphrase_cb, &info); - } + agent_info = getenv("GPG_AGENT_INFO"); + if (!(agent_info && strchr (agent_info, ':'))) + gpgme_set_passphrase_cb (ctx, passphrase_cb, 0); - err = gpgme_op_keylist_start (ctx, pattern, 0); - fail_if_err (err); - err = gpgme_op_keylist_next (ctx, &key); - fail_if_err (err); - err = gpgme_op_keylist_end (ctx); - fail_if_err (err); + err = gpgme_op_keylist_start (ctx, pattern, 0); + fail_if_err (err); + err = gpgme_op_keylist_next (ctx, &key); + fail_if_err (err); + err = gpgme_op_keylist_end (ctx); + fail_if_err (err); - err = gpgme_op_edit (ctx, key, edit_fnc, out, out); - fail_if_err (err); + err = gpgme_op_edit (ctx, key, edit_fnc, out, out); + fail_if_err (err); - fputs ("[-- Last response --]\n", stdout); - flush_data (out); + fputs ("[-- Last response --]\n", stdout); + flush_data (out); - gpgme_data_release (out); - gpgme_key_unref (key); - gpgme_release (ctx); - } - while (argc > 1 && !strcmp( argv[1], "--loop")); + gpgme_data_release (out); + gpgme_key_unref (key); + gpgme_release (ctx); return 0; } diff --git a/tests/gpg/t-encrypt-sign.c b/tests/gpg/t-encrypt-sign.c index 40a654be..fc99d56c 100644 --- a/tests/gpg/t-encrypt-sign.c +++ b/tests/gpg/t-encrypt-sign.c @@ -25,45 +25,9 @@ #include -#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; -} - +#include "t-support.h" + static void check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) { diff --git a/tests/gpg/t-encrypt-sym.c b/tests/gpg/t-encrypt-sym.c index 41fe3085..7c84f3dc 100644 --- a/tests/gpg/t-encrypt-sym.c +++ b/tests/gpg/t-encrypt-sym.c @@ -1,4 +1,4 @@ -/* t-encrypt-sym.c - regression test +/* t-encrypt-sym.c - Regression test. Copyright (C) 2000 Werner Koch (dd9jn) Copyright (C) 2001, 2003 g10 Code GmbH @@ -26,46 +26,11 @@ #include -#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); -} - - -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; -} - +#include "t-support.h" + int -main (int argc, char **argv) +main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; diff --git a/tests/gpg/t-encrypt.c b/tests/gpg/t-encrypt.c index 1373a397..bebd9938 100644 --- a/tests/gpg/t-encrypt.c +++ b/tests/gpg/t-encrypt.c @@ -24,38 +24,11 @@ #include -#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); -} - +#include "t-support.h" + int -main (int argc, char **argv) +main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; diff --git a/tests/gpg/t-eventloop.c b/tests/gpg/t-eventloop.c index 990876d7..43e2c09b 100644 --- a/tests/gpg/t-eventloop.c +++ b/tests/gpg/t-eventloop.c @@ -27,35 +27,9 @@ #include -#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); -} - +#include "t-support.h" + /* Stripped down version of gpgme/wait.c. */ 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) - return GPGME_General_Error; + return gpg_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_GENERAL); *r_tag = &fds[i]; return 0; } diff --git a/tests/gpg/t-export.c b/tests/gpg/t-export.c index 7ec69e6f..a5c24fc6 100644 --- a/tests/gpg/t-export.c +++ b/tests/gpg/t-export.c @@ -25,35 +25,9 @@ #include -#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); -} - +#include "t-support.h" + int main (int argc, char **argv) { diff --git a/tests/gpg/t-genkey.c b/tests/gpg/t-genkey.c index 40aa3036..b218122e 100644 --- a/tests/gpg/t-genkey.c +++ b/tests/gpg/t-genkey.c @@ -24,20 +24,11 @@ #include -#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) +#include "t-support.h" + /* True if progress function printed something on the screen. */ -int progress_called; +static int progress_called; static void progress (void *self, const char *what, int type, int current, int total) diff --git a/tests/gpg/t-import.c b/tests/gpg/t-import.c index fd275080..3733d5c6 100644 --- a/tests/gpg/t-import.c +++ b/tests/gpg/t-import.c @@ -25,38 +25,9 @@ #include +#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 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 -main (int argc, char **argv) +main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; gpgme_data_t in; gpgme_import_result_t result; - const char *pubkey_1_asc = mk_fname ("pubkey-1.asc"); - const char *seckey_1_asc = mk_fname ("seckey-1.asc"); + const char *pubkey_1_asc = make_filename ("pubkey-1.asc"); + const char *seckey_1_asc = make_filename ("seckey-1.asc"); err = gpgme_new (&ctx); fail_if_err (err); diff --git a/tests/gpg/t-keylist-sig.c b/tests/gpg/t-keylist-sig.c index 63251ad7..1a897686 100644 --- a/tests/gpg/t-keylist-sig.c +++ b/tests/gpg/t-keylist-sig.c @@ -24,20 +24,9 @@ #include +#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 { char *fpr; @@ -74,6 +63,7 @@ keys[] = { NULL } }; + int main (int argc, char **argv) { @@ -611,7 +601,7 @@ main (int argc, char **argv) gpgme_key_unref (key); i++; } - if (err != GPGME_EOF) + if (gpg_err_code (err) != GPG_ERR_EOF) fail_if_err (err); err = gpgme_op_keylist_end (ctx); fail_if_err (err); diff --git a/tests/gpg/t-keylist.c b/tests/gpg/t-keylist.c index a4c46ae8..9e68f0cc 100644 --- a/tests/gpg/t-keylist.c +++ b/tests/gpg/t-keylist.c @@ -24,20 +24,9 @@ #include +#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 { char *fpr; @@ -514,7 +503,7 @@ main (int argc, char **argv) gpgme_key_unref (key); i++; } - if (err != GPGME_EOF) + if (gpg_err_code (err) != GPG_ERR_EOF) fail_if_err (err); err = gpgme_op_keylist_end (ctx); fail_if_err (err); diff --git a/tests/gpg/t-sign.c b/tests/gpg/t-sign.c index cb32246d..ff40e7cd 100644 --- a/tests/gpg/t-sign.c +++ b/tests/gpg/t-sign.c @@ -25,45 +25,9 @@ #include -#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; -} - +#include "t-support.h" + static void check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) { diff --git a/tests/gpg/t-signers.c b/tests/gpg/t-signers.c index 3c97a735..12b0b083 100644 --- a/tests/gpg/t-signers.c +++ b/tests/gpg/t-signers.c @@ -25,45 +25,9 @@ #include -#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; -} - +#include "t-support.h" + static void check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) { diff --git a/tests/gpg/t-support.h b/tests/gpg/t-support.h new file mode 100644 index 00000000..8f91838d --- /dev/null +++ b/tests/gpg/t-support.h @@ -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 +#include + +#include + +#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; +} diff --git a/tests/gpg/t-trustlist.c b/tests/gpg/t-trustlist.c index d7c6bc8c..db10cf0c 100644 --- a/tests/gpg/t-trustlist.c +++ b/tests/gpg/t-trustlist.c @@ -24,20 +24,9 @@ #include +#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 main (int argc, char *argv[]) { @@ -50,7 +39,7 @@ main (int argc, char *argv[]) err = gpgme_op_trustlist_start (ctx, "alice", 0); fail_if_err (err); - + while (!(err = gpgme_op_trustlist_next (ctx, &item))) { printf ("l=%d k=%s t=%d o=%s v=%s u=%s\n", @@ -58,7 +47,7 @@ main (int argc, char *argv[]) item->validity, item->name); gpgme_trust_item_unref (item); } - if (err != GPGME_EOF) + if (gpg_err_code (err) != GPG_ERR_EOF) fail_if_err (err); gpgme_release (ctx); diff --git a/tests/gpg/t-verify.c b/tests/gpg/t-verify.c index df0c9dfd..74d333f4 100644 --- a/tests/gpg/t-verify.c +++ b/tests/gpg/t-verify.c @@ -24,18 +24,7 @@ #include - -#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) +#include "t-support.h" 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); exit (1); } - if (sig->status != status) + if (gpg_err_code (sig->status) != status) { fprintf (stderr, "%s:%i: Unexpected signature status: %s\n", - __FILE__, __LINE__, gpgme_strerror (sig->status)); + __FILE__, __LINE__, gpg_strerror (sig->status)); exit (1); } if (notation) @@ -145,7 +134,7 @@ check_result (gpgme_verify_result_t result, int summary, char *fpr, __FILE__, __LINE__, sig->validity); 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", __FILE__, __LINE__, gpgme_strerror (sig->validity_reason)); @@ -174,7 +163,7 @@ main (int argc, char *argv[]) fail_if_err (err); result = gpgme_op_verify_result (ctx); check_result (result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", - GPGME_No_Error, 1); + GPG_ERR_NO_ERROR, 1); /* Checking a manipulated message. */ gpgme_data_release (text); @@ -185,7 +174,7 @@ main (int argc, char *argv[]) fail_if_err (err); result = gpgme_op_verify_result (ctx); check_result (result, GPGME_SIGSUM_RED, "2D727CC768697734", - GPGME_Bad_Signature, 0); + GPG_ERR_BAD_SIGNATURE, 0); /* Checking a normal signature. */ gpgme_data_release (sig); @@ -198,7 +187,7 @@ main (int argc, char *argv[]) fail_if_err (err); result = gpgme_op_verify_result (ctx); check_result (result, 0, "A0FF4590BB6122EDEF6E3C542D727CC768697734", - GPGME_No_Error, 0); + GPG_ERR_NO_ERROR, 0); gpgme_data_release (sig); gpgme_data_release (text); diff --git a/tests/gpgsm/Makefile.am b/tests/gpgsm/Makefile.am index 85ea1c83..fa132346 100644 --- a/tests/gpgsm/Makefile.am +++ b/tests/gpgsm/Makefile.am @@ -23,9 +23,11 @@ GPGSM = @GPGSM@ TESTS_ENVIRONMENT = GNUPGHOME=. +noinst_HEADERS = t-support.h 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 diff --git a/tests/gpgsm/t-decrypt.c b/tests/gpgsm/t-decrypt.c index f3dc976d..21d6bd14 100644 --- a/tests/gpgsm/t-decrypt.c +++ b/tests/gpgsm/t-decrypt.c @@ -24,6 +24,7 @@ #include #include +#include "t-support.h" static const char test_text1[] = "Hallo Leute!\n"; @@ -39,30 +40,6 @@ static const char test_cip1[] = "BAiiytWtOSmqnwAA\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 main (int argc, char *argv[]) diff --git a/tests/gpgsm/t-encrypt.c b/tests/gpgsm/t-encrypt.c index 5f8916f7..247f1ca9 100644 --- a/tests/gpgsm/t-encrypt.c +++ b/tests/gpgsm/t-encrypt.c @@ -24,35 +24,7 @@ #include -#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); -} - +#include "t-support.h" int main (int argc, char **argv) diff --git a/tests/gpgsm/t-export.c b/tests/gpgsm/t-export.c index 3d536ad4..a2355e0c 100644 --- a/tests/gpgsm/t-export.c +++ b/tests/gpgsm/t-export.c @@ -24,34 +24,7 @@ #include #include - -#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); -} +#include "t-support.h" int diff --git a/tests/gpgsm/t-genkey.c b/tests/gpgsm/t-genkey.c index d5df2c61..8b08a65b 100644 --- a/tests/gpgsm/t-genkey.c +++ b/tests/gpgsm/t-genkey.c @@ -24,35 +24,7 @@ #include #include - -#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); -} +#include "t-support.h" /* 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 -main (int argc, char **argv) +main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; diff --git a/tests/gpgsm/t-keylist.c b/tests/gpgsm/t-keylist.c index 215f1e44..7e596283 100644 --- a/tests/gpgsm/t-keylist.c +++ b/tests/gpgsm/t-keylist.c @@ -335,7 +335,7 @@ main (int argc, char **argv) gpgme_key_unref (key); i++; } - if (err != GPGME_EOF) + if (gpg_err_code (err) != GPG_ERR_EOF) fail_if_err (err); err = gpgme_op_keylist_end (ctx); fail_if_err (err); diff --git a/tests/gpgsm/t-sign.c b/tests/gpgsm/t-sign.c index 3c557cfa..fbd72f1a 100644 --- a/tests/gpgsm/t-sign.c +++ b/tests/gpgsm/t-sign.c @@ -23,35 +23,7 @@ #include #include - -#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); -} +#include "t-support.h" static void @@ -102,7 +74,7 @@ check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type) int -main (int argc, char **argv) +main (int argc, char *argv[]) { gpgme_ctx_t ctx; gpgme_error_t err; diff --git a/tests/gpgsm/t-support.h b/tests/gpgsm/t-support.h new file mode 100644 index 00000000..c6470515 --- /dev/null +++ b/tests/gpgsm/t-support.h @@ -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 +#include + +#include + +#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; +} diff --git a/tests/gpgsm/t-verify.c b/tests/gpgsm/t-verify.c index de36073b..be61cbb2 100644 --- a/tests/gpgsm/t-verify.c +++ b/tests/gpgsm/t-verify.c @@ -78,7 +78,7 @@ check_result (gpgme_verify_result_t result, int summary, char *fpr, __FILE__, __LINE__, sig->fpr); exit (1); } - if (sig->status != status) + if (gpg_err_code (sig->status) != status) { fprintf (stderr, "%s:%i: Unexpected signature status: %s\n", __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); 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", __FILE__, __LINE__, gpgme_strerror (sig->validity_reason)); @@ -133,7 +133,7 @@ main (int argc, char **argv) result = gpgme_op_verify_result (ctx); check_result (result, GPGME_SIGSUM_VALID | GPGME_SIGSUM_GREEN, "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E", - GPGME_No_Error, GPGME_VALIDITY_FULL); + GPG_ERR_NO_ERROR, GPGME_VALIDITY_FULL); /* Checking a manipulated message. */ gpgme_data_release (text); @@ -145,7 +145,7 @@ main (int argc, char **argv) result = gpgme_op_verify_result (ctx); check_result (result, GPGME_SIGSUM_RED, "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E", - GPGME_Bad_Signature, GPGME_VALIDITY_UNKNOWN); + GPG_ERR_BAD_SIGNATURE, GPGME_VALIDITY_UNKNOWN); gpgme_release (ctx); return 0; diff --git a/tests/t-data.c b/tests/t-data.c index 46c553db..882ffc82 100644 --- a/tests/t-data.c +++ b/tests/t-data.c @@ -157,7 +157,7 @@ write_test (round_t round, gpgme_data_t data) amt = gpgme_data_write (data, text, 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); @@ -191,7 +191,7 @@ main (int argc, char **argv) const char *text_filename = make_filename ("t-data-1.txt"); const char *longer_text_filename = make_filename ("t-data-2.txt"); 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; while (++round) @@ -231,7 +231,8 @@ main (int argc, char **argv) case TEST_INOUT_MEM_FROM_FILE_NO_COPY: err = gpgme_data_new_from_file (&data, text_filename, 0); /* 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; break; case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME: