This re-shuffles struct entity a bit and removes the unneeded has_data
indicator. Both data and datasz are not null when data is present and null
when there is no data. With this in mind the code becomes simpler.

-- 
:wq Claudio

Index: extern.h
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/extern.h,v
retrieving revision 1.99
diff -u -p -r1.99 extern.h
--- extern.h    22 Dec 2021 09:35:14 -0000      1.99
+++ extern.h    28 Dec 2021 15:40:55 -0000
@@ -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);
 
Index: main.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v
retrieving revision 1.169
diff -u -p -r1.169 main.c
--- main.c      22 Dec 2021 09:35:14 -0000      1.169
+++ main.c      28 Dec 2021 15:39:11 -0000
@@ -120,9 +120,7 @@ entity_read_req(struct ibuf *b, struct e
        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 *en
        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,
        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++;
 
Index: parser.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/parser.c,v
retrieving revision 1.28
diff -u -p -r1.28 parser.c
--- parser.c    4 Nov 2021 18:26:48 -0000       1.28
+++ parser.c    28 Dec 2021 15:40:04 -0000
@@ -195,7 +195,7 @@ proc_parser_cert(const struct entity *en
        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 entit
        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 m
                        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);

Reply via email to