2009-01-26 10:21:10 +00:00
|
|
|
/* t-command.c - Regression test.
|
|
|
|
Copyright (C) 2009 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 Lesser General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2.1 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
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <locale.h>
|
2009-02-24 15:13:01 +00:00
|
|
|
#include <assert.h>
|
2009-01-26 10:21:10 +00:00
|
|
|
|
|
|
|
#include <gpgme.h>
|
|
|
|
|
|
|
|
#define fail_if_err(err) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (err) \
|
|
|
|
{ \
|
|
|
|
fprintf (stderr, "%s:%d: %s: %s (%d.%d)\n", \
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
__FILE__, __LINE__, gpgme_strsource (err), \
|
|
|
|
gpgme_strerror (err), \
|
|
|
|
gpgme_err_source (err), gpgme_err_code (err)); \
|
2009-01-26 10:21:10 +00:00
|
|
|
exit (1); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
static gpgme_error_t
|
2009-01-26 10:21:10 +00:00
|
|
|
data_cb (void *opaque, const void *data, size_t datalen)
|
|
|
|
{
|
|
|
|
printf ("DATA_CB: datalen=%d\n", (int)datalen);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
static gpgme_error_t
|
2009-01-26 10:21:10 +00:00
|
|
|
inq_cb (void *opaque, const char *name, const char *args,
|
2009-02-24 15:13:01 +00:00
|
|
|
gpgme_data_t *r_data)
|
2009-01-26 10:21:10 +00:00
|
|
|
{
|
2009-02-24 15:13:01 +00:00
|
|
|
gpgme_data_t data;
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
gpgme_error_t err;
|
2009-02-24 15:13:01 +00:00
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
printf ("INQ_CB: name=`%s' args=`%s'\n", name, args);
|
|
|
|
/* There shall be no data object. */
|
|
|
|
assert (!*r_data);
|
|
|
|
|
|
|
|
err = gpgme_data_new (&data);
|
|
|
|
fail_if_err (err);
|
|
|
|
*r_data = data;
|
|
|
|
printf (" sending data object %p\n", data);
|
|
|
|
}
|
|
|
|
else /* Finished using the formerly returned data object. */
|
|
|
|
{
|
|
|
|
printf ("INQ_CB: data object %p finished\n", *r_data);
|
|
|
|
/* There shall be a data object so that it can be cleaned up. */
|
|
|
|
assert (r_data);
|
|
|
|
|
|
|
|
gpgme_data_release (*r_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Uncomment the next lines and send a "SCD LEARN" to test sending
|
|
|
|
cancel from in inquiry. */
|
|
|
|
/* if (name && !strcmp (name, "KNOWNCARDP")) */
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
/* return gpgme_error (GPG_ERR_ASS_CANCELED); */
|
2009-02-24 15:13:01 +00:00
|
|
|
|
2009-01-26 10:21:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Use gpgme interface for error handling to avoid linking with gpg-error.
* tests/t-data.c, tests/run-export.c, tests/run-keylist.c,
tests/run-support.h, tests/run-verify.c, tests/gpg/t-decrypt-verify.c,
tests/gpg/t-edit.c, tests/gpg/t-eventloop.c, tests/gpg/t-keylist-sig.c,
tests/gpg/t-keylist.c, tests/gpg/t-support.h, tests/gpg/t-trustlist.c,
tests/gpg/t-verify.c, tests/gpg/t-wait.c, tests/gpgsm/cms-decrypt.c,
tests/gpgsm/cms-keylist.c, tests/gpgsm/t-keylist.c,
tests/gpgsm/t-support.h, tests/gpgsm/t-verify.c,
tests/opassuan/t-command.c: Use gpgme interface for gpg-error functions.
2012-02-08 14:26:17 +00:00
|
|
|
static gpgme_error_t
|
2009-01-26 10:21:10 +00:00
|
|
|
status_cb (void *opaque, const char *status, const char *args)
|
|
|
|
{
|
|
|
|
printf ("STATUS_CB: status=`%s' args=`%s'\n", status, args);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
gpgme_error_t err;
|
2009-10-26 18:52:32 +00:00
|
|
|
gpgme_error_t op_err;
|
2009-01-26 10:21:10 +00:00
|
|
|
gpgme_ctx_t ctx;
|
|
|
|
const char *command;
|
|
|
|
|
|
|
|
gpgme_check_version (NULL);
|
|
|
|
#ifndef HAVE_W32_SYSTEM
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
|
|
|
|
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (argc)
|
|
|
|
{
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
command = argc? *argv : "NOP";
|
|
|
|
|
|
|
|
|
|
|
|
err = gpgme_new (&ctx);
|
|
|
|
fail_if_err (err);
|
|
|
|
|
|
|
|
err = gpgme_set_protocol (ctx, GPGME_PROTOCOL_ASSUAN);
|
|
|
|
fail_if_err (err);
|
|
|
|
|
2009-10-26 18:52:32 +00:00
|
|
|
err = gpgme_op_assuan_transact_ext (ctx, command, data_cb, NULL,
|
|
|
|
inq_cb, NULL, status_cb, NULL, &op_err);
|
|
|
|
fail_if_err (err || op_err);
|
2009-01-26 10:21:10 +00:00
|
|
|
|
|
|
|
gpgme_release (ctx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|