ActionConfig.cxx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include "ActionConfig.h"
  22. ActionConfig::ActionConfig()
  23. {
  24. m_pHandle = tsip_action_create(tsip_atype_config,
  25. TSIP_ACTION_SET_NULL());
  26. }
  27. ActionConfig::~ActionConfig()
  28. {
  29. TSK_OBJECT_SAFE_FREE(m_pHandle);
  30. }
  31. bool ActionConfig::addHeader(const char* name, const char* value)
  32. {
  33. return (tsip_action_set(m_pHandle,
  34. TSIP_ACTION_SET_HEADER(name, value),
  35. TSIP_ACTION_SET_NULL()) == 0);
  36. }
  37. bool ActionConfig::addPayload(const void* payload, unsigned len)
  38. {
  39. return (tsip_action_set(m_pHandle,
  40. TSIP_ACTION_SET_PAYLOAD(payload, len),
  41. TSIP_ACTION_SET_NULL()) == 0);
  42. }
  43. bool ActionConfig::setActiveMedia(twrap_media_type_t type)
  44. {
  45. tmedia_type_t media_type = twrap_get_native_media_type(type);
  46. return (tsip_action_set(m_pHandle,
  47. TSIP_ACTION_SET_MEDIA_TYPE(media_type),
  48. TSIP_ACTION_SET_NULL()) == 0);
  49. }
  50. ActionConfig* ActionConfig::setResponseLine(short code, const char* phrase)
  51. {
  52. int32_t _code = code;
  53. tsip_action_set(m_pHandle,
  54. TSIP_ACTION_SET_RESP_LINE(_code, phrase),
  55. TSIP_ACTION_SET_NULL());
  56. return this;
  57. }
  58. ActionConfig* ActionConfig::setMediaString(twrap_media_type_t type, const char* key, const char* value)
  59. {
  60. tmedia_type_t media_type = twrap_get_native_media_type(type);
  61. tsip_action_set(m_pHandle,
  62. TSIP_ACTION_SET_MEDIA(
  63. TMEDIA_SESSION_SET_STR(media_type, key, value),
  64. TMEDIA_SESSION_SET_NULL()),
  65. TSIP_ACTION_SET_NULL());
  66. return this;
  67. }
  68. ActionConfig* ActionConfig::setMediaInt(twrap_media_type_t type, const char* key, int value)
  69. {
  70. tmedia_type_t media_type = twrap_get_native_media_type(type);
  71. tsip_action_set(m_pHandle,
  72. TSIP_ACTION_SET_MEDIA(
  73. TMEDIA_SESSION_SET_INT32(media_type, key, value),
  74. TMEDIA_SESSION_SET_NULL()),
  75. TSIP_ACTION_SET_NULL());
  76. return this;
  77. }