recorder/gcache-dump.c
2015-09-04 08:10:52 +02:00

66 lines
2.1 KiB
C

/*
* Copyright (C) 2015 Jan-Piet Mens <jpmens@gmail.com> and OwnTracks
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* JAN-PIET MENS OR OWNTRACKS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include "lmdb.h"
int main(int argc,char **argv)
{
int rc;
MDB_env *env;
MDB_dbi dbi;
MDB_val key, data;
MDB_txn *txn;
MDB_cursor *cursor;
if (argc != 2) {
fprintf(stderr, "Usage: %s storage-directory/ghash\n", *argv);
return (1);
}
rc = mdb_env_create(&env);
rc = mdb_env_open(env, argv[1], 0, 0664);
if (rc) {
fprintf(stderr, "%s: %s: %s\n", *argv, argv[1], mdb_strerror(rc));
return (2);
}
key.mv_size = 0;
key.mv_data = NULL;
rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
rc = mdb_dbi_open(txn, NULL, 0, &dbi);
rc = mdb_cursor_open(txn, dbi, &cursor);
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("%*.*s %*.*s\n",
(int)key.mv_size, (int)key.mv_size, (char *)key.mv_data,
(int)data.mv_size, (int)data.mv_size, (char *)data.mv_data);
}
mdb_cursor_close(cursor);
mdb_txn_abort(txn);
mdb_dbi_close(env, dbi);
mdb_env_close(env);
return (0);
}