/* * Function registers a new domain with presence agent * if the domain exists, pointer to existing structure * will be returned, otherwise a new domain will be * created */ int register_pdomain(const char* _n, pdomain_t** _d) { pdomain_t *pdomain; dlist_t* d; str s; s.s = (char*)_n; s.len = strlen(_n); if (find_dlist(&s, &d) == 0) { *_d = d->d; return 0; } if (new_dlist(&s, &d) < 0) { LOG(L_ERR, "register_pdomain(): Error while creating new domain\n"); return -1; } pdomain = d->d; lock_pdomain(pdomain); /* do not enable timer to delete presentities in it */ d->next = root; root = d; *_d = pdomain; /* Preload domain with data from database if we are gonna * to use database */ pdomain_load_presentities(pdomain); unlock_pdomain(pdomain); return 0; }
/*! * \brief Registers a new domain with usrloc * * Registers a new domain with usrloc. If the domain exists, * a pointer to existing structure will be returned, otherwise * a new domain will be created * \param _n domain name * \param _d new created domain * \return 0 on success, -1 on failure */ int register_udomain(const char* _n, udomain_t** _d) { dlist_t* d; str s; db1_con_t* con; s.s = (char*)_n; s.len = strlen(_n); if (find_dlist(&s, &d) == 0) { *_d = d->d; return 0; } if (new_dlist(&s, &d) < 0) { LM_ERR("failed to create new domain\n"); return -1; } /* Test tables from database if we are gonna * to use database */ if (db_mode != NO_DB) { con = ul_dbf.init(&db_url); if (!con) { LM_ERR("failed to open database connection\n"); goto err; } if(ul_version_table != 0 && db_check_table_version(&ul_dbf, con, &s, UL_TABLE_VERSION) < 0) { LM_ERR("error during table version check.\n"); goto err; } /* test if DB really exists */ if (testdb_udomain(con, d->d) < 0) { LM_ERR("testing domain '%.*s' failed\n", s.len, ZSW(s.s)); goto err; } ul_dbf.close(con); } d->next = root; root = d; *_d = d->d; return 0; err: if (con) ul_dbf.close(con); free_udomain(d->d); shm_free(d->name.s); shm_free(d); return -1; }
/*! * \brief Find a particular domain, small wrapper around find_dlist * \param _d domain name * \param _p pointer to domain if found * \return 1 if domain was found, 0 otherwise */ int find_domain(str* _d, udomain_t** _p) { dlist_t* d; if (find_dlist(_d, &d) == 0) { *_p = d->d; return 0; } return 1; }
/*! * \brief Registers a new domain with usrloc * * Find and return a usrloc domain (location table) * \param _n domain name * \param _d usrloc domain * \return 0 on success, -1 on failure */ int get_udomain(const char* _n, udomain_t** _d) { dlist_t* d; str s; s.s = (char*)_n; s.len = strlen(_n); if (find_dlist(&s, &d) == 0) { *_d = d->d; return 0; } *_d = NULL; return -1; }
int find_pdomain(const char* _n, pdomain_t** _d) { dlist_t* d; str s; s.s = (char*)_n; s.len = strlen(_n); if (find_dlist(&s, &d) == 0) { *_d = d->d; return 0; } return 1; }
/*! * \brief Registers a new domain with usrloc * * Registers a new domain with usrloc. If the domain exists, * a pointer to existing structure will be returned, otherwise * a new domain will be created * \param _n domain name * \param _d new created domain * \return 0 on success, -1 on failure */ int register_udomain(const char *name, udomain_t **domain) { struct domain_list_item *item; str name_str; ul_domain_db_t * d; name_str.s = (char *) name; name_str.len = strlen (name); item = find_dlist (&name_str); if (item == NULL) { if((d = ul_find_domain(name)) == NULL){ LM_ERR("domain %s not found.\n", name); return -1; } item = add_to_dlist (&name_str, d->dbt); } if (item == NULL) { return -1; } *domain = &item->domain; LM_DBG("found domain %.*s, type: %s\n", (*domain)->name->len, (*domain)->name->s, (((*domain)->dbt) == DB_TYPE_CLUSTER ? "cluster" : "single")); return 0; }
/*! * \brief Registers a new domain with usrloc * * Registers a new domain with usrloc. If the domain exists, * a pointer to existing structure will be returned, otherwise * a new domain will be created * \param _n domain name * \param _d new created domain * \return 0 on success, -1 on failure */ int register_udomain(const char* _n, udomain_t** _d) { dlist_t* d; str s; s.s = (char*)_n; s.len = strlen(_n); if (find_dlist(&s, &d) == 0) { *_d = d->d; return 0; } if (new_dlist(&s, &d) < 0) { LM_ERR("failed to create new domain\n"); return -1; } d->next = root; root = d; *_d = d->d; return 0; }
/* * Function registers a new domain with usrloc * if the domain exists, pointer to existing structure * will be returned, otherwise a new domain will be * created */ int register_udomain(const char* _n, udomain_t** _d) { dlist_t* d; str s; int ver; db_con_t* con; s.s = (char*)_n; s.len = strlen(_n); if (find_dlist(&s, &d) == 0) { *_d = d->d; return 0; } if (new_dlist(&s, &d) < 0) { LOG(L_ERR, "register_udomain(): Error while creating new domain\n"); return -1; } /* Preload domain with data from database if we are gonna * to use database */ if (db_mode != NO_DB) { con = ul_dbf.init(db_url.s); if (!con) { LOG(L_ERR, "register_udomain(): Can not open database connection\n"); goto err; } ver = table_version(&ul_dbf, con, &s); if (ver < 0) { LOG(L_ERR, "register_udomain(): Error while querying table version\n"); goto err; } else if (ver < TABLE_VERSION) { LOG(L_ERR, "register_udomain(): Invalid table version (use ser_mysql.sh reinstall)\n"); goto err; } if (preload_udomain(con, d->d) < 0) { LOG(L_ERR, "register_udomain(): Error while preloading domain '%.*s'\n", s.len, ZSW(s.s)); goto err; } ul_dbf.close(con); } d->next = root; root = d; *_d = d->d; return 0; err: if (con) ul_dbf.close(con); free_udomain(d->d); shm_free(d->name.s); shm_free(d); return -1; }