Add proto_tree_add_unicode_string() to add UTF-8 string to tree.

Convert some proto_tree_add_string_format_value(..., val, "%s", val); to use new function.

svn path=/trunk/; revision=43363
This commit is contained in:
Jakub Zawadzki 2012-06-19 14:32:24 +00:00
parent 7c59ac0280
commit 85aad38347
6 changed files with 37 additions and 31 deletions

View File

@ -434,12 +434,7 @@ dissect_gadu_gadu_stringz_cp1250(tvbuff_t *tvb, int hfindex, proto_tree *tree, i
if (len > 0)
offset++; /* NUL */
/* proto_item_fill_label() is broken for UTF-8 strings.
* It's using internally format_text() which doesn't support UTF-8
*
* So don't use proto_tree_add_string() but proto_tree_add_string_format_value()
*/
proto_tree_add_string_format_value(tree, hfindex, tvb, org_offset, offset - org_offset, str->str, "%s", str->str);
proto_tree_add_unicode_string(tree, hfindex, tvb, org_offset, offset - org_offset, str->str);
g_string_free(str, TRUE);
return offset;
@ -457,7 +452,9 @@ dissect_gadu_gadu_uint32_string_utf8(tvbuff_t *tvb, int hfindex, proto_tree *tre
offset += 4;
if (len > 0) {
/* The one below doesn't work, same reason like in dissect_gadu_gadu_stringz_cp1250() */
/* proto_item_fill_label() is broken for UTF-8 strings.
* It's using internally format_text() which doesn't support UTF-8
*/
/* proto_tree_add_item(tree, hfindex, tvb, offset, len, ENC_UTF_8|ENC_NA); */
/* Use workaround */
@ -468,7 +465,7 @@ dissect_gadu_gadu_uint32_string_utf8(tvbuff_t *tvb, int hfindex, proto_tree *tre
offset += len;
proto_tree_add_string_format_value(tree, hfindex, tvb, org_offset, offset - org_offset, str, "%s", str);
proto_tree_add_unicode_string(tree, hfindex, tvb, org_offset, offset - org_offset, str);
return offset;
}

View File

@ -2728,9 +2728,9 @@ dis_field_ud(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint32 length, gb
(udl > SMS_MAX_MESSAGE_SIZE ? SMS_MAX_MESSAGE_SIZE : udl),
tvb_get_ptr(tvb , offset , length) , messagebuf);
messagebuf[out_len] = '\0';
utf8_text = gsm_sms_chars_to_utf8(messagebuf, out_len);
proto_tree_add_string_format_value(subtree, hf_gsm_sms_text, tvb, offset,
length, utf8_text, "%s", utf8_text);
proto_tree_add_unicode_string(subtree, hf_gsm_sms_text, tvb, offset,
length,
gsm_sms_chars_to_utf8(messagebuf, out_len));
}
else
{
@ -2751,10 +2751,9 @@ dis_field_ud(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint32 length, gb
tvb_get_ptr(sm_tvb, total_sms_len, p_frag_params->length), messagebuf);
messagebuf[out_len] = '\0';
utf8_text = gsm_sms_chars_to_utf8(messagebuf, out_len);
proto_tree_add_string_format_value(subtree, hf_gsm_sms_text, sm_tvb,
total_sms_len, p_frag_params->length,
utf8_text, "%s", utf8_text);
proto_tree_add_unicode_string(subtree, hf_gsm_sms_text, sm_tvb,
total_sms_len, p_frag_params->length,
gsm_sms_chars_to_utf8(messagebuf, out_len));
total_sms_len += p_frag_params->length;
}
@ -2779,6 +2778,7 @@ dis_field_ud(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint32 length, gb
}
else if (ucs2)
{
/* XXX, use tvb_get_ephemeral_unicode_string(.., ENC_BIG_ENDIAN); */
if ((cd = g_iconv_open("UTF-8","UCS-2BE")) != (GIConv)-1)
{
guint8 rep_len = tvb_reported_length(sm_tvb);
@ -2788,9 +2788,8 @@ dis_field_ud(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint32 length, gb
/* Show unreassembled SMS */
utf8_text = g_convert_with_iconv(tvb_get_ptr(sm_tvb, 0, rep_len), rep_len , cd , NULL , NULL , &l_conv_error);
if(!l_conv_error) {
/* XXX - using proto_tree_add_string() doesn't work */
ucs2_item = proto_tree_add_string_format_value(subtree, hf_gsm_sms_text, tvb,
offset, length, utf8_text, "%s", utf8_text);
ucs2_item = proto_tree_add_unicode_string(subtree, hf_gsm_sms_text, tvb,
offset, length, utf8_text, "%s", utf8_text);
} else {
ucs2_item = proto_tree_add_text(subtree, tvb, offset, length, "Failed to decode UCS2!");
}
@ -2821,11 +2820,9 @@ dis_field_ud(tvbuff_t *tvb, proto_tree *tree, guint32 offset, guint32 length, gb
} else
length_ucs2 = len_sms % MAX_SMS_FRAG_LEN;
/* XXX - using proto_tree_add_string() doesn't work */
ucs2_item = proto_tree_add_string_format_value(subtree, hf_gsm_sms_text, sm_tvb,
i * MAX_SMS_FRAG_LEN, length_ucs2,
&utf8_text[i * MAX_SMS_FRAG_LEN],
"%s", &utf8_text[i * MAX_SMS_FRAG_LEN]);
ucs2_item = proto_tree_add_unicode_string(subtree, hf_gsm_sms_text, sm_tvb,
i * MAX_SMS_FRAG_LEN, length_ucs2,
&utf8_text[i * MAX_SMS_FRAG_LEN]);
PROTO_ITEM_SET_GENERATED(ucs2_item);
/* return the save byte to utf8 buffer*/

View File

@ -563,11 +563,11 @@ add_geoip_info_entry(proto_item *geoip_info_item, tvbuff_t *tvb, gint offset, gu
PROTO_ITEM_SET_GENERATED(item);
PROTO_ITEM_SET_HIDDEN(item);
} else {
item = proto_tree_add_string_format_value(geoip_info_tree, geoip_local_hf,
tvb, offset, 4, geoip_str, "%s", geoip_str);
item = proto_tree_add_unicode_string(geoip_info_tree, geoip_local_hf,
tvb, offset, 4, geoip_str);
PROTO_ITEM_SET_GENERATED(item);
item = proto_tree_add_string_format_value(geoip_info_tree, geoip_hf,
tvb, offset, 4, geoip_str, "%s", geoip_str);
item = proto_tree_add_unicode_string(geoip_info_tree, geoip_hf,
tvb, offset, 4, geoip_str);
PROTO_ITEM_SET_GENERATED(item);
PROTO_ITEM_SET_HIDDEN(item);
}

View File

@ -512,11 +512,11 @@ add_geoip_info_entry(proto_tree *geoip_info_item, tvbuff_t *tvb, gint offset, co
PROTO_ITEM_SET_GENERATED(item);
PROTO_ITEM_SET_HIDDEN(item);
} else {
item = proto_tree_add_string_format_value(geoip_info_tree, geoip_local_hf, tvb,
offset, 16, geoip_str, "%s", geoip_str);
item = proto_tree_add_unicode_string(geoip_info_tree, geoip_local_hf, tvb,
offset, 16, geoip_str);
PROTO_ITEM_SET_GENERATED(item);
item = proto_tree_add_string_format_value(geoip_info_tree, geoip_hf, tvb,
offset, 16, geoip_str, "%s", geoip_str);
item = proto_tree_add_unicode_string(geoip_info_tree, geoip_hf, tvb,
offset, 16, geoip_str);
PROTO_ITEM_SET_GENERATED(item);
PROTO_ITEM_SET_HIDDEN(item);
}

View File

@ -2486,6 +2486,14 @@ proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
return pi;
}
proto_item *
proto_tree_add_unicode_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
gint length, const char* value)
{
DISSECTOR_ASSERT(g_utf8_validate(value, -1, NULL));
return proto_tree_add_string_format_value(tree, hfindex, tvb, start, length, value, "%s", value);
}
proto_item *
proto_tree_add_string_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
gint start, gint length, const char* value,

View File

@ -1215,6 +1215,10 @@ extern proto_item *
proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
gint length, const char* value, const char *format, ...) G_GNUC_PRINTF(7,8);
extern proto_item *
proto_tree_add_unicode_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
gint length, const char* value);
/** Add a FT_BOOLEAN to a proto_tree.
@param tree the tree to append this item to
@param hfindex field index