SOAPDebug.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. #include <kopano/platform.h>
  18. #include "SOAPDebug.h"
  19. #include <kopano/kcodes.h>
  20. #include <kopano/ECDebug.h>
  21. #include <edkmdb.h>
  22. #include <mapidefs.h>
  23. #include <kopano/stringutil.h>
  24. using namespace std;
  25. namespace KC {
  26. std::string RestrictionToString(const restrictTable *lpRestriction,
  27. unsigned int indent)
  28. {
  29. std::string strResult;
  30. unsigned int j = 0;
  31. if(lpRestriction == NULL)
  32. return "NULL";
  33. for (j = 0; j < indent; ++j)
  34. strResult += " ";
  35. switch(lpRestriction->ulType)
  36. {
  37. case RES_OR:
  38. strResult = "RES_OR:\n";
  39. for (gsoap_size_t i = 0; i < lpRestriction->lpOr->__size; ++i) {
  40. for (j = 0; j < indent + 1; ++j)
  41. strResult += " ";
  42. strResult += "Restriction: " + RestrictionToString(lpRestriction->lpOr->__ptr[i], indent + 1) + "\n";
  43. }
  44. for (j = 0; j < indent; ++j)
  45. strResult += " ";
  46. return strResult += "---or---\n";
  47. case RES_AND:
  48. strResult = "RES_AND:\n";
  49. for (gsoap_size_t i = 0; i < lpRestriction->lpAnd->__size; ++i) {
  50. for (j = 0; j < indent + 1; ++j)
  51. strResult += " ";
  52. strResult += "Restriction: " + RestrictionToString(lpRestriction->lpAnd->__ptr[i], indent + 1);
  53. }
  54. for (j = 0; j < indent; ++j)
  55. strResult += " ";
  56. return strResult += "---and---\n";
  57. case RES_BITMASK:
  58. strResult = "RES_BITMASK:\n";
  59. for (j = 0; j < indent; ++j)
  60. strResult += " ";
  61. switch (lpRestriction->lpBitmask->ulType) {
  62. case BMR_EQZ:
  63. strResult += "BMR: R_EQZ\n";
  64. break;
  65. case BMR_NEZ:
  66. strResult += "BMR: R_NEZ\n";
  67. break;
  68. default:
  69. strResult += "BMR: Not specified(" + stringify(lpRestriction->lpBitmask->ulType) + ")\n";
  70. break;
  71. }
  72. for (j = 0; j < indent; ++j)
  73. strResult += " ";
  74. strResult += "proptag: " + PropNameFromPropTag(lpRestriction->lpBitmask->ulPropTag) + "\n";
  75. for (j = 0; j < indent; ++j)
  76. strResult += " ";
  77. return strResult += "mask: " + stringify(lpRestriction->lpBitmask->ulMask) + "\n";
  78. case RES_COMMENT:
  79. strResult = "RES_COMMENT:\n";
  80. for (j = 0; j < indent; ++j)
  81. strResult += " ";
  82. strResult += "props: " + PropNameFromPropArray(lpRestriction->lpComment->sProps.__size, lpRestriction->lpComment->sProps.__ptr) + "\n";
  83. for (j = 0; j < indent; ++j)
  84. strResult += " ";
  85. return strResult += "restriction: " + RestrictionToString(lpRestriction->lpComment->lpResTable, indent + 1) + "\n";
  86. case RES_COMPAREPROPS:
  87. strResult = "RES_COMPAREPROPS:\n";
  88. for (j = 0; j < indent; ++j)
  89. strResult += " ";
  90. strResult += "relop: ";
  91. strResult += RelationalOperatorToString(lpRestriction->lpCompare->ulType);
  92. strResult += "\n";
  93. for (j = 0; j < indent; ++j)
  94. strResult += " ";
  95. strResult += "proptag1: " + PropNameFromPropTag(lpRestriction->lpCompare->ulPropTag1) + "\n";
  96. for (j = 0; j < indent; ++j)
  97. strResult += " ";
  98. return strResult += "proptag2: " + PropNameFromPropTag(lpRestriction->lpCompare->ulPropTag2) + "\n";
  99. case RES_CONTENT:
  100. strResult = "RES_CONTENT:\n";
  101. for (j = 0; j < indent; ++j)
  102. strResult += " ";
  103. strResult += "FuzzyLevel: " + FuzzyLevelToString(lpRestriction->lpContent->ulFuzzyLevel) + "\n";
  104. for (j = 0; j < indent; ++j)
  105. strResult += " ";
  106. strResult += "proptag: " + PropNameFromPropTag(lpRestriction->lpContent->ulPropTag) + "\n";
  107. for (j = 0; j < indent; ++j)
  108. strResult += " ";
  109. return strResult += "props: " + PropNameFromPropArray(1, lpRestriction->lpContent->lpProp) + "\n";
  110. case RES_EXIST:
  111. strResult = "RES_EXIST:\n";
  112. for (j = 0; j < indent; ++j)
  113. strResult += " ";
  114. return strResult += "proptag: " + PropNameFromPropTag(lpRestriction->lpExist->ulPropTag) + "\n";
  115. case RES_NOT:
  116. strResult = "RES_NOT:\n";
  117. for (j = 0; j < indent; ++j)
  118. strResult += " ";
  119. return strResult += "restriction: " + RestrictionToString(lpRestriction->lpNot->lpNot, indent + 1) + "\n";
  120. case RES_PROPERTY:
  121. strResult = "RES_PROPERTY:\n";
  122. for (j = 0; j < indent; ++j)
  123. strResult += " ";
  124. strResult += "relop: ";
  125. strResult += RelationalOperatorToString(lpRestriction->lpProp->ulType);
  126. strResult += "\n";
  127. for (j = 0; j < indent; ++j)
  128. strResult += " ";
  129. strResult += "proptag: " + PropNameFromPropTag(lpRestriction->lpProp->ulPropTag) + ((lpRestriction->lpProp->ulPropTag & MV_FLAG) ? " (MV_PROP)" : "") + "\n";
  130. for (j = 0; j < indent; ++j)
  131. strResult += " ";
  132. return strResult += "props: " + PropNameFromPropArray(1, lpRestriction->lpProp->lpProp) + ((lpRestriction->lpProp->lpProp->ulPropTag & MV_FLAG) ? " (MV_PROP)" : "") + "\n";
  133. case RES_SIZE:
  134. strResult = "RES_SIZE:\n";
  135. for (j = 0; j < indent; ++j)
  136. strResult += " ";
  137. strResult += "relop: ";
  138. strResult += RelationalOperatorToString(lpRestriction->lpSize->ulType);
  139. strResult += "\n";
  140. for (j = 0; j < indent; ++j)
  141. strResult += " ";
  142. strResult += "proptag: " + PropNameFromPropTag(lpRestriction->lpSize->ulPropTag) + "\n";
  143. for (j = 0; j < indent; ++j)
  144. strResult += " ";
  145. return strResult += "sizeofprop: " + stringify(lpRestriction->lpSize->cb) + "\n";
  146. case RES_SUBRESTRICTION:
  147. strResult = "RES_SUBRESTRICTION:\n";
  148. for (j = 0; j < indent; ++j)
  149. strResult += " ";
  150. switch (lpRestriction->lpSub->ulSubObject) {
  151. case PR_MESSAGE_RECIPIENTS:
  152. strResult += "subobject: PR_MESSAGE_RECIPIENTS\n";
  153. break;
  154. case PR_MESSAGE_ATTACHMENTS:
  155. strResult += "subobject: PR_MESSAGE_ATTACHMENTS\n";
  156. break;
  157. default:
  158. strResult += "subobject: Not specified(" + stringify(lpRestriction->lpSub->ulSubObject) + ")\n";
  159. break;
  160. }
  161. for (j = 0; j < indent; ++j)
  162. strResult += " ";
  163. return strResult += "Restriction: " + RestrictionToString(lpRestriction->lpSub->lpSubObject, indent + 1) + "\n";
  164. default:
  165. return "UNKNOWN TYPE:\n";
  166. }
  167. }
  168. std::string PropNameFromPropArray(unsigned int cValues,
  169. const propVal *lpPropArray)
  170. {
  171. std::string data;
  172. if(lpPropArray == NULL)
  173. return "NULL";
  174. else if(cValues == 0)
  175. return "EMPTY";
  176. for (unsigned int i = 0; i < cValues; ++i) {
  177. if(i>0)
  178. data+=", ";
  179. data += PropNameFromPropTag(lpPropArray[i].ulPropTag);
  180. data += ": ";
  181. data += PropValueToString(&lpPropArray[i]);
  182. data += "\n";
  183. }
  184. return data;
  185. }
  186. std::string PropValueToString(const propVal *lpPropValue)
  187. {
  188. std::string strResult;
  189. if(lpPropValue == NULL)
  190. return "NULL";
  191. switch(PROP_TYPE(lpPropValue->ulPropTag)) {
  192. case PT_I2:
  193. return "PT_I2: " + stringify(lpPropValue->Value.i);
  194. case PT_LONG:
  195. return "PT_LONG: " + stringify(lpPropValue->Value.ul);
  196. case PT_BOOLEAN:
  197. return "PT_BOOLEAN: " + stringify(lpPropValue->Value.b);
  198. case PT_R4:
  199. return "PT_R4: " + stringify_float(lpPropValue->Value.flt);
  200. case PT_DOUBLE:
  201. return "PT_DOUBLE: " + stringify_double(lpPropValue->Value.dbl);
  202. case PT_APPTIME:
  203. return "PT_APPTIME: " + stringify_double(lpPropValue->Value.dbl);
  204. case PT_CURRENCY:
  205. return "PT_CURRENCY: lo=" + stringify(lpPropValue->Value.hilo->lo) + " hi=" + stringify(lpPropValue->Value.hilo->hi);
  206. case PT_SYSTIME:
  207. //strResult = "PT_SYSTIME: fth="+stringify(lpPropValue->Value.hilo->hi)+" ftl="+stringify(lpPropValue->Value.hilo->lo);
  208. {
  209. time_t t = FileTimeToUnixTime(lpPropValue->Value.hilo->hi, lpPropValue->Value.hilo->lo);
  210. return (std::string)"PT_SYSTIME: " + ctime(&t);
  211. }
  212. break;
  213. case PT_I8:
  214. return "PT_I8: " + stringify_int64(lpPropValue->Value.li);
  215. case PT_UNICODE:
  216. return "PT_UNICODE: " + (lpPropValue->Value.lpszA ? (std::string)lpPropValue->Value.lpszA : std::string("NULL"));
  217. case PT_STRING8:
  218. return "PT_STRING8: " + (lpPropValue->Value.lpszA ? (std::string)lpPropValue->Value.lpszA : std::string("NULL"));
  219. case PT_BINARY:
  220. strResult = "PT_BINARY: cb=" + stringify(lpPropValue->Value.bin->__size);
  221. return strResult += " Data=" + (lpPropValue->Value.bin->__ptr ? bin2hex(lpPropValue->Value.bin->__size, lpPropValue->Value.bin->__ptr) : std::string("NULL"));
  222. case PT_CLSID:
  223. return "PT_CLSID: (Skip)";
  224. case PT_NULL:
  225. return "PT_NULL: ";
  226. case PT_UNSPECIFIED:
  227. return "PT_UNSPECIFIED: ";
  228. case PT_ERROR:
  229. return "PT_ERROR: " + stringify(lpPropValue->Value.ul, true);
  230. case PT_SRESTRICTION:
  231. return "PT_SRESTRICTION: structure...";
  232. case PT_ACTIONS:
  233. return "PT_ACTIONS: structure...";
  234. case PT_OBJECT:
  235. return "<OBJECT>";
  236. case PT_MV_I2:
  237. return "PT_MV_I2[" + stringify(lpPropValue->Value.mvi.__size) + "]";
  238. case PT_MV_LONG:
  239. return "PT_MV_LONG[" + stringify(lpPropValue->Value.mvl.__size) + "]";
  240. case PT_MV_R4:
  241. return "PT_MV_R4[" + stringify(lpPropValue->Value.mvflt.__size) + "]";
  242. case PT_MV_DOUBLE:
  243. return "PT_MV_DOUBLE[" + stringify(lpPropValue->Value.mvdbl.__size) + "]";
  244. case PT_MV_APPTIME:
  245. return "PT_MV_APPTIME[" + stringify(lpPropValue->Value.mvbin.__size) + "]";
  246. case PT_MV_CURRENCY:
  247. return "PT_MV_CURRENCY[" + stringify(lpPropValue->Value.mvbin.__size) + "]";
  248. case PT_MV_SYSTIME:
  249. return "PT_MV_SYSTIME[" + stringify(lpPropValue->Value.mvbin.__size) + "]";
  250. case PT_MV_I8:
  251. return "PT_MV_I8[" + stringify(lpPropValue->Value.mvli.__size) + "]";
  252. case PT_MV_UNICODE:
  253. strResult = "PT_MV_UNICODE[" + stringify(lpPropValue->Value.mvszA.__size) + "]" + "\n";
  254. for (gsoap_size_t i = 0; i < lpPropValue->Value.mvszA.__size; ++i)
  255. strResult += std::string("\t") + lpPropValue->Value.mvszA.__ptr[i] + "\n";
  256. return strResult;
  257. case PT_MV_STRING8:
  258. strResult = "PT_MV_STRING8[" + stringify(lpPropValue->Value.mvszA.__size) + "]" + "\n";
  259. for (gsoap_size_t i = 0; i < lpPropValue->Value.mvszA.__size; ++i)
  260. strResult += std::string("\t") + lpPropValue->Value.mvszA.__ptr[i] + "\n";
  261. return strResult;
  262. case PT_MV_BINARY:
  263. return "PT_MV_BINARY[" + stringify(lpPropValue->Value.mvbin.__size) + "]";
  264. case PT_MV_CLSID:
  265. return "PT_MV_CLSID[" + stringify(lpPropValue->Value.mvbin.__size) + "]";
  266. default:
  267. return "<UNKNOWN>";
  268. }
  269. }
  270. const char* RightsToString(unsigned int ulecRights)
  271. {
  272. switch (ulecRights) {
  273. case(ecSecurityRead):
  274. return "read";
  275. case(ecSecurityCreate):
  276. return "create";
  277. case(ecSecurityEdit):
  278. return "edit";
  279. case(ecSecurityDelete):
  280. return "delete";
  281. case(ecSecurityCreateFolder):
  282. return "change hierarchy";
  283. case(ecSecurityFolderVisible):
  284. return "view";
  285. case(ecSecurityFolderAccess):
  286. return "folder permissions";
  287. case(ecSecurityOwner):
  288. return "owner";
  289. case(ecSecurityAdmin):
  290. return "admin";
  291. default:
  292. return "none";
  293. };
  294. }
  295. } /* namespace */