home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / winsock / finger10 / finger.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  7.7 KB  |  299 lines

  1. //
  2. // Finger Version 1.0, a Windows Sockets Finger Client
  3. //
  4. // Copyright (C) 1994 by Zoran Dukic.
  5. //
  6. // Permission to use, modify, and distribute this software and its
  7. // documentation for any purpose and without fee is hereby granted, provided
  8. // that the above copyright notice appears in all copies and that both
  9. // that copyright notice and this permission notice appear in supporting
  10. // documentation.  Zoran Dukic makes no claims as to the suitability of this 
  11. // software for any purpose.
  12. //
  13.  
  14. #include <windows.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <winsock.h>
  18. #include <memory.h>
  19. #include <owl.h>
  20. #include <object.h>
  21. #include <combobox.h>
  22. #include <edit.h>
  23. #include <scrollba.h>
  24.  
  25. #include "fingerrc.h"
  26.  
  27. //
  28. // Finger include holds all shared data, function & class definitions.
  29. //
  30.  
  31. //
  32. // Windows Sockets 1.0 versions define inet_addr as returning a struct,
  33. // whereas later version use an unsigned long.  We use the latter
  34. // definition and provide a #define for backwards compatability.
  35. //
  36.  
  37.  
  38. #define WSVERSION 0x101                   // Windows Sockets version
  39.  
  40. #if (WSVERSION == 0x100)
  41.    #define INET_ADDR ul_inet_addr
  42.    u_long ul_inet_addr(char *szIP);
  43.  
  44.    u_long ul_inet_addr(char *szIP)        // make our own inet_addr
  45.    {
  46.       IN_ADDR in;
  47.  
  48.       in = inet_addr(szIP);
  49.       return in.s_addr;
  50.    }
  51. #else                               
  52.    #define INET_ADDR inet_addr            // WS DLL has the right inet_addr
  53. #endif
  54.  
  55.  
  56. #define dim(x) (sizeof(x) / sizeof(x[0]))
  57.  
  58.  
  59. #define MAXTEXT   132
  60.  
  61. #define FE_ERROR     1  // finger operation was not successful
  62. #define FE_NOPORT    2  // failure to resolve finger service to a port 
  63. #define FE_NOHOST    3  // failure to resolve host specifier
  64. #define FE_NOSOCK    4  // failure to obtain socket for connection
  65. #define FE_NOCONN    5  // failure to connect to remote finger server
  66. #define FE_NOSEND    6  // failure to send finger query
  67. #define FE_NORECV    7  // failure to receive finger data
  68.  
  69. // messages for windows sockets returns
  70. #define WM_SERVICE            (WM_USER + 1)
  71. #define WM_HOSTRESOLVED       (WM_USER + 2)
  72. #define WM_CONNECTED          (WM_USER + 3)
  73. #define WM_OKTORECV           (WM_USER + 4)
  74. #define NETWINDOW "NetWindow"
  75.  
  76. #define MAXHOST   40
  77. #define MAXUSER   40
  78.  
  79. #define  LF 10                         // linefeed
  80. #define  CR 13                         // carriage return
  81. #define  TABSTRING "        "          // 8 character tab
  82.  
  83.  
  84. /***********************************
  85.  * Class and structure declaration *
  86.  ***********************************/
  87.  
  88. _CLASSDEF(TFingerApp)
  89. _CLASSDEF(THostDlg)
  90. _CLASSDEF(TFingerWnd)
  91. _CLASSDEF(TNetWnd)
  92. _CLASSDEF(THostTransfer)
  93. _CLASSDEF(TLine)
  94. _CLASSDEF(TOutputWnd)
  95.  
  96.  
  97. typedef unsigned long IPA;
  98. typedef IPA FAR *LPIPA;
  99. typedef LPIPA FAR *LPPIPA;
  100.  
  101.  
  102. typedef struct                      // associates an error code with text
  103. {
  104.    UINT err;
  105.    char *sztext;
  106. } ERRENTRY;
  107.  
  108.  
  109. // transfer structure for host dialog
  110.  
  111. struct THostTransfer
  112. {
  113.      PTComboBoxData pHost;
  114.      char pUser[41];
  115. };
  116.  
  117.  
  118. // application class
  119.  
  120. class TFingerApp : public TApplication
  121. {
  122. public:
  123.  
  124.      TFingerApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  125.              LPSTR lpCmdLine, int nCmdShow)
  126.        : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  127.      virtual void InitMainWindow();
  128. };
  129.  
  130.  
  131. // Host Dialog class
  132.  
  133. class THostDlg : public TDialog
  134. {
  135. public:
  136.  
  137.      PTComboBox pHostCombo;
  138.  
  139.      THostDlg(PTWindowsObject AParent, LPSTR AName, PTModule AModule = NULL);
  140.  
  141.      virtual void WMControlColor(TMessage& Msg)
  142.            = [WM_FIRST + WM_CTLCOLOR];
  143.  
  144.      virtual void Cancel(RTMessage Msg)
  145.                 = [ID_FIRST + IDCANCEL];
  146.  
  147.      virtual void HandleFingerMsg(RTMessage Msg)
  148.            = [ID_FIRST + ID_FINGER];
  149.      virtual void HandleCloseMsg(RTMessage Msg)
  150.            = [ID_FIRST + ID_CLOSE];
  151.      virtual void HandleAboutMsg(RTMessage Msg)
  152.            = [ID_FIRST + ID_ABOUT];
  153.      virtual void HandleDeleteMsg(RTMessage Msg)
  154.            = [ID_FIRST + ID_DELETEHOST];
  155.      virtual void HandleSaveMsg(RTMessage Msg)
  156.            = [ID_FIRST + ID_SAVEHOST];
  157.      virtual void WMMouseMove(RTMessage Msg)
  158.           = [WM_FIRST + WM_MOUSEMOVE];
  159. };
  160.  
  161.  
  162.  
  163. class TOutputWnd : public TWindow
  164. {
  165. public:
  166.  
  167.      PArray pViewList;            // ptr to displayed text
  168.      int maxLen;
  169.      int nClientLen;
  170.  
  171.      int nLineItems;          // number of items in display list
  172.  
  173.      int nClientLines;             // # of text lines in view
  174.     
  175.      TOutputWnd(PTWindowsObject AParent);
  176.      
  177.      virtual void Paint(HDC PaintDC, PAINTSTRUCT& PS);
  178.  
  179.      void SetRange();
  180.  
  181.      virtual void WMSize(RTMessage Msg)
  182.       = [WM_FIRST + WM_SIZE];
  183.      virtual void WMMouseMove(RTMessage Msg)
  184.           = [WM_FIRST + WM_MOUSEMOVE];
  185. };
  186.  
  187.  
  188. // Main Window - Finger Window class
  189.  
  190. class TFingerWnd : public TWindow
  191. {
  192. public:
  193.  
  194.      THostTransfer HostTransfer;
  195.  
  196.      PTHostDlg pHostDlg;
  197.      PTOutputWnd pOutput;
  198.      PTNetWnd pNetWnd;
  199.  
  200.      HCURSOR  hCursor;             // current cursor (either wait or normal)
  201.           
  202.      int CharY;                    // pixel character height
  203.  
  204.      TFingerWnd(PTWindowsObject AParent);
  205.      ~TFingerWnd();
  206.  
  207.      void SetupWindow();
  208.      
  209.      LPSTR GetClassName();
  210.      void GetWindowClass(WNDCLASS& AWndClass);
  211.  
  212.      void ReadHosts();
  213.      void WriteHosts();
  214.      virtual BOOL CanClose();
  215.  
  216.      void Repaint();
  217.  
  218.      void SetWinCaption();
  219.  
  220.      void FingerStart();
  221.      void FingerFinish(UINT Err);
  222.      void ReportFingerErr(UINT Err);
  223.      void ReportWSError(UINT Err);
  224.  
  225.      void ActivationResponse(WORD Activated, BOOL IsIconified);
  226.  
  227.      virtual void WMMouseMove(RTMessage Msg)
  228.           = [WM_FIRST + WM_MOUSEMOVE];
  229. };
  230.  
  231.  
  232.  
  233. // Network window - receives WinSocket messages
  234.  
  235. class TNetWnd : public TWindow
  236. {
  237. public:
  238.  
  239.      PArray pReceiveList;              // ptr to received text
  240.  
  241.      char LineBuf[132];                // holds accumulating text line
  242.      int LineLen;                      // length of text line
  243.      int maxLineLen;
  244.  
  245.      WSADATA  WSAData;                // windows sockets info return
  246.  
  247.      char     szHostName[MAXHOST+1];    // name of host to finger
  248.      char     szUser[MAXUSER+1];        // query for this user id (can be null)
  249.  
  250.      SOCKET   Sock;                     // connects to remote server's socket
  251.      int      Port;                     // hold port for finger service
  252.      char     EntBuf[MAXGETHOSTSTRUCT]; // buf for service & resolve returns
  253.  
  254.      TNetWnd(PTWindowsObject AParent);
  255.      ~TNetWnd();
  256.  
  257.      LPSTR GetClassName();
  258.      void GetWindowClass(WNDCLASS& AWndClass);
  259.  
  260.      void FingerStart();
  261.      void FingerFinish(UINT Err);
  262.      void ReportFingerErr(UINT Err);
  263.      void LoadEntBuf(IPA ipa);
  264.  
  265.      void PushChar(char ch);
  266.      void PushChars(char *buf, int buflen);
  267.      void PushLine();
  268.  
  269.      virtual void DoResolveHost(RTMessage Msg)
  270.           = [WM_FIRST + WM_SERVICE];
  271.      virtual void DoConnect(RTMessage Msg)
  272.       = [WM_FIRST + WM_HOSTRESOLVED];
  273.      virtual void DoQuery(RTMessage Msg)
  274.           = [WM_FIRST + WM_CONNECTED];
  275.      virtual void DoRetrieval(RTMessage Msg)
  276.       = [WM_FIRST + WM_OKTORECV];
  277. };
  278.  
  279.  
  280.  
  281. class TLine: public Object
  282. {
  283. public:
  284.     char *sztext;
  285.     int LLen;
  286.  
  287.     TLine(char *srcbuf, int Len);
  288.  
  289.     virtual classType isA() const { return __firstUserClass; }
  290.     virtual Pchar nameOf() const { return "TLine"; }
  291.     virtual hashValueType hashValue() const { return 0; }
  292.     virtual int isEqual(RCObject ALine) const
  293.            { return LLen == ((RTLine)ALine).LLen; }
  294.     virtual void printOn(Rostream outputStream) const
  295.            { outputStream << LLen; }
  296. };
  297.  
  298. /**************************************************************************/
  299.