Commit graph

392 commits

Author SHA1 Message Date
Yousong Zhou
cead67c804 ustream-fd: readability change.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2015-06-14 15:16:10 +02:00
Yousong Zhou
9386d0717a ustream: tweak ustream_prepare_buf() a bit.
No functional change.

 - Reuse existing NULL check on buf.
 - Add some comments for ease of reading the code.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2015-06-14 15:15:43 +02:00
Yegor Yefremov
791a361ad1 ubox: CMake: fix json-c detection
Use PKG_SEARCH_MODULE() to detect json-c library,
otherwise the search fails, if both json-c and json
are not present in pkg-config database.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2015-05-10 14:14:45 +02:00
Felix Fietkau
a8e70c6d36 add a base64 implementation (based on FreeBSD code)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2015-05-08 14:34:29 +02:00
John Crispin
b8d9b382e3 allow process callback to call uloop_end()
Signed-off-by: John Crispin <blogic@openwrt.org>
2015-03-21 05:50:23 +01:00
Jo-Philipp Wich
2a9edb4642 ulog: implement ulog_close()
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2015-02-26 13:35:50 +01:00
Jo-Philipp Wich
ca6d547205 ulog: introduce new simple logging api
The ulog api is intended to be used by procd, fstools, ubox etc. to provide
a generic logging api for early boot messages and automatic switching between
syslog / kmsg / stdout depending on the way the process is executed.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2015-02-26 10:43:56 +01:00
Rafał Miłecki
827ad8337e uloop: ignore SIGPIPE by default
Most app don't want to crash because of unhandled SIGPIPE. It could
happen is such trivial situations like writing to socket.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
2015-01-28 10:51:15 +01:00
Yousong Zhou
ad9aa180d3 utils: use clock_get_time() for clock_gettime() on Apple.
It turns out that mach_absolute_time() is not monotonic at all.  While
at it, convert the CLOCK_REALTIME implementation to using
clock_get_time() as well.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2015-01-21 20:11:30 +01:00
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