Index: trunk/src/common.c
===================================================================
--- trunk/src/common.c	(revision 136)
+++ trunk/src/common.c	(revision 137)
@@ -38,4 +38,14 @@
 }
 
+void printMsgs(REGFI_ITERATOR* iter)
+{
+  char* msgs = regfi_get_messages(iter->f);
+  if(msgs != NULL)
+  {
+    fprintf(stderr, "%s", msgs);
+    free(msgs);
+  }
+}
+
 
 /* Returns a newly malloc()ed string which contains original buffer,
@@ -205,4 +215,8 @@
  * is the responsibility of the caller to free both a non-NULL return
  * value, and a non-NULL (*error_msg).
+ */
+/* XXX: Part of this function's logic should be pushed into the regfi API.
+ *      The structures should be parsed and stored with VK records and only 
+ *      escaped/encoded later in reglookup and reglookup-recover.
  */
 static char* data_to_ascii(unsigned char* datap, uint32 len, uint32 type, 
Index: trunk/src/reglookup.c
===================================================================
--- trunk/src/reglookup.c	(revision 136)
+++ trunk/src/reglookup.c	(revision 137)
@@ -67,5 +67,5 @@
   if(size > REGFI_VK_MAX_DATA_LENGTH)
   {
-    fprintf(stderr, "WARNING: value data size %d larger than "
+    fprintf(stderr, "WARN: value data size %d larger than "
 	    "%d, truncating...\n", size, REGFI_VK_MAX_DATA_LENGTH);
     size = REGFI_VK_MAX_DATA_LENGTH;
@@ -90,8 +90,8 @@
   {
     if(conv_error == NULL)
-      fprintf(stderr, "WARNING: Could not quote value for '%s/%s'.  "
+      fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
 	      "Memory allocation failure likely.\n", prefix, quoted_name);
     else if(print_verbose)
-      fprintf(stderr, "WARNING: Could not quote value for '%s/%s'.  "
+      fprintf(stderr, "WARN: Could not quote value for '%s/%s'.  "
 	      "Returned error: %s\n", prefix, quoted_name, conv_error);
   }
@@ -129,9 +129,4 @@
 
 
-
-/* XXX: Each chunk must be unquoted after it is split out. 
- *      Quoting syntax may need to be standardized and pushed into the API 
- *      to deal with this issue and others.
- */
 char** splitPath(const char* s)
 {
@@ -200,7 +195,4 @@
 
 /* Returns a quoted path from an iterator's stack */
-/* XXX: Some way should be found to integrate this into regfi's API 
- *      The problem is that the escaping is sorta reglookup-specific.
- */
 char* iter2Path(REGFI_ITERATOR* i)
 {
@@ -273,19 +265,20 @@
 
 
-void printValueList(REGFI_ITERATOR* i, char* prefix)
+void printValueList(REGFI_ITERATOR* iter, char* prefix)
 {
   const REGFI_VK_REC* value;
 
-  value = regfi_iterator_first_value(i);
+  value = regfi_iterator_first_value(iter);
   while(value != NULL)
   {
     if(!type_filter_enabled || (value->type == type_filter))
       printValue(value, prefix);
-    value = regfi_iterator_next_value(i);
-  }
-}
-
-
-void printKey(REGFI_ITERATOR* i, char* full_path)
+    value = regfi_iterator_next_value(iter);
+    printMsgs(iter);
+  }
+}
+
+
+void printKey(REGFI_ITERATOR* iter, char* full_path)
 {
   static char empty_str[1] = "";
@@ -300,5 +293,5 @@
   struct tm* tmp_time_s = NULL;
   const REGFI_SK_REC* sk;
-  const REGFI_NK_REC* k = regfi_iterator_cur_key(i);
+  const REGFI_NK_REC* k = regfi_iterator_cur_key(iter);
 
   *tmp_time = nt_time_to_unix(&k->mtime);
@@ -306,5 +299,5 @@
   strftime(mtime, sizeof(mtime), "%Y-%m-%d %H:%M:%S", tmp_time_s);
 
-  if(print_security && (sk=regfi_iterator_cur_sk(i)))
+  if(print_security && (sk=regfi_iterator_cur_sk(iter)))
   {
     owner = regfi_get_owner(sk->sec_desc);
@@ -340,5 +333,5 @@
       {
 	if(print_verbose)
-	  fprintf(stderr, "WARNING: While converting classname"
+	  fprintf(stderr, "WARN: While converting classname"
 		  " for key '%s': %s.\n", full_path, error_msg);
 	free(error_msg);
@@ -348,4 +341,5 @@
       quoted_classname = empty_str;
 
+    printMsgs(iter);
     printf("%s,KEY,,%s,%s,%s,%s,%s,%s\n", full_path, mtime, 
 	   owner, group, sacl, dacl, quoted_classname);
@@ -373,5 +367,4 @@
   const REGFI_NK_REC* sub = NULL;
   char* path = NULL;
-  char* msgs = NULL;
   int key_type = regfi_type_str2val("KEY");
   bool print_this = true;
@@ -379,7 +372,6 @@
   root = cur = regfi_iterator_cur_key(iter);
   sub = regfi_iterator_first_subkey(iter);
-  msgs = regfi_get_messages(iter->f);
-  if(msgs != NULL)
-    fprintf(stderr, "%s", msgs);
+  printMsgs(iter);
+
   if(root == NULL)
     bailOut(EX_DATAERR, "ERROR: root cannot be NULL.\n");
@@ -392,5 +384,5 @@
       if(path == NULL)
 	bailOut(EX_OSERR, "ERROR: Could not construct iterator's path.\n");
-      
+
       if(!type_filter_enabled || (key_type == type_filter))
 	printKey(iter, path);
@@ -407,10 +399,16 @@
 	/* We're done with this sub-tree, going up and hitting other branches. */
 	if(!regfi_iterator_up(iter))
+	{
+	  printMsgs(iter);
 	  bailOut(EX_DATAERR, "ERROR: could not traverse iterator upward.\n");
-	
+	}
+
 	cur = regfi_iterator_cur_key(iter);
 	if(cur == NULL)
+	{
+	  printMsgs(iter);
 	  bailOut(EX_DATAERR, "ERROR: unexpected NULL for key.\n");
-	
+	}
+
 	sub = regfi_iterator_next_subkey(iter);
       }
@@ -422,5 +420,8 @@
        */
       if(!regfi_iterator_down(iter))
+      {
+	printMsgs(iter);
 	bailOut(EX_DATAERR, "ERROR: could not traverse iterator downward.\n");
+      }
 
       cur = sub;
@@ -428,4 +429,5 @@
       print_this = true;
     }
+    printMsgs(iter);
   } while(!((cur == root) && (sub == NULL)));
 
@@ -479,4 +481,5 @@
   if(!regfi_iterator_walk_path(iter, tmp_path))
   {
+    printMsgs(iter);
     free(tmp_path);
     return 0;
@@ -489,4 +492,5 @@
 
     value = regfi_iterator_cur_value(iter);
+    printMsgs(iter);
     tmp_path_joined = iter2Path(iter);
 
@@ -503,12 +507,17 @@
   else if(regfi_iterator_find_subkey(iter, path[i]))
   {
+    printMsgs(iter);
     if(print_verbose)
       fprintf(stderr, "VERBOSE: Found final path element as key.\n");
 
     if(!regfi_iterator_down(iter))
+    {
+      printMsgs(iter);
       bailOut(EX_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
+    }
 
     return 2;
   }
+  printMsgs(iter);
 
   if(print_verbose)
@@ -625,8 +634,9 @@
   {
     retr_path_ret = retrievePath(iter, path);
+    printMsgs(iter);
     freePath(path);
 
     if(retr_path_ret == 0)
-      fprintf(stderr, "WARNING: specified path not found.\n");
+      fprintf(stderr, "WARN: specified path not found.\n");
     else if (retr_path_ret == 2)
       printKeyTree(iter);
