/*! \brief checks if the proto: host:port is one of the address we listen on * * if port==0, the port number is ignored * if proto==0 (PROTO_NONE) the protocol is ignored * returns 1 if true, 0 if false, -1 on error * WARNING: uses str2ip6 so it will overwrite any previous * unsaved result of this function (static buffer) */ int check_self(str* host, unsigned short port, unsigned short proto) { grep_aliases(host->s, host->len, port, proto); if (grep_sock_info(host, port, proto)) goto found; /* try to look into the aliases*/ if (grep_aliases(host->s, host->len, port, proto)==0){ LM_DBG("host != me\n"); return 1; } found: return 1; }
/* 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 */ int add_alias(char* name, int len, unsigned short port, unsigned short proto) { struct host_alias* a; 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); if (a->alias.s==0) goto error; a->alias.len=len; 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; error: LM_ERR("pkg memory allocation error\n"); if (a) pkg_free(a); return -1; }
/* checks if the proto: host:port is one of the address we listen on; * if port==0, the port number is ignored * if proto==0 (PROTO_NONE) the protocol is ignored * returns 1 if true, 0 if false, -1 on error * WARNING: uses str2ip6 so it will overwrite any previous * unsaved result of this function (static buffer) */ int check_self(str* host, unsigned short port, unsigned short proto) { if (grep_sock_info(host, port, proto)) goto found; /* try to look into the aliases*/ if (grep_aliases(host->s, host->len, port, proto)==0){ DBG("check_self: host != me\n"); return (_check_self_func_list==NULL)?0:run_check_self_func(host, port, proto); } found: return 1; }