NeoMutt  2023-05-17-16-g61469c
Teaching an old dog new tricks
DOXYGEN
dlg_verifycert.c File Reference

Certificate Verification Dialog. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "mutt/lib.h"
#include "gui/lib.h"
#include "color/lib.h"
#include "menu/lib.h"
#include "globals.h"
#include "keymap.h"
#include "opcodes.h"
#include "ssl.h"
+ Include dependency graph for dlg_verifycert.c:

Go to the source code of this file.

Functions

static int menu_dialog_dokey (struct Menu *menu, int *id)
 Check if there are any menu key events to process. More...
 
static int menu_dialog_translate_op (int op)
 Convert menubar movement to scrolling. More...
 
static void cert_make_entry (struct Menu *menu, char *buf, size_t buflen, int line)
 Create a string to display in a Menu - Implements Menu::make_entry() -. More...
 
void cert_array_clear (struct CertArray *carr)
 Free all memory of a CertArray. More...
 
int dlg_verify_certificate (const char *title, struct CertArray *carr, bool allow_always, bool allow_skip)
 Ask the user to validate the certificate. More...
 

Variables

static const struct Mapping VerifyHelp []
 Help Bar for the Certificate Verification dialog. More...
 

Detailed Description

Certificate Verification Dialog.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file dlg_verifycert.c.

Function Documentation

◆ menu_dialog_dokey()

static int menu_dialog_dokey ( struct Menu menu,
int *  id 
)
static

Check if there are any menu key events to process.

Parameters
menuCurrent Menu
idKeyEvent ID
Return values
0An event occurred for the menu, or a timeout
-1There was an event, but not for menu

Definition at line 82 of file dlg_verifycert.c.

83{
84 struct KeyEvent ch = mutt_getch_timeout(5000);
85
86 if ((ch.op == OP_TIMEOUT) || (ch.op == OP_ABORT))
87 {
88 *id = ch.op;
89 return 0;
90 }
91
92 struct CertMenuData *mdata = menu->mdata;
93 char *p = NULL;
94 if ((ch.ch != 0) && (p = strchr(mdata->keys, ch.ch)))
95 {
96 *id = OP_MAX + (p - mdata->keys + 1);
97 return 0;
98 }
99
100 if (ch.op == OP_NULL)
101 mutt_unget_ch(ch.ch);
102 else
103 mutt_unget_op(ch.op);
104 return -1;
105}
struct KeyEvent mutt_getch_timeout(int delay)
Get an event with a timeout.
Definition: curs_lib.c:198
void mutt_unget_op(int op)
Return an operation to the input buffer.
Definition: curs_lib.c:533
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition: curs_lib.c:522
#define OP_TIMEOUT
Definition: opcodes.h:32
#define OP_ABORT
Definition: opcodes.h:33
@ OP_MAX
Definition: opcodes.h:378
Certificate data to use in the Menu.
Definition: ssl.h:42
char * keys
Keys used in the prompt.
Definition: ssl.h:45
An event such as a keypress.
Definition: keymap.h:65
int op
Function opcode, e.g. OP_HELP.
Definition: keymap.h:67
int ch
Raw key pressed.
Definition: keymap.h:66
void * mdata
Private data.
Definition: lib.h:138
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_dialog_translate_op()

static int menu_dialog_translate_op ( int  op)
static

Convert menubar movement to scrolling.

Parameters
opAction requested, e.g. OP_NEXT_ENTRY
Return values
numAction to perform, e.g. OP_NEXT_LINE

Definition at line 112 of file dlg_verifycert.c.

113{
114 switch (op)
115 {
116 case OP_NEXT_ENTRY:
117 return OP_NEXT_LINE;
118 case OP_PREV_ENTRY:
119 return OP_PREV_LINE;
120 case OP_CURRENT_TOP:
121 return OP_TOP_PAGE;
122 case OP_CURRENT_BOTTOM:
123 return OP_BOTTOM_PAGE;
124 case OP_CURRENT_MIDDLE:
125 return OP_MIDDLE_PAGE;
126 }
127
128 return op;
129}
+ Here is the caller graph for this function:

◆ cert_array_clear()

void cert_array_clear ( struct CertArray *  carr)

Free all memory of a CertArray.

Parameters
carrArray of text to clear
Note
Array is emptied, but not freed

Definition at line 156 of file dlg_verifycert.c.

157{
158 const char **line = NULL;
159 ARRAY_FOREACH(line, carr)
160 {
161 FREE(line);
162 }
163}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define FREE(x)
Definition: memory.h:43
+ Here is the caller graph for this function:

◆ dlg_verify_certificate()

int dlg_verify_certificate ( const char *  title,
struct CertArray *  carr,
bool  allow_always,
bool  allow_skip 
)

Ask the user to validate the certificate.

Parameters
titleMenu title
carrCertificate text to display
allow_alwaysIf true, allow the user to always accept the certificate
allow_skipIf true, allow the user to skip the verification
Return values
1Reject certificate (or menu aborted)
2Accept certificate once
3Accept certificate always/skip (see notes)
4Accept certificate skip

The possible retvals will depend on the parameters. The options are given in the order: Reject, Once, Always, Skip. The retval represents the chosen option.

Definition at line 180 of file dlg_verifycert.c.

182{
184
185 struct CertMenuData mdata = { carr };
186
187 struct Menu *menu = dlg->wdata;
188 menu->mdata = &mdata;
189 menu->mdata_free = NULL; // Menu doesn't own the data
191 menu->max = ARRAY_SIZE(carr);
192
193 struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
194 sbar_set_title(sbar, title);
195
196 if (allow_always)
197 {
198 if (allow_skip)
199 {
200 mdata.prompt = _("(r)eject, accept (o)nce, (a)ccept always, (s)kip");
201 /* L10N: The letters correspond to the choices in the string:
202 "(r)eject, accept (o)nce, (a)ccept always, (s)kip"
203 This is an interactive certificate confirmation prompt for an SSL connection. */
204 mdata.keys = _("roas");
205 }
206 else
207 {
208 mdata.prompt = _("(r)eject, accept (o)nce, (a)ccept always");
209 /* L10N: The letters correspond to the choices in the string:
210 "(r)eject, accept (o)nce, (a)ccept always"
211 This is an interactive certificate confirmation prompt for an SSL connection. */
212 mdata.keys = _("roa");
213 }
214 }
215 else
216 {
217 if (allow_skip)
218 {
219 mdata.prompt = _("(r)eject, accept (o)nce, (s)kip");
220 /* L10N: The letters correspond to the choices in the string:
221 "(r)eject, accept (o)nce, (s)kip"
222 This is an interactive certificate confirmation prompt for an SSL connection. */
223 mdata.keys = _("ros");
224 }
225 else
226 {
227 mdata.prompt = _("(r)eject, accept (o)nce");
228 /* L10N: The letters correspond to the choices in the string:
229 "(r)eject, accept (o)nce"
230 This is an interactive certificate confirmation prompt for an SSL connection. */
231 mdata.keys = _("ro");
232 }
233 }
235
236 bool old_ime = OptIgnoreMacroEvents;
238
239 // ---------------------------------------------------------------------------
240 // Event Loop
241 int choice = 0;
242 int op = OP_NULL;
243 do
244 {
245 window_redraw(NULL);
247
248 // Try to catch dialog keys before ops
249 if (menu_dialog_dokey(menu, &op) != 0)
250 {
251 struct KeyEvent event = km_dokey_event(MENU_GENERIC);
252 if (event.ch == 'q')
253 op = OP_EXIT;
254 else
255 op = event.op;
256 }
257
258 if (op == OP_TIMEOUT)
259 continue;
260
261 // Convert menubar movement to scrolling
263
264 if (op <= OP_MAX)
265 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
266 else
267 mutt_debug(LL_DEBUG1, "Got choice %d\n", op - OP_MAX);
268
269 switch (op)
270 {
271 case -1: // Abort: Ctrl-G
272 case OP_EXIT: // Q)uit
273 case OP_MAX + 1: // R)eject
274 choice = 1;
275 break;
276 case OP_MAX + 2: // O)nce
277 choice = 2;
278 break;
279 case OP_MAX + 3: // A)lways / S)kip
280 choice = 3;
281 break;
282 case OP_MAX + 4: // S)kip
283 choice = 4;
284 break;
285
286 case OP_JUMP:
287 case OP_JUMP_1:
288 case OP_JUMP_2:
289 case OP_JUMP_3:
290 case OP_JUMP_4:
291 case OP_JUMP_5:
292 case OP_JUMP_6:
293 case OP_JUMP_7:
294 case OP_JUMP_8:
295 case OP_JUMP_9:
296 mutt_error(_("Jumping is not implemented for dialogs"));
297 continue;
298
299 case OP_SEARCH:
300 case OP_SEARCH_NEXT:
301 case OP_SEARCH_OPPOSITE:
302 case OP_SEARCH_REVERSE:
303 mutt_error(_("Search is not implemented for this menu"));
304 continue;
305 }
306
307 (void) menu_function_dispatcher(menu->win, op);
308 } while (choice == 0);
309 // ---------------------------------------------------------------------------
310
311 OptIgnoreMacroEvents = old_ime;
312
313 simple_dialog_free(&dlg);
314
315 return choice;
316}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
@ MT_COLOR_PROMPT
Question/user input.
Definition: color.h:60
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.
bool OptIgnoreMacroEvents
(pseudo) don't process macro/push/exec events while set
Definition: globals.c:72
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:317
#define mutt_error(...)
Definition: logging2.h:87
#define mutt_debug(LEVEL,...)
Definition: logging2.h:84
static void cert_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Create a string to display in a Menu - Implements Menu::make_entry() -.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
struct KeyEvent km_dokey_event(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:643
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:40
void msgwin_set_text(enum ColorId cid, const char *text)
Set the text for the Message Window.
Definition: msgwin.c:234
#define _(a)
Definition: message.h:28
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:605
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
@ WT_DLG_CERTIFICATE
Certificate Dialog, dlg_verify_certificate()
Definition: mutt_window.h:81
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
struct CertArray * carr
Lines of the Certificate.
Definition: ssl.h:43
char * prompt
Prompt for user, similar to mutt_multi_choice.
Definition: ssl.h:44
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
int max
Number of entries in the menu.
Definition: lib.h:72
void * wdata
Private data.
Definition: mutt_window.h:145
@ MENU_GENERIC
Generic selection list.
Definition: type.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ VerifyHelp

const struct Mapping VerifyHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Help Bar for the Certificate Verification dialog.

Definition at line 67 of file dlg_verifycert.c.