msg_translator.h 5.0 KB

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