Only .crl files need to be parsed first (the other file depend on the
certificate revocation list to be present). Instead of many loops over the
same fileset just do it twice. First for .crl and then for the other known
file types. This should save some CPU cycles.

-- 
:wq Claudio

Index: main.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v
retrieving revision 1.114
diff -u -p -r1.114 main.c
--- main.c      4 Mar 2021 15:44:13 -0000       1.114
+++ main.c      9 Mar 2021 16:17:02 -0000
@@ -532,7 +532,7 @@ queue_add_from_mft_set(struct entityq *q
                f = &mft->files[i];
                sz = strlen(f->file);
                assert(sz > 4);
-               if (strcasecmp(f->file + sz - 4, ".crl"))
+               if (strcasecmp(f->file + sz - 4, ".crl") != 0)
                        continue;
                queue_add_from_mft(q, mft->file, f, RTYPE_CRL);
        }
@@ -541,39 +541,17 @@ queue_add_from_mft_set(struct entityq *q
                f = &mft->files[i];
                sz = strlen(f->file);
                assert(sz > 4);
-               if (strcasecmp(f->file + sz - 4, ".cer"))
+               if (strcasecmp(f->file + sz - 4, ".crl") == 0)
                        continue;
-               queue_add_from_mft(q, mft->file, f, RTYPE_CER);
-       }
-
-       for (i = 0; i < mft->filesz; i++) {
-               f = &mft->files[i];
-               sz = strlen(f->file);
-               assert(sz > 4);
-               if (strcasecmp(f->file + sz - 4, ".roa"))
-                       continue;
-               queue_add_from_mft(q, mft->file, f, RTYPE_ROA);
-       }
-
-       for (i = 0; i < mft->filesz; i++) {
-               f = &mft->files[i];
-               sz = strlen(f->file);
-               assert(sz > 4);
-               if (strcasecmp(f->file + sz - 4, ".gbr"))
-                       continue;
-               queue_add_from_mft(q, mft->file, f, RTYPE_GBR);
-       }
-
-       for (i = 0; i < mft->filesz; i++) {
-               f = &mft->files[i];
-               sz = strlen(f->file);
-               assert(sz > 4);
-               if (strcasecmp(f->file + sz - 4, ".crl") == 0 ||
-                   strcasecmp(f->file + sz - 4, ".cer") == 0 ||
-                   strcasecmp(f->file + sz - 4, ".roa") == 0 ||
-                   strcasecmp(f->file + sz - 4, ".gbr") == 0)
-                       continue;
-               logx("%s: unsupported file type: %s", mft->file, f->file);
+               else if (strcasecmp(f->file + sz - 4, ".cer") == 0)
+                       queue_add_from_mft(q, mft->file, f, RTYPE_CER);
+               else if (strcasecmp(f->file + sz - 4, ".roa") == 0)
+                       queue_add_from_mft(q, mft->file, f, RTYPE_ROA);
+               else if (strcasecmp(f->file + sz - 4, ".gbr") == 0)
+                       queue_add_from_mft(q, mft->file, f, RTYPE_GBR);
+               else
+                       logx("%s: unsupported file type: %s", mft->file,
+                           f->file);
        }
 }
 

Reply via email to