public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output.
@ 2011-03-09 16:48 elektra
  2011-03-09 17:04 ` Sven Eckelmann
  0 siblings, 1 reply; 5+ messages in thread
From: elektra @ 2011-03-09 16:48 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Alberto Escudero-Pascual

The current vis server JSON output format is breaking the json_decode() 
function for PHP. 

This patch mainly:
- Removes all spaces
- Removes all the \t TABS
- Double quotes the string-variables

Reported-by:  "Alberto Escudero-Pascual" <aep@it46.se>
Signed-off-by: "elektra" <onelektra@gmx.net>


--- vis.c       2011-03-09 17:19:59.000000000 +0100
+++ new/vis.c   2011-03-09 17:15:26.000000000 +0100
@@ -88,19 +88,21 @@
        if ( fork() )
                exit(EXIT_SUCCESS);
 
-       chdir( "/" );
+       if (chdir( "/" )==0) {
 
-       if ( ( fd = open(_PATH_DEVNULL, O_RDWR, 0) ) != -1 ) {
+               if ( ( fd = open(_PATH_DEVNULL, O_RDWR, 0) ) != -1 ) {
 
-               dup2(fd, STDIN_FILENO);
-               dup2(fd, STDOUT_FILENO);
-               dup2(fd, STDERR_FILENO);
+                       dup2(fd, STDIN_FILENO);
+                       dup2(fd, STDOUT_FILENO);
+                       dup2(fd, STDERR_FILENO);
 
-               if ( fd > 2 )
-                       close(fd);
+                       if ( fd > 2 )
+                               close(fd);
 
+               }
+       } else {
+               exit_error( "Error - can't chdir\n");
        }
-
        return 0;
 }
 
@@ -395,7 +397,7 @@
                                                fillme->dot_buffer = (char 
*)debugRealloc( fillme->dot_buffer, strlen( tmp ) + strlen( fillme->dot_buffer ) + 
1, 408 );
                                                strncat( fillme->dot_buffer, 
tmp, strlen( tmp ) );
 
-                                               snprintf( tmp, sizeof( tmp ), 
"%s\t{ router : \"%s\", neighbour : \"%s\", label : %.2f }",
+                                               snprintf( tmp, sizeof( tmp ), 
"%s{\"router\":\"%s\",\"neighbour\":\"%s\",\"label\":%.2f}",
                                                        (first_line ? "" : ",
\n"), from_str, to_str, (float)( orig_node->tq_max / (float)neigh->tq_avg ) );
                                                first_line = 0;
                                                fillme->json_buffer = (char 
*)debugRealloc( fillme->json_buffer, strlen( tmp ) + strlen( fillme->json_buffer ) 
+ 1, 408 );
@@ -416,7 +418,7 @@
                                        fillme->dot_buffer = (char 
*)debugRealloc( fillme->dot_buffer, strlen( tmp ) + strlen( fillme->dot_buffer ) + 
1, 409 );
                                        strncat( fillme->dot_buffer, tmp, 
strlen( tmp ) );
 
-                                       snprintf( tmp, sizeof( tmp ), "%s\t{ 
router : \"%s\", gateway : \"%s/%s\", label : \"HNA\" }",
+                                       snprintf( tmp, sizeof( tmp ), 
"%s{\"router\":\"%s\",\"gateway\":\"%s/%s\",\"label\":\"HNA\"}",
                                                (first_line ? "" : ",\n"), 
from_str, to_str, hna_str );
                                        first_line = 0;
                                        fillme->json_buffer = (char 
*)debugRealloc( fillme->json_buffer, strlen( tmp ) + strlen( fillme->json_buffer ) 
+ 1, 409 );
@@ -432,7 +434,7 @@
                                        strncat( fillme->dot_buffer, tmp, 
strlen( tmp ) );
 

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

* Re: [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output.
  2011-03-09 16:48 [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output elektra
@ 2011-03-09 17:04 ` Sven Eckelmann
  2011-03-10  7:55   ` Alberto Escudero-Pascual
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Eckelmann @ 2011-03-09 17:04 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Alberto Escudero-Pascual

[-- Attachment #1: Type: Text/Plain, Size: 736 bytes --]

On Wednesday 09 March 2011 17:48:32 elektra wrote:
> The current vis server JSON output format is breaking the json_decode()
> function for PHP.
> 
> This patch mainly:
> - Removes all spaces
> - Removes all the \t TABS
> - Double quotes the string-variables
> 
> Reported-by:  "Alberto Escudero-Pascual" <aep@it46.se>
> Signed-off-by: "elektra" <onelektra@gmx.net>

I am not sure if anyone currently maintains batmand and vis.

Anyway, your patch is more or less scrambled. Can you please resend it using a 
client which doesn't create a wordwrap and space massacre[1]. Many people here 
seem to use git-send-email for that purpose.

Kind regards,
	Sven

[1] http://kernel.org/doc/Documentation/email-clients.txt

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output.
@ 2011-03-09 17:16 elektra
  0 siblings, 0 replies; 5+ messages in thread
From: elektra @ 2011-03-09 17:16 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Alberto Escudero-Pascual

The current vis server JSON output format is breaking the json_decode() 
function for PHP. 

This patch mainly:
- Removes all spaces
- Removes all the \t TABS
- Double quotes the string-variables

Reported-by:  "Alberto Escudero-Pascual" <aep@it46.se>
Signed-off-by: "elektra" <onelektra@gmx.net>

--- vis.c       2011-03-09 17:19:59.000000000 +0100
+++ new/vis.c   2011-03-09 17:15:26.000000000 +0100
@@ -88,19 +88,21 @@
        if ( fork() )
                exit(EXIT_SUCCESS);
 
-       chdir( "/" );
+       if (chdir( "/" )==0) {
 
-       if ( ( fd = open(_PATH_DEVNULL, O_RDWR, 0) ) != -1 ) {
+               if ( ( fd = open(_PATH_DEVNULL, O_RDWR, 0) ) != -1 ) {
 
-               dup2(fd, STDIN_FILENO);
-               dup2(fd, STDOUT_FILENO);
-               dup2(fd, STDERR_FILENO);
+                       dup2(fd, STDIN_FILENO);
+                       dup2(fd, STDOUT_FILENO);
+                       dup2(fd, STDERR_FILENO);
 
-               if ( fd > 2 )
-                       close(fd);
+                       if ( fd > 2 )
+                               close(fd);
 
+               }
+       } else {
+               exit_error( "Error - can't chdir\n");
        }
-
        return 0;
 }
 
@@ -395,7 +397,7 @@
                                                fillme->dot_buffer = (char *)debugRealloc( fillme->dot_buffer, strlen( tmp ) + strlen( fillme->dot_buffer ) + 1, 408 );
                                                strncat( fillme->dot_buffer, tmp, strlen( tmp ) );
 
-                                               snprintf( tmp, sizeof( tmp ), "%s\t{ router : \"%s\", neighbour : \"%s\", label : %.2f }",
+                                               snprintf( tmp, sizeof( tmp ), "%s{\"router\":\"%s\",\"neighbour\":\"%s\",\"label\":%.2f}",
                                                        (first_line ? "" : ",\n"), from_str, to_str, (float)( orig_node->tq_max / (float)neigh->tq_avg ) );
                                                first_line = 0;
                                                fillme->json_buffer = (char *)debugRealloc( fillme->json_buffer, strlen( tmp ) + strlen( fillme->json_buffer ) + 1, 408 );
@@ -416,7 +418,7 @@
                                        fillme->dot_buffer = (char *)debugRealloc( fillme->dot_buffer, strlen( tmp ) + strlen( fillme->dot_buffer ) + 1, 409 );
                                        strncat( fillme->dot_buffer, tmp, strlen( tmp ) );
 
-                                       snprintf( tmp, sizeof( tmp ), "%s\t{ router : \"%s\", gateway : \"%s/%s\", label : \"HNA\" }",
+                                       snprintf( tmp, sizeof( tmp ), "%s{\"router\":\"%s\",\"gateway\":\"%s/%s\",\"label\":\"HNA\"}",
                                                (first_line ? "" : ",\n"), from_str, to_str, hna_str );
                                        first_line = 0;
                                        fillme->json_buffer = (char *)debugRealloc( fillme->json_buffer, strlen( tmp ) + strlen( fillme->json_buffer ) + 1, 409 );
@@ -432,7 +434,7 @@
                                        strncat( fillme->dot_buffer, tmp, strlen( tmp ) );
 
                                        snprintf( tmp, sizeof( tmp ),
-                                               "%s\t{ router : \"%s\", gateway : \"%s\", label : \"%s\" }",
+                                               "%s{\"router\":\"%s\",\"gateway\":\"%s\",\"label\":\"%s\"}",
                                                (first_line ? "" : ",\n"), from_str, "0.0.0.0/0.0.0.0", "HNA" );
                                        first_line = 0;
                                        fillme->json_buffer = (char *)debugRealloc( fillme->json_buffer, strlen( tmp ) + strlen( fillme->json_buffer ) + 1, 410 );

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

* Re: [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output.
  2011-03-09 17:04 ` Sven Eckelmann
@ 2011-03-10  7:55   ` Alberto Escudero-Pascual
  2011-03-10  8:28     ` Marek Lindner
  0 siblings, 1 reply; 5+ messages in thread
From: Alberto Escudero-Pascual @ 2011-03-10  7:55 UTC (permalink / raw)
  To: Sven Eckelmann; +Cc: b.a.t.m.a.n

Hi Sven,

Here you can get the two files

PATCHED VIS.C

http://dev.villagetelco.org/svn/villagetelco/server/trunk/src/install/vis/vis.c

and

http://dev.villagetelco.org/svn/villagetelco/server/trunk/src/install/vis/vis.c.patch

The patch was applied against the version

http://downloads.open-mesh.org/batman/releases/batman-0.3.2/vis-0.3.2.tar.gz


* The patch fixes three issues
 - Reporting of duplicated entries in the VIS output, this is fixed in
trunk but not in vis.0.3.2
 - Removed a gcc warning related to the use of chdir()
 - Cleaned up the JSON output of vis

Our code is in SVN so I have not git-send-email magic :)

-aep


On 03/09/2011 06:04 PM, Sven Eckelmann wrote:
> On Wednesday 09 March 2011 17:48:32 elektra wrote:
>> The current vis server JSON output format is breaking the json_decode()
>> function for PHP.
>>
>> This patch mainly:
>> - Removes all spaces
>> - Removes all the \t TABS
>> - Double quotes the string-variables
>>
>> Reported-by:  "Alberto Escudero-Pascual" <aep@it46.se>
>> Signed-off-by: "elektra" <onelektra@gmx.net>
> 
> I am not sure if anyone currently maintains batmand and vis.
> 
> Anyway, your patch is more or less scrambled. Can you please resend it using a 
> client which doesn't create a wordwrap and space massacre[1]. Many people here 
> seem to use git-send-email for that purpose.
> 
> Kind regards,
> 	Sven
> 
> [1] http://kernel.org/doc/Documentation/email-clients.txt

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

* Re: [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output.
  2011-03-10  7:55   ` Alberto Escudero-Pascual
@ 2011-03-10  8:28     ` Marek Lindner
  0 siblings, 0 replies; 5+ messages in thread
From: Marek Lindner @ 2011-03-10  8:28 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Alberto Escudero-Pascual

On Thursday 10 March 2011 08:55:36 Alberto Escudero-Pascual wrote:
> * The patch fixes three issues
>  - Reporting of duplicated entries in the VIS output, this is fixed in
> trunk but not in vis.0.3.2
>  - Removed a gcc warning related to the use of chdir()
>  - Cleaned up the JSON output of vis
> 
> Our code is in SVN so I have not git-send-email magic :)

The point is not to make everybody use git - feel free to use other tools (git 
just makes it easy). But sending the patch to the list enables everybody to 
read & comment on the proposed patch and also allows a painless commit.

Broken spacing, broken line endings, patched files in remote SVNs, etc don't 
make reviewing the code a pleasure experience and are most likely to be 
ignored.

Regards,
Marek

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

end of thread, other threads:[~2011-03-10  8:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-09 16:48 [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output elektra
2011-03-09 17:04 ` Sven Eckelmann
2011-03-10  7:55   ` Alberto Escudero-Pascual
2011-03-10  8:28     ` Marek Lindner
  -- strict thread matches above, loose matches on Subject: below --
2011-03-09 17:16 elektra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox