Skip to content

Commit

Permalink
Pass heartbeats through pubsub_filtered.
Browse files Browse the repository at this point in the history
Skip filtering on heartbeat messages (e.g.: {"_heartbeat_": 1}) and
pass through to all connected clients.
  • Loading branch information
James Socol committed Aug 23, 2013
1 parent e677e0b commit 1c7deb7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pubsub_filtered/README.md
Expand Up @@ -4,6 +4,8 @@ pubsub_filtered
pubsub_filtered connects to a remote pubsub server and filters out or
hashes entries before re-publishing as a pubsub stream

will not filter heartbeat messages but will pass them through to all clients

if you have a message like '{desc:"ip added", ip:"127.0.0.1"}' to encrypt the ip you would start pubsub_filtered with '-e ip'

OPTIONS
Expand Down
13 changes: 10 additions & 3 deletions pubsub_filtered/pubsub_filtered.c
Expand Up @@ -179,6 +179,7 @@ void process_message_cb(char *source, void *arg)
const char *raw_string;
char *encrypted_string;
const char *json_out;
int is_heartbeat = 0; // FALSE
struct cli *client;
struct filter *fltr;
char *subject;
Expand All @@ -195,13 +196,19 @@ void process_message_cb(char *source, void *arg)
return;
}

// some streams might have a heartbeat message, pass these through
if (json_object_object_get(json_in, "_heartbeat_") != NULL) {
//if (DEBUG) fprintf(stdout, "heartbeat received\n");
is_heartbeat = 1;
}

// filter
if (expected_value && !filter_message_simple(expected_key, expected_value, json_in)) {
if (!is_heartbeat && expected_value && !filter_message_simple(expected_key, expected_value, json_in)) {
json_object_put(json_in);
return;
}

if (expected_value_regex && !filter_message(expected_key, expected_value_regex, json_in)) {
if (!is_heartbeat && expected_value_regex && !filter_message(expected_key, expected_value_regex, json_in)) {
json_object_put(json_in);
return;
}
Expand Down Expand Up @@ -229,7 +236,7 @@ void process_message_cb(char *source, void *arg)
continue;
}
// filter
if (client->fltr.ok && !filter_message(client->fltr.subject, client->fltr.re, json_in)) {
if (!is_heartbeat && client->fltr.ok && !filter_message(client->fltr.subject, client->fltr.re, json_in)) {
continue;
}
if (client->websocket) {
Expand Down

0 comments on commit 1c7deb7

Please sign in to comment.