Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added push_max_channel_id_length config option

  • Loading branch information...
commit 0be70b67f6a4b16b1a3c29a313ed4e496b50abbe 1 parent feb997c
Leo P. authored
6 README
View
@@ -87,6 +87,12 @@ push_channel_group [ string ]
locations and never others. That's where this setting comes in. Think of it
as a prefix string for the channel id.
+push_max_channel_id_length [ number ]
+ default: 512
+ context: main, server, location
+ Maximum permissible channel id length (number of characters).
+ Longer ids will be truncated.
+
push_queue_messages [ on | off ] (DEPRECATED)
default: on
context: http, server, location
16 src/ngx_http_push_module.c
View
@@ -117,7 +117,9 @@ static ngx_http_push_msg_t * ngx_http_push_find_message_locked(ngx_http_push_cha
static ngx_str_t * ngx_http_push_get_channel_id(ngx_http_request_t *r, ngx_http_push_loc_conf_t *cf) {
ngx_http_variable_value_t *vv = ngx_http_get_indexed_variable(r, cf->index);
- ngx_str_t *prefix;
+ ngx_str_t *group = &cf->channel_group;
+ size_t group_len = group->len;
+ size_t var_len;
size_t len;
ngx_str_t *id;
if (vv == NULL || vv->not_found || vv->len == 0) {
@@ -125,8 +127,9 @@ static ngx_str_t * ngx_http_push_get_channel_id(ngx_http_request_t *r, ngx_http_
"push module: the $push_channel_id variable is required but is not set");
return NULL;
}
- prefix = &cf->channel_group;
- len = prefix->len + 1 + vv->len;
+ //maximum length limiter for channel id
+ var_len = vv->len <= cf->max_channel_id_length ? vv->len : cf->max_channel_id_length;
+ len = group_len + 1 + var_len;
if((id = ngx_palloc(r->pool, sizeof(*id) + len))==NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"push module: unable to allocate memory for $push_channel_id string");
@@ -134,9 +137,9 @@ static ngx_str_t * ngx_http_push_get_channel_id(ngx_http_request_t *r, ngx_http_
}
id->len=len;
id->data=(u_char *)(id+1);
- ngx_memcpy(id->data, prefix->data, prefix->len);
- id->data[prefix->len]='/';
- ngx_memcpy(id->data + prefix->len + 1, vv->data, id->len);
+ ngx_memcpy(id->data, group->data, group_len);
+ id->data[group_len]='/';
+ ngx_memcpy(id->data + group_len + 1, vv->data, var_len);
return id;
}
@@ -460,7 +463,6 @@ static void ngx_http_push_publisher_body_handler(ngx_http_request_t * r) {
//just find the channel. if it's not there, NULL.
channel = ngx_http_push_find_channel(id, &((ngx_http_push_shm_data_t *) ngx_http_push_shm_zone->data)->tree, shpool, r->connection->log);
}
- ngx_pfree(ngx_http_push_pool, id);
if(channel!=NULL) {
subscribers = channel->subscribers;
2  src/ngx_http_push_module.h
View
@@ -19,6 +19,8 @@
#define NGX_HTTP_PUSH_MIN_MESSAGE_RECIPIENTS 0
+#define NGX_HTTP_PUSH_MAX_CHANNEL_ID_LENGTH 1024 //bytes
+
#ifndef NGX_HTTP_CONFLICT
#define NGX_HTTP_CONFLICT 409
#endif
12 src/ngx_http_push_module_setup.c
View
@@ -102,6 +102,7 @@ static void * ngx_http_push_create_loc_conf(ngx_conf_t *cf) {
lcf->authorize_channel=NGX_CONF_UNSET;
lcf->store_messages=NGX_CONF_UNSET;
lcf->min_message_recipients=NGX_CONF_UNSET;
+ lcf->max_channel_id_length=NGX_CONF_UNSET;
lcf->channel_group.data=NULL;
return lcf;
}
@@ -116,7 +117,9 @@ static char * ngx_http_push_merge_loc_conf(ngx_conf_t *cf, void *parent, void *c
ngx_conf_merge_value(conf->authorize_channel, prev->authorize_channel, 0);
ngx_conf_merge_value(conf->store_messages, prev->store_messages, 1);
ngx_conf_merge_value(conf->min_message_recipients, prev->min_message_recipients, NGX_HTTP_PUSH_MIN_MESSAGE_RECIPIENTS);
+ ngx_conf_merge_value(conf->max_channel_id_length, prev->max_channel_id_length, NGX_HTTP_PUSH_MAX_CHANNEL_ID_LENGTH);
ngx_conf_merge_str_value(conf->channel_group, prev->channel_group, "");
+
//sanity checks
if(conf->max_messages < conf->min_messages) {
//min/max buffer size makes sense?
@@ -266,6 +269,14 @@ static ngx_command_t ngx_http_push_commands[] = {
offsetof(ngx_http_push_loc_conf_t, channel_group),
NULL },
+ { ngx_string("push_max_channel_id_length"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_push_loc_conf_t, max_channel_id_length),
+ NULL },
+
+
//deprecated and misleading. remove no earlier than november 2009.
{ ngx_string("push_buffer_size"),
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
@@ -285,7 +296,6 @@ static ngx_command_t ngx_http_push_commands[] = {
ngx_null_command
};
-
static ngx_http_module_t ngx_http_push_module_ctx = {
NULL, /* preconfiguration */
ngx_http_push_postconfig, /* postconfiguration */
Please sign in to comment.
Something went wrong with that request. Please try again.