Ejemplo n.º 1
0
const char * smpd_get_string(const char *str, char *val, int maxlen, int *num_chars)
{
    smpd_enter_fn(FCNAME);
    if (maxlen < 1)
    {
	*num_chars = 0;
	smpd_exit_fn(FCNAME);
	return NULL;
    }

    /* line up with the first token */
    str = first_token(str);
    if (str == NULL)
    {
	*num_chars = 0;
	smpd_exit_fn(FCNAME);
	return NULL;
    }

    /* copy the token */
    token_copy(str, val, maxlen);
    *num_chars = (int)strlen(val);

    /* move to the next token */
    str = next_token(str);

    smpd_exit_fn(FCNAME);
    return str;
}
Ejemplo n.º 2
0
static int get_call_id(struct _sipcapture_object *sco, str *source_string)
{

	if(!sco->callid.s || !sco->callid.len) {
		return -1;
	}
	source_string->s = sco->callid.s;
	source_string->len = sco->callid.len;
	first_token(source_string);
	return 0;
}
Ejemplo n.º 3
0
Archivo: http.c Proyecto: s0cks/AngeliC
angelic_http_request*
angelic_http_request_parser_parse(angelic_http_request_parser* parser){
    angelic_http_request* request = angelic_http_request_malloc();
    angelic_buffer* line = next_line(parser);

    if(angelic_buffer_starts_with_str(line, "GET")){
        request->method = angelic_buffer_wrap("GET");
    } else if(angelic_buffer_starts_with_str(line, "POST")){
        request->method = angelic_buffer_wrap("POST");
    } else{
        fprintf(stderr, "Unknown request method: %s\n", angelic_buffer_cstr(line));
        abort();
    }

    parser->pos += line->size;

    angelic_buffer* tmp = angelic_buffer_slice(line, request->method->size + 1, line->size - 1 - request->method->size);
    angelic_buffer* route = first_token(tmp);
    angelic_buffer_putb(request->route, route);
    angelic_buffer_free(route);
    angelic_buffer_free(line);
    angelic_buffer_free(tmp);

    uint8_t c;
    while((c = next_char(parser)) != '\n'){
        angelic_buffer* key = angelic_buffer_malloc(100);
        angelic_buffer* value = angelic_buffer_malloc(100);

        angelic_buffer_putc(key, c);

        while((c = next_char(parser)) != ':'){
            angelic_buffer_putc(key, c);
        }

        parser->pos++;

        while((c = next_char(parser)) != '\n'){
            angelic_buffer_putc(value, c);
        }

        angelic_http_header* header = angelic_http_header_malloc(angelic_buffer_cstr(key), angelic_buffer_cstr(value));
        angelic_http_request_add_header(request, header);
    }

    while((c = next_char(parser)) != -1){
        angelic_buffer_putc(request->body, c);
    }

    return request;
}
Ejemplo n.º 4
0
int smpd_get_string_arg(const char *str, const char *flag, char *val, int maxlen)
{
    smpd_enter_fn(FCNAME);
    if (maxlen < 1)
    {
	smpd_exit_fn(FCNAME);
	return SMPD_FALSE;
    }

    /* line up with the first token */
    str = first_token(str);
    if (str == NULL)
    {
	smpd_exit_fn(FCNAME);
	return SMPD_FALSE;
    }

    /* This loop will match the first instance of "flag = value" in the string. */
    do
    {
	if (compare_token(str, flag) == 0)
	{
	    str = next_token(str);
	    if (compare_token(str, SMPD_DELIM_STR) == 0)
	    {
		str = next_token(str);
		if (str == NULL)
		{
		    smpd_exit_fn(FCNAME);
		    return SMPD_FALSE;
		}
		token_copy(str, val, maxlen);
		smpd_exit_fn(FCNAME);
		return SMPD_TRUE;
	    }
	}
	else
	{
	    str = next_token(str);
	}
    } while (str);
    smpd_exit_fn(FCNAME);
    return SMPD_FALSE;
}
Ejemplo n.º 5
0
STATIC int
pf_gametype_new(char *text, void *_context)
{
	GameTypeContext *context = (GameTypeContext *)_context;
	char *token;
	int key;

	token = first_token(text);
	if (token == NULL) {
		return (0);
	}

	if (strcmp(token, "end") == 0) {
		add_config_type(context->gametype);
		parse_func = pf_top_level;
		parse_context = NULL;
		return (0);
	}

	key = get_config_key(token, new_keys);

	if (key <= 0) {
		return (key);
	}

	token = next_token();
	if (strcmp(token, "=") != 0) {
		REPORT_ERROR((stderr, "Expecting \"=\", found \"%s\"", token));
		return (-1);
	}

	token = next_value();
	if ((token == NULL) && ((key != CK_MASTER_PROTOCOL) && (key != CK_MASTER_QUERY))) {
		REPORT_ERROR((stderr, "Missing value after \"=\""));
		return (-1);
	}

	if (debug) {
		printf("%d %s = <%s>\n", key, new_keys[key - 1].key_name, token ? token : "");
	}

	return (set_game_type_value(context->gametype, key, token));
}
Ejemplo n.º 6
0
STATIC int
pf_gametype_modify(char *text, void *_context)
{
	GameTypeContext *context = (GameTypeContext *)_context;
	char *token;
	int key;

	token = first_token(text);
	if (token == NULL) {
		return (0);
	}

	if (strcmp(token, "end") == 0) {
		parse_func = pf_top_level;
		parse_context = NULL;
		return (0);
	}

	key = get_config_key(token, modify_keys);

	token = next_token();

	if (strcmp(token, "=") != 0) {
		REPORT_ERROR((stderr, "Expecting \"=\", found \"%s\"", token));
		return (-1);
	}

	token = next_value();
	if (token == NULL) {
		REPORT_ERROR((stderr, "Missing value after \"=\""));
		return (-1);
	}

	if (debug) {
		printf("%d %s = <%s>\n", key, modify_keys[key - 1].key_name,
		    token ? token : "");
	}

	return (modify_game_type_value(context->gametype, key, token));
}
Ejemplo n.º 7
0
int smpd_hide_string_arg(char *str, const char *flag)
{
    smpd_enter_fn(FCNAME);
    /* line up with the first token */
    str = (char*)first_token(str);
    if (str == NULL)
    {
	smpd_exit_fn(FCNAME);
	return SMPD_SUCCESS;
    }

    do
    {
	if (compare_token(str, flag) == 0)
	{
	    str = (char*)next_token(str);
	    if (compare_token(str, SMPD_DELIM_STR) == 0)
	    {
		str = (char*)next_token(str);
		if (str == NULL)
		{
		    smpd_exit_fn(FCNAME);
		    return SMPD_SUCCESS;
		}
		token_hide(str);
		smpd_exit_fn(FCNAME);
		return SMPD_SUCCESS;
	    }
	}
	else
	{
	    str = (char*)next_token(str);
	}
    } while (str);
    smpd_exit_fn(FCNAME);
    return SMPD_SUCCESS;
}
Ejemplo n.º 8
0
static int determine_call_id (struct sip_msg *msg, str *source_string) {
	source_string->s = msg->callid->body.s;
	source_string->len = msg->callid->body.len;
	first_token (source_string);
	return 0;
}
Ejemplo n.º 9
0
static const char * next_token(const char *str)
{
    const char *result;

    smpd_enter_fn(FCNAME);
    if (str == NULL)
    {
	smpd_exit_fn(FCNAME);
	return NULL;
    }
    str = first_token(str);
    if (str == NULL)
    {
	smpd_exit_fn(FCNAME);
	return NULL;
    }
    if (*str == SMPD_QUOTE_CHAR)
    {
	/* move over string */
	str++; /* move over the first quote */
	if (*str == '\0')
	{
	    smpd_exit_fn(FCNAME);
	    return NULL;
	}
	while (*str != SMPD_QUOTE_CHAR)
	{
	    /* move until the last quote, ignoring escaped quotes */
	    if (*str == SMPD_ESCAPE_CHAR)
	    {
		str++;
		if (*str == SMPD_QUOTE_CHAR)
		    str++;
	    }
	    else
	    {
		str++;
	    }
	    if (*str == '\0')
	    {
		smpd_exit_fn(FCNAME);
		return NULL;
	    }
	}
	str++; /* move over the last quote */
    }
    else
    {
	if (*str == SMPD_DELIM_CHAR)
	{
	    /* move over the DELIM token */
	    str++;
	}
	else
	{
	    /* move over literal */
	    while (!isspace(*str) && *str != SMPD_DELIM_CHAR && *str != '\0')
		str++;
	}
    }
    result = first_token(str);
    smpd_exit_fn(FCNAME);
    return result;
}
Ejemplo n.º 10
0
static void token_hide(char *token)
{
    smpd_enter_fn(FCNAME);
    /* check parameters */
    if (token == NULL)
    {
	smpd_exit_fn(FCNAME);
	return;
    }

    /* cosy up to the token */
    token = (char*)first_token(token);
    if (token == NULL)
    {
	smpd_exit_fn(FCNAME);
	return;
    }

    if (*token == SMPD_DELIM_CHAR)
    {
	*token = SMPD_HIDE_CHAR;
	smpd_exit_fn(FCNAME);
	return;
    }

    /* quoted */
    if (*token == SMPD_QUOTE_CHAR)
    {
	*token = SMPD_HIDE_CHAR;
	token++; /* move over the first quote */
	while (*token != '\0')
	{
	    if (*token == SMPD_ESCAPE_CHAR)
	    {
		if (*(token+1) == SMPD_QUOTE_CHAR)
		{
		    *token = SMPD_HIDE_CHAR;
		    token++;
		}
		*token = SMPD_HIDE_CHAR;
	    }
	    else
	    {
		if (*token == SMPD_QUOTE_CHAR)
		{
		    *token = SMPD_HIDE_CHAR;
		    smpd_exit_fn(FCNAME);
		    return;
		}
		*token = SMPD_HIDE_CHAR;
	    }
	    token++;
	}
	smpd_exit_fn(FCNAME);
	return;
    }

    /* literal */
    while (*token != SMPD_DELIM_CHAR && !isspace(*token) && *token != '\0')
    {
	*token = SMPD_HIDE_CHAR;
	token++;
    }
    smpd_exit_fn(FCNAME);
}
Ejemplo n.º 11
0
static void token_copy(const char *token, char *str, int maxlen)
{
    smpd_enter_fn(FCNAME);
    /* check parameters */
    if (token == NULL || str == NULL)
    {
	smpd_exit_fn(FCNAME);
	return;
    }

    /* check special buffer lengths */
    if (maxlen < 1)
    {
	smpd_exit_fn(FCNAME);
	return;
    }
    if (maxlen == 1)
    {
	*str = '\0';
	smpd_exit_fn(FCNAME);
	return;
    }

    /* cosy up to the token */
    token = first_token(token);
    if (token == NULL)
    {
	smpd_exit_fn(FCNAME);
	return;
    }

    if (*token == SMPD_DELIM_CHAR)
    {
	/* copy the special deliminator token */
	str[0] = SMPD_DELIM_CHAR;
	str[1] = '\0';
	smpd_exit_fn(FCNAME);
	return;
    }

    if (*token == SMPD_QUOTE_CHAR)
    {
	/* quoted copy */
	token++; /* move over the first quote */
	do
	{
	    if (*token == SMPD_ESCAPE_CHAR)
	    {
		if (*(token+1) == SMPD_QUOTE_CHAR)
		    token++;
		*str = *token;
	    }
	    else
	    {
		if (*token == SMPD_QUOTE_CHAR)
		{
		    *str = '\0';
		    smpd_exit_fn(FCNAME);
		    return;
		}
		*str = *token;
	    }
	    str++;
	    token++;
	    maxlen--;
	} while (maxlen);
	/* we've run out of destination characters so back up and null terminate the string */
	str--;
	*str = '\0';
	smpd_exit_fn(FCNAME);
	return;
    }

    /* literal copy */
    while (*token != SMPD_DELIM_CHAR && !isspace(*token) && *token != '\0' && maxlen)
    {
	*str = *token;
	str++;
	token++;
	maxlen--;
    }
    if (maxlen)
	*str = '\0';
    smpd_exit_fn(FCNAME);
}
Ejemplo n.º 12
0
/* Top level
 *   Keywords: gametype
 */
STATIC int
pf_top_level(char *text, void *_context)
{
	GameTypeContext *context;
	server_type *extend;
	char *token, *game_type, *extend_type;

	token = first_token(text);
	if (token == NULL) {
		return (0);
	}

	if (strcmp(token, "gametype") != 0) {
		REPORT_ERROR((stderr, "Unknown config command \"%s\"", token));
		return (-1);
	}

	game_type = next_token_dup();
	if (game_type == NULL) {
		REPORT_ERROR((stderr, "Missing game type"));
		return (-1);
	}

	force_lower_case(game_type);

	token = next_token();
	if (token == NULL) {
		REPORT_ERROR((stderr, "Expecting \"new\" or \"modify\""));
		return (-1);
	}

	if (strcmp(token, "new") == 0) {
		parse_func = pf_gametype_new;
	} else if (strcmp(token, "modify") == 0) {
		parse_func = pf_gametype_modify;
	} else {
		REPORT_ERROR((stderr, "Expecting \"new\" or \"modify\""));
		return (-1);
	}

	context = (GameTypeContext *)malloc(sizeof(GameTypeContext));
	context->type = game_type;
	context->extend_type = NULL;
	context->gametype = NULL;

	token = next_token();

	if (parse_func == pf_gametype_modify) {
		if (token != NULL) {
			REPORT_ERROR((stderr, "Extra text after gametype modify"));
			return (-1);
		}
		context->gametype = get_server_type(game_type);
		if (context->gametype == NULL) {
			REPORT_ERROR((stderr, "Unknown game type \"%s\"", game_type));
			free(context);
			return (-1);
		}
		parse_context = context;
		return (0);
	}

	if ((token == NULL) || (strcmp(token, "extend") != 0)) {
		REPORT_ERROR((stderr, "Expecting \"extend\""));
		return (-1);
	}

	extend_type = next_token();

	if (extend_type == NULL) {
		REPORT_ERROR((stderr, "Missing extend game type"));
		return (-1);
	}

	force_lower_case(extend_type);

	if (strcasecmp(extend_type, game_type) == 0) {
		REPORT_ERROR((stderr, "Identical game type and extend type"));
		return (-1);
	}

	context->extend_type = extend_type;
	extend = get_server_type(extend_type);
	if (extend == NULL) {
		REPORT_ERROR((stderr, "Unknown extend game type \"%s\"", extend_type));
		return (-1);
	}

	/* Over-write a previous gametype new */
	context->gametype = get_config_type(game_type);
	if (context->gametype == NULL) {
		context->gametype = (server_type *)malloc(sizeof(server_type));
	}
	copy_server_type(context->gametype, extend);

	/* Set flag for new type-id if not re-defining previous config type */
	if (get_config_type(game_type) == NULL) {
		context->gametype->id = 0;
	}

	context->gametype->type_string = game_type;
	context->gametype->type_prefix = strdup(game_type);
	force_upper_case(context->gametype->type_prefix);
	context->gametype->type_option = (char *)malloc(strlen(game_type) + 2);
	context->gametype->type_option[0] = '-';
	strcpy(&context->gametype->type_option[1], game_type);

	parse_context = context;

	return (0);
}