Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #66 from ploxiln/stream_filter_print
Browse files Browse the repository at this point in the history
stream_filter: tweak status printing, add verbose option
  • Loading branch information
mreiferson committed Jun 29, 2012
2 parents 5184d1a + e4eba2d commit f0d761b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pubsub_filtered/stream_filter.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <simplehttp/options.h> #include <simplehttp/options.h>
#include "md5.h" #include "md5.h"


#define VERSION "1.0" #define VERSION "1.1"


#define BUF_SZ (1024 * 16) #define BUF_SZ (1024 * 16)


Expand All @@ -21,6 +21,10 @@ static char *blacklisted_fields[64];
static int num_blacklisted_fields = 0; static int num_blacklisted_fields = 0;
static char *expected_key = NULL; static char *expected_key = NULL;
static char *expected_value = NULL; static char *expected_value = NULL;
static int verbose;

static uint64_t msgRecv = 0;
static uint64_t msgFail = 0;


static char buf[BUF_SZ]; static char buf[BUF_SZ];


Expand Down Expand Up @@ -121,7 +125,10 @@ void process_message(const char *source)
json_in = json_tokener_parse(source); json_in = json_tokener_parse(source);


if (json_in == NULL) { if (json_in == NULL) {
fprintf(stderr, "ERR: unable to parse json %s\n", source); msgFail++;
if (verbose) {
fprintf(stderr, "ERR: unable to parse json '%s'\n", source);
}
return; return;
} }


Expand Down Expand Up @@ -179,9 +186,8 @@ int version_cb(int value)


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
uint64_t msgRecv = 0;

option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION); option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION);
option_define_bool("verbose", OPT_OPTIONAL, 0, &verbose, NULL, "verbose output (to stderr)");
option_define_str("blacklist_fields", OPT_OPTIONAL, NULL, NULL, parse_blacklisted_fields, "comma separated list of fields to remove"); option_define_str("blacklist_fields", OPT_OPTIONAL, NULL, NULL, parse_blacklisted_fields, "comma separated list of fields to remove");
option_define_str("encrypted_fields", OPT_OPTIONAL, NULL, NULL, parse_encrypted_fields, "comma separated list of fields to encrypt"); option_define_str("encrypted_fields", OPT_OPTIONAL, NULL, NULL, parse_encrypted_fields, "comma separated list of fields to encrypt");
option_define_str("expected_key", OPT_OPTIONAL, NULL, &expected_key, NULL, "key to expect in messages before echoing to clients"); option_define_str("expected_key", OPT_OPTIONAL, NULL, &expected_key, NULL, "key to expect in messages before echoing to clients");
Expand All @@ -197,14 +203,11 @@ int main(int argc, char **argv)
} }


while (fgets(buf, BUF_SZ, stdin)) { while (fgets(buf, BUF_SZ, stdin)) {
process_message(buf);

msgRecv++; msgRecv++;
if (msgRecv % 5000) { process_message(buf);
fprintf(stderr, "message #%lu\r", msgRecv);
}
} }


fprintf(stderr, "processed %lu lines, failed to parse %lu of them\n", msgRecv, msgFail);
free_options(); free_options();


return 0; return 0;
Expand Down

0 comments on commit f0d761b

Please sign in to comment.