Beispiel #1
0
/**
 *	Decode a r_subscription from a binary data structure
 * @param x - binary data to decode from
 * @returns the r_subscription* where the data has been decoded
 */
r_subscription* bin_decode_r_subscription(bin_data *x)
{
	r_subscription *s=0;
	int len;
	str st;
	char c;
	
	len = sizeof(r_subscription);
	s = (r_subscription*) shm_malloc(len);
	if (!s) {
		LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_subscription: Error allocating %d bytes.\n",len);
		goto error;
	}
	memset(s,0,len);
	
	if (!bin_decode_str(x,&st)||!str_shm_dup(&(s->req_uri),&st)) goto error;
	if (!bin_decode_int(x,&s->duration)) goto error;
	if (!bin_decode_time_t(x,&s->expires)) goto error;	
	if (!bin_decode_char(x,&c)) goto error;
	s->attempts_left = c;
	
	if (!bin_decode_dlg_t(x,&(s->dialog))) goto error;
	
	s->hash = get_subscription_hash(s->req_uri);
	
	return s;
error:
	LOG(L_ERR,"ERR:"M_NAME":bin_decode_r_subscription: Error while decoding (at %d (%04x)).\n",x->max,x->max);
	if (s) {
		if (s->req_uri.s) shm_free(s->req_uri.s);
		if (s->dialog) tmb.free_dlg(s->dialog);		
		shm_free(s);
	}
	return 0;
}
Beispiel #2
0
/**
 * Adds a subscription to the list of subscriptions at the end (FIFO).
 * @param s - the subscription to be added
 */
void add_r_subscription(r_subscription *s)
{
	if (!s) return;
	s->hash = get_subscription_hash(s->req_uri);
	subs_lock(s->hash);
		s->next = 0;
		s->prev = subscriptions[s->hash].tail;
		if (subscriptions[s->hash].tail) subscriptions[s->hash].tail->next = s;			
		subscriptions[s->hash].tail = s;
		if (!subscriptions[s->hash].head) subscriptions[s->hash].head = s;		
	subs_unlock(s->hash);
}
Beispiel #3
0
/**
 * Returns a subscription if it exists
 * \note - this returns with a lock on the subscriptions[s->hash] if found. Don't forget to unlock when done!!!
 * @param aor - AOR to look for
 * @returns 1 if found, 0 if not
 */
r_subscription* get_r_subscription(str aor)
{
	r_subscription *s;
	unsigned int hash = get_subscription_hash(aor);
	subs_lock(hash);
		s = subscriptions[hash].head;
		while(s){
			if (s->req_uri.len == aor.len &&
				strncasecmp(s->req_uri.s,aor.s,aor.len)==0)
			{
				return s;
			}
			s = s->next;
		}
	subs_unlock(hash);	
	return 0;
}