Index: admin/Makefile.am =================================================================== --- admin/Makefile.am (revision 4034) +++ admin/Makefile.am (working copy) @@ -69,6 +69,7 @@ ModuleBalancer.py \ ModuleSsi.py \ ModuleSecdownload.py \ +ModuleTile.py \ ModuleEmptyGif.py \ ModuleProxy.py \ ModuleDbslayer.py \ Index: admin/ModuleTile.py =================================================================== --- admin/ModuleTile.py (revision 0) +++ admin/ModuleTile.py (revision 0) @@ -0,0 +1,47 @@ +from Form import * +from Table import * +from ModuleHandler import * +from validations import * +from consts import * + +# For gettext +N_ = lambda x: x + +from ModuleBalancer import NOTE_BALANCER + +class ModuleTile (ModuleHandler): + PROPERTIES = [ + 'balancer' + ] + + def __init__ (self, cfg, prefix, submit): + ModuleHandler.__init__ (self, 'tile', cfg, prefix, submit) + self.show_document_root = False + + def _op_render (self): + txt = '' + + txt += '

%s

' % (_('Renderd servers')) + table = TableProps() + prefix = "%s!balancer" % (self._prefix) + e = self.AddPropOptions_Reload_Module (table, _("Balancer"), prefix, + modules_available(BALANCERS), _(NOTE_BALANCER)) + txt += self.Indent(str(table) + e) + return txt + + def _op_apply_changes (self, uri, post): + # Apply balancer changes + pre = "%s!balancer" % (self._prefix) + + new_balancer = post.pop(pre) + if new_balancer: + self._cfg[pre] = new_balancer + + cfg = self._cfg[pre] + if cfg and cfg.value: + name = cfg.value + props = module_obj_factory (name, self._cfg, pre, self.submit_url) + props._op_apply_changes (uri, post) + + # And apply the rest + self.ApplyChangesPrefix (self._prefix, [], post) Index: cherokee/Makefile.am =================================================================== --- cherokee/Makefile.am (revision 4034) +++ cherokee/Makefile.am (working copy) @@ -759,6 +759,23 @@ # +# 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_SECDOWNLOAD +static_handler_tile_src = $(handler_tile) +else +dynamic_handler_tile_lib = libplugin_tile.la +endif + + +# # Handler secdownload # handler_secdownload = \ @@ -812,17 +829,17 @@ dynamic_handler_streaming_lib = libplugin_streaming.la endif - # # Handler DB Slayer # handler_dbslayer = \ handler_dbslayer.h \ -handler_dbslayer.c +handler_dbslayer.c \ +handler_dbslayer_monetdb.c -libplugin_dbslayer_la_LDFLAGS = $(module_ldflags) $(MYSQL_LDFLAGS) +libplugin_dbslayer_la_LDFLAGS = $(module_ldflags) $(MYSQL_LDFLAGS) -L/opt/monetdb-head/lib -lMapi libplugin_dbslayer_la_SOURCES = $(handler_dbslayer) -libplugin_dbslayer_la_CFLAGS = $(MYSQL_CFLAGS) +libplugin_dbslayer_la_CFLAGS = $(MYSQL_CFLAGS) -I/opt/monetdb-head/include/MonetDB/mapilib -DHAVE_MYSQL_H -DHAVE_MAPI_H if HAVE_MYSQL if STATIC_HANDLER_DBSLAYER @@ -834,7 +851,6 @@ endif endif - # # Handler custom_error # @@ -1471,6 +1487,7 @@ $(static_handler_common_src) \ $(static_handler_proxy_src) \ $(static_handler_ssi_src) \ +$(static_handler_tile_src) \ $(static_handler_secdownload_src) \ $(static_handler_empty_gif_src) \ $(static_handler_streaming_src) \ @@ -1653,6 +1670,7 @@ $(dynamic_handler_redir_lib) \ $(dynamic_handler_proxy_lib) \ $(dynamic_handler_ssi_lib) \ +$(dynamic_handler_tile_lib) \ $(dynamic_handler_secdownload_lib) \ $(dynamic_handler_empty_gif_lib) \ $(dynamic_handler_streaming_lib) \ Index: cherokee/handler_tile.h =================================================================== --- cherokee/handler_tile.h (revision 0) +++ cherokee/handler_tile.h (revision 0) @@ -0,0 +1,84 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* Cherokee + * + * Authors: + * Alvaro Lopez Ortega + * Stefan de Konink + * + * 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 + +/* 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_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 */ Index: cherokee/handler_tile.c =================================================================== --- cherokee/handler_tile.c (revision 0) +++ cherokee/handler_tile.c (revision 0) @@ -0,0 +1,267 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +/* Cherokee + * + * Authors: + * Alvaro Lopez Ortega + * Stefan de Konink + * + * 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 + +#include "connection-protected.h" +#include "source_interpreter.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; + 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; + cherokee_connection_t *conn = HANDLER_CONN(hdl); + bzero(&cmd, sizeof(struct protocol)); + + from = conn->request.buf+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_t 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; + return ret_error; + default: + conn->error_code = http_service_unavailable; + return ret_error; + } + + 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"); + + cherokee_fd_set_nonblocking (S_SOCKET_FD(hdl->socket), false); + + struct protocol resp; + bzero(&resp, sizeof(struct protocol)); + cherokee_socket_read(&hdl->socket, (char *) &resp, sizeof(struct protocol), &len); + if (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; +}