• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22550237931

01 Mar 2026 06:56PM UTC coverage: 64.812% (-8.9%) from 73.687%
22550237931

Pull #14920

github

web-flow
Merge e05854a6d into 90823fa90
Pull Request #14920: draft: rust based configuration file parser and loader - v4

561 of 789 new or added lines in 4 files covered. (71.1%)

23225 existing lines in 498 files now uncovered.

131605 of 203055 relevant lines covered (64.81%)

2328818.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/util-lua-dataset.c
1
/* Copyright (C) 2025 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
/**
19
 * \file
20
 *
21
 * Dataset API for Lua.
22
 *
23
 * local dataset = require("suricata.dataset")
24
 */
25

26
#include "suricata-common.h"
27

28
#include "util-lua-dataset.h"
29

30
#include "app-layer-protos.h" /* Required by util-lua-common. */
31
#include "util-lua-common.h"
32
#include "util-lua.h"
33
#include "util-debug.h"
34

35
#include "datasets.h"
36

37
struct LuaDataset {
38
    Dataset *set;
39
};
40

41
static int LuaDatasetGC(lua_State *luastate)
UNCOV
42
{
×
UNCOV
43
    SCLogDebug("gc:start");
×
UNCOV
44
    struct LuaDataset *s = (struct LuaDataset *)lua_touserdata(luastate, 1);
×
UNCOV
45
    if (s != NULL && s->set != NULL) {
×
UNCOV
46
        SCLogDebug("deref %s", s->set->name);
×
UNCOV
47
        s->set = NULL;
×
UNCOV
48
    }
×
UNCOV
49
    SCLogDebug("gc:done");
×
UNCOV
50
    return 0;
×
UNCOV
51
}
×
52

53
static int LuaDatasetGetRef(lua_State *luastate)
UNCOV
54
{
×
UNCOV
55
    SCLogDebug("get");
×
UNCOV
56
    struct LuaDataset *s = (struct LuaDataset *)lua_touserdata(luastate, 1);
×
UNCOV
57
    if (s == NULL) {
×
58
        LUA_ERROR("dataset is not initialized");
×
59
    }
×
60

UNCOV
61
    const char *name = lua_tostring(luastate, 2);
×
UNCOV
62
    if (name == NULL) {
×
63
        LUA_ERROR("null string");
×
64
    }
×
65

UNCOV
66
    Dataset *dataset = DatasetFind(name, DATASET_TYPE_STRING);
×
UNCOV
67
    if (dataset == NULL) {
×
68
        LUA_ERROR("dataset not found");
×
69
    }
×
UNCOV
70
    s->set = dataset;
×
UNCOV
71
    return 0;
×
UNCOV
72
}
×
73

74
static int LuaDatasetAdd(lua_State *luastate)
UNCOV
75
{
×
UNCOV
76
    SCLogDebug("add:start");
×
UNCOV
77
    struct LuaDataset *s = (struct LuaDataset *)lua_touserdata(luastate, 1);
×
UNCOV
78
    if (s == NULL) {
×
79
        LUA_ERROR("dataset is not initialized");
×
80
    }
×
UNCOV
81
    if (!lua_isstring(luastate, 2)) {
×
82
        LUA_ERROR("1st arg is not a string");
×
83
    }
×
UNCOV
84
    if (!lua_isnumber(luastate, 3)) {
×
85
        LUA_ERROR("2nd arg is not a number");
×
86
    }
×
87

UNCOV
88
    const uint8_t *str = (const uint8_t *)lua_tostring(luastate, 2);
×
UNCOV
89
    if (str == NULL) {
×
90
        LUA_ERROR("1st arg is not null string");
×
91
    }
×
92

UNCOV
93
    uint32_t str_len = lua_tonumber(luastate, 3);
×
94

UNCOV
95
    int r = SCDatasetAdd(s->set, (const uint8_t *)str, str_len);
×
96
    /* return value through luastate, as a luanumber */
UNCOV
97
    lua_pushnumber(luastate, (lua_Number)r);
×
UNCOV
98
    SCLogDebug("add:end");
×
UNCOV
99
    return 1;
×
UNCOV
100
}
×
101

102
static int LuaDatasetNew(lua_State *luastate)
UNCOV
103
{
×
UNCOV
104
    SCLogDebug("new:start");
×
UNCOV
105
    struct LuaDataset *s = (struct LuaDataset *)lua_newuserdata(luastate, sizeof(*s));
×
UNCOV
106
    if (s == NULL) {
×
107
        LUA_ERROR("failed to get userdata");
×
108
    }
×
UNCOV
109
    luaL_getmetatable(luastate, "dataset::metatable");
×
UNCOV
110
    lua_setmetatable(luastate, -2);
×
UNCOV
111
    SCLogDebug("new:done");
×
UNCOV
112
    return 1;
×
UNCOV
113
}
×
114

115
// clang-format off
116
static const luaL_Reg datasetlib[] = {
117
    { "new", LuaDatasetNew },
118
    { "get", LuaDatasetGetRef },
119
    { "add", LuaDatasetAdd },
120
    { "__gc", LuaDatasetGC },
121
    { NULL, NULL }
122
};
123
// clang-format on
124

125
int LuaLoadDatasetLib(lua_State *luastate)
UNCOV
126
{
×
UNCOV
127
    luaL_newmetatable(luastate, "dataset::metatable");
×
UNCOV
128
    lua_pushvalue(luastate, -1);
×
UNCOV
129
    lua_setfield(luastate, -2, "__index");
×
UNCOV
130
    luaL_setfuncs(luastate, datasetlib, 0);
×
UNCOV
131
    luaL_newlib(luastate, datasetlib);
×
132

UNCOV
133
    return 1;
×
UNCOV
134
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc