Example #1
0
void t_phone_user::options(const t_url &to_uri, const string &to_display) {
	// RFC 3261 11.1
	// Construct OPTIONS request

	t_request *req = create_request(OPTIONS, to_uri);

	// To
	req->hdr_to.set_uri(to_uri);
	req->hdr_to.set_display(to_display);

	// Call-ID
	req->hdr_call_id.set_call_id(NEW_CALL_ID(user_config));

	// CSeq
	req->hdr_cseq.set_method(OPTIONS);
	req->hdr_cseq.set_seqnr(NEW_SEQNR);

	// Accept
	req->hdr_accept.add_media(t_media("application","sdp"));

	// Store and send request
	// Delete a possible pending options request
	if (r_options) {
		MEMMAN_DELETE(r_options);
		delete r_options;
	}
	r_options = new t_client_request(user_config, req, 0);
	MEMMAN_NEW(r_options);
	phone->send_request(user_config, req, r_options->get_tuid());
	MEMMAN_DELETE(req);
	delete req;
}
Example #2
0
bool t_phone_user::send_im_iscomposing(const t_url &to_uri, const string &to_display, 
			const string &state, time_t refresh)
{
	t_request *req = create_request(MESSAGE, to_uri);
	
	// To
	req->hdr_to.set_uri(to_uri);
	req->hdr_to.set_display(to_display);

	// Call-ID
	req->hdr_call_id.set_call_id(NEW_CALL_ID(user_config));

	// CSeq
	req->hdr_cseq.set_method(MESSAGE);
	req->hdr_cseq.set_seqnr(NEW_SEQNR);
	
	// Body and Content-Type
	t_im_iscomposing_xml_body *body = new t_im_iscomposing_xml_body;
	MEMMAN_NEW(body);
	
	body->set_state(state);
	body->set_refresh(refresh);
	
	req->body = body;
	req->hdr_content_type.set_media(body->get_media());
	
	// Store and send request
	// Delete a possible pending options request
	if (r_message) {
		// RFC 3428 8
		// Send only 1 message at a time.
		// Store the message. It will be sent if the previous
		// message transaction is finished.
		pending_messages.push_back(req);
	} else {
		r_message = new t_client_request(user_config, req, 0);
		MEMMAN_NEW(r_message);
		phone->send_request(user_config, req, r_message->get_tuid());
		MEMMAN_DELETE(req);
		delete req;
	}
	
	return true;
}
void t_subscription_dialog::subscribe(unsigned long expires, const t_url &req_uri,
		const t_url &to_uri, const string &to_display) 
{
	t_user *user_config = phone_user->get_user_profile();
	
	assert (get_subscription_state() == SS_NULL);
	call_id = NEW_CALL_ID(user_config);
	call_id_owner = true;
	local_tag = NEW_TAG;
	local_display = user_config->get_display(false);
	local_uri = user_config->create_user_uri(false);
	local_seqnr = rand() % 1000 + 1;
	remote_uri = to_uri;
	remote_display = to_display;
	remote_tag.clear();
	remote_target_uri = req_uri;
	route_set = phone_user->get_service_route();
	
	subscription->subscribe(expires);
}
Example #4
0
void t_phone_user::registration(t_register_type register_type, bool re_register,
		unsigned long expires)
{
	// If STUN is enabled, then do a STUN query before registering to
	// determine the public IP address.
	if (register_type == REG_REGISTER && use_stun) {
		if (stun_public_ip_sip == 0) {
			send_stun_request();
			register_after_stun = true;
			registration_time = expires;
			return;
		}
		
		stun_binding_inuse_registration = true;
	}

	// Stop registration timer for non-query request
	if (register_type != REG_QUERY) {
		phone->stop_timer(PTMR_REGISTRATION, this);
	}

	// Create call-id if no call-id is created yet
	if (register_call_id == "") {
		register_call_id = NEW_CALL_ID(user_config);
	}

	// RFC 3261 10.2
	// Construct REGISTER request

	t_request *req = create_request(REGISTER, 
			t_url(string(USER_SCHEME) + ":" + user_config->get_domain()));

	// To
	req->hdr_to.set_uri(user_config->create_user_uri(false));
	req->hdr_to.set_display(user_config->get_display(false));

	//Call-ID
	req->hdr_call_id.set_call_id(register_call_id);

	// CSeq
	req->hdr_cseq.set_method(REGISTER);
	req->hdr_cseq.set_seqnr(++register_seqnr);

	// Contact
        t_contact_param contact;

        switch (register_type) {
        case REG_REGISTER:
        	// URI
                contact.uri.set_url(user_config->create_user_contact(false,
                		h_ip2str(req->get_local_ip())));
                
                // Expires
                if (expires > 0) {
			if (user_config->get_registration_time_in_contact()) {
				contact.set_expires(expires);
			} else {
				req->hdr_expires.set_time(expires);
			}
		}
		
		// q-value
		if (user_config->get_reg_add_qvalue()) {
			contact.set_qvalue(user_config->get_reg_qvalue());
		}

                req->hdr_contact.add_contact(contact);
                break;
        case REG_DEREGISTER:
                contact.uri.set_url(user_config->create_user_contact(false,
                		h_ip2str(req->get_local_ip())));
 		if (user_config->get_registration_time_in_contact()) {
			contact.set_expires(0);
		} else {
			req->hdr_expires.set_time(0);
		}
                req->hdr_contact.add_contact(contact);
                break;
        case REG_DEREGISTER_ALL:
                req->hdr_contact.set_any();
                req->hdr_expires.set_time(0);
                break;
        default:
                break;
        }

	// Allow
	SET_HDR_ALLOW(req->hdr_allow, user_config);

	// Store request in the proper place
	t_tuid tuid;

        switch(register_type) {
        case REG_REGISTER:
		// Delete a possible pending registration request
		if (r_register) {
			MEMMAN_DELETE(r_register);
			delete r_register;
		}
                r_register = new t_client_request(user_config, req, 0);
		MEMMAN_NEW(r_register);
                tuid = r_register->get_tuid();

                // Store expiration time for re-registration.
                registration_time = expires;
                break;
        case REG_QUERY:
		// Delete a possible pending query registration request
		if (r_query_register) {
			MEMMAN_DELETE(r_query_register);
			delete r_query_register;
		}
                r_query_register = new t_client_request(user_config, req, 0);
		MEMMAN_NEW(r_query_register);
                tuid = r_query_register->get_tuid();
                break;
        case REG_DEREGISTER:
        case REG_DEREGISTER_ALL:
		// Delete a possible pending de-registration request
		if (r_deregister) {
			MEMMAN_DELETE(r_deregister);
			delete r_deregister;
		}
                r_deregister = new t_client_request(user_config, req, 0);
		MEMMAN_NEW(r_deregister);
                tuid = r_deregister->get_tuid();
                break;
        default:
                assert(false);
        }

        // Send REGISTER
        authorizor.set_re_register(re_register);
	ui->cb_register_inprog(user_config, register_type);
        phone->send_request(user_config, req, tuid);
	MEMMAN_DELETE(req);
        delete req;
}
Example #5
0
bool t_phone_user::send_message(const t_url &to_uri, const string &to_display, 
		const t_msg &msg)
{
	t_request *req = create_request(MESSAGE, to_uri);
	
	// To
	req->hdr_to.set_uri(to_uri);
	req->hdr_to.set_display(to_display);

	// Call-ID
	req->hdr_call_id.set_call_id(NEW_CALL_ID(user_config));

	// CSeq
	req->hdr_cseq.set_method(MESSAGE);
	req->hdr_cseq.set_seqnr(NEW_SEQNR);
	
	// Subject
	if (!msg.subject.empty()) {
		req->hdr_subject.set_subject(msg.subject);
	}
	
	// Body and Content-Type
	if (!msg.has_attachment) {
		// A message without an attachment is a text message.
		req->set_body_plain_text(msg.message, MSG_TEXT_CHARSET);
	} else {
		// Send message with file attachment
		if (!req->set_body_from_file(msg.attachment_filename, msg.attachment_media)) {
			log_file->write_header("t_phone_user::send_message", LOG_NORMAL, LOG_WARNING);
			log_file->write_raw("Could not read file ");
			log_file->write_raw(msg.attachment_filename);
			log_file->write_endl();
			log_file->write_footer();
			
			MEMMAN_DELETE(req);
			delete req;
			
			return false;
		}
		
		// Content-Disposition
		req->hdr_content_disp.set_type(DISPOSITION_ATTACHMENT);
		req->hdr_content_disp.set_filename(msg.attachment_save_as_name);
	}
	
	// Store and send request
	// Delete a possible pending options request
	if (r_message) {
		// RFC 3428 8
		// Send only 1 message at a time.
		// Store the message. It will be sent if the previous
		// message transaction is finished.
		pending_messages.push_back(req);
	} else {
		r_message = new t_client_request(user_config, req, 0);
		MEMMAN_NEW(r_message);
		phone->send_request(user_config, req, r_message->get_tuid());
		MEMMAN_DELETE(req);
		delete req;
	}
	
	return true;
}