+2003-06-06 Marcus Brinkmann <marcus@g10code.de>
+
+ * configure.ac: Check for libgpg-error. Define
+ GPG_ERR_SOURCE_DEFAULT.
+
2003-05-26 Marcus Brinkmann <marcus@g10code.de>
* configure.ac (NEED_GPG_VERSION): Bump up to 1.2.2.
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.
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:
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
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,
* 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
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:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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
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)
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
* 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
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
+2003-06-06 Marcus Brinkmann <marcus@g10code.de>
+
+ * gpgme.texi: Change error codes to GPG_ERR_* variants.
+ (Error Handling): Rewritten.
+
2003-05-29 Marcus Brinkmann <marcus@g10code.de>
* gpgme.texi (Exporting Keys): Change and document prototypes.
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
`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
@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
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,
@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.
@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.
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
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
@table @code
@item GPGME_PROTOCOL_OpenPGP
This specifies the OpenPGP protocol.
+
@item GPGME_PROTOCOL_CMS
This specifies the Cryptographic Message Syntax.
@end table
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
@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
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.
@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;
[...]
-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);
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} {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
-@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:
+
+@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
-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.
-
-@item GPGME_Exec_Error
-This value means that an error occurred when trying to spawn a child
-process.
-
-@item GPGME_Too_Many_Procs
-This value means that there are too many active backend processes.
+@item GPG_ERR_E...
+System errors are mapped to GPG_ERR_FOO where FOO is the symbol for
+the system error.
-@item GPGME_Pipe_Error
-This value means that the creation of a pipe failed.
+@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.
-@item GPGME_No_UserID
-This value means that no valid recipients for a message have been set.
+@item GPG_ERR_UNUSABLE_PUBKEY
+This value means that some recipients for a message were invalid.
-@item GPGME_Invalid_UserID
-This value means that some, but not all, recipients for a message have
-been invalid.
+@item GPG_ERR_UNUSABLE_SECKEY
+This value means that some signers were 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 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_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}:
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
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}})
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}})
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}})
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
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}})
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
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
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
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}.
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.
@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
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
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}})
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}})
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
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}})
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:
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}})
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}})
@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}})
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
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),
@}
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));
@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
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
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
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}})
@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}
@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}})
@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}})
@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}})
@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
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}})
@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}
@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
@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.
@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}})
@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
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}})
@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
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
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
@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}
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}})
@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}
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
@{
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;
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:
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
@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}})
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
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}})
@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
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}.
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}})
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}
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
@}
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;
@}
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
@}
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);
@}
@}
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. */
+2003-06-05 Marcus Brinkmann <marcus@g10code.de>
+
+ Everywhere: Use libgpg-error error codes.
+
+ * Makefile.am (EXTRA_DIST): Remove mkerrors.
+ (BUILT_SOURCES): Remove errors.c.
+ (MOSTLYCLEANFILES): Likewise.
+ (libgpgme_la_SOURCES): Likewise. Add error.c.
+ (errors.c): Remove target.
+ * mkerrors: File removed.
+ * error.c: New file.
+
+ * gpgme.h (gpgme_error_t): Change to type gpg_error_t.
+ (gpgme_err_code_t, gpgme_err_source_t): New types.
+ (gpgme_err_code, gpgme_err_source, gpgme_error, gpgme_err_make):
+ New static inline functions.
+ (gpgme_strsource, gpgme_err_code_from_errno,
+ gpgme_err_code_to_errno, gpgme_err_make_from_errno,
+ gpgme_error_from_errno): New prototypes.
+
2003-05-29 Marcus Brinkmann <marcus@g10code.de>
* gpgme.h (gpgme_op_export_start): Change second arg to const char *.
## 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
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
-
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "gpgme.h"
#include "util.h"
if (len)
{
if (len < strlen (src) + 1)
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INTERNAL);
dest = *destp;
}
string. */
dest = malloc (strlen (src) + 1);
if (!dest)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
*destp = dest;
}
if (len)
{
if (len < strlen (src) + 1)
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INTERNAL);
dest = *destp;
}
string. */
dest = malloc (strlen (src) + 1);
if (!dest)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
*destp = dest;
}
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 }
};
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);
}
/* 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.
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)
(*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;
- }
}
\f
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);
}
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)
{
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;
}
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;
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;
}
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);
{
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;
}
{
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);
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);
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)
{
#endif
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "gpgme.h"
#include "util.h"
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:
{
opd->result.unsupported_algorithm = strdup (args);
if (!opd->result.unsupported_algorithm)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
}
}
}
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;
errno = 0;
problem = strtol (args, &tail, 0);
if (errno || (*tail && *tail != ' '))
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INV_ENGINE);
switch (problem)
{
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;
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;
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)
{
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:
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;
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)
{
#include <unistd.h>
#include <locale.h>
#include <fcntl.h> /* FIXME */
+#include <errno.h>
#include "gpgme.h"
#include "util.h"
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;
+ return gpg_error (GPG_ERR_INV_VALUE);
+ case ASSUAN_Timeout:
+ return gpg_error (GPG_ERR_ETIMEDOUT);
case ASSUAN_Read_Error:
- return GPGME_Read_Error;
+ return gpg_error (GPG_ERR_GENERAL);
case ASSUAN_Write_Error:
- return GPGME_Write_Error;
+ return gpg_error (GPG_ERR_GENERAL);
- case ASSUAN_Timeout:
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);
+
+ case ASSUAN_Invalid_Response:
+ return gpg_error (GPG_ERR_INV_RESPONSE);
- /* These are errors in the server. */
- case ASSUAN_Server_Fault:
+ 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:
+ return gpg_error (GPG_ERR_MISSING_CERT);
+ case ASSUAN_Bad_Signature:
+ 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:
- case ASSUAN_Card_Error: /* XXX: Oh well. */
- case ASSUAN_Invalid_Card: /* XXX: Oh well. */
- case ASSUAN_No_PKCS15_App: /* XXX: Oh well. */
- case ASSUAN_Card_Not_Present: /* XXX: Oh well. */
- case ASSUAN_Invalid_Id: /* XXX: Oh well. */
- return GPGME_Invalid_Key;
-
- case ASSUAN_Bad_Signature:
- return GPGME_Invalid_Key; /* XXX: This is wrong. */
-
+ 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);
}
}
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;
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];
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];
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];
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
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;
{
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,
{
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,
{
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,
old_lc = strdup (old_lc);
if (!old_lc)
{
- err = GPGME_Out_Of_Core;
+ err = gpg_error_from_errno (errno);
goto leave;
}
}
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,
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;
}
}
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,
|| _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;
}
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);
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'
unsigned char *newline = realloc (*aline,
*alinelen + linelen + 1);
if (!newline)
- err = GPGME_Out_Of_Core;
+ err = gpg_error_from_errno (errno);
else
{
*aline = newline;
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");
int length = 8; /* "DELKEYS " */
if (!fpr)
- return GPGME_Invalid_Key;
+ return gpg_error (GPG_ERR_INV_VALUE);
while (*linep)
{
line = malloc (length);
if (!line)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
strcpy (line, "DELKEYS ");
linep = &line[8];
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])
{
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;
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)
{
i++;
}
free (line);
- return invalid_recipients ? GPGME_Invalid_Key : 0;
+ return gpg_error (invalid_recipients
+ ? GPG_ERR_UNUSABLE_PUBKEY : GPG_ERR_NO_ERROR);
}
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,
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);
char *linep;
if (!gpgsm || reserved)
- return GPGME_Invalid_Value;
+ return gpg_error (GPG_ERR_INV_VALUE);
if (pattern && *pattern)
{
}
line = malloc (length);
if (!line)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
strcpy (line, "EXPORT ");
linep = &line[7];
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,
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,
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)
/* 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 ");
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;
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)
}
line = malloc (length);
if (!line)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
if (secret_only)
{
strcpy (line, "LISTSECRETKEYS ");
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)
NULL, NULL);
}
else
- err = GPGME_Invalid_Key;
+ err = gpg_error (GPG_ERR_INV_VALUE);
gpgme_key_unref (key);
if (err)
return err;
}
-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)
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,
gpgsm_keylist,
gpgsm_keylist_ext,
gpgsm_sign,
- gpgsm_trustlist,
+ NULL, /* trustlist */
gpgsm_verify,
gpgsm_set_io_cbs,
gpgsm_io_event
#endif
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "gpgme.h"
#include "util.h"
{
return _gpgme_compare_versions (engine_get_version (proto),
engine_get_req_version (proto))
- ? 0 : GPGME_Invalid_Engine;
+ ? 0 : gpg_error (GPG_ERR_INV_ENGINE);
}
{
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++)
*lastp = malloc (sizeof (*engine_info));
if (!*lastp)
{
+ int saved_errno = errno;
+
while (engine_info)
{
gpgme_engine_info_t next_info = engine_info->next;
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];
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)
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);
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);
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);
}
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);
}
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);
}
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);
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);
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);
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);
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);
_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);
}
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);
}
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);
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);
_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);
}
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);
}
--- /dev/null
+/* error.c - Error handling for GPGME.
+ Copyright (C) 2003 g10 Code GmbH
+
+ This file is part of GPGME.
+
+ GPGME is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GPGME is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GPGME; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gpgme.h>
+
+/* Return a pointer to a string containing a description of the error
+ code in the error value ERR. */
+const char *
+gpgme_strerror (gpgme_error_t err)
+{
+ return gpg_strerror (err);
+}
+
+
+/* Return a pointer to a string containing a description of the error
+ source in the error value ERR. */
+const char *
+gpgme_strsource (gpgme_error_t err)
+{
+ return gpg_strsource (err);
+}
+
+
+/* Retrieve the error code for the system error ERR. This returns
+ GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
+ this). */
+gpgme_err_code_t
+gpgme_err_code_from_errno (int err)
+{
+ return gpg_err_code_from_errno (err);
+}
+
+
+/* Retrieve the system error for the error code CODE. This returns 0
+ if CODE is not a system error code. */
+int
+gpgme_err_code_to_errno (gpgme_err_code_t code)
+{
+ return gpg_err_code_from_errno (code);
+}
+
+
+/* Return an error value with the error source SOURCE and the system
+ error ERR. */
+gpgme_error_t
+gpgme_err_make_from_errno (gpg_err_source_t source, int err)
+{
+ return gpg_err_make_from_errno (source, err);
+}
+
+
+/* Return an error value with the system error ERR. */
+gpgme_err_code_t
+gpgme_error_from_errno (int err)
+{
+ return gpgme_error (gpg_err_code_from_errno (err));
+}
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)
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)
#endif
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "gpgme.h"
#include "context.h"
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;
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:
/* Extract the key parameter from the XML structure. */
parms = strstr (parms, "<GnupgKeyParms ");
if (!parms)
- return GPGME_Invalid_Value;
+ return gpg_error (GPG_ERR_INV_VALUE);
content = strchr (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, "</GnupgKeyParms>");
/* FIXME: Check that there are no control statements inside. */
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <errno.h>
#include "util.h"
#include "context.h"
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;
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;
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;
#endif
#endif
+#include <gpg-error.h>
+
\f
/* Check for compiler features. */
#if __GNUC__
typedef struct gpgme_data *gpgme_data_t;
\f
-/* Public data types provided by GPGME. */
+/* Wrappers for the libgpg-error library. */
+
+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;
+
+
+static __inline__ gpgme_error_t
+gpgme_err_make (gpgme_err_source_t source, gpgme_err_code_t code)
+{
+ return gpg_err_make (source, code);
+}
-/* 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,
-
- /* Reasons for invalid user id. */
- GPGME_Unknown_Reason = 0x0100,
- GPGME_Not_Found = 0x0101,
- GPGME_Ambiguous_Specification = 0x0102,
- GPGME_Wrong_Key_Usage = 0x0103,
- GPGME_Key_Revoked = 0x0104,
- GPGME_Key_Expired = 0x0105,
- GPGME_No_CRL_Known = 0x0106,
- GPGME_CRL_Too_Old = 0x0107,
- GPGME_Policy_Mismatch = 0x0108,
- GPGME_No_Secret_Key = 0x0109,
- GPGME_Key_Not_Trusted = 0x010a,
-
- /* Import problems. */
- GPGME_Issuer_Missing = 0x0200,
- GPGME_Chain_Too_Long = 0x0201,
-
- /* Verification problems. */
- GPGME_Unsupported_Algorithm = 0x0300,
- GPGME_Sig_Expired = 0x0301,
- GPGME_Bad_Signature = 0x0302,
- GPGME_No_Public_Key = 0x0303,
-
- /* Deprecated, see below. */
- GPGME_x_Busy = -2,
- GPGME_x_No_Request = -3,
- GPGME_x_Invalid_Type = -4,
- GPGME_x_Invalid_Mode = -5
- }
-gpgme_error_t;
-typedef gpgme_error_t _gpgme_deprecated_error_t _GPGME_DEPRECATED;
+/* 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);
\f
/* The possible encoding mode of gpgme_data_t objects. */
/* 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);
-
\f
/* Engine support functions. */
import = malloc (sizeof (*import));
if (!import)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
import->next = NULL;
errno = 0;
{
/* The crypto backend does not behave. */
free (import);
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INV_ENGINE);
}
args = tail;
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;
}
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;
(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);
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);
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <errno.h>
#include "util.h"
#include "ops.h"
key = calloc (1, sizeof *key);
if (!key)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
key->_refs = 1;
*r_key = key;
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';
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);
#include <time.h>
#include <assert.h>
#include <ctype.h>
+#include <errno.h>
#include "gpgme.h"
#include "util.h"
{
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. */
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. */
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])
{
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). */
{
key->chain_id = strdup (field[12]);
if (!key->chain_id)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
}
break;
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;
}
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;
return err;
if (!opd->key_cond)
- return GPGME_EOF;
+ return gpg_error (GPG_ERR_EOF);
opd->key_cond = 0;
assert (opd->key_queue);
gpgme_op_keylist_end (gpgme_ctx_t ctx)
{
if (!ctx)
- return GPGME_Invalid_Value;
+ return gpg_error (GPG_ERR_INV_VALUE);
return 0;
}
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. */
+++ /dev/null
-#!/bin/sh
-# mkerrors - Extract error strings from gpgme.h
-# and create C source for gpgme_strerror
-# Copyright (C) 2000 Werner Koch (dd9jn)
-# Copyright (C) 2001 g10 Code GmbH
-#
-# This file is part of GPGME.
-#
-# GPGME is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# GPGME is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
-
-cat <<EOF
-/* Generated automatically by mkerrors */
-/* Do not edit! */
-
-#include <stdio.h>
-#include "gpgme.h"
-
-/**
- * gpgme_strerror:
- * @err: Error code
- *
- * This function returns a textual representaion of the given
- * errocode. If this is an unknown value, a string with the value
- * is returned (which is hold in a static buffer).
- *
- * Return value: String with the error description.
- **/
-const char *
-gpgme_strerror (gpgme_error_t err)
-{
- const char *s;
- static char buf[25];
-
- switch (err) {
-EOF
-
-awk '
-/GPGME_No_Error/ { okay=1 }
-!okay {next}
-/}/ { exit 0 }
-/GPGME_[A-Za-z_]*/ { print_code($1) }
-
-
-function print_code( s )
-{
-printf " case %s: s=\"", s ;
-gsub(/_/, " ", s );
-printf "%s\"; break;\n", substr(s,7);
-}
-'
-
-cat <<EOF
- default: sprintf (buf, "ec=%d", err ); s=buf; break;
-}
-
-return s;
-}
-
-EOF
-
-
-
-
-
-
-
-
-
-
-
-
-
data = calloc (1, sizeof (struct ctx_op_data) + size);
if (!data)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
data->next = ctx->op_data;
data->type = type;
data->cleanup = cleanup;
_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;
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);
{
/* 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;
}
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
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <errno.h>
#include "gpgme.h"
#include "context.h"
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:
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:
case GPGME_STATUS_EOF:
if (opd->no_passphrase || opd->bad_passphrase)
- return GPGME_Bad_Passphrase;
+ return gpg_error (GPG_ERR_BAD_PASSPHRASE);
break;
default:
#endif
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include "util.h"
#include "context.h"
args_cpy = strdup (args);
if (!args_cpy)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
p = strchr (args_cpy, ' ');
if (p)
if (!a)
{
gpg->arg_error = 1;
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
}
a->next = NULL;
a->data = NULL;
if (!a)
{
gpg->arg_error = 1;
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
}
a->next = NULL;
a->data = data;
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;
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],
|| _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;
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;
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)
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++;
}
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++;
}
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)
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)
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)
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",
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++;
}
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)
{
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. */
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)
{
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)
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 */
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 );*/
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);
}
{
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);
}
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)
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)
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)
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)
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)
sig = malloc (sizeof (*sig));
if (!sig)
- return GPGME_Out_Of_Core;
+ return gpg_error_from_errno (errno);
sig->next = NULL;
switch (*args)
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;
{
/* The crypto backend does not behave. */
free (sig);
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INV_ENGINE);
}
args = tail;
{
/* The crypto backend does not behave. */
free (sig);
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INV_ENGINE);
}
args = tail;
{
/* The crypto backend does not behave. */
free (sig);
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INV_ENGINE);
}
args = tail;
{
/* The crypto backend does not behave. */
free (sig);
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INV_ENGINE);
}
args = tail;
while (*args == ' ')
{
/* The crypto backend does not behave. */
free (sig);
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INV_ENGINE);
}
tail = strchr (args, ' ');
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;
case GPGME_STATUS_EOF:
if (opd->result.invalid_signers)
- return GPGME_Invalid_UserID;
+ return gpg_error (GPG_ERR_INV_USER_ID);
break;
default:
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)
{
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
+#include <errno.h>
#include "util.h"
#include "context.h"
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)
{
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;
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <errno.h>
#include "util.h"
#include "ops.h"
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';
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <errno.h>
#include "gpgme.h"
#include "util.h"
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;
}
}
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)
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;
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);
}
gpgme_op_trustlist_end (gpgme_ctx_t ctx)
{
if (!ctx)
- return GPGME_Invalid_Value;
+ return gpg_error (GPG_ERR_INV_VALUE);
return 0;
}
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:
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:
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;
}
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)
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;
}
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)
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)
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)
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;
}
return err;
}
else
- return GPGME_General_Error;
+ return gpg_error (GPG_ERR_INV_ENGINE);
return 0;
}
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;
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)
_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);
}
idx--;
}
if (!sig || idx)
- return GPGME_EOF;
+ return gpg_error (GPG_ERR_EOF);
return gpgme_get_key (ctx, sig->fpr, r_key, 0);
}
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;
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:
#include <stdlib.h>
#include <assert.h>
#include <string.h>
+#include <errno.h>
#include "gpgme.h"
#include "sema.h"
{
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);
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;
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;
}
#include <config.h>
#endif
#include <assert.h>
+#include <errno.h>
#include "gpgme.h"
#include "context.h"
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);
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;
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;
+2003-06-06 Marcus Brinkmann <marcus@g10code.de>
+
+ Everywhere: Use libgpg-error error codes.
+
+ * gpg/Makefile.am (noinst_HEADERS): New variable.
+ * gpg/t-support.h: New file.
+ * gpgsm/Makefile.am (noinst_HEADERS): New variable.
+ * gpgsm/t-support.h: New file.
+
2003-05-29 Marcus Brinkmann <marcus@g10code.de>
* gpg/t-encrypt-sym.c (main): Adapt to new syntax.
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 \
#include <gpgme.h>
-\f
-#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"
+\f
static void
check_verify_result (gpgme_verify_result_t result, int summary, char *fpr,
gpgme_error_t status)
__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__, 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));
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);
-/* t-decrypt.c - regression test
+/* t-decrypt.c - Regression test.
Copyright (C) 2000 Werner Koch (dd9jn)
Copyright (C) 2001, 2003 g10 Code GmbH
#include <gpgme.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;
-}
-
+#include "t-support.h"
+\f
int
main (int argc, char *argv[])
{
-/* 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 <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <unistd.h>
+#include <errno.h>
#include <gpgme.h>
-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"
+\f
static void
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));
}
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);
- }
-
- 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);
-
- 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"));
+ 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_edit (ctx, key, edit_fnc, out, out);
+ fail_if_err (err);
+
+ fputs ("[-- Last response --]\n", stdout);
+ flush_data (out);
+
+ gpgme_data_release (out);
+ gpgme_key_unref (key);
+ gpgme_release (ctx);
return 0;
}
#include <gpgme.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;
-}
-
+#include "t-support.h"
+\f
static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{
-/* 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
#include <gpgme.h>
-#define fail_if_err(err) \
- do \
- { \
- if (err) \
- { \
- fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
- __FILE__, __LINE__, gpgme_strerror (err)); \
- exit (1); \
- } \
- } \
- while (0)
-
-
-static void
-print_data (gpgme_data_t dh)
-{
- char buf[100];
- int ret;
-
- ret = gpgme_data_seek (dh, 0, SEEK_SET);
- if (ret)
- fail_if_err (GPGME_File_Error);
- while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
- fwrite (buf, ret, 1, stdout);
- if (ret < 0)
- fail_if_err (GPGME_File_Error);
-}
-
-
-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"
+\f
int
-main (int argc, char **argv)
+main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
#include <gpgme.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);
-}
-
+#include "t-support.h"
+\f
int
-main (int argc, char **argv)
+main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
#include <gpgme.h>
-#define fail_if_err(err) \
- do \
- { \
- if (err) \
- { \
- fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
- __FILE__, __LINE__, gpgme_strerror (err)); \
- exit (1); \
- } \
- } \
- while (0)
-
-
-static void
-print_data (gpgme_data_t dh)
-{
- char buf[100];
- int ret;
-
- ret = gpgme_data_seek (dh, 0, SEEK_SET);
- if (ret)
- fail_if_err (GPGME_File_Error);
- while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
- fwrite (buf, ret, 1, stdout);
- if (ret < 0)
- fail_if_err (GPGME_File_Error);
-}
-
+#include "t-support.h"
+\f
/* Stripped down version of gpgme/wait.c. */
struct op_result
}
}
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;
}
#include <gpgme.h>
-#define fail_if_err(err) \
- do \
- { \
- if (err) \
- { \
- fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
- __FILE__, __LINE__, gpgme_strerror (err)); \
- exit (1); \
- } \
- } \
- while (0)
-
-
-static void
-print_data (gpgme_data_t dh)
-{
- char buf[100];
- int ret;
-
- ret = gpgme_data_seek (dh, 0, SEEK_SET);
- if (ret)
- fail_if_err (GPGME_File_Error);
- while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
- fwrite (buf, ret, 1, stdout);
- if (ret < 0)
- fail_if_err (GPGME_File_Error);
-}
-
+#include "t-support.h"
+\f
int
main (int argc, char **argv)
{
#include <gpgme.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)
+#include "t-support.h"
+\f
/* 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)
#include <gpgme.h>
-\f
-#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;
-}
-
+#include "t-support.h"
+\f
void
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);
#include <gpgme.h>
-\f
-#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"
+\f
struct
{
char *fpr;
{ NULL }
};
+
int
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);
#include <gpgme.h>
-\f
-#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"
+\f
struct
{
char *fpr;
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);
#include <gpgme.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;
-}
-
+#include "t-support.h"
+\f
static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{
#include <gpgme.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;
-}
-
+#include "t-support.h"
+\f
static void
check_result (gpgme_sign_result_t result, gpgme_sig_mode_t type)
{
--- /dev/null
+/* t-support.h - Helper routines for regression tests.
+ Copyright (C) 2000 Werner Koch (dd9jn)
+ Copyright (C) 2001, 2002, 2003 g10 Code GmbH
+
+ This file is part of GPGME.
+
+ GPGME is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GPGME is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GPGME; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include <unistd.h>
+#include <errno.h>
+
+#include <gpgme.h>
+
+#define fail_if_err(err) \
+ do \
+ { \
+ if (err) \
+ { \
+ fprintf (stderr, "%s:%d: %s: %s\n", \
+ __FILE__, __LINE__, gpgme_strsource (err), \
+ gpgme_strerror (err)); \
+ exit (1); \
+ } \
+ } \
+ while (0)
+
+
+void
+print_data (gpgme_data_t dh)
+{
+#define BUF_SIZE 512
+ char buf[BUF_SIZE + 1];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (gpgme_error_from_errno (errno));
+ while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (gpgme_error_from_errno (errno));
+}
+
+
+gpgme_error_t
+passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
+ int last_was_bad, int fd)
+{
+ write (fd, "abc\n", 4);
+ return 0;
+}
+
+
+char *
+make_filename (const char *fname)
+{
+ const char *srcdir = getenv ("srcdir");
+ char *buf;
+
+ if (!srcdir)
+ srcdir = ".";
+ buf = malloc (strlen(srcdir) + strlen(fname) + 2);
+ if (!buf)
+ exit (8);
+ strcpy (buf, srcdir);
+ strcat (buf, "/");
+ strcat (buf, fname);
+ return buf;
+}
#include <gpgme.h>
-\f
-#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"
+\f
int
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",
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);
#include <gpgme.h>
-\f
-#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"
\f
static const char test_text1[] = "Just GNU it!\n";
__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)
__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));
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);
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);
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);
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
#include <errno.h>
#include <gpgme.h>
+#include "t-support.h"
\f
static const char test_text1[] = "Hallo Leute!\n";
"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[])
#include <gpgme.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);
-}
-
+#include "t-support.h"
int
main (int argc, char **argv)
#include <assert.h>
#include <gpgme.h>
-
-#define fail_if_err(err) \
- do \
- { \
- if (err) \
- { \
- fprintf (stderr, "%s:%d: gpgme_error_t %s\n", \
- __FILE__, __LINE__, gpgme_strerror (err)); \
- exit (1); \
- } \
- } \
- while (0)
-
-
-static void
-print_data (gpgme_data_t dh)
-{
- char buf[100];
- int ret;
-
- ret = gpgme_data_seek (dh, 0, SEEK_SET);
- if (ret)
- fail_if_err (GPGME_File_Error);
- while ((ret = gpgme_data_read (dh, buf, 100)) > 0)
- fwrite (buf, ret, 1, stdout);
- if (ret < 0)
- fail_if_err (GPGME_File_Error);
-}
+#include "t-support.h"
int
#include <errno.h>
#include <gpgme.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);
-}
+#include "t-support.h"
/* True if progress function printed something on the screen. */
int
-main (int argc, char **argv)
+main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
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);
#include <string.h>
#include <gpgme.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);
-}
+#include "t-support.h"
static void
int
-main (int argc, char **argv)
+main (int argc, char *argv[])
{
gpgme_ctx_t ctx;
gpgme_error_t err;
--- /dev/null
+/* t-support.h - Helper routines for regression tests.
+ Copyright (C) 2000 Werner Koch (dd9jn)
+ Copyright (C) 2001, 2002, 2003 g10 Code GmbH
+
+ This file is part of GPGME.
+
+ GPGME is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ GPGME is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GPGME; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#include <unistd.h>
+#include <errno.h>
+
+#include <gpgme.h>
+
+#define fail_if_err(err) \
+ do \
+ { \
+ if (err) \
+ { \
+ fprintf (stderr, "%s:%d: %s: %s\n", \
+ __FILE__, __LINE__, gpg_strsource (err), \
+ gpg_strerror (err)); \
+ exit (1); \
+ } \
+ } \
+ while (0)
+
+
+void
+print_data (gpgme_data_t dh)
+{
+#define BUF_SIZE 512
+ char buf[BUF_SIZE + 1];
+ int ret;
+
+ ret = gpgme_data_seek (dh, 0, SEEK_SET);
+ if (ret)
+ fail_if_err (gpg_error_from_errno (errno));
+ while ((ret = gpgme_data_read (dh, buf, BUF_SIZE)) > 0)
+ fwrite (buf, ret, 1, stdout);
+ if (ret < 0)
+ fail_if_err (gpg_error_from_errno (errno));
+}
+
+
+gpgme_error_t
+passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info,
+ int last_was_bad, int fd)
+{
+ write (fd, "abc\n", 4);
+ return 0;
+}
+
+
+char *
+make_filename (const char *fname)
+{
+ const char *srcdir = getenv ("srcdir");
+ char *buf;
+
+ if (!srcdir)
+ srcdir = ".";
+ buf = malloc (strlen(srcdir) + strlen(fname) + 2);
+ if (!buf)
+ exit (8);
+ strcpy (buf, srcdir);
+ strcat (buf, "/");
+ strcat (buf, fname);
+ return buf;
+}
__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__, 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));
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);
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;
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);
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)
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: