NeoMutt  2025-12-11-980-ge38c27
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_verifycert.c
Go to the documentation of this file.
1
23
53
54#include "config.h"
55#include <stdbool.h>
56#include <string.h>
57#include "mutt/lib.h"
58#include "gui/lib.h"
59#include "color/lib.h"
60#include "key/lib.h"
61#include "menu/lib.h"
62#include "ssl.h"
63
65static const struct Mapping VerifyHelp[] = {
66 // clang-format off
67 { N_("Exit"), OP_EXIT },
68 { N_("Help"), OP_HELP },
69 { NULL, 0 },
70 // clang-format on
71};
72
80static int menu_dialog_dokey(struct Menu *menu, int *id)
81{
83
84 if ((event.op == OP_TIMEOUT) || (event.op == OP_ABORT))
85 {
86 *id = event.op;
87 return 0;
88 }
89
90 struct CertMenuData *mdata = menu->mdata;
91 char *p = NULL;
92 if ((event.ch != 0) && (p = strchr(mdata->keys, event.ch)))
93 {
94 *id = OP_MAX + (p - mdata->keys + 1);
95 return 0;
96 }
97
98 if (event.op == OP_NULL)
99 mutt_unget_ch(event.ch);
100 else
101 mutt_unget_op(event.op);
102 return -1;
103}
104
110static int menu_dialog_translate_op(int op)
111{
112 switch (op)
113 {
114 case OP_NEXT_ENTRY:
115 return OP_NEXT_LINE;
116 case OP_PREV_ENTRY:
117 return OP_PREV_LINE;
118 case OP_CURRENT_TOP:
119 return OP_TOP_PAGE;
120 case OP_CURRENT_BOTTOM:
121 return OP_BOTTOM_PAGE;
122 case OP_CURRENT_MIDDLE:
123 return OP_MIDDLE_PAGE;
124 }
125
126 return op;
127}
128
132static int cert_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
133{
134 struct CertMenuData *mdata = menu->mdata;
135
136 int total_cols = 0;
137
138 const char **line_ptr = ARRAY_GET(mdata->carr, line);
139 if (line_ptr)
140 {
141 const int bytes = buf_addstr(buf, *line_ptr);
142 total_cols = mutt_strnwidth(buf_string(buf), bytes);
143 }
144
145 return total_cols;
146}
147
166int dlg_certificate(const char *title, struct StringArray *carr, bool allow_always, bool allow_skip)
167{
168 const struct MenuDefinition *md_generic = generic_get_menu_definition();
170
171 struct CertMenuData mdata = { carr };
172
173 struct Menu *menu = sdw.menu;
174 menu->mdata = &mdata;
175 menu->mdata_free = NULL; // Menu doesn't own the data
177 menu->max = ARRAY_SIZE(carr);
178 menu->show_indicator = false;
179
180 sbar_set_title(sdw.sbar, title);
181
182 if (allow_always)
183 {
184 if (allow_skip)
185 {
186 mdata.prompt = _("(r)eject, accept (o)nce, (a)ccept always, (s)kip");
187 /* L10N: The letters correspond to the choices in the string:
188 "(r)eject, accept (o)nce, (a)ccept always, (s)kip"
189 This is an interactive certificate confirmation prompt for an SSL connection. */
190 mdata.keys = _("roas");
191 }
192 else
193 {
194 mdata.prompt = _("(r)eject, accept (o)nce, (a)ccept always");
195 /* L10N: The letters correspond to the choices in the string:
196 "(r)eject, accept (o)nce, (a)ccept always"
197 This is an interactive certificate confirmation prompt for an SSL connection. */
198 mdata.keys = _("roa");
199 }
200 }
201 else
202 {
203 if (allow_skip)
204 {
205 mdata.prompt = _("(r)eject, accept (o)nce, (s)kip");
206 /* L10N: The letters correspond to the choices in the string:
207 "(r)eject, accept (o)nce, (s)kip"
208 This is an interactive certificate confirmation prompt for an SSL connection. */
209 mdata.keys = _("ros");
210 }
211 else
212 {
213 mdata.prompt = _("(r)eject, accept (o)nce");
214 /* L10N: The letters correspond to the choices in the string:
215 "(r)eject, accept (o)nce"
216 This is an interactive certificate confirmation prompt for an SSL connection. */
217 mdata.keys = _("ro");
218 }
219 }
221
222 struct MuttWindow *old_focus = window_set_focus(menu->win);
223 // ---------------------------------------------------------------------------
224 // Event Loop
225 int choice = 0;
226 int op = OP_NULL;
227 struct KeyEvent event = { 0, OP_NULL };
228 do
229 {
230 window_redraw(NULL);
232
233 // Try to catch dialog keys before ops
234 if (menu_dialog_dokey(menu, &op) != 0)
235 {
236 event = km_dokey(md_generic, GETCH_IGNORE_MACRO);
237 op = event.op;
238 }
239
240 if (op == OP_TIMEOUT)
241 continue;
242
243 // Convert menubar movement to scrolling
245
246 if (op <= OP_MAX)
247 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
248 else
249 mutt_debug(LL_DEBUG1, "Got choice %d\n", op - OP_MAX);
250
251 switch (op)
252 {
253 case OP_ABORT: // Abort: Ctrl-G
254 case OP_QUIT: // Q)uit
255 case OP_MAX + 1: // R)eject
256 choice = 1;
257 break;
258 case OP_MAX + 2: // O)nce
259 choice = 2;
260 break;
261 case OP_MAX + 3: // A)lways / S)kip
262 choice = 3;
263 break;
264 case OP_MAX + 4: // S)kip
265 choice = 4;
266 break;
267
268 case OP_JUMP:
269 mutt_error(_("Jumping is not implemented for dialogs"));
270 continue;
271
272 case OP_SEARCH:
273 case OP_SEARCH_NEXT:
274 case OP_SEARCH_OPPOSITE:
275 case OP_SEARCH_REVERSE:
276 mutt_error(_("Search is not implemented for this menu"));
277 continue;
278 }
279
280 (void) menu_function_dispatcher(menu->win, &event);
281 } while (choice == 0);
282 // ---------------------------------------------------------------------------
283
284 window_set_focus(old_focus);
286
287 return choice;
288}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:233
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Color and attribute parsing.
@ MT_COLOR_PROMPT
Question/user input.
Definition color.h:56
size_t mutt_strnwidth(const char *s, size_t n)
Measure a string's width in screen cells.
Definition curs_lib.c:462
static int menu_dialog_dokey(struct Menu *menu, int *id)
Check if there are any menu key events to process.
static int menu_dialog_translate_op(int op)
Convert menubar movement to scrolling.
static const struct Mapping VerifyHelp[]
Help Bar for the Certificate Verification dialog.
struct KeyEvent mutt_getch(GetChFlags flags)
Read a character from the input buffer.
Definition get.c:319
struct KeyEvent km_dokey(const struct MenuDefinition *md, GetChFlags flags)
Determine what a keypress should do.
Definition get.c:519
void mutt_unget_op(int op)
Return an operation to the input buffer.
Definition get.c:159
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition get.c:147
@ GETCH_IGNORE_MACRO
Don't use MacroEvents.
Definition get.h:39
int menu_function_dispatcher(struct MuttWindow *win, const struct KeyEvent *event)
Perform a Menu function - Implements function_dispatcher_t -.
Definition functions.c:366
int dlg_certificate(const char *title, struct StringArray *carr, bool allow_always, bool allow_skip)
Ask the user to validate the certificate -.
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int cert_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Create a Certificate for the Menu - Implements Menu::make_entry() -.
struct MenuDefinition * generic_get_menu_definition(void)
Get the Generic Menu Definition.
Definition functions.c:177
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition simple.c:169
struct SimpleDialogWindows simple_dialog_new(const struct MenuDefinition *md, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition simple.c:132
Manage keymappings.
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
GUI present the user with a selectable list.
void msgwin_set_text(struct MuttWindow *win, const char *text, enum ColorId color)
Set the text for the Message Window.
Definition msgwin.c:502
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
@ WT_DLG_CERTIFICATE
Certificate Dialog, dlg_certificate()
Definition mutt_window.h:81
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition opcodes.c:48
#define OP_TIMEOUT
1 second with no events
Definition opcodes.h:35
#define OP_ABORT
$abort_key pressed (Ctrl-G)
Definition opcodes.h:36
@ OP_MAX
Definition opcodes.h:686
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition sbar.c:227
Handling of SSL encryption.
String manipulation buffer.
Definition buffer.h:36
Certificate data to use in the Menu.
Definition ssl.h:37
char * prompt
Prompt for user, similar to mw_multi_choice.
Definition ssl.h:39
struct StringArray * carr
Lines of the Certificate.
Definition ssl.h:38
char * keys
Keys used in the prompt.
Definition ssl.h:40
An event such as a keypress.
Definition get.h:75
int op
Function opcode, e.g. OP_HELP.
Definition get.h:77
int ch
Raw key pressed.
Definition get.h:76
Mapping between user-readable string and a constant.
Definition mapping.h:33
Functions for a Dialog or Window.
Definition menudef.h:44
Definition lib.h:86
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition lib.h:169
bool show_indicator
Show the Indicator colour.
Definition lib.h:93
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition lib.h:114
void * mdata
Private data.
Definition lib.h:155
int max
Number of entries in the menu.
Definition lib.h:88
Tuple for the results of simple_dialog_new()
Definition simple.h:35
struct MuttWindow * sbar
Simple Bar.
Definition simple.h:37
struct Menu * menu
Menu.
Definition simple.h:38
struct MuttWindow * dlg
Main Dialog Window.
Definition simple.h:36