PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/620/Final/AlajarDll/HttpRequest.h

http://almonaster.codeplex.com
C Header | 228 lines | 123 code | 65 blank | 40 comment | 0 complexity | 9c1f17cf953271e2f82746d7302ff0cf MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0
  1. // HttpRequest.h: interface for the HttpRequest class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. //
  5. // Alajar.dll
  6. // Copyright (C) 1998-1999 Max Attar Feingold (maf6@cornell.edu)
  7. //
  8. // This program is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU General Public License
  10. // as published by the Free Software Foundation; either version 2
  11. // of the License, or (at your option) any later version.
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program; if not, write to the Free Software
  19. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. #if !defined(AFX_HTTPREQUEST_H__7E3E4056_A569_11D1_9C4E_0060083E8062__INCLUDED_)
  21. #define AFX_HTTPREQUEST_H__7E3E4056_A569_11D1_9C4E_0060083E8062__INCLUDED_
  22. #include "Osal/HashTable.h"
  23. #include "Osal/Socket.h"
  24. #include "Osal/String.h"
  25. #define ALAJAR_BUILD
  26. #include "Alajar.h"
  27. #undef ALAJAR_BUILD
  28. #include "HttpForm.h"
  29. #include "Cookie.h"
  30. // Error codes
  31. #define ERROR_MALFORMED_REQUEST (-70000000)
  32. #define ERROR_UNSUPPORTED_HTTP_VERSION (-70000001)
  33. #define ERROR_UNSUPPORTED_HTTP_METHOD (-70000002)
  34. #define MAX_URI_LEN (1024 * 4)
  35. class PageSource;
  36. class PageSourceHashValue;
  37. class PageSourceEquals;
  38. class HttpServer;
  39. class HttpRequest : public IHttpRequest {
  40. private:
  41. // Method, version, Uri
  42. HttpMethod m_iMethod;
  43. HttpVersion m_iVersion;
  44. char* m_pszUri;
  45. size_t m_stUriLength;
  46. // Uri as hard drive path
  47. char m_pszFileName [OS::MaxFileNameLength + 1];
  48. bool m_bCanonicalPath;
  49. // Browsername
  50. String m_strBrowserName;
  51. // Headers
  52. String m_strHeaders;
  53. // Client IP address
  54. String m_strIPAddress;
  55. // Referer
  56. String m_strReferer;
  57. // Name of host requested by client
  58. String m_strHostName;
  59. // True if file requested is cached (and last modification date of file is non-null also)
  60. bool m_bCached;
  61. // Separator text
  62. char* m_pszSeparator;
  63. size_t m_stSeparatorLength;
  64. size_t m_stSeparatorSpace;
  65. // Content length
  66. size_t m_stContentLength;
  67. // Authorization
  68. String m_strLogin;
  69. String m_strPassword;
  70. // Parse time
  71. MilliSeconds m_msParseTime;
  72. class RequestHashValue {
  73. public:
  74. static int GetHashValue (const char* pszKey, unsigned int iNumBuckets, const void* pHashHint);
  75. };
  76. class RequestEquals {
  77. public:
  78. static bool Equals (const char* pszLeft, const char* pszRight, const void* pEqualsHint);
  79. };
  80. // Forms
  81. unsigned int m_iNumHttpForms;
  82. unsigned int m_iNumHttpFormsSpace;
  83. const char** m_ppszHttpFormName;
  84. HttpForm** m_ppHttpForms;
  85. HashTable<const char*, HttpForm*, RequestHashValue, RequestEquals>* m_phtHttpFormTable;
  86. // Cookies
  87. unsigned int m_iNumCookies;
  88. const char** m_ppszCookieName;
  89. Cookie** m_ppCookies;
  90. size_t m_stCookieSpace;
  91. HashTable<const char*, Cookie*, RequestHashValue, RequestEquals>* m_phtCookieTable;
  92. // Keep-alive?
  93. bool m_bKeepAlive;
  94. // Server
  95. HttpServer* m_pHttpServer;
  96. // PageSource
  97. PageSource* m_pPageSource;
  98. // Socket
  99. Socket* m_pSocket;
  100. // Uploaded files
  101. unsigned int m_iNumFiles;
  102. size_t m_stNumBytes;
  103. bool m_bParsedUriForms;
  104. bool m_bMultiPartForms;
  105. int ParseRequestHeader (char* pszLine);
  106. int ParseHeader (char* pszLine);
  107. int HandleSimpleForms (char* pszBuffer, size_t stBufferSize, size_t stNumBytesInBuffer);
  108. int HandleLargeSimpleForm (char* pszBuffer, size_t stBufferSize, size_t stBytesParsed, size_t* pstCurrentPos,
  109. size_t* pstBytesParsed);
  110. int HandleMultipartForms (char* pszBuffer, size_t stNumBytes);
  111. int HandleMultiPartFormsInBuffer (size_t iNumBytes, char* pszBuffer, size_t* pstBytesProcessed,
  112. size_t* pstBytesRemaining);
  113. int HandleBigMultiPartForm (size_t stNumBytesRemaining, char* pszBuffer, size_t* pstNumBytesProcessed,
  114. size_t* pstBytesNumRemaining);
  115. int ParseForms (char* pszFormStart, size_t* pstParsed, bool bLastBytes);
  116. int AddHttpForm (HttpFormType ftFormType, const char* pszHttpFormName, const char* pszHttpFormValue,
  117. const char* pszFileName);
  118. public:
  119. HttpRequest();
  120. ~HttpRequest();
  121. void SetHttpServer (HttpServer* pHttpServer);
  122. void Recycle();
  123. MilliSeconds GetRequestParseTime() const;
  124. unsigned int GetNumFilesUploaded();
  125. size_t GetNumBytesInUploadedFiles();
  126. int ParseHeaders();
  127. bool GetKeepAlive() const;
  128. PageSource* GetPageSource() const;
  129. bool IsCached() const;
  130. bool ParsedUriForms() const;
  131. const char* GetParsedUriForms() const;
  132. void SetSocket (Socket* pSocket);
  133. // IHttpRequest
  134. IMPLEMENT_INTERFACE (IHttpRequest);
  135. HttpMethod GetMethod();
  136. HttpVersion GetVersion();
  137. const char* GetUri();
  138. const char* GetFileName();
  139. bool IsFileNameCanonical();
  140. const char* GetBrowserName();
  141. const char* GetClientIP();
  142. const char* GetReferer();
  143. unsigned int GetNumForms();
  144. IHttpForm* GetForm (unsigned int iIndex);
  145. const char** GetFormNames();
  146. IHttpForm* GetForm (const char* pszName);
  147. IHttpForm* GetFormBeginsWith (const char* pszName);
  148. unsigned int GetNumCookies();
  149. ICookie* GetCookie (unsigned int iIndex);
  150. const char** GetCookieNames();
  151. ICookie* GetCookie (const char* pszName);
  152. ICookie* GetCookieBeginsWith (const char* pszName);
  153. const char* GetLogin();
  154. const char* GetPassword();
  155. const char* GetHeaders();
  156. size_t GetHeaderLength();
  157. };
  158. class HttpRequestAllocator {
  159. public:
  160. static HttpRequest* New() { return new HttpRequest(); }
  161. static void Delete (HttpRequest* pHttpRequest) { delete pHttpRequest; }
  162. };
  163. #endif // !defined(AFX_HTTPREQUEST_H__7E3E4056_A569_11D1_9C4E_0060083E8062__INCLUDED_)