/usr/share/libprelude/swig/lua/libpreludecpp-lua.i is in libprelude-dev 4.1.0-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | /*****
*
* Copyright (C) 2005-2017 CS-SI. All Rights Reserved.
* Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com>
*
* This file is part of the Prelude library.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****/
%begin %{
#include "config.h"
#include "glthread/thread.h"
%}
/*
* Lua overloading fixes
*/
%ignore IDMEFCriteria(std::string const &);
%ignore IDMEFValue(int8_t);
%ignore IDMEFValue(uint8_t);
%ignore IDMEFValue(int16_t);
%ignore IDMEFValue(uint16_t);
%ignore IDMEFValue(int32_t);
%ignore IDMEFValue(uint32_t);
%ignore IDMEFValue(int64_t);
%ignore IDMEFValue(uint64_t);
%ignore IDMEFValue(float);
%ignore IDMEFValue(std::string);
%ignore Set(Prelude::IDMEF &, int8_t);
%ignore Set(Prelude::IDMEF &, uint8_t);
%ignore Set(Prelude::IDMEF &, int16_t);
%ignore Set(Prelude::IDMEF &, uint16_t);
%ignore Set(Prelude::IDMEF &, int32_t);
%ignore Set(Prelude::IDMEF &, uint32_t);
%ignore Set(Prelude::IDMEF &, int64_t);
%ignore Set(Prelude::IDMEF &, uint64_t);
%ignore Set(Prelude::IDMEF &, float);
%ignore Set(Prelude::IDMEF &, std::string);
%ignore Set(char const *, int8_t);
%ignore Set(char const *, uint8_t);
%ignore Set(char const *, int16_t);
%ignore Set(char const *, uint16_t);
%ignore Set(char const *, int32_t);
%ignore Set(char const *, uint32_t);
%ignore Set(char const *, int64_t);
%ignore Set(char const *, uint64_t);
%ignore Set(char const *, float);
%ignore Set(char const *, std::string);
/*
* Conversion not allowed
*/
%ignore *::operator =;
%ignore *::operator int() const;
%ignore *::operator long() const;
%ignore *::operator int32_t() const;
%ignore *::operator uint32_t() const;
%ignore *::operator int64_t() const;
%ignore *::operator uint64_t() const;
%ignore *::operator float() const;
%ignore *::operator double() const;
%ignore *::operator Prelude::IDMEFTime() const;
%ignore operator <<;
%ignore operator >>;
%rename (__str__) *::operator const char *() const;
%begin %{
#define TARGET_LANGUAGE_SELF void *
#define TARGET_LANGUAGE_OUTPUT_TYPE int *
%}
%header {
char *my_strdup(const char *in)
{
char *out = new char[strlen(in) + 1];
strcpy(out, in);
return out;
}
}
%ignore Prelude::IDMEFCriteria::operator const std::string() const;
%newobject Prelude::IDMEFCriteria::__str__;
%extend Prelude::IDMEFCriteria {
char *__str__() { return my_strdup(self->toString().c_str()); }
}
%ignore Prelude::IDMEFTime::operator const std::string() const;
%newobject Prelude::IDMEFTime::__str__;
%extend Prelude::IDMEFTime {
char *__str__() { return my_strdup(self->toString().c_str()); }
}
%ignore Prelude::IDMEF::operator const std::string() const;
%newobject Prelude::IDMEF::__str__;
%extend Prelude::IDMEF {
char *__str__() { return my_strdup(self->toString().c_str()); }
}
%header %{
int integer2lua(lua_State *L, lua_Number result)
{
lua_pushnumber(L, (lua_Number) result);
return 0;
}
int str2lua(lua_State *L, const char *str)
{
lua_pushstring(L, str);
return 0;
}
int strsize2lua(lua_State *L, const char *str, size_t len)
{
lua_pushlstring(L, str, len);
return 0;
}
int _SWIG_Prelude_NewPointerObj(lua_State *L, void *obj, swig_type_info *objtype, int val)
{
SWIG_NewPointerObj(L, obj, objtype, val);
return 0;
}
%}
/* tell squid not to cast void * value */
%typemap(in) void *nocast_p {
FILE **pf;
pf = (FILE **)lua_touserdata(L, $input);
if (pf == NULL) {
lua_pushstring(L,"Argument is not a file");
SWIG_fail;
}
$1 = *pf;
}
%fragment("TransitionFunc", "header") {
static int __prelude_log_func;
static lua_State *__lua_state = NULL;
static gl_thread_t __initial_thread;
static void _cb_lua_log(int level, const char *str)
{
if ( (gl_thread_t) gl_thread_self() != __initial_thread )
return;
lua_rawgeti(__lua_state, LUA_REGISTRYINDEX, __prelude_log_func);
lua_pushnumber(__lua_state, level);
lua_pushstring(__lua_state, str);
lua_call(__lua_state, 2, 0);
}
static int _cb_lua_write(prelude_msgbuf_t *fd, prelude_msg_t *msg)
{
size_t ret;
FILE *f = (FILE *) prelude_msgbuf_get_data(fd);
ret = fwrite((const char *)prelude_msg_get_message_data(msg), 1, prelude_msg_get_len(msg), f);
if ( ret != prelude_msg_get_len(msg) )
return prelude_error_from_errno(errno);
prelude_msg_recycle(msg);
return 0;
}
static ssize_t _cb_lua_read(prelude_io_t *fd, void *buf, size_t size)
{
ssize_t ret;
FILE *f = (FILE *) prelude_io_get_fdptr(fd);
ret = fread(buf, 1, size, f);
if ( ret < 0 )
ret = prelude_error_from_errno(errno);
else if ( ret == 0 )
ret = prelude_error(PRELUDE_ERROR_EOF);
return ret;
}
};
%typemap(in, fragment="TransitionFunc") void (*log_cb)(int level, const char *log) {
if ( ! lua_isfunction(L, -1) )
SWIG_exception(SWIG_ValueError, "Argument should be a function");
if ( __lua_state )
luaL_unref(L, LUA_REGISTRYINDEX, __prelude_log_func);
__prelude_log_func = luaL_ref(L, LUA_REGISTRYINDEX);
$1 = _cb_lua_log;
__lua_state = L;
};
%exception {
try {
$action
} catch(Prelude::PreludeError &e) {
SWIG_exception(SWIG_RuntimeError, e.what());
SWIG_fail;
}
}
%exception read(void *nocast_p) {
try {
$action
} catch(Prelude::PreludeError &e) {
if ( e.getCode() == PRELUDE_ERROR_EOF )
return 0;
else {
SWIG_exception(SWIG_RuntimeError, e.what());
SWIG_fail;
}
}
}
%extend Prelude::IDMEF {
void write(void *nocast_p) {
self->_genericWrite(_cb_lua_write, nocast_p);
}
int read(void *nocast_p) {
self->_genericRead(_cb_lua_read, nocast_p);
return 1;
}
}
%fragment("SWIG_NewPointerObj", "header") {
#define SWIG_NewPointerObj(obj, objtype, val) _SWIG_Prelude_NewPointerObj((lua_State *) extra, obj, objtype, val);
}
%fragment("SWIG_FromCharPtr", "header") {
#define SWIG_FromCharPtr(result) str2lua((lua_State *) extra, result)
}
%fragment("SWIG_FromBytePtrAndSize", "header") {
#define SWIG_FromBytePtrAndSize(result, len) strsize2lua((lua_State *) extra, result, len)
}
%fragment("SWIG_FromCharPtrAndSize", "header") {
#define SWIG_FromCharPtrAndSize(result, len) strsize2lua((lua_State *) extra, result, len)
}
%fragment("SWIG_From_float", "header") {
#define SWIG_From_float(result) integer2lua((lua_State *) extra, result)
}
%fragment("SWIG_From_int", "header") {
#define SWIG_From_int(result) integer2lua((lua_State *) extra, result)
}
%fragment("SWIG_From_double", "header") {
#define SWIG_From_double(result) integer2lua((lua_State *) extra, result)
}
%fragment("SWIG_From_unsigned_SS_int", "header") {
#define SWIG_From_unsigned_SS_int(result) integer2lua((lua_State *) extra, result)
}
%fragment("SWIG_From_long_SS_long", "header") {
#define SWIG_From_long_SS_long(result) integer2lua((lua_State *) extra, result)
}
%fragment("SWIG_From_unsigned_SS_long_SS_long", "header") {
#define SWIG_From_unsigned_SS_long_SS_long(result) integer2lua((lua_State *) extra, result)
}
%fragment("IDMEFValueList_to_SWIG", "header") {
int IDMEFValue_to_SWIG(TARGET_LANGUAGE_SELF self, const Prelude::IDMEFValue &result, void *extra, TARGET_LANGUAGE_OUTPUT_TYPE ret);
int IDMEFValueList_to_SWIG(TARGET_LANGUAGE_SELF self, const Prelude::IDMEFValue &value, void *extra)
{
bool is_list;
int index = 0, ret, unused;
std::vector<Prelude::IDMEFValue> result = value;
std::vector<Prelude::IDMEFValue>::const_iterator i;
lua_newtable((lua_State *) extra);
for ( i = result.begin(); i != result.end(); i++ ) {
ret = lua_checkstack((lua_State *) extra, 2);
if ( ret < 0 )
return ret;
if ( (*i).isNull() ) {
lua_pushnil((lua_State *) extra);
lua_rawseti((lua_State *) extra, -2, ++index);
} else {
is_list = (i->getType() == IDMEFValue::TYPE_LIST);
if ( is_list )
lua_pushnumber((lua_State *) extra, ++index);
ret = IDMEFValue_to_SWIG(&unused, *i, extra, &unused);
if ( ret < 0 )
return -1;
if ( is_list )
lua_settable((lua_State *) extra, -3);
else
lua_rawseti((lua_State *) extra, -2, ++index);
}
}
return 1;
}
}
%typemap(out, fragment="IDMEFValue_to_SWIG") Prelude::IDMEFValue {
int ret, unused;
if ( $1.isNull() ) {
lua_pushnil(L);
SWIG_arg = 1;
} else {
SWIG_arg = IDMEFValue_to_SWIG(&unused, $1, L, &unused);
if ( SWIG_arg < 0 ) {
std::stringstream s;
s << "IDMEFValue typemap does not handle value of type '" << idmef_value_type_to_string((idmef_value_type_id_t) $1.getType()) << "'";
SWIG_exception(SWIG_ValueError, s.str().c_str());
}
}
};
#define MAX(x, y) ((x) > (y) ? (x) : (y))
%init {
int argc = 0, ret;
static char *argv[1024];
__initial_thread = (gl_thread_t) gl_thread_self();
lua_getglobal(L, "arg");
if ( ! lua_istable(L, -1) )
return;
lua_pushnil(L);
while ( lua_next(L, -2) != 0 ) {
int idx;
const char *val;
idx = lua_tonumber(L, -2);
val = lua_tostring(L, -1);
lua_pop(L, 1);
if ( idx < 0 )
continue;
if ( idx >= ((sizeof(argv) / sizeof(char *)) - 1) )
throw PreludeError("Argument index too large");
argv[idx] = strdup(val);
argc = MAX(idx, argc);
}
argc++;
argv[argc] = NULL;
ret = prelude_init(&argc, argv);
if ( ret < 0 )
throw PreludeError(ret);
}
|