Coverage Report

Created: 2026-08-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-text-media.c
Line
Count
Source
1
/* packet-text-media.c
2
 * Routines for text-based media dissection.
3
 *
4
 * NOTE - The media type is either found in pinfo->match_string,
5
 *        or passed into the dissector
6
 *
7
 * (C) Olivier Biot, 2004.
8
 *
9
 * Refer to the AUTHORS file or the AUTHORS section in the man page
10
 * for contacting the author(s) of this file.
11
 *
12
 * Wireshark - Network traffic analyzer
13
 * By Gerald Combs <gerald@wireshark.org>
14
 * Copyright 1998 Gerald Combs
15
 *
16
 * SPDX-License-Identifier: GPL-2.0-or-later
17
 */
18
19
/* Edit this file with 4-space tabs */
20
21
#include "config.h"
22
23
#include <epan/packet.h>
24
25
#include "packet-media-type.h"
26
27
/*
28
 * Media dissector for line-based text media like text/plain, message/http.
29
 *
30
 * TODO - character set and chunked transfer-coding
31
 */
32
void proto_register_text_lines(void);
33
void event_register_text_lines(void);
34
void proto_reg_handoff_text_lines(void);
35
void event_reg_handoff_text_lines(void);
36
37
/* Filterable header fields */
38
static int proto_text_lines;
39
40
/* Subtrees */
41
static int ett_text_lines;
42
43
/* Dissector handles */
44
static dissector_handle_t xml_handle;
45
46
static int
47
dissect_text_lines(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
48
2.38k
{
49
2.38k
  proto_tree  *subtree;
50
2.38k
  proto_item  *ti;
51
2.38k
  unsigned  offset = 0, next_offset;
52
2.38k
  unsigned  len;
53
2.38k
  media_content_info_t *content_info;
54
2.38k
  const char  *data_name;
55
2.38k
  int length = tvb_captured_length(tvb);
56
57
  /* Check if this is actually xml
58
   * If there is less than 38 characters this is not XML
59
   * <?xml version="1.0" encoding="UTF-8"?>
60
   */
61
2.38k
  if(length > 38){
62
1.97k
    if (tvb_strncaseeql(tvb, 0, "<?xml", 5) == 0){
63
1.77k
      call_dissector(xml_handle, tvb, pinfo, tree);
64
1.77k
      return length;
65
1.77k
    }
66
1.97k
  }
67
68
617
  data_name = pinfo->match_string;
69
617
  if (! (data_name && data_name[0])) {
70
    /*
71
     * No information from "match_string"
72
     */
73
523
    content_info = (media_content_info_t *)data;
74
523
    if (content_info == NULL) {
75
      /*
76
       * No information from dissector data
77
       */
78
523
      data_name = NULL;
79
523
    } else {
80
0
      data_name = content_info->media_str;
81
0
      if (! (data_name && data_name[0])) {
82
        /*
83
         * No information from dissector data
84
         */
85
0
        data_name = NULL;
86
0
      }
87
0
    }
88
523
  }
89
90
617
  if (data_name)
91
94
    col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "(%s)",
92
94
        data_name);
93
94
617
  if (tree) {
95
617
    unsigned lines_read = 0;
96
617
    ti = proto_tree_add_item(tree, proto_text_lines,
97
617
        tvb, 0, -1, ENC_NA);
98
617
    if (data_name)
99
94
      proto_item_append_text(ti, ": %s", data_name);
100
617
    subtree = proto_item_add_subtree(ti, ett_text_lines);
101
    /* Read the media line by line */
102
12.0k
    while (tvb_offset_exists(tvb, offset)) {
103
      /*
104
       * XXX - we need to be passed the parameters
105
       * of the content type via data parameter,
106
       * so that we know the character set.  We'd
107
       * have to handle that character set, which
108
       * might be a multibyte character set such
109
       * as "iso-10646-ucs-2", or might require other
110
       * special processing.
111
       */
112
11.4k
      tvb_find_line_end_remaining(tvb, offset, &len, &next_offset);
113
114
      /* We use next_offset - offset instead of len in the
115
       * call to proto_tree_add_format_text() so it will include the
116
       * line terminator(s) (\r and/or \n) in the display.
117
       */
118
11.4k
      proto_tree_add_format_text(subtree, tvb, offset, next_offset - offset);
119
11.4k
      lines_read++;
120
11.4k
      offset = next_offset;
121
11.4k
    }
122
617
    proto_item_append_text(subtree, " (%u lines)", lines_read);
123
617
  }
124
125
617
  return length;
126
2.38k
}
127
128
static void
129
common_register_text_lines(void)
130
16
{
131
16
  static int *ett[] = {
132
16
    &ett_text_lines,
133
16
  };
134
135
16
  proto_register_subtree_array(ett, array_length(ett));
136
137
16
  proto_text_lines = proto_register_protocol("Line-based text data", "Line-based text data", "data-text-lines");
138
16
  register_dissector("data-text-lines", dissect_text_lines, proto_text_lines);
139
16
}
140
141
void
142
proto_register_text_lines(void)
143
16
{
144
16
  common_register_text_lines();
145
16
}
146
147
void
148
event_register_text_lines(void)
149
0
{
150
0
  common_register_text_lines();
151
0
}
152
153
static void common_reg_handoff_text_lines(void)
154
16
{
155
16
  dissector_handle_t text_lines_handle;
156
157
16
  text_lines_handle = find_dissector("data-text-lines");
158
159
16
  dissector_add_string("media_type", "text/plain", text_lines_handle); /* RFC 2046 */
160
16
  dissector_add_string("media_type", "text/richtext", text_lines_handle);  /* RFC 1341 */
161
16
  dissector_add_string("media_type", "text/enriched", text_lines_handle);  /* RFC 1896 */
162
16
  dissector_add_string("media_type", "text/parameters", text_lines_handle);
163
  /* W3C line-based textual media */
164
16
  dissector_add_string("media_type", "text/html", text_lines_handle);
165
16
  dissector_add_string("media_type", "text/xml-external-parsed-entity", text_lines_handle);
166
16
  dissector_add_string("media_type", "text/css", text_lines_handle);
167
16
  dissector_add_string("media_type", "application/xml-external-parsed-entity", text_lines_handle);
168
16
  dissector_add_string("media_type", "text/javascript", text_lines_handle);
169
16
  dissector_add_string("media_type", "application/x-javascript", text_lines_handle);
170
16
  dissector_add_string("media_type", "application/x-tia-p25-issi", text_lines_handle);
171
16
  dissector_add_string("media_type", "application/x-tia-p25-sndcp", text_lines_handle);
172
16
  dissector_add_string("media_type", "application/x-ns-proxy-autoconfig", text_lines_handle);
173
174
16
  dissector_add_string("media_type", "text/vnd.sun.j2me.app-descriptor", text_lines_handle);
175
16
  dissector_add_string("media_type", "application/vnd.poc.refer-to", text_lines_handle);
176
16
  dissector_add_string("media_type", "application/vnd.drm.message", text_lines_handle);
177
178
16
  dissector_add_string("media_type", "application/x-wms-logplaystats", text_lines_handle);
179
16
  dissector_add_string("media_type", "application/x-rtsp-udp-packetpair", text_lines_handle);
180
16
  xml_handle = find_dissector_add_dependency("xml", proto_text_lines);
181
16
}
182
183
void
184
proto_reg_handoff_text_lines(void)
185
16
{
186
16
  common_reg_handoff_text_lines();
187
16
}
188
189
void
190
event_reg_handoff_text_lines(void)
191
0
{
192
0
  common_reg_handoff_text_lines();
193
0
}
194
195
/*
196
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
197
 *
198
 * Local variables:
199
 * c-basic-offset: 8
200
 * tab-width: 8
201
 * indent-tabs-mode: t
202
 * End:
203
 *
204
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
205
 * :indentSize=8:tabSize=8:noTabs=false:
206
 */