All of lore.kernel.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON
@ 2013-09-07 20:19 Nils Schneider
  2013-09-07 20:32 ` Antonio Quartulli
  0 siblings, 1 reply; 7+ messages in thread
From: Nils Schneider @ 2013-09-07 20:19 UTC (permalink / raw)
  To: b.a.t.m.a.n

With this patch alfred -r will output JSON like this:

{
  "00:11:22:33:44:55" : "...",
  "22:33:44:55:66:FF" : "..."
}
---
 client.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/client.c b/client.c
index a535f5a..ec882d9 100644
--- a/client.c
+++ b/client.c
@@ -39,7 +39,7 @@ int alfred_client_request_data(struct globals *globals)
 	struct alfred_status_v0 *status;
 	struct alfred_tlv *tlv;
 	struct alfred_data *data;
-	int ret, len, data_len, i;
+	int ret, len, data_len, i, count;
 
 	if (unix_sock_open_client(globals, ALFRED_SOCK_PATH))
 		return -1;
@@ -59,6 +59,9 @@ int alfred_client_request_data(struct globals *globals)
 		fprintf(stderr, "%s: only wrote %d of %d bytes: %s\n",
 			__func__, ret, len, strerror(errno));
 
+	printf("{");
+
+	count = 0;
 	push = (struct alfred_push_data_v0 *)buf;
 	tlv = (struct alfred_tlv *)buf;
 	while ((ret = read(globals->unix_sock, buf, sizeof(*tlv))) > 0) {
@@ -98,9 +101,12 @@ int alfred_client_request_data(struct globals *globals)
 		if (ret < data_len)
 			break;
 
+		if (count > 0)
+			printf(",\n");
+
 		pos = data->data;
 
-		printf("{ \"%02x:%02x:%02x:%02x:%02x:%02x\", \"",
+		printf("\n  \"%02x:%02x:%02x:%02x:%02x:%02x\": \"",
 		       data->source[0], data->source[1],
 		       data->source[2], data->source[3],
 		       data->source[4], data->source[5]);
@@ -110,14 +116,18 @@ int alfred_client_request_data(struct globals *globals)
 			else if (pos[i] == '\\')
 				printf("\\\\");
 			else if (!isprint(pos[i]))
-				printf("\\x%02x", pos[i]);
+				printf("\\u00%02x", pos[i]);
 			else
 				printf("%c", pos[i]);
 		}
 
-		printf("\" },\n");
+		printf("\"");
+
+		count++;
 	}
 
+	printf("\n}\n");
+
 	unix_sock_close(globals);
 
 	return 0;
-- 
1.8.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON
  2013-09-07 20:19 [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON Nils Schneider
@ 2013-09-07 20:32 ` Antonio Quartulli
  2013-09-07 20:56   ` Nils Schneider
  0 siblings, 1 reply; 7+ messages in thread
From: Antonio Quartulli @ 2013-09-07 20:32 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

[-- Attachment #1: Type: text/plain, Size: 399 bytes --]

On Sat, Sep 07, 2013 at 10:19:46PM +0200, Nils Schneider wrote:
> With this patch alfred -r will output JSON like this:
> 
> {
>   "00:11:22:33:44:55" : "...",
>   "22:33:44:55:66:FF" : "..."
> }

is this patch fixing a broken behaviour? The commit message is not very clear
about this.

Regards,

-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON
  2013-09-07 20:32 ` Antonio Quartulli
@ 2013-09-07 20:56   ` Nils Schneider
  2013-09-08  2:39     ` Marek Lindner
  0 siblings, 1 reply; 7+ messages in thread
From: Nils Schneider @ 2013-09-07 20:56 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

The current output format isn't really broken, just tricky to parse.
I decided to make it valid JSOΝ as it was already pretty close. This
allows parsing with virtually any programming language.

At Sat, 7 Sep 2013 22:32:07 +0200,
Antonio Quartulli wrote:
>=20
> [1  <text/plain; utf-8 (quoted-printable)>]
> On Sat, Sep 07, 2013 at 10:19:46PM +0200, Nils Schneider wrote:
> > With this patch alfred -r will output JSON like this:
> >=20
> > {
> >   "00:11:22:33:44:55" : "...",
> >   "22:33:44:55:66:FF" : "..."
> > }
>=20
> is this patch fixing a broken behaviour? The commit message is not very c=
lear
> about this.
>=20
> Regards,
>=20
> --=20
> Antonio Quartulli
>=20
> ..each of us alone is worth nothing..
> Ernesto "Che" Guevara
> [2 Digital signature <application/pgp-signature (7bit)>]
>=20

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON
  2013-09-07 20:56   ` Nils Schneider
@ 2013-09-08  2:39     ` Marek Lindner
  2013-09-08  8:47       ` Nils Schneider
  0 siblings, 1 reply; 7+ messages in thread
From: Marek Lindner @ 2013-09-08  2:39 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Sunday, September 08, 2013 04:56:39 Nils Schneider wrote:
> The current output format isn't really broken, just tricky to parse.
> I decided to make it valid JSOΝ as it was already pretty close. This
> allows parsing with virtually any programming language.

Please be more specific about what was broken and how your fix addresses the 
problem. An example would be nice too.

Cheers,
Marek

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON
  2013-09-08  2:39     ` Marek Lindner
@ 2013-09-08  8:47       ` Nils Schneider
  2013-09-08 21:53         ` Simon Wunderlich
  0 siblings, 1 reply; 7+ messages in thread
From: Nils Schneider @ 2013-09-08  8:47 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

The current output format of alfred -r looks like this:

{ "fe:f1:00:00:01:01", "OpenWRT-node-1\x0a" },
{ "fe:f1:00:00:02:01", "OpenWRT-node-2\x0a" },
{ "fe:f1:00:00:03:01", "OpenWRT-node-3\x0a" },

It's not clear how one should parse this as there is no documentation
except the source code.

With my patch, it'll look like this:

{
  "fe:f1:00:00:01:01": "OpenWRT-node-1\u000a",
  "fe:f1:00:00:02:01": "OpenWRT-node-2\u000a",
  "fe:f1:00:00:03:01": "OpenWRT-node-3\u000a"
}

This is JSOΝ which is well documented and thus can be parsed
easily. It's a dictionary with the node's ID as the key and the data
as value.

At Sun, 8 Sep 2013 10:39:23 +0800,
Marek Lindner wrote:
>=20
> On Sunday, September 08, 2013 04:56:39 Nils Schneider wrote:
> > The current output format isn't really broken, just tricky to parse.
> > I decided to make it valid JSOΝ as it was already pretty close. This
> > allows parsing with virtually any programming language.
>=20
> Please be more specific about what was broken and how your fix addresses =
the=20
> problem. An example would be nice too.
>=20
> Cheers,
> Marek

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON
  2013-09-08  8:47       ` Nils Schneider
@ 2013-09-08 21:53         ` Simon Wunderlich
  2013-09-08 23:40           ` Gui Iribarren
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Wunderlich @ 2013-09-08 21:53 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

[-- Attachment #1: Type: text/plain, Size: 1926 bytes --]

Hey Nils,

thanks for your patch!

On Sun, Sep 08, 2013 at 10:47:00AM +0200, Nils Schneider wrote:
> The current output format of alfred -r looks like this:
> 
> { "fe:f1:00:00:01:01", "OpenWRT-node-1\x0a" },
> { "fe:f1:00:00:02:01", "OpenWRT-node-2\x0a" },
> { "fe:f1:00:00:03:01", "OpenWRT-node-3\x0a" },
> 
> It's not clear how one should parse this as there is no documentation
> except the source code.

The output was first designed for debugging and scripts who should parse
that (binary programs like vis may access the unix sockets directly).

> 
> With my patch, it'll look like this:
> 
> {
>   "fe:f1:00:00:01:01": "OpenWRT-node-1\u000a",
>   "fe:f1:00:00:02:01": "OpenWRT-node-2\u000a",
>   "fe:f1:00:00:03:01": "OpenWRT-node-3\u000a"
> }
> 
> This is JSOΝ which is well documented and thus can be parsed
> easily. It's a dictionary with the node's ID as the key and the data
> as value.

I think your suggestion/patch is a good idea, it will result in a more
general format. I'd like to ask you to send your patch again with a
revised commit message (e.g. add your examples from this mail and a
short explanation why the old format was bad, and why JSON is better).

I'd then would like to wait for approx. 1 week to gather comments from
people who already parse the old format already (Guido?), and if there are
no objections merge it.

Thanks!
	Simon
> 
> At Sun, 8 Sep 2013 10:39:23 +0800,
> Marek Lindner wrote:
> > 
> > On Sunday, September 08, 2013 04:56:39 Nils Schneider wrote:
> > > The current output format isn't really broken, just tricky to parse.
> > > I decided to make it valid JSOΝ as it was already pretty close. This
> > > allows parsing with virtually any programming language.
> > 
> > Please be more specific about what was broken and how your fix addresses the 
> > problem. An example would be nice too.
> > 
> > Cheers,
> > Marek

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON
  2013-09-08 21:53         ` Simon Wunderlich
@ 2013-09-08 23:40           ` Gui Iribarren
  0 siblings, 0 replies; 7+ messages in thread
From: Gui Iribarren @ 2013-09-08 23:40 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking,
	Simon Wunderlich

I'm already turning your output into proper json, but inside my lua script. So getting json out of alfred would simplify things :)
I.e.: +1 and thanks for the patch!

Simon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de> wrote:
>Hey Nils,
>
>thanks for your patch!
>
>On Sun, Sep 08, 2013 at 10:47:00AM +0200, Nils Schneider wrote:
>> The current output format of alfred -r looks like this:
>> 
>> { "fe:f1:00:00:01:01", "OpenWRT-node-1\x0a" },
>> { "fe:f1:00:00:02:01", "OpenWRT-node-2\x0a" },
>> { "fe:f1:00:00:03:01", "OpenWRT-node-3\x0a" },
>> 
>> It's not clear how one should parse this as there is no documentation
>> except the source code.
>
>The output was first designed for debugging and scripts who should
>parse
>that (binary programs like vis may access the unix sockets directly).
>
>> 
>> With my patch, it'll look like this:
>> 
>> {
>>   "fe:f1:00:00:01:01": "OpenWRT-node-1\u000a",
>>   "fe:f1:00:00:02:01": "OpenWRT-node-2\u000a",
>>   "fe:f1:00:00:03:01": "OpenWRT-node-3\u000a"
>> }
>> 
>> This is JSOΝ which is well documented and thus can be parsed
>> easily. It's a dictionary with the node's ID as the key and the data
>> as value.
>
>I think your suggestion/patch is a good idea, it will result in a more
>general format. I'd like to ask you to send your patch again with a
>revised commit message (e.g. add your examples from this mail and a
>short explanation why the old format was bad, and why JSON is better).
>
>I'd then would like to wait for approx. 1 week to gather comments from
>people who already parse the old format already (Guido?), and if there
>are
>no objections merge it.
>
>Thanks!
>	Simon
>> 
>> At Sun, 8 Sep 2013 10:39:23 +0800,
>> Marek Lindner wrote:
>> > 
>> > On Sunday, September 08, 2013 04:56:39 Nils Schneider wrote:
>> > > The current output format isn't really broken, just tricky to
>parse.
>> > > I decided to make it valid JSOΝ as it was already pretty close.
>This
>> > > allows parsing with virtually any programming language.
>> > 
>> > Please be more specific about what was broken and how your fix
>addresses the 
>> > problem. An example would be nice too.
>> > 
>> > Cheers,
>> > Marek


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-09-08 23:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-07 20:19 [B.A.T.M.A.N.] [PATCH] alfred: output valid JSON Nils Schneider
2013-09-07 20:32 ` Antonio Quartulli
2013-09-07 20:56   ` Nils Schneider
2013-09-08  2:39     ` Marek Lindner
2013-09-08  8:47       ` Nils Schneider
2013-09-08 21:53         ` Simon Wunderlich
2013-09-08 23:40           ` Gui Iribarren

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.