From: Marcus Brinkmann Date: Wed, 9 Oct 2002 00:16:38 +0000 (+0000) Subject: gpgme/ X-Git-Tag: gpgme-1.2.0@1385~799 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=354c9dd85a36918422a3c5e0c79026d51b9a0305;p=gpgme.git gpgme/ 2002-10-08 Marcus Brinkmann New data object component: * gpgme.h (GpgmeDataReadCb, GpgmeDataWriteCb, GpgmeDataSeekCb, GpgmeDataReleaseCb): New types. (struct GpgmeDataCbs): New structure. (gpgme_data_read): Changed prototype to match that of read() closely. (gpgme_data_write): Similar for write(). (gpgme_data_seek, gpgme_data_new_from_cbs, gpgme_data_new_from_fd, gpgme_data_new_from_stream): New prototypes. (gpgme_data_get_type, gpgme_check_engine): Prototype removed. * Makefile.am (libgpgme_la_SOURCES): Add data.h, data-fd.c, data-stream.c, data-mem.c, data-user.c and data-compat.c. * data.c: Reimplemented from scratch. * (data-compat.c, data-fd.c, data.h, data-mem.c, data-stream.c, data-user.c): New file. * context.h (struct gpgme_data_s): Removed. * conversion.c: Include and . (_gpgme_data_append): New function. * data.c (_gpgme_data_append_string): Move to ... * conversion.c (_gpgme_data_append_string): ... here. * data.c (_gpgme_data_append_for_xml): Move to ... * conversion.c (_gpgme_data_append_for_xml): ... here. * data.c (_gpgme_data_append_string_for_xml): Move to ... * conversion.c (_gpgme_data_append_string_for_xml): ... here. * data.c (_gpgme_data_append_percentstring_for_xml): Move to ... * conversion.c (_gpgme_data_append_percentstring_for_xml): ... here. * ops.h (_gpgme_data_get_mode, _gpgme_data_set_mode): Prototype removed. * types.h (GpgmeDataMode): Type removed. * decrypt.c (_gpgme_decrypt_start): Don't check data type or mode. * edit.c (_gpgme_op_edit_start): Likewise. * encrypt.c (_gpgme_op_encrypt_start): Likewise. * encrypt-sign.c (_gpgme_op_encrypt_sign_start): Likewise. * encrypt-sign.c (_gpgme_op_encrypt_sign_start): Likewise. * export.c (_gpgme_op_export_start): Likewise. * genkey.c (_gpgme_op_genkey_start): Likewise. * import.c (_gpgme_op_import_start): Likewise. * sign.c (_gpgme_op_sign_start): Likewise. * verify.c (_gpgme_op_verify_start): Likewise. * encrypt.c (gpgme_op_encrypt): Remove hack that returns invalid no recipient if no data was returned. * encrypt-sign.c (gpgme_op_encrypt_sign): Remove hack that returns no recipient if no data was returned. * encrypt-sign.c (gpgme_op_encrypt_sign): Remove hack that returns no recipient if no data was returned. * engine.c (_gpgme_engine_op_verify): Add new argument to differentiate detached from normal signatures. * engine.h (_gpgme_engine_op_verify): Likewise for prototype. * engine-gpgsm.c (_gpgme_gpgsm_op_verify): Likewise. Don't check mode of data argument. * engine-gpgsm.h (_gpgme_gpgsm_op_verify): Likewise for prototype. * gpgme.h (gpgme_op_verify_start): Likewise for prototype. (gpgme_op_verify): Likewise for prototype. * rungpg.c (_gpgme_gpg_op_verify): Likewise. * rungpg.h (_gpgme_gpg_op_verify): Likewise for prototype. * verify.c (_gpgme_op_verify_start): Likewise. (gpgme_op_verify_start): Likewise. (gpgme_op_verify): Likewise. * rungpg.c (struct arg_and_data_s): New member INBOUND to hold direction of data object. (_gpgme_gpg_add_data): Add new argument INBOUND. Use it to determine direction of data object. (_gpgme_gpg_add_pm_data, _gpgme_gpg_set_command_handler, _gpgme_gpg_op_decrypt, _gpgme_gpg_op_edit, _gpgme_gpg_op_encrypt, _gpgme_gpg_op_encrypt_sign, _gpgme_gpg_op_export, _gpgme_gpg_op_genkey, _gpgme_gpg_op_import, _gpgme_gpg_op_sign, _gpgme_gpg_op_verify): Add new argument to _gpgme_gpg_add_data invocation. (build_argv): Use new member INBOUND to determine direction of file descriptor. Don't check the data type. * rungpg.h (_gpgme_gpg_add_data): Add new argument to prototype. * gpgme.c (gpgme_get_op_info): Don't call _gpgme_data_get_as_string if CTX->op_info is NULL. * version.c (gpgme_check_engine): Function removed. tests/ 2002-10-09 Marcus Brinkmann * gpg/t-decrypt.c (print_data): Update to new gpgme_data_read interface, and use gpgme_engine_check_version instead gpgme_check_version. * gpg/t-decrypt-verify.c (print_data): Likewise. * gpg/t-edit.c (main): Likewise. * gpg/t-encrypt.c (print_data): Likewise. * gpg/t-encrypt-sign.c (print_data): Likewise. * gpg/t-encrypt-sym.c (print_data): Likewise. * gpg/t-eventloop.c (print_data): Likewise. * gpg/t-export.c (print_data): Likewise. * gpg/t-sign.c (print_data): Likewise. * gpg/t-signers.c (print_data): Likewise. * gpgsm/t-decrypt.c (print_data): Likewise. * gpgsm/t-encrypt.c (print_data): Likewise. * gpgsm/t-export.c (print_data): Likewise. * gpgsm/t-sign.c (print_data): Likewise. * gpg/t-verify.c (main): Likewise for gpgme_op_verify. * gpgsm/t-verify.c (main): Likewise for gpgme_op_verify. * t-data.c (read_once_test): Likewise. (write_test): Update for new behaviour of data objects. (main): Remove type test. --- diff --git a/trunk/NEWS b/trunk/NEWS index 0b15b9b..9a5ea04 100644 --- a/trunk/NEWS +++ b/trunk/NEWS @@ -1,6 +1,28 @@ Noteworthy changes in version 0.4.0 (unreleased) ------------------------------------------------ + * New data object interface, which is more flexible and transparent. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +GpgmeDataReadCb NEW +GpgmeDataWriteCb NEW +GpgmeDataSeekCb NEW +GpgmeDataReleaseCb NEW +GpgmeDataCbs NEW +gpgme_data_read CHANGED: Match read() closely. +gpgme_data_write CHANGED: Match write() closely. +gpgme_data_seek NEW +gpgme_data_from_fd NEW +gpgme_data_from_stream NEW +gpgme_data_from_cbs NEW +gpgme_data_rewind DEPRECATED: Replaced by gpgme_data_seek(). +gpgme_data_new_from_read_cb DEPRECATED: Replaced by gpgme_data_from_cbs(). +gpgme_data_get_type REMOVED: No replacement. +gpgme_op_verify CHANGED: Take different data objects for + signed text and plain text. +gpgme_op_verify_start CHANGED: See gpgme_op_verify. +gpgme_check_engine REMOVED: Deprecated since 0.3.0. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Noteworthy changes in version 0.3.11 (2002-09-20) ------------------------------------------------- diff --git a/trunk/TODO b/trunk/TODO index 2ece7e9..c9f5d3c 100644 --- a/trunk/TODO +++ b/trunk/TODO @@ -26,6 +26,8 @@ Hey Emacs, this is -*- outline -*- mode! ** validity/trust * Engines +** Optimize the case where a data object has an underlying fd we can pass + directly to the engine. ** Move code common to all engines up from gpg to engine. ** engine operations can return General Error on unknown protocol (it's an internal error, as select_protocol checks already). @@ -37,7 +39,7 @@ Hey Emacs, this is -*- outline -*- mode! * Operations ** Passphrase callback should not copy password. !!! -** Export status handler need much more work. +** Export status handler need much more work. !!! ** Import should return a useful error when one happened. ** Genkey should return something more useful than General_Error. ** Factor out common code in _op_*_start functions. diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index 7ddcd36..443dfa5 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,3 +1,88 @@ +2002-10-08 Marcus Brinkmann + + New data object component: + + * gpgme.h (GpgmeDataReadCb, GpgmeDataWriteCb, GpgmeDataSeekCb, + GpgmeDataReleaseCb): New types. + (struct GpgmeDataCbs): New structure. + (gpgme_data_read): Changed prototype to match that of read() closely. + (gpgme_data_write): Similar for write(). + (gpgme_data_seek, gpgme_data_new_from_cbs, gpgme_data_new_from_fd, + gpgme_data_new_from_stream): New prototypes. + (gpgme_data_get_type, gpgme_check_engine): Prototype removed. + + * Makefile.am (libgpgme_la_SOURCES): Add data.h, data-fd.c, + data-stream.c, data-mem.c, data-user.c and data-compat.c. + * data.c: Reimplemented from scratch. + * (data-compat.c, data-fd.c, data.h, data-mem.c, data-stream.c, + data-user.c): New file. + * context.h (struct gpgme_data_s): Removed. + * conversion.c: Include and . + (_gpgme_data_append): New function. + * data.c (_gpgme_data_append_string): Move to ... + * conversion.c (_gpgme_data_append_string): ... here. + * data.c (_gpgme_data_append_for_xml): Move to ... + * conversion.c (_gpgme_data_append_for_xml): ... here. + * data.c (_gpgme_data_append_string_for_xml): Move to ... + * conversion.c (_gpgme_data_append_string_for_xml): ... here. + * data.c (_gpgme_data_append_percentstring_for_xml): Move to ... + * conversion.c (_gpgme_data_append_percentstring_for_xml): ... here. + + * ops.h (_gpgme_data_get_mode, _gpgme_data_set_mode): Prototype + removed. + * types.h (GpgmeDataMode): Type removed. + + * decrypt.c (_gpgme_decrypt_start): Don't check data type or mode. + * edit.c (_gpgme_op_edit_start): Likewise. + * encrypt.c (_gpgme_op_encrypt_start): Likewise. + * encrypt-sign.c (_gpgme_op_encrypt_sign_start): Likewise. + * encrypt-sign.c (_gpgme_op_encrypt_sign_start): Likewise. + * export.c (_gpgme_op_export_start): Likewise. + * genkey.c (_gpgme_op_genkey_start): Likewise. + * import.c (_gpgme_op_import_start): Likewise. + * sign.c (_gpgme_op_sign_start): Likewise. + * verify.c (_gpgme_op_verify_start): Likewise. + + * encrypt.c (gpgme_op_encrypt): Remove hack that returns invalid + no recipient if no data was returned. + * encrypt-sign.c (gpgme_op_encrypt_sign): Remove hack that returns + no recipient if no data was returned. + * encrypt-sign.c (gpgme_op_encrypt_sign): Remove hack that returns + no recipient if no data was returned. + + * engine.c (_gpgme_engine_op_verify): Add new argument to + differentiate detached from normal signatures. + * engine.h (_gpgme_engine_op_verify): Likewise for prototype. + * engine-gpgsm.c (_gpgme_gpgsm_op_verify): Likewise. Don't check + mode of data argument. + * engine-gpgsm.h (_gpgme_gpgsm_op_verify): Likewise for prototype. + * gpgme.h (gpgme_op_verify_start): Likewise for prototype. + (gpgme_op_verify): Likewise for prototype. + * rungpg.c (_gpgme_gpg_op_verify): Likewise. + * rungpg.h (_gpgme_gpg_op_verify): Likewise for prototype. + * verify.c (_gpgme_op_verify_start): Likewise. + (gpgme_op_verify_start): Likewise. + (gpgme_op_verify): Likewise. + + * rungpg.c (struct arg_and_data_s): New member INBOUND to hold + direction of data object. + (_gpgme_gpg_add_data): Add new argument INBOUND. Use it to + determine direction of data object. + (_gpgme_gpg_add_pm_data, _gpgme_gpg_set_command_handler, + _gpgme_gpg_op_decrypt, _gpgme_gpg_op_edit, _gpgme_gpg_op_encrypt, + _gpgme_gpg_op_encrypt_sign, _gpgme_gpg_op_export, + _gpgme_gpg_op_genkey, _gpgme_gpg_op_import, _gpgme_gpg_op_sign, + _gpgme_gpg_op_verify): Add new argument to _gpgme_gpg_add_data + invocation. + (build_argv): Use new member INBOUND to determine direction of + file descriptor. Don't check the data type. + * rungpg.h (_gpgme_gpg_add_data): Add new argument to prototype. + + * gpgme.c (gpgme_get_op_info): Don't call + _gpgme_data_get_as_string if CTX->op_info is NULL. + + * version.c (gpgme_check_engine): Function removed. + 2002-09-30 Werner Koch * keylist.c (keylist_colon_handler): Take care when printing a diff --git a/trunk/gpgme/Makefile.am b/trunk/gpgme/Makefile.am index 36cb9c1..dbcfc2a 100644 --- a/trunk/gpgme/Makefile.am +++ b/trunk/gpgme/Makefile.am @@ -57,7 +57,9 @@ endif libgpgme_la_SOURCES = \ gpgme.h types.h util.h util.c conversion.c context.h ops.h \ - data.c recipient.c signers.c wait.c wait.h op-support.c \ + data.h data.c data-fd.c data-stream.c data-mem.c data-user.c \ + data-compat.c \ + recipient.c signers.c wait.c wait.h op-support.c \ encrypt.c encrypt-sign.c decrypt.c decrypt-verify.c verify.c \ sign.c passphrase.c progress.c \ key.h key.c keylist.c trustlist.c \ diff --git a/trunk/gpgme/context.h b/trunk/gpgme/context.h index dbafc61..4a588ce 100644 --- a/trunk/gpgme/context.h +++ b/trunk/gpgme/context.h @@ -1,4 +1,4 @@ -/* context.h +/* context.h * Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2001, 2002 g10 Code GmbH * @@ -40,12 +40,12 @@ struct trust_queue_item_s }; -/* Currently we need it at several places, so we put the definition - * into this header file */ +/* Currently we need it at several places, so we put the definition + into this header file. */ struct gpgme_context_s { int initialized; - /* A gpg request is still pending. */ + /* An engine request is still pending. */ int pending; int use_cms; @@ -112,44 +112,29 @@ struct gpgme_context_s GpgmeData help_data_1; }; - -struct gpgme_data_s { - size_t len; - const char *data; - GpgmeDataType type; - GpgmeDataMode mode; - GpgmeDataEncoding encoding; - - int (*read_cb)( void *, char *, size_t, size_t *); - void *read_cb_value; - int read_cb_eof; - - size_t readpos; - size_t writepos; - size_t private_len; - char *private_buffer; -}; - /* Forward declaration of a structure to store certification - signatures. */ + signatures. */ struct certsig_s; -/* Structure to store user IDs. */ -struct user_id_s { - struct user_id_s *next; - unsigned int revoked:1; - unsigned int invalid:1; - GpgmeValidity validity; - struct certsig_s *certsigs; - const char *name_part; /* all 3 point into strings behind name */ - const char *email_part; /* or to read-only strings */ - const char *comment_part; - char name[1]; +/* Structure to store user IDs. */ +struct user_id_s +{ + struct user_id_s *next; + unsigned int revoked : 1; + unsigned int invalid : 1; + GpgmeValidity validity; + struct certsig_s *certsigs; + const char *name_part; /* All 3 point into strings behind name */ + const char *email_part; /* or to read-only strings. */ + const char *comment_part; + char name[1]; }; -struct gpgme_recipients_s { - struct user_id_s *list; - int checked; /* wether the recipients are all valid */ + +struct gpgme_recipients_s +{ + struct user_id_s *list; + int checked; /* Wether the recipients are all valid. */ }; @@ -166,4 +151,4 @@ struct gpgme_recipients_s { gpgme_wait ((c), 1); \ } while (0) -#endif /* CONTEXT_H */ +#endif /* CONTEXT_H */ diff --git a/trunk/gpgme/conversion.c b/trunk/gpgme/conversion.c index ad85a8a..4d8e3c5 100644 --- a/trunk/gpgme/conversion.c +++ b/trunk/gpgme/conversion.c @@ -24,7 +24,10 @@ #endif #include +#include #include +#include + #include "gpgme.h" #include "util.h" @@ -138,3 +141,117 @@ _gpgme_decode_c_string (const char *src, char **destp) return 0; } + + +GpgmeError +_gpgme_data_append (GpgmeData dh, const char *buffer, size_t length) +{ + if (!dh || !buffer) + return mk_error (Invalid_Value); + + do + { + ssize_t amt = gpgme_data_write (dh, buffer, length); + if (amt == 0 || (amt < 0 && errno != EINTR)) + return mk_error (File_Error); + buffer += amt; + length -= amt; + } + while (length > 0); + + return 0; +} + + +GpgmeError +_gpgme_data_append_string (GpgmeData dh, const char *str) +{ + if (!str) + return 0; + + return _gpgme_data_append (dh, str, strlen (str)); +} + + +GpgmeError +_gpgme_data_append_for_xml (GpgmeData dh, const char *buffer, size_t len) +{ + const char *text, *str; + size_t count; + int err = 0; + + if (!dh || !buffer) + return mk_error (Invalid_Value); + + do + { + text = NULL; + str = buffer; + for (count = len; count && !text; str++, count--) + { + if (*str == '<') + text = "<"; + else if (*str == '>') + text = ">"; /* Not sure whether this is really needed. */ + else if (*str == '&') + text = "&"; + else if (!*str) + text = "�"; + } + if (text) + { + str--; + count++; + } + if (str != buffer) + err = _gpgme_data_append (dh, buffer, str - buffer); + if (!err && text) + { + err = _gpgme_data_append_string (dh, text); + str++; + count--; + } + buffer = str; + len = count; + } + while (!err && len); + return err; +} + + +/* Append a string to DATA and convert it so that the result will be + valid XML. */ +GpgmeError +_gpgme_data_append_string_for_xml (GpgmeData dh, const char *str) +{ + return _gpgme_data_append_for_xml (dh, str, strlen (str)); +} + + +/* Append a string with percent style (%XX) escape characters as + XML. */ +GpgmeError +_gpgme_data_append_percentstring_for_xml (GpgmeData dh, const char *str) +{ + const byte *src; + byte *buf, *dst; + int val; + GpgmeError err; + + buf = xtrymalloc (strlen (str)); + dst = buf; + for (src = str; *src; src++) + { + if (*src == '%' && (val = _gpgme_hextobyte (src + 1)) != -1) + { + *dst++ = val; + src += 2; + } + else + *dst++ = *src; + } + + err = _gpgme_data_append_for_xml (dh, buf, dst - buf); + xfree (buf); + return err; +} diff --git a/trunk/gpgme/data.c b/trunk/gpgme/data.c index dcdf4ec..4f5b191 100644 --- a/trunk/gpgme/data.c +++ b/trunk/gpgme/data.c @@ -1,882 +1,161 @@ -/* data.c - * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 g10 Code GmbH - * - * This file is part of GPGME. - * - * GPGME is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * GPGME is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - +/* data.c - An abstraction for data objects. + Copyright (C) 2002 g10 Code GmbH + + This file is part of GPGME. + + GPGME is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + GPGME is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GPGME; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA. */ + +#if HAVE_CONFIG_H #include -#include +#endif + #include -#include -#include +#include #include -#include -#include +#include +#include "data.h" #include "util.h" -#include "context.h" #include "ops.h" #include "io.h" -/* When expanding an internal buffer, always extend it by ALLOC_CHUNK - bytes at a time. */ -#define ALLOC_CHUNK 1024 - - -/** - * gpgme_data_new: - * @r_dh: returns the new data object - * - * Create a new data object without any content. - * - * Return value: An error value or 0 on success - **/ + GpgmeError -gpgme_data_new (GpgmeData *r_dh) +_gpgme_data_new (GpgmeData *r_dh, struct gpgme_data_cbs *cbs) { GpgmeData dh; if (!r_dh) return mk_error (Invalid_Value); - *r_dh = NULL; - dh = xtrycalloc (1, sizeof *dh); + *r_dh = NULL; + dh = xtrycalloc (1, sizeof (*dh)); if (!dh) return mk_error (Out_Of_Core); - dh->mode = GPGME_DATA_MODE_INOUT; - - *r_dh = dh; - return 0; -} - - -/** - * gpgme_data_new_from_mem: - * @r_dh: Returns a new data object. - * @buffer: Initialize with this. - * @size: Size of the buffer - * @copy: Flag wether a copy of the buffer should be used. - * - * Create a new data object and initialize with data from the memory. - * A @copy with value %TRUE creates a copy of the memory, a value of - * %FALSE uses the original memory of @buffer and the caller has to - * make sure that this buffer is valid until gpgme_data_release() is - * called. - * - * Return value: An error value or 0 for success. - **/ -GpgmeError -gpgme_data_new_from_mem (GpgmeData *r_dh, const char *buffer, size_t size, - int copy) -{ - GpgmeData dh; - GpgmeError err; - - if (!r_dh) - return mk_error (Invalid_Value); - *r_dh = NULL; - if (!buffer) - return mk_error (Invalid_Value); - - err = gpgme_data_new (&dh); - if (err) - return err; - - dh->type = GPGME_DATA_TYPE_MEM; - dh->len = size; - if (!copy) - dh->data = buffer; - else - { - dh->private_buffer = xtrymalloc (size); - if (!dh->private_buffer) - { - gpgme_data_release (dh); - return mk_error (Out_Of_Core); - } - dh->private_len = size; - memcpy (dh->private_buffer, buffer, size); - dh->data = dh->private_buffer; - dh->writepos = size; - } + dh->cbs = cbs; *r_dh = dh; return 0; } -/** - * gpgme_data_new_with_read_cb: - * @r_dh: returns the new data object - * @read_cb: callback function - * @read_cb_value: value passed to the callback function - * - * Create a new data object which is a wrapper around the callback function. - * The callback function is defined as: - * - * typedef int (*read_cb) (void *cb_value, - * char *buffer, - * size_t count, - * size_t *nread); - * - * - * The callback should return a maximium of @count bytes in @buffer - * and the number actually read in @nread. It may return 0 in @nread - * if there are no bytes currently available. To indicate EOF the - * function should return with an error code of %-1 and set @nread to - * 0. The callback may support passing %NULL for @buffer and @nread - * and %0 for count as an indication to reset its internal read - * pointer. - * - * Return value: An error value or 0 for success. - **/ -GpgmeError -gpgme_data_new_with_read_cb (GpgmeData *r_dh, - int (*read_cb) (void *,char *, size_t ,size_t *), - void *read_cb_value) +void +_gpgme_data_release (GpgmeData dh) { - GpgmeData dh; - GpgmeError err; - - if (!r_dh) - return mk_error (Invalid_Value); - *r_dh = NULL; - - if (!read_cb) - return mk_error (Invalid_Value); - - err = gpgme_data_new (&dh); - if (err) - return err; - - dh->type = GPGME_DATA_TYPE_CB; - dh->mode = GPGME_DATA_MODE_OUT; - dh->read_cb = read_cb; - dh->read_cb_value = read_cb_value; - - *r_dh = dh; - return 0; + if (dh) + xfree (dh); } - -/** - * gpgme_data_new_from_file: - * @r_dh: returns the new data object - * @fname: filename - * @copy: Flag, whether the file should be copied. - * - * Create a new data object and initialize it with the content of - * the file @file. If @copy is %True the file is immediately read in - * and closed. @copy of %False is not yet supportted. - * - * Return value: An error code or 0 on success. If the error code is - * %GPGME_File_Error, the OS error code is held in %errno. - **/ -GpgmeError -gpgme_data_new_from_file (GpgmeData *r_dh, const char *fname, int copy) + +/* Read up to SIZE bytes into buffer BUFFER from the data object with + the handle DH. Return the number of characters read, 0 on EOF and + -1 on error. If an error occurs, errno is set. */ +int +gpgme_data_read (GpgmeData dh, void *buffer, size_t size) { - GpgmeData dh; - GpgmeError err; - struct stat st; - FILE *fp; - - if (!r_dh) - return mk_error (Invalid_Value); - *r_dh = NULL; - if (!fname) - return mk_error (Invalid_Value); - - /* We only support copy for now. In future we might want to honor - the copy flag and just store a file pointer. */ - if (!copy) - return mk_error (Not_Implemented); - - err = gpgme_data_new (&dh); - if (err) - return err; - - fp = fopen (fname, "rb"); - if (!fp) - { - int save_errno = errno; - gpgme_data_release (dh); - errno = save_errno; - return mk_error (File_Error); - } - - if (fstat(fileno(fp), &st)) - { - int save_errno = errno; - fclose (fp); - gpgme_data_release (dh); - errno = save_errno; - return mk_error (File_Error); - } - - /* We should check the length of the file and don't allow for too - large files. */ - dh->private_buffer = xtrymalloc (st.st_size); - if (!dh->private_buffer) + if (!dh) { - fclose (fp); - gpgme_data_release (dh); - return mk_error (Out_Of_Core); + errno = EINVAL; + return -1; } - dh->private_len = st.st_size; - - while (fread (dh->private_buffer, dh->private_len, 1, fp) < 1 - && ferror (fp) && errno == EINTR); - - if (ferror (fp)) + if (!dh->cbs->read) { - int save_errno = errno; - fclose (fp); - gpgme_data_release (dh); - errno = save_errno; - return mk_error (File_Error); + errno = EOPNOTSUPP; + return -1; } - - fclose (fp); - - dh->type = GPGME_DATA_TYPE_MEM; - dh->len = dh->private_len; - dh->data = dh->private_buffer; - dh->writepos = dh->len; - - *r_dh = dh; - return 0; + return (*dh->cbs->read) (dh, buffer, size); } -/** - * gpgme_data_new_from_filepart: - * @r_dh: returns the new data object - * @fname: filename - * @fp: filepointer - * @offset: Start reading at this offset - * @length: Read this many bytes - * - * Create a new data object and initialize it with @length bytes - * starting at @offset of @file or @fp. Either a filename or an open - * filepointer may be given. - * - * - * Return value: An error code or 0 on success. If the error code is - * %GPGME_File_Error, the OS error code is held in %errno. - **/ -GpgmeError -gpgme_data_new_from_filepart (GpgmeData *r_dh, const char *fname, FILE *fp, - off_t offset, size_t length) +/* Write up to SIZE bytes from buffer BUFFER to the data object with + the handle DH. Return the number of characters written, or -1 on + error. If an error occurs, errno is set. */ +ssize_t +gpgme_data_write (GpgmeData dh, const void *buffer, size_t size) { - GpgmeData dh; - GpgmeError err; - int save_errno = 0; - - if (!r_dh) - return mk_error (Invalid_Value); - *r_dh = NULL; - - if ((fname && fp) || (!fname && !fp)) - return mk_error (Invalid_Value); - - err = gpgme_data_new (&dh); - if (err) - return err; - - if (!length) - goto out; - - if (fname) - { - fp = fopen (fname, "rb"); - if (!fp) - { - err = mk_error (File_Error); - goto out; - } - } - - if (fseek (fp, (long) offset, SEEK_SET)) - { - err = mk_error (File_Error); - goto out; - } - - dh->private_buffer = xtrymalloc (length); - if (!dh->private_buffer) + if (!dh) { - err = mk_error (Out_Of_Core); - goto out; + errno = EINVAL; + return -1; } - dh->private_len = length; - - while (fread (dh->private_buffer, dh->private_len, 1, fp) < 1 - && ferror (fp) && errno == EINTR); - - if (ferror (fp)) + if (!dh->cbs->write) { - err = mk_error (File_Error); - goto out; + errno = EOPNOTSUPP; + return -1; } - - dh->type = GPGME_DATA_TYPE_MEM; - dh->len = dh->private_len; - dh->data = dh->private_buffer; - dh->writepos = dh->len; - - out: - if (err) - save_errno = errno; - - if (fname && fp) - fclose (fp); - - if (err) - { - gpgme_data_release (dh); - errno = save_errno; - } - else - *r_dh = dh; - return err; + return (*dh->cbs->write) (dh, buffer, size); } -/** - * gpgme_data_release: - * @dh: Data object - * - * Release the data object @dh. @dh may be NULL in which case nothing - * happens. - **/ -void -gpgme_data_release (GpgmeData dh) +/* 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 (GpgmeData dh, off_t offset, int whence) { - if (dh) + if (!dh) { - xfree (dh->private_buffer); - xfree (dh); + errno = EINVAL; + return -1; } -} - - -/* - * Release the data object @dh. @dh may be NULL in which case nothing - * happens. - * - * Return value: An allocated memory object with the content of the - * data object. The function makes sure that the returned string can - * safely be accessed using the string fucntions. - **/ -char * -_gpgme_data_release_and_return_string (GpgmeData dh) -{ - char *val = NULL; - - if (dh) + if (!dh->cbs->read) { - if (_gpgme_data_append (dh, "", 1)) /* append EOS */ - xfree (dh->private_buffer ); - else - { - val = dh->private_buffer; - if (!val && dh->data) - { - val = xtrymalloc (dh->len); - if (val) - memcpy (val, dh->data, dh->len); - } - } - xfree (dh); + errno = EOPNOTSUPP; + return -1; } - return val; + return (*dh->cbs->seek) (dh, offset, whence); } -/** - * gpgme_data_release_and_get_mem: - * @dh: the data object - * @r_len: returns the length of the memory - * - * Release the data object @dh and return its content and the length - * of that content. The caller has to free this data. @dh maybe NULL - * in which case NULL is returned. If there is not enough memory for - * allocating the return value, NULL is returned and the object is - * released. - * - * Return value: a pointer to an allocated buffer of length @r_len. - **/ -char * -gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len) +/* Release the data object with the handle DH. */ +void +gpgme_data_release (GpgmeData dh) { - char *val = NULL; + if (!dh) + return; - if (r_len) - *r_len = 0; - if (dh) - { - size_t len = dh->len; - val = dh->private_buffer; - if (!val && dh->data) - { - val = xtrymalloc (len); - if (val) - memcpy (val, dh->data, len); - } - xfree (dh); - if (val && r_len) - *r_len = len; - } - return val; + if (dh->cbs->release) + (*dh->cbs->release) (dh); + _gpgme_data_release (dh); } -/** - * gpgme_data_get_type: - * @dh: the data object - * - * Get the type of the data object. - * Data types are prefixed with %GPGME_DATA_TYPE_ - * - * Return value: the data type - **/ -GpgmeDataType -gpgme_data_get_type (GpgmeData dh) -{ - if (!dh || (!dh->data && !dh->read_cb)) - return GPGME_DATA_TYPE_NONE; - - return dh->type; -} - -/* Get the current encoding meta information. */ +/* Get the current encoding meta information for the data object with + handle DH. */ GpgmeDataEncoding gpgme_data_get_encoding (GpgmeData dh) { - return dh? dh->encoding : GPGME_DATA_ENCODING_NONE; + return dh ? dh->encoding : GPGME_DATA_ENCODING_NONE; } -/* Set the encoding meta information for DB to ENC */ + +/* Set the encoding meta information for the data object with handle + DH to ENC. */ GpgmeError gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc) { if (!dh) - return GPGME_Invalid_Value; + return mk_error (Invalid_Value); if (enc < 0 || enc > GPGME_DATA_ENCODING_ARMOR) return GPGME_Invalid_Value; dh->encoding = enc; return 0; } -void -_gpgme_data_set_mode (GpgmeData dh, GpgmeDataMode mode) -{ - assert (dh); - dh->mode = mode; -} - - -GpgmeDataMode -_gpgme_data_get_mode (GpgmeData dh) -{ - assert (dh); - return dh->mode; -} - - -/** - * gpgme_data_rewind: - * @dh: the data object - * - * Prepare the data object in a way, that a gpgme_data_read() does start - * at the beginning of the data. This has to be done for all types - * of data objects. - * - * Return value: An error code or 0 on success - **/ -GpgmeError -gpgme_data_rewind (GpgmeData dh) -{ - if (!dh) - return mk_error (Invalid_Value); - - switch (dh->type) - { - case GPGME_DATA_TYPE_NONE: - case GPGME_DATA_TYPE_MEM: - dh->readpos = 0; - return 0; - - case GPGME_DATA_TYPE_CB: - dh->len = dh->readpos = 0; - dh->read_cb_eof = 0; - if (dh->read_cb (dh->read_cb_value, NULL, 0, NULL)) - return mk_error (Not_Implemented); - return 0; - - default: - return mk_error (General_Error); - } -} - -/** - * gpgme_data_read: - * @dh: the data object - * @buffer: A buffer - * @length: The length of that bufer - * @nread: Returns the number of bytes actually read. - * - * Copy data from the current read position (which may be set by - * gpgme_data_rewind()) to the supplied @buffer, max. @length bytes - * are copied and the actual number of bytes are returned in @nread. - * If there are no more bytes available %GPGME_EOF is returned and @nread - * is set to 0. - * - * With a @buffer of NULL, the function does only return the number of - * bytes available and does not move the read pointer. This does only - * work for certain data types, all other will respond with an - * %GPGME_Invalid_Type. - * - * Return value: An error code or 0 on success, EOF is indcated by the - * error code GPGME_EOF. - **/ -GpgmeError -gpgme_data_read (GpgmeData dh, void *buffer, size_t length, size_t *nread) -{ - size_t nbytes; - - if (!dh) - return mk_error (Invalid_Value); - - switch (dh->type) - { - case GPGME_DATA_TYPE_NONE: - *nread = 0; - return mk_error(EOF); - break; - - case GPGME_DATA_TYPE_MEM: - nbytes = dh->len - dh->readpos; - if (!nbytes) - { - *nread = 0; - return mk_error(EOF); - } - - if (!buffer) - *nread = nbytes; - else - { - if (nbytes > length) - nbytes = length; - memcpy (buffer, dh->data + dh->readpos, nbytes); - *nread = nbytes; - dh->readpos += nbytes; - } - return 0; - - case GPGME_DATA_TYPE_CB: - if (!buffer) - { - *nread = 0; - return mk_error (Invalid_Type); - } - nbytes = dh->len - dh->readpos; - if (nbytes) - { - /* We have unread data - return this. */ - if (nbytes > length) - nbytes = length; - memcpy (buffer, dh->data + dh->readpos, nbytes); - *nread = nbytes; - dh->readpos += nbytes; - } - else - { - /* Get the data from the callback. */ - if (!dh->read_cb || dh->read_cb_eof) - { - *nread = 0; - return mk_error (EOF); - } - if (dh->read_cb (dh->read_cb_value, buffer, length, nread)) - { - *nread = 0; - dh->read_cb_eof = 1; - return mk_error (EOF); - } - } - return 0; - - default: - return mk_error (General_Error); - } -} - - -GpgmeError -_gpgme_data_unread (GpgmeData dh, const char *buffer, size_t length) -{ - if (!dh) - return mk_error (Invalid_Value); - - if (dh->type == GPGME_DATA_TYPE_MEM) - { - /* Check that we don't unread more than we have yet read. */ - if (dh->readpos < length) - return mk_error (Invalid_Value); - /* No need to use the buffer for this data type. */ - dh->readpos -= length; - } - else - return mk_error (General_Error); - - return 0; -} - - -/* - * This function does make sense when we know that it contains no nil chars. - */ -char * -_gpgme_data_get_as_string (GpgmeData dh) -{ - char *val = NULL; - - if (dh) - { - val = xtrymalloc (dh->len+1); - if (val) - { - memcpy (val, dh->data, dh->len); - val[dh->len] = 0; - } - } - return val; -} - - -/** - * gpgme_data_write: - * @dh: the context - * @buffer: data to be written to the data object - * @length: length of this data - * - * Write the content of @buffer to the data object @dh at the current write - * position. - * - * Return value: 0 on success or an error code - **/ -GpgmeError -gpgme_data_write (GpgmeData dh, const void *buffer, size_t length) -{ - if (!dh || !buffer) - return mk_error (Invalid_Value); - - return _gpgme_data_append (dh, (const char *)buffer, length ); -} - - -GpgmeError -_gpgme_data_append (GpgmeData dh, const char *buffer, size_t length) -{ - assert (dh); - - if (dh->type == GPGME_DATA_TYPE_NONE) - { - /* Convert it to a mem data type. */ - assert (!dh->private_buffer); - dh->type = GPGME_DATA_TYPE_MEM; - dh->private_len = length < ALLOC_CHUNK? ALLOC_CHUNK : length; - dh->private_buffer = xtrymalloc (dh->private_len); - if (!dh->private_buffer) - { - dh->private_len = 0; - return mk_error (Out_Of_Core); - } - dh->writepos = 0; - dh->data = dh->private_buffer; - } - else if (dh->type != GPGME_DATA_TYPE_MEM) - return mk_error (Invalid_Type); - - if (dh->mode != GPGME_DATA_MODE_INOUT - && dh->mode != GPGME_DATA_MODE_IN) - return mk_error (Invalid_Mode); - - if (!dh->private_buffer) - { - /* We have to copy it now. */ - assert (dh->data); - dh->private_len = dh->len+length; - if (dh->private_len < ALLOC_CHUNK) - dh->private_len = ALLOC_CHUNK; - dh->private_buffer = xtrymalloc (dh->private_len); - if (!dh->private_buffer) - { - dh->private_len = 0; - return mk_error (Out_Of_Core); - } - memcpy (dh->private_buffer, dh->data, dh->len); - dh->writepos = dh->len; - dh->data = dh->private_buffer; - } - - /* Allocate more memory if needed. */ - if (dh->writepos + length > dh->private_len) - { - char *p; - size_t newlen = dh->private_len - + (length < ALLOC_CHUNK? ALLOC_CHUNK : length); - p = xtryrealloc (dh->private_buffer, newlen); - if (!p) - return mk_error (Out_Of_Core); - dh->private_buffer = p; - dh->private_len = newlen; - dh->data = dh->private_buffer; - assert (!(dh->writepos + length > dh->private_len)); - } - - memcpy (dh->private_buffer + dh->writepos, buffer, length); - dh->writepos += length; - dh->len += length; - - return 0; -} - - -GpgmeError -_gpgme_data_append_string (GpgmeData dh, const char *s) -{ - return _gpgme_data_append (dh, s, s ? strlen(s) : 0); -} - - -GpgmeError -_gpgme_data_append_for_xml (GpgmeData dh, - const char *buffer, size_t len) -{ - const char *text, *s; - size_t n; - int rc = 0; - - if (!dh || !buffer) - return mk_error (Invalid_Value); - - do - { - for (text=NULL, s = buffer, n = len; n && !text; s++, n--) - { - if (*s == '<') - text = "<"; - else if (*s == '>') - text = ">"; /* Not sure whether this is really needed. */ - else if (*s == '&') - text = "&"; - else if (!*s) - text = "�"; - } - if (text) - { - s--; - n++; - } - if (s != buffer) - rc = _gpgme_data_append (dh, buffer, s-buffer); - if (!rc && text) - { - rc = _gpgme_data_append_string (dh, text); - s++; - n--; - } - buffer = s; - len = n; - } - while (!rc && len); - return rc; -} - - -/* - * Append a string to DATA and convert it so that the result will be - * valid XML. - */ -GpgmeError -_gpgme_data_append_string_for_xml (GpgmeData dh, const char *string) -{ - return _gpgme_data_append_for_xml (dh, string, strlen (string)); -} - - -static int -hextobyte(const byte *s) -{ - int c; - - if (*s >= '0' && *s <= '9') - c = 16 * (*s - '0'); - else if (*s >= 'A' && *s <= 'F') - c = 16 * (10 + *s - 'A'); - else if (*s >= 'a' && *s <= 'f') - c = 16 * (10 + *s - 'a'); - else - return -1; - s++; - if (*s >= '0' && *s <= '9') - c += *s - '0'; - else if (*s >= 'A' && *s <= 'F') - c += 10 + *s - 'A'; - else if (*s >= 'a' && *s <= 'f') - c += 10 + *s - 'a'; - else - return -1; - return c; -} - -/* - * Append a string with percent style (%XX) escape characters as XML. - */ -GpgmeError -_gpgme_data_append_percentstring_for_xml (GpgmeData dh, const char *string) -{ - const byte *s; - byte *buf, *d; - int val; - GpgmeError err; - - d = buf = xtrymalloc (strlen (string)); - for (s = string; *s; s++) - { - if (*s == '%' && (val = hextobyte (s+1)) != -1) - { - *d++ = val; - s += 2; - } - else - *d++ = *s; - } - - err = _gpgme_data_append_for_xml (dh, buf, d - buf); - xfree (buf); - return err; -} - + /* Functions to support the wait interface. */ void @@ -884,127 +163,60 @@ _gpgme_data_inbound_handler (void *opaque, int fd) { GpgmeData dh = opaque; GpgmeError err; - int nread; - char buf[200]; - - assert (_gpgme_data_get_mode (dh) == GPGME_DATA_MODE_IN); + char buffer[BUFFER_SIZE]; + ssize_t buflen; - nread = _gpgme_io_read (fd, buf, 200); - if (nread < 0) - { - DEBUG3 ("read_mem_data: read failed on fd %d (n=%d): %s", - fd, nread, strerror (errno) ); - _gpgme_io_close (fd); /* XXX ??? */ - return; - } - else if (!nread) + buflen = read (fd, buffer, BUFFER_SIZE); + if (buflen <= 0) { _gpgme_io_close (fd); - return; /* eof */ + return; } - /* We could improve this with a GpgmeData function which takes - * the read function or provides a memory area for writing to it. - */ - - err = _gpgme_data_append (dh, buf, nread); + + err = _gpgme_data_append (dh, buffer, buflen); if (err) { - DEBUG1 ("_gpgme_append_data failed: %s\n", - gpgme_strerror(err)); + DEBUG1 ("_gpgme_data_append failed: %s\n", gpgme_strerror (err)); /* Fixme: we should close the pipe or read it to /dev/null in - * this case. Returnin EOF is not sufficient */ - _gpgme_io_close (fd); /* XXX ??? */ + * this case. Returning EOF is not sufficient */ + _gpgme_io_close (fd); /* XXX ??? */ return; } - return; } -static int -write_mem_data (GpgmeData dh, int fd) -{ - size_t nbytes; - int nwritten; - nbytes = dh->len - dh->readpos; - if (!nbytes) - { - return 1; - } - - /* FIXME: Arggg, the pipe blocks on large write request, although - * select told us that it is okay to write - need to figure out - * why this happens? Stevens says nothing about this problem (or - * is it my Linux kernel 2.4.0test1) - * To avoid that we have set the pipe to nonblocking. - */ - - nwritten = _gpgme_io_write (fd, dh->data+dh->readpos, nbytes); - if (nwritten == -1 && errno == EAGAIN) - return 0; - if (nwritten < 1) - { - DEBUG3 ("write_mem_data(%d): write failed (n=%d): %s", - fd, nwritten, strerror (errno)); - return 1; - } - - dh->readpos += nwritten; - return 0; -} - -static int -write_cb_data (GpgmeData dh, int fd) +void +_gpgme_data_outbound_handler (void *opaque, int fd) { - size_t nbytes; - int err, nwritten; - char buffer[512]; + GpgmeData dh = opaque; + ssize_t nwritten; - err = gpgme_data_read (dh, buffer, DIM(buffer), &nbytes); - if (err == GPGME_EOF) + if (!dh->pending_len) { - return 1; + ssize_t amt = gpgme_data_read (dh, dh->pending, BUFFER_SIZE); + if (amt <= 0) + { + _gpgme_io_close (fd); + return; + } + dh->pending_len = amt; } - - nwritten = _gpgme_io_write (fd, buffer, nbytes); + + nwritten = _gpgme_io_write (fd, dh->pending, dh->pending_len); if (nwritten == -1 && errno == EAGAIN ) - return 0; - if (nwritten < 1) - { - DEBUG3 ("write_cb_data(%d): write failed (n=%d): %s", - fd, nwritten, strerror (errno)); - return 1; - } + return; - if (nwritten < nbytes) + if (nwritten <= 0) { - /* ugly, ugly: It does currently only for for MEM type data */ - if (_gpgme_data_unread (dh, buffer + nwritten, nbytes - nwritten)) - DEBUG1 ("wite_cb_data: unread of %d bytes failed\n", - nbytes - nwritten); - return 1; + DEBUG3 ("_gpgme_data_outbound_handler (%d): write failed (n=%d): %s", + fd, nwritten, strerror (errno)); + _gpgme_io_close (fd); + return; } - - return 0; -} -void -_gpgme_data_outbound_handler (void *opaque, int fd) -{ - GpgmeData dh = opaque; - - assert (_gpgme_data_get_mode (dh) == GPGME_DATA_MODE_OUT); - switch (gpgme_data_get_type (dh)) - { - case GPGME_DATA_TYPE_MEM: - if (write_mem_data (dh, fd)) - _gpgme_io_close (fd); - break; - case GPGME_DATA_TYPE_CB: - if (write_cb_data (dh, fd)) - _gpgme_io_close (fd); - break; - default: - assert (0); - } + if (nwritten < dh->pending_len) + memmove (dh->pending, dh->pending + nwritten, dh->pending_len - nwritten); + dh->pending_len -= nwritten; + return; } diff --git a/trunk/gpgme/decrypt.c b/trunk/gpgme/decrypt.c index 7c77680..9734ae7 100644 --- a/trunk/gpgme/decrypt.c +++ b/trunk/gpgme/decrypt.c @@ -170,19 +170,16 @@ _gpgme_decrypt_start (GpgmeCtx ctx, int synchronous, goto leave; /* Check the supplied data. */ - if (!ciph || gpgme_data_get_type (ciph) == GPGME_DATA_TYPE_NONE) + if (!ciph) { err = mk_error (No_Data); goto leave; } - _gpgme_data_set_mode (ciph, GPGME_DATA_MODE_OUT); - - if (gpgme_data_get_type (plain) != GPGME_DATA_TYPE_NONE) + if (!plain) { err = mk_error (Invalid_Value); goto leave; } - _gpgme_data_set_mode (plain, GPGME_DATA_MODE_IN); err = _gpgme_passphrase_start (ctx); if (err) diff --git a/trunk/gpgme/edit.c b/trunk/gpgme/edit.c index e4dbba3..fdf928c 100644 --- a/trunk/gpgme/edit.c +++ b/trunk/gpgme/edit.c @@ -94,12 +94,11 @@ _gpgme_op_edit_start (GpgmeCtx ctx, int synchronous, ctx->result.edit->fnc_value = fnc_value; /* Check the supplied data. */ - if (!out || gpgme_data_get_type (out) != GPGME_DATA_TYPE_NONE) + if (!out) { err = mk_error (Invalid_Value); goto leave; } - _gpgme_data_set_mode (out, GPGME_DATA_MODE_IN); err = _gpgme_engine_set_command_handler (ctx->engine, command_handler, ctx, out); diff --git a/trunk/gpgme/encrypt-sign.c b/trunk/gpgme/encrypt-sign.c index 39ec6d1..43bd1dc 100644 --- a/trunk/gpgme/encrypt-sign.c +++ b/trunk/gpgme/encrypt-sign.c @@ -61,18 +61,16 @@ _gpgme_op_encrypt_sign_start (GpgmeCtx ctx, int synchronous, _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); /* Check the supplied data */ - if (gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE) + if (!plain) { err = mk_error (No_Data); goto leave; } - _gpgme_data_set_mode (plain, GPGME_DATA_MODE_OUT); - if (!cipher || gpgme_data_get_type (cipher) != GPGME_DATA_TYPE_NONE) + if (!cipher) { err = mk_error (Invalid_Value); goto leave; } - _gpgme_data_set_mode (cipher, GPGME_DATA_MODE_IN); err = _gpgme_engine_op_encrypt_sign (ctx->engine, recp, plain, cipher, ctx->use_armor, ctx /* FIXME */); @@ -116,17 +114,7 @@ gpgme_op_encrypt_sign (GpgmeCtx ctx, GpgmeRecipients recp, GpgmeData plain, GpgmeData cipher) { GpgmeError err = _gpgme_op_encrypt_sign_start (ctx, 1, recp, plain, cipher); - if (!err) - { - err = _gpgme_wait_one (ctx); - /* Old gpg versions don't return status info for invalid - recipients, so we simply check whether we got any output at - all, and if not we assume that we don't have valid - recipients. */ - if (!ctx->error && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE) - ctx->error = mk_error (No_Recipients); - err = ctx->error; - } + err = _gpgme_wait_one (ctx); return err; } diff --git a/trunk/gpgme/encrypt.c b/trunk/gpgme/encrypt.c index aeae6d0..43e552f 100644 --- a/trunk/gpgme/encrypt.c +++ b/trunk/gpgme/encrypt.c @@ -190,18 +190,16 @@ _gpgme_op_encrypt_start (GpgmeCtx ctx, int synchronous, _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); /* Check the supplied data */ - if (gpgme_data_get_type (plain) == GPGME_DATA_TYPE_NONE) + if (!plain) { err = mk_error (No_Data); goto leave; } - _gpgme_data_set_mode (plain, GPGME_DATA_MODE_OUT); - if (!ciph || gpgme_data_get_type (ciph) != GPGME_DATA_TYPE_NONE) + if (!ciph) { err = mk_error (Invalid_Value); goto leave; } - _gpgme_data_set_mode (ciph, GPGME_DATA_MODE_IN); err = _gpgme_engine_op_encrypt (ctx->engine, recp, plain, ciph, ctx->use_armor); @@ -247,15 +245,6 @@ gpgme_op_encrypt (GpgmeCtx ctx, GpgmeRecipients recp, { int err = _gpgme_op_encrypt_start (ctx, 1, recp, plain, cipher); if (!err) - { - err = _gpgme_wait_one (ctx); - /* Old gpg versions don't return status info for invalid - recipients, so we simply check whether we got any output at - all, and if not we assume that we don't have valid - recipients. */ - if (!ctx->error && gpgme_data_get_type (cipher) == GPGME_DATA_TYPE_NONE) - ctx->error = mk_error (No_Recipients); - err = ctx->error; - } + err = _gpgme_wait_one (ctx); return err; } diff --git a/trunk/gpgme/engine-gpgsm.c b/trunk/gpgme/engine-gpgsm.c index 6d98a9d..6167510 100644 --- a/trunk/gpgme/engine-gpgsm.c +++ b/trunk/gpgme/engine-gpgsm.c @@ -1146,7 +1146,8 @@ _gpgme_gpgsm_op_trustlist (GpgsmObject gpgsm, const char *pattern) GpgmeError -_gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData text) +_gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData signed_text, + GpgmeData plaintext) { GpgmeError err; @@ -1162,10 +1163,10 @@ _gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData text) map_input_enc (gpgsm->input_cb.data)); if (err) return err; - if (_gpgme_data_get_mode (text) == GPGME_DATA_MODE_IN) + if (plaintext) { /* Normal or cleartext signature. */ - gpgsm->output_cb.data = text; + gpgsm->output_cb.data = plaintext; err = gpgsm_set_fd (gpgsm->assuan_ctx, "OUTPUT", gpgsm->output_fd_server, 0); _gpgme_io_close (gpgsm->message_cb.fd); @@ -1173,7 +1174,7 @@ _gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, GpgmeData text) else { /* Detached signature. */ - gpgsm->message_cb.data = text; + gpgsm->message_cb.data = signed_text; err = gpgsm_set_fd (gpgsm->assuan_ctx, "MESSAGE", gpgsm->message_fd_server, 0); _gpgme_io_close (gpgsm->output_cb.fd); diff --git a/trunk/gpgme/engine-gpgsm.h b/trunk/gpgme/engine-gpgsm.h index 6092829..4a98084 100644 --- a/trunk/gpgme/engine-gpgsm.h +++ b/trunk/gpgme/engine-gpgsm.h @@ -61,7 +61,7 @@ GpgmeError _gpgme_gpgsm_op_sign (GpgsmObject gpgsm, GpgmeData in, GpgmeCtx ctx /* FIXME */); GpgmeError _gpgme_gpgsm_op_trustlist (GpgsmObject gpgsm, const char *pattern); GpgmeError _gpgme_gpgsm_op_verify (GpgsmObject gpgsm, GpgmeData sig, - GpgmeData text); + GpgmeData signed_text, GpgmeData plaintext); GpgmeError _gpgme_gpgsm_start (GpgsmObject gpgsm, void *opaque); void _gpgme_gpgsm_set_io_cbs (GpgsmObject gpgsm, struct GpgmeIOCbs *io_cbs); void _gpgme_gpgsm_io_event (GpgsmObject gpgsm, GpgmeEventIO type, void *type_data); diff --git a/trunk/gpgme/engine.c b/trunk/gpgme/engine.c index ee56076..fabb945 100644 --- a/trunk/gpgme/engine.c +++ b/trunk/gpgme/engine.c @@ -542,7 +542,8 @@ _gpgme_engine_op_trustlist (EngineObject engine, const char *pattern) } GpgmeError -_gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, GpgmeData text) +_gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, + GpgmeData signed_text, GpgmeData plaintext) { if (!engine) return mk_error (Invalid_Value); @@ -550,9 +551,11 @@ _gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, GpgmeData text) switch (engine->protocol) { case GPGME_PROTOCOL_OpenPGP: - return _gpgme_gpg_op_verify (engine->engine.gpg, sig, text); + return _gpgme_gpg_op_verify (engine->engine.gpg, sig, + signed_text, plaintext); case GPGME_PROTOCOL_CMS: - return _gpgme_gpgsm_op_verify (engine->engine.gpgsm, sig, text); + return _gpgme_gpgsm_op_verify (engine->engine.gpgsm, sig, + signed_text, plaintext); default: break; } diff --git a/trunk/gpgme/engine.h b/trunk/gpgme/engine.h index be46ec7..bb345ef 100644 --- a/trunk/gpgme/engine.h +++ b/trunk/gpgme/engine.h @@ -76,7 +76,7 @@ GpgmeError _gpgme_engine_op_sign (EngineObject engine, GpgmeData in, GpgmeError _gpgme_engine_op_trustlist (EngineObject engine, const char *pattern); GpgmeError _gpgme_engine_op_verify (EngineObject engine, GpgmeData sig, - GpgmeData text); + GpgmeData signed_text, GpgmeData plaintext); GpgmeError _gpgme_engine_start (EngineObject engine, void *opaque); void _gpgme_engine_set_io_cbs (EngineObject engine, diff --git a/trunk/gpgme/export.c b/trunk/gpgme/export.c index 341d260..ad4984d 100644 --- a/trunk/gpgme/export.c +++ b/trunk/gpgme/export.c @@ -51,12 +51,11 @@ _gpgme_op_export_start (GpgmeCtx ctx, int synchronous, if (err) goto leave; - if (!keydata || gpgme_data_get_type (keydata) != GPGME_DATA_TYPE_NONE) + if (!keydata) { err = mk_error (Invalid_Value); goto leave; } - _gpgme_data_set_mode (keydata, GPGME_DATA_MODE_IN); _gpgme_engine_set_status_handler (ctx->engine, export_status_handler, ctx); _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); @@ -99,12 +98,7 @@ gpgme_op_export (GpgmeCtx ctx, GpgmeRecipients recipients, GpgmeData keydata) { GpgmeError err = _gpgme_op_export_start (ctx, 1, recipients, keydata); if (!err) - { - err = _gpgme_wait_one (ctx); - /* XXX We don't get status information. */ - if (!ctx->error && gpgme_data_get_type (keydata) == GPGME_DATA_TYPE_NONE) - ctx->error = mk_error (No_Recipients); - err = ctx->error; - } + err = _gpgme_wait_one (ctx); + /* XXX We don't get enough status information. */ return err; } diff --git a/trunk/gpgme/genkey.c b/trunk/gpgme/genkey.c index 41d0e1b..e573d92 100644 --- a/trunk/gpgme/genkey.c +++ b/trunk/gpgme/genkey.c @@ -92,27 +92,6 @@ _gpgme_op_genkey_start (GpgmeCtx ctx, int synchronous, const char *parms, gpgme_data_release (ctx->help_data_1); ctx->help_data_1 = NULL; - if (!pubkey && !seckey) - ; /* okay: Add key to the keyrings */ - else if (pubkey && gpgme_data_get_type (pubkey) != GPGME_DATA_TYPE_NONE) - { - err = mk_error (Invalid_Value); - goto leave; - } - else if (seckey && gpgme_data_get_type (seckey) != GPGME_DATA_TYPE_NONE) - { - err = mk_error (Invalid_Value); - goto leave; - } - - if (pubkey) - /* FIXME: Need some more things here. */ - _gpgme_data_set_mode (pubkey, GPGME_DATA_MODE_IN); - - if (seckey) - /* FIXME: Need some more things here. */ - _gpgme_data_set_mode (seckey, GPGME_DATA_MODE_IN); - if ((parms = strstr (parms, "')) && (sx = strstr (parms, "format=\"internal\"")) @@ -130,8 +109,6 @@ _gpgme_op_genkey_start (GpgmeCtx ctx, int synchronous, const char *parms, if (err) goto leave; - - _gpgme_data_set_mode (ctx->help_data_1, GPGME_DATA_MODE_OUT); _gpgme_engine_set_status_handler (ctx->engine, genkey_status_handler, ctx); _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); diff --git a/trunk/gpgme/gpgme.c b/trunk/gpgme/gpgme.c index 6ee2bb1..37e3b71 100644 --- a/trunk/gpgme/gpgme.c +++ b/trunk/gpgme/gpgme.c @@ -168,7 +168,7 @@ gpgme_get_notation (GpgmeCtx ctx) char * gpgme_get_op_info (GpgmeCtx ctx, int reserved) { - if (!ctx || reserved) + if (!ctx || reserved || !ctx->op_info) return NULL; /* Invalid value. */ return _gpgme_data_get_as_string (ctx->op_info); diff --git a/trunk/gpgme/gpgme.h b/trunk/gpgme/gpgme.h index 08261fe..d853403 100644 --- a/trunk/gpgme/gpgme.h +++ b/trunk/gpgme/gpgme.h @@ -507,9 +507,54 @@ GpgmeError gpgme_recipients_enum_close (const GpgmeRecipients rset, /* Functions to handle data objects. */ +/* Read up to SIZE bytes into buffer BUFFER from the data object with + the handle HANDLE. Return the number of characters read, 0 on EOF + and -1 on error. If an error occurs, errno is set. */ +typedef int (*GpgmeDataReadCb) (void *handle, void *buffer, size_t size); + +/* Write up to SIZE bytes from buffer BUFFER to the data object with + the handle HANDLE. Return the number of characters written, or -1 + on error. If an error occurs, errno is set. */ +typedef ssize_t (*GpgmeDataWriteCb) (void *handle, const void *buffer, + size_t size); + +/* Set the current position from where the next read or write starts + in the data object with the handle HANDLE to OFFSET, relativ to + WHENCE. */ +typedef int (*GpgmeDataSeekCb) (void *handle, off_t offset, int whence); + +/* Close the data object with the handle DL. */ +typedef void (*GpgmeDataReleaseCb) (void *handle); + +struct GpgmeDataCbs +{ + GpgmeDataReadCb read; + GpgmeDataWriteCb write; + GpgmeDataSeekCb seek; + GpgmeDataReleaseCb release; +}; + +/* Read up to SIZE bytes into buffer BUFFER from the data object with + the handle DH. Return the number of characters read, 0 on EOF and + -1 on error. If an error occurs, errno is set. */ +int gpgme_data_read (GpgmeData dh, void *buffer, size_t size); + +/* Write up to SIZE bytes from buffer BUFFER to the data object with + the handle DH. Return the number of characters written, or -1 on + error. If an error occurs, errno is set. */ +ssize_t gpgme_data_write (GpgmeData dh, const void *buffer, size_t size); + +/* Set the current position from where the next read or write starts + in the data object with the handle DH to OFFSET, relativ to + WHENCE. */ +off_t gpgme_data_seek (GpgmeData dh, off_t offset, int whence); + /* Create a new data buffer and return it in R_DH. */ GpgmeError gpgme_data_new (GpgmeData *r_dh); +/* Destroy the data buffer DH. */ +void gpgme_data_release (GpgmeData dh); + /* Create a new data buffer filled with SIZE bytes starting from BUFFER. If COPY is zero, copying is delayed until necessary, and the data is taken from the original location when needed. */ @@ -517,14 +562,37 @@ GpgmeError gpgme_data_new_from_mem (GpgmeData *r_dh, const char *buffer, size_t size, int copy); +/* Destroy the data buffer DH and return a pointer to its content. + The memory has be to released with free by the user. It's size is + returned in R_LEN. */ +char *gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len); + +GpgmeError gpgme_data_new_from_cbs (GpgmeData *dh, + struct GpgmeDataCbs *cbs, + void *handle); + +GpgmeError gpgme_data_new_from_fd (GpgmeData *dh, int fd); + +GpgmeError gpgme_data_new_from_stream (GpgmeData *dh, FILE *stream); + +/* Return the encoding attribute of the data buffer DH */ +GpgmeDataEncoding gpgme_data_get_encoding (GpgmeData dh); + +/* Set the encoding attribute of data buffer DH to ENC */ +GpgmeError gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc); + + + /* Create a new data buffer which retrieves the data from the callback - function READ_CB. */ + function READ_CB. Deprecated, please use gpgme_data_new_from_cbs + instead. */ GpgmeError gpgme_data_new_with_read_cb (GpgmeData *r_dh, int (*read_cb) (void*,char *,size_t,size_t*), void *read_cb_value); /* Create a new data buffer filled with the content of file FNAME. - COPY must be non-zero (delayed reads are not supported yet). */ + COPY must be non-zero. For delayed read, please use + gpgme_data_new_from_fd or gpgme_data_new_from stream instead. */ GpgmeError gpgme_data_new_from_file (GpgmeData *r_dh, const char *fname, int copy); @@ -536,35 +604,10 @@ GpgmeError gpgme_data_new_from_filepart (GpgmeData *r_dh, const char *fname, FILE *fp, off_t offset, size_t length); -/* Destroy the data buffer DH. */ -void gpgme_data_release (GpgmeData dh); - -/* Destroy the data buffer DH and return a pointer to its content. - The memory has be to released with free by the user. It's size is - returned in R_LEN. */ -char *gpgme_data_release_and_get_mem (GpgmeData dh, size_t *r_len); - -/* Return the type of the data buffer DH. */ -GpgmeDataType gpgme_data_get_type (GpgmeData dh); - -/* Return the encoding attribute of the data buffer DH */ -GpgmeDataEncoding gpgme_data_get_encoding (GpgmeData dh); - -/* Set the encoding attribute of data buffer DH to ENC */ -GpgmeError gpgme_data_set_encoding (GpgmeData dh, GpgmeDataEncoding enc); - -/* Reset the read pointer in DH. */ +/* Reset the read pointer in DH. Deprecated, please use + gpgme_data_seek instead. */ GpgmeError gpgme_data_rewind (GpgmeData dh); -/* Read LENGTH bytes from the data object DH and store them in the - memory starting at BUFFER. The number of bytes actually read is - returned in NREAD. */ -GpgmeError gpgme_data_read (GpgmeData dh, void *buffer, - size_t length, size_t *nread); - -/* Write LENGTH bytes starting from BUFFER into the data object DH. */ -GpgmeError gpgme_data_write (GpgmeData dh, const void *buffer, size_t length); - /* Key and trust functions. */ @@ -654,10 +697,10 @@ GpgmeError gpgme_op_sign (GpgmeCtx ctx, GpgmeSigMode mode); /* Verify within CTX that SIG is a valid signature for TEXT. */ -GpgmeError gpgme_op_verify_start (GpgmeCtx ctx, - GpgmeData sig, GpgmeData text); -GpgmeError gpgme_op_verify (GpgmeCtx ctx, - GpgmeData sig, GpgmeData text, +GpgmeError gpgme_op_verify_start (GpgmeCtx ctx, GpgmeData sig, + GpgmeData signed_text, GpgmeData plaintext); +GpgmeError gpgme_op_verify (GpgmeCtx ctx, GpgmeData sig, + GpgmeData signed_text, GpgmeData plaintext, GpgmeSigStat *r_status); /* Import the key in KEYDATA into the keyring. */ @@ -729,9 +772,6 @@ GpgmeError gpgme_op_trustlist_end (GpgmeCtx ctx); /* Check that the library fulfills the version requirement. */ const char *gpgme_check_version (const char *req_version); -/* Check that the backend engine is available. DEPRECATED. */ -GpgmeError gpgme_check_engine (void); - /* Retrieve information about the backend engines. */ const char *gpgme_get_engine_info (void); diff --git a/trunk/gpgme/import.c b/trunk/gpgme/import.c index a550f86..35f0bbb 100644 --- a/trunk/gpgme/import.c +++ b/trunk/gpgme/import.c @@ -186,12 +186,11 @@ _gpgme_op_import_start (GpgmeCtx ctx, int synchronous, GpgmeData keydata) goto leave; /* Check the supplied data */ - if (gpgme_data_get_type (keydata) == GPGME_DATA_TYPE_NONE) + if (!keydata) { err = mk_error (No_Data); goto leave; } - _gpgme_data_set_mode (keydata, GPGME_DATA_MODE_OUT); _gpgme_engine_set_status_handler (ctx->engine, import_status_handler, ctx); _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); diff --git a/trunk/gpgme/ops.h b/trunk/gpgme/ops.h index 29cfb02..efef73f 100644 --- a/trunk/gpgme/ops.h +++ b/trunk/gpgme/ops.h @@ -57,10 +57,8 @@ GpgmeError _gpgme_wait_on_condition (GpgmeCtx ctx, volatile int *cond); int _gpgme_recipients_all_valid ( const GpgmeRecipients rset ); -/*-- data.c --*/ +/*-- data.c and conversion.c --*/ char * _gpgme_data_release_and_return_string ( GpgmeData dh ); -GpgmeDataMode _gpgme_data_get_mode ( GpgmeData dh ); -void _gpgme_data_set_mode ( GpgmeData dh, GpgmeDataMode mode ); char * _gpgme_data_get_as_string ( GpgmeData dh ); GpgmeError _gpgme_data_append ( GpgmeData dh, const char *buffer, size_t length ); diff --git a/trunk/gpgme/rungpg.c b/trunk/gpgme/rungpg.c index f67f68f..fb797ed 100644 --- a/trunk/gpgme/rungpg.c +++ b/trunk/gpgme/rungpg.c @@ -44,14 +44,16 @@ #include "status-table.h" -/* This type is used to build a list of gpg arguments and - * data sources/sinks */ -struct arg_and_data_s { - struct arg_and_data_s *next; - GpgmeData data; /* If this is not NULL .. */ - int dup_to; - int print_fd; /* print the fd number and not the special form of it */ - char arg[1]; /* .. this is used */ +/* This type is used to build a list of gpg arguments and data + sources/sinks. */ +struct arg_and_data_s +{ + struct arg_and_data_s *next; + GpgmeData data; /* If this is not NULL, use arg below. */ + int inbound; /* True if this is used for reading from gpg. */ + int dup_to; + int print_fd; /* Print the fd number and not the special form of it. */ + char arg[1]; /* Used if data above is not used. */ }; struct fd_data_map_s @@ -378,33 +380,37 @@ _gpgme_gpg_add_arg ( GpgObject gpg, const char *arg ) } GpgmeError -_gpgme_gpg_add_data ( GpgObject gpg, GpgmeData data, int dup_to ) +_gpgme_gpg_add_data (GpgObject gpg, GpgmeData data, int dup_to, int inbound) { - struct arg_and_data_s *a; + struct arg_and_data_s *a; - assert (gpg); - assert (data); - if (gpg->pm.active) - return 0; + assert (gpg); + assert (data); + if (gpg->pm.active) + return 0; - a = xtrymalloc ( sizeof *a - 1 ); - if ( !a ) { - gpg->arg_error = 1; - return mk_error(Out_Of_Core); + a = xtrymalloc (sizeof *a - 1); + if (!a) + { + gpg->arg_error = 1; + return mk_error(Out_Of_Core); } - a->next = NULL; - a->data = data; - if ( dup_to == -2 ) { - a->print_fd = 1; - a->dup_to = -1; + a->next = NULL; + a->data = data; + a->inbound = inbound; + if (dup_to == -2) + { + a->print_fd = 1; + a->dup_to = -1; } - else { - a->print_fd = 0; - a->dup_to = dup_to; + else + { + a->print_fd = 0; + a->dup_to = dup_to; } - *gpg->argtail = a; - gpg->argtail = &a->next; - return 0; + *gpg->argtail = a; + gpg->argtail = &a->next; + return 0; } GpgmeError @@ -435,7 +441,7 @@ _gpgme_gpg_add_pm_data ( GpgObject gpg, GpgmeData data, int what ) rc = gpgme_data_new_with_read_cb ( &tmp, pipemode_cb, gpg ); if (!rc ) - rc = _gpgme_gpg_add_data (gpg, tmp, 0); + rc = _gpgme_gpg_add_data (gpg, tmp, 0, 0); } if ( !rc ) { /* here we can reset the handler stuff */ @@ -532,8 +538,8 @@ _gpgme_gpg_set_command_handler (GpgObject gpg, if (err) return err; - _gpgme_gpg_add_arg ( gpg, "--command-fd" ); - _gpgme_gpg_add_data (gpg, tmp, -2); + _gpgme_gpg_add_arg (gpg, "--command-fd"); + _gpgme_gpg_add_data (gpg, tmp, -2, 0); gpg->cmd.cb_data = tmp; gpg->cmd.fnc = fnc; gpg->cmd.fnc_value = fnc_value; @@ -696,41 +702,9 @@ build_argv (GpgObject gpg) { if (a->data) { - switch (_gpgme_data_get_mode (a->data)) - { - case GPGME_DATA_MODE_NONE: - case GPGME_DATA_MODE_INOUT: - xfree (fd_data_map); - free_argv (argv); - return mk_error (Invalid_Mode); - case GPGME_DATA_MODE_IN: - /* Create a pipe to read from gpg. */ - fd_data_map[datac].inbound = 1; - break; - case GPGME_DATA_MODE_OUT: - /* Create a pipe to pass it down to gpg. */ - fd_data_map[datac].inbound = 0; - break; - } + /* Create a pipe to pass it down to gpg. */ + fd_data_map[datac].inbound = a->inbound; - switch (gpgme_data_get_type (a->data)) - { - case GPGME_DATA_TYPE_NONE: - if (fd_data_map[datac].inbound) - break; /* Allowed. */ - xfree (fd_data_map); - free_argv (argv); - return mk_error (Invalid_Type); - case GPGME_DATA_TYPE_MEM: - case GPGME_DATA_TYPE_CB: - break; - case GPGME_DATA_TYPE_FD: - case GPGME_DATA_TYPE_FILE: - xfree (fd_data_map); - free_argv (argv); - return mk_error (Not_Implemented); - } - /* Create a pipe. */ { int fds[2]; @@ -1256,29 +1230,30 @@ read_colon_line ( GpgObject gpg ) } static GpgmeError -pipemode_copy (char *buffer, size_t length, size_t *nread, GpgmeData data ) +pipemode_copy (char *buffer, size_t length, size_t *nread, GpgmeData data) { - GpgmeError err; - size_t nbytes; - char tmp[1000], *s, *d; - - /* we can optimize this whole thing but for now we just - * return after each escape character */ - if (length > 990) - length = 990; - - err = gpgme_data_read ( data, tmp, length, &nbytes ); - if (err) - return err; - for (s=tmp, d=buffer; nbytes; s++, nbytes--) { - *d++ = *s; - if (*s == '@' ) { - *d++ = '@'; - break; - } + size_t nbytes; + char tmp[1000], *src, *dst; + + /* We can optimize this whole thing but for now we just return after + each escape character. */ + if (length > 990) + length = 990; + + nbytes = gpgme_data_read (data, tmp, length); + if (nbytes < 0) + return mk_error (File_Error); + for (src = tmp, dst = buffer; nbytes; src++, nbytes--) + { + *dst++ = *src; + if (*src == '@') + { + *dst++ = '@'; + break; + } } - *nread = d - buffer; - return 0; + *nread = dst - buffer; + return 0; } @@ -1409,9 +1384,9 @@ _gpgme_gpg_op_decrypt (GpgObject gpg, GpgmeData ciph, GpgmeData plain) if (!err) err = _gpgme_gpg_add_arg (gpg, "-"); if (!err) - err = _gpgme_gpg_add_data (gpg, plain, 1); + err = _gpgme_gpg_add_data (gpg, plain, 1, 1); if (!err) - err = _gpgme_gpg_add_data (gpg, ciph, 0); + err = _gpgme_gpg_add_data (gpg, ciph, 0, 0); return err; } @@ -1477,7 +1452,7 @@ _gpgme_gpg_op_edit (GpgObject gpg, GpgmeKey key, GpgmeData out, if (!err) err = _gpgme_gpg_add_arg (gpg, "--edit-key"); if (!err) - err = _gpgme_gpg_add_data (gpg, out, 1); + err = _gpgme_gpg_add_data (gpg, out, 1, 1); if (!err) err = _gpgme_gpg_add_arg (gpg, "--"); if (!err) @@ -1542,11 +1517,11 @@ _gpgme_gpg_op_encrypt (GpgObject gpg, GpgmeRecipients recp, if (!err) err = _gpgme_gpg_add_arg (gpg, "-"); if (!err) - err = _gpgme_gpg_add_data (gpg, ciph, 1); + err = _gpgme_gpg_add_data (gpg, ciph, 1, 1); if (!err) err = _gpgme_gpg_add_arg (gpg, "--"); if (!err) - err = _gpgme_gpg_add_data (gpg, plain, 0); + err = _gpgme_gpg_add_data (gpg, plain, 0, 0); return err; } @@ -1581,11 +1556,11 @@ _gpgme_gpg_op_encrypt_sign (GpgObject gpg, GpgmeRecipients recp, if (!err) err = _gpgme_gpg_add_arg (gpg, "-"); if (!err) - err = _gpgme_gpg_add_data (gpg, ciph, 1); + err = _gpgme_gpg_add_data (gpg, ciph, 1, 1); if (!err) err = _gpgme_gpg_add_arg (gpg, "--"); if (!err) - err = _gpgme_gpg_add_data (gpg, plain, 0); + err = _gpgme_gpg_add_data (gpg, plain, 0, 0); return err; } @@ -1600,7 +1575,7 @@ _gpgme_gpg_op_export (GpgObject gpg, GpgmeRecipients recp, if (!err && use_armor) err = _gpgme_gpg_add_arg (gpg, "--armor"); if (!err) - err = _gpgme_gpg_add_data (gpg, keydata, 1); + err = _gpgme_gpg_add_data (gpg, keydata, 1, 1); if (!err) err = _gpgme_gpg_add_arg (gpg, "--"); @@ -1639,7 +1614,7 @@ _gpgme_gpg_op_genkey (GpgObject gpg, GpgmeData help_data, int use_armor, if (!err && use_armor) err = _gpgme_gpg_add_arg (gpg, "--armor"); if (!err) - err = _gpgme_gpg_add_data (gpg, help_data, 0); + err = _gpgme_gpg_add_data (gpg, help_data, 0, 0); return err; } @@ -1651,7 +1626,7 @@ _gpgme_gpg_op_import (GpgObject gpg, GpgmeData keydata) err = _gpgme_gpg_add_arg (gpg, "--import"); if (!err) - err = _gpgme_gpg_add_data (gpg, keydata, 0); + err = _gpgme_gpg_add_data (gpg, keydata, 0, 0); return err; } @@ -1741,9 +1716,9 @@ _gpgme_gpg_op_sign (GpgObject gpg, GpgmeData in, GpgmeData out, /* Tell the gpg object about the data. */ if (!err) - err = _gpgme_gpg_add_data (gpg, in, 0); + err = _gpgme_gpg_add_data (gpg, in, 0, 0); if (!err) - err = _gpgme_gpg_add_data (gpg, out, 1); + err = _gpgme_gpg_add_data (gpg, out, 1, 1); return err; } @@ -1767,11 +1742,11 @@ _gpgme_gpg_op_trustlist (GpgObject gpg, const char *pattern) } GpgmeError -_gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text) +_gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData signed_text, GpgmeData plaintext) { GpgmeError err = 0; - if (_gpgme_data_get_mode (text) == GPGME_DATA_MODE_IN) + if (plaintext) { /* Normal or cleartext signature. */ @@ -1781,9 +1756,9 @@ _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text) if (!err) err = _gpgme_gpg_add_arg (gpg, "--"); if (!err) - err = _gpgme_gpg_add_data (gpg, sig, 0); + err = _gpgme_gpg_add_data (gpg, sig, 0, 0); if (!err) - err = _gpgme_gpg_add_data (gpg, text, 1); + err = _gpgme_gpg_add_data (gpg, plaintext, 1, 1); } else { @@ -1795,7 +1770,7 @@ _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text) if (!err) err = _gpgme_gpg_add_pm_data (gpg, sig, 0); if (!err) - err = _gpgme_gpg_add_pm_data (gpg, text, 1); + err = _gpgme_gpg_add_pm_data (gpg, signed_text, 1); } else { @@ -1803,13 +1778,13 @@ _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text) if (!err) err = _gpgme_gpg_add_arg (gpg, "--"); if (!err) - err = _gpgme_gpg_add_data (gpg, sig, -1); - if (text) + err = _gpgme_gpg_add_data (gpg, sig, -1, 0); + if (signed_text) { if (!err) err = _gpgme_gpg_add_arg (gpg, "-"); if (!err) - err = _gpgme_gpg_add_data (gpg, text, 0); + err = _gpgme_gpg_add_data (gpg, signed_text, 0, 0); } } } diff --git a/trunk/gpgme/rungpg.h b/trunk/gpgme/rungpg.h index dcb6709..0ed0d2d 100644 --- a/trunk/gpgme/rungpg.h +++ b/trunk/gpgme/rungpg.h @@ -37,7 +37,7 @@ void _gpgme_gpg_release ( GpgObject gpg ); void _gpgme_gpg_housecleaning (void); void _gpgme_gpg_enable_pipemode ( GpgObject gpg ); GpgmeError _gpgme_gpg_add_arg ( GpgObject gpg, const char *arg ); -GpgmeError _gpgme_gpg_add_data ( GpgObject gpg, GpgmeData data, int dup_to ); +GpgmeError _gpgme_gpg_add_data (GpgObject gpg, GpgmeData data, int dup_to, int inbound); GpgmeError _gpgme_gpg_add_pm_data ( GpgObject gpg, GpgmeData data, int what ); void _gpgme_gpg_set_status_handler (GpgObject gpg, GpgStatusHandler fnc, @@ -79,7 +79,9 @@ GpgmeError _gpgme_gpg_op_sign (GpgObject gpg, GpgmeData in, GpgmeData out, GpgmeSigMode mode, int use_armor, int use_textmode, GpgmeCtx ctx /* FIXME */); GpgmeError _gpgme_gpg_op_trustlist (GpgObject gpg, const char *pattern); -GpgmeError _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, GpgmeData text); +GpgmeError _gpgme_gpg_op_verify (GpgObject gpg, GpgmeData sig, + GpgmeData signed_text, + GpgmeData plaintext); GpgmeError _gpgme_gpg_spawn (GpgObject gpg, void *opaque); void _gpgme_gpg_set_io_cbs (GpgObject gpg, struct GpgmeIOCbs *io_cbs); void _gpgme_gpg_io_event (GpgObject gpg, GpgmeEventIO type, void *type_data); diff --git a/trunk/gpgme/sign.c b/trunk/gpgme/sign.c index c077c55..c07354d 100644 --- a/trunk/gpgme/sign.c +++ b/trunk/gpgme/sign.c @@ -185,18 +185,16 @@ _gpgme_op_sign_start (GpgmeCtx ctx, int synchronous, goto leave; /* Check the supplied data. */ - if (gpgme_data_get_type (in) == GPGME_DATA_TYPE_NONE) + if (!in) { err = mk_error (No_Data); goto leave; } - _gpgme_data_set_mode (in, GPGME_DATA_MODE_OUT); - if (!out || gpgme_data_get_type (out) != GPGME_DATA_TYPE_NONE) + if (!out) { err = mk_error (Invalid_Value); goto leave; } - _gpgme_data_set_mode (out, GPGME_DATA_MODE_IN); err = _gpgme_passphrase_start (ctx); if (err) diff --git a/trunk/gpgme/types.h b/trunk/gpgme/types.h index 1fa4bbf..3059222 100644 --- a/trunk/gpgme/types.h +++ b/trunk/gpgme/types.h @@ -32,14 +32,6 @@ typedef unsigned long ulong; #endif -typedef enum { - GPGME_DATA_MODE_NONE = 0, - GPGME_DATA_MODE_IN = 1, - GPGME_DATA_MODE_OUT = 2, - GPGME_DATA_MODE_INOUT = 3 -} GpgmeDataMode; - - /* * Declaration of internal objects */ diff --git a/trunk/gpgme/verify.c b/trunk/gpgme/verify.c index a15a634..da23b7e 100644 --- a/trunk/gpgme/verify.c +++ b/trunk/gpgme/verify.c @@ -359,7 +359,7 @@ _gpgme_verify_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args) static GpgmeError _gpgme_op_verify_start (GpgmeCtx ctx, int synchronous, - GpgmeData sig, GpgmeData text) + GpgmeData sig, GpgmeData signed_text, GpgmeData plaintext) { int err = 0; int pipemode = 0; /* !!text; use pipemode for detached sigs. */ @@ -382,25 +382,17 @@ _gpgme_op_verify_start (GpgmeCtx ctx, int synchronous, _gpgme_engine_set_verbosity (ctx->engine, ctx->verbosity); /* Check the supplied data. */ - if (gpgme_data_get_type (sig) == GPGME_DATA_TYPE_NONE) + if (!sig) { err = mk_error (No_Data); goto leave; } - if (!text) + if (!signed_text && !plaintext) { err = mk_error (Invalid_Value); goto leave; } - _gpgme_data_set_mode (sig, GPGME_DATA_MODE_OUT); - if (gpgme_data_get_type (text) == GPGME_DATA_TYPE_NONE) - /* Normal or cleartext signature. */ - _gpgme_data_set_mode (text, GPGME_DATA_MODE_IN); - else - /* Detached signature. */ - _gpgme_data_set_mode (text, GPGME_DATA_MODE_OUT); - - err = _gpgme_engine_op_verify (ctx->engine, sig, text); + err = _gpgme_engine_op_verify (ctx->engine, sig, signed_text, plaintext); if (!err) /* And kick off the process. */ err = _gpgme_engine_start (ctx->engine, ctx); @@ -415,9 +407,10 @@ _gpgme_op_verify_start (GpgmeCtx ctx, int synchronous, } GpgmeError -gpgme_op_verify_start (GpgmeCtx ctx, GpgmeData sig, GpgmeData text) +gpgme_op_verify_start (GpgmeCtx ctx, GpgmeData sig, GpgmeData signed_text, + GpgmeData plaintext) { - return _gpgme_op_verify_start (ctx, 0, sig, text); + return _gpgme_op_verify_start (ctx, 0, sig, signed_text, plaintext); } /* @@ -469,8 +462,8 @@ _gpgme_intersect_stati (VerifyResult result) * the signature itself did go wrong. **/ GpgmeError -gpgme_op_verify (GpgmeCtx ctx, GpgmeData sig, GpgmeData text, - GpgmeSigStat *r_stat) +gpgme_op_verify (GpgmeCtx ctx, GpgmeData sig, GpgmeData signed_text, + GpgmeData plaintext, GpgmeSigStat *r_stat) { GpgmeError err; @@ -481,7 +474,7 @@ gpgme_op_verify (GpgmeCtx ctx, GpgmeData sig, GpgmeData text, ctx->notation = NULL; *r_stat = GPGME_SIG_STAT_NONE; - err = _gpgme_op_verify_start (ctx, 1, sig, text); + err = _gpgme_op_verify_start (ctx, 1, sig, signed_text, plaintext); if (!err) { err = _gpgme_wait_one (ctx); diff --git a/trunk/gpgme/version.c b/trunk/gpgme/version.c index 6fb0512..8e539dd 100644 --- a/trunk/gpgme/version.c +++ b/trunk/gpgme/version.c @@ -193,22 +193,6 @@ gpgme_get_engine_info () } -/** - * gpgme_check_engine: - * - * Check whether the installed crypto engine for the OpenPGP protocol - * matches the requirement of GPGME. This function is deprecated, - * instead use gpgme_engine_get_info() with the specific protocol you - * need. - * - * Return value: 0 or an error code. - **/ -GpgmeError -gpgme_check_engine () -{ - return gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); -} - #define LINELENGTH 80 diff --git a/trunk/tests/ChangeLog b/trunk/tests/ChangeLog index 770b4b5..3ef332a 100644 --- a/trunk/tests/ChangeLog +++ b/trunk/tests/ChangeLog @@ -1,3 +1,27 @@ +2002-10-09 Marcus Brinkmann + + * gpg/t-decrypt.c (print_data): Update to new gpgme_data_read + interface, and use gpgme_engine_check_version instead + gpgme_check_version. + * gpg/t-decrypt-verify.c (print_data): Likewise. + * gpg/t-edit.c (main): Likewise. + * gpg/t-encrypt.c (print_data): Likewise. + * gpg/t-encrypt-sign.c (print_data): Likewise. + * gpg/t-encrypt-sym.c (print_data): Likewise. + * gpg/t-eventloop.c (print_data): Likewise. + * gpg/t-export.c (print_data): Likewise. + * gpg/t-sign.c (print_data): Likewise. + * gpg/t-signers.c (print_data): Likewise. + * gpgsm/t-decrypt.c (print_data): Likewise. + * gpgsm/t-encrypt.c (print_data): Likewise. + * gpgsm/t-export.c (print_data): Likewise. + * gpgsm/t-sign.c (print_data): Likewise. + * gpg/t-verify.c (main): Likewise for gpgme_op_verify. + * gpgsm/t-verify.c (main): Likewise for gpgme_op_verify. + * t-data.c (read_once_test): Likewise. + (write_test): Update for new behaviour of data objects. + (main): Remove type test. + 2002-09-30 Werner Koch * gpgsm/t-keylist.c (doit): Add arg SECRET. diff --git a/trunk/tests/gpg/t-decrypt-verify.c b/trunk/tests/gpg/t-decrypt-verify.c index 0c85d1b..276f7e6 100644 --- a/trunk/tests/gpg/t-decrypt-verify.c +++ b/trunk/tests/gpg/t-decrypt-verify.c @@ -42,21 +42,23 @@ struct passphrase_cb_info_s exit (1); } \ } while(0) + static void print_data (GpgmeData dh) { char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind (dh); - fail_if_err (err); - while (!(err = gpgme_data_read (dh, buf, 100, &nread))) - fwrite ( buf, nread, 1, stdout ); - if (err != GPGME_EOF) - fail_if_err (err); + 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 const char * passphrase_cb (void *opaque, const char *desc, void **r_hd) { diff --git a/trunk/tests/gpg/t-decrypt.c b/trunk/tests/gpg/t-decrypt.c index 6b21d41..0eda6ac 100644 --- a/trunk/tests/gpg/t-decrypt.c +++ b/trunk/tests/gpg/t-decrypt.c @@ -42,19 +42,33 @@ struct passphrase_cb_info_s { } while(0) static void -print_data ( GpgmeData dh ) +print_op_info (GpgmeCtx ctx) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); + char *str = gpgme_get_op_info (ctx, 0); + + if (!str) + puts (""); + else + { + puts (str); + free (str); } - if (err != GPGME_EOF) - fail_if_err (err); +} + + +static void +print_data (GpgmeData 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); } diff --git a/trunk/tests/gpg/t-edit.c b/trunk/tests/gpg/t-edit.c index 4a22955..8117d58 100644 --- a/trunk/tests/gpg/t-edit.c +++ b/trunk/tests/gpg/t-edit.c @@ -45,13 +45,15 @@ static void flush_data (GpgmeData dh) { char buf[100]; - size_t nread; - GpgmeError err; - - while (!(err = gpgme_data_read (dh, buf, 100, &nread))) - fwrite (buf, nread, 1, stdout); - if (err != GPGME_EOF) - fail_if_err (err); + 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); } diff --git a/trunk/tests/gpg/t-encrypt-sign.c b/trunk/tests/gpg/t-encrypt-sign.c index b92d74c..1517db0 100644 --- a/trunk/tests/gpg/t-encrypt-sign.c +++ b/trunk/tests/gpg/t-encrypt-sign.c @@ -33,33 +33,33 @@ } while(0) static void -print_op_info (GpgmeCtx c) +print_op_info (GpgmeCtx ctx) { - char *s = gpgme_get_op_info (c, 0); - - if (!s) - puts (""); - else { - puts (s); - free (s); + char *str = gpgme_get_op_info (ctx, 0); + + if (!str) + puts (""); + else + { + puts (str); + free (str); } } static void -print_data ( GpgmeData dh ) +print_data (GpgmeData dh) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); - } - if (err != GPGME_EOF) - fail_if_err (err); + 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); } @@ -92,7 +92,7 @@ main (int argc, char **argv ) GpgmeRecipients rset; char *p; - err = gpgme_check_engine (); + err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); fail_if_err (err); puts ( gpgme_get_engine_info() ); diff --git a/trunk/tests/gpg/t-encrypt-sym.c b/trunk/tests/gpg/t-encrypt-sym.c index 441f747..db3f3e9 100644 --- a/trunk/tests/gpg/t-encrypt-sym.c +++ b/trunk/tests/gpg/t-encrypt-sym.c @@ -36,15 +36,15 @@ static void print_data (GpgmeData dh) { char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind (dh); - fail_if_err (err); - while (!(err = gpgme_data_read (dh, buf, 100, &nread))) - fwrite ( buf, nread, 1, stdout ); - if (err != GPGME_EOF) - fail_if_err (err); + 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); } @@ -79,7 +79,7 @@ main (int argc, char **argv) char *p; size_t len; - err = gpgme_check_engine (); + err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); fail_if_err (err); do diff --git a/trunk/tests/gpg/t-encrypt.c b/trunk/tests/gpg/t-encrypt.c index 06736b3..14a407d 100644 --- a/trunk/tests/gpg/t-encrypt.c +++ b/trunk/tests/gpg/t-encrypt.c @@ -35,44 +35,44 @@ static void print_op_info (GpgmeCtx c) { - char *s = gpgme_get_op_info (c, 0); - - if (!s) - puts (""); - else { - puts (s); - free (s); + char *s = gpgme_get_op_info (c, 0); + + if (!s) + puts (""); + else + { + puts (s); + free (s); } } static void -print_data ( GpgmeData dh ) +print_data (GpgmeData dh) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); - } - if (err != GPGME_EOF) - fail_if_err (err); + char buf[100]; + int ret; + + ret = gpgme_data_seek (dh, 0, SEEK_SET); + if (ret) + fail_if_err (GPGME_File_Error); + while ((ret = gpgme_data_read (dh, buf, 100)) > 0) + fwrite (buf, ret, 1, stdout); + if (ret < 0) + fail_if_err (GPGME_File_Error); } int -main (int argc, char **argv ) +main (int argc, char **argv) { GpgmeCtx ctx; GpgmeError err; GpgmeData in, out; GpgmeRecipients rset; - err = gpgme_check_engine (); + err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); fail_if_err (err); puts ( gpgme_get_engine_info() ); diff --git a/trunk/tests/gpg/t-eventloop.c b/trunk/tests/gpg/t-eventloop.c index 634911a..887de64 100644 --- a/trunk/tests/gpg/t-eventloop.c +++ b/trunk/tests/gpg/t-eventloop.c @@ -37,14 +37,14 @@ static void print_op_info (GpgmeCtx ctx) { - char *s = gpgme_get_op_info (ctx, 0); + char *str = gpgme_get_op_info (ctx, 0); - if (!s) + if (!str) puts (""); else { - puts (s); - free (s); + puts (str); + free (str); } } @@ -53,15 +53,15 @@ static void print_data (GpgmeData dh) { char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind (dh); - fail_if_err (err); - while (!(err = gpgme_data_read (dh, buf, 100, &nread))) - fwrite (buf, nread, 1, stdout); - if (err != GPGME_EOF) - fail_if_err (err); + 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); } @@ -203,7 +203,7 @@ main (int argc, char *argv[]) for (i = 0; i < FDLIST_MAX; i++) fdlist[i].fd = -1; - err = gpgme_check_engine (); + err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); fail_if_err (err); puts (gpgme_get_engine_info ()); diff --git a/trunk/tests/gpg/t-export.c b/trunk/tests/gpg/t-export.c index 373e9f5..dbcdd88 100644 --- a/trunk/tests/gpg/t-export.c +++ b/trunk/tests/gpg/t-export.c @@ -32,24 +32,22 @@ exit (1); } \ } while(0) + static void -print_data ( GpgmeData dh ) +print_data (GpgmeData dh) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); - } - if (err != GPGME_EOF) - fail_if_err (err); + char buf[100]; + int ret; + + ret = gpgme_data_seek (dh, 0, SEEK_SET); + if (ret) + fail_if_err (GPGME_File_Error); + while ((ret = gpgme_data_read (dh, buf, 100)) > 0) + fwrite (buf, ret, 1, stdout); + if (ret < 0) + fail_if_err (GPGME_File_Error); } - - int main (int argc, char **argv ) { diff --git a/trunk/tests/gpg/t-keylist.c b/trunk/tests/gpg/t-keylist.c index d77cd70..24edef5 100644 --- a/trunk/tests/gpg/t-keylist.c +++ b/trunk/tests/gpg/t-keylist.c @@ -149,7 +149,7 @@ main (int argc, char **argv) } pattern = argc? *argv : NULL; - err = gpgme_check_engine(); + err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); fail_if_err (err); err = gpgme_new (&ctx); diff --git a/trunk/tests/gpg/t-sign.c b/trunk/tests/gpg/t-sign.c index 0e5f5c3..9caaf69 100644 --- a/trunk/tests/gpg/t-sign.c +++ b/trunk/tests/gpg/t-sign.c @@ -33,34 +33,36 @@ } while(0) static void -print_op_info (GpgmeCtx c) +print_op_info (GpgmeCtx ctx) { - char *s = gpgme_get_op_info (c, 0); - - if (!s) - puts (""); - else { - puts (s); - free (s); + char *str = gpgme_get_op_info (ctx, 0); + + if (!str) + puts (""); + else + { + puts (str); + free (str); } } + static void -print_data ( GpgmeData dh ) +print_data (GpgmeData dh) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); - } - if (err != GPGME_EOF) - fail_if_err (err); + 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 const char * passphrase_cb ( void *opaque, const char *desc, void **r_hd ) { diff --git a/trunk/tests/gpg/t-signers.c b/trunk/tests/gpg/t-signers.c index d0aa00b..2e8d3f4 100644 --- a/trunk/tests/gpg/t-signers.c +++ b/trunk/tests/gpg/t-signers.c @@ -33,34 +33,36 @@ } while(0) static void -print_op_info (GpgmeCtx c) +print_op_info (GpgmeCtx ctx) { - char *s = gpgme_get_op_info (c, 0); + char *str = gpgme_get_op_info (ctx, 0); - if (!s) + if (!str) puts (""); else { - puts (s); - free (s); + puts (str); + free (str); } } + static void print_data (GpgmeData dh) { char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind (dh); - fail_if_err (err); - while (!(err = gpgme_data_read (dh, buf, 100, &nread))) - fwrite (buf, nread, 1, stdout); - if (err != GPGME_EOF) - fail_if_err (err); + 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 const char * passphrase_cb (void *opaque, const char *desc, void **r_hd) { diff --git a/trunk/tests/gpg/t-verify.c b/trunk/tests/gpg/t-verify.c index 13eca93..f12b606 100644 --- a/trunk/tests/gpg/t-verify.c +++ b/trunk/tests/gpg/t-verify.c @@ -188,25 +188,25 @@ main (int argc, char **argv ) fail_if_err (err); puts ("checking a valid message:\n"); - err = gpgme_op_verify (ctx, sig, text, &status ); + err = gpgme_op_verify (ctx, sig, text, NULL, &status); fail_if_err (err); - print_sig_stat ( ctx, status ); + print_sig_stat (ctx, status); if (status != GPGME_SIG_STAT_GOOD) { fprintf (stderr, "%s:%d: Wrong sig stat\n", __FILE__, __LINE__); exit (1); } - if ( (nota=gpgme_get_notation (ctx)) ) + if ((nota = gpgme_get_notation (ctx))) printf ("---Begin Notation---\n%s---End Notation---\n", nota ); puts ("checking a manipulated message:\n"); gpgme_data_release (text); - err = gpgme_data_new_from_mem ( &text, - test_text1f, strlen (test_text1f), 0 ); + err = gpgme_data_new_from_mem (&text, + test_text1f, strlen (test_text1f), 0); fail_if_err (err); - gpgme_data_rewind ( sig ); - err = gpgme_op_verify (ctx, sig, text, &status ); + gpgme_data_rewind (sig); + err = gpgme_op_verify (ctx, sig, text, NULL, &status); fail_if_err (err); print_sig_stat (ctx, status); @@ -215,17 +215,17 @@ main (int argc, char **argv ) fprintf (stderr, "%s:%d: Wrong sig stat\n", __FILE__, __LINE__); exit (1); } - if ( (nota=gpgme_get_notation (ctx)) ) + if ((nota = gpgme_get_notation (ctx))) printf ("---Begin Notation---\n%s---End Notation---\n", nota ); puts ("checking a normal signature:"); gpgme_data_release (sig); gpgme_data_release (text); - err = gpgme_data_new_from_mem (&sig, test_sig2, strlen (test_sig2), 0); + err = gpgme_data_new_from_mem (&sig, test_sig2, strlen (test_sig2), 0); fail_if_err (err); err = gpgme_data_new (&text); fail_if_err (err); - err = gpgme_op_verify (ctx, sig, text, &status); + err = gpgme_op_verify (ctx, sig, NULL, text, &status); fail_if_err (err); nota = gpgme_data_release_and_get_mem (text, &len); diff --git a/trunk/tests/gpgsm/t-decrypt.c b/trunk/tests/gpgsm/t-decrypt.c index 212fcf8..7b8e186 100644 --- a/trunk/tests/gpgsm/t-decrypt.c +++ b/trunk/tests/gpgsm/t-decrypt.c @@ -49,21 +49,21 @@ static const char test_cip1[] = } while(0) static void -print_data ( GpgmeData dh ) +print_data (GpgmeData dh) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); - } - if (err != GPGME_EOF) - fail_if_err (err); + char buf[100]; + int ret; + + ret = gpgme_data_seek (dh, 0, SEEK_SET); + if (ret) + fail_if_err (GPGME_File_Error); + while ((ret = gpgme_data_read (dh, buf, 100)) > 0) + fwrite (buf, ret, 1, stdout); + if (ret < 0) + fail_if_err (GPGME_File_Error); } + int main (int argc, char **argv ) { diff --git a/trunk/tests/gpgsm/t-encrypt.c b/trunk/tests/gpgsm/t-encrypt.c index 9a7358c..5409624 100644 --- a/trunk/tests/gpgsm/t-encrypt.c +++ b/trunk/tests/gpgsm/t-encrypt.c @@ -33,37 +33,36 @@ } while(0) static void -print_op_info (GpgmeCtx c) +print_op_info (GpgmeCtx ctx) { - char *s = gpgme_get_op_info (c, 0); - - if (!s) - puts (""); - else { - puts (s); - free (s); + char *str = gpgme_get_op_info (ctx, 0); + + if (!str) + puts (""); + else + { + puts (str); + free (str); } } static void -print_data ( GpgmeData dh ) +print_data (GpgmeData dh) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); - } - if (err != GPGME_EOF) - fail_if_err (err); + char buf[100]; + int ret; + + ret = gpgme_data_seek (dh, 0, SEEK_SET); + if (ret) + fail_if_err (GPGME_File_Error); + while ((ret = gpgme_data_read (dh, buf, 100)) > 0) + fwrite (buf, ret, 1, stdout); + if (ret < 0) + fail_if_err (GPGME_File_Error); } - int main (int argc, char **argv ) { diff --git a/trunk/tests/gpgsm/t-export.c b/trunk/tests/gpgsm/t-export.c index a5f9e73..dd2ac54 100644 --- a/trunk/tests/gpgsm/t-export.c +++ b/trunk/tests/gpgsm/t-export.c @@ -33,23 +33,21 @@ } while(0) static void -print_data ( GpgmeData dh ) +print_data (GpgmeData dh) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); - } - if (err != GPGME_EOF) - fail_if_err (err); + char buf[100]; + int ret; + + ret = gpgme_data_seek (dh, 0, SEEK_SET); + if (ret) + fail_if_err (GPGME_File_Error); + while ((ret = gpgme_data_read (dh, buf, 100)) > 0) + fwrite (buf, ret, 1, stdout); + if (ret < 0) + fail_if_err (GPGME_File_Error); } - int main (int argc, char **argv ) { diff --git a/trunk/tests/gpgsm/t-sign.c b/trunk/tests/gpgsm/t-sign.c index 5d54475..b4c8332 100644 --- a/trunk/tests/gpgsm/t-sign.c +++ b/trunk/tests/gpgsm/t-sign.c @@ -33,36 +33,38 @@ } while(0) static void -print_op_info (GpgmeCtx c) +print_op_info (GpgmeCtx ctx) { - char *s = gpgme_get_op_info (c, 0); + char *str = gpgme_get_op_info (ctx, 0); - if (!s) - puts (""); - else { - puts (s); - free (s); + if (!str) + puts (""); + else + { + puts (str); + free (str); } } + static void -print_data ( GpgmeData dh ) +print_data (GpgmeData dh) { - char buf[100]; - size_t nread; - GpgmeError err; - - err = gpgme_data_rewind ( dh ); - fail_if_err (err); - while ( !(err = gpgme_data_read ( dh, buf, 100, &nread )) ) { - fwrite ( buf, nread, 1, stdout ); - } - if (err != GPGME_EOF) - fail_if_err (err); + char buf[100]; + int ret; + + ret = gpgme_data_seek (dh, 0, SEEK_SET); + if (ret) + fail_if_err (GPGME_File_Error); + while ((ret = gpgme_data_read (dh, buf, 100)) > 0) + fwrite (buf, ret, 1, stdout); + if (ret < 0) + fail_if_err (GPGME_File_Error); } + int -main (int argc, char **argv ) +main (int argc, char **argv) { GpgmeCtx ctx; GpgmeError err; diff --git a/trunk/tests/gpgsm/t-verify.c b/trunk/tests/gpgsm/t-verify.c index f65a83b..715b347 100644 --- a/trunk/tests/gpgsm/t-verify.c +++ b/trunk/tests/gpgsm/t-verify.c @@ -186,33 +186,33 @@ main (int argc, char **argv ) fail_if_err (err); puts ("checking a valid message:\n"); - err = gpgme_op_verify (ctx, sig, text, &status ); - print_sig_stat ( ctx, status ); - print_sig_stat ( ctx, status ); - print_sig_stat ( ctx, status ); - print_sig_stat ( ctx, status ); + err = gpgme_op_verify (ctx, sig, text, NULL, &status); + print_sig_stat (ctx, status); + print_sig_stat (ctx, status); + print_sig_stat (ctx, status); + print_sig_stat (ctx, status); fail_if_err (err); if ( (nota=gpgme_get_notation (ctx)) ) - printf ("---Begin Notation---\n%s---End Notation---\n", nota ); + printf ("---Begin Notation---\n%s---End Notation---\n", nota); puts ("checking a manipulated message:\n"); gpgme_data_release (text); err = gpgme_data_new_from_mem ( &text, - test_text1f, strlen (test_text1f), 0 ); + test_text1f, strlen (test_text1f), 0); fail_if_err (err); gpgme_data_rewind ( sig ); - err = gpgme_op_verify (ctx, sig, text, &status ); + err = gpgme_op_verify (ctx, sig, text, NULL, &status); - print_sig_stat ( ctx, status ); + print_sig_stat (ctx, status); fail_if_err (err); - if ( (nota=gpgme_get_notation (ctx)) ) - printf ("---Begin Notation---\n%s---End Notation---\n", nota ); + if ((nota=gpgme_get_notation (ctx))) + printf ("---Begin Notation---\n%s---End Notation---\n", nota); gpgme_data_release (sig); gpgme_data_release (text); - -} while ( argc > 1 && !strcmp( argv[1], "--loop" ) && ++n < 20 ); + + } while ( argc > 1 && !strcmp( argv[1], "--loop" ) && ++n < 20 ); gpgme_release (ctx); return 0; diff --git a/trunk/tests/t-data.c b/trunk/tests/t-data.c index f3c769f..3135dbd 100644 --- a/trunk/tests/t-data.c +++ b/trunk/tests/t-data.c @@ -106,12 +106,10 @@ read_cb (void *cb_value, char *buffer, size_t count, size_t *nread) void read_once_test (round_t round, GpgmeData data) { - GpgmeError err; char buffer[1024]; size_t read; - err = gpgme_data_read (data, buffer, sizeof (buffer), &read); - fail_if_err (err); + read = gpgme_data_read (data, buffer, sizeof (buffer)); if (read != strlen (text) || strncmp (buffer, text, strlen (text))) { @@ -120,8 +118,8 @@ read_once_test (round_t round, GpgmeData data) exit (1); } - err = gpgme_data_read (data, buffer, sizeof (buffer), &read); - if (err != GPGME_EOF) + read = gpgme_data_read (data, buffer, sizeof (buffer)); + if (read) { fprintf (stderr, "%s:%d: (%i) gpgme_data_read did not signal EOF\n", __FILE__, __LINE__, round); @@ -138,8 +136,8 @@ read_test (round_t round, GpgmeData data) if (round == TEST_INOUT_NONE) { - err = gpgme_data_read (data, buffer, sizeof (buffer), &read); - if (!err) + read = gpgme_data_read (data, buffer, sizeof (buffer)); + if (read > 0) { fprintf (stderr, "%s:%d: (%i) gpgme_data_read succeded unexpectedly\n", __FILE__, __LINE__, round); @@ -159,12 +157,12 @@ write_test (round_t round, GpgmeData data) { GpgmeError err; char buffer[1024]; - size_t read; + size_t amt; - err = gpgme_data_write (data, text, strlen (text)); - fail_if_err (err); + amt = gpgme_data_write (data, text, strlen (text)); + if (amt != strlen (text)) + fail_if_err (GPGME_File_Error); - read_once_test (round, data); err = gpgme_data_rewind (data); fail_if_err (err); @@ -172,18 +170,17 @@ write_test (round_t round, GpgmeData data) read_once_test (round, data); else { - err = gpgme_data_read (data, buffer, sizeof (buffer), &read); - fail_if_err (err); + amt = gpgme_data_read (data, buffer, sizeof (buffer)); - if (read != strlen (text2) || strncmp (buffer, text2, strlen (text2))) + if (amt != strlen (text2) || strncmp (buffer, text2, strlen (text2))) { fprintf (stderr, "%s:%d: (%i) gpgme_data_read returned wrong data\n", __FILE__, __LINE__, round); exit (1); } - err = gpgme_data_read (data, buffer, sizeof (buffer), &read); - if (err != GPGME_EOF) + amt = gpgme_data_read (data, buffer, sizeof (buffer)); + if (amt) { fprintf (stderr, "%s:%d: (%i) gpgme_data_read did not signal EOF\n", __FILE__, __LINE__, round); @@ -193,7 +190,7 @@ write_test (round_t round, GpgmeData data) } int -main (int argc, char **argv ) +main (int argc, char **argv) { round_t round = TEST_INITIALIZER; const char *text_filename = make_filename ("t-data-1.txt"); @@ -214,12 +211,6 @@ main (int argc, char **argv ) "unexpectedly\n", __FILE__, __LINE__); exit (1); } - if (gpgme_data_get_type (NULL) != GPGME_DATA_TYPE_NONE) - { - fprintf (stderr, "%s:%d: gpgme_data_get_type on NULL incorrect\n", - __FILE__, __LINE__); - exit (1); - } continue; case TEST_INOUT_NONE: err = gpgme_data_new (&data); @@ -245,7 +236,7 @@ main (int argc, char **argv ) case TEST_INOUT_MEM_FROM_FILE_NO_COPY: err = gpgme_data_new_from_file (&data, text_filename, 0); /* This is not implemented yet. */ - if (err == GPGME_Not_Implemented) + if (err == GPGME_Not_Implemented || err == GPGME_Invalid_Value) continue; break; case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME: @@ -287,34 +278,6 @@ main (int argc, char **argv ) } fail_if_err (err); - switch (round) - { - case TEST_INOUT_NONE: - if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_NONE) - err = GPGME_Invalid_Type; - break; - case TEST_INOUT_MEM_NO_COPY: - case TEST_INOUT_MEM_COPY: - case TEST_INOUT_MEM_FROM_FILE_COPY: - case TEST_INOUT_MEM_FROM_FILE_NO_COPY: - case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME: - case TEST_INOUT_MEM_FROM_FILE_PART_BY_FP: - if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_MEM) - err = GPGME_Invalid_Type; - break; - case TEST_OUT_CB: - if (gpgme_data_get_type (data) != GPGME_DATA_TYPE_CB) - err = GPGME_Invalid_Type; - break; - case TEST_INITIALIZER: - case TEST_INVALID_ARGUMENT: - case TEST_INOUT_MEM_FROM_INEXISTANT_FILE: - case TEST_INOUT_MEM_FROM_INEXISTANT_FILE_PART: - case TEST_END: - /* Shouldn't happen. */ - fprintf (stderr, "%s:%d: impossible condition\n", __FILE__, __LINE__); - exit (1); - } read_test (round, data); if (round != TEST_OUT_CB) write_test (round, data);