tags.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /*
  37. * History:
  38. * --------
  39. * 2003-02-18 changed TOTAG_LEN into TOTAG_VALUE_LEN, to solve
  40. * redefinition conflict with tm/t_msgbuilder.h (andrei)
  41. */
  42. #ifndef _TAGS_H
  43. #define _TAGS_H
  44. #include "parser/msg_parser.h"
  45. #include "globals.h"
  46. #include "crc.h"
  47. #include "str.h"
  48. #include "socket_info.h"
  49. #define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1)
  50. /* generate variable part of to-tag for a request;
  51. * it will have length of CRC16_LEN, sufficiently
  52. * long buffer must be passed to the function */
  53. static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
  54. {
  55. int ss_nr;
  56. str suffix_source[3];
  57. ss_nr=2;
  58. if (msg->via1==0) return; /* no via, bad message */
  59. suffix_source[0]=msg->via1->host;
  60. suffix_source[1]=msg->via1->port_str;
  61. if (msg->via1->branch)
  62. suffix_source[ss_nr++]=msg->via1->branch->value;
  63. crcitt_string_array( tag_suffix, suffix_source, ss_nr );
  64. }
  65. static void inline init_tags( char *tag, char **suffix,
  66. char *signature, char separator )
  67. {
  68. str src[3];
  69. struct socket_info* si;
  70. si=get_first_socket();
  71. src[0].s=signature; src[0].len=strlen(signature);
  72. /* if we are not listening on anything we shouldn't be here */
  73. src[1].s=si?si->address_str.s:"";
  74. src[1].len=si?si->address_str.len:0;
  75. src[2].s=si?si->port_no_str.s:"";
  76. src[2].len=si?si->port_no_str.len:0;
  77. MD5StringArray( tag, src, 3 );
  78. tag[MD5_LEN]=separator;
  79. *suffix=tag+MD5_LEN+1;
  80. }
  81. #endif