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

  1. // Contents ---------------------------------------------------------------
  2. //
  3. //   fingerd.h -- Include file for fingerd
  4. //
  5. //   Version 1.00, a Windows Socket Finger Daemon
  6. //
  7. //   Copyright (C) Frederick W. Bent 1994
  8. //   All rights reserved.
  9. //
  10. //
  11. // Description
  12. //
  13. //
  14. // Ends -------------------------------------------------------------------
  15.  
  16. // History ----------------------------------------------------------------
  17. //
  18. // 6/28/94  1.0  Fred Bent         Wrote this thing
  19. //
  20. // Ends -------------------------------------------------------------------
  21.  
  22. #if !defined(_FINGERD_H_)
  23.  
  24. #define _FINGERD_H_    1
  25.  
  26. #ifndef STRICT
  27. #define    STRICT    1
  28. #endif
  29.  
  30. #include <windows.h>
  31. #include <windowsx.h>
  32. #include <winsock.h>
  33. #include <stdarg.h>
  34. #include "dsplist.h"
  35.  
  36. #define USE_CTL3D    1        // Use the CTL3D.DLL
  37. #define WINSOCK_BUG    1        // We have a broken Winsock
  38. // #define ASYNC_WRITE    1        // Do not use blocking sockets
  39. #define STRING_UNKNOWN    "localhost"    // can't determine local host name
  40.  
  41. #define WSVERSION_REQ    0x0101           // windows sockets version 1.1
  42. #define WSVERSION_MAJOR    HIBYTE(WSVERSION_REQ)
  43. #define WSVERSION_MINOR LOBYTE(WSVERSION_REQ)
  44.  
  45. /* Application and class names */
  46. #define APP_NAME    "Finger Daemon"
  47. #define APP_CLASS    "Fingerd"
  48.  
  49. #define    CLASS_NETWORK    "Fingerd.Server"
  50. #define CLASS_SIZE    40
  51.  
  52. #define HELP_FILE    "fingerd.hlp"
  53.  
  54. /* Stuff for network setup */
  55. #define FINGER_NAME "finger"        // use database lookup first
  56. #define FINGER_PORT IPPORT_FINGER    // server listens on this port
  57. #define SENDBUFLEN  (1024)        // the size of the send buffer
  58. #define MAXCLIENTS  5            // max # of clients in listen queue
  59.  
  60. /* .INI file stuff **/
  61.  
  62. #define SECTION_MAIN    "FingerSrv"
  63. #define ENTRY_DIR    "Path"
  64. #define ENTRY_DEFAULTFILE      "DefaultFile"
  65. #define ENTRY_DEBUG    "Debug"
  66. #define ENTRY_ONLYSNARK    "OnlySnark"
  67. #define INI_FILE    "fingerd.ini"
  68. #define DEFAULTFILE    "default.txt"   // send this file for null queries
  69.  
  70.  
  71. #define MAX_DRIVE    (3)        // max drive
  72. #define MAX_DIR        (256)        // max directory
  73. #define MAX_FNAME    (256)        // max file name length
  74. #define MAX_EXT        (256)        // max extension
  75. #define MAX_PATH    (260)        // max full path name length
  76. #define MAXITEMS    (256)        // number strings in list box
  77. #define MAXLINE         (80)        // max length of a string
  78. #define MAX_DISP_LINES  (200)        // max lines in main window 132 * 200 = 28672 bytes
  79.  
  80. /* Debugging stuff */
  81. #define DEBUG_OFF    0
  82. #define DEBUG_ON    1
  83. #define DEBUG_HIGH    2
  84.  
  85. #define    LOG_TIME    8
  86.  
  87. /* Macros go here... */
  88.  
  89. #define dim(x) (sizeof(x) / sizeof(x[0]))
  90.  
  91. // Data strcutures --------------------------------------------------------
  92.  
  93. //typedef struct                      // associates an error code with text
  94. //{
  95. //   UINT err;
  96. //   char *sztext;
  97. //} ERRENTRY;
  98. //
  99. typedef struct                      // associates messages (or menu ids)
  100. {                                   // with a handler function
  101.    UINT Code;
  102.    LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);
  103. } DECODEWORD;
  104.  
  105. #ifdef STRICT
  106. DECLARE_HANDLE(HCLIENT);
  107. #else
  108. typedef HGLOBAL HCLIENT;
  109. #endif
  110.  
  111. enum tagClientState
  112. {
  113.     STATE_WAIT_FOR_USER
  114.       , STATE_SENDING
  115.       , STATE_SEND_TIME
  116.       , STATE_FINISHED
  117.       , STATE_CLOSING
  118.       , STATE_WSERROR
  119. };
  120.  
  121. typedef enum tagClientState ClientState;
  122.  
  123. typedef struct tagCLIENT
  124. {
  125.     SOCKET        sSocket;         // The clients socket
  126.     HCLIENT        hClient;         // The memory handle
  127.  
  128.     SOCKADDR_IN    saPeer;             // The Internet address of peer
  129.     char        szPeer[MAXLINE];
  130.  
  131.     ClientState    iState;
  132.  
  133.     int        iExtErr;
  134.  
  135.     HFILE        hfFile;             // The MS-DOS file handle
  136.  
  137.  
  138.     /* We need buffers to talk with - unique ones at that */
  139.  
  140.     HANDLE    hOutputBuffer;       // Handle to output FIFO buffer
  141.     LPSTR    lpOutputBuffer;      // FIFO buffer for output
  142.     int    iOutputSize;
  143.     HANDLE     hInputBuffer;        // Handle to input FIFO buffer
  144.     LPSTR     lpInputBuffer;       // FIFO buffer for input
  145.     int     iInputSize;          // Size of FIFO buffer for input
  146.  
  147.     /* Keep the buffer state information here... */
  148.  
  149.     int       fifoOutputStart;
  150.     int       fifoOutputStop;
  151.     BOOL    fifoOutputFull;
  152.     int    fifoInputStart;
  153.     int     fifoInputStop;
  154.     BOOL    fifoInputFull;
  155.  
  156.     struct tagCLIENT FAR *lpPrevClient; // Link to previous client struct
  157.     struct tagCLIENT FAR *lpNextClient; // Link to next client struct
  158.  
  159. } CLIENT;
  160.  
  161. typedef CLIENT FAR*    LPCLIENT;
  162.  
  163. // Ends -------------------------------------------------------------------
  164.  
  165. /* Function protptypes */
  166.  
  167. BOOL     InitApp(HINSTANCE hInstance);
  168. BOOL     InitInstance(HINSTANCE hInstance, int nCmdShow);
  169. BOOL    InitFinger(HINSTANCE hInstance, PSTR pFilename);
  170.  
  171. BOOL    netInit(void);
  172. int    netSendData(LPCLIENT lpClient);
  173. int    netReceiveData(LPCLIENT lpClient);
  174. BOOL    netBlocking(LPCLIENT lpClient);
  175. void    netClose(void);
  176. BOOL    netSelectEvents(LPCLIENT lpClient, long lEvent);
  177. BOOL    netGetTimeAndDate(LPSTR szLine, int iLine);
  178.  
  179. BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  180. BOOL CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  181. void DlgGetLogStrings(HWND hDlg, UINT nButton, int iMax);
  182.  
  183. BOOL CALLBACK FindDirDlgProc(HWND hDlg, UINT nMsg, WPARAM wParam, LPARAM lParam);
  184.  
  185. LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  186. LRESULT CALLBACK NetWndProc(HWND, UINT, WPARAM, LPARAM);
  187. LRESULT DoMenuAbout(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  188. LRESULT DoMenuOptions(HWND, UINT, WPARAM, LPARAM);
  189. LRESULT DoMenuHelp(HWND, UINT, WPARAM, LPARAM);
  190. LRESULT DoMenuExit(HWND, UINT, WPARAM, LPARAM);
  191. LRESULT DoEdit(HWND, UINT, WPARAM, LPARAM);
  192. LRESULT DoEditCopy(HWND, UINT, WPARAM, LPARAM);
  193. LRESULT DoEditClear(HWND, UINT, WPARAM, LPARAM);
  194. LRESULT DoEditSelall(HWND, UINT, WPARAM, LPARAM);
  195. LRESULT DoFindDirDlg(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
  196.  
  197. LRESULT DoSize(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  198. LRESULT DoInitMenuPopup(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  199. LRESULT DoPaint(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  200. LRESULT DoSetFocus(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  201. LRESULT DoActivate(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  202. LRESULT DoVScroll(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  203. LRESULT DoSetFocus(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  204. LRESULT DoCreate(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  205. LRESULT DoCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  206. LRESULT DoClose(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  207. LRESULT DoDestroy(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  208. LRESULT DoQueryEndSession(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  209.  
  210. BOOL    fingerSendFile(LPCLIENT lpClient);
  211. //int    clientReceiveLine(LPCLIENT lpClient, LPSTR lpLine, int iLine);
  212.  
  213. void     UpdateDisplay(LPSTR szString, int iLen);
  214. void     SizeWindow(HWND hWnd);
  215. void    FingerFinished(void);
  216.  
  217. void    FileOpen(HWND hWnd);
  218. BOOL    VerifyDir(PSTR szPath);
  219. void     Whine(HWND hWnd, PSTR szCaption);
  220. void     MakeHelpPathName(HINSTANCE hInst, LPSTR szHelpFileName);
  221.  
  222. void     SendError(LPCLIENT lpClient, PSTR errstr);
  223. void     DebugOut(LPSTR lps, ...);
  224. void    DisplayWSError(PSTR str, ...);
  225. PSTR    WSErrorString(UINT err);
  226. void    OkMsgBox(PSTR szCaption, PSTR szFormat, ...);
  227.  
  228. BOOL    fingerServer(LPCLIENT lpClient);
  229. LPCLIENT fingerSocketToClient(SOCKET sSocket);
  230. LPCLIENT fingerAddClient(SOCKET sSocket);
  231. BOOL     fingerDestroyClient(LPCLIENT lpClient);
  232. void    fingerLog(int iLevel, int ResourceID, ...);
  233.  
  234. // External definitions
  235.  
  236. extern LPCLIENT fingerClientsHead;
  237. extern char szLocalFile[MAX_PATH];
  238. extern char szFileDir[MAX_PATH];
  239. extern BOOL bOnlySnark;
  240.  
  241. /* Windows stuff.... */
  242.  
  243. #define IDS_BAD_VERSION            200
  244. #define IDS_INITIALIZE            201
  245. #define IDS_FILTER            202
  246. #define IDS_CONNECT_S            203
  247. #define IDS_RECV_S            204
  248. #define IDS_SENT_S            205
  249. #define IDS_DISCONNECT_S        206
  250. #define IDS_REQUEST_ERR            207
  251. #define IDS_EXIT_ACTIVE            208
  252. #define IDS_EXITING            209
  253. #define IDS_DAEMON_START        210
  254. #define IDS_FILE_ERR            211
  255.  
  256. #define IDL_LOG                     101
  257. #define IDE_PATH                    102
  258. #define IDE_DIR                111
  259. #define IDB_PATH                    103
  260. #define IDB_DIR                112
  261. #define IDI_ICON                    104
  262. #define IDI_ICONEMPTY               105
  263. #define IDI_ICONFULL                106
  264. #define IDE_HOSTNAME                107
  265. #define IDR_NORMAL                  108
  266. #define IDR_DEBUG                   109
  267. #define IDR_ONLYSNARK            110
  268. #define IDE_EDIT            113
  269.  
  270. #define IDM_ABOUT                   120
  271. #define IDM_OPTIONS            121
  272. #define IDM_HELP            122
  273. #define IDM_EXIT            123
  274. #define IDM_COPY            124
  275. #define IDM_CLEAR            125
  276. #define IDM_SELALL            126
  277.  
  278. #define    IDL_MAIN            130
  279.  
  280. #define IDD_FPATH            140
  281. #define IDD_FNAME            141
  282. #define IDD_FLIST            142
  283.  
  284. #define WM_LISTEN       (WM_USER + 1)  // listen for connections
  285. #define WM_CONNECTION   (WM_USER + 2)  // connection request awaits
  286. #define WM_GETREQUEST   (WM_USER + 3)  // request is waiting
  287. #define WM_REPLY        (WM_USER + 4)  // start reply
  288.  
  289. #define NET_BASE         (WM_USER + 5)  // network messages start here...
  290. #define SOCKET_MESSAGE   NET_BASE
  291. #define NET_NAME        (NET_BASE + 1)
  292.  
  293. #endif // _FINGERD_H_
  294.