1*b62679aaSagc#! /usr/bin/env lua 2*b62679aaSagc 3*b62679aaSagc-- 4*b62679aaSagc-- Copyright (c) 2010 The NetBSD Foundation, Inc. 5*b62679aaSagc-- All rights reserved. 6*b62679aaSagc-- 7*b62679aaSagc-- This code is derived from software contributed to The NetBSD Foundation 8*b62679aaSagc-- by Alistair Crooks (agc@netbsd.org) 9*b62679aaSagc-- 10*b62679aaSagc-- Redistribution and use in source and binary forms, with or without 11*b62679aaSagc-- modification, are permitted provided that the following conditions 12*b62679aaSagc-- are met: 13*b62679aaSagc-- 1. Redistributions of source code must retain the above copyright 14*b62679aaSagc-- notice, this list of conditions and the following disclaimer. 15*b62679aaSagc-- 2. Redistributions in binary form must reproduce the above copyright 16*b62679aaSagc-- notice, this list of conditions and the following disclaimer in the 17*b62679aaSagc-- documentation and/or other materials provided with the distribution. 18*b62679aaSagc-- 19*b62679aaSagc-- THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20*b62679aaSagc-- ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21*b62679aaSagc-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*b62679aaSagc-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23*b62679aaSagc-- BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*b62679aaSagc-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*b62679aaSagc-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*b62679aaSagc-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*b62679aaSagc-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*b62679aaSagc-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*b62679aaSagc-- POSSIBILITY OF SUCH DAMAGE. 30*b62679aaSagc-- 31*b62679aaSagc 32*b62679aaSagc-- a short HKP client 33*b62679aaSagc 34*b62679aaSagcrequire("cURL") 35*b62679aaSagc 36*b62679aaSagc-- command line args 37*b62679aaSagcdofile "optparse.lua" 38*b62679aaSagc 39*b62679aaSagcopt = OptionParser{usage="%prog [options] file", version="20100226"} 40*b62679aaSagc 41*b62679aaSagcopt.add_option{"-V", "--version", action="store_true", dest="version", 42*b62679aaSagc help="--version"} 43*b62679aaSagcopt.add_option{"-m", "--mr", action="store_true", dest="mr", help="-m"} 44*b62679aaSagcopt.add_option{"-o", "--op", action="store", dest="op", help="-o op"} 45*b62679aaSagcopt.add_option{"-p", "--port", action="store", dest="port", help="-p port"} 46*b62679aaSagcopt.add_option{"-s", "--server", action="store", dest="server", help="-s server"} 47*b62679aaSagc 48*b62679aaSagc-- parse command line args 49*b62679aaSagcoptions,args = opt.parse_args() 50*b62679aaSagc 51*b62679aaSagc-- set defaults 52*b62679aaSagclocal server = options.server or "pgp.mit.edu" 53*b62679aaSagclocal port = options.port or 11371 54*b62679aaSagclocal op = options.op or "get" 55*b62679aaSagclocal mr = "" 56*b62679aaSagcif options.mr then mr = "&options=mr" end 57*b62679aaSagc 58*b62679aaSagc-- get output stream 59*b62679aaSagcf = io.output() 60*b62679aaSagc 61*b62679aaSagcc = cURL.easy_init() 62*b62679aaSagc 63*b62679aaSagc-- setup url 64*b62679aaSagcc:setopt_url("http://" .. server .. ":" .. port .. 65*b62679aaSagc "/pks/lookup?op=" .. op .. "&search=" .. args[1] .. mr) 66*b62679aaSagc 67*b62679aaSagc-- perform, invokes callbacks 68*b62679aaSagcc:perform({writefunction = function(str) 69*b62679aaSagc f:write(str) 70*b62679aaSagc end}) 71*b62679aaSagc 72*b62679aaSagc-- close output file 73*b62679aaSagcf:close() 74*b62679aaSagc 75