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.

95 lines
3.0 KiB

  1. /*--
  2. Copyright (c) 1995-1998 Microsoft Corporation
  3. Module Name: BUFFIO.H
  4. Author: Arul Menezes
  5. Abstract: Buffer handling class & socket IO helpers
  6. --*/
  7. // returned from the socket IO functions
  8. typedef enum
  9. {
  10. INPUT_OK = 0,
  11. INPUT_TIMEOUT = 1,
  12. INPUT_ERROR = 2,
  13. INPUT_NOCHANGE = 3
  14. //INPUT_EOF = 2,
  15. }
  16. HRINPUT;
  17. class CHttpRequest; // forward declaration
  18. int MySelect(SOCKET sock, DWORD dwMillisecs);
  19. //
  20. // There is one such buffer for all the headers of a request and another for the POST-body if any
  21. //
  22. class CBuffer
  23. {
  24. private:
  25. PSTR m_pszBuf;
  26. int m_iSize;
  27. int m_iNextOut;
  28. int m_iNextIn;
  29. int m_iNextInFollow; // next place to read, needed by raw read filters.
  30. CHAR m_chSaved; // Used by the parser
  31. BOOL AllocMem(DWORD dwLen);
  32. BOOL NextToken(PSTR* ppszTok, int* piLen, BOOL fWS, BOOL fColon = FALSE);
  33. public:
  34. CBuffer() {
  35. memset(this, 0, sizeof(*this));
  36. }
  37. ~CBuffer() {
  38. MyFree(m_pszBuf);
  39. }
  40. // Used to reset a buffer through the course of 1 session, uses
  41. // same allocated mem block. (don't change m_iSize)
  42. void Reset()
  43. {
  44. m_iNextInFollow = m_iNextOut = m_iNextIn = m_chSaved = 0;
  45. }
  46. // accessors
  47. DWORD Count() { return m_iNextIn - m_iNextOut; }
  48. BOOL HasPostData() { return (m_iNextIn > m_iNextOut); }
  49. PBYTE Data() { return (PBYTE)(m_pszBuf + m_iNextOut); }
  50. DWORD UnaccessedCount() { return m_iNextIn - m_iNextInFollow; } // this is data that hasn't been modified yet, for filters
  51. DWORD AvailableBufferSize() { return m_iSize - m_iNextInFollow; } // size of buffer, used by filters
  52. PBYTE FilterRawData() { return (PBYTE)(m_pszBuf + m_iNextInFollow); }
  53. PSTR Headers() { return m_pszBuf; } // Http headers are at beginning of buf
  54. DWORD GetINextOut() { return m_iNextOut; }
  55. BOOL TrimWhiteSpace();
  56. // input functions
  57. HRINPUT RecvToBuf(SOCKET sock, DWORD dwLength, DWORD dwTimeout,BOOL fFromFilter=FALSE);
  58. HRINPUT RecvHeaders(SOCKET sock)
  59. {
  60. DEBUGCHK(!m_iNextOut && !m_iNextIn);
  61. return RecvToBuf(sock, (DWORD)-1, KEEPALIVETIMEOUT);
  62. };
  63. HRINPUT RecvBody(SOCKET sock, DWORD dwLength, BOOL fFromFilter = FALSE)
  64. {
  65. DEBUGCHK(m_pszBuf && m_iSize);
  66. DEBUGCHK(m_iNextOut <= m_iNextIn);
  67. DEBUGCHK(m_iNextInFollow <= m_iNextIn);
  68. return RecvToBuf(sock, dwLength, RECVTIMEOUT,fFromFilter);
  69. };
  70. BOOL NextTokenWS(PSTR* ppszTok, int * piLen) { return NextToken(ppszTok, piLen, TRUE); }
  71. BOOL NextTokenEOL(PSTR* ppszTok, int * piLen) { return NextToken(ppszTok, piLen, FALSE); }
  72. BOOL NextTokenColon(PSTR* ppszTok, int * piLen) { return NextToken(ppszTok, piLen, TRUE, TRUE); }
  73. BOOL NextLine();
  74. BOOL AddHeader(PSTR pszName, PSTR pszValue, BOOL fAddColon=FALSE);
  75. // output functions
  76. BOOL AppendData(PSTR pszData, int iLen);
  77. BOOL SendBuffer(SOCKET sock, CHttpRequest *pRequest);
  78. BOOL FilterDataUpdate(PVOID pvData, DWORD cbData, BOOL fModifiedPointer);
  79. };