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
23 /* WSLUA_CONTINUE_MODULE Proto */
26 WSLUA_CLASS_DEFINE(ProtoExpert
,FAIL_ON_NULL("null ProtoExpert"));
27 /* A Protocol expert info field, to be used when adding items to the dissection tree. */
29 WSLUA_CONSTRUCTOR
ProtoExpert_new(lua_State
* L
) {
30 /* Creates a new `ProtoExpert` object to be used for a protocol's expert information notices. */
31 #define WSLUA_ARG_ProtoExpert_new_ABBR 1 /* Filter name of the expert info field (the string that
32 is used in filters). */
33 #define WSLUA_ARG_ProtoExpert_new_TEXT 2 /* The default text of the expert field. */
34 #define WSLUA_ARG_ProtoExpert_new_GROUP 3 /* Expert group type: one of:
35 `expert.group.CHECKSUM`,
36 `expert.group.SEQUENCE`,
37 `expert.group.RESPONSE_CODE`,
38 `expert.group.REQUEST_CODE`,
39 `expert.group.UNDECODED`,
40 `expert.group.REASSEMBLE`,
41 `expert.group.MALFORMED`,
43 `expert.group.PROTOCOL`,
44 `expert.group.SECURITY`,
45 `expert.group.COMMENTS_GROUP`,
46 `expert.group.DECRYPTION`,
47 `expert.group.ASSUMPTION`,
48 `expert.group.DEPRECATED`,
49 `expert.group.RECEIVE`,
50 or `expert.group.INTERFACE`. */
51 #define WSLUA_ARG_ProtoExpert_new_SEVERITY 4 /* Expert severity type: one of:
52 `expert.severity.COMMENT`,
53 `expert.severity.CHAT`,
54 `expert.severity.NOTE`,
55 `expert.severity.WARN`,
56 or `expert.severity.ERROR`. */
58 ProtoExpert pe
= NULL
;
59 const char* abbr
= wslua_checkstring_only(L
,WSLUA_ARG_ProtoExpert_new_ABBR
);
60 const char* text
= wslua_checkstring_only(L
,WSLUA_ARG_ProtoExpert_new_TEXT
);
61 int group
= (int)luaL_checkinteger(L
, WSLUA_ARG_ProtoExpert_new_GROUP
);
62 int severity
= (int)luaL_checkinteger(L
, WSLUA_ARG_ProtoExpert_new_SEVERITY
);
65 luaL_argerror(L
, WSLUA_ARG_ProtoExpert_new_ABBR
, "Empty field name abbrev");
69 if (proto_check_field_name(abbr
)) {
70 luaL_argerror(L
, WSLUA_ARG_ProtoExpert_new_ABBR
, "Invalid char in abbrev");
74 if (proto_registrar_get_byname(abbr
)) {
75 luaL_argerror(L
, WSLUA_ARG_ProtoExpert_new_ABBR
, "This abbrev already exists");
80 luaL_argerror(L
, WSLUA_ARG_ProtoExpert_new_TEXT
, "Empty text");
87 case PI_RESPONSE_CODE
:
95 case PI_COMMENTS_GROUP
:
101 case PI_DISSECTOR_BUG
:
104 luaL_argerror(L
, WSLUA_ARG_ProtoExpert_new_GROUP
, "Group must be one of expert.group.*");
116 luaL_argerror(L
, WSLUA_ARG_ProtoExpert_new_SEVERITY
, "Severity must be one of expert.severity.*");
120 pe
= g_new(wslua_expert_field_t
,1);
122 pe
->ids
.ei
= EI_INIT_EI
;
124 pe
->abbrev
= g_strdup(abbr
);
125 pe
->text
= g_strdup(text
);
127 pe
->severity
= severity
;
129 pushProtoExpert(L
,pe
);
131 WSLUA_RETURN(1); /* The newly created `ProtoExpert` object. */
134 WSLUA_METAMETHOD
ProtoExpert__tostring(lua_State
* L
) {
135 /* Returns a string with debugging information about a `ProtoExpert` object. */
136 ProtoExpert pe
= toProtoExpert(L
,1);
139 lua_pushstring(L
,"ProtoExpert pointer is NULL!");
141 lua_pushfstring(L
, "ProtoExpert: ei=%d, hf=%d, abbr=%s, text=%s, group=%d, severity=%d",
142 pe
->ids
.ei
, pe
->ids
.hf
, pe
->abbrev
, pe
->text
, pe
->group
, pe
->severity
);
147 static int ProtoExpert__gc(lua_State
* L
) {
148 ProtoExpert pe
= toProtoExpert(L
,1);
151 * Initialized to -2 in ProtoExpert_new,
152 * changed to -1 in Proto_commit and subsequently replaced by
153 * an allocated number in proto_register_field_array.
154 * Reset to -2 again in wslua_deregister_protocols.
156 if (pe
->ids
.hf
!= -2) {
157 /* Only free unregistered and deregistered ProtoExpert */
161 g_free((char *)pe
->abbrev
);
162 g_free((char *)pe
->text
);
168 WSLUA_METHODS ProtoExpert_methods
[] = {
169 WSLUA_CLASS_FNREG(ProtoExpert
,new),
173 WSLUA_META ProtoExpert_meta
[] = {
174 WSLUA_CLASS_MTREG(ProtoExpert
,tostring
),
178 int ProtoExpert_register(lua_State
* L
) {
179 WSLUA_REGISTER_CLASS(ProtoExpert
);
185 * Editor modelines - https://www.wireshark.org/tools/modelines.html
190 * indent-tabs-mode: nil
193 * vi: set shiftwidth=4 tabstop=8 expandtab:
194 * :indentSize=4:tabSize=8:noTabs=true: