adds an alias to the list (only if it isn't already there) * if port==0, the alias will match all the ports * 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 */
| 40 | * returns 1 if a new alias was added, 0 if a matching alias was already on |
| 41 | * the list and -1 on error */ |
| 42 | int add_alias(char* name, int len, unsigned short port, unsigned short proto, int accept_subdomain) |
| 43 | { |
| 44 | struct host_alias* a; |
| 45 | |
| 46 | if ((port) && (proto)){ |
| 47 | /* don't add if there is already an alias matching it */ |
| 48 | if (grep_aliases(name,len, port, proto)) return 0; |
| 49 | }else{ |
| 50 | /* don't add if already in the list with port or proto ==0*/ |
| 51 | for(a=aliases;a;a=a->next) |
| 52 | if ((a->alias.len==len) && (a->port==port) && (a->proto==proto) && |
| 53 | (strncasecmp(a->alias.s, name, len)==0)) |
| 54 | return 0; |
| 55 | } |
| 56 | a=(struct host_alias*)pkg_malloc(sizeof(struct host_alias)); |
| 57 | if(a==0) goto error; |
| 58 | a->alias.s=(char*)pkg_malloc(len+1); |
| 59 | if (a->alias.s==0) goto error; |
| 60 | a->alias.len=len; |
| 61 | memcpy(a->alias.s, name, len); |
| 62 | a->alias.s[len]=0; /* null terminate for easier printing*/ |
| 63 | a->port=port; |
| 64 | a->proto=proto; |
| 65 | a->accept_subdomain=accept_subdomain; |
| 66 | a->next=aliases; |
| 67 | aliases=a; |
| 68 | return 1; |
| 69 | error: |
| 70 | LM_ERR("pkg memory allocation error\n"); |
| 71 | if (a) pkg_free(a); |
| 72 | return -1; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | int register_alias_fct( is_alias_fct *fct ) |
no test coverage detected