Commit 240bdae1 authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

changing ngx_http_push_stream_template_queue_t type and...

changing ngx_http_push_stream_template_queue_t type and ngx_http_push_stream_find_or_add_template function to be possible to use ngx_http_push_stream_create_str on the copy of template
parent 8cd0db6b
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
// template queue // template queue
typedef struct { typedef struct {
ngx_queue_t queue; // this MUST be first ngx_queue_t queue; // this MUST be first
ngx_str_t template; ngx_str_t *template;
ngx_uint_t index; ngx_uint_t index;
} ngx_http_push_stream_template_queue_t; } ngx_http_push_stream_template_queue_t;
......
...@@ -206,7 +206,7 @@ static ngx_int_t ngx_http_push_stream_send_only_header_response(ngx_h ...@@ -206,7 +206,7 @@ static ngx_int_t ngx_http_push_stream_send_only_header_response(ngx_h
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 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_str_t * ngx_http_push_stream_get_formatted_chunk(const u_char *text, off_t len, ngx_pool_t *temp_pool); static ngx_str_t * ngx_http_push_stream_get_formatted_chunk(const u_char *text, off_t len, ngx_pool_t *temp_pool);
static ngx_str_t * ngx_http_push_stream_get_formatted_message(ngx_http_request_t *r, ngx_http_push_stream_channel_t *channel, ngx_http_push_stream_msg_t *msg, ngx_pool_t *temp_pool); static ngx_str_t * ngx_http_push_stream_get_formatted_message(ngx_http_request_t *r, ngx_http_push_stream_channel_t *channel, ngx_http_push_stream_msg_t *msg, ngx_pool_t *temp_pool);
static ngx_str_t * ngx_http_push_stream_format_message(ngx_http_push_stream_channel_t *channel, ngx_http_push_stream_msg_t *message, ngx_str_t message_template, ngx_pool_t *temp_pool); static ngx_str_t * ngx_http_push_stream_format_message(ngx_http_push_stream_channel_t *channel, ngx_http_push_stream_msg_t *message, ngx_str_t *message_template, 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_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_text(ngx_http_request_t *r, const u_char *text, uint len, ngx_flag_t last_buffer); static ngx_int_t ngx_http_push_stream_send_response_text(ngx_http_request_t *r, const u_char *text, uint len, ngx_flag_t last_buffer);
static ngx_int_t ngx_http_push_stream_send_ping(ngx_log_t *log, ngx_http_push_stream_loc_conf_t *pslcf); static ngx_int_t ngx_http_push_stream_send_ping(ngx_log_t *log, ngx_http_push_stream_loc_conf_t *pslcf);
......
...@@ -313,10 +313,10 @@ static ngx_int_t ...@@ -313,10 +313,10 @@ static ngx_int_t
ngx_http_push_stream_find_or_add_template(ngx_conf_t *cf, ngx_str_t template) { ngx_http_push_stream_find_or_add_template(ngx_conf_t *cf, ngx_str_t template) {
ngx_http_push_stream_template_queue_t *sentinel = &ngx_http_push_stream_module_main_conf->msg_templates; ngx_http_push_stream_template_queue_t *sentinel = &ngx_http_push_stream_module_main_conf->msg_templates;
ngx_http_push_stream_template_queue_t *cur = sentinel; ngx_http_push_stream_template_queue_t *cur = sentinel;
u_char *aux = NULL; ngx_str_t *aux = NULL;
while ((cur = (ngx_http_push_stream_template_queue_t *) ngx_queue_next(&cur->queue)) != sentinel) { while ((cur = (ngx_http_push_stream_template_queue_t *) ngx_queue_next(&cur->queue)) != sentinel) {
if (ngx_memn2cmp(cur->template.data, template.data, cur->template.len, template.len) == 0) { if (ngx_memn2cmp(cur->template->data, template.data, cur->template->len, template.len) == 0) {
return cur->index; return cur->index;
} }
} }
...@@ -324,16 +324,14 @@ ngx_http_push_stream_find_or_add_template(ngx_conf_t *cf, ngx_str_t template) { ...@@ -324,16 +324,14 @@ ngx_http_push_stream_find_or_add_template(ngx_conf_t *cf, ngx_str_t template) {
ngx_http_push_stream_module_main_conf->qtd_templates++; ngx_http_push_stream_module_main_conf->qtd_templates++;
cur = ngx_pcalloc(cf->pool, sizeof(ngx_http_push_stream_template_queue_t)); cur = ngx_pcalloc(cf->pool, sizeof(ngx_http_push_stream_template_queue_t));
aux = ngx_pcalloc(cf->pool, template.len + 1); aux = ngx_http_push_stream_create_str(cf->pool, template.len);
if ((cur == NULL) || (aux == NULL)) { if ((cur == NULL) || (aux == NULL)) {
ngx_log_error(NGX_LOG_ERR, cf->log, 0, "push stream module: unable to allocate memory for add template to main configuration"); ngx_log_error(NGX_LOG_ERR, cf->log, 0, "push stream module: unable to allocate memory for add template to main configuration");
return -1; return -1;
} }
cur->template.data = aux; cur->template = aux;
cur->index = ngx_http_push_stream_module_main_conf->qtd_templates; cur->index = ngx_http_push_stream_module_main_conf->qtd_templates;
cur->template.len = template.len; ngx_memcpy(cur->template->data, template.data, template.len);
ngx_memset(cur->template.data, '\0', template.len + 1);
ngx_memcpy(cur->template.data, template.data, template.len);
ngx_queue_insert_tail(&ngx_http_push_stream_module_main_conf->msg_templates.queue, &cur->queue); ngx_queue_insert_tail(&ngx_http_push_stream_module_main_conf->msg_templates.queue, &cur->queue);
return cur->index; return cur->index;
} }
...@@ -699,15 +699,15 @@ ngx_http_push_stream_get_formatted_message(ngx_http_request_t *r, ngx_http_push_ ...@@ -699,15 +699,15 @@ ngx_http_push_stream_get_formatted_message(ngx_http_request_t *r, ngx_http_push_
} }
static ngx_str_t * static ngx_str_t *
ngx_http_push_stream_format_message(ngx_http_push_stream_channel_t *channel, ngx_http_push_stream_msg_t *message, ngx_str_t message_template, ngx_pool_t *pool) ngx_http_push_stream_format_message(ngx_http_push_stream_channel_t *channel, ngx_http_push_stream_msg_t *message, ngx_str_t *message_template, ngx_pool_t *pool)
{ {
ngx_uint_t len = 0; ngx_uint_t len = 0;
u_char *txt = NULL; u_char *txt = NULL;
ngx_str_t *str = NULL; ngx_str_t *str = NULL;
u_char template[message_template.len + 1]; u_char template[message_template->len + 1];
ngx_memset(template, '\0', message_template.len + 1); ngx_memset(template, '\0', message_template->len + 1);
ngx_memcpy(template, message_template.data, message_template.len); ngx_memcpy(template, message_template->data, message_template->len);
u_char char_id[NGX_INT_T_LEN]; u_char char_id[NGX_INT_T_LEN];
ngx_memset(char_id, '\0', NGX_INT_T_LEN); ngx_memset(char_id, '\0', NGX_INT_T_LEN);
......
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