NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
dlgverifycert.c
Go to the documentation of this file.
1 
55 #include "config.h"
56 #include <stdbool.h>
57 #include <stdio.h>
58 #include "mutt/lib.h"
59 #include "gui/lib.h"
60 #include "menu/lib.h"
61 #include "opcodes.h"
62 #include "options.h"
63 #include "ssl.h"
64 
65 #ifdef USE_SSL
66 static const struct Mapping VerifyHelp[] = {
68  // clang-format off
69  { N_("Exit"), OP_EXIT },
70  { N_("Help"), OP_HELP },
71  { NULL, 0 },
72  // clang-format on
73 };
74 #endif
75 
76 #ifdef USE_SSL
77 
92 int dlg_verify_certificate(const char *title, struct ListHead *list,
93  bool allow_always, bool allow_skip)
94 {
95  struct MuttWindow *dlg = simple_dialog_new(MENU_GENERIC, WT_DLG_CERTIFICATE, VerifyHelp);
96 
97  struct Menu *menu = dlg->wdata;
98 
99  struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
100  sbar_set_title(sbar, title);
101 
102  struct ListNode *np = NULL;
103  STAILQ_FOREACH(np, list, entries)
104  {
105  menu_add_dialog_row(menu, NONULL(np->data));
106  }
107 
108  if (allow_always)
109  {
110  if (allow_skip)
111  {
112  menu->prompt = _("(r)eject, accept (o)nce, (a)ccept always, (s)kip");
113  /* L10N: The letters correspond to the choices in the string:
114  "(r)eject, accept (o)nce, (a)ccept always, (s)kip"
115  This is an interactive certificate confirmation prompt for an SSL connection. */
116  menu->keys = _("roas");
117  }
118  else
119  {
120  menu->prompt = _("(r)eject, accept (o)nce, (a)ccept always");
121  /* L10N: The letters correspond to the choices in the string:
122  "(r)eject, accept (o)nce, (a)ccept always"
123  This is an interactive certificate confirmation prompt for an SSL connection. */
124  menu->keys = _("roa");
125  }
126  }
127  else
128  {
129  if (allow_skip)
130  {
131  menu->prompt = _("(r)eject, accept (o)nce, (s)kip");
132  /* L10N: The letters correspond to the choices in the string:
133  "(r)eject, accept (o)nce, (s)kip"
134  This is an interactive certificate confirmation prompt for an SSL connection. */
135  menu->keys = _("ros");
136  }
137  else
138  {
139  menu->prompt = _("(r)eject, accept (o)nce");
140  /* L10N: The letters correspond to the choices in the string:
141  "(r)eject, accept (o)nce"
142  This is an interactive certificate confirmation prompt for an SSL connection. */
143  menu->keys = _("ro");
144  }
145  }
146 
147  bool old_ime = OptIgnoreMacroEvents;
148  OptIgnoreMacroEvents = true;
149 
150  int rc = 0;
151  while (rc == 0)
152  {
153  switch (menu_loop(menu))
154  {
155  case -1: // Abort: Ctrl-G
156  case OP_EXIT: // Q)uit
157  case OP_MAX + 1: // R)eject
158  rc = 1;
159  break;
160  case OP_MAX + 2: // O)nce
161  rc = 2;
162  break;
163  case OP_MAX + 3: // A)lways / S)kip
164  rc = 3;
165  break;
166  case OP_MAX + 4: // S)kip
167  rc = 4;
168  break;
169  }
170  }
171  OptIgnoreMacroEvents = old_ime;
172 
173  simple_dialog_free(&dlg);
174 
175  return rc;
176 }
177 #endif
Convenience wrapper for the gui headers.
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:550
#define NONULL(x)
Definition: string2.h:37
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:165
Definition: lib.h:67
Generic selection list.
Definition: type.h:45
char * prompt
Prompt for user, similar to mutt_multi_choice.
Definition: lib.h:85
#define _(a)
Definition: message.h:28
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:37
All user-callable functions.
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:221
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
int dlg_verify_certificate(const char *title, struct ListHead *list, bool allow_always, bool allow_skip)
Ask the user to validate the certificate.
Definition: dlgverifycert.c:92
char * keys
Keys used in the prompt.
Definition: lib.h:86
char * data
String.
Definition: list.h:36
Handling of SSL encryption.
Mapping between user-readable string and a constant.
Definition: mapping.h:31
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:128
Handling of global boolean variables.
Convenience wrapper for the library headers.
A List node for strings.
Definition: list.h:34
Certificate Dialog, dlg_verify_certificate()
Definition: mutt_window.h:81
void * wdata
Private data.
Definition: mutt_window.h:145
#define N_(a)
Definition: message.h:32