NeoMutt  2025-09-05-55-g97fc89
Teaching an old dog new tricks
DOXYGEN
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gnupgparse.h File Reference

Parse the output of CLI PGP programinclude "pgpkey.h". More...

#include "pgpkey.h"
+ Include dependency graph for gnupgparse.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct PgpKeyInfopgp_get_candidates (enum PgpRing keyring, struct ListHead *hints)
 Find PGP keys matching a list of hints.
 

Detailed Description

Parse the output of CLI PGP programinclude "pgpkey.h".

Authors
  • Richard Russon
  • Pietro Cerutti

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 gnupgparse.h.

Function Documentation

◆ pgp_get_candidates()

struct PgpKeyInfo * pgp_get_candidates ( enum PgpRing keyring,
struct ListHead * hints )

Find PGP keys matching a list of hints.

Parameters
keyringPGP Keyring
hintsList of strings to match
Return values
ptrKey list
NULLError

Definition at line 417 of file gnupgparse.c.

418{
419 FILE *fp = NULL;
420 pid_t pid;
421 char buf[1024] = { 0 };
422 struct PgpKeyInfo *db = NULL, **kend = NULL, *k = NULL, *kk = NULL, *mainkey = NULL;
423 bool is_sub = false;
424
425 int fd_null = open("/dev/null", O_RDWR);
426 if (fd_null == -1)
427 return NULL;
428
430
431 pid = pgp_invoke_list_keys(NULL, &fp, NULL, -1, -1, fd_null, keyring, hints);
432 if (pid == -1)
433 {
434 close(fd_null);
435 return NULL;
436 }
437
438 kend = &db;
439 k = NULL;
440 while (fgets(buf, sizeof(buf) - 1, fp))
441 {
442 kk = parse_pub_line(buf, &is_sub, k);
443 if (!kk)
444 continue;
445
446 /* Only append kk to the list if it's new. */
447 if (kk != k)
448 {
449 if (k)
450 kend = &k->next;
451 *kend = kk;
452 k = kk;
453
454 if (is_sub)
455 {
456 struct PgpUid **l = NULL;
457
458 k->flags |= KEYFLAG_SUBKEY;
459 k->parent = mainkey;
460 for (l = &k->address; *l; l = &(*l)->next)
461 ; // do nothing
462
463 *l = pgp_copy_uids(mainkey->address, k);
464 }
465 else
466 {
467 mainkey = k;
468 }
469 }
470 }
471
472 if (ferror(fp))
473 mutt_perror("fgets");
474
475 mutt_file_fclose(&fp);
476 filter_wait(pid);
477
478 close(fd_null);
479
480 return db;
481}
const char * cc_charset(void)
Get the cached value of $charset.
#define mutt_file_fclose(FP)
Definition file.h:139
static char * Charset
Cached copy of $charset.
Definition gnupgparse.c:75
static struct PgpKeyInfo * parse_pub_line(char *buf, bool *is_subkey, struct PgpKeyInfo *k)
Parse the 'pub' line from the pgp output.
Definition gnupgparse.c:134
#define mutt_perror(...)
Definition logging2.h:94
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition filter.c:220
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:282
#define KEYFLAG_SUBKEY
Key is a subkey.
Definition lib.h:140
pid_t pgp_invoke_list_keys(FILE **fp_pgp_in, FILE **fp_pgp_out, FILE **fp_pgp_err, int fd_pgp_in, int fd_pgp_out, int fd_pgp_err, enum PgpRing keyring, struct ListHead *hints)
Find matching PGP Keys.
Definition pgpinvoke.c:421
struct PgpUid * pgp_copy_uids(struct PgpUid *up, struct PgpKeyInfo *parent)
Copy a list of PGP UIDs.
Definition pgplib.c:127
Information about a PGP key.
Definition pgplib.h:49
PGP User ID.
Definition pgplib.h:36
int flags
Definition pgplib.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function: