Skip to content

Commit

Permalink
NEW: permit client to request deletion of geohashes
Browse files Browse the repository at this point in the history
	closes #1
  • Loading branch information
jpmens committed Dec 21, 2018
1 parent 3e0d952 commit c0d489f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ The following command-line switches are supported:

* `-d`: dump content of database (all keys/values) to stdout
* `-D`: dump content of database (all keys/values) to stdout, lines prefixed by lat,lon
* `-k`: kill (i.e. delete) individual geohashes
* `-q`: query individual geohashes
* `-s`: attempt to connect to _revgeod_ to obtain and print statistics
* `-v`: show version and exit
Expand Down
1 change: 1 addition & 0 deletions db.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ long db_get(struct db *, char *key, char *buf, long buflen);
void db_dump(char *path, char *lmdbname);
void db_list(char *path, char *lmdbname, int (*func)(int, char *, int, char *));
void db_load(char *path, char *lmdbname);
int db_del(struct db *db, char *keystr);
size_t db_numentries(struct db *db);
const char *db_getpath(struct db *db);
#endif
19 changes: 14 additions & 5 deletions revgeod.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ int main(int argc, char **argv)
struct sockaddr_in sad;
char *s_ip, *s_port;
unsigned short port;
bool query = false;
bool query = false, kill = false;
int ch;

#ifdef STATSD
Expand All @@ -448,12 +448,15 @@ int main(int argc, char **argv)
s_port = LISTEN_PORT;
port = atoi(s_port);

while ((ch = getopt(argc, argv, "dDqsv")) != EOF) {
while ((ch = getopt(argc, argv, "dDqsvk")) != EOF) {
switch (ch) {
case 'D':
case 'd':
return dump_all(ch == 'D');
break; /* NOTREACHED */
case 'k':
kill = true;
break;
case 'q':
query = true;
break;
Expand All @@ -464,18 +467,19 @@ int main(int argc, char **argv)
printf("revgeod %s\n", VERSION);
exit(0);
default:
fprintf(stderr, "Usage: %s [-dD] [-q] [-s] [-v]\n", *argv);
fprintf(stderr, "Usage: %s [-dD] [-k] [-q] [-s] [-v]\n", *argv);
exit(2);
}
}

argc -= optind;
argv += optind;

if (query) {
if (query || kill) {
struct db *db;
bool rdonly = !kill;

if ((db = db_open(LMDB_DATABASE, NULL, true)) == NULL) {
if ((db = db_open(LMDB_DATABASE, NULL, rdonly)) == NULL) {
perror(LMDB_DATABASE);
return (1);
}
Expand All @@ -484,6 +488,11 @@ int main(int argc, char **argv)
char apbuf[8192], *geohash = *argv++;

if (db_get(db, geohash, apbuf, sizeof(apbuf)) > 0) {
if (kill) {
int rc = db_del(db, geohash);

printf("%s ", !rc ? "DELETED" : "ERROR");
}
printf("%s %s\n", geohash, apbuf);
} else {
printf("%s not found\n", geohash);
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION "0.1.9"
#define VERSION "0.2.0"

#define USER_AGENT "revgeod/"VERSION

0 comments on commit c0d489f

Please sign in to comment.