tsip_transac.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_transac.h
  23. * @brief SIP transaction base class as per RFC 3261 subclause 17.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYSIP_TRANSAC_H
  29. #define TINYSIP_TRANSAC_H
  30. #include "tinysip_config.h"
  31. #include "tsip.h"
  32. #include "tinysip/tsip_timers.h"
  33. #include "tinysip/tsip_message.h"
  34. #include "tinysip/dialogs/tsip_dialog.h"
  35. #include "tsk_safeobj.h"
  36. #include "tsk_list.h"
  37. #include "tsk_fsm.h"
  38. TSIP_BEGIN_DECLS
  39. #define TSIP_TRANSAC(self) ((tsip_transac_t*)(self))
  40. #define TSIP_TRANSAC_GET_TYPE(self) TSIP_TRANSAC((self))->type
  41. #define TSIP_TRANSAC_GET_FSM(self) TSIP_TRANSAC((self))->fsm
  42. #define TSIP_TRANSAC_GET_SESSION(self) ((struct tsip_ssession_s*)(TSIP_TRANSAC_GET_DIALOG((self)) ? TSIP_TRANSAC_GET_DIALOG((self))->ss : tsk_null))
  43. #define TSIP_TRANSAC_GET_DIALOG(self) ((struct tsip_dialog_s*)(TSIP_TRANSAC_GET_DST((self))->type == tsip_transac_dst_type_dialog ? TSIP_TRANSAC_GET_DST((self))->dialog.dlg : tsk_null))
  44. #define TSIP_TRANSAC_GET_DST(self) TSIP_TRANSAC((self))->dst
  45. #define TSIP_TRANSAC_GET_STACK(self) TSIP_TRANSAC_GET_DST((self))->stack
  46. #define TSIP_TRANSAC_GET_TIMER_MGR(self) TSIP_TRANSAC_GET_STACK((self))->timer_mgr
  47. #define TSIP_TRANSAC_IS_CLIENT(self) ((self) && ((self)->type == tsip_transac_type_ict || (self)->type == tsip_transac_type_nict))
  48. #define TSIP_TRANSAC_IS_SERVER(self) !TSIP_TRANSAC_IS_CLIENT((self))
  49. #define TSIP_TRANSAC_MAGIC_COOKIE "z9hG4bK"
  50. #define TSIP_TRANSAC_SYNC_BEGIN(self) tsk_safeobj_lock(TSIP_TRANSAC(self))
  51. #define TSIP_TRANSAC_SYNC_END(self) tsk_safeobj_unlock(TSIP_TRANSAC(self))
  52. #define TRANSAC_TIMER_SCHEDULE(name, TX) \
  53. self->timer##TX.id = tsk_timer_mgr_global_schedule(self->timer##TX.timeout, TSK_TIMER_CALLBACK_F(tsip_transac_##name##_timer_callback), self)
  54. #define TRANSAC_TIMER_CANCEL(TX) \
  55. tsk_timer_mgr_global_cancel(self->timer##TX.id)
  56. typedef enum tsip_transac_event_type_e {
  57. tsip_transac_incoming_msg,
  58. tsip_transac_outgoing_msg,
  59. tsip_transac_canceled,
  60. tsip_transac_terminated,
  61. tsip_transac_timedout,
  62. tsip_transac_error,
  63. tsip_transac_transport_error
  64. }
  65. tsip_transac_event_type_t;
  66. /*typedef struct tsip_transac_event_s
  67. {
  68. tsip_transac_event_type_t type;
  69. const tsip_message_t *msg;
  70. }
  71. tsip_transac_event_t;
  72. #define TSIP_TRANSAC_EVENT_INIT(transac_event, type, msg) \
  73. transac_event.type = type; \
  74. transac_event.msg = msg;*/
  75. typedef int (*tsip_transac_event_callback_f)(const void *arg, tsip_transac_event_type_t type, const tsip_message_t *msg);
  76. #define TSIP_TRANSAC_EVENT_CALLBACK_F(callback) ((tsip_transac_event_callback_f)(callback))
  77. typedef enum tsip_transac_type_e {
  78. tsip_transac_type_ict, /**< Invite Client Transaction. */
  79. tsip_transac_type_ist, /**< Invite Server Transaction. */
  80. tsip_transac_type_nict, /**< Non-Invite Client Transaction. */
  81. tsip_transac_type_nist, /**< Non-Invite Server Transaction. */
  82. }
  83. tsip_transac_type_t;
  84. typedef enum tsip_transac_dst_type_e {
  85. tsip_transac_dst_type_dialog,
  86. tsip_transac_dst_type_net
  87. }
  88. tsip_transac_dst_type_t;
  89. typedef struct tsip_transac_dst_s {
  90. TSK_DECLARE_OBJECT;
  91. tsip_transac_dst_type_t type;
  92. struct tsip_stack_s* stack;
  93. union {
  94. struct {
  95. tsip_dialog_t *dlg;
  96. } dialog;
  97. //struct{
  98. //}net;
  99. };
  100. }
  101. tsip_transac_dst_t;
  102. #define TSIP_TRANSAC_DST(self) ((tsip_transac_dst_t*)(self))
  103. #define TSIP_DECLARE_TRANSAC_DST tsip_transac_dst_t __transac__
  104. typedef struct tsip_transac_s {
  105. TSK_DECLARE_OBJECT;
  106. tsip_transac_type_t type;
  107. struct tsip_transac_dst_s* dst;
  108. tsk_fsm_t *fsm;
  109. tsk_bool_t reliable;
  110. tsk_bool_t running;
  111. tsk_bool_t initialized;
  112. char *branch;
  113. int32_t cseq_value;
  114. char* cseq_method;
  115. char* callid;
  116. tsip_transac_event_callback_f callback;
  117. }
  118. tsip_transac_t;
  119. #define TSIP_DECLARE_TRANSAC tsip_transac_t __transac__
  120. typedef tsk_list_t tsip_transacs_L_t; /**< List of @ref tsip_transac_t elements. */
  121. /*
  122. ================================*/
  123. int tsip_transac_init(tsip_transac_t *self, tsip_transac_type_t type, int32_t cseq_value, const char* cseq_method, const char* callid, struct tsip_transac_dst_s* dst, tsk_fsm_state_id curr, tsk_fsm_state_id term);
  124. int tsip_transac_deinit(tsip_transac_t *self);
  125. int tsip_transac_start(tsip_transac_t *self, const tsip_request_t* request);
  126. int tsip_transac_deliver(tsip_transac_t* self, tsip_dialog_event_type_t event_type, const tsip_message_t *msg);
  127. int tsip_transac_send(tsip_transac_t *self, const char *branch, tsip_message_t *msg);
  128. int tsip_transac_cmp(const tsip_transac_t *t1, const tsip_transac_t *t2);
  129. int tsip_transac_remove(const tsip_transac_t* self);
  130. int tsip_transac_fsm_act(tsip_transac_t* self, tsk_fsm_action_id , const tsip_message_t*);
  131. struct tsip_transac_dst_s* tsip_transac_dst_dialog_create(tsip_dialog_t *dlg);
  132. struct tsip_transac_dst_s* tsip_transac_dst_net_create(struct tsip_stack_s* stack);
  133. TSIP_END_DECLS
  134. #endif /* TINYSIP_TRANSAC_H */