| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | # (C) 2004 Identity Commons. All Rights Reserved. | ||
| 4 | # See LICENSE for licensing details | ||
| 5 | |||
| 6 | # Author: Fen Labalme <fen@idcommons.net>, <fen@comedia.com> | ||
| 7 | |||
| 8 | # Command line interface to XRI Resolver library | ||
| 9 | # a return value that starts with "$error:" indicates an error | ||
| 10 | |||
| 11 | use XRI 0.2.0; | ||
| 12 | use Getopt::Std; | ||
| 13 | |||
| 14 | $VERSION = '0.2.0'; | ||
| 15 | |||
| 16 | # initialize options system | ||
| 17 | $Getopt::Std::STANDARD_HELP_VERSION = 1; | ||
| 18 | our ($opt_l, $opt_n, $opt_s, $opt_t); | ||
| 19 | getopts('lns:t:'); | ||
| 20 | |||
| 21 | die "Usage: $0 [-n] [-l] [-s service] [-t type] XRI\n" unless $#ARGV == 0; | ||
| 22 | |||
| 23 | getLocalAccess( $ARGV[0] ); | ||
| 24 | |||
| 25 | sub getLocalAccess { | ||
| 26 | my $xri = shift; | ||
| 27 | my $XRI = XRI->new($xri); | ||
| 28 | |||
| 29 | eval { | ||
| 30 | local (*STDERR) = stderr; | ||
| 31 | if ( $opt_n ) { | ||
| 32 | # FIXME: HACK: need to get logging done correctly in XRI library | ||
| 33 | # FIXME: HACK: only turn on logging when option -d is given. | ||
| 34 | open(DN, ">/dev/null") || die "Can't open /dev/null for writing\n"; | ||
| 35 | *STDERR = *DN; | ||
| 36 | } | ||
| 37 | if ( $opt_l || $opt_s || $opt_t ) { | ||
| 38 | $XRI->resolveToLocalAccessURI($opt_s, $opt_t); | ||
| 39 | } | ||
| 40 | else { | ||
| 41 | $XRI->resolveToAuthorityXML; | ||
| 42 | } | ||
| 43 | }; | ||
| 44 | if ( $@ ) { | ||
| 45 | chomp $@; | ||
| 46 | print "\$error: $@"; | ||
| 47 | exit 1; | ||
| 48 | } | ||
| 49 | if ( $opt_l || $opt_s || $opt_t ) { | ||
| 50 | print $XRI->{localAccessURL}; | ||
| 51 | } | ||
| 52 | else { | ||
| 53 | print $XRI->{descriptorXML}; | ||
| 54 | } | ||
| 55 | exit 0; | ||
| 56 | } | ||
| 57 | __END__ |