home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d5 / Telnet 2.6.1d5.src.sit.hqx / Telnet 2.6.1d5 src / source / main / Connections.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-22  |  21.2 KB  |  737 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1993,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. *****************************************************************/
  13.  
  14. #ifdef MPW
  15. #pragma segment 4
  16. #endif
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21.  
  22. #include "TelnetHeader.h"
  23. #include "dialog_resrcdefs.h"
  24. #include "menu_resrcdefs.h"
  25. #include "string_resrcdefs.h"
  26. #include "debug.h"
  27.  
  28. #include "telneterrors.h"
  29. #include "DlogUtils.proto.h"
  30.  
  31. #include "wind.h"
  32. #include "event.proto.h"
  33.  
  34. #include "rsinterf.proto.h"
  35. #include "vsdata.h"
  36. #include "vskeys.h"
  37. #include "vsinterf.proto.h"
  38. #include "vgtek.proto.h"
  39. #include "tekrgmac.proto.h"
  40. #include "vr.h"
  41. #include "vrrgmac.proto.h" 
  42. #include "network.proto.h"
  43. #include "mydnr.proto.h"
  44. #include "InternalEvents.h"
  45. #include "menuseg.proto.h"
  46. #include "maclook.proto.h"
  47. #include "parse.proto.h"
  48. #include "parse.h"
  49. #include "configure.proto.h"
  50. #include "netevent.proto.h"
  51.  
  52. #include "prefs.proto.h"
  53. #include "popup.h"
  54. #include "popup.proto.h"
  55.  
  56. #include "Connections.proto.h"
  57. #include "tnae.h"
  58. #include "authencrypt.h"
  59. #include "authencrypt.proto.h"
  60. #include "wdefpatch.proto.h"
  61.  
  62. /*    These are all of the variables we need... */
  63.  
  64. extern    Cursor    *theCursors[NUMCURS];        /* all the cursors in a nice bundle */
  65. extern    WindRec    *screens;
  66. extern    short    scrn;
  67. extern    short    nNational;                // Number of user-installed translation tables
  68. extern    MenuHandle    myMenus[];
  69. extern    Boolean    authOK;
  70. extern    Boolean    encryptOK;
  71. extern    unsigned char *gReadspace;
  72. extern    short    gBlocksize;
  73.  
  74. static    short    WindByPort(short port);
  75. static    void setSessStates(DialogPtr dptr);
  76.  
  77. static    pascal short POCdlogfilter( DialogPtr dptr, EventRecord *evt, short *item);
  78. PROTO_UPP(POCdlogfilter, ModalFilter);
  79.  
  80. void OpenPortSpecial(MenuHandle menuh, short item)
  81. {
  82.     ConnInitParams        **theParams;
  83.     Boolean                success;
  84.     Str255                scratchPstring;
  85.     
  86.     GetItem(menuh, item, scratchPstring);
  87.     
  88.     theParams = NameToConnInitParams(scratchPstring);
  89.     if (theParams == NULL) {
  90.         OutOfMemory(1020);
  91.         return;
  92.         }
  93.         
  94.     success = CreateConnectionFromParams(theParams);
  95. }
  96.  
  97. SIMPLE_UPP(POCdlogfilter, ModalFilter);
  98. pascal short POCdlogfilter( DialogPtr dptr, EventRecord *evt, short *item)
  99. {
  100.     short key;
  101.  
  102.     if (evt->what == keyDown) {
  103.         key = evt->message & charCodeMask;
  104.         if ( ((key == 'A') || (key == 'a')) && (evt->modifiers & cmdKey) ) {
  105.             *item = NCauthenticate;
  106.             return(-1);
  107.             }
  108.         if ( ((key == 'E') || (key == 'e')) && (evt->modifiers & cmdKey) ) {
  109.             *item = NCencrypt;
  110.             return(-1);
  111.             }
  112.         }
  113.     
  114.     return(DLOGwOK_Cancel(dptr, evt, item));
  115. }
  116.  
  117. void    PresentOpenConnectionDialog(void)
  118. {
  119.     ConnInitParams    **InitParams;
  120.     DialogPtr        dptr;
  121.     short            ditem, scratchshort;
  122.     static long        numWind = 1;
  123.     Boolean            success;
  124.     long            scratchlong;
  125.     Str255            scratchPstring;
  126.     Handle            ItemHandle;
  127.     SessionPrefs    **defaultSessHdl;
  128.     MenuHandle        SessPopupHdl;
  129.     Rect            scratchRect;
  130.     Point            SessPopupLoc;
  131.     
  132.     SetCursor(theCursors[normcurs]);
  133.     
  134.     dptr = GetNewMyDialog(NewCnxnDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  135.     if (dptr == NULL) {
  136.         OutOfMemory(1000);
  137.         return;
  138.         }
  139.         
  140.     ditem = 3;
  141.     
  142.     SessPopupHdl = NewMenu(668, "\pSession:");
  143.     if (SessPopupHdl == NULL) {
  144.         OutOfMemory(1000);
  145.         DisposeDialog(dptr);
  146.         return;
  147.         }
  148.         
  149.     UseResFile(TelInfo->SettingsFile);
  150.     AddResMenu(SessPopupHdl, SESSIONPREFS_RESTYPE);
  151.     EnableItem(SessPopupHdl, 0);        // Make sure the entire menu is enabled
  152.     
  153.     GetDItem(dptr, NCsesspopup, &scratchshort, &ItemHandle, &scratchRect);
  154.     SessPopupLoc.h = scratchRect.left;
  155.     SessPopupLoc.v = scratchRect.top;
  156.     SetPort(dptr);
  157.     LocalToGlobal(&SessPopupLoc);
  158.     
  159.     // Get default auth/encrypt settings from default session
  160.     defaultSessHdl = GetDefaultSession();
  161.     HLock((Handle)defaultSessHdl);
  162.  
  163.     BlockMove("\p<Default>", scratchPstring, 15);
  164.     GetHostNameFromSession(scratchPstring);
  165.     SetTEText(dptr, NChostname, scratchPstring);
  166.     SelIText(dptr, NChostname, 0, 32767);
  167.  
  168.     SetCntrl(dptr, NCauthenticate, (**defaultSessHdl).authenticate && authOK);
  169.     SetCntrl(dptr, NCencrypt, (**defaultSessHdl).encrypt && encryptOK);
  170.     DisposeHandle((Handle)defaultSessHdl);
  171.         
  172.     setSessStates(dptr);
  173.  
  174.     while (ditem > NCcancel) {
  175.         ModalDialog(POCdlogfilterUPP, &ditem);
  176.         switch(ditem) {
  177.             case    NCauthenticate:
  178.             case    NCencrypt:
  179.                 GetDItem(dptr, ditem, &scratchshort, &ItemHandle, &scratchRect);
  180.                 if ((**(ControlHandle)ItemHandle).contrlHilite == 0) {    // if control not disabled
  181.                     FlipCheckBox(dptr, ditem);
  182.                     setSessStates(dptr);
  183.                 }
  184.                 break;
  185.  
  186.             case    NCsesspopup:
  187.                 InsertMenu(SessPopupHdl, hierMenu);
  188.                 CalcMenuSize(SessPopupHdl);
  189.                 scratchlong = PopUpMenuSelect(SessPopupHdl, SessPopupLoc.v,
  190.                                                 SessPopupLoc.h, 0);
  191.                 DeleteMenu(668);
  192.                 if (scratchlong) {
  193.                     scratchshort = scratchlong & 0xFFFF; //    Apple sez ignore the high word
  194.                     GetItem(SessPopupHdl, scratchshort, scratchPstring);
  195.                     SetTEText(dptr, NChostname, scratchPstring);
  196.                     SelIText(dptr, NChostname, 0, 32767);
  197.                     }
  198.                 break;
  199.                                 
  200.             default:
  201.                 break;
  202.             } // switch
  203.         } // while
  204.     
  205.     DisposeMenu(SessPopupHdl);
  206.     
  207.     if (ditem == NCcancel) {
  208.         DisposeDialog(dptr);
  209.         return;
  210.         }
  211.     
  212.     GetTEText(dptr, NChostname, scratchPstring);
  213.     if (!Length(scratchPstring)) {
  214.         DisposeDialog(dptr);
  215.         return;
  216.         }
  217.         
  218.     InitParams = NameToConnInitParams(scratchPstring);
  219.     if (InitParams == NULL) {
  220.         OutOfMemory(1000);
  221.         DisposeDialog(dptr);
  222.         return;
  223.         }
  224.  
  225.     HLock((Handle)InitParams);
  226.     HLock((Handle)(**InitParams).session);
  227.     GetTEText(dptr, NCwindowname, scratchPstring);
  228.  
  229.     // Copy over the user specified window name.  If blank, CreateConnectionFromParams 
  230.     // will copy the hostname to the windowname and append a number.
  231.     if (Length(scratchPstring)) 
  232.         BlockMove(scratchPstring, (**InitParams).WindowName,
  233.                     (Length(scratchPstring) > 63) ? 64 : (Length(scratchPstring) + 1));
  234.  
  235.      if (GetCntlVal(dptr, NCauthenticate))
  236.           (**(**InitParams).session).authenticate = 1;
  237.      else
  238.          (**(**InitParams).session).authenticate = 0;
  239.      if (GetCntlVal(dptr, NCencrypt))
  240.           (**(**InitParams).session).encrypt = 1;
  241.      else
  242.          (**(**InitParams).session).encrypt = 0;
  243.         
  244.     HUnlock((Handle)(**InitParams).session);
  245.     HUnlock((Handle)InitParams);
  246.         
  247.     DisposeDialog(dptr);
  248.     
  249.     success = CreateConnectionFromParams(InitParams);
  250. }
  251.  
  252. // Set states of session checkboxes
  253. static    void setSessStates (DialogPtr dptr)
  254. {        
  255.     if (GetCntlVal(dptr, NCauthenticate)) {
  256.         Hilite(dptr, NCencrypt, (encryptOK)? 0 : 255);
  257.     } else {
  258.         Hilite(dptr, NCencrypt, 255);
  259.         SetCntrl(dptr, NCencrypt, false);
  260.     }
  261. }
  262.  
  263. void    OpenConnectionFromURL(char *host, char *portstring, char *user, char *password)
  264. {
  265.     ConnInitParams    **Params;
  266.     Str255            windowName, tempString;
  267.     short            len;
  268.     long            port;
  269.     
  270.     Params = ReturnDefaultConnInitParams();
  271.     
  272.     windowName[0] = 0;
  273.     
  274.     // Set up window name if user (and password) given
  275.     if (user != nil) {
  276.         GetIndString(windowName, MISC_STRINGS, MISC_USERPRMPT);
  277.         len = strlen(user);
  278.         BlockMoveData(user,& windowName[Length(windowName)+1], len);
  279.         windowName[0] += len;
  280.         if (password != nil) {
  281.         GetIndString(tempString, MISC_STRINGS, MISC_PSWDPRMPT);
  282.             BlockMoveData(&tempString[1], &windowName[Length(windowName)+1], tempString[0]);
  283.             windowName[0] += tempString[0];
  284.             len = strlen(password);
  285.             BlockMoveData(password, &windowName[Length(windowName)+1], len);
  286.             windowName[0] += len;
  287.             }
  288.  
  289.         if (windowName[0] != 0) {
  290.             BlockMoveData(windowName, (**Params).WindowName, Length(windowName)+1);
  291.             }
  292.         }        
  293.     
  294.     CtoPstr(host);
  295.     BlockMoveData(host, (**(**Params).session).hostname, host[0]+1);
  296.     
  297.     if (portstring != nil) {
  298.         CtoPstr(portstring);
  299.         StringToNum((StringPtr)portstring, &port);
  300.         (**(**Params).session).port = port;
  301.         }
  302.         
  303.     (void)CreateConnectionFromParams(Params);
  304. }    
  305.  
  306. Boolean CreateConnectionFromParams( ConnInitParams **Params)
  307. {
  308.     short            scratchshort, fontnumber, offset;
  309.     static short    numWind = 1, stagNum = 1;
  310.     SessionPrefs    *SessPtr;
  311.     TerminalPrefs    *TermPtr;
  312.     short            cur;
  313.     Str32            numPstring;
  314.     Str255            scratchPstring;
  315.     Boolean            scratchBoolean;
  316.     
  317.     SetCursor(theCursors[watchcurs]);                    /* We may be here a bit */
  318.  
  319.     // Check if we have the max number of sessions open
  320.     if (TelInfo->numwindows == MaxSess) return(FALSE);
  321.     
  322.     cur = TelInfo->numwindows;            /* Adjust # of windows and get this window's number */
  323.     TelInfo->numwindows++;
  324.     screens[cur].active = CNXN_NOTINUSE;    // Make sure it is marked as dead (in case we
  325.                                         // abort screen creation after initiating DNR.
  326.                                         // That way CompleteConnectionOpening will know
  327.                                         // we didn't make it.
  328.     HLockHi((Handle)Params);
  329.     HLockHi((Handle)(**Params).terminal);
  330.     HLockHi((Handle)(**Params).session);
  331.     SessPtr = *((**Params).session);
  332.     TermPtr = *((**Params).terminal);
  333.  
  334.     if (Length((**Params).WindowName) == 0) {
  335.         BlockMove((**(**Params).session).hostname, (**Params).WindowName, 
  336.                     Length((**(**Params).session).hostname)+1);
  337.         NumToString(numWind++, numPstring);
  338.         pstrcat((**Params).WindowName, "\p ");
  339.         pstrcat((**Params).WindowName, numPstring);    // tack the number onto the end.
  340.         }
  341.         
  342.     // Get the IP for the host while we set up the connection
  343.     if (DoTheDNR(SessPtr->hostname, cur) != noErr) {
  344.         OutOfMemory(1010);
  345.         DisposeHandle((Handle)(**Params).terminal);
  346.         DisposeHandle((Handle)(**Params).session);
  347.         DisposeHandle((Handle)Params);
  348.         TelInfo->numwindows--;
  349.         updateCursor(1);
  350.         return(FALSE);
  351.         }
  352.         
  353.     DoTheMenuChecks();
  354.     
  355.       screens[cur].authenticate = SessPtr->authenticate && authOK;
  356.       screens[cur].encrypt = SessPtr->encrypt && encryptOK;
  357.  
  358.     screens[cur].aedata = NULL;
  359.      
  360.      for (scratchshort = 0; scratchshort < sizeof(screens[cur].myopts); scratchshort++) {
  361.         screens[cur].myopts[scratchshort] = 0;
  362.         screens[cur].hisopts[scratchshort] = 0;        
  363.     }    
  364.     screens[cur].cannon[0] = '\0';
  365.  
  366.     screens[cur].vtemulation = TermPtr->vtemulation;
  367.     screens[cur].forcesave = SessPtr->forcesave;
  368.     screens[cur].lineAllow = SessPtr->linemode;
  369.     screens[cur].eightbit = TermPtr->eightbit;    // Is this necessary?
  370.     screens[cur].portNum = SessPtr->port;
  371.     screens[cur].emacsmeta = TermPtr->emacsmetakey;
  372.     screens[cur].Xterm = TermPtr->Xtermsequences;
  373.     
  374.     screens[cur].port = -1;                // netxopen will take care of this
  375.  
  376.     screens[cur].lmode = 0;
  377.     for (scratchshort=0; scratchshort<= SLC_ARRAY_SIZE; scratchshort++)
  378.         screens[cur].slc[scratchshort] = -1;
  379.     screens[cur].slc[SLC_IP] = 3;
  380.     screens[cur].slc[SLC_EC] = 127;
  381.     screens[cur].slc[SLC_EL] = 21;
  382.     screens[cur].slc[SLC_EOF] = 4;
  383.     screens[cur].slc[SLC_ABORT] = 3;
  384.     screens[cur].slc[SLC_SUSP] = 26; 
  385.  
  386.     // If the caller has not specified a window location, come up with our own.
  387.     // This function can possibly stagger windows right off the screen.
  388.     if((**Params).WindowLocation.top == 0) {
  389.         offset = ((gApplicationPrefs->StaggerWindows == TRUE) ? 10 : 2) * (stagNum++);
  390.         (**Params).WindowLocation.top = GetMBarHeight() + 10 + offset;
  391.         (**Params).WindowLocation.left  = offset;
  392.         (**Params).WindowLocation.bottom= 30000 + offset;
  393.         (**Params).WindowLocation.right = 30000 + offset;
  394.         }
  395.         
  396.     GetFNum(TermPtr->DisplayFont, &fontnumber);
  397.     
  398.     screens[cur].vs = RSnewwindow( &((**Params).WindowLocation), TermPtr->numbkscroll, TermPtr->vtwidth,
  399.                                     TermPtr->vtheight, (**Params).WindowName, TermPtr->vtwrap,
  400.                                     fontnumber, TermPtr->fontsize, 0,
  401.                                     1,
  402.                                     SessPtr->forcesave);
  403.                                     
  404.     if (screens[cur].vs <0 ) {     /* we have a problem opening up the virtual screen */
  405.         OutOfMemory(1011);
  406.         DisposeHandle((Handle)(**Params).terminal);
  407.         DisposeHandle((Handle)(**Params).session);
  408.         DisposeHandle((Handle)Params);
  409.         TelInfo->numwindows--;
  410.         DoTheMenuChecks();
  411.         updateCursor(1);
  412.         return(FALSE);
  413.         }
  414.  
  415.     screens[cur].wind = RSgetwindow( screens[cur].vs);
  416.     ((WindowPeek)screens[cur].wind)->windowKind = WIN_CNXN;
  417.     
  418.     /*
  419.      * Attach our extra part to display encryption status
  420.      */
  421.     PatchWindowWDEF(screens[cur].wind, &screens[cur]);
  422.  
  423.     screens[cur].arrowmap = TermPtr->emacsarrows;          /* MAT -- save our arrow setting */
  424.     screens[cur].maxscroll= TermPtr->numbkscroll;
  425.     screens[cur].bsdel = SessPtr->bksp;
  426.     screens[cur].crmap = SessPtr->crmap;
  427.     screens[cur].tekclear = SessPtr->tekclear;
  428.     screens[cur].ESscroll= TermPtr->clearsave;
  429.     screens[cur].tektype = SessPtr->tektype;
  430.     screens[cur].wrap = TermPtr->vtwrap;
  431.     screens[cur].pgupdwn = TermPtr->MATmappings;        /* JMB: map pgup/pgdwn/home/end? */
  432.     screens[cur].TELstop = SessPtr->skey;
  433.     screens[cur].TELgo = SessPtr->qkey;
  434.     screens[cur].TELip = SessPtr->ckey;
  435.     BlockMove((Ptr)SessPtr->hostname, screens[cur].machine, Length(SessPtr->hostname)+1);
  436.     BlockMove(TermPtr->AnswerBackMessage, screens[cur].answerback, 32);
  437.     screens[cur].termstate = VTEKTYPE;
  438.     screens[cur].naws = 0;                                /* NCSA - set default NAWS to zero */
  439.     screens[cur].telstate=0;
  440.     screens[cur].timing=0;
  441.     screens[cur].curgraph=-1;                /* No graphics screen */
  442.     screens[cur].clientflags = 0;            /* BYU */
  443.     screens[cur].kblen = 0;                /* nothing in the buffer */
  444.     screens[cur].enabled = 1;            /* Gotta be enabled to start with */
  445.     screens[cur].Ittype = 0;
  446.     screens[cur].Isga = 0;                /* I suppress go ahead = no */
  447.     screens[cur].Usga = 0;                /* U suppress go ahead = no */
  448.  
  449.     screens[cur].termstate=VTEKTYPE;    /* BYU */
  450.     screens[cur].echo = 1;
  451.     screens[cur].halfdup = SessPtr->halfdup;    /* BYU */
  452.     
  453.     screens[cur].national = 0;            // Default to no translation.
  454.     // Now see if the desired translation is available, if not use default translation.
  455.     for(scratchshort = 1; scratchshort <= nNational+1; scratchshort++) {
  456.         GetItem(myMenus[National], scratchshort, scratchPstring);
  457.         if (EqualString(SessPtr->TranslationTable, scratchPstring, TRUE, FALSE))
  458.             screens[cur].national = scratchshort-1;
  459.         }
  460.                 
  461.     
  462.     // Set up paste related variables
  463.     screens[cur].incount = 0;
  464.     screens[cur].outcount = 0;
  465.     screens[cur].outptr = NULL;
  466.     screens[cur].outhand = NULL;
  467.     screens[cur].outlen = 0;
  468.     screens[cur].pastemethod = SessPtr->pastemethod;
  469.     screens[cur].pastesize = SessPtr->pasteblocksize;
  470.     
  471.     scratchBoolean = RSsetcolor( screens[cur].vs, 0, TermPtr->nfcolor);
  472.     scratchBoolean = RSsetcolor( screens[cur].vs, 1, TermPtr->nbcolor);
  473.     scratchBoolean = RSsetcolor( screens[cur].vs, 2, TermPtr->bfcolor);
  474.     scratchBoolean = RSsetcolor( screens[cur].vs, 3, TermPtr->bbcolor);
  475.  
  476.     addinmenu(cur, (**Params).WindowName, diamondMark);
  477.     screens[cur].active = CNXN_DNRWAIT;            // Signal we are waiting for DNR.
  478.  
  479.     screens[cur].myInitParams = (Handle)Params;
  480.     HUnlock((Handle)(**Params).terminal);
  481.     HUnlock((Handle)(**Params).session);
  482.     // Params handle must stay locked because interrupt level DNR completion routine needs to deref it
  483.  
  484.     VSscrolcontrol( screens[cur].vs, -1, screens[cur].ESscroll);
  485.  
  486.     updateCursor(1);                            /* Done stalling the user */
  487.     return(TRUE);
  488. }
  489.  
  490. void    CompleteConnectionOpening(short dat, ip_addr the_IP, OSErr DNRerror, char *cname)
  491. {
  492.     ConnInitParams    **Params;
  493.     
  494.     if (screens[dat].active != CNXN_DNRWAIT) return;            // Something is wrong.
  495.     
  496.     Params = (ConnInitParams **)screens[dat].myInitParams;
  497.     
  498.     if (DNRerror == noErr) {
  499.         HLockHi((Handle)(**Params).session);
  500.  
  501.         if ((**(**Params).session).NetBlockSize <= 512)
  502.             (**(**Params).session).NetBlockSize = 512; //less than this can really get messy
  503.         if (setReadBlockSize((**(**Params).session).NetBlockSize,dat) != 0) //couldnt get read buffer
  504.             return;
  505.         screens[dat].port  = netxopen(the_IP,(**(**Params).session).port,40);/* BYU 2.4.15 - open to host name */
  506.         
  507.         // We need the cannonical hostname for Kerberos. Make best guess if
  508.         // DNR did not return a cname.
  509.         if (cname)
  510.             strncpy(screens[dat].cannon, cname, sizeof(screens[dat].cannon));
  511.         else
  512.             strncpy(screens[dat].cannon, (char *)(**(**Params).session).hostname, sizeof(screens[dat].cannon));
  513.         screens[dat].cannon[sizeof(screens[dat].cannon)-1] = '\0';
  514.         
  515.         DisposeHandle((Handle)(**Params).session);
  516.         DisposeHandle((Handle)(**Params).terminal);
  517.         DisposeHandle((Handle)Params);
  518.         
  519.         if (screens[dat].port <0) {                    /* Handle netxopen fail */
  520.             destroyport(dat);
  521.             }
  522.         screens[dat].active = CNXN_OPENING;
  523.         SetMenuMarkToOpeningForAGivenScreen(dat);    /* Change status mark */
  524.         }
  525.     else
  526.         {    // We should report the real DNR error here!
  527.         Str255        errorString, numberString, numberString2, scratchPstring;
  528.         DialogPtr    theDialog;
  529.         short        message, ditem = 3;
  530.         
  531.         HLockHi((Handle)(**Params).session);
  532.         BlockMove((**(**Params).session).hostname, scratchPstring, Length((**(**Params).session).hostname)+1);
  533.  
  534.         if (DNRerror >= -23048 && DNRerror <= -23041) message = DNRerror + 23050;
  535.         else message = 1;
  536.         
  537.         GetIndString(errorString,DNR_MESSAGES_ID, message);
  538.         NumToString((long)0, numberString);
  539.         NumToString((long)DNRerror, numberString2);
  540.         ParamText(scratchPstring, errorString, numberString, numberString2);
  541.         
  542.         theDialog = GetNewMyDialog(DNRErrorDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  543.         ShowWindow(theDialog);
  544.     
  545.         while (ditem > 1)    ModalDialog(DLOGwOKUPP, &ditem);
  546.         DisposeDialog(theDialog);
  547.  
  548.         DisposeHandle((Handle)(**Params).session);
  549.         DisposeHandle((Handle)(**Params).terminal);
  550.         DisposeHandle((Handle)Params);
  551.         destroyport(dat);
  552.         }
  553. }
  554.  
  555. void    ConnectionOpenEvent(short port)
  556. {
  557.     short    i;
  558.     
  559.     i=WindByPort(port);
  560.     if (i<0) { 
  561.         return;
  562.         }
  563.              
  564.     screens[ i].active= CNXN_ACTIVE;
  565.     RSshow( screens[i].vs);            /* BYU */
  566.     SelectWindow(screens[i].wind);    /* BYU */
  567.  
  568.     telnet_send_initial_options(&screens[i]);
  569.  
  570.     changeport(scrn,i);        /* BYU */
  571.     SetMenuMarkToLiveForAGivenScreen(scrn);            /* BYU */
  572.     DoTheMenuChecks();        /* BYU */
  573. }
  574.  
  575. void    ConnectionDataEvent(short port)
  576. {
  577.     short    i, cnt;
  578.     
  579.     i=WindByPort(port);                                    /* BYU */
  580.     if (i<0) {return; }                    /* BYU */
  581.     if (TelInfo->ScrlLock || !screens[i].enabled)    /* BYU LSC */
  582.         netputuev( CONCLASS, CONDATA, port,0);
  583.     else {
  584.         cnt = netread(port,gReadspace,gBlocksize);    /* BYU LSC */
  585.         parse( &screens[i], gReadspace, cnt);    /* BYU LSC */
  586.         screens[i].incount += cnt;                /* BYU LSC */
  587.         }
  588. }
  589.  
  590. void    ConnectionFailedEvent(short port)
  591. {
  592.     short    i;
  593.     Str255    scratchPstring;
  594.     
  595.     netclose( port);
  596.     i= WindByPort(port);
  597.     if (i<0) { return; }
  598.     BlockMove((Ptr)screens[i].machine, (Ptr)scratchPstring, Length(screens[i].machine)+1);
  599.     PtoCstr(scratchPstring);
  600.     DoError(807 | NET_ERRORCLASS, LEVEL2, (char *)scratchPstring);
  601.     
  602.     if (screens[i].active != CNXN_ACTIVE) destroyport(i);    // JMB - 2.6
  603.     else removeport(&screens[i]);        // JMB - 2.6
  604. }
  605.  
  606. void    ConnectionClosedEvent(short port)
  607. {
  608.     short i;
  609.  
  610.     i= WindByPort(port);
  611.     if (i<0) { 
  612.         netclose( port);            /* We close again.... */
  613.         return;
  614.         }
  615.  
  616.     FlushNetwork(i);                /* BYU */
  617.     netclose( screens[i].port);        /* BYU */
  618.     removeport(&screens[i]);                    /* BYU */
  619. }
  620.  
  621. static    short    WindByPort(short port)
  622. {
  623.     short i=0;
  624.  
  625.     while (i<TelInfo->numwindows &&
  626.             (screens[i].port != port || 
  627.                 ((screens[i].active != CNXN_ACTIVE) && (screens[i].active != CNXN_OPENING)))
  628.             ) i++;
  629.  
  630.     if (i>=TelInfo->numwindows) {                    /* BYU */
  631.         putln("Can't find a window for the port # in WindByPort");    /* BYU */
  632.         if (i==0) i=999;        /* BYU */
  633.         return(-i);                /* BYU */
  634.         }                        /* BYU */
  635.  
  636.     return(i);
  637. }
  638.  
  639. void destroyport(short wind)
  640. {
  641.     Handle    h;
  642.     short    i,
  643.             callNoWindow=0;
  644.     WindRecPtr    tw;
  645.     
  646.     tw = &screens[wind];
  647.     
  648.     SetCursor(theCursors[watchcurs]);        /* We may be here a while */
  649.  
  650.     if (tw->active == CNXN_ISCORPSE) {
  651.         if (tw->curgraph>-1)
  652.             detachGraphics( tw->curgraph);    /* Detach the Tek screen */
  653.         if (tw->outlen>0) {
  654.             tw->outlen=0;                        /* Kill the remaining send*/
  655.             HUnlock( tw->outhand);            /*  buffer */
  656.             HPurge ( tw->outhand);
  657.             }
  658.         }
  659.  
  660.     if (FrontWindow() == tw->wind)
  661.         callNoWindow=1;
  662.  
  663.     if (tw->aedata != NULL)
  664.         DisposePtr((Ptr)tw->aedata);
  665.  
  666.     /*
  667.      * Get handle to the WDEF patch block, kill the window, and then
  668.      * release the handle.
  669.      */
  670.     h = GetPatchStuffHandle(tw->wind, tw);
  671.     RSkillwindow( tw->vs);
  672.     if (h)
  673.         DisposeHandle(h);
  674.  
  675.     tw->active = CNXN_NOTINUSE;
  676.     for (i=wind;i<TelInfo->numwindows-1;i++) {
  677.         screens[i]=screens[i+1];        /* Bump all of the pointers */
  678.         RePatchWindowWDEF(screens[i].wind, &screens[i]);    /* hack hack hack */
  679.         }
  680.     if (scrn>wind) scrn--;                /* Adjust for deleting a lower #ered screen */
  681.  
  682.     TelInfo->numwindows--;                        /* There are now fewer windows */
  683.     extractmenu( wind);                    /* remove from the menu bar */
  684.  
  685.     DoTheMenuChecks();
  686.  
  687. /* BYU 2.4.11 - the call to "NoWindow()" changes "myfrontwindow", 
  688.                 which is used by "updateCursor()", so we reversed 
  689.                 the order of the following two lines. */
  690.     if (callNoWindow) NoWindow();        /* BYU 2.4.11 - Update cursor stuff if front window */
  691.     updateCursor(1);                    /* BYU 2.4.11 - Done stalling the user */
  692.  
  693. } /* destroyport */
  694.  
  695. void removeport(WindRecPtr tw)
  696. {
  697.     Str255        scratchPstring;
  698.     
  699.     SetCursor(theCursors[watchcurs]);                /* We may be here a while */
  700.  
  701.     if (tw->curgraph>-1)
  702.         detachGraphics( tw->curgraph);        /* Detach the Tek screen */
  703.         
  704.     if (tw->outlen>0) {
  705.                 tw->outlen=0;                /* Kill the remaining send*/
  706.                 HUnlock( tw->outhand);        /*  buffer */
  707.                 HPurge ( tw->outhand);
  708.                 }
  709.  
  710.     if (VSiscapturing(tw->vs))                /* NCSA: close up the capture */
  711.         CloseCaptureFile(tw->vs);            /* NCSA */
  712.  
  713.     if (VSisprinting(tw->vs))
  714.         ClosePrintingFile(tw->vs);
  715.         
  716.     if (!gApplicationPrefs->WindowsDontGoAway)
  717.         destroyport(findbyVS(tw->vs));
  718.     else {
  719.         Str255    temp;
  720.         
  721.         GetWTitle(tw->wind, scratchPstring);
  722. #ifdef THINK_C
  723.         sprintf((char *)temp, "(%#s)", scratchPstring);
  724. #else
  725.         PtoCstr(scratchPstring);
  726.         sprintf((char *)temp, "(%s)", scratchPstring);
  727. #endif
  728.         CtoPstr((char *)temp);
  729.         SetWTitle(tw->wind, temp);
  730.  
  731.         tw->port = 32700;
  732.         tw->active = CNXN_ISCORPSE;
  733.         }
  734.  
  735.     updateCursor(1);                            /* Done stalling the user */
  736. } /* removeport */
  737.