/* * Check if domain is local */ static int is_local(struct sip_msg* msg, char* fp, char* s2) { str domain, tmp; if (get_str_fparam(&domain, msg, (fparam_t*)fp) != 0) { ERR("Unable to get domain to check\n"); return -1; } tmp.s = pkg_malloc(domain.len); if (!tmp.s) { ERR("No memory left\n"); return -1; } memcpy(tmp.s, domain.s, domain.len); tmp.len = domain.len; strlower(&tmp); if (!db_mode) { switch(db_get_did(0, &tmp)) { case 1: goto found; default: goto not_found; } } else { if (hash_lookup(0, *active_hash, &tmp) == 1) goto found; else goto not_found; } found: pkg_free(tmp.s); return 1; not_found: pkg_free(tmp.s); return -1; }
static int db_load_domain(domain_t** d, unsigned long flags, str* domain) { int ret; int_str name, val; domain_t* p; str name_s = STR_STATIC_INIT(AVP_DID); if (flags & AVP_TRACK_FROM) { p = &dom_buf[0]; } else { p = &dom_buf[1]; } free_old_domain(p); ret = db_get_did(&p->did, domain); if (ret != 1) return ret; if (load_domain_attrs) { if (db_load_domain_attrs(p) < 0) return -1; } /* Create an attribute containing did of the domain */ name.s = name_s; val.s = p->did; if (add_avp_list(&p->attrs, AVP_CLASS_DOMAIN | AVP_NAME_STR | AVP_VAL_STR, name, val) < 0) return -1; *d = p; return 0; }
/* Check if the domain name given in the parameter is one * of the locally configured domain names. * Returns 1 if yes and -1 otherwise */ int is_domain_local(str* domain) { str tmp; /* Make a temporary copy, domain name comparisons are always * case insensitive */ tmp.s = pkg_malloc(domain->len); if (!tmp.s) { ERR("No memory left\n"); return -1; } memcpy(tmp.s, domain->s, domain->len); tmp.len = domain->len; strlower(&tmp); if (!db_mode) { switch(db_get_did(0, &tmp)) { case 1: goto found; default: goto not_found; } } else { if (hash_lookup(0, *active_hash, &tmp) == 1) goto found; else goto not_found; } found: pkg_free(tmp.s); return 1; not_found: pkg_free(tmp.s); return -1; }