forked from Vocalocity/opensips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
name_alias.h
95 lines (76 loc) · 2.51 KB
/
name_alias.h
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
89
90
91
92
93
/*
* $Id$
*
* Copyright (C) 2001-2003 FhG Fokus
* Copyright (C) 2009 Voice Sistem SRL
*
* This file is part of opensips, a free SIP server.
*
* opensips 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
*
* opensips 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
*
* History:
* --------
* 2003-03-19 replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
* 2003-10-21 support for proto added: proto:host:port (andrei)
* 2009-02-01 added interface to registed additional functions for checking
* the aliases (bogdan)
*/
#include <strings.h>
#include "str.h"
#include "dprint.h"
#include "mem/mem.h"
struct host_alias{
str alias;
unsigned short port;
unsigned short proto;
struct host_alias* next;
};
extern struct host_alias* aliases;
typedef int (is_alias_fct)(char* name, int len, unsigned short port,
unsigned short proto);
struct alias_function {
is_alias_fct *alias_f;
struct alias_function *next;
};
extern struct alias_function* alias_fcts;
/* returns 1 if name is in the alias list; if port=0, port no is ignored
* if proto=0, proto is ignored*/
static inline int grep_aliases(char* name, int len, unsigned short port,
unsigned short proto)
{
struct host_alias* a;
struct alias_function *af;
#ifdef USE_IPV6
if ((len>2)&&((*name)=='[')&&(name[len-1]==']')){
/* ipv6 reference, skip [] */
name++;
len-=2;
}
#endif
for(a=aliases;a;a=a->next)
if ((a->alias.len==len) && ((a->port==0) || (port==0) ||
(a->port==port)) && ((a->proto==0) || (proto==0) ||
(a->proto==proto)) && (strncasecmp(a->alias.s, name, len)==0))
return 1;
for( af=alias_fcts ; af ; af=af->next ) {
if ( af->alias_f(name,len,port,proto)>0 )
return 1;
}
return 0;
}
/* adds an alias to the list (only if it isn't already there) */
int add_alias(char* name, int len, unsigned short port, unsigned short proto);
/* register a new function for detecting aliases */
int register_alias_fct( is_alias_fct *fct );