static int module_init(void) { int err; err = ui_alloc(&wincons); if (err) return err; ui_register(&ui_wincons); return 0; }
static int module_init(void) { int err; err = ui_alloc(&ui_state); if (err) return err; ui_register(&ui_stdio); return 0; }
void set_daemon_interface(void) { struct ui_ops ops; ops.init = &daemon_init; ops.start = &daemon_interface; ops.cleanup = &daemon_cleanup; ops.msg = &daemon_msg; ops.error = &daemon_error; ops.fatal_error = &daemon_error; ops.progress = &daemon_progress; ops.type = UI_DAEMONIZE; ui_register(&ops); }
static int cons_init(void) { struct sa laddr; int err; if (conf_get_sa(conf_cur(), "cons_listen", &laddr)) { sa_set_str(&laddr, "0.0.0.0", CONS_PORT); } err = cons_alloc(&cons, &laddr); if (err) return err; ui_register(&ui_cons); return 0; }
static int module_init(void) { struct sa laddr; int err; if (conf_get_sa(conf_cur(), "http_listen", &laddr)) { sa_set_str(&laddr, "0.0.0.0", 8000); } err = http_listen(&httpsock, &laddr, http_req_handler, NULL); if (err) return err; ui_register(&ui_http); info("httpd: listening on %J\n", &laddr); return 0; }
void set_curses_interface(void) { struct ui_ops ops; /* wipe the struct */ memset(&ops, 0, sizeof(ops)); /* register the functions */ ops.init = &curses_init; ops.start = &curses_interface; ops.cleanup = &curses_cleanup; ops.msg = &curses_msg; ops.error = &curses_error; ops.fatal_error = &curses_fatal_error; ops.input = &curses_input; ops.progress = &curses_progress; ops.type = UI_CURSES; ui_register(&ops); }
void set_gtk_interface(void) { struct ui_ops ops; /* wipe the struct */ memset(&ops, 0, sizeof(ops)); /* register the functions */ ops.init = >kui_init; ops.start = >kui_start; ops.type = UI_GTK; ops.cleanup = >kui_cleanup_wrap; ops.msg = >kui_msg_wrap; ops.error = >kui_error_wrap; ops.fatal_error = >kui_fatal_error_wrap; ops.input = >kui_input_wrap; ops.progress = >kui_progress_wrap; ui_register(&ops); }
void set_gtk_interface(void) { struct ui_ops ops; /* wipe the struct */ memset(&ops, 0, sizeof(ops)); /* register the functions */ ops.init = >kui_init; ops.start = >kui_start; ops.type = UI_GTK; ops.cleanup = >kui_cleanup_wrap; ops.msg = >kui_msg_wrap; ops.error = >kui_error_wrap; ops.fatal_error = >kui_fatal_error_wrap; ops.input = >kui_input; ops.progress = >kui_progress_wrap; ops.update = >kui_update; ui_register(&ops); DEBUG_MSG("GTK -> gtk+ %d.%d.%d\n", gtk_major_version, gtk_minor_version, gtk_micro_version); }
void ui_text_main() { ui_register(&ui); DEBUG_MSG("Text UI registered"); }
/* point-of-entry */ int main(int argc, char **argv) { int ret = -1, c, index, action = ACTION_NONE, tmp; char *action_param = NULL; processor_config_t *config = 0, *config2 = 0; char *conf_file = 0; int load_autoreg = 0; int flag_quiet = 0; int log_to_file = 0; int console_only = 0; int do_test = 0; // do whatever the test of the day is xmlInitParser(); xmlInitThreads(); //initGenericErrorDefaultFunc((xmlGenericErrorFunc *)xml_error_func); /* the getopt values */ static struct option long_options[] = { {"verbose", no_argument, 0, 0}, {"iface", required_argument, 0, 0}, {"threads", required_argument, 0, 0}, {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, {"console", no_argument, 0, 0}, #ifdef CONFIG_PYTHON_ENABLED {"shell", no_argument, 0, 0}, {"run", required_argument, 0, 0}, {"no-scripts", no_argument, 0, 0}, #endif #ifdef CONFIG_SIP_ENABLED {"proxy-iface", required_argument, 0, 0}, {"no-mp", no_argument, 0, 0}, {"tunnel-mp", no_argument, 0, 0}, {"force-mp", no_argument, 0, 0}, {"allow-unknown", no_argument, 0, 0}, {"allow-untrusted", no_argument, 0, 0}, #endif {"list-ca", no_argument, 0, 0}, {"import-ca", required_argument, 0, 0}, {"remove-ca", required_argument, 0, 0}, {"list", no_argument, 0, 0}, {"import", required_argument, 0, 0}, {"remove", required_argument, 0, 0}, {"idents", required_argument, 0, 0}, {"log", required_argument, 0, 0}, #ifdef CONFIG_BROADCAST_ENABLED {"bc-addr", required_argument, 0, 0}, #endif #ifdef CONFIG_WEBCONF_ENABLED {"webconf", required_argument, 0, 0}, #endif #ifdef CONFIG_OPENDHT_ENABLED {"opendht", required_argument, 0, 0}, #endif #ifdef CONFIG_HIP_ENABLED {"list-hits", no_argument, 0, 0}, {"rvs", required_argument, 0, 0}, {"provide-rvs", no_argument, 0, 0}, #endif {0, 0, 0, 0} }; #ifdef LOCK_DEBUG debug2_init(); #endif #ifdef REF_DEBUG2 ship_debug_initref(); #endif if (!(config = processor_config_new()) || !(config2 = processor_config_new())) { USER_ERROR("Error loading application\n"); goto err; } if (processor_config_load_defaults(config2)) { USER_ERROR("Error loading default configurations\n"); goto err; } processor_config_get_string(config2, P2PSHIP_CONF_CONF_FILE, &conf_file); opterr = 0; while ((c = getopt_long(argc, argv, "LqvhDVs:c:p:i:Rr:kKt", long_options, &index)) != -1) { if (!c) { if (!strcmp(long_options[index].name, "threads")) { processor_config_set_int(config, P2PSHIP_CONF_WORKER_THREADS, atoi(optarg)); } else if (!strcmp(long_options[index].name, "help")) { c = '?'; } else if (!strcmp(long_options[index].name, "version")) { c = 'V'; } else if (!strcmp(long_options[index].name, "verbose")) { c = 'v'; } else if (!strcmp(long_options[index].name, "iface")) { c = 'i'; } else if (!strcmp(long_options[index].name, "console")) { console_only = 1; #ifdef CONFIG_PYTHON_ENABLED } else if (!strcmp(long_options[index].name, "shell")) { processor_config_set_true(config, P2PSHIP_CONF_START_SHELL); } else if (!strcmp(long_options[index].name, "run")) { processor_config_set_string(config, P2PSHIP_CONF_RUN_SCRIPT, optarg); } else if (!strcmp(long_options[index].name, "no-scripts")) { processor_config_set_false(config, P2PSHIP_CONF_STARTUP_SCRIPTS); #endif #ifdef CONFIG_SIP_ENABLED } else if (!strcmp(long_options[index].name, "proxy-iface")) { processor_config_set_string(config, P2PSHIP_CONF_SIPP_PROXY_IFACES, optarg); } else if (!strcmp(long_options[index].name, "no-mp")) { processor_config_set_string(config, P2PSHIP_CONF_SIPP_MEDIA_PROXY, "no"); } else if (!strcmp(long_options[index].name, "tunnel-mp")) { processor_config_set_string(config, P2PSHIP_CONF_SIPP_TUNNEL_PROXY, "yes"); } else if (!strcmp(long_options[index].name, "force-mp")) { processor_config_set_string(config, P2PSHIP_CONF_SIPP_FORCE_PROXY, "yes"); } else if (!strcmp(long_options[index].name, "allow-unknown")) { processor_config_set_string(config, P2PSHIP_CONF_IDENT_ALLOW_UNKNOWN_REGISTRATIONS, "yes"); } else if (!strcmp(long_options[index].name, "allow-untrusted")) { processor_config_set_string(config, P2PSHIP_CONF_IDENT_ALLOW_UNTRUSTED, "yes"); #endif } else if (!action && !strcmp(long_options[index].name, "list-ca")) { action = ACTION_LIST_CA; } else if (!action && !strcmp(long_options[index].name, "remove-ca")) { action = ACTION_REMOVE_CA; if (!action_param) action_param = strdup(optarg); } else if (!action && !strcmp(long_options[index].name, "import-ca")) { action = ACTION_IMPORT_CA; if (!action_param) action_param = strdup(optarg); } else if (!action && !strcmp(long_options[index].name, "list")) { action = ACTION_LIST; } else if (!action && !strcmp(long_options[index].name, "remove")) { action = ACTION_REMOVE; if (!action_param) action_param = strdup(optarg); } else if (!action && !strcmp(long_options[index].name, "import")) { action = ACTION_IMPORT; if (!action_param) action_param = strdup(optarg); } else if (!strcmp(long_options[index].name, "idents")) { processor_config_set_string(config, P2PSHIP_CONF_IDENTS_FILE, optarg); } else if (!strcmp(long_options[index].name, "log")) { processor_config_set_string(config, P2PSHIP_CONF_LOG_FILE, optarg); #ifdef CONFIG_BROADCAST_ENABLED } else if (!strcmp(long_options[index].name, "bc-addr")) { processor_config_set_string(config, P2PSHIP_CONF_BC_ADDR, optarg); #endif #ifdef CONFIG_OPENDHT_ENABLED } else if (!strcmp(long_options[index].name, "opendht")) { processor_config_set_string(config, P2PSHIP_CONF_OPENDHT_PROXY, optarg); #endif #ifdef CONFIG_HIP_ENABLED } else if (!strcmp(long_options[index].name, "list-hits")) { action = ACTION_LIST_HITS; } else if (!strcmp(long_options[index].name, "rvs")) { processor_config_set_string(config, P2PSHIP_CONF_RVS, optarg); } else if (!strcmp(long_options[index].name, "provide-rvs")) { processor_config_set_string(config, P2PSHIP_CONF_PROVIDE_RVS, "yes"); #endif #ifdef CONFIG_WEBCONF_ENABLED } else if (!strcmp(long_options[index].name, "webconf")) { processor_config_set_string(config, P2PSHIP_CONF_WEBCONF_SS, optarg); #endif } else { c = '?'; } } switch (c) { case 0: /* already processed */ break; case 'v': if (p2pship_log_level > -1) p2pship_log_level++; break; case 'q': flag_quiet = 1; p2pship_log_level = -1; break; case 'D': log_to_file = 1; processor_config_set_string(config, P2PSHIP_CONF_DAEMON, "yes"); break; case 'c': conf_file = optarg; processor_config_set_string(config, P2PSHIP_CONF_CONF_FILE, conf_file); break; case 'i': processor_config_set_string(config, P2PSHIP_CONF_IFACES, optarg); break; #ifdef CONFIG_SIP_ENABLED case 'p': if (sscanf(optarg, "%u", &tmp) != 1) { USER_ERROR("Invalid port %s\n", optarg); return 1; } else { processor_config_set_int(config, P2PSHIP_CONF_SIPP_PROXY_PORT, tmp); } break; #endif case 's': if (sscanf(optarg, "%u", &tmp) != 1) { USER_ERROR("Invalid port %s\n", optarg); return 1; } else { processor_config_set_int(config, P2PSHIP_CONF_SHIP_PORT, tmp); } break; case 'V': print_version(); return 0; case 'R': load_autoreg = 1; break; case 'r': processor_config_set_string(config, P2PSHIP_CONF_AUTOREG_FILE, optarg); break; case 'L': log_to_file = 1; break; case 'k': processor_kill_existing_pid(); break; case 'K': processor_kill_all_existing(); break; case 't': do_test = 1; break; case 'h': case '?': default: print_version(); print_usage(); return 1; } } if (!flag_quiet) print_version(); /* 1. load the defaults (done already), 2. load the conf file, 3. put on the manual overrides */ /* ensure that we have a config file! */ if (ship_ensure_file(conf_file, "# Autocreated\n\n") || processor_config_load(config2, conf_file)) { USER_ERROR("Error processing config file %s\n", conf_file); goto err; } if (processor_config_transfer(config2, config)) { USER_ERROR("Error processing configs\n"); goto err; } /* transfer */ processor_config_free(config); config = config2; config2 = NULL; /* ok, ready to rock! */ processor_config_ensure_configs(config); if (log_to_file) { p2pship_log_file = processor_config_string(config, P2PSHIP_CONF_LOG_FILE); } #ifdef CONFIG_START_GLIB_MAIN_LOOP if (!g_thread_supported()) g_thread_init(NULL); #endif #ifdef CONFIG_START_GTK gdk_threads_init(); gdk_threads_enter(); gtk_init(&argc, &argv); #endif #ifdef CALL_DEBUG calldebug_init(); #endif /* mark starttime for uptime calcs */ time(&p2pship_start); /* register each modules */ ASSERT_ZERO(processor_init(config), err); #ifdef CONFIG_HIP_ENABLED hipapi_register(); #endif #ifdef CONFIG_SIP_ENABLED sipp_register(); #endif ident_addr_register(); ident_register(); #ifdef CONFIG_WEBCONF_ENABLED webconf_register(); #endif #ifdef CONFIG_EXTAPI_ENABLED extapi_register(); #endif #ifdef CONFIG_WEBCACHE_ENABLED webcache_register(); #endif resourceman_register(); olclient_register(); conn_register(); netio_register(); netio_events_register(); netio_ff_register(); netio_man_register(); netio_http_register(); ui_register(); ui_stdin_register(); processor_init_module("ui_stdin", config); #ifdef CONFIG_DBUS_ENABLED dbus_register(); #endif if (!console_only) { #ifdef CONFIG_GTKUI_ENABLED ui_gtk_register(); processor_init_module("ui_gtk", config); #endif } addrbook_register(); #ifdef CONFIG_PYTHON_ENABLED pymod_register(); #endif #ifdef CONFIG_MEDIA_ENABLED media_register(); #endif /* check what we actually should do */ switch (action) { case ACTION_LIST_CA: { /* list ca */ if (processor_init_module("ident", config)) { USER_ERROR("Error initializing system\n"); } else { ident_data_print_cas(ident_get_cas()); } break; } case ACTION_REMOVE_CA: { /* remove ca */ if (processor_init_module("ident", config)) { USER_ERROR("Error initializing system\n"); } else { ident_remove_ca(action_param); } break; } case ACTION_LIST: { /* list */ if (processor_init_module("ident", config)) { USER_ERROR("Error initializing system\n"); } else { ident_data_print_idents(ident_get_identities()); } break; } case ACTION_REMOVE: { /* remove */ if (processor_init_module("ident", config)) { USER_ERROR("Error initializing system\n"); } else { ident_remove_ident(action_param); } break; } case ACTION_IMPORT: /* import */ case ACTION_IMPORT_CA: { /* import ca */ if (processor_init_module("ident", config)) { USER_ERROR("Error initializing system\n"); } else { if (ident_import_file(action_param, 1)) { USER_ERROR("Error loading processing file %s\n", action_param); } } break; } #ifdef CONFIG_HIP_ENABLED case ACTION_LIST_HITS: { if (processor_init_module("hipapi", config)) { USER_ERROR("Error initializing system\n"); } else { hipapi_list_hits(); } break; } #endif case ACTION_NONE: default: { struct rlimit rl; int result; #ifdef CONFIG_PYTHON_ENABLED if (processor_config_is_true(config, P2PSHIP_CONF_START_SHELL)) processor_config_set_false(config, P2PSHIP_CONF_DAEMON); #endif /* go daemon (..whee!) */ if (processor_config_is_true(config, P2PSHIP_CONF_DAEMON)) { if (fork()) goto err; } /* check the stack size */ if (!(result = getrlimit(RLIMIT_STACK, &rl))) { const rlim_t stacksize = 32L * 1024L * 1024L; if (rl.rlim_cur < stacksize) { LOG_INFO("increasing stack size to %d\n", stacksize); rl.rlim_cur = stacksize; if (setrlimit(RLIMIT_STACK, &rl)) { LOG_ERROR("could not set new stack size!\n"); } } } else { LOG_ERROR("error checking stack size\n"); } if (processor_init_modules(config) || (load_autoreg && ident_autoreg_load())) { USER_ERROR("Error initializing system\n"); } else { #ifdef REMOTE_DEBUG ship_remote_debug_init(config); #endif /* start the main loop, blocks */ #ifdef REF_DEBUG2 // processor_tasks_add_periodic(ship_debug_reportref, 10000); #endif if (do_test) { LOG_DEBUG("Run tests..\n"); } processor_run(); } } } ret = 0; err: #ifdef REF_DEBUG2 ship_debug_reportref(); #endif processor_close(); freez(action_param); processor_config_free(config); processor_config_free(config2); #ifdef LOCK_DEBUG debug2_close(); #endif #ifdef REF_DEBUG2 ship_debug_closeref(); #endif xmlCleanupThreads(); if (!ret && !flag_quiet) USER_ERROR("ending ok\n"); processor_cleanup_pid(); return ret; }
/* * 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: ; }
static int cons_init(void) { return ui_register(&cons, "cons", cons_alloc, NULL); }