1 /* t-gpgconf.c - Regression test.
2 Copyright (C) 2001, 2004, 2007 g10 Code GmbH
4 This file is part of GPGME.
6 GPGME is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
11 GPGME is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #ifdef HAVE_W32_SYSTEM
38 #define fail_if_err(err) \
43 fprintf (stderr, "%s:%d: %s: %s\n", \
44 __FILE__, __LINE__, gpgme_strsource (err), \
45 gpgme_strerror (err)); \
53 init_gpgme (gpgme_protocol_t proto)
57 gpgme_check_version (NULL);
58 setlocale (LC_ALL, "");
59 gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
60 #ifndef HAVE_W32_SYSTEM
61 gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
64 err = gpgme_engine_check_version (proto);
70 spaces (char *str, int extra)
73 int len = str ? strlen (str) : 0;
77 n = TABSTOP - len - extra;
79 memset (buf, ' ', sizeof (buf));
80 if (n < 1 || n > (sizeof (buf) - 1))
92 dump_arg (int type, gpgme_conf_arg_t arg)
104 case GPGME_CONF_STRING:
105 case GPGME_CONF_PATHNAME:
106 case GPGME_CONF_LDAP_SERVER:
107 printf ("%s", arg->value.string);
110 case GPGME_CONF_UINT32:
111 printf ("%u", arg->value.uint32);
114 case GPGME_CONF_INT32:
115 printf ("%i", arg->value.int32);
118 case GPGME_CONF_NONE:
119 printf ("%i (times)", arg->value.count);
123 printf ("(unknown type)");
134 dump_opt (gpgme_conf_opt_t opt)
137 char runtime = (opt->flags & GPGME_CONF_RUNTIME) ? 'r' : ' ';
141 case GPGME_CONF_BASIC:
144 case GPGME_CONF_ADVANCED:
147 case GPGME_CONF_EXPERT:
150 case GPGME_CONF_INVISIBLE:
153 case GPGME_CONF_INTERNAL:
160 if (opt->flags & GPGME_CONF_GROUP)
163 printf ("%c%c [%s]%s%s\n", level, runtime, opt->name, spaces (opt->name, 5),
165 ? opt->description : "");
171 char *more = (opt->flags & GPGME_CONF_LIST) ? "..." : "";
173 if (opt->flags & GPGME_CONF_OPTIONAL)
175 printf ("%c%c --%s [%s%s] %s", level, runtime, opt->name, opt->argname, more,
176 spaces (opt->name, 9 + strlen (opt->argname) + strlen (more)));
180 printf ("%c%c --%s %s%s %s", level, runtime, opt->name, opt->argname, more,
181 spaces (opt->name, 7 + strlen (opt->argname) + strlen (more)));
185 printf ("%c%c --%s%s", level, runtime, opt->name, spaces (opt->name, 5));
187 if (opt->description)
188 printf ("%s", opt->description);
191 if (opt->flags & GPGME_CONF_DEFAULT)
193 printf ("%s%s = ", spaces (NULL, 0), opt->argname ? opt->argname : "(default)");
194 dump_arg (opt->type, opt->default_value);
197 else if (opt->flags & GPGME_CONF_DEFAULT_DESC)
198 printf ("%s%s = %s\n", spaces (NULL, 0), opt->argname ? opt->argname : "(default)",
199 opt->default_description);
201 if (opt->no_arg_value)
203 printf ("%sNo Arg Def = ", spaces (NULL, 0));
204 dump_arg (opt->type, opt->no_arg_value);
209 printf ("%sCurrent = ", spaces (NULL, 0));
210 dump_arg (opt->type, opt->value);
227 dump_comp (gpgme_conf_comp_t comp)
229 gpgme_conf_opt_t opt;
231 printf ("COMPONENT\n");
232 printf ("=========\n");
233 printf (" Name: %s\n", comp->name);
234 if (comp->description)
235 printf (" Desc: %s\n", comp->description);
236 if (comp->program_name)
237 printf (" Path: %s\n", comp->program_name);
250 main (int argc, char **argv)
254 gpgme_conf_comp_t conf;
255 gpgme_conf_comp_t comp;
258 #ifndef ENABLE_GPGCONF
262 init_gpgme (GPGME_PROTOCOL_GPGCONF);
264 err = gpgme_new (&ctx);
267 err = gpgme_op_conf_load (ctx, &conf);
283 /* Now change something. */
285 unsigned int count = 1;
286 gpgme_conf_arg_t arg;
287 gpgme_conf_opt_t opt;
289 err = gpgme_conf_arg_new (&arg, GPGME_CONF_NONE, &count);
293 while (comp && strcmp (comp->name, "dirmngr"))
299 while (opt && strcmp (opt->name, "verbose"))
302 /* Allow for the verbose option not to be there. */
305 err = gpgme_conf_opt_change (opt, 0, arg);
308 err = gpgme_op_conf_save (ctx, comp);
315 gpgme_conf_release (conf);