tsip_message.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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_message.h
  23. * @brief Represents a SIP message. A SIP message is either a request from a client to a server, or a
  24. * response from a server to a client. See RFC 3261 suc-bclause 7.
  25. *
  26. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  27. *
  28. */
  29. #ifndef TSIP_MESSAGE_H
  30. #define TSIP_MESSAGE_H
  31. #include "tinysip_config.h"
  32. #include "tinysip/tsip_message_common.h"
  33. #include "tinysip/headers/tsip_header_Call_ID.h"
  34. #include "tinysip/headers/tsip_header_Contact.h"
  35. #include "tinysip/headers/tsip_header_Content_Length.h"
  36. #include "tinysip/headers/tsip_header_Content_Type.h"
  37. #include "tinysip/headers/tsip_header_CSeq.h"
  38. #include "tinysip/headers/tsip_header_Expires.h"
  39. #include "tinysip/headers/tsip_header_From.h"
  40. #include "tinysip/headers/tsip_header_P_Access_Network_Info.h"
  41. #include "tinysip/headers/tsip_header_To.h"
  42. #include "tinysip/headers/tsip_header_Via.h"
  43. #include "tnet_types.h"
  44. #include "tnet_socket.h"
  45. #include "tsk_object.h"
  46. #include "tsk_buffer.h"
  47. TSIP_BEGIN_DECLS
  48. ///**
  49. // * @struct tsip_request_line_t
  50. // *
  51. // * @brief Defines SIP request header line.
  52. // * ABNF: Request-Line = Method SP Request-URI SP SIP-Version CRLF
  53. // * Ref: RFC 3261 subclause 7.1.
  54. // * @sa tsip_status_line_t.
  55. // *
  56. // * @author Mamadou
  57. // * @date 12/3/2009
  58. //**/
  59. //typedef struct tsip_request_line_s
  60. //{
  61. // char *method; /**< SIP method name. e.g REGISTER, ACK or INVITE.*/
  62. // tsip_uri_t *uri; /**< The Request-URI is a SIP or SIPS URI as described in Section 19.1 or a general URI (RFC 2396 [5]). It indicates
  63. // the user or service to which this request is being addressed. The Request-URI MUST NOT contain unescaped spaces or control
  64. // characters and MUST NOT be enclosed in "<>". */
  65. //}
  66. //tsip_request_line_t;
  67. //
  68. ///**
  69. // * @struct tsip_status_line_t
  70. // *
  71. // * @brief Defines SIP response status line.
  72. // * ABNF: Status-Line = SIP-Version SP Status-Code SP Reason-Phrase CRLF
  73. // * Ref: RFC 3261 subclause 7.2.
  74. // * @sa tsip_request_line_t.
  75. // *
  76. // * @author Mamadou
  77. // * @date 12/3/2009
  78. //**/
  79. //typedef struct tsip_status_line_s
  80. //{
  81. // short status_code; /**< 3-digit integer result code that indicates the outcome of an attempt to understand and satisfy a request. */
  82. // char *reason_phrase; /**< Textual description related to the status code. */
  83. //}
  84. //tsip_status_line_t;
  85. /**
  86. * @struct tsip_message_t
  87. *
  88. * @brief Represents a SIP message. A SIP message is either a request from a client to a server,
  89. * or a response from a server to a client. See RFC 3261 suc-bclause 7.
  90. * You must call @ref tsip_message_create to create a sip message and TSK_OBJECT_SAFE_FREE to free the message.
  91. *
  92. * @author Mamadou
  93. * @date 12/2/2009
  94. **/
  95. typedef struct tsip_message_s {
  96. TSK_DECLARE_OBJECT;
  97. char *sip_version; /**< The SIP version. Only 'SIP/2.0' is supported. */
  98. tsip_message_type_t type; /**< The type of this SIP message. */
  99. /* Request Line */
  100. union {
  101. struct {
  102. char *method; /**< SIP method name. e.g REGISTER, ACK or INVITE.*/
  103. tsip_uri_t *uri; /**< The Request-URI is a SIP or SIPS URI as described in Section 19.1 or a general URI (RFC 2396 [5]). It indicates
  104. the user or service to which this request is being addressed. The Request-URI MUST NOT contain unescaped spaces or control
  105. characters and MUST NOT be enclosed in "<>". */
  106. tsip_request_type_t request_type;
  107. } request;
  108. struct {
  109. short status_code; /**< 3-digit integer result code that indicates the outcome of an attempt to understand and satisfy a request. */
  110. char *reason_phrase; /**< Textual description related to the status code. */
  111. } response;
  112. } line;
  113. /*== MOST COMMON HEADERS. */
  114. tsip_header_Via_t *firstVia; /**< First Via header. */
  115. tsip_header_From_t *From;
  116. tsip_header_To_t *To;
  117. tsip_header_Contact_t *Contact;
  118. tsip_header_Call_ID_t *Call_ID;
  119. tsip_header_CSeq_t *CSeq;
  120. tsip_header_Expires_t *Expires;
  121. tsip_header_Content_Type_t *Content_Type;
  122. tsip_header_Content_Length_t *Content_Length;
  123. tsk_buffer_t *Content;
  124. /*== OTHER HEADERS*/
  125. tsip_headers_L_t *headers;
  126. /*== to hack the message */
  127. char* sigcomp_id;
  128. tnet_fd_t local_fd;
  129. struct sockaddr_storage remote_addr; // Only valid for Dgram
  130. tsk_bool_t update;
  131. enum tnet_socket_type_e src_net_type;
  132. enum tnet_socket_type_e dst_net_type;
  133. char* dst_address;
  134. tnet_port_t dst_port;
  135. }
  136. tsip_message_t;
  137. typedef tsip_message_t tsip_request_t; /**< SIP request message. */
  138. typedef tsip_message_t tsip_response_t; /**< SIP response message. */
  139. TINYSIP_API int tsip_message_add_header(tsip_message_t *self, const tsip_header_t *hdr);
  140. TINYSIP_API int tsip_message_add_headers(tsip_message_t *self, ...);
  141. TINYSIP_API int tsip_message_add_content(tsip_message_t *self, const char* content_type, const void* content, tsk_size_t size);
  142. #if defined(__SYMBIAN32__) && 0
  143. static void TSIP_MESSAGE_ADD_HEADER(tsip_message_t *self, ...)
  144. {
  145. va_list ap;
  146. tsip_header_t *header;
  147. const tsk_object_def_t *objdef;
  148. va_start(ap, self);
  149. objdef = va_arg(ap, const tsk_object_def_t*);
  150. header = (tsip_header_t *)tsk_object_new_2(objdef, &ap);
  151. va_end(ap);
  152. tsip_message_add_header(self, header);
  153. tsk_object_unref(header);
  154. }
  155. #else
  156. #define TSIP_MESSAGE_ADD_HEADER(self, objdef, ...) \
  157. { \
  158. tsip_header_t *header = (tsip_header_t *)tsk_object_new(objdef, ##__VA_ARGS__); \
  159. tsip_message_add_header(self, header); \
  160. tsk_object_unref(header); \
  161. }
  162. #endif
  163. TINYSIP_API const tsip_header_t *tsip_message_get_headerAt(const tsip_message_t *self, tsip_header_type_t type, tsk_size_t index);
  164. TINYSIP_API const tsip_header_t *tsip_message_get_headerLast(const tsip_message_t *self, tsip_header_type_t type);
  165. TINYSIP_API const tsip_header_t *tsip_message_get_header(const tsip_message_t *self, tsip_header_type_t type);
  166. TINYSIP_API tsk_bool_t tsip_message_allowed(const tsip_message_t *self, const char* method);
  167. TINYSIP_API tsk_bool_t tsip_message_supported(const tsip_message_t *self, const char* option);
  168. TINYSIP_API tsk_bool_t tsip_message_required(const tsip_message_t *self, const char* option);
  169. TINYSIP_API int64_t tsip_message_getExpires(const tsip_message_t *message);
  170. TINYSIP_API uint32_t tsip_message_getContent_length(const tsip_message_t *message);
  171. TINYSIP_API int32_t tsip_message_getCSeq(const tsip_message_t *message);
  172. TINYSIP_API int tsip_message_tostring(const tsip_message_t *self, tsk_buffer_t *output);
  173. TINYSIP_API tsip_request_type_t tsip_request_get_type(const char* method);
  174. TINYSIP_API tsip_request_t *tsip_request_new(const char* method, const tsip_uri_t *request_uri, const tsip_uri_t *from, const tsip_uri_t *to, const char *call_id, int32_t cseq);
  175. TINYSIP_API tsip_response_t *tsip_response_new(short status_code, const char* reason_phrase, const tsip_request_t *request);
  176. TINYSIP_API tsip_message_t* tsip_message_create();
  177. TINYSIP_API tsip_request_t* tsip_request_create(const char* method, const tsip_uri_t* uri);
  178. TINYSIP_API tsip_response_t* tsip_response_create(const tsip_request_t* request, short status_code, const char* reason_phrase);
  179. TINYSIP_GEXTERN const tsk_object_def_t *tsip_message_def_t;
  180. TSIP_END_DECLS
  181. #endif /* TSIP_MESSAGE_H */