Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / wslua / wslua_proto_expert.c
blob0cd2f8adbe8ef15d5ffb2a0b5b762196c0d1adc1
1 /*
2 * wslua_proto_expert.c
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
18 #include "config.h"
20 #include "wslua.h"
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`,
42 `expert.group.DEBUG`,
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);
64 if (!abbr[0]) {
65 luaL_argerror(L, WSLUA_ARG_ProtoExpert_new_ABBR, "Empty field name abbrev");
66 return 0;
69 if (proto_check_field_name(abbr)) {
70 luaL_argerror(L, WSLUA_ARG_ProtoExpert_new_ABBR, "Invalid char in abbrev");
71 return 0;
74 if (proto_registrar_get_byname(abbr)) {
75 luaL_argerror(L, WSLUA_ARG_ProtoExpert_new_ABBR, "This abbrev already exists");
76 return 0;
79 if (!text[0]) {
80 luaL_argerror(L, WSLUA_ARG_ProtoExpert_new_TEXT, "Empty text");
81 return 0;
84 switch (group) {
85 case PI_CHECKSUM:
86 case PI_SEQUENCE:
87 case PI_RESPONSE_CODE:
88 case PI_REQUEST_CODE:
89 case PI_UNDECODED:
90 case PI_REASSEMBLE:
91 case PI_MALFORMED:
92 case PI_DEBUG:
93 case PI_PROTOCOL:
94 case PI_SECURITY:
95 case PI_COMMENTS_GROUP:
96 case PI_DECRYPTION:
97 case PI_ASSUMPTION:
98 case PI_DEPRECATED:
99 case PI_RECEIVE:
100 case PI_INTERFACE:
101 case PI_DISSECTOR_BUG:
102 break;
103 default:
104 luaL_argerror(L, WSLUA_ARG_ProtoExpert_new_GROUP, "Group must be one of expert.group.*");
105 return 0;
108 switch (severity) {
109 case PI_COMMENT:
110 case PI_CHAT:
111 case PI_NOTE:
112 case PI_WARN:
113 case PI_ERROR:
114 break;
115 default:
116 luaL_argerror(L, WSLUA_ARG_ProtoExpert_new_SEVERITY, "Severity must be one of expert.severity.*");
117 return 0;
120 pe = g_new(wslua_expert_field_t,1);
122 pe->ids.ei = EI_INIT_EI;
123 pe->ids.hf = -2;
124 pe->abbrev = g_strdup(abbr);
125 pe->text = g_strdup(text);
126 pe->group = group;
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);
138 if (!pe) {
139 lua_pushstring(L,"ProtoExpert pointer is NULL!");
140 } else {
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);
144 return 1;
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 */
158 return 0;
161 g_free((char *)pe->abbrev);
162 g_free((char *)pe->text);
163 g_free(pe);
165 return 0;
168 WSLUA_METHODS ProtoExpert_methods[] = {
169 WSLUA_CLASS_FNREG(ProtoExpert,new),
170 { NULL, NULL }
173 WSLUA_META ProtoExpert_meta[] = {
174 WSLUA_CLASS_MTREG(ProtoExpert,tostring),
175 { NULL, NULL }
178 int ProtoExpert_register(lua_State* L) {
179 WSLUA_REGISTER_CLASS(ProtoExpert);
180 return 0;
185 * Editor modelines - https://www.wireshark.org/tools/modelines.html
187 * Local variables:
188 * c-basic-offset: 4
189 * tab-width: 8
190 * indent-tabs-mode: nil
191 * End:
193 * vi: set shiftwidth=4 tabstop=8 expandtab:
194 * :indentSize=4:tabSize=8:noTabs=true: