Constify a character array;

Add forward declarations for proto_register_...() & proto_reg_hand_off_...();
Remove a boilerpalte comment;
Tweak some whitespace;
Add editor modelines.


svn path=/trunk/; revision=53359
This commit is contained in:
Bill Meier 2013-11-16 02:48:43 +00:00
parent d973799957
commit 3e5b82ddcc
1 changed files with 194 additions and 183 deletions

View File

@ -72,7 +72,7 @@ static const value_string message_types_val[] = {
{ 0, NULL }
};
static char chix_msg[] = "apex";
static const char chix_msg[] = "apex";
static const value_string system_event_val[] = {
{ 'O', "Start of Messages" },
@ -153,12 +153,12 @@ static int
order_ref_number(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int offset)
{
const char *str_value = tvb_get_string(wmem_packet_scope(), tvb, offset, 9);
guint32 value = (guint32)strtoul(str_value, NULL, 10);
guint32 value = (guint32)strtoul(str_value, NULL, 10);
proto_tree_add_uint(nasdaq_itch_tree, hf_nasdaq_itch_order_reference, tvb, offset, 9, value);
col_append_fstr(pinfo->cinfo, COL_INFO, "%u ", value);
return offset+9;
return offset + 9;
}
/* -------------------------- */
@ -167,8 +167,8 @@ time_stamp(tvbuff_t *tvb, proto_tree *nasdaq_itch_tree, int id, int offset, int
{
if (nasdaq_itch_tree) {
guint32 ms, val;
const char *display = "";
guint32 ms, val;
const char *display = "";
const char *str_value = tvb_get_string(wmem_packet_scope(), tvb, offset, size);
ms = val = (guint32)strtoul(str_value, NULL, 10);
@ -185,14 +185,14 @@ time_stamp(tvbuff_t *tvb, proto_tree *nasdaq_itch_tree, int id, int offset, int
}
proto_tree_add_uint_format_value(nasdaq_itch_tree, id, tvb, offset, size, val, "%s", display);
}
return offset+size;
return offset + size;
}
/* -------------------------- */
static int
number_of_shares(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int id, int offset, int big)
{
gint size = (big)?10:6;
gint size = (big) ? 10 : 6;
const char *str_value = tvb_get_string(wmem_packet_scope(), tvb, offset, size);
guint32 value = (guint32)strtoul(str_value, NULL, 10);
@ -200,22 +200,22 @@ number_of_shares(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree
proto_tree_add_uint(nasdaq_itch_tree, id, tvb, offset, size, value);
col_append_fstr(pinfo->cinfo, COL_INFO, "qty %u ", value);
return offset +size;
return offset + size;
}
/* -------------------------- */
static int
price(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int id, int offset, int big)
{
gint size = (big)?19:10;
gint size = (big) ? 19 : 10;
const char *str_value = tvb_get_string(wmem_packet_scope(), tvb, offset, size);
gdouble value = guint64_to_gdouble(g_ascii_strtoull(str_value, NULL, 10))/((big)?1000000.0:10000.0);
gdouble value = guint64_to_gdouble(g_ascii_strtoull(str_value, NULL, 10))/((big)?1000000.0:10000.0);
proto_tree_add_double(nasdaq_itch_tree, id, tvb, offset, size, value);
col_append_fstr(pinfo->cinfo, COL_INFO, "price %g ", value);
return offset+size;
return offset + size;
}
/* -------------------------- */
@ -227,7 +227,7 @@ stock(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int offse
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_stock, tvb, offset, 6, ENC_ASCII|ENC_NA);
col_append_fstr(pinfo->cinfo, COL_INFO, "<%s> ", stock_p);
return offset+6;
return offset + 6;
}
/* -------------------------- */
@ -269,181 +269,184 @@ executed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *nasdaq_itch_tree, int of
static void
dissect_nasdaq_itch(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
proto_item *ti;
proto_tree *nasdaq_itch_tree = NULL;
guint8 nasdaq_itch_type;
int offset = 0;
int version = 3;
int big = 0;
const gchar *rep;
proto_item *ti;
proto_tree *nasdaq_itch_tree = NULL;
guint8 nasdaq_itch_type;
int offset = 0;
int version = 3;
int big = 0;
const gchar *rep;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Nasdaq-ITCH");
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Nasdaq-ITCH");
nasdaq_itch_type = tvb_get_guint8(tvb, offset);
if (nasdaq_itch_type >= '0' && nasdaq_itch_type <= '9') {
version = 2;
nasdaq_itch_type = tvb_get_guint8(tvb, offset +8);
}
nasdaq_itch_type = tvb_get_guint8(tvb, offset);
if (nasdaq_itch_type >= '0' && nasdaq_itch_type <= '9') {
version = 2;
nasdaq_itch_type = tvb_get_guint8(tvb, offset +8);
}
if ((!nasdaq_itch_chi_x || version == 3) && strchr(chix_msg, nasdaq_itch_type)) {
nasdaq_itch_type = 0; /* unknown */
}
if ((!nasdaq_itch_chi_x || version == 3) && strchr(chix_msg, nasdaq_itch_type)) {
nasdaq_itch_type = 0; /* unknown */
}
rep = val_to_str(nasdaq_itch_type, message_types_val, "Unknown packet type (0x%02x) ");
col_add_str(pinfo->cinfo, COL_INFO, rep);
rep = val_to_str(nasdaq_itch_type, message_types_val, "Unknown packet type (0x%02x) ");
col_add_str(pinfo->cinfo, COL_INFO, rep);
if (tree) {
proto_item *item;
if (tree) {
proto_item *item;
ti = proto_tree_add_protocol_format(tree, proto_nasdaq_itch, tvb, offset, -1, "Nasdaq TotalView-ITCH %s, %s",
version == 2?"2.0":"3.0", rep);
ti = proto_tree_add_protocol_format(tree, proto_nasdaq_itch, tvb, offset, -1, "Nasdaq TotalView-ITCH %s, %s",
version == 2?"2.0":"3.0", rep);
nasdaq_itch_tree = proto_item_add_subtree(ti, ett_nasdaq_itch);
nasdaq_itch_tree = proto_item_add_subtree(ti, ett_nasdaq_itch);
item=proto_tree_add_uint(nasdaq_itch_tree, hf_nasdaq_itch_version, tvb, 0, 0, version);
PROTO_ITEM_SET_GENERATED(item);
}
item = proto_tree_add_uint(nasdaq_itch_tree, hf_nasdaq_itch_version, tvb, 0, 0, version);
PROTO_ITEM_SET_GENERATED(item);
}
if (version == 2) {
offset = time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_millisecond, offset, 8);
}
if (version == 2) {
offset = time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_millisecond, offset, 8);
}
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_message_type, tvb, offset, 1, ENC_BIG_ENDIAN);
offset++;
if (version == 3) {
switch (nasdaq_itch_type) {
case 'T': /* seconds */
/*offset =*/ time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_second, offset, 5);
return;
case 'M': /* milliseconds */
/*offset =*/ time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_millisecond, offset, 3);
return;
}
}
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_message_type, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
if (version == 3) {
switch (nasdaq_itch_type) {
case 'S': /* system event */
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_system_event, tvb, offset, 1, ENC_BIG_ENDIAN);
offset++;
break;
case 'T': /* seconds */
/*offset =*/ time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_second, offset, 5);
return;
case 'R': /* Stock Directory */
offset = stock(tvb, pinfo, nasdaq_itch_tree, offset);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_market_category, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_financial_status, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_round_lot_size, tvb, offset, 6, ENC_ASCII|ENC_NA);
offset += 6;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_round_lots_only, tvb, offset, 1, ENC_BIG_ENDIAN);
/*offset += 1;*/
break;
case 'H': /* Stock trading action */
offset = stock(tvb, pinfo, nasdaq_itch_tree, offset);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_trading_state, tvb, offset, 1, ENC_ASCII|ENC_NA);
offset += 1;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_reserved, tvb, offset, 1, ENC_ASCII|ENC_NA);
offset += 1;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_reason, tvb, offset, 4, ENC_ASCII|ENC_NA);
/*offset += 4;*/
break;
case 'a' :
big = 1;
case 'A': /* Add order, no MPID */
offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big);
if (version == 2) {
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_printable, tvb, offset, 1, ENC_ASCII|ENC_NA);
/*offset += 1;*/
}
break;
case 'F': /* Add order, MPID */
offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_attribution, tvb, offset, 4, ENC_ASCII|ENC_NA);
/*offset += 4;*/
break;
case 'e' :
big = 1;
case 'E' : /* Order executed */
/*offset =*/ executed(tvb, pinfo, nasdaq_itch_tree, offset, big);
break;
case 'C' : /* Order executed with price */
offset = executed(tvb, pinfo, nasdaq_itch_tree, offset, big);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_printable, tvb, offset, 1, ENC_ASCII|ENC_NA);
offset += 1;
/*offset = */price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_execution_price, offset, big);
break;
case 'x' :
big = 1;
case 'X' : /* Order cancel */
offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset);
/*offset = */number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_canceled, offset, big);
break;
case 'D' : /* Order delete */
/*offset = */order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset);
/*offset += 9;*/
break;
case 'p' :
big = 1;
case 'P' : /* Trade identifier */
offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA);
/*offset += 9;*/
break;
case 'Q' : /* Cross Trade */
offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_shares, offset, big);
offset = stock(tvb, pinfo, nasdaq_itch_tree, offset);
offset = price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_price, offset, big);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA);
offset += 9;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_cross, tvb, offset, 1, ENC_ASCII|ENC_NA);
/*offset += 1;*/
break;
case 'B' : /* Broken Trade */
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA);
/*offset += 9;*/
break;
case 'I': /* NOII, FIXME */
offset = stock(tvb, pinfo, nasdaq_itch_tree, offset);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_cross, tvb, offset, 1, ENC_ASCII|ENC_NA);
/*offset += 1;*/
break;
default:
/* unknown */
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_message, tvb, offset, -1, ENC_ASCII|ENC_NA);
/*offset += 5-1;*/
break;
case 'M': /* milliseconds */
/*offset =*/ time_stamp (tvb, nasdaq_itch_tree, hf_nasdaq_itch_millisecond, offset, 3);
return;
}
}
switch (nasdaq_itch_type) {
case 'S': /* system event */
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_system_event, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
break;
case 'R': /* Stock Directory */
offset = stock(tvb, pinfo, nasdaq_itch_tree, offset);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_market_category, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_financial_status, tvb, offset, 1, ENC_BIG_ENDIAN);
offset += 1;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_round_lot_size, tvb, offset, 6, ENC_ASCII|ENC_NA);
offset += 6;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_round_lots_only, tvb, offset, 1, ENC_BIG_ENDIAN);
/*offset += 1;*/
break;
case 'H': /* Stock trading action */
offset = stock(tvb, pinfo, nasdaq_itch_tree, offset);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_trading_state, tvb, offset, 1, ENC_ASCII|ENC_NA);
offset += 1;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_reserved, tvb, offset, 1, ENC_ASCII|ENC_NA);
offset += 1;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_reason, tvb, offset, 4, ENC_ASCII|ENC_NA);
/*offset += 4;*/
break;
case 'a' :
big = 1;
case 'A': /* Add order, no MPID */
offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big);
if (version == 2) {
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_printable, tvb, offset, 1, ENC_ASCII|ENC_NA);
/*offset += 1;*/
}
break;
case 'F': /* Add order, MPID */
offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_attribution, tvb, offset, 4, ENC_ASCII|ENC_NA);
/*offset += 4;*/
break;
case 'e' :
big = 1;
case 'E' : /* Order executed */
/*offset =*/ executed(tvb, pinfo, nasdaq_itch_tree, offset, big);
break;
case 'C' : /* Order executed with price */
offset = executed(tvb, pinfo, nasdaq_itch_tree, offset, big);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_printable, tvb, offset, 1, ENC_ASCII|ENC_NA);
offset += 1;
/*offset = */price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_execution_price, offset, big);
break;
case 'x' :
big = 1;
case 'X' : /* Order cancel */
offset = order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset);
/*offset = */number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_canceled, offset, big);
break;
case 'D' : /* Order delete */
/*offset = */order_ref_number(tvb, pinfo, nasdaq_itch_tree, offset);
/*offset += 9;*/
break;
case 'p' :
big = 1;
case 'P' : /* Trade identifier */
offset = order(tvb, pinfo, nasdaq_itch_tree, offset, big);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA);
/*offset += 9;*/
break;
case 'Q' : /* Cross Trade */
offset = number_of_shares(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_shares, offset, big);
offset = stock(tvb, pinfo, nasdaq_itch_tree, offset);
offset = price(tvb, pinfo, nasdaq_itch_tree, hf_nasdaq_itch_price, offset, big);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA);
offset += 9;
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_cross, tvb, offset, 1, ENC_ASCII|ENC_NA);
/*offset += 1;*/
break;
case 'B' : /* Broken Trade */
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_match, tvb, offset, 9, ENC_ASCII|ENC_NA);
/*offset += 9;*/
break;
case 'I': /* NOII, FIXME */
offset = stock(tvb, pinfo, nasdaq_itch_tree, offset);
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_cross, tvb, offset, 1, ENC_ASCII|ENC_NA);
/*offset += 1;*/
break;
default:
/* unknown */
proto_tree_add_item(nasdaq_itch_tree, hf_nasdaq_itch_message, tvb, offset, -1, ENC_ASCII|ENC_NA);
/*offset += 5-1;*/
break;
}
}
/* Register the protocol with Wireshark */
void proto_reg_handoff_nasdaq_itch(void);
void proto_register_nasdaq_itch(void);
void
proto_register_nasdaq_itch(void)
{
/* Setup list of header fields See Section 1.6.1 for details*/
static hf_register_info hf[] = {
static hf_register_info hf[] = {
{ &hf_nasdaq_itch_version,
{ "Version", "nasdaq-itch.version",
FT_UINT8, BASE_DEC, NULL, 0x0,
@ -568,37 +571,45 @@ proto_register_nasdaq_itch(void)
{ "Message", "nasdaq-itch.message",
FT_STRING, BASE_NONE, NULL, 0x0,
NULL, HFILL }}
};
};
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_nasdaq_itch
};
static gint *ett[] = {
&ett_nasdaq_itch
};
module_t *nasdaq_itch_module;
module_t *nasdaq_itch_module;
/* Register the protocol name and description */
proto_nasdaq_itch = proto_register_protocol("Nasdaq TotalView-ITCH", "NASDAQ-ITCH", "nasdaq_itch");
/* Register the protocol name and description */
proto_nasdaq_itch = proto_register_protocol("Nasdaq TotalView-ITCH", "NASDAQ-ITCH", "nasdaq_itch");
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_nasdaq_itch, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_nasdaq_itch, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
nasdaq_itch_module = prefs_register_protocol(proto_nasdaq_itch, NULL);
prefs_register_bool_preference(nasdaq_itch_module, "chi_x", "Decode Chi X extensions",
"Whether the Nasdaq ITCH dissector should decode Chi X extensions.",
&nasdaq_itch_chi_x);
nasdaq_itch_module = prefs_register_protocol(proto_nasdaq_itch, NULL);
prefs_register_bool_preference(nasdaq_itch_module, "chi_x", "Decode Chi X extensions",
"Whether the Nasdaq ITCH dissector should decode Chi X extensions.",
&nasdaq_itch_chi_x);
register_dissector("nasdaq-itch", dissect_nasdaq_itch, proto_nasdaq_itch);
register_dissector("nasdaq-itch", dissect_nasdaq_itch, proto_nasdaq_itch);
}
/* If this dissector uses sub-dissector registration add a registration routine.
This format is required because a script is used to find these routines and
create the code that calls these routines.
*/
void
proto_reg_handoff_nasdaq_itch(void)
{
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 2
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=2 tabstop=8 expandtab:
* :indentSize=2:tabSize=8:noTabs=true:
*/