Enhance MRCPv2 dissector * Fix indent (Tab => 4 Spaces) and add Modelines info * Replace by string_string * Replace if else if... by switch()

svn path=/trunk/; revision=47146
This commit is contained in:
Alexis La Goutte 2013-01-18 15:51:33 +00:00
parent 39b51c7c07
commit b4cdfdc5f1
1 changed files with 1241 additions and 1289 deletions

View File

@ -380,84 +380,25 @@ static gint ett_Event_Line = -1;
static gint ett_Status_Code = -1;
/* format status code description */
void
get_status_code_description(gint status_code, gchar *text, int size)
{
switch(status_code)
{
case 200:
g_snprintf(text, size, "Success");
break;
case 201:
g_snprintf(text, size, "Success with some optional header fields ignored");
break;
case 401:
g_snprintf(text, size, "Client Failure:\n"
"\tMethod not allowed");
break;
case 402:
g_snprintf(text, size, "Client Failure:\n"
"\tMethod not valid in this state");
break;
case 403:
g_snprintf(text, size, "Client Failure:\n"
"\tUnsupported header field");
break;
case 404:
g_snprintf(text, size, "Client Failure:\n"
"\tIllegal value for header field. This is the error\n"
"\tfor a syntax violation.");
break;
case 405:
g_snprintf(text, size, "Client Failure:\n"
"\tResource not allocated for this session or does not exist");
break;
case 406:
g_snprintf(text, size, "Client Failure:\n"
"\tMandatory Header Field Missing");
break;
case 407:
g_snprintf(text, size, "Client Failure:\n"
"\tMethod or Operation Failed (e.g., Grammar\n"
"\tcompilation failed in the recognizer. Detailed\n"
"\tcause codes might be available through a resource\n"
"\tspecific header.)");
break;
case 408:
g_snprintf(text, size, "Client Failure:\n"
"\tUnrecognized or unsupported message entity");
break;
case 409:
g_snprintf(text, size, "Client Failure:\n"
"\tUnsupported Header Field Value. This is a value\n"
"\tthat is syntactically legal but exceeds the\n"
"\timplementation's capabilities or expectations.");
break;
case 410:
g_snprintf(text, size, "Client Failure:\n"
"\tNon-Monotonic or Out of order sequence number in request.\n");
break;
case 501:
g_snprintf(text, size, "Server Failure:\n"
"\tServer Internal Error");
break;
case 502:
g_snprintf(text, size, "Server Failure:\n"
"\tProtocol Version not supported");
break;
case 503:
g_snprintf(text, size, "Server Failure:\n"
"\tReserved for future assignment");
break;
case 504:
g_snprintf(text, size, "Server Failure:\n"
"\tMessage too large");
break;
default:
g_snprintf(text, size, "Unknown status code");
break;
}
}
static const string_string status_code_vals[] = {
{ "200", "Success" },
{ "201", "Success with some optional header fields ignored" },
{ "401", "Client Failure: Method not allowed" },
{ "402", "Client Failure: Method not valid in this state" },
{ "403", "Client Failure: Unsupported header field" },
{ "404", "Client Failure: Illegal value for header field. This is the error for a syntax violation." },
{ "405", "Client Failure: Resource not allocated for this session or does not exist" },
{ "406", "Client Failure: Mandatory Header Field Missing" },
{ "407", "Client Failure: Method or Operation Failed (e.g., Grammar compilation failed in the recognizer. Detailed cause codes might be available through a resource specific header.)" },
{ "408", "Client Failure: Unrecognized or unsupported message entity" },
{ "409", "Client Failure: Unsupported Header Field Value. This is a value that is syntactically legal but exceeds the implementation's capabilities or expectations." },
{ "410", "Client Failure: Non-Monotonic or Out of order sequence number in request." },
{ "501", "Server Failure: Server Internal Error" },
{ "502", "Server Failure: Protocol Version not supported" },
{ "503", "Server Failure: Reserved for future assignment" },
{ "504", "Server Failure: Message too large" },
{ "", NULL }
};
/* Code to actually dissect the packets */
static int
@ -484,7 +425,6 @@ dissect_mrcpv2_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_item *request_line_item = NULL;
proto_item *response_line_item = NULL;
proto_item *event_line_item = NULL;
proto_item *status_code_line = NULL;
proto_item *status_code_item = NULL;
gint sp_start;
@ -566,7 +506,8 @@ dissect_mrcpv2_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
return -1;
/* process MRCP header line */
if (line_type == REQUEST_LINE)
switch(line_type){
case REQUEST_LINE:
{
col_add_str(pinfo->cinfo, COL_INFO, "Request: ");
line_item = proto_tree_add_item(mrcpv2_tree, hf_mrcpv2_Request_Line, tvb, offset, linelen, ENC_UTF_8);
@ -589,7 +530,8 @@ dissect_mrcpv2_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_item(request_line_item, hf_mrcpv2_request_id, tvb, offset, str_len, ENC_UTF_8);
offset += str_len + 2; /* add CRLF */
}
else if (line_type == RESPONSE_LINE)
break;
case RESPONSE_LINE:
{
col_add_str(pinfo->cinfo, COL_INFO, "Response: ");
line_item = proto_tree_add_item(mrcpv2_tree, hf_mrcpv2_Response_Line, tvb, offset, linelen, ENC_UTF_8);
@ -608,22 +550,18 @@ dissect_mrcpv2_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
offset += str_len + 1; /* add SP */
/* status code */
str_len = (gint)strlen(field4);
status_code_line = proto_tree_add_item(response_line_item, hf_mrcpv2_status_code, tvb, offset,
status_code_item = proto_tree_add_item(response_line_item, hf_mrcpv2_status_code, tvb, offset,
str_len, ENC_UTF_8);
status_code_item = proto_item_add_subtree(status_code_line, ett_Request_Line);
/* add status code description into the tree */
get_status_code_description(atoi(field4), helper_str, sizeof(helper_str));
proto_tree_add_string_format(status_code_item, hf_mrcpv2_status_code, tvb, offset, str_len,
helper_str, "%s", helper_str);
proto_item_append_text(status_code_item, " %s", str_to_str(field4, status_code_vals, "Unknown Status Code"));
offset += str_len + 1; /* add SP */
/* request state */
g_snprintf(helper_str, sizeof(helper_str), "(%s) %s", field4, field5);
col_append_str(pinfo->cinfo, COL_INFO, helper_str);
col_append_fstr(pinfo->cinfo, COL_INFO, "(%s) %s", field4, field5);
str_len = (gint)strlen(field5);
proto_tree_add_item(response_line_item, hf_mrcpv2_request_state, tvb, offset, str_len, ENC_UTF_8);
offset += str_len + 2; /* add CRLF */
}
else if (line_type == EVENT_LINE)
break;
case EVENT_LINE:
{
col_add_str(pinfo->cinfo, COL_INFO, "Event: ");
line_item = proto_tree_add_item(mrcpv2_tree, hf_mrcpv2_Event_Line, tvb, offset, linelen, ENC_UTF_8);
@ -650,13 +588,15 @@ dissect_mrcpv2_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
proto_tree_add_item(event_line_item, hf_mrcpv2_request_state, tvb, offset, str_len, ENC_UTF_8);
offset += str_len + 2; /* add CRLF */
}
else
break;
default:
{
/* mark whole packet as unknown and return */
col_add_str(pinfo->cinfo, COL_INFO, "UNKNOWN message");
proto_tree_add_item(mrcpv2_tree, hf_mrcpv2_Unknown_Message, tvb, offset, tvb_len, ENC_UTF_8);
return tvb_len;
}
}
/* process the rest of the header lines here */
content_length = 0;
@ -1547,3 +1487,15 @@ proto_reg_handoff_mrcpv2(void)
TCPPort = global_mrcpv2_tcp_port;
dissector_add_uint("tcp.port", TCPPort, mrcpv2_handle);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/