Xcap.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef TINYWRAP_XCAP_H
  23. #define TINYWRAP_XCAP_H
  24. #include "tinyxcap.h"
  25. class XcapStack;
  26. typedef tsk_list_t twrap_xcap_steps_L_t;
  27. //
  28. // XcapSelector
  29. //
  30. class XcapSelector
  31. {
  32. public:
  33. XcapSelector(XcapStack* stack);
  34. virtual ~XcapSelector();
  35. public: /* API functions */
  36. XcapSelector* setAUID(const char* auid);
  37. XcapSelector* setName(const char* qname);
  38. XcapSelector* setAttribute(const char* qname, const char* att_qname, const char* att_value);
  39. XcapSelector* setPos(const char* qname, unsigned pos);
  40. XcapSelector* setPosAttribute(const char* qname, unsigned pos, const char* att_qname, const char* att_value);
  41. XcapSelector* setNamespace(const char* prefix, const char* value);
  42. char* getString();// %newobject
  43. void reset();
  44. private:
  45. txcap_stack_handle_t* stack_handle;
  46. char* auid;
  47. twrap_xcap_steps_L_t* steps;
  48. };
  49. //
  50. // XcapMessage
  51. //
  52. class XcapMessage
  53. {
  54. public:
  55. XcapMessage();
  56. #if !defined(SWIG)
  57. XcapMessage(const thttp_message_t *httpmessage);
  58. #endif
  59. virtual ~XcapMessage();
  60. short getCode() const;
  61. const char* getPhrase() const;
  62. char* getXcapHeaderValue(const char* name, unsigned index = 0);
  63. char* getXcapHeaderParamValue(const char* name, const char* param, unsigned index = 0);
  64. unsigned getXcapContentLength();
  65. unsigned getXcapContent(void* output, unsigned maxsize);
  66. private:
  67. const thttp_message_t *httpmessage;
  68. };
  69. //
  70. // XcapEvent
  71. //
  72. class XcapEvent
  73. {
  74. public:
  75. #if !defined(SWIG)
  76. XcapEvent(const thttp_event_t *httpevent);
  77. #endif
  78. virtual ~XcapEvent();
  79. thttp_event_type_t getType();
  80. const XcapMessage* getXcapMessage() const;
  81. private:
  82. const thttp_event_t *httpevent;
  83. const XcapMessage* httpmessage;
  84. };
  85. //
  86. // XcapCallback
  87. //
  88. class XcapCallback
  89. {
  90. public:
  91. XcapCallback();
  92. virtual ~XcapCallback();
  93. virtual int onEvent(const XcapEvent* e)const {
  94. return -1;
  95. }
  96. };
  97. //
  98. // XcapStack
  99. //
  100. class XcapStack
  101. {
  102. public:
  103. XcapStack(XcapCallback* callback, const char* xui, const char* password, const char* xcap_root);
  104. virtual ~XcapStack();
  105. public: /* API functions */
  106. bool registerAUID(const char* id, const char* mime_type, const char* ns, const char* document_name, bool is_global);
  107. bool start();
  108. bool setCredentials(const char* xui, const char* password);
  109. bool setXcapRoot(const char* xcap_root);
  110. bool setLocalIP(const char* ip);
  111. bool setLocalPort(unsigned port);
  112. bool addHeader(const char* name, const char* value);
  113. bool removeHeader(const char* name);
  114. bool setTimeout(unsigned timeout);
  115. bool getDocument(const char* url);
  116. bool getElement(const char* url);
  117. bool getAttribute(const char* url);
  118. bool deleteDocument(const char* url);
  119. bool deleteElement(const char* url);
  120. bool deleteAttribute(const char* url);
  121. bool putDocument(const char* url, const void* payload, unsigned len, const char* contentType);
  122. bool putElement(const char* url, const void* payload, unsigned len);
  123. bool putAttribute(const char* url, const void* payload, unsigned len);
  124. bool stop();
  125. public: /* Public helper function */
  126. #if !defined(SWIG)
  127. txcap_stack_handle_t* getHandle() {
  128. return this->handle;
  129. }
  130. XcapCallback* getCallback()const {
  131. return this->callback;
  132. }
  133. #endif
  134. private:
  135. txcap_stack_handle_t* handle;
  136. XcapCallback* callback;
  137. static unsigned count;
  138. };
  139. #endif /* TINYWRAP_XCAP_H */