HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / column.c
blob53e64ecc88f17d337a90a8570eed473489e3ad25
1 /* column.c
2 * Routines for handling column preferences
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
25 #include "config.h"
27 #include <stdio.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <errno.h>
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
36 #include <epan/timestamp.h>
37 #include <epan/prefs.h>
38 #include <epan/dfilter/dfilter.h>
39 #include <epan/column.h>
40 #include <epan/packet.h>
42 /* Given a format number (as defined in column-info.h), returns its equivalent
43 string */
44 const gchar *
45 col_format_to_string(const gint fmt) {
46 static const gchar *const slist[NUM_COL_FMTS] = {
47 "%q", /* 0) COL_8021Q_VLAN_ID */
48 "%Yt", /* 1) COL_ABS_YMD_TIME */
49 "%YDOYt", /* 2) COL_ABS_YDOY_TIME */
50 "%At", /* 3) COL_ABS_TIME */
51 "%c", /* 4) COL_CIRCUIT_ID */
52 "%Xd", /* 5) COL_DSTIDX - !! DEPRECATED !!*/
53 "%Xs", /* 6) COL_SRCIDX - !! DEPRECATED !!*/
54 "%V", /* 7) COL_VSAN - !! DEPRECATED !!*/
55 "%B", /* 8) COL_CUMULATIVE_BYTES */
56 "%Cus", /* 9) COL_CUSTOM */
57 "%y", /* 10) COL_DCE_CALL */
58 "%z", /* 11) COL_DCE_CTX */
59 "%Tt", /* 12) COL_DELTA_TIME */
60 "%dct", /* 13) COL_DELTA_CONV_TIME */
61 "%Gt", /* 14) COL_DELTA_TIME_DIS */
62 "%rd", /* 15) COL_RES_DST */
63 "%ud", /* 16) COL_UNRES_DST */
64 "%rD", /* 17) COL_RES_DST_PORT */
65 "%uD", /* 18) COL_UNRES_DST_PORT */
66 "%d", /* 19) COL_DEF_DST */
67 "%D", /* 20) COL_DEF_DST_PORT */
68 "%a", /* 21) COL_EXPERT */
69 "%I", /* 22) COL_IF_DIR */
70 "%XO", /* 23) COL_OXID */
71 "%XR", /* 24) COL_RXID */
72 "%C", /* 25) !! DEPRECATED !! - COL_FR_DLCI */
73 "%F", /* 26) COL_FREQ_CHAN */
74 "%l", /* 27) !! DEPRECATED !! - COL_BSSGP_TLLI */
75 "%P", /* 28) !! DEPRECATED !! - COL_HPUX_DEVID */
76 "%H", /* 29) !! DEPRECATED !! - COL_HPUX_SUBSYS */
77 "%hd", /* 30) COL_DEF_DL_DST */
78 "%hs", /* 31) COL_DEF_DL_SRC */
79 "%rhd", /* 32) COL_RES_DL_DST */
80 "%uhd", /* 33) COL_UNRES_DL_DST */
81 "%rhs", /* 34) COL_RES_DL_SRC*/
82 "%uhs", /* 35) COL_UNRES_DL_SRC */
83 "%e", /* 36) COL_RSSI */
84 "%x", /* 37) COL_TX_RATE */
85 "%f", /* 38) COL_DSCP_VALUE */
86 "%i", /* 39) COL_INFO */
87 "%U", /* 40) !! DEPRECATED !! - COL_COS_VALUE */
88 "%rnd", /* 41) COL_RES_NET_DST */
89 "%und", /* 42) COL_UNRES_NET_DST */
90 "%rns", /* 43) COL_RES_NET_SRC */
91 "%uns", /* 44) COL_UNRES_NET_SRC */
92 "%nd", /* 45) COL_DEF_NET_DST */
93 "%ns", /* 46) COL_DEF_NET_SRC */
94 "%m", /* 47) COL_NUMBER */
95 "%L", /* 48) COL_PACKET_LENGTH */
96 "%p", /* 49) COL_PROTOCOL */
97 "%Rt", /* 50) COL_REL_TIME */
98 "%rct", /* 51) !! DEPRECATED !! - COL_REL_CONV_TIME */
99 "%s", /* 52) COL_DEF_SRC */
100 "%S", /* 53) COL_DEF_SRC_PORT */
101 "%rs", /* 54) COL_RES_SRC */
102 "%us", /* 55) COL_UNRES_SRC */
103 "%rS", /* 56) COL_RES_SRC_PORT */
104 "%uS", /* 57) COL_UNRES_SRC_PORT */
105 "%E", /* 58) COL_TEI */
106 "%Yut", /* 59) COL_UTC_YMD_TIME */
107 "%YDOYut", /* 60) COL_UTC_YDOY_TIME */
108 "%Aut", /* 61) COL_UTC_TIME */
109 "%t" /* 62) COL_CLS_TIME */
112 if (fmt < 0 || fmt >= NUM_COL_FMTS)
113 return NULL;
115 return(slist[fmt]);
118 /* Given a format number (as defined in column-info.h), returns its
119 description */
120 const gchar *
121 col_format_desc(const gint fmt) {
122 static const gchar *const dlist[NUM_COL_FMTS] = {
123 "802.1Q VLAN id", /* 0) COL_8021Q_VLAN_ID */
124 "Absolute date, as YYYY-MM-DD, and time", /* 1) COL_ABS_YMD_TIME */
125 "Absolute date, as YYYY/DOY, and time", /* 2) COL_ABS_YDOY_TIME */
126 "Absolute time", /* 3) COL_ABS_TIME */
127 "Circuit ID", /* 4) COL_CIRCUIT_ID */
128 "Cisco Dst PortIdx", /* 5) COL_DSTIDX */
129 "Cisco Src PortIdx", /* 6) COL_SRCIDX */
130 "Cisco VSAN", /* 7) COL_VSAN */
131 "Cumulative Bytes" , /* 8) COL_CUMULATIVE_BYTES */
132 "Custom", /* 9) COL_CUSTOM */
133 "DCE/RPC call (cn_call_id / dg_seqnum)", /* 10) COL_DCE_CALL */
134 "DCE/RPC context ID (cn_ctx_id)", /* 11) COL_DCE_CTX */
135 "Delta time", /* 12) COL_DELTA_TIME */
136 "Delta time (conversation)", /* 13) COL_DELTA_CONV_TIME */
137 "Delta time displayed", /* 14) COL_DELTA_TIME_DIS */
138 "Dest addr (resolved)", /* 15) COL_RES_DST */
139 "Dest addr (unresolved)", /* 16) COL_UNRES_DST */
140 "Dest port (resolved)", /* 17) COL_RES_DST_PORT */
141 "Dest port (unresolved)", /* 18) COL_UNRES_DST_PORT */
142 "Destination address", /* 19) COL_DEF_DST */
143 "Destination port", /* 20) COL_DEF_DST_PORT */
144 "Expert Info Severity", /* 21) COL_EXPERT */
145 "FW-1 monitor if/direction", /* 22) COL_IF_DIR */
146 "Fibre Channel OXID", /* 23) COL_OXID */
147 "Fibre Channel RXID", /* 24) COL_RXID */
148 "Frame Relay DLCI", /* 25) !! DEPRECATED !! - COL_FR_DLCI */
149 "Frequency/Channel", /* 26) COL_FREQ_CHAN */
150 "GPRS BSSGP TLLI", /* 27) !! DEPRECATED !! - COL_BSSGP_TLLI */
151 "HP-UX Device ID", /* 28) !! DEPRECATED !! - COL_HPUX_DEVID */
152 "HP-UX Subsystem", /* 29) !! DEPRECATED !! - COL_HPUX_SUBSYS */
153 "Hardware dest addr", /* 30) COL_DEF_DL_DST */
154 "Hardware src addr", /* 31) COL_DEF_DL_SRC */
155 "Hw dest addr (resolved)", /* 32) COL_RES_DL_DST */
156 "Hw dest addr (unresolved)", /* 33) COL_UNRES_DL_DST */
157 "Hw src addr (resolved)", /* 34) COL_RES_DL_SRC*/
158 "Hw src addr (unresolved)", /* 35) COL_UNRES_DL_SRC */
159 "IEEE 802.11 RSSI", /* 36) COL_RSSI */
160 "IEEE 802.11 TX rate", /* 37) COL_TX_RATE */
161 "IP DSCP Value", /* 38) COL_DSCP_VALUE */
162 "Information", /* 39) COL_INFO */
163 "L2 COS Value (802.1p)", /* 40) !! DEPRECATED !! - COL_COS_VALUE */
164 "Net dest addr (resolved)", /* 41) COL_RES_NET_DST */
165 "Net dest addr (unresolved)", /* 42) COL_UNRES_NET_DST */
166 "Net src addr (resolved)", /* 43) COL_RES_NET_SRC */
167 "Net src addr (unresolved)", /* 44) COL_UNRES_NET_SRC */
168 "Network dest addr", /* 45) COL_DEF_NET_DST */
169 "Network src addr", /* 46) COL_DEF_NET_SRC */
170 "Number", /* 47) COL_NUMBER */
171 "Packet length (bytes)" , /* 48) COL_PACKET_LENGTH */
172 "Protocol", /* 49) COL_PROTOCOL */
173 "Relative time", /* 50) COL_REL_TIME */
174 "Relative time (conversation)", /* 51) !! DEPRECATED !! - COL_REL_CONV_TIME */
175 "Source address", /* 52) COL_DEF_SRC */
176 "Source port", /* 53) COL_DEF_SRC_PORT */
177 "Src addr (resolved)", /* 54) COL_RES_SRC */
178 "Src addr (unresolved)", /* 55) COL_UNRES_SRC */
179 "Src port (resolved)", /* 56) COL_RES_SRC_PORT */
180 "Src port (unresolved)", /* 57) COL_UNRES_SRC_PORT */
181 "TEI", /* 58) COL_TEI */
182 "UTC date, as YYYY-MM-DD, and time", /* 59) COL_UTC_YMD_TIME */
183 "UTC date, as YYYY/DOY, and time", /* 60) COL_UTC_YDOY_TIME */
184 "UTC time", /* 61) COL_UTC_TIME */
185 "Time (format as specified)" /* 62) COL_CLS_TIME */
188 g_assert((fmt >= 0) && (fmt < NUM_COL_FMTS));
189 return(dlist[fmt]);
192 void
193 column_dump_column_formats(void)
195 gint fmt;
197 for (fmt = 0; fmt < NUM_COL_FMTS; fmt++) {
198 printf("%s\t%s\n", col_format_to_string(fmt), col_format_desc(fmt));
201 printf("\nFor example, to print Wireshark's default columns with tshark:\n\n"
202 #ifdef _WIN32
203 "tshark.exe -o \"gui.column.format:"
204 "\\\"No.\\\",\\\"%%m\\\","
205 "\\\"Time\\\",\\\"%%t\\\","
206 "\\\"Source\\\",\\\"%%s\\\","
207 "\\\"Destination\\\",\\\"%%d\\\","
208 "\\\"Protocol\\\",\\\"%%p\\\","
209 "\\\"Length\\\",\\\"%%L\\\","
210 "\\\"Info\\\",\\\"%%i\\\"\"\n");
211 #else
212 "tshark -o 'gui.column.format:"
213 "\"No.\",\"%%m\","
214 "\"Time\",\"%%t\","
215 "\"Source\",\"%%s\","
216 "\"Destination\",\"%%d\","
217 "\"Protocol\",\"%%p\","
218 "\"Length\",\"%%L\","
219 "\"Info\",\"%%i\"'\n");
220 #endif
223 /* Marks each array element true if it can be substituted for the given
224 column format */
225 void
226 get_column_format_matches(gboolean *fmt_list, const gint format) {
228 /* Get the obvious: the format itself */
229 if ((format >= 0) && (format < NUM_COL_FMTS))
230 fmt_list[format] = TRUE;
232 /* Get any formats lower down on the chain */
233 switch (format) {
234 case COL_DEF_SRC:
235 fmt_list[COL_RES_DL_SRC] = TRUE;
236 fmt_list[COL_RES_NET_SRC] = TRUE;
237 break;
238 case COL_RES_SRC:
239 fmt_list[COL_RES_DL_SRC] = TRUE;
240 fmt_list[COL_RES_NET_SRC] = TRUE;
241 break;
242 case COL_UNRES_SRC:
243 fmt_list[COL_UNRES_DL_SRC] = TRUE;
244 fmt_list[COL_UNRES_NET_SRC] = TRUE;
245 break;
246 case COL_DEF_DST:
247 fmt_list[COL_RES_DL_DST] = TRUE;
248 fmt_list[COL_RES_NET_DST] = TRUE;
249 break;
250 case COL_RES_DST:
251 fmt_list[COL_RES_DL_DST] = TRUE;
252 fmt_list[COL_RES_NET_DST] = TRUE;
253 break;
254 case COL_UNRES_DST:
255 fmt_list[COL_UNRES_DL_DST] = TRUE;
256 fmt_list[COL_UNRES_NET_DST] = TRUE;
257 break;
258 case COL_DEF_DL_SRC:
259 fmt_list[COL_RES_DL_SRC] = TRUE;
260 break;
261 case COL_DEF_DL_DST:
262 fmt_list[COL_RES_DL_DST] = TRUE;
263 break;
264 case COL_DEF_NET_SRC:
265 fmt_list[COL_RES_NET_SRC] = TRUE;
266 break;
267 case COL_DEF_NET_DST:
268 fmt_list[COL_RES_NET_DST] = TRUE;
269 break;
270 case COL_DEF_SRC_PORT:
271 fmt_list[COL_RES_SRC_PORT] = TRUE;
272 break;
273 case COL_DEF_DST_PORT:
274 fmt_list[COL_RES_DST_PORT] = TRUE;
275 break;
276 default:
277 break;
281 /* Returns a string representing the longest possible value for
282 a timestamp column type. */
283 static const char *
284 get_timestamp_column_longest_string(const gint type, const gint precision)
287 switch(type) {
288 case(TS_ABSOLUTE_WITH_YMD):
289 case(TS_UTC_WITH_YMD):
290 switch(precision) {
291 case(TS_PREC_AUTO_SEC):
292 case(TS_PREC_FIXED_SEC):
293 return "0000-00-00 00:00:00";
294 break;
295 case(TS_PREC_AUTO_DSEC):
296 case(TS_PREC_FIXED_DSEC):
297 return "0000-00-00 00:00:00.0";
298 break;
299 case(TS_PREC_AUTO_CSEC):
300 case(TS_PREC_FIXED_CSEC):
301 return "0000-00-00 00:00:00.00";
302 break;
303 case(TS_PREC_AUTO_MSEC):
304 case(TS_PREC_FIXED_MSEC):
305 return "0000-00-00 00:00:00.000";
306 break;
307 case(TS_PREC_AUTO_USEC):
308 case(TS_PREC_FIXED_USEC):
309 return "0000-00-00 00:00:00.000000";
310 break;
311 case(TS_PREC_AUTO_NSEC):
312 case(TS_PREC_FIXED_NSEC):
313 return "0000-00-00 00:00:00.000000000";
314 break;
315 default:
316 g_assert_not_reached();
318 break;
319 case(TS_ABSOLUTE_WITH_YDOY):
320 case(TS_UTC_WITH_YDOY):
321 switch(precision) {
322 case(TS_PREC_AUTO_SEC):
323 case(TS_PREC_FIXED_SEC):
324 return "0000/000 00:00:00";
325 break;
326 case(TS_PREC_AUTO_DSEC):
327 case(TS_PREC_FIXED_DSEC):
328 return "0000/000 00:00:00.0";
329 break;
330 case(TS_PREC_AUTO_CSEC):
331 case(TS_PREC_FIXED_CSEC):
332 return "0000/000 00:00:00.00";
333 break;
334 case(TS_PREC_AUTO_MSEC):
335 case(TS_PREC_FIXED_MSEC):
336 return "0000/000 00:00:00.000";
337 break;
338 case(TS_PREC_AUTO_USEC):
339 case(TS_PREC_FIXED_USEC):
340 return "0000/000 00:00:00.000000";
341 break;
342 case(TS_PREC_AUTO_NSEC):
343 case(TS_PREC_FIXED_NSEC):
344 return "0000/000 00:00:00.000000000";
345 break;
346 default:
347 g_assert_not_reached();
349 break;
350 case(TS_ABSOLUTE):
351 case(TS_UTC):
352 switch(precision) {
353 case(TS_PREC_AUTO_SEC):
354 case(TS_PREC_FIXED_SEC):
355 return "00:00:00";
356 break;
357 case(TS_PREC_AUTO_DSEC):
358 case(TS_PREC_FIXED_DSEC):
359 return "00:00:00.0";
360 break;
361 case(TS_PREC_AUTO_CSEC):
362 case(TS_PREC_FIXED_CSEC):
363 return "00:00:00.00";
364 break;
365 case(TS_PREC_AUTO_MSEC):
366 case(TS_PREC_FIXED_MSEC):
367 return "00:00:00.000";
368 break;
369 case(TS_PREC_AUTO_USEC):
370 case(TS_PREC_FIXED_USEC):
371 return "00:00:00.000000";
372 break;
373 case(TS_PREC_AUTO_NSEC):
374 case(TS_PREC_FIXED_NSEC):
375 return "00:00:00.000000000";
376 break;
377 default:
378 g_assert_not_reached();
380 break;
381 case(TS_RELATIVE): /* fallthrough */
382 case(TS_DELTA):
383 case(TS_DELTA_DIS):
384 switch(precision) {
385 case(TS_PREC_AUTO_SEC):
386 case(TS_PREC_FIXED_SEC):
387 return "0000";
388 break;
389 case(TS_PREC_AUTO_DSEC):
390 case(TS_PREC_FIXED_DSEC):
391 return "0000.0";
392 break;
393 case(TS_PREC_AUTO_CSEC):
394 case(TS_PREC_FIXED_CSEC):
395 return "0000.00";
396 break;
397 case(TS_PREC_AUTO_MSEC):
398 case(TS_PREC_FIXED_MSEC):
399 return "0000.000";
400 break;
401 case(TS_PREC_AUTO_USEC):
402 case(TS_PREC_FIXED_USEC):
403 return "0000.000000";
404 break;
405 case(TS_PREC_AUTO_NSEC):
406 case(TS_PREC_FIXED_NSEC):
407 return "0000.000000000";
408 break;
409 default:
410 g_assert_not_reached();
412 break;
413 case(TS_EPOCH):
414 /* This is enough to represent 2^63 (signed 64-bit integer) + fractions */
415 switch(precision) {
416 case(TS_PREC_AUTO_SEC):
417 case(TS_PREC_FIXED_SEC):
418 return "0000000000000000000";
419 break;
420 case(TS_PREC_AUTO_DSEC):
421 case(TS_PREC_FIXED_DSEC):
422 return "0000000000000000000.0";
423 break;
424 case(TS_PREC_AUTO_CSEC):
425 case(TS_PREC_FIXED_CSEC):
426 return "0000000000000000000.00";
427 break;
428 case(TS_PREC_AUTO_MSEC):
429 case(TS_PREC_FIXED_MSEC):
430 return "0000000000000000000.000";
431 break;
432 case(TS_PREC_AUTO_USEC):
433 case(TS_PREC_FIXED_USEC):
434 return "0000000000000000000.000000";
435 break;
436 case(TS_PREC_AUTO_NSEC):
437 case(TS_PREC_FIXED_NSEC):
438 return "0000000000000000000.000000000";
439 break;
440 default:
441 g_assert_not_reached();
443 break;
444 case(TS_NOT_SET):
445 return "0000.000000";
446 break;
447 default:
448 g_assert_not_reached();
451 /* never reached, satisfy compiler */
452 return "";
455 /* Returns the longer string of the column title or the hard-coded width of
456 * its contents for building the packet list layout. */
457 const gchar *
458 get_column_width_string(const gint format, const gint col)
460 if(strlen(get_column_longest_string(format)) >
461 strlen(get_column_title(col)))
462 return get_column_longest_string(format);
463 else
464 return get_column_title(col);
467 /* Returns a string representing the longest possible value for a
468 particular column type. See also get_column_width_string() above.
470 Except for the COL...SRC and COL...DST columns, these are used
471 only when a capture is being displayed while it's taking place;
472 they are arguably somewhat fragile, as changes to the code that
473 generates them don't cause these widths to change, but that's
474 probably not too big a problem, given that the sizes are
475 recomputed based on the actual data in the columns when the capture
476 is done, and given that the width for COL...SRC and COL...DST columns
477 is somewhat arbitrary in any case. We should probably clean
478 that up eventually, though. */
479 const char *
480 get_column_longest_string(const gint format)
482 switch (format) {
483 case COL_NUMBER:
484 return "0000000";
485 break;
486 case COL_CLS_TIME:
487 return get_timestamp_column_longest_string(timestamp_get_type(), timestamp_get_precision());
488 break;
489 case COL_ABS_YMD_TIME:
490 return get_timestamp_column_longest_string(TS_ABSOLUTE_WITH_YMD, timestamp_get_precision());
491 break;
492 case COL_ABS_YDOY_TIME:
493 return get_timestamp_column_longest_string(TS_ABSOLUTE_WITH_YDOY, timestamp_get_precision());
494 break;
495 case COL_UTC_YMD_TIME:
496 return get_timestamp_column_longest_string(TS_UTC_WITH_YMD, timestamp_get_precision());
497 break;
498 case COL_UTC_YDOY_TIME:
499 return get_timestamp_column_longest_string(TS_UTC_WITH_YDOY, timestamp_get_precision());
500 break;
501 case COL_ABS_TIME:
502 return get_timestamp_column_longest_string(TS_ABSOLUTE, timestamp_get_precision());
503 break;
504 case COL_UTC_TIME:
505 return get_timestamp_column_longest_string(TS_UTC, timestamp_get_precision());
506 break;
507 case COL_REL_TIME:
508 return get_timestamp_column_longest_string(TS_RELATIVE, timestamp_get_precision());
509 break;
510 case COL_DELTA_TIME:
511 return get_timestamp_column_longest_string(TS_DELTA, timestamp_get_precision());
512 break;
513 case COL_DELTA_TIME_DIS:
514 return get_timestamp_column_longest_string(TS_DELTA_DIS, timestamp_get_precision());
515 break;
516 case COL_REL_CONV_TIME: /* 'abuse' TS_RELATIVE to set the time format */
517 case COL_DELTA_CONV_TIME: /* for the conversation related time columns */
518 return get_timestamp_column_longest_string(TS_RELATIVE, timestamp_get_precision());
519 break;
520 case COL_DEF_SRC:
521 case COL_RES_SRC:
522 case COL_UNRES_SRC:
523 case COL_DEF_DL_SRC:
524 case COL_RES_DL_SRC:
525 case COL_UNRES_DL_SRC:
526 case COL_DEF_NET_SRC:
527 case COL_RES_NET_SRC:
528 case COL_UNRES_NET_SRC:
529 case COL_DEF_DST:
530 case COL_RES_DST:
531 case COL_UNRES_DST:
532 case COL_DEF_DL_DST:
533 case COL_RES_DL_DST:
534 case COL_UNRES_DL_DST:
535 case COL_DEF_NET_DST:
536 case COL_RES_NET_DST:
537 case COL_UNRES_NET_DST:
538 return "00000000.000000000000"; /* IPX-style */
539 break;
540 case COL_DEF_SRC_PORT:
541 case COL_RES_SRC_PORT:
542 case COL_UNRES_SRC_PORT:
543 case COL_DEF_DST_PORT:
544 case COL_RES_DST_PORT:
545 case COL_UNRES_DST_PORT:
546 return "000000";
547 break;
548 case COL_PROTOCOL:
549 return "Protocol"; /* not the longest, but the longest is too long */
550 break;
551 case COL_PACKET_LENGTH:
552 return "00000";
553 break;
554 case COL_CUMULATIVE_BYTES:
555 return "00000000";
556 break;
557 case COL_RXID:
558 case COL_OXID:
559 return "000000";
560 break;
561 case COL_IF_DIR:
562 return "i 00000000 I";
563 break;
564 case COL_CIRCUIT_ID:
565 return "000000";
566 break;
567 case COL_SRCIDX:
568 case COL_DSTIDX:
569 return "00000000";
570 break;
571 case COL_VSAN:
572 return "000000";
573 break;
574 case COL_TX_RATE:
575 return "108.0";
576 break;
577 case COL_RSSI:
578 return "100";
579 break;
580 case COL_HPUX_SUBSYS:
581 return "OTS9000-TRANSPORT";
582 break;
583 case COL_HPUX_DEVID:
584 return "0000";
585 break;
586 case COL_DCE_CALL:
587 return "0000";
588 break;
589 case COL_DCE_CTX:
590 return "0000";
591 break;
592 case COL_8021Q_VLAN_ID:
593 return "0000";
594 break;
595 case COL_DSCP_VALUE:
596 return "00";
597 break;
598 case COL_COS_VALUE:
599 return "0";
600 break;
601 case COL_TEI:
602 return "127";
603 break;
604 case COL_FR_DLCI:
605 return "8388608";
606 break;
607 case COL_BSSGP_TLLI:
608 return "0xffffffff";
609 break;
610 case COL_EXPERT:
611 return "ERROR";
612 break;
613 case COL_FREQ_CHAN:
614 return "9999 MHz [A 999]";
615 break;
616 case COL_CUSTOM:
617 return "0000000000"; /* not the longest, but the longest is too long */
618 break;
619 default: /* COL_INFO */
620 return "Source port: kerberos-master Destination port: kerberos-master";
621 break;
625 /* Returns the longest possible width, in characters, for a particular
626 column type. */
627 gint
628 get_column_char_width(const gint format)
630 return (gint)strlen(get_column_longest_string(format));
633 gint
634 get_column_format(const gint col)
636 GList *clp = g_list_nth(prefs.col_list, col);
637 fmt_data *cfmt;
639 if (!clp) /* Invalid column requested */
640 return -1;
642 cfmt = (fmt_data *) clp->data;
644 return(cfmt->fmt);
647 void
648 set_column_format(const gint col, const gint fmt)
650 GList *clp = g_list_nth(prefs.col_list, col);
651 fmt_data *cfmt;
653 if (!clp) /* Invalid column requested */
654 return;
656 cfmt = (fmt_data *) clp->data;
658 cfmt->fmt = fmt;
661 gint
662 get_column_format_from_str(const gchar *str)
664 gint i;
666 for (i = 0; i < NUM_COL_FMTS; i++) {
667 if (strcmp(str, col_format_to_string(i)) == 0)
668 return i;
670 return -1; /* illegal */
673 gchar *
674 get_column_title(const gint col)
676 GList *clp = g_list_nth(prefs.col_list, col);
677 fmt_data *cfmt;
679 if (!clp) /* Invalid column requested */
680 return NULL;
682 cfmt = (fmt_data *) clp->data;
684 return(cfmt->title);
687 void
688 set_column_title(const gint col, const gchar *title)
690 GList *clp = g_list_nth(prefs.col_list, col);
691 fmt_data *cfmt;
693 if (!clp) /* Invalid column requested */
694 return;
696 cfmt = (fmt_data *) clp->data;
698 g_free (cfmt->title);
699 cfmt->title = g_strdup (title);
702 gboolean
703 get_column_visible(const gint col)
705 GList *clp = g_list_nth(prefs.col_list, col);
706 fmt_data *cfmt;
708 if (!clp) /* Invalid column requested */
709 return TRUE;
711 cfmt = (fmt_data *) clp->data;
713 return(cfmt->visible);
716 void
717 set_column_visible(const gint col, gboolean visible)
719 GList *clp = g_list_nth(prefs.col_list, col);
720 fmt_data *cfmt;
722 if (!clp) /* Invalid column requested */
723 return;
725 cfmt = (fmt_data *) clp->data;
727 cfmt->visible = visible;
730 gboolean
731 get_column_resolved(const gint col)
733 GList *clp = g_list_nth(prefs.col_list, col);
734 fmt_data *cfmt;
736 if (!clp) /* Invalid column requested */
737 return TRUE;
739 cfmt = (fmt_data *) clp->data;
741 return(cfmt->resolved);
744 void
745 set_column_resolved(const gint col, gboolean resolved)
747 GList *clp = g_list_nth(prefs.col_list, col);
748 fmt_data *cfmt;
750 if (!clp) /* Invalid column requested */
751 return;
753 cfmt = (fmt_data *) clp->data;
755 cfmt->resolved = resolved;
758 const gchar *
759 get_column_custom_field(const gint col)
761 GList *clp = g_list_nth(prefs.col_list, col);
762 fmt_data *cfmt;
764 if (!clp) /* Invalid column requested */
765 return NULL;
767 cfmt = (fmt_data *) clp->data;
769 return(cfmt->custom_field);
772 void
773 set_column_custom_field(const gint col, const char *custom_field)
775 GList *clp = g_list_nth(prefs.col_list, col);
776 fmt_data *cfmt;
778 if (!clp) /* Invalid column requested */
779 return;
781 cfmt = (fmt_data *) clp->data;
783 g_free (cfmt->custom_field);
784 cfmt->custom_field = g_strdup (custom_field);
787 gint
788 get_column_custom_occurrence(const gint col)
790 GList *clp = g_list_nth(prefs.col_list, col);
791 fmt_data *cfmt;
793 if (!clp) /* Invalid column requested */
794 return 0;
796 cfmt = (fmt_data *) clp->data;
798 return(cfmt->custom_occurrence);
801 void
802 set_column_custom_occurrence(const gint col, const gint custom_occurrence)
804 GList *clp = g_list_nth(prefs.col_list, col);
805 fmt_data *cfmt;
807 if (!clp) /* Invalid column requested */
808 return;
810 cfmt = (fmt_data *) clp->data;
812 cfmt->custom_occurrence = custom_occurrence;
815 void
816 build_column_format_array(column_info *cinfo, const gint num_cols, const gboolean reset_fences)
818 int i;
820 /* Build the column format array */
821 col_setup(cinfo, num_cols);
823 for (i = 0; i < cinfo->num_cols; i++) {
824 cinfo->col_fmt[i] = get_column_format(i);
825 cinfo->col_title[i] = g_strdup(get_column_title(i));
827 if (cinfo->col_fmt[i] == COL_CUSTOM) {
828 cinfo->col_custom_field[i] = g_strdup(get_column_custom_field(i));
829 cinfo->col_custom_occurrence[i] = get_column_custom_occurrence(i);
830 if(!dfilter_compile(cinfo->col_custom_field[i], &cinfo->col_custom_dfilter[i])) {
831 /* XXX: Should we issue a warning? */
832 g_free(cinfo->col_custom_field[i]);
833 cinfo->col_custom_field[i] = NULL;
834 cinfo->col_custom_occurrence[i] = 0;
835 cinfo->col_custom_dfilter[i] = NULL;
837 } else {
838 cinfo->col_custom_field[i] = NULL;
839 cinfo->col_custom_occurrence[i] = 0;
840 cinfo->col_custom_dfilter[i] = NULL;
843 cinfo->fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) * NUM_COL_FMTS);
844 get_column_format_matches(cinfo->fmt_matx[i], cinfo->col_fmt[i]);
845 cinfo->col_data[i] = NULL;
847 if (cinfo->col_fmt[i] == COL_INFO)
848 cinfo->col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
849 else
850 cinfo->col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
852 if(reset_fences)
853 cinfo->col_fence[i] = 0;
855 cinfo->col_expr.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
856 cinfo->col_expr.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
859 cinfo->col_expr.col_expr[i] = NULL;
860 cinfo->col_expr.col_expr_val[i] = NULL;
862 for (i = 0; i < cinfo->num_cols; i++) {
863 int j;
865 for (j = 0; j < NUM_COL_FMTS; j++) {
866 if (!cinfo->fmt_matx[i][j])
867 continue;
869 if (cinfo->col_first[j] == -1)
870 cinfo->col_first[j] = i;
872 cinfo->col_last[j] = i;
878 * Editor modelines - http://www.wireshark.org/tools/modelines.html
880 * Local variables:
881 * c-basic-offset: 2
882 * tab-width: 2
883 * indent-tabs-mode: nil
884 * End:
886 * vi: set shiftwidth=2 tabstop=2 expandtab:
887 * :indentSize=2:tabSize=2:noTabs=true: