Overhaul of key management (again).
[u/mdw/catacomb] / key-flags.c
index f25bb21..7840462 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: key-flags.c,v 1.1 1999/12/22 15:47:48 mdw Exp $
+ * $Id: key-flags.c,v 1.2 2000/02/12 18:21:02 mdw Exp $
  *
  * Reading and writing key flag strings
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: key-flags.c,v $
+ * Revision 1.2  2000/02/12 18:21:02  mdw
+ * Overhaul of key management (again).
+ *
  * Revision 1.1  1999/12/22 15:47:48  mdw
  * Major key-management revision.
  *
@@ -176,4 +179,31 @@ void key_writeflags(unsigned f, dstr *d)
   }
 }
 
+/* --- @key_match@ --- *
+ *
+ * Arguments:  @key_data *k@ = pointer to key data block
+ *             @const key_filter *kf@ = pointer to filter block
+ *
+ * Returns:    Nonzero if the key matches the filter.
+ *
+ * Use:                Checks whether a key matches a filter.
+ */
+
+int key_match(key_data *k, const key_filter *kf)
+{
+  sym_iter i;
+  key_struct *ks;
+
+  if (!kf)
+    return (1);
+  if ((k->e & KF_ENCMASK) != KENC_STRUCT)
+    return ((k->e & kf->m) == kf->f);
+
+  for (sym_mkiter(&i, &k->u.s); (ks = sym_next(&i)) != 0; ) {
+    if (key_match(&ks->k, kf))
+      return (1);
+  }
+  return (0);
+}
+
 /*----- That's all, folks -------------------------------------------------*/