From owner-freebsd-arch@FreeBSD.ORG Thu Jul 31 01:37:58 2014 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 43931DC6; Thu, 31 Jul 2014 01:37:58 +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 005C5208F; Thu, 31 Jul 2014 01:37:57 +0000 (UTC) Received: from smtp-auth2.server.rpi.edu (smtp-auth2.server.rpi.edu [128.113.2.232]) by smtp10.server.rpi.edu (8.14.3/8.14.3/Debian-9.4) with ESMTP id s6V1btZl018390; Wed, 30 Jul 2014 21:37:55 -0400 Received: from smtp-auth2.server.rpi.edu (localhost [127.0.0.1]) by smtp-auth2.server.rpi.edu (Postfix) with ESMTP id 99F0F1825C; Wed, 30 Jul 2014 21:37:55 -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-auth2.server.rpi.edu (Postfix) with ESMTPSA id 8832918009; Wed, 30 Jul 2014 21:37:55 -0400 (EDT) From: "Garance A Drosehn" To: "Simon Gerraty" Subject: Re: XML Output: libxo - provide single API to output TXT, XML, JSON and HTML Date: Wed, 30 Jul 2014 21:37:54 -0400 Message-ID: <82CFA67F-BA93-44EE-BD4B-9105F89AD157@rpi.edu> In-Reply-To: <20140725044921.9F0D3580A2@chaos.jnpr.net> References: <20140725044921.9F0D3580A2@chaos.jnpr.net> MIME-Version: 1.0 Content-Type: text/plain; format=flowed 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: 03MwNBTaX 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: sjg@freebsd.org, arch@freebsd.org, marcel@freebsd.org, phil@juniper.net X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Jul 2014 01:37:58 -0000 On 25 Jul 2014, at 0:49, Simon Gerraty wrote: > > The following from Phil provides some idea of the functionality > available and the API. > The one shown here uses the default output handle (stdout), but there > are variants that allow multiple output handles. > >> Here's some sample output (from my libxo-ified "w"): >> >> (This uses an environment variable to trigger the mode and options: >> T X J and H are the modes (text, xml, json, html); [...etc...] >> >> % foreach i ( T XP JP HP HPIx ) >> echo === $i === >> env LIBXO_OPTIONS=$i ./xtest -n | head -10 >> end >> === T === >> 6:47PM up 18 days, 2:01, 9 user%s, load averages: 0.00, 0.00, 0.00 >> USER TTY FROM LOGIN@ IDLE WHAT >> phil pts/0 76.182.32.73 5:09PM 33 /bin/sh >> phil pts/1 76.182.32.73 05Jul14 2 >> /usr/bin/perl /u/phil/bin/plum ( >> phil pts/2 76.182.32.73 05Jul14 1 /bin/tcsh >> phil pts/3 76.182.32.73 05Jul14 2days ssh dent >> phil pts/4 76.182.32.73 Tue02PM 2days ssh >> svl-junos-d026.juniper.net >> phil pts/5 76.182.32.73 Wed01AM 2days telnet >> man-o-war 2006 >> phil pts/6 76.182.32.73 Fri10PM 2days ssh >> 198.85.229.65 >> phil pts/7 76.182.32.73 Fri10PM 2days ssh zap >> === XP === >> >> 6:47PM >> 18 days >> 2:01 >> 9 >> 0.00 >> 0.00 >> 0.00 >> >> >> === JP === Do you have links to the library itself? Over the years I've dabbled with doing something like this for the lpr/lpc/lpq programs, so I've done a fair amount of thinking about it. I didn't do as much *work* as either libxo or the GSOC project, but I have done some thinking! Mind you, even that thinking is based only on the lpr-programs, and not a larger set of utilities. I'd suggest that the above isn't quite what one would want, either. For the text version it's fine to have a time-of-day value as '6:47PM', but if you're going for machine-readable output then you'd want that in some format which was much more specific and *standard* (as opposed to arbitrary pretty-printed strings). Something like the ISO 8601 format used in obscure parts of lpd: #define LPD_TIMESTAMP_PATTERN "%Y-%m-%dT%T%z %a" (actually the %a part is not part of ISO 8601, but it is useful for some programs which might want to process the time). Or you might want to print it as a unix-epoch integer. Something that makes it easy for a program to process it. Or you could follow the example of EDN, and use rfc-3339-format (see '#inst' at https://github.com/edn-format/edn). The nice thing about standards is that there are so many to choose from. It's hard to tell based on your sample output, but there's also the question of truncating strings. In the text output of your example, it obviously makes sense to truncate the 'WHAT' value to 'ssh svl-junos-d026.juniper.net', but when printing the same output in a machine-readable format you wouldn't want to truncate it. Let the application which *reads* the data decide how many characters *it* wants to use. -- Garance Alistair Drosehn = drosih@rpi.edu Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA