Ejemplo n.º 1
0
/****************************************************************************
 ** Current version of sngrep launches a thread that execs original ngrep
 ** binary. sngrep was born with the idea of parsing ngrep output.
 ** This could be changed with a bit of effort to a network capturing thread
 ** using libpcap functions, but we'll keep this way for now.
 **
 ** Also, take into account that as a parser, we expect ngrep header in an
 ** expecific format that is obtained using ngrep arguments -qpt which are
 ** forced by the exec process.
 **
 ** U DD/MM/YY hh:mm:ss.uuuuuu fff.fff.fff.fff:pppp -> fff.fff.fff.fff:pppp
 **
 ** If any other parameters are supplied to sngrep that changes this header
 ** (let's say -T), sngrep will fail at parsing any header :(
 **
 ****************************************************************************/
int
online_capture(void *pargv)
{
    char **argv = (char**) pargv;
    int argc = 1;
    char cmdline[512];
    FILE *fp;
    char stdout_line[2048] = "";
    char msg_header[256], msg_payload[20480];

    // Build the commald line to execute ngrep
    memset(cmdline, 0, sizeof(cmdline));
    sprintf(cmdline, "%s %s %s %s", STDBUF_BIN, STDBUF_ARGS, NGREP_BIN, NGREP_ARGS);
    // Add save to temporal file (if option enabled)
    if (!is_option_disabled("sngrep.tmpfile"))
        sprintf(cmdline + strlen(cmdline), " -O %s", get_option_value("sngrep.tmpfile"));

    while (argv[argc]){
        if (strchr(argv[argc], ' ')) {
            sprintf(cmdline + strlen(cmdline), " \"%s\"", argv[argc++]);
        } else {
            sprintf(cmdline + strlen(cmdline), " %s", argv[argc++]);
        }
    }

    // Open the command for reading.
    fp = popen(cmdline, "r");
    if (fp == NULL) {
        printf("Failed to run command\n");
        return 1;
    }

    // Read the output a line at a time - output it.
    while (fgets(stdout_line, 1024, fp) != NULL) {
        if (!strncmp(stdout_line, "\n", 1) && strlen(msg_header) && strlen(msg_payload)) {
            // Parse message
            struct sip_msg *msg;
            if ((msg = sip_load_message(msg_header, strdup((const char*) msg_payload)))) {
                // Update the ui
                ui_new_msg_refresh(msg);
            }

            // Initialize structures
            strcpy(msg_header, "");
            strcpy(msg_payload, "");
        } else {
            if (!strncmp(stdout_line, "U ", 2)) {
                strcpy(msg_header, stdout_line);
            } else {
                if (strlen(msg_header)) {
                    strcat(msg_payload, stdout_line);
                }
            }
        }
    }

    // Close read pipe
    pclose(fp);
    return 0;
}
Ejemplo n.º 2
0
int adtn_var_socket(socket_params in)
{
	char default_config_file[CONFIG_FILE_PATH_L] = {0};
	char *config_file;
	int ret = -1;
	char *data_path = NULL;

	snprintf(default_config_file, CONFIG_FILE_PATH_L, DEFAULT_CONF_FILE_PATH);
	config_file = in.config_file ? strdup(in.config_file) : strdup(default_config_file);

	struct conf_list ritm_configuration = {0};
	if (load_config("global", &ritm_configuration, config_file) != 1) {
		errno = ENOENT;
		goto end;
	}
	if ((data_path = get_option_value("data", &ritm_configuration)) == NULL) {
		errno = EBADRQC;
		goto end;
	}
	ret = 0;
end:
	if (ritm_configuration.section)
		free(ritm_configuration.section);
	free(config_file);
	ret = (ret == -1) ? -1 : adtn_socket_base(data_path);
	if (data_path)
		free(data_path);

	return ret;
}
Ejemplo n.º 3
0
int
get_option_int_value(const char *opt)
{
    const char *value;
    if ((value = get_option_value(opt))) {
        return atoi(value);
    }
    return -1;
}
Ejemplo n.º 4
0
int generate_namelist(ezxml_t registry, FILE* fd, int pairs, char **keys, char **values){/*{{{*/
	ezxml_t nmlrecs_xml, nmlopt_xml;

	const char *recname;
	const char *optname, *opttype;
	char *optval;

	int write_opt, write_record, record_written;
	int i;

	for (nmlrecs_xml = ezxml_child(registry, "nml_record"); nmlrecs_xml; nmlrecs_xml = nmlrecs_xml->next){
		recname = ezxml_attr(nmlrecs_xml, "name");

		record_written = 0;
		write_record = is_structure_writable(nmlrecs_xml, pairs, keys, values);

		/* If record doesn't have a key, record is writeable */
		if ( write_record == -1 ) write_record = 1;

		if ( write_record == 1 ) {
			fprintf(fd, "&%s\n", recname);
			record_written = 1;
		}

		for (nmlopt_xml = ezxml_child(nmlrecs_xml, "nml_option"); nmlopt_xml; nmlopt_xml = nmlopt_xml->next){
			optname = ezxml_attr(nmlopt_xml, "name");
			opttype = ezxml_attr(nmlopt_xml, "type");

			write_opt = is_structure_writable(nmlopt_xml, pairs, keys, values);

			if ( write_opt == 1 || ( write_opt == -1 && write_record == 1) ){
				if ( !record_written ) {
					fprintf(fd, "&%s\n", recname);
					record_written = 1;
				}

				optval = get_option_value(nmlopt_xml, pairs, values);

				if ( strcmp(opttype, "character") == 0){
					fprintf(fd, "    %s = '%s'\n", optname, optval);
				} else {
					fprintf(fd, "    %s = %s\n", optname, optval);
				}

				free(optval);
			}
		}

		if ( record_written ) {
			fprintf(fd, "/\n");
		}
	}

	return 0;
}/*}}}*/
Ejemplo n.º 5
0
void
set_option_value(const char *opt, const char *value)
{
    if (!opt || !value)
        return;

    int i;
    if (!get_option_value(opt)) {
        options[optscnt].type = COLUMN;
        options[optscnt].opt = strdup(opt);
        options[optscnt].value = strdup(value);
        optscnt++;
    } else {
        for (i = 0; i < optscnt; i++) {
            if (!strcasecmp(opt, options[i].opt)) {
                sng_free(options[i].value);
                options[i].value = strdup(value);
            }
        }
    }
}
Ejemplo n.º 6
0
/*
 *  In Ruby 1.9 or later, ruby String object has encoding.
 *  conversion buffer string of vim to ruby String object using
 *  VIM encoding option.
 */
static VALUE
vim_str2rb_enc_str(const char *s)
{
#ifdef RUBY19_OR_LATER
    int isnum;
    long lval;
    char_u *sval;
    rb_encoding *enc;

    isnum = get_option_value((char_u *)"enc", &lval, &sval, 0);
    if (isnum == 0)
    {
        enc = rb_enc_find((char *)sval);
        vim_free(sval);
        if (enc) {
            return rb_enc_str_new(s, strlen(s), enc);
        }
    }
#endif
    return rb_str_new2(s);
}
Ejemplo n.º 7
0
    static VALUE
eval_enc_string_protect(const char *str, int *state)
{
#ifdef RUBY19_OR_LATER
    int isnum;
    long lval;
    char_u *sval;
    rb_encoding *enc;
    VALUE v;

    isnum = get_option_value((char_u *)"enc", &lval, &sval, 0);
    if (isnum == 0)
    {
	enc = rb_enc_find((char *)sval);
	vim_free(sval);
	if (enc)
	{
	    v = rb_sprintf("#-*- coding:%s -*-\n%s", rb_enc_name(enc), str);
	    return rb_eval_string_protect(StringValuePtr(v), state);
	}
    }
#endif
    return rb_eval_string_protect(str, state);
}
Ejemplo n.º 8
0
Archivo: info.c Proyecto: cfillion/vifm
/* Writes current values of all options into vifminfo file. */
static void
write_options(FILE *const fp)
{
	fputs("\n# Options:\n", fp);
	fprintf(fp, "=aproposprg=%s\n", escape_spaces(cfg.apropos_prg));
	fprintf(fp, "=%sautochpos\n", cfg.auto_ch_pos ? "" : "no");
	fprintf(fp, "=cdpath=%s\n", cfg.cd_path);
	fprintf(fp, "=%schaselinks\n", cfg.chase_links ? "" : "no");
	fprintf(fp, "=columns=%d\n", cfg.columns);
	fprintf(fp, "=%sconfirm\n", cfg.confirm ? "" : "no");
	fprintf(fp, "=cpoptions=%s%s%s\n",
			cfg.filter_inverted_by_default ? "f" : "",
			cfg.selection_is_primary ? "s" : "",
			cfg.tab_switches_pane ? "t" : "");
	fprintf(fp, "=deleteprg=%s\n", escape_spaces(cfg.delete_prg));
	fprintf(fp, "=%sfastrun\n", cfg.fast_run ? "" : "no");
	if(strcmp(cfg.border_filler, " ") != 0)
	{
		fprintf(fp, "=fillchars+=vborder:%s\n", cfg.border_filler);
	}
	fprintf(fp, "=findprg=%s\n", escape_spaces(cfg.find_prg));
	fprintf(fp, "=%sfollowlinks\n", cfg.follow_links ? "" : "no");
	fprintf(fp, "=fusehome=%s\n", escape_spaces(cfg.fuse_home));
	fprintf(fp, "=%sgdefault\n", cfg.gdefault ? "" : "no");
	fprintf(fp, "=grepprg=%s\n", escape_spaces(cfg.grep_prg));
	fprintf(fp, "=history=%d\n", cfg.history_len);
	fprintf(fp, "=%shlsearch\n", cfg.hl_search ? "" : "no");
	fprintf(fp, "=%siec\n", cfg.use_iec_prefixes ? "" : "no");
	fprintf(fp, "=%signorecase\n", cfg.ignore_case ? "" : "no");
	fprintf(fp, "=%sincsearch\n", cfg.inc_search ? "" : "no");
	fprintf(fp, "=%slaststatus\n", cfg.display_statusline ? "" : "no");
	fprintf(fp, "=%stitle\n", cfg.set_title ? "" : "no");
	fprintf(fp, "=lines=%d\n", cfg.lines);
	fprintf(fp, "=locateprg=%s\n", escape_spaces(cfg.locate_prg));
	fprintf(fp, "=mintimeoutlen=%d\n", cfg.min_timeout_len);
	fprintf(fp, "=rulerformat=%s\n", escape_spaces(cfg.ruler_format));
	fprintf(fp, "=%srunexec\n", cfg.auto_execute ? "" : "no");
	fprintf(fp, "=%sscrollbind\n", cfg.scroll_bind ? "" : "no");
	fprintf(fp, "=scrolloff=%d\n", cfg.scroll_off);
	fprintf(fp, "=shell=%s\n", escape_spaces(cfg.shell));
	fprintf(fp, "=shortmess=%s\n",
			escape_spaces(get_option_value("shortmess", OPT_GLOBAL)));
#ifndef _WIN32
	fprintf(fp, "=slowfs=%s\n", escape_spaces(cfg.slow_fs_list));
#endif
	fprintf(fp, "=%ssmartcase\n", cfg.smart_case ? "" : "no");
	fprintf(fp, "=%ssortnumbers\n", cfg.sort_numbers ? "" : "no");
	fprintf(fp, "=statusline=%s\n", escape_spaces(cfg.status_line));
	fprintf(fp, "=tabstop=%d\n", cfg.tab_stop);
	fprintf(fp, "=timefmt=%s\n", escape_spaces(cfg.time_format + 1));
	fprintf(fp, "=timeoutlen=%d\n", cfg.timeout_len);
	fprintf(fp, "=%strash\n", cfg.use_trash ? "" : "no");
	fprintf(fp, "=tuioptions=%s%s\n",
			cfg.extra_padding ? "p" : "",
			cfg.side_borders_visible ? "s" : "");
	fprintf(fp, "=undolevels=%d\n", cfg.undo_levels);
	fprintf(fp, "=vicmd=%s%s\n", escape_spaces(cfg.vi_command),
			cfg.vi_cmd_bg ? " &" : "");
	fprintf(fp, "=vixcmd=%s%s\n", escape_spaces(cfg.vi_x_command),
			cfg.vi_cmd_bg ? " &" : "");
	fprintf(fp, "=%swrapscan\n", cfg.wrap_scan ? "" : "no");
	fprintf(fp, "=[viewcolumns=%s\n", escape_spaces(lwin.view_columns_g));
	fprintf(fp, "=]viewcolumns=%s\n", escape_spaces(rwin.view_columns_g));
	fprintf(fp, "=[sortgroups=%s\n", escape_spaces(lwin.sort_groups_g));
	fprintf(fp, "=]sortgroups=%s\n", escape_spaces(rwin.sort_groups_g));
	fprintf(fp, "=[%slsview\n", lwin.ls_view_g ? "" : "no");
	fprintf(fp, "=]%slsview\n", rwin.ls_view_g ? "" : "no");
	fprintf(fp, "=[%snumber\n", (lwin.num_type_g & NT_SEQ) ? "" : "no");
	fprintf(fp, "=]%snumber\n", (rwin.num_type_g & NT_SEQ) ? "" : "no");
	fprintf(fp, "=[numberwidth=%d\n", lwin.num_width_g);
	fprintf(fp, "=]numberwidth=%d\n", rwin.num_width_g);
	fprintf(fp, "=[%srelativenumber\n", (lwin.num_type_g & NT_REL) ? "" : "no");
	fprintf(fp, "=]%srelativenumber\n", (rwin.num_type_g & NT_REL) ? "" : "no");

	fprintf(fp, "%s", "=dotdirs=");
	if(cfg.dot_dirs & DD_ROOT_PARENT)
		fprintf(fp, "%s", "rootparent,");
	if(cfg.dot_dirs & DD_NONROOT_PARENT)
		fprintf(fp, "%s", "nonrootparent,");
	fprintf(fp, "\n");

	fprintf(fp, "%s", "=iooptions=");
	if(cfg.fast_file_cloning)
		fprintf(fp, "%s", "fastfilecloning,");
	fprintf(fp, "\n");

	fprintf(fp, "=dirsize=%s", cfg.view_dir_size == VDS_SIZE ? "size" : "nitems");

	fprintf(fp, "=classify=%s\n", escape_spaces(classify_to_str()));

	fprintf(fp, "=vifminfo=options");
	if(cfg.vifm_info & VIFMINFO_FILETYPES)
		fprintf(fp, ",filetypes");
	if(cfg.vifm_info & VIFMINFO_COMMANDS)
		fprintf(fp, ",commands");
	if(cfg.vifm_info & VIFMINFO_MARKS)
		fprintf(fp, ",bookmarks");
	if(cfg.vifm_info & VIFMINFO_TUI)
		fprintf(fp, ",tui");
	if(cfg.vifm_info & VIFMINFO_DHISTORY)
		fprintf(fp, ",dhistory");
	if(cfg.vifm_info & VIFMINFO_STATE)
		fprintf(fp, ",state");
	if(cfg.vifm_info & VIFMINFO_CS)
		fprintf(fp, ",cs");
	if(cfg.vifm_info & VIFMINFO_SAVEDIRS)
		fprintf(fp, ",savedirs");
	if(cfg.vifm_info & VIFMINFO_CHISTORY)
		fprintf(fp, ",chistory");
	if(cfg.vifm_info & VIFMINFO_SHISTORY)
		fprintf(fp, ",shistory");
	if(cfg.vifm_info & VIFMINFO_PHISTORY)
		fprintf(fp, ",phistory");
	if(cfg.vifm_info & VIFMINFO_FHISTORY)
		fprintf(fp, ",fhistory");
	if(cfg.vifm_info & VIFMINFO_DIRSTACK)
		fprintf(fp, ",dirstack");
	if(cfg.vifm_info & VIFMINFO_REGISTERS)
		fprintf(fp, ",registers");
	fprintf(fp, "\n");

	fprintf(fp, "=%svimhelp\n", cfg.use_vim_help ? "" : "no");
	fprintf(fp, "=%swildmenu\n", cfg.wild_menu ? "" : "no");
	fprintf(fp, "=wildstyle=%s\n", cfg.wild_popup ? "popup" : "bar");
	fprintf(fp, "=wordchars=%s\n",
			escape_spaces(get_option_value("wordchars", OPT_GLOBAL)));
	fprintf(fp, "=%swrap\n", cfg.wrap_quick_view ? "" : "no");
}
Ejemplo n.º 9
0
PANEL *
save_raw_create()
{
    PANEL *panel;
    WINDOW *win;
    int height, width;
    save_raw_info_t *info;
    char savefile[128];

    // Calculate window dimensions
    height = 10;
    width = 90;

    // Cerate a new indow for the panel and form
    win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2);

    // Create a new panel
    panel = new_panel(win);

    // Initialize save panel specific data
    info = malloc(sizeof(save_raw_info_t));
    memset(info, 0, sizeof(save_raw_info_t));

    // Store it into panel userptr
    set_panel_userptr(panel, (void*) info);

    // Initialize the fields
    info->fields[FLD_SAVE_RAW_FILE] = new_field(1, 68, 3, 15, 0, 0);
    info->fields[FLD_SAVE_RAW_SELECTED] = new_field(1, 1, 4, 5, 0, 0);
    info->fields[FLD_SAVE_RAW_SAVE] = new_field(1, 10, height - 2, 30, 0, 0);
    info->fields[FLD_SAVE_RAW_CANCEL] = new_field(1, 10, height - 2, 50, 0, 0);
    info->fields[FLD_SAVE_RAW_COUNT] = NULL;

    // Set fields options
    field_opts_off(info->fields[FLD_SAVE_RAW_FILE], O_AUTOSKIP);

    // Change background of input fields
    set_field_back(info->fields[FLD_SAVE_RAW_FILE], A_UNDERLINE);

    // Create the form and post it
    info->form = new_form(info->fields);
    set_form_sub(info->form, win);
    post_form(info->form);

    // Fields labels
    mvwprintw(win, 3, 3, "Save file:");
    mvwprintw(win, 4, 4, "[ ] Only save selected calls");

    // Set Default field values
    sprintf(savefile, "%s/sngrep-raw-%u.txt", get_option_value("sngrep.savepath"),
            (unsigned) time(NULL));

    set_field_buffer(info->fields[FLD_SAVE_RAW_FILE], 0, savefile);
    set_field_buffer(info->fields[FLD_SAVE_RAW_SELECTED], 0,
                     is_option_enabled("sngrep.saveselected") ? "*" : "");
    set_field_buffer(info->fields[FLD_SAVE_RAW_SAVE], 0, "[  Save  ]");
    set_field_buffer(info->fields[FLD_SAVE_RAW_CANCEL], 0, "[ Cancel ]");

    // Set the window title and boxes
    mvwprintw(win, 1, 28, "Save raw data to file");
    wattron(win, COLOR_PAIR(CP_BLUE_ON_DEF));
    title_foot_box(panel_window(panel));
    mvwhline(win, height - 3, 1, ACS_HLINE, width - 1);
    mvwaddch(win, height - 3, 0, ACS_LTEE);
    mvwaddch(win, height - 3, width - 1, ACS_RTEE);
    wattroff(win, COLOR_PAIR(CP_BLUE_ON_DEF));

    // Set default cursor position
    set_current_field(info->form, info->fields[FLD_SAVE_RAW_FILE]);
    wmove(win, 3, 15);
    curs_set(1);

    return panel;
}
Ejemplo n.º 10
0
PANEL *
call_list_create()
{
    PANEL *panel;
    WINDOW *win;
    int height, width, i, attrid, collen;
    call_list_info_t *info;
    char option[80];
    const char *field, *title;

    // Create a new panel that fill all the screen
    panel = new_panel(newwin(LINES, COLS, 0, 0));
    // Initialize Call List specific data
    info = sng_malloc(sizeof(call_list_info_t));
    // Store it into panel userptr
    set_panel_userptr(panel, (void*) info);

    // Add configured columns
    for (i = 0; i < SIP_ATTR_COUNT; i++) {
        // Get column attribute name from options
        sprintf(option, "cl.column%d", i);
        if ((field = get_option_value(option))) {
            if ((attrid = sip_attr_from_name(field)) == -1)
                continue;
            // Get column width from options
            sprintf(option, "cl.column%d.width", i);
            if ((collen = get_option_int_value(option)) == -1)
                collen = sip_attr_get_width(attrid);
            // Get column title
            title = sip_attr_get_title(attrid);
            // Add column to the list
            call_list_add_column(panel, attrid, field, title, collen);
        }
    }

    // Let's draw the fixed elements of the screen
    win = panel_window(panel);
    getmaxyx(win, height, width);

    // Initialize the fields
    info->fields[FLD_LIST_FILTER] = new_field(1, width - 19, 2, 18, 0, 0);
    info->fields[FLD_LIST_COUNT] = NULL;

    // Create the form and post it
    info->form = new_form(info->fields);
    set_form_sub(info->form, win);

    // Form starts inactive
    call_list_form_activate(panel, 0);

    // Calculate available printable area
    info->list_win = subwin(win, height - 5, width, 4, 0);
    info->group = call_group_create();

    // Get current call list
    info->calls = sip_calls_iterator();
    vector_iterator_set_filter(&info->calls, filter_check_call);
    info->cur_call = info->first_call = -1;

    // Set autoscroll default status
    info->autoscroll = setting_enabled(SETTING_CL_AUTOSCROLL);

    // Apply initial configured method filters
    filter_method_from_setting(setting_get_value(SETTING_FILTER_METHODS));


    // Return the created panel
    return panel;
}