Exemple #1
0
/*
 * 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;
}
Exemple #2
0
/*
 * Find a presentity in domain
 */
int find_presentity(pdomain_t* _d, str* _uri, struct presentity** _p)
{
	int sl, i;
	struct presentity* p;
	
	if (!_d->first) {
	     pdomain_load_presentities(_d);
	}

	sl = hash_func(_d, _uri->s, _uri->len);
	
	p = _d->table[sl].first;
	
	for(i = 0; i < _d->table[sl].n; i++) {
		if ((p->uri.len == _uri->len) && !memcmp(p->uri.s, _uri->s, _uri->len)) {
			*_p = p;
			return 0;
		}
		
		p = p->next;
	}

	return 1;   /* Nothing found */
}