static apr_status_t htdbm_list(htdbm_t *htdbm) { apr_status_t rv; apr_datum_t key, val; char *cmnt; int i = 0; rv = apr_dbm_firstkey(htdbm->dbm, &key); if (rv != APR_SUCCESS) { fprintf(stderr, "Empty database -- %s\n", htdbm->filename); return APR_ENOENT; } fprintf(stderr, "Dumping records from database -- %s\n", htdbm->filename); fprintf(stderr, " %-32s Comment\n", "Username"); while (key.dptr != NULL) { rv = apr_dbm_fetch(htdbm->dbm, key, &val); if (rv != APR_SUCCESS) { fprintf(stderr, "Failed getting data from %s\n", htdbm->filename); return APR_EGENERAL; } /* Note: we don't store \0-terminators on our dbm data */ fprintf(stderr, " %-32.*s", (int)key.dsize, key.dptr); cmnt = memchr(val.dptr, ':', val.dsize); if (cmnt) fprintf(stderr, " %.*s", (int)(val.dptr+val.dsize - (cmnt+1)), cmnt + 1); fprintf(stderr, "\n"); rv = apr_dbm_nextkey(htdbm->dbm, &key); if (rv != APR_SUCCESS) fprintf(stderr, "Failed getting NextKey\n"); ++i; } fprintf(stderr, "Total #records : %d\n", i); return APR_SUCCESS; }
/* handy debugging function */ static void dump_dbm(apr_dbm_t *d) { apr_status_t status; apr_datum_t key; status = apr_dbm_firstkey(d, &key); while (key.dptr != 0 && status == APR_SUCCESS) { /* FIXME: Assumes that keys are NULL terminated char. */ printf("key: %s\n", key.dptr); status = apr_dbm_nextkey(d, &key); } }
static dav_error * dav_dbm_nextkey(dav_db *db, apr_datum_t *pkey) { apr_status_t status = apr_dbm_nextkey(db->file, pkey); return dav_fs_dbm_error(db, NULL, status); }