home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / ip / ppp / mac / macppp2.0.1-src.hqx / MacPPP 2.0.1 src / pppcdev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-20  |  45.9 KB  |  1,700 lines

  1. /*
  2.  *  pppcdev.c    -- The Control Panel for MacPPP
  3.  *
  4.  * Copyright (c) 1992-1993 Merit Network, Inc. and The Regents of the
  5.  *  University of Michigan.  Usage of this source code is restricted
  6.  *  to non-profit, non-commercial purposes.  The source is provided
  7.  *  "as-is", without warranty.
  8.  */
  9. #include "ppp.h"
  10. #include <GestaltEqu.h>
  11. #include <CommResources.h>
  12. #include <CRMSerialDevices.h>
  13. #include <Folders.h>
  14. #include <Menus.h>
  15. #include <ToolUtils.h>
  16.  
  17. /* Trap numbers */
  18. #define TN_UnknownOS        0xA09F
  19. #define TN_CommToolbox        0xA08B
  20.  
  21. /* Menus */
  22. #define BAUDMENU -4033
  23. #define PORTMENU -4034
  24. #define IDLEMENU -4035
  25. #define SERVERMENU -4036
  26. #define ECHOMENU -4037
  27. #define FLOWMENU -4038
  28.  
  29. /* ICONs */
  30. #define PPPUPICON -4033
  31. #define PPPDOWNICON -4034
  32.  
  33. /* Default preferences resources */
  34. #define DEFAULTPREF -4033
  35. #define DEFAULTLCP -4034
  36. #define DEFAULTIPCP -4035
  37. #define DEFAULTCNFGNAME -4036
  38.  
  39. /* STR# resources */
  40. #define STATUSSTRINGS -4033
  41. #define CANNEDPORTS -4034
  42.  
  43. /* status strings */
  44. #define ACCMMESS 1        /* invalid ACCM */
  45. #define MRUMESS 2        /* invalid MRU */
  46. #define IPMESS 3        /* invalid IP address */
  47. #define STRINGMESS 4    /* string too long */
  48. #define PREFSCMESS 5    /* Pref file create error */
  49. #define PREFSOMESS 6    /* Pref file open error */
  50. #define PREFSRMESS 7    /* Pref file read error */
  51. #define PREFSWMESS 8    /* Pref file write error */
  52. #define OLDPREFSMESS 9    /* there's an old version of the preferences file */
  53. #define CONFIGMESS 10    /* must be more than one config for deletion */
  54. #define NULLMESS 11        /* null length server name */
  55. #define SAMEMESS 12        /* name is the same as another server */
  56.  
  57. /* number for Preferences file name */
  58. #define PREFFILENAME -4033
  59. #define SYS6FOLDER -4034
  60.  
  61. /* Dialog numbers */
  62. #define SCRIPTDLOG -4033
  63. #define CONNECTDLOG -4034
  64. #define LCPDLOG -4035
  65. #define STATSDLOG -4036
  66. #define AUTHDLOG -4037
  67. #define IPCPDLOG -4038
  68. #define ASKDLOG -4039
  69. #define NEWDLOG -4040
  70.  
  71. /* Alerts */
  72. #define ERRALERT -4033
  73. #define OLDPREFSALERT -4034
  74.  
  75. /* cdev dialog items (add numitems to these) */
  76. #define OPENBTN 1
  77. #define SOFTCLOSEBTN 2
  78. #define HARDCLOSEBTN 3
  79. #define STATSBTN 4
  80. #define PTITLERECT 5
  81. #define PORTRECT 6
  82. #define    ITITLERECT 7
  83. #define IDLERECT 8
  84. #define ETITLERECT 9
  85. #define ECHORECT 10
  86. #define STITLERECT 11
  87. #define SERVERRECT 12
  88. #define CONFIGBTN 13
  89. #define NEWBTN 14
  90. #define DELETEBTN 15
  91. #define TERMCHECK 16
  92. #define HANGUPCHECK 17
  93. #define QUIETCHECK 18
  94. #define PPPICON 19
  95.  
  96. /* config dialog */
  97. #define SERVERNAME 3
  98. #define BTITLERECT 4
  99. #define BAUDRECT 5
  100. #define FTITLERECT 19
  101. #define    FLOWRECT 20
  102. #define TONEBTN 17
  103. #define PULSEBTN 18
  104. #define PHONENUM 8
  105. #define MODEMINIT 9
  106. #define SCRIPTBTN 10
  107. #define AUTHBTN 11
  108. #define LCPBTN 12
  109. #define IPCPBTN 13
  110. #define CONNECTTIME 15
  111.  
  112. /* connect script dialog */
  113. #define COMMANDBTNS 3
  114. #define COMMANDS 19
  115. #define ADDRETURNS 28
  116. #define WAITTIME 37
  117.  
  118. /* auth fields */
  119. #define AUTHID 3
  120. #define AUTHPW 4
  121. #define AUTHRETRIES 9
  122. #define AUTHTIMEOUT 11
  123.  
  124. /* LCP options dialog items */
  125. #define LCPDEFAULT 3
  126. #define PFCBOXES 15
  127. #define ACFCBOXES 19
  128. #define AUTHENTBOXES 23
  129. #define MAGICBOXES 27
  130. #define    ACCMBOXES 33
  131. #define MRUBOXES 39
  132. #define LCPRETRIES 46
  133. #define LCPTIMEOUT 48
  134.  
  135. /* IPCP options dialog items */
  136. #define IPCPDEFAULT 3
  137. #define COMPRESSBOXES 8
  138. #define ADDRESSBOXES 12
  139. #define IPCPRETRIES 21
  140. #define IPCPTIMEOUT 23
  141.  
  142. /* stats boxes */
  143. #define UPDATEBTN 2
  144. #define    INOCTETS 13
  145. #define OUTOCTETS 14
  146. #define INPACKETS 15
  147. #define OUTPACKETS 16
  148. #define CHECKSEQERRS 17
  149. #define HEADERERRS 18
  150. #define HWOVERRUNS 19
  151. #define SWOVERRUNS 20
  152. #define FRAMINGERRS 21
  153. #define OUTOFBUFS 22
  154. #define PFCVALS 35
  155. #define ACFCVALS 37
  156. #define PAPVALS 39
  157. #define MAGICVALS 41
  158. #define ACCMVALS 43
  159. #define MRUVALS 45
  160. #define VJVALS 47
  161. #define VJSLOTS 55
  162. #define VJCID 59
  163. #define IPADDRVALS 49
  164.  
  165. /* new server dialog */
  166. #define PPPSERVNAME 4
  167.  
  168. struct mydlogrec {
  169.     DialogRecord    adlogrec;
  170.     b_8            *strptr;
  171. };
  172.  
  173. struct cdevstore {
  174.     struct popup {
  175.         MenuHandle    menuh;        /* Handle to popupmenu */
  176.         Rect        poprect;    /* rectangle to do popupmenu */
  177.         Rect        titlerect;    /* rectangle to invert */
  178.         } port, baud, idle, server, echo, flow;
  179.     b_8        saved_state;
  180.     short    prefref;                /* file ref for PPP preferences */
  181.     struct lcpconfig deflcp;    /* default LCP settings */
  182.     struct ipcpconfig defipcp;    /* default IPCP settings */
  183.     struct ppp_pref prefdata;    /* Preferences data */
  184.     struct ppp_config prefcnfg;    /* current config settings */
  185.     };
  186.  
  187. void AppendStr(b_8 *, b_8 *);
  188. void MyNoteAlert(b_8);
  189. void updatecp(struct cdevstore *, DialogPtr, short);
  190. OSErr updateprefs(struct cdevstore *);
  191. OSErr readconfig(struct cdevstore *, short);
  192. void initconfigs(struct cdevstore *);
  193. void dostatsdlog(), doauthdlog(struct cdevstore *);
  194. void dolcpdlog(struct cdevstore *), doipcpdlog(struct cdevstore *);
  195. void doconfigdlog (struct cdevstore *), doscriptdlog(struct cdevstore *);
  196. long DoPopInt(struct popup *, unsigned short *);
  197. long DoPopUp(struct popup *, b_8 *);
  198. void drawpopup(struct popup *, DialogPtr, b_8 *);
  199. void drawpopint(struct popup *, DialogPtr, unsigned short);
  200. pascal    Boolean dumbfilter(DialogPtr, EventRecord *, short *);
  201. Boolean gettext(DialogPtr, short, b_8 *);
  202. Boolean getbyte(DialogPtr, short, b_8 *);
  203. void dosetctlval(DialogPtr, short, short);
  204. void dosetilong(DialogPtr, short, b_32);
  205. void dosetitext(DialogPtr, short, b_8 *);
  206. void dosethex(DialogPtr, short, b_32);
  207. void dosetipaddr(DialogPtr, short, b_32);
  208. void dosetcbox(DialogPtr, short, short);
  209. void getnegval(DialogPtr, short, short, b_16 *);
  210. void setbuttons(struct cdevstore *, DialogPtr, short);
  211.  
  212. pascal long pppcdev(short msg, short item, short numitems, short cpid, EventRecord *evt,
  213.                         struct cdevstore *p, DialogPtr dlogp)
  214. {
  215. LapInfo        *lap;
  216. Handle        itemH;
  217. Str63        workstr, holdstr;
  218. short        i, j, type, itemhit;
  219. unsigned short        curconfig;
  220. long        rv;
  221. Rect        box;
  222. OSErr        onewresult, oresult;
  223. DialogPtr    askdlog;
  224.  
  225.     if ( msg == macDev )
  226.         return(1L);     /* this will work anywhere */
  227.     else if ( msg == initDev ) {
  228.         struct        cdevstore *tempcdev;
  229.         Handle        tempH;
  230.         short        rn, prefVol;
  231.         long        prefDir, count;
  232.         Boolean        commtoolbox, HaveFindFolder, HavePrefFolder;
  233.  
  234.         /* get some mem.  I suppose this should be Handle instead. */
  235.         tempcdev = (struct cdevstore *)NewPtr(sizeof(struct cdevstore));
  236.         if (tempcdev == 0L)
  237.             return (0L);
  238.         
  239.         if (commtoolbox = 
  240.             (NGetTrapAddress(TN_CommToolbox, OSTrap) != GetTrapAddress(TN_UnknownOS)))
  241.             InitCRM();
  242.         /* try to find our Preferences folder and open Prefs file */
  243.         HaveFindFolder = HavePrefFolder = false;
  244.         if ( Gestalt(gestaltFindFolderAttr, &rv) == noErr) {
  245.             if ( ( 1L << gestaltFindFolderPresent ) & rv ) {
  246.                 HaveFindFolder = true;
  247.                 if ( FindFolder(kOnSystemDisk,kPreferencesFolderType,
  248.                     kCreateFolder,&prefVol,&prefDir) == noErr)
  249.                     HavePrefFolder = true;
  250.             }
  251.         }
  252.         
  253.         workstr[0] = 0;
  254.         if (!HavePrefFolder) {
  255.             tempH = GetResource('STR ',SYS6FOLDER); /* system 6 folder */
  256.             AppendStr(workstr, *((b_8 **) tempH));
  257.             ReleaseResource(tempH);
  258.         }
  259.         tempH = GetResource('STR ',PREFFILENAME); /* get pref file */
  260.         AppendStr(workstr, *((b_8 **) tempH));
  261.         ReleaseResource(tempH);
  262.         
  263.         rn = -1;
  264.         if (HavePrefFolder) {
  265.             if ( (oresult = HOpen(prefVol,prefDir,workstr,fsRdWrPerm,&rn)) == fnfErr ) {
  266.                 HCreate(prefVol,prefDir,workstr,'Mppp','PREF');
  267.                 onewresult = HOpen(prefVol,prefDir,workstr,fsRdWrPerm,&rn);
  268.             }
  269.         /* if we don't have PrefFolder, just use System Folder */
  270.         } else {
  271.             GetVRefNum(SysMap, &prefVol);    /* get system Vol ref */
  272.             if ( (oresult = FSOpen(workstr,prefVol,&rn)) == fnfErr ) {
  273.                 Create(workstr,prefVol,'Mppp','PREF');
  274.                 onewresult = FSOpen(workstr,prefVol,&rn);
  275.             }
  276.         }
  277.         
  278.         tempH = GetResource('cnfg',DEFAULTLCP);
  279.         tempcdev->deflcp = **((struct lcpconfig **) tempH);
  280.         ReleaseResource(tempH);
  281.         tempH = GetResource('cnfg',DEFAULTIPCP);
  282.         tempcdev->defipcp = **((struct ipcpconfig **) tempH);
  283.         ReleaseResource(tempH);
  284.  
  285.         tempcdev->prefref = rn;
  286.  
  287.         if ( oresult == fnfErr ) {
  288.             if (onewresult != noErr) {
  289.                 MyNoteAlert(PREFSCMESS);
  290.                 DisposePtr((Ptr) tempcdev);
  291.                 return (-1);
  292.             }
  293. new_configs:
  294.             tempH = GetResource('cnfg',DEFAULTPREF);
  295.             tempcdev->prefdata = **((struct ppp_pref **) tempH);    /* copy struct */
  296.             ReleaseResource(tempH);
  297.             initconfigs(tempcdev);
  298.             tempH = GetResource('cnfg',DEFAULTCNFGNAME);
  299.             AppendStr(tempcdev->prefcnfg.config_name, *((b_8 **) tempH));
  300.             ReleaseResource(tempH);
  301.             updateprefs(tempcdev);
  302.         } else if (rn != -1 && oresult == noErr) {
  303.             count = sizeof (struct ppp_pref);
  304.             oresult = FSRead(rn, &count, &(tempcdev->prefdata));
  305.             if (tempcdev->prefdata.version < PREF_VERSION) {
  306.                 if (NoteAlert(OLDPREFSALERT,nil) == OK)
  307.                     goto new_configs;
  308.                 else {
  309.                     FSClose(rn);
  310.                     DisposePtr((Ptr) tempcdev);
  311.                     return (-1);
  312.                 }
  313.             }
  314.         } else {
  315.             MyNoteAlert(PREFSOMESS);
  316.             DisposePtr((Ptr) tempcdev);
  317.             return (-1);
  318.         }
  319.  
  320.                 /* get the pop-up menus */
  321.  
  322.         tempcdev->server.menuh = GetMenu(SERVERMENU);
  323.         for (i=0 ; i < tempcdev->prefdata.max_config; i++ ) {
  324.             if ( readconfig(tempcdev, i) != noErr) {
  325.                 ReleaseResource((Handle) tempcdev->server.menuh);
  326.                 FSClose(rn);
  327.                 DisposePtr((Ptr) tempcdev);
  328.                 return (-1);
  329.             }
  330.             AppendMenu(tempcdev->server.menuh, "\p ");
  331.             SetItem(tempcdev->server.menuh, i + 1, 
  332.                         tempcdev->prefcnfg.config_name);
  333.         }
  334.         readconfig(tempcdev, tempcdev->prefdata.active_config);
  335.         tempcdev->baud.menuh = GetMenu(BAUDMENU);
  336.         tempcdev->flow.menuh = GetMenu(FLOWMENU);
  337.         tempcdev->idle.menuh = GetMenu(IDLEMENU);
  338.         tempcdev->port.menuh = GetMenu(PORTMENU);
  339.         tempcdev->echo.menuh = GetMenu(ECHOMENU);
  340.         if (commtoolbox) {
  341.             CRMRec *crmrecptr, acrmrec;
  342.             CRMSerialRecord *serrec;
  343.             long old = 0;
  344.             short index = 1;
  345.  
  346.             acrmrec.qType = crmType;
  347.             while (true) {
  348.                 acrmrec.crmDeviceType = crmSerialDevice;
  349.                 acrmrec.crmDeviceID = old;
  350.                 if (!(crmrecptr = (CRMRec *)CRMSearch((QElemPtr)(&acrmrec))))
  351.                     break;
  352.                 serrec = (CRMSerialRecord *)crmrecptr->crmAttributes;
  353.                 /* must do a set item because of special characters */
  354.                 AppendMenu(tempcdev->port.menuh, "\p ");
  355.                 SetItem(tempcdev->port.menuh, index, *(serrec->name));
  356.                 old = crmrecptr->crmDeviceID;
  357.                 ++index;
  358.             }
  359.         } else {
  360.             AddResMenu(tempcdev->port.menuh, 'Port');
  361.         }
  362.         /* get port rects */
  363.         GetDItem(dlogp, PORTRECT + numitems, &type, &itemH, &(tempcdev->port.poprect));
  364.         GetDItem(dlogp, PTITLERECT + numitems, &type, &itemH, &(tempcdev->port.titlerect));
  365.         /* get idle timeout rects */
  366.         GetDItem(dlogp, IDLERECT + numitems, &type, &itemH, &(tempcdev->idle.poprect));
  367.         GetDItem(dlogp, ITITLERECT + numitems, &type, &itemH, &(tempcdev->idle.titlerect));
  368.         /* get server rects */
  369.         GetDItem(dlogp, SERVERRECT + numitems, &type, &itemH, &(tempcdev->server.poprect));
  370.         GetDItem(dlogp, STITLERECT + numitems, &type, &itemH, &(tempcdev->server.titlerect));
  371.         /* get LCP echo interval rects */
  372.         GetDItem(dlogp, ECHORECT + numitems, &type, &itemH, &(tempcdev->echo.poprect));
  373.         GetDItem(dlogp, ETITLERECT + numitems, &type, &itemH, &(tempcdev->echo.titlerect));
  374.  
  375.         /* term window checkbox */
  376.         if (tempcdev->prefdata.use_term)
  377.             dosetctlval(dlogp, TERMCHECK + numitems, 1);
  378.         /* hangup checkbox */
  379.         if (tempcdev->prefdata.hangup)
  380.             dosetctlval(dlogp, HANGUPCHECK + numitems, 1);
  381.         /* quiet checkbox */
  382.         if (tempcdev->prefdata.quiet)
  383.             dosetctlval(dlogp, QUIETCHECK + numitems, 1);
  384.         setbuttons(tempcdev, dlogp, numitems);
  385.  
  386.         return (long)tempcdev;
  387.     }
  388.     
  389.   if ( (long)p != cdevUnset && (long)p != 0L ) {
  390.     
  391.     switch (msg) {
  392.  
  393.     case nulDev:
  394.         if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
  395.             if (lap) {
  396.                 if  (lap->ppp_fsm[IPcp].state != p->saved_state)
  397.                     setbuttons(p, dlogp, numitems);
  398.             }
  399.         }
  400.         break;
  401.  
  402.     case updateDev:
  403.         updatecp(p, dlogp, numitems);
  404.         break;
  405.         
  406.     case closeDev:
  407.         updateprefs(p);    /* update the preferences file */
  408.         FSClose(p->prefref);    /* close the Preferences file */
  409.         ReleaseResource((Handle) p->baud.menuh);
  410.         ReleaseResource((Handle) p->flow.menuh);
  411.         ReleaseResource((Handle) p->port.menuh);
  412.         ReleaseResource((Handle) p->idle.menuh);
  413.         ReleaseResource((Handle) p->echo.menuh);
  414.         ReleaseResource((Handle) p->server.menuh);
  415.         DisposPtr((Ptr) p);            /* release our memory */
  416.         break;
  417.  
  418.     case hitDev:
  419.         GetDItem(dlogp, item, &type, &itemH, &box);
  420.         switch (item-numitems) {
  421.     
  422.         case SOFTCLOSEBTN:
  423.         case HARDCLOSEBTN:
  424.             if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
  425.                 if (lap && lap->lapClose && lap->transProc) {
  426.                     (*(lap->lapClose))(lap);    /* close PPP */
  427.                     if ( (item - numitems) == SOFTCLOSEBTN) {
  428.                         lap->ppp_flags |= CLOSE_PPP;
  429.                         (*(lap->transProc))(TransitionOpen);
  430.                     }
  431.                     updatecp(p, dlogp, numitems);
  432.                 }
  433.             }
  434.             break;
  435.     
  436.         case OPENBTN:
  437.             if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
  438.                 if (lap) {
  439.                     if (lap->transProc == nil) {
  440.                         if (noErr == OpenDriver("\p.IPP",&type)) {    /* open TCP */
  441.                         CntrlParam tiopb;
  442. #define ipctlGetAddr        15            /* csCode to get our IP address */
  443.                             bzero((b_8 *)&tiopb, sizeof(tiopb));
  444.                             tiopb.ioCRefNum = type;
  445.                             tiopb.csCode = ipctlGetAddr;
  446.                             PBControl((ParamBlockRec *) &tiopb, false);
  447.                         }
  448.                     } else
  449.                         (*(lap->transProc))(TransitionOpen);
  450.                     updatecp(p, dlogp, numitems);
  451.                 }
  452.             }
  453.             break;
  454.  
  455.         case PORTRECT:
  456.             DoPopUp(&(p->port), p->prefdata.portname);
  457.             drawpopup(&(p->port), dlogp, p->prefdata.portname);
  458.             updateprefs(p);    /* update the preferences file */
  459.             break;
  460.  
  461.         case IDLERECT:
  462.             DoPopInt(&(p->idle), &(p->prefdata.timeout));
  463.             drawpopint(&(p->idle), dlogp, p->prefdata.timeout);
  464.             updateprefs(p);    /* update the preferences file */
  465.             break;
  466.  
  467.         case ECHORECT:
  468.             DoPopInt(&(p->echo), &(p->prefdata.echo));
  469.             drawpopint(&(p->echo), dlogp, p->prefdata.echo);
  470.             updateprefs(p);    /* update the preferences file */
  471.             break;
  472.  
  473.         case SERVERRECT:
  474.             workstr[0] = 0;
  475.             AppendStr(workstr, p->prefcnfg.config_name);
  476.             rv = DoPopUp(&(p->server), workstr);
  477.             if (HiWord(rv) != 0) {
  478.                 p->prefdata.active_config = LoWord(rv) - 1;
  479.                 readconfig(p, p->prefdata.active_config);
  480.                 updateprefs(p);    /* update the preferences file */
  481.             }
  482.             drawpopup(&(p->server), dlogp, workstr);
  483.             break;
  484.  
  485.         case TERMCHECK:
  486.             SetCtlValue((ControlHandle) itemH, (p->prefdata.use_term =
  487.                 GetCtlValue((ControlHandle) itemH) ^ 1));
  488.             updateprefs(p);    /* update the preferences file */
  489.             break;
  490.  
  491.         case HANGUPCHECK:
  492.             SetCtlValue((ControlHandle) itemH, (p->prefdata.hangup =
  493.                 GetCtlValue((ControlHandle) itemH) ^ 1));
  494.             updateprefs(p);    /* update the preferences file */
  495.             break;
  496.  
  497.         case QUIETCHECK:
  498.             SetCtlValue((ControlHandle) itemH, (p->prefdata.quiet =
  499.                 GetCtlValue((ControlHandle) itemH) ^ 1));
  500.             updateprefs(p);    /* update the preferences file */
  501.             break;
  502.  
  503.         case STATSBTN:
  504.             dostatsdlog();
  505.             break;
  506.  
  507.         case CONFIGBTN:
  508.             doconfigdlog(p);
  509.             updatecp(p, dlogp, numitems);
  510.             break;
  511.             
  512.         case DELETEBTN:
  513.             if (p->prefdata.max_config == 1) {
  514.                 MyNoteAlert(CONFIGMESS);
  515.                 break;
  516.             }
  517.             ParamText(p->prefcnfg.config_name, "\p", "\p", "\p");
  518.             askdlog = GetNewDialog(ASKDLOG, 0L, (WindowPtr) -1L);
  519.             do {
  520.                 ModalDialog(nil, &itemhit);
  521.             } while (itemhit == 0);
  522.             DisposDialog(askdlog);
  523.             if (itemhit != OK)
  524.                 break;
  525.             ReleaseResource((Handle) p->server.menuh);
  526.             p->server.menuh = GetMenu(SERVERMENU);
  527.             --(p->prefdata.max_config);
  528.             curconfig = p->prefdata.active_config;
  529.             p->prefdata.active_config = 0;
  530.             i = 1;
  531.             for (j = 0 ; j <= p->prefdata.max_config; j++ ) {
  532.                 readconfig(p, j);
  533.                 if (j == curconfig)
  534.                     continue;
  535.                 updateprefs(p);
  536.                 (p->prefdata.active_config)++;
  537.                 AppendMenu(p->server.menuh, "\p ");
  538.                 SetItem(p->server.menuh, i, p->prefcnfg.config_name);
  539.                 i++;
  540.             }
  541.             if ( curconfig == p->prefdata.max_config )
  542.                 --curconfig;
  543.             p->prefdata.active_config = curconfig;
  544.             readconfig(p, curconfig);
  545.             drawpopup(&(p->server), dlogp, p->prefcnfg.config_name);
  546.             break;
  547.             
  548.         case NEWBTN:
  549.             askdlog = GetNewDialog(NEWDLOG, 0L, (WindowPtr) -1L);
  550.             do {
  551.                 ModalDialog(nil, &itemhit);
  552.             } while (itemhit != OK && itemhit != Cancel);
  553.             if (!gettext(askdlog, PPPSERVNAME, workstr)) {
  554.                 DisposDialog(askdlog);
  555.                 break;
  556.             }
  557.             DisposDialog(askdlog);
  558.             if (itemhit != OK)
  559.                 break;
  560.             if (workstr[0] == 0) {
  561.                 MyNoteAlert(NULLMESS);
  562.                 break;
  563.             }
  564.             for (j = 1 ; j <= p->prefdata.max_config; j++ ) {
  565.                 GetItem(p->server.menuh, j, holdstr);
  566.                 if (EqualString(workstr, holdstr, true, false)) {
  567.                     MyNoteAlert(SAMEMESS);
  568.                     goto badstring;
  569.                 }
  570.             }
  571.             /* we are adding a new server entry, init a new entry */
  572.             initconfigs(p);
  573.             AppendStr(p->prefcnfg.config_name, workstr);        
  574.             AppendMenu(p->server.menuh,"\p ");
  575.             p->prefdata.active_config = p->prefdata.max_config++;
  576.             SetItem(p->server.menuh, p->prefdata.max_config, p->prefcnfg.config_name);
  577.             updateprefs(p);
  578.             drawpopup(&(p->server), dlogp, p->prefcnfg.config_name);
  579. badstring:
  580.             break;
  581.  
  582.         default:
  583.             break;
  584.         }
  585.     default:
  586.         break;
  587.     }
  588.   }
  589.   return (long)p;
  590. }
  591.  
  592. void
  593. updatecp(struct cdevstore *p, DialogPtr dlogp, short numitems)
  594. {
  595.     drawpopup(&(p->port), dlogp, p->prefdata.portname);
  596.     drawpopint(&(p->idle), dlogp, p->prefdata.timeout);
  597.     drawpopint(&(p->echo), dlogp, p->prefdata.echo);
  598.     drawpopup(&(p->server), dlogp, p->prefcnfg.config_name);
  599.     setbuttons(p, dlogp, numitems);
  600. }
  601.  
  602. void
  603. drawpopint(struct popup *p, DialogPtr dlogp, unsigned short value)
  604. {
  605.     b_8    popstring[24];
  606.     unsigned long tempvalue;
  607.  
  608.     if (value == 0)
  609.         GetItem(p->menuh, 1, popstring); /* use first item if 0 */
  610.     else {
  611.         tempvalue = value;
  612.         NumToString(tempvalue, popstring);
  613.     }
  614.     drawpopup(p, dlogp, popstring);
  615. }
  616.  
  617. void            
  618. drawpopup(struct popup *p, DialogPtr dlogp, b_8 *popstring)
  619. {
  620. short        savfont,savsize,i;
  621. GrafPtr    savport;
  622. Rect    r;
  623.  
  624.     GetPort(&savport);
  625.     SetPort(dlogp);
  626.     savfont = dlogp->txFont;
  627.     savsize = dlogp->txSize;
  628.     TextFont(0);
  629.     TextSize(12);
  630.     p->poprect.bottom++;
  631.     EraseRect(&(p->poprect));
  632.     p->poprect.bottom--;
  633.     /* calc pop up rectangle based on width of menu items */
  634.     SetRect(&r, p->poprect.left,
  635.                 p->poprect.top,
  636.                 p->poprect.left + StringWidth(popstring) + 24,
  637.                 p->poprect.bottom);
  638.                 
  639.     MoveTo(p->titlerect.left, p->titlerect.bottom-4);
  640.     DrawString((b_8 *) &(**p->menuh).menuData);
  641.     MoveTo(p->poprect.left+4,p->poprect.bottom-4);
  642.     DrawString(popstring);
  643.  
  644.     FrameRect(&r);
  645.     /* This must be the stupidest way to shadow a rect */    
  646.     MoveTo(r.left+3, r.bottom);
  647.     LineTo(r.right, r.bottom);
  648.     LineTo(r.right, r.top+3);
  649.     /* draw the menu indicator thingy */
  650.     for (i = 0; i < 6; ++i)    {
  651.         MoveTo(r.right - 10 - i, r.bottom - 7 - i);
  652.         Line(2*i, 0);
  653.     }
  654.     TextFont(savfont);
  655.     TextSize(savsize);
  656.     SetPort(savport);
  657. }
  658.  
  659. void dosetitext(DialogPtr dlogp, short itemnum, b_8 *string)
  660. {
  661. short        type;
  662. Handle    itemH;
  663. Rect    box;
  664.  
  665.     GetDItem(dlogp, itemnum, &type, &itemH, &box);
  666.     SetIText(itemH, string);
  667. }
  668.  
  669. void dosetctlval(DialogPtr dlogp, short itemnum, short value)
  670. {
  671. short    type;
  672. Handle    itemH;
  673. Rect    box;
  674.  
  675.     GetDItem(dlogp, itemnum, &type, &itemH, &box);
  676.     SetCtlValue((ControlHandle) itemH, value);
  677. }
  678.  
  679. void dosetilong(DialogPtr dlogp, short itemnum, b_32 value)
  680. {
  681. b_8    s[12];
  682.  
  683.     NumToString(value, s);
  684.     dosetitext(dlogp, itemnum, s);
  685. }
  686.  
  687. void dosetipaddr(DialogPtr dlogp, short itemnum, b_32 address)
  688. {
  689. b_8    s[20];
  690. b_8    s2[12];
  691. short        i;
  692. b_8 *ptr = (b_8 *) &address;
  693.  
  694.     /* display 4 byte num in dot notation */
  695.     s[0] = 0;
  696.     for (i = 0; i<4; i++) {
  697.         NumToString((unsigned long) *ptr++, s2);
  698.         AppendStr(s, s2);
  699.         AppendStr(s, "\p.");        
  700.     }
  701.     s[0] = s[0] - 1;        /* delete last dot */
  702.     dosetitext(dlogp, itemnum, s);
  703. }
  704.  
  705. void dosethex(DialogPtr dlogp, short itemnum, b_32 value)
  706. {
  707. b_8 s[10];
  708. short i;
  709.  
  710.     s[0] = 8;
  711.     for (i=8; i > 0 ; i--) {
  712.         s[i] = (value & 0xf) + '0';
  713.         if (s[i] > '9')
  714.             s[i] += 7;
  715.         value >>= 4;
  716.     }
  717.     dosetitext(dlogp, itemnum, s);
  718. }
  719.     
  720. void dosetcbox(DialogPtr dlogp, short itemnum, short state)
  721. {
  722. GrafPtr        saveptr;
  723. short            type;
  724. Handle        itemH;
  725. Rect        box;
  726.  
  727.     GetDItem(dlogp, itemnum, &type, &itemH, &box);
  728.     GetPort(&saveptr);
  729.     SetPort(dlogp);
  730.     EraseRect(&box);
  731.     FrameRect(&box);
  732.     if (state) {
  733.         MoveTo(box.left + 1 , box.bottom - 1 );
  734.         LineTo(box.right - 1, box.top );
  735.         MoveTo(box.left , box.top );
  736.         LineTo(box.right -1 , box.bottom -1);
  737.     }
  738.     SetPort(saveptr);
  739. }
  740.  
  741. struct    pppopts {
  742.     short itemnum;
  743.     short optionbit;
  744. };
  745.  
  746. void setlcpboxes(DialogPtr dlogptr, struct lcpconfig *lcpptr,
  747.                  struct pppopts *optsptr)
  748. {
  749. register    short    optval = optsptr->optionbit;
  750. register    short    optitem = optsptr->itemnum;
  751.  
  752.     dosetctlval(dlogptr, optitem++, 
  753.                 (lcpptr->local.want_negotiate & optval) ? 1 : 0);
  754.     dosetctlval(dlogptr, optitem++,
  755.                 (lcpptr->local.will_negotiate & optval) ? 1 : 0);
  756.     dosetctlval(dlogptr, optitem++, 
  757.                 (lcpptr->remote.want_negotiate & optval) ? 1 : 0);
  758.     dosetctlval(dlogptr, optitem++, 
  759.                 (lcpptr->remote.will_negotiate & optval) ? 1 : 0);
  760.  
  761.     switch (optval) {
  762.     case LCP_N_MAGIC:
  763.         dosetilong(dlogptr, optitem++, lcpptr->local.want.magic_number);
  764.         dosetilong(dlogptr, optitem, lcpptr->remote.want.magic_number);
  765.         break;
  766.     case LCP_N_MRU:
  767.         dosetilong(dlogptr, optitem++, (b_32) lcpptr->local.want.mru);
  768.         dosetilong(dlogptr, optitem, (b_32) lcpptr->remote.want.mru);
  769.         break;
  770.     case LCP_N_ACCM:
  771.         dosethex(dlogptr, optitem++, (b_32) lcpptr->local.want.accm);
  772.         dosethex(dlogptr, optitem, (b_32) lcpptr->remote.want.accm);
  773.         break;
  774.     }
  775. }
  776.  
  777. Boolean getlcpboxes(DialogPtr dlogptr, struct lcpconfig *lcpptr,
  778.                  struct pppopts *optsptr)
  779. {
  780. short            type, i, k;
  781. unsigned long lv;
  782. b_8 digit;
  783. Handle        itemH,litemH,ritemH;
  784. Rect        box;
  785. b_32        mruval;
  786. Str255        s;
  787. register    short    optval = optsptr->optionbit;
  788. register    short    optitem = optsptr->itemnum;
  789.  
  790.     getnegval(dlogptr, optitem++, optval, &(lcpptr->local.want_negotiate));
  791.     getnegval(dlogptr, optitem++, optval, &(lcpptr->local.will_negotiate));
  792.     getnegval(dlogptr, optitem++, optval, &(lcpptr->remote.want_negotiate));
  793.     getnegval(dlogptr, optitem++, optval, &(lcpptr->remote.will_negotiate));
  794.  
  795.     GetDItem(dlogptr, optitem++, &type, &litemH, &box);
  796.     GetDItem(dlogptr, optitem, &type, &ritemH, &box);
  797.     switch (optval) {
  798.     case LCP_N_AUTHENT:    /* we only support PAP, hardcode it */
  799.         lcpptr->remote.want.authentication = PPP_PAP_PROTOCOL;
  800.         break;
  801.     case LCP_N_MAGIC:
  802.         GetIText(litemH, s);
  803.         StringToNum(s, (long *) &(lcpptr->local.want.magic_number));
  804.         GetIText(ritemH, s);
  805.         StringToNum(s, (long *) &(lcpptr->remote.want.magic_number));
  806.         break;
  807.     case LCP_N_ACCM:
  808.         lcpptr->local.want.accm = 0L;
  809.         lcpptr->remote.want.accm = 0L;
  810.         k = optitem - 1;
  811.         while( k <= optitem ) {
  812.             gettext(dlogptr, k, s);
  813.             lv = 0;
  814.             /* convert string from hex to a long int */
  815.             if (s[0] > 8) {    /* too long */
  816.                 MyNoteAlert(ACCMMESS);
  817.                 SelIText(dlogptr, k, 0, 32767);
  818.                 return false;
  819.             }
  820.             for (i = 1; i <= s[0]; i++) {
  821.                 digit = s[i];
  822.                 if (digit > 0x60)
  823.                     digit &= 0xDF;    /* convert to upper case */
  824.                 if (digit >= '0' && digit <= '9') {
  825.                     lv <<= 4;
  826.                     lv += digit - '0';
  827.                 } else if (digit >= 'A' && digit <= 'F') {
  828.                     lv <<= 4;
  829.                     lv += digit - 55;
  830.                 } else {
  831.                     MyNoteAlert(ACCMMESS);
  832.                     SelIText(dlogptr, k, 0, 32767);
  833.                     return false;    /* parse error */
  834.                 }
  835.             }
  836.             if ( k == optitem )
  837.                 lcpptr->remote.want.accm = lv;
  838.             else
  839.                 lcpptr->local.want.accm = lv;
  840.             k++;
  841.         }
  842.         break;
  843.     case LCP_N_MRU:
  844.         GetIText(litemH, s);
  845.         StringToNum(s, (long *) &mruval);
  846.         if ( mruval < LCP_MRU_LO || mruval > LCP_MRU_HI ) {
  847.             MyNoteAlert(MRUMESS);
  848.             SelIText(dlogptr, optitem-1, 0, 32767);
  849.             return false;
  850.         } else
  851.             lcpptr->local.want.mru = mruval;
  852.         GetIText(ritemH, s);
  853.         StringToNum(s, (long *) &mruval);
  854.         if ( mruval < LCP_MRU_LO || mruval > LCP_MRU_HI ) {
  855.             MyNoteAlert(MRUMESS);
  856.             SelIText(dlogptr, optitem, 0, 32767);
  857.             return false;
  858.         } else
  859.             lcpptr->remote.want.mru = mruval;
  860.         break;
  861.     }
  862.     return true;
  863. }
  864.  
  865. void doconfigdlog(struct cdevstore *p) {
  866. DialogPtr    tempdlog, askdlog;
  867. GrafPtr        savport;
  868. b_8        s[MAXSLEN + 1];
  869. long        numval;
  870. short        curconfig, j, i, type, itemhit;
  871. Handle        itemH;
  872. Rect        box;
  873. Boolean        needupdate = true, quit = false;
  874.  
  875.     tempdlog = GetNewDialog(CONNECTDLOG, 0L, (WindowPtr) -1L);
  876.     GetPort(&savport);
  877.     SetPort(tempdlog);
  878.     /* get baud rects */
  879.     GetDItem(tempdlog, BAUDRECT, &type, &itemH, &(p->baud.poprect));
  880.     GetDItem(tempdlog, BTITLERECT, &type, &itemH, &(p->baud.titlerect));
  881.     /* get flowcontrol rects */
  882.     GetDItem(tempdlog, FLOWRECT, &type, &itemH, &(p->flow.poprect));
  883.     GetDItem(tempdlog, FTITLERECT, &type, &itemH, &(p->flow.titlerect));
  884.     
  885. setconfigs:
  886.         /* pulse/touchtone dialing */
  887.     i = p->prefcnfg.flags & USE_PULSE ? PULSEBTN : TONEBTN;
  888.     dosetctlval(tempdlog, i, 1);
  889.     dosetitext(tempdlog, SERVERNAME, p->prefcnfg.config_name);
  890.     dosetitext(tempdlog, MODEMINIT, p->prefcnfg.modeminit);
  891.     dosetitext(tempdlog, PHONENUM, p->prefcnfg.phonenum);
  892.     dosetilong(tempdlog, CONNECTTIME, p->prefcnfg.connecttimeout);
  893.     SelIText(tempdlog, SERVERNAME, 0, 32767);
  894.     curconfig = p->prefdata.active_config;
  895.  
  896.     while (!quit) {
  897.         if (needupdate) {
  898.             drawpopint(&(p->baud), tempdlog, p->prefcnfg.baudrate);
  899.             GetItem(p->flow.menuh, (p->prefcnfg.flags & FLOWBITS) + 1, s);
  900.             drawpopup(&(p->flow), tempdlog, s);
  901.         }
  902.         ModalDialog(dumbfilter, &itemhit);
  903.         needupdate = true;
  904.  
  905.         switch (itemhit) {
  906.         case TONEBTN:
  907.             needupdate = false;
  908.             dosetctlval(tempdlog, itemhit, 1);
  909.             dosetctlval(tempdlog, PULSEBTN, 0);
  910.             p->prefcnfg.flags &= ~USE_PULSE;
  911.             break;
  912.         
  913.         case PULSEBTN:
  914.             needupdate = false;
  915.             dosetctlval(tempdlog, itemhit, 1);
  916.             dosetctlval(tempdlog, TONEBTN, 0);
  917.             p->prefcnfg.flags |= USE_PULSE;
  918.             break;
  919.             
  920.         case LCPBTN:
  921.             dolcpdlog(p);
  922.             break;
  923.         
  924.         case IPCPBTN:
  925.             doipcpdlog(p);
  926.             break;
  927.  
  928.         case AUTHBTN:
  929.             doauthdlog(p);
  930.             break;
  931.         
  932.         case SCRIPTBTN:
  933.             doscriptdlog(p);
  934.             break;
  935.  
  936.         case BAUDRECT:
  937.             DoPopInt(&(p->baud), &(p->prefcnfg.baudrate));
  938.             break;
  939.         
  940.         case FLOWRECT:
  941.             GetItem(p->flow.menuh, (p->prefcnfg.flags & FLOWBITS) + 1, s);
  942.             numval = DoPopUp(&(p->flow), s);
  943.             if (HiWord(numval) != 0) {
  944.                 p->prefcnfg.flags &= ~FLOWBITS;
  945.                 p->prefcnfg.flags |= ((LoWord(numval) - 1) & FLOWBITS);
  946.             }
  947.             break;
  948.  
  949.         case OK:
  950.             /* read boxes and set resource fields */
  951.             if (!gettext(tempdlog, MODEMINIT, p->prefcnfg.modeminit))
  952.                 break;
  953.             if (!gettext(tempdlog, PHONENUM, p->prefcnfg.phonenum))
  954.                 break;
  955.             if (!gettext(tempdlog, SERVERNAME, p->prefcnfg.config_name))
  956.                 break;
  957.             if (p->prefcnfg.config_name[0] == 0) {
  958.                 MyNoteAlert(NULLMESS);
  959.                 SelIText(tempdlog, SERVERNAME, 0, 32767);
  960.                 break;
  961.             }            
  962.             for (j = 1 ; j <= p->prefdata.max_config; j++ ) {
  963.                 if (j == curconfig + 1)
  964.                     continue;
  965.                 GetItem(p->server.menuh, j, s);
  966.                 if (EqualString(s, p->prefcnfg.config_name, true, false)) {
  967.                     MyNoteAlert(SAMEMESS);
  968.                     goto setconfigs;
  969.                 }
  970.             }
  971.             SetItem(p->server.menuh, curconfig + 1, p->prefcnfg.config_name);
  972.             if (!gettext(tempdlog, CONNECTTIME, s))
  973.                 break;
  974.             StringToNum(s, &numval);
  975.             p->prefcnfg.connecttimeout = LoWord(numval);
  976.             updateprefs(p);
  977.             quit = true;
  978.             break;
  979.  
  980.         default:
  981.             needupdate = false;
  982.             break;
  983.         }
  984.     }
  985.     DisposDialog(tempdlog);
  986.     SetPort(savport);
  987. }
  988.  
  989. void doauthdlog(struct cdevstore *p) {
  990. pascal        Boolean authfilter(DialogPtr, EventRecord *, short *);
  991. DialogPtr    tempdlog;
  992. struct         mydlogrec authdlogrec;
  993. short            itemhit;
  994. b_8        s[MAXSLEN + 1];
  995. short            strlen;
  996.  
  997.     tempdlog = GetNewDialog(AUTHDLOG, &authdlogrec, (WindowPtr) -1L);
  998.  
  999.     dosetitext(tempdlog, AUTHID, p->prefcnfg.defaultid);
  1000.     strlen = (s[0] = p->prefcnfg.defaultpw[0]);
  1001.     while (strlen > 0)
  1002.         s[strlen--] = 'Ñ';
  1003.     dosetitext(tempdlog, AUTHPW, s);
  1004.     s[0] = 0;
  1005.     AppendStr(s, p->prefcnfg.defaultpw);
  1006.     authdlogrec.strptr = s;
  1007.     dosetilong(tempdlog, AUTHRETRIES, (b_32) p->prefcnfg.pap_retries);
  1008.     dosetilong(tempdlog, AUTHTIMEOUT, (b_32) p->prefcnfg.pap_timeout);
  1009.     
  1010.     do {
  1011.         ModalDialog(authfilter, &itemhit);
  1012.         if (itemhit == OK) {
  1013.             if (!gettext(tempdlog, AUTHID, p->prefcnfg.defaultid))
  1014.                 continue;
  1015.             if (!getbyte(tempdlog, AUTHRETRIES, &(p->prefcnfg.pap_retries)))
  1016.                 continue;
  1017.             if (!getbyte(tempdlog, AUTHTIMEOUT, &(p->prefcnfg.pap_timeout)))
  1018.                 continue;
  1019.             strlen = p->prefcnfg.defaultpw[0];
  1020.             while (strlen >= 0)
  1021.                 p->prefcnfg.defaultpw[strlen--] = 0; /* clear old string */
  1022.             AppendStr(p->prefcnfg.defaultpw, s);
  1023.             break;
  1024.         }
  1025.     } while (itemhit != Cancel);
  1026.     CloseDialog(tempdlog);
  1027. }
  1028.  
  1029. void doscriptdlog(struct cdevstore *p) {
  1030. pascal        Boolean scriptfilter(DialogPtr, EventRecord *, short *);
  1031. DialogPtr    tempdlog;
  1032. b_8        s[MAXSLEN + 1];
  1033. long        numval;
  1034. short            i, type, itemhit;
  1035. Handle        itemH;
  1036. Rect        box;
  1037.  
  1038.     tempdlog = GetNewDialog(SCRIPTDLOG, 0L, (WindowPtr) -1L);
  1039.     dosetilong(tempdlog, WAITTIME, p->prefcnfg.waittimeout);
  1040.  
  1041.     for (i = 0 ; i < NUMCOMMANDS; i++ ) {
  1042.         dosetitext(tempdlog, COMMANDS + i, p->prefcnfg.commands[i].scriptstr);
  1043.         dosetctlval(tempdlog, ADDRETURNS + i, p->prefcnfg.commands[i].addreturn);
  1044.         itemhit = COMMANDBTNS + i*2;
  1045.         if (!p->prefcnfg.commands[i].sendout)
  1046.             itemhit++;
  1047.         dosetctlval(tempdlog, itemhit, 1);
  1048.     }
  1049. scriptretry:
  1050.     do {
  1051.         ModalDialog(scriptfilter, &itemhit);
  1052.     
  1053.         if (itemhit >= COMMANDBTNS && itemhit < (COMMANDBTNS +NUMCOMMANDS * 2) ) {
  1054.             dosetctlval(tempdlog, itemhit, 1);
  1055.             dosetctlval(tempdlog, COMMANDBTNS + ((itemhit - COMMANDBTNS) ^ 1), 0);
  1056.         }
  1057.         if (itemhit >= ADDRETURNS && itemhit < (ADDRETURNS + NUMCOMMANDS) ) {
  1058.             GetDItem(tempdlog, itemhit, &type, &itemH, &box);
  1059.             SetCtlValue((ControlHandle) itemH,
  1060.                 (GetCtlValue((ControlHandle) itemH) ^ 1));
  1061.         }
  1062.  
  1063.         if (itemhit == OK) {
  1064.             for (i = 0 ; i < NUMCOMMANDS; i++ ) {
  1065.                 if (!gettext(tempdlog, COMMANDS+i, p->prefcnfg.commands[i].scriptstr))
  1066.                     goto scriptretry;
  1067.                 GetDItem(tempdlog,ADDRETURNS + i,&type,&itemH,&box);
  1068.                 p->prefcnfg.commands[i].addreturn =
  1069.                     GetCtlValue((ControlHandle) itemH);
  1070.                 GetDItem(tempdlog,COMMANDBTNS + i*2,&type,&itemH,&box);
  1071.                 p->prefcnfg.commands[i].sendout =
  1072.                     GetCtlValue((ControlHandle) itemH);
  1073.             }
  1074.             if (!gettext(tempdlog, WAITTIME, s))
  1075.                 goto scriptretry;
  1076.             StringToNum(s, (long *) &numval);
  1077.             p->prefcnfg.waittimeout = LoWord(numval);
  1078.             break;
  1079.         }
  1080.     } while (itemhit != Cancel);
  1081.     DisposDialog(tempdlog);
  1082. }
  1083.  
  1084. void dostatsdlog() {
  1085. LapInfo        *lap;
  1086. DialogPtr    tempdlog;
  1087. short            itemhit;
  1088.  
  1089.     if ( Gestalt((OSType) 'PPP ', (long *) &lap) != noErr)
  1090.         return;
  1091.     tempdlog = GetNewDialog(STATSDLOG, 0L, (WindowPtr) -1L);
  1092. updatestats:    
  1093.     dosetilong(tempdlog, INOCTETS, lap->InRxOctetCount);
  1094.     dosetilong(tempdlog, OUTOCTETS, lap->OutTxOctetCount);
  1095.     dosetilong(tempdlog, INPACKETS, lap->InOpenFlag);
  1096.     dosetilong(tempdlog, OUTPACKETS, lap->OutOpenFlag);
  1097.     dosetilong(tempdlog, CHECKSEQERRS, (b_32) lap->InCheckSeq);
  1098.     dosetilong(tempdlog, HEADERERRS, (b_32) lap->InHeader);
  1099.     dosetilong(tempdlog, HWOVERRUNS, (b_32) lap->InHardOvr);
  1100.     dosetilong(tempdlog, SWOVERRUNS, (b_32) lap->InSoftOvr);
  1101.     dosetilong(tempdlog, FRAMINGERRS, (b_32) lap->InFramingErr);
  1102.     dosetilong(tempdlog, OUTOFBUFS, (b_32) lap->OutofBuffers);
  1103.     dosetcbox(tempdlog, PFCVALS,lap->lcp_i.local.work_negotiate & LCP_N_PFC);
  1104.     dosetcbox(tempdlog, PFCVALS + 1, lap->lcp_i.remote.work_negotiate & LCP_N_PFC);
  1105.     dosetcbox(tempdlog, ACFCVALS, lap->lcp_i.local.work_negotiate & LCP_N_ACFC);
  1106.     dosetcbox(tempdlog, ACFCVALS + 1, lap->lcp_i.remote.work_negotiate & LCP_N_ACFC);
  1107.     dosetcbox(tempdlog, PAPVALS, lap->lcp_i.local.work_negotiate & LCP_N_AUTHENT);
  1108.     dosetcbox(tempdlog, PAPVALS + 1, lap->lcp_i.remote.work_negotiate & LCP_N_AUTHENT);
  1109.     dosethex(tempdlog, MAGICVALS, lap->lcp_i.local.work.lcp_option.magic_number);
  1110.     dosethex(tempdlog, MAGICVALS + 1, lap->lcp_i.remote.work.lcp_option.magic_number);
  1111.     dosethex(tempdlog, ACCMVALS, lap->lcp_i.local.work.lcp_option.accm);
  1112.     dosethex(tempdlog, ACCMVALS + 1, lap->lcp_i.remote.work.lcp_option.accm);
  1113.     dosetilong(tempdlog, MRUVALS, lap->lcp_i.local.work.lcp_option.mru);
  1114.     dosetilong(tempdlog, MRUVALS + 1, lap->lcp_i.remote.work.lcp_option.mru);
  1115.     dosetcbox(tempdlog, VJVALS,lap->ipcp_i.local.work_negotiate & IPCP_N_COMPRESS);
  1116.     dosetcbox(tempdlog, VJVALS + 1, lap->ipcp_i.remote.work_negotiate & IPCP_N_COMPRESS);
  1117.     dosetilong(tempdlog, VJSLOTS, lap->ipcp_i.local.work.ipcp_option.slots);
  1118.     dosetilong(tempdlog, VJSLOTS + 1,lap->ipcp_i.remote.work.ipcp_option.slots);
  1119.     dosetcbox(tempdlog, VJCID,lap->ipcp_i.local.work.ipcp_option.slot_compress);
  1120.     dosetcbox(tempdlog, VJCID + 1, lap->ipcp_i.remote.work.ipcp_option.slot_compress);
  1121.     dosetipaddr(tempdlog, IPADDRVALS, lap->ipcp_i.local.work.ipcp_option.address);
  1122.     dosetipaddr(tempdlog, IPADDRVALS + 1, lap->ipcp_i.remote.work.ipcp_option.address);
  1123.     do {
  1124.         ModalDialog(nil, &itemhit);
  1125.         if (itemhit == UPDATEBTN)
  1126.             goto updatestats;
  1127.     } while (itemhit != OK);
  1128.     DisposDialog(tempdlog);
  1129. }
  1130. #define NUMLCPOPTS 6
  1131.  
  1132. void dolcpdlog(struct cdevstore *p)
  1133. {
  1134. DialogPtr    optsdlog;
  1135. Str255        s;
  1136. short            type, i, itemhit, ctlvalue;
  1137. Handle        itemH;
  1138. Rect        box;
  1139. struct    pppopts    options[NUMLCPOPTS];
  1140.  
  1141.     options[0].itemnum = PFCBOXES;
  1142.     options[0].optionbit = LCP_N_PFC;
  1143.     options[1].itemnum = ACFCBOXES;
  1144.     options[1].optionbit = LCP_N_ACFC;
  1145.     options[2].itemnum = AUTHENTBOXES;
  1146.     options[2].optionbit = LCP_N_AUTHENT;
  1147.     options[3].itemnum = MAGICBOXES;
  1148.     options[3].optionbit = LCP_N_MAGIC;
  1149.     options[4].itemnum = ACCMBOXES;
  1150.     options[4].optionbit = LCP_N_ACCM;
  1151.     options[5].itemnum = MRUBOXES;
  1152.     options[5].optionbit = LCP_N_MRU;
  1153.  
  1154.     optsdlog = GetNewDialog(LCPDLOG, 0L, (WindowPtr) -1L);
  1155.     
  1156.     for ( i=0 ; i < NUMLCPOPTS; i++ )
  1157.         setlcpboxes(optsdlog, &(p->prefcnfg.lcpconf), &options[i]);
  1158.     dosetilong(optsdlog, LCPRETRIES, (b_32) p->prefcnfg.lcpconf.req_tries);
  1159.     dosetilong(optsdlog, LCPTIMEOUT, (b_32) p->prefcnfg.lcpconf.timeout);
  1160.     do {
  1161. dolcpdlog:                
  1162.         ModalDialog(dumbfilter, &itemhit);
  1163.         for ( i=0 ; i < NUMLCPOPTS; i++ ) {
  1164.             if (itemhit >= options[i].itemnum && 
  1165.                 itemhit < options[i].itemnum + 4) {
  1166.                 GetDItem(optsdlog, itemhit, &type, &itemH, &box);
  1167.                 SetCtlValue((ControlHandle) itemH,
  1168.                     (ctlvalue = GetCtlValue((ControlHandle) itemH) ^ 1));
  1169.                 switch (itemhit - options[i].itemnum) {
  1170.                 case 0:
  1171.                 case 2:
  1172.                     if (ctlvalue) {
  1173.                         dosetctlval(optsdlog, itemhit+1, 1);
  1174.                     }
  1175.                     break;
  1176.                 case 1:
  1177.                 case 3:
  1178.                     if (!ctlvalue) {
  1179.                         dosetctlval(optsdlog, itemhit-1, 0);
  1180.                     }
  1181.                 }
  1182.                 break;
  1183.             }
  1184.         }
  1185.         if (itemhit == LCPDEFAULT) {
  1186.             for ( i=0 ; i < NUMLCPOPTS; i++ )
  1187.                 setlcpboxes(optsdlog, &(p->deflcp), &options[i]);
  1188.             dosetilong(optsdlog, LCPRETRIES, (b_32) p->deflcp.req_tries);
  1189.             dosetilong(optsdlog, LCPTIMEOUT, (b_32) p->deflcp.timeout);
  1190.         }
  1191.         if (itemhit == OK) {
  1192.             for ( i=0 ; i < NUMLCPOPTS; i++ ) {
  1193.                 if (!getlcpboxes(optsdlog, &(p->prefcnfg.lcpconf), &options[i]))
  1194.                     goto dolcpdlog;
  1195.             }
  1196.             if (!getbyte(optsdlog, LCPRETRIES, &(p->prefcnfg.lcpconf.req_tries)))
  1197.                 goto dolcpdlog;
  1198.             if (!getbyte(optsdlog, LCPTIMEOUT, &(p->prefcnfg.lcpconf.timeout)))
  1199.                 goto dolcpdlog;
  1200.             updateprefs(p);
  1201.             break;
  1202.         }
  1203.     }
  1204.     while (itemhit != Cancel);
  1205.  
  1206.     DisposDialog(optsdlog);
  1207. }
  1208.  
  1209. void setipcpboxes(DialogPtr dlogptr, struct ipcpconfig *ipcpptr,
  1210.                  struct pppopts *optsptr)
  1211. {
  1212. register short    optval = optsptr->optionbit;
  1213. register short    optitem = optsptr->itemnum;
  1214.  
  1215.     dosetctlval(dlogptr, optitem++,
  1216.                 (ipcpptr->local.want_negotiate & optval) ? 1 : 0);
  1217.     dosetctlval(dlogptr, optitem++,
  1218.                 (ipcpptr->local.will_negotiate & optval) ? 1 : 0);
  1219.     dosetctlval(dlogptr, optitem++,
  1220.                 (ipcpptr->remote.want_negotiate & optval) ? 1 : 0);
  1221.     dosetctlval(dlogptr, optitem++,
  1222.                 (ipcpptr->remote.will_negotiate & optval) ? 1 : 0);
  1223.  
  1224.     switch (optval) {
  1225.     case IPCP_N_ADDRESS:
  1226.         dosetipaddr(dlogptr, optitem++, ipcpptr->local.want.address);
  1227.         dosetipaddr(dlogptr, optitem, ipcpptr->remote.want.address);
  1228.         break;
  1229.     };
  1230. }
  1231.  
  1232. Boolean getipcpboxes(DialogPtr dlogptr, struct ipcpconfig *ipcpptr,
  1233.                  struct pppopts *optsptr)
  1234. {
  1235. short            type, i, j, k;
  1236. unsigned long    lv;
  1237. b_8        *ptr;
  1238. Str255        s;
  1239. Str32        s2;
  1240. register    short    optval = optsptr->optionbit;
  1241. register    short    optitem = optsptr->itemnum;
  1242.  
  1243.     getnegval(dlogptr, optitem++, optval, &(ipcpptr->local.want_negotiate));
  1244.     getnegval(dlogptr, optitem++, optval, &(ipcpptr->local.will_negotiate));
  1245.     getnegval(dlogptr, optitem++, optval, &(ipcpptr->remote.want_negotiate));
  1246.     getnegval(dlogptr, optitem++, optval, &(ipcpptr->remote.will_negotiate));
  1247.  
  1248.     switch (optval) {
  1249.     case IPCP_N_ADDRESS:
  1250.         /* accept both forms of address negotiation */
  1251.         if (ipcpptr->local.will_negotiate & IPCP_N_ADDRESS)
  1252.             ipcpptr->local.will_negotiate | IPCP_N_ADDRESSES;
  1253.         else
  1254.             ipcpptr->local.will_negotiate & ~IPCP_N_ADDRESSES;
  1255.             
  1256.         if (ipcpptr->remote.will_negotiate & IPCP_N_ADDRESS)
  1257.             ipcpptr->remote.will_negotiate | IPCP_N_ADDRESSES;
  1258.         else
  1259.             ipcpptr->remote.will_negotiate & ~IPCP_N_ADDRESSES;
  1260.             
  1261.         ipcpptr->local.want.address = 0L;
  1262.         ipcpptr->remote.want.address = 0L;
  1263.         ipcpptr->local.want.other = 0L;
  1264.         ipcpptr->remote.want.other = 0L;
  1265.         k = optitem++;
  1266.         while( k <= optitem ) {
  1267.             gettext(dlogptr, k, s);
  1268.             /* convert string from dot notation to a long int */
  1269.             ptr = &s[1];
  1270.             s[s[0]+1] = '.';
  1271.             for (j = 3; j >= 0; j--) {
  1272.                 s2[0] = 0;
  1273.                 for (i = 1; *ptr != '.'; i++) {
  1274.                     if ((ptr > s + s[0]) || (*ptr > '9') || (*ptr < '0')){
  1275.                         MyNoteAlert(IPMESS);
  1276.                         SelIText(dlogptr, k, 0, 32767);
  1277.                         return false;    /* parse error */
  1278.                     }
  1279.                     s2[i] = *ptr++;
  1280.                     s2[0]++;
  1281.                 }
  1282.                 ptr++;
  1283.                 StringToNum(s2, (long *) &lv);
  1284.                 if (lv > 255) {
  1285.                     MyNoteAlert(IPMESS);
  1286.                     SelIText(dlogptr, k, 0, 32767);
  1287.                     return false;    /* parse error */
  1288.                 }
  1289.                 lv <<= j*8;
  1290.                 if ( k == optitem ) {
  1291.                     ipcpptr->remote.want.address |= lv;
  1292.                     ipcpptr->local.want.other |= lv;
  1293.                 } else {
  1294.                     ipcpptr->local.want.address |= lv;
  1295.                     ipcpptr->remote.want.other |= lv;
  1296.                 }
  1297.             }
  1298.             k++;
  1299.         }
  1300.         break;
  1301.     }
  1302.     return true;
  1303. }
  1304.  
  1305. #define NUMIPCPOPTS 2
  1306.  
  1307. void doipcpdlog(struct cdevstore *p)
  1308. {
  1309. DialogPtr    optsdlog;
  1310. Str255        s;
  1311. short            type, i, itemhit, ctlvalue;
  1312. Handle        itemH;
  1313. Rect        box;
  1314. struct    pppopts    options[NUMIPCPOPTS];
  1315.  
  1316.     options[0].itemnum = COMPRESSBOXES;
  1317.     options[0].optionbit = IPCP_N_COMPRESS;
  1318.     options[1].itemnum = ADDRESSBOXES;
  1319.     options[1].optionbit = IPCP_N_ADDRESS;
  1320.  
  1321.     optsdlog = GetNewDialog(IPCPDLOG, 0L, (WindowPtr) -1L);
  1322.     for ( i=0 ; i < NUMIPCPOPTS; i++ )
  1323.         setipcpboxes(optsdlog, &(p->prefcnfg.ipcpconf), &options[i]);
  1324.     dosetilong(optsdlog, IPCPRETRIES, (b_32) p->prefcnfg.ipcpconf.req_tries);
  1325.     dosetilong(optsdlog, IPCPTIMEOUT, (b_32) p->prefcnfg.ipcpconf.timeout);
  1326.     do {                
  1327. doipcpdlog:
  1328.         ModalDialog(dumbfilter, &itemhit);
  1329.         for ( i=0 ; i < NUMIPCPOPTS; i++ ) {
  1330.             if (itemhit >= options[i].itemnum && 
  1331.                 itemhit < options[i].itemnum + 4) {
  1332.                 GetDItem(optsdlog, itemhit, &type, &itemH, &box);
  1333.                 SetCtlValue((ControlHandle) itemH,
  1334.                     (ctlvalue = GetCtlValue((ControlHandle) itemH) ^ 1));
  1335.                 switch (itemhit - options[i].itemnum) {
  1336.                 case 0:
  1337.                 case 2:
  1338.                     if (ctlvalue) {
  1339.                         dosetctlval(optsdlog, itemhit+1, 1);
  1340.                     }
  1341.                     break;
  1342.                 case 1:
  1343.                 case 3:
  1344.                     if (!ctlvalue) {
  1345.                         dosetctlval(optsdlog, itemhit-1, 0);
  1346.                     }
  1347.                 }
  1348.                 break;
  1349.             }
  1350.         }
  1351.         if (itemhit == IPCPDEFAULT) {
  1352.             for ( i=0 ; i < NUMIPCPOPTS; i++ )
  1353.                 setipcpboxes(optsdlog, &(p->defipcp), &options[i]);
  1354.             dosetilong(optsdlog, IPCPRETRIES, (b_32) p->defipcp.req_tries);
  1355.             dosetilong(optsdlog, IPCPTIMEOUT, (b_32) p->defipcp.timeout);
  1356.         }
  1357.     }
  1358.     while (itemhit != OK && itemhit != Cancel);
  1359.     if (itemhit == OK) {
  1360.         for ( i=0 ; i < NUMIPCPOPTS; i++ ) {
  1361.             if (!getipcpboxes(optsdlog, &(p->prefcnfg.ipcpconf), &options[i]))
  1362.                 goto doipcpdlog;
  1363.         }
  1364.         if (!getbyte(optsdlog, IPCPRETRIES, &(p->prefcnfg.ipcpconf.req_tries)))
  1365.             goto doipcpdlog;
  1366.         if (!getbyte(optsdlog, IPCPTIMEOUT, &(p->prefcnfg.ipcpconf.timeout)))
  1367.             goto doipcpdlog;
  1368.         updateprefs(p);
  1369.     }
  1370.     DisposDialog(optsdlog);
  1371. }
  1372.  
  1373. void getnegval(DialogPtr dlogptr, short itemnum, short optval, b_16 *optptr)
  1374. {
  1375. short            type;
  1376. Handle        itemH;
  1377. Rect        box;
  1378.  
  1379.     GetDItem(dlogptr, itemnum, &type, &itemH, &box);
  1380.     if (GetCtlValue((ControlHandle) itemH))
  1381.         *optptr |= optval;
  1382.     else
  1383.         *optptr &= ~optval;
  1384. }
  1385.  
  1386. long DoPopInt(struct popup *p, b_16 *value)
  1387. {
  1388.     long rv;
  1389.     b_8 valstring[24];
  1390.     unsigned long tempval;
  1391.     
  1392.     tempval = *value;
  1393.     NumToString(tempval, valstring);
  1394.     rv = DoPopUp(p, valstring);
  1395.     if (HiWord(rv) != 0) {
  1396.         if (valstring[1] < '0' || valstring[1] > '9' )
  1397.             *value = 0;
  1398.         else {
  1399.             StringToNum(valstring, (long *) &tempval);
  1400.             *value = LoWord(tempval);
  1401.         }
  1402.     }
  1403.     return rv;
  1404. }
  1405.  
  1406. long DoPopUp(struct popup *p, b_8 *nameptr)
  1407. {
  1408.     long    rv;
  1409.     short        mitems;
  1410.     b_8    istring[64];
  1411.     Point    where;
  1412.     
  1413.     where.h = p->poprect.left;
  1414.     where.v = p->poprect.top;
  1415.     p->poprect.bottom++;
  1416.     EraseRect(&(p->poprect));
  1417.     p->poprect.bottom--;
  1418.     LocalToGlobal(&(where));
  1419.     mitems = CountMItems(p->menuh);
  1420.     while (mitems > 0) {
  1421.         GetItem(p->menuh, mitems, istring);
  1422.         if (EqualString(istring, nameptr, FALSE, FALSE))
  1423.             break;
  1424.         mitems--;
  1425.     }
  1426.     if (mitems == 0)
  1427.         mitems = 1;
  1428.         
  1429.     InvertRect(&(p->titlerect));
  1430.     InsertMenu(p->menuh, -1);
  1431.     rv = PopUpMenuSelect(p->menuh, where.v, where.h, mitems);
  1432.     DeleteMenu((*(p->menuh))->menuID);
  1433.     InvertRect(&(p->titlerect));
  1434.     if (HiWord(rv) != 0)
  1435.         GetItem(p->menuh, LoWord(rv), nameptr);
  1436.     return rv;
  1437. }
  1438.  
  1439. OSErr readconfig( struct cdevstore *storptr, short confignum )
  1440. {
  1441. long    count;
  1442. OSErr    rc;
  1443.  
  1444.     rc = SetFPos(storptr->prefref,fsFromStart,
  1445.         sizeof(struct ppp_pref) + sizeof (struct ppp_config) * confignum);
  1446.     count = sizeof ( struct ppp_config );
  1447.     if ( rc == noErr)
  1448.         rc = FSRead(storptr->prefref, &count, &(storptr->prefcnfg));
  1449.     if (rc != noErr)
  1450.         MyNoteAlert(PREFSRMESS);
  1451.     return rc;
  1452. }
  1453.  
  1454. OSErr updateprefs( struct cdevstore *storptr )
  1455. {
  1456. long    count, index;
  1457. OSErr    rc;
  1458.  
  1459.     rc = SetFPos(storptr->prefref,fsFromStart,0L);    /* start at beginning */
  1460.     count = sizeof(struct ppp_pref);
  1461.     if ( rc == noErr )
  1462.         rc = FSWrite(storptr->prefref, &count, &(storptr->prefdata));
  1463.     count = sizeof (struct ppp_config);
  1464.     index = storptr->prefdata.active_config * count;
  1465.     if ( rc == noErr )
  1466.         rc = SetFPos(storptr->prefref,fsFromMark,index);
  1467.     if ( rc == noErr )
  1468.         rc = FSWrite(storptr->prefref, &count, &(storptr->prefcnfg));
  1469.     if (rc != noErr)
  1470.         MyNoteAlert(PREFSWMESS);
  1471.     return rc;
  1472. }
  1473.  
  1474. Boolean getbyte(DialogPtr dlogptr, short itemnum, b_8 *byte)
  1475. {
  1476. Str255    s;
  1477. long    numval;
  1478.  
  1479.     if (!gettext(dlogptr, itemnum, s))
  1480.         return false;
  1481.     StringToNum(s, &numval);
  1482.     *byte = numval & 0xff;
  1483.     return true;
  1484. }
  1485.  
  1486. Boolean gettext(DialogPtr dlogptr, short itemnum, b_8 *textptr)
  1487. {
  1488. Str255    s;
  1489. short    type, i, itemhit;
  1490. Handle    itemH;
  1491. Rect    box;
  1492.  
  1493.     GetDItem(dlogptr, itemnum, &type, &itemH, &box);
  1494.     GetIText(itemH, s);
  1495.     if (s[0] > MAXSLEN) {
  1496.         MyNoteAlert(STRINGMESS);
  1497.         SelIText(dlogptr, itemnum, 0, 32767);
  1498.         return false;
  1499.     } else {
  1500.         *textptr = 0;
  1501.         AppendStr(textptr, s);
  1502.         return true;
  1503.     }
  1504. }
  1505.  
  1506. void setbuttons(struct cdevstore *p, DialogPtr dlogp, short numitems)
  1507. {
  1508. LapInfo *lap;
  1509. short    type;
  1510. Rect box,iconrect;
  1511. Handle itemH1, itemH2, itemH3, tempH;        
  1512.  
  1513.     GetDItem(dlogp, numitems + PPPICON, &type, &tempH, &iconrect);
  1514.     GetDItem(dlogp, numitems + OPENBTN, &type, &itemH1, &box);
  1515.     GetDItem(dlogp, numitems + SOFTCLOSEBTN, &type, &itemH2, &box);
  1516.     GetDItem(dlogp, numitems + HARDCLOSEBTN, &type, &itemH3, &box);
  1517.     if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
  1518.         if (lap != nil) {
  1519.             p->saved_state = lap->ppp_fsm[IPcp].state;
  1520.             if  (lap->ppp_fsm[IPcp].state == fsmOPENED ) {
  1521.                 tempH = GetIcon(PPPUPICON);
  1522.                 PlotIcon(&iconrect, tempH);
  1523.                 ReleaseResource(tempH);
  1524.                 HiliteControl((ControlHandle) itemH3, 0);
  1525.                 HiliteControl((ControlHandle) itemH2, 0);
  1526.                 HiliteControl((ControlHandle) itemH1, 255);
  1527.                 return;
  1528.             } else {
  1529.                 HiliteControl((ControlHandle) itemH1, 0);
  1530.                 goto buttonjmp;
  1531.             }
  1532.         }
  1533.     }
  1534.     HiliteControl((ControlHandle) itemH1, 255);    /* buttons are inactive */
  1535. buttonjmp:
  1536.     HiliteControl((ControlHandle) itemH2, 255);
  1537.     HiliteControl((ControlHandle) itemH3, 255);
  1538.     tempH = GetIcon(PPPDOWNICON);
  1539.     PlotIcon(&iconrect, tempH);
  1540.     ReleaseResource(tempH);
  1541. }
  1542.  
  1543. main()
  1544. {}
  1545.  
  1546. pascal Boolean authfilter(DialogPtr dlog, EventRecord *evt, short *itemhit)
  1547. {
  1548.     short    itemType;
  1549.     Handle    itemHdl;
  1550.     Rect    itemRect;
  1551.     short    c,i;
  1552.     b_8        *charptr;
  1553.     b_8        s[MAXSLEN + 1];
  1554.     
  1555.     charptr = ( (struct mydlogrec *) dlog)->strptr;
  1556.     c = evt->message & charCodeMask;
  1557.     
  1558.     if ( ((DialogPeek) dlog)->editField + 1 == AUTHPW ) {
  1559.       switch(evt->what) {
  1560.         case keyDown:
  1561.         case autoKey:
  1562.             if (c > 31) {
  1563.                 if (*charptr < MAXSLEN)
  1564.                      *( charptr + ++(*charptr) )= c;
  1565.                 *itemhit = 0;
  1566.             } else if (c == RETURN || c == ENTER )
  1567.                 *itemhit = OK;
  1568.             else if (c == TAB)
  1569.                 *itemhit == AUTHRETRIES;
  1570.             else if (c == BACKSPACE) {
  1571.                 if (*charptr > 0)
  1572.                     (*charptr)--;
  1573.                 *itemhit = 0;
  1574.             }
  1575.             GetDItem(dlog, AUTHPW, &itemType, &itemHdl, &itemRect);
  1576.             i = s[0] = *charptr;
  1577.             while ( i > 0 )
  1578.                 s[i--] = 'Ñ';
  1579.             SetIText(itemHdl, s);
  1580.             SelIText(dlog, AUTHPW, 32767, 32767);
  1581.             return(true);
  1582.             break;
  1583.       }
  1584.     } else if ( ((DialogPeek) dlog)->editField + 1 == AUTHID ) {
  1585.         switch(evt->what) {
  1586.             case keyDown:
  1587.             case autoKey:
  1588.                 if (c == RETURN || c == ENTER || c == TAB) {
  1589.                     *itemhit = AUTHPW;
  1590.                     SelIText(dlog, AUTHPW, 0, 32767);
  1591.                     return(true);
  1592.                 }
  1593.                 break;
  1594.         }
  1595.     }
  1596.     
  1597.     *itemhit=0;
  1598.     return(false);                
  1599. }
  1600.  
  1601. pascal Boolean scriptfilter(DialogPtr dlog, EventRecord *evt, short *itemhit)
  1602. {
  1603.     short c;
  1604.  
  1605.     switch(evt->what) {
  1606.     case keyDown:
  1607.     case autoKey:
  1608.         c = evt->message & charCodeMask;
  1609.         if ( c == 8 || ( c >= 28 && c <= 31 ) || c > 31 )
  1610.             break;
  1611.         if ( c == 13 || c == 9 ) {
  1612.             switch ( ((DialogPeek) dlog)->editField + 1 ) {
  1613.                 case WAITTIME:
  1614.                     SelIText(dlog, COMMANDS, 0, 32767);
  1615.                     break;
  1616.                 case (COMMANDS + NUMCOMMANDS - 1):
  1617.                     if (c == 13)
  1618.                         *itemhit = 1;
  1619.                     else
  1620.                         SelIText(dlog, WAITTIME, 0, 32767);
  1621.                     break;
  1622.                 default:
  1623.                     SelIText(dlog, ((DialogPeek) dlog)->editField + 2, 0, 32767);
  1624.             }
  1625.         }
  1626.         return true;
  1627.     }                            
  1628.     return false;
  1629. }
  1630.  
  1631. pascal Boolean dumbfilter(DialogPtr dlog, EventRecord *evt, short *itemhit)
  1632. {
  1633.     short c;
  1634.     switch(evt->what) {
  1635.     case keyDown:
  1636.     case autoKey:
  1637.         c = evt->message & charCodeMask;
  1638.         if ( c == 8 || ( c >= 28 && c <= 31 ) || ( c > 31 ) )
  1639.             break;
  1640.         return true;        /* don't process <returns> etc. */
  1641.     }
  1642.     return false;
  1643. }
  1644.  
  1645. void
  1646. MyNoteAlert(b_8 stringnum)
  1647. {
  1648. register b_8 *strptr;
  1649. b_8    **messages;
  1650.  
  1651.     messages = (b_8 **) Get1Resource('STR#',STATUSSTRINGS);
  1652.     strptr = *messages;
  1653.     strptr++;
  1654.     if (stringnum > *strptr++ )        /* check if string is out of range */
  1655.         return;
  1656.     while (--stringnum > 0)            /* find string in list */
  1657.         strptr += *strptr + 1;
  1658.     HLock((Handle) messages);        /* lock down the Handle */
  1659.     ParamText(strptr,"\p","\p","\p");    /* set the text in the dialog */
  1660.     HUnlock((Handle) messages);
  1661.     ResetAlrtStage();
  1662.     NoteAlert(ERRALERT, nil);
  1663.     ReleaseResource((Handle) messages);
  1664. }
  1665.  
  1666. void initconfigs(struct cdevstore *p) {
  1667. short        i;
  1668.  
  1669.     p->prefcnfg.lcpconf = p->deflcp;
  1670.     p->prefcnfg.ipcpconf = p->defipcp;
  1671.     p->prefcnfg.pap_retries = 10;
  1672.     p->prefcnfg.pap_timeout = 3;
  1673.     p->prefcnfg.baudrate = 9600;    /* use 9600 as default for baudrate */
  1674.     p->prefcnfg.flags = 0;        /* no flow control, tone dial */
  1675.     p->prefcnfg.config_name[0] = 0;
  1676.     p->prefcnfg.defaultid[0] = 0;    /* init strings */
  1677.     p->prefcnfg.defaultpw[0] = 0;
  1678.     p->prefcnfg.modeminit[0] = 0;
  1679.     p->prefcnfg.phonenum[0] = 0;
  1680.     p->prefcnfg.connecttimeout = 90;    /* initial connect timeout */
  1681.     p->prefcnfg.waittimeout = 40; /* initial wait timeout */
  1682.     for (i=0 ; i < NUMCOMMANDS; i++) {
  1683.         p->prefcnfg.commands[i].sendout = true; /* make all output */
  1684.         p->prefcnfg.commands[i].addreturn = false; /* no returns */
  1685.         p->prefcnfg.commands[i].scriptstr[0] = 0;
  1686.     }
  1687. }
  1688.  
  1689. void AppendStr(b_8 *dst, b_8 *src)
  1690. {
  1691. b_8        dl,sl;
  1692.  
  1693.     dl = *dst;
  1694.     sl = *src++;
  1695.     *dst++ += sl;
  1696.     dst    += dl;
  1697.     BlockMove(src, dst, (unsigned long) sl);
  1698. }
  1699.  
  1700.