9aeca9e9a781a40f9e0a04b63fca52003da8e761
[obnox/wireshark/wip.git] / epan / proto.h
1 /* proto.h
2  * Definitions for protocol display
3  *
4  * $Id: proto.h,v 1.62 2004/05/09 09:26:31 ulfl Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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 #ifndef __PROTO_H__
26 #define __PROTO_H__
27
28 #ifdef HAVE_STDARG_H
29 # include <stdarg.h>
30 #else
31 # include <varargs.h>
32 #endif
33
34 #include <glib.h>
35
36 #include "ipv4.h"
37 #include "nstime.h"
38 #include "tvbuff.h"
39 #include "ftypes/ftypes.h"
40
41 /* The header-field index for the special text pseudo-field */
42 extern int hf_text_only;
43
44 struct _value_string;
45
46 #define ITEM_LABEL_LENGTH       240
47
48 /* In order to make a const value_string[] look like a value_string*, I
49  * need this macro */
50 #define VALS(x) (const struct _value_string*)(x)
51
52 /* ... and similarly for bitfield strings */
53 #define TFS(x)  (const struct true_false_string*)(x)
54
55 struct _protocol;
56 typedef struct _protocol protocol_t;
57  
58 /* check protocol activation */
59 #define CHECK_DISPLAY_AS_X(x_handle,index, tvb, pinfo, tree) {  \
60         if (!proto_is_protocol_enabled(find_protocol_by_id(index))) {   \
61                 call_dissector(x_handle,tvb, pinfo, tree);              \
62                 return;                                                 \
63         }                                                               \
64   }
65
66 /* values for header_field_info.display */
67 enum {
68         BASE_NONE,
69         BASE_DEC,
70         BASE_HEX,
71         BASE_OCT
72 };
73
74 typedef struct _header_field_info header_field_info;
75
76 /* information describing a header field */
77 struct _header_field_info {
78         /* ---------- set by dissector --------- */
79         char                            *name;      /* full name of this field */
80         char                            *abbrev;    /* abbreviated name of this field */
81         enum ftenum                     type;       /* field type, one of FT_ (from ftypes.h) */
82         int                                     display;        /* one of BASE_, or number of field bits for FT_BOOLEAN */
83         const void                      *strings;       /* val_string or true_false_string for FT_BOOLEAN, typically VALS() or TFS() */
84         guint32                         bitmask;    /* FT_BOOLEAN: bitmask of interesting bits */
85         char                            *blurb;         /* Brief description of field. */
86
87         /* ------- set by proto routines (prefilled by HFILL macro, see below) ------ */
88         int                             id;             /* Field ID */
89         int                             parent;         /* parent protocol */
90         int                             bitshift;       /* bits to shift */
91         header_field_info               *same_name_next; /* Link to next hfinfo with same abbrev*/
92         header_field_info               *same_name_prev; /* Link to previous hfinfo with same abbrev*/
93 };
94
95 /*
96  * HFILL initializes all the "set by proto routines" fields in a
97  * "header_field_info"; if new fields are added or removed, it should
98  * be changed as necessary.
99  */
100 #define HFILL 0, 0, 0, NULL, NULL
101
102 /* Used when registering many fields at once */
103 typedef struct hf_register_info {
104         int                     *p_id;  /* pointer to int; written to by register() function */
105         header_field_info       hfinfo;
106 } hf_register_info;
107
108
109 /* string representation, if one of the proto_tree_add_..._format() functions used */
110 typedef struct _item_label_t {
111         char representation[ITEM_LABEL_LENGTH];
112 } item_label_t;
113
114
115 /* Contains the field information for the proto_item. */
116 typedef struct field_info {
117         header_field_info       *hfinfo;    /* pointer to registered field information */
118         gint                            start;      /* current start of data */
119         gint                            length;     /* current data length of item */
120         gint                            tree_type;  /* ETT_ */
121         item_label_t            *rep;       /* string for GUI tree */
122         int                                     flags;      /* one of FI_ */
123         tvbuff_t                        *ds_tvb;    /* data source tvbuff */
124         fvalue_t                        value;
125 } field_info;
126
127
128 /* flags for field_info.flags (must be or'ed together) */
129 #define FI_HIDDEN       0x0001
130 #define FI_GENERATED    0x0002
131
132 /* convenience macros to manipulate flags field */
133 #define FI_GET_FLAG(fi, flag) (fi->flags & flag)
134 #define FI_SET_FLAG(fi, flag) (fi->flags = fi->flags | flag)
135
136
137
138 /* One of these exists for the entire protocol tree. Each proto_node
139  * in the protocol tree points to the same copy. */
140 typedef struct {
141     GHashTable  *interesting_hfids;
142     gboolean    visible;
143 } tree_data_t;
144
145 /* Each proto_tree, proto_item is one of these. */
146 typedef struct _proto_node {
147         struct _proto_node *first_child;
148         struct _proto_node *last_child;
149         struct _proto_node *next;
150         struct _proto_node *parent;
151         field_info  *finfo;
152         tree_data_t *tree_data;
153 } proto_node;
154
155 typedef proto_node proto_tree;
156 typedef proto_node proto_item;
157
158
159 /* indicate that this field should not be shown by Ethereal (used for filtering only) */
160 #define PROTO_ITEM_IS_HIDDEN(proto_item)        \
161         ((proto_item) ? FI_GET_FLAG(proto_item->finfo, FI_HIDDEN) : 0)
162 #define PROTO_ITEM_SET_HIDDEN(proto_item)       \
163         ((proto_item) ? FI_SET_FLAG(proto_item->finfo, FI_HIDDEN) : 0)
164 /* indicate that this field is generated by Ethereal (and not inside the packet data) */
165 #define PROTO_ITEM_IS_GENERATED(proto_item)     \
166         ((proto_item) ? FI_GET_FLAG(proto_item->finfo, FI_GENERATED) : 0)
167 #define PROTO_ITEM_SET_GENERATED(proto_item)    \
168         ((proto_item) ? FI_SET_FLAG(proto_item->finfo, FI_GENERATED) : 0)
169
170
171 typedef void (*proto_tree_foreach_func)(proto_node *, gpointer);
172
173 extern void proto_tree_children_foreach(proto_tree *tree,
174     proto_tree_foreach_func func, gpointer data);
175
176 /* Retrieve the field_info from a proto_item */
177 #define PITEM_FINFO(t)  ((t)->finfo)
178
179 /* Retrieve the tree_data_t from a proto_tree */
180 #define PTREE_DATA(t)   ((t)->tree_data)
181
182 /* Sets up memory used by proto routines. Called at program startup */
183 extern void proto_init(const char *plugin_dir,
184     void (register_all_protocols)(void), void (register_all_handoffs)(void));
185
186 /* Frees memory used by proto routines. Called at program shutdown */
187 extern void proto_cleanup(void);
188
189
190
191 /* Create a subtree under an existing item; returns tree pointer */
192 extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx);
193
194 /* Get a subtree under an item; returns tree pointer */
195 extern proto_tree* proto_item_get_subtree(proto_item *ti);
196
197 /* Get a parent item; returns item pointer */
198 extern proto_item* proto_item_get_parent(proto_item *ti);
199
200 /* Get Nth generation parent item; returns item pointer */
201 extern proto_item* proto_item_get_parent_nth(proto_item *ti, int gen);
202
203 /* Set text of proto_item after having already been created. */
204 #if __GNUC__ >= 2
205 extern void proto_item_set_text(proto_item *ti, const char *format, ...)
206         __attribute__((format (printf, 2, 3)));
207 #else
208 extern void proto_item_set_text(proto_item *ti, const char *format, ...);
209 #endif
210
211 /* Append to text of proto_item after having already been created. */
212 #if __GNUC__ >= 2
213 extern void proto_item_append_text(proto_item *ti, const char *format, ...)
214         __attribute__((format (printf, 2, 3)));
215 #else
216 extern void proto_item_append_text(proto_item *ti, const char *format, ...);
217 #endif
218
219 /* Set length of proto_item after having already been created. */
220 extern void proto_item_set_len(proto_item *ti, gint length);
221
222 /*
223  * Sets the length of the item based on its start and on the specified
224  * offset, which is the offset past the end of the item; as the start
225  * in the item is relative to the beginning of the data source tvbuff,
226  * we need to pass in a tvbuff - the end offset is relative to the beginning
227  * of that tvbuff.
228  */
229 extern void proto_item_set_end(proto_item *pi, tvbuff_t *tvb, gint end);
230
231 /* Get length of proto_item. Useful after using proto_tree_add_item()
232  * to add a variable-length field (e.g., FT_NSTRING_UINT8) */
233 extern int proto_item_get_len(proto_item *ti);
234
235
236
237 /* Creates new proto_tree root */
238 extern proto_tree* proto_tree_create_root(void);
239
240 /* Clear memory for entry proto_tree. Clears proto_tree struct also. */
241 extern void proto_tree_free(proto_tree *tree);
242
243 extern void
244 proto_tree_set_visible(proto_tree *tree, gboolean visible);
245
246 /* Mark a field/protocol ID as "interesting". */
247 extern void
248 proto_tree_prime_hfid(proto_tree *tree, int hfid);
249
250 /* Get a parent item of subtree; returns item pointer */
251 extern proto_item* proto_tree_get_parent(proto_tree *tree);
252
253
254
255
256 /* Add an item to a proto_tree, using the text label registered to that item;
257    the item is extracted from the tvbuff handed to it. */
258 extern proto_item *
259 proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
260     gint start, gint length, gboolean little_endian);
261
262 extern proto_item *
263 proto_tree_add_item_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb,
264     gint start, gint length, gboolean little_endian);
265
266 /* Add a FT_NONE to a proto_tree */
267 #if __GNUC__ >= 2
268 extern proto_item *
269 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
270         gint length, const char *format, ...)
271         __attribute__((format (printf, 6, 7)));
272 #else
273 extern proto_item *
274 proto_tree_add_none_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
275         gint length, const char *format, ...);
276 #endif
277
278 /* Add a FT_PROTOCOL to a proto_tree */
279 #if __GNUC__ >= 2
280 extern proto_item *
281 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
282         gint length, const char *format, ...)
283         __attribute__((format (printf, 6, 7)));
284 #else
285 extern proto_item *
286 proto_tree_add_protocol_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
287         gint length, const char *format, ...);
288 #endif
289
290 /* Add a FT_BYTES to a proto_tree */
291 extern proto_item *
292 proto_tree_add_bytes(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
293         gint length, const guint8* start_ptr);
294
295 extern proto_item *
296 proto_tree_add_bytes_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
297         gint length, const guint8* start_ptr);
298
299 #if __GNUC__ >= 2
300 extern proto_item *
301 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
302         gint length, const guint8* start_ptr, const char *format, ...)
303         __attribute__((format (printf, 7, 8)));
304 #else
305 extern proto_item *
306 proto_tree_add_bytes_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
307         gint length, const guint8* start_ptr, const char *format, ...);
308 #endif
309
310 /* Add a FT_*TIME to a proto_tree */
311 extern proto_item *
312 proto_tree_add_time(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
313         gint length, nstime_t* value_ptr);
314
315 extern proto_item *
316 proto_tree_add_time_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
317         gint length, nstime_t* value_ptr);
318
319 #if __GNUC__ >= 2
320 extern proto_item *
321 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
322         gint length, nstime_t* value_ptr, const char *format, ...)
323         __attribute__((format (printf, 7, 8)));
324 #else
325 extern proto_item *
326 proto_tree_add_time_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
327         gint length, nstime_t* value_ptr, const char *format, ...);
328 #endif
329
330 /* Add a FT_IPXNET to a proto_tree */
331 extern proto_item *
332 proto_tree_add_ipxnet(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
333         gint length, guint32 value);
334
335 extern proto_item *
336 proto_tree_add_ipxnet_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
337         gint length, guint32 value);
338
339 #if __GNUC__ >= 2
340 extern proto_item *
341 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
342         gint length, guint32 value, const char *format, ...)
343         __attribute__((format (printf, 7, 8)));
344 #else
345 extern proto_item *
346 proto_tree_add_ipxnet_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
347         gint length, guint32 value, const char *format, ...);
348 #endif
349
350 /* Add a FT_IPv4 to a proto_tree */
351 extern proto_item *
352 proto_tree_add_ipv4(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
353         gint length, guint32 value);
354
355 extern proto_item *
356 proto_tree_add_ipv4_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
357         gint length, guint32 value);
358
359 #if __GNUC__ >= 2
360 extern proto_item *
361 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
362         gint length, guint32 value, const char *format, ...)
363         __attribute__((format (printf, 7, 8)));
364 #else
365 extern proto_item *
366 proto_tree_add_ipv4_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
367         gint length, guint32 value, const char *format, ...);
368 #endif
369
370 /* Add a FT_IPv6 to a proto_tree */
371 extern proto_item *
372 proto_tree_add_ipv6(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
373         gint length, const guint8* value_ptr);
374
375 extern proto_item *
376 proto_tree_add_ipv6_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
377         gint length, const guint8* value_ptr);
378
379 #if __GNUC__ >= 2
380 extern proto_item *
381 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
382         gint length, const guint8* value_ptr, const char *format, ...)
383         __attribute__((format (printf, 7, 8)));
384 #else
385 extern proto_item *
386 proto_tree_add_ipv6_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
387         gint length, const guint8* value_ptr, const char *format, ...);
388 #endif
389
390 /* Add a FT_ETHER to a proto_tree */
391 extern proto_item *
392 proto_tree_add_ether(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
393         gint length, const guint8* value);
394
395 extern proto_item *
396 proto_tree_add_ether_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
397         gint length, const guint8* value);
398
399 #if __GNUC__ >= 2
400 extern proto_item *
401 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
402         gint length, const guint8* value, const char *format, ...)
403         __attribute__((format (printf, 7, 8)));
404 #else
405 extern proto_item *
406 proto_tree_add_ether_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
407         gint length, const guint8* value, const char *format, ...);
408 #endif
409
410 /* Add a FT_STRING to a proto_tree */
411 extern proto_item *
412 proto_tree_add_string(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
413         gint length, const char* value);
414
415 extern proto_item *
416 proto_tree_add_string_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
417         gint length, const char* value);
418
419 #if __GNUC__ >= 2
420 extern proto_item *
421 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
422         gint length, const char* value, const char *format, ...)
423         __attribute__((format (printf, 7, 8)));
424 #else
425 extern proto_item *
426 proto_tree_add_string_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
427         gint length, const char* value, const char *format, ...);
428 #endif
429
430 extern void
431 proto_item_append_string(proto_item *pi, const char *str);
432
433 /* Add a FT_BOOLEAN to a proto_tree */
434 extern proto_item *
435 proto_tree_add_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
436         gint length, guint32 value);
437
438 extern proto_item *
439 proto_tree_add_boolean_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
440         gint length, guint32 value);
441
442 #if __GNUC__ >= 2
443 extern proto_item *
444 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
445         gint length, guint32 value, const char *format, ...)
446         __attribute__((format (printf, 7, 8)));
447 #else
448 extern proto_item *
449 proto_tree_add_boolean_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
450         gint length, guint32 value, const char *format, ...);
451 #endif
452
453 /* Add a FT_FLOAT to a proto_tree */
454 extern proto_item *
455 proto_tree_add_float(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
456         gint length, float value);
457
458 extern proto_item *
459 proto_tree_add_float_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
460         gint length, float value);
461
462 #if __GNUC__ >= 2
463 extern proto_item *
464 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
465         gint length, float value, const char *format, ...)
466         __attribute__((format (printf, 7, 8)));
467 #else
468 extern proto_item *
469 proto_tree_add_float_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
470         gint length, float value, const char *format, ...);
471 #endif
472
473 /* Add a FT_DOUBLE to a proto_tree */
474 extern proto_item *
475 proto_tree_add_double(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
476         gint length, double value);
477
478 extern proto_item *
479 proto_tree_add_double_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
480         gint length, double value);
481
482 #if __GNUC__ >= 2
483 extern proto_item *
484 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
485         gint length, double value, const char *format, ...)
486         __attribute__((format (printf, 7, 8)));
487 #else
488 extern proto_item *
489 proto_tree_add_double_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
490         gint length, double value, const char *format, ...);
491 #endif
492
493 /* Add any FT_UINT* to a proto_tree */
494 extern proto_item *
495 proto_tree_add_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
496         gint length, guint32 value);
497
498 extern proto_item *
499 proto_tree_add_uint_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
500         gint length, guint32 value);
501
502 #if __GNUC__ >= 2
503 extern proto_item *
504 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
505         gint length, guint32 value, const char *format, ...)
506         __attribute__((format (printf, 7, 8)));
507 #else
508 extern proto_item *
509 proto_tree_add_uint_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
510         gint length, guint32 value, const char *format, ...);
511 #endif
512
513 /* Add any FT_INT* to a proto_tree */
514 extern proto_item *
515 proto_tree_add_int(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
516         gint length, gint32 value);
517
518 extern proto_item *
519 proto_tree_add_int_hidden(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
520         gint length, gint32 value);
521
522 #if __GNUC__ >= 2
523 extern proto_item *
524 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
525         gint length, gint32 value, const char *format, ...)
526         __attribute__((format (printf, 7, 8)));
527 #else
528 extern proto_item *
529 proto_tree_add_int_format(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
530         gint length, gint32 value, const char *format, ...);
531 #endif
532
533
534 /* Add a text-only node to the proto_tree */
535 #if __GNUC__ >= 2
536 extern proto_item *
537 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
538         ...) __attribute__((format (printf, 5, 6)));
539 #else
540 extern proto_item *
541 proto_tree_add_text(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, const char *,
542         ...);
543 #endif
544
545 extern proto_item *
546 proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
547         gint length, const char *format, va_list ap);
548
549
550 /* Useful for quick debugging. Also sends string to STDOUT, so don't
551  * leave call to this function in production code. */
552 #if __GNUC__ >= 2
553 extern proto_item *
554 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...)
555         __attribute__((format (printf, 2, 3)));
556 #else
557 extern proto_item *
558 proto_tree_add_debug_text(proto_tree *tree, const char *format, ...);
559 #endif
560
561
562 extern void
563 proto_item_fill_label(field_info *fi, gchar *label_str);
564
565
566
567 extern int
568 proto_register_protocol(char *name, char *short_name, char *filter_name);
569
570 extern void
571 proto_register_field_array(int parent, hf_register_info *hf, int num_records);
572
573 extern void
574 proto_register_subtree_array(gint **indices, int num_indices);
575
576 /* Returns number of items (protocols or header fields) registered. */
577 extern int proto_registrar_n(void);
578
579 /* Returns char* to name for item # n (0-indexed) */
580 extern char* proto_registrar_get_name(int n);
581
582 /* Returns char* to abbrev for item # n (0-indexed) */
583 extern char* proto_registrar_get_abbrev(int n);
584
585 /* get the header field information based upon a field or protocol id */
586 extern header_field_info* proto_registrar_get_nth(guint hfindex);
587
588 /* get the header field information based upon a field name */
589 extern header_field_info* proto_registrar_get_byname(char *field_name);
590
591 /* Returns enum ftenum for item # n */
592 extern int proto_registrar_get_ftype(int n);
593
594 /* Returns parent protocol for item # n.
595  * Returns -1 if item _is_ a protocol */
596 extern int proto_registrar_get_parent(int n);
597
598 /* Is item #n a protocol? */
599 extern gboolean proto_registrar_is_protocol(int n);
600
601 /* Is protocol's decoding enabled ? */
602 extern gboolean proto_is_protocol_enabled(protocol_t *protocol);
603
604 /* Can item #n decoding be disabled? */
605 extern gboolean proto_can_toggle_protocol(int proto_id);
606
607 /* Routines to use to iterate over the protocols and their fields;
608  * they return the item number of the protocol in question or the
609  * appropriate hfinfo pointer, and keep state in "*cookie". */
610 extern int proto_get_first_protocol(void **cookie);
611 extern int proto_get_next_protocol(void **cookie);
612 extern header_field_info *proto_get_first_protocol_field(int proto_id, void **cookle);
613 extern header_field_info *proto_get_next_protocol_field(void **cookle);
614
615 /* Given a protocol's "protocol_t", return its proto_id */
616 extern int proto_get_id(protocol_t *protocol);
617
618 /* Given a protocol's filter_name, return its proto_id */
619 extern int proto_get_id_by_filter_name(gchar* filter_name);
620
621 /* Given a protocol's item number, find the "protocol_t" structure for it */
622 extern protocol_t *find_protocol_by_id(int proto_id);
623
624 /* Given a protocol's item number, return its name. */
625 extern char *proto_get_protocol_name(int n);
626
627 /* Given a protocol's "protocol_t", return its short name. */
628 extern char *proto_get_protocol_short_name(protocol_t *protocol);
629
630 /* Given a protocol's item number, return its filter name. */
631 extern char *proto_get_protocol_filter_name(int proto_id);
632
633 /* Enable / Disable protocol */
634 extern void proto_set_decoding(int proto_id, gboolean enabled);
635
636 /* Disable disabling/enabling of protocol */
637 extern void proto_set_cant_toggle(int proto_id);
638
639 /* Get length of registered field according to field type.
640  * 0 means undeterminable at registration time.
641  * -1 means unknown field */
642 extern gint proto_registrar_get_length(int n);
643
644 /* Checks for existence any protocol or field within a tree.
645  * "Protocols" are assumed to be a child of the [empty] root node.
646  * TRUE = found, FALSE = not found */
647 extern gboolean proto_check_for_protocol_or_field(proto_tree* tree, int id);
648
649 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
650  * tree. Only works with primed trees, and is fast. */
651 extern GPtrArray* proto_get_finfo_ptr_array(proto_tree *tree, int hfindex);
652
653 /* Return GPtrArray* of field_info pointers for all hfindex that appear in
654  * tree. Works with any tree, primed or unprimed, and is slower than
655  * proto_get_finfo_ptr_array because it has to search through the tree. */
656 extern GPtrArray* proto_find_finfo(proto_tree *tree, int hfindex);
657
658 /* Dumps a glossary of the protocol registrations to STDOUT */
659 extern void proto_registrar_dump_protocols(void);
660
661 /* Dumps a glossary of the protocol and field registrations to STDOUT */
662 extern void proto_registrar_dump_fields(void);
663
664
665
666 /* Points to the first element of an array of Booleans, indexed by
667    a subtree item type; that array element is TRUE if subtrees of
668    an item of that type are to be expanded. */
669 extern gboolean      *tree_is_expanded;
670
671 /* Number of elements in that array. */
672 extern int           num_tree_types;
673
674 /* glib doesn't have g_ptr_array_len of all things!*/
675 #ifndef g_ptr_array_len
676 #define g_ptr_array_len(a)      ((a)->len)
677 #endif
678
679 extern int
680 hfinfo_bitwidth(header_field_info *hfinfo);
681
682
683
684
685 #include "epan.h"
686
687 /*
688  * Returns TRUE if we can do a "match selected" on the field, FALSE
689  * otherwise.
690  */
691 extern gboolean
692 proto_can_match_selected(field_info *finfo, epan_dissect_t *edt);
693
694 extern char*
695 proto_construct_dfilter_string(field_info *finfo, epan_dissect_t *edt);
696
697 extern field_info*
698 proto_find_field_from_offset(proto_tree *tree, guint offset, tvbuff_t *tvb);
699
700 #endif /* proto.h */