Index: /tags/ipp-20100525/dbconfig/changes.txt
===================================================================
--- /tags/ipp-20100525/dbconfig/changes.txt	(revision 28109)
+++ /tags/ipp-20100525/dbconfig/changes.txt	(revision 28110)
@@ -1712,2 +1712,7 @@
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
+CREATE TABLE pstampWebRequest (
+        num BIGINT AUTO_INCREMENT,
+        PRIMARY KEY(num)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
Index: /tags/ipp-20100525/dbconfig/pstamp.md
===================================================================
--- /tags/ipp-20100525/dbconfig/pstamp.md	(revision 28109)
+++ /tags/ipp-20100525/dbconfig/pstamp.md	(revision 28110)
@@ -59,2 +59,6 @@
     fault       S16         0
 END
+
+pstampWebRequest METADATA
+    num         S64         0    # Primary Key AUTO_INCREMENT
+END
Index: /tags/ipp-20100525/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- /tags/ipp-20100525/ippTools/share/pxadmin_create_tables.sql	(revision 28109)
+++ /tags/ipp-20100525/ippTools/share/pxadmin_create_tables.sql	(revision 28110)
@@ -1401,4 +1401,9 @@
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
+CREATE TABLE pstampWebRequest (
+        num BIGINT AUTO_INCREMENT,
+        PRIMARY KEY(num)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
 CREATE TABLE distTarget (
     target_id   BIGINT AUTO_INCREMENT,
Index: /tags/ipp-20100525/ippTools/share/pxadmin_drop_tables.sql
===================================================================
--- /tags/ipp-20100525/ippTools/share/pxadmin_drop_tables.sql	(revision 28109)
+++ /tags/ipp-20100525/ippTools/share/pxadmin_drop_tables.sql	(revision 28110)
@@ -85,4 +85,5 @@
 DROP TABLE IF EXISTS staticskyRun;
 DROP TABLE IF EXISTS Label;
+DROP TABLE IF EXISTS pstampWebRequest;
 
 SET FOREIGN_KEY_CHECKS=1
Index: /tags/ipp-20100525/ippTools/src/pstamptool.c
===================================================================
--- /tags/ipp-20100525/ippTools/src/pstamptool.c	(revision 28109)
+++ /tags/ipp-20100525/ippTools/src/pstamptool.c	(revision 28110)
@@ -53,4 +53,5 @@
 static bool updatedependentMode(pxConfig *config);
 static bool revertdependentMode(pxConfig *config);
+static bool getwebrequestnumMode(pxConfig *config);
 
 # define MODECASE(caseName, func) \
@@ -95,4 +96,5 @@
         MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode);
         MODECASE(PSTAMPTOOL_MODE_REVERTDEPENDENT, revertdependentMode);
+        MODECASE(PSTAMPTOOL_MODE_GETWEBREQUESTNUM, getwebrequestnumMode);
         default:
             psAbort("invalid option (this should not happen)");
@@ -1334,2 +1336,18 @@
     return true;
 }
+
+static bool getwebrequestnumMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    if (!pstampWebRequestInsert(config->dbh, 0 )) {
+        psError(PS_ERR_UNKNOWN, false, "failed to insert pstampWebRequest");
+        return false;
+    }
+
+    psS64 req_id = psDBLastInsertID(config->dbh);
+
+    printf("%" PRId64 "\n", req_id);
+
+    return true;
+}
Index: /tags/ipp-20100525/ippTools/src/pstamptool.h
===================================================================
--- /tags/ipp-20100525/ippTools/src/pstamptool.h	(revision 28109)
+++ /tags/ipp-20100525/ippTools/src/pstamptool.h	(revision 28110)
@@ -48,4 +48,5 @@
     PSTAMPTOOL_MODE_UPDATEDEPENDENT,
     PSTAMPTOOL_MODE_REVERTDEPENDENT,
+    PSTAMPTOOL_MODE_GETWEBREQUESTNUM,
 } pstamptoolMode;
 
Index: /tags/ipp-20100525/ippTools/src/pstamptoolConfig.c
===================================================================
--- /tags/ipp-20100525/ippTools/src/pstamptoolConfig.c	(revision 28109)
+++ /tags/ipp-20100525/ippTools/src/pstamptoolConfig.c	(revision 28110)
@@ -235,4 +235,7 @@
     psMetadataAddBool(projectArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
 
+    // -getwebrequestnum
+    psMetadata *getwebrequestnumArgs = psMetadataAlloc();
+
     psMetadata *argSets = psMetadataAlloc();
     psMetadata *modes = psMetadataAlloc();
@@ -264,4 +267,5 @@
     PXOPT_ADD_MODE("-modproject",      "", PSTAMPTOOL_MODE_MODPROJECT, modprojectArgs);
     PXOPT_ADD_MODE("-project",         "", PSTAMPTOOL_MODE_PROJECT,    projectArgs);
+    PXOPT_ADD_MODE("-getwebrequestnum","", PSTAMPTOOL_MODE_GETWEBREQUESTNUM,   getwebrequestnumArgs);
 
     if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Index: /tags/ipp-20100525/ippTools/src/pxtools.c
===================================================================
--- /tags/ipp-20100525/ippTools/src/pxtools.c	(revision 28109)
+++ /tags/ipp-20100525/ippTools/src/pxtools.c	(revision 28110)
@@ -48,142 +48,159 @@
 }
 
-psString pxMergeCodeVersions(psString version1, psString version2) {
+psString pxMergeCodeVersions(psString version1, psString version2)
+{
+    if (!version1 && !version2) {
+        return NULL;
+    }
+
+    if (!version1) {
+        return psStringCopy(version2);
+    }
+    if (!version2) {
+        return psStringCopy(version1);
+    }
+
+    bool mod1 = false, mod2 = false;    // Modified versions?
+    if (strchr(version1, 'M')) {
+        psStringSubstitute(&version1, "M", "");
+        mod1 = true;
+    }
+    if (strchr(version2, 'M')) {
+        psStringSubstitute(&version2, "M", "");
+        mod2 = true;
+    }
+
+    int num1 = strtol(version1, NULL, 10);
+    int num2 = strtol(version2, NULL, 10);
+    int numO = PS_MAX(num1, num2);
+
     psString out = NULL;
-
-    bool mod1 = false;
-    bool mod2 = false;
-
-    psS32 num1;
-    psS32 num2;
-    psS32 numO;
-
-    if (!version1) {
-	psStringAppend(&out, "%s", version2);
-	return(out);
-    }
-    if (!version2) {
-	psStringAppend(&out, "%s", version1);
-	return(out);
-    }
-  
-    if (strchr(version1,'M')) {
-	psStringSubstitute(&version1,"M","");
-	mod1 = true;
-    }
-    if (strchr(version2,'M')) {
-	psStringSubstitute(&version2,"M","");
-	mod2 = true;
-    }
-
-    num1 = strtol(version1,NULL,10);
-    num2 = strtol(version2,NULL,10);
-
-    if (num1 >= num2) {
-	numO = num1;
-    }
-    else {
-	numO = num2;
-    }
-  
-    psStringAppend(&out,"%" PRId32,numO);
+    psStringAppend(&out, "%" PRId32, numO);
     if (mod1 || mod2) {
-	psStringAppend(&out,"M");
-    }
-    return(out);
+        psStringAppend(&out, "M");
+    }
+    return out;
 }
 
 bool pxCoalesceRunStatus(pxConfig *config, const psString dbQFile, psS64 stage_id, psString *software_ver,
-			 psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic,
-			 psF32 *maskfrac_magic, psF32 *maskfrac_advisory) {
+                         psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic,
+                         psF32 *maskfrac_magic, psF32 *maskfrac_advisory)
+{
     psString query = pxDataGet(dbQFile);
-/*   psString text_id = NULL; */
-/*   psStringAppend(&text_id," %" PRId64,stage_id); */
-/*   psStringSubstitute(&query,text_id,"@STAGE_ID@"); */
-/*   psFree(text_id); */
+    if (!query) {
+        psError(psErrorCodeLast(), false, "Unable to read query");
+        return false;
+    }
     if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {
-	psError(PS_ERR_UNKNOWN, false, "database error");
-	psFree(query);
-	return(false);
+        psError(psErrorCodeLast(), false, "database error");
+        psFree(query);
+        return false;
     }
     psFree(query);
+
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-	psError(PS_ERR_UNKNOWN, false, "database error");
-	return(false);
-    }
-  
+        psError(psErrorCodeLast(), false, "database error");
+        return false;
+    }
+
+    *maskfrac_npix = 0;
+    *maskfrac_static = 0.0;
+    *maskfrac_dynamic = 0.0;
+    *maskfrac_magic = 0.0;
+    *maskfrac_advisory = 0.0;
+
     for (long i = 0; i < psArrayLength(output); i++) {
-	psMetadata *row = output->data[i];
-
-	psS32 this_npix = psMetadataLookupS32(NULL, row, "maskfrac_npix");
-	psF32 this_static = psMetadataLookupF32(NULL, row, "maskfrac_static");
-	psF32 this_dynamic = psMetadataLookupF32(NULL, row, "maskfrac_dynamic");
-	psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic");
-	psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory");
-	psString this_version = psMetadataLookupStr(NULL, row, "software_ver");
-
-	*software_ver = pxMergeCodeVersions(*software_ver,this_version);
-/*     printf("%ld : %d %f %f %f %f <-> %ld %f %f %f %f\n",i,this_npix,this_static,this_dynamic,this_magic,this_advisory, */
-/* 	   *maskfrac_npix,*maskfrac_static,*maskfrac_dynamic,*maskfrac_magic,*maskfrac_advisory); */
-	if (this_npix > 0) {
-	    *maskfrac_static = ((*maskfrac_static * *maskfrac_npix) + (this_npix * this_static)) / (this_npix + *maskfrac_npix);
-	    *maskfrac_dynamic = ((*maskfrac_dynamic * *maskfrac_npix) + (this_npix * this_dynamic)) / (this_npix + *maskfrac_npix);
-	    *maskfrac_magic = ((*maskfrac_magic * *maskfrac_npix) + (this_npix * this_magic)) / (this_npix + *maskfrac_npix);
-	    *maskfrac_advisory = ((*maskfrac_advisory * *maskfrac_npix) + (this_npix * this_advisory)) / (this_npix + *maskfrac_npix);
-	    *maskfrac_npix += this_npix;
-	}
+        psMetadata *row = output->data[i];
+
+        psS32 this_npix = psMetadataLookupS32(NULL, row, "maskfrac_npix");
+        psF32 this_static = psMetadataLookupF32(NULL, row, "maskfrac_static");
+        psF32 this_dynamic = psMetadataLookupF32(NULL, row, "maskfrac_dynamic");
+        psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic");
+        psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory");
+
+        psTrace("pxtools", 3, "Mask stats: %d %f %f %f %f\n",
+                this_npix, this_static, this_dynamic, this_magic, this_advisory);
+
+        if (this_npix == 0 || this_npix == PS_MAX_S32) {
+            continue;
+        }
+        if (!isfinite(this_static) || !isfinite(this_dynamic) ||
+            !isfinite(this_magic) || !isfinite(this_advisory)) {
+            continue;
+        }
+
+        psString this_version = psMetadataLookupStr(NULL, row, "software_ver");
+        *software_ver = pxMergeCodeVersions(*software_ver,this_version);
+
+        *maskfrac_npix += this_npix;
+        *maskfrac_static += this_npix * this_static;
+        *maskfrac_dynamic += this_npix * this_dynamic;
+        *maskfrac_magic += this_npix * this_magic;
+        *maskfrac_advisory += this_npix * this_advisory;
     }
     psFree(output);
-    return(true);
-}
-
-bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
-		      psString software_ver) {
+
+    if (*maskfrac_npix > 0) {
+        *maskfrac_static /= *maskfrac_npix;
+        *maskfrac_dynamic /= *maskfrac_npix;
+        *maskfrac_magic /= *maskfrac_npix;
+        *maskfrac_advisory /= *maskfrac_npix;
+    }
+
+    return true;
+}
+
+bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name,
+                      const psS64 stage_id, psString software_ver)
+{
     char *query = "UPDATE %s SET software_ver = '%s' WHERE %s = %" PRId64;
-/*   printf(query,tableName,software_ver,stage_id_name,stage_id); */
-    if (!p_psDBRunQueryF(config->dbh,query,tableName,software_ver,stage_id_name,stage_id)) {
-	psError(PS_ERR_UNKNOWN, false,
-		"failed to set software version for %s %" PRId64,stage_id_name,stage_id);
-	return(false);
-    }
-  
-    return(true);
-}
-
-bool pxSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
-		      psS64 maskfrac_npix, psF32 maskfrac_static, psF32 maskfrac_dynamic,
-		      psF32 maskfrac_magic, psF32 maskfrac_advisory) {
-    char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64;
-    if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_npix,maskfrac_static,
-			 maskfrac_dynamic, maskfrac_magic,maskfrac_advisory,stage_id_name,stage_id)) {
-	psError(PS_ERR_UNKNOWN, false,
-		"failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
-	return(false);
-    }
-  
-
-
-    return(true);
-}
-
-bool pxCamSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
-			 psS64 maskfrac_ref_npix, psF32 maskfrac_ref_static, psF32 maskfrac_ref_dynamic,
-			 psF32 maskfrac_ref_magic, psF32 maskfrac_ref_advisory,
-			 psS64 maskfrac_max_npix, psF32 maskfrac_max_static, psF32 maskfrac_max_dynamic,
-			 psF32 maskfrac_max_magic, psF32 maskfrac_max_advisory) {
-  char *query = "UPDATE %s SET maskfrac_ref_npix = %f, maskfrac_ref_static = %f, maskfrac_ref_dynamic = %f, maskfrac_ref_magic = %f, maskfrac_ref_advisory = %f, maskfrac_max_npix = %f, maskfrac_max_static = %f, maskfrac_max_dynamic = %f, maskfrac_max_magic = %f, maskfrac_max_advisory = %f WHERE %s = %" PRId64;
-  if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_ref_npix,maskfrac_ref_static,
-		       maskfrac_ref_dynamic, maskfrac_ref_magic,maskfrac_ref_advisory,
-		       (float) maskfrac_max_npix,maskfrac_max_static,
-		       maskfrac_max_dynamic, maskfrac_max_magic,maskfrac_max_advisory,
-		       stage_id_name,stage_id)) {
-    psError(PS_ERR_UNKNOWN, false,
-	    "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
-    return(false);
+    if (!p_psDBRunQueryF(config->dbh, query, tableName, software_ver, stage_id_name, stage_id)) {
+        psError(psErrorCodeLast(), false,
+                "failed to set software version for %s %" PRId64, stage_id_name, stage_id);
+        return false;
+    }
+
+    return true;
+}
+
+bool pxSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name,
+                      const psS64 stage_id, psS64 maskfrac_npix, psF32 maskfrac_static,
+                      psF32 maskfrac_dynamic, psF32 maskfrac_magic, psF32 maskfrac_advisory)
+{
+    char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, "
+        "maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64;
+    if (!p_psDBRunQueryF(config->dbh, query, tableName, (float)maskfrac_npix, maskfrac_static,
+                         maskfrac_dynamic, maskfrac_magic, maskfrac_advisory, stage_id_name, stage_id)) {
+        psError(psErrorCodeLast(), false,
+                "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
+        return false;
+    }
+
+
+
+    return true;
+}
+
+bool pxCamSetRunMaskfrac(pxConfig *config, const psString tableName,
+                         const psString stage_id_name, const psS64 stage_id,
+                         psS64 maskfrac_ref_npix, psF32 maskfrac_ref_static, psF32 maskfrac_ref_dynamic,
+                         psF32 maskfrac_ref_magic, psF32 maskfrac_ref_advisory,
+                         psS64 maskfrac_max_npix, psF32 maskfrac_max_static, psF32 maskfrac_max_dynamic,
+                         psF32 maskfrac_max_magic, psF32 maskfrac_max_advisory) {
+  char *query = "UPDATE %s SET maskfrac_ref_npix = %f, maskfrac_ref_static = %f, maskfrac_ref_dynamic = %f, "
+      "maskfrac_ref_magic = %f, maskfrac_ref_advisory = %f, maskfrac_max_npix = %f, maskfrac_max_static = %f, "
+      "maskfrac_max_dynamic = %f, maskfrac_max_magic = %f, maskfrac_max_advisory = %f WHERE %s = %" PRId64;
+  if (!p_psDBRunQueryF(config->dbh, query, tableName, (float)maskfrac_ref_npix, maskfrac_ref_static,
+                       maskfrac_ref_dynamic,  maskfrac_ref_magic, maskfrac_ref_advisory,
+                       (float)maskfrac_max_npix, maskfrac_max_static,
+                       maskfrac_max_dynamic,  maskfrac_max_magic, maskfrac_max_advisory,
+                       stage_id_name, stage_id)) {
+      psError(psErrorCodeLast(), false,
+              "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
+      return false;
   }
-  
-
-
-  return(true);
+
+  return true;
 }
 
@@ -222,5 +239,5 @@
     psMetadataItem *item = psMetadataLookup(config->args, name);
     if (!item) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", name);
+        psError(psErrorCodeLast(), false, "failed to lookup value for %s", name);
         return false;
     }
@@ -239,5 +256,5 @@
             item->comment = psStringCopy (op);
             if (!psMetadataAddItem(where, item, PS_LIST_TAIL, PS_META_DUPLICATE_OK)) {
-                psError(PS_ERR_UNKNOWN, false, "failed to add item %s", field);
+                psError(psErrorCodeLast(), false, "failed to add item %s", field);
                 psFree(where);
                 return false;
@@ -293,10 +310,10 @@
     char *comma = ",";
 
-#   define addColumn(_tab, _val)					\
-    do {								\
-	if (_val) {							\
-	    psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \
-	    separator = comma;						\
-	}								\
+#   define addColumn(_tab, _val)                                        \
+    do {                                                                \
+        if (_val) {                                                     \
+            psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \
+            separator = comma;                                          \
+        }                                                               \
     } while (0)
 
@@ -331,5 +348,5 @@
 
     if (!p_psDBRunQueryF(config->dbh, *pQuery, joinHook)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+        psError(psErrorCodeLast(), false, "database error");
         return false;
     }
@@ -343,5 +360,5 @@
 
     if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+        psError(psErrorCodeLast(), false, "database error");
         return false;
     }
@@ -349,14 +366,14 @@
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+        psError(psErrorCodeLast(), false, "database error");
         return false;
     }
     if (!psArrayLength(output)) {
         psFree(output);
-        psError(PS_ERR_UNKNOWN, true, "no rows in dbversion");
+        psError(PXTOOLS_ERR_PROG, true, "no rows in dbversion");
         return false;
     }
     if (psArrayLength(output) > 1) {
-        psError(PS_ERR_UNKNOWN, true, "unexpected number of rows found in dbversion: %ld",
+        psError(PXTOOLS_ERR_PROG, true, "unexpected number of rows found in dbversion: %ld",
                 psArrayLength(output));
         return false;
@@ -373,10 +390,10 @@
     psArray *array = NULL;
     if (!pxLookupVersion(config, &array)) {
-        psError(PS_ERR_UNKNOWN, false, "pxLookupVersion failed");
+        psError(psErrorCodeLast(), false, "pxLookupVersion failed");
         return NULL;
     }
     psMetadata *md = array->data[0];
     if (!md) {
-        psError(PS_ERR_UNKNOWN, true, "output of pxLookupVersion is null");
+        psError(PXTOOLS_ERR_PROG, true, "output of pxLookupVersion is null");
         return NULL;
     }
@@ -394,9 +411,9 @@
     psArray *array = NULL;
     if (!pxLookupVersion(config, &array) || !array) {
-        psError(PS_ERR_UNKNOWN, false, "pxLookupVersion failed");
+        psError(psErrorCodeLast(), false, "pxLookupVersion failed");
         return false;
     }
     if (!ippdbPrintMetadatas(file, array, "dbversion", true)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psError(psErrorCodeLast(), false, "failed to print array");
         psFree(array);
         return false;
@@ -414,5 +431,5 @@
     psMetadataItem *multi_item =  psMetadataLookup(input, "dbversion");
     if (!multi_item || (multi_item->type != PS_DATA_METADATA_MULTI)) {
-        psError(PS_ERR_UNKNOWN, true, "dbversion multi not found in input");
+        psError(PXTOOLS_ERR_PROG, true, "dbversion multi not found in input");
         return false;
     }
@@ -420,5 +437,5 @@
     psMetadataItem *dbversion = psListGet(multi_item->data.list, 0);
     if (!dbversion) {
-        psError(PS_ERR_UNKNOWN, true, "dbversion not found in input");
+        psError(PXTOOLS_ERR_PROG, true, "dbversion not found in input");
         return false;
     }
@@ -429,5 +446,5 @@
         psString schema_version = pxGetDBVersion(config);
         if (!schema_version) {
-            psError(PS_ERR_UNKNOWN, false, "pxGetDBVersion failed");
+            psError(psErrorCodeLast(), false, "pxGetDBVersion failed");
             return false;
         }
@@ -435,9 +452,9 @@
         psString import_version = psMetadataLookupStr(NULL, md, "schema_version");
         if (import_version && strcmp(import_version, schema_version)) {
-            psError(PS_ERR_UNKNOWN, true, "input file schema_version: %s does not match data base: %s",
-		    import_version, schema_version);
+            psError(PXTOOLS_ERR_PROG, true, "input file schema_version: %s does not match data base: %s",
+                    import_version, schema_version);
             return false;
         } else if (!import_version) {
-            psError(PS_ERR_UNKNOWN, true, "input file schema_version is NULL");
+            psError(PXTOOLS_ERR_PROG, true, "input file schema_version is NULL");
             return false;
         } else {
@@ -445,8 +462,8 @@
         }
     } else {
-        psError(PS_ERR_UNKNOWN, true, "Unexpected config dump format");
-        return false;
-    }
-
-    return true;
-}
+        psError(PXTOOLS_ERR_PROG, true, "Unexpected config dump format");
+        return false;
+    }
+
+    return true;
+}
Index: /tags/ipp-20100525/pstamp/scripts/pstamp_insert_request.pl
===================================================================
--- /tags/ipp-20100525/pstamp/scripts/pstamp_insert_request.pl	(revision 28109)
+++ /tags/ipp-20100525/pstamp/scripts/pstamp_insert_request.pl	(revision 28110)
@@ -114,31 +114,25 @@
 
 exit 0;
-
-# Temporary hack
-# webrequest number is stored in a file in the current directory
-#
-# get this number from the database
+# Ask the database for the next web request number
 sub get_webreq_num
 {
-    my $filename = "$workdir/webreq_num.txt";
-    if (! open IN, "+< $filename" ) {
-        my $initial_num = 1;
-        open IN, "> $filename" or die "can't open $filename";
-        print IN "$initial_num\n" or die "failed to initialize $filename";
-        close IN;
-        return $initial_num;
+    my $command = "$pstamptool -getwebrequestnum";
+    $command .= " -dbname $dbname" if $dbname;
+    $command .= " -dbserver $dbserver" if $dbserver;
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        print STDERR @$stderr_buf;
+        die("Unable to perform pstamptool -getwebrequestnum: $error_code");
+    }
+    my $webreq_num = ${$stdout_buf}[0];
+    chomp $webreq_num;
+
+    if (!$webreq_num) {
+        die("pstamptool -getwebreqnum returned no value");
     }
 
-    my $webreq_num = <IN>;
-    chomp $webreq_num;
+    # print STDERR "webreq_num $webreq_num\n";
 
-    print STDERR "$webreq_num\n" if $verbose;
-
-    my $next = $webreq_num + 1;
-    truncate IN, 0;
-    seek IN, 0, 0;
-    print IN "$next\n";
-
-    close IN;
     return $webreq_num;
 }
Index: /tags/ipp-20100525/pstamp/scripts/pstamp_webrequest.pl
===================================================================
--- /tags/ipp-20100525/pstamp/scripts/pstamp_webrequest.pl	(revision 28109)
+++ /tags/ipp-20100525/pstamp/scripts/pstamp_webrequest.pl	(revision 28110)
@@ -23,5 +23,5 @@
 
 my $host = hostname();
-my $verbose = 0;
+my $verbose = 1;
 my $dbname;
 my $dbserver;
@@ -152,29 +152,25 @@
 exit 0;
 
-# Temporary hack
-# webrequest number is stored in a file in the current directory
-#
+# Ask the database for the next web request number
 sub get_webreq_num
 {
-    my $filename = "webreq_num.txt";
-    if (! open IN, "+< $filename" ) {
-        my $initial_num = 1;
-        open IN, "> $filename" or die "can't open $filename";
-        print IN "$initial_num\n" or die "failed to initialize $filename";
-        close IN;
-        return $initial_num;
+    my $command = "$pstamptool -getwebrequestnum";
+    $command .= " -dbname $dbname" if $dbname;
+    $command .= " -dbserver $dbserver" if $dbserver;
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        print STDERR @$stderr_buf;
+        die("Unable to perform pstamptool -getwebrequestnum: $error_code");
+    }
+    my $webreq_num = ${$stdout_buf}[0];
+    chomp $webreq_num;
+
+    if (!$webreq_num) {
+        die("pstamptool -getwebreqnum returned no value");
     }
 
-    my $webreq_num = <IN>;
-    chomp $webreq_num;
+    # print STDERR "webreq_num $webreq_num\n";
 
-    print STDERR "$webreq_num\n" if $verbose;
-
-    my $next = $webreq_num + 1;
-    truncate IN, 0;
-    seek IN, 0, 0;
-    print IN "$next\n";
-
-    close IN;
     return $webreq_num;
 }
