Esempio 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);
}
Esempio n. 2
0
int
serve_style_css(struct http_request *req)
{
    char		*date;
    time_t		tstamp;

    tstamp = 0;
    if (http_request_header(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 <= asset_mtime_style_css) {
        http_response(req, 304, NULL, 0);
    } else {
        date = kore_time_to_date(asset_mtime_style_css);
        if (date != NULL)
            http_response_header(req, "last-modified", date);

        http_response_header(req, "content-type", "text/css");
        http_response(req, 200, asset_style_css, asset_len_style_css);
    }

    return (KORE_RESULT_OK);
}
Esempio n. 3
0
int
kore_accesslog_wait(void)
{
	ssize_t			len;
	time_t			now;
	struct kore_domain	*dom;
	struct pollfd		pfd[1];
	int			nfds, l;
	struct kore_log_packet	logpacket;
	char			addr[INET6_ADDRSTRLEN];
	char			*method, *buf, *tbuf, *cn;

	pfd[0].fd = accesslog_fd[0];
	pfd[0].events = POLLIN;
	pfd[0].revents = 0;

	nfds = poll(pfd, 1, 1000);
	if (nfds == -1 || (pfd[0].revents & (POLLERR | POLLHUP | POLLNVAL))) {
		if (nfds == -1 && errno == EINTR)
			return (KORE_RESULT_OK);
		kore_log(LOG_WARNING, "poll(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	if (nfds == 0)
		return (KORE_RESULT_OK);

	len = recv(accesslog_fd[0], &logpacket, sizeof(logpacket), 0);
	if (len == -1) {
		kore_log(LOG_WARNING, "recv(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	if (len != sizeof(logpacket))
		return (KORE_RESULT_ERROR);

	if ((dom = kore_domain_lookup(logpacket.host)) == NULL) {
		kore_log(LOG_WARNING,
		    "got accesslog packet for unknown domain: %s",
		    logpacket.host);
		return (KORE_RESULT_OK);
	}

	switch (logpacket.method) {
	case HTTP_METHOD_GET:
		method = "GET";
		break;
	case HTTP_METHOD_POST:
		method = "POST";
		break;
	default:
		method = "UNKNOWN";
		break;
	}

	if (logpacket.cn[0] != '\0')
		cn = logpacket.cn;
	else
		cn = "none";

	if (inet_ntop(logpacket.addrtype, &(logpacket.addr),
	    addr, sizeof(addr)) == NULL)
		kore_strlcpy(addr, "unknown", sizeof(addr));

	time(&now);
	tbuf = kore_time_to_date(now);
	l = asprintf(&buf, "[%s] %s %d %s %s (w#%d) (%dms) (%s) (%s)\n",
	    tbuf, addr, logpacket.status, method, logpacket.path,
	    logpacket.worker_id, logpacket.time_req, cn, logpacket.agent);
	if (l == -1) {
		kore_log(LOG_WARNING,
		    "kore_accesslog_wait(): asprintf() == -1");
		return (KORE_RESULT_ERROR);
	}

	len = write(dom->accesslog, buf, l);
	if (len == -1) {
		free(buf);
		kore_log(LOG_WARNING,
		    "kore_accesslog_wait(): write(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	if (len != l)
		kore_log(LOG_NOTICE, "accesslog: %s", buf);

	free(buf);
	return (KORE_RESULT_OK);
}
Esempio n. 4
0
int
kore_accesslog_wait(void)
{
	ssize_t			len;
	time_t			now;
	size_t			slen;
	int			nfds;
	struct kore_domain	*dom;
	struct pollfd		pfd[1];
	struct kore_log_packet	logpacket;
	char			*method, buf[4096], *tbuf;

	pfd[0].fd = accesslog_fd[0];
	pfd[0].events = POLLIN;
	pfd[0].revents = 0;

	nfds = poll(pfd, 1, 1000);
	if (nfds == -1 || (pfd[0].revents & (POLLERR | POLLHUP | POLLNVAL))) {
		if (nfds == -1 && errno == EINTR)
			return (KORE_RESULT_OK);
		kore_log(LOG_WARNING, "poll(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	if (nfds == 0)
		return (KORE_RESULT_OK);

	len = recv(accesslog_fd[0], &logpacket, sizeof(logpacket), 0);
	if (len == -1) {
		kore_log(LOG_WARNING, "recv(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	if (len != sizeof(logpacket))
		return (KORE_RESULT_ERROR);

	if ((dom = kore_domain_lookup(logpacket.host)) == NULL) {
		kore_log(LOG_WARNING,
		    "got accesslog packet for unknown domain: %s",
		    logpacket.host);
		return (KORE_RESULT_OK);
	}

	if (logpacket.method == HTTP_METHOD_GET)
		method = "GET";
	else
		method = "POST";

	time(&now);
	tbuf = kore_time_to_date(now);
	snprintf(buf, sizeof(buf), "[%s] %s %d %s %s (w#%d) (%dms) (%s)\n",
	    tbuf, inet_ntoa(logpacket.src), logpacket.status, method,
	    logpacket.path, logpacket.worker_id, logpacket.time_req,
	    logpacket.agent);
	slen = strlen(buf);

	len = write(dom->accesslog, buf, slen);
	if (len == -1) {
		kore_log(LOG_WARNING,
		    "kore_accesslog_wait(): write(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	if ((size_t)len != slen)
		kore_log(LOG_NOTICE, "accesslog: %s", buf);

	return (KORE_RESULT_OK);
}
Esempio n. 5
0
int
kore_accesslog_write(const void *data, u_int32_t len)
{
	int			l;
	time_t			now;
	ssize_t			sent;
	struct kore_domain	*dom;
	struct kore_log_packet	logpacket;
	char			addr[INET6_ADDRSTRLEN];
	char			*method, *buf, *tbuf, *cn;

	if (len != sizeof(struct kore_log_packet))
		return (KORE_RESULT_ERROR);

	(void)memcpy(&logpacket, data, sizeof(logpacket));

	if ((dom = kore_domain_lookup(logpacket.host)) == NULL) {
		kore_log(LOG_WARNING,
		    "got accesslog packet for unknown domain: %s",
		    logpacket.host);
		return (KORE_RESULT_OK);
	}

	switch (logpacket.method) {
	case HTTP_METHOD_GET:
		method = "GET";
		break;
	case HTTP_METHOD_POST:
		method = "POST";
		break;
	case HTTP_METHOD_PUT:
		method = "PUT";
		break;
	case HTTP_METHOD_DELETE:
		method = "DELETE";
		break;
	case HTTP_METHOD_HEAD:
		method = "HEAD";
		break;
	default:
		method = "UNKNOWN";
		break;
	}

	cn = "none";
#if !defined(KORE_NO_TLS)
	if (logpacket.cn[0] != '\0')
		cn = logpacket.cn;
#endif

	if (inet_ntop(logpacket.addrtype, &(logpacket.addr),
	    addr, sizeof(addr)) == NULL)
		(void)kore_strlcpy(addr, "unknown", sizeof(addr));

	time(&now);
	tbuf = kore_time_to_date(now);
	l = asprintf(&buf, "[%s] %s %d %s %s (w#%d) (%dms) (%s) (%s)\n",
	    tbuf, addr, logpacket.status, method, logpacket.path,
	    logpacket.worker_id, logpacket.time_req, cn, logpacket.agent);
	if (l == -1) {
		kore_log(LOG_WARNING,
		    "kore_accesslog_write(): asprintf() == -1");
		return (KORE_RESULT_ERROR);
	}

	sent = write(dom->accesslog, buf, l);
	if (sent == -1) {
		free(buf);
		kore_log(LOG_WARNING,
		    "kore_accesslog_write(): write(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	if (sent != l)
		kore_log(LOG_NOTICE, "accesslog: %s", buf);

	free(buf);
	return (KORE_RESULT_OK);
}