Permalink
Browse files

git-svn-id: svn://cherokee-project.com/cherokee/trunk@1398 5dc97367-9…

…7f1-0310-9951-d761b3857238
  • Loading branch information...
1 parent 57474f1 commit b0dd10b77fe3760068e189d31d6e38ce25f00261 @alobbs alobbs committed Apr 15, 2008
Showing with 1,281 additions and 835 deletions.
  1. +98 −0 ChangeLog
  2. +20 −1 cherokee/Makefile.am
  3. +13 −0 cherokee/config_node.c
  4. +2 −0 cherokee/config_node.h
  5. +0 −70 cherokee/getopt/getopt.c
  6. +0 −92 cherokee/getopt/getopt1.c
  7. +5 −2 cherokee/handler_fcgi.c
  8. +62 −24 cherokee/main.c
  9. +81 −35 cherokee/main_admin.c
  10. +0 −2 cherokee/module.h
  11. +1 −0 cherokee/plugin_loader.h
  12. +46 −0 cherokee/rule.c
  13. +7 −3 cherokee/rule.h
  14. +10 −4 cherokee/rule_default.c
  15. +1 −5 cherokee/rule_default.h
  16. +31 −14 cherokee/rule_directory.c
  17. +2 −5 cherokee/rule_directory.h
  18. +21 −5 cherokee/rule_extensions.c
  19. +1 −4 cherokee/rule_extensions.h
  20. +99 −0 cherokee/rule_header.c
  21. +54 −0 cherokee/rule_header.h
  22. +2 −1 cherokee/rule_list.c
  23. +34 −13 cherokee/rule_request.c
  24. +4 −8 cherokee/rule_request.h
  25. +4 −0 cherokee/socket.c
  26. +4 −0 cherokee/validator.c
  27. +85 −86 cherokee/virtual_server.c
  28. +2 −1 configure.in
  29. +0 −1 qa/001-basic.py
  30. +3 −2 qa/015-CGI-simple.py
  31. +3 −2 qa/016-CGI-pathinfo.py
  32. +3 −2 qa/017-CGI-pathinfo2.py
  33. +3 −2 qa/018-CGI-pathinfo3.py
  34. +2 −2 qa/020-VirtualHost.py
  35. +2 −2 qa/021-VirtualHost2.py
  36. +4 −3 qa/029-Post+Without-lenght.py
  37. +3 −2 qa/030-Post+urlencoded.py
  38. +3 −2 qa/031-Post+urlencoded2.py
  39. +3 −2 qa/033-DirIndex.py
  40. +3 −2 qa/034-DirIndex2.py
  41. +4 −3 qa/035-PHP-simple.py
  42. +4 −3 qa/036-DocumentRoot-common.py
  43. +7 −6 qa/039-Auth-Basic.py
  44. +7 −6 qa/040-Auth-Basic2.py
  45. +7 −6 qa/041-Auth-Basic3.py
  46. +3 −1 qa/044-Home.py
  47. +3 −1 qa/045-Home2.py
  48. +4 −3 qa/046-Redir.py
  49. +4 −3 qa/047-Redir2.py
  50. +3 −2 qa/048-NN.py
  51. +3 −2 qa/049-NN-broken.py
  52. +3 −2 qa/050-HeadBody.py
  53. +6 −4 qa/061-PAM.py
  54. +6 −4 qa/062-PAM2.py
  55. +4 −3 qa/063-DocumentRoot.py
  56. +3 −2 qa/064-DirectoryIndex.py
  57. +3 −2 qa/066-DirectoryIndex3.py
  58. +3 −2 qa/067-PathInfo.py
  59. +4 −3 qa/068-PathInfo2.py
  60. +3 −2 qa/069-PathInfo3.py
  61. +10 −8 qa/070-Inherit.py
  62. +10 −8 qa/071-Inherit2.py
  63. +7 −5 qa/072-Inherit3.py
  64. +4 −3 qa/073-Access.py
  65. +4 −3 qa/074-Access2.py
  66. +4 −3 qa/075-AccessRange.py
  67. +4 −3 qa/076-AccessRange2.py
  68. +4 −3 qa/077-AccessRange3.py
  69. +4 −3 qa/078-AccessAny.py
  70. +8 −6 qa/079-Extension.py
  71. +7 −5 qa/080-Extension2.py
  72. +4 −3 qa/081-DocumentRoot-Common-index.py
  73. +8 −6 qa/082-Auth-header.py
  74. +6 −5 qa/083-RedirParam.py
  75. +6 −5 qa/084-RedirParamShow.py
  76. +8 −7 qa/085-AuthUsers.py
  77. +8 −7 qa/086-AuthUsers2.py
  78. +5 −4 qa/088-CGI-envs.py
  79. +3 −2 qa/089-gzip-encoding.py
  80. +7 −6 qa/090-Digest.py
  81. +7 −6 qa/091-Digest2.py
  82. +7 −6 qa/092-Digest3.py
  83. +3 −2 qa/093-InvalidLinks.py
  84. +6 −4 qa/094-URL-request.py
  85. +7 −6 qa/095-htpasswd-apache-md5.py
  86. +7 −6 qa/096-htpasswd-md5.py
  87. +7 −6 qa/097-htpasswd-sha1.py
  88. +7 −6 qa/098-htpasswd-crypt.py
  89. +7 −6 qa/099-htpasswd-plain.py
  90. +8 −8 qa/100-Digest-htdigest.py
  91. +3 −2 qa/102-QueryString.py
  92. +5 −4 qa/103-ScriptName.py
  93. +4 −3 qa/104-ScriptAlias_PathInfo.py
  94. +3 −2 qa/105-If-Range.py
  95. +3 −2 qa/106-If-Range2.py
  96. +6 −4 qa/107-Priority1.py
  97. +6 −4 qa/108-Priority2.py
  98. +6 −4 qa/109-Priority3.py
  99. +6 −4 qa/110-Priority4.py
  100. +4 −3 qa/112-NiceError-CGI.py
  101. +4 −3 qa/113-HeaderFile.py
  102. +4 −3 qa/114-HeaderFile2.py
  103. +15 −12 qa/115-Respin.py
  104. +10 −8 qa/116-RequestTiny.py
  105. +6 −5 qa/117-DomainToDir.py
  106. +5 −4 qa/118-Request-redir.py
  107. +3 −2 qa/121-NoUserDir.py
  108. +3 −2 qa/122-Methods.py
  109. +4 −3 qa/123-ImplicitRedit.py
  110. +10 −7 qa/124-DomainToDir2.py
  111. +9 −8 qa/125-domain-redir1.py
  112. +7 −6 qa/126-SCGI.py
  113. +7 −6 qa/127-SCGI-Post.py
  114. +4 −3 qa/128-ValidMethod-common.py
  115. +7 −6 qa/129-Basic-EmptyPasswd.py
  116. +7 −6 qa/130-Digest-EmptyPasswd.py
  117. +5 −4 qa/131-ChangeUser-phpcgi.py
  118. +14 −12 qa/135-RedirParams.py
  119. +4 −3 qa/138-ChangeUser-cgi.py
  120. +5 −2 qa/139-domain-wildcards1.py
  121. +7 −6 qa/140-SCGI-EmptyVars.py
  122. +7 −6 qa/141-FastCGI-EmptyVars.py
  123. +8 −7 qa/142-SCGI-ExtraVars.py
  124. +4 −3 qa/143-ContentRange-NoIO.py
  125. +4 −3 qa/144-ContentRange2-NoIO.py
  126. +4 −3 qa/145-ContentRange3-NoIO.py
  127. +4 −3 qa/146-ContentRange4-NoIO.py
  128. +4 −3 qa/147-ContentRange-Double-NoIO.py
  129. +4 −3 qa/148-ContentRange-Double2-NoIO.py
  130. +4 −3 qa/149-Common-PathInfo.py
  131. +4 −3 qa/150-Common-No-PathInfo.py
  132. +8 −7 qa/151-SCGI-vars.py
  133. +8 −7 qa/152-SCGI-vars2.py
  134. +9 −7 qa/153-SCGI-vars-root.py
  135. +4 −3 qa/154-DirRedirection.py
  136. +4 −3 qa/155-DirRedirection2.py
  137. +4 −3 qa/157-Dirlist-symlinks.py
  138. +19 −15 qa/run-tests.py
View
98 ChangeLog
@@ -1,3 +1,101 @@
+2008-04-13 Alvaro Lopez Ortega <alvaro@alobbs.com>
+
+ (This is what a MacBook Pro battery lasts): flying from Austin to
+ Madrid. After the Linux Foundation Collaboration Summit 2008.
+
+ * cherokee/main.c, cherokee/main_admin.c, cherokee/module.h,
+ cherokee/plugin_loader.h, cherokee/rule.c, cherokee/rule.h,
+ cherokee/rule_default.c, cherokee/rule_default.h,
+ cherokee/rule_directory.c, cherokee/rule_directory.h,
+ cherokee/rule_extensions., cherokee/rule_extensions.h,
+ cherokee/rule_list.c, cherokee/rule_request.c,
+ cherokee/rule_request.h, cherokee/validator.c,
+ cherokee/virtual_server.c, qa/001-basic.py, qa/015-CGI-simple.py,
+ qa/016-CGI-pathinfo.py, qa/017-CGI-pathinfo2.py,
+ qa/018-CGI-pathinfo3.py, qa/020-VirtualHost.py,
+ qa/021-VirtualHost2.py, qa/029-Post+Without-lenght.py,
+ qa/030-Post+urlencoded.py, qa/031-Post+urlencoded2.py,
+ qa/033-DirIndex.py, qa/034-DirIndex2.py, qa/035-PHP-simple.py,
+ qa/036-DocumentRoot-common.py, qa/039-Auth-Basic.py,
+ qa/040-Auth-Basic2.py, qa/041-Auth-Basic3.py, qa/044-Home.py,
+ qa/045-Home2.py, qa/046-Redir.py, qa/047-Redir2.py, qa/048-NN.py,
+ qa/049-NN-broken.py, qa/050-HeadBody.py, qa/061-PAM.py,
+ qa/062-PAM2.py, qa/063-DocumentRoot.py, qa/064-DirectoryIndex.py,
+ qa/066-DirectoryIndex3.py, qa/067-PathInfo.py,
+ qa/068-PathInfo2.py, qa/069-PathInfo3.py, qa/070-Inherit.py,
+ qa/071-Inherit2.py, qa/072-Inherit3.py, qa/073-Access.py,
+ qa/074-Access2.py, qa/075-AccessRange.py, qa/076-AccessRange2.py,
+ qa/077-AccessRange3.py, qa/078-AccessAny.py, qa/079-Extension.py,
+ qa/080-Extension2.py, qa/081-DocumentRoot-Common-index.py,
+ qa/082-Auth-header., qa/083-RedirParam.py,
+ qa/084-RedirParamShow.py, qa/085-AuthUsers.py,
+ qa/086-AuthUsers2.py, qa/088-CGI-envs.py, qa/089-gzip-encoding.py,
+ qa/090-Digest.py, qa/091-Digest2.py, qa/092-Digest3.py,
+ qa/093-InvalidLinks.py, qa/094-URL-request.py,
+ qa/095-htpasswd-apache-md5.py, qa/096-htpasswd-md5.py,
+ qa/097-htpasswd-sha1.py, qa/098-htpasswd-crypt.py,
+ qa/099-htpasswd-plain.py, qa/100-Digest-htdigest.py,
+ qa/102-QueryString.py, qa/103-ScriptName.py,
+ qa/104-ScriptAlias_PathInfo.py, qa/105-If-Range.py,
+ qa/106-If-Range2.py, qa/107-Priority1.py, qa/108-Priority2.py,
+ qa/109-Priority3.py, qa/110-Priority4.py, qa/112-NiceError-CGI.py,
+ qa/113-HeaderFile.py, qa/114-HeaderFile2.py, qa/115-Respin.py,
+ qa/116-RequestTiny.py, qa/117-DomainToDir.py,
+ qa/118-Request-redir.py, qa/121-NoUserDir.py, qa/122-Methods.py,
+ qa/123-ImplicitRedit.py, qa/124-DomainToDir2.py,
+ qa/125-domain-redir1.py, qa/126-SCGI.py, qa/127-SCGI-Post.py,
+ qa/128-ValidMethod-common.py, qa/129-Basic-EmptyPasswd.py,
+ qa/130-Digest-EmptyPasswd.py, qa/131-ChangeUser-phpcgi.py,
+ qa/135-RedirParams.py, qa/138-ChangeUser-cgi.py,
+ qa/139-domain-wildcards1.py, qa/140-SCGI-EmptyVars.py,
+ qa/141-FastCGI-EmptyVars.py, qa/142-SCGI-ExtraVars.py,
+ qa/143-ContentRange-NoIO.py, qa/144-ContentRange2-NoIO.py,
+ qa/145-ContentRange3-NoIO.py, qa/146-ContentRange4-NoIO.py,
+ qa/147-ContentRange-Double-NoIO.py,
+ qa/148-ContentRange-Double2-NoIO.py, qa/149-Common-PathInfo.py,
+ qa/150-Common-No-PathInfo.py, qa/151-SCGI-vars.py,
+ qa/152-SCGI-vars2.py, qa/153-SCGI-vars-root.py,
+ qa/154-DirRedirection.py, qa/155-DirRedirection2.py,
+ qa/157-Dirlist-symlinks.py, qa/run-tests.py: The configuration
+ file format for 0.7 has changed again. The latest approach was
+ fair enough, although it was not as flexible as it should have
+ been. This mega-patch makes it work as the rest of the server;
+ which is, instead if receiving a buffer with an string, it
+ receives a cherokee_config_node_t reference and it is reads it
+ configuration from there. I ran into problems when I was writing
+ the header based rule plug-in because for this previous
+ implementation; not it is okay.
+
+ * cherokee/rule_header.h, cherokee/rule_header.c: Added new rule
+ type to allow to based decisions on certain header entries values.
+
+ * cherokee/config_node.c, cherokee/config_node.h: Added a new
+ convenience method for copying a key content.
+
+ * cherokee/getopt/getopt.c, cherokee/getopt/getopt1.c: Test
+ removed. There were completely useless.
+
+ * cherokee/handler_fcgi.c, cherokee/socket.c: Added a few trace
+ entries. I needed it to investigate a weird issue about the fcgi
+ handler (work on progress here).
+
+ * configure.in, cherokee/Makefile.am: Added entries for a new
+ header base rule plug-in.
+
+ * cherokee/rule_request.h (CHEROKEE_RULE_REQS_H): Fixed #if
+ protection against multiple inclusions.
+
+ * cherokee/main_admin.c (process_parameters): Now it adminst a
+ conditional parameter for the network interface to bind to:
+ cherokee-admin --> localhost
+ cherokee-admin --bind --> all interfaces
+ cherokee-admin --bind=IP --> Only IP interface
+
+ * cherokee/main.c, cherokee/main_admin.c: Ported to use
+ getopt_long. Now it accpets -- parameters and includes a better
+ version and help functions. (TODO: Update cherokee.1 and
+ cherokee-admin.1 man pages).
+
2008-04-12 A.D.F <adefacc@tin.it>
* admin/*.help.html:
View
21 cherokee/Makefile.am
@@ -138,6 +138,23 @@ endif
#
+# Rule header
+#
+rule_header = \
+rule_header.c \
+rule_header.h
+
+libplugin_header_la_LDFLAGS = $(module_ldflags)
+libplugin_header_la_SOURCES = $(rule_header)
+
+if STATIC_RULE_HEADER
+static_rule_header_src = $(rule_header)
+else
+dynamic_rule_header_lib = libplugin_header.la
+endif
+
+
+#
# Handler server_info
#
handler_server_info = \
@@ -861,9 +878,10 @@ endif
libcherokee_server_la_SOURCES = \
-$(static_rule_directory_src) \
$(static_rule_extensions_src) \
$(static_rule_request_src) \
+$(static_rule_header_src) \
+$(static_rule_directory_src) \
\
$(static_handler_file_src) \
$(static_handler_admin_src) \
@@ -1002,6 +1020,7 @@ plugin_LTLIBRARIES = \
$(dynamic_rule_directory_lib) \
$(dynamic_rule_extensions_lib) \
$(dynamic_rule_request_lib) \
+$(dynamic_rule_header_lib) \
$(dynamic_handler_cgi_lib) \
$(dynamic_handler_phpcgi_lib) \
$(dynamic_handler_server_info_lib) \
View
13 cherokee/config_node.c
@@ -246,6 +246,19 @@ cherokee_config_node_read (cherokee_config_node_t *conf, const char *key, cherok
ret_t
+cherokee_config_node_copy (cherokee_config_node_t *conf, const char *key, cherokee_buffer_t *buf)
+{
+ ret_t ret;
+ cherokee_buffer_t *tmp = NULL;
+
+ ret = cherokee_config_node_read (conf, key, &tmp);
+ if (ret != ret_ok) return ret;
+
+ return cherokee_buffer_add_buffer (buf, tmp);
+}
+
+
+ret_t
cherokee_config_node_read_int (cherokee_config_node_t *conf, const char *key, int *num)
{
ret_t ret;
View
2 cherokee/config_node.h
@@ -67,6 +67,8 @@ ret_t cherokee_config_node_while (cherokee_config_node_t *conf, cherokee_con
/* Convenience functions: value retrieving
*/
ret_t cherokee_config_node_read (cherokee_config_node_t *conf, const char *key, cherokee_buffer_t **buf);
+ret_t cherokee_config_node_copy (cherokee_config_node_t *conf, const char *key, cherokee_buffer_t *buf);
+
ret_t cherokee_config_node_read_path (cherokee_config_node_t *conf, const char *key, cherokee_buffer_t **buf);
ret_t cherokee_config_node_read_int (cherokee_config_node_t *conf, const char *key, int *num);
ret_t cherokee_config_node_read_bool (cherokee_config_node_t *conf, const char *key, cherokee_boolean_t *val);
View
70 cherokee/getopt/getopt.c
@@ -1137,73 +1137,3 @@ getopt (int argc, char *const *argv, const char *optstring)
}
#endif /* Not ELIDE_CODE. */
-
-#ifdef TEST
-
-/* Compile with -DTEST to make an executable for use in testing
- the above definition of `getopt'. */
-
-int
-main (int argc, char **argv)
-{
- int c;
- int digit_optind = 0;
-
- while (1)
- {
- int this_option_optind = optind ? optind : 1;
-
- c = getopt (argc, argv, "abc:d:0123456789");
- if (c == -1)
- break;
-
- switch (c)
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (digit_optind != 0 && digit_optind != this_option_optind)
- printf ("digits occur in two different argv-elements.\n");
- digit_optind = this_option_optind;
- printf ("option %c\n", c);
- break;
-
- case 'a':
- printf ("option a\n");
- break;
-
- case 'b':
- printf ("option b\n");
- break;
-
- case 'c':
- printf ("option c with value `%s'\n", optarg);
- break;
-
- case '?':
- break;
-
- default:
- printf ("?? getopt returned character code 0%o ??\n", c);
- }
- }
-
- if (optind < argc)
- {
- printf ("non-option ARGV-elements: ");
- while (optind < argc)
- printf ("%s ", argv[optind++]);
- printf ("\n");
- }
-
- exit (0);
-}
-
-#endif /* TEST */
View
92 cherokee/getopt/getopt1.c
@@ -91,95 +91,3 @@ libc_hidden_def (getopt_long_only)
# endif
#endif /* Not ELIDE_CODE. */
-
-#ifdef TEST
-
-#include <stdio.h>
-
-int
-main (int argc, char **argv)
-{
- int c;
- int digit_optind = 0;
-
- while (1)
- {
- int this_option_optind = optind ? optind : 1;
- int option_index = 0;
- static struct option long_options[] =
- {
- {"add", 1, 0, 0},
- {"append", 0, 0, 0},
- {"delete", 1, 0, 0},
- {"verbose", 0, 0, 0},
- {"create", 0, 0, 0},
- {"file", 1, 0, 0},
- {0, 0, 0, 0}
- };
-
- c = getopt_long (argc, argv, "abc:d:0123456789",
- long_options, &option_index);
- if (c == -1)
- break;
-
- switch (c)
- {
- case 0:
- printf ("option %s", long_options[option_index].name);
- if (optarg)
- printf (" with arg %s", optarg);
- printf ("\n");
- break;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- if (digit_optind != 0 && digit_optind != this_option_optind)
- printf ("digits occur in two different argv-elements.\n");
- digit_optind = this_option_optind;
- printf ("option %c\n", c);
- break;
-
- case 'a':
- printf ("option a\n");
- break;
-
- case 'b':
- printf ("option b\n");
- break;
-
- case 'c':
- printf ("option c with value `%s'\n", optarg);
- break;
-
- case 'd':
- printf ("option d with value `%s'\n", optarg);
- break;
-
- case '?':
- break;
-
- default:
- printf ("?? getopt returned character code 0%o ??\n", c);
- }
- }
-
- if (optind < argc)
- {
- printf ("non-option ARGV-elements: ");
- while (optind < argc)
- printf ("%s ", argv[optind++]);
- printf ("\n");
- }
-
- exit (0);
-}
-
-#endif /* TEST */
View
7 cherokee/handler_fcgi.c
@@ -188,7 +188,10 @@ read_from_fcgi (cherokee_handler_cgi_base_t *cgi, cherokee_buffer_t *buffer)
return ret;
case ret_eof:
+ cgi->got_eof = true;
+ return ret;
case ret_error:
+ printf ("ERROR\n");
cgi->got_eof = true;
return ret;
@@ -534,7 +537,7 @@ connect_to_server (cherokee_handler_fcgi_t *hdl)
}
- TRACE (ENTRIES, "Connected sucessfully try=%d, fd=%d\n", try, hdl->socket.socket);
+ TRACE (ENTRIES, "Connected successfully try=%d, fd=%d\n", try, hdl->socket.socket);
cherokee_fd_set_nonblocking (SOCKET_FD(&hdl->socket));
return ret_ok;
@@ -545,7 +548,7 @@ static ret_t
do_send (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *buffer)
{
ret_t ret;
- size_t written;
+ size_t written = 0;
cherokee_connection_t *conn = HANDLER_CONN(hdl);
ret = cherokee_socket_bufwrite (&hdl->socket, buffer, &written);
View
86 cherokee/main.c
@@ -31,24 +31,37 @@
# include <getopt.h>
#endif
+/* Notices
+ */
+#define APP_NAME \
+ "Cherokee Web Server"
+
+#define APP_COPY_NOTICE \
+ "Written by Alvaro Lopez Ortega <alvaro@gnu.org>\n\n" \
+ "Copyright (C) 2001-2008 Alvaro Lopez Ortega.\n" \
+ "This is free software; see the source for copying conditions. There is NO\n" \
+ "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
+
+
+/* Default configuration
+ */
#define DEFAULT_CONFIG_FILE CHEROKEE_CONFDIR "/cherokee.conf"
-#define GETOPT_OPT "C:r:p:bhvgt"
-#define CONFIG_FILE_HELP "[-C configfile] [-r DIR [-p PORT]] [-g] [-t]"
-
-#define BASIC_CONFIG \
- "vserver!default!rule!default!handler = common\n" \
- "vserver!default!rule!default!handler!iocache = 0\n" \
- "vserver!default!rule!default!priority = 1\n" \
- "vserver!default!rule!directory!/icons!handler = file\n" \
- "vserver!default!rule!directory!/icons!document_root = " CHEROKEE_ICONSDIR "\n" \
- "vserver!default!rule!directory!/icons!priority = 2\n" \
- "vserver!default!rule!directory!/cherokee_themes!handler = file\n" \
- "vserver!default!rule!directory!/cherokee_themes!document_root = " CHEROKEE_THEMEDIR "\n" \
- "vserver!default!rule!directory!/cherokee_themes!priority = 3\n" \
- "icons!default = page_white.png\n" \
- "icons!directory = folder.png\n" \
- "icons!parent_directory = arrow_turn_left.png\n" \
+#define BASIC_CONFIG \
+ "vserver!default!rule!1!match!type = default\n" \
+ "vserver!default!rule!1!handler = common\n" \
+ "vserver!default!rule!1!handler!iocache = 0\n" \
+ "vserver!default!rule!2!match!type = directory\n" \
+ "vserver!default!rule!2!match!directory = /icons\n" \
+ "vserver!default!rule!2!handler = file\n" \
+ "vserver!default!rule!2!document_root = " CHEROKEE_ICONSDIR "\n" \
+ "vserver!default!rule!3!match!type = directory\n" \
+ "vserver!default!rule!3!match!directory = /cherokee_themes\n" \
+ "vserver!default!rule!3!handler = file\n" \
+ "vserver!default!rule!3!document_root = " CHEROKEE_THEMEDIR "\n" \
+ "icons!default = page_white.png\n" \
+ "icons!directory = folder.png\n" \
+ "icons!parent_directory = arrow_turn_left.png\n" \
"try_include = " CHEROKEE_CONFDIR "/mods-enabled\n"
static cherokee_server_t *srv = NULL;
@@ -171,18 +184,43 @@ common_server_initialization (cherokee_server_t *srv)
return ret_ok;
}
+static void
+print_help (void)
+{
+ printf (APP_NAME "\n"
+ "Usage: cherokee [options]\n\n"
+ " -h, --help Print this help\n"
+ " -V, --version Print version and exit\n"
+ " -t, --test Just test configuration file\n"
+ " -d, --detach Detach from the console\n"
+ " -C, --config=PATH Configuration file\n"
+ " -p, --port=NUM TCP port number\n"
+ " -r, --documentroot=PATH Server directory content\n\n"
+ "Report bugs to " PACKAGE_BUGREPORT "\n");
+}
static void
process_parameters (int argc, char **argv)
{
int c;
- while ((c = getopt(argc, argv, GETOPT_OPT)) != -1) {
+ struct option long_options[] = {
+ {"help", no_argument, NULL, 'h'},
+ {"version", no_argument, NULL, 'V'},
+ {"detach", no_argument, NULL, 'd'},
+ {"test", no_argument, NULL, 't'},
+ {"port", required_argument, NULL, 'p'},
+ {"documentroot", required_argument, NULL, 'r'},
+ {"config", required_argument, NULL, 'C'},
+ {NULL, 0, NULL, 0}
+ };
+
+ while ((c = getopt_long(argc, argv, "hVdtp:r:C:", long_options, NULL)) != -1) {
switch(c) {
case 'C':
config_file = strdup(optarg);
break;
- case 'b':
+ case 'd':
daemon_mode = true;
break;
case 'r':
@@ -191,17 +229,17 @@ process_parameters (int argc, char **argv)
case 'p':
port = atoi(optarg);
break;
- case 'v':
- fprintf (stdout, "%s\n", PACKAGE_STRING);
- exit(1);
- break;
case 't':
just_test = true;
break;
+ case 'V':
+ printf (APP_NAME " " PACKAGE_VERSION "\n" APP_COPY_NOTICE);
+ exit(0);
case 'h':
+ case '?':
default:
- fprintf (stderr, "Usage: %s " CONFIG_FILE_HELP " [-b] -h -v\n", argv[0]);
- exit(1);
+ print_help();
+ exit(0);
}
}
}
View
116 cherokee/main_admin.c
@@ -31,19 +31,25 @@
# include <getopt.h>
#endif
-#define GETOPT_OPT "d:p:aC:"
-#define CONFIG_FILE_HELP "[-d DIR] [-p PORT] [-C FILE] [-a]"
+#define APP_NAME \
+ "Cherokee Web Server: Admin"
+
+#define APP_COPY_NOTICE \
+ "Written by Alvaro Lopez Ortega <alvaro@gnu.org>\n\n" \
+ "Copyright (C) 2001-2008 Alvaro Lopez Ortega.\n" \
+ "This is free software; see the source for copying conditions. There is NO\n" \
+ "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
#define DEFAULT_PORT 9090
#define DEFAULT_DOCUMENTROOT CHEROKEE_DATADIR "/admin"
#define DEFAULT_CONFIG_FILE CHEROKEE_CONFDIR "/cherokee.conf"
+#define DEFAULT_BIND "127.0.0.1"
#define RULE "vserver!default!rule!"
-static int port = DEFAULT_PORT;
-static char *document_root = DEFAULT_DOCUMENTROOT;
-static char *config_file = DEFAULT_CONFIG_FILE;
-static cherokee_boolean_t bind_local = true;
-
+static int port = DEFAULT_PORT;
+static char *document_root = DEFAULT_DOCUMENTROOT;
+static char *config_file = DEFAULT_CONFIG_FILE;
+static char *bind_to = DEFAULT_BIND;
static ret_t
config_server (cherokee_server_t *srv)
@@ -55,32 +61,41 @@ config_server (cherokee_server_t *srv)
cherokee_buffer_add_str (&buf, "server!ipv6 = 0\n");
cherokee_buffer_add_str (&buf, "server!max_connection_reuse = 0\n");
- if (bind_local)
- cherokee_buffer_add_str (&buf, "server!listen = 127.0.0.1\n");
+ if (bind_to)
+ cherokee_buffer_add_va (&buf, "server!listen = %s\n", bind_to);
cherokee_buffer_add_va (&buf, "vserver!default!document_root = %s\n", document_root);
- cherokee_buffer_add_str (&buf, RULE"default!handler = scgi\n");
- cherokee_buffer_add_str (&buf, RULE"default!handler!balancer = round_robin\n");
- cherokee_buffer_add_str (&buf, RULE"default!handler!balancer!type = interpreter\n");
- cherokee_buffer_add_str (&buf, RULE"default!handler!balancer!local1!host = localhost:4000\n");
- cherokee_buffer_add_va (&buf, RULE"default!handler!balancer!local1!interpreter = %s/server.py %s\n", document_root, config_file);
- cherokee_buffer_add_str (&buf, RULE"default!priority = 1\n");
-
- cherokee_buffer_add_str (&buf, RULE"directory!/about!handler = server_info\n");
- cherokee_buffer_add_str (&buf, RULE"directory!/about!priority = 2\n");
-
- cherokee_buffer_add_str (&buf, RULE"directory!/static!handler = file\n");
- cherokee_buffer_add_str (&buf, RULE"directory!/static!handler!iocache = 0\n");
- cherokee_buffer_add_str (&buf, RULE"directory!/static!priority = 3\n");
-
- cherokee_buffer_add_str (&buf, RULE"request!^/favicon.ico$!handler = file\n");
- cherokee_buffer_add_str (&buf, RULE"request!^/favicon.ico$!priority = 4\n");
-
- cherokee_buffer_add_str (&buf, RULE"directory!/icons_local!handler = file\n");
- cherokee_buffer_add_str (&buf, RULE"directory!/icons_local!handler!iocache = 0\n");
- cherokee_buffer_add_va (&buf, RULE"directory!/icons_local!document_root = %s\n", CHEROKEE_ICONSDIR);
- cherokee_buffer_add_str (&buf, RULE"directory!/icons_local!priority = 5\n");
+ cherokee_buffer_add_va (&buf,
+ RULE "1!match!type = default\n"
+ RULE "1!handler = scgi\n"
+ RULE "1!handler!balancer = round_robin\n"
+ RULE "1!handler!balancer!type = interpreter\n"
+ RULE "1!handler!balancer!local1!host = localhost:4000\n"
+ RULE "1!handler!balancer!local1!interpreter = %s/server.py %s\n", document_root, config_file);
+
+ cherokee_buffer_add_str (&buf,
+ RULE "2!match!type = directory\n"
+ RULE "2!match!directory = /about\n"
+ RULE "2!handler = server_info\n");
+
+ cherokee_buffer_add_str (&buf,
+ RULE "3!match!type = directory\n"
+ RULE "3!match!directory = /static\n"
+ RULE "3!handler = file\n"
+ RULE "3!handler!iocache = 0\n");
+
+ cherokee_buffer_add_str (&buf,
+ RULE "4!match!type = request\n"
+ RULE "4!match!request = ^/favicon.ico$\n"
+ RULE "4!handler = file\n");
+
+ cherokee_buffer_add_va (&buf,
+ RULE "5!match!type = directory\n"
+ RULE "5!match!directory = /icons_local\n"
+ RULE "5!handler = file\n"
+ RULE "5!handler!iocache = 0\n"
+ RULE "5!document_root = %s\n", CHEROKEE_ICONSDIR);
ret = cherokee_server_read_config_string (srv, &buf);
if (ret != ret_ok) return ret;
@@ -89,16 +104,42 @@ config_server (cherokee_server_t *srv)
return ret_ok;
}
+static void
+print_help (void)
+{
+ printf (APP_NAME "\n"
+ "Usage: cherokee-admin [options]\n\n"
+ " -h, --help Print this help\n"
+ " -V, --version Print version and exit\n"
+ " -l, --listen[=IP] Bind net iface; no arg means all\n"
+ " -d, --appdir=DIR Application directory\n"
+ " -p, --port=NUM TCP port\n"
+ " -C, --target=PATH Configuration file to modify\n\n"
+ "Report bugs to " PACKAGE_BUGREPORT "\n");
+}
static void
process_parameters (int argc, char **argv)
{
int c;
- while ((c = getopt(argc, argv, GETOPT_OPT)) != -1) {
+ struct option long_options[] = {
+ {"help", no_argument, NULL, 'h'},
+ {"version", no_argument, NULL, 'V'},
+ {"bind", optional_argument, NULL, 'b'},
+ {"appdir", required_argument, NULL, 'd'},
+ {"port", required_argument, NULL, 'p'},
+ {"target", required_argument, NULL, 'C'},
+ {NULL, 0, NULL, 0}
+ };
+
+ while ((c = getopt_long(argc, argv, "hVb::d:p:C:", long_options, NULL)) != -1) {
switch(c) {
- case 'a':
- bind_local = false;
+ case 'b':
+ if (optarg)
+ bind_to = strdup(optarg);
+ else
+ bind_to = NULL;
break;
case 'p':
port = atoi(optarg);
@@ -109,9 +150,14 @@ process_parameters (int argc, char **argv)
case 'C':
config_file = strdup(optarg);
break;
+ case 'V':
+ printf (APP_NAME " " PACKAGE_VERSION "\n" APP_COPY_NOTICE);
+ exit(0);
+ case 'h':
+ case '?':
default:
- fprintf (stderr, "Usage: %s " CONFIG_FILE_HELP "\n", argv[0]);
- exit(1);
+ print_help();
+ exit(0);
}
}
}
View
2 cherokee/module.h
@@ -34,10 +34,8 @@
#include <cherokee/config_node.h>
#include <cherokee/server.h>
-
CHEROKEE_BEGIN_DECLS
-
/* Callback function prototipes
*/
typedef void * module_func_init_t;
View
1 cherokee/plugin_loader.h
@@ -32,6 +32,7 @@
#include <cherokee/common.h>
#include <cherokee/module.h>
#include <cherokee/avl.h>
+#include <cherokee/plugin.h>
CHEROKEE_BEGIN_DECLS
View
46 cherokee/rule.c
@@ -25,7 +25,9 @@
#include "common-internal.h"
#include "rule.h"
#include "connection.h"
+#include "virtual_server.h"
+#define ENTRIES "rule"
ret_t
cherokee_rule_init_base (cherokee_rule_t *rule, cherokee_plugin_info_t *info)
@@ -61,6 +63,49 @@ cherokee_rule_free (cherokee_rule_t *rule)
}
+static ret_t
+configure_base (cherokee_rule_t *rule,
+ cherokee_config_node_t *conf,
+ cherokee_virtual_server_t *vsrv)
+{
+ ret_t ret;
+ cherokee_buffer_t *final = NULL;
+
+ /* Set the final value
+ */
+ ret = cherokee_config_node_read (conf, "final", &final);
+ if (ret == ret_ok) {
+ rule->final = !! atoi(final->buf);
+ TRACE(ENTRIES, "Rule prio=%d set final to %d\n",
+ rule->priority, rule->final);
+ }
+
+ return ret_ok;
+}
+
+
+ret_t
+cherokee_rule_configure (cherokee_rule_t *rule, cherokee_config_node_t *conf, void *vsrv)
+{
+ ret_t ret;
+
+ /* Sanity checks
+ */
+ return_if_fail (rule != NULL, ret_error);
+
+ if (rule->configure == NULL) {
+ return ret_error;
+ }
+
+ ret = configure_base (rule, conf, VSERVER(vsrv));
+ if (ret != ret_ok) return ret;
+
+ /* Call the real method
+ */
+ return rule->configure (rule, conf, VSERVER(vsrv));
+}
+
+
ret_t
cherokee_rule_match (cherokee_rule_t *rule, void *cnt)
{
@@ -76,3 +121,4 @@ cherokee_rule_match (cherokee_rule_t *rule, void *cnt)
*/
return rule->match (rule, CONN(cnt));
}
+
View
10 cherokee/rule.h
@@ -31,7 +31,9 @@
#include <cherokee/common.h>
#include <cherokee/module.h>
#include <cherokee/buffer.h>
+#include <cherokee/list.h>
#include <cherokee/config_entry.h>
+#include <cherokee/plugin.h>
CHEROKEE_BEGIN_DECLS
@@ -40,8 +42,9 @@ CHEROKEE_BEGIN_DECLS
/* Callback function definitions
*/
-typedef ret_t (* rule_func_new_t) (void **rule, cherokee_buffer_t *value, void *vsrv);
-typedef ret_t (* rule_func_match_t) (void *rule, void *cnt);
+typedef ret_t (* rule_func_new_t) (void **rule);
+typedef ret_t (* rule_func_configure_t) (void *rule, cherokee_config_node_t *conf, void *vsrv);
+typedef ret_t (* rule_func_match_t) (void *rule, void *cnt);
/* Data types
*/
@@ -57,7 +60,7 @@ typedef struct {
/* Virtual methods */
rule_func_match_t match;
-
+ rule_func_configure_t configure;
} cherokee_rule_t;
#define RULE(x) ((cherokee_rule_t *)(x))
@@ -84,6 +87,7 @@ ret_t cherokee_rule_init_base (cherokee_rule_t *rule, cherokee_plugin_info_t *
/* Rule virtual methods
*/
ret_t cherokee_rule_match (cherokee_rule_t *rule, void *cnt);
+ret_t cherokee_rule_configure (cherokee_rule_t *rule, cherokee_config_node_t *conf, void *vsrv);
CHEROKEE_END_DECLS
View
14 cherokee/rule_default.c
@@ -45,11 +45,16 @@ match (cherokee_rule_t *rule, cherokee_connection_t *conn)
return ret_ok;
}
+static ret_t
+configure (cherokee_rule_default_t *rule,
+ cherokee_config_node_t *conf,
+ cherokee_virtual_server_t *vsrv)
+{
+ return ret_ok;
+}
ret_t
-cherokee_rule_default_new (cherokee_rule_t **rule,
- cherokee_buffer_t *value,
- cherokee_virtual_server_t *vsrv)
+cherokee_rule_default_new (cherokee_rule_t **rule)
{
CHEROKEE_NEW_STRUCT (n, rule_default);
@@ -59,7 +64,8 @@ cherokee_rule_default_new (cherokee_rule_t **rule,
/* Virtual methos
*/
- RULE(n)->match = (rule_func_match_t) match;
+ RULE(n)->match = (rule_func_match_t) match;
+ RULE(n)->configure = (rule_func_configure_t) configure;
*rule = n;
return ret_ok;
View
6 cherokee/rule_default.h
@@ -31,17 +31,13 @@
#include <cherokee/common.h>
#include <cherokee/rule.h>
-#include <cherokee/buffer.h>
-#include <cherokee/virtual_server.h>
CHEROKEE_BEGIN_DECLS
typedef cherokee_rule_t cherokee_rule_default_t;
#define RULE_DEFAULT(x) ((cherokee_rule_default_t *)(x))
-ret_t cherokee_rule_default_new (cherokee_rule_t **rule,
- cherokee_buffer_t *value,
- cherokee_virtual_server_t *vsrv);
+ret_t cherokee_rule_default_new (cherokee_rule_t **rule);
CHEROKEE_END_DECLS
View
45 cherokee/rule_directory.c
@@ -32,21 +32,22 @@
PLUGIN_INFO_RULE_EASIEST_INIT(directory);
-static ret_t
+
+static ret_t
match (cherokee_rule_directory_t *rule, cherokee_connection_t *conn)
{
- /* Not the same lenght
+ /* Not the same lenght
*/
if (conn->request.len < rule->directory.len) {
TRACE(ENTRIES, "Match directory: rule=%s conn=%s: (shorter) ret_not_found\n",
rule->directory.buf, conn->request.buf);
return ret_not_found;
}
- /* Does not match
+ /* Does not match
*/
if (strncmp (rule->directory.buf, conn->request.buf, rule->directory.len) != 0) {
- TRACE(ENTRIES, "Match directory: rule=%s conn=%s: (str) ret_not_found\n",
+ TRACE(ENTRIES, "Match directory: rule=%s conn=%s: (str) ret_not_found\n",
rule->directory.buf, conn->request.buf);
return ret_not_found;
}
@@ -76,23 +77,39 @@ match (cherokee_rule_directory_t *rule, cherokee_connection_t *conn)
return ret_error;
}
- /* Set the web_directory if needed
+ /* Set the web_directory if needed
*/
- if (cherokee_buffer_is_empty (&conn->web_directory)) {
- cherokee_buffer_add_str (&conn->web_directory, "/");
- }
+ if (cherokee_buffer_is_empty (&conn->web_directory)) {
+ cherokee_buffer_add_str (&conn->web_directory, "/");
+ }
- TRACE(ENTRIES, "Match! rule=%s conn=%s: ret_ok\n",
+ TRACE(ENTRIES, "Match! rule=%s conn=%s: ret_ok\n",
rule->directory.buf, conn->request.buf);
return ret_ok;
}
+static ret_t
+configure (cherokee_rule_directory_t *rule,
+ cherokee_config_node_t *conf,
+ cherokee_virtual_server_t *vsrv)
+{
+ ret_t ret;
+
+ ret = cherokee_config_node_copy (conf, "directory", &rule->directory);
+ if (ret != ret_ok) {
+ PRINT_ERROR ("Rule prio=%d needs a 'directory' property",
+ RULE(rule)->priority);
+ return ret_error;
+ }
+
+ return ret_ok;
+}
+
+
ret_t
-cherokee_rule_directory_new (cherokee_rule_directory_t **rule,
- cherokee_buffer_t *value,
- cherokee_virtual_server_t *vsrv)
+cherokee_rule_directory_new (cherokee_rule_directory_t **rule)
{
CHEROKEE_NEW_STRUCT (n, rule_directory);
@@ -102,12 +119,12 @@ cherokee_rule_directory_new (cherokee_rule_directory_t **rule,
/* Virtual methos
*/
- RULE(n)->match = (rule_func_match_t) match;
+ RULE(n)->match = (rule_func_match_t) match;
+ RULE(n)->configure = (rule_func_configure_t) configure;
/* Properties
*/
cherokee_buffer_init (&n->directory);
- cherokee_buffer_add_buffer (&n->directory, value);
*rule = n;
return ret_ok;
View
7 cherokee/rule_directory.h
@@ -30,9 +30,8 @@
#define CHEROKEE_RULE_DIR_H
#include <cherokee/common.h>
-#include <cherokee/buffer.h>
#include <cherokee/rule.h>
-#include <cherokee/virtual_server.h>
+#include <cherokee/buffer.h>
CHEROKEE_BEGIN_DECLS
@@ -43,9 +42,7 @@ typedef struct {
#define RULE_DIRECTORY(x) ((cherokee_rule_directory_t *)(x))
-ret_t cherokee_rule_directory_new (cherokee_rule_directory_t **rule,
- cherokee_buffer_t *value,
- cherokee_virtual_server_t *vsrv);
+ret_t cherokee_rule_directory_new (cherokee_rule_directory_t **rule);
CHEROKEE_END_DECLS
View
26 cherokee/rule_extensions.c
@@ -74,10 +74,26 @@ match (cherokee_rule_extensions_t *rule, cherokee_connection_t *conn)
}
+static ret_t
+configure (cherokee_rule_extensions_t *rule,
+ cherokee_config_node_t *conf,
+ cherokee_virtual_server_t *vsrv)
+{
+ ret_t ret;
+ cherokee_buffer_t *tmp = NULL;
+
+ ret = cherokee_config_node_read (conf, "extensions", &tmp);
+ if (ret != ret_ok) {
+ PRINT_ERROR ("Rule prio=%d needs an 'extensions' property\n",
+ RULE(rule)->priority);
+ return ret_error;
+ }
+
+ return parse_value (tmp, &rule->extensions);
+}
+
ret_t
-cherokee_rule_extensions_new (cherokee_rule_extensions_t **rule,
- cherokee_buffer_t *value,
- cherokee_virtual_server_t *vsrv)
+cherokee_rule_extensions_new (cherokee_rule_extensions_t **rule)
{
CHEROKEE_NEW_STRUCT (n, rule_extensions);
@@ -87,12 +103,12 @@ cherokee_rule_extensions_new (cherokee_rule_extensions_t **rule,
/* Virtual methos
*/
- RULE(n)->match = (rule_func_match_t) match;
+ RULE(n)->match = (rule_func_match_t) match;
+ RULE(n)->configure = (rule_func_configure_t) configure;
/* Properties
*/
cherokee_avl_init (&n->extensions);
- parse_value (value, &n->extensions);
*rule = n;
return ret_ok;
View
5 cherokee/rule_extensions.h
@@ -33,7 +33,6 @@
#include <cherokee/buffer.h>
#include <cherokee/rule.h>
#include <cherokee/avl.h>
-#include <cherokee/virtual_server.h>
CHEROKEE_BEGIN_DECLS
@@ -44,9 +43,7 @@ typedef struct {
#define RULE_EXTENSIONS(x) ((cherokee_rule_extensions_t *)(x))
-ret_t cherokee_rule_extensions_new (cherokee_rule_extensions_t **rule,
- cherokee_buffer_t *value,
- cherokee_virtual_server_t *vsrv);
+ret_t cherokee_rule_extensions_new (cherokee_rule_extensions_t **rule);
CHEROKEE_END_DECLS
View
99 cherokee/rule_header.c
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* Cherokee
+ *
+ * Authors:
+ * Alvaro Lopez Ortega <alvaro@alobbs.com>
+ *
+ * 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 "common-internal.h"
+#include "rule_header.h"
+
+#include "plugin_loader.h"
+#include "server-protected.h"
+#include "connection-protected.h"
+#include "util.h"
+#include "pcre/pcre.h"
+
+#define ENTRIES "rule,header"
+
+PLUGIN_INFO_RULE_EASIEST_INIT(header);
+
+
+static ret_t
+match (cherokee_rule_header_t *rule,
+ cherokee_connection_t *conn)
+{
+ return ret_ok;
+}
+
+
+static ret_t
+configure (cherokee_rule_header_t *rule,
+ cherokee_config_node_t *conf,
+ cherokee_virtual_server_t *vsrv)
+{
+ ret_t ret;
+ cherokee_buffer_t *header = NULL;
+
+ ret = cherokee_config_node_read (conf, "header", &header);
+ if (ret != ret_ok) {
+ PRINT_ERROR ("Rule header prio=%d needs a header entry\n",
+ RULE(rule)->priority);
+ return ret_error;
+ }
+
+
+
+
+/* cherokee_buffer_add_buffer (&n->pattern, value); */
+
+/* ret = cherokee_regex_table_add (VSERVER_SRV(vsrv)->regexs, value->buf); */
+/* if (ret != ret_ok) return ret; */
+
+/* ret = cherokee_regex_table_get (VSERVER_SRV(vsrv)->regexs, value->buf, &n->pcre); */
+/* if (ret != ret_ok) return ret; */
+
+ return ret_ok;
+}
+
+
+ret_t
+cherokee_rule_header_new (cherokee_rule_header_t **rule)
+{
+ ret_t ret;
+
+ CHEROKEE_NEW_STRUCT (n, rule_header);
+
+ /* Parent class constructor
+ */
+ cherokee_rule_init_base (RULE(n), PLUGIN_INFO_PTR(header));
+
+ /* Virtual methos
+ */
+ RULE(n)->match = (rule_func_match_t) match;
+
+ /* Properties
+ */
+ n->pcre = NULL;
+ cherokee_buffer_init (&n->pattern);
+
+ *rule = n;
+ return ret_ok;
+}
View
54 cherokee/rule_header.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* Cherokee
+ *
+ * Authors:
+ * Alvaro Lopez Ortega <alvaro@alobbs.com>
+ *
+ * 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
+ */
+
+#if !defined (CHEROKEE_INSIDE_CHEROKEE_H) && !defined (CHEROKEE_COMPILATION)
+# error "Only <cherokee/cherokee.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef CHEROKEE_RULE_HEADER_H
+#define CHEROKEE_RULE_HEADER_H
+
+#include <cherokee/common.h>
+#include <cherokee/buffer.h>
+#include <cherokee/rule.h>
+#include <cherokee/regex.h>
+
+CHEROKEE_BEGIN_DECLS
+
+typedef struct {
+ cherokee_rule_t rule;
+
+ int ovector[OVECTOR_LEN];
+ int ovecsize;
+ void *pcre;
+ cherokee_buffer_t pattern;
+} cherokee_rule_header_t;
+
+#define RULE_HEADER(x) ((cherokee_rule_header_t *)(x))
+
+ret_t cherokee_rule_header_new (cherokee_rule_header_t **rule);
+
+CHEROKEE_END_DECLS
+
+#endif /* CHEROKEE_RULE_HEADER_H */
View
3 cherokee/rule_list.c
@@ -24,6 +24,7 @@
#include "common-internal.h"
#include "rule_list.h"
+
#include "util.h"
#include "connection-protected.h"
#include "rule_default.h"
@@ -38,7 +39,7 @@ cherokee_rule_list_init (cherokee_rule_list_t *list)
INIT_LIST_HEAD (&list->rules);
- ret = cherokee_rule_default_new (&list->def_rule, NULL, NULL);
+ ret = cherokee_rule_default_new (&list->def_rule);
if (ret != ret_ok) return ret;
return ret_ok;
View
47 cherokee/rule_request.c
@@ -99,10 +99,38 @@ match (cherokee_rule_request_t *rule, cherokee_connection_t *conn)
}
+static ret_t
+configure (cherokee_rule_request_t *rule,
+ cherokee_config_node_t *conf,
+ cherokee_virtual_server_t *vsrv)
+{
+ ret_t ret;
+
+ /* Read the configuration entry
+ */
+ ret = cherokee_config_node_copy (conf, "request", &rule->pattern);
+ if (ret != ret_ok) {
+ PRINT_ERROR ("Rule prio=%d needs a 'request' property",
+ RULE(rule)->priority);
+ return ret_error;
+ }
+
+ /* Add it to the regular extension table
+ */
+ ret = cherokee_regex_table_add (VSERVER_SRV(vsrv)->regexs,
+ rule->pattern.buf);
+ if (ret != ret_ok) return ret;
+
+ ret = cherokee_regex_table_get (VSERVER_SRV(vsrv)->regexs,
+ rule->pattern.buf, &rule->pcre);
+ if (ret != ret_ok) return ret;
+
+ return ret_ok;
+}
+
+
ret_t
-cherokee_rule_request_new (cherokee_rule_request_t **rule,
- cherokee_buffer_t *value,
- cherokee_virtual_server_t *vsrv)
+cherokee_rule_request_new (cherokee_rule_request_t **rule)
{
ret_t ret;
@@ -114,20 +142,13 @@ cherokee_rule_request_new (cherokee_rule_request_t **rule,
/* Virtual methos
*/
- RULE(n)->match = (rule_func_match_t) match;
+ RULE(n)->match = (rule_func_match_t) match;
+ RULE(n)->configure = (rule_func_configure_t) configure;
/* Properties
*/
- cherokee_buffer_init (&n->pattern);
- cherokee_buffer_add_buffer (&n->pattern, value);
-
n->pcre = NULL;
-
- ret = cherokee_regex_table_add (VSERVER_SRV(vsrv)->regexs, value->buf);
- if (ret != ret_ok) return ret;
-
- ret = cherokee_regex_table_get (VSERVER_SRV(vsrv)->regexs, value->buf, &n->pcre);
- if (ret != ret_ok) return ret;
+ cherokee_buffer_init (&n->pattern);
*rule = n;
return ret_ok;
View
12 cherokee/rule_request.h
@@ -26,14 +26,13 @@
# error "Only <cherokee/cherokee.h> can be included directly, this file may disappear or change contents."
#endif
-#ifndef CHEROKEE_RULE_EXTS_H
-#define CHEROKEE_RULE_EXTS_H
+#ifndef CHEROKEE_RULE_REQS_H
+#define CHEROKEE_RULE_REQS_H
#include <cherokee/common.h>
#include <cherokee/buffer.h>
#include <cherokee/rule.h>
#include <cherokee/regex.h>
-#include <cherokee/virtual_server.h>
CHEROKEE_BEGIN_DECLS
@@ -47,11 +46,8 @@ typedef struct {
} cherokee_rule_request_t;
#define RULE_REQUEST(x) ((cherokee_rule_request_t *)(x))
-
-ret_t cherokee_rule_request_new (cherokee_rule_request_t **rule,
- cherokee_buffer_t *value,
- cherokee_virtual_server_t *vsrv);
+ret_t cherokee_rule_request_new (cherokee_rule_request_t **rule);
CHEROKEE_END_DECLS
-#endif /* CHEROKEE_RULE_EXTS_H */
+#endif /* CHEROKEE_RULE_REQS_H */
View
4 cherokee/socket.c
@@ -1587,6 +1587,8 @@ cherokee_socket_connect (cherokee_socket_t *sock)
{
int r;
+ TRACE (ENTRIES, "connect type=%d\n", SOCKET_AF(sock));
+
switch (SOCKET_AF(sock)) {
case AF_INET:
r = connect (SOCKET_FD(sock), (struct sockaddr *) &SOCKET_ADDR(sock), sizeof(struct sockaddr_in));
@@ -1606,6 +1608,8 @@ cherokee_socket_connect (cherokee_socket_t *sock)
return ret_no_sys;
}
+ TRACE (ENTRIES, "connect type=%d ret=%d\n", SOCKET_AF(sock), r);
+
if (r < 0) {
int err = SOCK_ERRNO();
View
4 cherokee/validator.c
@@ -426,11 +426,15 @@ cherokee_validator_configure (cherokee_config_node_t *conf, void *config_entry)
subconf = CONFIG_NODE(i);
if (equal_buf_str (&subconf->key, "realm")) {
+ TRACE(ENTRIES, "Realm: %s\n", subconf->val.buf);
+
ret = cherokee_buffer_dup (&subconf->val, &entry->auth_realm);
if (ret != ret_ok)
return ret;
} else if (equal_buf_str (&subconf->key, "methods")) {
+ TRACE(ENTRIES, "Methods: %s\n", subconf->val.buf);
+
ret = cherokee_config_node_read_list (subconf, NULL, add_method, entry);
if (ret != ret_ok)
return ret;
View
171 cherokee/virtual_server.c
@@ -460,9 +460,10 @@ init_entry_property (cherokee_config_node_t *conf, void *data)
} else if (equal_buf_str (&conf->key, "only_secure")) {
entry->only_secure = !! atoi(conf->val.buf);
- } else if ((equal_buf_str (&conf->key, "final")) ||
- (equal_buf_str (&conf->key, "priority")))
- {
+ } else if (equal_buf_str (&conf->key, "only_secure")) {
+ entry->only_secure = !! atoi(conf->val.buf);
+
+ } else if (equal_buf_str (&conf->key, "match")) {
/* Ignore: Previously handled
*/
} else {
@@ -489,30 +490,6 @@ init_entry (cherokee_virtual_server_t *vserver,
return ret_ok;
}
-static ret_t
-init_rule (cherokee_virtual_server_t *vserver,
- cherokee_config_node_t *config,
- cherokee_rule_t *rule)
-{
- ret_t ret;
-
- /* Check whether is rule is 'final'
- */
- cherokee_config_node_read_bool (config, "final", &rule->final);
-
- /* Read the priority value. Needed value.
- */
- ret = cherokee_config_node_read_int (config, "priority", (int *)&rule->priority);
- if (ret != ret_ok) {
- PRINT_ERROR("A valid 'priority' property is required: '%s'\n", config->key.buf);
- return ret_error;
- }
-
- /* Read the the config_entry properties
- */
- return init_entry (vserver, config, &rule->config);
-}
-
static ret_t
add_error_handler (cherokee_config_node_t *config, cherokee_virtual_server_t *vserver)
@@ -548,65 +525,100 @@ add_error_handler (cherokee_config_node_t *config, cherokee_virtual_server_t *vs
static ret_t
-add_rule_default (cherokee_config_node_t *config,
- cherokee_virtual_server_t *vserver,
- cherokee_rule_list_t *rule_list)
+configure_rule_match (cherokee_config_node_t *config,
+ cherokee_virtual_server_t *vserver,
+ cherokee_rule_list_t *rule_list,
+ cuint_t priority,
+ cherokee_rule_t **rule)
{
- ret_t ret;
+ ret_t ret;
+ rule_func_new_t func_new;
+ cherokee_buffer_t *type = NULL;
+ cherokee_plugin_info_t *info = NULL;
+ cherokee_server_t *srv = VSERVER_SRV(vserver);
+
+ ret = cherokee_config_node_read (config, "type", &type);
+ if (ret != ret_ok) {
+ PRINT_ERROR ("Rule match prio=%d must include a type property\n", priority);
+ return ret;
+ }
+
+ TRACE (ENTRIES, "Adding type=%s\n", type->buf);
- /* Read config_node into the default rule
+ /* Default is compled in, the rest are loded as plug-ins
*/
- ret = init_entry (vserver, config, &rule_list->def_rule->config);
- if (ret != ret_ok)
- return ret;
+ if (equal_buf_str (type, "default")) {
+ func_new = (rule_func_new_t) cherokee_rule_default_new;
+
+ } else {
+ ret = cherokee_plugin_loader_get (&srv->loader, type->buf, &info);
+ if (ret < ret_ok) {
+ PRINT_MSG ("ERROR: Couldn't load rule module '%s'\n", type->buf);
+ return ret_error;
+ }
+
+ func_new = (rule_func_new_t) info->instance;
+ }
+
+ /* Instance the rule object
+ */
+ if (func_new == NULL)
+ return ret_error;
+
+ ret = func_new ((void **) rule);
+ if ((ret != ret_ok) || (*rule == NULL))
+ return ret_error;
+
+ /* Configure it
+ */
+ (*rule)->priority = priority;
+
+ ret = cherokee_rule_configure (*rule, config, vserver);
+ if (ret != ret_ok)
+ return ret_error;
- TRACE(ENTRIES, "Adding rule: type='default' %s", "\n");
return ret_ok;
}
static ret_t
-add_rule (cherokee_buffer_t *rule_type,
- cherokee_buffer_t *rule_value,
- cherokee_config_node_t *config,
+add_rule (cherokee_config_node_t *config,
cherokee_virtual_server_t *vserver,
cherokee_rule_list_t *rule_list)
{
ret_t ret;
- rule_func_new_t func_new;
- cherokee_rule_t *rule = NULL;
- cherokee_plugin_info_t *info = NULL;
- cherokee_server_t *srv = VSERVER_SRV(vserver);
+ cuint_t prio;
+ cherokee_rule_t *rule = NULL;
+ cherokee_config_node_t *subconf = NULL;
- /* Load the rule plugin
+ /* Validate priority
*/
- ret = cherokee_plugin_loader_get (&srv->loader, rule_type->buf, &info);
- if (ret < ret_ok) {
- PRINT_MSG ("ERROR: Couldn't load logger module '%s'\n", config->val.buf);
+ prio = atoi(config->key.buf);
+ if (prio <= CHEROKEE_RULE_PRIO_NONE) {
+ PRINT_ERROR ("Invalid priority: '%s'\n", config->key.buf);
return ret_error;
}
-
- /* Instance a new rule object
+
+ /* Configure the rule match section
*/
- func_new = (rule_func_new_t) info->instance;
- if (func_new == NULL)
- goto failed;
+ ret = cherokee_config_node_get (config, "match", &subconf);
+ if (ret != ret_ok) {
+ PRINT_ERROR ("Rule prio=%d needs a 'match' section\n", prio);
+ return ret_error;
+ }
- ret = func_new ((void **) &rule, rule_value, vserver);
- if (ret != ret_ok)
+ ret = configure_rule_match (subconf, vserver, rule_list, prio, &rule);
+ if (ret != ret_ok)
goto failed;
-
+
/* config_node -> config_entry
*/
- ret = init_rule (vserver, config, rule);
+ ret = init_entry (vserver, config, &rule->config);
if (ret != ret_ok)
goto failed;
- /* Add the rule to the list
+ /* Add the rule to the vserver's list
*/
- TRACE(ENTRIES, "Adding rule: prio='%d' type='%s' value='%s'\n",
- rule->priority, rule_type->buf, rule_value->buf);
-
ret = cherokee_rule_list_add (rule_list, rule);
if (ret != ret_ok)
goto failed;
@@ -620,6 +632,7 @@ add_rule (cherokee_buffer_t *rule_type,
return ret_error;
}
+
static ret_t
add_domain (cherokee_config_node_t *config, cherokee_virtual_server_t *vserver)
{
@@ -682,38 +695,24 @@ configure_rules (cherokee_config_node_t *config,
ret_t ret;
cherokee_list_t *i, *j;
cherokee_config_node_t *subconf;
- cherokee_boolean_t did_default = false;
+// cherokee_boolean_t did_default = false;
cherokee_config_node_foreach (i, config) {
subconf = CONFIG_NODE(i);
-
- if (equal_buf_str (&subconf->key, "default")) {
- ret = add_rule_default (CONFIG_NODE(i),
- vserver,
- rule_list);
- if (ret != ret_ok)
- return ret;
-
- did_default = true;
- } else {
- cherokee_config_node_foreach (j, subconf) {
- ret = add_rule (&CONFIG_NODE(i)->key,
- &CONFIG_NODE(j)->key,
- CONFIG_NODE(j),
- vserver,
- rule_list);
- if (ret != ret_ok)
- return ret;
- }
- }
+
+ ret = add_rule (subconf, vserver, rule_list);
+ if (ret != ret_ok) return ret;
}
-
+
+ /* Sort rules by its priority
+ */
cherokee_rule_list_sort (rule_list);
- if (! did_default) {
- PRINT_ERROR ("ERROR: vserver '%s': A default rule is needed\n", vserver->name.buf);
- return ret_error;
- }
+// TODO:
+/* if (! did_default) { */
+/* PRINT_ERROR ("ERROR: vserver '%s': A default rule is needed\n", vserver->name.buf); */
+/* return ret_error; */
+/* } */
return ret_ok;
}
View
3 configure.in
@@ -1167,7 +1167,7 @@ AC_ARG_ENABLE(static-module,
AC_HELP_STRING([--enable-static-module=MODULE][]),
[use_static_module="$use_static_module $enableval "],[])
-modules="error_redir server_info file admin dirlist fcgi fastcgi scgi redir common nn cgi phpcgi proxy mirror gzip ncsa combined w3c pam ldap mysql htpasswd plain htdigest round_robin directory extensions request"
+modules="error_redir server_info file admin dirlist fcgi fastcgi scgi redir common nn cgi phpcgi proxy mirror gzip ncsa combined w3c pam ldap mysql htpasswd plain htdigest round_robin directory extensions request header"
# Remove modules that will not be compiles
#
@@ -1241,6 +1241,7 @@ AM_CONDITIONAL(STATIC_BALANCER_ROUND_ROBIN, grep round_robin $conf_h >/dev/
AM_CONDITIONAL(STATIC_RULE_DIRECTORY, grep directory $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_EXTENSIONS, grep extensions $conf_h >/dev/null)
AM_CONDITIONAL(STATIC_RULE_REQUEST, grep request $conf_h >/dev/null)
+AM_CONDITIONAL(STATIC_RULE_HEADER, grep header $conf_h >/dev/null)
AC_OUTPUT([
Makefile
View
1 qa/001-basic.py
@@ -7,7 +7,6 @@ def __init__ (self):
self.expected_error = 200
self.request = "GET /basic_test1/ HTTP/1.0\r\n"
- self.conf = "vserver!default!rule!default!handler = common"
def Prepare (self, www):
self.Mkdir (www, "basic_test1")
View
5 qa/015-CGI-simple.py
@@ -2,8 +2,9 @@
MAGIC = "This is the magic string"
CONF = """
-vserver!default!rule!directory!/cgi-bin1!handler = cgi
-vserver!default!rule!directory!/cgi-bin1!priority = 150
+vserver!default!rule!150!match!type = directory
+vserver!default!rule!150!match!directory = /cgi-bin1
+vserver!default!rule!150!handler = cgi
"""
class Test (TestBase):
View
5 qa/016-CGI-pathinfo.py
@@ -2,8 +2,9 @@
MAGIC = "It works"
CONF = """
-vserver!default!rule!directory!/cgi-bin2!handler = cgi
-vserver!default!rule!directory!/cgi-bin2!priority = 160
+vserver!default!rule!160!match!type = directory
+vserver!default!rule!160!match!directory = /cgi-bin2
+vserver!default!rule!160!handler = cgi
"""
class Test (TestBase):
View
5 qa/017-CGI-pathinfo2.py
@@ -3,8 +3,9 @@
MAGIC = "Cherokee rocks"
CONF = """
-vserver!default!rule!directory!/cgi-bin3!handler = cgi
-vserver!default!rule!directory!/cgi-bin3!priority = 170
+vserver!default!rule!170!match!type = directory
+vserver!default!rule!170!match!directory = /cgi-bin3
+vserver!default!rule!170!handler = cgi
"""
class Test (TestBase):
View
5 qa/018-CGI-pathinfo3.py
@@ -1,8 +1,9 @@
from base import *
CONF = """
-vserver!default!rule!directory!/cgi-bin4!handler = cgi
-vserver!default!rule!directory!/cgi-bin4!priority = 180
+vserver!default!rule!180!match!type = directory
+vserver!default!rule!180!match!directory = /cgi-bin4
+vserver!default!rule!180!handler = cgi
"""
class Test (TestBase):
View
4 qa/020-VirtualHost.py
@@ -5,8 +5,8 @@
CONF = """
vserver!cherokee.test!document_root = %s
vserver!cherokee.test!domain!1 = cherokee.test
-vserver!cherokee.test!rule!default!handler = common
-vserver!cherokee.test!rule!default!priority = 10
+vserver!cherokee.test!rule!1!match!type = default
+vserver!cherokee.test!rule!1!handler = common
"""
class Test (TestBase):
View
4 qa/021-VirtualHost2.py
@@ -6,8 +6,8 @@
vserver!first.domain!document_root = %s
vserver!first.domain!domain!1 = first.domain
vserver!first.domain!domain!2 = second.domain
-vserver!first.domain!rule!default!handler = common
-vserver!first.domain!rule!default!priority = 10
+vserver!first.domain!rule!1!match!type = default
+vserver!first.domain!rule!1!handler = common
"""
class Test (TestBase):
View
7 qa/029-Post+Without-lenght.py
@@ -1,9 +1,10 @@
from base import *
CONF = """
-vserver!default!rule!directory!/post1!handler = phpcgi
-vserver!default!rule!directory!/post1!handler!interpreter = %s
-vserver!default!rule!directory!/post1!priority = 290
+vserver!default!rule!290!match!type = directory
+vserver!default!rule!290!match!directory = /post1
+vserver!default!rule!290!handler = phpcgi
+vserver!default!rule!290!handler!interpreter = %s
"""
class Test (TestBase):
View
5 qa/030-Post+urlencoded.py
@@ -2,8 +2,9 @@
from base import *
CONF = """
-vserver!default!rule!directory!/post2!handler = cgi
-vserver!default!rule!directory!/post2!priority = 300
+vserver!default!rule!300!match!type = directory
+vserver!default!rule!300!match!directory = /post2
+vserver!default!rule!300!handler = cgi
"""
class Test (TestBase):
View
5 qa/031-Post+urlencoded2.py
@@ -1,8 +1,9 @@
from base import *
CONF = """
-vserver!default!rule!directory!/post3!handler = common
-vserver!default!rule!directory!/post3!priority = 310
+vserver!default!rule!310!match!type = directory
+vserver!default!rule!310!match!directory = /post3
+vserver!default!rule!310!handler = common
"""
class Test (TestBase):
View
5 qa/033-DirIndex.py
@@ -3,8 +3,9 @@
MAGIC = "The_index_page_should_contain_this"
CONF = """
-vserver!default!rule!directory!/index1!handler = dirlist
-vserver!default!rule!directory!/index1!priority = 330
+vserver!default!rule!330!match!type = directory
+vserver!default!rule!330!match!directory = /index1
+vserver!default!rule!330!handler = dirlist
"""
class Test (TestBase):
View
5 qa/034-DirIndex2.py
@@ -3,8 +3,9 @@
MAGIC = "The_index_page_should_contain_this"
CONF = """
-vserver!default!rule!directory!/index2!handler = common
-vserver!default!rule!directory!/index2!priority = 340
+vserver!default!rule!340!match!type = directory
+vserver!default!rule!340!match!directory = /index2
+vserver!default!rule!340!handler = common
"""
class Test (TestBase):
View
7 qa/035-PHP-simple.py
@@ -1,9 +1,10 @@
from base import *
CONF = """
-vserver!default!rule!directory!/php1!handler = phpcgi
-vserver!default!rule!directory!/php1!handler!interpreter = %s
-vserver!default!rule!directory!/php1!priority = 350
+vserver!default!rule!350!match!type = directory
+vserver!default!rule!350!match!directory = /php1
+vserver!default!rule!350!handler = phpcgi
+vserver!default!rule!350!handler!interpreter = %s
"""
class Test (TestBase):
View
7 qa/036-DocumentRoot-common.py
@@ -3,9 +3,10 @@
MAGIC = "This_is_the_magic_key"
CONF = """
-vserver!default!rule!directory!/dr_common!handler = common
-vserver!default!rule!directory!/dr_common!document_root = %s
-vserver!default!rule!directory!/dr_common!priority = 360
+vserver!default!rule!360!match!type = directory
+vserver!default!rule!360!match!directory = /dr_common
+vserver!default!rule!360!handler = common
+vserver!default!rule!360!document_root = %s
"""
class Test (TestBase):
View
13 qa/039-Auth-Basic.py
@@ -1,12 +1,13 @@
from base import *
CONF = """
-vserver!default!rule!directory!/auth1!auth = plain
-vserver!default!rule!directory!/auth1!auth!methods = basic
-vserver!default!rule!directory!/auth1!auth!realm = Test
-vserver!default!rule!directory!/auth1!auth!passwdfile = %s
-vserver!default!rule!directory!/auth1!final = 0
-vserver!default!rule!directory!/auth1!priority = 390
+vserver!default!rule!390!match!type = directory
+vserver!default!rule!390!match!directory = /auth1
+vserver!default!rule!390!match!final = 0
+vserver!default!rule!390!auth = plain
+vserver!default!rule!390!auth!methods = basic
+vserver!default!rule!390!auth!realm = Test
+vserver!default!rule!390!auth!passwdfile = %s</