NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
dlgsmime.c File Reference

SMIME Key Selection Dialog. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "menu/lib.h"
#include "question/lib.h"
#include "mutt_logging.h"
#include "opcodes.h"
#include "smime.h"
+ Include dependency graph for dlgsmime.c:

Go to the source code of this file.

Functions

static char * smime_key_flags (KeyFlags flags)
 Turn SMIME key flags into a string. More...
 
static void smime_make_entry (struct Menu *menu, char *buf, size_t buflen, int line)
 Format a menu item for the smime key list - Implements Menu::make_entry() -. More...
 
static void smime_key_table_free (struct Menu *menu, void **ptr)
 Free the key table - Implements Menu::mdata_free() -. More...
 
struct SmimeKeydlg_select_smime_key (struct SmimeKey *keys, char *query)
 Get the user to select a key. More...
 

Variables

static const struct Mapping SmimeHelp []
 Help Bar for the Smime key selection dialog. More...
 

Detailed Description

SMIME Key Selection 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 dlgsmime.c.

Function Documentation

◆ smime_key_flags()

static char* smime_key_flags ( KeyFlags  flags)
static

Turn SMIME key flags into a string.

Parameters
flagsFlags, see KeyFlags
Return values
ptrFlag string
Note
The string is statically allocated

Definition at line 90 of file dlgsmime.c.

91 {
92  static char buf[3];
93 
94  if (!(flags & KEYFLAG_CANENCRYPT))
95  buf[0] = '-';
96  else
97  buf[0] = 'e';
98 
99  if (!(flags & KEYFLAG_CANSIGN))
100  buf[1] = '-';
101  else
102  buf[1] = 's';
103 
104  buf[2] = '\0';
105 
106  return buf;
107 }
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:125
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:124
int flags
Definition: pgplib.h:38
+ Here is the caller graph for this function:

◆ dlg_select_smime_key()

struct SmimeKey* dlg_select_smime_key ( struct SmimeKey keys,
char *  query 
)

Get the user to select a key.

Parameters
keysList of keys to select from
queryString to match
Return values
ptrKey selected by user

Definition at line 195 of file dlgsmime.c.

196 {
197  struct SmimeKey **table = NULL;
198  int table_size = 0;
199  int table_index = 0;
200  struct SmimeKey *key = NULL;
201  struct SmimeKey *selected_key = NULL;
202  char buf[1024];
203  const char *s = "";
204  bool done = false;
205 
206  for (table_index = 0, key = keys; key; key = key->next)
207  {
208  if (table_index == table_size)
209  {
210  table_size += 5;
211  mutt_mem_realloc(&table, sizeof(struct SmimeKey *) * table_size);
212  }
213 
214  table[table_index++] = key;
215  }
216 
218 
219  struct Menu *menu = dlg->wdata;
220  menu->max = table_index;
222  menu->mdata = table;
224  /* sorting keys might be done later - TODO */
225 
226  char title[256];
227  struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
228  snprintf(title, sizeof(title), _("S/MIME certificates matching \"%s\""), query);
229  sbar_set_title(sbar, title);
230 
232 
233  done = false;
234  while (!done)
235  {
236  switch (menu_loop(menu))
237  {
238  case OP_GENERIC_SELECT_ENTRY:
239  {
240  const int index = menu_get_index(menu);
241  struct SmimeKey *cur_key = table[index];
242  if (cur_key->trust != 't')
243  {
244  switch (cur_key->trust)
245  {
246  case 'e':
247  case 'i':
248  case 'r':
249  s = _("ID is expired/disabled/revoked. Do you really want to use "
250  "the key?");
251  break;
252  case 'u':
253  s = _("ID has undefined validity. Do you really want to use the "
254  "key?");
255  break;
256  case 'v':
257  s = _("ID is not trusted. Do you really want to use the key?");
258  break;
259  }
260 
261  snprintf(buf, sizeof(buf), "%s", s);
262 
263  if (mutt_yesorno(buf, MUTT_NO) != MUTT_YES)
264  {
266  break;
267  }
268  }
269 
270  selected_key = cur_key;
271  done = true;
272  break;
273  }
274 
275  case OP_EXIT:
276  done = true;
277  break;
278  }
279  }
280 
281  simple_dialog_free(&dlg);
282  return selected_key;
283 }
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
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:165
Definition: lib.h:67
static void smime_key_table_free(struct Menu *menu, void **ptr)
Free the key table - Implements Menu::mdata_free() -.
Definition: dlgsmime.c:184
static const struct Mapping SmimeHelp[]
Help Bar for the Smime key selection dialog.
Definition: dlgsmime.c:74
#define _(a)
Definition: message.h:28
char trust
i=Invalid r=revoked e=expired u=unverified v=verified t=trusted
Definition: smime.h:50
An SIME key.
Definition: smime.h:44
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:105
const char * title
Title of this menu.
Definition: lib.h:69
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:112
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
void * mdata
Private data.
Definition: lib.h:155
struct SmimeKey * next
Definition: smime.h:52
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:221
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:180
int max
Number of entries in the menu.
Definition: lib.h:71
Smime Dialog, dlg_select_smime_key()
Definition: mutt_window.h:92
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:170
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
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
SMIME encryption menu.
Definition: type.h:58
void * wdata
Private data.
Definition: mutt_window.h:145
static void smime_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the smime key list - Implements Menu::make_entry() -.
Definition: dlgsmime.c:112
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ SmimeHelp

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

Help Bar for the Smime key selection dialog.

Definition at line 74 of file dlgsmime.c.