Http.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #ifndef _HTTP_H_
  18. #define _HTTP_H_
  19. #include <kopano/zcdefs.h>
  20. #include <mapidefs.h>
  21. #include <mapicode.h>
  22. #include <kopano/stringutil.h>
  23. #include <kopano/CommonUtil.h>
  24. #include <kopano/ECChannel.h>
  25. #include <kopano/ECIConv.h>
  26. #include <cstdio>
  27. #include <cstdarg>
  28. #include <cctype>
  29. #include <libxml/xmlmemory.h>
  30. #include <libxml/uri.h>
  31. #include <libxml/globals.h>
  32. #include <kopano/charset/convert.h>
  33. #define HTTP_CHUNK_SIZE 10000
  34. #define SERVICE_UNKNOWN 0x00
  35. #define SERVICE_ICAL 0x01
  36. #define SERVICE_CALDAV 0x02
  37. #define REQ_PUBLIC 0x04
  38. #define REQ_COLLECTION 0x08
  39. HRESULT HrParseURL(const std::string &stUrl, ULONG *lpulFlag, std::string *lpstrUrlUser = NULL, std::string *lpstrFolder = NULL);
  40. class Http _kc_final {
  41. public:
  42. Http(ECChannel *lpChannel, ECConfig *lpConfig);
  43. HRESULT HrReadHeaders();
  44. HRESULT HrValidateReq();
  45. HRESULT HrReadBody();
  46. HRESULT HrGetHeaderValue(const std::string &strHeader, std::string *strValue);
  47. /* @todo, remove and use HrGetHeaderValue() */
  48. HRESULT HrGetMethod(std::string *strMethod);
  49. HRESULT HrGetUser(std::wstring *strUser);
  50. HRESULT HrGetPass(std::wstring *strPass);
  51. HRESULT HrGetRequestUrl(std::string *strURL);
  52. HRESULT HrGetUrl(std::string *strURL);
  53. HRESULT HrGetBody(std::string *strBody);
  54. HRESULT HrGetDepth(ULONG *ulDepth);
  55. HRESULT HrGetCharSet(std::string *strCharset);
  56. HRESULT HrGetDestination(std::string *strDestination);
  57. HRESULT HrGetUserAgent(std::string *strUserAgent);
  58. HRESULT HrGetUserAgentVersion(std::string *strUserAgentVersion);
  59. HRESULT HrToHTTPCode(HRESULT hr);
  60. HRESULT HrResponseHeader(unsigned int ulCode, std::string strResponse);
  61. HRESULT HrResponseHeader(std::string strHeader, std::string strValue);
  62. HRESULT HrRequestAuth(std::string strMsg);
  63. HRESULT HrResponseBody(std::string strResponse);
  64. HRESULT HrSetKeepAlive(int ulKeepAlive);
  65. HRESULT HrFinalize();
  66. bool CheckIfMatch(LPMAPIPROP lpProp);
  67. private:
  68. ECChannel *m_lpChannel;
  69. ECConfig *m_lpConfig;
  70. /* request */
  71. std::string m_strAction; //!< full 1st-line
  72. std::string m_strMethod; //!< HTTP method, eg. GET, PROPFIND, etc.
  73. std::string m_strURL; //!< original action url
  74. std::string m_strPath; //!< decoded url
  75. std::string m_strHttpVer;
  76. std::map<std::string, std::string> mapHeaders;
  77. std::string m_strUser;
  78. std::string m_strPass;
  79. std::string m_strReqBody;
  80. std::string m_strCharSet;
  81. std::string m_strUserAgent;
  82. std::string m_strUserAgentVersion;
  83. /* response */
  84. std::string m_strRespHeader; //!< first header with http status code
  85. std::list<std::string> m_lstHeaders; //!< other headers
  86. std::string m_strRespBody;
  87. ULONG m_ulRetCode;
  88. int m_ulKeepAlive;
  89. convert_context m_converter;
  90. HRESULT HrParseHeaders();
  91. HRESULT HrFlushHeaders();
  92. HRESULT X2W(const std::string &strIn, std::wstring *lpstrOut);
  93. };
  94. #endif