tags.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * - utility for generating to-tags
  3. * in Kamailio, to-tags consist of two parts: a fixed part
  4. * which is bound to server instance and variable part
  5. * which is bound to request -- that helps to recognize,
  6. * who generated the to-tag in loops through the same
  7. * server -- in such cases, fixed part is constant, but
  8. * the variable part varies because it depends on
  9. * via
  10. *
  11. * Copyright (C) 2001-2003 FhG Fokus
  12. *
  13. * This file is part of Kamailio, a free SIP server.
  14. *
  15. * Kamailio is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version
  19. *
  20. * Kamailio is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #ifndef _TAGS_H
  30. #define _TAGS_H
  31. #include "parser/msg_parser.h"
  32. #include "globals.h"
  33. #include "crc.h"
  34. #include "str.h"
  35. #include "socket_info.h"
  36. #define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1)
  37. /*! generate variable part of to-tag for a request;
  38. * it will have length of CRC16_LEN, sufficiently
  39. * long buffer must be passed to the function */
  40. static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
  41. {
  42. int ss_nr;
  43. str suffix_source[3];
  44. ss_nr=2;
  45. if (msg->via1==0) return; /* no via, bad message */
  46. suffix_source[0]=msg->via1->host;
  47. suffix_source[1]=msg->via1->port_str;
  48. if (msg->via1->branch)
  49. suffix_source[ss_nr++]=msg->via1->branch->value;
  50. crcitt_string_array( tag_suffix, suffix_source, ss_nr );
  51. }
  52. static void inline init_tags( char *tag, char **suffix,
  53. char *signature, char separator )
  54. {
  55. str src[3];
  56. struct socket_info* si;
  57. si=get_first_socket();
  58. src[0].s=signature; src[0].len=strlen(signature);
  59. /* if we are not listening on anything we shouldn't be here */
  60. src[1].s=si?si->address_str.s:"";
  61. src[1].len=si?si->address_str.len:0;
  62. src[2].s=si?si->port_no_str.s:"";
  63. src[2].len=si?si->port_no_str.len:0;
  64. MD5StringArray( tag, src, 3 );
  65. tag[MD5_LEN]=separator;
  66. *suffix=tag+MD5_LEN+1;
  67. }
  68. #endif