Beispiel #1
0
static void _create_arg_index(char_t *pbeg,char_t *pend, std::vector<const char_t *> &idx)
{
	assert(pbeg==pend||_istspace((ushort)pend[-1]));

	char_t *px=pbeg;

	while(px<pend)
	{
		char_t *pbx=_skip_space(px,pend);
		char_t *pex=_skip_non_str_non_space(pbx,pend);

		if(pbx!=pex)
		{
			_cvt_cmd_string(pbx,pex);
			idx.push_back(pbx);
			px=pex+1;
		}
		else
		{
			assert(pex==pend);

			px=pend;
		}
	}
}
Beispiel #2
0
Lexer::Token Lexer::token()
{
    m_identifier.clear();
    if (!m_reader.at())
        return CONST_T_IDENTIFIER;
    char c = _skip_space(m_reader);
    switch (c)
    {
    case '(' : m_reader.next();                       return CONST_T_OPEN_LIST;
    case ')' : m_reader.next();                       return CONST_T_CLOSE_LIST;
    case '\'': m_reader.next();                       return CONST_T_QUOTE;
	case '\"': m_reader.string_literal(m_identifier); return CONST_T_LITERAL;
    }
    if (m_reader.numeric_literal(m_identifier))
        return CONST_T_NUMERIC;
    m_reader.until(m_identifier, " \r\n\t\f();");
    return m_reader.at() || !m_identifier.empty() ? CONST_T_IDENTIFIER : CONST_T_NONE;
}
Beispiel #3
0
http_response_t* http_parser(const char* head)
{
	http_response_t *response = NULL;
	const char_t *s = head;
	const char_t *tmp = NULL;
	int32_t tmp_len = 0;
	http_field_t *field = NULL;

	if (head == NULL)
		return NULL;

	response = (http_response_t *)cc_calloc(1, sizeof(http_response_t));

	s = _skip_space(s);

	response->http_major = 0;
	response->http_minor = 0;
	response->status = 0;
	cc_double_link_cleanup(&response->link);

	//HTTP 1.0 200
	if (_tolower(*s) == 'h' && _tolower(*(s + 1)) == 't' && _tolower(*(s + 2)) == 't' && _tolower(*(s + 3)) == 'p' && *(s + 4) == '/') {
		s = _skip_space(s + 5);

		if (_istdigit(*s)) {
			do
			response->http_major = (response->http_major * 10) + (*s++ - _T('0'));
			while (_istdigit(*s));

			if (*s == '.') {
				s = (s + 1);
				do
				response->http_minor = (response->http_minor * 10) + (*s++ - _T('0'));
				while (_istdigit(*s));
			}
		}

		//get http status
		if (*s == ' ') {
			s = (s + 1);
			do
			response->status = (response->status * 10) + (*s++ - _T('0'));
			while (_istdigit(*s));
		}
	}

	s = strstr(s, CRLF);
	if (s == NULL) {
		cc_free(response);
		return NULL;
	}

	while(*s) {
		field = (http_field_t *)cc_calloc(1, sizeof(http_field_t));

		s = _skip_space(s);
		tmp = s;
		tmp_len = 0;

		while(*tmp){
			tmp++;
			++tmp_len;
			if (*tmp == ':' || *tmp == 0) {
				field->field_name = (char_t *)cc_malloc(sizeof(char_t) * (tmp_len + 1));
				strncpy(field->field_name, s, tmp_len);
				field->field_name[tmp_len] = 0;
				break;
			}
		}

		if (tmp == NULL) {
			cc_free(field->field_name);
			cc_free(field);
			return response;
		}

		s = _skip_space(tmp + 1);
		tmp = s;
		tmp_len = 0;

		while(*tmp){
			tmp++;
			++tmp_len;
			if ((*tmp == CR && *(tmp + 1) == LF) || *tmp == 0) {
				field->field_value = (char_t *)cc_malloc(sizeof(char_t) * (tmp_len + 1));
				strncpy(field->field_value, s, tmp_len);
				field->field_value[tmp_len] = 0;
				break;
			}
		}

		cc_double_link_push_back(&response->link, &field->base_address);

		if(*tmp && (*tmp == CR && *(tmp + 1) == LF)) {
			s = tmp + 2;
			//结尾了
			if(*s && (*s == CR && *(s + 1) == LF))
				return response;
		}

	} 

	return response;
}