Exemplo n.º 1
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;
}
Exemplo n.º 2
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_free (cherokee_handler_proxy_conn_t *pconn)
{
	cherokee_socket_close    (&pconn->socket);
	cherokee_socket_mrproper (&pconn->socket);

	cherokee_buffer_mrproper (&pconn->post.buf_temp);
	cherokee_buffer_mrproper (&pconn->header_in_raw);

	return ret_ok;
}
Exemplo n.º 4
0
ret_t
cherokee_downloader_mrproper (cherokee_downloader_t *downloader)
{
	/* Free the memory
	 */
	cherokee_request_header_mrproper (&downloader->request);

	cherokee_buffer_mrproper (&downloader->request_header);
	cherokee_buffer_mrproper (&downloader->reply_header);
	cherokee_buffer_mrproper (&downloader->proxy);
	cherokee_buffer_mrproper (&downloader->body);
	cherokee_buffer_mrproper (&downloader->post);

	cherokee_buffer_mrproper (&downloader->tmp1);
	cherokee_buffer_mrproper (&downloader->tmp2);

	cherokee_socket_close (&downloader->socket);
	cherokee_socket_mrproper (&downloader->socket);

	cherokee_header_free (downloader->header);

	return ret_ok;
}