summaryrefslogtreecommitdiff
path: root/tests/t-engine-info.c
blob: 8f617f9a86fa0b45e3d51d42b123f562de77e6db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* t-engine-info.c - Regression test for gpgme_get_engine_info.
   Copyright (C) 2003, 2004, 2007 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, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.  */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <gpgme.h>

#define PGM "t-engine-info"

static int verbose;




#define fail_if_err(err)					\
  do								\
    {								\
      if (err)							\
        {							\
          fprintf (stderr, "%s:%d: gpgme_error_t %s\n",		\
                   __FILE__, __LINE__, gpgme_strerror (err));   \
          exit (1);						\
        }							\
    }								\
  while (0)


int
main (int argc, char **argv )
{
  int last_argc = -1;
  gpgme_engine_info_t info;
  gpgme_error_t err;

  if (argc)
    { argc--; argv++; }

  while (argc && last_argc != argc )
    {
      last_argc = argc;
      if (!strcmp (*argv, "--"))
        {
          argc--; argv++;
          break;
        }
      else if (!strcmp (*argv, "--help"))
        {
          fputs ("usage: " PGM " [options]\n"
                 "Options:\n"
                 "  --set-global-flag KEY VALUE\n",
                 stdout);
          exit (0);
        }
      else if (!strcmp (*argv, "--verbose"))
        {
          verbose++;
          argc--; argv++;
        }
      else if (!strcmp (*argv, "--set-global-flag"))
        {
          argc--; argv++;
          if (argc < 2)
            {
              fprintf (stderr, PGM ": not enough arguments for option\n");
              exit (1);
            }
          if (gpgme_set_global_flag (argv[0], argv[1]))
            {
              fprintf (stderr, PGM ": gpgme_set_global_flag failed\n");
              exit (1);
            }
          argc--; argv++;
          argc--; argv++;
        }
      else if (!strncmp (*argv, "--", 2))
        {
          fprintf (stderr, PGM ": unknown option '%s'\n", *argv);
          exit (1);
        }
    }

  if (argc)
    {
      fprintf (stderr, PGM ": unexpected arguments\n");
      exit (1);
    }

  gpgme_check_version (NULL);

  {
    const char *keys[] = {"homedir",
                          "sysconfdir",
                          "bindir",
                          "libexecdir",
                          "libdir",
                          "datadir",
                          "localedir",
                          "agent-socket",
                          "agent-ssh-socket",
                          "dirmngr-socket",
                          "uiserver-socket",
                          "gpgconf-name",
                          "gpg-name",
                          "gpgsm-name",
                          "g13-name", NULL };
    const char *s;
    int i;

    for (i=0; keys[i]; i++)
      if ((s = gpgme_get_dirinfo (keys[i])))
        fprintf (stderr, "dirinfo: %s='%s'\n", keys[i], s);
  }

  err = gpgme_get_engine_info (&info);
  fail_if_err (err);

  for (; info; info = info->next)
    fprintf (stdout, "protocol=%d engine='%s' v='%s' (min='%s') home='%s'\n",
             info->protocol, info->file_name, info->version, info->req_version,
             info->home_dir? info->home_dir : "[default]");

  return 0;
}