rem: dlg_t* dialog;
context: static int update_presentity(struct sip_msg* _m, struct pdomain* _d, 			     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;	dlg_id_t dlg_id;		if (_m->event) {		event = (event_t*)(_m->event->parsed);		et = event->parsed;	} else {		LOG(L_ERR, "update_presentity defaulting to EVENT_PRESENCE\n");		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 (get_watch_uri(_m, &watch_uri, &watch_dn) < 0) {		LOG(L_ERR, "update_presentity(): Error while extracting watcher URI\n");		return -1;	}	get_dlg_id(_m, &dlg_id);		if (find_watcher_dlg(_p, &dlg_id, et, _w) == 0) { /* FIXME: experimental */	/* if (find_watcher(_p, &watch_uri, et, _w) == 0) { */		LOG(L_ERR, "update_presentity() found watcher\n");		if (e == 0) {			/* FIXME: experimental *//*						if (et != EVENT_PRESENCE_WINFO) {				if (remove_watcher(_p, *_w) < 0) {					LOG(L_ERR, "update_presentity(): Error while deleting winfo watcher\n");					return -2;				} 			} else {				if (remove_winfo_watcher(_p, *_w) < 0) {					LOG(L_ERR, "update_presentity(): Error while deleting winfo watcher\n");					return -2;				} 			}*/						(*_w)->expires = 0;   /* The watcher will be freed after NOTIFY is sent */			/* FIXME: experimental *//*			if (!_p->watchers && !_p->winfo_watchers) {				remove_presentity(_d, _p); 			}*/		} else {			e += act_time;			if (update_watcher(*_w, e) < 0) {				LOG(L_ERR, "update_presentity(): Error while updating watcher\n");				return -3;			}		}	} else {		if (e) {			e += act_time;			if (tmb.new_dlg_uas(_m, 200, &dialog) < 0) {				paerrno = PA_DIALOG_ERR;				LOG(L_ERR, "update_presentity(): Error while creating dialog state\n");				return -4;			}						if (extract_server_contact(_m, &server_contact) != 0) {				paerrno = PA_DIALOG_ERR;				LOG(L_ERR, "create_presentity(): Error while extracting server contact\n");				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, "update_presentity(): Error while creating presentity\n");					tmb.free_dlg(dialog);					if (server_contact.s) shm_free(server_contact.s);					return -5;				}			} else {				if (add_winfo_watcher(_p, &watch_uri, e, et, acc, dialog, &watch_dn, &server_contact, _w) < 0) {					LOG(L_ERR, "update_presentity(): Error while creating winfo watcher\n");					tmb.free_dlg(dialog);					if (server_contact.s) shm_free(server_contact.s);					return -5;				}						}						if (server_contact.s) shm_free(server_contact.s);					} else {			DBG("update_presentity(): expires = 0 but no watcher found\n");			*_w = 0;		}	}	return 0;}