Commit da8a3b09 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

fixing bug when apply message and channel name to template with values...

fixing bug when apply message and channel name to template with values containing the same template pattern
parent d6c423c5
h2. Version 0.2.2
* Creating different timers to clear the memory, one for expired messages and another for empty channels
* Fixing bug when apply message and channel name to template with values containing the same template pattern, could result in 100% of memory and CPU consumption, by recursion
* Fixing bug when manipulating a channel which was removed from tree for another worker (the 100% CPU bug)
* Fixing memory allocation for channel id
* Creating different timers to clear the memory, one for expired messages and another for empty channels
* Disable Nginx chuncked filter for module locations
h2. Version 0.2.1
......
......@@ -198,7 +198,7 @@ ngx_buf_t *ngx_http_push_stream_ping_buf = NULL;
ngx_http_push_stream_msg_t *ngx_http_push_stream_convert_buffer_to_msg_on_shared_locked(ngx_buf_t *buf);
static ngx_table_elt_t * ngx_http_push_stream_add_response_header(ngx_http_request_t *r, const ngx_str_t *header_name, const ngx_str_t *header_value);
static ngx_int_t ngx_http_push_stream_send_only_header_response(ngx_http_request_t *r, ngx_int_t status, const ngx_str_t *explain_error_message);
static u_char * ngx_http_push_stream_str_replace(u_char *org, u_char *find, u_char *replace, ngx_pool_t *temp_pool);
static u_char * ngx_http_push_stream_str_replace(u_char *org, u_char *find, u_char *replace, ngx_uint_t offset, ngx_pool_t *temp_pool);
static ngx_buf_t * ngx_http_push_stream_get_formatted_message(ngx_http_push_stream_loc_conf_t *pslcf, ngx_http_push_stream_channel_t *channel, ngx_buf_t *buf, ngx_pool_t *temp_pool);
static ngx_int_t ngx_http_push_stream_send_response_content_header(ngx_http_request_t *r, ngx_http_push_stream_loc_conf_t *pslcf);
static ngx_int_t ngx_http_push_stream_send_response_chunk(ngx_http_request_t *r, const u_char *chunk_text, uint chunk_len, ngx_flag_t last_buffer);
......
......@@ -486,7 +486,7 @@ ngx_http_push_stream_buffer_timer_wake_handler(ngx_event_t *ev)
}
static u_char *
ngx_http_push_stream_str_replace(u_char *org, u_char *find, u_char *replace, ngx_pool_t *pool)
ngx_http_push_stream_str_replace(u_char *org, u_char *find, u_char *replace, ngx_uint_t offset, ngx_pool_t *pool)
{
ngx_uint_t len_org = ngx_strlen(org);
ngx_uint_t len_find = ngx_strlen(find);
......@@ -495,7 +495,7 @@ ngx_http_push_stream_str_replace(u_char *org, u_char *find, u_char *replace, ngx
u_char *result = org;
if (len_find > 0) {
u_char *ret = (u_char *) ngx_strstr(org, find);
u_char *ret = (u_char *) ngx_strstr(org + offset, find);
if (ret != NULL) {
u_char *tmp = ngx_pcalloc(pool, len_org + len_replace + len_find + 1);
ngx_memset(tmp, '\0', len_org + len_replace + len_find + 1);
......@@ -505,7 +505,7 @@ ngx_http_push_stream_str_replace(u_char *org, u_char *find, u_char *replace, ngx
ngx_memcpy(tmp + len_found, replace, len_replace);
ngx_memcpy(tmp + len_found + len_replace, org + len_found + len_find, len_org - len_found - len_find);
result = ngx_http_push_stream_str_replace(tmp, find, replace, pool);
result = ngx_http_push_stream_str_replace(tmp, find, replace, len_found + len_replace, pool);
}
}
......@@ -540,9 +540,9 @@ ngx_http_push_stream_get_formatted_message(ngx_http_push_stream_loc_conf_t *pslc
ngx_memcpy(char_id, NGX_PUSH_STREAM_PING_MESSAGE_ID.data, NGX_PUSH_STREAM_PING_MESSAGE_ID.len + 1);
}
txt = ngx_http_push_stream_str_replace(template, NGX_PUSH_STREAM_TOKEN_MESSAGE_ID.data, char_id, pool);
txt = ngx_http_push_stream_str_replace(txt, NGX_PUSH_STREAM_TOKEN_MESSAGE_CHANNEL.data, channel_id, pool);
txt = ngx_http_push_stream_str_replace(txt, NGX_PUSH_STREAM_TOKEN_MESSAGE_TEXT.data, msg, pool);
txt = ngx_http_push_stream_str_replace(template, NGX_PUSH_STREAM_TOKEN_MESSAGE_ID.data, char_id, 0, pool);
txt = ngx_http_push_stream_str_replace(txt, NGX_PUSH_STREAM_TOKEN_MESSAGE_CHANNEL.data, channel_id, 0, pool);
txt = ngx_http_push_stream_str_replace(txt, NGX_PUSH_STREAM_TOKEN_MESSAGE_TEXT.data, msg, 0, pool);
len = ngx_strlen(txt);
buf = ngx_calloc_buf(pool);
......
......@@ -141,4 +141,38 @@ class TestComunicationProperties < Test::Unit::TestCase
fail_if_connecttion_error(sub)
}
end
def config_test_message_and_channel_with_same_pattern_of_the_template
@authorized_channels_only = "off"
@header_template = "header"
@message_template = '{\"channel\":\"~channel~\", \"message\":\"~text~\", \"message_id\":\"~id~\"}'
@ping_message_interval = "1s"
end
def test_message_and_channel_with_same_pattern_of_the_template
channel = 'ch_test_message_and_channel_with_same_pattern_of_the_template~channel~~channel~~channel~~text~~text~~text~'
headers = {'accept' => 'text/html'}
body = '~channel~~channel~~channel~~text~~text~~text~'
publish_message(channel, headers, body)
response = ""
EventMachine.run {
chunksReceived = 0
sub = EventMachine::HttpRequest.new(nginx_address + '/sub/' + channel.to_s + '.b1').get :head => headers, :timeout => 60
sub.stream { |chunk|
response += chunk
lines = response.split("\r\n")
if lines.length >= 3
assert_equal("#{@header_template}", lines[0], "Didn't received header template")
assert_equal("{\"channel\":\"ch_test_message_and_channel_with_same_pattern_of_the_template~channel~~channel~~channel~~channel~~channel~~channel~~text~~text~~text~~channel~~channel~~channel~~text~~text~~text~~channel~~channel~~channel~~text~~text~~text~\", \"message\":\"~channel~~channel~~channel~~text~~text~~text~\", \"message_id\":\"1\"}", lines[1], "Didn't received message formatted: #{lines[1]}")
assert_equal("{\"channel\":\"\", \"message\":\"\", \"message_id\":\"-1\"}", lines[2], "Didn't received ping message: #{lines[2]}")
EventMachine.stop
end
}
fail_if_connecttion_error(sub)
}
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment