Beispiel #1
0
PJ_DECL(pj_status_t) csipsimple_init_acc_msg_data(pjsua_acc_id acc_id, pjsua_msg_data* msg_data){
	csipsimple_acc_config *additional_acc_cfg = NULL;

	// P-Asserted-Identity header
	pj_str_t hp_preferred_identity_name = { "P-Preferred-Identity", 20 };
	pjsip_generic_string_hdr hp_preferred_identity;

	// Sanity check
	PJ_ASSERT_RETURN(msg_data != NULL, PJ_EINVAL);


	// Get acc infos
	if(pjsua_acc_is_valid(acc_id)){
		additional_acc_cfg = (csipsimple_acc_config *) pjsua_acc_get_user_data(acc_id);
	}


	// Process additionnal config for this account
	if(additional_acc_cfg != NULL){

		if(additional_acc_cfg->p_preferred_identity.slen > 0){
			// Create new P-Asserted-Identity hdr if necessary
			pjsip_generic_string_hdr_init2(&hp_preferred_identity, &hp_preferred_identity_name, &additional_acc_cfg->p_preferred_identity);

			// Push it to msg data
			pj_list_push_back(&msg_data->hdr_list, &hp_preferred_identity);
		}
	}

	return PJ_SUCCESS;
}
Beispiel #2
0
/* Callback from timer when the maximum call duration has been
 * exceeded.
 */
static void call_timeout_callback(pj_timer_heap_t *timer_heap,
				  struct pj_timer_entry *entry)
{
    pjsua_call_id call_id = entry->id;
    pjsua_msg_data msg_data;
    pjsip_generic_string_hdr warn;
    pj_str_t hname = pj_str("Warning");
    pj_str_t hvalue = pj_str("399 pjsua \"Call duration exceeded\"");

    PJ_UNUSED_ARG(timer_heap);

    if (call_id == PJSUA_INVALID_ID) {
	PJ_LOG(1,(THIS_FILE, "Invalid call ID in timer callback"));
	return;
    }
    
    /* Add warning header */
    pjsua_msg_data_init(&msg_data);
    pjsip_generic_string_hdr_init2(&warn, &hname, &hvalue);
    pj_list_push_back(&msg_data.hdr_list, &warn);

    /* Call duration has been exceeded; disconnect the call */
    PJ_LOG(3,(THIS_FILE, "Duration (%d seconds) has been exceeded "
			 "for call %d, disconnecting the call",
			 app_config.duration, call_id));
    entry->id = PJSUA_INVALID_ID;
    pjsua_call_hangup(call_id, 200, NULL, &msg_data);
}
Beispiel #3
0
static void ui_call_transfer(pj_bool_t no_refersub)
{
    if (current_call == -1) {
	PJ_LOG(3,(THIS_FILE, "No current call"));
    } else {
	int call = current_call;
	char buf[128];
	pjsip_generic_string_hdr refer_sub;
	pj_str_t STR_REFER_SUB = { "Refer-Sub", 9 };
	pj_str_t STR_FALSE = { "false", 5 };
	pjsua_call_info ci;
	input_result result;
	pjsua_msg_data msg_data;

	pjsua_call_get_info(current_call, &ci);
	printf("Transferring current call [%d] %.*s\n", current_call,
	       (int)ci.remote_info.slen, ci.remote_info.ptr);

	ui_input_url("Transfer to URL", buf, sizeof(buf), &result);

	/* Check if call is still there. */

	if (call != current_call) {
	    puts("Call has been disconnected");
	    return;
	}

	pjsua_msg_data_init(&msg_data);
	if (no_refersub) {
	    /* Add Refer-Sub: false in outgoing REFER request */
	    pjsip_generic_string_hdr_init2(&refer_sub, &STR_REFER_SUB,
		&STR_FALSE);
	    pj_list_push_back(&msg_data.hdr_list, &refer_sub);
	}
	if (result.nb_result != PJSUA_APP_NO_NB) {
	    if (result.nb_result == -1 || result.nb_result == 0)
		puts("You can't do that with transfer call!");
	    else {
		pjsua_buddy_info binfo;
		pjsua_buddy_get_info(result.nb_result-1, &binfo);
		pjsua_call_xfer( current_call, &binfo.uri, &msg_data);
	    }

	} else if (result.uri_result) {
	    pj_str_t tmp;
	    tmp = pj_str(result.uri_result);
	    pjsua_call_xfer( current_call, &tmp, &msg_data);
	}
    }
}
Beispiel #4
0
pj_status_t BlabbleCall::MakeCall(const std::string& dest, const std::string& identity)
{
	BlabbleAccountPtr p = parent_.lock();
	if (!p)
		return false;

	if (call_id_ != INVALID_CALL)
		return false;

	pj_status_t status;
	pj_str_t desturi;
	desturi.ptr = const_cast<char*>(dest.c_str());
	desturi.slen = dest.length();

	if (!identity.empty())
	{
		pjsua_msg_data msgData;
		pjsua_msg_data_init(&msgData);
		pjsip_generic_string_hdr cidHdr;
		pj_str_t name = pj_str(const_cast<char*>("P-Asserted-Identity"));
		pj_str_t value = pj_str(const_cast<char*>(identity.c_str()));

		pjsip_generic_string_hdr_init2(&cidHdr, &name, &value);
		pj_list_push_back(&msgData.hdr_list, &cidHdr);

		status = pjsua_call_make_call(acct_id_, &desturi, 0,
			&id_, &msgData, (pjsua_call_id*)&call_id_);
	}
	else 
	{
		status = pjsua_call_make_call(acct_id_, &desturi, 0,
			&id_, NULL, (pjsua_call_id*)&call_id_);
	}

	if (status == PJ_SUCCESS) 
	{
		destination_ = dest;
		StartOutRinging();
	} 

	return status;
}
Beispiel #5
0
static void ui_answer_call()
{
    pjsua_call_info call_info;
    char buf[128];
    pjsua_msg_data msg_data;

    if (current_call != -1) {
	pjsua_call_get_info(current_call, &call_info);
    } else {
	/* Make compiler happy */
	call_info.role = PJSIP_ROLE_UAC;
	call_info.state = PJSIP_INV_STATE_DISCONNECTED;
    }

    if (current_call == -1 ||
	call_info.role != PJSIP_ROLE_UAS ||
	call_info.state >= PJSIP_INV_STATE_CONNECTING)
    {
	puts("No pending incoming call");
	fflush(stdout);
	return;

    } else {
	int st_code;
	char contact[120];
	pj_str_t hname = { "Contact", 7 };
	pj_str_t hvalue;
	pjsip_generic_string_hdr hcontact;

	if (!simple_input("Answer with code (100-699)", buf, sizeof(buf)))
	    return;

	st_code = my_atoi(buf);
	if (st_code < 100)
	    return;

	pjsua_msg_data_init(&msg_data);

	if (st_code/100 == 3) {
	    if (!simple_input("Enter URL to be put in Contact",
		contact, sizeof(contact)))
		return;
	    hvalue = pj_str(contact);
	    pjsip_generic_string_hdr_init2(&hcontact, &hname, &hvalue);

	    pj_list_push_back(&msg_data.hdr_list, &hcontact);
	}

	/*
	* Must check again!
	* Call may have been disconnected while we're waiting for
	* keyboard input.
	*/
	if (current_call == -1) {
	    puts("Call has been disconnected");
	    fflush(stdout);
	    return;
	}

	pjsua_call_answer2(current_call, &call_opt, st_code, NULL, &msg_data);
    }
}
Beispiel #6
0
static void ui_call_transfer_replaces(pj_bool_t no_refersub)
{
    if (current_call == -1) {
	PJ_LOG(3,(THIS_FILE, "No current call"));
    } else {
	int call = current_call;
	int dst_call;
	pjsip_generic_string_hdr refer_sub;
	pj_str_t STR_REFER_SUB = { "Refer-Sub", 9 };
	pj_str_t STR_FALSE = { "false", 5 };
	pjsua_call_id ids[PJSUA_MAX_CALLS];
	pjsua_call_info ci;
	pjsua_msg_data msg_data;
	char buf[128];
	unsigned i, count;

	count = PJ_ARRAY_SIZE(ids);
	pjsua_enum_calls(ids, &count);

	if (count <= 1) {
	    puts("There are no other calls");
	    return;
	}

	pjsua_call_get_info(current_call, &ci);
	printf("Transfer call [%d] %.*s to one of the following:\n",
	       current_call,
	       (int)ci.remote_info.slen, ci.remote_info.ptr);

	for (i=0; i<count; ++i) {
	    pjsua_call_info call_info;

	    if (ids[i] == call)
		continue;

	    pjsua_call_get_info(ids[i], &call_info);
	    printf("%d  %.*s [%.*s]\n",
		ids[i],
		(int)call_info.remote_info.slen,
		call_info.remote_info.ptr,
		(int)call_info.state_text.slen,
		call_info.state_text.ptr);
	}

	if (!simple_input("Enter call number to be replaced", buf, sizeof(buf)))
	    return;

	dst_call = my_atoi(buf);

	/* Check if call is still there. */

	if (call != current_call) {
	    puts("Call has been disconnected");
	    return;
	}

	/* Check that destination call is valid. */
	if (dst_call == call) {
	    puts("Destination call number must not be the same "
		"as the call being transferred");
	    return;
	}
	if (dst_call >= PJSUA_MAX_CALLS) {
	    puts("Invalid destination call number");
	    return;
	}
	if (!pjsua_call_is_active(dst_call)) {
	    puts("Invalid destination call number");
	    return;
	}

	pjsua_msg_data_init(&msg_data);
	if (no_refersub) {
	    /* Add Refer-Sub: false in outgoing REFER request */
	    pjsip_generic_string_hdr_init2(&refer_sub, &STR_REFER_SUB,
					   &STR_FALSE);
	    pj_list_push_back(&msg_data.hdr_list, &refer_sub);
	}

	pjsua_call_xfer_replaces(call, dst_call,
				 PJSUA_XFER_NO_REQUIRE_REPLACES,
				 &msg_data);
    }
}