|
@@ -29,6 +29,7 @@
|
|
|
* 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)
|
|
|
*/
|
|
|
|
|
|
|
|
@@ -42,6 +43,7 @@
|
|
|
struct host_alias{
|
|
|
str alias;
|
|
|
unsigned short port;
|
|
|
+ unsigned short proto;
|
|
|
struct host_alias* next;
|
|
|
};
|
|
|
|
|
@@ -50,19 +52,17 @@ extern struct host_alias* aliases;
|
|
|
|
|
|
|
|
|
|
|
|
-/* returns 1 if name is in the alias list; if port=0, port no is ignored*/
|
|
|
-static inline int grep_aliases(char* name, int len, unsigned short port)
|
|
|
+/* 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;
|
|
|
|
|
|
for(a=aliases;a;a=a->next)
|
|
|
-#ifdef USE_TLS
|
|
|
if ((a->alias.len==len) && ((a->port==0) || (port==0) ||
|
|
|
- (port==tls_port_no) ||
|
|
|
-#else
|
|
|
- if ((a->alias.len==len) && ((a->port==0) || (port==0) ||
|
|
|
-#endif
|
|
|
- (a->port==port)) && (strncasecmp(a->alias.s, name, len)==0))
|
|
|
+ (a->port==port)) && ((a->proto==0) || (proto==0) ||
|
|
|
+ (a->proto==proto)) && (strncasecmp(a->alias.s, name, len)==0))
|
|
|
return 1;
|
|
|
return 0;
|
|
|
}
|
|
@@ -71,14 +71,24 @@ static inline int grep_aliases(char* name, int len, unsigned short port)
|
|
|
|
|
|
/* adds an alias to the list (only if it isn't already there)
|
|
|
* if port==0, the alias will match all the ports
|
|
|
- * returns 1 if a new alias was added, 0 if the alias was already on the list
|
|
|
- * and -1 on error */
|
|
|
-static inline int add_alias(char* name, int len, unsigned short port)
|
|
|
+ * if proto==0, the alias will match all the protocols
|
|
|
+ * returns 1 if a new alias was added, 0 if a matching alias was already on
|
|
|
+ * the list and -1 on error */
|
|
|
+static inline int add_alias(char* name, int len, unsigned short port,
|
|
|
+ unsigned short proto)
|
|
|
{
|
|
|
struct host_alias* a;
|
|
|
|
|
|
- if ((port) && grep_aliases(name,len, port)) return 0;
|
|
|
- a=0;
|
|
|
+ if ((port) && (proto)){
|
|
|
+ /* don't add if there is already an alias matching it */
|
|
|
+ if (grep_aliases(name,len, port, proto)) return 0;
|
|
|
+ }else{
|
|
|
+ /* don't add if already in the list with port or proto ==0*/
|
|
|
+ for(a=aliases;a;a=a->next)
|
|
|
+ if ((a->alias.len==len) && (a->port==port) && (a->proto==proto) &&
|
|
|
+ (strncasecmp(a->alias.s, name, len)==0))
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
a=(struct host_alias*)pkg_malloc(sizeof(struct host_alias));
|
|
|
if(a==0) goto error;
|
|
|
a->alias.s=(char*)pkg_malloc(len+1);
|
|
@@ -87,6 +97,7 @@ static inline int add_alias(char* name, int len, unsigned short port)
|
|
|
memcpy(a->alias.s, name, len);
|
|
|
a->alias.s[len]=0; /* null terminate for easier printing*/
|
|
|
a->port=port;
|
|
|
+ a->proto=proto;
|
|
|
a->next=aliases;
|
|
|
aliases=a;
|
|
|
return 1;
|