home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / comm / news102.sit / NewsWatcher / source / dnr.c < prev    next >
Text File  |  1991-04-03  |  4KB  |  174 lines

  1. /*     DNR.c - DNR library for MPW
  2.  
  3.     (c) Copyright 1988 by Apple Computer.  All rights reserved
  4.     
  5. */
  6.  
  7. #ifndef THINK_C
  8. #include <OSUtils.h>
  9. #include <Errors.h>
  10. #include <Files.h>
  11. #include <Resources.h>
  12. #include <Memory.h>
  13. #include <CursorCtl.h>
  14. #endif
  15.  
  16. #include "MacTCPCommonTypes.h"
  17. #include "AddressXLation.h"
  18.  
  19. #define OPENRESOLVER    1L
  20. #define CLOSERESOLVER    2L
  21. #define STRTOADDR        3L
  22. #define    ADDRTOSTR        4L
  23. #define    ENUMCACHE        5L
  24. #define ADDRTONAME        6L
  25.  
  26. Handle codeHndl = 0L;
  27.  
  28. OSErrProcPtr dnr = 0L;
  29.  
  30. short OpenOurRF(void);
  31.  
  32.  
  33. /* OpenOurRF is called to open the MacTCP driver resources */
  34.  
  35. short OpenOurRF(void)
  36. {
  37.     SysEnvRec info;
  38.     HParamBlockRec fi;
  39.     Str255 filename;
  40.  
  41.     SysEnvirons(1, &info);
  42.  
  43.     fi.fileParam.ioCompletion = 0L;
  44.     fi.fileParam.ioNamePtr = filename;
  45.     fi.fileParam.ioVRefNum = info.sysVRefNum;
  46.     fi.fileParam.ioDirID = 0;
  47.     fi.fileParam.ioFDirIndex = 1;
  48.     
  49.     while (PBHGetFInfo(&fi, false) == noErr) {
  50.         /* scan system folder for driver resource files of specific type & creator */
  51.         if (fi.fileParam.ioFlFndrInfo.fdType == 'cdev' &&
  52.             fi.fileParam.ioFlFndrInfo.fdCreator == 'mtcp') {
  53.             /* found the MacTCP driver file */
  54.             SetVol(0,info.sysVRefNum);
  55.             return(OpenResFile(&filename));
  56.             }
  57.         /* check next file in system folder */
  58.         fi.fileParam.ioFDirIndex++;
  59.         fi.fileParam.ioDirID = 0;
  60.         }
  61.     return(-1);
  62.     }    
  63.  
  64.  
  65. OSErr OpenResolver(fileName)
  66. char *fileName;
  67. {
  68.     short refnum;
  69.     OSErr rc;
  70.     
  71.     if (dnr != 0L)
  72.         /* resolver already loaded in */
  73.         return(noErr);
  74.         
  75.     /* open the MacTCP driver to get DNR resources. Search for it based on
  76.        creator & type rather than simply file name */    
  77.     refnum = OpenOurRF();
  78.  
  79.     /* ignore failures since the resource may have been installed in the 
  80.        System file if running on a Mac 512Ke */
  81.        
  82.     /* load in the DNR resource package */
  83.     codeHndl = GetIndResource('dnrp', 1);
  84.     if (codeHndl == 0L) {
  85.         /* can't open DNR */
  86.         return(ResError());
  87.         }
  88.     
  89.     DetachResource(codeHndl);
  90.     if (refnum != -1) {
  91.         CloseResFile(refnum);
  92.         }
  93.         
  94.     /* lock the DNR resource since it cannot be reloated while opened */
  95.     HLock(codeHndl);
  96.     dnr = (OSErrProcPtr) *codeHndl;
  97.     
  98.     /* call open resolver */
  99.     rc = (*dnr)(OPENRESOLVER, fileName);
  100.     if (rc != noErr) {
  101.         /* problem with open resolver, flush it */
  102.         HUnlock(codeHndl);
  103.         DisposHandle(codeHndl);
  104.         dnr = 0L;
  105.         }
  106.     return(rc);
  107.     }
  108.  
  109.  
  110. OSErr CloseResolver(void)
  111. {
  112.     if (dnr == 0L)
  113.         /* resolver not loaded error */
  114.         return(notOpenErr);
  115.         
  116.     /* call close resolver */
  117.     (void) (*dnr)(CLOSERESOLVER);
  118.  
  119.     /* release the DNR resource package */
  120.     HUnlock(codeHndl);
  121.     DisposHandle(codeHndl);
  122.     dnr = 0L;
  123.     return(noErr);
  124.     }
  125.  
  126. OSErr StrToAddr(hostName, rtnStruct, resultproc, userDataPtr)
  127. char *hostName;
  128. struct hostInfo *rtnStruct;
  129. ResultProcPtr resultproc;
  130. char *userDataPtr;
  131. {
  132.     if (dnr == 0L)
  133.         /* resolver not loaded error */
  134.         return(notOpenErr);
  135.     return((*dnr)(STRTOADDR, hostName, rtnStruct, resultproc, userDataPtr));
  136.     }
  137.     
  138. OSErr AddrToStr(addr, addrStr)
  139. unsigned long addr;
  140. char *addrStr;                                    
  141. {
  142.     if (dnr == 0L)
  143.         /* resolver not loaded error */
  144.         return(notOpenErr);
  145.         
  146.     (*dnr)(ADDRTOSTR, addr, addrStr);
  147.     return(noErr);
  148.     }
  149.     
  150. OSErr EnumCache(resultproc, userDataPtr)
  151. ResultProcPtr resultproc;
  152. char *userDataPtr;
  153. {
  154.     if (dnr == 0L)
  155.         /* resolver not loaded error */
  156.         return(notOpenErr);
  157.         
  158.     return((*dnr)(ENUMCACHE, resultproc, userDataPtr));
  159.     }
  160.     
  161.     
  162. OSErr AddrToName(addr, rtnStruct, resultproc, userDataPtr)
  163. unsigned long addr;
  164. struct hostInfo *rtnStruct;
  165. ResultProcPtr resultproc;
  166. char *userDataPtr;                                    
  167. {
  168.     if (dnr == 0L)
  169.         /* resolver not loaded error */
  170.         return(notOpenErr);
  171.         
  172.     return((*dnr)(ADDRTONAME, addr, rtnStruct, resultproc, userDataPtr));
  173.     }
  174.