|
|
@@ -78,6 +78,15 @@ static ngx_int_t ngx_http_uploadprogress_init_zone(ngx_shm_zone_t * shm_zone, vo
|
|
78
|
78
|
static ngx_int_t ngx_http_uploadprogress_init(ngx_conf_t * cf);
|
|
79
|
79
|
static void *ngx_http_uploadprogress_create_loc_conf(ngx_conf_t *cf);
|
|
80
|
80
|
static char *ngx_http_uploadprogress_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);
|
|
|
81
|
+static ngx_int_t ngx_http_uploadprogress_add_variables(ngx_conf_t *cf);
|
|
|
82
|
+
|
|
|
83
|
+static ngx_int_t ngx_http_uploadprogress_received_variable(ngx_http_request_t *r,
|
|
|
84
|
+ ngx_http_variable_value_t *v, uintptr_t data);
|
|
|
85
|
+static ngx_int_t ngx_http_uploadprogress_offset_variable(ngx_http_request_t *r,
|
|
|
86
|
+ ngx_http_variable_value_t *v, uintptr_t data);
|
|
|
87
|
+static ngx_int_t ngx_http_uploadprogress_status_variable(ngx_http_request_t *r,
|
|
|
88
|
+ ngx_http_variable_value_t *v, uintptr_t data);
|
|
|
89
|
+
|
|
81
|
90
|
static char *ngx_http_track_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
|
|
82
|
91
|
static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
|
|
83
|
92
|
static char *ngx_http_upload_progress(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
|
|
|
@@ -142,9 +151,29 @@ static ngx_command_t ngx_http_uploadprogress_commands[] = {
|
|
142
|
151
|
ngx_null_command
|
|
143
|
152
|
};
|
|
144
|
153
|
|
|
|
154
|
+static ngx_http_variable_t ngx_http_uploadprogress_variables[] = {
|
|
|
155
|
+
|
|
|
156
|
+ { ngx_string("uploadprogress_received"), NULL, ngx_http_uploadprogress_received_variable,
|
|
|
157
|
+ (uintptr_t) offsetof(ngx_http_uploadprogress_node_t, rest),
|
|
|
158
|
+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
|
|
159
|
+
|
|
|
160
|
+ { ngx_string("uploadprogress_remaining"), NULL, ngx_http_uploadprogress_offset_variable,
|
|
|
161
|
+ (uintptr_t) offsetof(ngx_http_uploadprogress_node_t, rest),
|
|
|
162
|
+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
|
|
163
|
+
|
|
|
164
|
+ { ngx_string("uploadprogress_length"), NULL, ngx_http_uploadprogress_offset_variable,
|
|
|
165
|
+ (uintptr_t) offsetof(ngx_http_uploadprogress_node_t, length),
|
|
|
166
|
+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
|
|
167
|
+
|
|
|
168
|
+ { ngx_string("uploadprogress_status"), NULL, ngx_http_uploadprogress_status_variable,
|
|
|
169
|
+ (uintptr_t) offsetof(ngx_http_uploadprogress_node_t, err_status),
|
|
|
170
|
+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
|
|
|
171
|
+
|
|
|
172
|
+ { ngx_null_string, NULL, NULL, 0, 0, 0 }
|
|
|
173
|
+};
|
|
145
|
174
|
|
|
146
|
175
|
static ngx_http_module_t ngx_http_uploadprogress_module_ctx = {
|
|
147
|
|
- NULL, /* preconfiguration */
|
|
|
176
|
+ ngx_http_uploadprogress_add_variables, /* preconfiguration */
|
|
148
|
177
|
ngx_http_uploadprogress_init, /* postconfiguration */
|
|
149
|
178
|
|
|
150
|
179
|
NULL, /* create main configuration */
|
|
|
@@ -609,6 +638,8 @@ ngx_http_reportuploads_handler(ngx_http_request_t * r)
|
|
609
|
638
|
}
|
|
610
|
639
|
}
|
|
611
|
640
|
|
|
|
641
|
+ ngx_http_set_ctx(r, up, ngx_http_uploadprogress_module);
|
|
|
642
|
+
|
|
612
|
643
|
/*
|
|
613
|
644
|
There are 4 possibilities
|
|
614
|
645
|
* request not yet started: found = false
|
|
|
@@ -1268,6 +1299,23 @@ ngx_http_uploadprogress_merge_loc_conf(ngx_conf_t * cf, void *parent, void *chil
|
|
1268
|
1299
|
return NGX_CONF_OK;
|
|
1269
|
1300
|
}
|
|
1270
|
1301
|
|
|
|
1302
|
+static ngx_int_t
|
|
|
1303
|
+ngx_http_uploadprogress_add_variables(ngx_conf_t *cf)
|
|
|
1304
|
+{
|
|
|
1305
|
+ ngx_http_variable_t *var, *v;
|
|
|
1306
|
+
|
|
|
1307
|
+ for (v = ngx_http_uploadprogress_variables; v->name.len; v++) {
|
|
|
1308
|
+ var = ngx_http_add_variable(cf, &v->name, v->flags);
|
|
|
1309
|
+ if (var == NULL) {
|
|
|
1310
|
+ return NGX_ERROR;
|
|
|
1311
|
+ }
|
|
|
1312
|
+
|
|
|
1313
|
+ var->get_handler = v->get_handler;
|
|
|
1314
|
+ var->data = v->data;
|
|
|
1315
|
+ }
|
|
|
1316
|
+
|
|
|
1317
|
+ return NGX_OK;
|
|
|
1318
|
+}
|
|
1271
|
1319
|
|
|
1272
|
1320
|
static char*
|
|
1273
|
1321
|
ngx_http_upload_progress(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
|
|
|
@@ -1495,3 +1543,79 @@ ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void
|
|
1495
|
1543
|
return NGX_CONF_OK;
|
|
1496
|
1544
|
}
|
|
1497
|
1545
|
|
|
|
1546
|
+static ngx_int_t ngx_http_uploadprogress_received_variable(ngx_http_request_t *r,
|
|
|
1547
|
+ ngx_http_variable_value_t *v, uintptr_t data)
|
|
|
1548
|
+{
|
|
|
1549
|
+ ngx_http_uploadprogress_node_t *up;
|
|
|
1550
|
+ u_char *p;
|
|
|
1551
|
+ off_t *value;
|
|
|
1552
|
+
|
|
|
1553
|
+ up = ngx_http_get_module_ctx(r, ngx_http_uploadprogress_module);
|
|
|
1554
|
+
|
|
|
1555
|
+ value = (off_t *) ((char *) up + data);
|
|
|
1556
|
+
|
|
|
1557
|
+ p = ngx_palloc(r->pool, NGX_OFF_T_LEN);
|
|
|
1558
|
+ if (p == NULL) {
|
|
|
1559
|
+ return NGX_ERROR;
|
|
|
1560
|
+ }
|
|
|
1561
|
+
|
|
|
1562
|
+ v->len = ngx_sprintf(p, "%O", up->length - *value) - p;
|
|
|
1563
|
+ v->valid = 1;
|
|
|
1564
|
+ v->no_cacheable = 0;
|
|
|
1565
|
+ v->not_found = 0;
|
|
|
1566
|
+ v->data = p;
|
|
|
1567
|
+
|
|
|
1568
|
+ return NGX_OK;
|
|
|
1569
|
+}
|
|
|
1570
|
+
|
|
|
1571
|
+static ngx_int_t ngx_http_uploadprogress_offset_variable(ngx_http_request_t *r,
|
|
|
1572
|
+ ngx_http_variable_value_t *v, uintptr_t data)
|
|
|
1573
|
+{
|
|
|
1574
|
+ ngx_http_uploadprogress_node_t *up;
|
|
|
1575
|
+ u_char *p;
|
|
|
1576
|
+ off_t *value;
|
|
|
1577
|
+
|
|
|
1578
|
+ up = ngx_http_get_module_ctx(r, ngx_http_uploadprogress_module);
|
|
|
1579
|
+
|
|
|
1580
|
+ value = (off_t *) ((char *) up + data);
|
|
|
1581
|
+
|
|
|
1582
|
+ p = ngx_palloc(r->pool, NGX_OFF_T_LEN);
|
|
|
1583
|
+ if (p == NULL) {
|
|
|
1584
|
+ return NGX_ERROR;
|
|
|
1585
|
+ }
|
|
|
1586
|
+
|
|
|
1587
|
+ v->len = ngx_sprintf(p, "%O", *value) - p;
|
|
|
1588
|
+ v->valid = 1;
|
|
|
1589
|
+ v->no_cacheable = 0;
|
|
|
1590
|
+ v->not_found = 0;
|
|
|
1591
|
+ v->data = p;
|
|
|
1592
|
+
|
|
|
1593
|
+ return NGX_OK;
|
|
|
1594
|
+}
|
|
|
1595
|
+
|
|
|
1596
|
+static ngx_int_t
|
|
|
1597
|
+ngx_http_uploadprogress_status_variable(ngx_http_request_t *r,
|
|
|
1598
|
+ ngx_http_variable_value_t *v, uintptr_t data)
|
|
|
1599
|
+{
|
|
|
1600
|
+ ngx_http_uploadprogress_node_t *up;
|
|
|
1601
|
+ u_char *p;
|
|
|
1602
|
+ off_t *value;
|
|
|
1603
|
+
|
|
|
1604
|
+ up = ngx_http_get_module_ctx(r, ngx_http_uploadprogress_module);
|
|
|
1605
|
+
|
|
|
1606
|
+ value = (off_t *) ((char *) up + data);
|
|
|
1607
|
+
|
|
|
1608
|
+ p = ngx_palloc(r->pool, NGX_OFF_T_LEN);
|
|
|
1609
|
+ if (p == NULL) {
|
|
|
1610
|
+ return NGX_ERROR;
|
|
|
1611
|
+ }
|
|
|
1612
|
+
|
|
|
1613
|
+ v->len = ngx_sprintf(p, "%O", *value) - p;
|
|
|
1614
|
+ v->valid = 1;
|
|
|
1615
|
+ v->no_cacheable = 0;
|
|
|
1616
|
+ v->not_found = 0;
|
|
|
1617
|
+ v->data = p;
|
|
|
1618
|
+
|
|
|
1619
|
+ return NGX_OK;
|
|
|
1620
|
+}
|
|
|
1621
|
+
|