NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sort_pgp.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <locale.h>
31#include <stdbool.h>
32#include "mutt/lib.h"
33#include "config/lib.h"
34#include "core/lib.h"
35#include "lib.h"
36#include "pgp.h"
37#include "pgplib.h"
38#include "sort.h"
39
43static int pgp_sort_address(const void *a, const void *b, void *sdata)
44{
45 struct PgpUid const *s = *(struct PgpUid const *const *) a;
46 struct PgpUid const *t = *(struct PgpUid const *const *) b;
47 const bool sort_reverse = *(bool *) sdata;
48
49 int rc = mutt_istr_cmp(s->addr, t->addr);
50 if (rc != 0)
51 goto done;
52
54
55done:
56 return sort_reverse ? -rc : rc;
57}
58
62static int pgp_sort_date(const void *a, const void *b, void *sdata)
63{
64 struct PgpUid const *s = *(struct PgpUid const *const *) a;
65 struct PgpUid const *t = *(struct PgpUid const *const *) b;
66 const bool sort_reverse = *(bool *) sdata;
67
69 if (rc != 0)
70 goto done;
71
72 rc = mutt_istr_cmp(s->addr, t->addr);
73
74done:
75 return sort_reverse ? -rc : rc;
76}
77
81static int pgp_sort_keyid(const void *a, const void *b, void *sdata)
82{
83 struct PgpUid const *s = *(struct PgpUid const *const *) a;
84 struct PgpUid const *t = *(struct PgpUid const *const *) b;
85 const bool sort_reverse = *(bool *) sdata;
86
88 if (rc != 0)
89 goto done;
90
91 rc = mutt_istr_cmp(s->addr, t->addr);
92
93done:
94 return sort_reverse ? -rc : rc;
95}
96
100static int pgp_sort_trust(const void *a, const void *b, void *sdata)
101{
102 struct PgpUid const *s = *(struct PgpUid const *const *) a;
103 struct PgpUid const *t = *(struct PgpUid const *const *) b;
104 const bool sort_reverse = *(bool *) sdata;
105
108 if (rc != 0)
109 goto done;
110
111 // Note: reversed
112 rc = mutt_numeric_cmp(t->trust, s->trust);
113 if (rc != 0)
114 goto done;
115
116 // Note: reversed
118 if (rc != 0)
119 goto done;
120
121 // Note: reversed
123 if (rc != 0)
124 goto done;
125
126 rc = mutt_istr_cmp(s->addr, t->addr);
127 if (rc != 0)
128 goto done;
129
131
132done:
133 return sort_reverse ? -rc : rc;
134}
135
142void pgp_sort_keys(struct PgpUidArray *pua)
143{
144 if (!pua)
145 return;
146
147 sort_t fn = NULL;
148 short c_pgp_sort_keys = cs_subset_sort(NeoMutt->sub, "pgp_key_sort");
149 switch (c_pgp_sort_keys & SORT_MASK)
150 {
151 case KEY_SORT_ADDRESS:
152 fn = pgp_sort_address;
153 break;
154 case KEY_SORT_DATE:
155 fn = pgp_sort_date;
156 break;
157 case KEY_SORT_KEYID:
158 fn = pgp_sort_keyid;
159 break;
160 case KEY_SORT_TRUST:
161 default:
162 fn = pgp_sort_trust;
163 break;
164 }
165
166 if (ARRAY_SIZE(pua) > 1)
167 {
168 bool sort_reverse = c_pgp_sort_keys & SORT_REVERSE;
169 ARRAY_SORT(pua, fn, &sort_reverse);
170 }
171}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition: array.h:279
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
Convenience wrapper for the config headers.
#define SORT_MASK
Mask for the sort id.
Definition: sort.h:38
#define mutt_numeric_cmp(a, b)
Definition: sort.h:26
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort.h:39
Convenience wrapper for the core headers.
static int pgp_sort_trust(const void *a, const void *b, void *sdata)
Compare two keys by their trust levels - Implements sort_t -.
Definition: sort_pgp.c:100
static int pgp_sort_keyid(const void *a, const void *b, void *sdata)
Compare two keys by their IDs - Implements sort_t -.
Definition: sort_pgp.c:81
static int pgp_sort_date(const void *a, const void *b, void *sdata)
Compare two keys by their dates - Implements sort_t -.
Definition: sort_pgp.c:62
static int pgp_sort_address(const void *a, const void *b, void *sdata)
Compare two keys by their addresses - Implements sort_t -.
Definition: sort_pgp.c:43
Convenience wrapper for the library headers.
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:412
#define KEYFLAG_RESTRICTIONS
Definition: lib.h:146
@ KEY_SORT_ADDRESS
Sort by address.
Definition: sort.h:34
@ KEY_SORT_DATE
Sort by date.
Definition: sort.h:35
@ KEY_SORT_TRUST
Sort by trust level.
Definition: sort.h:37
@ KEY_SORT_KEYID
Sort by key id.
Definition: sort.h:36
char * pgp_fpr_or_lkeyid(struct PgpKeyInfo *k)
Get the fingerprint or long keyid.
Definition: pgp.c:234
PGP sign, encrypt, check routines.
Misc PGP helper routines.
int(* sort_t)(const void *a, const void *b, void *sdata)
Definition: qsort_r.h:41
Sidebar sorting functions.
void pgp_sort_keys(struct PgpUidArray *pua)
Sort an array of PGP keys.
Definition: sort_pgp.c:142
Key value store.
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
KeyFlags flags
Definition: pgplib.h:53
short keylen
Definition: pgplib.h:54
time_t gen_time
Definition: pgplib.h:55
PGP User ID.
Definition: pgplib.h:36
short trust
Definition: pgplib.h:38
struct PgpKeyInfo * parent
Parent key.
Definition: pgplib.h:40
char * addr
Definition: pgplib.h:37