コード例 #1
0
ファイル: sqlparse.c プロジェクト: loveshell/libinjection
size_t parse_number(const char *cs, const size_t len, size_t pos,
                    stoken_t * st)
{
    if (pos + 1 < len && cs[pos] == '0' && cs[pos + 1] == 'X') {
        // TBD compare if isxdigit
        size_t len = strspn(cs + pos + 2, "0123456789ABCDEF");
        if (len == 0) {
            st_assign_cstr(st, 'n', "0X");
            return pos + 2;
        } else {
            st_assign(st, '1', cs, 2 + len);
            return pos + 2 + len;
        }
    }
    size_t start = pos;

    while (isdigit(cs[pos])) {
        pos += 1;
    }
    if (cs[pos] == '.') {
        pos += 1;
        while (pos < len && isdigit(cs[pos])) {
            pos += 1;
        }
        if (pos - start == 1) {
            st_assign_char(st, 'n', '.');
            return pos;
        }
    }

    if (cs[pos] == 'E') {
        pos += 1;
        if (pos < len && (cs[pos] == '+' || cs[pos] == '-')) {
            pos += 1;
        }
        while (isdigit(cs[pos])) {
            pos += 1;
        }
    } else if (isalpha(cs[pos])) {
        // oh no, we have something like '6FOO'
        // which is not a number, grab as many alphanum
        // as possible
        pos += 1;
        while (pos < len && isalnum(cs[pos])) {
            pos += 1;
        }
        st_assign(st, 'n', cs + start, pos - start);
        return pos;
    }

    st_assign(st, '1', cs + start, pos - start);
    return pos;
}
コード例 #2
0
ファイル: ft_function_cmd.c プロジェクト: janteuni/Zappy
int					ft_function_cmd(t_env *env, int cs, char *rcv)
{
	int				i;
	static t_cmd	cmds[NB_CMDS];
	char			**split;

	split = NULL;
	split = ft_super_split(rcv);
	st_assign(cmds, env);
	i = 0;
	while (i < NB_CMDS)
	{
		if (0 == ft_strcmp(cmds[i].name, split[0]))
		{
			if (i == 9)
				ft_action_incantation(cs, 0, cmds[i].fn, rcv);
			else
				ft_action_add(cs, cmds[i].t, cmds[i].fn, rcv);
			if (i == 10)
				ft_graphic_reply(env, cs, ft_graphic_pfk);
			ft_free_tab((void ***)&split);
			return (OK);
		}
		++i;
	}
	ft_free_tab((void ***)&split);
	return (ERR);
}
コード例 #3
0
ファイル: sqlparse.c プロジェクト: loveshell/libinjection
bool syntax_merge_words(stoken_t * a, stoken_t * b)
{
    if (!
        (a->type == 'k' || a->type == 'n' || a->type == 'o'
         || a->type == 'U')) {
        return false;
    }

    size_t sz1 = strlen(a->val);
    size_t sz2 = strlen(b->val);
    size_t sz3 = sz1 + sz2 + 1;
    if (sz3 >= ST_MAX_SIZE) {
        return false;
    }
    // oddly annoying  last.val + ' ' + current.val
    char tmp[ST_MAX_SIZE];
    memcpy(tmp, a->val, sz1);
    tmp[sz1] = ' ';
    memcpy(tmp + sz1 + 1, b->val, sz2);
    tmp[sz3] = CHAR_NULL;

    //printf("\nTMP = %s\n", tmp);
    char ch = bsearch_keyword_type(tmp, multikeywords, multikeywords_sz);
    if (ch != CHAR_NULL) {
        // -1, don't copy the null byte
        st_assign(a, ch, tmp, sz3);
        return true;
    } else {
        return false;
    }
}
コード例 #4
0
ファイル: sqlparse.c プロジェクト: loveshell/libinjection
size_t parse_slash(const char *cs, const size_t len, size_t pos,
                   stoken_t * st)
{
    size_t pos1 = pos + 1;
    if (pos1 == len || cs[pos1] != '*') {
        return parse_operator1(cs, len, pos, st);
    }
    size_t inc = is_mysql_comment(cs, len, pos);

    if (inc == 0) {
        const char *ptr = strstr(cs + pos, "*/");
        if (ptr == NULL) {
            // unterminated comment
            st_assign_cstr(st, 'c', cs + pos);
            return len;
        } else {
            st_assign(st, 'c', cs + pos, (ptr + 2) - (cs + pos));
            return (ptr - cs) + 2;
        }
    } else {
        // MySQL Comment
        st_clear(st);
        return pos + inc;
    }
}
コード例 #5
0
ファイル: sqlparse.c プロジェクト: loveshell/libinjection
size_t parse_var(const char *cs, const size_t len, size_t pos,
                 stoken_t * st)
{
    size_t pos1 = pos + 1;

    // move past optional other '@'
    if (pos < len && cs[pos1] == '@') {
        pos1 += 1;
    }

    size_t slen =
        strspn(cs + pos1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.$");
    if (slen == 0) {
        st_assign(st, 'v', cs + pos, (pos1 - pos));
        return pos1;
    } else {
        st_assign(st, 'v', cs + pos, slen + (pos1 - pos));
        return pos1 + slen;
    }
}
コード例 #6
0
ファイル: sqlparse.c プロジェクト: loveshell/libinjection
size_t parse_eol_comment(const char *cs, const size_t len, size_t pos,
                         stoken_t * st)
{
    const char *endpos = strchr(cs + pos, '\n');
    if (endpos == NULL) {
        st_assign_cstr(st, 'c', cs + pos);
        return len;
    } else {
        st_assign(st, 'c', cs + pos, endpos - cs - pos);
        return (endpos - cs) + 1;
    }
}
コード例 #7
0
ファイル: sqlparse.c プロジェクト: loveshell/libinjection
size_t parse_word(const char *cs, const size_t UNUSED(len), size_t pos,
                  stoken_t * st)
{
    size_t slen =
        strspn(cs + pos, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.$");
    st_assign(st, 'n', cs + pos, slen);
    if (slen < ST_MAX_SIZE) {
        char ch = bsearch_keyword_type(st->val, keywords, keywords_sz);
        if (ch == CHAR_NULL) {
            ch = 'n';
        }
        st->type = ch;
    }
    return pos + slen;
}
コード例 #8
0
ファイル: sqlparse.c プロジェクト: loveshell/libinjection
size_t parse_string_core(const char *cs, const size_t len, size_t pos,
                         stoken_t * st, char delim, size_t offset)
{
    // offset is to skip the perhaps first quote char
    const char *qpos = strchr(cs + pos + offset, delim);
    while (true) {
        if (qpos == NULL) {
            st_assign_cstr(st, 's', cs + pos);
            return len;
        } else if (*(qpos - 1) != '\\') {
            st_assign(st, 's', cs + pos, qpos - (cs + pos) + 1);
            return qpos - cs + 1;
        } else {
            qpos = strchr(qpos + 1, delim);
        }
    }
}