NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "smime.h"
40
44static int op_exit(struct SmimeData *sd, int op)
45{
46 sd->done = true;
47 return FR_SUCCESS;
48}
49
53static int op_generic_select_entry(struct SmimeData *sd, int op)
54{
55 const int index = menu_get_index(sd->menu);
56 struct SmimeKey *cur_key = sd->table[index];
57 if (cur_key->trust != 't')
58 {
59 const char *s = "";
60 switch (cur_key->trust)
61 {
62 case 'e':
63 case 'i':
64 case 'r':
65 s = _("ID is expired/disabled/revoked. Do you really want to use the key?");
66 break;
67 case 'u':
68 s = _("ID has undefined validity. Do you really want to use the key?");
69 break;
70 case 'v':
71 s = _("ID is not trusted. Do you really want to use the key?");
72 break;
73 }
74
75 char buf[1024] = { 0 };
76 snprintf(buf, sizeof(buf), "%s", s);
77
78 if (query_yesorno(buf, MUTT_NO) != MUTT_YES)
79 {
81 return FR_NO_ACTION;
82 }
83 }
84
85 sd->key = cur_key;
86 sd->done = true;
87 return FR_SUCCESS;
88}
89
90// -----------------------------------------------------------------------------
91
95static const struct SmimeFunction SmimeFunctions[] = {
96 // clang-format off
97 { OP_EXIT, op_exit },
98 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
99 { 0, NULL },
100 // clang-format on
101};
102
107{
108 if (!win || !win->wdata)
109 return FR_UNKNOWN;
110
111 struct MuttWindow *dlg = dialog_find(win);
112 if (!dlg)
113 return FR_ERROR;
114
115 struct SmimeData *sd = dlg->wdata;
116
117 int rc = FR_UNKNOWN;
118 for (size_t i = 0; SmimeFunctions[i].op != OP_NULL; i++)
119 {
120 const struct SmimeFunction *fn = &SmimeFunctions[i];
121 if (fn->op == op)
122 {
123 rc = fn->function(sd, op);
124 break;
125 }
126 }
127
128 if (rc == FR_UNKNOWN) // Not our function
129 return rc;
130
131 const char *result = dispatcher_get_retval_name(rc);
132 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
133
134 return rc;
135}
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:89
const char * dispatcher_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:89
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:156
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
@ 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 query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:330
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