Ejemplo n.º 1
0
int
serve_style_css(struct http_request *req)
{
	int		ret;
	char		*date;
	time_t		tstamp;

	tstamp = 0;
	if (http_request_header_get(req, "if-modified-since", &date)) {
		tstamp = kore_date_to_time(date);
		kore_mem_free(date);

		kore_debug("header was present with %ld", tstamp);
	}

	if (tstamp != 0 && tstamp <= static_mtime_css_style) {
		ret = http_response(req, 304, NULL, 0);
	} else {
		date = kore_time_to_date(static_mtime_css_style);
		if (date != NULL)
			http_response_header_add(req, "last-modified", date);

		http_response_header_add(req, "content-type", "text/css");
		ret = http_response(req, 200, static_css_style,
		    static_len_css_style);
	}

	return (ret);
}
Ejemplo n.º 2
0
int
serve_private(struct http_request *req)
{
	http_response_header_add(req, "content-type", "text/html");
	http_response_header_add(req, "set-cookie", "session_id=test123");
	http_response(req, 200, static_html_private, static_len_html_private);

	return (KORE_RESULT_OK);
}
Ejemplo n.º 3
0
int
serve_index(struct http_request *req)
{
	http_response_header_add(req, "content-type", "text/html");
	http_response(req, 200, static_html_index, static_len_html_index);

	return (KORE_RESULT_OK);
}
Ejemplo n.º 4
0
int
serve_intro(struct http_request *req)
{
	http_response_header_add(req, "content-type", "image/jpg");
	http_response(req, 200, static_jpg_intro, static_len_jpg_intro);

	return (KORE_RESULT_OK);
}
Ejemplo n.º 5
0
int
serve_intro(struct http_request *req)
{
	int		ret;

	http_response_header_add(req, "content-type", "image/jpg");
	ret = http_response(req, 200, static_jpg_intro,
	    static_len_jpg_intro);

	return (ret);
}
Ejemplo n.º 6
0
int
serve_index(struct http_request *req)
{
	int		ret;

	http_response_header_add(req, "content-type", "text/html");
	ret = http_response(req, 200, static_html_index,
	    static_len_html_index);

	return (ret);
}
Ejemplo n.º 7
0
int
serve_b64test(struct http_request *req)
{
	int			i, ret;
	u_int32_t		len;
	struct kore_buf		*res;
	u_int8_t		*data;

	res = kore_buf_create(1024);
	for (i = 0; b64tests[i] != NULL; i++)
		test_base64((u_int8_t *)b64tests[i], strlen(b64tests[i]), res);

	data = kore_buf_release(res, &len);

	http_response_header_add(req, "content-type", "text/plain");
	ret = http_response(req, 200, data, len);
	kore_mem_free(data);

	return (ret);
}
Ejemplo n.º 8
0
int
serve_file_upload(struct http_request *req)
{
	int			r;
	u_int8_t		*d;
	struct kore_buf		*b;
	u_int32_t		len;
	char			*name, buf[BUFSIZ];

	b = kore_buf_create(static_len_html_upload);
	kore_buf_append(b, static_html_upload, static_len_html_upload);

	if (req->method == HTTP_METHOD_POST) {
		http_populate_multipart_form(req, &r);
		if (http_argument_get_string("firstname", &name, &len)) {
			kore_buf_replace_string(b, "$firstname$", name, len);
		} else {
			kore_buf_replace_string(b, "$firstname$", NULL, 0);
		}

		if (http_file_lookup(req, "file", &name, &d, &len)) {
			snprintf(buf, sizeof(buf), "%s is %d bytes", name, len);
			kore_buf_replace_string(b,
			    "$upload$", buf, strlen(buf));
		} else {
			kore_buf_replace_string(b, "$upload$", NULL, 0);
		}
	} else {
		kore_buf_replace_string(b, "$upload$", NULL, 0);
		kore_buf_replace_string(b, "$firstname$", NULL, 0);
	}

	d = kore_buf_release(b, &len);

	http_response_header_add(req, "content-type", "text/html");
	http_response(req, 200, d, len);
	kore_mem_free(d);

	return (KORE_RESULT_OK);
}
Ejemplo n.º 9
0
int
serve_params_test(struct http_request *req)
{
	struct kore_buf		*b;
	u_int8_t		*d;
	u_int32_t		len;
	int			r, i;
	char			*test, name[10];

	http_populate_arguments(req);

	b = kore_buf_create(static_len_html_params);
	kore_buf_append(b, static_html_params, static_len_html_params);

	/*
	 * The GET parameters will be filtered out on POST.
	 */
	if (http_argument_get_string("arg1", &test, &len)) {
		kore_buf_replace_string(b, "$arg1$", test, len);
	} else {
		kore_buf_replace_string(b, "$arg1$", NULL, 0);
	}

	if (http_argument_get_string("arg2", &test, &len)) {
		kore_buf_replace_string(b, "$arg2$", test, len);
	} else {
		kore_buf_replace_string(b, "$arg2$", NULL, 0);
	}

	if (req->method == HTTP_METHOD_GET) {
		kore_buf_replace_string(b, "$test1$", NULL, 0);
		kore_buf_replace_string(b, "$test2$", NULL, 0);
		kore_buf_replace_string(b, "$test3$", NULL, 0);

		if (http_argument_get_uint16("id", &r))
			kore_log(LOG_NOTICE, "id: %d", r);
		else
			kore_log(LOG_NOTICE, "No id set");

		http_response_header_add(req, "content-type", "text/html");
		d = kore_buf_release(b, &len);
		http_response(req, 200, d, len);
		kore_mem_free(d);

		return (KORE_RESULT_OK);
	}

	for (i = 1; i < 4; i++) {
		snprintf(name, sizeof(name), "test%d", i);
		if (http_argument_get_string(name, &test, &len)) {
			snprintf(name, sizeof(name), "$test%d$", i);
			kore_buf_replace_string(b, name, test, len);
		} else {
			snprintf(name, sizeof(name), "$test%d$", i);
			kore_buf_replace_string(b, name, NULL, 0);
		}
	}

	http_response_header_add(req, "content-type", "text/html");
	d = kore_buf_release(b, &len);
	http_response(req, 200, d, len);
	kore_mem_free(d);

	return (KORE_RESULT_OK);
}