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

Re: [MacPerl] AppleEvents with remote addresses



Success!  Sorta.

I don't know why it works, though, which is a problem.  Perhaps you can
figure it out.  :)

It worked with ircle and with Netscape, sending to one machine.  Let me
know if it works for you, and if possible, _why_ it works for you.  :)

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.

Also, how do you do the logins?  What OSAX?

#!perl -wl
use Mac::AppleEvents::Simple ':all';
use Data::Dumper;

#open STDOUT, ">test.pl.txt" or die $!;

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

$sessionid = 0;                   #  safe to leave 0?
$scriptcode = 0;                  #  May or may not be safe to leave 0
$porttypesel = 520;                 #  PPCPortKinds : ppcByCreatorAndType
$creatortype = "ep01";            #  from empirical observation
$locationtypesel = 1;             #  PPCLocationKind : ppcNBPLocation
#$appname = "Internet Explorer";
#$appsign = "MSIE";
$appname = "ircle3.0" || "Netscape Communicator";
$appsign = "pręC" || "MOSS";
$machine = "Orr";
$porttype = "PPCToolbox";
$zone = "*";  # your zone may vary

$url = "/msg #macperl hi there" || "www.slashdot.org";

# Pascal style strings of type Str32Field
# (which is 34 bytes long for alignment)
#$sappname = pack("ca34", length($appname), $appname);
#$smachine = pack("ca34", length($machine), $machine);
#$sporttype = pack("ca34", length($porttype), $porttype);
#$szone = pack("ca34", length($zone), $zone);
#print $sappname, "\n";


# pack a struct targetID - sessionid, PPCPortRec, LocationNameRec
# significant changes to the format will generate the error:
# "PPCPortRec malformed (OS error -919)."
# perhaps there's an alignment issue somewhere?
@foo = (	$sessionid,
			$scriptcode,
			length($appname),
			$appname,
			$porttypesel,
			$appsign,
			$creatortype,
			$locationtypesel,
			length($machine),
			$machine,
			length($porttype),
			$porttype,
			length($zone),
			$zone);

print Dumper \@foo;

$foo = pack($format,
			$sessionid,
			$scriptcode,
			length($appname),
			$appname,
			$porttypesel,
			$appsign,
			$creatortype,
			$locationtypesel,
			length($machine),
			$machine,
			length($porttype),
			$porttype,
			length($zone),
			$zone
			);

print "< $foo >\n";

#$bar = new AEDesc('targ', $foo) or die $^E;

#$evt = AECreateAppleEvent("WWW!", "OURL", $bar) or die $^E;
#AEPutParamDesc($evt, '----', (AEBuild('TEXT(@)', $url))) or die $^E;

$evt = AEBuildAppleEvent(qw(aevt dosc targ), $foo,
	kAutoGenerateReturnID, kAnyTransactionID,
	"'----':TEXT(\@)", $url) or warn $^E;

# Here we get:
# "Invalid or inappropriate locationKindSelector in location name
# (OS error -902)."
if ($evt) {
	$rep = AESend($evt, kAEWaitReply()) or warn $^E;
}

AEDisposeDesc($rep) if $rep;
AEDisposeDesc($evt) if $evt;
#exit;
$foo = do_event(qw(syso ppcb MACS))->data->data->get;
print "< $foo >\n";
print Dumper [unpack($format, $foo)];

#  Apendix A:  data structures of interest...
#
#  struct TargetID {
#  	long	sessionID;
#  	PPCPortRec	name;
#  	LocationNameRec	location;
#  	PPCPortRec	recvrName;	/* This field is reserved */
#  };
#  typedef struct TargetID	TargetID;
#
#  struct PPCPortRec {
#  	ScriptCode	nameScript;	/* script of name */
#  	Str32Field	name;	/* name of port as seen in browser */
#  	PPCPortKinds	portKindSelector;	/* which variant */
#  	union {
#  		Str32	portTypeStr;		* pascal type string */
#  		struct {
#  			OSType	portCreator;
#  			OSType	portType;
#  		}	port;
#  	}	u;
#  };
#  typedef struct PPCPortRec	PPCPortRec;
#
#  struct LocationNameRec {
#  	PPCLocationKind	locationKindSelector;	/* which variant */
#  	union {
#  		EntityName nbpEntity;	/* NBP name entity */
#  		Str32	 nbpType; /* just the NBP type string, for PPCOpen */
#  	}	u;
#  };
#  typedef struct LocationNameRec	LocationNameRec;
#
#  struct EntityName {
#  	Str32Field	objStr;
#  	Str32Field	typeStr;
#  	Str32Field	zoneStr;
#  };
#  typedef struct EntityName	EntityName;

__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