00001 /* 00002 * $Id: tags.h 4993 2008-09-25 12:12:28Z henningw $ 00003 * 00004 * Copyright (C) 2001-2003 FhG Fokus 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * History: 00023 * -------- 00024 * 2003-02-18 changed TOTAG_LEN into TOTAG_VALUE_LEN, to solve 00025 * redefinition conflict with tm/t_msgbuilder.h (andrei) 00026 */ 00027 00028 /*! 00029 * \file 00030 * \brief Tag handling functions 00031 * To-tags consist of two parts: a fixed part which is bound to 00032 * a server instance and variable part which is bound to a request. 00033 * That helps to recognize, who generated the to-tag in loops through 00034 * the same server, in such cases, the fixed part is constant, but 00035 * the variable part varies because it depends on the via header. 00036 */ 00037 00038 00039 #ifndef _TAGS_H 00040 #define _TAGS_H 00041 00042 #include "parser/msg_parser.h" 00043 #include "globals.h" 00044 #include "crc.h" 00045 #include "str.h" 00046 #include "socket_info.h" 00047 00048 /*! length of a To-tag, MD5 + CRC 16 + separator */ 00049 #define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1) 00050 00051 00052 /*! 00053 * \brief Generate variable part of To-tag for a request 00054 * 00055 * Generate variable part of to-tag for a request, it will 00056 * have the length of CRC16_LEN. A sufficiently long buffer must 00057 * be passed to the function. This function avaluates the first 00058 * VIA branch parameter for calculating the CRC array. 00059 * \param msg SIP message 00060 * \param tag_suffix suffix of the tag 00061 */ 00062 static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix) 00063 { 00064 int ss_nr; 00065 str suffix_source[3]; 00066 00067 ss_nr=2; 00068 if (msg->via1==0) return; /* no via, bad message */ 00069 suffix_source[0]=msg->via1->host; 00070 suffix_source[1]=msg->via1->port_str; 00071 if (msg->via1->branch) 00072 suffix_source[ss_nr++]=msg->via1->branch->value; 00073 crcitt_string_array( tag_suffix, suffix_source, ss_nr ); 00074 } 00075 00076 00077 /*! 00078 * \brief Initialize To-tag value 00079 * 00080 * Initialize To-tags, the tag will be generated from the MD5 00081 * hash of the signature, server address and port number. 00082 * \param tag initialized tag 00083 * \param suffix pointer to the suffix part 00084 * \param signature some unique string for initialisation 00085 * \param separator separator between prefix and suffix 00086 */ 00087 inline static void init_tags( char *tag, char **suffix, 00088 char *signature, char separator ) 00089 { 00090 str src[3]; 00091 struct socket_info* si; 00092 00093 si=get_first_socket(); 00094 src[0].s=signature; src[0].len=strlen(signature); 00095 /* if we are not listening on anything we shouldn't be here */ 00096 src[1].s=si?si->address_str.s:""; 00097 src[1].len=si?si->address_str.len:0; 00098 src[2].s=si?si->port_no_str.s:""; 00099 src[2].len=si?si->port_no_str.len:0; 00100 00101 MD5StringArray( tag, src, 3 ); 00102 00103 tag[MD5_LEN]=separator; 00104 *suffix=tag+MD5_LEN+1; 00105 } 00106 00107 00108 #endif
1.5.6