Index: trunk/ippTools/src/pztool.c
===================================================================
--- trunk/ippTools/src/pztool.c	(revision 6669)
+++ trunk/ippTools/src/pztool.c	(revision 6670)
@@ -7,4 +7,6 @@
 static bool copydoneMode(pxConfig *config);
 bool summitExpPrint(FILE *stream, summitExpRow *summitExp);
+psArray *pzsearchPendingImfiles(pxConfig *config);
+bool pzsearchFlushPendingExp(pxConfig *config);
 
 int main(int argc, char **argv)
@@ -89,12 +91,10 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    psArray *new = pzPendingFrameSearch(config);
-    if (!new) {
+    psArray *pending = pzPendingFrameSearch(config);
+    if (!pending) {
         psError(PS_ERR_UNKNOWN, false, "no pzPendingFrames found");
         return false;
     }
-
-    bool status = pzPendingFramePrint(stdout, config, new);
-    if (!status) {
+    if (!pzPendingFramePrint(stdout, config, pending)) {
         psError(PS_ERR_UNKNOWN, false, "pzPendingFramePrint() failed");
         return false;
@@ -107,4 +107,46 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // we don't have to operate on complete frames here as it's ok to start
+    // downloading the imfiles before the exp has been registered
+    psArray *pending = pzsearchPendingImfiles(config);
+    if (!pending) {
+        psError(PS_ERR_UNKNOWN, false, "no pzPendingImfiles found");
+        return false;
+    }
+
+    // XXX start transaction
+
+    for (long i = 0; i < pending->n; i++) {
+        pzPendingImfileRow *pendingImfile = pending->data[i];
+        newImfileRow *newImfile = newImfileRowAlloc(
+            pendingImfile->exp_id,
+            pendingImfile->class,
+            pendingImfile->class_id,
+            // XXX get this from the CLI
+            pendingImfile->uri
+        );
+
+        if (!newImfileInsertObject(config->dbh, newImfile)) {
+            psError(PS_ERR_UNKNOWN, false, "dbh access failed");
+            return false;
+        }
+    }
+
+    if (pzPendingImfileDeleteRowObjects(config->dbh, pending, MAX_ROWS)
+        < 0) {
+            psError(PS_ERR_UNKNOWN, false, "dbh access failed");
+            return false;
+    }
+
+    // XXX commit transaction
+
+    // check for completed exps
+    if (!pzsearchFlushPendingExp(config)) {
+        psError(PS_ERR_UNKNOWN, false, "pzsearchFlushPendingExp() failed");
+        return false;
+    }
+
+    return true;
 }
 
@@ -124,2 +166,24 @@
     return true;
 }
+
+psArray *pzsearchPendingImfiles(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+
+    psArray *imfiles = pzPendingImfileSelectRowObjects(config->dbh,
+        config->where, MAX_ROWS);
+    if (!imfiles) {
+        psError(PS_ERR_UNKNOWN, false, "no pzPendingImfile rows found");
+
+        return NULL;
+    }
+
+    return imfiles;
+}
+
+bool pzsearchFlushPendingExp(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    return true;
+}
