chiark / gitweb /
Silence two -Wlogical-op warnings.
[gnupg2.git] / common / agent-opt.c
1 /* agent-opt.c - Helper for certain agent options
2  * Copyright (C) 2013 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * This file is free software; you can redistribute it and/or modify
7  * it under the terms of either
8  *
9  *   - the GNU Lesser General Public License as published by the Free
10  *     Software Foundation; either version 3 of the License, or (at
11  *     your option) any later version.
12  *
13  * or
14  *
15  *   - the GNU General Public License as published by the Free
16  *     Software Foundation; either version 2 of the License, or (at
17  *     your option) any later version.
18  *
19  * or both in parallel, as here.
20  *
21  * This file is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, see <https://www.gnu.org/licenses/>.
28  */
29
30 #include <config.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include "shareddefs.h"
35
36
37 /* Parse VALUE and return an integer representing a pinentry_mode_t.
38    (-1) is returned for an invalid VALUE.  */
39 int
40 parse_pinentry_mode (const char *value)
41 {
42   int result;
43
44   if (!strcmp (value, "ask") || !strcmp (value, "default"))
45     result = PINENTRY_MODE_ASK;
46   else if (!strcmp (value, "cancel"))
47     result = PINENTRY_MODE_CANCEL;
48   else if (!strcmp (value, "error"))
49     result = PINENTRY_MODE_ERROR;
50   else if (!strcmp (value, "loopback"))
51     result = PINENTRY_MODE_LOOPBACK;
52   else
53     result = -1;
54
55   return result;
56 }
57
58 /* Return the string representation for the pinentry MODE.  Returns
59    "?" for an invalid mode.  */
60 const char *
61 str_pinentry_mode (pinentry_mode_t mode)
62 {
63   switch (mode)
64     {
65     case PINENTRY_MODE_ASK:      return "ask";
66     case PINENTRY_MODE_CANCEL:   return "cancel";
67     case PINENTRY_MODE_ERROR:    return "error";
68     case PINENTRY_MODE_LOOPBACK: return "loopback";
69     }
70  return "?";
71 }