Пример #1
0
void ts_onreply(struct cell* t, int type, struct tmcb_params *param)
{
	ts_urecord_t* _r;
	ts_entry_t* _e;
	ts_transaction_t *cb_ptr, *ptr;

	if(t_table==0) return;
	if((type & (TMCB_DESTROY)) && destroy_modules_phase()) return;

	cb_ptr = (ts_transaction_t*)(*param->param);
	if (cb_ptr == NULL) {
		LM_DBG("NULL param for type %d\n", type);
		return;
	}

	if (type &(TMCB_DESTROY)) {
		LM_DBG("TMCB_DESTROY called for transaction %u:%u\n", cb_ptr->tindex, cb_ptr->tlabel);
		_r = cb_ptr->urecord;
		_e = _r->entry;
		lock_entry(_e);
		ptr = _r->transactions;
		while(ptr) {
			if ((ptr->tindex == cb_ptr->tindex) && (ptr->tlabel == cb_ptr->tlabel)) {
				remove_ts_transaction(ptr);

				if (_r->transactions == NULL) {
					LM_DBG("last transaction for %.*s, removing urecord\n", _r->ruri.len, _r->ruri.s);
					remove_ts_urecord(_r);
				}
				unlock_entry(_e);
				return;
			}
			ptr = ptr->next;
		}
		LM_DBG("transaction %u:%u not found\n",cb_ptr->tindex, cb_ptr->tlabel);
		unlock_entry(_e);
	} else {
		LM_DBG("called with uknown type %d\n", type);
	}

	return;
}
Пример #2
0
void ul_publish(ucontact_t* c, int type, void* param)
{
	str* body= NULL;
	str uri= {NULL, 0};
	char* at= NULL;
	publ_info_t* publ= NULL;
	int size= 0;
	str content_type;
	int error;

	if(destroy_modules_phase()) return;

	content_type.s= "application/pidf+xml";
	content_type.len= 20;

	if(pua_ul_publish==0 && pua_ul_bmask==0)
	{
		LM_INFO("should not send ul publish\n");
		return;
	}
	if(pua_ul_bmask!=0 && (c->cflags & pua_ul_bmask)==0)
	{
		LM_INFO("not marked for publish\n");
		return;
	}

	if(type & UL_CONTACT_DELETE) {
		LM_DBG("\nDELETE type\n");
	} else {
		if(type & UL_CONTACT_INSERT) {
			LM_DBG("\nINSERT type\n");
		} else {
			if(type & UL_CONTACT_UPDATE) {
				LM_DBG("\nUPDATE type\n");
			} else {
				if(type & UL_CONTACT_EXPIRE) {
					LM_DBG("\nEXPIRE type\n");
				}
			}
		}
	}

	if(type & UL_CONTACT_INSERT)
	{
		body= build_pidf(c);
		if(body == NULL || body->s == NULL)
			goto error;
	}
	else
		body = NULL;

	uri.s = (char*)pkg_malloc(sizeof(char)*(c->aor->len+default_domain.len+6));
	if(uri.s == NULL)
		goto error;

	memcpy(uri.s, "sip:", 4);
	uri.len = 4;
	memcpy(uri.s+ uri.len, c->aor->s, c->aor->len);
	uri.len+= c->aor->len;
	at = memchr(c->aor->s, '@', c->aor->len);
	if(!at)
	{
		uri.s[uri.len++]= '@';
		memcpy(uri.s+ uri.len, default_domain.s, default_domain.len);
		uri.len+= default_domain.len;
	}
	LM_DBG("uri= %.*s\n", uri.len, uri.s);

	size= sizeof(publ_info_t)+ sizeof(str)+( uri.len
			+c->callid.len+ 12 + content_type.len)*sizeof(char);

	if(body)
		size+= sizeof(str)+ body->len* sizeof(char);

	publ= (publ_info_t*)pkg_malloc(size);
	if(publ== NULL)
	{
		LM_ERR("no more share memory\n");
		goto error;
	}
	memset(publ, 0, size);
	size= sizeof(publ_info_t);

	publ->pres_uri= (str*)((char*)publ + size);
	size+= sizeof(str);
	publ->pres_uri->s= (char*)publ+ size;
	memcpy(publ->pres_uri->s, uri.s, uri.len);
	publ->pres_uri->len= uri.len;
	size+= uri.len;

	if(body)
	{
		publ->body= (str*)( (char*)publ + size);
		size+= sizeof(str);

		publ->body->s= (char*)publ + size;
		memcpy(publ->body->s, body->s, body->len);
		publ->body->len= body->len;
		size+= body->len;
	}
	publ->id.s= (char*)publ+ size;
	memcpy(publ->id.s, "UL_PUBLISH.", 11);
	memcpy(publ->id.s+11, c->callid.s, c->callid.len);
	publ->id.len= 11+ c->callid.len;
	size+= publ->id.len;

	publ->content_type.s= (char*)publ+ size;
	memcpy(publ->content_type.s, content_type.s, content_type.len);
	publ->content_type.len= content_type.len;
	size+= content_type.len;

	if(type & UL_CONTACT_EXPIRE || type & UL_CONTACT_DELETE)
		publ->expires= 0;
	else
		publ->expires= c->expires - (int)time(NULL);

	if(type & UL_CONTACT_INSERT)
		publ->flag|= INSERT_TYPE;
	else
		publ->flag|= UPDATE_TYPE;

	publ->source_flag|= UL_PUBLISH;
	publ->event|= PRESENCE_EVENT;
	publ->extra_headers= NULL;
	print_publ(publ);
	if((error=_pu_pua.send_publish(publ))< 0)
	{
		LM_ERR("failed sending publish for ul event %d\n", type);
		if((type & UL_CONTACT_UPDATE) && error == ERR_PUBLISH_NO_BODY) {
			/* This error can occur if Kamailio was restarted/stopped and for any reason couldn't store a pua
			 * entry in 'pua' DB table. It can also occur if 'pua' table is cleaned externally while Kamailio
			 * is stopped so cannot retrieve these entries from DB when restarting.
			 * In these cases, when a refresh registration for that user creates an UPDATE action in pua_usrloc,
			 * pua 'ul_publish()' would fail since the appropiate entry doesn't exist in pua hast table ("New
			 * PUBLISH and no body found - invalid request").
			 * This code solves this problem by invoking an INSERT action if an UPDATE action failed due to the
			 * above error. It will however generate a new presentity entry in the presence server (until the
			 * previous one expires), but this is a minor issue. */
			LM_ERR("UPDATE action generated a PUBLISH without body -> invoking INSERT action\n");
			ul_publish(c, UL_CONTACT_INSERT, param);
			goto error;
		}
	}

error:
	pua_ul_publish = 0;
	if(publ)
		pkg_free(publ);

	if(body) {
		if(body->s)
			xmlFree(body->s);
		pkg_free(body);
	}

	if(uri.s)
		pkg_free(uri.s);

	return;
}