public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: elektra <onelektra@gmx.net>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Alberto Escudero-Pascual <aep@it46.se>
Subject: [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output.
Date: Wed, 9 Mar 2011 17:48:32 +0100	[thread overview]
Message-ID: <201103091748.32512.onelektra@gmx.net> (raw)

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 ) );
 

             reply	other threads:[~2011-03-09 16:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09 16:48 elektra [this message]
2011-03-09 17:04 ` [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201103091748.32512.onelektra@gmx.net \
    --to=onelektra@gmx.net \
    --cc=aep@it46.se \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox