msg_translator.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 * build_res_buf_from_sip_req(unsigned int code,
  77. str *text,
  78. str *new_tag,
  79. struct sip_msg* msg,
  80. unsigned int *returned_len,
  81. struct bookmark *bmark);
  82. /*
  83. char * build_res_buf_with_body_from_sip_req( unsigned int code ,
  84. char *text ,
  85. char *new_tag ,
  86. unsigned int new_tag_len ,
  87. char *body ,
  88. unsigned int body_len,
  89. char *content_type,
  90. unsigned int content_type_len,
  91. struct sip_msg* msg,
  92. unsigned int *returned_len,
  93. struct bookmark *bmark);
  94. */
  95. char* via_builder( unsigned int *len,
  96. struct dest_info* send_info,
  97. str *branch, str* extra_params, struct hostport *hp );
  98. /* creates a via header honoring the protocol of the incomming socket
  99. * msg is an optional parameter */
  100. char* create_via_hf( unsigned int *len,
  101. struct sip_msg *msg,
  102. struct dest_info* send_info /* where to send the reply */,
  103. str* branch);
  104. int branch_builder( unsigned int hash_index,
  105. /* only either parameter useful */
  106. unsigned int label, char * char_v,
  107. int branch,
  108. /* output value: string and actual length */
  109. char *branch_str, int *len );
  110. char* id_builder(struct sip_msg* msg, unsigned int *id_len);
  111. /* check if IP address in Via != source IP address of signaling */
  112. int received_test( struct sip_msg *msg );
  113. /* builds a char* buffer from message headers without body
  114. * first line is excluded in case of skip_first_line=1
  115. */
  116. char * build_only_headers( struct sip_msg* msg, int skip_first_line,
  117. unsigned int *returned_len,
  118. int *error,
  119. struct dest_info* send_info);
  120. /* builds a char* buffer from message body
  121. * error is set -1 if the memory allocation failes
  122. */
  123. char * build_body( struct sip_msg* msg,
  124. unsigned int *returned_len,
  125. int *error,
  126. struct dest_info* send_info);
  127. /* builds a char* buffer from SIP message including body
  128. * The function adjusts the Content-Length HF according
  129. * to body lumps in case of adjust_clen=1.
  130. */
  131. char * build_all( struct sip_msg* msg, int adjust_clen,
  132. unsigned int *returned_len,
  133. int *error,
  134. struct dest_info* send_info);
  135. /** cfg framework fixup */
  136. void fix_global_req_flags(str* gname, str* name);
  137. int build_sip_msg_from_buf(struct sip_msg *msg, char *buf, int len,
  138. unsigned int id);
  139. #endif