From patchwork Wed Mar 9 16:48:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: elektra X-Patchwork-Id: 862 Return-Path: Received: from mailout-de.gmx.net (mailout-de.gmx.net [213.165.64.23]) by open-mesh.org (Postfix) with SMTP id 90DDD1540CB for ; Wed, 9 Mar 2011 17:48:36 +0100 (CET) Received: (qmail invoked by alias); 09 Mar 2011 16:48:34 -0000 Received: from p579F8213.dip0.t-ipconnect.de (EHLO eee.localnet) [87.159.130.19] by mail.gmx.net (mp063) with SMTP; 09 Mar 2011 17:48:34 +0100 X-Authenticated: #2746672 X-Provags-ID: V01U2FsdGVkX19J3BUzKSBJ9C6jDP8ijAri1v9A6atRcEtIuC2OVf LjKihpNSgPBIEp From: elektra Organization: open-mesh.net To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 9 Mar 2011 17:48:32 +0100 User-Agent: KMail/1.12.2 (Linux/2.6.33.1; KDE/4.3.2; i686; ; ) MIME-Version: 1.0 Message-Id: <201103091748.32512.onelektra@gmx.net> X-Y-GMX-Trusted: 0 Cc: Alberto Escudero-Pascual Subject: [B.A.T.M.A.N.] [Patch] vis: Modified format of JSON output. X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Mar 2011 16:48:36 -0000 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" Signed-off-by: "elektra" + 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 ) ); --- 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 }",