diff options
author | Guy Harris <guy@alum.mit.edu> | 2013-12-19 03:12:59 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2013-12-19 03:12:59 +0000 |
commit | 4a346b71882c782cf070e382a4bf718150b192d8 (patch) | |
tree | 8dd1d8374bd49eed41b9323e514ea5586e129401 | |
parent | 30129013b0d64d61834792d49183df1f6098f304 (diff) |
Use tvb_get_string_enc(), or proto_tree_add_item(), rather than
tvb_get_unicode_string() or g_iconv stuff.
svn path=/trunk/; revision=54244
-rw-r--r-- | epan/dissectors/packet-gsm_a_dtap.c | 21 | ||||
-rw-r--r-- | epan/dissectors/packet-gsm_sms.c | 85 |
2 files changed, 35 insertions, 71 deletions
diff --git a/epan/dissectors/packet-gsm_a_dtap.c b/epan/dissectors/packet-gsm_a_dtap.c index aeee86956a..19e2c0254e 100644 --- a/epan/dissectors/packet-gsm_a_dtap.c +++ b/epan/dissectors/packet-gsm_a_dtap.c @@ -679,8 +679,6 @@ de_network_name(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 off guint8 coding_scheme, num_spare_bits; guint32 num_chars, num_text_bits; gchar *net_name = NULL; - GIConv cd; - GError *l_conv_error = NULL; proto_item *item; curr_offset = offset; @@ -763,23 +761,8 @@ de_network_name(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 off proto_tree_add_text(tree, tvb , curr_offset, len - 1, "Text String: %s", net_name); break; case 1: - if ((cd = g_iconv_open("UTF-8","UCS-2BE")) != (GIConv)-1) - { - net_name = g_convert_with_iconv(tvb_get_ptr(tvb, curr_offset, len - 1), len - 1, cd, NULL, NULL, &l_conv_error); - if(!l_conv_error){ - proto_tree_add_text(tree, tvb, curr_offset, len - 1, "Text String: %s", net_name); - }else{ - proto_tree_add_text(tree, tvb, curr_offset, len - 1, "Failed on UCS2 contact wireshark developers"); - } - - g_free(net_name); - g_iconv_close(cd); - } - else - { - net_name = tvb_get_unicode_string(wmem_packet_scope(), tvb, curr_offset, (len - 1), ENC_BIG_ENDIAN); - proto_tree_add_text(tree, tvb, curr_offset, len - 1, "Text String: %s", net_name); - } + net_name = tvb_get_string_enc(wmem_packet_scope(), tvb, curr_offset, (len - 1), ENC_UCS_2|ENC_BIG_ENDIAN); + proto_tree_add_text(tree, tvb, curr_offset, len - 1, "Text String: %s", net_name); break; default: proto_tree_add_text(tree, diff --git a/epan/dissectors/packet-gsm_sms.c b/epan/dissectors/packet-gsm_sms.c index 04281b0840..ba27a60870 100644 --- a/epan/dissectors/packet-gsm_sms.c +++ b/epan/dissectors/packet-gsm_sms.c @@ -2656,12 +2656,9 @@ dis_field_ud(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset fragment_head *fd_sm = NULL; guint8 fill_bits; guint32 out_len, total_sms_len, len_sms, length_ucs2, i; - char *ustr; proto_item *ucs2_item; gchar *utf8_text = NULL; gchar save_byte = 0, save_byte2 = 0; - GIConv cd; - GError *l_conv_error = NULL; gboolean reassembled = FALSE; guint32 reassembled_in = 0; @@ -2838,70 +2835,54 @@ dis_field_ud(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset } else if (ucs2) { - /* XXX, use tvb_get_unicode_string(.., ENC_BIG_ENDIAN); */ - if ((cd = g_iconv_open("UTF-8","UCS-2BE")) != (GIConv)-1) { - guint8 rep_len = tvb_reported_length(sm_tvb); + guint rep_len = tvb_reported_length(sm_tvb); if (!(reassembled && pinfo->fd->num == reassembled_in)) { /* 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) { - ucs2_item = proto_tree_add_string(subtree, hf_gsm_sms_text, tvb, - offset, length, utf8_text); - } else { - ucs2_item = proto_tree_add_text(subtree, tvb, offset, length, "Failed to decode UCS2!"); - } + ucs2_item = proto_tree_add_item(subtree, hf_gsm_sms_text, sm_tvb, + 0, rep_len, ENC_UCS_2|ENC_BIG_ENDIAN); PROTO_ITEM_SET_GENERATED(ucs2_item); } else { /* Show reassembled SMS. We show each fragment separately * so that the text doesn't get truncated when we add it to * the tree. + * + * XXX - careful with splitting UTF-8 chunks; should + * we be adding each fragment as a UCS-2 string? */ - 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) - { - len_sms = (int)strlen(utf8_text); - num_labels = len_sms / MAX_SMS_FRAG_LEN; - num_labels += (len_sms % MAX_SMS_FRAG_LEN) ? 1 : 0; - for(i = 0; i < num_labels;i++) { - if(i * MAX_SMS_FRAG_LEN < len_sms) { - /* set '\0' to byte number 134 text_node MAX size*/ - save_byte = utf8_text[i * MAX_SMS_FRAG_LEN]; - save_byte2 = utf8_text[i * MAX_SMS_FRAG_LEN + 1]; - if(i > 0) - { - utf8_text[i * MAX_SMS_FRAG_LEN] = '\0'; - utf8_text[i * MAX_SMS_FRAG_LEN + 1] = '\0'; - } - - length_ucs2 = MAX_SMS_FRAG_LEN; - } else - length_ucs2 = len_sms % MAX_SMS_FRAG_LEN; - - ucs2_item = proto_tree_add_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*/ - if(i * MAX_SMS_FRAG_LEN < len_sms) { - utf8_text[i * MAX_SMS_FRAG_LEN] = save_byte; - utf8_text[i * MAX_SMS_FRAG_LEN + 1] = save_byte2; + utf8_text = tvb_get_string_enc(wmem_packet_scope(), sm_tvb, 0, rep_len, ENC_UCS_2|ENC_BIG_ENDIAN); + len_sms = (int)strlen(utf8_text); + num_labels = len_sms / MAX_SMS_FRAG_LEN; + num_labels += (len_sms % MAX_SMS_FRAG_LEN) ? 1 : 0; + for(i = 0; i < num_labels;i++) { + if(i * MAX_SMS_FRAG_LEN < len_sms) { + /* set '\0' to byte number 134 text_node MAX size*/ + save_byte = utf8_text[i * MAX_SMS_FRAG_LEN]; + save_byte2 = utf8_text[i * MAX_SMS_FRAG_LEN + 1]; + if(i > 0) + { + utf8_text[i * MAX_SMS_FRAG_LEN] = '\0'; + utf8_text[i * MAX_SMS_FRAG_LEN + 1] = '\0'; } - } - } else { - ucs2_item = proto_tree_add_text(subtree, tvb, offset, length, "Failed to decode UCS2!"); + + length_ucs2 = MAX_SMS_FRAG_LEN; + } else + length_ucs2 = len_sms % MAX_SMS_FRAG_LEN; + + ucs2_item = proto_tree_add_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*/ + if(i * MAX_SMS_FRAG_LEN < len_sms) { + utf8_text[i * MAX_SMS_FRAG_LEN] = save_byte; + utf8_text[i * MAX_SMS_FRAG_LEN + 1] = save_byte2; + } } } - - g_free(utf8_text); - g_iconv_close(cd); - } else { - ustr = tvb_get_unicode_string(wmem_packet_scope(), tvb, offset, length, ENC_BIG_ENDIAN); - proto_tree_add_text(subtree, tvb, offset, length, "%s", ustr); } } } |