From owner-freebsd-arch@FreeBSD.ORG Fri Aug 15 18:46:16 2014 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A673CD6; Fri, 15 Aug 2014 18:46:16 +0000 (UTC) Received: from smtp10.server.rpi.edu (gateway.canit.rpi.edu [128.113.2.230]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 570A229F0; Fri, 15 Aug 2014 18:46:15 +0000 (UTC) Received: from smtp-auth1.server.rpi.edu (route.canit.rpi.edu [128.113.2.231]) by smtp10.server.rpi.edu (8.14.3/8.14.3/Debian-9.4) with ESMTP id s7FIjg9N005936; Fri, 15 Aug 2014 14:45:43 -0400 Received: from smtp-auth1.server.rpi.edu (localhost [127.0.0.1]) by smtp-auth1.server.rpi.edu (Postfix) with ESMTP id DD465580CD; Fri, 15 Aug 2014 14:45:42 -0400 (EDT) Received: from [128.113.24.47] (gilead-qc124.netel.rpi.edu [128.113.124.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: drosih) by smtp-auth1.server.rpi.edu (Postfix) with ESMTPSA id BA06D580B7; Fri, 15 Aug 2014 14:45:42 -0400 (EDT) From: "Garance A Drosehn" To: "Marcel Moolenaar" Subject: Re: XML Output: libxo - provide single API to output TXT, XML, JSON and HTML Date: Fri, 15 Aug 2014 14:45:41 -0400 Message-ID: In-Reply-To: <613EB1A5-2932-446A-A9A2-8CBDD060A00B@xcllnt.net> References: <201408131936.s7DJaA1r089174@idle.juniper.net> <613EB1A5-2932-446A-A9A2-8CBDD060A00B@xcllnt.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: MailMate (1.7.2r3905) X-Virus-Scanned: ClamAV using ClamSMTP X-Bayes-Prob: 0.0001 (Score 0, tokens from: outgoing, @@RPTN) X-Spam-Score: 0.00 () [Hold at 15.10] X-CanIt-Incident-Id: 03MD6JHXh X-CanIt-Geo: ip=128.113.124.17; country=US; region=New York; city=Troy; latitude=42.7495; longitude=-73.5951; http://maps.google.com/maps?q=42.7495,-73.5951&z=6 X-CanItPRO-Stream: outgoing X-Canit-Stats-ID: Bayes signature not available X-Scanned-By: CanIt (www . roaringpenguin . com) on 128.113.2.230 Cc: Marcel Moolenaar , Phil Shafer , John-Mark Gurney , "Simon J. Gerraty" , arch@freebsd.org, Poul-Henning Kamp X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 18:46:16 -0000 On 13 Aug 2014, at 19:02, Marcel Moolenaar wrote: > On Aug 13, 2014, at 12:36 PM, Phil Shafer wrote: >> >> I've a related topic: when an app goes to run a child command, how >> can it determine whether that binary supports libxo-based encoding >> requests? This should be known before the binary is run, since >> there's no means of auto-detecting the supported output after the >> fact. >> >> For example, say I want to make a JSON-based API for my server. I >> can setenv("LIBXO_OPTIONS", "json") to get JSON output, but I won't >> know if the binary supports this or if the output needs to be wrapped >> and escaped. > > Aside: > Using environment variables can be handy, but isn't always. > What do you think about calling a libxo init function from > main() and giving it argc and argv so that libxo options > are parsed and removed just like what xlib does? Here are two alternate ideas for controlling the machine-readable output, in a way where a script can easily tell *if* a command can generate machine-readable output, and we can provide some set of common arguments across all commands which do support that output. 1. For each command, the command could check what name it is started with. If the main() routine sees the command was started as 'xo-netstat', then it generates machine-readable output and supports some extra xo-specific arguments. It is pretty easy to come up with some workable syntax for those arguments if the command has a new command name. 2. some shell for launching an xo-aware command. In this case only one command would be added to the system, and you'd say 'xocmd netstat ...' instead of 'xo-netstat ...'. The special xo-specific parameters would be specified between the 'xocmd' and the standard unix command ('netstat', in this example). If you're wondering how this could be done: How about having each command looking for a weak-external symbol, and it generates the machine-readable output if that loader symbol was resolved when the command started up. Maybe that loader could be the entry point for a large chunk of the libxo library. Thus a unix command running without the libxo support would be only slightly bigger than it is now. Please note that in both cases, I am not saying that anyone would write two separate versions of each unix command. I'm saying = there would still be just one set of source files per unix command, and each unix command would decide which type of output to generate based on how it was launched. -- = Garance Alistair Drosehn =3D drosih@rpi.edu Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA