NeoMutt  2024-12-12-14-g7b49f7
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 **pkey = ARRAY_GET(sd->ska, index);
57 if (!pkey)
58 return FR_NO_ACTION;
59
60 if ((*pkey)->trust != 't')
61 {
62 const char *s = "";
63 switch ((*pkey)->trust)
64 {
65 case 'e':
66 case 'i':
67 case 'r':
68 s = _("ID is expired/disabled/revoked. Do you really want to use the key?");
69 break;
70 case 'u':
71 s = _("ID has undefined validity. Do you really want to use the key?");
72 break;
73 case 'v':
74 s = _("ID is not trusted. Do you really want to use the key?");
75 break;
76 }
77
78 char buf[1024] = { 0 };
79 snprintf(buf, sizeof(buf), "%s", s);
80
81 if (query_yesorno(buf, MUTT_NO) != MUTT_YES)
82 {
84 return FR_NO_ACTION;
85 }
86 }
87
88 sd->key = *pkey;
89 sd->done = true;
90 return FR_SUCCESS;
91}
92
93// -----------------------------------------------------------------------------
94
98static const struct SmimeFunction SmimeFunctions[] = {
99 // clang-format off
100 { OP_EXIT, op_exit },
101 { OP_GENERIC_SELECT_ENTRY, op_generic_select_entry },
102 { 0, NULL },
103 // clang-format on
104};
105
110{
111 // The Dispatcher may be called on any Window in the Dialog
112 struct MuttWindow *dlg = dialog_find(win);
113 if (!dlg || !dlg->wdata)
114 return FR_ERROR;
115
116 struct Menu *menu = dlg->wdata;
117 struct SmimeData *sd = menu->mdata;
118
119 int rc = FR_UNKNOWN;
120 for (size_t i = 0; SmimeFunctions[i].op != OP_NULL; i++)
121 {
122 const struct SmimeFunction *fn = &SmimeFunctions[i];
123 if (fn->op == op)
124 {
125 rc = fn->function(sd, op);
126 break;
127 }
128 }
129
130 if (rc == FR_UNKNOWN) // Not our function
131 return rc;
132
133 const char *result = dispatcher_get_retval_name(rc);
134 mutt_debug(LL_DEBUG1, "Handled %s (%d) -> %s\n", opcodes_get_name(op), op, NONULL(result));
135
136 return rc;
137}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
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:160
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:74
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:327
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
Definition: lib.h:79
void * mdata
Private data.
Definition: lib.h:147
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 SmimeKeyArray * ska
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:43