Example #1
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);
    }
}
Example #2
0
static void ui_send_dtmf_info()
{
    if (current_call == -1) {
	PJ_LOG(3,(THIS_FILE, "No current call"));
    } else {
	const pj_str_t SIP_INFO = pj_str("INFO");
	pj_str_t digits;
	int call = current_call;
	int i;
	pj_status_t status;
	char buf[128];

	if (!simple_input("DTMF strings to send (0-9*#A-B)", buf,
	    sizeof(buf)))
	{
	    return;
	}

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

	digits = pj_str(buf);
	for (i=0; i<digits.slen; ++i) {
	    char body[80];
	    pjsua_msg_data msg_data;

	    pjsua_msg_data_init(&msg_data);
	    msg_data.content_type = pj_str("application/dtmf-relay");

	    pj_ansi_snprintf(body, sizeof(body),
		"Signal=%c\r\n"
		"Duration=160",
		buf[i]);
	    msg_data.msg_body = pj_str(body);

	    status = pjsua_call_send_request(current_call, &SIP_INFO,
		&msg_data);
	    if (status != PJ_SUCCESS) {
		return;
	    }
	}
    }
}
Example #3
0
 */PJ_DECL(pj_status_t) send_dtmf_info(int current_call, pj_str_t digits) {
	/* Send DTMF with INFO */
	if (current_call == -1) {
		PJ_LOG(3, (THIS_FILE, "No current call"));
		return PJ_EINVAL;
	} else {
		const pj_str_t SIP_INFO = pj_str((char *) "INFO");
		int call = current_call;
		int i;
		pj_status_t status = PJ_EINVAL;
		pjsua_msg_data msg_data;
		PJ_LOG(4, (THIS_FILE, "SEND DTMF : %.*s", digits.slen, digits.ptr));

		for (i = 0; i < digits.slen; ++i) {
			char body[80];

			pjsua_msg_data_init(&msg_data);
			msg_data.content_type = pj_str((char *) "application/dtmf-relay");

			pj_ansi_snprintf(body, sizeof(body), "Signal=%c\r\n"
					"Duration=160", digits.ptr[i]);
			msg_data.msg_body = pj_str(body);
			PJ_LOG(
					4,
					(THIS_FILE, "Send %.*s", msg_data.msg_body.slen, msg_data.msg_body.ptr));

			status = pjsua_call_send_request(current_call, &SIP_INFO,
					&msg_data);
			if (status != PJ_SUCCESS) {
				PJ_LOG(2, (THIS_FILE, "Failed %d", status));
				break;
			}
		}
		return status;
	}
}