nxt_application.c (408:9d8ed4fab957) nxt_application.c (417:47366bb40f2c)
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

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

23
24static nxt_buf_t *nxt_discovery_modules(nxt_task_t *task, const char *path);
25static nxt_int_t nxt_discovery_module(nxt_task_t *task, nxt_mp_t *mp,
26 nxt_array_t *modules, const char *name);
27static nxt_app_module_t *nxt_app_module_load(nxt_task_t *task,
28 const char *name);
29static nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length);
30
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

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

23
24static nxt_buf_t *nxt_discovery_modules(nxt_task_t *task, const char *path);
25static nxt_int_t nxt_discovery_module(nxt_task_t *task, nxt_mp_t *mp,
26 nxt_array_t *modules, const char *name);
27static nxt_app_module_t *nxt_app_module_load(nxt_task_t *task,
28 const char *name);
29static nxt_app_type_t nxt_app_parse_type(u_char *p, size_t length);
30
31static nxt_int_t nxt_app_request_content_length(void *ctx,
32 nxt_http_field_t *field, uintptr_t data);
33static nxt_int_t nxt_app_request_content_type(void *ctx,
34 nxt_http_field_t *field, uintptr_t data);
35static nxt_int_t nxt_app_request_cookie(void *ctx, nxt_http_field_t *field,
36 uintptr_t data);
37static nxt_int_t nxt_app_request_host(void *ctx, nxt_http_field_t *field,
38 uintptr_t data);
31
39
32static nxt_thread_mutex_t nxt_app_mutex;
33static nxt_thread_cond_t nxt_app_cond;
34
40
35static nxt_http_fields_hash_entry_t nxt_app_request_fields[];
36static nxt_http_fields_hash_t *nxt_app_request_fields_hash;
41static nxt_http_field_proc_t nxt_app_request_fields[] = {
42 { nxt_string("Content-Length"), &nxt_app_request_content_length, 0 },
43 { nxt_string("Content-Type"), &nxt_app_request_content_type, 0 },
44 { nxt_string("Cookie"), &nxt_app_request_cookie, 0 },
45 { nxt_string("Host"), &nxt_app_request_host, 0 },
46};
37
47
38static nxt_application_module_t *nxt_app;
39
48
40
41static uint32_t compat[] = {
42 NXT_VERNUM, NXT_DEBUG,
43};
44
45
49static uint32_t compat[] = {
50 NXT_VERNUM, NXT_DEBUG,
51};
52
53
54static nxt_lvlhsh_t nxt_app_request_fields_hash;
55
56static nxt_thread_mutex_t nxt_app_mutex;
57static nxt_thread_cond_t nxt_app_cond;
58
59static nxt_application_module_t *nxt_app;
60
61
46nxt_int_t
47nxt_discovery_start(nxt_task_t *task, void *data)
48{
49 nxt_buf_t *b;
50 nxt_port_t *main_port;
51 nxt_runtime_t *rt;
52
53 nxt_debug(task, "DISCOVERY");

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

354
355 return NULL;
356}
357
358
359nxt_int_t
360nxt_app_http_init(nxt_task_t *task, nxt_runtime_t *rt)
361{
62nxt_int_t
63nxt_discovery_start(nxt_task_t *task, void *data)
64{
65 nxt_buf_t *b;
66 nxt_port_t *main_port;
67 nxt_runtime_t *rt;
68
69 nxt_debug(task, "DISCOVERY");

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

370
371 return NULL;
372}
373
374
375nxt_int_t
376nxt_app_http_init(nxt_task_t *task, nxt_runtime_t *rt)
377{
362 nxt_http_fields_hash_t *hash;
363
364 hash = nxt_http_fields_hash_create(nxt_app_request_fields, rt->mem_pool);
365 if (nxt_slow_path(hash == NULL)) {
366 return NXT_ERROR;
367 }
368
369 nxt_app_request_fields_hash = hash;
370
371 return NXT_OK;
378 return nxt_http_fields_hash(&nxt_app_request_fields_hash, rt->mem_pool,
379 nxt_app_request_fields,
380 nxt_nitems(nxt_app_request_fields));
372}
373
374
375void
376nxt_port_app_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
377{
378 size_t dump_size;
379 nxt_buf_t *b;

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

507 }
508
509 return NXT_OK;
510}
511
512
513nxt_int_t
514nxt_app_msg_write_prefixed_upcase(nxt_task_t *task, nxt_app_wmsg_t *msg,
381}
382
383
384void
385nxt_port_app_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
386{
387 size_t dump_size;
388 nxt_buf_t *b;

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

516 }
517
518 return NXT_OK;
519}
520
521
522nxt_int_t
523nxt_app_msg_write_prefixed_upcase(nxt_task_t *task, nxt_app_wmsg_t *msg,
515 const nxt_str_t *prefix, const nxt_str_t *v)
524 const nxt_str_t *prefix, u_char *c, size_t size)
516{
517 u_char *dst, *src;
518 size_t i, length, dst_length;
519
525{
526 u_char *dst, *src;
527 size_t i, length, dst_length;
528
520 length = prefix->length + v->length;
529 length = prefix->length + size;
521
522 dst_length = length + (length < 128 ? 1 : 4) + 1;
523
524 dst = nxt_app_msg_write_get_buf(task, msg, dst_length);
525 if (nxt_slow_path(dst == NULL)) {
526 return NXT_ERROR;
527 }
528
529 dst = nxt_app_msg_write_length(dst, length + 1); /* +1 for trailing 0 */
530
531 nxt_memcpy(dst, prefix->start, prefix->length);
532 dst += prefix->length;
533
530
531 dst_length = length + (length < 128 ? 1 : 4) + 1;
532
533 dst = nxt_app_msg_write_get_buf(task, msg, dst_length);
534 if (nxt_slow_path(dst == NULL)) {
535 return NXT_ERROR;
536 }
537
538 dst = nxt_app_msg_write_length(dst, length + 1); /* +1 for trailing 0 */
539
540 nxt_memcpy(dst, prefix->start, prefix->length);
541 dst += prefix->length;
542
534 src = v->start;
535 for (i = 0; i < v->length; i++, dst++, src++) {
543 src = c;
544 for (i = 0; i < size; i++, dst++, src++) {
536
537 if (*src >= 'a' && *src <= 'z') {
538 *dst = *src & ~0x20;
539 continue;
540 }
541
542 if (*src == '-') {
543 *dst = '_';

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

699 nxt_debug(task, "nxt_read_size: %d", (int) *size);
700
701 return NXT_OK;
702}
703
704
705static nxt_int_t
706nxt_app_request_content_length(void *ctx, nxt_http_field_t *field,
545
546 if (*src >= 'a' && *src <= 'z') {
547 *dst = *src & ~0x20;
548 continue;
549 }
550
551 if (*src == '-') {
552 *dst = '_';

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

708 nxt_debug(task, "nxt_read_size: %d", (int) *size);
709
710 return NXT_OK;
711}
712
713
714static nxt_int_t
715nxt_app_request_content_length(void *ctx, nxt_http_field_t *field,
707 nxt_log_t *log)
716 uintptr_t data)
708{
717{
709 nxt_str_t *v;
710 nxt_app_parse_ctx_t *c;
711 nxt_app_request_header_t *h;
712
713 c = ctx;
714 h = &c->r.header;
718 nxt_app_parse_ctx_t *c;
719 nxt_app_request_header_t *h;
720
721 c = ctx;
722 h = &c->r.header;
715 v = &field->value;
716
723
717 h->content_length = *v;
718 h->parsed_content_length = nxt_off_t_parse(v->start, v->length);
724 h->content_length.length = field->value_length;
725 h->content_length.start = field->value;
719
726
727 h->parsed_content_length = nxt_off_t_parse(field->value,
728 field->value_length);
729
720 return NXT_OK;
721}
722
723
724static nxt_int_t
725nxt_app_request_content_type(void *ctx, nxt_http_field_t *field,
730 return NXT_OK;
731}
732
733
734static nxt_int_t
735nxt_app_request_content_type(void *ctx, nxt_http_field_t *field,
726 nxt_log_t *log)
736 uintptr_t data)
727{
728 nxt_app_parse_ctx_t *c;
729 nxt_app_request_header_t *h;
730
731 c = ctx;
732 h = &c->r.header;
733
737{
738 nxt_app_parse_ctx_t *c;
739 nxt_app_request_header_t *h;
740
741 c = ctx;
742 h = &c->r.header;
743
734 h->content_type = field->value;
744 h->content_type.length = field->value_length;
745 h->content_type.start = field->value;
735
736 return NXT_OK;
737}
738
739
740static nxt_int_t
746
747 return NXT_OK;
748}
749
750
751static nxt_int_t
741nxt_app_request_cookie(void *ctx, nxt_http_field_t *field,
742 nxt_log_t *log)
752nxt_app_request_cookie(void *ctx, nxt_http_field_t *field, uintptr_t data)
743{
744 nxt_app_parse_ctx_t *c;
745 nxt_app_request_header_t *h;
746
747 c = ctx;
748 h = &c->r.header;
749
753{
754 nxt_app_parse_ctx_t *c;
755 nxt_app_request_header_t *h;
756
757 c = ctx;
758 h = &c->r.header;
759
750 h->cookie = field->value;
760 h->cookie.length = field->value_length;
761 h->cookie.start = field->value;
751
752 return NXT_OK;
753}
754
755
756static nxt_int_t
762
763 return NXT_OK;
764}
765
766
767static nxt_int_t
757nxt_app_request_host(void *ctx, nxt_http_field_t *field,
758 nxt_log_t *log)
768nxt_app_request_host(void *ctx, nxt_http_field_t *field, uintptr_t data)
759{
760 nxt_app_parse_ctx_t *c;
761 nxt_app_request_header_t *h;
762
763 c = ctx;
764 h = &c->r.header;
765
769{
770 nxt_app_parse_ctx_t *c;
771 nxt_app_request_header_t *h;
772
773 c = ctx;
774 h = &c->r.header;
775
766 h->host = field->value;
776 h->host.length = field->value_length;
777 h->host.start = field->value;
767
768 return NXT_OK;
769}
770
771
778
779 return NXT_OK;
780}
781
782
772static nxt_http_fields_hash_entry_t nxt_app_request_fields[] = {
773 { nxt_string("Content-Length"), &nxt_app_request_content_length, 0 },
774 { nxt_string("Content-Type"), &nxt_app_request_content_type, 0 },
775 { nxt_string("Cookie"), &nxt_app_request_cookie, 0 },
776 { nxt_string("Host"), &nxt_app_request_host, 0 },
777
778 { nxt_null_string, NULL, 0 }
779};
780
781
782nxt_app_parse_ctx_t *
783nxt_app_http_req_init(nxt_task_t *task)
784{
785 nxt_mp_t *mp;
786 nxt_int_t rc;
787 nxt_app_parse_ctx_t *ctx;
788
789 mp = nxt_mp_create(1024, 128, 256, 32);

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

800 ctx->mem_pool = mp;
801
802 rc = nxt_http_parse_request_init(&ctx->parser, mp);
803 if (nxt_slow_path(rc != NXT_OK)) {
804 nxt_mp_destroy(mp);
805 return NULL;
806 }
807
783nxt_app_parse_ctx_t *
784nxt_app_http_req_init(nxt_task_t *task)
785{
786 nxt_mp_t *mp;
787 nxt_int_t rc;
788 nxt_app_parse_ctx_t *ctx;
789
790 mp = nxt_mp_create(1024, 128, 256, 32);

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

801 ctx->mem_pool = mp;
802
803 rc = nxt_http_parse_request_init(&ctx->parser, mp);
804 if (nxt_slow_path(rc != NXT_OK)) {
805 nxt_mp_destroy(mp);
806 return NULL;
807 }
808
808 ctx->parser.fields_hash = nxt_app_request_fields_hash;
809
810 return ctx;
811}
812
813
814nxt_int_t
815nxt_app_http_req_header_parse(nxt_task_t *task, nxt_app_parse_ctx_t *ctx,
816 nxt_buf_t *buf)
817{

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

827 nxt_assert(h->done == 0);
828
829 rc = nxt_http_parse_request(p, &buf->mem);
830
831 if (nxt_slow_path(rc != NXT_DONE)) {
832 return rc;
833 }
834
809 return ctx;
810}
811
812
813nxt_int_t
814nxt_app_http_req_header_parse(nxt_task_t *task, nxt_app_parse_ctx_t *ctx,
815 nxt_buf_t *buf)
816{

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

826 nxt_assert(h->done == 0);
827
828 rc = nxt_http_parse_request(p, &buf->mem);
829
830 if (nxt_slow_path(rc != NXT_DONE)) {
831 return rc;
832 }
833
835 rc = nxt_http_fields_process(p->fields, ctx, task->log);
834 rc = nxt_http_fields_process(p->fields, &nxt_app_request_fields_hash, ctx);
836
837 if (nxt_slow_path(rc != NXT_OK)) {
838 return rc;
839 }
840
841 h->fields = p->fields;
842 h->done = 1;
843

--- 230 unchanged lines hidden ---
835
836 if (nxt_slow_path(rc != NXT_OK)) {
837 return rc;
838 }
839
840 h->fields = p->fields;
841 h->done = 1;
842

--- 230 unchanged lines hidden ---