Commit graph

31 commits

Author SHA1 Message Date
Etienne Champetier
2f793a4eb0 lua: add optional path filter to objects() method
'ubus list [<path>]' passes the path to ubusd,
this commit fix the lua bindings to do the same

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2022-05-30 07:00:52 +02:00
Alin Nastac
171469e313 lua: avoid truncation of large numeric values
If the Lua number exceeds the maximum value representable by an
unsigned 32bit integer, store it in an unsigned 64bit integer
field instead.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
[align code style, reword commit message]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2020-03-15 20:49:27 +01:00
Petr Štetiar
72be8e93f0 lua: ubus_lua_do_subscribe: fix copy&paste error
Fix copy&paste error in Lua ubus subscriber removal callback.

Addresses-Coverity-ID: 1412311 ("Copy-paste error")
Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-16 23:39:16 +01:00
Petr Štetiar
a995b1e681 lua: workaround false positive dereference of null pointer
scan-build from clang-9 has reported following:

 ubus.c:837:16: warning: Access to field 'rnotify' results in a dereference of a null pointer (loaded from variable 'sub')
                 sub->rnotify = luaL_ref(L, -2);

Which is false positive as the lua_error() does a long jump and
therefore never returns and this long jump probably confuses the static
analyzer. So this patch workarounds this false positive by helping
static analyzer by using common Lua idiom which is to return
lua_error()'s return value.

Ref: https://www.lua.org/manual/5.1/manual.html#lua_error
Addresses-Coverity-ID: 1412355 ("Dereference after null check")
Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-16 23:39:16 +01:00
Petr Štetiar
d2e026a33d iron out all extra compiler warnings
clang-9 on x86/64 has reported following warnings/errors:

 libubus-acl.c:123:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 libubus-io.c:108:18: error: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
 libubus-io.c:395:56: error: comparison of integers of different signs: 'ssize_t' (aka 'long') and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
 libubus-req.c:441:4: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 ubusd_acl.c:119:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
 ubusd_acl.c:152:5: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 ubusd_acl.c:348:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 ubusd_acl.c:352:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 ubusd_acl.c:357:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 ubusd_acl.c:362:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 ubusd_acl.c:367:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
 ubusd_acl.c:447:16: error: comparison of integers of different signs: 'int' and '__size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
 ubusd_acl.c:502:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
 ubusd.c:123:13: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
 ubusd.c:170:15: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
 ubusd.c:262:43: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
 ubusd.c:287:30: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
 ubusd_event.c:170:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
 ubusd_obj.c:71:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]

Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-16 23:39:16 +01:00
Marcus Comstedt
0327a91beb ubus/lua: add support for BLOBMSG_TYPE_DOUBLE
Signed-off-by: Marcus Comstedt <marcus@mc.pp.se>
2018-09-10 09:48:17 +02:00
Dirk Feytons
5bae22eb54 ubus/lua: pass notification name to callback
The callback function registered to be invoked when subscribing to a
notification was only passed the notification data (if any) but not the name
of the notification.

This name is now passed as second argument to remain backwards compatible.
The example subscriber.lua has also be updated.

Signed-off-by: Dirk Feytons <dirk.feytons@gmail.com>
2018-01-17 09:59:58 +01:00
Rosen Penev
9c13096b16 ubus: Remove unnecessary memset calls.
Replace malloc+memset with calloc.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2017-11-13 09:46:12 +01:00
Vasily Goldobin
d009a08473 lua: add 'defer_request' and 'complete_deferred_request' functions
Add Lua bindings for 'ubus_defer_request' and 'ubus_complete_deferred_request' functions with sample code.

Signed-off-by: Vasily Goldobin <vasily@lynxtech.ru>
2016-11-21 11:27:05 +01:00
Iain Fraser
976719d89c Implemented publish/subscribe lua bindings to libubus-lua with example lua files. 2016-06-06 14:47:10 +02:00
Felix Fietkau
8bb34756ce lua: fix stack leak in ubus method handling
Signed-off-by: Chen Bin <ewolfok@126.com>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2016-01-20 14:59:06 +01:00
Hans Dedecker
d23b07a9ff lua: Fix stack imbalance in ubus_event_handler
The value from getglobal wasn't being removed from the stack,
resulting in an ever growing stack in the ubus event handler.

Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
2015-11-02 19:02:35 +01:00
陈斌
f361bfa5fc lua: fix memory leak problem
Signed-off-by: Chen Bin <ewolfok@126.com>
2015-05-25 23:06:19 +02:00
Hans Dedecker
7798d56301 ubus: Fix issues reported by static code analysis tool Klocwork
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
2015-04-20 15:43:19 +02:00
Steven Barth
6dffecb36b lua: forward return codes from lua to ubus
Signed-off-by: Steven Barth <cyrus@openwrt.org>
Tested-by: Luka Perkov <luka@openwrt.org>
2014-05-05 19:56:31 +02:00
Karl Vogel
334c389180 ubus: Fix imbalance in lua stack push/pop of values.
The lua getglobal and rawgeti both push a value onto the lua stack,
but they weren't being removed by the ubus_method_handler function,
thus corrupting the lua stack.

In case the specified method wasn't a function, the stack was also
corrupted as the method name remained on the stack.

Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
2014-02-23 18:20:29 +01:00
Luka Perkov
4e82a1fabb lua: allow methods with no arguments
In C it is possible to have methods without arguments (UBUS_METHOD_NOARG).
Enable support for the same calls in Lua too.

This commit also fixes segfault which can be caused by passing non-table type
where table is expected. The lua_gettablelen() function is called after we have
made sure we are dealing with a table in the first place.

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-28 22:20:30 +00:00
Luka Perkov
b356773921 lua: fix whitespaces and typo
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-28 22:20:26 +00:00
John Crispin
8ea9667036 add Lua bindings for ubus events
It mostly mimick the style of the existing code.

With it and the ubox Lua bindings, you can now send ubus events
through Lua or listen for events (you can register for multiple events
at the same time).

Signed-off-by: Jeff Remy <jeff.remy@gmail.com>
2013-11-07 16:23:30 +01:00
Thomas Gstädtner
a15a09aed4 add INCLUDE_DIRECTORIES to subdirectories 2013-03-03 03:43:22 +01:00
Jo-Philipp Wich
bf566871bd lua: pass u64 blob type as double to Lua 2013-01-13 20:37:19 +01:00
Jo-Philipp Wich
77eefb3bdd lua: remove a superfluous lua_pop() when checking table style 2012-10-17 15:32:26 +02:00
Jo-Philipp Wich
9c0b821573 lua: fix ubus_lua_format_blob_is_array() to not leave garbage on the stack 2012-10-16 19:37:31 +03:00
John Crispin
0f793d3a45 lua: propagate incoming message to method callback inside the lua context
Signed-off-by: John Crispin <blogic@openwrt.org>
2012-09-29 01:41:09 +02:00
John Crispin
73380e45c9 add lua binding test scripts
Signed-off-by: John Crispin <blogic@openwrt.org>
2012-09-27 14:05:51 +02:00
Felix Fietkau
c382792d98 lua: add support for registering methods
Signed-off-by: John Crispin <blogic@openwrt.org>
2012-09-27 14:00:49 +02:00
Felix Fietkau
0371c8f5fd lua: add uloop support 2012-09-27 13:59:47 +02:00
John Crispin
115b7a8c73 lua: allow building the lua binding with vanilla lua
Signed-off-by: John Crispin <blogic@openwrt.org>
2012-09-27 13:49:45 +02:00
Felix Fietkau
960c342b4a lua: add a prototype for luaopen_ubus so that -Wmissing-declarations can be enabled 2012-05-29 00:41:27 +02:00
Felix Fietkau
a204ae358b lua: put LUAPATH in quotes to prevent weird error messages when it is unset 2012-05-06 10:25:46 +02:00
Jo-Philipp Wich
25b9b4b827 implement Lua binding 2012-05-05 22:37:46 +02:00