Example #1
0
static int line_end_callback(int count, int key) {
    reset_indent();
    int end = line_end(rl_point);
    int flush_right = rl_point == end;
    rl_point = flush_right ? rl_end : end;
    return 0;
}
Example #2
0
static int process_escape(t_tokenline *tl)
{
	if (tl->escape_len == 4) {
		if (!strncmp(tl->escape, "\x1b\x5b\x33\x7e", 4)) {
			/* Delete */
			line_delete_char(tl);
		} else if (!strncmp(tl->escape, "\x1b\x5b\x31\x7e", 4)) {
			/* Home */
			line_home(tl);
		} else if (!strncmp(tl->escape, "\x1b\x5b\x34\x7e", 4)) {
			/* End */
			line_end(tl);
		}
	} else if (tl->escape_len == 3) {
		if (!strncmp(tl->escape, "\x1b\x5b\x41", 3)) {
			/* Up arrow */
			history_up(tl);
		} else if (!strncmp(tl->escape, "\x1b\x5b\x42", 3)) {
			/* Down arrow */
			history_down(tl);
		} else if (!strncmp(tl->escape, "\x1b\x5b\x44", 3)) {
			/* Left arrow */
			if (tl->pos > 0) {
				tl->pos--;
				tl->print(tl->user, "\x1b\x5b\x31\x44");
			}
		} else if (!strncmp(tl->escape, "\x1b\x5b\x43", 3)) {
			/* Right arrow */
			if (tl->pos < tl->buf_len) {
				tl->pos++;
				tl->print(tl->user, "\x1b\x5b\x31\x43");
			}
		} else if (!strncmp(tl->escape, "\x1b\x4f\x48", 3)) {
			/* Home */
			line_home(tl);
		} else if (!strncmp(tl->escape, "\x1b\x4f\x46", 3)) {
			/* End */
			line_end(tl);
		} else
			return FALSE;
	} else
		return FALSE;

	return TRUE;
}
Example #3
0
static int down_callback(int count, int key) {
    reset_indent();
    int j = line_end(rl_point);
    if (j < rl_end) {
        int i = line_start(rl_point);
        if (i == 0) rl_point += prompt_length;
        rl_point += j - i + 1;
        int k = line_end(j+1);
        if (rl_point > k) rl_point = k;
        return 0;
    } else {
        if (last_hist_offset >= 0) {
            history_set_pos(last_hist_offset);
            last_hist_offset = -1;
        }
        return rl_get_next_history(count, key);
    }
}
Example #4
0
static int line_kill_callback(int count, int key) {
    reset_indent();
    int end = line_end(rl_point);
    int flush_right = rl_point == end;
    int kill = flush_right ? end + prompt_length + 1 : end;
    if (kill > rl_end) kill = rl_end;
    rl_kill_text(rl_point, kill);
    return 0;
}
Example #5
0
BOOST_AUTO_TEST_CASE_TEMPLATE(test_nonstandard, Range, checker_test_types) {

	request_checker checker(MAX_REQUEST_SIZE);
	is_line_end<char> line_end;
	Range range = as<Range>("GET / HTTP/1.1\nHost: xiva.yandex.net\n\n");

	std::pair<typename Range::iterator, bool> result = checker(range.begin(), range.end());
	BOOST_CHECK(line_end(*result.first));
	BOOST_CHECK(result.second);
}
Example #6
0
static int up_callback(int count, int key) {
    reset_indent();
    int i = line_start(rl_point);
    if (i > 0) {
        int j = line_start(i-1);
        if (j == 0) rl_point -= prompt_length;
        rl_point += j - i;
        if (rl_point >= i) rl_point = i - 1;
    } else {
        last_hist_offset = -1;
        rl_get_previous_history(count, key);
        rl_point = line_end(0);
    }
    return 0;
}
/*
 * parse the first line (by first_line_fn) and headers
 * return -1 if the message is too long or non-standard
 */
static int
parse_general_http(struct parser *req, int (*first_line_fn)(struct parser *p))
{
        enum parse_state p_state = REQUEST_LINE;
        while (1) {
                if (req->parse_start >= req->parse_end) {
                        int ret = try_read(req, (req->recv_buf_end - req->parse_end));
                        if (ret == 0 || ret == -1) {  /* 0 means client closed */
                                syslog(LOG_INFO, "early close");
                                return -1;
                        }
                }

                char *p = line_end(req);
                if (!p) {
                        syslog(LOG_CRIT, "The headers are too long to handle");
                        return -1;
                }

                switch (p_state) {
                case REQUEST_LINE:
                        if (first_line_fn(req) == -1) {
                                syslog(LOG_CRIT, "The 1st line is bad");
                                return -1;
                        }
                        p_state = HEADER_LINES;
                        break;
                case HEADER_LINES:
                        if (p == req->parse_start) {  /* meeting 2 CRLF: end of headers */
                                req->parse_start += 2;
                                return 0;
                        }
                        if (parse_header_line(req) == -1) {
                                syslog(LOG_CRIT, "The header line is bad");
                                return -1;
                        }
                        break;
                }
        }
}