Exemplo n.º 1
0
ret_t
cherokee_handler_dbslayer_init (cherokee_handler_dbslayer_t *hdl)
{
	ret_t                              ret;
	cherokee_connection_t             *conn  = HANDLER_CONN(hdl);
	cherokee_handler_dbslayer_props_t *props = HANDLER_DBSLAYER_PROPS(hdl);

	/* Check client headers
	 */
	cherokee_client_headers (hdl);

	/* Get a reference to the target host
	 */
	if (hdl->src_ref == NULL) {
		ret = cherokee_balancer_dispatch (props->balancer, conn, &hdl->src_ref);
		if (ret != ret_ok)
			return ret;
	}

	/* Connect to the MySQL server
	 */
	ret = connect_to_database(hdl);
	if (unlikely (ret != ret_ok))
		return ret;

	/* Send query:
	 * Do not check whether it failed, ::step() will do
	 * it and send an error message if needed.
	 */
	send_query(hdl);

	return ret_ok;
}
Exemplo n.º 2
0
static ret_t
dbslayer_add_headers (cherokee_handler_dbslayer_t *hdl,
		      cherokee_buffer_t           *buffer)
{
	switch (HANDLER_DBSLAYER_PROPS(hdl)->lang) {
	case dwriter_json:
		cherokee_buffer_add_str (buffer, "Content-Type: application/json" CRLF);
		break;
	case dwriter_python:
		cherokee_buffer_add_str (buffer, "Content-Type: application/x-python" CRLF);
		break;
	case dwriter_php:
		cherokee_buffer_add_str (buffer, "Content-Type: application/x-php" CRLF);
		break;
	case dwriter_ruby:
		cherokee_buffer_add_str (buffer, "Content-Type: application/x-ruby" CRLF);
		break;
	case dwriter_xmlrpc:
		cherokee_buffer_add_str (buffer, "Content-Type: application/xml+rpc" CRLF);
		break;
	default:
		SHOULDNT_HAPPEN;
		return ret_error;
	}

	return ret_ok;
}
Exemplo n.º 3
0
static ret_t
connect_to_database (cherokee_handler_dbslayer_t *hdl)
{
	MYSQL                             *conn;
	cherokee_handler_dbslayer_props_t *props      = HANDLER_DBSLAYER_PROPS(hdl);
	cherokee_connection_t             *connection = HANDLER_CONN(hdl);

	conn = mysql_real_connect (hdl->conn,
				   hdl->src_ref->host.buf,
				   props->user.buf,
				   props->password.buf,
				   props->db.buf,
				   hdl->src_ref->port,
				   hdl->src_ref->unix_socket.buf,
				   CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS);
	if (conn == NULL) {
		cherokee_balancer_report_fail (props->balancer, connection, hdl->src_ref);

		connection->error_code = http_bad_gateway;
		return ret_error;
	}

	return ret_ok;
}