Adds calculation of preamble length and frame duration.
[metze/wireshark/wip.git] / epan / expert.c
1 /* expert.c
2  * Collecting Expert information.
3  *
4  * Implemented as a tap named "expert".
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "packet.h"
31 #include "expert.h"
32 #include "uat.h"
33 #include "prefs.h"
34 #include "wmem/wmem.h"
35 #include "tap.h"
36
37 /* proto_expert cannot be static because it's referenced in the
38  * print routines
39  */
40 int proto_expert              = -1;
41
42 static int proto_malformed    = -1;
43
44 static int expert_tap         = -1;
45 static int highest_severity   =  0;
46
47 static int ett_expert         = -1;
48 static int ett_subexpert      = -1;
49
50 static int hf_expert_msg      = -1;
51 static int hf_expert_group    = -1;
52 static int hf_expert_severity = -1;
53
54 struct expert_module
55 {
56         const char *proto_name;
57         int         proto_id;      /* Cache this for registering hfs */
58 };
59
60 /* List which stores protocols and expert_info that have been registered */
61 typedef struct _gpa_expertinfo_t {
62         guint32             len;
63         guint32             allocated_len;
64         expert_field_info **ei;
65 } gpa_expertinfo_t;
66 static gpa_expertinfo_t gpa_expertinfo;
67
68 /* Hash table of abbreviations and IDs */
69 static GHashTable *gpa_name_map = NULL;
70
71 /* Deregistered expert infos */
72 static GPtrArray *deregistered_expertinfos = NULL;
73
74 const value_string expert_group_vals[] = {
75         { PI_CHECKSUM,          "Checksum" },
76         { PI_SEQUENCE,          "Sequence" },
77         { PI_RESPONSE_CODE,     "Response" },
78         { PI_REQUEST_CODE,      "Request" },
79         { PI_UNDECODED,         "Undecoded" },
80         { PI_REASSEMBLE,        "Reassemble" },
81         { PI_MALFORMED,         "Malformed" },
82         { PI_DEBUG,             "Debug" },
83         { PI_PROTOCOL,          "Protocol" },
84         { PI_SECURITY,          "Security" },
85         { PI_COMMENTS_GROUP,    "Comment" },
86         { PI_DECRYPTION,        "Decryption" },
87         { PI_ASSUMPTION,        "Assumption" },
88         { 0, NULL }
89 };
90
91 const value_string expert_severity_vals[] = {
92         { PI_ERROR,             "Error" },
93         { PI_WARN,              "Warn" },
94         { PI_NOTE,              "Note" },
95         { PI_CHAT,              "Chat" },
96         { PI_COMMENT,           "Comment" },
97         { 1,                    "Ok" },
98         { 0, NULL }
99 };
100
101 /* Possible values for a checksum evaluation */
102 const value_string expert_checksum_vals[] = {
103         { EXPERT_CHECKSUM_DISABLED,   "Disabled"  },
104         { EXPERT_CHECKSUM_UNKNOWN,    "Unknown"  },
105         { EXPERT_CHECKSUM_GOOD,       "Good"  },
106         { EXPERT_CHECKSUM_BAD,        "Bad" },
107         { 0,        NULL }
108 };
109
110 static expert_field_info *expert_registrar_get_byname(const char *field_name);
111
112 /*----------------------------------------------------------------------------*/
113 /* UAT for customizing severity levels.                                       */
114 /*----------------------------------------------------------------------------*/
115 typedef struct
116 {
117         char    *field;
118         guint32  severity;
119 } expert_level_entry_t;
120
121 static expert_level_entry_t *uat_expert_entries = NULL;
122 static guint expert_level_entry_count = 0;
123 /* Array of field names currently in UAT */
124 static GArray *uat_saved_fields = NULL;
125
126 UAT_CSTRING_CB_DEF(uat_expert_entries, field, expert_level_entry_t)
127 UAT_VS_DEF(uat_expert_entries, severity, expert_level_entry_t, guint32, PI_ERROR, "Error")
128
129 static gboolean uat_expert_update_cb(void *r, char **err)
130 {
131         expert_level_entry_t *rec = (expert_level_entry_t *)r;
132
133         if (expert_registrar_get_byname(rec->field) == NULL) {
134                 *err = g_strdup_printf("Expert Info field doesn't exist");
135                 return FALSE;
136         }
137         return TRUE;
138 }
139
140 static void *uat_expert_copy_cb(void *n, const void *o, size_t siz _U_)
141 {
142         expert_level_entry_t       *new_record = (expert_level_entry_t*)n;
143         const expert_level_entry_t *old_record = (const expert_level_entry_t *)o;
144
145         if (old_record->field) {
146                 new_record->field = g_strdup(old_record->field);
147         } else {
148                 new_record->field = NULL;
149         }
150
151         new_record->severity = old_record->severity;
152
153         return new_record;
154 }
155
156 static void uat_expert_free_cb(void*r)
157 {
158         expert_level_entry_t *rec = (expert_level_entry_t *)r;
159
160         if (rec->field)
161                 g_free(rec->field);
162 }
163
164 static void uat_expert_post_update_cb(void)
165 {
166         guint              i;
167         expert_field_info *field;
168
169         /* Reset any of the previous list of expert info fields to their original severity */
170         for ( i = 0 ; i < uat_saved_fields->len; i++ ) {
171                 field = g_array_index(uat_saved_fields, expert_field_info*, i);
172                 if (field != NULL) {
173                         field->severity = field->orig_severity;
174                 }
175         }
176
177         g_array_set_size(uat_saved_fields, 0);
178
179         for (i = 0; i < expert_level_entry_count; i++)
180         {
181                 field = expert_registrar_get_byname(uat_expert_entries[i].field);
182                 if (field != NULL)
183                 {
184                         field->severity = uat_expert_entries[i].severity;
185                         g_array_append_val(uat_saved_fields, field);
186                 }
187         }
188 }
189
190 #define EXPERT_REGISTRAR_GET_NTH(eiindex, expinfo)                                               \
191         if((guint)eiindex >= gpa_expertinfo.len && getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG"))   \
192                 g_error("Unregistered expert info! index=%d", eiindex);                          \
193         DISSECTOR_ASSERT_HINT((guint)eiindex < gpa_expertinfo.len, "Unregistered expert info!"); \
194         DISSECTOR_ASSERT_HINT(gpa_expertinfo.ei[eiindex] != NULL, "Unregistered expert info!"); \
195         expinfo = gpa_expertinfo.ei[eiindex];
196
197 void
198 expert_packet_init(void)
199 {
200         module_t *module_expert;
201         uat_t    *expert_uat;
202
203         static hf_register_info hf[] = {
204                 { &hf_expert_msg,
205                         { "Message", "_ws.expert.message", FT_STRING, BASE_NONE, NULL, 0, "Wireshark expert information", HFILL }
206                 },
207                 { &hf_expert_group,
208                         { "Group", "_ws.expert.group", FT_UINT32, BASE_HEX, VALS(expert_group_vals), 0, "Wireshark expert group", HFILL }
209                 },
210                 { &hf_expert_severity,
211                         { "Severity level", "_ws.expert.severity", FT_UINT32, BASE_HEX, VALS(expert_severity_vals), 0, "Wireshark expert severity level", HFILL }
212                 }
213         };
214         static gint *ett[] = {
215                 &ett_expert,
216                 &ett_subexpert
217         };
218
219         /* UAT for overriding severity levels */
220         static uat_field_t custom_expert_fields[] = {
221                 UAT_FLD_CSTRING(uat_expert_entries, field, "Field name", "Expert Info filter name"),
222                 UAT_FLD_VS(uat_expert_entries, severity, "Severity", expert_severity_vals, "Custom severity level"),
223                 UAT_END_FIELDS
224         };
225
226         if (expert_tap == -1) {
227                 expert_tap = register_tap("expert");
228         }
229
230         if (proto_expert == -1) {
231                 proto_expert = proto_register_protocol("Expert Info", "Expert", "_ws.expert");
232                 proto_register_field_array(proto_expert, hf, array_length(hf));
233                 proto_register_subtree_array(ett, array_length(ett));
234                 proto_set_cant_toggle(proto_expert);
235
236                 module_expert = prefs_register_protocol(proto_expert, NULL);
237
238                 expert_uat = uat_new("Expert Info Severity Level Configuration",
239                         sizeof(expert_level_entry_t),
240                         "expert_severity",
241                         TRUE,
242                         (void **)&uat_expert_entries,
243                         &expert_level_entry_count,
244                         UAT_AFFECTS_DISSECTION,
245                         NULL,
246                         uat_expert_copy_cb,
247                         uat_expert_update_cb,
248                         uat_expert_free_cb,
249                         uat_expert_post_update_cb,
250                         custom_expert_fields);
251
252                 prefs_register_uat_preference(module_expert,
253                         "expert_severity_levels",
254                         "Severity Level Configuration",
255                         "A table that overrides Expert Info field severity levels to user configured levels",
256                         expert_uat);
257
258         }
259
260         highest_severity = 0;
261
262         proto_malformed = proto_get_id_by_filter_name("_ws.malformed");
263 }
264
265 void
266 expert_init(void)
267 {
268         gpa_expertinfo.len           = 0;
269         gpa_expertinfo.allocated_len = 0;
270         gpa_expertinfo.ei            = NULL;
271         gpa_name_map                 = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
272         uat_saved_fields             = g_array_new(FALSE, FALSE, sizeof(expert_field_info*));
273         deregistered_expertinfos     = g_ptr_array_new();
274 }
275
276 void
277 expert_packet_cleanup(void)
278 {
279 }
280
281 void
282 expert_cleanup(void)
283 {
284         if (gpa_expertinfo.allocated_len) {
285                 gpa_expertinfo.len           = 0;
286                 gpa_expertinfo.allocated_len = 0;
287                 g_free(gpa_expertinfo.ei);
288                 gpa_expertinfo.ei          = NULL;
289         }
290
291         /* Free the abbrev/ID GTree */
292         if (gpa_name_map) {
293                 g_hash_table_destroy(gpa_name_map);
294                 gpa_name_map = NULL;
295         }
296
297         /* Free the UAT saved fields */
298         if (uat_saved_fields) {
299                 g_array_free(uat_saved_fields, TRUE);
300                 uat_saved_fields = NULL;
301         }
302
303         if (deregistered_expertinfos) {
304                 g_ptr_array_free(deregistered_expertinfos, FALSE);
305                 deregistered_expertinfos = NULL;
306         }
307 }
308
309
310 int
311 expert_get_highest_severity(void)
312 {
313         return highest_severity;
314 }
315
316 void
317 expert_update_comment_count(guint64 count)
318 {
319         if (count==0 && highest_severity==PI_COMMENT)
320                 highest_severity = 0;
321 }
322
323 expert_module_t *expert_register_protocol(int id)
324 {
325         expert_module_t *module;
326         protocol_t      *protocol;
327
328         protocol = find_protocol_by_id(id);
329
330         module = wmem_new(wmem_epan_scope(), expert_module_t);
331         module->proto_id = id;
332         module->proto_name = proto_get_protocol_short_name(protocol);
333
334         return module;
335 }
336
337 void
338 expert_deregister_expertinfo (const char *abbrev)
339 {
340         expert_field_info *expinfo = (expert_field_info*)g_hash_table_lookup(gpa_name_map, abbrev);
341         if (expinfo) {
342                 g_ptr_array_add(deregistered_expertinfos, gpa_expertinfo.ei[expinfo->id]);
343                 g_hash_table_steal(gpa_name_map, abbrev);
344         }
345 }
346
347 void
348 expert_deregister_protocol (expert_module_t *module)
349 {
350         wmem_free(wmem_epan_scope(), module);
351 }
352
353 static void
354 free_deregistered_expertinfo (gpointer data, gpointer user_data _U_)
355 {
356         expert_field_info *expinfo = (expert_field_info *) data;
357         gpa_expertinfo.ei[expinfo->id] = NULL; /* Invalidate this id */
358 }
359
360 void
361 expert_free_deregistered_expertinfos (void)
362 {
363         g_ptr_array_foreach(deregistered_expertinfos, free_deregistered_expertinfo, NULL);
364         g_ptr_array_free(deregistered_expertinfos, TRUE);
365         deregistered_expertinfos = g_ptr_array_new();
366 }
367
368 static int
369 expert_register_field_init(expert_field_info *expinfo, expert_module_t *module)
370 {
371         expinfo->protocol      = module->proto_name;
372
373         /* if we always add and never delete, then id == len - 1 is correct */
374         if (gpa_expertinfo.len >= gpa_expertinfo.allocated_len) {
375                 if (!gpa_expertinfo.ei) {
376                         gpa_expertinfo.allocated_len = PRE_ALLOC_EXPERT_FIELDS_MEM;
377                         gpa_expertinfo.ei = (expert_field_info **)g_malloc(sizeof(expert_field_info *)*PRE_ALLOC_EXPERT_FIELDS_MEM);
378                 } else {
379                         gpa_expertinfo.allocated_len += 1000;
380                         gpa_expertinfo.ei = (expert_field_info **)g_realloc(gpa_expertinfo.ei,
381                                                    sizeof(expert_field_info *)*gpa_expertinfo.allocated_len);
382                 }
383         }
384         gpa_expertinfo.ei[gpa_expertinfo.len] = expinfo;
385         gpa_expertinfo.len++;
386         expinfo->id = gpa_expertinfo.len - 1;
387         /* Save the original severity so it can be restored by the UAT */
388         expinfo->orig_severity = expinfo->severity;
389
390         /* save field name for lookup */
391         g_hash_table_insert(gpa_name_map, (gpointer) (expinfo->name), expinfo);
392
393         return expinfo->id;
394 }
395
396
397 /* for use with static arrays only, since we don't allocate our own copies
398 of the expert_field_info struct contained within the exp_register_info struct */
399 void
400 expert_register_field_array(expert_module_t *module, ei_register_info *exp, const int num_records)
401 {
402         int               i;
403         ei_register_info *ptr = exp;
404
405         for (i = 0; i < num_records; i++, ptr++) {
406                 /*
407                  * Make sure we haven't registered this yet.
408                  * Most fields have variables associated with them
409                  * that are initialized to -1; some have array elements,
410                  * or possibly uninitialized variables, so we also allow
411                  * 0 (which is unlikely to be the field ID we get back
412                  * from "expert_register_field_init()").
413                  */
414                 if (ptr->ids->ei != -1 && ptr->ids->ei != 0) {
415                         fprintf(stderr,
416                                 "Duplicate field detected in call to expert_register_field_array: '%s' is already registered, name=%s\n",
417                                 ptr->eiinfo.summary, ptr->eiinfo.name);
418                         return;
419                 }
420
421                 /* Register the field with the experts */
422                 ptr->ids->ei = expert_register_field_init(&ptr->eiinfo, module);
423
424                 /* Register with the header field info, so it's display filterable */
425                 ptr->eiinfo.hf_info.p_id = &ptr->ids->hf;
426                 ptr->eiinfo.hf_info.hfinfo.abbrev = ptr->eiinfo.name;
427                 ptr->eiinfo.hf_info.hfinfo.blurb = ptr->eiinfo.summary;
428
429                 proto_register_field_array(module->proto_id, &ptr->eiinfo.hf_info, 1);
430         }
431 }
432
433 /* Finds a record in the expert array by name.
434  * For the moment, this function is only used "internally"
435  * but may find a reason to be exported
436  */
437 static expert_field_info *
438 expert_registrar_get_byname(const char *field_name)
439 {
440         expert_field_info *hfinfo;
441
442         if (!field_name)
443                 return NULL;
444
445         hfinfo = (expert_field_info*)g_hash_table_lookup(gpa_name_map, field_name);
446
447         return hfinfo;
448 }
449
450 /**
451  * Get summary text of an expert_info field.
452  * This is intended for use in expert_add_info_format or proto_tree_add_expert_format
453  * to get the "base" string to then append additional information
454  */
455 const gchar* expert_get_summary(expert_field *eiindex)
456 {
457         expert_field_info *eiinfo;
458
459         /* Look up the item */
460         EXPERT_REGISTRAR_GET_NTH(eiindex->ei, eiinfo);
461
462     return eiinfo->summary;
463 }
464
465 /** clear flags according to the mask and set new flag values */
466 #define FI_REPLACE_FLAGS(fi, mask, flags_in) { \
467         (fi->flags = (fi)->flags & ~(mask)); \
468         (fi->flags = (fi)->flags | (flags_in)); \
469 }
470
471 /* set's the PI_ flags to a protocol item
472  * (and its parent items till the toplevel) */
473 static void
474 expert_set_item_flags(proto_item *pi, const int group, const guint severity)
475 {
476         if (pi != NULL && PITEM_FINFO(pi) != NULL && (severity >= FI_GET_FLAG(PITEM_FINFO(pi), PI_SEVERITY_MASK))) {
477                 FI_REPLACE_FLAGS(PITEM_FINFO(pi), PI_GROUP_MASK, group);
478                 FI_REPLACE_FLAGS(PITEM_FINFO(pi), PI_SEVERITY_MASK, severity);
479
480                 /* propagate till toplevel item */
481                 pi = proto_item_get_parent(pi);
482                 expert_set_item_flags(pi, group, severity);
483         }
484 }
485
486 static proto_tree*
487 expert_create_tree(proto_item *pi, int group, int severity, const char *msg)
488 {
489         proto_tree *tree;
490         proto_item *ti;
491
492         tree = proto_item_add_subtree(pi, ett_expert);
493         ti = proto_tree_add_protocol_format(tree, proto_expert, NULL, 0, 0, "Expert Info (%s/%s): %s",
494                                             val_to_str(severity, expert_severity_vals, "Unknown (%u)"),
495                                             val_to_str(group, expert_group_vals, "Unknown (%u)"),
496                                             msg);
497         PROTO_ITEM_SET_GENERATED(ti);
498
499         if (group == PI_MALFORMED) {
500                 /* Add hidden malformed protocol filter */
501                 proto_item *malformed_ti = proto_tree_add_item(tree, proto_malformed, NULL, 0, 0, ENC_NA);
502                 PROTO_ITEM_SET_HIDDEN(malformed_ti);
503         }
504
505         return proto_item_add_subtree(ti, ett_subexpert);
506 }
507
508 static void
509 expert_set_info_vformat(packet_info *pinfo, proto_item *pi, int group, int severity, int hf_index, gboolean use_vaformat,
510                         const char *format, va_list ap)
511 {
512         char           formatted[ITEM_LABEL_LENGTH];
513         int            tap;
514         expert_info_t *ei;
515         proto_tree    *tree;
516         proto_item    *ti;
517
518         if (pinfo == NULL && pi && pi->tree_data) {
519                 pinfo = PTREE_DATA(pi)->pinfo;
520         }
521
522         /* if this packet isn't loaded because of a read filter, don't output anything */
523         if (pinfo == NULL || pinfo->num == 0) {
524                 return;
525         }
526
527         if (severity > highest_severity) {
528                 highest_severity = severity;
529         }
530
531         /* XXX: can we get rid of these checks and make them programming errors instead now? */
532         if (pi != NULL && PITEM_FINFO(pi) != NULL) {
533                 expert_set_item_flags(pi, group, severity);
534         }
535
536         if ((pi == NULL) || (PITEM_FINFO(pi) == NULL) ||
537                 ((guint)severity >= FI_GET_FLAG(PITEM_FINFO(pi), PI_SEVERITY_MASK))) {
538                 col_add_str(pinfo->cinfo, COL_EXPERT, val_to_str(severity, expert_severity_vals, "Unknown (%u)"));
539         }
540
541         if (use_vaformat) {
542                 g_vsnprintf(formatted, ITEM_LABEL_LENGTH, format, ap);
543         } else {
544                 g_strlcpy(formatted, format, ITEM_LABEL_LENGTH);
545         }
546
547         tree = expert_create_tree(pi, group, severity, formatted);
548
549         if (hf_index == -1) {
550                 /* If no filterable expert info, just add the message */
551                 ti = proto_tree_add_string(tree, hf_expert_msg, NULL, 0, 0, formatted);
552                 PROTO_ITEM_SET_GENERATED(ti);
553         } else {
554                 /* If filterable expert info, hide the "generic" form of the message,
555                    and generate the formatted filterable expert info */
556                 ti = proto_tree_add_none_format(tree, hf_index, NULL, 0, 0, "%s", formatted);
557                 PROTO_ITEM_SET_GENERATED(ti);
558                 ti = proto_tree_add_string(tree, hf_expert_msg, NULL, 0, 0, formatted);
559                 PROTO_ITEM_SET_HIDDEN(ti);
560         }
561
562         ti = proto_tree_add_uint_format_value(tree, hf_expert_severity, NULL, 0, 0, severity,
563                                               "%s", val_to_str_const(severity, expert_severity_vals, "Unknown"));
564         PROTO_ITEM_SET_GENERATED(ti);
565         ti = proto_tree_add_uint_format_value(tree, hf_expert_group, NULL, 0, 0, group,
566                                               "%s", val_to_str_const(group, expert_group_vals, "Unknown"));
567         PROTO_ITEM_SET_GENERATED(ti);
568
569         tap = have_tap_listener(expert_tap);
570
571         if (!tap)
572                 return;
573
574         ei = wmem_new(wmem_packet_scope(), expert_info_t);
575
576         ei->packet_num  = pinfo->num;
577         ei->group       = group;
578         ei->severity    = severity;
579         ei->hf_index    = hf_index;
580         ei->protocol    = pinfo->current_proto;
581         ei->summary     = wmem_strdup(wmem_packet_scope(), formatted);
582
583         /* if we have a proto_item (not a faked item), set expert attributes to it */
584         if (pi != NULL && PITEM_FINFO(pi) != NULL) {
585                 ei->pitem = pi;
586         }
587         /* XXX: remove this because we don't have an internal-only function now? */
588         else {
589                 ei->pitem = NULL;
590         }
591
592         tap_queue_packet(expert_tap, pinfo, ei);
593 }
594
595 /* Helper function for expert_add_info() to work around compiler's special needs on ARM */
596 static inline void
597 expert_add_info_internal(packet_info *pinfo, proto_item *pi, expert_field *expindex, ...)
598 {
599         /* the va_list is ignored */
600         va_list            unused;
601         expert_field_info *eiinfo;
602
603         /* Look up the item */
604         EXPERT_REGISTRAR_GET_NTH(expindex->ei, eiinfo);
605
606         va_start(unused, expindex);
607         expert_set_info_vformat(pinfo, pi, eiinfo->group, eiinfo->severity, *eiinfo->hf_info.p_id, FALSE, eiinfo->summary, unused);
608         va_end(unused);
609 }
610
611 void
612 expert_add_info(packet_info *pinfo, proto_item *pi, expert_field *expindex)
613 {
614         expert_add_info_internal(pinfo, pi, expindex);
615 }
616
617 void
618 expert_add_info_format(packet_info *pinfo, proto_item *pi, expert_field *expindex, const char *format, ...)
619 {
620         va_list            ap;
621         expert_field_info *eiinfo;
622
623         /* Look up the item */
624         EXPERT_REGISTRAR_GET_NTH(expindex->ei, eiinfo);
625
626         va_start(ap, format);
627         expert_set_info_vformat(pinfo, pi, eiinfo->group, eiinfo->severity, *eiinfo->hf_info.p_id, TRUE, format, ap);
628         va_end(ap);
629 }
630
631 /* Helper function for expert_add_expert() to work around compiler's special needs on ARM */
632 static inline proto_item *
633 proto_tree_add_expert_internal(proto_tree *tree, packet_info *pinfo, expert_field *expindex,
634                 tvbuff_t *tvb, gint start, gint length, ...)
635 {
636         expert_field_info *eiinfo;
637         proto_item        *ti;
638         va_list            unused;
639
640         /* Look up the item */
641         EXPERT_REGISTRAR_GET_NTH(expindex->ei, eiinfo);
642
643         ti = proto_tree_add_text_internal(tree, tvb, start, length, "%s", eiinfo->summary);
644         va_start(unused, length);
645         expert_set_info_vformat(pinfo, ti, eiinfo->group, eiinfo->severity, *eiinfo->hf_info.p_id, FALSE, eiinfo->summary, unused);
646         va_end(unused);
647         return ti;
648 }
649
650 proto_item *
651 proto_tree_add_expert(proto_tree *tree, packet_info *pinfo, expert_field *expindex,
652                 tvbuff_t *tvb, gint start, gint length)
653 {
654         return proto_tree_add_expert_internal(tree, pinfo, expindex, tvb, start, length);
655 }
656
657 proto_item *
658 proto_tree_add_expert_format(proto_tree *tree, packet_info *pinfo, expert_field *expindex,
659                 tvbuff_t *tvb, gint start, gint length, const char *format, ...)
660 {
661         va_list            ap;
662         expert_field_info *eiinfo;
663         proto_item        *ti;
664
665         /* Look up the item */
666         EXPERT_REGISTRAR_GET_NTH(expindex->ei, eiinfo);
667
668         va_start(ap, format);
669         ti = proto_tree_add_text_valist_internal(tree, tvb, start, length, format, ap);
670         va_end(ap);
671
672         va_start(ap, format);
673         expert_set_info_vformat(pinfo, ti, eiinfo->group, eiinfo->severity, *eiinfo->hf_info.p_id, TRUE, format, ap);
674         va_end(ap);
675
676         return ti;
677 }
678
679 /*
680  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
681  *
682  * Local variables:
683  * c-basic-offset: 8
684  * tab-width: 8
685  * indent-tabs-mode: t
686  * End:
687  *
688  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
689  * :indentSize=8:tabSize=8:noTabs=false:
690  */