Skip to content
Browse files

various fixed for php and cgi plugins, added notfound plugin

  • Loading branch information...
1 parent 2932168 commit 48175d0759edf4b85865f50c4ee918d0bd3a89a1 roberto@icarus committed Mar 11, 2012
Showing with 66 additions and 15 deletions.
  1. +14 −4 plugins/cgi/cgi_plugin.c
  2. +35 −0 plugins/notfound/notfound.c
  3. +6 −0 plugins/notfound/uwsgiplugin.py
  4. +5 −9 plugins/php/php_plugin.c
  5. +0 −1 routing.c
  6. +4 −0 utils.c
  7. +1 −1 uwsgi.c
  8. +1 −0 uwsgi.h
View
18 plugins/cgi/cgi_plugin.c
@@ -12,6 +12,7 @@ struct uwsgi_cgi {
struct uwsgi_string_list *unset;
struct uwsgi_string_list *loadlib;
int optimize;
+ int from_docroot;
int has_mountpoints;
struct uwsgi_dyn_dict *default_cgi;
int path_info;
@@ -45,6 +46,8 @@ struct uwsgi_option uwsgi_cgi_options[] = {
{"cgi-map-helper", required_argument, 0, "add a cgi map-helper", uwsgi_opt_add_cgi_maphelper, NULL, 0},
{"cgi-helper", required_argument, 0, "add a cgi map-helper", uwsgi_opt_add_cgi_maphelper, NULL, 0},
+ {"cgi-from-docroot", no_argument, 0, "blindly enable cgi in DOCUMENT_ROOT", uwsgi_opt_true, &uc.from_docroot, 0},
+
{"cgi-buffer-size", required_argument, 0, "set cgi buffer size", uwsgi_opt_set_64bit, &uc.buffer_size, 0},
{"cgi-timeout", required_argument, 0, "set cgi script timeout", uwsgi_opt_set_int, &uc.timeout, 0},
@@ -500,16 +503,23 @@ int uwsgi_cgi_request(struct wsgi_request *wsgi_req) {
return -1;
}
- // check for file availability (and 'runnability')
+ char *docroot = NULL;
- char *docroot = uwsgi_cgi_get_docroot(wsgi_req->path_info, wsgi_req->path_info_len, &need_free, &is_a_file, &discard_base, &script_name);
+ // check for file availability (and 'runnability')
+ if (uc.from_docroot) {
+ docroot = wsgi_req->document_root;
+ docroot_len = wsgi_req->document_root_len;
+ }
+ else {
+ docroot = uwsgi_cgi_get_docroot(wsgi_req->path_info, wsgi_req->path_info_len, &need_free, &is_a_file, &discard_base, &script_name);
+ docroot_len = strlen(docroot);
+ }
- if (docroot == NULL) {
+ if (docroot == NULL || docroot_len == 0) {
uwsgi_cgi_404(wsgi_req);
return UWSGI_OK;
}
- docroot_len = strlen(docroot);
memcpy(full_path, docroot, docroot_len);
if (!is_a_file) {
View
35 plugins/notfound/notfound.c
@@ -0,0 +1,35 @@
+#include "../../uwsgi.h"
+
+int uwsgi_request_notfound(struct wsgi_request *wsgi_req) {
+
+ struct iovec iov[3];
+
+ if (wsgi_req->protocol_len > 0) {
+ iov[0].iov_base = wsgi_req->protocol;
+ iov[0].iov_len = wsgi_req->protocol_len;
+ }
+ else {
+ iov[0].iov_base = "HTTP/1.0";
+ iov[0].iov_len = 8;
+ }
+
+ iov[1].iov_base = " 404 Not Found\r\n";
+ iov[1].iov_len = 16;
+
+ iov[2].iov_base = "Content-Type: text/plain\r\n\r\n";
+ iov[2].iov_len = 28;
+
+ wsgi_req->headers_size = wsgi_req->socket->proto_writev_header(wsgi_req, iov, 3);
+
+ wsgi_req->response_size = wsgi_req->socket->proto_write(wsgi_req, "Not Found", 9);
+ wsgi_req->status = 404;
+
+ return UWSGI_OK;
+}
+
+
+struct uwsgi_plugin notfound_plugin = {
+
+ .name = "notfound",
+ .request = uwsgi_request_notfound,
+};
View
6 plugins/notfound/uwsgiplugin.py
@@ -0,0 +1,6 @@
+NAME='notfound'
+
+CFLAGS = []
+LDFLAGS = []
+LIBS = []
+GCC_LIST = ['notfound']
View
14 plugins/php/php_plugin.c
@@ -299,15 +299,11 @@ static sapi_module_struct uwsgi_sapi_module;
void uwsgi_php_set(char *opt) {
uwsgi_sapi_module.ini_entries = realloc(uwsgi_sapi_module.ini_entries, uphp.ini_size + strlen(opt)+2);
- if (uphp.ini_size == 0) {
- memcpy(uwsgi_sapi_module.ini_entries, opt, strlen(opt));
- }
- else {
- memcpy(uwsgi_sapi_module.ini_entries + (uphp.ini_size -1), opt, strlen(opt));
- }
- uphp.ini_size += strlen(opt)+2;
- uwsgi_sapi_module.ini_entries[uphp.ini_size-2] = '\n';
- uwsgi_sapi_module.ini_entries[uphp.ini_size-1] = 0;
+ memcpy(uwsgi_sapi_module.ini_entries + uphp.ini_size, opt, strlen(opt));
+
+ uphp.ini_size += strlen(opt)+1;
+ uwsgi_sapi_module.ini_entries[uphp.ini_size-1] = '\n';
+ uwsgi_sapi_module.ini_entries[uphp.ini_size] = 0;
}
// future implementation...
View
1 routing.c
@@ -26,7 +26,6 @@ int uwsgi_apply_routes(struct wsgi_request *wsgi_req) {
return ret;
}
}
-
routes = routes->next;
}
View
4 utils.c
@@ -2067,6 +2067,10 @@ void add_exported_option(char *key, char *value, int configured) {
if (op->flags & UWSGI_OPT_POST_BUFFERING) {
if (!uwsgi.post_buffering) uwsgi.post_buffering = 4096;
}
+ // requires building mime dict ?
+ if (op->flags & UWSGI_OPT_MIME) {
+ uwsgi.build_mime_dict = 1;
+ }
// immediate ?
if (op->flags & UWSGI_OPT_IMMEDIATE) {
op->func(key, value, op->data);
View
2 uwsgi.c
@@ -348,7 +348,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
#endif
{"add-header", required_argument, 0, "automatically add HTTP headers to response", uwsgi_opt_add_string_list, &uwsgi.additional_headers, 0},
{"check-static", required_argument, 0, "check for static files in the specified directory", uwsgi_opt_check_static, NULL, 0},
- {"check-static-docroot", no_argument, 0, "check for static files in the requested DOCUMENT_ROOT", uwsgi_opt_true, &uwsgi.check_static_docroot, 0},
+ {"check-static-docroot", no_argument, 0, "check for static files in the requested DOCUMENT_ROOT", uwsgi_opt_true, &uwsgi.check_static_docroot, UWSGI_OPT_MIME},
{"static-check", required_argument, 0, "check for static files in the specified directory", uwsgi_opt_check_static, NULL, 0},
{"static-map", required_argument, 0, "map mountpoint to static directory", uwsgi_opt_static_map, NULL, 0},
{"static-skip-ext", required_argument, 0, "skip specified extension from staticfile checks", uwsgi_opt_add_string_list, &uwsgi.static_skip_ext, 0},
View
1 uwsgi.h
@@ -50,6 +50,7 @@ extern "C" {
#define UWSGI_OPT_NO_SERVER (1 << 10)
#define UWSGI_OPT_POST_BUFFERING (1 << 11)
#define UWSGI_OPT_CLUSTER (1 << 12)
+#define UWSGI_OPT_MIME (1 << 13)
#define MAX_APPS 64
#define MAX_GENERIC_PLUGINS 64

0 comments on commit 48175d0

Please sign in to comment.
Something went wrong with that request. Please try again.