]> git.kaiwu.me - nginx.git/commitdiff
$realpath_root
authorIgor Sysoev <igor@sysoev.ru>
Sat, 27 Sep 2008 11:53:41 +0000 (11:53 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Sat, 27 Sep 2008 11:53:41 +0000 (11:53 +0000)
src/http/ngx_http_variables.c
src/os/unix/ngx_files.h
src/os/win32/ngx_files.c
src/os/win32/ngx_files.h

index 08343b8e8298a70fc29916ac1ed7dc39e7a9c520..003510a6a8442f9e6bbc3f140f7f8a26b4dff70a 100644 (file)
@@ -46,6 +46,8 @@ static ngx_int_t ngx_http_variable_is_args(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_document_root(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_realpath_root(ngx_http_request_t *r,
+    ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_http_variable_server_name(ngx_http_request_t *r,
@@ -162,6 +164,9 @@ static ngx_http_variable_t  ngx_http_core_variables[] = {
     { ngx_string("document_root"), NULL,
       ngx_http_variable_document_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
 
+    { ngx_string("realpath_root"), NULL,
+      ngx_http_variable_realpath_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
     { ngx_string("query_string"), NULL, ngx_http_variable_request,
       offsetof(ngx_http_request_t, args),
       NGX_HTTP_VAR_NOCACHEABLE, 0 },
@@ -999,6 +1004,61 @@ ngx_http_variable_document_root(ngx_http_request_t *r,
 }
 
 
+static ngx_int_t
+ngx_http_variable_realpath_root(ngx_http_request_t *r,
+    ngx_http_variable_value_t *v, uintptr_t data)
+{
+    size_t                     len;
+    ngx_str_t                  path;
+    ngx_http_core_loc_conf_t  *clcf;
+    u_char                     real[NGX_MAX_PATH];
+
+    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+    if (clcf->root_lengths == NULL) {
+        path = clcf->root;
+
+    } else {
+        if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 1,
+                                clcf->root_values->elts)
+            == NULL)
+        {
+            return NGX_ERROR;
+        }
+
+        path.data[path.len - 1] = '\0';
+
+        if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0)
+            == NGX_ERROR)
+        {
+            return NGX_ERROR;
+        }
+    }
+
+    if (ngx_realpath(path.data, real) == NULL) {
+        ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
+                      ngx_realpath_n " \"%s\" failed", path.data);
+        return NGX_ERROR;
+    }
+
+    len = ngx_strlen(real);
+
+    v->data = ngx_pnalloc(r->pool, len);
+    if (v->data == NULL) {
+        return NGX_ERROR;
+    }
+
+    v->len = len;
+    v->valid = 1;
+    v->no_cacheable = 0;
+    v->not_found = 0;
+
+    ngx_memcpy(v->data, real, len);
+
+    return NGX_OK;
+}
+
+
 static ngx_int_t
 ngx_http_variable_request_filename(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data)
index d7a38d95a5fa7f78789a98f37c676e71c95fae89..d8182b4b6875ddfa9c82015bc3372532722a853a 100644 (file)
@@ -145,6 +145,8 @@ ngx_int_t ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s);
 #endif
 
 
+#define ngx_realpath(p, r)       realpath((char *) p, (char *) r)
+#define ngx_realpath_n           "realpath()"
 #define ngx_getcwd(buf, size)    (getcwd(buf, size) != NULL)
 #define ngx_getcwd_n             "getcwd()"
 #define NGX_MAX_PATH             PATH_MAX
index cbba0bbfb520b401fa2d59cdf96f0c65eacb1a27..c2dda2ae33ac0f6ef954b97aa74dc5a28a763cef 100644 (file)
@@ -318,6 +318,14 @@ ngx_file_info(u_char *file, ngx_file_info_t *sb)
 }
 
 
+char *
+ngx_realpath(u_char *path, u_char *resolved)
+{
+    /* STUB */
+    return (char *) path;
+}
+
+
 ngx_int_t
 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir)
 {
index 95ea65b67d3a619dd54b9f04ddb6a63daae33807..174c6f574b22741ec33a0f94171d67a8542d1e62 100644 (file)
@@ -156,6 +156,8 @@ ngx_int_t ngx_file_info(u_char *filename, ngx_file_info_t *fi);
 #define ngx_filename_cmp(s1, s2, n) _strnicmp((char *) s1, (char *) s2, n)
 
 
+char *ngx_realpath(u_char *path, u_char *resolved);
+#define ngx_realpath_n              ""
 #define ngx_getcwd(buf, size)       GetCurrentDirectory(size, buf)
 #define ngx_getcwd_n                "GetCurrentDirectory()"
 #define NGX_MAX_PATH                MAX_PATH