Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
10 KiB

  1. /*--
  2. Copyright (c) 1995-1998 Microsoft Corporation
  3. Module Name: HTTPD.H
  4. Author: Arul Menezes
  5. Abstract: Global defns for the HTTP server
  6. --*/
  7. #ifndef _HTTPD_H_
  8. #define _HTTPD_H_
  9. #ifndef UNDER_CE
  10. #define SECURITY_WIN32
  11. #endif
  12. #if DBG
  13. #define DEBUG
  14. #endif
  15. #include <windows.h>
  16. #include <winsock2.h>
  17. // OLD_CE_BUILD is defined when using the Windows CE Toolkit in Visual
  18. // Studio (in proj servers\vc\httpexece). We build this way when we're building for
  19. // older Windows CE devices (version 2.x). The reason we do this in the first place is
  20. // for shipping a beta version of the web server.
  21. // We won't have functions like sprintf or sscanf, so we implement our own, scaled down versions.
  22. // Also, there is no ASP support in this case.
  23. #ifdef OLD_CE_BUILD
  24. #pragma message ("Using Visual Studio Windows CE Toolkit Settings")
  25. // Write our own strrchr if we're using version 2.0 of CE, it wouldn't exist otherwise
  26. inline char *strrchr( const char *string, int c )
  27. {
  28. PCSTR pszTrav = string;
  29. PSTR pszLast = NULL;
  30. while ( *pszTrav )
  31. {
  32. if (*pszTrav == (CHAR) c)
  33. pszLast = (PSTR) pszTrav;
  34. pszTrav++;
  35. }
  36. return pszLast;
  37. }
  38. inline int isspace(int c) {
  39. return ( c == ' ' || c == '\n' || c == '\t' || c == '\r' || c == '\f' || c == '\v');
  40. }
  41. #else
  42. #include <stdio.h>
  43. #endif
  44. #include <httpext.h>
  45. #include <httpfilt.h>
  46. #include <service.h>
  47. #include <uhres.h>
  48. #include <creg.hxx>
  49. #include <sspi.h>
  50. #include <issperr.h>
  51. #include <servutil.h>
  52. #include <httpcomn.h>
  53. #ifdef UNDER_CE
  54. #include <windbase.h>
  55. #include <extfile.h>
  56. #else
  57. #include <wininet.h>
  58. #endif
  59. //------------- Arbitrary constants -----------------------
  60. // the assumption is that this buffer size covers the vast majority of requests
  61. #define MINBUFSIZE 1024
  62. // this the the timeout we use when waiting for the next request on a keep-alive connection
  63. #define KEEPALIVETIMEOUT 60000
  64. // subsequent-input timeout value. shoudl only hit on malformed headers/garbled packets
  65. #define RECVTIMEOUT 30000
  66. // maximum size of output headers
  67. #define MAXHEADERS 512
  68. // maximum size of a mime-type
  69. #define MAXMIME 64
  70. // maximum size username+password
  71. #define MAXUSERPASS 256
  72. // the assumption is that this buffer size covers most dir listings
  73. #define DIRBUFSIZE 4096
  74. // Size of response headers ("normal" headers, cookies and other extra headers are dynamic)
  75. #define HEADERBUFSIZE 4096
  76. // Used for dynamically growing arrays
  77. #define VALUE_GROW_SIZE 5
  78. // Size of buffer to hold all the bodies on web server errors
  79. #define BODYSTRINGSIZE 2048
  80. #define HTTPD_DEV_PREFIX L"HTP"
  81. #define HTTPD_DEV_INDEX 0
  82. #define HTTPD_DEV_NAME L"HTP0:"
  83. //------------- not-so-arbitrary constants -----------------------
  84. #define IPPORT_HTTP 2869
  85. //-------------------- Debug defines ------------------------
  86. // Debug zones
  87. #ifdef DEBUG
  88. #define ZONE_ERROR DEBUGZONE(0)
  89. #define ZONE_INIT DEBUGZONE(1)
  90. #define ZONE_LISTEN DEBUGZONE(2)
  91. #define ZONE_SOCKET DEBUGZONE(3)
  92. #define ZONE_REQUEST DEBUGZONE(4)
  93. #define ZONE_RESPONSE DEBUGZONE(5)
  94. #define ZONE_ISAPI DEBUGZONE(6)
  95. #define ZONE_VROOTS DEBUGZONE(7)
  96. #define ZONE_ASP DEBUGZONE(8)
  97. #define ZONE_DEVICE DEBUGZONE(9)
  98. #define ZONE_MEM DEBUGZONE(13)
  99. #define ZONE_PARSER DEBUGZONE(14)
  100. #define ZONE_TOKEN DEBUGZONE(15)
  101. #endif
  102. #define NTLM_PACKAGE_NAME TEXT("NTLM")
  103. // We need CE_STRING because GetProcAddress takes a LPCSTR as arg on NT, but UNICODE is defined
  104. // so the TEXT macro would return a UNICODE string
  105. #ifdef UNDER_CE
  106. #define NTLM_DLL_NAME TEXT("secur32.dll")
  107. #define CE_STRING(x) TEXT(x)
  108. #define SECURITY_ENTRYPOINT_CE SECURITY_ENTRYPOINT
  109. #else
  110. #define NTLM_DLL_NAME TEXT("security.dll")
  111. #define CE_STRING(x) (LPCSTR) (x)
  112. #define SECURITY_ENTRYPOINT_CE SECURITY_ENTRYPOINT_ANSIA
  113. #endif
  114. #define ASP_DLL_NAME TEXT("asp.dll")
  115. /////////////////////////////////////////////////////////////////////////////
  116. // Misc string handling helpers
  117. /////////////////////////////////////////////////////////////////////////////
  118. PSTR MySzDupA(PCSTR pszIn, int iLen=0);
  119. PWSTR MySzDupW(PCWSTR wszIn, int iLen=0);
  120. PWSTR MySzDupAtoW(PCSTR pszIn, int iInLen=-1);
  121. PSTR MySzDupWtoA(PCWSTR wszIn, int iInLen=-1);
  122. BOOL MyStrCatA(PSTR *ppszDest, PSTR pszSource, PSTR pszDivider=NULL);
  123. // Misc HTTP helper macros
  124. #define CHECKHCONN(h) if(!h || ((CHttpRequest*)h)->m_dwSig != CHTTPREQUEST_SIG) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; }
  125. #define CHECKPFC(h) if (!h || ((CHttpRequest*)h->ServerContext)->m_dwSig != CHTTPREQUEST_SIG) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; }
  126. #define CHECKPTR(p) if (!p) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; }
  127. #define CHECKPTRS2(p1, p2) if(!p1 || !p2) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; }
  128. #define CHECKPTRS3(p1, p2, p3) if(!p1 || !p2 || !p3) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; }
  129. #define CHECKFILTER(pfc) { if (! ((CHttpRequest*)pfc->ServerContext)->m_pFInfo->m_fFAccept) \
  130. { SetLastError(ERROR_OPERATION_ABORTED); return FALSE; } }
  131. #define SkipWWhiteSpace(lpsz) while ( (lpsz)[0] != L'\0' && iswspace((lpsz)[0])) ++(lpsz)
  132. //------------- Scalar Data typedefs -----------------------
  133. // HTTP status codes
  134. typedef enum
  135. {
  136. STATUS_OK = 0,
  137. STATUS_MOVED,
  138. STATUS_NOTMODIFIED,
  139. STATUS_BADREQ,
  140. STATUS_UNAUTHORIZED,
  141. STATUS_FORBIDDEN,
  142. STATUS_NOTFOUND,
  143. STATUS_INTERNALERR,
  144. STATUS_NOTIMPLEM,
  145. STATUS_NOTSUPP,
  146. STATUS_MAX,
  147. }
  148. RESPONSESTATUS;
  149. // Data used for response static data
  150. typedef struct
  151. {
  152. DWORD dwStatusNumber;
  153. PCSTR pszStatusText;
  154. PCSTR pszStatusBody;
  155. }
  156. STATUSINFO;
  157. //------------- Const data prototypes -----------------------
  158. extern STATUSINFO rgStatus[STATUS_MAX];
  159. extern const char cszTextHtml[];
  160. extern const char cszEmpty[];
  161. extern const char cszServerID[];
  162. extern const char cszProductID[];
  163. extern const char* rgMonth[];
  164. extern const char cszKeepAlive[];
  165. extern const char cszHTTPVER[];
  166. extern const char cszDateParseFmt[];
  167. extern const char cszDateOutputFmt[];
  168. extern const char* rgWkday[];
  169. extern const char* rgMonth[];
  170. extern const char cszCRLF[];
  171. extern const char cszBasic[];
  172. extern BOOL g_fFromExe; // Did the executable start us?
  173. //----------------------- Class defns -----------------------
  174. #include <asp.h>
  175. #include <buffio.h>
  176. #include <extns.h>
  177. #include <vroots.hpp>
  178. #include <auth.h>
  179. #include <request.h>
  180. #include <log.h>
  181. #include <filters.h>
  182. #include <authhlp.h>
  183. //-------------------- All global data is accessed through Global Class ----------
  184. class CGlobalVariables
  185. {
  186. public:
  187. SOCKET m_sockListen;
  188. DWORD m_dwListenPort; // port we're listening on (can be modified in registry. default=80)
  189. CVRoots* m_pVroots; // ptr to VRoot structure, containing or URL-->Paths mappings
  190. BOOL m_fBasicAuth; // are we allowing Basic auth (from registry)
  191. BOOL m_fNTLMAuth; // are we allowing NTLM auth (from registry)
  192. BOOL m_fFilters; // Is ISAPI filter component included?
  193. BOOL m_fExtensions; // Is ISAPI extension component included?
  194. BOOL m_fASP; // Is ASP component included?
  195. BOOL m_fDirBrowse; // are we allowing directory browsing (from registry)
  196. PWSTR m_wszDefaultPages; // are we allowing directory browsing (from registry)
  197. BOOL m_fAcceptConnections; // are we accepting new threads?
  198. LONG m_nConnections; // # of connections (threads) we're handling
  199. LONG m_nMaxConnections; // Maximum # of connections we support concurrently
  200. CLog* m_pLog; // Logging structure
  201. DWORD m_dwPostReadSize; // Size of chunks of data to recv() in POST request.
  202. PSTR m_pszServerID; // Server ID
  203. CISAPICache *m_pISAPICache; // Used to cache ISAPI extension and ASP dlls
  204. DWORD m_dwCacheSleep; // How often (in millesecs) do we
  205. PWSTR m_wszAdminUsers; // List of users who have administrative privelages
  206. PWSTR m_wszAdminGroups; // List of groups who have administrative privelages
  207. PSTR m_pszStatusBodyBuf; // Holds the strings of http bodies loaded from rc file
  208. SVSThreadPool *m_pThreadPool; // All httpd threads other than HttpConnectionThread use this
  209. LONG m_fISAPICacheRunning; // Is ISAPI cache cleanup thread running?
  210. // ASP Specific
  211. SCRIPT_LANG m_ASPScriptLang; // Registry set default scripting language
  212. LCID m_ASPlcid; // Registry set default LCID
  213. UINT m_lASPCodePage; // Registry set default Code Page
  214. // Authentication Specific
  215. HINSTANCE m_hNTLMLib; // Global NTLM library handle
  216. DWORD m_cbNTLMMax; // max ntlm allowable data size
  217. PSecurityFunctionTable m_pNTLMFuncs; // fcn table for NTLM requests
  218. HANDLE m_hEventSelect;
  219. HANDLE m_hEventShutdown;
  220. CGlobalVariables();
  221. ~CGlobalVariables();
  222. };
  223. extern CGlobalVariables *g_pVars;
  224. extern HINSTANCE g_hInst;
  225. extern HANDLE g_hListenThread;
  226. extern BOOL g_fRegistered;
  227. extern LONG g_fState;
  228. //------------- Function prototypes -------------------------
  229. DWORD WINAPI HttpConnectionThread(LPVOID lpv);
  230. DWORD WINAPI HandleAccept(LPVOID lpv);
  231. extern "C" int HttpInitialize(TCHAR *szRegPath);
  232. void GetRemoteAddress(SOCKET sock, PSTR pszBuf);
  233. void GetLocalAddress(SOCKET sock, PSTR pszBuf);
  234. DWORD WINAPI RemoveUnusedISAPIs(LPVOID lpv);
  235. BOOL SetHTTPVersion(PSTR pszVersion, DWORD *pdwVersion);
  236. void WriteHTTPVersion(PSTR pszVersion, DWORD dwVersion);
  237. char *strcpyEx(char *szDest, const char *szSrc);
  238. BOOL SetHTTPDate(PSTR pszDate, PSTR pszMonth, SYSTEMTIME *pst,PDWORD pdwModifiedLength);
  239. PSTR WriteHTTPDate(PSTR pszDateBuf, SYSTEMTIME *pst, BOOL fAddGMT);
  240. void InitializeResponseCodes(PSTR pszStatusBodyBuf);
  241. BOOL Base64Encode(
  242. BYTE * bufin, // in
  243. DWORD nbytes, // in
  244. char * pbuffEncoded); // out
  245. BOOL Base64Decode(
  246. char * bufcoded, // in
  247. char * pbuffdecoded, // out
  248. DWORD * pcbDecoded); // in out
  249. #endif //_HTTPD_H_