tsip_message_common.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_common.h
  23. * @brief Common macros and enums for SIP messages.
  24. * Mostly used to avoid circular #includes.
  25. *
  26. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  27. *
  28. */
  29. #ifndef TSIP_MESSAGE_COMMON_H
  30. #define TSIP_MESSAGE_COMMON_H
  31. #include "tinysip_config.h"
  32. TSIP_BEGIN_DECLS
  33. #define TSIP_MESSAGE_VERSION_10 "SIP/1.0"
  34. #define TSIP_MESSAGE_VERSION_20 "SIP/2.0"
  35. #define TSIP_MESSAGE_VERSION_DEFAULT TSIP_MESSAGE_VERSION_20
  36. #define TSIP_MESSAGE_IS_REQUEST(self) ((self) ? (self)->type == tsip_request : tsk_false)
  37. #define TSIP_MESSAGE_IS_RESPONSE(self) ((self) ? (self)->type == tsip_response : tsk_false)
  38. #define TSIP_MESSAGE(self) ((tsip_message_t*)(self))
  39. #define TSIP_MESSAGE_AS_RESPONSE(self) (TSIP_MESSAGE_IS_RESPONSE((self)) ? (tsip_response_t*)(self) : tsk_null)
  40. #define TSIP_MESSAGE_AS_REQUEST(self) (TSIP_MESSAGE_IS_REQUEST((self)) ? (tsip_request_t*)(self) : tsk_null)
  41. #define TSIP_RESPONSE_CODE(self) (TSIP_MESSAGE_IS_RESPONSE((self)) ? (self)->line.response.status_code : 0)
  42. #define TSIP_RESPONSE_PHRASE(self) (TSIP_MESSAGE_IS_RESPONSE((self)) ? (self)->line.response.reason_phrase : tsk_null)
  43. #define TSIP_REQUEST_METHOD(self) ((self)->line.request.method)
  44. #define TSIP_REQUEST_URI(self) ((self)->line.request.uri)
  45. #define TSIP_MESSAGE_CSEQ_METHOD(self) ((self)->CSeq ? (self)->CSeq->method : tsk_null)
  46. #define TSIP_MESSAGE_HAS_CONTENT(self) ((self) && (self)->Content && (self)->Content->data)
  47. #define TSIP_MESSAGE_CONTENT_LENGTH(self) (uint32_t)(((self) && (self)->Content_Length) ? (self)->Content_Length->length : 0)
  48. #define TSIP_MESSAGE_CONTENT_DATA(self) (TSIP_MESSAGE_HAS_CONTENT(self) ? (self)->Content->data : tsk_null)
  49. #define TSIP_MESSAGE_CONTENT_DATA_LENGTH(self) (TSIP_MESSAGE_HAS_CONTENT(self) ? (self)->Content->size : 0)
  50. #define TSIP_MESSAGE_CONTENT(self) (TSIP_MESSAGE_HAS_CONTENT(self) ? (self)->Content : tsk_null)
  51. #define TSIP_MESSAGE_CONTENT_TYPE(self) (((self) && (self)->Content_Type) ? (self)->Content_Type->type : tsk_null)
  52. #define TSIP_REQUEST_IS_ACK(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_ACK))
  53. #define TSIP_REQUEST_IS_BYE(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_BYE))
  54. #define TSIP_REQUEST_IS_CANCEL(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_CANCEL))
  55. #define TSIP_REQUEST_IS_INVITE(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_INVITE))
  56. #define TSIP_REQUEST_IS_OPTIONS(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_OPTIONS))
  57. #define TSIP_REQUEST_IS_REGISTER(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_REGISTER))
  58. #define TSIP_REQUEST_IS_SUBSCRIBE(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_SUBSCRIBE))
  59. #define TSIP_REQUEST_IS_NOTIFY(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_NOTIFY))
  60. #define TSIP_REQUEST_IS_REFER(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_REFER))
  61. #define TSIP_REQUEST_IS_INFO(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_INFO))
  62. #define TSIP_REQUEST_IS_UPDATE(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_UPDATE))
  63. #define TSIP_REQUEST_IS_MESSAGE(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_MESSAGE))
  64. #define TSIP_REQUEST_IS_PUBLISH(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_PUBLISH))
  65. #define TSIP_REQUEST_IS_PRACK(self) ((self) && TSIP_MESSAGE_IS_REQUEST((self)) &&((self)->line.request.request_type==tsip_PRACK))
  66. #define TSIP_RESPONSE_IS_TO_ACK(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_ACK))
  67. #define TSIP_RESPONSE_IS_TO_BYE(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_BYE))
  68. #define TSIP_RESPONSE_IS_TO_CANCEL(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_CANCEL))
  69. #define TSIP_RESPONSE_IS_TO_INVITE(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_INVITE))
  70. #define TSIP_RESPONSE_IS_TO_OPTIONS(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_OPTIONS))
  71. #define TSIP_RESPONSE_IS_TO_REGISTER(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_REGISTER))
  72. #define TSIP_RESPONSE_IS_TO_SUBSCRIBE(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_SUBSCRIBE))
  73. #define TSIP_RESPONSE_IS_TO_NOTIFY(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_NOTIFY))
  74. #define TSIP_RESPONSE_IS_TO_REFER(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_REFER))
  75. #define TSIP_RESPONSE_IS_TO_INFO(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_INFO))
  76. #define TSIP_RESPONSE_IS_TO_UPDATE(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_UPDATE))
  77. #define TSIP_RESPONSE_IS_TO_MESSAGE(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_MESSAGE))
  78. #define TSIP_RESPONSE_IS_TO_PUBLISH(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_PUBLISH))
  79. #define TSIP_RESPONSE_IS_TO_PRACK(self) ((self) && TSIP_MESSAGE_IS_RESPONSE((self)) && (self)->CSeq &&((self)->CSeq->type==tsip_PRACK))
  80. #define TSIP_RESPONSE_IS(self, code) (TSIP_RESPONSE_CODE((self)) == code)
  81. #define TSIP_RESPONSE_IS_NXX(self, N) (TSIP_MESSAGE_IS_RESPONSE((self)) && N##00<= TSIP_RESPONSE_CODE((self)) && TSIP_RESPONSE_CODE((self)) <= N##99)
  82. #define TSIP_RESPONSE_IS_1XX(self) TSIP_RESPONSE_IS_NXX(self, 1)
  83. #define TSIP_RESPONSE_IS_2XX(self) TSIP_RESPONSE_IS_NXX(self, 2)
  84. #define TSIP_RESPONSE_IS_3XX(self) TSIP_RESPONSE_IS_NXX(self, 3)
  85. #define TSIP_RESPONSE_IS_4XX(self) TSIP_RESPONSE_IS_NXX(self, 4)
  86. #define TSIP_RESPONSE_IS_5XX(self) TSIP_RESPONSE_IS_NXX(self, 5)
  87. #define TSIP_RESPONSE_IS_6XX(self) TSIP_RESPONSE_IS_NXX(self, 6)
  88. #define TSIP_RESPONSE_IS_23456(self) (TSIP_MESSAGE_IS_RESPONSE((self)) && 200<= TSIP_RESPONSE_CODE((self)) && TSIP_RESPONSE_CODE((self)) <= 699)
  89. #define TSIP_RESPONSE_IS_3456(self) (TSIP_MESSAGE_IS_RESPONSE((self)) && 300<= TSIP_RESPONSE_CODE((self)) && TSIP_RESPONSE_CODE((self)) <= 699)
  90. /** Defines the message type (Request or Response).
  91. **/
  92. typedef enum tsip_message_type_e {
  93. tsip_unknown,
  94. tsip_request,
  95. tsip_response
  96. }
  97. tsip_message_type_t;
  98. // SWIG
  99. typedef enum tsip_request_type_e {
  100. tsip_NONE = 0,
  101. tsip_ACK,
  102. tsip_BYE,
  103. tsip_CANCEL,
  104. tsip_INVITE,
  105. tsip_OPTIONS,
  106. tsip_REGISTER,
  107. tsip_SUBSCRIBE,
  108. tsip_NOTIFY,
  109. tsip_REFER,
  110. tsip_INFO,
  111. tsip_UPDATE,
  112. tsip_MESSAGE,
  113. tsip_PUBLISH,
  114. tsip_PRACK
  115. }
  116. tsip_request_type_t;
  117. TSIP_END_DECLS
  118. #endif /* TSIP_MESSAGE_COMMON_H */