tsip_action.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]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. /**@file tsip_action.h
  23. * @brief SIP action.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TSIP_ACTION_H
  29. #define TSIP_ACTION_H
  30. #include "tinysip_config.h"
  31. #include "tsk_buffer.h"
  32. #include "tsk_options.h"
  33. #include "tsk_params.h"
  34. #include "tinymedia/tmedia_common.h"
  35. #include "tinymedia/tmedia_params.h"
  36. TSIP_BEGIN_DECLS
  37. typedef uint64_t tsip_action_id_t;
  38. #define TSIP_ACTION_INVALID_ID 0
  39. #define TSIP_ACTION_INVALID_HANDLE tsk_null
  40. /** List of all supported actions */
  41. typedef enum tsip_action_type_e {
  42. //! Used as configuration action
  43. tsip_atype_config,
  44. tsip_atype_dtmf_send,
  45. /* === REGISTER == */
  46. tsip_atype_register, /**< Sends SIP REGISTER request */
  47. //! Unregister by sending SIP REGISTER request with expires value equals to zero
  48. #define tsip_atype_unregister tsip_atype_hangup
  49. /* === SUBSCRIBE === */
  50. tsip_atype_subscribe, /**< Sends SIP SUBSCRIBE request */
  51. //! Unsubsribe by sending SIP SUBSCRIBE request with expires value equals to zero
  52. #define tsip_atype_unsubscribe tsip_atype_hangup
  53. /* === MESSAGE === */
  54. tsip_atype_message_send, /**< Sends SIP MESSAGE request */
  55. /* === INFO === */
  56. tsip_atype_info_send, /**< Sends SIP INFO request */
  57. /* === PUBLISH === */
  58. tsip_atype_publish, /**< Sends SIP PUBLISH request */
  59. //! Unpublish by sending SIP PUBLISH request with expires value equals to zero
  60. #define tsip_atype_unpublish tsip_atype_hangup
  61. /* === OPTIONS === */
  62. tsip_atype_options_send, /**< Sends SIP OPTIONS request */
  63. /* === INVITE === */
  64. tsip_atype_invite, /**< Sends SIP INVITE/reINVITE request */
  65. tsip_atype_hold, /**< Puts the session on hold state */
  66. tsip_atype_resume, /**< Resumes a previously held session */
  67. tsip_atype_ect, /**< Transfer the call */
  68. tsip_atype_ect_accept, /**< Accept call transfer request */
  69. tsip_atype_ect_reject, /**< Reject call transfer request */
  70. tsip_atype_ect_lnotify, /**< Intra-Dialog notify. Never called by the end-user */
  71. tsip_atype_lmessage, /**< Large message (MSRP). The session must be connected */
  72. #define tsip_atype_bye tsip_atype_hangup
  73. /* === common === */
  74. //! Accept incoming call (INVITE) or message (SIP MESSAGE)
  75. tsip_atype_accept,
  76. //! Reject incoming call (INVITE) or message (SIP MESSAGE)
  77. #define tsip_atype_reject tsip_atype_hangup
  78. //! Cancel an outgoing request
  79. tsip_atype_cancel,
  80. //! Hangup any SIP dialog (BYE, unREGISTER, unSUBSCRIBE ...). If the dialog is in early state, then it will be canceled.
  81. tsip_atype_hangup,
  82. //! Shutdown a SIP dialog. Should only be called by the stack.
  83. tsip_atype_shutdown,
  84. //! Signal transport error. Should only be called by the stack.
  85. tsip_atype_transport_error,
  86. }
  87. tsip_action_type_t;
  88. /* internal enum used to pass parameters from the application layer to the stack */
  89. typedef enum tsip_action_param_type_e {
  90. aptype_null = 0,
  91. aptype_header,
  92. aptype_config,
  93. aptype_payload,
  94. aptype_resp_line,
  95. aptype_media_type,
  96. aptype_media,
  97. }
  98. tsip_action_param_type_t;
  99. #define TSIP_ACTION_SET_HEADER(NAME_STR, VALUE_STR) aptype_header, (const char*)NAME_STR, (const char*)VALUE_STR
  100. #define TSIP_ACTION_SET_PAYLOAD(PAY_PTR, PAY_SIZE) aptype_payload, (const void*)PAY_PTR, (tsk_size_t)PAY_SIZE
  101. #define TSIP_ACTION_SET_RESP_LINE(CODE_INT, PHRASE_STR) aptype_resp_line, (int32_t)CODE_INT, (const char*)PHRASE_STR
  102. #define TSIP_ACTION_SET_CONFIG(ACTION_CONFIG_HANDLE) aptype_config, (const tsip_action_handle_t*)ACTION_CONFIG_HANDLE
  103. #define TSIP_ACTION_SET_MEDIA_TYPE(TYPE_ENUM) aptype_media_type, (enum tmedia_type_e)TYPE_ENUM
  104. #define TSIP_ACTION_SET_MEDIA(...) aptype_media, ##__VA_ARGS__
  105. #define TSIP_ACTION_SET_NULL() aptype_null
  106. /* private action object. public api should use tsip_action_handle_t. */
  107. typedef struct tsip_action_s {
  108. TSK_DECLARE_OBJECT;
  109. tsip_action_type_t type;
  110. tsk_params_L_t *headers;
  111. tsk_buffer_t* payload;
  112. struct {
  113. short code;
  114. char* phrase;
  115. } line_resp;
  116. struct {
  117. tmedia_type_t type;
  118. tmedia_params_L_t *params;
  119. } media;
  120. struct {
  121. int volume; // useless (manager will always use "10")
  122. int event;
  123. } dtmf;
  124. struct {
  125. char* to;
  126. } ect;
  127. }
  128. tsip_action_t;
  129. /**< Handle to SIP action */
  130. typedef void tsip_action_handle_t;
  131. TINYSIP_API tsip_action_handle_t* tsip_action_create(tsip_action_type_t type, ...);
  132. TINYSIP_API int tsip_action_set(tsip_action_handle_t* self, ...);
  133. typedef tsk_list_t tsip_actions_L_t; /**< List of @ref tsip_action_handle_t elements. */
  134. TINYSIP_GEXTERN const tsk_object_def_t *tsip_action_def_t;
  135. TSIP_END_DECLS
  136. #endif /* TSIP_ACTION_H */