iacnetwork.c

Go to the documentation of this file.
00001 
00002 /*  $Id: iacnetwork.c 1198 2006-04-05 22:03:52Z karstenw $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "frontier.h"
00008 #include "standard.h"
00009 
00010 #include <appletdefs.h>
00011 #include "iac.h"
00012 
00013 #define typeTargetID 'targ'
00014 
00015 
00016 #if TARGET_API_MAC_OS8
00017 
00018 static void MakePascalStringWLen (StringPtr theDest, int theDestLen, char *theSrc, int theSrcLen) {
00019     
00020     /*
00021     10/22/91 dmb: imported this code from Leonard Rosenthal.  Reformmatted 
00022     somewhat, but left variable names as he had them.  comments are his.
00023     
00024     Given a C string, put it into a pascal storage area.    We also make
00025     sure that the length of the pascal string isn't too long (the caller
00026     specifiys the longest length possible). We are passed in the length
00027     of the C string... This makes our life simpler...
00028     */
00029     
00030     theDest [0] = theSrcLen > theDestLen ? theDestLen : theSrcLen;
00031     
00032     BlockMove (theSrc, &(theDest[1]), theDest [0]);
00033     } /*MakePascalStringWLen*/
00034 
00035 
00036 static OSErr HCProgramToPortAndLoc (char *theName, short len, LocationNameRec *theLoc, PortInfoRec *thePort) {
00037     
00038     /*
00039     10/22/91 dmb: imported this code from Leonard Rosenthal.  Reformmatted 
00040     somewhat, but left variable names as he had them.  comments are his.
00041     
00042     Convert a Hypercard program name (<zone>:<mac>:<program>) to a port.
00043     If that program has more than one port open, we take the first port 
00044     we find!
00045     */
00046     //Code change by Timothy Paustian Monday, June 26, 2000 2:02:16 PM
00047     //This routine just won't work. I doubt Hypercard is a big player on OS X
00048     
00049     char *appleZone = 0;
00050     char *macName = 0;
00051     char *progName = 0;
00052     char *theLastChar = 0;
00053     PPCPortRec thePortSearchSpec;
00054     IPCListPortsPBRec thePBRec;
00055     int theErr;
00056     
00057     /*
00058     Assemble a location.    This is a bit of a pain, as we must
00059     carefully unpack the incomming string...
00060     */
00061     
00062     /*
00063     First job -- find the end of the incomming string so we don't
00064     run off into memory...
00065     */
00066     
00067     theLastChar = theName;
00068     
00069     appleZone = theName; /* First thing there... */
00070     
00071     while (--len >= 0) {
00072         
00073         if (*theLastChar == ':') {
00074             
00075             if (!macName) {
00076                 
00077                 macName = theLastChar + 1;
00078                 }
00079             else if (!progName) {
00080                 
00081                 progName = theLastChar + 1;
00082                 }
00083             }
00084         
00085         theLastChar++;
00086         }
00087     
00088     /*
00089     Right, make sure that we got everything...
00090     */
00091     
00092     if ((progName == 0) || (macName == 0))
00093         return (1); /* Random error... */
00094     
00095     /*
00096     Next, assemble a port record that we can use to specify what
00097     the hell we are looking for...  Use a roman script (sorry, guys),
00098     match only names that have our program, and match all types.
00099     That way we will get the first type.
00100     */
00101     
00102     thePortSearchSpec.nameScript = smRoman;
00103     
00104     thePortSearchSpec.portKindSelector = ppcByString;
00105     
00106     MakePascalStringWLen ((StringPtr) thePortSearchSpec.name, 32, progName, (Size)(theLastChar - progName));
00107     
00108     MakePascalStringWLen ((StringPtr) thePortSearchSpec.u.portTypeStr, 32, "=", 1);
00109     
00110     /*
00111     Next job is to fill in the location record that the guy passed
00112     in. The objString is the mac we wish to connect to. The zone
00113     is the apple zone.  We let the type be random...    so we set it
00114     to PPCToolBox as defined by IM VI 6 7-23.
00115     */
00116     
00117     theLoc -> locationKindSelector = ppcNBPLocation;
00118     
00119     /*bundle*/ {
00120         
00121         EntityName *theE = &(theLoc -> u.nbpEntity);
00122     
00123         MakePascalStringWLen ((StringPtr) &(theE -> objStr), 32, macName, (int) (progName - macName - 1));
00124         
00125         MakePascalStringWLen ((StringPtr) &(theE -> typeStr), 32, "PPCToolBox", 10);
00126         
00127         MakePascalStringWLen ((StringPtr) &(theE -> zoneStr), 32, appleZone, (macName - appleZone - 1));
00128         }
00129     
00130     /*
00131     Right.  Finally, we fill in the parameter block we are to pass
00132     to IPCListPorts.
00133     */
00134     
00135     thePBRec.startIndex = 0;
00136     thePBRec.requestCount = 1;
00137     thePBRec.portName = &thePortSearchSpec;
00138     thePBRec.locationName = theLoc;
00139     thePBRec.bufferPtr = thePort;
00140     
00141     /*
00142     Call the damm routine and try to get the stupid port back!
00143     */
00144     //Code change by Timothy Paustian Sunday, June 25, 2000 10:22:24 PM
00145     //This call won't work in carbon. Is it worth supporting?
00146     #if TARGET_API_MAC_CARBON == 1
00147     //I set it to a bogus error that makes some sense, but this is a cop out. :-(
00148     theErr = noResponseErr;
00149     #else   
00150     theErr = IPCListPortsSync (&thePBRec);
00151     #endif
00152     
00153     return (theErr);
00154     } /*HCProgramToPortAndLoc*/
00155 
00156 
00157 static boolean goodstring32 (byte s32 []) {
00158     
00159     byte *s = s32;
00160     short len = *s;
00161     
00162     if ((len == 0) || (len > 32))
00163         return (false);
00164     
00165     while (--len >= 0) {
00166         
00167         if ((*++s) < ' ') /*non-printing character*/
00168             return (false);
00169         }
00170     
00171     return (true);
00172     } /*goodstring32*/
00173 
00174 
00175 static pascal Boolean string2networkaddress (ConstStr255Param bsadr, TargetID *target) {
00176     
00177     /*
00178     10/27/91 dmb: even when HCProgramToPortAndLoc's IPCListPorts call returns noErr,
00179     the network address may be invalid.  so a reality check is done on the port name 
00180     to attempt to verify that something has actually been found
00181     */
00182         
00183     LocationNameRec loc;
00184     PortInfoRec port;
00185     OSErr ec;
00186     
00187     ec = HCProgramToPortAndLoc ((char *) bsadr + 1, stringlength (bsadr), &loc, &port);
00188     
00189     if (ec != noErr) {
00190         
00191         IACglobals.errorcode = ec;
00192         
00193         return (false);
00194         }
00195     
00196     if (!goodstring32 (port.name.name)) { /*make sure it actually found something*/
00197         
00198         IACglobals.errorcode = noResponseErr;
00199         
00200         return (false);
00201         }
00202     
00203     (*target).sessionID = 0;
00204     
00205     (*target).location = loc;
00206     
00207     (*target).name = port.name;
00208     
00209     return (true);
00210     } /*string2networkaddress*/
00211 
00212 #else
00213 
00214 static pascal Boolean string2networkaddress (ConstStr255Param bsadr, TargetID *target) {
00215 #pragma unused(bsadr, target)
00216 
00217     /*
00218     2004-10-21 aradke: Can't do this on Carbon, give up and return bogus error
00219     */
00220 
00221     IACglobals.errorcode = noResponseErr;
00222 
00223     return (false);
00224 
00225     } /*string2networkaddress*/
00226 
00227 #endif
00228 
00229 
00230 Boolean IACnewnetworkverb (ConstStr255Param bsadr, OSType vclass, OSType vtoken, AppleEvent *event) {
00231     
00232     TargetID target;
00233     AEAddressDesc adr; 
00234     OSErr ec;
00235     
00236     if (!string2networkaddress (bsadr, &target))
00237         return (false);
00238     
00239     ec = AECreateDesc (typeTargetID, (Ptr) &target, sizeof (target), &adr);
00240     
00241     if (ec != noErr)
00242         goto exit;
00243     
00244     ec = AECreateAppleEvent (vclass, vtoken, &adr, kAutoGenerateReturnID, kAnyTransactionID, event);
00245     
00246     /*AEDisposeDesc (&adr);*/
00247     
00248     exit:
00249     
00250     IACglobals.errorcode = ec;
00251     
00252     return (ec == noErr);
00253     } /*IACnewnetworkverb*/
00254 

Generated on Wed May 31 18:19:48 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6