Use correct subtree for proto_tree_add_item in several places: Coverity 1130 [UNUSED];

Also: Reformat a few lines and do some whitespace cleanup.

svn path=/trunk/; revision=37357
This commit is contained in:
Bill Meier 2011-05-23 14:11:14 +00:00
parent c13f268e8b
commit a9652ea66e
1 changed files with 217 additions and 214 deletions

View File

@ -30,16 +30,14 @@
# include "config.h"
#endif
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <glib.h>
#include <epan/packet.h>
/* Pre definitions */
void proto_reg_handoff_xcsl(void);
/* string array size */
#define MAXLEN 4096
@ -69,16 +67,16 @@ static gint ett_xcsl = -1;
/* Result code meanings. */
static const value_string xcsl_action_vals[] = {
{ XCSL_SUCCESS, "Success" },
{ XCSL_UNKNOWN, "Unknown" },
{ XCSL_USRUNKN, "User unknown" },
{ XCSL_ERROR, "Error" },
{ XCSL_BUSY, "Busy" },
{ XCSL_UNDEFINED, "Undefined" },
{ XCSL_MORE, "More" },
{ XCSL_MAINT, "Maintenance" },
{ XCSL_PROTSEQERR, "Protocol Sequence Error" },
{ 0, NULL }
{ XCSL_SUCCESS, "Success" },
{ XCSL_UNKNOWN, "Unknown" },
{ XCSL_USRUNKN, "User unknown" },
{ XCSL_ERROR, "Error" },
{ XCSL_BUSY, "Busy" },
{ XCSL_UNDEFINED, "Undefined" },
{ XCSL_MORE, "More" },
{ XCSL_MAINT, "Maintenance" },
{ XCSL_PROTSEQERR, "Protocol Sequence Error" },
{ 0, NULL }
};
/* This routine gets the next item from the ';' separated list */
@ -89,18 +87,18 @@ static gboolean get_next_item(tvbuff_t *tvb, gint offset, gint maxlen, guint8 *s
/* Obtain items */
while (maxlen > 1) {
ch = tvb_get_guint8(tvb, offset+idx);
if (ch == ';' || ch == '\r' || ch == '\n')
break;
/* Array protect */
if (idx==MAXLEN) {
*next_offset = offset + idx;
*len = idx;
return FALSE;
}
/* Copy data into string array */
str[idx++] = ch;
maxlen--;
ch = tvb_get_guint8(tvb, offset+idx);
if (ch == ';' || ch == '\r' || ch == '\n')
break;
/* Array protect */
if (idx==MAXLEN) {
*next_offset = offset + idx;
*len = idx;
return FALSE;
}
/* Copy data into string array */
str[idx++] = ch;
maxlen--;
}
/* Null terminate the item */
str[idx] = '\0';
@ -115,244 +113,249 @@ static gboolean get_next_item(tvbuff_t *tvb, gint offset, gint maxlen, guint8 *s
/* Dissector for xcsl */
static void dissect_xcsl_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
guint offset = 0;
gint length_remaining;
guint8 idx;
gboolean request;
guint8 par;
guint8 str[MAXLEN];
guint8 result;
const gchar *code;
guint len;
gint next_offset;
proto_item *xcsl_item = NULL;
proto_tree *xcsl_tree = NULL;
guint offset = 0;
gint length_remaining;
guint8 idx;
gboolean request;
guint8 par;
guint8 str[MAXLEN];
guint8 result;
const gchar *code;
guint len;
gint next_offset;
proto_tree *xcsl_tree = NULL;
/* color support */
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Xcsl");
col_clear(pinfo->cinfo, COL_INFO);
/* color support */
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Xcsl");
col_clear(pinfo->cinfo, COL_INFO);
/* Create display tree for the xcsl protocol */
if (tree) {
xcsl_item = proto_tree_add_item(tree, proto_xcsl,tvb, offset, -1, FALSE);
xcsl_tree = proto_item_add_subtree(xcsl_item, ett_xcsl);
}
/* Create display tree for the xcsl protocol */
if (tree) {
proto_item *xcsl_item;
xcsl_item = proto_tree_add_item(tree, proto_xcsl, tvb, offset, -1, FALSE);
xcsl_tree = proto_item_add_subtree(xcsl_item, ett_xcsl);
}
/* reset idx */
idx = 0;
/* reset idx */
idx = 0;
/* reset the parameter count */
par = 0;
/* reset the parameter count */
par = 0;
/* switch whether it concerns a command or an answer */
request = FALSE;
/* switch whether it concerns a command or an answer */
request = FALSE;
while (tvb_reported_length_remaining(tvb, offset) != 0) {
while (tvb_reported_length_remaining(tvb, offset) != 0) {
length_remaining = tvb_ensure_length_remaining(tvb, offset);
if ( length_remaining == -1 ) {
return;
}
length_remaining = tvb_ensure_length_remaining(tvb, offset);
if ( length_remaining == -1 ) {
return;
}
/* get next item */
if (!(get_next_item(tvb, offset, length_remaining, str, &next_offset, &len))) {
/* do not continue when get_next_item returns false */
return;
}
/* get next item */
if (!(get_next_item(tvb, offset, length_remaining, str, &next_offset, &len))) {
/* do not continue when get_next_item returns false */
return;
}
/* do not add to the tree when the string is of zero length */
if ( strlen(str) == 0 ) {
offset = next_offset + 1;
continue;
}
/* do not add to the tree when the string is of zero length */
if ( strlen(str) == 0 ) {
offset = next_offset + 1;
continue;
}
/* Xcsl (Call Specification Language) protocol in brief :
*
* Request :
*
* <xcsl-version>;<transaction-id>;<command>;[parameter1;parameter2;parameter3;....]
*
* Reply :
*
* <xcsl-version>;transaction-id;<result>;[answer data;answer data];...
*
* If result is one or more digits, this is determined as a Reply.
*
* Example :
*
* --> xcsl-1.0;1000;offhook;+31356871234
* <-- xcsl-1.0;1000;0 <- success
*
* --> xcsl-1.0;1001;dial;+31356871234;+31356875678
* <-- xcsl-1.0;1001;0 <- success
*
*
* index : 0 1 2 3 4
*
* Index 2 represents the return code (see the xcsl_action_vals[] definitions)
*
*/
/* Xcsl (Call Specification Language) protocol in brief :
*
* Request :
*
* <xcsl-version>;<transaction-id>;<command>;[parameter1;parameter2;parameter3;....]
*
* Reply :
*
* <xcsl-version>;transaction-id;<result>;[answer data;answer data];...
*
* If result is one or more digits, this is determined as a Reply.
*
* Example :
*
* --> xcsl-1.0;1000;offhook;+31356871234
* <-- xcsl-1.0;1000;0 <- success
*
* --> xcsl-1.0;1001;dial;+31356871234;+31356875678
* <-- xcsl-1.0;1001;0 <- success
*
*
* index : 0 1 2 3 4
*
* Index 2 represents the return code (see the xcsl_action_vals[] definitions)
*
*/
/* One by one go through each item ';' separated */
switch (idx) {
/* One by one go through each item ';' separated */
switch (idx) {
/* This is the protocol item */
case 0: proto_tree_add_item(tree, hf_xcsl_protocol_version, tvb, offset, len, FALSE);
break;
/* This is the protocol item */
case 0:
proto_tree_add_item(xcsl_tree, hf_xcsl_protocol_version, tvb, offset, len, FALSE);
break;
/* This should be the transaction ID, if non-digit, it is treated as info */
case 1: if ( isdigit(str[0]) ) {
proto_tree_add_item(tree, hf_xcsl_transaction_id, tvb, offset, len, FALSE);
} else {
proto_tree_add_item(tree, hf_xcsl_information, tvb, offset, len, FALSE);
/* This should be the transaction ID, if non-digit, it is treated as info */
case 1:
if ( isdigit(str[0]) ) {
proto_tree_add_item(xcsl_tree, hf_xcsl_transaction_id, tvb, offset, len, FALSE);
} else {
proto_tree_add_item(xcsl_tree, hf_xcsl_information, tvb, offset, len, FALSE);
}
if (check_col(pinfo->cinfo, COL_INFO))
col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",str);
break;
/* Starting with non-digit -> Command, if it starts with a digit -> reply */
case 2:
if ( isdigit(str[0]) ) {
proto_item *xcsl_item;
request = FALSE;
result = atoi(str);
if ( result >= XCSL_NONE ) {
result = XCSL_UNDEFINED;
}
code = val_to_str(result, xcsl_action_vals, "Unknown: %d");
/* Print result code and description */
xcsl_item = proto_tree_add_item(xcsl_tree, hf_xcsl_result, tvb, offset, len, FALSE);
proto_item_append_text(xcsl_item, " (%s)", code);
if (result != 0 && check_col(pinfo->cinfo, COL_INFO))
col_append_fstr(pinfo->cinfo, COL_INFO, "[%s] ", code);
} else {
request = TRUE;
proto_tree_add_item(xcsl_tree, hf_xcsl_command, tvb, offset, len, FALSE);
if (check_col(pinfo->cinfo, COL_INFO))
col_append_fstr(pinfo->cinfo, COL_INFO, "%s ",str);
break;
col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", str);
/* Starting with non-digit -> Command, if it starts with a digit -> reply */
case 2: if ( isdigit(str[0]) ) {
}
break;
request = FALSE;
result = atoi(str);
if ( result >= XCSL_NONE ) {
result = XCSL_UNDEFINED;
}
code = val_to_str(result, xcsl_action_vals, "Unknown: %d");
/* Print result code and description */
xcsl_item = proto_tree_add_item(tree, hf_xcsl_result, tvb, offset, len, FALSE);
proto_item_append_text(xcsl_item, " (%s)", code);
if (result != 0 && check_col(pinfo->cinfo, COL_INFO))
col_append_fstr(pinfo->cinfo, COL_INFO, "[%s] ", code);
/* This is a command parameter */
default:
proto_tree_add_item(xcsl_tree, hf_xcsl_parameter, tvb, offset, len, FALSE);
if (check_col(pinfo->cinfo, COL_INFO)) {
if ( request == TRUE ) {
col_append_fstr(pinfo->cinfo, COL_INFO, ": %s ",str);
} else {
request = TRUE;
proto_tree_add_item(tree, hf_xcsl_command, tvb, offset, len, FALSE);
if (check_col(pinfo->cinfo, COL_INFO))
col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", str);
if (par == 0) {
col_append_fstr(pinfo->cinfo, COL_INFO, "reply: %s ",str);
} else {
col_append_fstr(pinfo->cinfo, COL_INFO, ": %s ",str);
}
}
break;
}
/* This is a command parameter */
default: proto_tree_add_item(tree, hf_xcsl_parameter, tvb, offset, len, FALSE);
/* increment the parameter count */
par++;
if (check_col(pinfo->cinfo, COL_INFO)) {
if ( request == TRUE ) {
col_append_fstr(pinfo->cinfo, COL_INFO, ": %s ",str);
} else {
if (par == 0) {
col_append_fstr(pinfo->cinfo, COL_INFO, "reply: %s ",str);
} else {
col_append_fstr(pinfo->cinfo, COL_INFO, ": %s ",str);
}
}
}
break;
}
/* increment the parameter count */
par++;
offset = next_offset + 1;
idx++;
break;
}
offset = next_offset + 1;
idx++;
}
}
return;
return;
}
/* This function determines whether the first 4 octets equals to xcsl and the fifth is an ; or - */
static gboolean dissect_xcsl_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
gint offset = 0;
guint8 *protocol;
gint offset = 0;
guint8 *protocol;
if (tvb_length_remaining (tvb, offset) >= 5) {
protocol = tvb_get_ephemeral_string(tvb, offset, 5);
if (tvb_length_remaining (tvb, offset) >= 5) {
protocol = tvb_get_ephemeral_string(tvb, offset, 5);
if (strncmp(protocol,"xcsl",4) == 0 && (protocol[4] == ';' || protocol[4] == '-')) {
if (strncmp(protocol,"xcsl",4) == 0 && (protocol[4] == ';' || protocol[4] == '-')) {
/* Disssect it as being an xcsl message */
dissect_xcsl_tcp(tvb, pinfo, tree);
/* Disssect it as being an xcsl message */
dissect_xcsl_tcp(tvb, pinfo, tree);
return TRUE;
}
}
return TRUE;
}
}
return FALSE;
return FALSE;
}
/* register the various xcsl protocol filters */
void proto_register_xcsl(void) {
static hf_register_info hf[] = {
static hf_register_info hf[] = {
{ &hf_xcsl_protocol_version,
{ "Protocol Version", "xcsl.protocol_version",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
{ &hf_xcsl_protocol_version,
{ "Protocol Version", "xcsl.protocol_version",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
},
{ &hf_xcsl_transaction_id,
{ "Transaction ID", "xcsl.transacion_id",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
},
{ &hf_xcsl_command,
{ "Command", "xcsl.command",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
},
{ &hf_xcsl_result,
{ "Result", "xcsl.result",
FT_STRING, BASE_NONE,NULL, 0x0,
NULL, HFILL
}
},
{ &hf_xcsl_parameter,
{ "Parameter", "xcsl.parameter",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
},
{ &hf_xcsl_information,
{ "Information", "xcsl.information",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
}
},
};
{ &hf_xcsl_transaction_id,
{ "Transaction ID", "xcsl.transacion_id",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
},
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_xcsl
};
{ &hf_xcsl_command,
{ "Command", "xcsl.command",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
},
/* Register the protocol name and description */
proto_xcsl = proto_register_protocol("Call Specification Language (Xcsl)", "XCSL", "xcsl");
{ &hf_xcsl_result,
{ "Result", "xcsl.result",
FT_STRING, BASE_NONE,NULL, 0x0,
NULL, HFILL
}
},
{ &hf_xcsl_parameter,
{ "Parameter", "xcsl.parameter",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
},
{ &hf_xcsl_information,
{ "Information", "xcsl.information",
FT_STRING, BASE_NONE,NULL,0x0,
NULL, HFILL
}
}
};
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_xcsl
};
/* Register the protocol name and description */
proto_xcsl = proto_register_protocol("Call Specification Language (Xcsl)", "XCSL", "xcsl");
/* Required function calls to register the header fields and subtrees used */
proto_register_field_array(proto_xcsl, 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_xcsl, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
/* In case it concerns TCP, try to match on the xcsl header */
void proto_reg_handoff_xcsl(void) {
heur_dissector_add("tcp", dissect_xcsl_tcp_heur, proto_xcsl);
heur_dissector_add("tcp", dissect_xcsl_tcp_heur, proto_xcsl);
}