Add public function gpgme_io_writen.

* src/gpgme.c (gpgme_io_read): New.
--

This is a writen style variant for gpgme_io_write.  It is often easier
to use this one in passphrase and edit callbacks.
This commit is contained in:
Werner Koch 2013-02-07 20:51:29 +01:00
parent 51fd6d8292
commit 29eced5068
5 changed files with 158 additions and 129 deletions

View File

@ -2374,9 +2374,10 @@ previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
will be 0. will be 0.
The user must write the passphrase, followed by a newline character, The user must write the passphrase, followed by a newline character,
to the file descriptor @var{fd}. If the user returns 0 indicating to the file descriptor @var{fd}. The function @code{gpgme_io_writen}
success, the user must at least write a newline character before should be used for the write operation. Note that if the user returns
returning from the callback. 0 to indicate success, the user must at least write a newline
character before returning from the callback.
If an error occurs, return the corresponding @code{gpgme_error_t} If an error occurs, return the corresponding @code{gpgme_error_t}
value. You can use the error code @code{GPG_ERR_CANCELED} to abort value. You can use the error code @code{GPG_ERR_CANCELED} to abort

View File

@ -634,6 +634,30 @@ gpgme_io_write (int fd, const void *buffer, size_t count)
return TRACE_SYSRES (ret); return TRACE_SYSRES (ret);
} }
/* This function provides access to the internal write function. It
is to be used by user callbacks to return data to gpgme. See
gpgme_passphrase_cb_t and gpgme_edit_cb_t. Note that this is a
variant of gpgme_io_write which guarantees that all COUNT bytes are
written or an error is return. Returns: 0 on success or -1 on
error and the sets errno. */
int
gpgme_io_writen (int fd, const void *buffer, size_t count)
{
int ret = 0;
TRACE_BEG2 (DEBUG_GLOBAL, "gpgme_io_writen", fd,
"buffer=%p, count=%u", buffer, count);
while (count)
{
ret = _gpgme_io_write (fd, buffer, count);
if (ret < 0)
break;
buffer += ret;
count -= ret;
ret = 0;
}
return TRACE_SYSRES (ret);
}
/* This function returns the callback function for I/O. */ /* This function returns the callback function for I/O. */
void void

View File

@ -20,128 +20,128 @@
EXPORTS EXPORTS
gpgme_check_version @1 gpgme_check_version @1
gpgme_get_engine_info @2 gpgme_get_engine_info @2
gpgme_engine_check_version @3 gpgme_engine_check_version @3
gpgme_err_code_from_errno @4 gpgme_err_code_from_errno @4
gpgme_err_code_to_errno @5 gpgme_err_code_to_errno @5
gpgme_err_make_from_errno @6 gpgme_err_make_from_errno @6
gpgme_error_from_errno @7 gpgme_error_from_errno @7
gpgme_strerror @8 gpgme_strerror @8
gpgme_strerror_r @9 gpgme_strerror_r @9
gpgme_strsource @10 gpgme_strsource @10
gpgme_data_get_encoding @11 gpgme_data_get_encoding @11
gpgme_data_new @12 gpgme_data_new @12
gpgme_data_new_from_cbs @13 gpgme_data_new_from_cbs @13
gpgme_data_new_from_fd @14 gpgme_data_new_from_fd @14
gpgme_data_new_from_file @15 gpgme_data_new_from_file @15
gpgme_data_new_from_filepart @16 gpgme_data_new_from_filepart @16
gpgme_data_new_from_mem @17 gpgme_data_new_from_mem @17
gpgme_data_new_from_stream @18 gpgme_data_new_from_stream @18
gpgme_data_read @19 gpgme_data_read @19
gpgme_data_release @20 gpgme_data_release @20
gpgme_data_release_and_get_mem @21 gpgme_data_release_and_get_mem @21
gpgme_data_seek @22 gpgme_data_seek @22
gpgme_data_set_encoding @23 gpgme_data_set_encoding @23
gpgme_data_write @24 gpgme_data_write @24
gpgme_get_protocol_name @25 gpgme_get_protocol_name @25
gpgme_hash_algo_name @26 gpgme_hash_algo_name @26
gpgme_pubkey_algo_name @27 gpgme_pubkey_algo_name @27
gpgme_new @28 gpgme_new @28
gpgme_get_armor @29 gpgme_get_armor @29
gpgme_get_include_certs @30 gpgme_get_include_certs @30
gpgme_get_io_cbs @31 gpgme_get_io_cbs @31
gpgme_get_keylist_mode @32 gpgme_get_keylist_mode @32
gpgme_get_passphrase_cb @33 gpgme_get_passphrase_cb @33
gpgme_get_progress_cb @34 gpgme_get_progress_cb @34
gpgme_get_protocol @35 gpgme_get_protocol @35
gpgme_get_textmode @36 gpgme_get_textmode @36
gpgme_release @37 gpgme_release @37
gpgme_set_armor @38 gpgme_set_armor @38
gpgme_set_include_certs @39 gpgme_set_include_certs @39
gpgme_set_io_cbs @40 gpgme_set_io_cbs @40
gpgme_set_keylist_mode @41 gpgme_set_keylist_mode @41
gpgme_set_locale @42 gpgme_set_locale @42
gpgme_set_passphrase_cb @43 gpgme_set_passphrase_cb @43
gpgme_set_progress_cb @44 gpgme_set_progress_cb @44
gpgme_set_protocol @45 gpgme_set_protocol @45
gpgme_set_textmode @46 gpgme_set_textmode @46
gpgme_signers_add @47 gpgme_signers_add @47
gpgme_signers_clear @48 gpgme_signers_clear @48
gpgme_signers_enum @49 gpgme_signers_enum @49
gpgme_key_ref @50 gpgme_key_ref @50
gpgme_key_unref @51 gpgme_key_unref @51
gpgme_key_release @52 gpgme_key_release @52
gpgme_trust_item_ref @53 gpgme_trust_item_ref @53
gpgme_trust_item_unref @54 gpgme_trust_item_unref @54
gpgme_cancel @55 gpgme_cancel @55
gpgme_op_card_edit @56 gpgme_op_card_edit @56
gpgme_op_card_edit_start @57 gpgme_op_card_edit_start @57
gpgme_op_decrypt @58 gpgme_op_decrypt @58
gpgme_op_decrypt_result @59 gpgme_op_decrypt_result @59
gpgme_op_decrypt_start @60 gpgme_op_decrypt_start @60
gpgme_op_decrypt_verify @61 gpgme_op_decrypt_verify @61
gpgme_op_decrypt_verify_start @62 gpgme_op_decrypt_verify_start @62
gpgme_op_delete @63 gpgme_op_delete @63
gpgme_op_delete_start @64 gpgme_op_delete_start @64
gpgme_op_edit @65 gpgme_op_edit @65
gpgme_op_edit_start @66 gpgme_op_edit_start @66
gpgme_op_encrypt @67 gpgme_op_encrypt @67
gpgme_op_encrypt_result @68 gpgme_op_encrypt_result @68
gpgme_op_encrypt_sign @69 gpgme_op_encrypt_sign @69
gpgme_op_encrypt_sign_start @70 gpgme_op_encrypt_sign_start @70
gpgme_op_encrypt_start @71 gpgme_op_encrypt_start @71
gpgme_op_export @72 gpgme_op_export @72
gpgme_op_export_ext @73 gpgme_op_export_ext @73
gpgme_op_export_ext_start @74 gpgme_op_export_ext_start @74
gpgme_op_export_start @75 gpgme_op_export_start @75
gpgme_op_genkey @76 gpgme_op_genkey @76
gpgme_op_genkey_result @77 gpgme_op_genkey_result @77
gpgme_op_genkey_start @78 gpgme_op_genkey_start @78
gpgme_get_key @79 gpgme_get_key @79
gpgme_op_import @80 gpgme_op_import @80
gpgme_op_import_result @81 gpgme_op_import_result @81
gpgme_op_import_start @82 gpgme_op_import_start @82
gpgme_op_keylist_end @83 gpgme_op_keylist_end @83
gpgme_op_keylist_ext_start @84 gpgme_op_keylist_ext_start @84
gpgme_op_keylist_next @85 gpgme_op_keylist_next @85
gpgme_op_keylist_result @86 gpgme_op_keylist_result @86
gpgme_op_keylist_start @87 gpgme_op_keylist_start @87
gpgme_op_sign @88 gpgme_op_sign @88
gpgme_op_sign_result @89 gpgme_op_sign_result @89
gpgme_op_sign_start @90 gpgme_op_sign_start @90
gpgme_op_trustlist_end @91 gpgme_op_trustlist_end @91
gpgme_op_trustlist_next @92 gpgme_op_trustlist_next @92
gpgme_op_trustlist_start @93 gpgme_op_trustlist_start @93
gpgme_op_verify @94 gpgme_op_verify @94
gpgme_op_verify_result @95 gpgme_op_verify_result @95
gpgme_op_verify_start @96 gpgme_op_verify_start @96
gpgme_wait @97 gpgme_wait @97
gpgme_data_new_with_read_cb @98 gpgme_data_new_with_read_cb @98
gpgme_data_rewind @99 gpgme_data_rewind @99
gpgme_get_sig_status @100 gpgme_get_sig_status @100
gpgme_get_sig_string_attr @101 gpgme_get_sig_string_attr @101
gpgme_get_sig_ulong_attr @102 gpgme_get_sig_ulong_attr @102
gpgme_get_sig_key @103 gpgme_get_sig_key @103
gpgme_key_get_string_attr @104 gpgme_key_get_string_attr @104
gpgme_key_get_ulong_attr @105 gpgme_key_get_ulong_attr @105
gpgme_key_sig_get_string_attr @106 gpgme_key_sig_get_string_attr @106
gpgme_key_sig_get_ulong_attr @107 gpgme_key_sig_get_ulong_attr @107
gpgme_op_import_ext @108 gpgme_op_import_ext @108
gpgme_trust_item_get_int_attr @109 gpgme_trust_item_get_int_attr @109
gpgme_trust_item_get_string_attr @110 gpgme_trust_item_get_string_attr @110
gpgme_trust_item_release @111 gpgme_trust_item_release @111
gpgme_set_engine_info @112 gpgme_set_engine_info @112
gpgme_ctx_get_engine_info @113 gpgme_ctx_get_engine_info @113
gpgme_ctx_set_engine_info @114 gpgme_ctx_set_engine_info @114
gpgme_data_set_file_name @115 gpgme_data_set_file_name @115
@ -173,7 +173,7 @@ EXPORTS
gpgme_op_assuan_transact @134 gpgme_op_assuan_transact @134
gpgme_check_version_internal @135 gpgme_check_version_internal @135
gpgme_io_read @136 gpgme_io_read @136
gpgme_io_write @137 gpgme_io_write @137
@ -204,5 +204,6 @@ EXPORTS
gpgme_set_global_flag @156 gpgme_set_global_flag @156
gpgme_io_writen @157
; END ; END

View File

@ -1022,6 +1022,7 @@ void gpgme_get_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs);
gpgme_passphrase_cb_t and gpgme_edit_cb_t. */ gpgme_passphrase_cb_t and gpgme_edit_cb_t. */
ssize_t gpgme_io_read (int fd, void *buffer, size_t count); ssize_t gpgme_io_read (int fd, void *buffer, size_t count);
ssize_t gpgme_io_write (int fd, const void *buffer, size_t count); ssize_t gpgme_io_write (int fd, const void *buffer, size_t count);
int gpgme_io_writen (int fd, const void *buffer, size_t count);
/* Process the pending operation and, if HANG is non-zero, wait for /* Process the pending operation and, if HANG is non-zero, wait for
the pending operation to finish. */ the pending operation to finish. */

View File

@ -48,9 +48,9 @@ GPGME_1.1 {
gpgme_cancel_async; gpgme_cancel_async;
gpgme_op_assuan_result; gpgme_op_assuan_result;
gpgme_op_assuan_transact; gpgme_op_assuan_transact;
gpgme_op_assuan_transact_start; gpgme_op_assuan_transact_start;
gpgme_check_version_internal; gpgme_check_version_internal;
@ -81,6 +81,8 @@ GPGME_1.1 {
gpgme_op_passwd; gpgme_op_passwd;
gpgme_set_global_flag; gpgme_set_global_flag;
gpgme_io_writen;
}; };