3 * Copyright (C) 2001-2003 FhG Fokus
5 * This file is part of Kamailio, a free SIP server.
7 * Kamailio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version
12 * Kamailio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * \brief Kamailio core :: Name/alias handling
43 struct host_alias* next;
47 extern struct host_alias* aliases;
51 /** returns 1 if name is in the alias list; if port=0, port no is ignored
52 * if proto=0, proto is ignored*/
53 static inline int grep_aliases(char* name, int len, unsigned short port,
58 if ((len>2)&&((*name)=='[')&&(name[len-1]==']')){
59 /* ipv6 reference, skip [] */
63 for(a=aliases;a;a=a->next)
64 if ((a->alias.len==len) && ((a->port==0) || (port==0) ||
65 (a->port==port)) && ((a->proto==0) || (proto==0) ||
66 (a->proto==proto)) && (strncasecmp(a->alias.s, name, len)==0))
73 /** adds an alias to the list (only if it isn't already there)
74 * if port==0, the alias will match all the ports
75 * if proto==0, the alias will match all the protocols
76 * returns 1 if a new alias was added, 0 if a matching alias was already on
77 * the list and -1 on error */
78 static inline int add_alias(char* name, int len, unsigned short port,
83 if ((port) && (proto)){
84 /* don't add if there is already an alias matching it */
85 if (grep_aliases(name,len, port, proto)) return 0;
87 /* don't add if already in the list with port or proto ==0*/
88 for(a=aliases;a;a=a->next)
89 if ((a->alias.len==len) && (a->port==port) && (a->proto==proto) &&
90 (strncasecmp(a->alias.s, name, len)==0))
93 a=(struct host_alias*)pkg_malloc(sizeof(struct host_alias));
95 a->alias.s=(char*)pkg_malloc(len+1);
96 if (a->alias.s==0) goto error;
98 memcpy(a->alias.s, name, len);
99 a->alias.s[len]=0; /* null terminate for easier printing*/