tags.h
bbcbaf0f
 /*
  * - utility for generating to-tags
6806e46a
  *   in Kamailio, to-tags consist of two parts: a fixed part
bbcbaf0f
  *   which is bound to server instance and variable part
  *   which is bound to request -- that helps to recognize,
  *   who generated the to-tag in loops through the same
  *   server -- in such cases, fixed part is constant, but
  *   the variable part varies because it depends on 
  *   via
  *   
53c7e0f1
  * Copyright (C) 2001-2003 FhG Fokus
bbcbaf0f
  *
6806e46a
  * This file is part of Kamailio, a free SIP server.
bbcbaf0f
  *
6806e46a
  * Kamailio is free software; you can redistribute it and/or modify
bbcbaf0f
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
6806e46a
  * Kamailio is distributed in the hope that it will be useful,
bbcbaf0f
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
bbcbaf0f
  */
 
 #ifndef _TAGS_H
 #define _TAGS_H
 
 #include "parser/msg_parser.h"
b520a133
 #include "globals.h"
bbcbaf0f
 #include "crc.h"
 #include "str.h"
9f4c52ce
 #include "socket_info.h"
bbcbaf0f
 
d531a5d5
 #define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1)
bbcbaf0f
 
6806e46a
 /*! generate variable part of to-tag for a request;
bbcbaf0f
  * it will have length of CRC16_LEN, sufficiently
53c7e0f1
  * long buffer must be passed to the function */
bbcbaf0f
 static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
 {
 	int ss_nr;
 	str suffix_source[3];
 
 	ss_nr=2;
fa128269
 	if (msg->via1==0) return; /* no via, bad message */
bbcbaf0f
 	suffix_source[0]=msg->via1->host;
 	suffix_source[1]=msg->via1->port_str;
 	if (msg->via1->branch)
 		suffix_source[ss_nr++]=msg->via1->branch->value;
         crcitt_string_array( tag_suffix, suffix_source, ss_nr );
 }
 
17045ca6
 static void inline init_tags( char *tag, char **suffix, 
bbcbaf0f
 		char *signature, char separator )
 {
 	str src[3];
9f4c52ce
 	struct socket_info* si;
 	
 	si=get_first_socket();
bbcbaf0f
 	src[0].s=signature; src[0].len=strlen(signature);
9f4c52ce
 	/* if we are not listening on anything we shouldn't be here */
 	src[1].s=si?si->address_str.s:"";
 	src[1].len=si?si->address_str.len:0;
 	src[2].s=si?si->port_no_str.s:"";
 	src[2].len=si?si->port_no_str.len:0;
bbcbaf0f
 
12a262d2
 	MD5StringArray( tag, src, 3 );
bbcbaf0f
 
 	tag[MD5_LEN]=separator;
 	*suffix=tag+MD5_LEN+1;
 }
 
 
 #endif