4 * Wireshark's interface to the Lua Programming Language
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 * (c) 2008, Balint Reczey <balint.reczey@ericsson.com>
8 * (c) 2011, Stig Bjorlykke <stig@bjorlykke.org>
9 * (c) 2014, Hadriel Kaplan <hadrielk@yahoo.com>
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * SPDX-License-Identifier: GPL-2.0-or-later
21 #include <epan/unit_strings.h>
25 /* WSLUA_CONTINUE_MODULE Proto */
28 WSLUA_CLASS_DEFINE(ProtoField
,FAIL_ON_NULL("null ProtoField"));
29 /* A Protocol field (to be used when adding items to the dissection tree).
30 It must be registered via being added to a `Proto.fields` table. */
32 static const wslua_ft_types_t ftenums
[] = {
33 {"ftypes.NONE", FT_NONE
},
34 {"ftypes.BOOLEAN", FT_BOOLEAN
},
35 {"ftypes.CHAR", FT_CHAR
},
36 {"ftypes.UINT8", FT_UINT8
},
37 {"ftypes.UINT16", FT_UINT16
},
38 {"ftypes.UINT24", FT_UINT24
},
39 {"ftypes.UINT32", FT_UINT32
},
40 {"ftypes.UINT64", FT_UINT64
},
41 {"ftypes.INT8", FT_INT8
},
42 {"ftypes.INT16", FT_INT16
},
43 {"ftypes.INT24", FT_INT24
},
44 {"ftypes.INT32", FT_INT32
},
45 {"ftypes.INT64", FT_INT64
},
46 {"ftypes.FLOAT", FT_FLOAT
},
47 {"ftypes.DOUBLE", FT_DOUBLE
},
48 {"ftypes.ABSOLUTE_TIME", FT_ABSOLUTE_TIME
},
49 {"ftypes.RELATIVE_TIME", FT_RELATIVE_TIME
},
50 {"ftypes.STRING", FT_STRING
},
51 {"ftypes.STRINGZ", FT_STRINGZ
},
52 {"ftypes.ETHER", FT_ETHER
},
53 {"ftypes.BYTES", FT_BYTES
},
54 {"ftypes.UINT_BYTES", FT_UINT_BYTES
},
55 {"ftypes.IPv4", FT_IPv4
},
56 {"ftypes.IPv6", FT_IPv6
},
57 {"ftypes.IPXNET", FT_IPXNET
},
58 {"ftypes.FRAMENUM", FT_FRAMENUM
},
59 {"ftypes.GUID", FT_GUID
},
60 {"ftypes.OID", FT_OID
},
61 {"ftypes.SYSTEM_ID", FT_SYSTEM_ID
},
62 {"ftypes.REL_OID", FT_REL_OID
},
63 {"ftypes.EUI64", FT_EUI64
},
64 {"ftypes.FCWWN", FT_FCWWN
},
68 static enum ftenum
get_ftenum(const char* type
) {
69 const wslua_ft_types_t
* ts
;
70 for (ts
= ftenums
; ts
->str
; ts
++) {
71 if ( g_str_equal(ts
->str
,type
) ) {
78 static const char* ftenum_to_string(enum ftenum ft
) {
79 const wslua_ft_types_t
* ts
;
80 for (ts
= ftenums
; ts
->str
; ts
++) {
88 struct field_display_string_t
{
94 * This table is primarily used to convert from string representation
95 * to int representation in string_to_base().
96 * Some string values are added for backward compatibility.
98 static const struct field_display_string_t base_displays
[] = {
99 {"base.NONE", BASE_NONE
},
100 {"base.DEC", BASE_DEC
},
101 {"base.HEX", BASE_HEX
},
102 {"base.OCT", BASE_OCT
},
103 {"base.DEC_HEX", BASE_DEC_HEX
},
104 {"base.HEX_DEC", BASE_HEX_DEC
},
105 {"base.UNIT_STRING", BASE_UNIT_STRING
},
106 /* Byte separators */
107 {"base.DOT", SEP_DOT
},
108 {"base.DASH", SEP_DASH
},
109 {"base.COLON", SEP_COLON
},
110 {"base.SPACE", SEP_SPACE
},
111 /* for FT_BOOLEAN, how wide the parent bitfield is */
116 /* FT_ABSOLUTE_TIME */
117 {"base.LOCAL", ABSOLUTE_TIME_LOCAL
},
118 {"base.UTC", ABSOLUTE_TIME_UTC
},
119 {"base.DOY_UTC", ABSOLUTE_TIME_DOY_UTC
},
120 {"LOCAL", ABSOLUTE_TIME_LOCAL
}, /* for backward compatibility */
121 {"UTC", ABSOLUTE_TIME_UTC
}, /* for backward compatibility */
122 {"DOY_UTC", ABSOLUTE_TIME_DOY_UTC
}, /* for backward compatibility */
126 static const char* base_to_string(unsigned base
) {
127 const struct field_display_string_t
* b
;
128 for (b
=base_displays
;b
->str
;b
++) {
129 if ( base
== b
->base
)
135 static unsigned string_to_base(const char* str
) {
136 const struct field_display_string_t
* b
;
137 for (b
=base_displays
;b
->str
;b
++) {
138 if ( g_str_equal(str
,b
->str
))
144 static void cleanup_range_string(GArray
*rs
) {
145 range_string
*rs32
= (range_string
*)(void *)(rs
->data
);
147 while (rs32
->strptr
) {
148 g_free((char *)rs32
->strptr
);
151 g_array_free(rs
, true);
154 static range_string
* range_string_from_table(lua_State
* L
, int idx
) {
158 if (lua_isnil(L
,idx
)) {
160 } else if (!lua_istable(L
,idx
)) {
161 luaL_argerror(L
,idx
,"must be a table");
166 * The first parameter set to true means give us a zero-filled
169 rs
= g_array_new(true,true,sizeof(range_string
));
173 while (lua_next(L
, idx
) != 0) {
176 range_string r
= {0,0,NULL
};
178 if (!lua_istable(L
, -1)) {
179 cleanup_range_string(rs
);
180 luaL_argerror(L
, idx
, "All values of a table used as a range_string must be tables");
185 * Now process the table ... it must have three elements,
186 * the min value, the max, both integers and a string.
188 * However, they are each separate items in the table and we
191 inner_idx
= lua_gettop(L
);
195 * First two elements must be numbers, third is a string
197 while (lua_next(L
, inner_idx
) != 0) {
198 if (++key_count
> 3) {
205 if (!lua_isnumber(L
, -1)) {
206 cleanup_range_string(rs
);
207 luaL_argerror(L
, idx
, "First two elements of a range string value must be integers");
210 if (key_count
== 1) /* We incremented it above */
211 r
.value_min
= wslua_touint64(L
, -1);
213 r
.value_max
= wslua_touint64(L
, -1);
217 if (lua_type(L
, -1) != LUA_TSTRING
) {
218 cleanup_range_string(rs
);
219 luaL_argerror(L
, idx
, "Third element of a range string value must be a string");
222 r
.strptr
= g_strdup(lua_tostring(L
,-1));
224 * We append the value here to avoid a mem leak if there
225 * are more than three entries in the table.
227 g_array_append_val(rs
,r
);
234 if (key_count
!= 3) {
235 cleanup_range_string(rs
);
236 luaL_argerror(L
, idx
, "Values of a range string must be tables with exactly three elements");
243 rs32
= (range_string
*)(void*)g_array_free(rs
, false);
248 static value_string
* value_string_from_table(lua_State
* L
, int idx
) {
252 if (lua_isnil(L
,idx
)) {
254 } else if (!lua_istable(L
,idx
)) {
255 luaL_argerror(L
,idx
,"must be a table");
260 * The first parameter set to true means give us a zero-filled
263 vs
= g_array_new(true,true,sizeof(value_string
));
267 while (lua_next(L
, idx
) != 0) {
268 value_string v
= {0,NULL
};
270 if (! lua_isnumber(L
,-2)) {
271 vs32
= (value_string
*)(void *)vs
->data
;
272 while (vs32
->strptr
) {
273 g_free((char *)vs32
->strptr
);
276 g_array_free(vs
,true);
277 luaL_argerror(L
,idx
,"All keys of a table used as value_string must be integers");
281 if (! lua_isstring(L
,-1)) {
282 vs32
= (value_string
*)(void *)vs
->data
;
283 while (vs32
->strptr
) {
284 g_free((char *)vs32
->strptr
);
287 g_array_free(vs
,true);
288 luaL_argerror(L
,idx
,"All values of a table used as value_string must be strings");
292 v
.value
= wslua_touint32(L
,-2);
293 v
.strptr
= g_strdup(lua_tostring(L
,-1));
295 g_array_append_val(vs
,v
);
300 vs32
= (value_string
*)(void*)g_array_free(vs
, false);
305 static val64_string
* val64_string_from_table(lua_State
* L
, int idx
) {
309 if (lua_isnil(L
,idx
)) {
311 } else if (!lua_istable(L
,idx
)) {
312 luaL_argerror(L
,idx
,"must be a table");
317 * The first parameter set to true means give us a zero-filled
320 vs
= g_array_new(true,true,sizeof(val64_string
));
324 while (lua_next(L
, idx
) != 0) {
325 val64_string v
= {0,NULL
};
327 if (! lua_isnumber(L
,-2)) {
328 vs64
= (val64_string
*)(void *)vs
->data
;
329 while (vs64
->strptr
) {
330 g_free((char *)vs64
->strptr
);
333 g_array_free(vs
,true);
334 luaL_argerror(L
,idx
,"All keys of a table used as value string must be integers");
338 if (! lua_isstring(L
,-1)) {
339 vs64
= (val64_string
*)(void *)vs
->data
;
340 while (vs64
->strptr
) {
341 g_free((char *)vs64
->strptr
);
344 g_array_free(vs
,true);
345 luaL_argerror(L
,idx
,"All values of a table used as value string must be strings");
349 v
.value
= wslua_touint64(L
, -2);
350 v
.strptr
= g_strdup(lua_tostring(L
,-1));
352 g_array_append_val(vs
,v
);
357 vs64
= (val64_string
*)(void*)g_array_free(vs
, false);
362 static true_false_string
* true_false_string_from_table(lua_State
* L
, int idx
) {
363 true_false_string
* tfs
;
367 if (lua_isnil(L
,idx
)) {
369 } else if (!lua_istable(L
,idx
)) {
370 luaL_argerror(L
,idx
,"must be a table");
374 true_string
= g_strdup("True");
375 false_string
= g_strdup("False");
379 while (lua_next(L
, idx
)) {
381 if (! lua_isnumber(L
,-2)) {
382 g_free (true_string
);
383 g_free (false_string
);
384 luaL_argerror(L
,idx
,"All keys of a table used as true_false_string must be integers");
388 if (! lua_isstring(L
,-1)) {
389 g_free (true_string
);
390 g_free (false_string
);
391 luaL_argerror(L
,idx
,"All values of a table used as true_false_string must be strings");
395 /* Arrays in Lua start with index number 1 */
396 switch (lua_tointeger(L
,-2)) {
399 true_string
= g_strdup(lua_tostring(L
,-1));
402 g_free(false_string
);
403 false_string
= g_strdup(lua_tostring(L
,-1));
406 g_free (true_string
);
407 g_free (false_string
);
408 luaL_argerror(L
,idx
,"The true_false_string table can have maximum two strings with key value 1 and 2");
415 tfs
= g_new(true_false_string
, 1);
416 tfs
->true_string
= true_string
;
417 tfs
->false_string
= false_string
;
422 static uint64_t get_mask(lua_State
* L
, int idx
, uint64_t default_value
) {
423 uint64_t mask
= default_value
;
425 switch(lua_type(L
, idx
)) {
427 mask
= wslua_optuint64(L
, idx
, (lua_Number
)default_value
);
431 mask
= getUInt64(L
,idx
);
437 luaL_argerror(L
,idx
,"MASK field must be a number, UInt64 or string");
443 static unit_name_string
* unit_name_string_from_table(lua_State
* L
, int idx
) {
444 unit_name_string
* units
;
446 if (lua_isnil(L
,idx
)) {
448 } else if (!lua_istable(L
,idx
)) {
449 luaL_argerror(L
,idx
,"must be a table");
453 units
= g_new0(unit_name_string
, 1);
457 while (lua_next(L
, idx
)) {
459 if (! lua_isnumber(L
,-2)) {
460 g_free(units
->singular
);
461 g_free(units
->plural
);
463 luaL_argerror(L
,idx
,"All keys of a table used as unit name must be integers");
467 if (! lua_isstring(L
,-1)) {
468 g_free(units
->singular
);
469 g_free(units
->plural
);
471 luaL_argerror(L
,idx
,"All values of a table used as unit name must be strings");
475 /* Arrays in Lua start with index number 1 */
476 switch (lua_tointeger(L
,-2)) {
478 g_free((char *)units
->singular
);
479 units
->singular
= g_strdup(lua_tostring(L
,-1));
482 g_free((char *)units
->plural
);
483 units
->plural
= g_strdup(lua_tostring(L
,-1));
486 g_free(units
->singular
);
487 g_free(units
->plural
);
489 luaL_argerror(L
,idx
,"The unit name table can have maximum two strings with key value 1 and 2");
496 if (!units
->singular
) {
497 g_free(units
->plural
);
499 luaL_argerror(L
,idx
,"The unit name table must have a singular entry (key value 1)");
506 static const char* check_field_name(lua_State
* L
, const int abbr_idx
, const enum ftenum type
) {
507 const char* abbr
= luaL_checkstring(L
,abbr_idx
);
508 const header_field_info
* hfinfo
= NULL
;
511 luaL_argerror(L
, abbr_idx
, "Empty field name abbreviation");
515 if (proto_check_field_name(abbr
)) {
516 luaL_argerror(L
, abbr_idx
, "Invalid char in abbrev");
520 hfinfo
= proto_registrar_get_byname(abbr
);
522 if (hfinfo
&& !ftype_similar_types(type
, hfinfo
->type
)) {
523 luaL_argerror(L
, abbr_idx
, "A field of an incompatible ftype with this abbrev already exists");
530 WSLUA_CONSTRUCTOR
ProtoField_new(lua_State
* L
) {
531 /* Creates a new <<lua_class_ProtoField,`ProtoField`>> object to be used for a protocol field. */
532 #define WSLUA_ARG_ProtoField_new_NAME 1 /* Actual name of the field (the string that
533 appears in the tree). */
534 #define WSLUA_ARG_ProtoField_new_ABBR 2 /* Filter name of the field (the string that
535 is used in filters). */
536 #define WSLUA_ARG_ProtoField_new_TYPE 3 /* Field Type: one of: `ftypes.BOOLEAN`, `ftypes.CHAR`, `ftypes.UINT8`,
537 `ftypes.UINT16`, `ftypes.UINT24`, `ftypes.UINT32`, `ftypes.UINT64`, `ftypes.INT8`,
538 `ftypes.INT16`, `ftypes.INT24`, `ftypes.INT32`, `ftypes.INT64`, `ftypes.FLOAT`,
539 `ftypes.DOUBLE` , `ftypes.ABSOLUTE_TIME`, `ftypes.RELATIVE_TIME`, `ftypes.STRING`,
540 `ftypes.STRINGZ`, `ftypes.UINT_STRING`, `ftypes.ETHER`, `ftypes.BYTES`,
541 `ftypes.UINT_BYTES`, `ftypes.IPv4`, `ftypes.IPv6`, `ftypes.IPXNET`, `ftypes.FRAMENUM`,
542 `ftypes.PCRE`, `ftypes.GUID`, `ftypes.OID`, `ftypes.PROTOCOL`, `ftypes.REL_OID`,
543 `ftypes.SYSTEM_ID`, `ftypes.EUI64` or `ftypes.NONE`.
545 #define WSLUA_OPTARG_ProtoField_new_VALUESTRING 4 /* A table containing the text that
546 corresponds to the values, or a table containing tables of range string values that
547 corresponds to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name
548 for the values if base is `base.UNIT_STRING`, or one of `frametype.NONE`, `frametype.REQUEST`,
549 `frametype.RESPONSE`, `frametype.ACK` or `frametype.DUP_ACK` if field type is ftypes.FRAMENUM. */
550 #define WSLUA_OPTARG_ProtoField_new_BASE 5 /* The representation, one of: `base.NONE`, `base.DEC`,
551 `base.HEX`, `base.OCT`, `base.DEC_HEX`,
552 `base.HEX_DEC`, `base.UNIT_STRING` or
553 `base.RANGE_STRING`. */
554 #define WSLUA_OPTARG_ProtoField_new_MASK 6 /* The bitmask to be used. */
555 #define WSLUA_OPTARG_ProtoField_new_DESCRIPTION 7 /* The description of the field. */
558 int nargs
= lua_gettop(L
);
559 const char* name
= luaL_checkstring(L
,WSLUA_ARG_ProtoField_new_NAME
);
560 const char* abbr
= NULL
;
562 enum ft_framenum_type framenum_type
= FT_FRAMENUM_NONE
;
563 range_string
*rs32
= NULL
;
564 value_string
*vs32
= NULL
;
565 val64_string
*vs64
= NULL
;
566 true_false_string
*tfs
= NULL
;
567 unit_name_string
*uns
= NULL
;
569 uint64_t mask
= get_mask(L
,WSLUA_OPTARG_ProtoField_new_MASK
, 0x0);
570 const char *blob
= luaL_optstring(L
,WSLUA_OPTARG_ProtoField_new_DESCRIPTION
,NULL
);
571 bool base_unit_string
= false;
572 bool base_range_string
= false;
575 WSLUA_ARG_ERROR(ProtoField_new
,NAME
,"cannot be an empty string");
579 if (lua_isnumber(L
,WSLUA_ARG_ProtoField_new_TYPE
)) {
580 type
= (enum ftenum
)luaL_checkinteger(L
,WSLUA_ARG_ProtoField_new_TYPE
);
582 type
= get_ftenum(luaL_checkstring(L
,WSLUA_ARG_ProtoField_new_TYPE
));
585 abbr
= check_field_name(L
,WSLUA_ARG_ProtoField_new_ABBR
,type
);
587 if (lua_isnumber(L
, WSLUA_OPTARG_ProtoField_new_BASE
)) {
588 base
= (unsigned)luaL_optinteger(L
, WSLUA_OPTARG_ProtoField_new_BASE
, BASE_NONE
);
590 base
= string_to_base(luaL_optstring(L
, WSLUA_OPTARG_ProtoField_new_BASE
, "BASE_NONE"));
595 if (base
!= BASE_NONE
) {
596 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"FRAMENUM must use base.NONE");
600 WSLUA_OPTARG_ERROR(ProtoField_new
,MASK
,"FRAMENUM can not have a bitmask");
603 if (nargs
>= WSLUA_OPTARG_ProtoField_new_VALUESTRING
&& !lua_isnil(L
,WSLUA_OPTARG_ProtoField_new_VALUESTRING
)) {
604 framenum_type
= (enum ft_framenum_type
) luaL_checkinteger(L
, 4);
605 if (framenum_type
>= FT_FRAMENUM_NUM_TYPES
) {
606 WSLUA_OPTARG_ERROR(ProtoField_new
,VALUESTRING
,"Invalid frametype");
612 if (nargs
< WSLUA_OPTARG_ProtoField_new_BASE
|| lua_isnil(L
, WSLUA_OPTARG_ProtoField_new_BASE
)) {
613 base
= BASE_OCT
; /* Default base for characters (BASE_HEX instead?) */
615 if (base
& BASE_UNIT_STRING
) {
616 WSLUA_OPTARG_ERROR(ProtoField_new
, BASE
, "Character type can not use base.UNIT_STRING");
630 if (base
& BASE_UNIT_STRING
) {
631 base_unit_string
= true;
632 base
&= ~BASE_UNIT_STRING
;
634 if (base
& BASE_RANGE_STRING
) {
635 base_range_string
= true;
636 base
&= ~BASE_RANGE_STRING
;
638 if (base_unit_string
&& base_range_string
) {
639 WSLUA_OPTARG_ERROR(ProtoField_new
, BASE
, "Only one of base.UNIT_STRING and base.RANGE_STRING can be specified");
642 if (type
!= FT_CHAR
&& base
== BASE_NONE
) {
643 base
= BASE_DEC
; /* Default base for integer */
645 if (type
== FT_CHAR
) {
646 if (base
!= BASE_NONE
&& base
!= BASE_HEX
&& base
!= BASE_OCT
) {
647 luaL_argerror(L
, 3, "Base must be either base.NONE, base.HEX or base.OCT");
650 } else if ((base
!= BASE_DEC
) &&
651 (type
== FT_INT8
|| type
== FT_INT16
|| type
== FT_INT24
|| type
== FT_INT32
|| type
== FT_INT64
))
653 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"Base must be either base.DEC or base.UNIT_STRING");
655 } else if (base
< BASE_DEC
|| base
> BASE_HEX_DEC
) {
656 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"Base must be either base.DEC, base.HEX, base.OCT,"
657 " base.DEC_HEX, base.HEX_DEC or base.UNIT_STRING");
660 if (nargs
>= WSLUA_OPTARG_ProtoField_new_VALUESTRING
) {
661 if (base_unit_string
) {
662 uns
= unit_name_string_from_table(L
,WSLUA_OPTARG_ProtoField_new_VALUESTRING
);
663 } else if (base_range_string
) {
664 rs32
= range_string_from_table(L
, WSLUA_OPTARG_ProtoField_new_VALUESTRING
);
665 } else if (type
== FT_UINT64
|| type
== FT_INT64
) {
666 vs64
= val64_string_from_table(L
,WSLUA_OPTARG_ProtoField_new_VALUESTRING
);
668 vs32
= value_string_from_table(L
,WSLUA_OPTARG_ProtoField_new_VALUESTRING
);
671 if (type
== FT_CHAR
&& base
== BASE_NONE
&& rs32
== NULL
&& vs32
== NULL
) {
672 luaL_argerror(L
, 3, "Base base.NONE must be used with a valuestring");
677 if (mask
== 0x0 && base
!= BASE_NONE
) {
678 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"Base must be base.NONE if bitmask is zero.");
681 if (mask
!= 0x0 && (base
< 1 || base
> 64)) {
682 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"Base must be between 1 and 64 if bitmask is non-zero.");
685 if (nargs
>= WSLUA_OPTARG_ProtoField_new_VALUESTRING
&& !lua_isnil(L
,WSLUA_OPTARG_ProtoField_new_VALUESTRING
)) {
686 tfs
= true_false_string_from_table(L
,WSLUA_OPTARG_ProtoField_new_VALUESTRING
);
689 case FT_ABSOLUTE_TIME
:
690 if (base
== BASE_NONE
) {
691 base
= ABSOLUTE_TIME_LOCAL
; /* Default base for FT_ABSOLUTE_TIME */
692 } else if (!FIELD_DISPLAY_IS_ABSOLUTE_TIME(base
)) {
693 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"Base must be either base.LOCAL, base.UTC, or base.DOY_UTC");
697 WSLUA_OPTARG_ERROR(ProtoField_new
,MASK
,"ABSOLUTE_TIME can not have a bitmask");
703 if (base
!= BASE_NONE
) {
704 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"Display must be base.NONE");
708 WSLUA_OPTARG_ERROR(ProtoField_new
,MASK
,"This type can not have a bitmask");
714 if (base
!= BASE_NONE
&& (base
< SEP_DOT
|| base
> SEP_SPACE
)) {
715 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"Display must be either base.NONE, base.DOT, base.DASH, base.COLON or base.SPACE");
719 WSLUA_OPTARG_ERROR(ProtoField_new
,MASK
,"This type can not have a bitmask");
725 if (base
& BASE_UNIT_STRING
) {
726 base_unit_string
= true;
727 base
&= ~BASE_UNIT_STRING
;
729 if (nargs
>= WSLUA_OPTARG_ProtoField_new_VALUESTRING
) {
730 uns
= unit_name_string_from_table(L
,WSLUA_OPTARG_ProtoField_new_VALUESTRING
);
738 case FT_RELATIVE_TIME
:
747 if (base
!= BASE_NONE
) {
748 WSLUA_OPTARG_ERROR(ProtoField_new
,BASE
,"Base must be base.NONE");
752 WSLUA_OPTARG_ERROR(ProtoField_new
,MASK
,"This type can not have a bitmask");
756 /* TODO: not handled yet */
763 case FT_IEEE_11073_SFLOAT
:
764 case FT_IEEE_11073_FLOAT
:
768 case FT_STRINGZTRUNC
:
769 WSLUA_ARG_ERROR(ProtoField_new
,TYPE
,"Unsupported ProtoField field type");
772 WSLUA_ARG_ERROR(ProtoField_new
,TYPE
,"Invalid ProtoField field type");
776 if (base_unit_string
&& !uns
) {
777 WSLUA_OPTARG_ERROR(ProtoField_new
,VALUESTRING
, "Base contains base.UNIT_STRING but no table was provided");
781 if (base_range_string
&& !rs32
) {
782 WSLUA_OPTARG_ERROR(ProtoField_new
, VALUESTRING
, "Base contains bas.RANGE_STRING but no table was provided")
786 f
= g_new(wslua_field_t
,1);
790 f
->name
= g_strdup(name
);
791 f
->abbrev
= g_strdup(abbr
);
799 f
->base
|= BASE_RANGE_STRING
;
802 /* Indicate that we are using val64_string */
803 f
->base
|= BASE_VAL64_STRING
;
804 f
->vs
= VALS64(vs64
);
806 f
->base
|= BASE_UNIT_STRING
;
808 } else if (framenum_type
) {
809 f
->vs
= FRAMENUM_TYPE(framenum_type
);
814 lua_pushvalue(L
, WSLUA_OPTARG_ProtoField_new_VALUESTRING
);
815 f
->valuestring_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
817 f
->valuestring_ref
= LUA_NOREF
;
820 if (blob
&& strcmp(blob
, f
->name
) != 0) {
821 f
->blob
= g_strdup(blob
);
828 WSLUA_RETURN(1); /* The newly created <<lua_class_ProtoField,`ProtoField`>> object. */
831 static int ProtoField_integer(lua_State
* L
, enum ftenum type
) {
833 const char* abbr
= check_field_name(L
,1,type
);
834 const char* name
= luaL_optstring(L
,2,abbr
);
835 unsigned default_base
= (type
== FT_FRAMENUM
) ? BASE_NONE
: ((type
== FT_CHAR
) ? BASE_OCT
: BASE_DEC
);
836 unsigned base
= (unsigned)luaL_optinteger(L
, 3, default_base
);
837 enum ft_framenum_type framenum_type
= FT_FRAMENUM_NONE
;
838 value_string
* vs32
= NULL
;
839 range_string
* rs32
= NULL
;
840 val64_string
* vs64
= NULL
;
841 unit_name_string
* uns
= NULL
;
842 uint64_t mask
= get_mask(L
,5,0);
843 const char* blob
= luaL_optstring(L
,6,NULL
);
844 bool base_unit_string
= false;
845 bool base_range_string
= false;
848 luaL_argerror(L
, 2, "cannot be an empty string");
852 if (type
== FT_CHAR
&& base
& BASE_UNIT_STRING
) {
853 luaL_argerror(L
, 3, "Character type can not use base.UNIT_STRING");
857 if (base
& BASE_UNIT_STRING
) {
858 base_unit_string
= true;
859 base
&= ~BASE_UNIT_STRING
;
860 if (base
== BASE_NONE
) {
865 if (base
& BASE_RANGE_STRING
) {
866 base_range_string
= true;
867 base
&= ~BASE_RANGE_STRING
;
868 if (type
!= FT_CHAR
&& base
== BASE_NONE
) {
873 if (base_unit_string
&& base_range_string
) {
874 luaL_argerror(L
, 3, "Only one of base.RANGE_STRING and base.UNIT_STRING can be specified");
878 if (lua_gettop(L
) > 3 && !lua_isnil(L
, 4)) {
879 if (type
== FT_FRAMENUM
) {
880 framenum_type
= (enum ft_framenum_type
) luaL_checkinteger(L
, 4);
881 if (framenum_type
>= FT_FRAMENUM_NUM_TYPES
) {
882 luaL_argerror(L
, 4, "Invalid frametype");
885 } else if (base_unit_string
) {
886 uns
= unit_name_string_from_table(L
,4);
887 } else if (base_range_string
) {
888 rs32
= range_string_from_table(L
, 4);
889 } else if (type
== FT_UINT64
|| type
== FT_INT64
) {
890 vs64
= val64_string_from_table(L
,4);
892 vs32
= value_string_from_table(L
,4);
896 if (type
== FT_FRAMENUM
) {
897 if (base
!= BASE_NONE
)
898 luaL_argerror(L
, 3, "FRAMENUM must use base.NONE");
900 luaL_argerror(L
, 5, "FRAMENUM can not have a bitmask");
901 } else if (type
== FT_CHAR
) {
902 if (base
!= BASE_NONE
&& base
!= BASE_HEX
&& base
!= BASE_OCT
) {
903 luaL_argerror(L
, 3, "Base must be either base.NONE, base.HEX or base.OCT");
906 if (base
== BASE_NONE
&& rs32
== NULL
&& vs32
== NULL
) {
907 luaL_argerror(L
, 3, "Base base.NONE must be used with a valuestring");
910 } else if ((base
!= BASE_DEC
) &&
911 (type
== FT_INT8
|| type
== FT_INT16
|| type
== FT_INT24
|| type
== FT_INT32
|| type
== FT_INT64
)) {
912 luaL_argerror(L
, 3, "Base must be either base.DEC or base.UNIT_STRING");
914 } else if (base
< BASE_DEC
|| base
> BASE_HEX_DEC
) {
915 luaL_argerror(L
, 3, "Base must be either base.DEC, base.HEX, base.OCT,"
916 " base.DEC_HEX, base.HEX_DEC or base.UNIT_STRING");
920 if (base_unit_string
&& !uns
) {
921 luaL_argerror(L
, 4, "Base contains base.UNIT_STRING but no table was given");
925 if (base_range_string
&& !rs32
) {
926 luaL_argerror(L
, 4, "Base contains base.RANGE_STRING but no table was given");
930 f
= g_new(wslua_field_t
,1);
934 f
->name
= g_strdup(name
);
935 f
->abbrev
= g_strdup(abbr
);
939 /* Indicate that we are using val64_string */
940 f
->base
|= BASE_VAL64_STRING
;
941 f
->vs
= VALS64(vs64
);
943 f
->base
|= BASE_RANGE_STRING
;
948 f
->base
|= BASE_UNIT_STRING
;
950 } else if (framenum_type
) {
951 f
->vs
= FRAMENUM_TYPE(framenum_type
);
957 f
->valuestring_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
959 f
->valuestring_ref
= LUA_NOREF
;
962 if (blob
&& strcmp(blob
, f
->name
) != 0) {
963 f
->blob
= g_strdup(blob
);
973 #define PROTOFIELD_INTEGER(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_integer(L,FT); }
974 /* _WSLUA_CONSTRUCTOR_ ProtoField_char Creates a <<lua_class_ProtoField,`ProtoField`>> of an 8-bit ASCII character. */
975 /* WSLUA_ARG_ProtoField_char_ABBR Abbreviated name of the field (the string used in filters). */
976 /* WSLUA_OPTARG_ProtoField_char_NAME Actual name of the field (the string that appears in the tree). */
977 /* WSLUA_OPTARG_ProtoField_char_BASE One of `base.NONE`, `base.HEX`, `base.OCT` or `base.RANGE_STRING`. */
978 /* WSLUA_OPTARG_ProtoField_char_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`. */
979 /* WSLUA_OPTARG_ProtoField_char_MASK Integer mask of this field. */
980 /* WSLUA_OPTARG_ProtoField_char_DESCRIPTION Description of the field. */
981 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
983 /* _WSLUA_CONSTRUCTOR_ ProtoField_uint8 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 8-bit integer (i.e., a byte). */
984 /* WSLUA_ARG_ProtoField_uint8_ABBR Abbreviated name of the field (the string used in filters). */
985 /* WSLUA_OPTARG_ProtoField_uint8_NAME Actual name of the field (the string that appears in the tree). */
986 /* WSLUA_OPTARG_ProtoField_uint8_BASE One of `base.DEC`, `base.HEX` or `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */
987 /* WSLUA_OPTARG_ProtoField_uint8_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */
988 /* WSLUA_OPTARG_ProtoField_uint8_MASK Integer, String or UInt64 mask of this field. */
989 /* WSLUA_OPTARG_ProtoField_uint8_DESCRIPTION Description of the field. */
990 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
992 /* _WSLUA_CONSTRUCTOR_ ProtoField_uint16 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 16-bit integer. */
993 /* WSLUA_ARG_ProtoField_uint16_ABBR Abbreviated name of the field (the string used in filters). */
994 /* WSLUA_OPTARG_ProtoField_uint16_NAME Actual name of the field (the string that appears in the tree). */
995 /* WSLUA_OPTARG_ProtoField_uint16_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING` or `base.RANGE_STRING`. */
996 /* WSLUA_OPTARG_ProtoField_uint16_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
997 /* WSLUA_OPTARG_ProtoField_uint16_MASK Integer, String or UInt64 mask of this field. */
998 /* WSLUA_OPTARG_ProtoField_uint16_DESCRIPTION Description of the field. */
999 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1001 /* _WSLUA_CONSTRUCTOR_ ProtoField_uint24 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 24-bit integer. */
1002 /* WSLUA_ARG_ProtoField_uint24_ABBR Abbreviated name of the field (the string used in filters). */
1003 /* WSLUA_OPTARG_ProtoField_uint24_NAME Actual name of the field (the string that appears in the tree). */
1004 /* WSLUA_OPTARG_ProtoField_uint24_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */
1005 /* WSLUA_OPTARG_ProtoField_uint24_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */
1006 /* WSLUA_OPTARG_ProtoField_uint24_MASK Integer, String or UInt64 mask of this field. */
1007 /* WSLUA_OPTARG_ProtoField_uint24_DESCRIPTION Description of the field. */
1008 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1010 /* _WSLUA_CONSTRUCTOR_ ProtoField_uint32 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 32-bit integer. */
1011 /* WSLUA_ARG_ProtoField_uint32_ABBR Abbreviated name of the field (the string used in filters). */
1012 /* WSLUA_OPTARG_ProtoField_uint32_NAME Actual name of the field (the string that appears in the tree). */
1013 /* WSLUA_OPTARG_ProtoField_uint32_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */
1014 /* WSLUA_OPTARG_ProtoField_uint32_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */
1015 /* WSLUA_OPTARG_ProtoField_uint32_MASK Integer, String or UInt64 mask of this field. */
1016 /* WSLUA_OPTARG_ProtoField_uint32_DESCRIPTION Description of the field. */
1017 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1019 /* _WSLUA_CONSTRUCTOR_ ProtoField_uint64 Creates a <<lua_class_ProtoField,`ProtoField`>> of an unsigned 64-bit integer. */
1020 /* WSLUA_ARG_ProtoField_uint64_ABBR Abbreviated name of the field (the string used in filters). */
1021 /* WSLUA_OPTARG_ProtoField_uint64_NAME Actual name of the field (the string that appears in the tree). */
1022 /* WSLUA_OPTARG_ProtoField_uint64_BASE One of `base.DEC`, `base.HEX`, `base.OCT`, `base.DEC_HEX`, `base.HEX_DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */
1023 /* WSLUA_OPTARG_ProtoField_uint64_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing the unit name for the values if base is `base.UNIT_STRING`. */
1024 /* WSLUA_OPTARG_ProtoField_uint64_MASK Integer, String or UInt64 mask of this field. */
1025 /* WSLUA_OPTARG_ProtoField_uint64_DESCRIPTION Description of the field. */
1026 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1028 /* _WSLUA_CONSTRUCTOR_ ProtoField_int8 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 8-bit integer (i.e., a byte). */
1029 /* WSLUA_ARG_ProtoField_int8_ABBR Abbreviated name of the field (the string used in filters). */
1030 /* WSLUA_OPTARG_ProtoField_int8_NAME Actual name of the field (the string that appears in the tree). */
1031 /* WSLUA_OPTARG_ProtoField_int8_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */
1032 /* WSLUA_OPTARG_ProtoField_int8_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
1033 /* WSLUA_OPTARG_ProtoField_int8_MASK Integer, String or UInt64 mask of this field. */
1034 /* WSLUA_OPTARG_ProtoField_int8_DESCRIPTION Description of the field. */
1035 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1037 /* _WSLUA_CONSTRUCTOR_ ProtoField_int16 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 16-bit integer. */
1038 /* WSLUA_ARG_ProtoField_int16_ABBR Abbreviated name of the field (the string used in filters). */
1039 /* WSLUA_OPTARG_ProtoField_int16_NAME Actual name of the field (the string that appears in the tree). */
1040 /* WSLUA_OPTARG_ProtoField_int16_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */
1041 /* WSLUA_OPTARG_ProtoField_int16_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
1042 /* WSLUA_OPTARG_ProtoField_int16_MASK Integer, String or UInt64 mask of this field. */
1043 /* WSLUA_OPTARG_ProtoField_int16_DESCRIPTION Description of the field. */
1044 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1046 /* _WSLUA_CONSTRUCTOR_ ProtoField_int24 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 24-bit integer. */
1047 /* WSLUA_ARG_ProtoField_int24_ABBR Abbreviated name of the field (the string used in filters). */
1048 /* WSLUA_OPTARG_ProtoField_int24_NAME Actual name of the field (the string that appears in the tree). */
1049 /* WSLUA_OPTARG_ProtoField_int24_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */
1050 /* WSLUA_OPTARG_ProtoField_int24_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
1051 /* WSLUA_OPTARG_ProtoField_int24_MASK Integer, String or UInt64 mask of this field. */
1052 /* WSLUA_OPTARG_ProtoField_int24_DESCRIPTION Description of the field. */
1053 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1055 /* _WSLUA_CONSTRUCTOR_ ProtoField_int32 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 32-bit integer. */
1056 /* WSLUA_ARG_ProtoField_int32_ABBR Abbreviated name of the field (the string used in filters). */
1057 /* WSLUA_OPTARG_ProtoField_int32_NAME Actual name of the field (the string that appears in the tree). */
1058 /* WSLUA_OPTARG_ProtoField_int32_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */
1059 /* WSLUA_OPTARG_ProtoField_int32_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
1060 /* WSLUA_OPTARG_ProtoField_int32_MASK Integer, String or UInt64 mask of this field. */
1061 /* WSLUA_OPTARG_ProtoField_int32_DESCRIPTION Description of the field. */
1062 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1064 /* _WSLUA_CONSTRUCTOR_ ProtoField_int64 Creates a <<lua_class_ProtoField,`ProtoField`>> of a signed 64-bit integer. */
1065 /* WSLUA_ARG_ProtoField_int64_ABBR Abbreviated name of the field (the string used in filters). */
1066 /* WSLUA_OPTARG_ProtoField_int64_NAME Actual name of the field (the string that appears in the tree). */
1067 /* WSLUA_OPTARG_ProtoField_int64_BASE One of `base.DEC`, `base.UNIT_STRING`, or `base.RANGE_STRING`. */
1068 /* WSLUA_OPTARG_ProtoField_int64_VALUESTRING A table containing the text that corresponds to the values, or a table containing tables of range string values that correspond to the values ({min, max, "string"}) if the base is `base.RANGE_STRING`, or a table containing unit name for the values if base is `base.UNIT_STRING`. */
1069 /* WSLUA_OPTARG_ProtoField_int64_MASK Integer, String or UInt64 mask of this field. */
1070 /* WSLUA_OPTARG_ProtoField_int64_DESCRIPTION Description of the field. */
1071 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1073 /* _WSLUA_CONSTRUCTOR_ ProtoField_framenum Creates a <<lua_class_ProtoField,`ProtoField`>> for a frame number (for hyperlinks between frames). */
1074 /* WSLUA_ARG_ProtoField_framenum_ABBR Abbreviated name of the field (the string used in filters). */
1075 /* WSLUA_OPTARG_ProtoField_framenum_NAME Actual name of the field (the string that appears in the tree). */
1076 /* WSLUA_OPTARG_ProtoField_framenum_BASE Only `base.NONE` is supported for framenum. */
1077 /* WSLUA_OPTARG_ProtoField_framenum_FRAMETYPE One of `frametype.NONE`, `frametype.REQUEST`, `frametype.RESPONSE`, `frametype.ACK` or `frametype.DUP_ACK`. */
1078 /* WSLUA_OPTARG_ProtoField_framenum_MASK Integer, String or UInt64 mask of this field, which must be 0 for framenum. */
1079 /* WSLUA_OPTARG_ProtoField_framenum_DESCRIPTION Description of the field. */
1080 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1082 PROTOFIELD_INTEGER(char,FT_CHAR
)
1083 PROTOFIELD_INTEGER(uint8
,FT_UINT8
)
1084 PROTOFIELD_INTEGER(uint16
,FT_UINT16
)
1085 PROTOFIELD_INTEGER(uint24
,FT_UINT24
)
1086 PROTOFIELD_INTEGER(uint32
,FT_UINT32
)
1087 PROTOFIELD_INTEGER(uint64
,FT_UINT64
)
1088 PROTOFIELD_INTEGER(int8
,FT_INT8
)
1089 PROTOFIELD_INTEGER(int16
,FT_INT16
)
1090 PROTOFIELD_INTEGER(int24
,FT_INT24
)
1091 PROTOFIELD_INTEGER(int32
,FT_INT32
)
1092 PROTOFIELD_INTEGER(int64
,FT_INT64
)
1093 PROTOFIELD_INTEGER(framenum
,FT_FRAMENUM
)
1095 static int ProtoField_boolean(lua_State
* L
, enum ftenum type
) {
1097 const char* abbr
= check_field_name(L
,1,type
);
1098 const char* name
= luaL_optstring(L
,2,abbr
);
1099 unsigned base
= (unsigned)luaL_optinteger(L
, 3, BASE_NONE
);
1100 true_false_string
* tfs
= NULL
;
1101 uint64_t mask
= get_mask(L
,5,0);
1102 const char* blob
= luaL_optstring(L
,6,NULL
);
1105 luaL_argerror(L
, 2, "cannot be an empty string");
1109 if (mask
== 0x0 && base
!= BASE_NONE
) {
1110 luaL_argerror(L
,3,"Fieldbase (fielddisplay) must be base.NONE"
1111 " if bitmask is zero.");
1115 if (mask
!= 0x0 && (base
< 1 || base
> 64)) {
1116 luaL_argerror(L
,3,"Fieldbase (fielddisplay) must be between 1 and 64"
1117 " if bitmask is non-zero.");
1121 if (lua_gettop(L
) > 3 && !lua_isnil(L
,4)) {
1122 tfs
= true_false_string_from_table(L
,4);
1125 f
= g_new(wslua_field_t
,1);
1129 f
->name
= g_strdup(name
);
1130 f
->abbrev
= g_strdup(abbr
);
1135 lua_pushvalue(L
, 4);
1136 f
->valuestring_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
1138 f
->valuestring_ref
= LUA_NOREF
;
1141 if (blob
&& strcmp(blob
, f
->name
) != 0) {
1142 f
->blob
= g_strdup(blob
);
1147 pushProtoField(L
,f
);
1152 #define PROTOFIELD_BOOL(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_boolean(L,FT); }
1153 /* _WSLUA_CONSTRUCTOR_ ProtoField_bool Creates a <<lua_class_ProtoField,`ProtoField`>> for a boolean true/false value. */
1154 /* WSLUA_ARG_ProtoField_bool_ABBR Abbreviated name of the field (the string used in filters). */
1155 /* WSLUA_OPTARG_ProtoField_bool_NAME Actual name of the field (the string that appears in the tree). */
1156 /* WSLUA_OPTARG_ProtoField_bool_DISPLAY How wide the parent bitfield is (`base.NONE` is used for NULL-value). */
1157 /* WSLUA_OPTARG_ProtoField_bool_VALUESTRING A table containing the text that corresponds to the values. */
1158 /* WSLUA_OPTARG_ProtoField_bool_MASK Integer, String or UInt64 mask of this field. */
1159 /* WSLUA_OPTARG_ProtoField_bool_DESCRIPTION Description of the field. */
1160 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1162 PROTOFIELD_BOOL(bool,FT_BOOLEAN
)
1164 static int ProtoField_time(lua_State
* L
,enum ftenum type
) {
1166 const char* abbr
= check_field_name(L
,1,type
);
1167 const char* name
= luaL_optstring(L
,2,abbr
);
1168 unsigned base
= (unsigned)luaL_optinteger(L
,3,ABSOLUTE_TIME_LOCAL
);
1169 const char* blob
= luaL_optstring(L
,4,NULL
);
1172 luaL_argerror(L
, 2, "cannot be an empty string");
1176 if (type
== FT_ABSOLUTE_TIME
) {
1177 if (!FIELD_DISPLAY_IS_ABSOLUTE_TIME(base
)) {
1178 luaL_argerror(L
, 3, "Base must be either base.LOCAL, base.UTC, or base.DOY_UTC");
1183 f
= g_new(wslua_field_t
,1);
1187 f
->name
= g_strdup(name
);
1188 f
->abbrev
= g_strdup(abbr
);
1192 f
->valuestring_ref
= LUA_NOREF
;
1194 if (blob
&& strcmp(blob
, f
->name
) != 0) {
1195 f
->blob
= g_strdup(blob
);
1200 pushProtoField(L
,f
);
1205 #define PROTOFIELD_TIME(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_time(L,FT); }
1206 /* _WSLUA_CONSTRUCTOR_ ProtoField_absolute_time Creates a <<lua_class_ProtoField,`ProtoField`>> of a time_t structure value. */
1207 /* WSLUA_ARG_ProtoField_absolute_time_ABBR Abbreviated name of the field (the string used in filters). */
1208 /* WSLUA_OPTARG_ProtoField_absolute_time_NAME Actual name of the field (the string that appears in the tree). */
1209 /* WSLUA_OPTARG_ProtoField_absolute_time_BASE One of `base.LOCAL`, `base.UTC` or `base.DOY_UTC`. */
1210 /* WSLUA_OPTARG_ProtoField_absolute_time_DESCRIPTION Description of the field. */
1211 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1213 /* _WSLUA_CONSTRUCTOR_ ProtoField_relative_time Creates a <<lua_class_ProtoField,`ProtoField`>> of a time_t structure value. */
1214 /* WSLUA_ARG_ProtoField_relative_time_ABBR Abbreviated name of the field (the string used in filters). */
1215 /* WSLUA_OPTARG_ProtoField_relative_time_NAME Actual name of the field (the string that appears in the tree). */
1216 /* WSLUA_OPTARG_ProtoField_relative_time_DESCRIPTION Description of the field. */
1217 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1220 PROTOFIELD_TIME(absolute_time
,FT_ABSOLUTE_TIME
)
1222 static int ProtoField_floating(lua_State
* L
,enum ftenum type
) {
1224 const char* abbr
= check_field_name(L
,1,type
);
1225 const char* name
= luaL_optstring(L
,2,abbr
);
1226 unit_name_string
* uns
= NULL
;
1230 luaL_argerror(L
, 2, "cannot be an empty string");
1234 if (lua_istable(L
, 3)) {
1235 uns
= unit_name_string_from_table(L
,3);
1236 blob
= luaL_optstring(L
,4,NULL
);
1238 blob
= luaL_optstring(L
,3,NULL
);
1241 f
= g_new(wslua_field_t
,1);
1245 f
->name
= g_strdup(name
);
1246 f
->abbrev
= g_strdup(abbr
);
1249 f
->base
= BASE_NONE
| BASE_UNIT_STRING
;
1251 lua_pushvalue(L
, 3);
1252 f
->valuestring_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
1254 f
->base
= BASE_NONE
;
1256 f
->valuestring_ref
= LUA_NOREF
;
1259 if (blob
&& strcmp(blob
, f
->name
) != 0) {
1260 f
->blob
= g_strdup(blob
);
1265 pushProtoField(L
,f
);
1270 #define PROTOFIELD_FLOATING(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_floating(L,FT); }
1271 /* _WSLUA_CONSTRUCTOR_ ProtoField_float Creates a <<lua_class_ProtoField,`ProtoField`>> of a floating point number (4 bytes). */
1272 /* WSLUA_ARG_ProtoField_float_ABBR Abbreviated name of the field (the string used in filters). */
1273 /* WSLUA_OPTARG_ProtoField_float_NAME Actual name of the field (the string that appears in the tree). */
1274 /* WSLUA_OPTARG_ProtoField_float_VALUESTRING A table containing unit name for the values. */
1275 /* WSLUA_OPTARG_ProtoField_float_DESCRIPTION Description of the field. */
1276 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1278 /* _WSLUA_CONSTRUCTOR_ ProtoField_double Creates a <<lua_class_ProtoField,`ProtoField`>> of a double-precision floating point (8 bytes). */
1279 /* WSLUA_ARG_ProtoField_double_ABBR Abbreviated name of the field (the string used in filters). */
1280 /* WSLUA_OPTARG_ProtoField_double_NAME Actual name of the field (the string that appears in the tree). */
1281 /* WSLUA_OPTARG_ProtoField_double_VALUESTRING A table containing unit name for the values. */
1282 /* WSLUA_OPTARG_ProtoField_double_DESCRIPTION Description of the field. */
1283 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1285 PROTOFIELD_FLOATING(float,FT_FLOAT
)
1286 PROTOFIELD_FLOATING(double,FT_DOUBLE
)
1288 static int ProtoField_other_display(lua_State
* L
,enum ftenum type
) {
1290 const char* abbr
= check_field_name(L
,1,type
);
1291 const char* name
= luaL_optstring(L
,2,abbr
);
1292 unsigned base
= BASE_NONE
;
1296 luaL_argerror(L
, 2, "cannot be an empty string");
1300 if (lua_isnumber(L
, 3)) {
1301 base
= (unsigned)luaL_optinteger(L
,3,BASE_NONE
);
1302 if (type
== FT_STRING
|| type
== FT_STRINGZ
) {
1303 if (base
!= BASE_NONE
) {
1304 luaL_argerror(L
, 3, "Display must be base.NONE");
1307 } else if (type
== FT_BYTES
|| type
== FT_UINT_BYTES
) {
1308 if (base
!= BASE_NONE
&& (base
< SEP_DOT
|| base
> SEP_SPACE
)) {
1309 luaL_argerror(L
, 3, "Display must be either base.NONE, base.DOT, base.DASH, base.COLON or base.SPACE");
1314 blob
= luaL_optstring(L
,4,NULL
);
1316 blob
= luaL_optstring(L
,3,NULL
);
1319 f
= g_new(wslua_field_t
,1);
1323 f
->name
= g_strdup(name
);
1324 f
->abbrev
= g_strdup(abbr
);
1328 f
->valuestring_ref
= LUA_NOREF
;
1330 if (blob
&& strcmp(blob
, f
->name
) != 0) {
1331 f
->blob
= g_strdup(blob
);
1336 pushProtoField(L
,f
);
1341 #define PROTOFIELD_OTHER_DISPLAY(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_other_display(L,FT); }
1342 /* _WSLUA_CONSTRUCTOR_ ProtoField_string Creates a <<lua_class_ProtoField,`ProtoField`>> of a string value. */
1343 /* WSLUA_ARG_ProtoField_string_ABBR Abbreviated name of the field (the string used in filters). */
1344 /* WSLUA_OPTARG_ProtoField_string_NAME Actual name of the field (the string that appears in the tree). */
1345 /* WSLUA_OPTARG_ProtoField_string_DISPLAY One of `base.ASCII` or `base.UNICODE`. */
1346 /* WSLUA_OPTARG_ProtoField_string_DESCRIPTION Description of the field. */
1347 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1349 /* _WSLUA_CONSTRUCTOR_ ProtoField_stringz Creates a <<lua_class_ProtoField,`ProtoField`>> of a zero-terminated string value. */
1350 /* WSLUA_ARG_ProtoField_stringz_ABBR Abbreviated name of the field (the string used in filters). */
1351 /* WSLUA_OPTARG_ProtoField_stringz_NAME Actual name of the field (the string that appears in the tree). */
1352 /* WSLUA_OPTARG_ProtoField_stringz_DISPLAY One of `base.ASCII` or `base.UNICODE`. */
1353 /* WSLUA_OPTARG_ProtoField_stringz_DESCRIPTION Description of the field. */
1354 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1356 /* _WSLUA_CONSTRUCTOR_ ProtoField_bytes Creates a <<lua_class_ProtoField,`ProtoField`>> for an arbitrary number of bytes. */
1357 /* WSLUA_ARG_ProtoField_bytes_ABBR Abbreviated name of the field (the string used in filters). */
1358 /* WSLUA_OPTARG_ProtoField_bytes_NAME Actual name of the field (the string that appears in the tree). */
1359 /* WSLUA_OPTARG_ProtoField_bytes_DISPLAY One of `base.NONE`, `base.DOT`, `base.DASH`, `base.COLON` or `base.SPACE`. */
1360 /* WSLUA_OPTARG_ProtoField_bytes_DESCRIPTION Description of the field. */
1361 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1363 /* _WSLUA_CONSTRUCTOR_ ProtoField_ubytes Creates a <<lua_class_ProtoField,`ProtoField`>> for an arbitrary number of unsigned bytes. */
1364 /* WSLUA_ARG_ProtoField_ubytes_ABBR Abbreviated name of the field (the string used in filters). */
1365 /* WSLUA_OPTARG_ProtoField_ubytes_NAME Actual name of the field (the string that appears in the tree). */
1366 /* WSLUA_OPTARG_ProtoField_ubytes_DISPLAY One of `base.NONE`, `base.DOT`, `base.DASH`, `base.COLON` or `base.SPACE`. */
1367 /* WSLUA_OPTARG_ProtoField_ubytes_DESCRIPTION Description of the field. */
1368 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1371 PROTOFIELD_OTHER_DISPLAY(string
,FT_STRING
)
1372 PROTOFIELD_OTHER_DISPLAY(stringz
,FT_STRINGZ
)
1373 PROTOFIELD_OTHER_DISPLAY(bytes
,FT_BYTES
)
1374 PROTOFIELD_OTHER_DISPLAY(ubytes
,FT_UINT_BYTES
)
1376 static int ProtoField_other(lua_State
* L
,enum ftenum type
) {
1378 const char* abbr
= check_field_name(L
,1,type
);
1379 const char* name
= luaL_optstring(L
,2,abbr
);
1380 const char* blob
= luaL_optstring(L
,3,NULL
);
1383 luaL_argerror(L
, 2, "cannot be an empty string");
1387 f
= g_new(wslua_field_t
,1);
1391 f
->name
= g_strdup(name
);
1392 f
->abbrev
= g_strdup(abbr
);
1394 f
->base
= BASE_NONE
;
1396 f
->valuestring_ref
= LUA_NOREF
;
1398 if (blob
&& strcmp(blob
, f
->name
) != 0) {
1399 f
->blob
= g_strdup(blob
);
1404 pushProtoField(L
,f
);
1409 #define PROTOFIELD_OTHER(lower,FT) static int ProtoField_##lower(lua_State* L) { return ProtoField_other(L,FT); }
1410 /* _WSLUA_CONSTRUCTOR_ ProtoField_none Creates a <<lua_class_ProtoField,`ProtoField`>> of an unstructured type. */
1411 /* WSLUA_ARG_ProtoField_none_ABBR Abbreviated name of the field (the string used in filters). */
1412 /* WSLUA_OPTARG_ProtoField_none_NAME Actual name of the field (the string that appears in the tree). */
1413 /* WSLUA_OPTARG_ProtoField_none_DESCRIPTION Description of the field. */
1414 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1416 /* _WSLUA_CONSTRUCTOR_ ProtoField_ipv4 Creates a <<lua_class_ProtoField,`ProtoField`>> of an IPv4 address (4 bytes). */
1417 /* WSLUA_ARG_ProtoField_ipv4_ABBR Abbreviated name of the field (the string used in filters). */
1418 /* WSLUA_OPTARG_ProtoField_ipv4_NAME Actual name of the field (the string that appears in the tree). */
1419 /* WSLUA_OPTARG_ProtoField_ipv4_DESCRIPTION Description of the field. */
1420 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1422 /* _WSLUA_CONSTRUCTOR_ ProtoField_ipv6 Creates a <<lua_class_ProtoField,`ProtoField`>> of an IPv6 address (16 bytes). */
1423 /* WSLUA_ARG_ProtoField_ipv6_ABBR Abbreviated name of the field (the string used in filters). */
1424 /* WSLUA_OPTARG_ProtoField_ipv6_NAME Actual name of the field (the string that appears in the tree). */
1425 /* WSLUA_OPTARG_ProtoField_ipv6_DESCRIPTION Description of the field. */
1426 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1428 /* _WSLUA_CONSTRUCTOR_ ProtoField_ether Creates a <<lua_class_ProtoField,`ProtoField`>> of an Ethernet address (6 bytes). */
1429 /* WSLUA_ARG_ProtoField_ether_ABBR Abbreviated name of the field (the string used in filters). */
1430 /* WSLUA_OPTARG_ProtoField_ether_NAME Actual name of the field (the string that appears in the tree). */
1431 /* WSLUA_OPTARG_ProtoField_ether_DESCRIPTION Description of the field. */
1432 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1434 /* _WSLUA_CONSTRUCTOR_ ProtoField_guid Creates a <<lua_class_ProtoField,`ProtoField`>> for a Globally Unique IDentifier (GUID). */
1435 /* WSLUA_ARG_ProtoField_guid_ABBR Abbreviated name of the field (the string used in filters). */
1436 /* WSLUA_OPTARG_ProtoField_guid_NAME Actual name of the field (the string that appears in the tree). */
1437 /* WSLUA_OPTARG_ProtoField_guid_DESCRIPTION Description of the field. */
1438 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1440 /* _WSLUA_CONSTRUCTOR_ ProtoField_oid Creates a <<lua_class_ProtoField,`ProtoField`>> for an ASN.1 Organizational IDentified (OID). */
1441 /* WSLUA_ARG_ProtoField_oid_ABBR Abbreviated name of the field (the string used in filters). */
1442 /* WSLUA_OPTARG_ProtoField_oid_NAME Actual name of the field (the string that appears in the tree). */
1443 /* WSLUA_OPTARG_ProtoField_oid_DESCRIPTION Description of the field. */
1444 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1446 /* _WSLUA_CONSTRUCTOR_ ProtoField_protocol Creates a <<lua_class_ProtoField,`ProtoField`>> for a sub-protocol. */
1447 /* WSLUA_ARG_ProtoField_protocol_ABBR Abbreviated name of the field (the string used in filters). */
1448 /* WSLUA_OPTARG_ProtoField_protocol_NAME Actual name of the field (the string that appears in the tree). */
1449 /* WSLUA_OPTARG_ProtoField_protocol_DESCRIPTION Description of the field. */
1450 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1452 /* _WSLUA_CONSTRUCTOR_ ProtoField_rel_oid Creates a <<lua_class_ProtoField,`ProtoField`>> for an ASN.1 Relative-OID. */
1453 /* WSLUA_ARG_ProtoField_rel_oid_ABBR Abbreviated name of the field (the string used in filters). */
1454 /* WSLUA_OPTARG_ProtoField_rel_oid_NAME Actual name of the field (the string that appears in the tree). */
1455 /* WSLUA_OPTARG_ProtoField_rel_oid_DESCRIPTION Description of the field. */
1456 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1458 /* _WSLUA_CONSTRUCTOR_ ProtoField_systemid Creates a <<lua_class_ProtoField,`ProtoField`>> for an OSI System ID. */
1459 /* WSLUA_ARG_ProtoField_systemid_ABBR Abbreviated name of the field (the string used in filters). */
1460 /* WSLUA_OPTARG_ProtoField_systemid_NAME Actual name of the field (the string that appears in the tree). */
1461 /* WSLUA_OPTARG_ProtoField_systemid_DESCRIPTION Description of the field. */
1462 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1464 /* _WSLUA_CONSTRUCTOR_ ProtoField_eui64 Creates a <<lua_class_ProtoField,`ProtoField`>> for an EUI64. */
1465 /* WSLUA_ARG_ProtoField_eui64_ABBR Abbreviated name of the field (the string used in filters). */
1466 /* WSLUA_OPTARG_ProtoField_eui64_NAME Actual name of the field (the string that appears in the tree). */
1467 /* WSLUA_OPTARG_ProtoField_eui64_DESCRIPTION Description of the field. */
1468 /* _WSLUA_RETURNS_ A <<lua_class_ProtoField,`ProtoField`>> object to be added to a table set to the <<lua_class_attrib_proto_fields,`Proto.fields`>> attribute. */
1470 PROTOFIELD_OTHER(none
,FT_NONE
)
1471 PROTOFIELD_OTHER(ipv4
,FT_IPv4
)
1472 PROTOFIELD_OTHER(ipv6
,FT_IPv6
)
1473 PROTOFIELD_OTHER(ipx
,FT_IPXNET
)
1474 PROTOFIELD_OTHER(ether
,FT_ETHER
)
1475 PROTOFIELD_OTHER(relative_time
,FT_RELATIVE_TIME
)
1476 PROTOFIELD_OTHER(guid
,FT_GUID
)
1477 PROTOFIELD_OTHER(oid
,FT_OID
)
1478 PROTOFIELD_OTHER(protocol
,FT_PROTOCOL
)
1479 PROTOFIELD_OTHER(rel_oid
,FT_REL_OID
)
1480 PROTOFIELD_OTHER(systemid
,FT_SYSTEM_ID
)
1481 PROTOFIELD_OTHER(eui64
,FT_EUI64
)
1483 /* WSLUA_ATTRIBUTE ProtoField_type RO The type of the field.
1487 WSLUA_ATTRIBUTE_INTEGER_GETTER(ProtoField
,type
);
1489 /* WSLUA_ATTRIBUTE ProtoField_abbr RO The abbreviated name of the field.
1493 WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(ProtoField
,abbr
,abbrev
);
1495 /* WSLUA_ATTRIBUTE ProtoField_name RO The actual name of the field.
1499 WSLUA_ATTRIBUTE_STRING_GETTER(ProtoField
,name
);
1501 /* WSLUA_ATTRIBUTE ProtoField_base RO The base of the field.
1505 WSLUA_ATTRIBUTE_INTEGER_GETTER(ProtoField
,base
);
1507 /* WSLUA_ATTRIBUTE ProtoField_valuestring RO The valuestring of the field.
1511 WSLUA_METAMETHOD
ProtoField_get_valuestring(lua_State
* L
) {
1512 ProtoField f
= checkProtoField(L
,1);
1513 if (f
->valuestring_ref
!= LUA_NOREF
) {
1514 lua_rawgeti(L
, LUA_REGISTRYINDEX
, f
->valuestring_ref
);
1521 /* WSLUA_ATTRIBUTE ProtoField_mask RO The mask of the field.
1525 WSLUA_ATTRIBUTE_INTEGER_GETTER(ProtoField
,mask
);
1527 /* WSLUA_ATTRIBUTE ProtoField_description RO The description of this field.
1531 WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(ProtoField
,description
,blob
);
1533 WSLUA_METAMETHOD
ProtoField__tostring(lua_State
* L
) {
1534 /* Returns a string with info about a protofield (for debugging purposes). */
1535 ProtoField f
= checkProtoField(L
,1);
1536 char* s
= ws_strdup_printf("ProtoField(%i): %s %s %s %s %p %.16" PRIu64
"x %s",
1537 f
->hfid
,f
->name
,f
->abbrev
,
1538 ftenum_to_string(f
->type
),
1539 base_to_string(f
->base
),
1540 f
->vs
,f
->mask
,f
->blob
);
1541 lua_pushstring(L
,s
);
1546 static int ProtoField__gc(lua_State
* L
) {
1547 ProtoField f
= toProtoField(L
,1);
1550 * Initialized to -2 in ProtoField_new,
1551 * changed to -1 in Proto_commit and subsequently replaced by
1552 * an allocated number in proto_register_field_array.
1553 * Reset to -2 again in wslua_deregister_protocols.
1555 if (f
->hfid
!= -2) {
1556 /* Only free unregistered and deregistered ProtoField */
1560 /* Note: name, abbrev, blob and vs will be NULL after Proto deregistration. */
1564 proto_free_field_strings(f
->type
, f
->base
, f
->vs
);
1565 if (f
->valuestring_ref
!= LUA_NOREF
) {
1566 luaL_unref(L
, LUA_REGISTRYINDEX
, f
->valuestring_ref
);
1573 WSLUA_METHODS ProtoField_methods
[] = {
1574 WSLUA_CLASS_FNREG(ProtoField
,new),
1575 WSLUA_CLASS_FNREG(ProtoField
,none
),
1576 WSLUA_CLASS_FNREG(ProtoField
,char),
1577 WSLUA_CLASS_FNREG(ProtoField
,uint8
),
1578 WSLUA_CLASS_FNREG(ProtoField
,uint16
),
1579 WSLUA_CLASS_FNREG(ProtoField
,uint24
),
1580 WSLUA_CLASS_FNREG(ProtoField
,uint32
),
1581 WSLUA_CLASS_FNREG(ProtoField
,uint64
),
1582 WSLUA_CLASS_FNREG(ProtoField
,int8
),
1583 WSLUA_CLASS_FNREG(ProtoField
,int16
),
1584 WSLUA_CLASS_FNREG(ProtoField
,int24
),
1585 WSLUA_CLASS_FNREG(ProtoField
,int32
),
1586 WSLUA_CLASS_FNREG(ProtoField
,int64
),
1587 WSLUA_CLASS_FNREG(ProtoField
,framenum
),
1588 WSLUA_CLASS_FNREG(ProtoField
,ipv4
),
1589 WSLUA_CLASS_FNREG(ProtoField
,ipv6
),
1590 WSLUA_CLASS_FNREG(ProtoField
,ipx
),
1591 WSLUA_CLASS_FNREG(ProtoField
,ether
),
1592 WSLUA_CLASS_FNREG(ProtoField
,bool),
1593 WSLUA_CLASS_FNREG(ProtoField
,float),
1594 WSLUA_CLASS_FNREG(ProtoField
,double),
1595 WSLUA_CLASS_FNREG(ProtoField
,absolute_time
),
1596 WSLUA_CLASS_FNREG(ProtoField
,relative_time
),
1597 WSLUA_CLASS_FNREG(ProtoField
,string
),
1598 WSLUA_CLASS_FNREG(ProtoField
,stringz
),
1599 WSLUA_CLASS_FNREG(ProtoField
,bytes
),
1600 WSLUA_CLASS_FNREG(ProtoField
,ubytes
),
1601 WSLUA_CLASS_FNREG(ProtoField
,guid
),
1602 WSLUA_CLASS_FNREG(ProtoField
,oid
),
1603 WSLUA_CLASS_FNREG(ProtoField
,protocol
),
1604 WSLUA_CLASS_FNREG(ProtoField
,rel_oid
),
1605 WSLUA_CLASS_FNREG(ProtoField
,systemid
),
1606 WSLUA_CLASS_FNREG(ProtoField
,eui64
),
1610 /* This table is ultimately registered as a sub-table of the class' metatable,
1611 * and if __index/__newindex is invoked then it calls the appropriate function
1612 * from this table for getting/setting the members.
1614 WSLUA_ATTRIBUTES ProtoField_attributes
[] = {
1615 WSLUA_ATTRIBUTE_ROREG(ProtoField
,type
),
1616 WSLUA_ATTRIBUTE_ROREG(ProtoField
,abbr
),
1617 WSLUA_ATTRIBUTE_ROREG(ProtoField
,name
),
1618 WSLUA_ATTRIBUTE_ROREG(ProtoField
,base
),
1619 WSLUA_ATTRIBUTE_ROREG(ProtoField
,valuestring
),
1620 WSLUA_ATTRIBUTE_ROREG(ProtoField
,mask
),
1621 WSLUA_ATTRIBUTE_ROREG(ProtoField
,description
),
1622 { NULL
, NULL
, NULL
}
1625 WSLUA_META ProtoField_meta
[] = {
1626 WSLUA_CLASS_MTREG(ProtoField
,tostring
),
1630 int ProtoField_register(lua_State
* L
) {
1631 WSLUA_REGISTER_CLASS_WITH_ATTRS(ProtoField
);
1637 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1642 * indent-tabs-mode: nil
1645 * vi: set shiftwidth=4 tabstop=8 expandtab:
1646 * :indentSize=4:tabSize=8:noTabs=true: