cd ../gtk ==> cd ../ui/gtk
[obnox/wireshark/wip.git] / epan / column-utils.h
1 /* column-utils.h
2  * Definitions for column utility structures and routines
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 #ifndef __COLUMN_UTILS_H__
26 #define __COLUMN_UTILS_H__
27
28 #include <glib.h>
29
30 #include "column_info.h"
31 #include "packet_info.h"
32 #include <epan/epan.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif /* __cplusplus */
37
38 /** @file
39  *  Helper routines for column utility structures and routines.
40  */
41
42 /** Allocate all the data structures for constructing column data, given
43  * the number of columns.
44  *
45  * Internal, don't use this in dissectors!
46  */
47 extern void     col_setup(column_info *cinfo, const gint num_cols);
48
49 /** Initialize the data structures for constructing column data.
50  *
51  * Internal, don't use this in dissectors!
52  */
53 extern void     col_init(column_info *cinfo);
54
55 /** Set the format of the "variable time format".
56  *
57  * Internal, don't use this in dissectors!
58  */
59 extern void     col_set_fmt_time(const frame_data *fd, column_info *cinfo, const gint fmt, const gint col);
60
61 /** Fill in all columns of the given packet which are based on values from frame_data.
62  *
63  * Internal, don't use this in dissectors!
64  */
65 extern void col_fill_in_frame_data(const frame_data *fd, column_info *cinfo, const gint col, gboolean const fill_col_exprs);
66
67 /** Fill in all columns of the given packet.
68  *
69  * Internal, don't use this in dissectors!
70  */
71 extern void     col_fill_in(packet_info *pinfo, const gboolean fill_col_exprs, const gboolean fill_fd_colums);
72
73 /** Fill in columns if we got an error reading the packet.
74  * We set most columns to "???", and set the Info column to an error
75  * message.
76  *
77  * Internal, don't use this in dissectors!
78  */
79 extern void     col_fill_in_error(column_info *cinfo, frame_data *fdata, const gboolean fill_col_exprs, const gboolean fill_fd_colums);
80
81 /* Utility routines used by packet*.c */
82
83 /** Are the columns writable?
84  *
85  * @param cinfo the current packet row
86  * @return TRUE if it's writable, FALSE if not
87  */
88 extern gboolean col_get_writable(column_info *cinfo);
89
90 /** Set the columns writable.
91  *
92  * @param cinfo the current packet row
93  * @param writable TRUE if it's writable, FALSE if not
94  */
95 extern void     col_set_writable(column_info *cinfo, const gboolean writable);
96
97 /** 
98  * Checks if the given column can be filled with data.
99  *
100  * @param cinfo the current packet row
101  * @param col the column to use, e.g. COL_INFO
102  *
103  * @deprecated Not needed in new code the check is done in 
104  * in the column function calls.
105  */
106 extern gint     check_col(column_info *cinfo, const gint col);
107
108 /** Sets a fence for the current column content,
109  * so this content won't be affected by further col_... function calls.
110  *
111  * This can be useful if a protocol is more than once in a single packet,
112  * e.g. multiple HTTP calls in a single TCP packet.
113  *
114  * @param cinfo the current packet row
115  * @param col the column to use, e.g. COL_INFO
116  */
117 extern void     col_set_fence(column_info *cinfo, const gint col);
118
119 /** Clears the text of a column element.
120  *
121  * @param cinfo the current packet row
122  * @param col the column to use, e.g. COL_INFO
123  */
124 extern void     col_clear(column_info *cinfo, const gint col);
125
126 /** Set (replace) the text of a column element, the text won't be copied.
127  *
128  * Usually used to set const strings!
129  *
130  * @param cinfo the current packet row
131  * @param col the column to use, e.g. COL_INFO
132  * @param str the string to set
133  */
134 extern void     col_set_str(column_info *cinfo, const gint col, const gchar * str);
135
136 /** Add (replace) the text of a column element, the text will be copied.
137  *
138  * @param cinfo the current packet row
139  * @param col the column to use, e.g. COL_INFO
140  * @param str the string to add
141  */
142 extern void     col_add_str(column_info *cinfo, const gint col, const gchar *str);
143
144 /** Add (replace) the text of a column element, the text will be formatted and copied.
145  *
146  * Same function as col_add_str() but using a printf-like format string.
147  *
148  * @param cinfo the current packet row
149  * @param col the column to use, e.g. COL_INFO
150  * @param format the format string
151  * @param ... the variable number of parameters
152  */
153 extern void     col_add_fstr(column_info *cinfo, const gint col, const gchar *format, ...)
154     G_GNUC_PRINTF(3, 4);
155
156 /** For internal Wireshark use only.  Not to be called from dissectors. */
157 void col_custom_set_edt(epan_dissect_t *edt, column_info *cinfo);
158
159 /** For internal Wireshark use only.  Not to be called from dissectors. */
160 void col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo);
161
162 /** For internal Wireshark use only.  Not to be called from dissectors. */
163 gboolean have_custom_cols(column_info *cinfo);
164 /** For internal Wireshark use only.  Not to be called from dissectors. */
165 gboolean col_has_time_fmt(column_info *cinfo, const gint col);
166 /** For internal Wireshark use only.  Not to be called from dissectors. */
167 gboolean col_based_on_frame_data(column_info *cinfo, const gint col);
168
169 /** Append the given text to a column element, the text will be copied.
170  *
171  * @param cinfo the current packet row
172  * @param col the column to use, e.g. COL_INFO
173  * @param str the string to append
174  */
175 extern void     col_append_str(column_info *cinfo, const gint col, const gchar *str);
176
177 /** Append the given text to a column element, the text will be formatted and copied.
178  *
179  * Same function as col_append_str() but using a printf-like format string.
180  *
181  * @param cinfo the current packet row
182  * @param col the column to use, e.g. COL_INFO
183  * @param format the format string
184  * @param ... the variable number of parameters
185  */
186 extern void     col_append_fstr(column_info *cinfo, const gint col, const gchar *format, ...)
187     G_GNUC_PRINTF(3, 4);
188
189 /** Prepend the given text to a column element, the text will be formatted and copied.
190  *
191  * @param cinfo the current packet row
192  * @param col the column to use, e.g. COL_INFO
193  * @param format the format string
194  * @param ... the variable number of parameters
195  */
196 extern void     col_prepend_fstr(column_info *cinfo, const gint col, const gchar *format, ...)
197     G_GNUC_PRINTF(3, 4);
198
199 /**Prepend the given text to a column element, the text will be formatted and copied.
200  * This function is similar to col_prepend_fstr() but this function will
201  * unconditionally set a fence to the end of the prepended data even if there
202  * were no fence before.
203  * The col_prepend_fstr() will only prepend the data before the fence IF
204  * there is already a fence created. This function will create a fence in case
205  * it does not yet exist.
206  */
207 extern void     col_prepend_fence_fstr(column_info *cinfo, const gint col, const gchar *format, ...)
208     G_GNUC_PRINTF(3, 4);
209
210 /** Append the given text (prepended by a separator) to a column element.
211  *
212  * Much like col_append_str() but will prepend the given separator if the column isn't empty.
213  *
214  * @param cinfo the current packet row
215  * @param col the column to use, e.g. COL_INFO
216  * @param sep the separator string or NULL for default: ", "
217  * @param str the string to append
218  */
219 extern void     col_append_sep_str(column_info *cinfo, const gint col, const gchar *sep,
220                 const gchar *str);
221
222 /** Append the given text (prepended by a separator) to a column element.
223  *
224  * Much like col_append_fstr() but will prepend the given separator if the column isn't empty.
225  *
226  * @param cinfo the current packet row
227  * @param col the column to use, e.g. COL_INFO
228  * @param sep the separator string or NULL for default: ", "
229  * @param format the format string
230  * @param ... the variable number of parameters
231  */
232 extern void     col_append_sep_fstr(column_info *cinfo, const gint col, const gchar *sep,
233                 const gchar *format, ...)
234     G_GNUC_PRINTF(4, 5);
235
236 /** Set the given (relative) time to a column element.
237  *
238  * Used by multiple dissectors to set the time in the column
239  * COL_DELTA_CONV_TIME
240  *
241  * @param cinfo         the current packet row
242  * @param col           the column to use, e.g. COL_INFO
243  * @param ts            the time to set in the column
244  * @param fieldname     the fieldname to use for creating a filter (when
245  *                        applying/preparing/copying as filter)
246  */
247 extern void     col_set_time(column_info *cinfo, const int col,
248                         const nstime_t *ts, char *fieldname);
249
250 extern void set_fd_time(frame_data *fd, gchar *buf);
251
252 #ifdef __cplusplus
253 }
254 #endif /* __cplusplus */
255
256 #endif /* __COLUMN_UTILS_H__ */