Esempio n. 1
0
static ret_t
find_empty_port (int starting, int *port)
{
	ret_t             ret;
	cherokee_socket_t s;
	int               p     = starting;
	cherokee_buffer_t bind_ = CHEROKEE_BUF_INIT;

	cherokee_buffer_add_str (&bind_, "127.0.0.1");

	cherokee_socket_init (&s);
	cherokee_socket_set_client (&s, AF_INET);

	while (true) {
		ret = cherokee_socket_bind (&s, p, &bind_);
		if (ret == ret_ok)
			break;

		p += 1;
		if (p > 0XFFFF)
			return ret_error;
	}

	cherokee_socket_close (&s);

	cherokee_socket_mrproper (&s);
	cherokee_buffer_mrproper (&bind_);

	*port = p;
	return ret_ok;
}
ret_t
cherokee_handler_proxy_conn_new (cherokee_handler_proxy_conn_t **pconn)
{
	CHEROKEE_NEW_STRUCT (n, handler_proxy_conn);

	/* Socket stuff
	 */
	cherokee_socket_init (&n->socket);

	n->post.sent        = 0;
	n->post.do_buf_sent = true;
	cherokee_buffer_init (&n->post.buf_temp);

	cherokee_buffer_init (&n->header_in_raw);
	cherokee_buffer_ensure_size (&n->header_in_raw, 512);

	n->poll_ref      = NULL;
	n->keepalive_in  = false;
	n->size_in       = 0;
	n->sent_out      = 0;
	n->enc           = pconn_enc_none;

	*pconn = n;
	return ret_ok;
}
Esempio n. 3
0
ret_t
cherokee_downloader_init (cherokee_downloader_t *n)
{
	ret_t ret;

	/* Build
	 */
	ret = cherokee_request_header_init (&n->request);
	if (unlikely(ret != ret_ok)) return ret;

	ret = cherokee_buffer_init (&n->request_header);
	if (unlikely(ret != ret_ok)) return ret;

	ret = cherokee_buffer_init (&n->reply_header);
	if (unlikely(ret != ret_ok)) return ret;

	ret = cherokee_buffer_init (&n->body);
	if (unlikely(ret != ret_ok)) return ret;

	ret = cherokee_socket_init (&n->socket);
	if (unlikely(ret != ret_ok)) return ret;

	ret = cherokee_header_new (&n->header, header_type_response);
	if (unlikely(ret != ret_ok)) return ret;

	cherokee_buffer_init (&n->proxy);
	n->proxy_port = 0;

	cherokee_buffer_init (&n->tmp1);
	cherokee_buffer_init (&n->tmp2);
	cherokee_buffer_init (&n->post);

	/* Init the properties
	 */
	n->phase             = downloader_phase_init;

	/* Lengths
	 */
	n->content_length    = 0;

	/* Info
	 */
	n->info.request_sent = 0;
	n->info.headers_recv = 0;
	n->info.post_sent    = 0;
	n->info.body_recv    = 0;

	n->status = downloader_status_none;

	return ret_ok;
}
Esempio n. 4
0
static ret_t
match (cherokee_vrule_target_ip_t *vrule,
       cherokee_buffer_t          *host,
       cherokee_connection_t      *conn)
{
	int               re;
	ret_t             ret;
	cherokee_socket_t sock;

	UNUSED (host);

	/* There might not be a connection
	 */
	if (conn == NULL)
		return ret_deny;

	/* Use a temporal socket object
	 */
	ret = cherokee_socket_init (&sock);
	if (unlikely(ret != ret_ok))
		return ret_error;

	/* Copy the server IP
	 */
	sock.client_addr_len = conn->socket.client_addr_len;

	re = getsockname (SOCKET_FD(&conn->socket),
	                  (struct sockaddr *) &(sock.client_addr),
	                  &sock.client_addr_len);
	if (re != 0) {
		TRACE(ENTRIES, "VRule target_ip could %s get the server IP\n", "not");
		goto deny;
	}

	/* Validate it
	 */
	ret = cherokee_access_ip_match (&vrule->access, &sock);
	if (ret != ret_ok) {
		TRACE(ENTRIES, "VRule target_ip did %s match any\n", "not");
		goto deny;
	}

	cherokee_socket_mrproper (&sock);
	TRACE(ENTRIES, "Rule from matched %s", "\n");
	return ret_ok;
deny:

	cherokee_socket_mrproper (&sock);
	return ret_deny;
}