NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
smime_functions.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdio.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "smime_functions.h"
36#include "menu/lib.h"
37#include "question/lib.h"
38#include "mutt_logging.h"
39#include "opcodes.h"
40#include "smime.h"
41
45static int op_exit(struct SmimeData *sd, int op)
46{
47 sd->done = true;
48 return FR_SUCCESS;
49}
50
54static int op_generic_select_entry(struct SmimeData *sd, int op)
55{
56 const int index = menu_get_index(sd->menu);
57 struct SmimeKey *cur_key = sd->table[index];
58 if (cur_key->trust != 't')
59 {
60 const char *s = "";
61 switch (cur_key->trust)
62 {
63 case 'e':
64 case 'i':
65 case 'r':
66 s = _("ID is expired/disabled/revoked. Do you really want to use the key?");
67 break;
68 case 'u':
69 s = _("ID has undefined validity. Do you really want to use the key?");
70 break;
71 case 'v':
72 s = _("ID is not trusted. Do you really want to use the key?");
73 break;
74 }
75
76 char buf[1024] = { 0 };
77 snprintf(buf, sizeof(buf), "%s", s);
78
79 if (mutt_yesorno(buf, MUTT_NO) != MUTT_YES)
80 {
82 return FR_NO_ACTION;
83 }
84 }
85
86 sd->key = cur_key;
87 sd->done = true;
88 return FR_SUCCESS;
89}
90
91// -----------------------------------------------------------------------------
92
96static const struct SmimeFunction SmimeFunctions[] = {
97 // clang-format off
98 { OP_EXIT, op_exit },
99 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
100 { 0, NULL },
101 // clang-format on
102};
103
108{
109 if (!win || !win->wdata)
110 return FR_UNKNOWN;
111
112 struct MuttWindow *dlg = dialog_find(win);
113 if (!dlg)
114 return FR_ERROR;
115
116 struct SmimeData *sd = dlg->wdata;
117
118 int rc = FR_UNKNOWN;
119 for (size_t i = 0; SmimeFunctions[i].op != OP_NULL; i++)
120 {
121 const struct SmimeFunction *fn = &SmimeFunctions[i];
122 if (fn->op == op)
123 {
124 rc = fn->function(sd, op);
125 break;
126 }
127 }
128
129 if (rc == FR_UNKNOWN) // Not our function
130 return rc;
131
132 const char *result = dispacher_get_retval_name(rc);
133 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
134
135 return rc;
136}
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
struct MuttWindow * dialog_find(struct MuttWindow *win)
Find the parent Dialog of a Window.
Definition: dialog.c:83
const char * dispacher_get_retval_name(int rv)
Get the name of a return value.
Definition: dispatcher.c:54
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
@ FR_NO_ACTION
Valid function - no action performed.
Definition: dispatcher.h:37
int smime_function_dispatcher(struct MuttWindow *win, int op)
Perform a Smime function - Implements function_dispatcher_t -.
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
static int op_exit(struct SmimeData *sd, int op)
Exit this menu - Implements smime_function_t -.
static int op_generic_select_entry(struct SmimeData *sd, int op)
Select the current entry - Implements smime_function_t -.
Convenience wrapper for the gui headers.
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
GUI present the user with a selectable list.
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:155
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
NeoMutt Logging.
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
All user-callable functions.
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition: quad.h:38
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
Ask the user a question.
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:194
SMIME helper routines.
static const struct SmimeFunction SmimeFunctions[]
All the NeoMutt functions that the Smime supports.
Smime functions.
#define NONULL(x)
Definition: string2.h:37
void * wdata
Private data.
Definition: mutt_window.h:145
Data to pass to the Smime Functions.
struct SmimeKey * key
Selected Key.
bool done
Should we close the Dialog?
struct Menu * menu
Smime Menu.
struct SmimeKey ** table
Array of Keys.
A NeoMutt function.
smime_function_t function
Function to call.
int op
Op code, e.g. OP_GENERIC_SELECT_ENTRY.
An SIME key.
Definition: smime.h:44
char trust
i=Invalid r=revoked e=expired u=unverified v=verified t=trusted
Definition: smime.h:49