Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implements handler_tile, to be used together with (a modified) form o…

…f renderd, allowing it to render meta tiles, but writing them out as single files.

Opposed to mod_tile which serves meta tiles, we might add this functionality later.

http://code.google.com/p/cherokee/issues/detail?id=683
  • Loading branch information...
commit d76faa49cac7e41915a80a17beb24c8ed3128f6b 1 parent e7daa3d
@skinkie authored
View
2  admin/consts.py
@@ -51,7 +51,6 @@
('', N_('None')),
('common', N_('List & Send')),
('file', N_('Static Content')),
- ('tile', N_('Renderd Frontend')),
('dirlist', N_('Only Listing')),
('redir', N_('Redirection')),
('fcgi', N_('FastCGI')),
@@ -69,6 +68,7 @@
('admin', N_('Remote Administration')),
('empty_gif', N_('1x1 Transparent GIF')),
('drop', N_('Drop Connection')),
+ ('tile', N_('Renderd Frontend')),
]
ERROR_HANDLERS = [
View
1  admin/plugins/Makefile.am
@@ -48,6 +48,7 @@ server_info.py \
ssi.py \
streaming.py \
target_ip.py \
+tile.py \
url_arg.py \
uwsgi.py \
wildcard.py \
View
52 admin/plugins/tile.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+#
+# Cherokee-admin
+#
+# Authors:
+# Alvaro Lopez Ortega <alvaro@alobbs.com>
+# Stefan de Konink <stefan@konink.de>
+#
+# Copyright (C) 2010 Alvaro Lopez Ortega
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of version 2 of the GNU General Public
+# License as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+
+import CTK
+import Handler
+import Cherokee
+import Balancer
+
+from util import *
+from consts import *
+
+URL_APPLY = '/plugin/tile/apply'
+HELPS = []
+
+class Plugin_tile (Handler.PluginHandler):
+ def __init__ (self, key, **kwargs):
+ kwargs['show_document_root'] = False
+ Handler.PluginHandler.__init__ (self, key, **kwargs)
+ Handler.PluginHandler.AddCommon (self)
+
+ # Load Balancing
+ modul = CTK.PluginSelector('%s!balancer'%(key), trans_options(Cherokee.support.filter_available (BALANCERS)))
+ table = CTK.PropsTable()
+ table.Add (_("Balancer"), modul.selector_widget, _(Balancer.NOTE_BALANCER))
+
+ self += CTK.RawHTML ('<h2>%s</h2>' %(_('Renderd Balancing')))
+ self += CTK.Indenter (table)
+ self += modul
+
+CTK.publish ('^%s$'%(URL_APPLY), CTK.cfg_apply_post, method="POST")
View
18 cherokee/Makefile.am
@@ -567,6 +567,22 @@ else
dynamic_handler_file_lib = libplugin_file.la
endif
+#
+# Handler tile
+#
+handler_tile = \
+handler_tile.c \
+handler_tile.h
+
+libplugin_tile_la_LDFLAGS = $(module_ldflags)
+libplugin_tile_la_SOURCES = $(handler_tile)
+
+if STATIC_HANDLER_TILE
+static_handler_tile_src = $(handler_tile)
+else
+dynamic_handler_tile_lib = libplugin_tile.la
+endif
+
#
# Handler dirlist
@@ -1547,6 +1563,7 @@ $(static_handler_post_report_src) \
$(static_collector_rrd_src) \
\
$(static_handler_file_src) \
+$(static_handler_tile_src) \
$(static_handler_dirlist_src) \
$(static_handler_cgi_src) \
$(static_handler_fcgi_src) \
@@ -1737,6 +1754,7 @@ $(dynamic_gen_evhost_lib) \
$(dynamic_post_track_lib) \
$(dynamic_handler_post_report_lib) \
$(dynamic_handler_file_lib) \
+$(dynamic_handler_tile_lib) \
$(dynamic_handler_server_info_lib) \
$(dynamic_handler_render_rrd_lib) \
$(dynamic_handler_dirlist_lib) \
View
4 cherokee/connection-protected.h
@@ -214,6 +214,10 @@ struct cherokee_connection {
int regex_host_ovector[OVECTOR_LEN];
int regex_host_ovecsize;
+ /* Private timeout to be used in handlers
+ */
+ time_t private_timeout;
+
/* Content Expiration
*/
cherokee_expiration_t expiration;
View
1  cherokee/connection.c
@@ -123,6 +123,7 @@ cherokee_connection_new (cherokee_connection_t **conn)
n->polling_fd = -1;
n->polling_multiple = false;
n->polling_mode = FDPOLL_MODE_NONE;
+ n->private_timeout = -1;
n->expiration = cherokee_expiration_none;
n->expiration_time = 0;
n->expiration_prop = cherokee_expiration_prop_none;
View
286 cherokee/handler_tile.c
@@ -0,0 +1,286 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* Cherokee
+ *
+ * Authors:
+ * Alvaro Lopez Ortega <alvaro@alobbs.com>
+ * Stefan de Konink <stefan@konink.de>
+ *
+ * Copyright (C) 2001-2008 Alvaro Lopez Ortega
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include "handler_tile.h"
+
+#include "connection-protected.h"
+#include "source_interpreter.h"
+#include "thread.h"
+#include <sys/stat.h>
+
+#define ENTRIES "handler,tile"
+
+/* Plug-in initialization
+ *
+ * In this function you can use any of these:
+ * http_delete | http_get | http_post | http_put
+ *
+ * For a full list: cherokee_http_method_t
+ *
+ * It is what your handler to be implements.
+ *
+ */
+PLUGIN_INFO_HANDLER_EASIEST_INIT (tile, http_get);
+
+
+/* Methods implementation
+ */
+static ret_t
+props_free (cherokee_handler_tile_props_t *props)
+{
+ return cherokee_module_props_free_base (MODULE_PROPS(props));
+}
+
+
+ret_t
+cherokee_handler_tile_configure (cherokee_config_node_t *conf, cherokee_server_t *srv, cherokee_module_props_t **_props)
+{
+ cherokee_list_t *i;
+ cherokee_handler_tile_props_t *props;
+
+ if (*_props == NULL) {
+ CHEROKEE_NEW_STRUCT (n, handler_tile_props);
+
+ cherokee_module_props_init_base (MODULE_PROPS(n),
+ MODULE_PROPS_FREE(props_free));
+
+ /* Look at handler_tile.h
+ * This is an tile of configuration.
+ */
+ *_props = MODULE_PROPS(n);
+ }
+
+ props = PROP_TILE(*_props);
+
+ cherokee_config_node_foreach (i, conf) {
+ cherokee_config_node_t *subconf = CONFIG_NODE(i);
+
+ if (equal_buf_str (&subconf->key, "balancer")) {
+ ret_t ret = cherokee_balancer_instance (&subconf->val, subconf, srv, &props->balancer);
+ if (ret != ret_ok)
+ return ret;
+ } else {
+ PRINT_MSG ("ERROR: Handler file: Unknown key: '%s'\n", subconf->key.buf);
+ return ret_error;
+ }
+ }
+
+ /* Final checks
+ */
+ if (props->balancer == NULL) {
+ return ret_error;
+ }
+
+ return ret_ok;
+}
+
+ret_t
+cherokee_handler_tile_new (cherokee_handler_t **hdl, cherokee_connection_t *cnt, cherokee_module_props_t *props)
+{
+ CHEROKEE_NEW_STRUCT (n, handler_tile);
+
+ /* Init the base class object
+ */
+ cherokee_handler_init_base(HANDLER(n), cnt, HANDLER_PROPS(props), PLUGIN_INFO_HANDLER_PTR(tile));
+
+ MODULE(n)->init = (handler_func_init_t) cherokee_handler_tile_init;
+ MODULE(n)->free = (module_func_free_t) cherokee_handler_tile_free;
+ HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_tile_add_headers;
+
+ HANDLER(n)->support = hsupport_nothing;
+
+ n->src_ref = NULL;
+ n->send_done = false;
+ cherokee_socket_init (&n->socket);
+
+ /* Init
+ */
+ *hdl = HANDLER(n);
+ return ret_ok;
+}
+
+
+ret_t
+cherokee_handler_tile_free (cherokee_handler_tile_t *hdl)
+{
+ TRACE(ENTRIES, "Close...");
+
+ cherokee_socket_close(&hdl->socket);
+ cherokee_socket_mrproper(&hdl->socket);
+ return ret_ok;
+}
+
+
+ static ret_t
+connect_to_server (cherokee_handler_tile_t *hdl)
+{
+ ret_t ret;
+ cherokee_connection_t *conn = HANDLER_CONN(hdl);
+ cherokee_handler_tile_props_t *props = HDL_TILE_PROPS(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;
+ }
+
+ /* Try to connect
+ */
+ if (hdl->src_ref->type == source_host) {
+ ret = cherokee_source_connect_polling (hdl->src_ref, &hdl->socket, conn);
+ if ((ret == ret_deny) || (ret == ret_error))
+ {
+ cherokee_balancer_report_fail (props->balancer, conn, hdl->src_ref);
+ }
+ } else {
+ ret = cherokee_source_interpreter_connect_polling (SOURCE_INT(hdl->src_ref), &hdl->socket, conn);
+ }
+
+ return ret;
+}
+
+
+ ret_t
+cherokee_handler_tile_init (cherokee_handler_tile_t *hdl)
+{
+ struct protocol cmd;
+ char *from, *to;
+ size_t len;
+ ret_t ret;
+ cherokee_connection_t *conn = HANDLER_CONN(hdl);
+ bzero(&cmd, sizeof(struct protocol));
+
+ from = conn->request.buf+conn->web_directory.len+1;
+ to = strchr(from, '/');
+
+ if (to && (len = (to - from)) < (XMLCONFIG_MAX - 1)) {
+ strncpy(cmd.xmlname, from, len);
+ } else {
+ TRACE(ENTRIES, "Could not extract xmlname from %s\n", from);
+ return ret_error;
+ }
+
+ from = to + 1;
+ cmd.z = (int) strtol(from, &to, 10);
+
+ from = to + 1;
+ cmd.x = (int) strtol(from, &to, 10);
+
+ from = to + 1;
+ cmd.y = (int) strtol(from, &to, 10);
+
+ TRACE(ENTRIES, "Found parameters: %d %d %d\n", cmd.z, cmd.x, cmd.y);
+
+ if (cmd.z < 0 || cmd.x < 0 || cmd.y < 0 ||
+ cmd.z == INT_MAX || cmd.x == INT_MAX || cmd.y == INT_MAX) {
+ TRACE(ENTRIES, "Found parameters exceed specifications\n");
+ return ret_error;
+ }
+
+ cmd.ver = 2;
+ cmd.cmd = cmdRenderPrio;
+
+ /* Connect
+ */
+ ret = connect_to_server (hdl);
+ switch (ret) {
+ case ret_ok:
+ break;
+ case ret_eagain:
+ return ret_eagain;
+ case ret_deny:
+// conn->error_code = http_gateway_timeout;
+ conn->error_code = http_not_found;
+ return ret_error;
+ default:
+ conn->error_code = http_service_unavailable;
+ return ret_error;
+ }
+
+ if (hdl->send_done == false) {
+ TRACE(ENTRIES, "Writing to socket...\n");
+ cherokee_socket_write (&hdl->socket, (const char *) &cmd, sizeof(struct protocol), &len);
+ if (len != sizeof(struct protocol)) {
+ TRACE(ENTRIES, "Unexpected return size!\n");
+ return ret_error;
+ }
+
+ }
+
+ TRACE(ENTRIES, "Reading from socket...\n");
+
+ struct protocol resp;
+ bzero(&resp, sizeof(struct protocol));
+
+ ret = cherokee_socket_read(&hdl->socket, (char *) &resp, sizeof(struct protocol), &len);
+
+ if (ret == ret_eagain) {
+ cherokee_thread_deactive_to_polling (HANDLER_THREAD(hdl),
+ HANDLER_CONN(hdl),
+ S_SOCKET_FD(hdl->socket),
+ FDPOLL_MODE_READ, false);
+ conn->error_code = http_not_found;
+ return ret_eagain;
+ }
+
+ conn->error_code = http_unset;
+
+ if (ret != ret_ok || len != sizeof(struct protocol)) {
+ TRACE(ENTRIES, "Unexpected return size!\n");
+ return ret_error;
+ }
+
+ if (cmd.x == resp.x && cmd.y == resp.y && cmd.z == resp.z &&
+ !strcmp(cmd.xmlname, resp.xmlname)) {
+ if (resp.cmd == cmdDone) {
+ TRACE(ENTRIES, "Command succesful\n");
+ cherokee_buffer_add_buffer (&conn->redirect, &conn->request);
+ conn->error_code = http_moved_temporarily;
+ return ret_ok;
+ } else {
+ TRACE(ENTRIES, "The command was not done\n");
+ conn->error_code = http_not_found;
+ return ret_error;
+ }
+ } else {
+ TRACE(ENTRIES, "We didn't get back what we asked for\n");
+ return ret_error;
+ }
+
+ SHOULDNT_HAPPEN;
+ return ret_error;
+}
+
+
+ret_t
+cherokee_handler_tile_add_headers (cherokee_handler_tile_t *hdl, cherokee_buffer_t *buffer)
+{
+ UNUSED(hdl);
+ UNUSED(buffer);
+
+ return ret_ok;
+}
View
85 cherokee/handler_tile.h
@@ -0,0 +1,85 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* Cherokee
+ *
+ * Authors:
+ * Alvaro Lopez Ortega <alvaro@alobbs.com>
+ * Stefan de Konink <stefan@konink.de>
+ *
+ * Copyright (C) 2001-2008 Alvaro Lopez Ortega
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef CHEROKEE_HANDLER_TILE_H
+#define CHEROKEE_HANDLER_TILE_H
+
+#include "common-internal.h"
+
+#include "handler.h"
+#include "buffer.h"
+#include "socket.h"
+#include "balancer.h"
+#include "plugin_loader.h"
+
+#include <sys/time.h>
+
+/* This we should load from protocol.h */
+#define RENDER_SOCKET "/tmp/osm-renderd"
+#define XMLCONFIG_MAX 41
+enum protoCmd { cmdIgnore, cmdRender, cmdDirty, cmdDone, cmdNotDone, cmdRenderPrio, cmdRenderBulk };
+
+struct protocol {
+ int ver;
+ enum protoCmd cmd;
+ int x;
+ int y;
+ int z;
+ char xmlname[XMLCONFIG_MAX];
+};
+
+/* Data types
+ */
+typedef struct {
+ cherokee_module_props_t base;
+ cherokee_balancer_t *balancer;
+} cherokee_handler_tile_props_t;
+
+typedef struct {
+ /* Shared structures */
+ cherokee_handler_t handler;
+ cherokee_source_t *src_ref;
+ cherokee_socket_t socket;
+ cherokee_boolean_t send_done;
+} cherokee_handler_tile_t;
+
+#define HDL_TILE(x) ((cherokee_handler_tile_t *)(x))
+#define PROP_TILE(x) ((cherokee_handler_tile_props_t *)(x))
+#define HDL_TILE_PROPS(x) (PROP_TILE(MODULE(x)->props))
+
+
+/* Library init function
+ */
+void PLUGIN_INIT_NAME(tile) (cherokee_plugin_loader_t *loader);
+ret_t cherokee_handler_tile_new (cherokee_handler_t **hdl, cherokee_connection_t *cnt, cherokee_module_props_t *props);
+
+/* virtual methods implementation
+ */
+ret_t cherokee_handler_tile_init (cherokee_handler_tile_t *hdl);
+ret_t cherokee_handler_tile_free (cherokee_handler_tile_t *hdl);
+ret_t cherokee_handler_tile_step (cherokee_handler_tile_t *hdl, cherokee_buffer_t *buffer);
+ret_t cherokee_handler_tile_add_headers (cherokee_handler_tile_t *hdl, cherokee_buffer_t *buffer);
+
+#endif /* CHEROKEE_HANDLER_TILE_H */
View
14 cherokee/thread.c
@@ -601,8 +601,9 @@ process_polling_connections (cherokee_thread_t *thd)
}
/* Is there information to be sent?
+ * Or did the caller request a private timeout?
*/
- if (conn->buffer.len > 0) {
+ if (conn->buffer.len > 0 || (conn->private_timeout > -1 && (conn->private_timeout < cherokee_bogonow_now))) {
ret = reactive_conn_from_polling (thd, conn);
if (unlikely (ret != ret_ok)) {
purge_closed_polling_connection (thd, conn);
@@ -2153,6 +2154,17 @@ reactive_conn_from_polling (cherokee_thread_t *thd, cherokee_connection_t *conn)
return move_connection_to_active (thd, conn);
}
+ret_t
+cherokee_thread_deactive_to_polling_timeout (cherokee_thread_t *thd,
+ cherokee_connection_t *conn,
+ int fd,
+ int rw,
+ char multiple,
+ int timeout)
+{
+ conn->private_timeout = cherokee_bogonow_now + timeout;
+ return cherokee_thread_deactive_to_polling (thd, conn, fd, rw, multiple);
+}
ret_t
cherokee_thread_deactive_to_polling (cherokee_thread_t *thd,
View
1  cherokee/thread.h
@@ -121,6 +121,7 @@ ret_t cherokee_thread_unlock (cherokee_thread_t *thd);
ret_t cherokee_thread_wait_end (cherokee_thread_t *thd);
ret_t cherokee_thread_deactive_to_polling (cherokee_thread_t *thd, cherokee_connection_t *conn, int fd, int rw, char multi);
+ret_t cherokee_thread_deactive_to_polling_timeout(cherokee_thread_t *thd, cherokee_connection_t *conn, int fd, int rw, char multi, int timeout);
int cherokee_thread_connection_num (cherokee_thread_t *thd);
ret_t cherokee_thread_retire_active_connection (cherokee_thread_t *thd, cherokee_connection_t *conn);
View
3  configure.in
@@ -1441,7 +1441,7 @@ AC_ARG_ENABLE(static-module,
modules="error_redir error_nn server_info file dirlist cgi fcgi scgi uwsgi proxy redir common ssi secdownload empty_gif drop admin custom_error dbslayer streaming gzip deflate ncsa combined custom pam ldap mysql htpasswd plain htdigest authlist round_robin ip_hash failover directory extensions request header exists fullpath method from bind tls geoip url_arg v_or wildcard rehost target_ip evhost post_track post_report libssl render_rrd rrd not and or"
-beta_modules="filetime"
+beta_modules="filetime tile"
# Include beta modules only when --enable-beta is provided
#
@@ -1527,6 +1527,7 @@ AM_CONDITIONAL(STATIC_HANDLER_CUSTOM_ERROR, grep custom_error $conf_h >/dev/
AM_CONDITIONAL(STATIC_HANDLER_DBSLAYER, grep dbslayer $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_STREAMING, grep streaming $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_HANDLER_RENDER_RRD, grep render_rrd $conf_h >/dev/null)
+AM_CONDITIONAL(STATIC_HANDLER_TILE, grep tile $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_ENCODER_GZIP, grep gzip $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_ENCODER_DEFLATE, grep deflate $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_LOGGER_NCSA, grep ncsa $conf_h >/dev/null)
Please sign in to comment.
Something went wrong with that request. Please try again.