From 08df5e84f37567f664842a7a424cdd92b33bfa5d Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 29 Dec 2021 11:37:57 +0000 Subject: [PATCH] Cleanup struct entity. Remove the unneeded has_data field, the same information can be figured out by looking at the data pointer itself. It is NULL when there is no data and not-NULL if there is data. OK benno@ --- usr.sbin/rpki-client/extern.h | 7 +++---- usr.sbin/rpki-client/main.c | 17 +++++------------ usr.sbin/rpki-client/parser.c | 8 ++++---- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 9a7dcf6ff42..47fc57cb173 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.99 2021/12/22 09:35:14 claudio Exp $ */ +/* $OpenBSD: extern.h,v 1.100 2021/12/29 11:37:57 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -336,13 +336,12 @@ enum publish_type { * and parsed. */ struct entity { - enum rtype type; /* type of entity (not RTYPE_EOF) */ + TAILQ_ENTRY(entity) entries; char *file; /* local path to file */ - int has_data; /* whether data blob is specified */ unsigned char *data; /* optional data blob */ size_t datasz; /* length of optional data blob */ int talid; /* tal identifier */ - TAILQ_ENTRY(entity) entries; + enum rtype type; /* type of entity (not RTYPE_EOF) */ }; TAILQ_HEAD(entityq, entity); diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index a2f476c8d00..7d67de30084 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.169 2021/12/22 09:35:14 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.170 2021/12/29 11:37:57 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -120,9 +120,7 @@ entity_read_req(struct ibuf *b, struct entity *ent) io_read_buf(b, &ent->type, sizeof(ent->type)); io_read_buf(b, &ent->talid, sizeof(ent->talid)); io_read_str(b, &ent->file); - io_read_buf(b, &ent->has_data, sizeof(ent->has_data)); - if (ent->has_data) - io_read_buf_alloc(b, (void **)&ent->data, &ent->datasz); + io_read_buf_alloc(b, (void **)&ent->data, &ent->datasz); } /* @@ -144,9 +142,7 @@ entity_write_req(const struct entity *ent) io_simple_buffer(b, &ent->type, sizeof(ent->type)); io_simple_buffer(b, &ent->talid, sizeof(ent->talid)); io_str_buffer(b, ent->file); - io_simple_buffer(b, &ent->has_data, sizeof(int)); - if (ent->has_data) - io_buf_buffer(b, ent->data, ent->datasz); + io_buf_buffer(b, ent->data, ent->datasz); io_close_buffer(&procq, b); } @@ -194,11 +190,8 @@ entityq_add(char *file, enum rtype type, struct repo *rp, p->type = type; p->talid = talid; p->file = file; - p->has_data = data != NULL; - if (p->has_data) { - p->data = data; - p->datasz = datasz; - } + p->data = data; + p->datasz = (data != NULL) ? datasz : 0; entity_queue++; diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index c58f84fa6b9..68ab66f5c31 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.28 2021/11/04 18:26:48 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.29 2021/12/29 11:37:57 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -195,7 +195,7 @@ proc_parser_cert(const struct entity *entp, const unsigned char *der, STACK_OF(X509) *chain; STACK_OF(X509_CRL) *crls; - assert(!entp->has_data); + assert(entp->data == NULL); /* Extract certificate data and X509. */ @@ -274,7 +274,7 @@ proc_parser_root_cert(const struct entity *entp, const unsigned char *der, struct cert *cert; X509 *x509; - assert(entp->has_data); + assert(entp->data != NULL); /* Extract certificate data and X509. */ @@ -525,7 +525,7 @@ parse_entity(struct entityq *q, struct msgbuf *msgq) tal_free(tal); break; case RTYPE_CER: - if (entp->has_data) + if (entp->data != NULL) cert = proc_parser_root_cert(entp, f, flen); else cert = proc_parser_cert(entp, f, flen); -- 2.20.1