Exemplo n.º 1
0
char *test_parser_thrashing()
{
    glob_t test_files;
    unsigned int i = 0;
    int nparsed = 0;
    int delta = 0;
    int tests_run = 0;
    int execs_run = 0;
    int unfinished = 0;
    int errors = 0;

    int rc = glob("tests/and_suite/*", 0, NULL, &test_files);
    mu_assert(rc == 0, "Failed to glob file sin tests/and_suite/*");

    for(i = 0; i < test_files.gl_pathc; i++) {
        FILE *infile = fopen(test_files.gl_pathv[i], "r");
        mu_assert(infile != NULL, "Failed to open test file.");

        bstring data = bread((bNread)fread, infile);
        fclose(infile);
        mu_assert(data != NULL, "Failed to read test file.");

        tests_run++;

        http_parser p = setup_parser();

        nparsed = 0;
        delta = 0;

        while(nparsed < blength(data)) {
            debug("json PARSING: %d of %d at %s", nparsed, blength(data), bdataofs(data, nparsed));

            delta = http_parser_execute(&p, bdata(data), blength(data), nparsed);
            execs_run++;

            if(delta == 0) { break; }

            if(!http_parser_finish(&p)) {
                unfinished++;
            }

            nparsed += delta;

            if(http_parser_has_error(&p)) {
                errors++;
            }

            debug("TEST %s results: delta %d, has_error: %d, is_finished: %d",
                    test_files.gl_pathv[i],
                    nparsed, http_parser_has_error(&p), http_parser_is_finished(&p));

            http_parser_init(&p);  // reset for the next try
        }
    }

    debug("HTTP PARSING: tests_run: %d, execs_run: %d, unfinished: %d, errors: %d",
            tests_run, execs_run, unfinished, errors);

    return NULL;
}
Exemplo n.º 2
0
static int
parse_bind_address(allium_ptcfg *cfg, const char *addrs)
{
	struct bstrList *l;
	struct tagbstring str;
	int i, j;

	assert(NULL != cfg);

	if (NULL == addrs) {
		fprintf(stdout, "ENV-ERROR No Bind Addresses\n");
		return (-1);
	}
	btfromcstr(str, addrs);
	if (0 == btlength(str)) {
		fprintf(stdout, "ENV-ERROR Empty Bind Address\n");
		return (-1);
	}
	l = bsplit(&str, ',');
	if (NULL == l) {
		fprintf(stdout, "ENV-ERROR OOM parsing Bind Addresses\n");
		return (-1);
	}
	if (l->qty != cfg->nr_methods) {
		fprintf(stdout, "ENV-ERROR Malformed Bind Addresses\n");
		bstrListDestroy(l);
		return (-1);
	}
	for (i = 0; i < l->qty; i++) {
		/*
		 * Per pt-spec.txt, the order is identical to the transport
		 * list.  I have no idea what is supposed to happen when
		 * the transport list is wildcarded, so this routine will
		 * currently fail gracefully.
		 */
		j = bstrrchr(l->entry[i], '-');
		if ((j != blength(cfg->methods[i].name)) || bstrncmp(l->entry[i],
			    cfg->methods[i].name, j - 1)) {
			fprintf(stdout, "ENV-ERROR Unexpected method in Bind Address\n");
			bstrListDestroy(l);
			return (-1);
		}
		cfg->methods[i].bind_addr_len = sizeof(cfg->methods[i].bind_addr);
		if (parse_addr(bdataofs(l->entry[i], j + 1),
			    (struct sockaddr *)&cfg->methods[i].bind_addr,
			    &cfg->methods[i].bind_addr_len)) {
			fprintf(stdout, "ENV-ERROR Invalid address in Bind Address (%s)\n",
			    bdata(l->entry[i]));
			bstrListDestroy(l);
			return (-1);
		}
		cfg->methods[i].has_bind_addr = 1;
	}
	bstrListDestroy(l);

	return (0);
}
Exemplo n.º 3
0
void Parse_print_error(const char *message, bstring content, int at, int line_number)
{
    int prev_nl = bstrrchrp(content, '\n', at);
    int next_nl = bstrchrp(content, '\n', at);

    if(prev_nl < 0) {
        log_err("%s AT '%c' on line %d:\n%.*s\n%*s", message,
                bchar(content, at), line_number-1, 
                next_nl, bdata(content),
                at, "^");
    } else {
        log_err("%s AT '%c' on line %d:%.*s\n%*s", message,
                bchar(content, at), line_number, 
                next_nl - prev_nl, bdataofs(content, prev_nl),
                at - prev_nl, "^");
    }
}
Exemplo n.º 4
0
tst_t *Parse_config_string(bstring content) 
{
    Token *temp = NULL;
    void *parser = ParseAlloc(malloc);
    check_mem(parser);
    ParserState state = {.settings = NULL, .error = 0, .line_number = 1};

    char *p = bdata(content);
    char *pe = bdataofs(content, blength(content) - 1);
    char *eof = pe;
    int cs = -1;
    int act = -1;
    char *ts = NULL;
    char *te = NULL;

    
#line 114 "src/lexer.c"
	{
	cs = m2sh_lexer_start;
	ts = 0;
	te = 0;
	act = 0;
	}

#line 135 "src/lexer.rl"
    
#line 124 "src/lexer.c"
	{
	if ( p == pe )
		goto _test_eof;
	switch ( cs )
	{
tr1:
#line 77 "src/lexer.rl"
	{te = p+1;{ TKSTR(QSTRING) }}
	goto st6;
tr4:
#line 91 "src/lexer.rl"
	{te = p+1;}
	goto st6;
tr7:
#line 89 "src/lexer.rl"
	{te = p+1;}
	goto st6;
tr9:
#line 88 "src/lexer.rl"
	{te = p+1;{ state.line_number++; }}
	goto st6;
tr10:
#line 83 "src/lexer.rl"
	{te = p+1;{ TK(LPAREN) }}
	goto st6;
tr11:
#line 84 "src/lexer.rl"
	{te = p+1;{ TK(RPAREN) }}
	goto st6;
tr12:
#line 85 "src/lexer.rl"
	{te = p+1;{ TK(COMMA) }}
	goto st6;
tr14:
#line 86 "src/lexer.rl"
	{te = p+1;{ TK(COLON) }}
	goto st6;
tr15:
#line 78 "src/lexer.rl"
	{te = p+1;{ TK(EQ) }}
	goto st6;
tr17:
#line 81 "src/lexer.rl"
	{te = p+1;{ TK(LBRACE) }}
	goto st6;
tr18:
#line 82 "src/lexer.rl"
	{te = p+1;{ TK(RBRACE) }}
	goto st6;
tr20:
#line 79 "src/lexer.rl"
	{te = p+1;{ TK(LBRACKET) }}
	goto st6;
tr21:
#line 80 "src/lexer.rl"
	{te = p+1;{ TK(RBRACKET) }}
	goto st6;
tr22:
#line 93 "src/lexer.rl"
	{te = p;p--;{ TK(NUMBER) }}
	goto st6;
tr23:
#line 1 "NONE"
	{	switch( act ) {
	case 15:
	{{p = ((te))-1;} TK(CLASS) }
	break;
	case 16:
	{{p = ((te))-1;} TK(IDENT) }
	break;
	}
	}
	goto st6;
tr25:
#line 95 "src/lexer.rl"
	{te = p;p--;{ TK(IDENT) }}
	goto st6;
st6:
#line 1 "NONE"
	{ts = 0;}
	if ( ++p == pe )
		goto _test_eof6;
case 6:
#line 1 "NONE"
	{ts = p;}
#line 210 "src/lexer.c"
	switch( (*p) ) {
		case 10: goto tr9;
		case 32: goto tr7;
		case 34: goto st1;
		case 35: goto st3;
		case 39: goto st4;
		case 40: goto tr10;
		case 41: goto tr11;
		case 44: goto tr12;
		case 58: goto tr14;
		case 61: goto tr15;
		case 91: goto tr17;
		case 93: goto tr18;
		case 95: goto st9;
		case 123: goto tr20;
		case 125: goto tr21;
	}
	if ( (*p) < 48 ) {
		if ( 9 <= (*p) && (*p) <= 13 )
			goto tr7;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st9;
		} else if ( (*p) >= 65 )
			goto tr16;
	} else
		goto st7;
	goto st0;
st0:
cs = 0;
	goto _out;
st1:
	if ( ++p == pe )
		goto _test_eof1;
case 1:
	switch( (*p) ) {
		case 34: goto tr1;
		case 92: goto st2;
	}
	goto st1;
st2:
	if ( ++p == pe )
		goto _test_eof2;
case 2:
	goto st1;
st3:
	if ( ++p == pe )
		goto _test_eof3;
case 3:
	if ( (*p) == 10 )
		goto tr4;
	goto st3;
st4:
	if ( ++p == pe )
		goto _test_eof4;
case 4:
	switch( (*p) ) {
		case 39: goto tr1;
		case 92: goto st5;
	}
	goto st4;
st5:
	if ( ++p == pe )
		goto _test_eof5;
case 5:
	goto st4;
st7:
	if ( ++p == pe )
		goto _test_eof7;
case 7:
	if ( 48 <= (*p) && (*p) <= 57 )
		goto st7;
	goto tr22;
tr16:
#line 1 "NONE"
	{te = p+1;}
#line 95 "src/lexer.rl"
	{act = 16;}
	goto st8;
tr24:
#line 1 "NONE"
	{te = p+1;}
#line 94 "src/lexer.rl"
	{act = 15;}
	goto st8;
st8:
	if ( ++p == pe )
		goto _test_eof8;
case 8:
#line 301 "src/lexer.c"
	if ( (*p) == 95 )
		goto st9;
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st9;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto tr24;
	} else
		goto tr24;
	goto tr23;
st9:
	if ( ++p == pe )
		goto _test_eof9;
case 9:
	if ( (*p) == 95 )
		goto st9;
	if ( (*p) < 65 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st9;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto st9;
	} else
		goto st9;
	goto tr25;
	}
	_test_eof6: cs = 6; goto _test_eof; 
	_test_eof1: cs = 1; goto _test_eof; 
	_test_eof2: cs = 2; goto _test_eof; 
	_test_eof3: cs = 3; goto _test_eof; 
	_test_eof4: cs = 4; goto _test_eof; 
	_test_eof5: cs = 5; goto _test_eof; 
	_test_eof7: cs = 7; goto _test_eof; 
	_test_eof8: cs = 8; goto _test_eof; 
	_test_eof9: cs = 9; goto _test_eof; 

	_test_eof: {}
	if ( p == eof )
	{
	switch ( cs ) {
	case 7: goto tr22;
	case 8: goto tr23;
	case 9: goto tr25;
	}
	}

	_out: {}
	}

#line 136 "src/lexer.rl"


    if(state.error) {
        Parse_print_error("SYNTAX ERROR", content, 
                (int)(ts - bdata(content)), ++state.line_number);
    } else if( cs == 
#line 359 "src/lexer.c"
0
#line 141 "src/lexer.rl"
 ) {
        Parse_print_error("INVALID CHARACTER", content,
                (int)(ts - bdata(content)), ++state.line_number);
    } else if( cs >= 
#line 366 "src/lexer.c"
6
#line 144 "src/lexer.rl"
 ) {
        Parse(parser, TKEOF, NULL, &state);
    } else {
        log_err("INCOMPLETE CONFIG FILE. There needs to be more to this.");
    }

    Parse(parser, 0, 0, &state);
    ParseFree(parser, free);

    return state.settings;

error:
    if(state.error) {
        Parse_print_error("SYNTAX ERROR", content, 
                (int)(ts - bdata(content)), ++state.line_number);
    }
    ParseFree(parser, free);
    return NULL;
}


tst_t *Parse_config_file(const char *path)
{
    FILE *script;
    bstring buffer = NULL;
    tst_t *settings = NULL;

    script = fopen(path, "r");
    check(script, "Failed to open file: %s", path);

    buffer = bread((bNread)fread, script);
    check_mem(buffer);

    fclose(script); script = NULL;

    // make sure there's a \n at the end
    bconchar(buffer, '\n');

    settings = Parse_config_string(buffer);
    check(settings != NULL, "Failed to parse file: %s", path);

    bdestroy(buffer);
    buffer = NULL;

    return settings;

error:
    bdestroy(buffer);
    if(script) fclose(script);
    return NULL;
}
Exemplo n.º 5
0
void cli_params_execute( struct params *fsm, bstring data)
{
	const char *p = bdata(data);
	const char *pe = bdataofs(data, blength(data)); // include \0
    const char *eof = pe;
    Token *temp = NULL;

	
#line 2 "src/cli.c"
	{
	if ( p == pe )
		goto _test_eof;
	switch (  fsm->cs )
	{
tr0:
#line 39 "src/cli.rl"
	{{p = (( fsm->te))-1;}{ TK(BLOB); }}
	goto st4;
tr2:
#line 33 "src/cli.rl"
	{ fsm->te = p+1;{ TKSTR(QSTRING); }}
	goto st4;
tr7:
#line 36 "src/cli.rl"
	{ fsm->te = p+1;}
	goto st4;
tr13:
#line 1 "NONE"
	{	switch(  fsm->act ) {
	case 3:
	{{p = (( fsm->te))-1;} TKSTR(QSTRING); }
	break;
	case 7:
	{{p = (( fsm->te))-1;} TK(BLOB); }
	break;
	}
	}
	goto st4;
tr14:
#line 39 "src/cli.rl"
	{ fsm->te = p;p--;{ TK(BLOB); }}
	goto st4;
tr21:
#line 32 "src/cli.rl"
	{ fsm->te = p;p--;{  TKOPT(2); }}
	goto st4;
tr22:
#line 31 "src/cli.rl"
	{ fsm->te = p;p--;{  TKOPT(1); }}
	goto st4;
tr23:
#line 35 "src/cli.rl"
	{ fsm->te = p;p--;{ TK(IDENT); }}
	goto st4;
tr24:
#line 34 "src/cli.rl"
	{ fsm->te = p;p--;{ TK(NUMBER); }}
	goto st4;
st4:
#line 1 "NONE"
	{ fsm->ts = 0;}
	if ( ++p == pe )
		goto _test_eof4;
case 4:
#line 1 "NONE"
	{ fsm->ts = p;}
#line 2 "src/cli.c"
	switch( (*p) ) {
		case 32: goto tr7;
		case 34: goto tr8;
		case 39: goto tr9;
		case 45: goto st10;
		case 46: goto st14;
		case 95: goto st14;
	}
	if ( (*p) < 48 ) {
		if ( 9 <= (*p) && (*p) <= 13 )
			goto tr7;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st14;
		} else if ( (*p) >= 65 )
			goto st14;
	} else
		goto st15;
	goto tr6;
tr6:
#line 1 "NONE"
	{ fsm->te = p+1;}
#line 39 "src/cli.rl"
	{ fsm->act = 7;}
	goto st5;
tr15:
#line 1 "NONE"
	{ fsm->te = p+1;}
#line 33 "src/cli.rl"
	{ fsm->act = 3;}
	goto st5;
st5:
	if ( ++p == pe )
		goto _test_eof5;
case 5:
#line 2 "src/cli.c"
	if ( (*p) == 32 )
		goto tr13;
	if ( 9 <= (*p) && (*p) <= 13 )
		goto tr13;
	goto tr6;
tr8:
#line 1 "NONE"
	{ fsm->te = p+1;}
	goto st6;
st6:
	if ( ++p == pe )
		goto _test_eof6;
case 6:
#line 2 "src/cli.c"
	switch( (*p) ) {
		case 32: goto st0;
		case 34: goto tr15;
		case 92: goto tr16;
	}
	if ( 9 <= (*p) && (*p) <= 13 )
		goto st0;
	goto tr8;
st0:
	if ( ++p == pe )
		goto _test_eof0;
case 0:
	switch( (*p) ) {
		case 34: goto tr2;
		case 92: goto st1;
	}
	goto st0;
st1:
	if ( ++p == pe )
		goto _test_eof1;
case 1:
	goto st0;
tr16:
#line 1 "NONE"
	{ fsm->te = p+1;}
	goto st7;
st7:
	if ( ++p == pe )
		goto _test_eof7;
case 7:
#line 2 "src/cli.c"
	if ( (*p) == 32 )
		goto st0;
	if ( 9 <= (*p) && (*p) <= 13 )
		goto st0;
	goto tr8;
tr9:
#line 1 "NONE"
	{ fsm->te = p+1;}
	goto st8;
st8:
	if ( ++p == pe )
		goto _test_eof8;
case 8:
#line 2 "src/cli.c"
	switch( (*p) ) {
		case 32: goto st2;
		case 39: goto tr15;
		case 92: goto tr17;
	}
	if ( 9 <= (*p) && (*p) <= 13 )
		goto st2;
	goto tr9;
st2:
	if ( ++p == pe )
		goto _test_eof2;
case 2:
	switch( (*p) ) {
		case 39: goto tr2;
		case 92: goto st3;
	}
	goto st2;
st3:
	if ( ++p == pe )
		goto _test_eof3;
case 3:
	goto st2;
tr17:
#line 1 "NONE"
	{ fsm->te = p+1;}
	goto st9;
st9:
	if ( ++p == pe )
		goto _test_eof9;
case 9:
#line 2 "src/cli.c"
	if ( (*p) == 32 )
		goto st2;
	if ( 9 <= (*p) && (*p) <= 13 )
		goto st2;
	goto tr9;
st10:
	if ( ++p == pe )
		goto _test_eof10;
case 10:
	switch( (*p) ) {
		case 32: goto tr14;
		case 45: goto st11;
		case 46: goto st13;
		case 95: goto st13;
	}
	if ( (*p) < 65 ) {
		if ( 9 <= (*p) && (*p) <= 13 )
			goto tr14;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto st13;
	} else
		goto st13;
	goto tr6;
st11:
	if ( ++p == pe )
		goto _test_eof11;
case 11:
	switch( (*p) ) {
		case 32: goto tr14;
		case 46: goto st12;
		case 95: goto st12;
	}
	if ( (*p) < 65 ) {
		if ( 9 <= (*p) && (*p) <= 13 )
			goto tr14;
	} else if ( (*p) > 90 ) {
		if ( 97 <= (*p) && (*p) <= 122 )
			goto st12;
	} else
		goto st12;
	goto tr6;
st12:
	if ( ++p == pe )
		goto _test_eof12;
case 12:
	switch( (*p) ) {
		case 32: goto tr21;
		case 46: goto st12;
		case 95: goto st12;
	}
	if ( (*p) < 48 ) {
		if ( 9 <= (*p) && (*p) <= 13 )
			goto tr21;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st12;
		} else if ( (*p) >= 65 )
			goto st12;
	} else
		goto st12;
	goto tr6;
st13:
	if ( ++p == pe )
		goto _test_eof13;
case 13:
	switch( (*p) ) {
		case 32: goto tr22;
		case 46: goto st13;
		case 95: goto st13;
	}
	if ( (*p) < 48 ) {
		if ( 9 <= (*p) && (*p) <= 13 )
			goto tr22;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st13;
		} else if ( (*p) >= 65 )
			goto st13;
	} else
		goto st13;
	goto tr6;
st14:
	if ( ++p == pe )
		goto _test_eof14;
case 14:
	switch( (*p) ) {
		case 32: goto tr23;
		case 46: goto st14;
		case 95: goto st14;
	}
	if ( (*p) < 48 ) {
		if ( 9 <= (*p) && (*p) <= 13 )
			goto tr23;
	} else if ( (*p) > 57 ) {
		if ( (*p) > 90 ) {
			if ( 97 <= (*p) && (*p) <= 122 )
				goto st14;
		} else if ( (*p) >= 65 )
			goto st14;
	} else
		goto st14;
	goto tr6;
st15:
	if ( ++p == pe )
		goto _test_eof15;
case 15:
	if ( (*p) == 32 )
		goto tr24;
	if ( (*p) > 13 ) {
		if ( 48 <= (*p) && (*p) <= 57 )
			goto st15;
	} else if ( (*p) >= 9 )
		goto tr24;
	goto tr6;
	}
	_test_eof4:  fsm->cs = 4; goto _test_eof; 
	_test_eof5:  fsm->cs = 5; goto _test_eof; 
	_test_eof6:  fsm->cs = 6; goto _test_eof; 
	_test_eof0:  fsm->cs = 0; goto _test_eof; 
	_test_eof1:  fsm->cs = 1; goto _test_eof; 
	_test_eof7:  fsm->cs = 7; goto _test_eof; 
	_test_eof8:  fsm->cs = 8; goto _test_eof; 
	_test_eof2:  fsm->cs = 2; goto _test_eof; 
	_test_eof3:  fsm->cs = 3; goto _test_eof; 
	_test_eof9:  fsm->cs = 9; goto _test_eof; 
	_test_eof10:  fsm->cs = 10; goto _test_eof; 
	_test_eof11:  fsm->cs = 11; goto _test_eof; 
	_test_eof12:  fsm->cs = 12; goto _test_eof; 
	_test_eof13:  fsm->cs = 13; goto _test_eof; 
	_test_eof14:  fsm->cs = 14; goto _test_eof; 
	_test_eof15:  fsm->cs = 15; goto _test_eof; 

	_test_eof: {}
	if ( p == eof )
	{
	switch (  fsm->cs ) {
	case 5: goto tr13;
	case 6: goto tr14;
	case 0: goto tr0;
	case 1: goto tr0;
	case 7: goto tr14;
	case 8: goto tr14;
	case 2: goto tr0;
	case 3: goto tr0;
	case 9: goto tr14;
	case 10: goto tr14;
	case 11: goto tr14;
	case 12: goto tr21;
	case 13: goto tr22;
	case 14: goto tr23;
	case 15: goto tr24;
	}
	}

	}

#line 62 "src/cli.rl"
}
Exemplo n.º 6
0
static int
parse_server_xport_options(allium_ptcfg *cfg, const char *options)
{
	struct bstrList *l;
	struct tagbstring str;
	int i;

	assert(NULL != cfg);

	if ((NULL == options) || (0 == strlen(options)))
		return (0);

	btfromcstr(str, options);
	l = bsplit(&str, ';');
	if (NULL == l) {
		fprintf(stdout, "ENV-ERROR OOM parsing Transport Options\n");
		return (-1);
	}
	for (i = 0; i < l->qty; /* See next_i */) {
		bstring arg_str;
		int next_i = i + 1;

		if (0 == blength(l->entry[i])) {
out_malformed:
			fprintf(stdout, "ENV-ERROR Malformed Transport Option\n");
			bstrListDestroy_safe(l);
			return (-1);
		}

		/*
		 * Allocate arg_str such that realloc will never be called by
		 * bconcat
		 */
		arg_str = bfromcstralloc(btlength(str), bdata(l->entry[i]));
		if (NULL == arg_str) {
out_oom:
			bstrListDestroy_safe(l);
			fprintf(stdout, "ENV-ERROR OOM parsing Transport Options\n");
			return (-1);
		}
		while ('\\' == bchar(arg_str, blength(arg_str) - 1) && next_i < l->qty) {
			*bdataofs(arg_str, blength(arg_str) - 1) = ';';
			if (NULL == l->entry[next_i]) {
				next_i++;
				break;
			}
			if (BSTR_ERR == bconcat(arg_str, l->entry[next_i])) {
				bdestroy_safe(arg_str);
				goto out_oom;
			}
			next_i++;
		}
		if (parse_server_xport_option(cfg, arg_str)) {
			/*
			 * XXX: This also will claim that the option is
			 * malformed if a malloc fails in the subroutine.
			 * However if that happens, you have bigger problems.
			 */
			bdestroy_safe(arg_str);
			goto out_malformed;
		}
		i = next_i;
		bdestroy_safe(arg_str);
	}
	bstrListDestroy_safe(l);

	return (0);
}