Browse Source

Added check for document_root != NULL in convert_uri_to_file_name(). Added #define rmdir _rmdir for win32

Sergey Lyubka 12 years ago
parent
commit
526f3aa31c
1 changed files with 7 additions and 3 deletions
  1. 7 3
      mongoose.c

+ 7 - 3
mongoose.c

@@ -146,6 +146,7 @@ typedef long off_t;
 #define flockfile(x) EnterCriticalSection(&global_log_file_lock)
 #define flockfile(x) EnterCriticalSection(&global_log_file_lock)
 #define funlockfile(x) LeaveCriticalSection(&global_log_file_lock)
 #define funlockfile(x) LeaveCriticalSection(&global_log_file_lock)
 #define sleep(x) Sleep((x) * 1000)
 #define sleep(x) Sleep((x) * 1000)
+#define rmdir(x) _rmdir(x)
 
 
 #if !defined(va_copy)
 #if !defined(va_copy)
 #define va_copy(x, y) x = y
 #define va_copy(x, y) x = y
@@ -1788,7 +1789,8 @@ int mg_get_cookie(const char *cookie_header, const char *var_name,
 static void convert_uri_to_file_name(struct mg_connection *conn, char *buf,
 static void convert_uri_to_file_name(struct mg_connection *conn, char *buf,
                                      size_t buf_len, struct file *filep) {
                                      size_t buf_len, struct file *filep) {
   struct vec a, b;
   struct vec a, b;
-  const char *rewrite, *uri = conn->request_info.uri;
+  const char *rewrite, *uri = conn->request_info.uri,
+        *root = conn->ctx->config[DOCUMENT_ROOT];
   char *p;
   char *p;
   int match_len;
   int match_len;
   char gz_path[PATH_MAX];
   char gz_path[PATH_MAX];
@@ -1796,8 +1798,10 @@ static void convert_uri_to_file_name(struct mg_connection *conn, char *buf,
 
 
   // Using buf_len - 1 because memmove() for PATH_INFO may shift part
   // Using buf_len - 1 because memmove() for PATH_INFO may shift part
   // of the path one byte on the right.
   // of the path one byte on the right.
-  mg_snprintf(conn, buf, buf_len - 1, "%s%s", conn->ctx->config[DOCUMENT_ROOT],
-              uri);
+  // If document_root is NULL, leave the file empty.
+  mg_snprintf(conn, buf, buf_len - 1, "%s%s",
+              root == NULL ? "" : root,
+              root == NULL ? "" : uri);
 
 
   rewrite = conn->ctx->config[REWRITE];
   rewrite = conn->ctx->config[REWRITE];
   while ((rewrite = next_option(rewrite, &a, &b)) != NULL) {
   while ((rewrite = next_option(rewrite, &a, &b)) != NULL) {