tsip_header.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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_header.h
  23. * @brief Defines a SIP header (field-name: field-value).
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYSIP_HEADER_H
  29. #define TINYSIP_HEADER_H
  30. #include "tinysip_config.h"
  31. #include "tsk_ragel_state.h"
  32. #include "tsk_params.h"
  33. #include "tsk_object.h"
  34. #include "tsk_safeobj.h"
  35. #include "tsk_memory.h"
  36. #include "tsk_string.h"
  37. #include "tsk_list.h"
  38. #include "tsk_buffer.h"
  39. TSIP_BEGIN_DECLS
  40. struct tsip_header_s;
  41. #define TSIP_HEADER(self) ((tsip_header_t*)(self))
  42. #define TSIP_HEADER_PARAMS(self) (TSIP_HEADER(self)->params)
  43. #define TSIP_HEADER_VALUE_SERIALIZE_F(self) ((tsip_header_value_serialize_f)(self))
  44. #define TSIP_HEADER_GET_PARAM_VALUE_F(self) ((tsip_header_get_param_value_f)(self))
  45. typedef int (*tsip_header_value_serialize_f)(const struct tsip_header_s* header, tsk_buffer_t* output);
  46. typedef char* (*tsip_header_get_special_param_value_f)(const struct tsip_header_s* header, const char* pname);
  47. /**
  48. * @enum tsip_header_type_e
  49. *
  50. * @brief List of all supported headers.
  51. **/
  52. typedef enum tsip_header_type_e {
  53. tsip_htype_Accept,
  54. tsip_htype_Accept_Contact,
  55. tsip_htype_Accept_Encoding,
  56. tsip_htype_Accept_Language,
  57. tsip_htype_Accept_Resource_Priority,
  58. tsip_htype_Alert_Info,
  59. tsip_htype_Allow,
  60. tsip_htype_Allow_Events,
  61. tsip_htype_Authentication_Info,
  62. tsip_htype_Authorization,
  63. tsip_htype_Call_ID,
  64. tsip_htype_Call_Info,
  65. tsip_htype_Contact,
  66. tsip_htype_Content_Disposition,
  67. tsip_htype_Content_Encoding,
  68. tsip_htype_Content_Language,
  69. tsip_htype_Content_Length,
  70. tsip_htype_Content_Type,
  71. tsip_htype_CSeq,
  72. tsip_htype_Date,
  73. tsip_htype_Dummy,
  74. tsip_htype_Error_Info,
  75. tsip_htype_Event,
  76. tsip_htype_Expires,
  77. tsip_htype_From,
  78. tsip_htype_History_Info,
  79. tsip_htype_Identity,
  80. tsip_htype_Identity_Info,
  81. tsip_htype_In_Reply_To,
  82. tsip_htype_Join,
  83. tsip_htype_Max_Forwards,
  84. tsip_htype_MIME_Version,
  85. tsip_htype_Min_Expires,
  86. tsip_htype_Min_SE,
  87. tsip_htype_Organization,
  88. tsip_htype_Path,
  89. tsip_htype_Priority,
  90. tsip_htype_Privacy,
  91. tsip_htype_Proxy_Authenticate,
  92. tsip_htype_Proxy_Authorization,
  93. tsip_htype_Proxy_Require,
  94. tsip_htype_RAck,
  95. tsip_htype_Reason,
  96. tsip_htype_Record_Route,
  97. tsip_htype_Refer_Sub,
  98. tsip_htype_Refer_To,
  99. tsip_htype_Referred_By,
  100. tsip_htype_Reject_Contact,
  101. tsip_htype_Replaces,
  102. tsip_htype_Reply_To,
  103. tsip_htype_Request_Disposition,
  104. tsip_htype_Require,
  105. tsip_htype_Resource_Priority,
  106. tsip_htype_Retry_After,
  107. tsip_htype_Route,
  108. tsip_htype_RSeq,
  109. tsip_htype_Security_Client,
  110. tsip_htype_Security_Server,
  111. tsip_htype_Security_Verify,
  112. tsip_htype_Server,
  113. tsip_htype_Service_Route,
  114. tsip_htype_Session_Expires,
  115. tsip_htype_SIP_ETag,
  116. tsip_htype_SIP_If_Match,
  117. tsip_htype_Subject,
  118. tsip_htype_Subscription_State,
  119. tsip_htype_Supported,
  120. tsip_htype_Target_Dialog,
  121. tsip_htype_Timestamp,
  122. tsip_htype_To,
  123. tsip_htype_Unsupported,
  124. tsip_htype_User_Agent,
  125. tsip_htype_Via,
  126. tsip_htype_Warning,
  127. tsip_htype_WWW_Authenticate,
  128. tsip_htype_P_Access_Network_Info,
  129. tsip_htype_P_Answer_State,
  130. tsip_htype_P_Asserted_Identity,
  131. tsip_htype_P_Associated_URI,
  132. tsip_htype_P_Called_Party_ID,
  133. tsip_htype_P_Charging_Function_Addresses,
  134. tsip_htype_P_Charging_Vector,
  135. tsip_htype_P_DCS_Billing_Info,
  136. tsip_htype_P_DCS_LAES,
  137. tsip_htype_P_DCS_OSPS,
  138. tsip_htype_P_DCS_Redirect,
  139. tsip_htype_P_DCS_Trace_Party_ID,
  140. tsip_htype_P_Early_Media,
  141. tsip_htype_P_Media_Authorization,
  142. tsip_htype_P_Preferred_Identity,
  143. tsip_htype_P_Profile_Key,
  144. tsip_htype_P_User_Database,
  145. tsip_htype_P_Visited_Network_ID
  146. }
  147. tsip_header_type_t;
  148. /*================================
  149. */
  150. typedef struct tsip_header_s {
  151. TSK_DECLARE_OBJECT;
  152. tsip_header_type_t type;
  153. tsip_header_value_serialize_f serialize;
  154. tsip_header_get_special_param_value_f get_special_param_value;
  155. tsk_params_L_t *params;
  156. }
  157. tsip_header_t;
  158. #define TSIP_DECLARE_HEADER tsip_header_t __header__
  159. typedef tsk_list_t tsip_headers_L_t; /**< List of @ref tsip_header_t elements. */
  160. /*
  161. ================================*/
  162. TINYSIP_API const char *tsip_header_get_name(tsip_header_type_t type);
  163. TINYSIP_API const char *tsip_header_get_name_2(const tsip_header_t *self);
  164. TINYSIP_API char tsip_header_get_param_separator(const tsip_header_t *self);
  165. TINYSIP_API int tsip_header_serialize(const tsip_header_t *self, tsk_buffer_t *output);
  166. TINYSIP_API char* tsip_header_tostring(const tsip_header_t *self);
  167. TINYSIP_API int tsip_header_value_serialize(const tsip_header_t *self, tsk_buffer_t *output);
  168. TINYSIP_API char* tsip_header_value_tostring(const tsip_header_t *self);
  169. TINYSIP_API char* tsip_header_get_param_value(const tsip_header_t *self, const char* pname);
  170. #define TSIP_HEADER_HAVE_PARAM(self, name) ((self) && TSIP_HEADER((self))->params) ? tsk_params_have_param(TSIP_HEADER(self)->params, name) : tsk_false
  171. #define TSIP_HEADER_ADD_PARAM(self, name, value) tsk_params_add_param((self) ? &TSIP_HEADER((self))->params : tsk_null, name, value)
  172. #define TSIP_HEADER_REMOVE_PARAM(self, name) tsk_params_remove_param((self) ? TSIP_HEADER((self))->params : tsk_null, name)
  173. #define TSIP_HEADER_GET_PARAM_BY_NAME(self, name) tsk_params_get_param_by_name((self) ? TSIP_HEADER((self))->params : tsk_null, name)
  174. #define TSIP_HEADER_GET_PARAM_VALUE(self, name) tsk_params_get_param_value((self) ? TSIP_HEADER((self))->params : tsk_null, name)
  175. #define TSIP_HEADER_GET_PARAM_VALUE_AS_INT(self, name) tsk_params_get_param_value_as_int((self) ? TSIP_HEADER((self))->params : tsk_null, name)
  176. TSIP_END_DECLS
  177. #endif /* TINYSIP_HEADERS_H */