[OpenWrt-Devel] [PATCH 1/3] [rpcd][v2] file: add support for base64

Felix Fietkau nbd at openwrt.org
Mon May 11 17:52:01 EDT 2015


On 2015-05-11 23:26, Luka Perkov wrote:
> Hi Felix,
> 
> On Mon, May 11, 2015 at 11:36:46AM +0200, Felix Fietkau wrote:
>> On 2015-05-11 00:26, Luka Perkov wrote:
>> > Signed-off-by: Luka Perkov <luka at openwrt.org>
>> > ---
>> > => changes in v2:
>> > 
>> > Use new libubox base64 provided API.
>> > 
>> >  file.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
>> >  1 file changed, 107 insertions(+), 11 deletions(-)
>> > 
>> > diff --git a/file.c b/file.c
>> > index 9c1b301..c3671bb 100644
>> > --- a/file.c
>> > +++ b/file.c
>> > @@ -182,7 +206,17 @@ rpc_file_read(struct ubus_context *ctx, struct ubus_object *obj,
>> >  
>> >  	blob_buf_init(&buf, 0);
>> >  
>> > -	wbuf = blobmsg_alloc_string_buffer(&buf, "data", s.st_size + 1);
>> > +	if (tb[RPC_F_RB_BASE64])
>> > +		base64 = blobmsg_get_bool(tb[RPC_F_RB_BASE64]);
>> > +
>> > +	if (base64)
>> > +	{
>> > +		wbuf = blobmsg_alloc_string_buffer(&buf, "data", B64_ENCODE_LEN(s.st_size));
>> > +	}
>> > +	else
>> > +	{
>> > +		wbuf = blobmsg_alloc_string_buffer(&buf, "data", s.st_size + 1);
>> > +	}
>> How about using the 'len' variable to avoid duplicating most of the code
>> here.
> 
> Can you be more specific here please? I don't see how by using 'len' we
> can reduce more code here.
len = s.st_size + 1;
if (base64)
	len = B64_ENCODE_LEN(s.st_size);
wbuf = blobmsg_alloc_string_buffer(&buf, "data", len);

- Felix
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list