[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] AppleEvents with remote addresses



At 9.09 -0400 1999.08.06, Chris Nandor wrote:
>It was crashing because you were using P, I think.  No need to do that,
>just use a.  You'll note that I packed the length and the string together,
>and used only 33 bytes for the strings, except for the first one, where I
>used 34.  Maybe that should be ca33x?  I also added x25, because there were
>25 extra nulls.  Why?  Beats me.  But it works, so I won't complain.
>Perhaps someone else can figure it out.
>
>I also changed the port type to 520.  Why?  Because it works.  :)  I think
>I very well might have some stuff wrong here, but it does work for me.

>$format = 'lsca34sa4a4x25sca33ca33ca33';
>         #"ls P34sa4a4   s P34 P34 P34"

Ok, I figured almost all of it out.  The x25 is (duh!) padding, because
that could be a 33-byte string if the type were a Str32.  And so this
really is:

  $format = 'lsca33sca33sca33ca33ca33';

where:

l = ID (0 ?)
s = script code (0 = smRoman English ?)
c = length of next
a33 = app name in PPC Browser
s = type (should be 1, but is 2!)
c = length off next
a33 = app id + creator type (rest is null padded)
s = location type
ca33 x 3 = length plus strings

So the only things I don't know are why the port type is 2, not 1, and why
the type code is ep01.  I also don't know if the session ID being set at 0
will be bad, or if the script code might need to change for other
localizations.

Here is a complete program to open a URL in Netscape on another platform.
It would also be nice not to have to put the exact name of the app in,
since this could be Netscape Communicator, Netscape Navigator, etc.  Not a
huge deal, though.

I could add this to the Mac::AppleEvents::Simple module if we figure out
the last remaining problems.

Note to Matthias: sockaddr_ppc switches the order of LocationNameRec and
PPCPortRec compared to what is needed here.  I don't know why.  Are there
different types of PPC addresses?  Or did you just get it wrong?  :)

#!perl -wl
use Mac::AppleEvents;
use Data::Dumper;
use strict;
use vars '$DEBUG';

$DEBUG = 1;

my($targ, $evt, $rep);

$targ = pack_ppc('MOSS', 'Netscape Communicator', 'Orr');

$evt = AEBuildAppleEvent(qw(WWW! OURL),
    typeTargetID, $targ, kAutoGenerateReturnID, kAnyTransactionID,
    "'----':TEXT(\@)", 'http://pudge.net/macperl/') or warn $^E;

if ($evt) {
    print AEPrint $evt if $DEBUG;
    $rep = AESend($evt, kAEWaitReply) or warn $^E;
    print AEPrint $rep if $rep && $DEBUG;
}

AEDisposeDesc($rep) if $rep;
AEDisposeDesc($evt) if $evt;

sub pack_ppc {
    my $format = 'lsca33sca33sca33ca33ca33';
    my $type   = 'PPCToolbox';
    my($id, $name, $server, $zone) = @_;
    $zone ||= '*';
    my @ppcdata = (
        0,                          # session id
        0,                          # script code (smRoman English?)
        length($name), $name,       # as in PPC Chooser
        2,                          # portKindSelector, ppcByCreatorAndType
                                    # should be 1, is 2?
        8,                          # length of port string
        $id . 'ep01',               # port string, why "ep01"?
        1,                          # PPCLocationKind, PPCNBPLocation
        length($server), $server,   # server name
        length($type), $type,       # port type
        length($zone), $zone,       # zone
    );
    my $targ = pack $format, @ppcdata;
    print Dumper [unpack $format, $targ] if $DEBUG;
    return $targ;
}

__END__

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org