Permalink
Browse files

git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97…

…f1-0310-9951-d761b3857238
  • Loading branch information...
alobbs committed Sep 4, 2006
1 parent 63f1dd7 commit 7b0e48a80898a6dd7c3f93f8177db5b3f0f640b7
Showing with 969 additions and 876 deletions.
  1. +5 −3 cherokee/Makefile.am
  2. +103 −26 cherokee/balancer.c
  3. +25 −28 cherokee/balancer.h
  4. +22 −10 cherokee/balancer_round_robin.c
  5. +2 −8 cherokee/balancer_round_robin.h
  6. +1 −1 cherokee/config_entry.c
  7. +6 −6 cherokee/config_entry.h
  8. +0 −417 cherokee/ext_source.c
  9. +0 −90 cherokee/ext_source.h
  10. +1 −1 cherokee/fcgi_dispatcher.c
  11. +1 −1 cherokee/fcgi_dispatcher.h
  12. +11 −8 cherokee/fcgi_manager.c
  13. +3 −3 cherokee/fcgi_manager.h
  14. +1 −33 cherokee/handler.c
  15. +3 −20 cherokee/handler.h
  16. +1 −1 cherokee/handler_admin.c
  17. +1 −1 cherokee/handler_admin.h
  18. +5 −5 cherokee/handler_cgi.c
  19. +2 −2 cherokee/handler_cgi.h
  20. +3 −3 cherokee/handler_cgi_base.c
  21. +3 −3 cherokee/handler_cgi_base.h
  22. +11 −11 cherokee/handler_common.c
  23. +3 −3 cherokee/handler_common.h
  24. +6 −6 cherokee/handler_dirlist.c
  25. +3 −3 cherokee/handler_dirlist.h
  26. +1 −1 cherokee/handler_error.c
  27. +1 −1 cherokee/handler_error.h
  28. +6 −6 cherokee/handler_error_redir.c
  29. +4 −4 cherokee/handler_error_redir.h
  30. +16 −13 cherokee/handler_fastcgi.c
  31. +3 −2 cherokee/handler_fastcgi.h
  32. +43 −34 cherokee/handler_fcgi.c
  33. +3 −4 cherokee/handler_fcgi.h
  34. +6 −6 cherokee/handler_file.c
  35. +5 −4 cherokee/handler_file.h
  36. +2 −2 cherokee/handler_nn.c
  37. +1 −1 cherokee/handler_nn.h
  38. +6 −6 cherokee/handler_phpcgi.c
  39. +1 −1 cherokee/handler_phpcgi.h
  40. +9 −24 cherokee/handler_proxy.c
  41. +3 −3 cherokee/handler_proxy.h
  42. +6 −6 cherokee/handler_redir.c
  43. +2 −2 cherokee/handler_redir.h
  44. +41 −34 cherokee/handler_scgi.c
  45. +4 −3 cherokee/handler_scgi.h
  46. +6 −6 cherokee/handler_server_info.c
  47. +2 −2 cherokee/handler_server_info.h
  48. +34 −0 cherokee/module.c
  49. +31 −9 cherokee/module.h
  50. +146 −0 cherokee/source.c
  51. +60 −0 cherokee/source.h
  52. +236 −0 cherokee/source_interpreter.c
  53. +54 −0 cherokee/source_interpreter.h
  54. +5 −3 qa/126-SCGI.py
  55. +5 −3 qa/127-SCGI-Post.py
  56. +5 −3 qa/run-tests.py
View
@@ -749,6 +749,10 @@ endif
libcherokee_server_la_SOURCES = \
+source.h \
+source.c \
+source_interpreter.h \
+source_interpreter.c \
$(static_handler_file_src) \
$(static_handler_admin_src) \
$(static_handler_dirlist_src) \
@@ -824,12 +828,10 @@ handler_error.c \
handler_error.h \
nonce.h \
nonce.c \
-ext_source.h \
-ext_source.c \
config_node.h \
config_node.c \
balancer.h \
-balancer.c
+balancer.c
libcherokee_config_la_SOURCES = \
$(config_common) \
View
@@ -24,9 +24,11 @@
#include "common-internal.h"
#include "balancer.h"
+#include "module_loader.h"
+#include "server-protected.h"
+#include "source_interpreter.h"
-
-#define DEFAULT_HOSTS_ALLOCATION 5
+#define DEFAULT_SOURCES_ALLOCATION 5
ret_t
@@ -38,13 +40,13 @@ cherokee_balancer_init_base (cherokee_balancer_t *balancer)
/* Virtual methods
*/
- balancer->dispatch = NULL;
+ balancer->dispatch = NULL;
- /* Hosts
+ /* Sources
*/
- balancer->hosts_len = 0;
- balancer->hosts_size = 0;
- balancer->hosts = NULL;
+ balancer->sources_len = 0;
+ balancer->sources_size = 0;
+ balancer->sources = NULL;
return ret_ok;
}
@@ -53,61 +55,112 @@ cherokee_balancer_init_base (cherokee_balancer_t *balancer)
ret_t
cherokee_balancer_mrproper (cherokee_balancer_t *balancer)
{
- if (balancer->hosts != NULL) {
- free (balancer->hosts);
+ if (balancer->sources != NULL) {
+ free (balancer->sources);
}
return ret_ok;
}
+ret_t
+cherokee_balancer_configure (cherokee_balancer_t *balancer, cherokee_config_node_t *conf)
+{
+ ret_t ret;
+ cherokee_list_t *i;
+ cherokee_buffer_t *buf;
+ cherokee_boolean_t interpreter = false;
+
+ /* Look for the type of the source objects
+ */
+ ret = cherokee_config_node_read (conf, "type", &buf);
+ if (ret != ret_ok) {
+ PRINT_ERROR_S ("ERROR: Balancer: An entry 'type' is needed\n");
+ return ret;
+ }
+
+ if (equal_buf_str (buf, "interpreter")) {
+ interpreter = true;
+ } else {
+ PRINT_ERROR ("ERROR: Balancer: Unknown type '%s'\n", buf->buf);
+ return ret_error;
+ }
+
+ /* Add the source objects
+ */
+ cherokee_config_node_foreach (i, conf) {
+ cherokee_source_t *src = NULL;
+ cherokee_config_node_t *subconf = CONFIG_NODE(i);
+
+ if (equal_buf_str (&subconf->key, "type"))
+ continue;
+
+ if (interpreter) {
+ cherokee_source_interpreter_t *src2;
+
+ ret = cherokee_source_interpreter_new (&src2);
+ if (ret != ret_ok) return ret;
+
+ ret = cherokee_source_interpreter_configure (src2, subconf);
+ if (ret != ret_ok) return ret;
+
+ src = SOURCE(src2);
+ }
+
+ cherokee_balancer_add_source (balancer, src);
+ }
+
+ return ret_ok;
+}
+
+
static ret_t
-alloc_more_hosts (cherokee_balancer_t *balancer)
+alloc_more_sources (cherokee_balancer_t *balancer)
{
size_t size;
- if (balancer->hosts == NULL) {
- size = DEFAULT_HOSTS_ALLOCATION * sizeof(cherokee_balancer_host_t *);
- balancer->hosts = (cherokee_balancer_host_t **) malloc (size);
+ if (balancer->sources == NULL) {
+ size = DEFAULT_SOURCES_ALLOCATION * sizeof(cherokee_source_t *);
+ balancer->sources = (cherokee_source_t **) malloc (size);
} else {
- size = (balancer->hosts_size + DEFAULT_HOSTS_ALLOCATION ) * sizeof(cherokee_balancer_host_t *);
- balancer->hosts = (cherokee_balancer_host_t **) realloc (balancer->hosts, size);
+ size = (balancer->sources_size + DEFAULT_SOURCES_ALLOCATION ) * sizeof(cherokee_source_t *);
+ balancer->sources = (cherokee_source_t **) realloc (balancer->sources, size);
}
- if (balancer->hosts == NULL)
+ if (balancer->sources == NULL)
return ret_nomem;
- memset (balancer->hosts + balancer->hosts_len, 0, DEFAULT_HOSTS_ALLOCATION);
+ memset (balancer->sources + balancer->sources_len, 0, DEFAULT_SOURCES_ALLOCATION);
- balancer->hosts_size += DEFAULT_HOSTS_ALLOCATION;
+ balancer->sources_size += DEFAULT_SOURCES_ALLOCATION;
return ret_ok;
}
ret_t
-cherokee_balancer_add_host (cherokee_balancer_t *balancer, cherokee_balancer_host_t *host)
+cherokee_balancer_add_source (cherokee_balancer_t *balancer, cherokee_source_t *source)
{
ret_t ret;
-
- if (balancer->hosts_len >= balancer->hosts_size) {
- ret = alloc_more_hosts (balancer);
+
+ if (balancer->sources_len >= balancer->sources_size) {
+ ret = alloc_more_sources (balancer);
if (ret != ret_ok) return ret;
}
- balancer->hosts[balancer->hosts_len] = host;
- balancer->hosts_len++;
+ balancer->sources[balancer->sources_len] = source;
+ balancer->sources_len++;
return ret_ok;
}
ret_t
-cherokee_balancer_dispatch (cherokee_balancer_t *balancer, cherokee_connection_t *conn, cherokee_balancer_host_t **host)
+cherokee_balancer_dispatch (cherokee_balancer_t *balancer, cherokee_connection_t *conn, cherokee_source_t **source)
{
if (balancer->dispatch == NULL)
return ret_error;
- return balancer->dispatch (balancer, conn, host);
+ return balancer->dispatch (balancer, conn, source);
}
@@ -135,3 +188,27 @@ cherokee_balancer_free (cherokee_balancer_t *bal)
free (bal);
return ret_ok;
}
+
+
+ret_t
+cherokee_balancer_instance (cherokee_buffer_t *name,
+ cherokee_config_node_t *conf,
+ cherokee_server_t *srv,
+ cherokee_balancer_t **balancer)
+{
+ ret_t ret;
+ balancer_new_func_t new_func;
+ cherokee_module_info_t *info = NULL;
+
+ ret = cherokee_module_loader_get (&srv->loader, name->buf, &info);
+ if (ret != ret_ok) return ret;
+
+ new_func = (balancer_new_func_t) info->new_func;
+ ret = new_func (balancer);
+ if (ret != ret_ok) return ret;
+
+ ret = cherokee_balancer_configure (*balancer, conf);
+ if (ret != ret_ok) return ret;
+
+ return ret_ok;
+}
View
@@ -32,55 +32,52 @@
#include <cherokee/common.h>
#include <cherokee/module.h>
#include <cherokee/connection.h>
+#include <cherokee/source.h>
CHEROKEE_BEGIN_DECLS
-
-/* Hosts
- */
-typedef struct {
- int foo;
-} cherokee_balancer_host_t;
-
-
-/* Handler properties
- */
-typedef ret_t (* balancer_props_func_free_t) (void *balancerp);
-
-typedef struct {
- balancer_props_func_free_t free;
-} cherokee_balancer_props_t;
-
-
-/* Balancer
- */
-typedef ret_t (* balancer_dispatch_func_t) (void *balancer, cherokee_connection_t *conn, cherokee_balancer_host_t **hosts);
-typedef ret_t (* balancer_free_func_t) (void *balancer);
+typedef ret_t (* balancer_dispatch_func_t) (void *balancer, cherokee_connection_t *conn, cherokee_source_t **src);
typedef struct {
- cherokee_module_t module;
+ cherokee_module_t module;
/* Properties */
- cherokee_balancer_host_t **hosts;
- cuint_t hosts_len;
- cuint_t hosts_size;
+ cherokee_source_t **sources;
+ cuint_t sources_len;
+ cuint_t sources_size;
/* Virtual methods */
- balancer_dispatch_func_t dispatch;
+ balancer_dispatch_func_t dispatch;
+
} cherokee_balancer_t;
#define BAL(b) ((cherokee_balancer_t *)(b))
+
+typedef ret_t (* balancer_new_func_t) (cherokee_balancer_t **balancer);
+typedef ret_t (* balancer_free_func_t) (cherokee_balancer_t *balancer);
+
+
ret_t cherokee_balancer_init_base (cherokee_balancer_t *balancer);
ret_t cherokee_balancer_mrproper (cherokee_balancer_t *balancer);
+ret_t cherokee_balancer_configure (cherokee_balancer_t *balancer, cherokee_config_node_t *conf);
-ret_t cherokee_balancer_add_host (cherokee_balancer_t *balancer, cherokee_balancer_host_t *host);
+/* Public methods
+ */
+ret_t cherokee_balancer_add_source (cherokee_balancer_t *balancer, cherokee_source_t *source);
/* Virtual methods
*/
-ret_t cherokee_balancer_dispatch (cherokee_balancer_t *balancer, cherokee_connection_t *conn, cherokee_balancer_host_t **host);
+ret_t cherokee_balancer_dispatch (cherokee_balancer_t *balancer, cherokee_connection_t *conn, cherokee_source_t **source);
ret_t cherokee_balancer_free (cherokee_balancer_t *balancer);
+/* Commodity
+ */
+ret_t cherokee_balancer_instance (cherokee_buffer_t *name,
+ cherokee_config_node_t *conf,
+ cherokee_server_t *srv,
+ cherokee_balancer_t **balancer);
+
CHEROKEE_END_DECLS
#endif /* CHEROKEE_BALANCER_H */
@@ -27,15 +27,26 @@
#include "balancer_round_robin.h"
#include "module_loader.h"
+static ret_t
+dispatch (cherokee_balancer_round_robin_t *balancer,
+ cherokee_connection_t *conn,
+ cherokee_source_t **src);
+
ret_t
-cherokee_balancer_round_robin_configure (cherokee_config_node_t *conf, cherokee_server_t *srv, void **props)
+cherokee_balancer_round_robin_configure (cherokee_balancer_t *balancer, cherokee_config_node_t *conf)
{
+ ret_t ret;
+
+ ret = cherokee_balancer_configure (BAL(balancer), conf);
+ if (ret != ret_ok) return ret;
+
return ret_ok;
}
+
ret_t
-cherokee_balancer_round_robin_new (cherokee_balancer_t **bal, cherokee_connection_t *cnt, cherokee_balancer_props_t *props)
+cherokee_balancer_round_robin_new (cherokee_balancer_t **bal)
{
CHEROKEE_NEW_STRUCT (n, balancer_round_robin);
@@ -44,7 +55,7 @@ cherokee_balancer_round_robin_new (cherokee_balancer_t **bal, cherokee_connectio
cherokee_balancer_init_base (BAL(n));
MODULE(n)->free = (module_func_free_t) cherokee_balancer_round_robin_free;
- BAL(n)->dispatch = (balancer_dispatch_func_t) cherokee_balancer_round_robin_dispatch;
+ BAL(n)->dispatch = (balancer_dispatch_func_t) dispatch;
/* Init properties
*/
@@ -66,20 +77,20 @@ cherokee_balancer_round_robin_free (cherokee_balancer_round_robin_t *balancer)
}
-ret_t
-cherokee_balancer_round_robin_dispatch (cherokee_balancer_round_robin_t *balancer,
- cherokee_connection_t *conn,
- cherokee_balancer_host_t **host)
+static ret_t
+dispatch (cherokee_balancer_round_robin_t *balancer,
+ cherokee_connection_t *conn,
+ cherokee_source_t **src)
{
cherokee_balancer_t *gbal = BAL(balancer);
CHEROKEE_MUTEX_LOCK (&balancer->last_one_mutex);
- if (gbal->hosts_len <= 0)
+ if (gbal->sources_len <= 0)
goto error;
- balancer->last_one = (balancer->last_one + 1) % gbal->hosts_len;
- *host = gbal->hosts[balancer->last_one];
+ balancer->last_one = (balancer->last_one + 1) % gbal->sources_len;
+ *src = gbal->sources[balancer->last_one];
CHEROKEE_MUTEX_UNLOCK (&balancer->last_one_mutex);
return ret_ok;
@@ -90,6 +101,7 @@ cherokee_balancer_round_robin_dispatch (cherokee_balancer_round_robin_t *balance
}
+
/* Module stuff
*/
@@ -38,17 +38,11 @@ typedef struct {
#endif
} cherokee_balancer_round_robin_t;
-
-#define PROP_RR(x) ((cherokee_balancer_round_robin_props_t *)(x))
#define BAL_RR(x) ((cherokee_balancer_round_robin_file_t *)(x))
-#define BAL_RR_PROP(x) (PROP_RR(BAL(x)->props))
-
-ret_t cherokee_balancer_round_robin_new (cherokee_balancer_t **hdl, cherokee_connection_t *cnt, cherokee_balancer_props_t *props);
-ret_t cherokee_balancer_round_robin_configure (cherokee_config_node_t *conf, cherokee_server_t *srv, void **props);
+ret_t cherokee_balancer_round_robin_new (cherokee_balancer_t **balancer);
+ret_t cherokee_balancer_round_robin_configure (cherokee_balancer_t *balancer, cherokee_config_node_t *conf);
ret_t cherokee_balancer_round_robin_free (cherokee_balancer_round_robin_t *balancer);
-ret_t cherokee_balancer_round_robin_dispatch (cherokee_balancer_round_robin_t *balancer, cherokee_connection_t *conn, cherokee_balancer_host_t **host);
-
#endif /* CHEROKEE_BALANCER_ROUND_ROBIN_H */
Oops, something went wrong.

0 comments on commit 7b0e48a

Please sign in to comment.