Commit graph

333 commits

Author SHA1 Message Date
Yousong Zhou
08c27ceb01 uloop: optimize uloop_timeout_set() implementaiton a bit.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2015-01-21 20:02:46 +01:00
Yousong Zhou
73c4b4fdfe ustream-fd: fix logic invert of write polling.
ustream_write_pending() returns true if write buffer was flushed there.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2015-01-21 20:02:03 +01:00
Yousong Zhou
60236c4853 ustream: add function ustream_read().
It can be used to fill caller-specified buffer with data already in
ustream read buffer.  Useful in the following use pattern.

	int available = ustream_pending_data(s, false);
	if (available >= sizeof(struct msghdr)) {
		struct msghdr h;
		ustream_read(s, &h, sizeof(h));
	}

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2015-01-21 20:00:39 +01:00
Rafał Miłecki
f1c794b29e usock: set socket flags right after creating it
Otherwise some flags like USOCK_NONBLOCK wouldn't work as expected
(O_NONBLOCK affects connect behavior).

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
2015-01-15 13:10:58 +01:00
Rafał Miłecki
ad9b5a387d usock: add helper waiting for socket to be ready
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
2015-01-15 13:10:49 +01:00
Yousong Zhou
fecaf2f5f6 examples: add example code for json_script.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-22 15:46:35 +01:00
Yousong Zhou
13b5c1d4ca json_script: fix logic invert of handle_expr_not().
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-22 15:46:21 +01:00
Yousong Zhou
0d22684faa json_script: remove unneed argument check before calling __json_script_file_free().
NULL check is present at the begining of function body.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:59:22 +01:00
Yousong Zhou
30e6cca939 json_script: fix eval_string().
- Fix handling of "%%".
 - Fix length requirement when calling blobmsg_realloc_string_buffer().

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:59:02 +01:00
Yousong Zhou
8c6dadbe03 jshn: add error handling and fix memory leak in jshn_format().
Though currently jshn is more a one-shot data transformation tool and
won't leak much memory in its lifetime, people may use it as example
code, so do it right.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:58:42 +01:00
Yousong Zhou
7f1ce63a84 blobmsg: remove unneeded assignment in blobmsg_alloc_string_buffer().
data_dest should already be assigned by blobmsg_new() if the return
value is not NULL.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:58:29 +01:00
Yousong Zhou
8cc3903383 examples: fix build.
- runqueue-example.c: fix include path for in-tree build.
 - blobmsg-example.c: add inttypes.h for using PRIu64.
 - add examples/ subdirectory to main CMakeLists.txt

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:57:19 +01:00
Yousong Zhou
c5d80836cd lua: do not hardcode /opt/local/include for Apple.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:57:07 +01:00
Yousong Zhou
cbf80de7f4 libubox: drop legacy json-c support
The cmake logic is wrong (E.G. PKG_CHECK_FOR_MODULES fails unless all
modules are found), and the legacy libjson.so name is also used by the other
libjson (http://sourceforge.net/projects/libjson/) which provides an
incompatible API, so just drop it.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2014-12-11 17:56:54 +01:00
Felix Fietkau
f09ae76445 Revert "jshn: only keep UP_* variables around while they are needed"
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 23:53:44 +01:00
Felix Fietkau
0bfb44f590 jshn: shorten JSON_VAR to J_V
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 20:59:49 +01:00
Felix Fietkau
d59fa8d588 jshn: shorten variable names to speed up processing
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 20:02:51 +01:00
Felix Fietkau
f386a0d7d8 jshn: remove TYPE_JSON_VAR
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 19:45:07 +01:00
Felix Fietkau
4a09bb0284 jshn: do not export JSON_SEQ
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 19:44:10 +01:00
Felix Fietkau
37b5203e18 jshn: only keep UP_* variables around while they are needed
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 19:43:56 +01:00
Felix Fietkau
d5d384b0ba jshn: improve performance by using let instead of $(( ))
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-11-23 19:25:39 +01:00
Felix Fietkau
d133da5562 blobmsg_json: avoid redefinition of json_object
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-10-24 13:40:14 +02:00
Michel Stam
464e05e33b uloop: Do not override signal handlers not installed by us
Signed-off-by: Michel Stam <m.stam@fugro.nl>
2014-10-12 13:21:20 +02:00
Michel Stam
213122a083 uloop: Remove uloop_cancelled variable, it is not used anywhere
Signed-off-by: Michel Stam <m.stam@fugro.nl>
2014-10-12 13:21:17 +02:00
Felix Fietkau
bae6bd19f3 md5: add a new implementation under permissive license
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-10-01 16:39:15 +02:00
Felix Fietkau
6f2c688d68 blobmsg_json: include json.h inside blobmsg_json.c instead of the public header file
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-23 12:03:32 +02:00
Felix Fietkau
c8fc0897cd avoid using the deprecated is_error() function from json-c
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-09-23 12:02:31 +02:00
Jo-Philipp Wich
fa73496098 usock: add usock_port() for convenient use of numeric ports
Add a new helper function usock_port() which converts the given numeric port number
into a string using a private static buffer. This way a calling application can
conveniently use numeric port arguments without having to convert them before:

  int fd = usock(USOCK_UDP, "example.org", usock_port(80));

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2014-09-23 12:01:00 +02:00
John Crispin
dffbc09baf jshn: pretty print indented output with jshn -i -w
Signed-off-by: John Crispin <blogic@openwrt.org>
2014-08-04 20:01:16 +02:00
Felix Fietkau
042f1a2546 blobmsg: accept NULL attr in blobmsg_get_string()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-08-03 15:00:54 +02:00
xfguo@credosemi.com
6e8e6aca1d lua/uloop: 'end' is the keyword of Lua, use 'cancel' replace it.
Signed-off-by: Xiongfei Guo <xfguo@credosemi.com>
2014-07-27 11:31:07 +02:00
ewolfok
22bbcfddd7 blob: improve out-of-memory handling
Signed-off-by: Chen Bin <ewolfok@126.com>
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-26 03:50:50 +02:00
Felix Fietkau
f3977836af blobmsg: add a helper function to reset the name of a blobmsg attribute
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-21 01:24:01 +02:00
Jo-Philipp Wich
bd388d2b6c jshn: do not collapse whitespace in json_load()
When running the test case below the $key variable holds "foo bar" instead
of the expected "foo  bar".

-- 8< --
. /usr/share/libubox/jshn.sh
json_init
json_load '{ "key": "foo  bar" }'
json_get_var key key
-- >8 --

Quote the output of the "jshn -r" backtick expression to prevent the shell
from erroneously collapsing whitespace.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2014-07-16 20:36:13 +02:00
Felix Fietkau
7ba1f8acd8 blobmsg: add blobmsg_check_array, which returns the size of the array
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-15 10:52:12 +02:00
Felix Fietkau
fd5b522ce6 blobmsg-example: use blobmsg_get_string()
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-03 13:50:49 +02:00
Luka Perkov
b538c2b20e examples: fix build error
Patch fixes the following error:

error: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘void *’ [-Werror=format=]
   indent_printf(indent, "%s\n", blobmsg_data(data));

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-07-03 13:48:30 +02:00
Felix Fietkau
8cee1e552a blobmsg_example: fix output
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-07-03 12:56:40 +02:00
Luka Perkov
db8e7060e0 examples: use PRIu64 instead %lld when printing uint64_t values
Patch fixes build failure:

error: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘uint64_t’ [-Werror=format=]
   indent_printf(indent, "%lld\n", *(uint64_t *)data);

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-07-03 12:53:13 +02:00
Luka Perkov
480b6c7da1 examples: add missing include
Patch fixes following build error:

error: implicit declaration of function ‘close’ [-Werror=implicit-function-declaration]
  close(cl->s.fd.fd);

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-07-03 12:53:13 +02:00
Luka Perkov
fd3a33b7ed examples: fix linking with json-c
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-07-03 12:53:13 +02:00
Luka Perkov
b10cd1c0f6 examples: remove set but unused variable
Fixes build failure.

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-07-03 12:53:13 +02:00
Luka Perkov
531570aa51 usock: fix indentation
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-07-03 12:53:13 +02:00
Xiongfei Guo
39a8fae441 Fix bug of GC in fd and timeout objects for lua binding.
fd and timeout lua object has a __gc method in its metatable. After the object
is freed and the another new object use the same reference in __uloop_cb and
__uloop_fds, the new object will be freed by the old __gc of the old object
when garbag collecting.

Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
Xiongfei Guo
3c92274bee Fix bug of unref resources in Lua binding; fd method delete -> cancel.
Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
Xiongfei Guo
02ca593347 Support delete a fd event.
When you call the fd_add, it will return an object with `delete` method.
So you can delete that event if you want.

Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
Xiongfei Guo
79b56268b4 Added fd_add method for uloop lua binding.
Use uloop.fd_add like this:

    local socket = require "socket"

    udp = socket.udp()

    uloop.fd_add(
        udp, -- socket
        function( -- callback function
            ufd,    -- socket object when register the fd
            events  -- uloop events. eg. uloop.ULOOP_READ .
        )
            local words, msg_or_ip, port_or_nil = ufd:receivefrom()
            print('Recv UDP packet from '..msg_or_ip..':'..port_or_nil..' : '..words)
        end,
        uloop.ULOOP_READ -- event you want to listen
    )

The `examples/uloop-example.lua` show an example of this work.

Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
Xiongfei Guo
9565bf86ae Fix stack overflow bug of uloop lua binding.
The static variable `state` in `lua/uloop.c` should be clean after every callback.

Signed-off-by: Xiongfei(Alex) Guo <xfguo@credosemi.com>
2014-06-24 14:30:30 +01:00
John Crispin
e130b08d98 build a static version of libubox
Signed-off-by: John Crispin <blogic@openwrt.org>
2014-06-11 01:39:12 +01:00
Felix Fietkau
949f0d00bf vlist: add static initializer macros
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-06-05 15:28:45 +02:00