nxt_controller.c (347:e14011f5f005) nxt_controller.c (357:b80698152fcd)
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>

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

26} nxt_controller_request_t;
27
28
29typedef struct {
30 nxt_uint_t status;
31 nxt_conf_value_t *conf;
32
33 u_char *title;
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>

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

26} nxt_controller_request_t;
27
28
29typedef struct {
30 nxt_uint_t status;
31 nxt_conf_value_t *conf;
32
33 u_char *title;
34 u_char *detail;
34 nxt_str_t detail;
35 ssize_t offset;
36 nxt_uint_t line;
37 nxt_uint_t column;
38} nxt_controller_response_t;
39
40
41static void nxt_controller_process_new_port_handler(nxt_task_t *task,
42 nxt_port_recv_msg_t *msg);

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

110 .rpc_error = nxt_port_rpc_handler,
111};
112
113
114nxt_int_t
115nxt_controller_start(nxt_task_t *task, void *data)
116{
117 nxt_mp_t *mp;
35 ssize_t offset;
36 nxt_uint_t line;
37 nxt_uint_t column;
38} nxt_controller_response_t;
39
40
41static void nxt_controller_process_new_port_handler(nxt_task_t *task,
42 nxt_port_recv_msg_t *msg);

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

110 .rpc_error = nxt_port_rpc_handler,
111};
112
113
114nxt_int_t
115nxt_controller_start(nxt_task_t *task, void *data)
116{
117 nxt_mp_t *mp;
118 nxt_int_t ret;
118 nxt_str_t *json;
119 nxt_runtime_t *rt;
120 nxt_conf_value_t *conf;
121 nxt_event_engine_t *engine;
119 nxt_str_t *json;
120 nxt_runtime_t *rt;
121 nxt_conf_value_t *conf;
122 nxt_event_engine_t *engine;
123 nxt_conf_validation_t vldt;
122 nxt_http_fields_hash_t *hash;
123
124 rt = task->thread->runtime;
125
126 engine = task->thread->engine;
127
128 engine->mem_pool = nxt_mp_create(4096, 128, 1024, 64);
129 if (nxt_slow_path(engine->mem_pool == NULL)) {

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

157 nxt_log(task, NXT_LOG_ALERT,
158 "failed to restore previous configuration: "
159 "file is corrupted or not enough memory");
160
161 nxt_mp_destroy(mp);
162 return NXT_OK;
163 }
164
124 nxt_http_fields_hash_t *hash;
125
126 rt = task->thread->runtime;
127
128 engine = task->thread->engine;
129
130 engine->mem_pool = nxt_mp_create(4096, 128, 1024, 64);
131 if (nxt_slow_path(engine->mem_pool == NULL)) {

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

159 nxt_log(task, NXT_LOG_ALERT,
160 "failed to restore previous configuration: "
161 "file is corrupted or not enough memory");
162
163 nxt_mp_destroy(mp);
164 return NXT_OK;
165 }
166
165 if (nxt_slow_path(nxt_conf_validate(conf) != NXT_OK)) {
166 nxt_log(task, NXT_LOG_ALERT,
167 "failed to restore previous configuration: "
168 "invalid configuration");
167 nxt_memzero(&vldt, sizeof(nxt_conf_validation_t));
169
168
170 nxt_mp_destroy(mp);
171 return NXT_OK;
169 vldt.pool = nxt_mp_create(1024, 128, 256, 32);
170 if (nxt_slow_path(vldt.pool == NULL)) {
171 return NXT_ERROR;
172 }
173
172 }
173
174 vldt.conf = conf;
174
175
176 ret = nxt_conf_validate(&vldt);
177
178 if (nxt_slow_path(ret != NXT_OK)) {
179
180 if (ret == NXT_DECLINED) {
181 nxt_log(task, NXT_LOG_ALERT,
182 "the previous configuration is invalid: %V", &vldt.error);
183
184 nxt_mp_destroy(vldt.pool);
185 nxt_mp_destroy(mp);
186
187 return NXT_OK;
188 }
189
190 /* ret == NXT_ERROR */
191
192 return NXT_ERROR;
193 }
194
195 nxt_mp_destroy(vldt.pool);
196
175 nxt_controller_conf.root = conf;
176 nxt_controller_conf.pool = mp;
177
178 return NXT_OK;
179}
180
181
182static void

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

735{
736 nxt_mp_t *mp;
737 nxt_int_t rc;
738 nxt_str_t path;
739 nxt_conn_t *c;
740 nxt_buf_mem_t *mbuf;
741 nxt_conf_op_t *ops;
742 nxt_conf_value_t *value;
197 nxt_controller_conf.root = conf;
198 nxt_controller_conf.pool = mp;
199
200 return NXT_OK;
201}
202
203
204static void

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

757{
758 nxt_mp_t *mp;
759 nxt_int_t rc;
760 nxt_str_t path;
761 nxt_conn_t *c;
762 nxt_buf_mem_t *mbuf;
763 nxt_conf_op_t *ops;
764 nxt_conf_value_t *value;
765 nxt_conf_validation_t vldt;
743 nxt_conf_json_error_t error;
744 nxt_controller_response_t resp;
745
746 static const nxt_str_t empty_obj = nxt_string("{}");
747
748 c = req->conn;
749 path = req->parser.path;
750

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

792 nxt_mp_destroy(mp);
793
794 if (error.pos == NULL) {
795 goto alloc_fail;
796 }
797
798 resp.status = 400;
799 resp.title = (u_char *) "Invalid JSON.";
766 nxt_conf_json_error_t error;
767 nxt_controller_response_t resp;
768
769 static const nxt_str_t empty_obj = nxt_string("{}");
770
771 c = req->conn;
772 path = req->parser.path;
773

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

815 nxt_mp_destroy(mp);
816
817 if (error.pos == NULL) {
818 goto alloc_fail;
819 }
820
821 resp.status = 400;
822 resp.title = (u_char *) "Invalid JSON.";
800 resp.detail = error.detail;
823 resp.detail.length = nxt_strlen(error.detail);
824 resp.detail.start = error.detail;
801 resp.offset = error.pos - mbuf->pos;
802
803 nxt_conf_json_position(mbuf->pos, error.pos,
804 &resp.line, &resp.column);
805
806 nxt_controller_response(task, req, &resp);
807 return;
808 }

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

823 value = nxt_conf_clone(mp, ops, nxt_controller_conf.root);
824
825 if (nxt_slow_path(value == NULL)) {
826 nxt_mp_destroy(mp);
827 goto alloc_fail;
828 }
829 }
830
825 resp.offset = error.pos - mbuf->pos;
826
827 nxt_conf_json_position(mbuf->pos, error.pos,
828 &resp.line, &resp.column);
829
830 nxt_controller_response(task, req, &resp);
831 return;
832 }

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

847 value = nxt_conf_clone(mp, ops, nxt_controller_conf.root);
848
849 if (nxt_slow_path(value == NULL)) {
850 nxt_mp_destroy(mp);
851 goto alloc_fail;
852 }
853 }
854
831 if (nxt_slow_path(nxt_conf_validate(value) != NXT_OK)) {
855 nxt_memzero(&vldt, sizeof(nxt_conf_validation_t));
856
857 vldt.conf = value;
858 vldt.pool = c->mem_pool;
859
860 rc = nxt_conf_validate(&vldt);
861
862 if (nxt_slow_path(rc != NXT_OK)) {
832 nxt_mp_destroy(mp);
863 nxt_mp_destroy(mp);
833 goto invalid_conf;
864
865 if (rc == NXT_DECLINED) {
866 resp.detail = vldt.error;
867 goto invalid_conf;
868 }
869
870 /* rc == NXT_ERROR */
871 goto alloc_fail;
834 }
835
836 rc = nxt_controller_conf_send(task, value,
837 nxt_controller_conf_handler, req);
838
839 if (nxt_slow_path(rc != NXT_OK)) {
840 nxt_mp_destroy(mp);
841

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

893 value = nxt_conf_clone(mp, ops, nxt_controller_conf.root);
894 }
895
896 if (nxt_slow_path(value == NULL)) {
897 nxt_mp_destroy(mp);
898 goto alloc_fail;
899 }
900
872 }
873
874 rc = nxt_controller_conf_send(task, value,
875 nxt_controller_conf_handler, req);
876
877 if (nxt_slow_path(rc != NXT_OK)) {
878 nxt_mp_destroy(mp);
879

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

931 value = nxt_conf_clone(mp, ops, nxt_controller_conf.root);
932 }
933
934 if (nxt_slow_path(value == NULL)) {
935 nxt_mp_destroy(mp);
936 goto alloc_fail;
937 }
938
901 if (nxt_slow_path(nxt_conf_validate(value) != NXT_OK)) {
939 nxt_memzero(&vldt, sizeof(nxt_conf_validation_t));
940
941 vldt.conf = value;
942 vldt.pool = c->mem_pool;
943
944 rc = nxt_conf_validate(&vldt);
945
946 if (nxt_slow_path(rc != NXT_OK)) {
902 nxt_mp_destroy(mp);
947 nxt_mp_destroy(mp);
903 goto invalid_conf;
948
949 if (rc == NXT_DECLINED) {
950 resp.detail = vldt.error;
951 goto invalid_conf;
952 }
953
954 /* rc == NXT_ERROR */
955 goto alloc_fail;
904 }
905
906 rc = nxt_controller_conf_send(task, value,
907 nxt_controller_conf_handler, req);
908
909 if (nxt_slow_path(rc != NXT_OK)) {
910 nxt_mp_destroy(mp);
911

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

1095 break;
1096 }
1097
1098 c = req->conn;
1099 value = resp->conf;
1100
1101 if (value == NULL) {
1102 n = 1
956 }
957
958 rc = nxt_controller_conf_send(task, value,
959 nxt_controller_conf_handler, req);
960
961 if (nxt_slow_path(rc != NXT_OK)) {
962 nxt_mp_destroy(mp);
963

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

1147 break;
1148 }
1149
1150 c = req->conn;
1151 value = resp->conf;
1152
1153 if (value == NULL) {
1154 n = 1
1103 + (resp->detail != NULL)
1155 + (resp->detail.length != 0)
1104 + (resp->status >= 400 && resp->offset != -1);
1105
1106 value = nxt_conf_create_object(c->mem_pool, n);
1107
1108 if (nxt_slow_path(value == NULL)) {
1109 nxt_controller_conn_close(task, c, req);
1110 return;
1111 }

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

1117 nxt_conf_set_member_string(value, &success_str, &str, 0);
1118
1119 } else {
1120 nxt_conf_set_member_string(value, &error_str, &str, 0);
1121 }
1122
1123 n = 0;
1124
1156 + (resp->status >= 400 && resp->offset != -1);
1157
1158 value = nxt_conf_create_object(c->mem_pool, n);
1159
1160 if (nxt_slow_path(value == NULL)) {
1161 nxt_controller_conn_close(task, c, req);
1162 return;
1163 }

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

1169 nxt_conf_set_member_string(value, &success_str, &str, 0);
1170
1171 } else {
1172 nxt_conf_set_member_string(value, &error_str, &str, 0);
1173 }
1174
1175 n = 0;
1176
1125 if (resp->detail != NULL) {
1126 str.length = nxt_strlen(resp->detail);
1127 str.start = resp->detail;
1128
1177 if (resp->detail.length != 0) {
1129 n++;
1130
1178 n++;
1179
1131 nxt_conf_set_member_string(value, &detail_str, &str, n);
1180 nxt_conf_set_member_string(value, &detail_str, &resp->detail, n);
1132 }
1133
1134 if (resp->status >= 400 && resp->offset != -1) {
1135 n++;
1136
1137 location = nxt_conf_create_object(c->mem_pool,
1138 resp->line != 0 ? 3 : 1);
1139

--- 98 unchanged lines hidden ---
1181 }
1182
1183 if (resp->status >= 400 && resp->offset != -1) {
1184 n++;
1185
1186 location = nxt_conf_create_object(c->mem_pool,
1187 resp->line != 0 ? 3 : 1);
1188

--- 98 unchanged lines hidden ---