rem: if (tmb.new_dlg_uas(_m, 200, &dialog) < 0) { paerrno = PA_DIALOG_ERR; LOG(L_ERR, "create_presentity(): Error while creating dialog state\n");
add: res = create_watcher(_m, *_p, _w, et, e); if (res != 0) {  db_remove_presentity(*_p);
context: int create_presentity(struct sip_msg* _m, struct pdomain* _d, str* _puri, 			     struct presentity** _p, struct watcher** _w){	time_t e;	dlg_t* dialog;	str watch_uri;	str watch_dn;	str server_contact = {0, 0};	event_t *event = NULL;	int et = 0;	int acc = 0;	if (_m->event) {		event = (event_t*)(_m->event->parsed);		et = event->parsed;	} else {		et = EVENT_PRESENCE;	}	acc = get_preferred_event_mimetype(_m, et);	if (_m->expires) {		e = ((exp_body_t*)_m->expires->parsed)->val;	} else {		e = default_expires;	}		if (e == 0) {		*_p = 0;		*_w = 0;		DBG("create_presentity(): expires = 0\n");		return 0;	}	/* Convert to absolute time */	e += act_time;	if (get_watch_uri(_m, &watch_uri, &watch_dn) < 0) {		LOG(L_ERR, "create_presentity(): Error while extracting watcher URI\n");		return -1;	}	if (new_presentity(_d, _puri, _p) < 0) {		LOG(L_ERR, "create_presentity(): Error while creating presentity\n");		return -2;	}	if (tmb.new_dlg_uas(_m, 200, &dialog) < 0) {		paerrno = PA_DIALOG_ERR;		LOG(L_ERR, "create_presentity(): Error while creating dialog state\n");		free_presentity(*_p);		return -3;	}	if (extract_server_contact(_m, &server_contact) != 0) {		paerrno = PA_DIALOG_ERR;		LOG(L_ERR, "create_presentity(): Error while extracting server contact\n");		free_presentity(*_p);		return -3;	}		if (et != EVENT_PRESENCE_WINFO) {		if (add_watcher(*_p, &watch_uri, e, et, acc, dialog, &watch_dn, &server_contact, _w) < 0) {			LOG(L_ERR, "create_presentity(): Error while adding a watcher\n");			if (server_contact.s) shm_free(server_contact.s);			tmb.free_dlg(dialog);			free_presentity(*_p);			return -4;		}	} else if (et == EVENT_PRESENCE_WINFO) {		if (add_winfo_watcher(*_p, &watch_uri, e, et, acc, dialog, &watch_dn, &server_contact, _w) < 0) {			LOG(L_ERR, "create_presentity(): Error while adding a winfo watcher\n");			if (server_contact.s) shm_free(server_contact.s);			tmb.free_dlg(dialog);			free_presentity(*_p);			return -5;		}	}	if (server_contact.s) shm_free(server_contact.s);	add_presentity(_d, *_p);	/* FIXME: experimental *//*	_d->reg(&watch_uri, _puri, (void*)callback, *_p);	LOG(L_ERR, "registering callback to %.*s (%p),  %.*s, %p (%p)\n",			watch_uri.len, watch_uri.s, &watch_uri,			_puri->len, _puri->s, *_p, _p); */	return 0;}