Fix bugs I introduced. Now
[metze/wireshark/wip.git] / epan / proto.h
1 /* proto.h
2  * Definitions for protocol display
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25
26 /*! @file proto.h
27     The protocol tree related functions.<BR>
28     A protocol tree will hold all necessary data to display the whole dissected packet.
29     Creating a protocol tree is done in a two stage process:
30     A static part at program startup, and a dynamic part when the dissection with the real packet data is done.<BR>
31     The "static" information is provided by creating a hf_register_info hf[] array, and register it using the
32     proto_register_field_array() function. This is usually done at dissector registering.<BR>
33     The "dynamic" information is added to the protocol tree by calling one of the proto_tree_add_...() functions,
34     e.g. proto_tree_add_bytes().
35 */
36
37 #ifndef __PROTO_H__
38 #define __PROTO_H__
39
40 #ifdef HAVE_STDARG_H
41 # include <stdarg.h>
42 #else
43 # include <varargs.h>
44 #endif
45
46 #include <glib.h>
47
48 #include "ipv4.h"
49 #include "nstime.h"
50 #include "time_fmt.h"
51 #include "tvbuff.h"
52 #include "ftypes/ftypes.h"
53 #include "register.h"
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif /* __cplusplus */
58
59 /** The header-field index for the special text pseudo-field. Exported by libwireshark.dll */
60 WS_VAR_IMPORT int hf_text_only;
61
62 /** the maximum length of a protocol field string representation */
63 #define ITEM_LABEL_LENGTH       240
64
65 struct _value_string;
66
67 /** Make a const value_string[] look like a _value_string pointer, used to set header_field_info.strings */
68 #define VALS(x) (const struct _value_string*)(x)
69
70 /** Make a const true_false_string[] look like a _true_false_string pointer, used to set header_field_info.strings */
71 #define TFS(x)  (const struct true_false_string*)(x)
72
73 typedef void (*custom_fmt_func_t)(gchar *, guint32);
74
75 /** Make a const range_string[] look like a _range_string pointer, used to set
76  * header_field_info.strings */
77 #define RVALS(x) (const struct _range_string*)(x)
78
79 struct _protocol;
80
81 /** Structure for information about a protocol */
82 typedef struct _protocol protocol_t;
83
84 /** check protocol activation
85  * @todo this macro looks like a hack */
86 #define CHECK_DISPLAY_AS_X(x_handle,index, tvb, pinfo, tree) {  \
87         if (!proto_is_protocol_enabled(find_protocol_by_id(index))) {   \
88                 call_dissector(x_handle,tvb, pinfo, tree);              \
89                 return;                                                 \
90         }                                                               \
91   }
92
93 /** Macro used for reporting errors in dissectors; it throws a
94  * DissectorError exception, with the string passed as an argument
95  * as the message for the exception, so that it can show up in
96  * the Info column and the protocol tree.
97  *
98  * If that string is dynamically allocated, it should be allocated with
99  * ep_alloc(); using ep_strdup_printf() would work.
100  *
101  * If the WIRESHARK_ABORT_ON_DISSECTOR_BUG environment variable is set,
102  * it will call abort(), instead, to make it easier to get a stack trace.
103  *
104  * @param message string to use as the message
105  */
106 #define REPORT_DISSECTOR_BUG(message)  \
107   ((getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL) ? \
108     abort() : \
109     THROW_MESSAGE(DissectorError, message))
110
111 /** Macro used to provide a hint to static analysis tools.
112  * (Currently only Visual C++.)
113  */
114 #if _MSC_VER >= 1400
115 /* XXX - Is there a way to say "quit checking at this point"? */
116 #define __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression) \
117   ; __analysis_assume(expression);
118 #else
119 #define __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
120 #endif
121
122 /** Macro used for assertions in dissectors; it doesn't abort, it just
123  * throws a DissectorError exception, with the assertion failure
124  * message as a parameter, so that it can show up in the protocol tree.
125  *
126  * NOTE: this should only be used to detect bugs in the dissector (e.g., logic
127  * conditions that shouldn't happen).  It should NOT be used for showing
128  * that a packet is malformed.  For that, use expert_infos instead.
129  *
130  * @param expression expression to test in the assertion
131  */
132
133 #define DISSECTOR_ASSERT(expression)  \
134   ((void) ((expression) ? (void)0 : \
135    __DISSECTOR_ASSERT (expression, __FILE__, __LINE__))) \
136    __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
137
138 /**
139  * Same as DISSECTOR_ASSERT(), but takes an extra 'hint' parameter that
140  * can be used to provide information as to why the assertion might fail.
141  *
142  * @param expression expression to test in the assertion
143  * @param hint message providing extra information
144  */
145 #define DISSECTOR_ASSERT_HINT(expression, hint)  \
146   ((void) ((expression) ? (void)0 : \
147    __DISSECTOR_ASSERT_HINT (expression, __FILE__, __LINE__, hint))) \
148    __DISSECTOR_ASSERT_STATIC_ANALYSIS_HINT(expression)
149
150 #if 0
151 /* win32: using a debug breakpoint (int 3) can be very handy while debugging,
152  * as the assert handling of GTK/GLib is currently not very helpful */
153 #define DISSECTOR_ASSERT(expression)  \
154 { if(!(expression)) _asm { int 3}; }
155 #endif
156
157 /** Same as DISSECTOR_ASSERT(), but will throw DissectorError exception
158  * unconditionally, much like GLIB's g_assert_not_reached works.
159  *
160  * NOTE: this should only be used to detect bugs in the dissector (e.g., logic
161  * conditions that shouldn't happen).  It should NOT be used for showing
162  * that a packet is malformed.  For that, use expert_infos instead.
163  *
164  */
165 #define DISSECTOR_ASSERT_NOT_REACHED()  \
166   (REPORT_DISSECTOR_BUG( \
167     ep_strdup_printf("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\"", \
168      __FILE__, __LINE__)))
169
170 #define __DISSECTOR_ASSERT_STRINGIFY(s) # s
171
172 #define __DISSECTOR_ASSERT(expression, file, lineno)  \
173   (REPORT_DISSECTOR_BUG( \
174     ep_strdup_printf("%s:%u: failed assertion \"%s\"", \
175      file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression))))
176
177 #define __DISSECTOR_ASSERT_HINT(expression, file, lineno, hint)  \
178   (REPORT_DISSECTOR_BUG( \
179     ep_strdup_printf("%s:%u: failed assertion \"%s\" (%s)", \
180      file, lineno, __DISSECTOR_ASSERT_STRINGIFY(expression), hint)))
181
182 /*
183  * The encoding of a field of a particular type may involve more
184  * than just whether it's big-endian or little-endian and its size.
185  *
186  * For integral values, that's it, as 99.9999999999999% of the machines
187  * out there are 2's complement binary machines with 8-bit bytes,
188  * so the protocols out there expect that and, for example, any Unisys
189  * 2200 series machines out there just have to translate between 2's
190  * complement and 1's complement (and nobody's put any IBM 709x's on
191  * any networks lately :-)).
192  *
193  * However:
194  *
195  *      for floating-point numbers, in addition to IEEE decimal
196  *      floating-point, there's also IBM System/3x0 and PDP-11/VAX
197  *      floating-point - most protocols use IEEE binary, but DCE RPC
198  *      can use other formats if that's what the sending host uses;
199  *
200  *      for character strings, there are various character encodings
201  *      (various ISO 646 sets, ISO 8859/x, various other national
202  *      standards, various DOS and Windows encodings, various Mac
203  *      encodings, UTF-8, UTF-16, other extensions to ASCII, EBCDIC,
204  *      etc.);
205  *
206  *      for absolute times, there's UNIX time_t, UNIX time_t followed
207  *      by 32-bit microseconds, UNIX time_t followed by 32-bit
208  *      nanoseconds, DOS date/time, Windows FILETIME, NTP time, etc..
209  *
210  * We might also, in the future, want to allow a field specifier to
211  * indicate the encoding of the field, or at least its default
212  * encoding, as most fields in most protocols always use the
213  * same encoding (although that's not true of all fields, so we
214  * still need to be able to specify that at run time).
215  *
216  * So, for now, we define ENC_BIG_ENDIAN and ENC_LITTLE_ENDIAN as
217  * bit flags, to be combined, in the future, with other information
218  * to specify the encoding in the last argument to
219  * proto_tree_add_item(), and possibly to specify in a field
220  * definition (e.g., ORed in with the type value).
221  *
222  * Currently, proto_tree_add_item() treats its last argument as a
223  * Boolean - if it's zero, the field is big-endian, and if it's non-zero,
224  * the field is little-endian - and other code in epan/proto.c does
225  * the same.  We therefore define ENC_BIG_ENDIAN as 0x00000000 and
226  * ENC_LITTLE_ENDIAN as 0x80000000 - we're using the high-order bit
227  * so that we could put a field type and/or a value such as a character
228  * encoding in the lower bits.
229  */
230 #define ENC_BIG_ENDIAN          0x00000000
231 #define ENC_LITTLE_ENDIAN       0x80000000
232
233 /*
234  * Historically FT_TIMEs were only timespecs; the only question was whether
235  * they were stored in big- or little-endian format.
236  *
237  * For backwards compatibility, we interpret an encoding of 1 as meaning
238  * "little-endian timespec", so that passing TRUE is interpreted as that.
239  */
240 #define ENC_TIME_TIMESPEC       0x00000000
241 #define ENC_TIME_NTP            0x00000002
242
243 /*
244  * Historically, the only place the representation mattered for strings
245  * was with FT_UINT_STRINGs, where we had FALSE for the string length
246  * being big-endian and TRUE for it being little-endian.
247  *
248  * We now have encoding values for the character encoding.  The encoding
249  * values are encoded in all but the top bit (which is the byte-order
250  * bit, required for FT_UINT_STRING and for UCS-2 and UTF-16 strings)
251  * and the bottom bit (which we ignore for now so that programs that
252  * pass TRUE for the encoding just do ASCII).  (The encodings are given
253  * directly as even numbers in hex, so that make-init-lua.pl can just
254  * turn them into numbers for use in init.lua.)
255  *
256  * We don't yet process ASCII and UTF-8 differently.  Ultimately, for
257  * ASCII, all bytes with the 8th bit set should be mapped to some "this
258  * is not a valid character" code point, as ENC_ASCII should mean "this
259  * is ASCII, not some extended variant thereof".  We should also map
260  * 0x00 to that as well - null-terminated and null-padded strings
261  * never have NULs in them, but counted strings might.  (Either that,
262  * or the values for strings should be counted, not null-terminated.)
263  * For UTF-8, invalid UTF-8 sequences should be mapped to the same
264  * code point.
265  *
266  * We also don't process UTF-16 or UCS-2 differently - we don't
267  * handle surrogate pairs, and don't handle 2-byte values that
268  * aren't valid in UTF-16 or UCS-2 strings.
269  *
270  * For display, perhaps we should also map control characters to the
271  * Unicode glyphs showing the name of the control character in small
272  * caps, diagonally.  (Unfortunately, those only exist for C0, not C1.)
273  */
274 #define ENC_CHARENCODING_MASK   0x7FFFFFFE      /* mask out byte-order bits */
275 #define ENC_ASCII               0x00000000
276 #define ENC_UTF_8               0x00000002
277 #define ENC_UTF_16              0x00000004
278 #define ENC_UCS_2               0x00000006
279 #define ENC_EBCDIC              0x00000008
280
281 /*
282  * TODO:
283  *
284  * These could probably be used by existing code:
285  *
286  *      ENC_UCS_4 - UCS-4
287  *      ENC_ISO_8859_1 - ISO 8859/1
288  *      ENC_ISO_8859_8 - ISO 8859/8
289  *       - "IBM MS DBCS"
290  *       - JIS C 6226
291  *      7-bit encodings such as ETSI 03.38 (GSM SMS character set
292  *          (see packet-ansi_337.c, packet-gsm_a_dtap.c, packet-gsm_map.c,
293  *          packet-gsm_sms.c)?
294  *
295  * See also packet-bacapp.c.
296  */
297
298 /*
299  * For protocols (FT_PROTOCOL), aggregate items with subtrees (FT_NONE),
300  * opaque byte-array fields (FT_BYTES), and other fields where there
301  * is no choice of encoding (either because it's "just a bucket
302  * of bytes" or because the encoding is completely fixed), we
303  * have ENC_NA (for "Not Applicable").
304  */
305 #define ENC_NA                  0x00000000
306
307 /* Values for header_field_info.display */
308
309 /* For integral types, the display format is a base_display_e value
310  * possibly ORed with BASE_RANGE_STRING. */
311
312 /** BASE_DISPLAY_E_MASK selects the base_display_e value.  Its current
313  * value means that we may have at most 16 base_display_e values. */
314 #define BASE_DISPLAY_E_MASK 0x0F
315
316 typedef enum {
317         BASE_NONE,      /**< none */
318         BASE_DEC,       /**< decimal */
319         BASE_HEX,       /**< hexadecimal */
320         BASE_OCT,       /**< octal */
321         BASE_DEC_HEX,   /**< decimal (hexadecimal) */
322         BASE_HEX_DEC,   /**< hexadecimal (decimal) */
323         BASE_CUSTOM     /**< call custom routine (in ->strings) to format */
324 } base_display_e;
325
326 /* Following constants have to be ORed with a base_display_e when dissector
327  * want to use specials MACROs (for the moment, only RVALS) for a
328  * header_field_info */
329 #define BASE_RANGE_STRING 0x10
330 #define BASE_EXT_STRING 0x20
331
332 /** BASE_ values that cause the field value to be displayed twice */
333 #define IS_BASE_DUAL(b) ((b)==BASE_DEC_HEX||(b)==BASE_HEX_DEC)
334
335 /* For FT_ABSOLUTE_TIME, the display format is an absolute_time_display_e
336  * as per time_fmt.h. */
337
338 typedef enum {
339     HF_REF_TYPE_NONE,       /**< Field is not referenced */
340     HF_REF_TYPE_INDIRECT,   /**< Field is indirectly referenced (only applicable for FT_PROTOCOL) via. its child */
341     HF_REF_TYPE_DIRECT      /**< Field is directly referenced */
342 } hf_ref_type;
343
344 /** information describing a header field */
345 typedef struct _header_field_info header_field_info;
346
347 /** information describing a header field */
348 struct _header_field_info {
349         /* ---------- set by dissector --------- */
350         const char              *name;           /**< [FIELDNAME] full name of this field */
351         const char              *abbrev;         /**< [FIELDABBREV] abbreviated name of this field */
352         enum ftenum              type;           /**< [FIELDTYPE] field type, one of FT_ (from ftypes.h) */
353         int                      display;        /**< [FIELDDISPLAY] one of BASE_, or field bit-width if FT_BOOLEAN and non-zero bitmask */
354         const void              *strings;        /**< [FIELDCONVERT] value_string, range_string or true_false_string,
355                                                       typically converted by VALS(), RVALS() or TFS().
356                                                       If this is an FT_PROTOCOL then it points to the
357                                                       associated protocol_t structure */
358         guint32                  bitmask;        /**< [BITMASK] bitmask of interesting bits */
359         const char              *blurb;          /**< [FIELDDESCR] Brief description of field */
360
361         /* ------- set by proto routines (prefilled by HFILL macro, see below) ------ */
362         int                                      id;             /**< Field ID */
363         int                                      parent;         /**< parent protocol tree */
364         hf_ref_type                      ref_type;       /**< is this field referenced by a filter */
365         int                                      bitshift;       /**< bits to shift */
366         header_field_info       *same_name_next; /**< Link to next hfinfo with same abbrev */
367         header_field_info       *same_name_prev; /**< Link to previous hfinfo with same abbrev */
368 };
369
370 /**
371  * HFILL initializes all the "set by proto routines" fields in a
372  * _header_field_info. If new fields are added or removed, it should
373  * be changed as necessary.
374  */
375 #define HFILL 0, 0, HF_REF_TYPE_NONE, 0, NULL, NULL
376
377 /** Used when registering many fields at once, using proto_register_field_array() */
378 typedef struct hf_register_info {
379         int                                             *p_id;           /**< written to by register() function */
380         header_field_info               hfinfo;      /**< the field info to be registered */
381 } hf_register_info;
382
383
384
385
386 /** string representation, if one of the proto_tree_add_..._format() functions used */
387 typedef struct _item_label_t {
388         char representation[ITEM_LABEL_LENGTH];
389 } item_label_t;
390
391
392 /** Contains the field information for the proto_item. */
393 typedef struct field_info {
394         header_field_info       *hfinfo;          /**< pointer to registered field information */
395         gint                             start;           /**< current start of data in field_info.ds_tvb */
396         gint                             length;          /**< current data length of item in field_info.ds_tvb */
397         gint                             appendix_start;  /**< start of appendix data */
398         gint                             appendix_length; /**< length of appendix data */
399         gint                             tree_type;       /**< one of ETT_ or -1 */
400         item_label_t            *rep;             /**< string for GUI tree */
401         guint32                          flags;           /**< bitfield like FI_GENERATED, ... */
402         tvbuff_t                        *ds_tvb;          /**< data source tvbuff */
403         fvalue_t                         value;
404 } field_info;
405
406
407 /*
408  * This structure describes one segment of a split-bits item
409  * crumb_bit_offset is the bit offset in the input tvb of the first (most significant) bit of this crumb
410  * crumb_bit_length is the number of contiguous bits of this crumb.
411  * The first element of an array of bits_specs describes the most significant crumb of the output value.
412  * The second element of an array of bits_specs describes the next-most significant crumb of the output value, etc.
413  * The array is terminated by a sentinal entry with crumb_bit_length of 0.
414 */
415 typedef struct
416 {
417     guint  crumb_bit_offset;
418     guint8 crumb_bit_length;
419 }crumb_spec_t;
420
421 /*
422  * Flag fields.  Do not assign values greater than 0x00000080 unless you
423  * shuffle the expert information upward; see below.
424  */
425
426 /** The protocol field should not be shown in the tree (it's used for filtering only),
427  * used in field_info.flags. */
428 /** HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN!
429    A user cannot tell by looking at the packet detail that the field exists
430    and that they can filter on its value. */
431 #define FI_HIDDEN               0x00000001
432 /** The protocol field should be displayed as "generated by Wireshark",
433  * used in field_info.flags. */
434 #define FI_GENERATED            0x00000002
435 /** The protocol field is actually a URL */
436 #define FI_URL                  0x00000004
437
438 /** The protocol field value is in little endian */
439 #define FI_LITTLE_ENDIAN        0x00000008
440 /** The protocol field value is in big endian */
441 #define FI_BIG_ENDIAN           0x00000010
442 /** Field value start from nth bit (values from 0x20 - 0x100) */
443 #define FI_BITS_OFFSET(n)       (((n) & 7) << 5)
444 /** Field value takes n bits (values from 0x100 - 0x4000) */
445 /* if 0, it means that field takes fi->length * 8 */
446 #define FI_BITS_SIZE(n)         (((n) & 63) << 8)
447
448 /** convenience macro to get field_info.flags */
449 #define FI_GET_FLAG(fi, flag)   ((fi) ? ((fi)->flags & (flag)) : 0)
450 /** convenience macro to set field_info.flags */
451 #define FI_SET_FLAG(fi, flag) \
452     do { \
453       if (fi) \
454         (fi)->flags = (fi)->flags | (flag); \
455     } while(0)
456 /** convenience macro to reset field_info.flags */
457 #define FI_RESET_FLAG(fi, flag) \
458     do { \
459       if (fi) \
460         (fi)->flags = (fi)->flags & ~(flag); \
461     } while(0)
462
463 #define FI_GET_BITS_OFFSET(fi) (FI_GET_FLAG(fi, FI_BITS_OFFSET(7)) >> 5)
464 #define FI_GET_BITS_SIZE(fi)   (FI_GET_FLAG(fi, FI_BITS_SIZE(63)) >> 8)
465
466 /** One of these exists for the entire protocol tree. Each proto_node
467  * in the protocol tree points to the same copy. */
468 typedef struct {
469     GHashTable  *interesting_hfids;
470     gboolean     visible;
471     gboolean     fake_protocols;
472     gint         count;
473     struct _packet_info *pinfo;
474     field_info  *fi_tmp;
475 } tree_data_t;
476
477 /** Each proto_tree, proto_item is one of these. */
478 typedef struct _proto_node {
479         struct _proto_node *first_child;
480         struct _proto_node *last_child;
481         struct _proto_node *next;
482         struct _proto_node *parent;
483         field_info  *finfo;
484         tree_data_t *tree_data;
485 } proto_node;
486
487 /** A protocol tree element. */
488 typedef proto_node proto_tree;
489 /** A protocol item element. */
490 typedef proto_node proto_item;
491
492 /*
493  * Expert information.
494  * This is in the flags field; we allocate this from the top down,
495  * so as not to collide with FI_ flags, which are allocated from
496  * the bottom up.
497  */
498
499 /* expert severities */
500 #define PI_SEVERITY_MASK        0x00F00000      /**< mask usually for internal use only! */
501 /** Packet is commented */
502 #define PI_COMMENT              0x00100000
503 /** Usual workflow, e.g. TCP connection establishing */
504 #define PI_CHAT                 0x00200000
505 /** Notable messages, e.g. an application returned an "usual" error code like HTTP 404 */
506 #define PI_NOTE                 0x00400000
507 /** Warning, e.g. application returned an "unusual" error code */
508 #define PI_WARN                 0x00600000
509 /** Serious problems, e.g. [Malformed Packet] */
510 #define PI_ERROR                0x00800000
511
512 /* expert "event groups" */
513 #define PI_GROUP_MASK           0xFF000000      /**< mask usually for internal use only! */
514 /** The protocol field has a bad checksum, usually PI_WARN */
515 #define PI_CHECKSUM             0x01000000
516 /** The protocol field indicates a sequence problem (e.g. TCP window is zero) */
517 #define PI_SEQUENCE             0x02000000
518 /** The protocol field indicates a bad application response code (e.g. HTTP 404), usually PI_NOTE */
519 #define PI_RESPONSE_CODE        0x03000000
520 /** The protocol field indicates an application request (e.g. File Handle == xxxx), usually PI_CHAT */
521 #define PI_REQUEST_CODE         0x04000000
522 /** The data is undecoded, the protocol dissection is incomplete here, usually PI_WARN */
523 #define PI_UNDECODED            0x05000000
524 /** The protocol field indicates a reassemble (e.g. DCE/RPC defragmentation), usually PI_CHAT (or PI_ERROR) */
525 #define PI_REASSEMBLE           0x06000000
526 /** The packet data is malformed, the dissector has "given up", usually PI_ERROR */
527 #define PI_MALFORMED            0x07000000
528 /** A generic debugging message (shouldn't remain in production code!), usually PI_ERROR */
529 #define PI_DEBUG                0x08000000
530 /** The protocol field violates a protocol specification, usually PI_WARN */
531 #define PI_PROTOCOL             0x09000000
532 /** The protocol field indicates a security probem (e.g. unsecure implementation) */
533 #define PI_SECURITY             0x0a000000
534 /** The protocol field indicates a packet comment */
535 #define PI_COMMENTS_GROUP       0x0b000000
536
537 /* add more, see http://wiki.wireshark.org/Development/ExpertInfo */
538
539
540 /** is this protocol field hidden from the protocol tree display (used for filtering only)? */
541 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
542 #define PROTO_ITEM_IS_HIDDEN(proto_item)        \
543         ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN) : 0)
544 /** mark this protocol field to be hidden from the protocol tree display (used for filtering only) */
545 /* HIDING PROTOCOL FIELDS IS DEPRECATED, IT'S CONSIDERED TO BE BAD GUI DESIGN! */
546 #define PROTO_ITEM_SET_HIDDEN(proto_item)       \
547   do { \
548     if (proto_item) \
549       FI_SET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN); \
550   } while(0)
551 /** mark this protocol field to be visible from the protocol tree display */
552 #define PROTO_ITEM_SET_VISIBLE(proto_item)       \
553   do { \
554     if (proto_item) \
555       FI_RESET_FLAG(PITEM_FINFO(proto_item), FI_HIDDEN); \
556   } while(0)
557
558 /** is this protocol field generated by Wireshark (and not read from the packet data)? */
559 #define PROTO_ITEM_IS_GENERATED(proto_item)     \
560         ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_GENERATED) : 0)
561 /** mark this protocol field as generated by Wireshark (and not read from the packet data) */
562 #define PROTO_ITEM_SET_GENERATED(proto_item)    \
563     do { \
564       if (proto_item) \
565         FI_SET_FLAG(PITEM_FINFO(proto_item), FI_GENERATED); \
566     } while(0)
567 /** is this protocol field actually a URL? */
568 #define PROTO_ITEM_IS_URL(proto_item)   \
569         ((proto_item) ? FI_GET_FLAG(PITEM_FINFO(proto_item), FI_URL) : 0)
570 /** mark this protocol field as a URL */
571 #define PROTO_ITEM_SET_URL(proto_item)  \
572     do { \
573       if (proto_item) \
574         FI_SET_FLAG(PITEM_FINFO(proto_item), FI_URL); \
575     } while(0)
576
577 typedef void (*proto_tree_foreach_func)(proto_node *, gpointer);
578 typedef gboolean (*proto_tree_traverse_func)(proto_node *, gpointer);
579
580 extern gboolean proto_tree_traverse_post_order(proto_tree *tree,
581     proto_tree_traverse_func func, gpointer data);
582
583 extern void proto_tree_children_foreach(proto_tree *tree,
584     proto_tree_foreach_func func, gpointer data);
585
586 /** Retrieve the field_info from a proto_node */
587 #define PNODE_FINFO(proto_node)  ((proto_node)->finfo)
588
589 /** Retrieve the field_info from a proto_item */
590 #define PITEM_FINFO(proto_item)  PNODE_FINFO(proto_item)
591
592 /** Retrieve the field_info from a proto_tree */
593 #define PTREE_FINFO(proto_tree)  PNODE_FINFO(proto_tree)
594
595 /** Retrieve the tree_data_t from a proto_tree */
596 #define PTREE_DATA(proto_tree)   ((proto_tree)->tree_data)
597
598 /** Sets up memory used by proto routines. Called at program startup */
599 extern void proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_data),
600                        void (register_all_handoffs_func)(register_cb cb, gpointer client_data),
601                        register_cb cb, void *client_data);
602
603
604 /** Frees memory used by proto routines. Called at program shutdown */
605 extern void proto_cleanup(void);
606
607 /** This function takes a tree and a protocol id as parameter and
608     will return TRUE/FALSE for whether the protocol or any of the filterable
609     fields in the protocol is referenced by any fitlers.
610     If this function returns FALSE then it is safe to skip any
611     proto_tree_add_...() calls and just treat the call as if the
612     dissector was called with tree==NULL.
613     If you reset the tree to NULL by this dissector returning FALSE,
614     you will still need to call any subdissector with the original value of
615     tree or filtering will break.
616
617     The purpose of this is to optimize wireshark for speed and make it
618     faster for when filters are being used.
619 */
620 extern gboolean proto_field_is_referenced(proto_tree *tree, int proto_id);
621
622 /** Create a subtree under an existing item.
623  @param ti the parent item of the new subtree
624  @param idx one of the ett_ array elements registered with proto_register_subtree_array()
625  @return the new subtree */
626 extern proto_tree* proto_item_add_subtree(proto_item *ti, const gint idx) G_GNUC_WARN_UNUSED_RESULT;
627
628 /** Get an existing subtree under an item.
629  @param ti the parent item of the subtree
630  @return the subtree or NULL */
631 extern proto_tree* proto_item_get_subtree(const proto_item *ti);
632
633 /** Get the parent of a subtree item.
634  @param ti the child item in the subtree
635  @return parent item or NULL */
636 extern proto_item* proto_item_get_parent(const proto_item *ti);
637
638 /** Get Nth generation parent item.
639  @param ti the child item in the subtree
640  @param gen the generation to get (using 1 here is the same as using proto_item_get_parent())
641  @return parent item */
642 extern proto_item* proto_item_get_parent_nth(proto_item *ti, int gen);
643
644 /** Replace text of item after it already has been created.
645  @param ti the item to set the text
646  @param format printf like format string
647  @param ... printf like parameters */
648 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
649         G_GNUC_PRINTF(2,3);
650
651 /** Append to text of item after it has already been created.
652  @param ti the item to append the text to
653  @param format printf like format string
654  @param ... printf like parameters */
655 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
656         G_GNUC_PRINTF(2,3);
657
658 /** Prepend to text of item after it has already been created.
659  @param ti the item to prepend the text to
660  @param format printf like format string
661  @param ... printf like parameters */
662 extern void proto_item_prepend_text(proto_item *ti, const char *format, ...)
663         G_GNUC_PRINTF(2,3);
664
665 /** Set proto_item's length inside tvb, after it has already been created.
666  @param ti the item to set the length
667  @param length the new length ot the item */
668 extern void proto_item_set_len(proto_item *ti, const gint length);
669
670 /**
671  * Sets the length of the item based on its start and on the specified
672  * offset, which is the offset past the end of the item; as the start
673  * in the item is relative to the beginning of the data source tvbuff,
674  * we need to pass in a tvbuff.
675  @param ti the item to set the length
676  @param tvb end is relative to this tvbuff
677  @param end this end offset is relative to the beginning of tvb
678  @todo make usage clearer, I don't understand it!
679  */
680 extern void proto_item_set_end(proto_item *ti, tvbuff_t *tvb, gint end);
681
682 /** Get length of a proto_item. Useful after using proto_tree_add_item()
683  * to add a variable-length field (e.g., FT_NSTRING_UINT8).
684  @param ti the item to get the length from
685  @return the current length */
686 extern int proto_item_get_len(const proto_item *ti);
687
688 /**
689  * Sets an expert info to the proto_item.
690  @param ti the item to set the expert info
691  @param group the group of this info (e.g. PI_CHECKSUM)
692  @param severity of this info (e.g. PI_ERROR)
693  @return TRUE if value was written
694  */
695 extern gboolean proto_item_set_expert_flags(proto_item *ti, const int group, const guint severity);
696
697
698
699
700 /** Creates a new proto_tree root.
701  @return the new tree root */
702 extern proto_tree* proto_tree_create_root(struct _packet_info *pinfo);
703
704 /** Clear memory for entry proto_tree. Clears proto_tree struct also.
705  @param tree the tree to free */
706 extern void proto_tree_free(proto_tree *tree);
707
708 /** Set the tree visible or invisible.
709  Is the parsing being done for a visible proto_tree or an invisible one?
710  By setting this correctly, the proto_tree creation is sped up by not
711  having to call g_vsnprintf and copy strings around.
712  @param tree the tree to be set
713  @param visible ... or not
714  @return the old value */
715 extern gboolean
716 proto_tree_set_visible(proto_tree *tree, gboolean visible);
717
718 /** Indicate whether we should fake protocols during dissection (default = TRUE)
719  @param tree the tree to be set
720  @param fake_protocols TRUE if we should fake protocols */
721 extern void
722 proto_tree_set_fake_protocols(proto_tree *tree, gboolean fake_protocols);
723
724 /** Mark a field/protocol ID as "interesting".
725  @param tree the tree to be set
726  @param hfid the interesting field id
727  @todo what *does* interesting mean? */
728 extern void
729 proto_tree_prime_hfid(proto_tree *tree, const int hfid);
730
731 /** Get a parent item of a subtree.
732  @param tree the tree to get the parent from
733  @return parent item */
734 extern proto_item* proto_tree_get_parent(const proto_tree *tree);
735
736 /** Get the root tree from any subtree.
737  @param tree the tree to get the root from
738  @return root tree */
739 extern proto_tree* proto_tree_get_root(proto_tree *tree);
740
741 /** Move an existing item behind another existing item.
742  @param tree the tree to which both items belong
743  @param fixed_item the item which keeps it's position
744  @param item_to_move the item which will be moved */
745 extern void proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move);
746
747
748 /** Set start and length of an appendix for a proto_tree.
749   @param tree the tree to set the appendix start and length
750   @param tvb the tv buffer of the current data
751   @param start the start offset of the appendix
752   @param length the length of the appendix */
753 extern void proto_tree_set_appendix(proto_tree *tree, tvbuff_t *tvb, gint start, const gint length);
754
755
756 /** Add an item to a proto_tree, using the text label registered to that item.
757    The item is extracted from the tvbuff handed to it.
758  @param tree the tree to append this item to
759  @param hfindex field index
760  @param tvb the tv buffer of the current data
761  @param start start of data in tvb
762  @param length length of data in tvb
763  @param encoding data encoding
764  @return the newly created item */
765 extern proto_item *
766 proto_tree_add_item(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
767     const gint start, gint length, const guint encoding);
768
769 /** Add a text-only node to a proto_tree.
770  @param tree the tree to append this item to
771  @param tvb the tv buffer of the current data
772  @param start start of data in tvb
773  @param length length of data in tvb
774  @param format printf like format string
775  @param ... printf like parameters
776  @return the newly created item */
777 extern proto_item *
778 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *format,
779         ...) G_GNUC_PRINTF(5,6);
780
781 /** Add a text-only node to a proto_tree using a variable argument list.
782  @param tree the tree to append this item to
783  @param tvb the tv buffer of the current data
784  @param start start of data in tvb
785  @param length length of data in tvb
786  @param format printf like format string
787  @param ap variable argument list
788  @return the newly created item */
789 extern proto_item *
790 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
791         gint length, const char *format, va_list ap);
792
793
794 /** Add a FT_NONE field to a proto_tree.
795  @param tree the tree to append this item to
796  @param hfindex field index
797  @param tvb the tv buffer of the current data
798  @param start start of data in tvb
799  @param length length of data in tvb
800  @param format printf like format string
801  @param ... printf like parameters
802  @return the newly created item */
803 extern proto_item *
804 proto_tree_add_none_format(proto_tree *tree, const int hfindex, tvbuff_t *tvb, const gint start,
805         gint length, const char *format, ...) G_GNUC_PRINTF(6,7);
806
807 /** Add a FT_PROTOCOL to a proto_tree.
808  @param tree the tree to append this item to
809  @param hfindex field index
810  @param tvb the tv buffer of the current data
811  @param start start of data in tvb
812  @param length length of data in tvb
813  @param format printf like format string
814  @param ... printf like parameters
815  @return the newly created item */
816 extern proto_item *
817 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
818         gint length, const char *format, ...) G_GNUC_PRINTF(6,7);
819
820
821
822
823 /** Add a FT_BYTES to a proto_tree.
824  @param tree the tree to append this item to
825  @param hfindex field index
826  @param tvb the tv buffer of the current data
827  @param start start of data in tvb
828  @param length length of data in tvb
829  @param start_ptr pointer to the data to display
830  @return the newly created item */
831 extern proto_item *
832 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
833         gint length, const guint8* start_ptr);
834
835 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
836     the string for the value and with the field name being included
837     automatically.
838  @param tree the tree to append this item to
839  @param hfindex field index
840  @param tvb the tv buffer of the current data
841  @param start start of data in tvb
842  @param length length of data in tvb
843  @param start_ptr pointer to the data to display
844  @param format printf like format string
845  @param ... printf like parameters
846  @return the newly created item */
847 extern proto_item *
848 proto_tree_add_bytes_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
849         gint start, gint length, const guint8* start_ptr, const char *format,
850         ...) G_GNUC_PRINTF(7,8);
851
852 /** Add a formatted FT_BYTES to a proto_tree, with the format generating
853     the entire string for the entry, including any field name.
854  @param tree the tree to append this item to
855  @param hfindex field index
856  @param tvb the tv buffer of the current data
857  @param start start of data in tvb
858  @param length length of data in tvb
859  @param start_ptr pointer to the data to display
860  @param format printf like format string
861  @param ... printf like parameters
862  @return the newly created item */
863 extern proto_item *
864 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
865         gint length, const guint8* start_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
866
867 /** Add a FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree.
868  @param tree the tree to append this item to
869  @param hfindex field index
870  @param tvb the tv buffer of the current data
871  @param start start of data in tvb
872  @param length length of data in tvb
873  @param value_ptr pointer to the data to display
874  @return the newly created item */
875 extern proto_item *
876 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
877         gint length, nstime_t* value_ptr);
878
879 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
880     the format generating the string for the value and with the field name
881     being included automatically.
882  @param tree the tree to append this item to
883  @param hfindex field index
884  @param tvb the tv buffer of the current data
885  @param start start of data in tvb
886  @param length length of data in tvb
887  @param value_ptr pointer to the data to display
888  @param format printf like format string
889  @param ... printf like parameters
890  @return the newly created item */
891 extern proto_item *
892 proto_tree_add_time_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
893         gint start, gint length, nstime_t* value_ptr, const char *format, ...)
894         G_GNUC_PRINTF(7,8);
895
896 /** Add a formatted FT_ABSOLUTE_TIME or FT_RELATIVE_TIME to a proto_tree, with
897     the format generating the entire string for the entry, including any field
898     name.
899  @param tree the tree to append this item to
900  @param hfindex field index
901  @param tvb the tv buffer of the current data
902  @param start start of data in tvb
903  @param length length of data in tvb
904  @param value_ptr pointer to the data to display
905  @param format printf like format string
906  @param ... printf like parameters
907  @return the newly created item */
908 extern proto_item *
909 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
910         gint length, nstime_t* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
911
912 /** Add a FT_IPXNET to a proto_tree.
913  @param tree the tree to append this item to
914  @param hfindex field index
915  @param tvb the tv buffer of the current data
916  @param start start of data in tvb
917  @param length length of data in tvb
918  @param value data to display
919  @return the newly created item */
920 extern proto_item *
921 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
922         gint length, guint32 value);
923
924 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
925     the string for the value and with the field name being included
926     automatically.
927  @param tree the tree to append this item to
928  @param hfindex field index
929  @param tvb the tv buffer of the current data
930  @param start start of data in tvb
931  @param length length of data in tvb
932  @param value data to display
933  @param format printf like format string
934  @param ... printf like parameters
935  @return the newly created item */
936 extern proto_item *
937 proto_tree_add_ipxnet_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
938         gint start, gint length, guint32 value, const char *format, ...)
939         G_GNUC_PRINTF(7,8);
940
941 /** Add a formatted FT_IPXNET to a proto_tree, with the format generating
942     the entire string for the entry, including any field name.
943  @param tree the tree to append this item to
944  @param hfindex field index
945  @param tvb the tv buffer of the current data
946  @param start start of data in tvb
947  @param length length of data in tvb
948  @param value data to display
949  @param format printf like format string
950  @param ... printf like parameters
951  @return the newly created item */
952 extern proto_item *
953 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
954         gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
955
956 /** Add a FT_IPv4 to a proto_tree.
957  @param tree the tree to append this item to
958  @param hfindex field index
959  @param tvb the tv buffer of the current data
960  @param start start of data in tvb
961  @param length length of data in tvb
962  @param value data to display
963  @return the newly created item */
964 extern proto_item *
965 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
966         gint length, guint32 value);
967
968 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
969     the string for the value and with the field name being included
970     automatically.
971  @param tree the tree to append this item to
972  @param hfindex field index
973  @param tvb the tv buffer of the current data
974  @param start start of data in tvb
975  @param length length of data in tvb
976  @param value data to display
977  @param format printf like format string
978  @param ... printf like parameters
979  @return the newly created item */
980 extern proto_item *
981 proto_tree_add_ipv4_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
982         gint start, gint length, guint32 value, const char *format, ...)
983         G_GNUC_PRINTF(7,8);
984
985 /** Add a formatted FT_IPv4 to a proto_tree, with the format generating
986     the entire string for the entry, including any field name.
987  @param tree the tree to append this item to
988  @param hfindex field index
989  @param tvb the tv buffer of the current data
990  @param start start of data in tvb
991  @param length length of data in tvb
992  @param value data to display
993  @param format printf like format string
994  @param ... printf like parameters
995  @return the newly created item */
996 extern proto_item *
997 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
998         gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
999
1000 /** Add a FT_IPv6 to a proto_tree.
1001  @param tree the tree to append this item to
1002  @param hfindex field index
1003  @param tvb the tv buffer of the current data
1004  @param start start of data in tvb
1005  @param length length of data in tvb
1006  @param value_ptr data to display
1007  @return the newly created item */
1008 extern proto_item *
1009 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1010         gint length, const guint8* value_ptr);
1011
1012 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1013     the string for the value and with the field name being included
1014     automatically.
1015  @param tree the tree to append this item to
1016  @param hfindex field index
1017  @param tvb the tv buffer of the current data
1018  @param start start of data in tvb
1019  @param length length of data in tvb
1020  @param value_ptr data to display
1021  @param format printf like format string
1022  @param ... printf like parameters
1023  @return the newly created item */
1024 extern proto_item *
1025 proto_tree_add_ipv6_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1026         gint start, gint length, const guint8* value_ptr, const char *format,
1027         ...) G_GNUC_PRINTF(7,8);
1028
1029 /** Add a formatted FT_IPv6 to a proto_tree, with the format generating
1030     the entire string for the entry, including any field name.
1031  @param tree the tree to append this item to
1032  @param hfindex field index
1033  @param tvb the tv buffer of the current data
1034  @param start start of data in tvb
1035  @param length length of data in tvb
1036  @param value_ptr data to display
1037  @param format printf like format string
1038  @param ... printf like parameters
1039  @return the newly created item */
1040 extern proto_item *
1041 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1042         gint length, const guint8* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1043
1044 /** Add a FT_AX25 to a proto_tree.
1045  @param tree the tree to append this item to
1046  @param hfindex field index
1047  @param tvb the tv buffer of the current data
1048  @param start start of data in tvb
1049  @param length length of data in tvb
1050  @param value data to display
1051  @return the newly created item */
1052 extern proto_item *
1053 proto_tree_add_ax25(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1054         gint length, const guint8* value);
1055
1056 /** Add a FT_ETHER to a proto_tree.
1057  @param tree the tree to append this item to
1058  @param hfindex field index
1059  @param tvb the tv buffer of the current data
1060  @param start start of data in tvb
1061  @param length length of data in tvb
1062  @param value data to display
1063  @return the newly created item */
1064 extern proto_item *
1065 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1066         gint length, const guint8* value);
1067
1068 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1069     the string for the value and with the field name being included
1070     automatically.
1071  @param tree the tree to append this item to
1072  @param hfindex field index
1073  @param tvb the tv buffer of the current data
1074  @param start start of data in tvb
1075  @param length length of data in tvb
1076  @param value data to display
1077  @param format printf like format string
1078  @param ... printf like parameters
1079  @return the newly created item */
1080 extern proto_item *
1081 proto_tree_add_ether_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1082         gint start, gint length, const guint8* value, const char *format, ...)
1083         G_GNUC_PRINTF(7,8);
1084
1085 /** Add a formatted FT_ETHER to a proto_tree, with the format generating
1086     the entire string for the entry, including any field name.
1087  @param tree the tree to append this item to
1088  @param hfindex field index
1089  @param tvb the tv buffer of the current data
1090  @param start start of data in tvb
1091  @param length length of data in tvb
1092  @param value data to display
1093  @param format printf like format string
1094  @param ... printf like parameters
1095  @return the newly created item */
1096 extern proto_item *
1097 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1098         gint length, const guint8* value, const char *format, ...) G_GNUC_PRINTF(7,8);
1099
1100 /** Add a FT_GUID to a proto_tree.
1101  @param tree the tree to append this item to
1102  @param hfindex field index
1103  @param tvb the tv buffer of the current data
1104  @param start start of data in tvb
1105  @param length length of data in tvb
1106  @param value_ptr data to display
1107  @return the newly created item */
1108 extern proto_item *
1109 proto_tree_add_guid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1110         gint length, const e_guid_t *value_ptr);
1111
1112 /** Add a formatted FT_GUID to a proto_tree, with the format generating
1113     the string for the value and with the field name being included
1114     automatically.
1115  @param tree the tree to append this item to
1116  @param hfindex field index
1117  @param tvb the tv buffer of the current data
1118  @param start start of data in tvb
1119  @param length length of data in tvb
1120  @param value_ptr data to display
1121  @param format printf like format string
1122  @param ... printf like parameters
1123  @return the newly created item */
1124 extern proto_item *
1125 proto_tree_add_guid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1126         gint start, gint length, const e_guid_t *value_ptr, const char *format,
1127         ...) G_GNUC_PRINTF(7,8);
1128
1129 /** Add a formatted FT_GUID to a proto_tree, with the format generating
1130     the entire string for the entry, including any field name.
1131  @param tree the tree to append this item to
1132  @param hfindex field index
1133  @param tvb the tv buffer of the current data
1134  @param start start of data in tvb
1135  @param length length of data in tvb
1136  @param value_ptr data to display
1137  @param format printf like format string
1138  @param ... printf like parameters
1139  @return the newly created item */
1140 extern proto_item *
1141 proto_tree_add_guid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1142         gint length, const e_guid_t *value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1143
1144 /** Add a FT_OID to a proto_tree.
1145  @param tree the tree to append this item to
1146  @param hfindex field index
1147  @param tvb the tv buffer of the current data
1148  @param start start of data in tvb
1149  @param length length of data in tvb
1150  @param value_ptr data to display
1151  @return the newly created item */
1152 extern proto_item *
1153 proto_tree_add_oid(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1154         gint length, const guint8* value_ptr);
1155
1156 /** Add a formatted FT_OID to a proto_tree, with the format generating
1157     the string for the value and with the field name being included
1158     automatically.
1159  @param tree the tree to append this item to
1160  @param hfindex field index
1161  @param tvb the tv buffer of the current data
1162  @param start start of data in tvb
1163  @param length length of data in tvb
1164  @param value_ptr data to display
1165  @param format printf like format string
1166  @param ... printf like parameters
1167  @return the newly created item */
1168 extern proto_item *
1169 proto_tree_add_oid_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1170         gint start, gint length, const guint8* value_ptr, const char *format,
1171         ...) G_GNUC_PRINTF(7,8);
1172
1173 /** Add a formatted FT_OID to a proto_tree, with the format generating
1174     the entire string for the entry, including any field name.
1175  @param tree the tree to append this item to
1176  @param hfindex field index
1177  @param tvb the tv buffer of the current data
1178  @param start start of data in tvb
1179  @param length length of data in tvb
1180  @param value_ptr data to display
1181  @param format printf like format string
1182  @param ... printf like parameters
1183  @return the newly created item */
1184 extern proto_item *
1185 proto_tree_add_oid_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1186         gint length, const guint8* value_ptr, const char *format, ...) G_GNUC_PRINTF(7,8);
1187
1188 /** Add a FT_STRING to a proto_tree.
1189  @param tree the tree to append this item to
1190  @param hfindex field index
1191  @param tvb the tv buffer of the current data
1192  @param start start of data in tvb
1193  @param length length of data in tvb
1194  @param value data to display
1195  @return the newly created item */
1196 extern proto_item *
1197 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1198         gint length, const char* value);
1199
1200 /** Add a formatted FT_STRING to a proto_tree, with the format generating
1201     the string for the value and with the field name being included
1202     automatically.
1203  @param tree the tree to append this item to
1204  @param hfindex field index
1205  @param tvb the tv buffer of the current data
1206  @param start start of data in tvb
1207  @param length length of data in tvb
1208  @param value data to display
1209  @param format printf like format string
1210  @param ... printf like parameters
1211  @return the newly created item */
1212 extern proto_item *
1213 proto_tree_add_string_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1214         gint start, gint length, const char* value, const char *format, ...)
1215         G_GNUC_PRINTF(7,8);
1216
1217 /** Add a formatted FT_STRING to a proto_tree, with the format generating
1218     the entire string for the entry, including any field name.
1219  @param tree the tree to append this item to
1220  @param hfindex field index
1221  @param tvb the tv buffer of the current data
1222  @param start start of data in tvb
1223  @param length length of data in tvb
1224  @param value data to display
1225  @param format printf like format string
1226  @param ... printf like parameters
1227  @return the newly created item */
1228 extern proto_item *
1229 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1230         gint length, const char* value, const char *format, ...) G_GNUC_PRINTF(7,8);
1231
1232 extern proto_item *
1233 proto_tree_add_unicode_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1234                       gint length, const char* value);
1235
1236 /** Add a FT_BOOLEAN to a proto_tree.
1237  @param tree the tree to append this item to
1238  @param hfindex field index
1239  @param tvb the tv buffer of the current data
1240  @param start start of data in tvb
1241  @param length length of data in tvb
1242  @param value data to display
1243  @return the newly created item */
1244 extern proto_item *
1245 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1246         gint length, guint32 value);
1247
1248 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
1249     the string for the value and with the field name being included
1250     automatically.
1251  @param tree the tree to append this item to
1252  @param hfindex field index
1253  @param tvb the tv buffer of the current data
1254  @param start start of data in tvb
1255  @param length length of data in tvb
1256  @param value data to display
1257  @param format printf like format string
1258  @param ... printf like parameters
1259  @return the newly created item */
1260 extern proto_item *
1261 proto_tree_add_boolean_format_value(proto_tree *tree, int hfindex,
1262         tvbuff_t *tvb, gint start, gint length, guint32 value,
1263         const char *format, ...) G_GNUC_PRINTF(7,8);
1264
1265 /** Add a formatted FT_BOOLEAN to a proto_tree, with the format generating
1266     the entire string for the entry, including any field name.
1267  @param tree the tree to append this item to
1268  @param hfindex field index
1269  @param tvb the tv buffer of the current data
1270  @param start start of data in tvb
1271  @param length length of data in tvb
1272  @param value data to display
1273  @param format printf like format string
1274  @param ... printf like parameters
1275  @return the newly created item */
1276 extern proto_item *
1277 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1278         gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1279
1280 /** Add a FT_FLOAT to a proto_tree.
1281  @param tree the tree to append this item to
1282  @param hfindex field index
1283  @param tvb the tv buffer of the current data
1284  @param start start of data in tvb
1285  @param length length of data in tvb
1286  @param value data to display
1287  @return the newly created item */
1288 extern proto_item *
1289 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1290         gint length, float value);
1291
1292 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1293     the string for the value and with the field name being included
1294     automatically.
1295  @param tree the tree to append this item to
1296  @param hfindex field index
1297  @param tvb the tv buffer of the current data
1298  @param start start of data in tvb
1299  @param length length of data in tvb
1300  @param value data to display
1301  @param format printf like format string
1302  @param ... printf like parameters
1303  @return the newly created item */
1304 extern proto_item *
1305 proto_tree_add_float_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1306         gint start, gint length, float value, const char *format, ...)
1307         G_GNUC_PRINTF(7,8);
1308
1309 /** Add a formatted FT_FLOAT to a proto_tree, with the format generating
1310     the entire string for the entry, including any field name.
1311  @param tree the tree to append this item to
1312  @param hfindex field index
1313  @param tvb the tv buffer of the current data
1314  @param start start of data in tvb
1315  @param length length of data in tvb
1316  @param value data to display
1317  @param format printf like format string
1318  @param ... printf like parameters
1319  @return the newly created item */
1320 extern proto_item *
1321 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1322         gint length, float value, const char *format, ...) G_GNUC_PRINTF(7,8);
1323
1324 /** Add a FT_DOUBLE to a proto_tree.
1325  @param tree the tree to append this item to
1326  @param hfindex field index
1327  @param tvb the tv buffer of the current data
1328  @param start start of data in tvb
1329  @param length length of data in tvb
1330  @param value data to display
1331  @return the newly created item */
1332 extern proto_item *
1333 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1334         gint length, double value);
1335
1336 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1337     the string for the value and with the field name being included
1338     automatically.
1339  @param tree the tree to append this item to
1340  @param hfindex field index
1341  @param tvb the tv buffer of the current data
1342  @param start start of data in tvb
1343  @param length length of data in tvb
1344  @param value data to display
1345  @param format printf like format string
1346  @param ... printf like parameters
1347  @return the newly created item */
1348 extern proto_item *
1349 proto_tree_add_double_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1350         gint start, gint length, double value, const char *format, ...)
1351         G_GNUC_PRINTF(7,8);
1352
1353 /** Add a formatted FT_DOUBLE to a proto_tree, with the format generating
1354     the entire string for the entry, including any field name.
1355  @param tree the tree to append this item to
1356  @param hfindex field index
1357  @param tvb the tv buffer of the current data
1358  @param start start of data in tvb
1359  @param length length of data in tvb
1360  @param value data to display
1361  @param format printf like format string
1362  @param ... printf like parameters
1363  @return the newly created item */
1364 extern proto_item *
1365 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1366         gint length, double value, const char *format, ...) G_GNUC_PRINTF(7,8);
1367
1368 /** Add one of FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree.
1369  @param tree the tree to append this item to
1370  @param hfindex field index
1371  @param tvb the tv buffer of the current data
1372  @param start start of data in tvb
1373  @param length length of data in tvb
1374  @param value data to display
1375  @return the newly created item */
1376 extern proto_item *
1377 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1378         gint length, guint32 value);
1379
1380 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1381     with the format generating the string for the value and with the field
1382     name being included automatically.
1383  @param tree the tree to append this item to
1384  @param hfindex field index
1385  @param tvb the tv buffer of the current data
1386  @param start start of data in tvb
1387  @param length length of data in tvb
1388  @param value data to display
1389  @param format printf like format string
1390  @param ... printf like parameters
1391  @return the newly created item */
1392 extern proto_item *
1393 proto_tree_add_uint_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1394         gint start, gint length, guint32 value, const char *format, ...)
1395         G_GNUC_PRINTF(7,8);
1396
1397 /** Add a formatted FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32 to a proto_tree,
1398     with the format generating the entire string for the entry, including any
1399     field name.
1400  @param tree the tree to append this item to
1401  @param hfindex field index
1402  @param tvb the tv buffer of the current data
1403  @param start start of data in tvb
1404  @param length length of data in tvb
1405  @param value data to display
1406  @param format printf like format string
1407  @param ... printf like parameters
1408  @return the newly created item */
1409 extern proto_item *
1410 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1411         gint length, guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1412
1413 /** Add an FT_UINT64 to a proto_tree.
1414  @param tree the tree to append this item to
1415  @param hfindex field index
1416  @param tvb the tv buffer of the current data
1417  @param start start of data in tvb
1418  @param length length of data in tvb
1419  @param value data to display
1420  @return the newly created item */
1421 extern proto_item *
1422 proto_tree_add_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1423         gint length, guint64 value);
1424
1425 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1426     the string for the value and with the field name being included
1427     automatically.
1428  @param tree the tree to append this item to
1429  @param hfindex field index
1430  @param tvb the tv buffer of the current data
1431  @param start start of data in tvb
1432  @param length length of data in tvb
1433  @param value data to display
1434  @param format printf like format string
1435  @param ... printf like parameters
1436  @return the newly created item */
1437 extern proto_item *
1438 proto_tree_add_uint64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1439         gint start, gint length, guint64 value, const char *format, ...)
1440         G_GNUC_PRINTF(7,8);
1441
1442 /** Add a formatted FT_UINT64 to a proto_tree, with the format generating
1443     the entire string for the entry, including any field name.
1444  @param tree the tree to append this item to
1445  @param hfindex field index
1446  @param tvb the tv buffer of the current data
1447  @param start start of data in tvb
1448  @param length length of data in tvb
1449  @param value data to display
1450  @param format printf like format string
1451  @param ... printf like parameters
1452  @return the newly created item */
1453 extern proto_item *
1454 proto_tree_add_uint64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1455         gint length, guint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1456
1457 /** Add one of FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree.
1458  @param tree the tree to append this item to
1459  @param hfindex field index
1460  @param tvb the tv buffer of the current data
1461  @param start start of data in tvb
1462  @param length length of data in tvb
1463  @param value data to display
1464  @return the newly created item */
1465 extern proto_item *
1466 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1467         gint length, gint32 value);
1468
1469 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1470     with the format generating the string for the value and with the field
1471     name being included automatically.
1472  @param tree the tree to append this item to
1473  @param hfindex field index
1474  @param tvb the tv buffer of the current data
1475  @param start start of data in tvb
1476  @param length length of data in tvb
1477  @param value data to display
1478  @param format printf like format string
1479  @param ... printf like parameters
1480  @return the newly created item */
1481 extern proto_item *
1482 proto_tree_add_int_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1483         gint start, gint length, gint32 value, const char *format, ...)
1484         G_GNUC_PRINTF(7,8);
1485
1486 /** Add a formatted FT_INT8, FT_INT16, FT_INT24 or FT_INT32 to a proto_tree,
1487     with the format generating the entire string for the entry, including
1488     any field name.
1489  @param tree the tree to append this item to
1490  @param hfindex field index
1491  @param tvb the tv buffer of the current data
1492  @param start start of data in tvb
1493  @param length length of data in tvb
1494  @param value data to display
1495  @param format printf like format string
1496  @param ... printf like parameters
1497  @return the newly created item */
1498 extern proto_item *
1499 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1500         gint length, gint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1501
1502 /** Add an FT_INT64 to a proto_tree.
1503  @param tree the tree to append this item to
1504  @param hfindex field index
1505  @param tvb the tv buffer of the current data
1506  @param start start of data in tvb
1507  @param length length of data in tvb
1508  @param value data to display
1509  @return the newly created item */
1510 extern proto_item *
1511 proto_tree_add_int64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1512         gint length, gint64 value);
1513
1514 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1515     the string for the value and with the field name being included
1516     automatically.
1517  @param tree the tree to append this item to
1518  @param hfindex field index
1519  @param tvb the tv buffer of the current data
1520  @param start start of data in tvb
1521  @param length length of data in tvb
1522  @param value data to display
1523  @param format printf like format string
1524  @param ... printf like parameters
1525  @return the newly created item */
1526 extern proto_item *
1527 proto_tree_add_int64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1528         gint start, gint length, gint64 value, const char *format, ...)
1529         G_GNUC_PRINTF(7,8);
1530
1531 /** Add a formatted FT_INT64 to a proto_tree, with the format generating
1532     the entire string for the entry, including any field name.
1533  @param tree the tree to append this item to
1534  @param hfindex field index
1535  @param tvb the tv buffer of the current data
1536  @param start start of data in tvb
1537  @param length length of data in tvb
1538  @param value data to display
1539  @param format printf like format string
1540  @param ... printf like parameters
1541  @return the newly created item */
1542 extern proto_item *
1543 proto_tree_add_int64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1544         gint length, gint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1545
1546 /** Add a FT_EUI64 to a proto_tree.
1547  @param tree the tree to append this item to
1548  @param hfindex field index
1549  @param tvb the tv buffer of the current data
1550  @param start start of data in tvb
1551  @param length length of data in tvb
1552  @param value data to display
1553  @return the newly created item */
1554 extern proto_item *
1555 proto_tree_add_eui64(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1556         gint length, const guint64 value);
1557
1558 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
1559     the string for the value and with the field name being included
1560     automatically.
1561  @param tree the tree to append this item to
1562  @param hfindex field index
1563  @param tvb the tv buffer of the current data
1564  @param start start of data in tvb
1565  @param length length of data in tvb
1566  @param value data to display
1567  @param format printf like format string
1568  @param ... printf like parameters
1569  @return the newly created item */
1570 extern proto_item *
1571 proto_tree_add_eui64_format_value(proto_tree *tree, int hfindex, tvbuff_t *tvb,
1572         gint start, gint length, const guint64 value, const char *format, ...)
1573         G_GNUC_PRINTF(7,8);
1574
1575 /** Add a formatted FT_EUI64 to a proto_tree, with the format generating
1576     the entire string for the entry, including any field name.
1577  @param tree the tree to append this item to
1578  @param hfindex field index
1579  @param tvb the tv buffer of the current data
1580  @param start start of data in tvb
1581  @param length length of data in tvb
1582  @param value data to display
1583  @param format printf like format string
1584  @param ... printf like parameters
1585  @return the newly created item */
1586 extern proto_item *
1587 proto_tree_add_eui64_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
1588         gint length, const guint64 value, const char *format, ...) G_GNUC_PRINTF(7,8);
1589
1590
1591 /** Useful for quick debugging. Also sends string to STDOUT, so don't
1592     leave call to this function in production code.
1593  @param tree the tree to append the text to
1594  @param format printf like format string
1595  @param ... printf like parameters
1596  @return the newly created item */
1597 extern proto_item *
1598 proto_tree_add_debug_text(proto_tree *tree, const char *format,
1599         ...) G_GNUC_PRINTF(2,3);
1600
1601
1602
1603 /** Append a string to a protocol item.<br>
1604     NOTE: this function will break with the TRY_TO_FAKE_THIS_ITEM()
1605     speed optimization.
1606     Currently only WSP use this function so it is not that bad but try to
1607     avoid using this one if possible.
1608     IF you must use this function you MUST also disable the
1609     TRY_TO_FAKE_THIS_ITEM() optimization for your dissector/function
1610     using proto_item_append_string().
1611     Do that by faking that the tree is visible by calling
1612     proto_tree_set_visible(tree, TRUE) (see packet-wsp.c)
1613     BEFORE you create the item you are later going to use
1614     proto_item_append_string() on.
1615  @param pi the item to append the string to
1616  @param str the string to append */
1617 extern void
1618 proto_item_append_string(proto_item *pi, const char *str);
1619
1620
1621
1622 /** Fill given label_str with string representation of field
1623  @param fi the item to get the info from
1624  @param label_str the string to fill
1625  @todo think about changing the parameter profile */
1626 extern void
1627 proto_item_fill_label(field_info *fi, gchar *label_str);
1628
1629
1630 /** Register a new protocol.
1631  @param name the full name of the new protocol
1632  @param short_name abbreviated name of the new protocol
1633  @param filter_name protocol name used for a display filter string
1634  @return the new protocol handle */
1635 extern int
1636 proto_register_protocol(const char *name, const char *short_name, const char *filter_name);
1637
1638 /** Mark protocol as private
1639  @param proto_id the handle of the protocol */
1640 extern void
1641 proto_mark_private(const int proto_id);
1642
1643 /** Return if protocol is private
1644  @param proto_id the handle of the protocol
1645  @return TRUE if it is a private protocol, FALSE is not. */
1646 extern gboolean
1647 proto_is_private(const int proto_id);
1648
1649 /** This is the type of function can be registered to get called whenever
1650     a given field was not found but a its prefix is matched
1651         it can be used to procrastinate the hf array registration
1652    @param match  what's being matched */
1653 typedef void (*prefix_initializer_t)(const char* match);
1654
1655 /** Register a new prefix for delayed initialization of field arrays
1656 @param prefix the prefix for the new protocol
1657 @param initializer function that will initialize the field array for the given prefix */
1658 extern void
1659 proto_register_prefix(const char *prefix,  prefix_initializer_t initializer);
1660
1661 /** Initialize every remaining uninitialized prefix. */
1662 extern void proto_initialize_all_prefixes(void);
1663
1664 /** Register a header_field array.
1665  @param parent the protocol handle from proto_register_protocol()
1666  @param hf the hf_register_info array
1667  @param num_records the number of records in hf */
1668 extern void
1669 proto_register_field_array(const int parent, hf_register_info *hf, const int num_records);
1670
1671 /** Unregister an already registered field.
1672  @param parent the protocol handle from proto_register_protocol()
1673  @param hf_id the field to unregister */
1674 extern void
1675 proto_unregister_field (const int parent, gint hf_id);
1676
1677 /** Register a protocol subtree (ett) array.
1678  @param indices array of ett indices
1679  @param num_indices the number of records in indices */
1680 extern void
1681 proto_register_subtree_array(gint *const *indices, const int num_indices);
1682
1683 /** Returns number of items (protocols or header fields) registered.
1684  @return the number of items */
1685 extern int proto_registrar_n(void);
1686
1687 /** Get name of registered header_field number n.
1688  @param n item # n (0-indexed)
1689  @return the name of this registered item */
1690 extern const char* proto_registrar_get_name(const int n);
1691
1692 /** Get abbreviation of registered header_field number n.
1693  @param n item # n (0-indexed)
1694  @return the abbreviation of this registered item */
1695 extern const char* proto_registrar_get_abbrev(const int n);
1696
1697 /** Get the header_field information based upon a field or protocol id.
1698  @param hfindex item # n (0-indexed)
1699  @return the registered item */
1700 extern header_field_info* proto_registrar_get_nth(guint hfindex);
1701
1702 /** Get the header_field information based upon a field name.
1703  @param field_name the field name to search for
1704  @return the registered item */
1705 extern header_field_info* proto_registrar_get_byname(const char *field_name);
1706
1707 /** Get enum ftenum FT_ of registered header_field number n.
1708  @param n item # n (0-indexed)
1709  @return the registered item */
1710 extern enum ftenum proto_registrar_get_ftype(const int n);
1711
1712 /** Get parent protocol of registered header_field number n.
1713  @param n item # n (0-indexed)
1714  @return -1 if item _is_ a protocol */
1715 extern int proto_registrar_get_parent(const int n);
1716
1717 /** Is item # n a protocol?
1718  @param n item # n (0-indexed)
1719  @return TRUE if it's a protocol, FALSE if it's not */
1720 extern gboolean proto_registrar_is_protocol(const int n);
1721
1722 /** Get length of registered field according to field type.
1723  @param n item # n (0-indexed)
1724  @return 0 means undeterminable at registration time, -1 means unknown field */
1725 extern gint proto_registrar_get_length(const int n);
1726
1727
1728 /** Routines to use to iterate over the protocols and their fields;
1729  * they return the item number of the protocol in question or the
1730  * appropriate hfinfo pointer, and keep state in "*cookie". */
1731 extern int proto_get_first_protocol(void **cookie);
1732 extern int proto_get_data_protocol(void *cookie);
1733 extern int proto_get_next_protocol(void **cookie);
1734 extern header_field_info *proto_get_first_protocol_field(const int proto_id, void **cookle);
1735 extern header_field_info *proto_get_next_protocol_field(void **cookle);
1736
1737 /** Given a protocol's filter_name.
1738  @param filter_name the filter name to search for
1739  @return proto_id */
1740 extern int proto_get_id_by_filter_name(const gchar* filter_name);
1741
1742 /** Can item # n decoding be disabled?
1743  @param proto_id protocol id (0-indexed)
1744  @return TRUE if it's a protocol, FALSE if it's not */
1745 extern gboolean proto_can_toggle_protocol(const int proto_id);
1746
1747 /** Get the "protocol_t" structure for the given protocol's item number.
1748  @param proto_id protocol id (0-indexed) */
1749 extern protocol_t *find_protocol_by_id(const int proto_id);
1750
1751 /** Get the protocol's name for the given protocol's item number.
1752  @param proto_id protocol id (0-indexed)
1753  @return its name */
1754 extern const char *proto_get_protocol_name(const int proto_id);
1755
1756 /** Get the protocol's item number, for the given protocol's "protocol_t".
1757  @return its proto_id */
1758 extern int proto_get_id(const protocol_t *protocol);
1759
1760 /** Get the protocol's short name, for the given protocol's "protocol_t".
1761  @return its short name. */
1762 extern const char *proto_get_protocol_short_name(const protocol_t *protocol);
1763
1764 /** Get the protocol's long name, for the given protocol's "protocol_t".
1765  @return its long name. */
1766 extern const char *proto_get_protocol_long_name(const protocol_t *protocol);
1767
1768 /** Is protocol's decoding enabled ?
1769  @param protocol
1770  @return TRUE if decoding is enabled, FALSE if not */
1771 extern gboolean proto_is_protocol_enabled(const protocol_t *protocol);
1772
1773 /** Get a protocol's filter name by it's item number.
1774  @param proto_id protocol id (0-indexed)
1775  @return its filter name. */
1776 extern const char *proto_get_protocol_filter_name(const int proto_id);
1777
1778 /** Enable / Disable protocol of the given item number.
1779  @param proto_id protocol id (0-indexed)
1780  @param enabled enable / disable the protocol */
1781 extern void proto_set_decoding(const int proto_id, const gboolean enabled);
1782
1783 /** Enable all protocols */
1784 extern void proto_enable_all(void);
1785
1786 /** Disable disabling/enabling of protocol of the given item number.
1787  @param proto_id protocol id (0-indexed) */
1788 extern void proto_set_cant_toggle(const int proto_id);
1789
1790 /** Checks for existence any protocol or field within a tree.
1791  @param tree "Protocols" are assumed to be a child of the [empty] root node.
1792  @param id hfindex of protocol or field
1793  @return TRUE = found, FALSE = not found
1794  @todo add explanation of id parameter */
1795 extern gboolean proto_check_for_protocol_or_field(const proto_tree* tree, const int id);
1796
1797 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1798     tree. Only works with primed trees, and is fast.
1799  @param tree tree of interest
1800  @param hfindex primed hfindex
1801  @return GPtrArry pointer */
1802 extern GPtrArray* proto_get_finfo_ptr_array(const proto_tree *tree, const int hfindex);
1803
1804 /** Return whether we're tracking any interesting fields.
1805     Only works with primed trees, and is fast.
1806  @param tree tree of interest
1807  @return TRUE if we're tracking interesting fields */
1808 extern gboolean proto_tracking_interesting_fields(const proto_tree *tree);
1809
1810 /** Return GPtrArray* of field_info pointers for all hfindex that appear in
1811     tree. Works with any tree, primed or unprimed, and is slower than
1812     proto_get_finfo_ptr_array because it has to search through the tree.
1813  @param tree tree of interest
1814  @param hfindex index of field info of interest
1815  @return GPtrArry pointer */
1816 extern GPtrArray* proto_find_finfo(proto_tree *tree, const int hfindex);
1817
1818 /** Return GPtrArray* of field_info pointers containg all hfindexes that appear
1819     in tree.
1820  @param tree tree of interest
1821  @return GPtrArry pointer */
1822 extern GPtrArray* proto_all_finfos(proto_tree *tree);
1823
1824 /** Dumps a glossary of the protocol registrations to STDOUT */
1825 extern void proto_registrar_dump_protocols(void);
1826
1827 /** Dumps a glossary of the field value strings or true/false strings to STDOUT */
1828 extern void proto_registrar_dump_values(void);
1829
1830 /** Dumps a glossary of the protocol and field registrations to STDOUT.
1831  * Format 1 is the original format. Format 2 includes the base (for integers)
1832  * and the blurb. */
1833 extern void proto_registrar_dump_fields(const int format);
1834
1835 /** Dumps a glossary field types and descriptive names to STDOUT */
1836 extern void proto_registrar_dump_ftypes(void);
1837
1838
1839
1840 /** Points to the first element of an array of Booleans, indexed by
1841    a subtree item type. That array element is TRUE if subtrees of
1842    an item of that type are to be expanded. With MSVC and a
1843    libwireshark.dll, we need a special declaration. */
1844 WS_VAR_IMPORT gboolean       *tree_is_expanded;
1845
1846 /** Number of elements in the tree_is_expanded array. With MSVC and a
1847  * libwireshark.dll, we need a special declaration. */
1848 WS_VAR_IMPORT int           num_tree_types;
1849
1850 /** glib doesn't have g_ptr_array_len of all things!*/
1851 #ifndef g_ptr_array_len
1852 #define g_ptr_array_len(a)      ((a)?(a)->len:0)
1853 #endif
1854
1855 /** Get number of bits of a header_field.
1856  @param hfinfo header_field
1857  @return the bitwidth */
1858 extern int
1859 hfinfo_bitwidth(const header_field_info *hfinfo);
1860
1861
1862
1863
1864 #include "epan.h"
1865
1866 /** Can we do a "match selected" on this field.
1867  @param finfo field_info
1868  @param edt epan dissecting
1869  @return TRUE if we can do a "match selected" on the field, FALSE otherwise. */
1870 extern gboolean
1871 proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
1872
1873 /** Construct a "match selected" display filter string.
1874  @param finfo field_info
1875  @param edt epan dissecting
1876  @return the display filter string */
1877 extern char*
1878 proto_construct_match_selected_string(field_info *finfo, epan_dissect_t *edt);
1879
1880 /** Find field from offset in tvb.
1881  @param tree tree of interest
1882  @param offset offset in the tvb
1883  @param tvb the tv buffer
1884  @return the corresponding field_info */
1885 extern field_info*
1886 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);
1887
1888 /** This function will dissect a sequence of bytes that describe a bitmask.
1889  @param tree the tree to append this item to
1890  @param tvb the tv buffer of the current data
1891  @param offset start of data in tvb
1892  @param hf_hdr an 8/16/24/32 bit integer that describes the bitmask to be dissected.
1893         This field will form an expansion under which the individual fields of the
1894         bitmask is dissected and displayed.
1895         This field must be of the type FT_[U]INT{8|16|24|32}.
1896  @param ett subtree index
1897  @param fields an array of pointers to int that lists all the fields of the
1898         bitmask. These fields can be either of the type FT_BOOLEAN for flags
1899         or another integer of the same type/size as hf_hdr with a mask specified.
1900         This array is terminated by a NULL entry.
1901         FT_BOOLEAN bits that are set to 1 will have the name added to the expansion.
1902         FT_integer fields that have a value_string attached will have the
1903         matched string displayed on the expansion line.
1904  @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN)
1905  @return the newly created item */
1906 extern proto_item *
1907 proto_tree_add_bitmask(proto_tree *tree, tvbuff_t *tvb, const guint offset,
1908                 const int hf_hdr, const gint ett, const int **fields, const guint encoding);
1909
1910 /** Add a text with a subtree of bitfields.
1911  @param tree the tree to append this item to
1912  @param tvb the tv buffer of the current data
1913  @param offset start of data in tvb
1914  @param len length of the field name
1915  @param name field name (NULL if bitfield contents should be used)
1916  @param fallback field name if none of bitfields were usable
1917  @param ett subtree index
1918  @param fields NULL-terminated array of bitfield indexes
1919  @param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN)
1920  @param flags
1921  @return the newly created item */
1922 extern proto_item *
1923 proto_tree_add_bitmask_text(proto_tree *tree, tvbuff_t *tvb, const guint offset, const guint len,
1924                 const char *name, const char *fallback,
1925                 const gint ett, const int **fields, const guint encoding, const int flags);
1926
1927 #define BMT_NO_APPEND   0x01    /**< Don't change the title at all */
1928 #define BMT_NO_INT      0x02    /**< Don't add integral (non-boolean) fields to title */
1929 #define BMT_NO_FALSE    0x04    /**< Don't add booleans unless they're TRUE */
1930 #define BMT_NO_TFS      0x08    /**< Don't use true_false_string while formatting booleans */
1931
1932 /** Add bits to a proto_tree, using the text label registered to that item.
1933    The item is extracted from the tvbuff handed to it.
1934  @param tree the tree to append this item to
1935  @param hf_index field index. Fields for use with this function should have bitmask==0.
1936  @param tvb the tv buffer of the current data
1937  @param bit_offset start of data in tvb expressed in bits
1938  @param no_of_bits length of data in tvb expressed in bits
1939  @param encoding data encoding
1940  @return the newly created item */
1941 extern proto_item *
1942 proto_tree_add_bits_item(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits, const guint encoding);
1943
1944 /** Add bits to a proto_tree, using the text label registered to that item.
1945 *  The item is extracted from the tvbuff handed to it as a set
1946 *  of crumbs (segments) of contiguous bits, specified by an
1947 *  array of crumb_spec elements.  The crumbs are assembled to
1948 *  create the value.  There may be any number of crumbs
1949 *  specifying up to a total of 64 bits which may occur anywhere
1950 *  within the tvb. If the span of the crumbs within the tvb is 4
1951 *  octets or less, a bitmap of the crumbs is produced.
1952  @param tree the tree to append this item to
1953  @param hf_index field index. Fields for use with this function should have bitmask==0.
1954  @param tvb the tv buffer of the current data
1955  @param bit_offset of the first crumb in tvb expressed in bits
1956  @param pointer to crumb_spec array
1957  @param return_value if a pointer is passed here the value is returned.
1958  @return the newly created item */
1959 extern proto_item *
1960 proto_tree_add_split_bits_item_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb,
1961                             const guint bit_offset, const crumb_spec_t *crumb_spec,
1962                             guint64 *return_value);
1963
1964
1965 /** Add bitmap text for a split-bits crumb to a proto_tree,
1966 *  using the text label registered to an item. The bitmap is
1967 *  extracted from the tvbuff handed to it as a crumb (segment)
1968 *  of contiguous bits, specified by one of an array of
1969 *  crumb_spec elements. This function is normally called once
1970 *  per crumb, after the call to
1971    proto_tree_add_split_bits_item_ret_val
1972  @param tree the tree to append this item to
1973  @param hf_index field index. Fields for use with this function should have bitmask==0.
1974  @param tvb the tv buffer of the current data
1975  @param bit_offset of the first crumb in tvb expressed in bits
1976  @param pointer to crumb_spec array
1977  @param index into the crumb_spec array for this crumb */
1978 void
1979 proto_tree_add_split_bits_crumb(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset,
1980                                 const crumb_spec_t *crumb_spec, guint16 crumb_index);
1981
1982 /** Add bits to a proto_tree, using the text label registered to that item.
1983    The item is extracted from the tvbuff handed to it.
1984  @param tree the tree to append this item to
1985  @param hf_index field index. Fields for use with this function should have bitmask==0.
1986  @param tvb the tv buffer of the current data
1987  @param bit_offset start of data in tvb expressed in bits
1988  @param no_of_bits length of data in tvb expressed in bits
1989  @param return_value if a pointer is passed here the value is returned.
1990  @param encoding data encoding
1991  @return the newly created item */
1992 extern proto_item *
1993 proto_tree_add_bits_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits, guint64 *return_value, const guint encoding);
1994
1995 /** Add bits for a FT_UINT8, FT_UINT16, FT_UINT24 or FT_UINT32
1996     header field to a proto_tree, with the format generating the
1997     string for the value and with the field name being included automatically.
1998  @param tree the tree to append this item to
1999  @param hf_index field index
2000  @param tvb the tv buffer of the current data
2001  @param bit_offset start of data in tvb expressed in bits
2002  @param no_of_bits length of data in tvb expressed in bit
2003  @param value data to display
2004  @param format printf like format string
2005  @return the newly created item */
2006 extern proto_item *
2007 proto_tree_add_uint_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2008         guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2009
2010 /** Add bits for a FT_BOOLEAN header field to a proto_tree, with
2011     the format generating the string for the value and with the field
2012     name being included automatically.
2013  @param tree the tree to append this item to
2014  @param hf_index field index
2015  @param tvb the tv buffer of the current data
2016  @param bit_offset start of data in tvb expressed in bits
2017  @param no_of_bits length of data in tvb expressed in bit
2018  @param value data to display
2019  @param format printf like format string
2020  @param ... printf like parameters
2021  @return the newly created item */
2022 extern proto_item *
2023 proto_tree_add_boolean_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2024         guint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2025
2026 /** Add bits for a FT_INT8, FT_INT16, FT_INT24 or FT_INT32
2027     header field to a proto_tree, with the format generating the
2028     string for the value and with the field name being included automatically.
2029  @param tree the tree to append this item to
2030  @param hf_index field index
2031  @param tvb the tv buffer of the current data
2032  @param bit_offset start of data in tvb expressed in bits
2033  @param no_of_bits length of data in tvb expressed in bit
2034  @param value data to display
2035  @param format printf like format string
2036  @param ... printf like parameters
2037  @return the newly created item */
2038 extern proto_item *
2039 proto_tree_add_int_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2040         gint32 value, const char *format, ...) G_GNUC_PRINTF(7,8);
2041
2042 /** Add bits for a FT_FLOAT header field to a proto_tree, with
2043     the format generating the string for the value and with the field
2044     name being included automatically.
2045  @param tree the tree to append this item to
2046  @param hf_index field index
2047  @param tvb the tv buffer of the current data
2048  @param bit_offset start of data in tvb expressed in bits
2049  @param no_of_bits length of data in tvb expressed in bit
2050  @param value data to display
2051  @param format printf like format string
2052  @param ... printf like parameters
2053  @return the newly created item */
2054 extern proto_item *
2055 proto_tree_add_float_bits_format_value(proto_tree *tree, const int hf_index, tvbuff_t *tvb, const guint bit_offset, const gint no_of_bits,
2056         float value, const char *format, ...) G_GNUC_PRINTF(7,8);
2057
2058 /** Check if given string is a valid field name
2059  @param field_name the field name to check
2060  @return 0 if valid, else first illegal character */
2061 extern guchar
2062 proto_check_field_name(const gchar *field_name);
2063
2064
2065 /** Check if given string is a valid field name
2066  @param tree the tree to append this item to
2067  @param field_id the field id used for custom column
2068  @param occurrence the occurrence of the field used for custom column
2069  @param result the buffer to fill with the field string
2070  @param expr the filter expression
2071  @param size the size of the string buffer */
2072 const gchar *
2073 proto_custom_set(proto_tree* tree, const int field_id,
2074                              gint occurrence,
2075                              gchar *result,
2076                              gchar *expr, const int size );
2077
2078 #ifdef __cplusplus
2079 }
2080 #endif /* __cplusplus */
2081
2082 #endif /* proto.h */