| From | Sent On | Attachments |
|---|---|---|
| Valery Kholodkov | Jul 25, 2009 10:21 am | |
| Michael Shadle | Jul 25, 2009 12:56 pm | |
| Valery Kholodkov | Jul 25, 2009 2:20 pm | |
| Michael Shadle | Jul 25, 2009 2:43 pm | |
| Igor Sysoev | Jul 27, 2009 2:47 am | |
| Valery Kholodkov | Jul 27, 2009 2:48 am | |
| Michael Shadle | Jul 27, 2009 8:57 am | |
| Michael Shadle | Jul 27, 2009 8:59 am | |
| Valery Kholodkov | Jul 27, 2009 10:47 am | |
| Daniel | Jul 27, 2009 9:09 pm | |
| Valery Kholodkov | Jul 27, 2009 10:51 pm | |
| Michael Shadle | Jul 27, 2009 11:03 pm | |
| Michael Shadle | Jul 27, 2009 11:07 pm | |
| Valery Kholodkov | Jul 27, 2009 11:14 pm | |
| Valery Kholodkov | Jul 27, 2009 11:21 pm | |
| Michael Shadle | Jul 28, 2009 12:38 am | |
| Michael Shadle | Jul 28, 2009 12:41 am | |
| Valery Kholodkov | Jul 28, 2009 3:45 am | |
| Valery Kholodkov | Jul 28, 2009 3:54 am | |
| Michael Shadle | Jul 28, 2009 10:14 am | |
| Michael Shadle | Jul 28, 2009 10:16 am | |
| Valery Kholodkov | Jul 30, 2009 3:27 am | |
| Valery Kholodkov | Jul 30, 2009 4:35 am | |
| Michael Shadle | Jul 30, 2009 9:47 am | |
| Michael Shadle | Jul 30, 2009 9:51 am | |
| Daniel | Aug 6, 2009 8:33 pm | |
| Valery Kholodkov | Aug 7, 2009 3:58 am | |
| Valery Kholodkov | Aug 7, 2009 10:15 am | .patch |
| Daniel | Aug 10, 2009 1:54 am | |
| Valery Kholodkov | Aug 10, 2009 11:14 am | .patch |
| Daniel | Aug 10, 2009 10:08 pm | |
| gogobu | Aug 30, 2009 12:46 am | |
| Valery Kholodkov | Aug 30, 2009 1:56 am | |
| gogobu | Aug 30, 2009 5:44 am | |
| Valery Kholodkov | Aug 30, 2009 6:41 am | |
| gogobu | Aug 30, 2009 8:15 am | |
| Michael Shadle | Aug 30, 2009 11:32 am | |
| davent | Aug 31, 2009 8:56 am |
| Subject: | Re: mogilefs module 1.0.2 | |
|---|---|---|
| From: | Valery Kholodkov (vale...@grid.net.ru) | |
| Date: | Aug 7, 2009 10:15:45 am | |
| List: | ru.sysoev.nginx | |
| Attachments: | ||
Daniel wrote:
As i said in the first sentence linking POST to PUT would be useful, maybe making a bridge between your Upload module and Mogilefs module could be enough to do the task. In other point as Michael said, using variables to set mogilefs_domain would be useful too. I looked the source but I didn't find how to set the Class for uploading files.
Please try attached patch. It implements mogilefs_class directives. The directive accepts up to 8 arguments, each of them can contain variables. The first argument which evaluates to non-empty string is supplied as class parameter to MogileFS tracker. If no argument evaluates to non-empty string or directive is not set, no class parameter will be supplied to MogileFS tracker.
-- Best regards, Valery Kholodkov
diff --git a/Changelog b/Changelog index 0049dcb..2c6c786 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,7 @@
+Version 1.0.3
+ * Added feature: directive mogilefs_class allows to specify resource class
+
Version 1.0.2
* Added feature: directive mogilefs_methods and support for PUT and DELETE
methods
* Added feature: dynamic evaluation of tracker name
diff --git a/ngx_http_mogilefs_module.c b/ngx_http_mogilefs_module.c
index ea87e17..7537fde 100644
--- a/ngx_http_mogilefs_module.c
+++ b/ngx_http_mogilefs_module.c
@@ -28,6 +28,12 @@ typedef struct {
ngx_str_t output_count_param;
} ngx_http_mogilefs_cmd_t;
+typedef struct { + ngx_str_t source; + ngx_array_t *lengths; + ngx_array_t *values; +} ngx_http_mogilefs_class_template_t; + typedef struct ngx_http_mogilefs_loc_conf_s { struct ngx_http_mogilefs_loc_conf_s *parent; ngx_uint_t methods; @@ -39,6 +45,7 @@ typedef struct ngx_http_mogilefs_loc_conf_s { ngx_array_t *tracker_lengths; ngx_array_t *tracker_values; ngx_str_t domain; + ngx_array_t *class_templates; ngx_str_t fetch_location; ngx_flag_t noverify; ngx_http_mogilefs_location_type_t location_type; @@ -78,11 +85,12 @@ typedef struct { ngx_str_t path; } ngx_http_mogilefs_src_t;
-static ngx_int_t ngx_http_mogilefs_eval_key(ngx_http_request_t *r, ngx_str_t
*key);
static ngx_int_t ngx_http_mogilefs_put_handler(ngx_http_request_t *r);
static ngx_int_t ngx_http_mogilefs_finish_phase_handler(ngx_http_request_t *r,
void *data, ngx_int_t rc);
static ngx_int_t ngx_http_mogilefs_eval_tracker(ngx_http_request_t *r,
ngx_http_mogilefs_loc_conf_t *mgcf);
+static ngx_int_t ngx_http_mogilefs_eval_class(ngx_http_request_t *r,
ngx_http_mogilefs_loc_conf_t *mgcf);
+static ngx_int_t ngx_http_mogilefs_eval_key(ngx_http_request_t *r, ngx_str_t
*key);
static ngx_int_t ngx_http_mogilefs_set_cmd(ngx_http_request_t *r,
ngx_http_mogilefs_ctx_t *ctx);
static ngx_int_t ngx_http_mogilefs_create_request(ngx_http_request_t *r); @@ -95,6 +103,8 @@ static ngx_int_t ngx_http_mogilefs_filter_init(void *data); static ngx_int_t ngx_http_mogilefs_filter(void *data, ssize_t bytes);
static ngx_int_t ngx_http_mogilefs_parse_param(ngx_http_request_t *r, ngx_str_t
*param);
+static ngx_int_t ngx_http_mogilefs_add_aux_param(ngx_http_request_t *r,
ngx_str_t *name,
+ ngx_str_t *value);
static ngx_int_t ngx_http_mogilefs_path_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
@@ -107,6 +117,8 @@ static ngx_int_t ngx_http_mogilefs_add_variables(ngx_conf_t
*cf);
static char *
ngx_http_mogilefs_tracker_command(ngx_conf_t *cf, ngx_command_t *cmd, void
*conf);
static char *
+ngx_http_mogilefs_class_command(ngx_conf_t *cf, ngx_command_t *cmd, void
*conf);
+static char *
ngx_http_mogilefs_pass_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_int_t ngx_http_mogilefs_init(ngx_conf_t *cf); @@ -195,6 +207,13 @@ static ngx_command_t ngx_http_mogilefs_commands[] = { offsetof(ngx_http_mogilefs_loc_conf_t, methods), &ngx_http_mogilefs_methods_mask },
+ { ngx_string("mogilefs_class"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, + ngx_http_mogilefs_class_command, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_mogilefs_loc_conf_t, class_templates), + &ngx_http_mogilefs_methods_mask }, + ngx_null_command };
@@ -237,6 +256,7 @@ static ngx_http_variable_t ngx_http_mogilefs_variables[] =
{ /* {{{ */
}; /* }}} */
static ngx_str_t ngx_http_mogilefs_path = ngx_string("mogilefs_path"); +static ngx_str_t ngx_http_mogilefs_class = ngx_string("class");
static ngx_int_t
ngx_http_mogilefs_handler(ngx_http_request_t *r)
@@ -529,6 +549,47 @@ ngx_http_mogilefs_eval_tracker(ngx_http_request_t *r,
ngx_http_mogilefs_loc_conf
}
static ngx_int_t
+ngx_http_mogilefs_eval_class(ngx_http_request_t *r,
ngx_http_mogilefs_loc_conf_t *mgcf)
+{
+ ngx_uint_t i;
+ ngx_http_mogilefs_class_template_t *t;
+ ngx_str_t class;
+
+ if(mgcf->class_templates == NULL) {
+ return NGX_DECLINED;
+ }
+
+ t = mgcf->class_templates->elts;
+
+ for(i = 0;i < mgcf->class_templates->nelts;i++) {
+ if(t->lengths != NULL) {
+ if(ngx_http_script_run(r, &class, t->lengths->elts, 0,
+ t->values->elts)
+ == NULL)
+ {
+ return NGX_ERROR;
+ }
+ }
+ else {
+ if(ngx_http_mogilefs_add_aux_param(r, &ngx_http_mogilefs_class,
&t->source) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ return NGX_OK;
+ }
+
+ if(class.len) {
+ if(ngx_http_mogilefs_add_aux_param(r, &ngx_http_mogilefs_class,
&class) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ return NGX_OK;
+ }
+ }
+
+ return NGX_DECLINED;
+}
+static ngx_int_t
ngx_http_mogilefs_eval_key(ngx_http_request_t *r, ngx_str_t *key)
{
size_t loc_len;
@@ -600,6 +661,7 @@ ngx_http_mogilefs_create_request(ngx_http_request_t *r)
ngx_http_mogilefs_ctx_t *ctx;
ngx_http_mogilefs_aux_param_t *a;
ngx_uint_t i;
+ ngx_int_t rc;
mgcf = ngx_http_get_module_loc_conf(r, ngx_http_mogilefs_module);
@@ -625,6 +687,12 @@ ngx_http_mogilefs_create_request(ngx_http_request_t *r) domain.data = mgcf->domain.data; }
+ rc = ngx_http_mogilefs_eval_class(r, mgcf->parent != NULL ? mgcf->parent :
mgcf);
+
+ if(rc == NGX_ERROR) {
+ return rc;
+ }
+
escape_domain = 2 * ngx_escape_uri(NULL, domain.data, domain.len,
NGX_ESCAPE_MEMCACHED);
escape_key = 2 * ngx_escape_uri(NULL, ctx->key.data, ctx->key.len,
NGX_ESCAPE_MEMCACHED);
@@ -1173,6 +1241,10 @@ ngx_http_mogilefs_merge_loc_conf(ngx_conf_t *cf, void
*parent, void *child)
ngx_conf_merge_bitmask_value(conf->methods, prev->methods,
(NGX_CONF_BITMASK_SET|NGX_HTTP_GET));
+ if(conf->class_templates == NULL) { + conf->class_templates = prev->class_templates; + } + return NGX_CONF_OK; }
@@ -1255,6 +1327,60 @@ ngx_http_mogilefs_tracker_command(ngx_conf_t *cf,
ngx_command_t *cmd, void *conf
return NGX_CONF_OK;
}
+static char *
+ngx_http_mogilefs_class_command(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_http_mogilefs_loc_conf_t *mgcf = conf;
+ ngx_http_mogilefs_class_template_t *t;
+ ngx_str_t *value;
+ ngx_url_t u;
+ ngx_uint_t i, n;
+ ngx_http_script_compile_t sc;
+
+ if(mgcf->class_templates == NULL) {
+ mgcf->class_templates = ngx_array_create(cf->pool, cf->args->nelts,
+ sizeof(ngx_http_mogilefs_class_template_t));
+
+ if(mgcf->class_templates == NULL) {
+ return NGX_CONF_ERROR;
+ }
+ }
+
+ value = cf->args->elts;
+
+ for(i = 0;i < cf->args->nelts;i++) {
+ t = ngx_array_push(mgcf->class_templates);
+
+ if(t == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ t->source = value[i];
+
+ n = ngx_http_script_variables_count(&t->source);
+
+ if(n) {
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
+
+ sc.cf = cf;
+ sc.source = &value[i];
+ sc.lengths = &t->lengths;
+ sc.values = &t->values;
+ sc.variables = n;
+ sc.complete_lengths = 1;
+ sc.complete_values = 1;
+
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ return NGX_CONF_OK;
+ }
+ }
+
+ return NGX_CONF_OK;
+}
+
static char*
ngx_http_mogilefs_create_spare_location(ngx_conf_t *cf, ngx_http_conf_ctx_t
**octx, ngx_str_t *name,
ngx_http_mogilefs_location_type_t location_type)






.patch