> I've hacked out some code in perl (I don't know python, but they're very
> close, so a port should be trivial) to implement the --install switch to
> enable plucker:// protocol system from a windows browser. Here is the code
> (it's very short):

        Here's an untested version (I usually get these things right the
first time) that doesn't use the system() command in an insecure way. Using
system() to call arguments directly, subject to shell interpretation, is
generally a very unwise thing to do, and will bite you if you're not
careful. Using system() in "list-mode" is the only way to do that, if you
want to rely on system, since it quite literally, does not use a shell at
all.

        If you want to check STDIN, STDOUT, and STDERR, use IPC::Open3
instead, which is perfectly suited to the task. system() and open() can be
used in this way, as long as you call them in list-context.

        Also, there's no need to use File::Temp, when you can just use $$ as
your filename, which is the pid of the running process. This should give you
some more to go on:

--
use strict;
use URI;

my $url         = $ARGV[0];
my $u           = URI->new($url);
my $plscheme    = "plucker";

my $filename    = "$$.plkr";
my $pl_build    = 'C:\Palmtop\Plucker\plucker-build.exe';
my $pl_install  = 'C:\Palm\Instapp.exe';
my @pl_args     = ('--zlib-compression',
                   '--stayonhost',
                   '--maxdepth=1',
                   '--backup',
                   '--beamable',
                   '--noimages',
                   '-V1',
                   # Add the rest here);

my %pi;
my ($scheme, $auth, $path, $query, $frag)
        = convpl($url, \%pi);

my $newscheme   = 'plucker'
        if ($scheme =~ /https?/);

system($pl_build, @pl_args);

############################################################
#
# Much better to split the URL apart with a module suited
# to the task, than to hand-roll regexes to handle it.
#
############################################################
sub convpl {
        my ($url, $pi) = @_;

        my $scheme      = $u->scheme;
        my $auth        = $u->authority;
        my $path        = $u->path;
        my $query       = $u->query;
        my $frag        = $u->fragment;

        @{$pi}{qw(scheme authority path query fragment)}
                = ($scheme, $auth, $path, $query, $frag);
}
--
_______________________________________________
plucker-dev mailing list
[EMAIL PROTECTED]
http://lists.rubberchicken.org/mailman/listinfo/plucker-dev

Reply via email to