Major and incompatible overhaul of key_data representation. Fix leaks.
[u/mdw/catacomb] / key-misc.c
index 54fdc89..6e3b441 100644 (file)
@@ -177,7 +177,7 @@ key *key_bytag(key_file *f, const char *tag)
  *             @const char *tag@ = pointer to tag string
  *             @dstr *d@ = pointer to string for full tag name
  *             @key **k@ = where to store the key pointer
  *             @const char *tag@ = pointer to tag string
  *             @dstr *d@ = pointer to string for full tag name
  *             @key **k@ = where to store the key pointer
- *             @key_data **kd@ = where to store the key data pointer
+ *             @key_data ***kd@ = where to store the key data pointer
  *
  * Returns:    Zero if OK, nonzero if it failed.
  *
  *
  * Returns:    Zero if OK, nonzero if it failed.
  *
@@ -185,15 +185,15 @@ key *key_bytag(key_file *f, const char *tag)
  *             qualified by the names of subkeys, separated by dots.  Hence,
  *             a qualified tag is ID|TAG[.TAG...].  The various result
  *             pointers can be null to indicate that the result isn't
  *             qualified by the names of subkeys, separated by dots.  Hence,
  *             a qualified tag is ID|TAG[.TAG...].  The various result
  *             pointers can be null to indicate that the result isn't
- *             interesting. 
+ *             interesting.
  */
 
  */
 
-int key_qtag(key_file *f, const char *tag, dstr *d, key **k, key_data **kd)
+int key_qtag(key_file *f, const char *tag, dstr *d, key **k, key_data ***kd)
 {
   dstr dd = DSTR_INIT;
   const char *q;
   key *kk;
 {
   dstr dd = DSTR_INIT;
   const char *q;
   key *kk;
-  key_data *kkd;
+  key_data **kkd;
 
   /* --- Find the end of the base tag --- */
 
 
   /* --- Find the end of the base tag --- */
 
@@ -222,36 +222,42 @@ int key_qtag(key_file *f, const char *tag, dstr *d, key **k, key_data **kd)
 
   /* --- Now dig through the rest of the tag --- */
 
 
   /* --- Now dig through the rest of the tag --- */
 
-  while (q && *q) {
-
-    /* --- Stick on the next bit of the fullqtag --- */
-
-    DRESET(&dd);
-    while (*q && *q != '.') {
-      DPUTC(&dd, *q);
-      q++;
+  if (q) {
+    while (*q) {
+      key_struct *ks;
+
+      /* --- Stick on the next bit of the fullqtag --- */
+
+      DRESET(&dd);
+      while (*q && *q != '.') {
+       DPUTC(&dd, *q);
+       q++;
+      }
+      DPUTZ(&dd);
+      if (d) {
+       DPUTC(d, '.');
+       DPUTD(d, &dd);
+      }
+
+      /* --- Look up the subkey --- */
+
+      if ((*kkd)->e != KENC_STRUCT) {
+       kkd = 0;
+       break;
+      }
+      if ((ks = sym_find(&(*kkd)->u.s, dd.buf, -1, 0, 0)) == 0) {
+       kkd = 0;
+       break;
+      }
+      kkd = &ks->k;
     }
     }
-    DPUTZ(&dd);
-    if (d) {
-      DPUTC(d, '.');
-      DPUTD(d, &dd);
-    }
-
-    /* --- Look up the subkey --- */
-
-    if (kkd->e != KENC_STRUCT) {
-      kkd = 0;
-      break;
-    }
-    if ((kkd = key_structfind(kkd, dd.buf)) == 0)
-      break;
   }
 
   /* --- Return the results --- */
 
   }
 
   /* --- Return the results --- */
 
+  dstr_destroy(&dd);
   if (!kkd)
     return (-1);
   if (!kkd)
     return (-1);
-  dstr_destroy(&dd);
   if (kd)
     *kd = kkd;
   return (0);
   if (kd)
     *kd = kkd;
   return (0);
@@ -374,7 +380,7 @@ int key_fingerprint(key *k, ghash *h, const key_filter *kf)
   size_t n, i;
   sym_iter ai;
 
   size_t n, i;
   sym_iter ai;
 
-  if (!key_encode(&k->k, &d, kf))
+  if (!key_encode(k->k, &d, kf))
     goto done;
   rc = 1;
   GH_HASHSTR(h, "catacomb-key-fingerprint:");
     goto done;
   rc = 1;
   GH_HASHSTR(h, "catacomb-key-fingerprint:");