Deleted
Added
nxt_router.c (1926:6e85d6c0b8bb) | nxt_router.c (1936:953434450ea9) |
---|---|
1 2/* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) Valentin V. Bartenev 5 * Copyright (C) NGINX, Inc. 6 */ 7 8#include <nxt_router.h> --- 93 unchanged lines hidden (view full) --- 102 nxt_router_temp_conf_t *tmcf); 103static void nxt_router_conf_send(nxt_task_t *task, 104 nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type); 105 106static nxt_int_t nxt_router_conf_create(nxt_task_t *task, 107 nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end); 108static nxt_int_t nxt_router_conf_process_static(nxt_task_t *task, 109 nxt_router_conf_t *rtcf, nxt_conf_value_t *conf); | 1 2/* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) Valentin V. Bartenev 5 * Copyright (C) NGINX, Inc. 6 */ 7 8#include <nxt_router.h> --- 93 unchanged lines hidden (view full) --- 102 nxt_router_temp_conf_t *tmcf); 103static void nxt_router_conf_send(nxt_task_t *task, 104 nxt_router_temp_conf_t *tmcf, nxt_port_msg_type_t type); 105 106static nxt_int_t nxt_router_conf_create(nxt_task_t *task, 107 nxt_router_temp_conf_t *tmcf, u_char *start, u_char *end); 108static nxt_int_t nxt_router_conf_process_static(nxt_task_t *task, 109 nxt_router_conf_t *rtcf, nxt_conf_value_t *conf); |
110static nxt_int_t nxt_router_conf_process_client_ip(nxt_task_t *task, 111 nxt_router_temp_conf_t *tmcf, nxt_socket_conf_t *skcf, 112 nxt_conf_value_t *conf); |
|
110 111static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name); 112static nxt_int_t nxt_router_apps_hash_test(nxt_lvlhsh_query_t *lhq, void *data); 113static nxt_int_t nxt_router_apps_hash_add(nxt_router_conf_t *rtcf, 114 nxt_app_t *app); 115static nxt_app_t *nxt_router_apps_hash_get(nxt_router_conf_t *rtcf, 116 nxt_str_t *name); 117static void nxt_router_apps_hash_use(nxt_task_t *task, nxt_router_conf_t *rtcf, --- 1327 unchanged lines hidden (view full) --- 1445 nxt_app_joint_t *app_joint; 1446#if (NXT_TLS) 1447 nxt_tls_init_t *tls_init; 1448 nxt_conf_value_t *certificate; 1449#endif 1450 nxt_conf_value_t *conf, *http, *value, *websocket; 1451 nxt_conf_value_t *applications, *application; 1452 nxt_conf_value_t *listeners, *listener; | 113 114static nxt_app_t *nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name); 115static nxt_int_t nxt_router_apps_hash_test(nxt_lvlhsh_query_t *lhq, void *data); 116static nxt_int_t nxt_router_apps_hash_add(nxt_router_conf_t *rtcf, 117 nxt_app_t *app); 118static nxt_app_t *nxt_router_apps_hash_get(nxt_router_conf_t *rtcf, 119 nxt_str_t *name); 120static void nxt_router_apps_hash_use(nxt_task_t *task, nxt_router_conf_t *rtcf, --- 1327 unchanged lines hidden (view full) --- 1448 nxt_app_joint_t *app_joint; 1449#if (NXT_TLS) 1450 nxt_tls_init_t *tls_init; 1451 nxt_conf_value_t *certificate; 1452#endif 1453 nxt_conf_value_t *conf, *http, *value, *websocket; 1454 nxt_conf_value_t *applications, *application; 1455 nxt_conf_value_t *listeners, *listener; |
1453 nxt_conf_value_t *routes_conf, *static_conf; | 1456 nxt_conf_value_t *routes_conf, *static_conf, *client_ip_conf; |
1454 nxt_socket_conf_t *skcf; 1455 nxt_http_routes_t *routes; 1456 nxt_event_engine_t *engine; 1457 nxt_app_lang_module_t *lang; 1458 nxt_router_app_conf_t apcf; 1459 nxt_router_access_log_t *access_log; 1460 nxt_router_listener_conf_t lscf; 1461 --- 5 unchanged lines hidden (view full) --- 1467#if (NXT_TLS) 1468 static nxt_str_t certificate_path = nxt_string("/tls/certificate"); 1469 static nxt_str_t conf_commands_path = nxt_string("/tls/conf_commands"); 1470 static nxt_str_t conf_cache_path = nxt_string("/tls/session/cache_size"); 1471 static nxt_str_t conf_timeout_path = nxt_string("/tls/session/timeout"); 1472#endif 1473 static nxt_str_t static_path = nxt_string("/settings/http/static"); 1474 static nxt_str_t websocket_path = nxt_string("/settings/http/websocket"); | 1457 nxt_socket_conf_t *skcf; 1458 nxt_http_routes_t *routes; 1459 nxt_event_engine_t *engine; 1460 nxt_app_lang_module_t *lang; 1461 nxt_router_app_conf_t apcf; 1462 nxt_router_access_log_t *access_log; 1463 nxt_router_listener_conf_t lscf; 1464 --- 5 unchanged lines hidden (view full) --- 1470#if (NXT_TLS) 1471 static nxt_str_t certificate_path = nxt_string("/tls/certificate"); 1472 static nxt_str_t conf_commands_path = nxt_string("/tls/conf_commands"); 1473 static nxt_str_t conf_cache_path = nxt_string("/tls/session/cache_size"); 1474 static nxt_str_t conf_timeout_path = nxt_string("/tls/session/timeout"); 1475#endif 1476 static nxt_str_t static_path = nxt_string("/settings/http/static"); 1477 static nxt_str_t websocket_path = nxt_string("/settings/http/websocket"); |
1478 static nxt_str_t client_ip_path = nxt_string("/client_ip"); |
|
1475 1476 conf = nxt_conf_json_parse(tmcf->mem_pool, start, end, NULL); 1477 if (conf == NULL) { 1478 nxt_alert(task, "configuration parsing error"); 1479 return NXT_ERROR; 1480 } 1481 1482 mp = tmcf->router_conf->mem_pool; --- 355 unchanged lines hidden (view full) --- 1838 1839 t = &skcf->body_temp_path; 1840 1841 if (t->length == 0) { 1842 t->start = (u_char *) task->thread->runtime->tmp; 1843 t->length = nxt_strlen(t->start); 1844 } 1845 | 1479 1480 conf = nxt_conf_json_parse(tmcf->mem_pool, start, end, NULL); 1481 if (conf == NULL) { 1482 nxt_alert(task, "configuration parsing error"); 1483 return NXT_ERROR; 1484 } 1485 1486 mp = tmcf->router_conf->mem_pool; --- 355 unchanged lines hidden (view full) --- 1842 1843 t = &skcf->body_temp_path; 1844 1845 if (t->length == 0) { 1846 t->start = (u_char *) task->thread->runtime->tmp; 1847 t->length = nxt_strlen(t->start); 1848 } 1849 |
1850 client_ip_conf = nxt_conf_get_path(listener, &client_ip_path); 1851 ret = nxt_router_conf_process_client_ip(task, tmcf, skcf, 1852 client_ip_conf); 1853 if (nxt_slow_path(ret != NXT_OK)) { 1854 return NXT_ERROR; 1855 } 1856 |
|
1846#if (NXT_TLS) 1847 certificate = nxt_conf_get_path(listener, &certificate_path); 1848 1849 if (certificate != NULL) { 1850 tls_init = nxt_mp_get(tmcf->mem_pool, sizeof(nxt_tls_init_t)); 1851 if (nxt_slow_path(tls_init == NULL)) { 1852 return NXT_ERROR; 1853 } --- 226 unchanged lines hidden (view full) --- 2080 } 2081 } 2082 } 2083 2084 return NXT_OK; 2085} 2086 2087 | 1857#if (NXT_TLS) 1858 certificate = nxt_conf_get_path(listener, &certificate_path); 1859 1860 if (certificate != NULL) { 1861 tls_init = nxt_mp_get(tmcf->mem_pool, sizeof(nxt_tls_init_t)); 1862 if (nxt_slow_path(tls_init == NULL)) { 1863 return NXT_ERROR; 1864 } --- 226 unchanged lines hidden (view full) --- 2091 } 2092 } 2093 } 2094 2095 return NXT_OK; 2096} 2097 2098 |
2099static nxt_int_t 2100nxt_router_conf_process_client_ip(nxt_task_t *task, nxt_router_temp_conf_t *tmcf, 2101 nxt_socket_conf_t *skcf, nxt_conf_value_t *conf) 2102{ 2103 char c; 2104 size_t i; 2105 nxt_mp_t *mp; 2106 uint32_t hash; 2107 nxt_str_t header; 2108 nxt_conf_value_t *source_conf, *header_conf, *recursive_conf; 2109 nxt_http_client_ip_t *client_ip; 2110 nxt_http_route_addr_rule_t *source; 2111 2112 static nxt_str_t header_path = nxt_string("/header"); 2113 static nxt_str_t source_path = nxt_string("/source"); 2114 static nxt_str_t recursive_path = nxt_string("/recursive"); 2115 2116 if (conf == NULL) { 2117 skcf->client_ip = NULL; 2118 2119 return NXT_OK; 2120 } 2121 2122 mp = tmcf->router_conf->mem_pool; 2123 2124 source_conf = nxt_conf_get_path(conf, &source_path); 2125 header_conf = nxt_conf_get_path(conf, &header_path); 2126 recursive_conf = nxt_conf_get_path(conf, &recursive_path); 2127 2128 if (source_conf == NULL || header_conf == NULL) { 2129 return NXT_ERROR; 2130 } 2131 2132 client_ip = nxt_mp_zget(mp, sizeof(nxt_http_client_ip_t)); 2133 if (nxt_slow_path(client_ip == NULL)) { 2134 return NXT_ERROR; 2135 } 2136 2137 source = nxt_http_route_addr_rule_create(task, mp, source_conf); 2138 if (nxt_slow_path(source == NULL)) { 2139 return NXT_ERROR; 2140 } 2141 2142 client_ip->source = source; 2143 2144 nxt_conf_get_string(header_conf, &header); 2145 2146 if (recursive_conf != NULL) { 2147 client_ip->recursive = nxt_conf_get_boolean(recursive_conf); 2148 } 2149 2150 client_ip->header = nxt_str_dup(mp, NULL, &header); 2151 if (nxt_slow_path(client_ip->header == NULL)) { 2152 return NXT_ERROR; 2153 } 2154 2155 hash = NXT_HTTP_FIELD_HASH_INIT; 2156 2157 for (i = 0; i < client_ip->header->length; i++) { 2158 c = client_ip->header->start[i]; 2159 hash = nxt_http_field_hash_char(hash, nxt_lowcase(c)); 2160 } 2161 2162 hash = nxt_http_field_hash_end(hash) & 0xFFFF; 2163 2164 client_ip->header_hash = hash; 2165 2166 skcf->client_ip = client_ip; 2167 2168 return NXT_OK; 2169} 2170 2171 |
|
2088static nxt_app_t * 2089nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name) 2090{ 2091 nxt_app_t *app; 2092 2093 nxt_queue_each(app, queue, nxt_app_t, link) { 2094 2095 if (nxt_strstr_eq(name, &app->name)) { --- 3710 unchanged lines hidden --- | 2172static nxt_app_t * 2173nxt_router_app_find(nxt_queue_t *queue, nxt_str_t *name) 2174{ 2175 nxt_app_t *app; 2176 2177 nxt_queue_each(app, queue, nxt_app_t, link) { 2178 2179 if (nxt_strstr_eq(name, &app->name)) { --- 3710 unchanged lines hidden --- |