comparison src/http/modules/ngx_http_sub_filter_module.c @ 5285:d47ef93134e5

Sub filter: switched to ngx_chain_get_free_buf(). No functional changes.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 25 Jul 2013 14:54:45 +0400
parents eaa9c732a1b9
children 819c5b53d8b5
comparison
equal deleted inserted replaced
5284:eaa9c732a1b9 5285:d47ef93134e5
266 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 266 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
267 "saved: \"%V\"", &ctx->saved); 267 "saved: \"%V\"", &ctx->saved);
268 268
269 if (ctx->saved.len) { 269 if (ctx->saved.len) {
270 270
271 if (ctx->free) { 271 cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
272 cl = ctx->free; 272 if (cl == NULL) {
273 ctx->free = ctx->free->next; 273 return NGX_ERROR;
274 b = cl->buf;
275 ngx_memzero(b, sizeof(ngx_buf_t));
276
277 } else {
278 b = ngx_calloc_buf(r->pool);
279 if (b == NULL) {
280 return NGX_ERROR;
281 }
282
283 cl = ngx_alloc_chain_link(r->pool);
284 if (cl == NULL) {
285 return NGX_ERROR;
286 }
287
288 cl->buf = b;
289 } 274 }
275
276 b = cl->buf;
277
278 ngx_memzero(b, sizeof(ngx_buf_t));
290 279
291 b->pos = ngx_pnalloc(r->pool, ctx->saved.len); 280 b->pos = ngx_pnalloc(r->pool, ctx->saved.len);
292 if (b->pos == NULL) { 281 if (b->pos == NULL) {
293 return NGX_ERROR; 282 return NGX_ERROR;
294 } 283 }
301 ctx->last_out = &cl->next; 290 ctx->last_out = &cl->next;
302 291
303 ctx->saved.len = 0; 292 ctx->saved.len = 0;
304 } 293 }
305 294
306 if (ctx->free) { 295 cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
307 cl = ctx->free; 296 if (cl == NULL) {
308 ctx->free = ctx->free->next; 297 return NGX_ERROR;
309 b = cl->buf; 298 }
310 299
311 } else { 300 b = cl->buf;
312 b = ngx_alloc_buf(r->pool);
313 if (b == NULL) {
314 return NGX_ERROR;
315 }
316
317 cl = ngx_alloc_chain_link(r->pool);
318 if (cl == NULL) {
319 return NGX_ERROR;
320 }
321
322 cl->buf = b;
323 }
324 301
325 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t)); 302 ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t));
326 303
327 b->pos = ctx->copy_start; 304 b->pos = ctx->copy_start;
328 b->last = ctx->copy_end; 305 b->last = ctx->copy_end;
333 if (b->in_file) { 310 if (b->in_file) {
334 b->file_last = b->file_pos + (b->last - ctx->buf->pos); 311 b->file_last = b->file_pos + (b->last - ctx->buf->pos);
335 b->file_pos += b->pos - ctx->buf->pos; 312 b->file_pos += b->pos - ctx->buf->pos;
336 } 313 }
337 314
338 cl->next = NULL;
339 *ctx->last_out = cl; 315 *ctx->last_out = cl;
340 ctx->last_out = &cl->next; 316 ctx->last_out = &cl->next;
341 } 317 }
342 318
343 if (ctx->state == sub_start_state) { 319 if (ctx->state == sub_start_state) {
354 } 330 }
355 331
356 332
357 /* rc == NGX_OK */ 333 /* rc == NGX_OK */
358 334
359 b = ngx_calloc_buf(r->pool); 335 cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
360 if (b == NULL) {
361 return NGX_ERROR;
362 }
363
364 cl = ngx_alloc_chain_link(r->pool);
365 if (cl == NULL) { 336 if (cl == NULL) {
366 return NGX_ERROR; 337 return NGX_ERROR;
367 } 338 }
339
340 b = cl->buf;
341
342 ngx_memzero(b, sizeof(ngx_buf_t));
368 343
369 slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module); 344 slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module);
370 345
371 if (ctx->sub.data == NULL) { 346 if (ctx->sub.data == NULL) {
372 347
384 359
385 } else { 360 } else {
386 b->sync = 1; 361 b->sync = 1;
387 } 362 }
388 363
389 cl->buf = b;
390 cl->next = NULL;
391 *ctx->last_out = cl; 364 *ctx->last_out = cl;
392 ctx->last_out = &cl->next; 365 ctx->last_out = &cl->next;
393 366
394 ctx->once = slcf->once; 367 ctx->once = slcf->once;
395 368
396 continue; 369 continue;
397 } 370 }
398 371
399 if (ctx->buf->last_buf || ngx_buf_in_memory(ctx->buf)) { 372 if (ctx->buf->last_buf || ngx_buf_in_memory(ctx->buf)) {
400 if (b == NULL) { 373 if (b == NULL) {
401 if (ctx->free) { 374 cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
402 cl = ctx->free; 375 if (cl == NULL) {
403 ctx->free = ctx->free->next; 376 return NGX_ERROR;
404 b = cl->buf; 377 }
405 ngx_memzero(b, sizeof(ngx_buf_t)); 378
406 379 b = cl->buf;
407 } else { 380
408 b = ngx_calloc_buf(r->pool); 381 ngx_memzero(b, sizeof(ngx_buf_t));
409 if (b == NULL) {
410 return NGX_ERROR;
411 }
412
413 cl = ngx_alloc_chain_link(r->pool);
414 if (cl == NULL) {
415 return NGX_ERROR;
416 }
417
418 cl->buf = b;
419 }
420 382
421 b->sync = 1; 383 b->sync = 1;
422 384
423 cl->next = NULL;
424 *ctx->last_out = cl; 385 *ctx->last_out = cl;
425 ctx->last_out = &cl->next; 386 ctx->last_out = &cl->next;
426 } 387 }
427 388
428 b->last_buf = ctx->buf->last_buf; 389 b->last_buf = ctx->buf->last_buf;