msg_translator.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. /*!
  22. * \file
  23. * \brief Kamailio core :: Message translations
  24. * \author jiri
  25. * \ingroup core
  26. * Module: \ref core
  27. */
  28. #ifndef _MSG_TRANSLATOR_H
  29. #define _MSG_TRANSLATOR_H
  30. #define MY_HF_SEP ": "
  31. #define MY_HF_SEP_LEN 2
  32. #define BRANCH_SEPARATOR '.'
  33. #define WARNING "Warning: 392 "
  34. #define WARNING_LEN (sizeof(WARNING)-1)
  35. #define WARNING_PHRASE " \"Noisy feedback tells: "
  36. #define WARNING_PHRASE_LEN (sizeof(WARNING_PHRASE)-1)
  37. /*#define MAX_CONTENT_LEN_BUF INT2STR_MAX_LEN *//* see ut.h/int2str() */
  38. #define BUILD_NO_LOCAL_VIA (1<<0)
  39. #define BUILD_NO_VIA1_UPDATE (1<<1)
  40. #define BUILD_NO_PATH (1<<2)
  41. #define BUILD_IN_SHM (1<<7)
  42. #include "parser/msg_parser.h"
  43. #include "ip_addr.h"
  44. /* point to some remarkable positions in a SIP message */
  45. struct bookmark {
  46. str to_tag_val;
  47. };
  48. /* used by via_builder */
  49. struct hostport {
  50. str* host;
  51. str* port;
  52. };
  53. #define set_hostport(hp, msg) \
  54. do{ \
  55. if ((msg) && ((struct sip_msg*)(msg))->set_global_address.len) \
  56. (hp)->host=&(((struct sip_msg*)(msg))->set_global_address); \
  57. else \
  58. (hp)->host=&default_global_address; \
  59. if ((msg) && ((struct sip_msg*)(msg))->set_global_port.len) \
  60. (hp)->port=&(((struct sip_msg*)(msg))->set_global_port); \
  61. else \
  62. (hp)->port=&default_global_port; \
  63. }while(0)
  64. char * build_req_buf_from_sip_req(struct sip_msg* msg,
  65. unsigned int *returned_len, struct dest_info* send_info,
  66. unsigned int mode);
  67. char * build_res_buf_from_sip_res(struct sip_msg* msg,
  68. unsigned int *returned_len);
  69. char * generate_res_buf_from_sip_res(struct sip_msg* msg,
  70. unsigned int *returned_len, unsigned int mode);
  71. char * build_res_buf_from_sip_req(unsigned int code,
  72. str *text,
  73. str *new_tag,
  74. struct sip_msg* msg,
  75. unsigned int *returned_len,
  76. struct bookmark *bmark);
  77. /*
  78. char * build_res_buf_with_body_from_sip_req( unsigned int code ,
  79. char *text ,
  80. char *new_tag ,
  81. unsigned int new_tag_len ,
  82. char *body ,
  83. unsigned int body_len,
  84. char *content_type,
  85. unsigned int content_type_len,
  86. struct sip_msg* msg,
  87. unsigned int *returned_len,
  88. struct bookmark *bmark);
  89. */
  90. char* via_builder( unsigned int *len,
  91. struct dest_info* send_info,
  92. str *branch, str* extra_params, struct hostport *hp );
  93. /* creates a via header honoring the protocol of the incomming socket
  94. * msg is an optional parameter */
  95. char* create_via_hf( unsigned int *len,
  96. struct sip_msg *msg,
  97. struct dest_info* send_info /* where to send the reply */,
  98. str* branch);
  99. int branch_builder( unsigned int hash_index,
  100. /* only either parameter useful */
  101. unsigned int label, char * char_v,
  102. int branch,
  103. /* output value: string and actual length */
  104. char *branch_str, int *len );
  105. char* id_builder(struct sip_msg* msg, unsigned int *id_len);
  106. /* check if IP address in Via != source IP address of signaling,
  107. * or the sender is asking to set the values for rport or received */
  108. int received_test( struct sip_msg *msg );
  109. /* check if IP address in Via != source IP address of signaling */
  110. int received_via_test( struct sip_msg *msg );
  111. /* builds a char* buffer from message headers without body
  112. * first line is excluded in case of skip_first_line=1
  113. */
  114. char * build_only_headers( struct sip_msg* msg, int skip_first_line,
  115. unsigned int *returned_len,
  116. int *error,
  117. struct dest_info* send_info);
  118. /* builds a char* buffer from message body
  119. * error is set -1 if the memory allocation failes
  120. */
  121. char * build_body( struct sip_msg* msg,
  122. unsigned int *returned_len,
  123. int *error,
  124. struct dest_info* send_info);
  125. /* builds a char* buffer from SIP message including body
  126. * The function adjusts the Content-Length HF according
  127. * to body lumps in case of adjust_clen=1.
  128. */
  129. char * build_all( struct sip_msg* msg, int adjust_clen,
  130. unsigned int *returned_len,
  131. int *error,
  132. struct dest_info* send_info);
  133. /** cfg framework fixup */
  134. void fix_global_req_flags(str* gname, str* name);
  135. int build_sip_msg_from_buf(struct sip_msg *msg, char *buf, int len,
  136. unsigned int id);
  137. /* returns a copy in private memory of the boundary in a multipart body */
  138. int get_boundary(struct sip_msg* msg, str* boundary);
  139. #endif