home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / winsock / wsftp32 / ws_host.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  38.9 KB  |  1,154 lines

  1. /***************************************************************************
  2.   Windows Sockets Client Application Support Module
  3.  
  4.   Written by:
  5.       John A. Junod             Internet: <junodj@gordon-emh2.army.mil>
  6.       267 Hillwood Street                 <zj8549@trotter.usma.edu>
  7.       Martinez, GA 30907      Compuserve: 72321,366 
  8.  
  9.   This program executable and all source code is released into the public
  10.   domain.  It would be nice (but is not required) to give me a little 
  11.   credit for any use of this code.  
  12.  
  13.   THE INFORMATION AND CODE PROVIDED IS PROVIDED AS IS WITHOUT WARRANTY 
  14.   OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  15.   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  16.   PURPOSE. IN NO EVENT SHALL JOHN A. JUNOD BE LIABLE FOR ANY DAMAGES 
  17.   WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS 
  18.   OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF JOHN A. JUNOD HAS BEEN 
  19.   ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  20.  
  21. *****************************************************************************/
  22.  
  23. #include "ws_glob.h"
  24. #include "ws_ftp.h"
  25. #include <io.h>     // access()
  26. #include <stdlib.h> // atoi()
  27.  
  28. char szInitDir[80];
  29. char szSessionName[80];
  30.  
  31. #define MAXTYPES 17
  32. LPSTR szHostTypes[MAXTYPES]={
  33.   "auto detect",
  34.   "Chameleon",
  35.   "FTP PC-TCP",
  36.   "IBM-PC TCP/IP",
  37.   "IBM-VM/MVS",
  38.   "KA9Q/NOS",
  39.   "NCSA/CUTCP",
  40.   "SI NT FTPD",
  41.   "Super TCP",
  42.   "Unisys 5000 (EXOS)",
  43.   "UNIX (default)",
  44.   "VMS-Multinet",
  45.   "VMS-UCX",
  46.   "WinQVT/Net",
  47.   "Windows NT",
  48.   "Solaris - Unix",
  49.   "Windows NT - Software Innovations"
  50.   };
  51.  
  52. // int nTypes[MAXHOSTS];
  53. BOOL bSavePWD=FALSE;
  54. BOOL bUseGateWay=FALSE;
  55. char szCrypt[160];
  56. LPSTR szAnony="anonymous";
  57. int nHostType=HOST_TYPE_AUTO;
  58. extern BOOL bHELP;
  59. extern BOOL bCanMKD,bCanRMD,bCanREN,bCanDELE;
  60. extern HBRUSH hbrGray1,hbrGray2;
  61. extern void check_scroll();
  62.  
  63.    // lgk new function to get remote search string
  64.  
  65.  char *remotesearchstring()
  66.   {
  67.           unsigned char szBuf[120];
  68.        WORD cbText;
  69.  
  70.        *(WORD *) szBuf = sizeof(szBuf) -1; // sets the buffer size
  71.  
  72.        cbText = (WORD)SendMessage(hRdirBox,
  73.                  EM_GETLINE,(WPARAM)0,(DWORD)(LPSTR)szBuf);
  74.        szBuf[cbText] = '\0';
  75.        return szBuf;
  76.   }
  77.   
  78.  
  79. void LoadConfigNames(HWND);
  80. /*
  81. // this encryption is not secure nor is it intended to be
  82. // this is just to keep the password from being plain text
  83. // in the ini file.  I'd really recommend people don't save
  84. // their passwords
  85. */
  86. LPSTR EnCrypt(LPSTR userid,LPSTR passwd)
  87. {
  88.   int nIndex;
  89.   if(lstrcmp(userid,szAnony)==0)
  90.     return(passwd);
  91.   szCrypt[0]=0;
  92.   for(nIndex=0;nIndex<lstrlen(passwd);nIndex++) {
  93.     wsprintf(&szCrypt[nIndex*2],"%02X",
  94.       ((char)passwd[nIndex])+nIndex);
  95.   }
  96.   return(szCrypt);
  97. }
  98.  
  99. int unhex(char c) {
  100.   if(c>'9') return(c-'7');
  101.   return (c-'0');
  102. }
  103.  
  104. LPSTR DeCrypt(LPSTR userid,LPSTR passwd)
  105. {
  106.   int nIndex;
  107.   if(lstrcmp(userid,szAnony)==0)
  108.     return(passwd);
  109.   szCrypt[0]=0;
  110.   for(nIndex=0;nIndex<lstrlen(passwd);nIndex+=2) {
  111.     (BYTE)szCrypt[nIndex/2]=
  112.       ((unhex(passwd[nIndex])*16)+
  113.        unhex(passwd[nIndex+1]))-(nIndex/2);
  114.     szCrypt[nIndex/2+1]=0;
  115.   }
  116.   return(szCrypt);
  117. }
  118.  
  119. /*******************************************************
  120.   Set the dialog box controls according to the current
  121.   selected host.
  122. */
  123. SetDefaultHostStuff(HWND hWndDlg,LPSTR szSession) {
  124.  
  125.   szRemoteHost[0]=0;
  126.   GetPrivateProfileString(szSession,"HOST",szSession,szRemoteHost,79,szIniFile);
  127.   SetDlgItemText(hWndDlg,DLG_HOST_ADDRESS,szRemoteHost);
  128.  
  129.   szUserID[0]=0;
  130.   GetPrivateProfileString(szSession,"UID",NULL,szUserID,79,szIniFile);
  131.   SetDlgItemText(hWndDlg,DLG_HOST_USERID,szUserID);
  132.  
  133.   szPassWord[0]=0; szMsgBuf[0]=0; bSavePWD=FALSE;
  134.   GetPrivateProfileString(szSession,"PWD",NULL,szMsgBuf,79,szIniFile);
  135.   if(szUserID[0]!=0 && szMsgBuf[0]!=0) {
  136.     lstrcpy(szPassWord,DeCrypt(szUserID,szMsgBuf));
  137.     bSavePWD=TRUE;
  138.   }
  139.   CheckDlgButton(hWndDlg,DLG_HOST_PWD,bSavePWD);
  140.  
  141.   if(lstrcmpi(szUserID,szAnony)==0) {
  142.     CheckDlgButton(hWndDlg,DLG_HOST_ANONY,TRUE);
  143.     if(szPassWord[0]==0) {
  144.       if(szMailAddress[0]==0)
  145.         StdInput(szMailAddress,"Enter your e-mail address:");
  146.       else
  147.         lstrcpy(szPassWord,szMailAddress);
  148.     }
  149.   } else
  150.     CheckDlgButton(hWndDlg,DLG_HOST_ANONY,FALSE);
  151.   SetDlgItemText(hWndDlg,DLG_HOST_PASSWORD,szPassWord);
  152.  
  153.   szInitDir[0]=0;
  154.   GetPrivateProfileString(szSession,"DIR",NULL,szInitDir,79,szIniFile);
  155.   SetDlgItemText(hWndDlg,DLG_HOST_DIR,szInitDir);
  156.  
  157.   szGateHost[0]=0; bUseGateWay=FALSE;
  158.   GetPrivateProfileString(szSession,"GATEHOST",NULL,szGateHost,79,szIniFile);
  159.   if(szGateHost[0]!=0) bUseGateWay=TRUE;
  160.   CheckDlgButton(hWndDlg,DLG_HOST_GATEWAY,bUseGateWay);
  161.  
  162.   nHostType=GetPrivateProfileInt(szSession,"TYPE",HOST_TYPE_AUTO,szIniFile);
  163.   SendDlgItemMessage(hWndDlg,DLG_HOST_TYPE,CB_SETCURSEL,nHostType-6000,0l);
  164.  
  165.   uiTimeOut=GetPrivateProfileInt(szSession,"TIMEOUT",65,szIniFile);
  166.   SetDlgItemInt(hWndDlg,DLG_HOST_TIMEOUT,uiTimeOut,FALSE);
  167.  
  168.   uiRetries=GetPrivateProfileInt(szSession,"RETRIES",0,szIniFile);
  169.   SetDlgItemInt(hWndDlg,DLG_HOST_RETRIES,uiRetries,FALSE);
  170.  
  171.   uiFtpPort=GetPrivateProfileInt(szSession,"FTPPORT",21,szIniFile);
  172.   SetDlgItemInt(hWndDlg,DLG_HOST_FTP_PORT,uiFtpPort,FALSE);
  173.  
  174.   return TRUE;
  175. }
  176.  
  177. BOOL CALLBACK WS_GateMsgProc(HWND hWndDlg, WORD Message,
  178.                                WORD wParam, LONG lParam)
  179. {
  180.  //nt nIndex;
  181.  //INT nRC;
  182.  
  183.   switch(Message)
  184.   {
  185.     case WM_INITDIALOG:
  186.       GetPrivateProfileString(szSessionName,"GATEHOST",
  187.         NULL,szGateHost,79,szIniFile);
  188.       SetDlgItemText(hWndDlg,DLG_HOST_ADDRESS,szGateHost);
  189.       GetPrivateProfileString(szSessionName,"GATEUSERID",
  190.         NULL,szGateUserID,79,szIniFile);
  191.       SetDlgItemText(hWndDlg,DLG_HOST_USERID,szGateUserID);
  192.       if(GetPrivateProfileString(szSessionName,"GATEPASSWORD",
  193.         NULL,szGatePassWord,79,szIniFile))
  194.         strcpy(szGatePassWord,DeCrypt(szGateUserID,szGatePassWord));
  195.       SetDlgItemText(hWndDlg,DLG_HOST_PASSWORD,szGatePassWord);
  196.       CheckDlgButton(hWndDlg,DLG_HOST_PWD,bSavePWD);
  197.       break;
  198.     case WM_CLOSE:
  199.       PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L);
  200.       break;
  201.  
  202.       
  203.         case WM_CTLCOLORBTN:
  204.             if(LOWORD(lParam)<10) return((LRESULT)NULL);
  205.        case WM_CTLCOLORDLG:
  206.         case WM_CTLCOLORSTATIC:
  207.           SetBkColor((HDC) wParam, RGB(192,192,192));
  208.           return(LRESULT)hbrGray1;
  209.           break;
  210.  
  211.         case WM_CTLCOLORLISTBOX:
  212.           return(LRESULT)hbrGray1;
  213.           break;
  214.  
  215.     case WM_COMMAND:
  216.       switch(LOWORD(wParam))
  217.       {
  218.         case IDOK:
  219.           GetDlgItemText(hWndDlg,DLG_HOST_ADDRESS,szGateHost,79);
  220.           WritePrivateProfileString(szSessionName,"GATEHOST",
  221.              szGateHost,szIniFile);
  222.           GetDlgItemText(hWndDlg,DLG_HOST_USERID,szGateUserID,79);
  223.           WritePrivateProfileString(szSessionName,"GATEUSERID",
  224.              szGateUserID,szIniFile);
  225.           GetDlgItemText(hWndDlg,DLG_HOST_PASSWORD,szGatePassWord,79);
  226.           if(IsDlgButtonChecked(hWndDlg,DLG_HOST_PWD))
  227.             WritePrivateProfileString(szSessionName,"GATEPASSWORD",
  228.               EnCrypt(szGateUserID,szGatePassWord),szIniFile);
  229.           else
  230.             WritePrivateProfileString(szSessionName,"GATEPASSWORD",
  231.               NULL,szIniFile);
  232.           EndDialog(hWndDlg,TRUE);
  233.           break;
  234.         case IDCANCEL:
  235.           EndDialog(hWndDlg, FALSE);
  236.           break;
  237.       }
  238.       break;
  239.     default:
  240.       return FALSE;
  241.   }
  242.   return TRUE;
  243. }
  244.  
  245. /******************************************************************
  246.   Message processing for host dialog box
  247. */
  248. BOOL CALLBACK WS_HostMsgProc(HWND hWndDlg, UINT Message,
  249.                                WPARAM wParam, LPARAM lParam)
  250. {
  251.   int nIndex;
  252.  //char szRHost[80];
  253.   UINT nRC;
  254.  
  255.   switch(Message)
  256.   {
  257.     case WM_INITDIALOG:
  258.       LoadConfigNames(hWndDlg);
  259.       for(nIndex=0;nIndex<MAXTYPES;nIndex++)
  260.         SendDlgItemMessage(hWndDlg,DLG_HOST_TYPE,CB_ADDSTRING,
  261.           0,(LONG)(LPSTR)szHostTypes[nIndex]);
  262.       SetDlgItemText(hWndDlg,DLG_HOST_NAME,szSessionName);
  263.       SetDlgItemText(hWndDlg,DLG_HOST_ADDRESS,szRemoteHost);
  264.       SetDlgItemText(hWndDlg,DLG_HOST_USERID,szUserID);
  265.       SetDlgItemText(hWndDlg,DLG_HOST_PASSWORD,szPassWord);
  266.       SetDlgItemText(hWndDlg,DLG_HOST_DIR,szInitDir);
  267.       SetDlgItemInt(hWndDlg,DLG_HOST_TIMEOUT,uiTimeOut,FALSE);
  268.       SetDlgItemInt(hWndDlg,DLG_HOST_RETRIES,uiRetries,FALSE);
  269.       SetDlgItemInt(hWndDlg,DLG_HOST_FTP_PORT,uiFtpPort,FALSE);
  270.       CheckDlgButton(hWndDlg,DLG_HOST_PWD,bSavePWD);
  271.       SendDlgItemMessage(hWndDlg,DLG_HOST_TYPE,CB_SETCURSEL,nHostType-6000,0L);
  272.       if(szSessionName[0]==0)
  273.         strcpy(szSessionName,szRemoteHost);
  274.       SetDefaultHostStuff(hWndDlg,szSessionName);
  275.       cwCenter(hWndDlg, 0);
  276.       SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,WM_SETREDRAW,TRUE,0l);
  277.       break;
  278.     case WM_CLOSE:
  279.       PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L);
  280.       break;
  281.  
  282.  
  283.      case WM_CTLCOLORBTN:
  284.            if(LOWORD(lParam)<10) return((LRESULT)NULL);
  285.      case WM_CTLCOLORDLG:
  286.      case WM_CTLCOLORSTATIC:
  287.            SetBkColor((HDC) wParam, RGB(192,192,192));
  288.           return (LRESULT)hbrGray1;
  289.            break;
  290.  
  291.        case WM_CTLCOLORLISTBOX:
  292.          return(LRESULT)hbrGray1;
  293.          break;
  294.  
  295. /*    case WM_CTLCOLOR:
  296.       switch(HIWORD(lParam)) {
  297.         case CTLCOLOR_BTN:
  298.           if(LOWORD(lParam)<10) return((LRESULT)NULL);
  299.         case CTLCOLOR_DLG:
  300.         case CTLCOLOR_STATIC:
  301.           SetBkColor((HDC) wParam, RGB(192,192,192));
  302.         case CTLCOLOR_LISTBOX:
  303.           return(LRESULT)hbrGray1;
  304.         } 
  305.  
  306.         return(LRESULT)NULL;
  307.         break; */
  308.  
  309.             // lgk change hiword lparam to loword wparam
  310.     case WM_COMMAND:
  311.       switch(LOWORD(wParam))
  312.       {
  313.         case DLG_HOST_NAME:
  314.           if(HIWORD(wParam)==CBN_KILLFOCUS ||
  315.              HIWORD(wParam)==CBN_EDITCHANGE) 
  316.              {
  317.               GetDlgItemText(hWndDlg,DLG_HOST_NAME,szSessionName,79);
  318.              } 
  319.            else if(HIWORD(wParam)==CBN_SELCHANGE) 
  320.               {
  321.                 if((nIndex=SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,
  322.                           CB_GETCURSEL,0,0L))!=LB_ERR)
  323.                    SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_GETLBTEXT,
  324.                                     nIndex,(LONG)szSessionName);
  325.                 else break;
  326.  
  327.               } 
  328.            else break;
  329.           SetDefaultHostStuff(hWndDlg,szSessionName);
  330.  
  331. /*                   SetDefaultHostStuff(hWndDlg,szSessionName);
  332.  
  333.           if(HIWORD(lParam)==CBN_KILLFOCUS)
  334.             SendDlgItemMessage(hWndDlg,DLG_HOST_ADDRESS,WM_SETREDRAW,TRUE,0l);
  335. */
  336.           break;
  337.  
  338.         case DLG_HOST_ANONY:
  339.           if(IsDlgButtonChecked(hWndDlg,DLG_HOST_ANONY)) {
  340.             SetDlgItemText(hWndDlg,DLG_HOST_USERID,szAnony);
  341.             if(*szMailAddress==0)
  342.               StdInput(szMailAddress,"Enter your e-mail address:");
  343.             SetDlgItemText(hWndDlg,DLG_HOST_PASSWORD,szMailAddress);
  344.             SetFocus(GetDlgItem(hWndDlg,DLG_HOST_ANONY));
  345.           }
  346.           return(FALSE);
  347.  
  348.         case DLG_BTN_DEL:
  349.           if(GetDlgItemText(hWndDlg,DLG_HOST_NAME,szSessionName,79)>0) {
  350.             WritePrivateProfileString(szSessionName,NULL,NULL,szIniFile);
  351.             if((nIndex=SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,
  352.                CB_FINDSTRINGEXACT,0,(LONG)(LPSTR)szSessionName))!=CB_ERR) {
  353.               SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_DELETESTRING,
  354.                  nIndex,0l);
  355.             } else nIndex=0;
  356.             if(SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_SETCURSEL,nIndex,0l)
  357.               ==CB_ERR)
  358.               SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_SETCURSEL,0,0l);
  359.           }
  360.           GetDlgItemText(hWndDlg,DLG_HOST_NAME,szSessionName,79);
  361.           SetDefaultHostStuff(hWndDlg,szSessionName);
  362.           SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,WM_SETREDRAW,TRUE,0l);
  363.           SetFocus(GetDlgItem(hWndDlg,DLG_HOST_NAME));
  364.           break;
  365.  
  366.         case DLG_BTN_SAVE:
  367.         case IDOK:
  368.           GetDlgItemText(hWndDlg,DLG_HOST_ADDRESS,szRemoteHost,79);
  369.           if(GetDlgItemText(hWndDlg,DLG_HOST_NAME,szSessionName,79)==0)
  370.             lstrcpy(szSessionName,szRemoteHost);
  371.           GetDlgItemText(hWndDlg,DLG_HOST_USERID,szUserID,79);
  372.           GetDlgItemText(hWndDlg,DLG_HOST_PASSWORD,szPassWord,79);
  373.           GetDlgItemText(hWndDlg,DLG_HOST_DIR,szInitDir,79);
  374.           uiRetries=GetDlgItemInt(hWndDlg,DLG_HOST_RETRIES,NULL,FALSE);
  375.           uiFtpPort=GetDlgItemInt(hWndDlg,DLG_HOST_FTP_PORT,NULL,FALSE);
  376.           nRC=GetDlgItemInt(hWndDlg,DLG_HOST_TIMEOUT,NULL,FALSE);
  377.           if(nRC==0) uiTimeOut=65; else uiTimeOut=nRC;
  378.           if(uiTimeOut > (65536/1000)) uiTimeOut=65530/1000;
  379.           if(IsDlgButtonChecked(hWndDlg,DLG_HOST_PWD))
  380.             bSavePWD=TRUE;
  381.           else
  382.             bSavePWD=FALSE;
  383.           nIndex=SendDlgItemMessage(hWndDlg,DLG_HOST_TYPE,CB_GETCURSEL,0,0l);
  384.           if(nIndex==CB_ERR)
  385.             nHostType=HOST_TYPE_AUTO;
  386.           else
  387.             nHostType=nIndex+HOST_TYPE_AUTO;
  388.           SaveHostName(szSessionName);
  389.           if (IsDlgButtonChecked(hWndDlg, DLG_HOST_GATEWAY))
  390.             { FARPROC lpfnMsgProc;
  391.               use_gateway=1;
  392.               lpfnMsgProc=MakeProcInstance((FARPROC)WS_GateMsgProc,hInst);
  393.               nRC=DialogBox(hInst,(LPSTR)"DLG_GATEWAY",hWndDlg,lpfnMsgProc);
  394.               FreeProcInstance(lpfnMsgProc);
  395.               SetFocus(hWndDlg);
  396.             } else use_gateway=0;
  397.           if(LOWORD(wParam)==IDOK)
  398.             EndDialog(hWndDlg, TRUE);
  399.           else
  400.             if(SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,
  401.                CB_FINDSTRINGEXACT,0,(LONG)(LPSTR)szSessionName)==CB_ERR) {
  402.               SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_ADDSTRING,
  403.                  0,(LONG)(LPSTR)szSessionName);
  404.               SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,WM_SETREDRAW,TRUE,0l);
  405.               SetFocus(GetDlgItem(hWndDlg,DLG_HOST_NAME));
  406.             }
  407.           break;
  408.  
  409.         case IDCANCEL:
  410.           EndDialog(hWndDlg, FALSE);
  411.  
  412.          if(!bConnected)
  413.            {
  414.            EnableWindow(hBtnConnect,TRUE);
  415.            EnableWindow(hBtnClose,FALSE);
  416.            }
  417.           break;
  418.       }
  419.       break;
  420.     default:
  421.       return FALSE;
  422.   }
  423.   return TRUE;
  424. }
  425.  
  426. /***************************************************************
  427.   save the information about the current host in the ini file
  428. */
  429. void SaveHostName(LPSTR lpszCName)
  430. {
  431.   char buf[30];
  432.   WritePrivateProfileString(lpszCName,"HOST",szRemoteHost,szIniFile);
  433.   WritePrivateProfileString(lpszCName,"UID",szUserID,szIniFile);
  434.   if(bSavePWD)
  435.     WritePrivateProfileString(lpszCName,"PWD",
  436.         EnCrypt(szUserID,szPassWord),szIniFile);
  437.   else
  438.     WritePrivateProfileString(lpszCName,"PWD",NULL,szIniFile);
  439.   if(szInitDir[0]!=0)
  440.     WritePrivateProfileString(lpszCName,"DIR",szInitDir,szIniFile);
  441.   else
  442.     WritePrivateProfileString(lpszCName,"DIR",NULL,szIniFile);
  443.  
  444.   wsprintf(buf,"%u",nHostType);
  445.   WritePrivateProfileString(lpszCName,"TYPE",buf,szIniFile);
  446.   wsprintf(buf,"%u",uiTimeOut);
  447.   WritePrivateProfileString(lpszCName,"TIMEOUT",buf,szIniFile);
  448.   wsprintf(buf,"%u",uiRetries);
  449.   WritePrivateProfileString(lpszCName,"RETRIES",buf,szIniFile);
  450.   wsprintf(buf,"%u",uiFtpPort);
  451.   WritePrivateProfileString(lpszCName,"FTPPORT",buf,szIniFile);
  452. }
  453.  
  454. /*****************************************************
  455.   convert remotename into something DOS can deal with here nt can deal with longer names
  456. */
  457. // lgk add fix for vax which makes names with ;version numbe now
  458.  
  459. MakeLocalName(LPSTR localname,LPSTR shortname, LPSTR remotename)
  460. {
  461.   int nIndex;
  462.   char Name[10],Ext[4],*s;
  463.   char Name2[140], Ext2[80];
  464.   char savedname[256];
  465.  
  466.   lstrcpy(savedname,remotename);
  467.  
  468.   // lgk on nt try the entire name first for localname
  469.  
  470.   while(*remotename!=0 && *remotename=='.')
  471.     remotename++;
  472.   for(nIndex=0;nIndex<140;nIndex++)
  473.     if(*remotename!=0 && *remotename!='.' && *remotename!=' ')
  474.       { 
  475.         if (nIndex < 8)
  476.          Name[nIndex] = *remotename;
  477.         Name2[nIndex] = *remotename++;
  478.       }
  479.     else break;
  480.  
  481.  if (nIndex <= 8)
  482.    Name[nIndex]=0; 
  483.  else Name[8]=0; 
  484.   
  485.   Name2[nIndex]=0; 
  486.   Ext2[0]=0;
  487.   Ext[0] = 0;
  488.  
  489.   if((s=strchr(remotename,'.'))!=NULL)
  490.     remotename=s;
  491.   while(*remotename!=0 && (*remotename=='.' || *remotename==' '))
  492.     remotename++;
  493.   if(*remotename!=0) {
  494.     for(nIndex=0;nIndex<80;nIndex++)
  495.       if(*remotename!=0 && *remotename!='.' && *remotename!=' ')
  496.         { if (nIndex < 3) 
  497.             Ext[nIndex] = *remotename;
  498.           Ext2[nIndex] = *remotename++;
  499.         }
  500.       else break;
  501.  
  502.   if (nIndex <=3)
  503.    Ext[nIndex]=0;
  504.   else Ext[3] = 0;
  505.  
  506.     Ext2[nIndex] = 0;
  507.   }
  508.   
  509.   if(Ext[0]==0) {
  510.     lstrcpy(shortname,Name);
  511.   } else {
  512.     wsprintf(shortname,"%s.%s",Name,Ext);
  513.   }
  514.  if(Ext2[0]==0) {
  515.     lstrcpy(localname,Name2);
  516.   } else {
  517.     wsprintf(localname,"%s.%s",Name2,Ext);
  518.   }
  519.  
  520.   if(lstrlen(shortname)==0) {
  521.     lstrcpy(Name,"aaremote");
  522.     lstrcpy(shortname,Name);
  523.   }
  524.   if(lstrlen(localname)==0) {
  525.     lstrcpy(Name,"aaremote");
  526.     lstrcpy(localname,Name2);
  527.   }
  528.  
  529.   if(bRecvUniq) {
  530.     nIndex=0;
  531.     while((int)access(shortname,0)==0 && nIndex<99) {
  532.       DoPrintf("[recvuniq] %s - %s - %s",Name,Ext,shortname);
  533.       if(Ext[0]==0)
  534.         wsprintf(shortname,"%s.%03u",Name,nIndex);
  535.       else if(lstrlen(Name)>5)
  536.         wsprintf(shortname,"%-5.5s%03u.%s",Name,nIndex,Ext);
  537.       else wsprintf(shortname,"%s%03u.%s",Name,nIndex,Ext);
  538.       nIndex++;
  539.     }
  540.   }
  541.   
  542.  if(bRecvUniq) {
  543.     nIndex=0;
  544.     while((int)access(localname,0)==0 && nIndex<99) {
  545.       DoPrintf("[recvuniq] %s - %s - %s",Name2,Ext2,localname);
  546.       if(Ext[0]==0)
  547.         wsprintf(localname,"%s.%03u",Name2,nIndex);
  548.       else if(lstrlen(Name)>5)
  549.         wsprintf(localname,"%-5.5s%03u.%s",Name2,nIndex,Ext2);
  550.       else wsprintf(localname,"%s%03u.%s",Name2,nIndex,Ext2);
  551.       nIndex++;
  552.     }
  553.   }
  554.    
  555.   // on nt try whole name for local name
  556.   lstrcpy(localname,savedname);
  557.   // fix vax however
  558.   {
  559.     char  *colonloc = strchr(savedname,';');
  560.     
  561.   if (colonloc != 0)
  562.     {
  563.       int i = 0;
  564.       while (savedname[i] != ';')
  565.         {
  566.          Name2[i] = savedname[i];
  567.          ++i;
  568.         }
  569.      Name2[i] = '\0';
  570.      lstrcpy(localname,Name2);
  571.     }
  572.   }  
  573.   return(TRUE);
  574. }
  575.  
  576. /*************************************************
  577.   find filename in a UNIX directory listing
  578. */
  579. LPSTR FindName(LPSTR szLine)
  580. {
  581.   int nIndex;
  582.   char *pStr;
  583.  
  584.   // strip trailing garbage from the line if there is any.
  585.   while((nIndex=strlen(szLine))>2 &&
  586.     (szLine[nIndex-1]==0x0a || szLine[nIndex-1]==0x0d || 
  587.      szLine[nIndex-1]==' ' || szLine[nIndex-1]==0x09))
  588.     szLine[nIndex]=0;
  589.  
  590.   // now the name SHOULD be the last thing on the line
  591.   if((pStr=strrchr(szLine,' '))!=NULL ||
  592.      (pStr=strrchr(szLine,0x09))!=NULL) {
  593.     while(*pStr && (*pStr==' ' || *pStr==0x09)) pStr++;
  594.     return(pStr);
  595.   }
  596.   return(szLine);
  597. }
  598.  
  599. /*****************************************************************
  600.   This is the routine that take the output from LIST and breaks
  601.   it down into files and directories.  The format for the output
  602.   from most of the machine types was provided by Chris Sacksteder.
  603. */
  604. int GetRemoteDirForWnd(HWND hWnd)
  605. {
  606.   char *pStr,*s,*t;
  607.   FILE *fd;
  608.   int result = 0;
  609.   int nRC;
  610.   char *searchstring = remotesearchstring();
  611.   int maxhfextent = 0;
  612.   int maxhdextent = 0;
  613.   
  614.   char temp[120];
  615.  
  616.   strcpy(temp,searchstring);
  617.  
  618.   // clean out the old contents of the list boxes
  619.   SendMessage(hLbxRDir,LB_RESETCONTENT,0,0);
  620.   SendMessage(hLbxRFiles,LB_RESETCONTENT,0,0);
  621.   // lgk 7/94 new code for horiz scroll bars
  622.   maxhfextent=0;
  623.   maxhdextent=0;
  624.   SendMessage(hLbxRFiles,LB_SETHORIZONTALEXTENT,0,0l);
  625.   SendMessage(hLbxRDir,LB_SETHORIZONTALEXTENT,0,0l);
  626.  
  627.   // can't do much if we aren't connected
  628.   if(!bConnected) {
  629.     SendMessage(hTxtRDir,WM_SETTEXT,0,(LPARAM)"");
  630.   }
  631.   else {
  632.     // get the remote directory name
  633.     strcpy(szString,"undecipherable");
  634.     nRC=DoPWD(ctrl_socket);
  635.     if(nRC==FTP_COMPLETE) {
  636.       if((pStr=strchr(szMsgBuf,'"'))!=NULL)
  637.         strncpy(szString,++pStr,180);
  638.       if((pStr=strchr(szString,'"'))!=NULL)
  639.         *pStr=0;
  640.       else szString[180]=0;
  641.     }
  642.     SendMessage(hTxtRDir,WM_SETTEXT,0,(LPARAM)szString);
  643.  
  644.     if(!bHELP) ReadProcessHelp(ctrl_socket);
  645.     // go get the current remote directory listing in tmpfile.tmp
  646.    
  647.    // lgk new code here to use search string if filled in
  648.     if (strlen(temp) != 0)
  649.       {
  650.        char temp2[200];
  651.        strcpy(temp2,"LIST ");
  652.        strcat(temp2,temp);
  653.        nRC=DoDirList(ctrl_socket,temp2);
  654.       }
  655.     else nRC=DoDirList(ctrl_socket,"LIST");
  656.  
  657.     SendMessage(hLbxRDir,LB_ADDSTRING,0,(LPARAM)"..");
  658.     if(nRC==FTP_COMPLETE) {
  659.       if((fd=fopen(szTmpFile,"r"))!=NULL) {
  660.         while(fgets(szString,180,fd)!=NULL) {
  661.           if((pStr=strchr(szString,'\n'))!=NULL) *pStr=0;
  662.           switch(nHostType) {
  663.             case HOST_TYPE_SUPER:
  664.             case HOST_TYPE_CHAMELEON:
  665.             case HOST_TYPE_NCSA:
  666.             // looks like a standard DOS directory
  667.                 //  filename.ext       <DIR>(or size)  date,etc...
  668.                 if(strstr(szString,"<DIR>")!=NULL || 
  669.                    strstr(szString,"<dir>")!=NULL) {
  670.                   if((pStr=strchr(szString,' '))!=NULL) *pStr=0;
  671.                   if(strcmp(szString,".")!=0 && strcmp(szString,"..")!=0)
  672.                    {
  673.                      SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString);
  674.                      // lgk 7/94 new code for horiz scroll bars
  675.                      check_scroll(hLbxRDir,(LONG)szString,&maxhdextent);
  676.            }
  677.            
  678.                  } else {
  679.                   if((pStr=strchr(szString,' '))!=NULL) *pStr=0;
  680.                   if(szString[0]!=0)
  681.                     SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
  682.                    // lgk 7/94 new code for horiz scroll bars
  683.                    check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent);
  684.                 }
  685.                 break;
  686. // lgk new code for software innovations server
  687.  
  688.           case HOST_TYPE_INNOV_WINDOWS_NT:
  689.                   if(strncmp(szString,"d    ",5)== 0) 
  690.                    {
  691.                     pStr = strstr(szString,"d    ");
  692.                      // ok it is a dir now skip over to the name field always starting at column 51
  693.             pStr = pStr  + 51;
  694.                     SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr);
  695.                     check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent);
  696.  
  697.            }
  698.             
  699.                 else 
  700.                  {
  701.                    pStr = strstr(szString,"     ");
  702.                    /* get to the name     */
  703.                    pStr = pStr  + 51;
  704.            /* Now we have the name */
  705.                    SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr);
  706.                    check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent);
  707.                 }
  708.                 break;
  709.  
  710.           case HOST_TYPE_WINDOWS_NT:
  711.             // lgk extra code here to check if we have an nt server but in unix mode then reset type to unix
  712.             // we know this if the directory comes back with a - in col 9 as it will be a space in the dos format mode
  713.  
  714.                  if (szString[8] == '-') // we have a unix mode
  715.                    {
  716.                      DoPrintf("NOTE: NT Server is in Unix Mode ... Resetting host type.");
  717.                      nHostType = HOST_TYPE_UNIX;
  718.                      pStr=FindName(szString);
  719.                     // if line starts with 'd' its a directory
  720.                     if(strchr("dl",szString[0])!=NULL)
  721.                       {
  722.                       if(pStr[strlen(pStr)-1]=='/' || // 93.12.04 fix for some NT ftpd
  723.                          pStr[strlen(pStr)-1]=='\\')  // 93.12.04
  724.                          pStr[strlen(pStr)-1]=0;       // 93.12.04
  725.                          if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0)
  726.                          {
  727.                           SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr);
  728.                           check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent);
  729.                          }
  730.                     } else
  731.                         // if line starts with - or f its a file
  732.                         if(nHostType==HOST_TYPE_SINTFTPD ||
  733.                         strchr("-f",szString[0])!=NULL)
  734.                          {
  735.                             // lgk fix bug here that checked length with szstring when name is pstr at this point
  736.                             SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr);
  737.                             check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent);
  738.  
  739.                      }
  740.  
  741.                    }
  742.                   else // not unix format note: this code should only be hit once as the type changes to unix
  743.                   
  744.                    {   
  745.                   if (strstr(szString,"<DIR>")!=NULL) 
  746.                    {
  747.                        pStr = strstr(szString,"<DIR>");
  748.                if ((pStr = strrchr(pStr,' ')) != NULL)
  749.              {
  750.                    /* now we should be on name so get it */
  751.                ++pStr;
  752.                            if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0)
  753.                              {
  754.                               SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr);
  755.                               check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent);
  756.                  }
  757.              }
  758.            }
  759.                 
  760.                 else 
  761.                  {
  762.                    /* get to the name     */
  763.                   if ((pStr = strrchr(szString,' ')) != NULL)
  764.             {
  765.                       ++pStr;
  766.                       /* Now we have the name */
  767.                       SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr);
  768.                       check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent);
  769.             }
  770.                  }
  771.                    }
  772.                 break;
  773.                 
  774.                 case HOST_TYPE_QVT:
  775.             // if the name is the first thing on the line and ends with a slash
  776.             // to indicate a directory
  777.                 if((s=strchr(szString,' '))!=NULL) *s=0; // use for ftp.uwp.edu
  778.                 if(szString[strlen(szString)-1]=='/' || 
  779.                    szString[strlen(szString)-1]=='\\')
  780.                 {
  781.                   szString[strlen(szString)-1]=0;
  782.                   if(strcmp(szString,".")!=0 && strcmp(szString,"..")!=0)
  783.                    {
  784.                       SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString);
  785.                       check_scroll(hLbxRDir,(LONG)szString,&maxhdextent);
  786.                    }
  787.                 } else
  788.                   {
  789.                    SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
  790.                    check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent);
  791.           }
  792.                 break;
  793.  
  794.             case HOST_TYPE_IBM_VM:
  795.             // IBM VM/VMS listing
  796.                 // filename extent (what does a directory look like??)
  797.                 szString[18]=0;
  798.                 while(strlen(szString)>1 && szString[strlen(szString)-1]==' ')
  799.                   szString[strlen(szString)-1]=0;
  800.                 if((s=strchr(szString,' '))!=NULL) {
  801.                   *s++ = '.';
  802.                   t=s;
  803.                   while(*t && *t==' ') t++;
  804.                   if(*t && t!=s) strcpy(s,t);
  805.                 }
  806.                 if(*s && *s!=' ' && *s!='\t')  // 93.12.04 eliminate blank lines
  807.                   {
  808.                    SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
  809.                    check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent);
  810.           }
  811.           
  812.                 break;
  813.  
  814.             case HOST_TYPE_VMS_UCX:
  815.             case HOST_TYPE_VMS_MULTINET:
  816.             // DEC listing
  817.                 if(*szString!=' ') {
  818.                   if((s=strchr(szString,';'))!=NULL) {
  819.                     *s=0;
  820.                     if(strlen(szString)>4 &&
  821.                        strcmp(&szString[strlen(szString)-4],".DIR")==0) {
  822.                       szString[strlen(szString)-4]=0;
  823.                       SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString);
  824.                       check_scroll(hLbxRDir,(LONG)szString,&maxhdextent);
  825.  
  826.                     } else {
  827.                       *s=';';
  828.                       if((s=strchr(szString,' '))!=NULL) *s=0;
  829.                       if((s=strchr(szString,'\t'))!=NULL) *s=0;
  830.                       SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
  831.                       check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent);
  832.  
  833.                     }
  834.                   }
  835.                 }
  836.                 break;
  837.  
  838.             case HOST_TYPE_PCTCP:
  839.             // size..... filename.ext   .......
  840.             // <dir>     filename.ext   .......
  841.                 szString[30]=0;
  842.                 s=FindName(szString);
  843.                 if(strnicmp(szString,"<dir>",5)==0) {
  844.                   if(strcmp(s,".")!=0 && strcmp(s,"..")!=0)
  845.                     {
  846.                     SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)s);
  847.                     check_scroll(hLbxRDir,(LONG)s,&maxhdextent);
  848.             }
  849.             
  850.                 } else
  851.                    {
  852.                   SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)s);
  853.                   // lgk fix bug here that checked length with szstring when name is s at this point
  854.                   check_scroll(hLbxRFiles,(LONG)s,&maxhfextent);
  855.            }
  856.               break;
  857.  
  858.             case HOST_TYPE_IBM_TCP:
  859.             // ........   <dir>   filename.ext
  860.             // ........    DIR    filename.ext    - host ibm tcp
  861.             // ........   size    filename.ext
  862.                 s=FindName(szString);
  863.                 if(strstr(szString," DIR ")!=NULL || 
  864.                    strstr(szString,"<dir>")!=NULL) {
  865.                   if(strcmp(s,".")!=0 && strcmp(s,"..")!=0)
  866.                    {
  867.                     SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)s);
  868.                     check_scroll(hLbxRDir,(LONG)s,&maxhdextent);
  869.            }
  870.                 } else
  871.                  {
  872.                   SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)s);
  873.                   // lgk fix bug here that checked length with szstring when name is s at this point
  874.                   check_scroll(hLbxRFiles,(LONG)s,&maxhfextent);
  875.          }
  876.          
  877.                 break;            
  878.  
  879.             case HOST_TYPE_NOS:
  880.             // ka9q 
  881.               if(strstr(szString,"Disk size")==NULL) {
  882.                 szString[13]=0; nRC=13;
  883.                 while((nRC=strlen(szString))>0 && szString[nRC-1]==' ')
  884.                   szString[nRC-1]=0;
  885.                 if(*szString!=0) {
  886.                   if(szString[strlen(szString)-1]=='/' || 
  887.                      szString[strlen(szString)-1]=='\\')
  888.                   {
  889.                     szString[strlen(szString)-1]=0;
  890.                     if(strcmp(szString,".")!=0)
  891.                       {
  892.                        SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString);
  893.                        check_scroll(hLbxRDir,(LONG)szString,&maxhdextent);
  894.                       }
  895.  
  896.                   } else
  897.                     {
  898.                       SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString);
  899.                       check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent);
  900.                     }
  901.  
  902.                 }
  903.                 pStr=&szString[41]; nRC=13; pStr[nRC]=0;
  904.                 while((nRC=strlen(pStr))>0 && pStr[nRC-1]==' ')
  905.                   pStr[nRC-1]=0;
  906.                 if(*pStr!=0) {
  907.                   if(pStr[strlen(pStr)-1]=='/' ||
  908.                      pStr[strlen(pStr)-1]=='\\')
  909.                   {
  910.                     pStr[strlen(pStr)-1]=0;
  911.                     if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0)
  912.                       {
  913.                        SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr);
  914.                        check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent);
  915.               }
  916.                   } else
  917.                     {
  918.                     SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr);
  919.                     // lgk fix bug here that checked length with szstring when name is pstr at this point
  920.                     check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent);
  921.             }
  922.                 }
  923.               }
  924.               break;
  925.               
  926.             case HOST_TYPE_SINTFTPD:
  927.             case HOST_TYPE_U5000:
  928.             case HOST_TYPE_UNIX:
  929.             case HOST_TYPE_SOLARIS:
  930.             default:
  931.             // assume UNIX ls format
  932.               pStr=FindName(szString);
  933.               // if line starts with 'd' its a directory
  934.               if(strchr("dl",szString[0])!=NULL) {
  935.                 if(pStr[strlen(pStr)-1]=='/' || // 93.12.04 fix for some NT ftpd
  936.                    pStr[strlen(pStr)-1]=='\\')  // 93.12.04
  937.                   pStr[strlen(pStr)-1]=0;       // 93.12.04
  938.                 if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0)
  939.                   {
  940.                    SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr);
  941.                    check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent);
  942.                   }
  943.               } else
  944.               // if line starts with - or f its a file
  945.               if(nHostType==HOST_TYPE_SINTFTPD ||
  946.                  strchr("-f",szString[0])!=NULL)
  947.                 {
  948.                 // lgk fix bug here that checked length with szstring when name is pstr at this point
  949.                 SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr);
  950.                 check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent);
  951.  
  952.                 }
  953.               break;
  954.           }
  955.         }
  956.         fclose(fd);
  957.       } else
  958.         DoAddLine("couldn't open tmpfile for read.");
  959.     } else
  960.       DoPrintf("DoDirList returned %u",nRC);
  961.   } // if we were connected
  962.   SendMessage(hRdirBox,EM_SETMODIFY,0,0);
  963.   return 0;
  964. }
  965.  
  966. /*
  967.   Read the output from HELP and see if we can determine the hosttype
  968.   (if we don't already know it) and determine what functions are
  969.   valid (things like mkdir, etc)
  970. lgk bug fix for solaris where remotehelp hangs the system.
  971. */
  972. int ReadProcessHelp(SOCKET ctrl_socket)
  973. {
  974.   int iRetCode;
  975.  
  976.   // lgk add support for getting the other types by executing the syst command
  977.  
  978.   BOOL defaulttype = FALSE;
  979.  
  980.   bCanMKD=bCanRMD=bCanREN=bCanDELE=FALSE;
  981.  
  982.   // lgk don't send help for solaris
  983.   if (nHostType != HOST_TYPE_SOLARIS)
  984.    {
  985.     
  986.   if(SendPacket(ctrl_socket,"HELP")!=-1) 
  987.    {
  988.     iRetCode=ReadLine(ctrl_socket);
  989.     if((iRetCode/100)==5 && nHostType==HOST_TYPE_AUTO) nHostType=HOST_TYPE_NOS;
  990.     else {
  991.       if(nHostType==HOST_TYPE_AUTO) 
  992.        {
  993.         if(strstr(szMsgBuf,"NCSA")!=NULL ||
  994.            strstr(szMsgBuf,"CUTCP")!=NULL)
  995.           nHostType=HOST_TYPE_NCSA;
  996.         else if(strncmp(szMsgBuf,"214-PC FTP server",17)==0 ||
  997.               strstr(szMsgBuf,"QVT")!=NULL)
  998.           nHostType=HOST_TYPE_QVT;
  999.         else
  1000.           {
  1001.            defaulttype = TRUE;
  1002.            nHostType=HOST_TYPE_UNIX;
  1003.           }
  1004.       }       
  1005.       while((iRetCode!=421) && ((iRetCode/100)!=2 || szMsgBuf[3]=='-'))
  1006.        {
  1007.         if(strstr(szMsgBuf,"MKD")!=NULL) bCanMKD=TRUE;
  1008.         if(strstr(szMsgBuf,"RMD")!=NULL) bCanRMD=TRUE;
  1009.         if(strstr(szMsgBuf,"RNFR")!=NULL) bCanREN=TRUE;
  1010.         if(strstr(szMsgBuf,"DELE")!=NULL) bCanDELE=TRUE;
  1011.         iRetCode=ReadLine(ctrl_socket);
  1012.       }
  1013.     }
  1014.   // if the host type defaulted to unix then try syst instead
  1015.   if (defaulttype)
  1016.     {
  1017.                          
  1018.       if(SendPacket(ctrl_socket,"SYST")!=-1) 
  1019.         {
  1020.           DoPrintf("%s","SYST");
  1021.           iRetCode=ReadLine(ctrl_socket);
  1022.       DoPrintf("%s",szMsgBuf);
  1023.  
  1024.           if(strstr(szMsgBuf,"Windows_NT")!=NULL)
  1025.             nHostType=HOST_TYPE_WINDOWS_NT;
  1026.           else if(strstr(szMsgBuf,"WINDOWS NT Type: L8")!=NULL)
  1027.                   nHostType=HOST_TYPE_INNOV_WINDOWS_NT;
  1028.           else if(strstr(szMsgBuf,"UNIX") !=NULL)
  1029.                  nHostType=HOST_TYPE_UNIX;
  1030.             else if(strstr(szMsgBuf,"MultiNet") !=NULL)
  1031.                  nHostType=HOST_TYPE_VMS_MULTINET;
  1032.           else if(strstr(szMsgBuf,"MultiNet") !=NULL)
  1033.                  nHostType=HOST_TYPE_VMS_MULTINET;
  1034.           else if(strstr(szMsgBuf,"VMS") !=NULL)
  1035.                  nHostType=HOST_TYPE_VMS_UCX;
  1036.        // add others later as we find out the type
  1037.       }
  1038.     }
  1039.   }
  1040.  
  1041.    }
  1042.  else // host type is  solaris so hardcode stuff
  1043.   {
  1044.      
  1045.         bCanMKD=TRUE;
  1046.         bCanRMD=TRUE;
  1047.         bCanREN=TRUE;
  1048.         bCanDELE=TRUE;
  1049.         iRetCode=214;
  1050.    }
  1051.     
  1052.   EnableWindow(hBtnRMKD,bCanMKD);
  1053.   EnableWindow(hBtnRRMD,bCanRMD);
  1054.   EnableWindow(hBtnRREN,bCanREN);
  1055.   EnableWindow(hBtnRDEL,bCanDELE);
  1056.   bHELP=TRUE;
  1057.   DoPrintf("Host type (%u): %s",nHostType-6000,szHostTypes[nHostType-6000]);
  1058.   
  1059.  
  1060.   return iRetCode;
  1061. }
  1062.  
  1063. //*************************************************//
  1064. // routines to load and save our list of hostnames //
  1065. //*************************************************//
  1066. LPSTR cfgname ="_config_";
  1067.  
  1068. int GPPS(LPSTR fldname,LPSTR deflt,LPSTR destination,int len) {
  1069.   return(GetPrivateProfileString(cfgname,fldname,
  1070.               deflt,destination,len,szIniFile));
  1071. }
  1072.  
  1073. int WPPS(LPSTR fldname,LPSTR value) {
  1074.   return (WritePrivateProfileString(cfgname,fldname,value,szIniFile));
  1075. }
  1076.  
  1077. void LoadConfigNames(HWND hWndDlg) {
  1078.   FILE *fp;
  1079.   char szPathName[156];
  1080.   char *s;
  1081.  
  1082.   szPathName[0]=0;
  1083.   if(GetWindowsDirectory(szPathName,144)!=0)
  1084.     lstrcat(szPathName,"\\");
  1085.   lstrcat(szPathName,szIniFile);
  1086.   if((fp=fopen(szPathName,"r"))!=NULL) {
  1087.     while(fgets(szPathName,150,fp)!=NULL)
  1088.       if(szPathName[0]=='[') {
  1089.         if((s=strchr(szPathName,']'))!=NULL) *s=0;
  1090.         if(stricmp(&szPathName[1],cfgname)!=0)
  1091.           SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_ADDSTRING,0,
  1092.             (LONG)(LPSTR)&szPathName[1]);
  1093.       }
  1094.     fclose(fp);
  1095.   }
  1096. }
  1097.             
  1098. void LoadUserInfo()
  1099. {
  1100.   UINT flags;
  1101. //  int nIndex;
  1102.  // LPSTR s;
  1103.  
  1104.   szSessionName[0]=0;
  1105.   szMailAddress[0]=0;
  1106.   szViewer[0]=0;
  1107.   szUserID[0]=0;
  1108.   szPassWord[0]=0;
  1109.   szInitDir[0]=0;
  1110.   nHostType=HOST_TYPE_AUTO;
  1111.   uiTimeOut=65;
  1112.   uiRetries=0;
  1113.   uiFtpPort=21;
  1114.   
  1115.   GPPS("SESSION", NULL,      szSessionName, 79);
  1116.   GPPS("MAILADDR",NULL,      szMailAddress,127);
  1117.   GPPS("VIEWER",  "notepad", szViewer,     120);
  1118.   bAutoStart=GetPrivateProfileInt(cfgname, "AUTOSTART",
  1119.            bAutoStart,szIniFile);
  1120.   flags=GetPrivateProfileInt(cfgname,"FLAGS",64+4+1,szIniFile);
  1121.   if(flags & 1) bRecvUniq=1; else bRecvUniq=0;
  1122.   if(flags & 2) bStorUniq=1; else bStorUniq=2;
  1123.   if(flags & 4) bBell=1; else bBell=0;
  1124.   if(flags & 8) bInteractive=1; else bInteractive=0;
  1125.   if(flags & 16) bVerbose=1; else bVerbose=0;
  1126.   if(flags & 32) bHash=1; else bHash=2;
  1127. //if(flags & 64) bSendPort=1; else bSendPort=0;
  1128.   if(flags & 128) bDoGlob=1; else bDoGlob=2;
  1129. }
  1130.  
  1131. void SaveUserInfo()
  1132. {
  1133.   UINT flags;
  1134.  // int nIndex;
  1135.  
  1136.   WPPS(NULL, NULL);
  1137.   WPPS("SESSION",  szSessionName);
  1138.   WPPS("MAILADDR", szMailAddress);
  1139.   WPPS("VIEWER",   szViewer);
  1140.   wsprintf(szString,"%u",bAutoStart);
  1141.   WPPS("AUTOSTART",szString);
  1142.   flags=((bRecvUniq==1)?1:0) +
  1143. //  ((bStorUniq==1)?2:0) +
  1144.     ((bBell==1)?4:0) +
  1145.     ((bInteractive==1)?8:0)+
  1146. //  ((bHash==1)?32:0) +
  1147. //  ((bSendPort==1)?64:0) +
  1148. //  ((bDoGlob==1)?128:0) +
  1149.     ((bVerbose==1)?16:0);
  1150.   wsprintf(szString,"%u",flags);
  1151.   WPPS("FLAGS",szString);
  1152. }
  1153.  
  1154.