name change
[metze/wireshark/wip.git] / epan / expert.c
1 /* expert.c
2  * Collecting Expert information.
3  *
4  * Implemented as a tap named "expert".
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include "packet.h"
32 #include "expert.h"
33 #include "emem.h"
34 #include "tap.h"
35
36
37
38 static int expert_tap = -1;
39
40
41 void
42 expert_init(void)
43 {
44         if(expert_tap == -1) {
45                 expert_tap = register_tap("expert");
46         }
47 }
48
49 void
50 expert_cleanup(void)
51 {
52         /* memory cleanup will be done by se_... */
53 }
54
55
56 /* set's the PI_ flags to a protocol item 
57  * (and it's parent items till the toplevel) */
58 static void
59 expert_set_item_flags(proto_item *pi, int group, int severity)
60 {
61
62         if(proto_item_set_expert_flags(pi, group, severity)) {
63                 /* propagate till toplevel item */
64                 pi = proto_item_get_parent(pi);
65                 expert_set_item_flags(pi, group, severity);
66         }
67 }
68
69
70 static void
71 expert_set_info_vformat(
72 packet_info *pinfo, proto_item *pi, int group, int severity, const char *format, va_list ap)
73 {
74         int                             ret;    /*tmp return value */
75         char                    formatted[300];
76         expert_info_t   *ei;
77
78
79         /* if this packet isn't loaded because of a read filter, don't output anything */
80         if(pinfo == NULL || pinfo->fd->num == 0) {
81                 return;
82         }
83
84         /* XXX - use currently nonexistant se_vsnprintf instead */
85         ret = g_vsnprintf(formatted, sizeof(formatted), format, ap);
86         if ((ret == -1) || (ret >= sizeof(formatted)))
87                 formatted[sizeof(formatted) - 1] = '\0';
88
89         ei = ep_alloc(sizeof(expert_info_t));
90         ei->packet_num  = pinfo->fd->num;
91         ei->group               = group;
92         ei->severity    = severity;
93         ei->protocol    = ep_strdup(pinfo->current_proto);
94         ei->summary             = ep_strdup(formatted);
95     ei->pitem       = NULL;
96
97         /* if we have a proto_item (not a faked item), set expert attributes to it */
98         if(pi != NULL && pi->finfo != NULL) {   
99         ei->pitem       = pi;
100                 expert_set_item_flags(pi, group, severity);
101         }
102
103         tap_queue_packet(expert_tap, pinfo, ei);
104 }
105
106
107 void
108 expert_add_info_format(
109 packet_info *pinfo, proto_item *pi, int group, int severity, const char *format, ...)
110 {
111         va_list ap;
112
113
114         va_start(ap, format);
115         expert_set_info_vformat(pinfo, pi, group, severity, format, ap);
116         va_end(ap);
117 }
118
119