Beispiel #1
0
/** UI Command **/
static void ui_make_new_call()
{
    char buf[128];
    pjsua_msg_data msg_data;
    input_result result;
    pj_str_t tmp;

    printf("(You currently have %d calls)\n", pjsua_call_get_count());

    ui_input_url("Make call", buf, sizeof(buf), &result);
    if (result.nb_result != PJSUA_APP_NO_NB) {

	if (result.nb_result == -1 || result.nb_result == 0) {
	    puts("You can't do that with make call!");
	    return;
	} else {
	    pjsua_buddy_info binfo;
	    pjsua_buddy_get_info(result.nb_result-1, &binfo);
	    tmp.ptr = buf;
	    pj_strncpy(&tmp, &binfo.uri, sizeof(buf));
	}

    } else if (result.uri_result) {
	tmp = pj_str(result.uri_result);
    } else {
	tmp.slen = 0;
    }

    pjsua_msg_data_init(&msg_data);
    TEST_MULTIPART(&msg_data);
    pjsua_call_make_call(current_acc, &tmp, &call_opt, NULL,
			 &msg_data, &current_call);
}
Beispiel #2
0
/*
 * Print buddy list.
 */
static void print_buddy_list()
{
    pjsua_buddy_id ids[64];
    int i;
    unsigned count = PJ_ARRAY_SIZE(ids);

    puts("Buddy list:");

    pjsua_enum_buddies(ids, &count);

    if (count == 0)
	puts(" -none-");
    else {
	for (i=0; i<(int)count; ++i) {
	    pjsua_buddy_info info;

	    if (pjsua_buddy_get_info(ids[i], &info) != PJ_SUCCESS)
		continue;

	    printf(" [%2d] <%.*s>  %.*s\n",
		    ids[i]+1,
		    (int)info.status_text.slen,
		    info.status_text.ptr,
		    (int)info.uri.slen,
		    info.uri.ptr);
	}
    }
    puts("");
}
Beispiel #3
0
static void ui_send_arbitrary_request()
{
    char text[128];
    char buf[128];
    char *uri;
    input_result result;
    pj_str_t tmp;

    if (pjsua_acc_get_count() == 0) {
	puts("Sorry, need at least one account configured");
	return;
    }

    puts("Send arbitrary request to remote host");

    /* Input METHOD */
    if (!simple_input("Request method:",text,sizeof(text)))
	return;

    /* Input destination URI */
    uri = NULL;
    ui_input_url("Destination URI", buf, sizeof(buf), &result);
    if (result.nb_result != PJSUA_APP_NO_NB) {

	if (result.nb_result == -1) {
	    puts("Sorry you can't do that!");
	    return;
	} else if (result.nb_result == 0) {
	    uri = NULL;
	    if (current_call == PJSUA_INVALID_ID) {
		puts("No current call");
		return;
	    }
	} else {
	    pjsua_buddy_info binfo;
	    pjsua_buddy_get_info(result.nb_result-1, &binfo);
	    tmp.ptr = buf;
	    pj_strncpy_with_null(&tmp, &binfo.uri, sizeof(buf));
	    uri = buf;
	}

    } else if (result.uri_result) {
	uri = result.uri_result;
    } else {
	return;
    }

    if (uri) {
	tmp = pj_str(uri);
	send_request(text, &tmp);
    } else {
	/* If you send call control request using this method
	* (such requests includes BYE, CANCEL, etc.), it will
	* not go well with the call state, so don't do it
	* unless it's for testing.
	*/
	pj_str_t method = pj_str(text);
	pjsua_call_send_request(current_call, &method, NULL);
    }
}
Beispiel #4
0
/* Handler on buddy state changed. */
static void on_buddy_state(pjsua_buddy_id buddy_id)
{
    pjsua_buddy_info info;
    pjsua_buddy_get_info(buddy_id, &info);

    PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s",
	      (int)info.uri.slen,
	      info.uri.ptr,
	      (int)info.status_text.slen,
	      info.status_text.ptr));
}
Beispiel #5
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 #6
0
/*
 * Handler on buddy state changed.
 */
static void on_buddy_state(pjsua_buddy_id buddy_id)
{
    pjsua_buddy_info info;
    pjsua_buddy_get_info(buddy_id, &info);

    PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s",
	      (int)info.uri.slen,
	      info.uri.ptr,
	      (int)info.status_text.slen,
	      info.status_text.ptr));

		wchar_t* text = (wchar_t*)pj_pool_alloc(app_config.pool, 255);
		text = PJ_STRING_TO_NATIVE(info.status_text.ptr, text, info.status_text.slen);

		// callback
		if (cb_buddystatus != 0) 
			cb_buddystatus(buddy_id, info.status, text);
}
Beispiel #7
0
static void ui_make_multi_call()
{
    char menuin[32];
    int count;
    char buf[128];
    input_result result;
    pj_str_t tmp;
    int i;

    printf("(You currently have %d calls)\n", pjsua_call_get_count());

    if (!simple_input("Number of calls", menuin, sizeof(menuin)))
	return;

    count = my_atoi(menuin);
    if (count < 1)
	return;

    ui_input_url("Make call", buf, sizeof(buf), &result);
    if (result.nb_result != PJSUA_APP_NO_NB) {
	pjsua_buddy_info binfo;
	if (result.nb_result == -1 || result.nb_result == 0) {
	    puts("You can't do that with make call!");
	    return;
	}
	pjsua_buddy_get_info(result.nb_result-1, &binfo);
	tmp.ptr = buf;
	pj_strncpy(&tmp, &binfo.uri, sizeof(buf));
    } else {
	tmp = pj_str(result.uri_result);
    }

    for (i=0; i<my_atoi(menuin); ++i) {
	pj_status_t status;

	status = pjsua_call_make_call(current_acc, &tmp, &call_opt, NULL,
	    NULL, NULL);
	if (status != PJ_SUCCESS)
	    break;
    }
}
Beispiel #8
0
static void ui_send_instant_message()
{
    char *uri = NULL;
    /* i is for call index to send message, if any */
    int i = -1;
    input_result result;
    char buf[128];
    char text[128];
    pj_str_t tmp;

    /* Input destination. */
    ui_input_url("Send IM to", buf, sizeof(buf), &result);
    if (result.nb_result != PJSUA_APP_NO_NB) {

	if (result.nb_result == -1) {
	    puts("You can't send broadcast IM like that!");
	    return;

	} else if (result.nb_result == 0) {
	    i = current_call;
	} else {
	    pjsua_buddy_info binfo;
	    pjsua_buddy_get_info(result.nb_result-1, &binfo);
	    tmp.ptr = buf;
	    pj_strncpy_with_null(&tmp, &binfo.uri, sizeof(buf));
	    uri = buf;
	}

    } else if (result.uri_result) {
	uri = result.uri_result;
    }


    /* Send typing indication. */
    if (i != -1)
	pjsua_call_send_typing_ind(i, PJ_TRUE, NULL);
    else {
	pj_str_t tmp_uri = pj_str(uri);
	pjsua_im_typing(current_acc, &tmp_uri, PJ_TRUE, NULL);
    }

    /* Input the IM . */
    if (!simple_input("Message", text, sizeof(text))) {
	/*
	* Cancelled.
	* Send typing notification too, saying we're not typing.
	*/
	if (i != -1)
	    pjsua_call_send_typing_ind(i, PJ_FALSE, NULL);
	else {
	    pj_str_t tmp_uri = pj_str(uri);
	    pjsua_im_typing(current_acc, &tmp_uri, PJ_FALSE, NULL);
	}
	return;
    }

    tmp = pj_str(text);

    /* Send the IM */
    if (i != -1)
	pjsua_call_send_im(i, NULL, &tmp, NULL, NULL);
    else {
	pj_str_t tmp_uri = pj_str(uri);
	pjsua_im_send(current_acc, &tmp_uri, NULL, &tmp, NULL, NULL);
    }
}