home *** CD-ROM | disk | FTP | other *** search
- /*
- * pppcdev.c -- The Control Panel for MacPPP
- *
- * Copyright (c) 1992-1993 Merit Network, Inc. and The Regents of the
- * University of Michigan. Usage of this source code is restricted
- * to non-profit, non-commercial purposes. The source is provided
- * "as-is", without warranty.
- */
- #include "ppp.h"
- #include <GestaltEqu.h>
- #include <CommResources.h>
- #include <CRMSerialDevices.h>
- #include <Folders.h>
- #include <Menus.h>
- #include <ToolUtils.h>
-
- /* Trap numbers */
- #define TN_UnknownOS 0xA09F
- #define TN_CommToolbox 0xA08B
-
- /* Menus */
- #define BAUDMENU -4033
- #define PORTMENU -4034
- #define IDLEMENU -4035
- #define SERVERMENU -4036
- #define ECHOMENU -4037
- #define FLOWMENU -4038
-
- /* ICONs */
- #define PPPUPICON -4033
- #define PPPDOWNICON -4034
-
- /* Default preferences resources */
- #define DEFAULTPREF -4033
- #define DEFAULTLCP -4034
- #define DEFAULTIPCP -4035
- #define DEFAULTCNFGNAME -4036
-
- /* STR# resources */
- #define STATUSSTRINGS -4033
- #define CANNEDPORTS -4034
-
- /* status strings */
- #define ACCMMESS 1 /* invalid ACCM */
- #define MRUMESS 2 /* invalid MRU */
- #define IPMESS 3 /* invalid IP address */
- #define STRINGMESS 4 /* string too long */
- #define PREFSCMESS 5 /* Pref file create error */
- #define PREFSOMESS 6 /* Pref file open error */
- #define PREFSRMESS 7 /* Pref file read error */
- #define PREFSWMESS 8 /* Pref file write error */
- #define OLDPREFSMESS 9 /* there's an old version of the preferences file */
- #define CONFIGMESS 10 /* must be more than one config for deletion */
- #define NULLMESS 11 /* null length server name */
- #define SAMEMESS 12 /* name is the same as another server */
-
- /* number for Preferences file name */
- #define PREFFILENAME -4033
- #define SYS6FOLDER -4034
-
- /* Dialog numbers */
- #define SCRIPTDLOG -4033
- #define CONNECTDLOG -4034
- #define LCPDLOG -4035
- #define STATSDLOG -4036
- #define AUTHDLOG -4037
- #define IPCPDLOG -4038
- #define ASKDLOG -4039
- #define NEWDLOG -4040
-
- /* Alerts */
- #define ERRALERT -4033
- #define OLDPREFSALERT -4034
-
- /* cdev dialog items (add numitems to these) */
- #define OPENBTN 1
- #define SOFTCLOSEBTN 2
- #define HARDCLOSEBTN 3
- #define STATSBTN 4
- #define PTITLERECT 5
- #define PORTRECT 6
- #define ITITLERECT 7
- #define IDLERECT 8
- #define ETITLERECT 9
- #define ECHORECT 10
- #define STITLERECT 11
- #define SERVERRECT 12
- #define CONFIGBTN 13
- #define NEWBTN 14
- #define DELETEBTN 15
- #define TERMCHECK 16
- #define HANGUPCHECK 17
- #define QUIETCHECK 18
- #define PPPICON 19
-
- /* config dialog */
- #define SERVERNAME 3
- #define BTITLERECT 4
- #define BAUDRECT 5
- #define FTITLERECT 19
- #define FLOWRECT 20
- #define TONEBTN 17
- #define PULSEBTN 18
- #define PHONENUM 8
- #define MODEMINIT 9
- #define SCRIPTBTN 10
- #define AUTHBTN 11
- #define LCPBTN 12
- #define IPCPBTN 13
- #define CONNECTTIME 15
-
- /* connect script dialog */
- #define COMMANDBTNS 3
- #define COMMANDS 19
- #define ADDRETURNS 28
- #define WAITTIME 37
-
- /* auth fields */
- #define AUTHID 3
- #define AUTHPW 4
- #define AUTHRETRIES 9
- #define AUTHTIMEOUT 11
-
- /* LCP options dialog items */
- #define LCPDEFAULT 3
- #define PFCBOXES 15
- #define ACFCBOXES 19
- #define AUTHENTBOXES 23
- #define MAGICBOXES 27
- #define ACCMBOXES 33
- #define MRUBOXES 39
- #define LCPRETRIES 46
- #define LCPTIMEOUT 48
-
- /* IPCP options dialog items */
- #define IPCPDEFAULT 3
- #define COMPRESSBOXES 8
- #define ADDRESSBOXES 12
- #define IPCPRETRIES 21
- #define IPCPTIMEOUT 23
-
- /* stats boxes */
- #define UPDATEBTN 2
- #define INOCTETS 13
- #define OUTOCTETS 14
- #define INPACKETS 15
- #define OUTPACKETS 16
- #define CHECKSEQERRS 17
- #define HEADERERRS 18
- #define HWOVERRUNS 19
- #define SWOVERRUNS 20
- #define FRAMINGERRS 21
- #define OUTOFBUFS 22
- #define PFCVALS 35
- #define ACFCVALS 37
- #define PAPVALS 39
- #define MAGICVALS 41
- #define ACCMVALS 43
- #define MRUVALS 45
- #define VJVALS 47
- #define VJSLOTS 55
- #define VJCID 59
- #define IPADDRVALS 49
-
- /* new server dialog */
- #define PPPSERVNAME 4
-
- struct mydlogrec {
- DialogRecord adlogrec;
- b_8 *strptr;
- };
-
- struct cdevstore {
- struct popup {
- MenuHandle menuh; /* Handle to popupmenu */
- Rect poprect; /* rectangle to do popupmenu */
- Rect titlerect; /* rectangle to invert */
- } port, baud, idle, server, echo, flow;
- b_8 saved_state;
- short prefref; /* file ref for PPP preferences */
- struct lcpconfig deflcp; /* default LCP settings */
- struct ipcpconfig defipcp; /* default IPCP settings */
- struct ppp_pref prefdata; /* Preferences data */
- struct ppp_config prefcnfg; /* current config settings */
- };
-
- void AppendStr(b_8 *, b_8 *);
- void MyNoteAlert(b_8);
- void updatecp(struct cdevstore *, DialogPtr, short);
- OSErr updateprefs(struct cdevstore *);
- OSErr readconfig(struct cdevstore *, short);
- void initconfigs(struct cdevstore *);
- void dostatsdlog(), doauthdlog(struct cdevstore *);
- void dolcpdlog(struct cdevstore *), doipcpdlog(struct cdevstore *);
- void doconfigdlog (struct cdevstore *), doscriptdlog(struct cdevstore *);
- long DoPopInt(struct popup *, unsigned short *);
- long DoPopUp(struct popup *, b_8 *);
- void drawpopup(struct popup *, DialogPtr, b_8 *);
- void drawpopint(struct popup *, DialogPtr, unsigned short);
- pascal Boolean dumbfilter(DialogPtr, EventRecord *, short *);
- Boolean gettext(DialogPtr, short, b_8 *);
- Boolean getbyte(DialogPtr, short, b_8 *);
- void dosetctlval(DialogPtr, short, short);
- void dosetilong(DialogPtr, short, b_32);
- void dosetitext(DialogPtr, short, b_8 *);
- void dosethex(DialogPtr, short, b_32);
- void dosetipaddr(DialogPtr, short, b_32);
- void dosetcbox(DialogPtr, short, short);
- void getnegval(DialogPtr, short, short, b_16 *);
- void setbuttons(struct cdevstore *, DialogPtr, short);
-
- pascal long pppcdev(short msg, short item, short numitems, short cpid, EventRecord *evt,
- struct cdevstore *p, DialogPtr dlogp)
- {
- LapInfo *lap;
- Handle itemH;
- Str63 workstr, holdstr;
- short i, j, type, itemhit;
- unsigned short curconfig;
- long rv;
- Rect box;
- OSErr onewresult, oresult;
- DialogPtr askdlog;
-
- if ( msg == macDev )
- return(1L); /* this will work anywhere */
- else if ( msg == initDev ) {
- struct cdevstore *tempcdev;
- Handle tempH;
- short rn, prefVol;
- long prefDir, count;
- Boolean commtoolbox, HaveFindFolder, HavePrefFolder;
-
- /* get some mem. I suppose this should be Handle instead. */
- tempcdev = (struct cdevstore *)NewPtr(sizeof(struct cdevstore));
- if (tempcdev == 0L)
- return (0L);
-
- if (commtoolbox =
- (NGetTrapAddress(TN_CommToolbox, OSTrap) != GetTrapAddress(TN_UnknownOS)))
- InitCRM();
- /* try to find our Preferences folder and open Prefs file */
- HaveFindFolder = HavePrefFolder = false;
- if ( Gestalt(gestaltFindFolderAttr, &rv) == noErr) {
- if ( ( 1L << gestaltFindFolderPresent ) & rv ) {
- HaveFindFolder = true;
- if ( FindFolder(kOnSystemDisk,kPreferencesFolderType,
- kCreateFolder,&prefVol,&prefDir) == noErr)
- HavePrefFolder = true;
- }
- }
-
- workstr[0] = 0;
- if (!HavePrefFolder) {
- tempH = GetResource('STR ',SYS6FOLDER); /* system 6 folder */
- AppendStr(workstr, *((b_8 **) tempH));
- ReleaseResource(tempH);
- }
- tempH = GetResource('STR ',PREFFILENAME); /* get pref file */
- AppendStr(workstr, *((b_8 **) tempH));
- ReleaseResource(tempH);
-
- rn = -1;
- if (HavePrefFolder) {
- if ( (oresult = HOpen(prefVol,prefDir,workstr,fsRdWrPerm,&rn)) == fnfErr ) {
- HCreate(prefVol,prefDir,workstr,'Mppp','PREF');
- onewresult = HOpen(prefVol,prefDir,workstr,fsRdWrPerm,&rn);
- }
- /* if we don't have PrefFolder, just use System Folder */
- } else {
- GetVRefNum(SysMap, &prefVol); /* get system Vol ref */
- if ( (oresult = FSOpen(workstr,prefVol,&rn)) == fnfErr ) {
- Create(workstr,prefVol,'Mppp','PREF');
- onewresult = FSOpen(workstr,prefVol,&rn);
- }
- }
-
- tempH = GetResource('cnfg',DEFAULTLCP);
- tempcdev->deflcp = **((struct lcpconfig **) tempH);
- ReleaseResource(tempH);
- tempH = GetResource('cnfg',DEFAULTIPCP);
- tempcdev->defipcp = **((struct ipcpconfig **) tempH);
- ReleaseResource(tempH);
-
- tempcdev->prefref = rn;
-
- if ( oresult == fnfErr ) {
- if (onewresult != noErr) {
- MyNoteAlert(PREFSCMESS);
- DisposePtr((Ptr) tempcdev);
- return (-1);
- }
- new_configs:
- tempH = GetResource('cnfg',DEFAULTPREF);
- tempcdev->prefdata = **((struct ppp_pref **) tempH); /* copy struct */
- ReleaseResource(tempH);
- initconfigs(tempcdev);
- tempH = GetResource('cnfg',DEFAULTCNFGNAME);
- AppendStr(tempcdev->prefcnfg.config_name, *((b_8 **) tempH));
- ReleaseResource(tempH);
- updateprefs(tempcdev);
- } else if (rn != -1 && oresult == noErr) {
- count = sizeof (struct ppp_pref);
- oresult = FSRead(rn, &count, &(tempcdev->prefdata));
- if (tempcdev->prefdata.version < PREF_VERSION) {
- if (NoteAlert(OLDPREFSALERT,nil) == OK)
- goto new_configs;
- else {
- FSClose(rn);
- DisposePtr((Ptr) tempcdev);
- return (-1);
- }
- }
- } else {
- MyNoteAlert(PREFSOMESS);
- DisposePtr((Ptr) tempcdev);
- return (-1);
- }
-
- /* get the pop-up menus */
-
- tempcdev->server.menuh = GetMenu(SERVERMENU);
- for (i=0 ; i < tempcdev->prefdata.max_config; i++ ) {
- if ( readconfig(tempcdev, i) != noErr) {
- ReleaseResource((Handle) tempcdev->server.menuh);
- FSClose(rn);
- DisposePtr((Ptr) tempcdev);
- return (-1);
- }
- AppendMenu(tempcdev->server.menuh, "\p ");
- SetItem(tempcdev->server.menuh, i + 1,
- tempcdev->prefcnfg.config_name);
- }
- readconfig(tempcdev, tempcdev->prefdata.active_config);
- tempcdev->baud.menuh = GetMenu(BAUDMENU);
- tempcdev->flow.menuh = GetMenu(FLOWMENU);
- tempcdev->idle.menuh = GetMenu(IDLEMENU);
- tempcdev->port.menuh = GetMenu(PORTMENU);
- tempcdev->echo.menuh = GetMenu(ECHOMENU);
- if (commtoolbox) {
- CRMRec *crmrecptr, acrmrec;
- CRMSerialRecord *serrec;
- long old = 0;
- short index = 1;
-
- acrmrec.qType = crmType;
- while (true) {
- acrmrec.crmDeviceType = crmSerialDevice;
- acrmrec.crmDeviceID = old;
- if (!(crmrecptr = (CRMRec *)CRMSearch((QElemPtr)(&acrmrec))))
- break;
- serrec = (CRMSerialRecord *)crmrecptr->crmAttributes;
- /* must do a set item because of special characters */
- AppendMenu(tempcdev->port.menuh, "\p ");
- SetItem(tempcdev->port.menuh, index, *(serrec->name));
- old = crmrecptr->crmDeviceID;
- ++index;
- }
- } else {
- AddResMenu(tempcdev->port.menuh, 'Port');
- }
- /* get port rects */
- GetDItem(dlogp, PORTRECT + numitems, &type, &itemH, &(tempcdev->port.poprect));
- GetDItem(dlogp, PTITLERECT + numitems, &type, &itemH, &(tempcdev->port.titlerect));
- /* get idle timeout rects */
- GetDItem(dlogp, IDLERECT + numitems, &type, &itemH, &(tempcdev->idle.poprect));
- GetDItem(dlogp, ITITLERECT + numitems, &type, &itemH, &(tempcdev->idle.titlerect));
- /* get server rects */
- GetDItem(dlogp, SERVERRECT + numitems, &type, &itemH, &(tempcdev->server.poprect));
- GetDItem(dlogp, STITLERECT + numitems, &type, &itemH, &(tempcdev->server.titlerect));
- /* get LCP echo interval rects */
- GetDItem(dlogp, ECHORECT + numitems, &type, &itemH, &(tempcdev->echo.poprect));
- GetDItem(dlogp, ETITLERECT + numitems, &type, &itemH, &(tempcdev->echo.titlerect));
-
- /* term window checkbox */
- if (tempcdev->prefdata.use_term)
- dosetctlval(dlogp, TERMCHECK + numitems, 1);
- /* hangup checkbox */
- if (tempcdev->prefdata.hangup)
- dosetctlval(dlogp, HANGUPCHECK + numitems, 1);
- /* quiet checkbox */
- if (tempcdev->prefdata.quiet)
- dosetctlval(dlogp, QUIETCHECK + numitems, 1);
- setbuttons(tempcdev, dlogp, numitems);
-
- return (long)tempcdev;
- }
-
- if ( (long)p != cdevUnset && (long)p != 0L ) {
-
- switch (msg) {
-
- case nulDev:
- if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
- if (lap) {
- if (lap->ppp_fsm[IPcp].state != p->saved_state)
- setbuttons(p, dlogp, numitems);
- }
- }
- break;
-
- case updateDev:
- updatecp(p, dlogp, numitems);
- break;
-
- case closeDev:
- updateprefs(p); /* update the preferences file */
- FSClose(p->prefref); /* close the Preferences file */
- ReleaseResource((Handle) p->baud.menuh);
- ReleaseResource((Handle) p->flow.menuh);
- ReleaseResource((Handle) p->port.menuh);
- ReleaseResource((Handle) p->idle.menuh);
- ReleaseResource((Handle) p->echo.menuh);
- ReleaseResource((Handle) p->server.menuh);
- DisposPtr((Ptr) p); /* release our memory */
- break;
-
- case hitDev:
- GetDItem(dlogp, item, &type, &itemH, &box);
- switch (item-numitems) {
-
- case SOFTCLOSEBTN:
- case HARDCLOSEBTN:
- if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
- if (lap && lap->lapClose && lap->transProc) {
- (*(lap->lapClose))(lap); /* close PPP */
- if ( (item - numitems) == SOFTCLOSEBTN) {
- lap->ppp_flags |= CLOSE_PPP;
- (*(lap->transProc))(TransitionOpen);
- }
- updatecp(p, dlogp, numitems);
- }
- }
- break;
-
- case OPENBTN:
- if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
- if (lap) {
- if (lap->transProc == nil) {
- if (noErr == OpenDriver("\p.IPP",&type)) { /* open TCP */
- CntrlParam tiopb;
- #define ipctlGetAddr 15 /* csCode to get our IP address */
- bzero((b_8 *)&tiopb, sizeof(tiopb));
- tiopb.ioCRefNum = type;
- tiopb.csCode = ipctlGetAddr;
- PBControl((ParamBlockRec *) &tiopb, false);
- }
- } else
- (*(lap->transProc))(TransitionOpen);
- updatecp(p, dlogp, numitems);
- }
- }
- break;
-
- case PORTRECT:
- DoPopUp(&(p->port), p->prefdata.portname);
- drawpopup(&(p->port), dlogp, p->prefdata.portname);
- updateprefs(p); /* update the preferences file */
- break;
-
- case IDLERECT:
- DoPopInt(&(p->idle), &(p->prefdata.timeout));
- drawpopint(&(p->idle), dlogp, p->prefdata.timeout);
- updateprefs(p); /* update the preferences file */
- break;
-
- case ECHORECT:
- DoPopInt(&(p->echo), &(p->prefdata.echo));
- drawpopint(&(p->echo), dlogp, p->prefdata.echo);
- updateprefs(p); /* update the preferences file */
- break;
-
- case SERVERRECT:
- workstr[0] = 0;
- AppendStr(workstr, p->prefcnfg.config_name);
- rv = DoPopUp(&(p->server), workstr);
- if (HiWord(rv) != 0) {
- p->prefdata.active_config = LoWord(rv) - 1;
- readconfig(p, p->prefdata.active_config);
- updateprefs(p); /* update the preferences file */
- }
- drawpopup(&(p->server), dlogp, workstr);
- break;
-
- case TERMCHECK:
- SetCtlValue((ControlHandle) itemH, (p->prefdata.use_term =
- GetCtlValue((ControlHandle) itemH) ^ 1));
- updateprefs(p); /* update the preferences file */
- break;
-
- case HANGUPCHECK:
- SetCtlValue((ControlHandle) itemH, (p->prefdata.hangup =
- GetCtlValue((ControlHandle) itemH) ^ 1));
- updateprefs(p); /* update the preferences file */
- break;
-
- case QUIETCHECK:
- SetCtlValue((ControlHandle) itemH, (p->prefdata.quiet =
- GetCtlValue((ControlHandle) itemH) ^ 1));
- updateprefs(p); /* update the preferences file */
- break;
-
- case STATSBTN:
- dostatsdlog();
- break;
-
- case CONFIGBTN:
- doconfigdlog(p);
- updatecp(p, dlogp, numitems);
- break;
-
- case DELETEBTN:
- if (p->prefdata.max_config == 1) {
- MyNoteAlert(CONFIGMESS);
- break;
- }
- ParamText(p->prefcnfg.config_name, "\p", "\p", "\p");
- askdlog = GetNewDialog(ASKDLOG, 0L, (WindowPtr) -1L);
- do {
- ModalDialog(nil, &itemhit);
- } while (itemhit == 0);
- DisposDialog(askdlog);
- if (itemhit != OK)
- break;
- ReleaseResource((Handle) p->server.menuh);
- p->server.menuh = GetMenu(SERVERMENU);
- --(p->prefdata.max_config);
- curconfig = p->prefdata.active_config;
- p->prefdata.active_config = 0;
- i = 1;
- for (j = 0 ; j <= p->prefdata.max_config; j++ ) {
- readconfig(p, j);
- if (j == curconfig)
- continue;
- updateprefs(p);
- (p->prefdata.active_config)++;
- AppendMenu(p->server.menuh, "\p ");
- SetItem(p->server.menuh, i, p->prefcnfg.config_name);
- i++;
- }
- if ( curconfig == p->prefdata.max_config )
- --curconfig;
- p->prefdata.active_config = curconfig;
- readconfig(p, curconfig);
- drawpopup(&(p->server), dlogp, p->prefcnfg.config_name);
- break;
-
- case NEWBTN:
- askdlog = GetNewDialog(NEWDLOG, 0L, (WindowPtr) -1L);
- do {
- ModalDialog(nil, &itemhit);
- } while (itemhit != OK && itemhit != Cancel);
- if (!gettext(askdlog, PPPSERVNAME, workstr)) {
- DisposDialog(askdlog);
- break;
- }
- DisposDialog(askdlog);
- if (itemhit != OK)
- break;
- if (workstr[0] == 0) {
- MyNoteAlert(NULLMESS);
- break;
- }
- for (j = 1 ; j <= p->prefdata.max_config; j++ ) {
- GetItem(p->server.menuh, j, holdstr);
- if (EqualString(workstr, holdstr, true, false)) {
- MyNoteAlert(SAMEMESS);
- goto badstring;
- }
- }
- /* we are adding a new server entry, init a new entry */
- initconfigs(p);
- AppendStr(p->prefcnfg.config_name, workstr);
- AppendMenu(p->server.menuh,"\p ");
- p->prefdata.active_config = p->prefdata.max_config++;
- SetItem(p->server.menuh, p->prefdata.max_config, p->prefcnfg.config_name);
- updateprefs(p);
- drawpopup(&(p->server), dlogp, p->prefcnfg.config_name);
- badstring:
- break;
-
- default:
- break;
- }
- default:
- break;
- }
- }
- return (long)p;
- }
-
- void
- updatecp(struct cdevstore *p, DialogPtr dlogp, short numitems)
- {
- drawpopup(&(p->port), dlogp, p->prefdata.portname);
- drawpopint(&(p->idle), dlogp, p->prefdata.timeout);
- drawpopint(&(p->echo), dlogp, p->prefdata.echo);
- drawpopup(&(p->server), dlogp, p->prefcnfg.config_name);
- setbuttons(p, dlogp, numitems);
- }
-
- void
- drawpopint(struct popup *p, DialogPtr dlogp, unsigned short value)
- {
- b_8 popstring[24];
- unsigned long tempvalue;
-
- if (value == 0)
- GetItem(p->menuh, 1, popstring); /* use first item if 0 */
- else {
- tempvalue = value;
- NumToString(tempvalue, popstring);
- }
- drawpopup(p, dlogp, popstring);
- }
-
- void
- drawpopup(struct popup *p, DialogPtr dlogp, b_8 *popstring)
- {
- short savfont,savsize,i;
- GrafPtr savport;
- Rect r;
-
- GetPort(&savport);
- SetPort(dlogp);
- savfont = dlogp->txFont;
- savsize = dlogp->txSize;
- TextFont(0);
- TextSize(12);
- p->poprect.bottom++;
- EraseRect(&(p->poprect));
- p->poprect.bottom--;
- /* calc pop up rectangle based on width of menu items */
- SetRect(&r, p->poprect.left,
- p->poprect.top,
- p->poprect.left + StringWidth(popstring) + 24,
- p->poprect.bottom);
-
- MoveTo(p->titlerect.left, p->titlerect.bottom-4);
- DrawString((b_8 *) &(**p->menuh).menuData);
- MoveTo(p->poprect.left+4,p->poprect.bottom-4);
- DrawString(popstring);
-
- FrameRect(&r);
- /* This must be the stupidest way to shadow a rect */
- MoveTo(r.left+3, r.bottom);
- LineTo(r.right, r.bottom);
- LineTo(r.right, r.top+3);
- /* draw the menu indicator thingy */
- for (i = 0; i < 6; ++i) {
- MoveTo(r.right - 10 - i, r.bottom - 7 - i);
- Line(2*i, 0);
- }
- TextFont(savfont);
- TextSize(savsize);
- SetPort(savport);
- }
-
- void dosetitext(DialogPtr dlogp, short itemnum, b_8 *string)
- {
- short type;
- Handle itemH;
- Rect box;
-
- GetDItem(dlogp, itemnum, &type, &itemH, &box);
- SetIText(itemH, string);
- }
-
- void dosetctlval(DialogPtr dlogp, short itemnum, short value)
- {
- short type;
- Handle itemH;
- Rect box;
-
- GetDItem(dlogp, itemnum, &type, &itemH, &box);
- SetCtlValue((ControlHandle) itemH, value);
- }
-
- void dosetilong(DialogPtr dlogp, short itemnum, b_32 value)
- {
- b_8 s[12];
-
- NumToString(value, s);
- dosetitext(dlogp, itemnum, s);
- }
-
- void dosetipaddr(DialogPtr dlogp, short itemnum, b_32 address)
- {
- b_8 s[20];
- b_8 s2[12];
- short i;
- b_8 *ptr = (b_8 *) &address;
-
- /* display 4 byte num in dot notation */
- s[0] = 0;
- for (i = 0; i<4; i++) {
- NumToString((unsigned long) *ptr++, s2);
- AppendStr(s, s2);
- AppendStr(s, "\p.");
- }
- s[0] = s[0] - 1; /* delete last dot */
- dosetitext(dlogp, itemnum, s);
- }
-
- void dosethex(DialogPtr dlogp, short itemnum, b_32 value)
- {
- b_8 s[10];
- short i;
-
- s[0] = 8;
- for (i=8; i > 0 ; i--) {
- s[i] = (value & 0xf) + '0';
- if (s[i] > '9')
- s[i] += 7;
- value >>= 4;
- }
- dosetitext(dlogp, itemnum, s);
- }
-
- void dosetcbox(DialogPtr dlogp, short itemnum, short state)
- {
- GrafPtr saveptr;
- short type;
- Handle itemH;
- Rect box;
-
- GetDItem(dlogp, itemnum, &type, &itemH, &box);
- GetPort(&saveptr);
- SetPort(dlogp);
- EraseRect(&box);
- FrameRect(&box);
- if (state) {
- MoveTo(box.left + 1 , box.bottom - 1 );
- LineTo(box.right - 1, box.top );
- MoveTo(box.left , box.top );
- LineTo(box.right -1 , box.bottom -1);
- }
- SetPort(saveptr);
- }
-
- struct pppopts {
- short itemnum;
- short optionbit;
- };
-
- void setlcpboxes(DialogPtr dlogptr, struct lcpconfig *lcpptr,
- struct pppopts *optsptr)
- {
- register short optval = optsptr->optionbit;
- register short optitem = optsptr->itemnum;
-
- dosetctlval(dlogptr, optitem++,
- (lcpptr->local.want_negotiate & optval) ? 1 : 0);
- dosetctlval(dlogptr, optitem++,
- (lcpptr->local.will_negotiate & optval) ? 1 : 0);
- dosetctlval(dlogptr, optitem++,
- (lcpptr->remote.want_negotiate & optval) ? 1 : 0);
- dosetctlval(dlogptr, optitem++,
- (lcpptr->remote.will_negotiate & optval) ? 1 : 0);
-
- switch (optval) {
- case LCP_N_MAGIC:
- dosetilong(dlogptr, optitem++, lcpptr->local.want.magic_number);
- dosetilong(dlogptr, optitem, lcpptr->remote.want.magic_number);
- break;
- case LCP_N_MRU:
- dosetilong(dlogptr, optitem++, (b_32) lcpptr->local.want.mru);
- dosetilong(dlogptr, optitem, (b_32) lcpptr->remote.want.mru);
- break;
- case LCP_N_ACCM:
- dosethex(dlogptr, optitem++, (b_32) lcpptr->local.want.accm);
- dosethex(dlogptr, optitem, (b_32) lcpptr->remote.want.accm);
- break;
- }
- }
-
- Boolean getlcpboxes(DialogPtr dlogptr, struct lcpconfig *lcpptr,
- struct pppopts *optsptr)
- {
- short type, i, k;
- unsigned long lv;
- b_8 digit;
- Handle itemH,litemH,ritemH;
- Rect box;
- b_32 mruval;
- Str255 s;
- register short optval = optsptr->optionbit;
- register short optitem = optsptr->itemnum;
-
- getnegval(dlogptr, optitem++, optval, &(lcpptr->local.want_negotiate));
- getnegval(dlogptr, optitem++, optval, &(lcpptr->local.will_negotiate));
- getnegval(dlogptr, optitem++, optval, &(lcpptr->remote.want_negotiate));
- getnegval(dlogptr, optitem++, optval, &(lcpptr->remote.will_negotiate));
-
- GetDItem(dlogptr, optitem++, &type, &litemH, &box);
- GetDItem(dlogptr, optitem, &type, &ritemH, &box);
- switch (optval) {
- case LCP_N_AUTHENT: /* we only support PAP, hardcode it */
- lcpptr->remote.want.authentication = PPP_PAP_PROTOCOL;
- break;
- case LCP_N_MAGIC:
- GetIText(litemH, s);
- StringToNum(s, (long *) &(lcpptr->local.want.magic_number));
- GetIText(ritemH, s);
- StringToNum(s, (long *) &(lcpptr->remote.want.magic_number));
- break;
- case LCP_N_ACCM:
- lcpptr->local.want.accm = 0L;
- lcpptr->remote.want.accm = 0L;
- k = optitem - 1;
- while( k <= optitem ) {
- gettext(dlogptr, k, s);
- lv = 0;
- /* convert string from hex to a long int */
- if (s[0] > 8) { /* too long */
- MyNoteAlert(ACCMMESS);
- SelIText(dlogptr, k, 0, 32767);
- return false;
- }
- for (i = 1; i <= s[0]; i++) {
- digit = s[i];
- if (digit > 0x60)
- digit &= 0xDF; /* convert to upper case */
- if (digit >= '0' && digit <= '9') {
- lv <<= 4;
- lv += digit - '0';
- } else if (digit >= 'A' && digit <= 'F') {
- lv <<= 4;
- lv += digit - 55;
- } else {
- MyNoteAlert(ACCMMESS);
- SelIText(dlogptr, k, 0, 32767);
- return false; /* parse error */
- }
- }
- if ( k == optitem )
- lcpptr->remote.want.accm = lv;
- else
- lcpptr->local.want.accm = lv;
- k++;
- }
- break;
- case LCP_N_MRU:
- GetIText(litemH, s);
- StringToNum(s, (long *) &mruval);
- if ( mruval < LCP_MRU_LO || mruval > LCP_MRU_HI ) {
- MyNoteAlert(MRUMESS);
- SelIText(dlogptr, optitem-1, 0, 32767);
- return false;
- } else
- lcpptr->local.want.mru = mruval;
- GetIText(ritemH, s);
- StringToNum(s, (long *) &mruval);
- if ( mruval < LCP_MRU_LO || mruval > LCP_MRU_HI ) {
- MyNoteAlert(MRUMESS);
- SelIText(dlogptr, optitem, 0, 32767);
- return false;
- } else
- lcpptr->remote.want.mru = mruval;
- break;
- }
- return true;
- }
-
- void doconfigdlog(struct cdevstore *p) {
- DialogPtr tempdlog, askdlog;
- GrafPtr savport;
- b_8 s[MAXSLEN + 1];
- long numval;
- short curconfig, j, i, type, itemhit;
- Handle itemH;
- Rect box;
- Boolean needupdate = true, quit = false;
-
- tempdlog = GetNewDialog(CONNECTDLOG, 0L, (WindowPtr) -1L);
- GetPort(&savport);
- SetPort(tempdlog);
- /* get baud rects */
- GetDItem(tempdlog, BAUDRECT, &type, &itemH, &(p->baud.poprect));
- GetDItem(tempdlog, BTITLERECT, &type, &itemH, &(p->baud.titlerect));
- /* get flowcontrol rects */
- GetDItem(tempdlog, FLOWRECT, &type, &itemH, &(p->flow.poprect));
- GetDItem(tempdlog, FTITLERECT, &type, &itemH, &(p->flow.titlerect));
-
- setconfigs:
- /* pulse/touchtone dialing */
- i = p->prefcnfg.flags & USE_PULSE ? PULSEBTN : TONEBTN;
- dosetctlval(tempdlog, i, 1);
- dosetitext(tempdlog, SERVERNAME, p->prefcnfg.config_name);
- dosetitext(tempdlog, MODEMINIT, p->prefcnfg.modeminit);
- dosetitext(tempdlog, PHONENUM, p->prefcnfg.phonenum);
- dosetilong(tempdlog, CONNECTTIME, p->prefcnfg.connecttimeout);
- SelIText(tempdlog, SERVERNAME, 0, 32767);
- curconfig = p->prefdata.active_config;
-
- while (!quit) {
- if (needupdate) {
- drawpopint(&(p->baud), tempdlog, p->prefcnfg.baudrate);
- GetItem(p->flow.menuh, (p->prefcnfg.flags & FLOWBITS) + 1, s);
- drawpopup(&(p->flow), tempdlog, s);
- }
- ModalDialog(dumbfilter, &itemhit);
- needupdate = true;
-
- switch (itemhit) {
- case TONEBTN:
- needupdate = false;
- dosetctlval(tempdlog, itemhit, 1);
- dosetctlval(tempdlog, PULSEBTN, 0);
- p->prefcnfg.flags &= ~USE_PULSE;
- break;
-
- case PULSEBTN:
- needupdate = false;
- dosetctlval(tempdlog, itemhit, 1);
- dosetctlval(tempdlog, TONEBTN, 0);
- p->prefcnfg.flags |= USE_PULSE;
- break;
-
- case LCPBTN:
- dolcpdlog(p);
- break;
-
- case IPCPBTN:
- doipcpdlog(p);
- break;
-
- case AUTHBTN:
- doauthdlog(p);
- break;
-
- case SCRIPTBTN:
- doscriptdlog(p);
- break;
-
- case BAUDRECT:
- DoPopInt(&(p->baud), &(p->prefcnfg.baudrate));
- break;
-
- case FLOWRECT:
- GetItem(p->flow.menuh, (p->prefcnfg.flags & FLOWBITS) + 1, s);
- numval = DoPopUp(&(p->flow), s);
- if (HiWord(numval) != 0) {
- p->prefcnfg.flags &= ~FLOWBITS;
- p->prefcnfg.flags |= ((LoWord(numval) - 1) & FLOWBITS);
- }
- break;
-
- case OK:
- /* read boxes and set resource fields */
- if (!gettext(tempdlog, MODEMINIT, p->prefcnfg.modeminit))
- break;
- if (!gettext(tempdlog, PHONENUM, p->prefcnfg.phonenum))
- break;
- if (!gettext(tempdlog, SERVERNAME, p->prefcnfg.config_name))
- break;
- if (p->prefcnfg.config_name[0] == 0) {
- MyNoteAlert(NULLMESS);
- SelIText(tempdlog, SERVERNAME, 0, 32767);
- break;
- }
- for (j = 1 ; j <= p->prefdata.max_config; j++ ) {
- if (j == curconfig + 1)
- continue;
- GetItem(p->server.menuh, j, s);
- if (EqualString(s, p->prefcnfg.config_name, true, false)) {
- MyNoteAlert(SAMEMESS);
- goto setconfigs;
- }
- }
- SetItem(p->server.menuh, curconfig + 1, p->prefcnfg.config_name);
- if (!gettext(tempdlog, CONNECTTIME, s))
- break;
- StringToNum(s, &numval);
- p->prefcnfg.connecttimeout = LoWord(numval);
- updateprefs(p);
- quit = true;
- break;
-
- default:
- needupdate = false;
- break;
- }
- }
- DisposDialog(tempdlog);
- SetPort(savport);
- }
-
- void doauthdlog(struct cdevstore *p) {
- pascal Boolean authfilter(DialogPtr, EventRecord *, short *);
- DialogPtr tempdlog;
- struct mydlogrec authdlogrec;
- short itemhit;
- b_8 s[MAXSLEN + 1];
- short strlen;
-
- tempdlog = GetNewDialog(AUTHDLOG, &authdlogrec, (WindowPtr) -1L);
-
- dosetitext(tempdlog, AUTHID, p->prefcnfg.defaultid);
- strlen = (s[0] = p->prefcnfg.defaultpw[0]);
- while (strlen > 0)
- s[strlen--] = 'Ñ';
- dosetitext(tempdlog, AUTHPW, s);
- s[0] = 0;
- AppendStr(s, p->prefcnfg.defaultpw);
- authdlogrec.strptr = s;
- dosetilong(tempdlog, AUTHRETRIES, (b_32) p->prefcnfg.pap_retries);
- dosetilong(tempdlog, AUTHTIMEOUT, (b_32) p->prefcnfg.pap_timeout);
-
- do {
- ModalDialog(authfilter, &itemhit);
- if (itemhit == OK) {
- if (!gettext(tempdlog, AUTHID, p->prefcnfg.defaultid))
- continue;
- if (!getbyte(tempdlog, AUTHRETRIES, &(p->prefcnfg.pap_retries)))
- continue;
- if (!getbyte(tempdlog, AUTHTIMEOUT, &(p->prefcnfg.pap_timeout)))
- continue;
- strlen = p->prefcnfg.defaultpw[0];
- while (strlen >= 0)
- p->prefcnfg.defaultpw[strlen--] = 0; /* clear old string */
- AppendStr(p->prefcnfg.defaultpw, s);
- break;
- }
- } while (itemhit != Cancel);
- CloseDialog(tempdlog);
- }
-
- void doscriptdlog(struct cdevstore *p) {
- pascal Boolean scriptfilter(DialogPtr, EventRecord *, short *);
- DialogPtr tempdlog;
- b_8 s[MAXSLEN + 1];
- long numval;
- short i, type, itemhit;
- Handle itemH;
- Rect box;
-
- tempdlog = GetNewDialog(SCRIPTDLOG, 0L, (WindowPtr) -1L);
- dosetilong(tempdlog, WAITTIME, p->prefcnfg.waittimeout);
-
- for (i = 0 ; i < NUMCOMMANDS; i++ ) {
- dosetitext(tempdlog, COMMANDS + i, p->prefcnfg.commands[i].scriptstr);
- dosetctlval(tempdlog, ADDRETURNS + i, p->prefcnfg.commands[i].addreturn);
- itemhit = COMMANDBTNS + i*2;
- if (!p->prefcnfg.commands[i].sendout)
- itemhit++;
- dosetctlval(tempdlog, itemhit, 1);
- }
- scriptretry:
- do {
- ModalDialog(scriptfilter, &itemhit);
-
- if (itemhit >= COMMANDBTNS && itemhit < (COMMANDBTNS +NUMCOMMANDS * 2) ) {
- dosetctlval(tempdlog, itemhit, 1);
- dosetctlval(tempdlog, COMMANDBTNS + ((itemhit - COMMANDBTNS) ^ 1), 0);
- }
- if (itemhit >= ADDRETURNS && itemhit < (ADDRETURNS + NUMCOMMANDS) ) {
- GetDItem(tempdlog, itemhit, &type, &itemH, &box);
- SetCtlValue((ControlHandle) itemH,
- (GetCtlValue((ControlHandle) itemH) ^ 1));
- }
-
- if (itemhit == OK) {
- for (i = 0 ; i < NUMCOMMANDS; i++ ) {
- if (!gettext(tempdlog, COMMANDS+i, p->prefcnfg.commands[i].scriptstr))
- goto scriptretry;
- GetDItem(tempdlog,ADDRETURNS + i,&type,&itemH,&box);
- p->prefcnfg.commands[i].addreturn =
- GetCtlValue((ControlHandle) itemH);
- GetDItem(tempdlog,COMMANDBTNS + i*2,&type,&itemH,&box);
- p->prefcnfg.commands[i].sendout =
- GetCtlValue((ControlHandle) itemH);
- }
- if (!gettext(tempdlog, WAITTIME, s))
- goto scriptretry;
- StringToNum(s, (long *) &numval);
- p->prefcnfg.waittimeout = LoWord(numval);
- break;
- }
- } while (itemhit != Cancel);
- DisposDialog(tempdlog);
- }
-
- void dostatsdlog() {
- LapInfo *lap;
- DialogPtr tempdlog;
- short itemhit;
-
- if ( Gestalt((OSType) 'PPP ', (long *) &lap) != noErr)
- return;
- tempdlog = GetNewDialog(STATSDLOG, 0L, (WindowPtr) -1L);
- updatestats:
- dosetilong(tempdlog, INOCTETS, lap->InRxOctetCount);
- dosetilong(tempdlog, OUTOCTETS, lap->OutTxOctetCount);
- dosetilong(tempdlog, INPACKETS, lap->InOpenFlag);
- dosetilong(tempdlog, OUTPACKETS, lap->OutOpenFlag);
- dosetilong(tempdlog, CHECKSEQERRS, (b_32) lap->InCheckSeq);
- dosetilong(tempdlog, HEADERERRS, (b_32) lap->InHeader);
- dosetilong(tempdlog, HWOVERRUNS, (b_32) lap->InHardOvr);
- dosetilong(tempdlog, SWOVERRUNS, (b_32) lap->InSoftOvr);
- dosetilong(tempdlog, FRAMINGERRS, (b_32) lap->InFramingErr);
- dosetilong(tempdlog, OUTOFBUFS, (b_32) lap->OutofBuffers);
- dosetcbox(tempdlog, PFCVALS,lap->lcp_i.local.work_negotiate & LCP_N_PFC);
- dosetcbox(tempdlog, PFCVALS + 1, lap->lcp_i.remote.work_negotiate & LCP_N_PFC);
- dosetcbox(tempdlog, ACFCVALS, lap->lcp_i.local.work_negotiate & LCP_N_ACFC);
- dosetcbox(tempdlog, ACFCVALS + 1, lap->lcp_i.remote.work_negotiate & LCP_N_ACFC);
- dosetcbox(tempdlog, PAPVALS, lap->lcp_i.local.work_negotiate & LCP_N_AUTHENT);
- dosetcbox(tempdlog, PAPVALS + 1, lap->lcp_i.remote.work_negotiate & LCP_N_AUTHENT);
- dosethex(tempdlog, MAGICVALS, lap->lcp_i.local.work.lcp_option.magic_number);
- dosethex(tempdlog, MAGICVALS + 1, lap->lcp_i.remote.work.lcp_option.magic_number);
- dosethex(tempdlog, ACCMVALS, lap->lcp_i.local.work.lcp_option.accm);
- dosethex(tempdlog, ACCMVALS + 1, lap->lcp_i.remote.work.lcp_option.accm);
- dosetilong(tempdlog, MRUVALS, lap->lcp_i.local.work.lcp_option.mru);
- dosetilong(tempdlog, MRUVALS + 1, lap->lcp_i.remote.work.lcp_option.mru);
- dosetcbox(tempdlog, VJVALS,lap->ipcp_i.local.work_negotiate & IPCP_N_COMPRESS);
- dosetcbox(tempdlog, VJVALS + 1, lap->ipcp_i.remote.work_negotiate & IPCP_N_COMPRESS);
- dosetilong(tempdlog, VJSLOTS, lap->ipcp_i.local.work.ipcp_option.slots);
- dosetilong(tempdlog, VJSLOTS + 1,lap->ipcp_i.remote.work.ipcp_option.slots);
- dosetcbox(tempdlog, VJCID,lap->ipcp_i.local.work.ipcp_option.slot_compress);
- dosetcbox(tempdlog, VJCID + 1, lap->ipcp_i.remote.work.ipcp_option.slot_compress);
- dosetipaddr(tempdlog, IPADDRVALS, lap->ipcp_i.local.work.ipcp_option.address);
- dosetipaddr(tempdlog, IPADDRVALS + 1, lap->ipcp_i.remote.work.ipcp_option.address);
- do {
- ModalDialog(nil, &itemhit);
- if (itemhit == UPDATEBTN)
- goto updatestats;
- } while (itemhit != OK);
- DisposDialog(tempdlog);
- }
- #define NUMLCPOPTS 6
-
- void dolcpdlog(struct cdevstore *p)
- {
- DialogPtr optsdlog;
- Str255 s;
- short type, i, itemhit, ctlvalue;
- Handle itemH;
- Rect box;
- struct pppopts options[NUMLCPOPTS];
-
- options[0].itemnum = PFCBOXES;
- options[0].optionbit = LCP_N_PFC;
- options[1].itemnum = ACFCBOXES;
- options[1].optionbit = LCP_N_ACFC;
- options[2].itemnum = AUTHENTBOXES;
- options[2].optionbit = LCP_N_AUTHENT;
- options[3].itemnum = MAGICBOXES;
- options[3].optionbit = LCP_N_MAGIC;
- options[4].itemnum = ACCMBOXES;
- options[4].optionbit = LCP_N_ACCM;
- options[5].itemnum = MRUBOXES;
- options[5].optionbit = LCP_N_MRU;
-
- optsdlog = GetNewDialog(LCPDLOG, 0L, (WindowPtr) -1L);
-
- for ( i=0 ; i < NUMLCPOPTS; i++ )
- setlcpboxes(optsdlog, &(p->prefcnfg.lcpconf), &options[i]);
- dosetilong(optsdlog, LCPRETRIES, (b_32) p->prefcnfg.lcpconf.req_tries);
- dosetilong(optsdlog, LCPTIMEOUT, (b_32) p->prefcnfg.lcpconf.timeout);
- do {
- dolcpdlog:
- ModalDialog(dumbfilter, &itemhit);
- for ( i=0 ; i < NUMLCPOPTS; i++ ) {
- if (itemhit >= options[i].itemnum &&
- itemhit < options[i].itemnum + 4) {
- GetDItem(optsdlog, itemhit, &type, &itemH, &box);
- SetCtlValue((ControlHandle) itemH,
- (ctlvalue = GetCtlValue((ControlHandle) itemH) ^ 1));
- switch (itemhit - options[i].itemnum) {
- case 0:
- case 2:
- if (ctlvalue) {
- dosetctlval(optsdlog, itemhit+1, 1);
- }
- break;
- case 1:
- case 3:
- if (!ctlvalue) {
- dosetctlval(optsdlog, itemhit-1, 0);
- }
- }
- break;
- }
- }
- if (itemhit == LCPDEFAULT) {
- for ( i=0 ; i < NUMLCPOPTS; i++ )
- setlcpboxes(optsdlog, &(p->deflcp), &options[i]);
- dosetilong(optsdlog, LCPRETRIES, (b_32) p->deflcp.req_tries);
- dosetilong(optsdlog, LCPTIMEOUT, (b_32) p->deflcp.timeout);
- }
- if (itemhit == OK) {
- for ( i=0 ; i < NUMLCPOPTS; i++ ) {
- if (!getlcpboxes(optsdlog, &(p->prefcnfg.lcpconf), &options[i]))
- goto dolcpdlog;
- }
- if (!getbyte(optsdlog, LCPRETRIES, &(p->prefcnfg.lcpconf.req_tries)))
- goto dolcpdlog;
- if (!getbyte(optsdlog, LCPTIMEOUT, &(p->prefcnfg.lcpconf.timeout)))
- goto dolcpdlog;
- updateprefs(p);
- break;
- }
- }
- while (itemhit != Cancel);
-
- DisposDialog(optsdlog);
- }
-
- void setipcpboxes(DialogPtr dlogptr, struct ipcpconfig *ipcpptr,
- struct pppopts *optsptr)
- {
- register short optval = optsptr->optionbit;
- register short optitem = optsptr->itemnum;
-
- dosetctlval(dlogptr, optitem++,
- (ipcpptr->local.want_negotiate & optval) ? 1 : 0);
- dosetctlval(dlogptr, optitem++,
- (ipcpptr->local.will_negotiate & optval) ? 1 : 0);
- dosetctlval(dlogptr, optitem++,
- (ipcpptr->remote.want_negotiate & optval) ? 1 : 0);
- dosetctlval(dlogptr, optitem++,
- (ipcpptr->remote.will_negotiate & optval) ? 1 : 0);
-
- switch (optval) {
- case IPCP_N_ADDRESS:
- dosetipaddr(dlogptr, optitem++, ipcpptr->local.want.address);
- dosetipaddr(dlogptr, optitem, ipcpptr->remote.want.address);
- break;
- };
- }
-
- Boolean getipcpboxes(DialogPtr dlogptr, struct ipcpconfig *ipcpptr,
- struct pppopts *optsptr)
- {
- short type, i, j, k;
- unsigned long lv;
- b_8 *ptr;
- Str255 s;
- Str32 s2;
- register short optval = optsptr->optionbit;
- register short optitem = optsptr->itemnum;
-
- getnegval(dlogptr, optitem++, optval, &(ipcpptr->local.want_negotiate));
- getnegval(dlogptr, optitem++, optval, &(ipcpptr->local.will_negotiate));
- getnegval(dlogptr, optitem++, optval, &(ipcpptr->remote.want_negotiate));
- getnegval(dlogptr, optitem++, optval, &(ipcpptr->remote.will_negotiate));
-
- switch (optval) {
- case IPCP_N_ADDRESS:
- /* accept both forms of address negotiation */
- if (ipcpptr->local.will_negotiate & IPCP_N_ADDRESS)
- ipcpptr->local.will_negotiate | IPCP_N_ADDRESSES;
- else
- ipcpptr->local.will_negotiate & ~IPCP_N_ADDRESSES;
-
- if (ipcpptr->remote.will_negotiate & IPCP_N_ADDRESS)
- ipcpptr->remote.will_negotiate | IPCP_N_ADDRESSES;
- else
- ipcpptr->remote.will_negotiate & ~IPCP_N_ADDRESSES;
-
- ipcpptr->local.want.address = 0L;
- ipcpptr->remote.want.address = 0L;
- ipcpptr->local.want.other = 0L;
- ipcpptr->remote.want.other = 0L;
- k = optitem++;
- while( k <= optitem ) {
- gettext(dlogptr, k, s);
- /* convert string from dot notation to a long int */
- ptr = &s[1];
- s[s[0]+1] = '.';
- for (j = 3; j >= 0; j--) {
- s2[0] = 0;
- for (i = 1; *ptr != '.'; i++) {
- if ((ptr > s + s[0]) || (*ptr > '9') || (*ptr < '0')){
- MyNoteAlert(IPMESS);
- SelIText(dlogptr, k, 0, 32767);
- return false; /* parse error */
- }
- s2[i] = *ptr++;
- s2[0]++;
- }
- ptr++;
- StringToNum(s2, (long *) &lv);
- if (lv > 255) {
- MyNoteAlert(IPMESS);
- SelIText(dlogptr, k, 0, 32767);
- return false; /* parse error */
- }
- lv <<= j*8;
- if ( k == optitem ) {
- ipcpptr->remote.want.address |= lv;
- ipcpptr->local.want.other |= lv;
- } else {
- ipcpptr->local.want.address |= lv;
- ipcpptr->remote.want.other |= lv;
- }
- }
- k++;
- }
- break;
- }
- return true;
- }
-
- #define NUMIPCPOPTS 2
-
- void doipcpdlog(struct cdevstore *p)
- {
- DialogPtr optsdlog;
- Str255 s;
- short type, i, itemhit, ctlvalue;
- Handle itemH;
- Rect box;
- struct pppopts options[NUMIPCPOPTS];
-
- options[0].itemnum = COMPRESSBOXES;
- options[0].optionbit = IPCP_N_COMPRESS;
- options[1].itemnum = ADDRESSBOXES;
- options[1].optionbit = IPCP_N_ADDRESS;
-
- optsdlog = GetNewDialog(IPCPDLOG, 0L, (WindowPtr) -1L);
- for ( i=0 ; i < NUMIPCPOPTS; i++ )
- setipcpboxes(optsdlog, &(p->prefcnfg.ipcpconf), &options[i]);
- dosetilong(optsdlog, IPCPRETRIES, (b_32) p->prefcnfg.ipcpconf.req_tries);
- dosetilong(optsdlog, IPCPTIMEOUT, (b_32) p->prefcnfg.ipcpconf.timeout);
- do {
- doipcpdlog:
- ModalDialog(dumbfilter, &itemhit);
- for ( i=0 ; i < NUMIPCPOPTS; i++ ) {
- if (itemhit >= options[i].itemnum &&
- itemhit < options[i].itemnum + 4) {
- GetDItem(optsdlog, itemhit, &type, &itemH, &box);
- SetCtlValue((ControlHandle) itemH,
- (ctlvalue = GetCtlValue((ControlHandle) itemH) ^ 1));
- switch (itemhit - options[i].itemnum) {
- case 0:
- case 2:
- if (ctlvalue) {
- dosetctlval(optsdlog, itemhit+1, 1);
- }
- break;
- case 1:
- case 3:
- if (!ctlvalue) {
- dosetctlval(optsdlog, itemhit-1, 0);
- }
- }
- break;
- }
- }
- if (itemhit == IPCPDEFAULT) {
- for ( i=0 ; i < NUMIPCPOPTS; i++ )
- setipcpboxes(optsdlog, &(p->defipcp), &options[i]);
- dosetilong(optsdlog, IPCPRETRIES, (b_32) p->defipcp.req_tries);
- dosetilong(optsdlog, IPCPTIMEOUT, (b_32) p->defipcp.timeout);
- }
- }
- while (itemhit != OK && itemhit != Cancel);
- if (itemhit == OK) {
- for ( i=0 ; i < NUMIPCPOPTS; i++ ) {
- if (!getipcpboxes(optsdlog, &(p->prefcnfg.ipcpconf), &options[i]))
- goto doipcpdlog;
- }
- if (!getbyte(optsdlog, IPCPRETRIES, &(p->prefcnfg.ipcpconf.req_tries)))
- goto doipcpdlog;
- if (!getbyte(optsdlog, IPCPTIMEOUT, &(p->prefcnfg.ipcpconf.timeout)))
- goto doipcpdlog;
- updateprefs(p);
- }
- DisposDialog(optsdlog);
- }
-
- void getnegval(DialogPtr dlogptr, short itemnum, short optval, b_16 *optptr)
- {
- short type;
- Handle itemH;
- Rect box;
-
- GetDItem(dlogptr, itemnum, &type, &itemH, &box);
- if (GetCtlValue((ControlHandle) itemH))
- *optptr |= optval;
- else
- *optptr &= ~optval;
- }
-
- long DoPopInt(struct popup *p, b_16 *value)
- {
- long rv;
- b_8 valstring[24];
- unsigned long tempval;
-
- tempval = *value;
- NumToString(tempval, valstring);
- rv = DoPopUp(p, valstring);
- if (HiWord(rv) != 0) {
- if (valstring[1] < '0' || valstring[1] > '9' )
- *value = 0;
- else {
- StringToNum(valstring, (long *) &tempval);
- *value = LoWord(tempval);
- }
- }
- return rv;
- }
-
- long DoPopUp(struct popup *p, b_8 *nameptr)
- {
- long rv;
- short mitems;
- b_8 istring[64];
- Point where;
-
- where.h = p->poprect.left;
- where.v = p->poprect.top;
- p->poprect.bottom++;
- EraseRect(&(p->poprect));
- p->poprect.bottom--;
- LocalToGlobal(&(where));
- mitems = CountMItems(p->menuh);
- while (mitems > 0) {
- GetItem(p->menuh, mitems, istring);
- if (EqualString(istring, nameptr, FALSE, FALSE))
- break;
- mitems--;
- }
- if (mitems == 0)
- mitems = 1;
-
- InvertRect(&(p->titlerect));
- InsertMenu(p->menuh, -1);
- rv = PopUpMenuSelect(p->menuh, where.v, where.h, mitems);
- DeleteMenu((*(p->menuh))->menuID);
- InvertRect(&(p->titlerect));
- if (HiWord(rv) != 0)
- GetItem(p->menuh, LoWord(rv), nameptr);
- return rv;
- }
-
- OSErr readconfig( struct cdevstore *storptr, short confignum )
- {
- long count;
- OSErr rc;
-
- rc = SetFPos(storptr->prefref,fsFromStart,
- sizeof(struct ppp_pref) + sizeof (struct ppp_config) * confignum);
- count = sizeof ( struct ppp_config );
- if ( rc == noErr)
- rc = FSRead(storptr->prefref, &count, &(storptr->prefcnfg));
- if (rc != noErr)
- MyNoteAlert(PREFSRMESS);
- return rc;
- }
-
- OSErr updateprefs( struct cdevstore *storptr )
- {
- long count, index;
- OSErr rc;
-
- rc = SetFPos(storptr->prefref,fsFromStart,0L); /* start at beginning */
- count = sizeof(struct ppp_pref);
- if ( rc == noErr )
- rc = FSWrite(storptr->prefref, &count, &(storptr->prefdata));
- count = sizeof (struct ppp_config);
- index = storptr->prefdata.active_config * count;
- if ( rc == noErr )
- rc = SetFPos(storptr->prefref,fsFromMark,index);
- if ( rc == noErr )
- rc = FSWrite(storptr->prefref, &count, &(storptr->prefcnfg));
- if (rc != noErr)
- MyNoteAlert(PREFSWMESS);
- return rc;
- }
-
- Boolean getbyte(DialogPtr dlogptr, short itemnum, b_8 *byte)
- {
- Str255 s;
- long numval;
-
- if (!gettext(dlogptr, itemnum, s))
- return false;
- StringToNum(s, &numval);
- *byte = numval & 0xff;
- return true;
- }
-
- Boolean gettext(DialogPtr dlogptr, short itemnum, b_8 *textptr)
- {
- Str255 s;
- short type, i, itemhit;
- Handle itemH;
- Rect box;
-
- GetDItem(dlogptr, itemnum, &type, &itemH, &box);
- GetIText(itemH, s);
- if (s[0] > MAXSLEN) {
- MyNoteAlert(STRINGMESS);
- SelIText(dlogptr, itemnum, 0, 32767);
- return false;
- } else {
- *textptr = 0;
- AppendStr(textptr, s);
- return true;
- }
- }
-
- void setbuttons(struct cdevstore *p, DialogPtr dlogp, short numitems)
- {
- LapInfo *lap;
- short type;
- Rect box,iconrect;
- Handle itemH1, itemH2, itemH3, tempH;
-
- GetDItem(dlogp, numitems + PPPICON, &type, &tempH, &iconrect);
- GetDItem(dlogp, numitems + OPENBTN, &type, &itemH1, &box);
- GetDItem(dlogp, numitems + SOFTCLOSEBTN, &type, &itemH2, &box);
- GetDItem(dlogp, numitems + HARDCLOSEBTN, &type, &itemH3, &box);
- if ( Gestalt((OSType) 'PPP ', (long *) &lap) == noErr) {
- if (lap != nil) {
- p->saved_state = lap->ppp_fsm[IPcp].state;
- if (lap->ppp_fsm[IPcp].state == fsmOPENED ) {
- tempH = GetIcon(PPPUPICON);
- PlotIcon(&iconrect, tempH);
- ReleaseResource(tempH);
- HiliteControl((ControlHandle) itemH3, 0);
- HiliteControl((ControlHandle) itemH2, 0);
- HiliteControl((ControlHandle) itemH1, 255);
- return;
- } else {
- HiliteControl((ControlHandle) itemH1, 0);
- goto buttonjmp;
- }
- }
- }
- HiliteControl((ControlHandle) itemH1, 255); /* buttons are inactive */
- buttonjmp:
- HiliteControl((ControlHandle) itemH2, 255);
- HiliteControl((ControlHandle) itemH3, 255);
- tempH = GetIcon(PPPDOWNICON);
- PlotIcon(&iconrect, tempH);
- ReleaseResource(tempH);
- }
-
- main()
- {}
-
- pascal Boolean authfilter(DialogPtr dlog, EventRecord *evt, short *itemhit)
- {
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short c,i;
- b_8 *charptr;
- b_8 s[MAXSLEN + 1];
-
- charptr = ( (struct mydlogrec *) dlog)->strptr;
- c = evt->message & charCodeMask;
-
- if ( ((DialogPeek) dlog)->editField + 1 == AUTHPW ) {
- switch(evt->what) {
- case keyDown:
- case autoKey:
- if (c > 31) {
- if (*charptr < MAXSLEN)
- *( charptr + ++(*charptr) )= c;
- *itemhit = 0;
- } else if (c == RETURN || c == ENTER )
- *itemhit = OK;
- else if (c == TAB)
- *itemhit == AUTHRETRIES;
- else if (c == BACKSPACE) {
- if (*charptr > 0)
- (*charptr)--;
- *itemhit = 0;
- }
- GetDItem(dlog, AUTHPW, &itemType, &itemHdl, &itemRect);
- i = s[0] = *charptr;
- while ( i > 0 )
- s[i--] = 'Ñ';
- SetIText(itemHdl, s);
- SelIText(dlog, AUTHPW, 32767, 32767);
- return(true);
- break;
- }
- } else if ( ((DialogPeek) dlog)->editField + 1 == AUTHID ) {
- switch(evt->what) {
- case keyDown:
- case autoKey:
- if (c == RETURN || c == ENTER || c == TAB) {
- *itemhit = AUTHPW;
- SelIText(dlog, AUTHPW, 0, 32767);
- return(true);
- }
- break;
- }
- }
-
- *itemhit=0;
- return(false);
- }
-
- pascal Boolean scriptfilter(DialogPtr dlog, EventRecord *evt, short *itemhit)
- {
- short c;
-
- switch(evt->what) {
- case keyDown:
- case autoKey:
- c = evt->message & charCodeMask;
- if ( c == 8 || ( c >= 28 && c <= 31 ) || c > 31 )
- break;
- if ( c == 13 || c == 9 ) {
- switch ( ((DialogPeek) dlog)->editField + 1 ) {
- case WAITTIME:
- SelIText(dlog, COMMANDS, 0, 32767);
- break;
- case (COMMANDS + NUMCOMMANDS - 1):
- if (c == 13)
- *itemhit = 1;
- else
- SelIText(dlog, WAITTIME, 0, 32767);
- break;
- default:
- SelIText(dlog, ((DialogPeek) dlog)->editField + 2, 0, 32767);
- }
- }
- return true;
- }
- return false;
- }
-
- pascal Boolean dumbfilter(DialogPtr dlog, EventRecord *evt, short *itemhit)
- {
- short c;
- switch(evt->what) {
- case keyDown:
- case autoKey:
- c = evt->message & charCodeMask;
- if ( c == 8 || ( c >= 28 && c <= 31 ) || ( c > 31 ) )
- break;
- return true; /* don't process <returns> etc. */
- }
- return false;
- }
-
- void
- MyNoteAlert(b_8 stringnum)
- {
- register b_8 *strptr;
- b_8 **messages;
-
- messages = (b_8 **) Get1Resource('STR#',STATUSSTRINGS);
- strptr = *messages;
- strptr++;
- if (stringnum > *strptr++ ) /* check if string is out of range */
- return;
- while (--stringnum > 0) /* find string in list */
- strptr += *strptr + 1;
- HLock((Handle) messages); /* lock down the Handle */
- ParamText(strptr,"\p","\p","\p"); /* set the text in the dialog */
- HUnlock((Handle) messages);
- ResetAlrtStage();
- NoteAlert(ERRALERT, nil);
- ReleaseResource((Handle) messages);
- }
-
- void initconfigs(struct cdevstore *p) {
- short i;
-
- p->prefcnfg.lcpconf = p->deflcp;
- p->prefcnfg.ipcpconf = p->defipcp;
- p->prefcnfg.pap_retries = 10;
- p->prefcnfg.pap_timeout = 3;
- p->prefcnfg.baudrate = 9600; /* use 9600 as default for baudrate */
- p->prefcnfg.flags = 0; /* no flow control, tone dial */
- p->prefcnfg.config_name[0] = 0;
- p->prefcnfg.defaultid[0] = 0; /* init strings */
- p->prefcnfg.defaultpw[0] = 0;
- p->prefcnfg.modeminit[0] = 0;
- p->prefcnfg.phonenum[0] = 0;
- p->prefcnfg.connecttimeout = 90; /* initial connect timeout */
- p->prefcnfg.waittimeout = 40; /* initial wait timeout */
- for (i=0 ; i < NUMCOMMANDS; i++) {
- p->prefcnfg.commands[i].sendout = true; /* make all output */
- p->prefcnfg.commands[i].addreturn = false; /* no returns */
- p->prefcnfg.commands[i].scriptstr[0] = 0;
- }
- }
-
- void AppendStr(b_8 *dst, b_8 *src)
- {
- b_8 dl,sl;
-
- dl = *dst;
- sl = *src++;
- *dst++ += sl;
- dst += dl;
- BlockMove(src, dst, (unsigned long) sl);
- }
-
-