// Create a request within a dialog // RFC 3261 12.2.1.1 t_request *t_abstract_dialog::create_request(t_method m) { t_user *user_config = phone_user->get_user_profile(); t_request *r = new t_request(m); MEMMAN_NEW(r); // To header r->hdr_to.set_uri(remote_uri); r->hdr_to.set_display(remote_display); r->hdr_to.set_tag(remote_tag); // From header r->hdr_from.set_uri(local_uri); r->hdr_from.set_display(local_display); r->hdr_from.set_tag(local_tag); // Call-ID header r->hdr_call_id.set_call_id(call_id); // CSeq header r->hdr_cseq.set_method(m); r->hdr_cseq.set_seqnr(++local_seqnr); // Set Max-Forwards header r->hdr_max_forwards.set_max_forwards(MAX_FORWARDS); // User-Agent SET_HDR_USER_AGENT(r->hdr_user_agent); // RFC 3261 12.2.1.1 // Request URI and Route header r->set_route(remote_target_uri, route_set); // Caculate destination set. A DNS request can result in multiple // IP address. In failover scenario's the request must be sent to // the next IP address in the list. As the request will be copied // in various places, the destination set must be calculated now. // In previous version the DNS request was done by the transaction // manager. This is too late as the transaction manager gets a copy // of the request. The destination set should be set in the copy // kept by the dialog. r->calc_destinations(*user_config); // The Via header can only be created after the destinations // are calculated, because the destination deterimines which // local IP address should be used. // Via header unsigned long local_ip = r->get_local_ip(); t_via via(USER_HOST(user_config, h_ip2str(local_ip)), PUBLIC_SIP_PORT(user_config)); r->hdr_via.add_via(via); return r; }
t_request *t_phone_user::create_request(t_method m, const t_url &request_uri) const { t_request *req = new t_request(m); MEMMAN_NEW(req); // From req->hdr_from.set_uri(user_config->create_user_uri(false)); req->hdr_from.set_display(user_config->get_display(false)); req->hdr_from.set_tag(NEW_TAG); // Max-Forwards header (mandatory) req->hdr_max_forwards.set_max_forwards(MAX_FORWARDS); // User-Agent SET_HDR_USER_AGENT(req->hdr_user_agent); // Set request URI and calculate destinations. By calculating // destinations now, the request can be resend to a next destination // if failover is needed. if (m == REGISTER) { // For a REGISTER do not use the service route for routing. req->uri = request_uri; } else { // RFC 3608 // For all other requests, use the service route set for routing. req->set_route(request_uri, service_route); } req->calc_destinations(*user_config); // The Via header can only be created after the destinations // are calculated, because the destination deterimines which // local IP address should be used. // Via unsigned long local_ip = req->get_local_ip(); t_via via(USER_HOST(user_config, h_ip2str(local_ip)), PUBLIC_SIP_PORT(user_config)); req->hdr_via.add_via(via); return req; }