Exemple #1
0
void parse_shi(FILE*file,double *shi)
{
  char s[100];
  fscanf(file,"%s",s);
  parse_check("shi:",s);
  fscanf(file,"%lf",shi);
  printf("shi: %f\n",*shi);
}
Exemple #2
0
void parse_rad(FILE*file,double *r)
{
  char str[100];
  fscanf(file,"%s",str);
  parse_check("rad:",str);
  fscanf(file,"%lf",r);
  printf("rad: %f\n",*r);
}
Exemple #3
0
void parse_doubles(FILE*file, char *check, double p[3])
{
  char str[100];
  fscanf(file,"%s",str);
  parse_check(check,str);
  fscanf(file,"%lf %lf %lf",&p[0],&p[1],&p[2]);
  printf("%s %lf %lf %lf\n",check,p[0],p[1],p[2]);
}
Exemple #4
0
static void
fail_tests_item (const gchar  *filename,
                 const gchar  *data,
                 const gchar  *data_output,
                 gpointer      user_data)
{
  if (parse_check (data, user_data, data_output, NULL)) {
    fprintf (stderr, "*** Test \"%s\" failed\n", filename);
    exit (1);
  }
}
Exemple #5
0
static void
success_tests_item (const gchar  *filename,
                    const gchar  *data,
                    const gchar  *data_output,
                    gpointer      user_data)
{
  GError *err = NULL;
  
  if (! parse_check (data, user_data, data_output, &err)) {
    fprintf (stderr, "*** Test \"%s\" failed: %s\n", filename, err->message);
    g_error_free (err);
    exit (1);
  }
}
Exemple #6
0
void sinsp_filter::compile(const string& fltstr)
{
	m_fltstr = fltstr;
	m_scansize = (uint32_t)m_fltstr.size();

	while(true)
	{
		char a = next();

		switch(a)
		{
		case 0:
			//
			// Finished parsing the filter string
			//
			if(m_nest_level != 0)
			{
				throw sinsp_exception("filter error: unexpected end of filter");
			}

			if(m_state != ST_EXPRESSION_DONE)
			{
				throw sinsp_exception("filter error: unexpected end of filter at position " + to_string((long long) m_scanpos));
			}

			//
			// Good filter
			//
			return;

			break;
		case '(':
			if(m_state != ST_NEED_EXPRESSION)
			{
				throw sinsp_exception("unexpected '(' after " + m_fltstr.substr(0, m_scanpos));
			}

			push_expression(m_last_boolop);

			break;
		case ')':
			pop_expression();
			break;
		case 'o':
			if(next() == 'r')
			{
				m_last_boolop = BO_OR;
			}
			else
			{
				throw sinsp_exception("syntax error in filter at position " + to_string((long long) m_scanpos));
			}

			if(m_state != ST_EXPRESSION_DONE)
			{
				throw sinsp_exception("unexpected 'or' after " + m_fltstr.substr(0, m_scanpos));
			}

			m_state = ST_NEED_EXPRESSION;

			break;
		case 'a':
			if(next() == 'n' && next() == 'd')
			{
				m_last_boolop = BO_AND;
			}
			else
			{
				throw sinsp_exception("syntax error in filter at position " + to_string((long long) m_scanpos));
			}

			if(m_state != ST_EXPRESSION_DONE)
			{
				throw sinsp_exception("unexpected 'and' after " + m_fltstr.substr(0, m_scanpos));
			}

			m_state = ST_NEED_EXPRESSION;

			break;
		case 'n':
			if(next() == 'o' && next() == 't')
			{
				m_last_boolop = (boolop)((uint32_t)m_last_boolop | BO_NOT);
			}
			else
			{
				throw sinsp_exception("syntax error in filter at position " + to_string((long long) m_scanpos));
			}

			if(m_state != ST_EXPRESSION_DONE && m_state != ST_NEED_EXPRESSION)
			{
				throw sinsp_exception("unexpected 'not' after " + m_fltstr.substr(0, m_scanpos));
			}

			m_state = ST_NEED_EXPRESSION;

			break;
		default:
			parse_check(m_curexpr, m_last_boolop);

			m_state = ST_EXPRESSION_DONE;

			break;
		}
	}

	vector<string> components = sinsp_split(m_fltstr, ' ');
}
Exemple #7
0
/* parse commands */
static int config_parse_command (struct configuration *config, 
			 const char *command, char *arg, int num) {  
    char *tmp;
  
    /* remove trailing whitespace from argument */
    tmp = arg + strnlen(arg, LINEMAX) - 1;
    while (isblank(*tmp)) {
        *tmp = 0;
        tmp--;
    }
  
    /*
     * note: because of the simplistic match function currently
     * implemented, each command name MUST NOT be a prefix of any other
     * command name; otherwise, the shorter name will be matched rather
     * than the longer one
     */

    if (match(command, "interface")) {
        parse_check(parse_string(&config->interface, arg, num));

    } else if (match(command, "promisc")) {
        parse_check(parse_bool(&config->promisc, arg, num));

    } else if (match(command, "daemon")) {
        parse_check(parse_bool(&config->daemon, arg, num));

    } else if (match(command, "output")) {
        parse_check(parse_string(&config->filename, arg, num));

    } else if (match(command, "outdir")) {
        parse_check(parse_string(&config->outputdir, arg, num));

    } else if (match(command, "log")) {
        parse_check(parse_string(&config->logfile, arg, num));

    } else if (match(command, "upload")) {
        parse_check(parse_string(&config->upload_servername, arg, num));

    } else if (match(command, "keyfile")) {
        parse_check(parse_string(&config->upload_key, arg, num));

    } else if (match(command, "model")) {
        parse_check(parse_string(&config->params_file, arg, num));

    } else if (match(command, "label")) {
        parse_check(parse_string_multiple(config->subnet, arg, num, config->num_subnets++, MAX_NUM_FLAGS));

    } else if (match(command, "retain")) {
        parse_check(parse_bool(&config->retain_local, arg, num));

    } else if (match(command, "zeros")) {
        parse_check(parse_bool(&config->include_zeroes, arg, num));

    } else if (match(command, "bidir")) {
        parse_check(parse_bool(&config->bidir, arg, num));

    } else if (match(command, "dist")) {
        parse_check(parse_bool(&config->byte_distribution, arg, num));

    } else if (match(command, "cdist")) {
        parse_check(parse_string(&config->compact_byte_distribution, arg, num));

    } else if (match(command, "entropy")) {
        parse_check(parse_bool(&config->report_entropy, arg, num));

    } else if (match(command, "hd")) {
        parse_check(parse_int(&config->report_hd, arg, num, 0, HDR_DSC_LEN));

    } else if (match(command, "tls")) {
        parse_check(parse_bool(&config->include_tls, arg, num));

    } else if (match(command, "classify")) {
        parse_check(parse_bool(&config->include_classifier, arg, num));

    } else if (match(command, "bpf")) {
        parse_check(parse_string(&config->bpf_filter_exp, arg, num));

    } else if (match(command, "verbosity")) {
        parse_check(parse_int(&config->output_level, arg, num, 0, 3));

    } else if (match(command, "num_pkts")) {
        parse_check(parse_int(&config->num_pkts, arg, num, 0, MAX_NUM_PKT_LEN));

    } else if (match(command, "type")) {
        parse_check(parse_int(&config->type, arg, num, 1, 2));
  
    } else if (match(command, "count")) {
        parse_check(parse_int(&config->max_records, arg, num, 1, INT_MAX));

    } else if (match(command, "idp")) {
        parse_check(parse_int(&config->idp, arg, num, 0, MAX_IDP));

    } else if (match(command, "nfv9_port")) {
        parse_check(parse_int(&config->nfv9_capture_port, arg, num, 0, 0xffff));

    } else if (match(command, "ipfix_cap_port")) {
        parse_check(parse_int(&config->ipfix_capture_port, arg, num, 0, 0xffff));

    } else if (match(command, "nat")) {
        parse_check(parse_bool(&config->flow_key_match_method, arg, num));

    } else if (match(command, "http")) {
        parse_check(parse_bool(&config->http, arg, num));

    } else if (match(command, "anon")) {
        parse_check(parse_string(&config->anon_addrs_file, arg, num));

    } else if (match(command, "useranon")) {
        parse_check(parse_string(&config->anon_http_file, arg, num));

    } else if (match(command, "exe")) {
        parse_check(parse_bool(&config->report_exe, arg, num));

    }

    config_all_features_bool(feature_list);

    return failure;
}