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