tags.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * $Id$
  3. *
  4. * - utility for generating to-tags
  5. * in SER, to-tags consist of two parts: a fixed part
  6. * which is bound to server instance and variable part
  7. * which is bound to request -- that helps to recognize,
  8. * who generated the to-tag in loops through the same
  9. * server -- in such cases, fixed part is constant, but
  10. * the variable part varies because it depends on
  11. * via
  12. *
  13. * Copyright (C) 2001-2003 Fhg Fokus
  14. *
  15. * This file is part of ser, a free SIP server.
  16. *
  17. * ser is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version
  21. *
  22. * For a license to use the ser software under conditions
  23. * other than those described here, or to purchase support for this
  24. * software, please contact iptel.org by e-mail at the following addresses:
  25. * [email protected]
  26. *
  27. * ser is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public License
  33. * along with this program; if not, write to the Free Software
  34. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  35. */
  36. #ifndef _TAGS_H
  37. #define _TAGS_H
  38. #include "parser/msg_parser.h"
  39. #include "crc.h"
  40. #include "str.h"
  41. #define TOTAG_LEN (MD5_LEN+CRC16_LEN+1)
  42. /* generate variable part of to-tag for a request;
  43. * it will have length of CRC16_LEN, sufficiently
  44. * long buffer must be passed to the fucntion */
  45. static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
  46. {
  47. int ss_nr;
  48. str suffix_source[3];
  49. ss_nr=2;
  50. suffix_source[0]=msg->via1->host;
  51. suffix_source[1]=msg->via1->port_str;
  52. if (msg->via1->branch)
  53. suffix_source[ss_nr++]=msg->via1->branch->value;
  54. crcitt_string_array( tag_suffix, suffix_source, ss_nr );
  55. }
  56. static void inline init_tags( char *tag, char **suffix,
  57. char *signature, char separator )
  58. {
  59. str src[3];
  60. src[0].s=signature; src[0].len=strlen(signature);
  61. src[1].s=sock_info[0].address_str.s;
  62. src[1].len=sock_info[0].address_str.len;
  63. src[2].s=sock_info[0].port_no_str.s;
  64. src[2].len=sock_info[0].port_no_str.len;
  65. MDStringArray( tag, src, 3 );
  66. tag[MD5_LEN]=separator;
  67. *suffix=tag+MD5_LEN+1;
  68. }
  69. #endif