nxt_application.c (141:96a65c601420) nxt_application.c (206:86a529b2ea9b)
1
2/*
3 * Copyright (C) Max Romanov
4 * Copyright (C) Igor Sysoev
5 * Copyright (C) Valentin V. Bartenev
6 * Copyright (C) NGINX, Inc.
7 */
8

--- 140 unchanged lines hidden (view full) ---

149
150 if (free_size >= size) {
151 res = b->mem.free;
152 b->mem.free += size;
153
154 return res;
155 }
156
1
2/*
3 * Copyright (C) Max Romanov
4 * Copyright (C) Igor Sysoev
5 * Copyright (C) Valentin V. Bartenev
6 * Copyright (C) NGINX, Inc.
7 */
8

--- 140 unchanged lines hidden (view full) ---

149
150 if (free_size >= size) {
151 res = b->mem.free;
152 b->mem.free += size;
153
154 return res;
155 }
156
157 if (nxt_port_mmap_increase_buf(task, b, size) == NXT_OK) {
157 if (nxt_port_mmap_increase_buf(task, b, size, size) == NXT_OK) {
158 res = b->mem.free;
159 b->mem.free += size;
160
161 return res;
162 }
163
164 msg->buf = &b->next;
165 } while(1);

--- 135 unchanged lines hidden (view full) ---

301
302 nxt_debug(task, "nxt_read_str: NULL");
303 }
304
305 return NXT_OK;
306}
307
308
158 res = b->mem.free;
159 b->mem.free += size;
160
161 return res;
162 }
163
164 msg->buf = &b->next;
165 } while(1);

--- 135 unchanged lines hidden (view full) ---

301
302 nxt_debug(task, "nxt_read_str: NULL");
303 }
304
305 return NXT_OK;
306}
307
308
309size_t
310nxt_app_msg_read_raw(nxt_task_t *task, nxt_app_rmsg_t *msg, void *dst,
311 size_t size)
312{
313 size_t res, read_size;
314 nxt_buf_t *buf;
315
316 res = 0;
317
318 while (size > 0) {
319 buf = msg->buf;
320
321 if (nxt_slow_path(buf == NULL)) {
322 break;
323 }
324
325 if (nxt_slow_path(nxt_buf_mem_used_size(&buf->mem) == 0)) {
326 msg->buf = buf->next;
327 continue;
328 }
329
330 read_size = nxt_buf_mem_used_size(&buf->mem);
331 read_size = nxt_min(read_size, size);
332
333 dst = nxt_cpymem(dst, buf->mem.pos, read_size);
334
335 size -= read_size;
336 buf->mem.pos += read_size;
337 res += read_size;
338 }
339
340 nxt_debug(task, "nxt_read_raw: %uz", res);
341
342 return res;
343}
344
345
309nxt_int_t
310nxt_app_msg_read_nvp(nxt_task_t *task, nxt_app_rmsg_t *rmsg, nxt_str_t *n,
311 nxt_str_t *v)
312{
313 nxt_int_t rc;
314
315 rc = nxt_app_msg_read_str(task, rmsg, n);
316 if (nxt_slow_path(rc != NXT_OK)) {

--- 137 unchanged lines hidden (view full) ---

454
455 ctx->parser.fields_hash = nxt_app_request_fields_hash;
456
457 return NXT_OK;
458}
459
460
461nxt_int_t
346nxt_int_t
347nxt_app_msg_read_nvp(nxt_task_t *task, nxt_app_rmsg_t *rmsg, nxt_str_t *n,
348 nxt_str_t *v)
349{
350 nxt_int_t rc;
351
352 rc = nxt_app_msg_read_str(task, rmsg, n);
353 if (nxt_slow_path(rc != NXT_OK)) {

--- 137 unchanged lines hidden (view full) ---

491
492 ctx->parser.fields_hash = nxt_app_request_fields_hash;
493
494 return NXT_OK;
495}
496
497
498nxt_int_t
462nxt_app_http_req_parse(nxt_task_t *task, nxt_app_parse_ctx_t *ctx,
499nxt_app_http_req_header_parse(nxt_task_t *task, nxt_app_parse_ctx_t *ctx,
463 nxt_buf_t *buf)
464{
465 nxt_int_t rc;
466 nxt_app_request_body_t *b;
467 nxt_http_request_parse_t *p;
468 nxt_app_request_header_t *h;
469
470 p = &ctx->parser;
471 b = &ctx->r.body;
472 h = &ctx->r.header;
473
500 nxt_buf_t *buf)
501{
502 nxt_int_t rc;
503 nxt_app_request_body_t *b;
504 nxt_http_request_parse_t *p;
505 nxt_app_request_header_t *h;
506
507 p = &ctx->parser;
508 b = &ctx->r.body;
509 h = &ctx->r.header;
510
474 if (h->done == 0) {
475 rc = nxt_http_parse_request(p, &buf->mem);
511 nxt_assert(h->done == 0);
476
512
477 if (nxt_slow_path(rc != NXT_DONE)) {
478 return rc;
479 }
513 rc = nxt_http_parse_request(p, &buf->mem);
480
514
481 rc = nxt_http_fields_process(p->fields, ctx, task->log);
515 if (nxt_slow_path(rc != NXT_DONE)) {
516 return rc;
517 }
482
518
483 if (nxt_slow_path(rc != NXT_OK)) {
484 return rc;
485 }
519 rc = nxt_http_fields_process(p->fields, ctx, task->log);
486
520
487 h->fields = p->fields;
488 h->done = 1;
521 if (nxt_slow_path(rc != NXT_OK)) {
522 return rc;
523 }
489
524
490 h->version.start = p->version.str;
491 h->version.length = nxt_strlen(p->version.str);
525 h->fields = p->fields;
526 h->done = 1;
492
527
493 h->method = p->method;
528 h->version.start = p->version.str;
529 h->version.length = nxt_strlen(p->version.str);
494
530
495 h->target.start = p->target_start;
496 h->target.length = p->target_end - p->target_start;
531 h->method = p->method;
497
532
498 h->path = p->path;
499 h->query = p->args;
533 h->target.start = p->target_start;
534 h->target.length = p->target_end - p->target_start;
500
535
501 if (h->parsed_content_length == 0) {
502 b->done = 1;
503 }
504 }
536 h->path = p->path;
537 h->query = p->args;
505
538
506 if (b->done == 0) {
507 b->preread.length = buf->mem.free - buf->mem.pos;
508 b->preread.start = buf->mem.pos;
539 if (h->parsed_content_length == 0) {
540 b->done = 1;
509
541
510 b->done = b->preread.length >= (size_t) h->parsed_content_length;
511 }
512
542 }
543
513 if (h->done == 1 && b->done == 1) {
544 if (buf->mem.free == buf->mem.pos) {
514 return NXT_DONE;
515 }
516
545 return NXT_DONE;
546 }
547
517 return NXT_AGAIN;
548 b->buf = buf;
549 b->done = nxt_buf_mem_used_size(&buf->mem) >=
550 h->parsed_content_length;
551
552 if (b->done == 1) {
553 b->preread_size = nxt_buf_mem_used_size(&buf->mem);
554 }
555
556 return NXT_DONE;
518}
519
520
521nxt_int_t
557}
558
559
560nxt_int_t
561nxt_app_http_req_body_read(nxt_task_t *task, nxt_app_parse_ctx_t *ctx,
562 nxt_buf_t *buf)
563{
564 nxt_app_request_body_t *b;
565 nxt_app_request_header_t *h;
566
567 b = &ctx->r.body;
568 h = &ctx->r.header;
569
570 nxt_assert(h->done == 1);
571 nxt_assert(b->done == 0);
572
573 b->done = nxt_buf_mem_used_size(&buf->mem) + b->preread_size >=
574 (size_t) h->parsed_content_length;
575
576 if (b->done == 1) {
577 b->preread_size += nxt_buf_mem_used_size(&buf->mem);
578 }
579
580 return b->done == 1 ? NXT_DONE : NXT_AGAIN;
581}
582
583
584nxt_int_t
522nxt_app_http_req_done(nxt_task_t *task, nxt_app_parse_ctx_t *ctx)
523{
524 nxt_mp_destroy(ctx->mem_pool);
525
526 return NXT_OK;
527}
528
529

--- 36 unchanged lines hidden (view full) ---

566 return rc;
567}
568
569
570nxt_int_t
571nxt_app_msg_write_raw(nxt_task_t *task, nxt_app_wmsg_t *msg, const u_char *c,
572 size_t size)
573{
585nxt_app_http_req_done(nxt_task_t *task, nxt_app_parse_ctx_t *ctx)
586{
587 nxt_mp_destroy(ctx->mem_pool);
588
589 return NXT_OK;
590}
591
592

--- 36 unchanged lines hidden (view full) ---

629 return rc;
630}
631
632
633nxt_int_t
634nxt_app_msg_write_raw(nxt_task_t *task, nxt_app_wmsg_t *msg, const u_char *c,
635 size_t size)
636{
574 u_char *dst;
637 size_t free_size, copy_size;
638 nxt_buf_t *b;
639 nxt_port_t *port;
575
640
576 dst = nxt_app_msg_write_get_buf(task, msg, size);
577 if (nxt_slow_path(dst == NULL)) {
578 return NXT_ERROR;
579 }
641 nxt_debug(task, "nxt_app_msg_write_raw: %uz", size);
580
642
581 nxt_memcpy(dst, c, size);
643 while (size > 0) {
644 b = *msg->buf;
582
645
583 nxt_debug(task, "nxt_app_msg_write_raw: %d %*s", (int)size,
584 (int)size, c);
646 if (b == NULL) {
647 port = nxt_app_msg_get_port(task, msg);
648 if (nxt_slow_path(port == NULL)) {
649 return NXT_ERROR;
650 }
585
651
652 b = nxt_port_mmap_get_buf(task, port, size);
653 if (nxt_slow_path(b == NULL)) {
654 return NXT_ERROR;
655 }
656
657 *msg->buf = b;
658 }
659
660 do {
661 free_size = nxt_buf_mem_free_size(&b->mem);
662
663 if (free_size > 0) {
664 copy_size = nxt_min(free_size, size);
665
666 b->mem.free = nxt_cpymem(b->mem.free, c, copy_size);
667
668 size -= copy_size;
669 c += copy_size;
670
671 if (size == 0) {
672 return NXT_OK;
673 }
674 }
675 } while (nxt_port_mmap_increase_buf(task, b, size, 1) == NXT_OK);
676
677 msg->buf = &b->next;
678 }
679
586 return NXT_OK;
587}
588
589
590nxt_app_type_t
591nxt_app_parse_type(nxt_str_t *str)
592{
593 if (nxt_str_eq(str, "python", 6)) {

--- 27 unchanged lines hidden ---
680 return NXT_OK;
681}
682
683
684nxt_app_type_t
685nxt_app_parse_type(nxt_str_t *str)
686{
687 if (nxt_str_eq(str, "python", 6)) {

--- 27 unchanged lines hidden ---