Ejemplo n.º 1
0
/* sends a keep alive to a server  */
int send_stun_keep_alive(const int udpSocket,struct sockaddr_in *stunServ)
{

  send_stun_request(udpSocket,stunServ);

  return 0;
}
Ejemplo n.º 2
0
void t_phone_user::subscribe_mwi(void) {
	mwi_auto_resubscribe = true;
	
	if (mwi_dialog) {
		// This situation may occur, when an unsubscription is still
		// in progress. The subscibe will be retried after the unsubscription
		// is finished. Note that mwi_auto_resubscribe has been set to true
		// to trigger an automatic subscription.
		log_file->write_header("t_phone_user::subscribe_mwi", LOG_NORMAL, LOG_DEBUG);
		log_file->write_raw("MWI dialog already exists.\n");
		log_file->write_raw("Subscription state: ");
		log_file->write_raw(t_subscription_state2str(mwi_dialog->get_subscription_state()));
		log_file->write_endl();
		log_file->write_footer();

		return;
	}
	
	// If STUN is enabled, then do a STUN query before registering to
	// determine the public IP address.
	if (use_stun) {
		if (stun_public_ip_sip == 0)
		{
			send_stun_request();
			mwi_subscribe_after_stun = true;
			return;
		}
		stun_binding_inuse_mwi = true;
	}
	
	mwi_dialog = new t_mwi_dialog(this);
	MEMMAN_NEW(mwi_dialog);
	
	// RFC 3842 4.1
	// The example flow shows:
	// Request-URI = mail_user@mailbox_server
	// To = user@domain
	mwi_dialog->subscribe(DUR_MWI(user_config), user_config->get_mwi_uri(),
		user_config->create_user_uri(false), user_config->get_display(false));
		
	// Start sending NAT keepalive packets when STUN is used
	// (or in case of symmetric firewall)
	if (use_nat_keepalive && id_nat_keepalive == 0) {
		// Just start the NAT keepalive timer. The SUBSCRIBE
		// message will create the NAT binding. So there is
		// no need to send a NAT keep alive packet now.
		phone->start_timer(PTMR_NAT_KEEPALIVE, this);
	}
		
	cleanup_mwi_dialog();
}
Ejemplo n.º 3
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;
}