WebDav.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 _WEBDAV_H_
  18. #define _WEBDAV_H_
  19. #include <libxml/tree.h>
  20. #include <libxml/xmlwriter.h>
  21. #include <libxml/parser.h>
  22. #include <mapi.h>
  23. #include <map>
  24. #include "ProtocolBase.h"
  25. #include "Http.h"
  26. struct WEBDAVPROPNAME {
  27. std::string strNS;
  28. std::string strPropname;
  29. std::string strPropAttribName;
  30. std::string strPropAttribValue;
  31. };
  32. struct WEBDAVVALUE {
  33. WEBDAVPROPNAME sPropName;
  34. std::string strValue;
  35. };
  36. struct WEBDAVITEM {
  37. WEBDAVVALUE sDavValue;
  38. ULONG ulDepth;
  39. };
  40. struct WEBDAVPROPERTY {
  41. WEBDAVPROPNAME sPropName;
  42. std::list<WEBDAVVALUE> lstValues;
  43. std::string strValue;
  44. std::list<WEBDAVITEM> lstItems;
  45. };
  46. struct WEBDAVPROP {
  47. WEBDAVPROPNAME sPropName;
  48. std::list<WEBDAVPROPERTY> lstProps;
  49. };
  50. struct WEBDAVPROPSTAT {
  51. WEBDAVPROPNAME sPropName; /* always propstat */
  52. WEBDAVPROP sProp;
  53. WEBDAVVALUE sStatus; /* always status */
  54. };
  55. struct WEBDAVRESPONSE {
  56. WEBDAVPROPNAME sPropName;
  57. std::list<WEBDAVPROPSTAT> lstsPropStat;
  58. std::list<WEBDAVPROPERTY> lstProps;
  59. WEBDAVVALUE sHRef;
  60. WEBDAVVALUE sStatus; /* possible on delete (but we don't use that) */
  61. };
  62. struct WEBDAVMULTISTATUS {
  63. WEBDAVPROPNAME sPropName;
  64. std::list<WEBDAVRESPONSE> lstResp;
  65. };
  66. struct WEBDAVFILTER {
  67. WEBDAVPROPNAME sPropName;
  68. std::list<std::string> lstFilters;
  69. time_t tStart;
  70. };
  71. struct WEBDAVREQSTPROPS {
  72. WEBDAVPROPNAME sPropName;
  73. WEBDAVPROP sProp;
  74. WEBDAVFILTER sFilter;
  75. };
  76. struct WEBDAVRPTMGET {
  77. WEBDAVPROPNAME sPropName;
  78. WEBDAVPROP sProp;
  79. std::list<WEBDAVVALUE> lstWebVal;
  80. };
  81. struct WEBDAVFBUSERINFO {
  82. std::string strUser;
  83. std::string strIcal;
  84. };
  85. struct WEBDAVFBINFO {
  86. time_t tStart;
  87. time_t tEnd;
  88. std::string strOrganiser;
  89. std::string strUID;
  90. std::list<WEBDAVFBUSERINFO> lstFbUserInfo;
  91. };
  92. #define WEBDAVNS "DAV:"
  93. #define CALDAVNS "urn:ietf:params:xml:ns:caldav"
  94. class WebDav : public ProtocolBase {
  95. public:
  96. WebDav(Http *, IMAPISession *, const std::string &srv_tz, const std::string &charset);
  97. virtual ~WebDav();
  98. protected:
  99. /* preprocesses xml for HrHandle* functions */
  100. HRESULT HrPropfind();
  101. HRESULT HrReport();
  102. HRESULT HrPut();
  103. HRESULT HrMkCalendar();
  104. HRESULT HrPropPatch();
  105. HRESULT HrPostFreeBusy(WEBDAVFBINFO *lpsWebFbInfo);
  106. /* caldav implements real processing */
  107. virtual HRESULT HrHandlePropfind(WEBDAVREQSTPROPS *sProp,WEBDAVMULTISTATUS *lpsDavMulStatus) = 0;
  108. virtual HRESULT HrListCalEntries(WEBDAVREQSTPROPS *sWebRCalQry,WEBDAVMULTISTATUS *sWebMStatus) = 0;
  109. virtual HRESULT HrHandleReport(WEBDAVRPTMGET *sWebRMGet, WEBDAVMULTISTATUS *sWebMStatus) = 0;
  110. virtual HRESULT HrHandlePropPatch(WEBDAVPROP *lpsDavProp, WEBDAVMULTISTATUS *sWebMStatus) = 0;
  111. virtual HRESULT HrHandleMkCal(WEBDAVPROP *lpsDavProp) = 0;
  112. virtual HRESULT HrHandlePropertySearch(WEBDAVRPTMGET *sWebRMGet, WEBDAVMULTISTATUS *sWebMStatus) = 0;
  113. virtual HRESULT HrHandlePropertySearchSet(WEBDAVMULTISTATUS *sWebMStatus) = 0;
  114. virtual HRESULT HrHandleDelete() = 0;
  115. private:
  116. xmlDoc *m_lpXmlDoc = nullptr;
  117. std::map <std::string,std::string> m_mapNs;
  118. HRESULT HrParseXml();
  119. /* more processing xml, but not as direct entrypoint */
  120. HRESULT HrHandleRptMulGet();
  121. HRESULT HrPropertySearch();
  122. HRESULT HrPropertySearchSet();
  123. HRESULT HrHandleRptCalQry();
  124. HRESULT RespStructToXml(WEBDAVMULTISTATUS *sDavMStatus, std::string *strXml);
  125. HRESULT GetNs(std::string *szPrefx, std::string *strNs);
  126. void RegisterNs(const std::string &strNs, std::string *strPrefix);
  127. HRESULT WriteData(xmlTextWriter *xmlWriter, const WEBDAVVALUE &sWebVal, std::string *szNsPrefix);
  128. HRESULT WriteNode(xmlTextWriter *xmlWriter, const WEBDAVPROPNAME &sWebPrName, std::string *szNsPrefix);
  129. HRESULT HrWriteSResponse(xmlTextWriter *xmlWriter, std::string *lpstrNsPrefix, const WEBDAVRESPONSE &sResponse);
  130. HRESULT HrWriteResponseProps(xmlTextWriter *xmlWriter, std::string *lpstrNsPrefix, std::list<WEBDAVPROPERTY> *lstProps);
  131. HRESULT HrWriteSPropStat(xmlTextWriter *xmlWriter, std::string *lpstrNsPrefix, const WEBDAVPROPSTAT &sPropStat);
  132. HRESULT HrWriteItems(xmlTextWriter *xmlWriter, std::string *lpstrNsPrefix, WEBDAVPROPERTY *lpsWebProprty);
  133. void HrSetDavPropName(WEBDAVPROPNAME *lpsDavPropName,xmlNode *lpXmlNode);
  134. protected:
  135. void HrSetDavPropName(WEBDAVPROPNAME *lpsDavPropName, const std::string &strPropName, const std::string &strNs);
  136. void HrSetDavPropName(WEBDAVPROPNAME *lpsDavPropName, const std::string &strPropName, const std::string &strPropAttribName, const std::string &strPropAttribValue, const std::string &strNs);
  137. };
  138. #endif