libcommon.i 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. %module libcommon
  2. %{
  3. #include <kopano/platform.h>
  4. #include <kopano/memory.hpp>
  5. #include <mapi.h>
  6. #include <mapidefs.h>
  7. #include <mapicode.h>
  8. #include <mapiutil.h>
  9. #include "HtmlToTextParser.h"
  10. #include "rtfutil.h"
  11. #include "favoritesutil.h"
  12. #include <kopano/Util.h>
  13. #include <kopano/memory.hpp>
  14. #include <kopano/ECLogger.h>
  15. #include "fileutil.h"
  16. #include "IStreamAdapter.h"
  17. // FIXME: why cant we get this from typemap_python
  18. #if PY_MAJOR_VERSION >= 3
  19. #define PyString_AsStringAndSize(value, input, size) \
  20. PyBytes_AsStringAndSize(value, input, size)
  21. #endif
  22. %}
  23. %include "wchar.i"
  24. %include "cstring.i"
  25. %include "cwstring.i"
  26. %include "std_string.i"
  27. %include <kopano/typemap.i>
  28. class CHtmlToTextParser {
  29. public:
  30. bool Parse(wchar_t *in);
  31. std::wstring& GetText();
  32. %extend {
  33. wchar_t *__str__() {
  34. return (wchar_t*)$self->GetText().c_str();
  35. }
  36. wchar_t *GetData() {
  37. return (wchar_t*)$self->GetText().c_str();
  38. }
  39. }
  40. };
  41. // std::string&
  42. %typemap(in,numinputs=0) std::string &OUTPUT (std::string s)
  43. {
  44. $1 = &s;
  45. }
  46. %typemap(argout,fragment="SWIG_FromCharPtr") (std::string &OUTPUT)
  47. {
  48. %append_output(SWIG_FromCharPtr($1->c_str()));
  49. if(PyErr_Occurred())
  50. goto fail;
  51. }
  52. %typemap(in,numinputs=0) std::wstring &OUTPUT (std::wstring s)
  53. {
  54. $1 = &s;
  55. }
  56. %typemap(argout,fragment="SWIG_FromWCharPtr") (std::wstring &OUTPUT)
  57. {
  58. %append_output(SWIG_FromWCharPtr($1->c_str()));
  59. if(PyErr_Occurred())
  60. goto fail;
  61. }
  62. // some common/rtfutil.h functions
  63. HRESULT HrExtractHTMLFromRTF(std::string lpStrRTFIn, std::string &OUTPUT, ULONG ulCodepage);
  64. HRESULT HrExtractHTMLFromTextRTF(std::string lpStrRTFIn, std::string &OUTPUT, ULONG ulCodepage);
  65. HRESULT HrExtractHTMLFromRealRTF(std::string lpStrRTFIn, std::string &OUTPUT, ULONG ulCodepage);
  66. HRESULT HrExtractBODYFromTextRTF(std::string lpStrRTFIn, std::wstring &OUTPUT);
  67. // functions from favoritesutil.h
  68. HRESULT GetShortcutFolder(IMAPISession *lpSession, LPTSTR lpszFolderName, LPTSTR lpszFolderComment, ULONG ulFlags, IMAPIFolder **lppShortcutFolder);
  69. HRESULT DelFavoriteFolder(IMAPIFolder *lpShortcutFolder, LPSPropValue lpPropSourceKey);
  70. HRESULT AddFavoriteFolder(IMAPIFolder *lpShortcutFolder, IMAPIFolder *lpFolder, LPTSTR lpszAliasName, ULONG ulFlags);
  71. HRESULT GetConfigMessage(IMsgStore *lpStore, char *szMessageName, IMessage **OUTPUT);
  72. // functions from common/Util.h
  73. class Util {
  74. public:
  75. static ULONG GetBestBody(IMAPIProp *lpPropObj, ULONG ulFlags);
  76. %extend {
  77. /* static ULONG GetBestBody(LPSPropValue lpProps, ULONG cValues, ULONG ulFlags); */
  78. /* swapped because typemap.i only implements (cValues, lpProps) */
  79. static ULONG GetBestBody(ULONG cValues, LPSPropValue lpProps, ULONG ulFlags) { return Util::GetBestBody(lpProps, cValues, ulFlags); }
  80. }
  81. };
  82. %feature("notabstract") IStreamAdapter;
  83. // this is a way to make std::string objects that you can pass to the IStreamAdapter
  84. %{
  85. std::string *new_StdString(char *szData) { return new std::string(szData); }
  86. void delete_StdString(std::string *string) { delete string; }
  87. typedef std::string std_string;
  88. %}
  89. class std_string {
  90. public:
  91. %extend {
  92. std_string(char *szData) { return new_StdString(szData); }
  93. ~std_string() { delete self; };
  94. }
  95. };
  96. %cstring_input_binary(const char *pv, ULONG cb);
  97. class IStreamAdapter {
  98. public:
  99. // Hard to typemap so using other method below
  100. // virtual HRESULT Read(void *OUTPUT, ULONG cb, ULONG *OUTPUT) = 0;
  101. virtual HRESULT Write(const char *pv, ULONG cb, ULONG *OUTPUT) = 0;
  102. %extend {
  103. HRESULT Read(ULONG cb, char **lpOutput, ULONG *ulRead) {
  104. char *buffer;
  105. HRESULT hr = MAPIAllocateBuffer(cb, (void **)&buffer);
  106. if(hr != hrSuccess)
  107. return hr;
  108. self->Read(buffer, cb, ulRead);
  109. *lpOutput = buffer;
  110. return hrSuccess;
  111. }
  112. }
  113. virtual HRESULT Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition) = 0;
  114. virtual HRESULT SetSize(ULARGE_INTEGER libNewSize) = 0;
  115. virtual HRESULT CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten) = 0;
  116. virtual HRESULT Commit(DWORD grfCommitFlags) = 0;
  117. virtual HRESULT Revert() = 0;
  118. virtual HRESULT LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) = 0;
  119. virtual HRESULT UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) = 0;
  120. virtual HRESULT Stat(STATSTG *pstatstg, DWORD grfStatFlag) = 0;
  121. virtual HRESULT Clone(IStream **ppstm) = 0;
  122. %extend {
  123. IStreamAdapter(std_string *strData) {
  124. IStreamAdapter *lpStream = new IStreamAdapter(*(std::string *)strData);
  125. return lpStream;
  126. }
  127. ~IStreamAdapter() {
  128. self->Release();
  129. }
  130. }
  131. };