diff options
author | Sergey Avseyev <sergey.avseyev@gmail.com> | 2017-12-21 00:24:35 +0300 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2017-12-21 05:05:56 +0000 |
commit | 2b0a1ec2cb13a223a1e0b731dc0f3bb947b1425e (patch) | |
tree | c7d290ca28cf699d05d6a64efc80c810490b8fa1 /epan/dissectors/packet-couchbase.c | |
parent | bb5ade02d5f9250c75c74d3920edaeea51561ad0 (diff) |
couchbase: uncompress snappy payloads
Change-Id: I70de47512dfe8ff1a390a243688ef13f012561fa
Reviewed-on: https://code.wireshark.org/review/24921
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/dissectors/packet-couchbase.c')
-rw-r--r-- | epan/dissectors/packet-couchbase.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/epan/dissectors/packet-couchbase.c b/epan/dissectors/packet-couchbase.c index 67a34b35ad..a003d6c8c4 100644 --- a/epan/dissectors/packet-couchbase.c +++ b/epan/dissectors/packet-couchbase.c @@ -45,6 +45,9 @@ #include <epan/prefs.h> #include <epan/expert.h> +#ifdef HAVE_SNAPPY +#include <snappy-c.h> +#endif #include "packet-tcp.h" #include "packet-ssl.h" @@ -429,6 +432,7 @@ static int hf_xattrs = -1; static expert_field ef_warn_shall_not_have_value = EI_INIT; static expert_field ef_warn_shall_not_have_extras = EI_INIT; static expert_field ef_warn_shall_not_have_key = EI_INIT; +static expert_field ef_compression_error = EI_INIT; static expert_field ei_value_missing = EI_INIT; static expert_field ef_warn_must_have_extras = EI_INIT; @@ -1839,6 +1843,36 @@ dissect_value(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, } } else { ti = proto_tree_add_item(tree, hf_value, tvb, offset, value_len, ENC_ASCII | ENC_NA); +#ifdef HAVE_SNAPPY + if (datatype & DT_SNAPPY) { + size_t orig_size = 0; + snappy_status ret; + guchar *decompressed_buffer = NULL; + tvbuff_t* compressed_tvb = NULL; + + ret = snappy_uncompressed_length(tvb_get_ptr(tvb, offset, -1), + tvb_captured_length_remaining(tvb, offset), + &orig_size); + if (ret == SNAPPY_OK) { + decompressed_buffer = (guchar*)wmem_alloc(pinfo->pool, orig_size); + ret = snappy_uncompress(tvb_get_ptr(tvb, offset, -1), + tvb_captured_length_remaining(tvb, offset), + decompressed_buffer, + &orig_size); + if (ret == SNAPPY_OK) { + compressed_tvb = tvb_new_child_real_data(tvb, decompressed_buffer, (guint32)orig_size, (guint32)orig_size); + add_new_data_source(pinfo, compressed_tvb, "Decompressed Data"); + if (datatype & DT_JSON) { + call_dissector(json_handle, compressed_tvb, pinfo, tree); + } + } else { + expert_add_info_format(pinfo, ti, &ef_compression_error, "Error uncompressing snappy data"); + } + } else { + expert_add_info_format(pinfo, ti, &ef_compression_error, "Error uncompressing snappy data"); + } + } +#endif } } @@ -2258,7 +2292,8 @@ proto_register_couchbase(void) { &ef_warn_unknown_opcode, { "couchbase.warn.unknown_opcode", PI_UNDECODED, PI_WARN, "Unknown opcode", EXPFILL }}, { &ef_note_status_code, { "couchbase.note.status_code", PI_RESPONSE_CODE, PI_NOTE, "Status", EXPFILL }}, { &ef_separator_not_found, { "couchbase.warn.separator_not_found", PI_UNDECODED, PI_WARN, "Separator not found", EXPFILL }}, - { &ef_illegal_value, { "couchbase.warn.illegal_value", PI_UNDECODED, PI_WARN, "Illegal value for command", EXPFILL }} + { &ef_illegal_value, { "couchbase.warn.illegal_value", PI_UNDECODED, PI_WARN, "Illegal value for command", EXPFILL }}, + { &ef_compression_error, { "couchbase.error.compression", PI_UNDECODED, PI_WARN, "Compression error", EXPFILL }} }; static gint *ett[] = { |