File: tags.h

package info (click to toggle)
openser 1.1.0-9etch1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,828 kB
  • ctags: 11,809
  • sloc: ansic: 120,528; sh: 5,249; yacc: 1,716; makefile: 1,261; php: 656; perl: 205; sql: 190
file content (88 lines) | stat: -rw-r--r-- 2,680 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * $Id: tags.h,v 1.1.1.1 2005/06/13 16:47:28 bogdan_iancu Exp $
 *
 * Copyright (C) 2001-2003 FhG Fokus
 *
 * This file is part of openser, a free SIP server.
 *
 * openser is free software; you can redistribute it and/or modify
 * 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
 *
 * openser is distributed in the hope that it will be useful,
 * 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 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * 
 * - utility for generating to-tags
 *   in SER, to-tags consist of two parts: a fixed part
 *   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
 *   
 * History:
 * --------
 *  2003-02-18  changed TOTAG_LEN into TOTAG_VALUE_LEN, to solve
 *               redefinition conflict with tm/t_msgbuilder.h (andrei)
 */


#ifndef _TAGS_H
#define _TAGS_H

#include "parser/msg_parser.h"
#include "globals.h"
#include "crc.h"
#include "str.h"
#include "socket_info.h"

#define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1)

/* generate variable part of to-tag for a request;
 * it will have length of CRC16_LEN, sufficiently
 * long buffer must be passed to the function */
static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
{
	int ss_nr;
	str suffix_source[3];

	ss_nr=2;
	if (msg->via1==0) return; /* no via, bad message */
	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 );
}

static void inline init_tags( char *tag, char **suffix, 
		char *signature, char separator )
{
	str src[3];
	struct socket_info* si;
	
	si=get_first_socket();
	src[0].s=signature; src[0].len=strlen(signature);
	/* 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;

	MDStringArray( tag, src, 3 );

	tag[MD5_LEN]=separator;
	*suffix=tag+MD5_LEN+1;
}


#endif