Exemplo n.º 1
0
/*
 * Get hostname.
 */
PJ_DEF(const pj_str_t*) pj_gethostname(void)
{
    static char buf[PJ_MAX_HOSTNAME];
    static pj_str_t hostname;

    PJ_CHECK_STACK();

    if (hostname.ptr == NULL) {
	hostname.ptr = buf;
	if (gethostname(buf, sizeof(buf)) != 0) {
	    hostname.ptr[0] = '\0';
	    hostname.slen = 0;
	} else {
            hostname.slen = strlen(buf);
#if defined(PJ_GETHOSTNAME_APPEND_LOCAL_SUFFIX) && \
    PJ_GETHOSTNAME_APPEND_LOCAL_SUFFIX!=0
            {
                const pj_str_t suffix = {".local", 6};

                if (hostname.slen < suffix.slen ||
                    pj_ansi_strnicmp(hostname.ptr + hostname.slen -
                                     suffix.slen, suffix.ptr, suffix.slen))
                {
                    if (hostname.slen + suffix.slen + 1 < sizeof(buf))
                        pj_strcat(&hostname, &suffix);
                    else
                        hostname.slen = 0;
                    hostname.ptr[hostname.slen] = '\0';
                }
            }
#endif
	}
    }
    return &hostname;
}
Exemplo n.º 2
0
PJ_DEF(int) pj_scan_stricmp( pj_scanner *scanner, const char *s, int len)
{
    if (scanner->curptr + len > scanner->end) {
	pj_scan_syntax_err(scanner);
	return -1;
    }
    return pj_ansi_strnicmp(scanner->curptr, s, len);
}
Exemplo n.º 3
0
static void ui_echo(char menuin[])
{
    if (pj_ansi_strnicmp(menuin, "echo", 4)==0) {
	pj_str_t tmp;

	tmp.ptr = menuin+5;
	tmp.slen = pj_ansi_strlen(menuin)-6;

	if (tmp.slen < 1) {
	    puts("Usage: echo [0|1]");
	    return;
	}
	cmd_echo = *tmp.ptr != '0' || tmp.slen!=1;
    }
}
Exemplo n.º 4
0
PJ_DEF(char*) pj_stristr(const pj_str_t *str, const pj_str_t *substr)
{
    const char *s, *ends;

    /* Special case when substr is zero */
    if (substr->slen == 0) {
	return (char*)str->ptr;
    }

    s = str->ptr;
    ends = str->ptr + str->slen - substr->slen;
    for (; s<=ends; ++s) {
	if (pj_ansi_strnicmp(s, substr->ptr, substr->slen)==0)
	    return (char*)s;
    }
    return NULL;
}
Exemplo n.º 5
0
static void ui_sleep(char menuin[])
{
    if (pj_ansi_strnicmp(menuin, "sleep", 5)==0) {
	pj_str_t tmp;
	int delay;

	tmp.ptr = menuin+6;
	tmp.slen = pj_ansi_strlen(menuin)-7;

	if (tmp.slen < 1) {
	    puts("Usage: sleep MSEC");
	    return;
	}

	delay = pj_strtoul(&tmp);
	if (delay < 0) delay = 0;
	pj_thread_sleep(delay);
    }
}
Exemplo n.º 6
0
/*
 * Main "user interface" loop.
 */
void legacy_main()
{
    char menuin[80];
    char buf[128];

    keystroke_help();

    for (;;) {

	printf(">>> ");
	fflush(stdout);

	if (fgets(menuin, sizeof(menuin), stdin) == NULL) {
	    /*
	     * Be friendly to users who redirect commands into
	     * program, when file ends, resume with kbd.
	     * If exit is desired end script with q for quit
	     */
 	    /* Reopen stdin/stdout/stderr to /dev/console */
#if ((defined(PJ_WIN32) && PJ_WIN32!=0) || \
     (defined(PJ_WIN64) && PJ_WIN64!=0)) && \
  (!defined(PJ_WIN32_WINCE) || PJ_WIN32_WINCE==0)
	    if (freopen ("CONIN$", "r", stdin) == NULL) {
#else
	    if (1) {
#endif
		puts("Cannot switch back to console from file redirection");
		menuin[0] = 'q';
		menuin[1] = '\0';
	    } else {
		puts("Switched back to console from file redirection");
		continue;
	    }
	}

	if (cmd_echo) {
	    printf("%s", menuin);
	}

	/* Update call setting */
	pjsua_call_setting_default(&call_opt);
	call_opt.aud_cnt = app_config.aud_cnt;
	call_opt.vid_cnt = app_config.vid.vid_cnt;

	switch (menuin[0]) {

	case 'm':
	    /* Make call! : */
	    ui_make_new_call();
	    break;

	case 'M':
	    /* Make multiple calls! : */
	    ui_make_multi_call();
	    break;

	case 'n':
	    ui_detect_nat_type();
	    break;

	case 'i':
	    /* Send instant messaeg */
	    ui_send_instant_message();
	    break;

	case 'a':
	    ui_answer_call();
	    break;

	case 'h':
	    ui_hangup_call(menuin);
	    break;

	case ']':
	case '[':
	    /*
	     * Cycle next/prev dialog.
	     */
	    ui_cycle_dialog(menuin);
	    break;

	case '>':
	case '<':
	    ui_cycle_account();
	    break;

	case '+':
	    if (menuin[1] == 'b') {
		ui_add_buddy();
	    } else if (menuin[1] == 'a') {
		ui_add_account(&app_config.rtp_cfg);
	    } else {
		printf("Invalid input %s\n", menuin);
	    }
	    break;

	case '-':
	    if (menuin[1] == 'b') {
		ui_delete_buddy();
	    } else if (menuin[1] == 'a') {
		ui_delete_account();
	    } else {
		printf("Invalid input %s\n", menuin);
	    }
	    break;

	case 'H':
	    /*
	     * Hold call.
	     */
	    ui_call_hold();
	    break;

	case 'v':
#if PJSUA_HAS_VIDEO
	    if (menuin[1]=='i' && menuin[2]=='d' && menuin[3]==' ') {
		vid_handle_menu(menuin);
	    } else
#endif
	    if (current_call != -1) {
		/*
		 * re-INVITE
		 */
		ui_call_reinvite();
	    } else {
		PJ_LOG(3,(THIS_FILE, "No current call"));
	    }
	    break;

	case 'U':
	    /*
	     * Send UPDATE
	     */
	    ui_send_update();
	    break;

	case 'C':
	    if (menuin[1] == 'p') {
		ui_manage_codec_prio();
	    }
	    break;

	case 'x':
	    /*
	     * Transfer call.
	     */
	    ui_call_transfer(app_config.no_refersub);
	    break;

	case 'X':
	    /*
	     * Transfer call with replaces.
	     */
	    ui_call_transfer_replaces(app_config.no_refersub);
	    break;

	case '#':
	    /*
	     * Send DTMF strings.
	     */
	    ui_send_dtmf_2833();
	    break;

	case '*':
	    /* Send DTMF with INFO */
	    ui_send_dtmf_info();
	    break;

	case 'S':
	    /*
	     * Send arbitrary request
	     */
	    ui_send_arbitrary_request();
	    break;

	case 'e':
	    ui_echo(menuin);
	    break;

	case 's':
	    if (pj_ansi_strnicmp(menuin, "sleep", 5)==0) {
		ui_sleep(menuin);
		break;
	    }
	    /* Continue below */

	case 'u':
	    /*
	     * Subscribe/unsubscribe presence.
	     */
	    ui_subscribe(menuin);
	    break;

	case 'r':
	    ui_register(menuin);
	    break;

	case 't':
	    ui_toggle_state();
	    break;

	case 'T':
	    ui_change_online_status();
	    break;

	case 'c':
	    switch (menuin[1]) {
	    case 'l':
		ui_conf_list();
		break;
	    case 'c':
	    case 'd':
		ui_conf_connect(menuin);
		break;
	    }
	    break;

	case 'V':
	    /* Adjust audio volume */
	    ui_adjust_volume();
	    break;

	case 'd':
	    if (menuin[1] == 'c') {
		ui_dump_configuration();
	    } else if (menuin[1] == 'q') {
		ui_dump_call_quality();
	    } else {
		ui_app_dump(menuin[1]=='d');
	    }
	    break;

	case 'f':
	    if (simple_input("Enter output filename", buf, sizeof(buf))) {
		ui_write_settings();
	    }
	    break;

	case 'L':   /* Restart */
	case 'q':
	    legacy_on_stopped(menuin[0]=='L');
	    goto on_exit;

	case 'R':
	    ui_call_redirect(menuin);
	    break;

	default:
	    if (menuin[0] != '\n' && menuin[0] != '\r') {
		printf("Invalid input %s", menuin);
	    }
	    keystroke_help();
	    break;
	}
    }

on_exit:
    ;
}