NeoMutt  2022-04-29-145-g9b6a0e
Teaching an old dog new tricks
DOXYGEN
dlg_smime.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 "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "menu/lib.h"
#include "keymap.h"
#include "mutt_logging.h"
#include "opcodes.h"
#include "smime.h"
#include "smime_functions.h"
+ Include dependency graph for dlg_smime.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, const 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 dlg_smime.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 89 of file dlg_smime.c.

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

◆ dlg_select_smime_key()

struct SmimeKey* dlg_select_smime_key ( struct SmimeKey keys,
const 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 194 of file dlg_smime.c.

195 {
196  struct SmimeKey **table = NULL;
197  int table_size = 0;
198  int table_index = 0;
199  struct SmimeKey *key = NULL;
200 
201  for (table_index = 0, key = keys; key; key = key->next)
202  {
203  if (table_index == table_size)
204  {
205  table_size += 5;
206  mutt_mem_realloc(&table, sizeof(struct SmimeKey *) * table_size);
207  }
208 
209  table[table_index++] = key;
210  }
211 
213 
214  struct Menu *menu = dlg->wdata;
215  menu->max = table_index;
217  menu->mdata = table;
219  /* sorting keys might be done later - TODO */
220 
221  struct SmimeData sd = { false, menu, table, NULL };
222  dlg->wdata = &sd;
223 
224  char title[256];
225  struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
226  snprintf(title, sizeof(title), _("S/MIME certificates matching \"%s\""), query);
227  sbar_set_title(sbar, title);
228 
230 
231  // ---------------------------------------------------------------------------
232  // Event Loop
233  int op = OP_NULL;
234  do
235  {
236  menu_tagging_dispatcher(menu->win, op);
237  window_redraw(NULL);
238 
239  op = km_dokey(MENU_SMIME);
240  mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
241  if (op < 0)
242  continue;
243  if (op == OP_NULL)
244  {
246  continue;
247  }
249 
250  int rc = smime_function_dispatcher(dlg, op);
251 
252  if (rc == FR_UNKNOWN)
253  rc = menu_function_dispatcher(menu->win, op);
254  if (rc == FR_UNKNOWN)
255  rc = global_function_dispatcher(NULL, op);
256  } while (!sd.done);
257 
258  simple_dialog_free(&dlg);
259  return sd.key;
260 }
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
static const struct Mapping SmimeHelp[]
Help Bar for the Smime key selection dialog.
Definition: dlg_smime.c:73
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
int smime_function_dispatcher(struct MuttWindow *win, int op)
Perform a Smime function - Implements function_dispatcher_t -.
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
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: dlg_smime.c:111
static void smime_key_table_free(struct Menu *menu, void **ptr)
Free the key table - Implements Menu::mdata_free() -.
Definition: dlg_smime.c:183
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:126
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:163
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:795
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1059
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
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_SMIME
Smime Dialog, dlg_select_smime_key()
Definition: mutt_window.h:92
@ 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
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:220
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
void * mdata
Private data.
Definition: lib.h:137
int max
Number of entries in the menu.
Definition: lib.h:71
void * wdata
Private data.
Definition: mutt_window.h:145
Data to pass to the Smime Functions.
struct SmimeKey * key
Selected Key.
bool done
Should we close the Dialog?
struct Menu * menu
Smime Menu.
struct SmimeKey ** table
Array of Keys.
An SIME key.
Definition: smime.h:44
struct SmimeKey * next
Definition: smime.h:51
@ MENU_SMIME
SMIME encryption menu.
Definition: type.h:58
+ 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 1 of file dlg_smime.c.