📄 httpd.h
字号:
extern const char cszTextHtml[];
extern const char cszOctetStream[];
extern const char cszEmpty[];
extern const char* rgMonth[];
extern const char cszKeepAlive[];
extern const char cszHTTPVER[];
extern const char cszDateParseFmt[];
extern const char cszDateOutputFmt[];
extern const char* rgWkday[];
extern const char* rgMonth[];
extern const char cszCRLF[];
extern const char cszBasic[];
extern const char cszNTLM[];
extern const char cszHTTPVER[];
extern const CHAR g_szHexDigits[];
extern const DWORD g_fIsapiExtensionModule;
extern const DWORD g_fIsapiFilterModule;
extern const DWORD g_fAuthModule;
extern const DWORD g_fWebDavModule;
//----------------------- Class defns -----------------------
class CGlobalVariables;
#include <asp.h>
#include <buffio.h>
#include <extns.h>
#include <vroots.hpp>
#include <auth.h>
#include <ssl.h>
#include <request.h>
#include <log.h>
#include <filters.h>
#include <httpstr.h>
#include <webdav.h>
#include <davlock.h>
#include <davxml.h>
#include <authhlp.h>
extern CHttpRequest *g_pRequestList;
extern CRITICAL_SECTION g_CritSect;
//-------------------- All global data is accessed through Global Class ----------
class CGlobalVariables : public SVSInterfaceMapper {
public:
DWORD m_dwSystemChangeNumber; // Current state of web server. Increments one each time settings are refreshed.
// Support for multiple websites
BOOL m_fRootSite; // TRUE if we're default website, FALSE otherwise
BOOL m_fUseDefaultSite; // TRUE if we allow g_pVars to host website if there's no IP address map, FALSE otherwise.
// Basic web server config variables
DWORD m_dwListenPort; // port we're listening on (can be modified in registry. default=80)
CVRoots* m_pVroots; // ptr to VRoot structure, containing or URL-->Paths mappings
BOOL m_fBasicAuth; // are we allowing Basic auth?
BOOL m_fNTLMAuth; // are we allowing NTLM auth?
BOOL m_fNegotiateAuth; // are we willing to Negotiate auth?
BOOL m_fFilters; // Is ISAPI filter component included?
BOOL m_fExtensions; // Is ISAPI extension component included?
BOOL m_fASP; // Is ASP component included?
BOOL m_fDirBrowse; // are we allowing directory browsing
PWSTR m_wszDefaultPages; // are we allowing directory browsing
BOOL m_fAcceptConnections; // are we accepting new threads?
LONG m_nConnections; // # of connections (threads) we're handling
LONG m_nMaxConnections; // Maximum # of connections we support concurrently
CLog* m_pLog; // Logging structure
DWORD m_dwPostReadSize; // Size of chunks of data to recv() in POST request.
DWORD m_dwMaxHeaderReadSize; // Maximum # of bytes of header to read before rejecting request.
PSTR m_szServerID; // Returned to client in "Server:" HTTP response header.
PSTR m_szBasicRealm; // Realm specified in Basic-Realm during Basic Auth.
DWORD m_dwConnectionTimeout; // Number of milliseconds inactive connections are kept open before being closed.
// WebDAV
BOOL m_fWebDav; // Are WebDAV extensions supported?
DWORD m_dwDavDefaultLockTimeout; // Default number of milliseconds until DAV locks expire.
CISAPICache *m_pISAPICache; // Used to cache ISAPI extension and ASP dlls
DWORD m_dwCacheSleep; // How often (in millesecs) do we
PWSTR m_wszAdminUsers; // List of users who have administrative privelages
PSTR m_pszStatusBodyBuf; // Holds the strings of http bodies loaded from rc file
SVSThreadPool *m_pThreadPool; // All httpd threads other than HttpConnectionThread use this
BOOL m_fReadFilters; // TRUE only if there's a registered read filter.
SCRIPT_MAP m_scriptMap; // Map file extensions to ISAPI / ASP scripts.
SCRIPT_NOUNLOAD m_scriptNoUnload; // List of ISAPI extensions never to unload.
CHAR m_szMaxConnectionMsg[256]; // Message to send when max # of connections have been established.
// ASP Specific
SCRIPT_LANG m_ASPScriptLang; // Default scripting language
LCID m_ASPlcid; // Default LCID
UINT m_lASPCodePage; // Default Code Page
DWORD m_fASPVerboseErrorMessages; // Whether to display descriptive messages on script error or not.
DWORD m_dwAspMaxFormSize; // Max size of HTTP body ASP will read as a result of Request.Form access
// Authentication Specific
void InitAuthentication(CReg *pReg);
BOOL InitSecurityLib(void);
HINSTANCE m_hSecurityLib; // Global Security library handle
DWORD m_cbMaxToken; // max ntlm allowable data size
SecurityFunctionTable m_SecurityInterface; // fcn table for Security requests
// SSL Specific
void InitSSL(CReg *pWebsite);
void FreeSSLResources(void);
BOOL m_fSSL; // Is SSL enabled?
BOOL m_fSSLSkipProcessing; // Bind to SSL Port but don't handle requests, letting user custom ISAPI Filter do the work.
DWORD m_dwSSLPort; // Port to bind to for SSL for.
PSTR m_pszSSLIssuer; // certificate's issuer
PSTR m_pszSSLSubject; // certificate's subject
CSSLUsers m_SSLUsers; // User <-> certificate info mapping table.
CredHandle m_hSSLCreds; // global credentials info
BOOL m_fHasSSLCreds; // Do we need to free credentials on shutdown?
HCERTSTORE m_hSSLCertStore; // certificate store
FixedMemDescr *m_SSLUserMemDescr; // Fixed mem descriptor to hold SSL user info.
DWORD m_dwSSLCertTrustOverride; // what errors to ignore from call to CertGetCertificateChain() on client certs.
void InitGlobals(CReg *pWebsite);
void DeInitGlobals(void);
CGlobalVariables(CReg *pWebsite) { InitGlobals(pWebsite); }
~CGlobalVariables() { DeInitGlobals(); }
void DeInitExtensions(void);
BOOL InitExtensions(CReg *pWebsite);
BOOL InitASP(CReg *pWebsite);
// deal with connection level socket
BOOL CreateHTTPSocket(BOOL fSecure);
BOOL IsSecureSocket(PSOCKADDR pSockAddr, DWORD cbSockAddr);
// WebDAV support
BOOL InitWebDav(CReg *pWebsite);
void DeInitWebDav(void);
};
extern CGlobalVariables *g_pVars;
extern CGlobalVariables *g_pWebsites;
extern DWORD g_cWebsites;
void CleanupGlobalMemory(DWORD dwWebsites);
CGlobalVariables* MapWebsite(SOCKET sock, PSTR szHostHeader);
extern HINSTANCE g_hInst;
extern HANDLE g_hAdminThread;
extern LONG g_fState;
extern CWebDavFileLockManager *g_pFileLockManager;
extern SVSThreadPool *g_pTimer;
extern const char *rg_cszMethods[];
//------------- Function prototypes -------------------------
DWORD WINAPI HttpConnectionThread(LPVOID lpv);
BOOL IsPathScript(WCHAR *szPath, SCRIPT_TYPE scriptType=SCRIPT_TYPE_NONE);
BOOL GetRemoteAddress(SOCKET sock, PSTR pszBuf, BOOL fTryHostName, DWORD cbBuf);
DWORD WINAPI PeriodicWakeupThread(LPVOID lpv);
char *strcpyEx(char *szDest, const char *szSrc);
// Writes date into buffer, returns next point to write out from.
inline int WriteDateGMT(PSTR szBuf,const SYSTEMTIME *pst, BOOL fCRLF=FALSE) {
int iLen = sprintf(szBuf, cszDateFmtGMT, rgWkday[pst->wDayOfWeek], pst->wDay, rgMonth[pst->wMonth], pst->wYear, pst->wHour, pst->wMinute, pst->wSecond);
if (fCRLF) {
strcpy(szBuf+iLen,cszCRLF);
iLen += 2;
}
return iLen;
}
inline int WriteDateGMT(PSTR szBuf, const FILETIME *pft, BOOL fCRLF=FALSE) {
SYSTEMTIME st;
FileTimeToSystemTime(pft,&st);
return WriteDateGMT(szBuf,&st,fCRLF);
}
void InitializeResponseCodes(PSTR pszStatusBodyBuf);
BOOL HttpInitializeOnce(void);
BOOL CreateHTTPConnection(SOCKET sock, PSOCKADDR pSockAddr, DWORD cbSockAddr);
DWORD WINAPI InitializeGlobalsThread(LPVOID lpv);
BOOL InitializeGlobals();
void WaitForConnectionThreadsToEnd(void);
BOOL IsHttpdEnabled(void);
PSTR MassageMultiStringToAnsi(PCWSTR wszIn, PCWSTR wszDefault);
DWORD GetETagFromFiletime(FILETIME *pft, DWORD dwFileSize, PSTR szWriteBuffer);
int PathNameCompare(WCHAR *szSrc, WCHAR *szDest);
int PathNameCompareN(WCHAR *src, WCHAR *dst, int len);
inline int IsNonCRLFSpace(CHAR c) {
return ( c == ' ' || c == '\t' || c == '\f' || c == '\v');
}
inline RESPONSESTATUS GLEtoStatus(void) {
return GLEtoStatus(GetLastError());
}
inline USHORT GetSocketPort(PSOCKADDR pSockAddr) {
PREFAST_SUPPRESS(24002,"Since port is in same place for both v4 + v6 sockets, this typecast is OK")
SOCKADDR_IN *pSockIn = (SOCKADDR_IN *)pSockAddr;
return pSockIn->sin_port;
}
#define HEX_ESCAPE '%'
// to milliseconds (10 * 1000)
#define FILETIME_TO_MILLISECONDS ((__int64)10000L)
#define SkipWhiteSpaceNonCRLF(lpsz) while ( (lpsz)[0] != '\0' && IsNonCRLFSpace((lpsz)[0])) ++(lpsz)
// This routine waits for the specified global thread handle to be set before
// it allows the given thread to execute
inline void MyWaitForReadyState(HANDLE hThread) {
#if defined (DEBUG)
int iAttempts = 0;
#endif
while (!hThread) {
Sleep(10);
#if defined (DEBUG)
if (iAttempts == 5) // we shouldn't have to wait this long for thread to be ready - something is probably wrong.
DEBUGCHK(0);
#endif
}
}
inline void MyWaitForAdminThreadReadyState(void) { MyWaitForReadyState(g_hAdminThread); }
#endif //_HTTPD_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -