Deleted Added
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_main.h>

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

83nxt_int_t
84nxt_controller_start(nxt_task_t *task, nxt_runtime_t *rt)
85{
86 nxt_mp_t *mp;
87 nxt_conf_value_t *conf;
88 nxt_http_fields_hash_t *hash;
89
90 static const nxt_str_t json
91 = nxt_string("{ \"listeners\": {}, \"applications\": {} }");
92
93 hash = nxt_http_fields_hash_create(nxt_controller_request_fields,
94 rt->mem_pool);
95 if (nxt_slow_path(hash == NULL)) {
96 return NXT_ERROR;
97 }
98
99 nxt_controller_fields_hash = hash;

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

588
589 mbuf = &c->read->mem;
590
591 value = nxt_conf_json_parse(mp, mbuf->pos, mbuf->free);
592
593 if (value == NULL) {
594 nxt_mp_destroy(mp);
595 status = 400;
596 nxt_str_set(&resp.json, "{ \"error\": \"Invalid JSON.\" }");
597 goto done;
598 }
599
600 if (path.length != 1) {
601 rc = nxt_conf_op_compile(c->mem_pool, &ops,
602 nxt_controller_conf.root,
603 &path, value);
604

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

616
617 if (nxt_slow_path(value == NULL)) {
618 nxt_mp_destroy(mp);
619 status = 500;
620 goto done;
621 }
622 }
623
624 if (nxt_slow_path(nxt_conf_validate(value) != NXT_OK)) {
625 status = 400;
626 nxt_str_set(&resp.json,
627 "{ \"error\": \"Invalid configuration.\" }");
628 goto done;
629 }
630
631 nxt_mp_destroy(nxt_controller_conf.pool);
632
633 nxt_controller_conf.root = value;
634 nxt_controller_conf.pool = mp;
635
636 nxt_str_set(&resp.json, "{ \"success\": \"Updated.\" }");
637
638 status = 200;

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

677 }
678
679 if (nxt_slow_path(value == NULL)) {
680 nxt_mp_destroy(mp);
681 status = 500;
682 goto done;
683 }
684
685 if (nxt_slow_path(nxt_conf_validate(value) != NXT_OK)) {
686 status = 400;
687 nxt_str_set(&resp.json,
688 "{ \"error\": \"Invalid configuration.\" }");
689 goto done;
690 }
691
692 nxt_mp_destroy(nxt_controller_conf.pool);
693
694 nxt_controller_conf.root = value;
695 nxt_controller_conf.pool = mp;
696
697 nxt_str_set(&resp.json, "{ \"success\": \"Deleted.\" }");
698
699 status = 200;

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

707 switch (status) {
708
709 case 200:
710 nxt_str_set(&resp.status_line, "200 OK");
711 break;
712
713 case 400:
714 nxt_str_set(&resp.status_line, "400 Bad Request");
715 break;
716
717 case 404:
718 nxt_str_set(&resp.status_line, "404 Not Found");
719 nxt_str_set(&resp.json, "{ \"error\": \"Value doesn't exist.\" }");
720 break;
721
722 case 405:

--- 88 unchanged lines hidden ---