NeoMutt  2022-04-29-249-gaae397
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 "keymap.h"
#include "opcodes.h"
#include "options.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...
 
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 // enum MuttCursorState cursor = mutt_curses_set_cursor(MUTT_CURSOR_VISIBLE);
85 struct KeyEvent ch = mutt_getch_timeout(5000);
86 // mutt_curses_set_cursor(cursor);
87
88 if ((ch.op == OP_TIMEOUT) || (ch.op == OP_ABORT))
89 {
90 *id = ch.op;
91 return 0;
92 }
93
94 struct CertMenuData *mdata = menu->mdata;
95 char *p = NULL;
96 if ((ch.ch != 0) && (p = strchr(mdata->keys, ch.ch)))
97 {
98 *id = OP_MAX + (p - mdata->keys + 1);
99 return 0;
100 }
101
102 if (ch.op == OP_NULL)
103 mutt_unget_ch(ch.ch);
104 else
105 mutt_unget_op(ch.op);
106 return -1;
107}
struct KeyEvent mutt_getch_timeout(int delay)
Get an event with a timeout.
Definition: curs_lib.c:197
void mutt_unget_op(int op)
Return an operation to the input buffer.
Definition: curs_lib.c:532
void mutt_unget_ch(int ch)
Return a keystroke to the input buffer.
Definition: curs_lib.c:521
#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:137
+ 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 114 of file dlg_verifycert.c.

115{
116 switch (op)
117 {
118 case OP_NEXT_ENTRY:
119 return OP_NEXT_LINE;
120 case OP_PREV_ENTRY:
121 return OP_PREV_LINE;
122 case OP_CURRENT_TOP:
123 return OP_TOP_PAGE;
124 case OP_CURRENT_BOTTOM:
125 return OP_BOTTOM_PAGE;
126 case OP_CURRENT_MIDDLE:
127 return OP_MIDDLE_PAGE;
128 }
129
130 return op;
131}
+ 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 158 of file dlg_verifycert.c.

159{
160 const char **line = NULL;
161 ARRAY_FOREACH(line, carr)
162 {
163 FREE(line);
164 }
165}
#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 182 of file dlg_verifycert.c.

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