landppc.c

Go to the documentation of this file.
00001 
00002 /*  $Id: landppc.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "landinternal.h"
00029 
00030 
00031 
00032 ATNBPRecHandle hNBPParms; 
00033 
00034 Handle hnamebuf; 
00035 
00036 
00037 pascal boolean landfindfirstnetname (bsname, bstype, bszone) bigstring bsname, bstype, bszone; {
00038 
00039     /* 
00040     requires name, type, and zone of network objects (accepts appropriate wildcards)
00041     returns the first matching object in those same strings.  If no match, the strings
00042     are nil and the function returns FALSE
00043     */
00044     
00045     EntityName searchname;
00046     AddrBlock address;
00047     Boolean flgotnames;
00048     
00049     if ((stringlength (bsname) > 31) || (stringlength (bstype) > 31) || (stringlength (bszone) > 31)) 
00050         return (false); 
00051         
00052     /* our name limit is 254 */
00053 
00054     hnamebuf  = NewHandle ((long)(254 * sizeof(EntityName)));
00055     hNBPParms = (ATNBPRecHandle)NewHandle ((long)sizeof (ATNBPRec));
00056     
00057     if (hNBPParms == nil || hnamebuf == nil)
00058         return(false);
00059     
00060     /* 
00061     note: we have our own type for recognition over then network, and we currently
00062     only work on one zone (the local one)
00063     */
00064     landcopystring(bsname, searchname.objStr);
00065     landcopystring("\pUserLand IAC Net Protocol", searchname.typeStr);
00066     searchname.zoneStr[0] = 1;
00067     searchname.zoneStr[1] = '*';
00068     
00069     /* Do the name binding protocol call. */
00070 
00071     (*hNBPParms)->nbpEntityPtr = &searchname;
00072     MoveHHi (hnamebuf);
00073     HLock (hnamebuf);
00074     (*hNBPParms)->nbpBufPtr = *hnamebuf;
00075     (*hNBPParms)->nbpBufSize = (long)(254 * sizeof(EntityName));
00076     (*hNBPParms)->nbpDataField = 254;
00077     (*hNBPParms)->nbpRetransmitInfo.retransInterval = 4;  /* Half a second. */
00078     (*hNBPParms)->nbpRetransmitInfo.retransCount = 2;
00079 
00080     /* 
00081     Get the names, check for error. If we had an error, or if we didn't get any
00082     names, release memory and return false
00083     */
00084     if (NBPLookup (hNBPParms, false) != noErr || (*hNBPParms)->nbpDataField == 0)
00085     {
00086         flgotnames = false;
00087         bsname[0] = bstype[0] = bszone[0] = 0;
00088         
00089     }   
00090     else
00091     {
00092         NBPExtract (*hnamebuf, (*hNBPParms)->nbpDataField, 1, &searchname, &address);
00093         landcopystring(searchname.objStr, bsname);
00094         flgotnames = true;
00095     } 
00096 
00097     /* unlock the name buffer no matter what happened */
00098     HUnlock(hnamebuf);
00099     
00100     /*
00101     if we didn't get any names, or we only got one, then trash everything: this will
00102     insure that landfindnextnetname will return appropriately
00103     */
00104     if (flgotnames == false || (*hNBPParms)->nbpDataField == 1)
00105     {
00106         DisposHandle((Handle)hnamebuf);
00107         DisposHandle((Handle)hNBPParms);
00108         hnamebuf = nil;
00109         hNBPParms = nil;
00110     }
00111     
00112     return(flgotnames);
00113     
00114 }   
00115 
00116 
00117 pascal boolean landfindnextnetname(bsname, bstype, bszone)
00118 bigstring bsname;
00119 bigstring bstype; 
00120 bigstring bszone;
00121 {
00122 
00123     /*
00124     called successively after the landfindfirstname call. The strings are filled in
00125     with the appropriate data for the matching network object. If there are no more
00126     matches, the strings are nil and the function returns FALSE.
00127     */
00128     
00129     static int ixname = 1;  /* the last name we returned */
00130     AddrBlock address;      /* dummy address block */   
00131     EntityName searchname;  /* the name struct our stuff gets returned in */
00132     
00133     if (hnamebuf == nil || hNBPParms == nil)
00134     {
00135         bsname[0] = bstype[0] = bszone[0] = 0;
00136         return(false);
00137     }
00138     
00139     /* if we got all the names there are to get, then clean up and return */
00140     if (ixname > (*hNBPParms)->nbpDataField)
00141     {
00142         bsname[0] = bstype[0] = bszone[0] = 0;
00143         DisposHandle((Handle)hnamebuf);
00144         DisposHandle((Handle)hNBPParms);
00145         hnamebuf = nil;
00146         hNBPParms = nil;
00147         return(false);
00148     }
00149 
00150     /* 
00151     get the next name out of our buffer. note: don't copy the other strings for
00152     now, since they have no real meaning
00153     */
00154     NBPExtract (*hnamebuf, (*hNBPParms)->nbpDataField, ixname, &searchname, &address);
00155     landcopystring(searchname.objStr, bsname);
00156     
00157     /* update our index of returned names */
00158     ixname++;
00159     
00160     return(true);
00161 
00162 }
00163 
00164 
00165 
00166 static boolean landvisitmachineports (LocationNameRec *ln, landcallback visit) {
00167     
00168     IPCListPortsPBRec pb;
00169     PortInfoRec buf;
00170     PPCPortRec portname;
00171     bigstring bs;
00172     OSErr errcode;
00173         
00174     setstringlength (bs, 1);
00175     
00176     bs [1] = '=';
00177     
00178     pb.startIndex = 0;
00179         
00180     while (true) {
00181     
00182         portname.portKindSelector = ppcNBPLocation; 
00183     
00184         landcopystring (bs, portname.name);
00185     
00186         landcopystring (bs, portname.u.portTypeStr);
00187         
00188         pb.portName = &portname;
00189         
00190         pb.requestCount = 1;
00191         
00192         pb.bufferPtr = (PortInfoArrayPtr) &buf; 
00193         
00194         pb.locationName = ln;
00195         
00196         errcode = IPCListPorts (&pb, nil);
00197         
00198         if (errcode != noErr)
00199             return (false);
00200             
00201         if (pb.actualCount == 0)
00202             return (true);
00203             
00204         if (!visit (buf.name.name))
00205             return (false);
00206         
00207         pb.startIndex++;
00208         } /*while*/
00209     } /*landvisitmachineports*/
00210   
00211 
00212 boolean landvisitport (name) Str32 name; {
00213     
00214     return (true);
00215     } /*landvisitport*/
00216     
00217     
00218 landvisitallports (landcallback visit) {
00219     
00220     /*
00221     See Inside Macintosh, volume VI, page 32-37.
00222     */
00223     
00224     XPPParamBlock pb;
00225     LocationNameRec ln;
00226     char zipbuf [578]; 
00227     OSErr errcode;
00228     
00229     landclearbytes (&pb, longsizeof (pb));
00230     
00231     pb.XCALL.csCode = xCall;
00232     
00233     pb.XCALL.xppSubCode = zipGetZoneList;
00234     
00235     pb.XCALL.xppTimeout = 4; /*four seconds*/
00236     
00237     pb.XCALL.xppRetry = 4; /*four retries*/
00238     
00239     pb.XCALL.zipBuffPtr = (Ptr) &zipbuf;
00240     
00241     pb.XCALL.zipInfoField [0] = (char) 0;
00242     
00243     pb.XCALL.zipInfoField [1] = (char) 0;
00244     
00245     /*
00246     errcode = GetMyZone (&pb, false);
00247     */
00248     
00249     /*
00250     ln.locationKindSelector = ppcNoLocation;
00251     
00252     landvisitmachineports (&ln, &landvisitport);
00253     */
00254     } /*landvisitallports*/
00255     
00256 
00257 landtestlistports (void) {
00258     
00259     bigstring bsname, bstype, bszone;
00260     
00261     return (true);
00262     
00263     Debugger ();
00264     
00265     setstringlength (bsname, 0);
00266     
00267     setstringlength (bstype, 0);
00268     
00269     setstringlength (bszone, 0);
00270     
00271     landfindfirstnetname (bsname, bstype, bszone);
00272     
00273     landvisitallports (&landvisitport);
00274     } /*landtestlistports*/
00275     
00276 
00277         

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