archiver.i 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* File : archiver.i */
  2. %module archiver
  3. %{
  4. #include <kopano/zcdefs.h>
  5. #include <stdexcept>
  6. #include "../../ECtools/archiver/Archiver.h"
  7. #include <kopano/charset/convert.h>
  8. #define TO_LPTST(s) ((s) ? converter.convert_to<LPTSTR>(s) : NULL)
  9. class _kc_export_throw ArchiverError : public std::runtime_error {
  10. public:
  11. ArchiverError(eResult e, const std::string &message)
  12. : std::runtime_error(message)
  13. , m_e(e)
  14. { }
  15. eResult result() const { return m_e; }
  16. private:
  17. eResult m_e;
  18. };
  19. %}
  20. %include "exception.i"
  21. %exception
  22. {
  23. try {
  24. $action
  25. } catch (const ArchiverError &ae) {
  26. SWIG_exception(SWIG_RuntimeError, ae.what());
  27. }
  28. }
  29. #if SWIGPYTHON
  30. %include "python/archiver_python.i"
  31. #endif
  32. class ArchiveControl {
  33. public:
  34. %extend {
  35. void ArchiveAll(bool bLocalOnly, bool bAutoAttach = false, unsigned int ulFlags = ArchiveManage::Writable) {
  36. eResult e = Success;
  37. e = self->ArchiveAll(bLocalOnly, bAutoAttach, ulFlags);
  38. if (e != Success)
  39. throw ArchiverError(e, "Method returned an error!");
  40. }
  41. void Archive(const char *lpszUser, bool bAutoAttach = false, unsigned int ulFlags = ArchiveManage::Writable) {
  42. eResult e = Success;
  43. convert_context converter;
  44. e = self->Archive(TO_LPTST(lpszUser), bAutoAttach, ulFlags);
  45. if (e != Success)
  46. throw ArchiverError(e, "Method returned an error!");
  47. }
  48. void CleanupAll(bool bLocalOnly) {
  49. eResult e = Success;
  50. e = self->CleanupAll(bLocalOnly);
  51. if (e != Success)
  52. throw ArchiverError(e, "Method returned an error!");
  53. }
  54. void Cleanup(const char *lpszUser) {
  55. eResult e = Success;
  56. convert_context converter;
  57. e = self->Cleanup(TO_LPTST(lpszUser));
  58. if (e != Success)
  59. throw ArchiverError(e, "Method returned an error!");
  60. }
  61. }
  62. private:
  63. ArchiveControl();
  64. };
  65. struct ArchiveEntry {
  66. std::string StoreName;
  67. std::string FolderName;
  68. std::string StoreOwner;
  69. unsigned Rights;
  70. };
  71. typedef std::list<ArchiveEntry> ArchiveList;
  72. struct UserEntry {
  73. std::string UserName;
  74. };
  75. typedef std::list<UserEntry> UserList;
  76. class ArchiveManage {
  77. public:
  78. enum {
  79. UseIpmSubtree = 1,
  80. Writable = 2,
  81. ReadOnly = 4
  82. };
  83. %extend {
  84. void AttachTo(const char *lpszArchiveServer, const char *lpszArchive, const char *lpszFolder, unsigned int ulFlags) {
  85. eResult e = Success;
  86. convert_context converter;
  87. e = self->AttachTo(lpszArchiveServer, TO_LPTST(lpszArchive), TO_LPTST(lpszFolder), ulFlags);
  88. if (e != Success)
  89. throw ArchiverError(e, "Method returned an error!");
  90. }
  91. void DetachFrom(const char *lpszArchiveServer, const char *lpszArchive, const char *lpszFolder) {
  92. eResult e = Success;
  93. convert_context converter;
  94. e = self->DetachFrom(lpszArchiveServer, TO_LPTST(lpszArchive), TO_LPTST(lpszFolder));
  95. if (e != Success)
  96. throw ArchiverError(e, "Method returned an error!");
  97. }
  98. void DetachFrom(unsigned int ulArchive) {
  99. eResult e = Success;
  100. e = self->DetachFrom(ulArchive);
  101. if (e != Success)
  102. throw ArchiverError(e, "Method returned an error!");
  103. }
  104. ArchiveList ListArchives(const char *lpszIpmSubtreeSubstitude = NULL) {
  105. eResult e = Success;
  106. ArchiveList lst;
  107. e = self->ListArchives(&lst);
  108. if (e != Success)
  109. throw ArchiverError(e, "Method returned an error!");
  110. return lst;
  111. }
  112. UserList ListAttachedUsers() {
  113. eResult e = Success;
  114. UserList lst;
  115. e = self->ListAttachedUsers(&lst);
  116. if (e != Success)
  117. throw ArchiverError(e, "Method returned an error!");
  118. return lst;
  119. }
  120. void AutoAttach(unsigned int ulFlags = ArchiveManage::Writable) {
  121. eResult e = Success;
  122. e = self->AutoAttach(ulFlags);
  123. if (e != Success)
  124. throw ArchiverError(e, "Method returned an error!");
  125. }
  126. }
  127. private:
  128. ArchiveManage();
  129. };
  130. class Archiver {
  131. public:
  132. enum {
  133. RequireConfig = 0x00000001,
  134. AttachStdErr = 0x00000002,
  135. InhibitErrorLogging = 0x40000000
  136. };
  137. %newobject Create;
  138. %newobject GetControl;
  139. %newobject GetManage;
  140. %extend {
  141. static Archiver *Create(const char *lpszAppName, const char *lpszConfig, unsigned int ulFlags = 0) {
  142. eResult r = Success;
  143. ArchiverPtr ptr;
  144. r = Archiver::Create(&ptr);
  145. if (r != Success)
  146. throw ArchiverError(r, "Failed to instantiate object!");
  147. r = ptr->Init(lpszAppName, lpszConfig, NULL, ulFlags);
  148. if (r != Success)
  149. throw ArchiverError(r, "Failed to initialize object!");
  150. return ptr.release();
  151. }
  152. ArchiveControl *GetControl(bool bForceCleanup = false) {
  153. eResult r = Success;
  154. ArchiveControlPtr ptr;
  155. r = self->GetControl(&ptr, bForceCleanup);
  156. if (r != Success)
  157. throw ArchiverError(r, "Failed to get object!");
  158. return ptr.release();
  159. }
  160. ArchiveManage *GetManage(const char *lpszUser) {
  161. eResult r = Success;
  162. ArchiveManagePtr ptr;
  163. convert_context converter;
  164. r = self->GetManage(TO_LPTST(lpszUser), &ptr);
  165. if (r != Success)
  166. throw ArchiverError(r, "Failed to get object!");
  167. return ptr.release();
  168. }
  169. void AutoAttach(unsigned int ulFlags = ArchiveManage::Writable) {
  170. eResult e = Success;
  171. e = self->AutoAttach(ulFlags);
  172. if (e != Success)
  173. throw ArchiverError(e, "Method returned an error!");
  174. }
  175. }
  176. private:
  177. Archiver();
  178. };