Make tvb_pbrk_guint8() return the found needle.

svn path=/trunk/; revision=32144
This commit is contained in:
Anders Broman 2010-03-08 20:45:13 +00:00
parent 990454aa93
commit 25af78517e
5 changed files with 46 additions and 43 deletions

View File

@ -337,8 +337,9 @@ get_unquoted_string(tvbuff_t *tvb, gint offset, gint *next_offset, guint *len)
const guint8* s = NULL;
guint l = 0;
gint o;
guchar found_needle = 0;
o = tvb_pbrk_guint8(tvb, offset, -1, (const guint8*)" \t\r\n");
o = tvb_pbrk_guint8(tvb, offset, -1, (const guint8*)" \t\r\n", NULL);
if (o != -1) {
l = o - offset;
s = tvb_get_ptr(tvb, offset, l);

View File

@ -989,7 +989,7 @@ static void dissect_sdp_session_attribute(tvbuff_t *tvb, packet_info * pinfo, pr
offset = next_offset + 1;
if (strcmp((char*)field_name, "ipbcp") == 0) {
offset = tvb_pbrk_guint8(tvb,offset,-1,(guint8 *)"0123456789");
offset = tvb_pbrk_guint8(tvb,offset,-1,(guint8 *)"0123456789", NULL);
if (offset == -1)
return;
@ -1003,7 +1003,7 @@ static void dissect_sdp_session_attribute(tvbuff_t *tvb, packet_info * pinfo, pr
proto_tree_add_item(sdp_session_attribute_tree,hf_ipbcp_version,tvb,offset,tokenlen,FALSE);
offset = tvb_pbrk_guint8(tvb,offset,-1,(guint8 *)"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
offset = tvb_pbrk_guint8(tvb,offset,-1,(guint8 *)"ABCDEFGHIJKLMNOPQRSTUVWXYZ", NULL);
if (offset == -1)
return;

View File

@ -679,7 +679,7 @@ static gboolean sip_is_known_request(tvbuff_t *tvb, int meth_offset,
static gint sip_is_known_sip_header(tvbuff_t *tvb, int offset,
guint header_len);
static void dfilter_sip_request_line(tvbuff_t *tvb, proto_tree *tree,
guint meth_len);
guint meth_len, gint linelen);
static void dfilter_sip_status_line(tvbuff_t *tvb, proto_tree *tree);
static void tvb_raw_text_add(tvbuff_t *tvb, int offset, int length, proto_tree *tree);
static guint sip_is_packet_resend(packet_info *pinfo,
@ -1967,7 +1967,7 @@ dissect_sip_common(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tr
tvb_format_text(tvb, offset, linelen));
reqresp_tree = proto_item_add_subtree(ti_a, ett_sip_reqresp);
}
dfilter_sip_request_line(tvb, reqresp_tree, token_1_len);
dfilter_sip_request_line(tvb, reqresp_tree, token_1_len, linelen);
break;
case STATUS_LINE:
@ -2789,34 +2789,34 @@ separator_found:
offset, next_offset-offset,
FALSE);
PROTO_ITEM_SET_HIDDEN(ti_c);
}
/* Parse each individual parameter in the line */
comma_offset = tvb_pbrk_guint8(tvb, value_offset, line_end_offset - value_offset, " \t\r\n");
/* Parse each individual parameter in the line */
comma_offset = tvb_pbrk_guint8(tvb, value_offset, line_end_offset - value_offset, " \t\r\n", NULL);
/* Authentication-Info does not begin with the scheme name */
if (hf_index != POS_AUTHENTICATION_INFO)
{
proto_tree_add_item(sip_element_tree, hf_sip_auth_scheme,
tvb, value_offset, comma_offset - value_offset,
FALSE);
}
while ((comma_offset = dissect_sip_authorization_item(tvb, sip_element_tree, comma_offset, line_end_offset)) != -1)
{
if(comma_offset == line_end_offset)
/* Authentication-Info does not begin with the scheme name */
if (hf_index != POS_AUTHENTICATION_INFO)
{
/* Line End reached: Stop Parsing */
break;
proto_tree_add_item(sip_element_tree, hf_sip_auth_scheme,
tvb, value_offset, comma_offset - value_offset,
FALSE);
}
if(tvb_get_guint8(tvb, comma_offset) != ',')
while ((comma_offset = dissect_sip_authorization_item(tvb, sip_element_tree, comma_offset, line_end_offset)) != -1)
{
/* Undefined value reached: Stop Parsing */
break;
if(comma_offset == line_end_offset)
{
/* Line End reached: Stop Parsing */
break;
}
if(tvb_get_guint8(tvb, comma_offset) != ',')
{
/* Undefined value reached: Stop Parsing */
break;
}
comma_offset++; /* skip comma */
}
comma_offset++; /* skip comma */
}
}/*hdr_tree*/
break;
case POS_VIA:
@ -3023,11 +3023,11 @@ separator_found:
/* Display filter for SIP Request-Line */
static void
dfilter_sip_request_line(tvbuff_t *tvb, proto_tree *tree, guint meth_len)
dfilter_sip_request_line(tvbuff_t *tvb, proto_tree *tree, guint meth_len, gint linelen)
{
char *value;
gint next_offset, linelen, parameter_end_offset;
gint parameter_end_offset;
guint offset = 0;
guint parameter_len = meth_len;
guchar c= '\0';
@ -3048,8 +3048,6 @@ dfilter_sip_request_line(tvbuff_t *tvb, proto_tree *tree, guint meth_len)
/* Copy request method for telling tap */
stat_info->request_method = value;
linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
if (tree) {
proto_tree_add_string(tree, hf_Method, tvb, offset, parameter_len, value);

View File

@ -970,7 +970,7 @@ guint8_find(const guint8* haystack, size_t haystacklen, guint8 needle)
}
static const guint8*
guint8_pbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles)
guint8_pbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles, guchar *found_needle)
{
const guint8 *b;
int i;
@ -981,8 +981,11 @@ guint8_pbrk(const guint8* haystack, size_t haystacklen, const guint8 *needles)
item = *b;
needlep = needles;
while ((needle = *needlep) != '\0') {
if (item == needle)
if (item == needle){
if(found_needle)
*found_needle = needle;
return b;
}
needlep++;
}
}
@ -1856,7 +1859,7 @@ tvb_find_guint8(tvbuff_t *tvb, gint offset, gint maxlength, guint8 needle)
* in that case, -1 will be returned if the boundary is reached before
* finding needle. */
gint
tvb_pbrk_guint8(tvbuff_t *tvb, gint offset, gint maxlength, const guint8 *needles)
tvb_pbrk_guint8(tvbuff_t *tvb, gint offset, gint maxlength, const guint8 *needles, guchar *found_needle)
{
const guint8 *result;
guint abs_offset, junk_length;
@ -1886,7 +1889,7 @@ tvb_pbrk_guint8(tvbuff_t *tvb, gint offset, gint maxlength, const guint8 *needle
/* If we have real data, perform our search now. */
if (tvb->real_data) {
result = guint8_pbrk(tvb->real_data + abs_offset, limit, needles);
result = guint8_pbrk(tvb->real_data + abs_offset, limit, needles, found_needle);
if (result == NULL) {
return -1;
}
@ -1902,7 +1905,7 @@ tvb_pbrk_guint8(tvbuff_t *tvb, gint offset, gint maxlength, const guint8 *needle
case TVBUFF_SUBSET:
return tvb_pbrk_guint8(tvb->tvbuffs.subset.tvb,
abs_offset - tvb->tvbuffs.subset.offset,
limit, needles);
limit, needles, found_needle);
case TVBUFF_COMPOSITE:
DISSECTOR_ASSERT_NOT_REACHED();
@ -2529,6 +2532,7 @@ tvb_find_line_end(tvbuff_t *tvb, gint offset, int len, gint *next_offset,
gint eob_offset;
gint eol_offset;
int linelen;
guchar found_needle = 0;
if (len == -1)
len = tvb_length_remaining(tvb, offset);
@ -2541,7 +2545,7 @@ tvb_find_line_end(tvbuff_t *tvb, gint offset, int len, gint *next_offset,
/*
* Look either for a CR or an LF.
*/
eol_offset = tvb_pbrk_guint8(tvb, offset, len, (const guint8 *)"\r\n");
eol_offset = tvb_pbrk_guint8(tvb, offset, len, (const guint8 *)"\r\n", &found_needle);
if (eol_offset == -1) {
/*
* No CR or LF - line is presumably continued in next packet.
@ -2570,8 +2574,8 @@ tvb_find_line_end(tvbuff_t *tvb, gint offset, int len, gint *next_offset,
/*
* Is it a CR?
*/
if (tvb_get_guint8(tvb, eol_offset) == '\r') {
*/
if (found_needle == '\r') {
/*
* Yes - is it followed by an LF?
*/
@ -2643,7 +2647,7 @@ tvb_find_line_end_unquoted(tvbuff_t *tvb, gint offset, int len,
{
gint cur_offset, char_offset;
gboolean is_quoted;
guchar c;
guchar c = 0;
gint eob_offset;
int linelen;
@ -2672,7 +2676,7 @@ tvb_find_line_end_unquoted(tvbuff_t *tvb, gint offset, int len,
* Look either for a CR, an LF, or a '"'.
*/
char_offset = tvb_pbrk_guint8(tvb, cur_offset, len,
(const guint8 *)"\r\n\"");
(const guint8 *)"\r\n\"", &c);
}
if (char_offset == -1) {
/*
@ -2698,7 +2702,6 @@ tvb_find_line_end_unquoted(tvbuff_t *tvb, gint offset, int len,
/*
* OK, what is it?
*/
c = tvb_get_guint8(tvb, char_offset);
if (c == '"') {
/*
* Un-quoted "; it begins a quoted

View File

@ -413,11 +413,12 @@ extern gint tvb_find_guint8(tvbuff_t*, gint offset, gint maxlength,
/** Find first occurence of any of the needles in tvbuff, starting at offset.
* Searches at most maxlength number of bytes. Returns the offset of the
* found needle, or -1 if not found. Will not throw an exception, even if
* found needle, or -1 if not found and the found needle.
* Will not throw an exception, even if
* maxlength exceeds boundary of tvbuff; in that case, -1 will be returned if
* the boundary is reached before finding needle. */
extern gint tvb_pbrk_guint8(tvbuff_t *, gint offset, gint maxlength,
const guint8 *needles);
const guint8 *needles, guchar *found_needle);
/** Find size of stringz (NUL-terminated string) by looking for terminating
* NUL. The size of the string includes the terminating NUL.