1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505
|
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/***************************************************************************
* Description: Utility functions (mainly configuration) *
* Author: Gal Shachor <shachor@il.ibm.com> *
* Author: Henri Gomez <hgomez@apache.org> *
* Author: Rainer Jung <rjung@apache.org> *
***************************************************************************/
#include "jk_util.h"
#include "jk_ajp12_worker.h"
#include "jk_ajp13_worker.h"
#include "jk_ajp14_worker.h"
#include "jk_lb_worker.h"
#include "jk_mt.h"
#define SYSPROPS_OF_WORKER "sysprops"
#define STDERR_OF_WORKER "stderr"
#define STDOUT_OF_WORKER "stdout"
#define SECRET_OF_WORKER "secret"
#define MX_OF_WORKER "mx"
#define MS_OF_WORKER "ms"
#define CP_OF_WORKER "class_path"
#define BRIDGE_OF_WORKER "bridge"
#define JVM_OF_WORKER "jvm_lib"
#define LIBPATH_OF_WORKER "ld_path"
#define CMD_LINE_OF_WORKER "cmd_line"
#define NATIVE_LIB_OF_WORKER "native_lib"
#define REFERENCE_OF_WORKER "reference"
#define HOST_OF_WORKER "host"
#define SOURCE_OF_WORKER "source"
#define PORT_OF_WORKER "port"
#define TYPE_OF_WORKER "type"
#define CACHE_OF_WORKER_DEPRECATED "cachesize"
#define CACHE_OF_WORKER "connection_pool_size"
#define CACHE_OF_WORKER_MIN "connection_pool_minsize"
#define CACHE_TIMEOUT_DEPRECATED "cache_timeout"
#define CACHE_TIMEOUT_OF_WORKER "connection_pool_timeout"
#define CACHE_ACQUIRE_OF_WORKER "connection_acquire_timeout"
#define RECOVERY_OPTS_OF_WORKER "recovery_options"
#define CONNECT_TIMEOUT_OF_WORKER "connect_timeout"
#define PREPOST_TIMEOUT_OF_WORKER "prepost_timeout"
#define REPLY_TIMEOUT_OF_WORKER "reply_timeout"
#define SOCKET_TIMEOUT_OF_WORKER "socket_timeout"
#define SOCKET_CONNECT_TIMEOUT_OF_WORKER "socket_connect_timeout"
#define PING_TIMEOUT_OF_WORKER "ping_timeout"
#define PING_MODE_OF_WORKER "ping_mode"
#define SOCKET_BUFFER_OF_WORKER "socket_buffer"
#define SOCKET_KEEPALIVE_OF_WORKER "socket_keepalive"
#define CONN_PING_INTERVAL_OF_WORKER "connection_ping_interval"
#define RECYCLE_TIMEOUT_DEPRECATED "recycle_timeout"
#define LOAD_FACTOR_OF_WORKER "lbfactor"
#define DISTANCE_OF_WORKER "distance"
#define BALANCED_WORKERS_DEPRECATED "balanced_workers"
#define BALANCE_WORKERS "balance_workers"
#define STICKY_SESSION "sticky_session"
#define STICKY_SESSION_FORCE "sticky_session_force"
#define SESSION_COOKIE_OF_WORKER "session_cookie"
#define SESSION_PATH_OF_WORKER "session_path"
#define SET_SESSION_COOKIE "set_session_cookie"
#define SESSION_COOKIE_PATH_OF_WORKER "session_cookie_path"
#define LOCAL_WORKER_DEPRECATED "local_worker"
#define LOCAL_WORKER_ONLY_DEPRECATED "local_worker_only"
#define JVM_ROUTE_OF_WORKER_DEPRECATED "jvm_route"
#define ROUTE_OF_WORKER "route"
#define DOMAIN_OF_WORKER "domain"
#define REDIRECT_OF_WORKER "redirect"
#define MOUNT_OF_WORKER "mount"
#define METHOD_OF_WORKER "method"
#define LOCK_OF_WORKER "lock"
#define IS_WORKER_DISABLED_DEPRECATED "disabled"
#define IS_WORKER_STOPPED_DEPRECATED "stopped"
#define ACTIVATION_OF_WORKER "activation"
#define WORKER_RECOVER_TIME "recover_time"
#define WORKER_ERROR_ESCALATION_TIME "error_escalation_time"
#define MAX_REPLY_TIMEOUTS_OF_WORKER "max_reply_timeouts"
#define RETRY_INTERVAL_OF_WORKER "retry_interval"
#define BUSY_LIMIT_OF_WORKER "busy_limit"
#define WORKER_MAX_PACKET_SIZE "max_packet_size"
#define STYLE_SHEET_OF_WORKER "css"
#define NAMESPACE_OF_WORKER "ns"
#define XML_NAMESPACE_OF_WORKER "xmlns"
#define XML_DOCTYPE_OF_WORKER "doctype"
#define PROP_PREFIX_OF_WORKER "prefix"
#define READ_ONLY_OF_WORKER "read_only"
#define USER_OF_WORKER "user"
#define USER_CASE_OF_WORKER "user_case_insensitive"
#define GOOD_RATING_OF_WORKER "good"
#define BAD_RATING_OF_WORKER "bad"
#define PREFER_IPV6_ADDRESS "prefer_ipv6"
#define DEFAULT_WORKER_TYPE JK_AJP13_WORKER_NAME
#define SECRET_KEY_OF_WORKER "secretkey"
#define RETRIES_OF_WORKER "retries"
#define LB_RETRIES_OF_WORKER "lb_retries"
#define STATUS_FAIL_OF_WORKER "fail_on_status"
#define DEFAULT_WORKER JK_AJP13_WORKER_NAME
#define WORKER_LIST_PROPERTY_NAME "worker.list"
#define LIST_PROPERTY_NAME "list"
#define WORKER_MAINTAIN_PROPERTY_NAME "worker.maintain"
#define MAINTAIN_PROPERTY_NAME "maintain"
#define DEFAULT_MAINTAIN_TIME 60
#define DEFAULT_LB_FACTOR 1
#define DEFAULT_DISTANCE 0
#define TOMCAT32_BRIDGE_NAME "tomcat32"
#define TOMCAT33_BRIDGE_NAME "tomcat33"
#define TOMCAT40_BRIDGE_NAME "tomcat40"
#define TOMCAT41_BRIDGE_NAME "tomcat41"
#define TOMCAT50_BRIDGE_NAME "tomcat5"
#define LOG_BUFFER_SIZE 1024
/*
* Our longest worker attribute name is below 30 bytes.
* Add space for "worker.", another ".", the
* worker name and the final '\0'.
*/
#define JK_MAX_ATTRIBUTE_NAME_LEN (30)
#define PARAM_BUFFER_SIZE (JK_MAX_NAME_LEN + 8 + JK_MAX_ATTRIBUTE_NAME_LEN + 1)
#define MAKE_WORKER_PARAM(P) \
{ \
size_t remain = PARAM_BUFFER_SIZE; \
strcpy(buf, "worker."); remain -= strlen("worker."); \
strncat(buf, wname, remain); remain -= strlen(wname); \
strncat(buf, ".", remain); remain -= 1; \
strncat(buf, P, remain); \
}
/*
* define the log format, we're using by default the one from error.log
*
* [Mon Mar 26 19:44:48.123 2001] [jk_uri_worker_map.c (155)]: Into jk_uri_worker_map_t::uri_worker_map_alloc
* log format used by apache in error.log
*/
#define JK_TIME_CONV_MILLI "%Q"
#define JK_TIME_CONV_MICRO "%q"
#define JK_TIME_PATTERN_MILLI "000"
#define JK_TIME_PATTERN_MICRO "000000"
#define JK_TIME_FORMAT_NONE "[%a %b %d %H:%M:%S %Y] "
#define JK_TIME_FORMAT_MILLI "[%a %b %d %H:%M:%S." JK_TIME_CONV_MILLI " %Y] "
#define JK_TIME_FORMAT_MICRO "[%a %b %d %H:%M:%S." JK_TIME_CONV_MICRO " %Y] "
#define JK_TIME_SUBSEC_NONE 0
#define JK_TIME_SUBSEC_MILLI 1
#define JK_TIME_SUBSEC_MICRO 2
/* Visual C++ Toolkit 2003 support */
#if defined (_MSC_VER) && (_MSC_VER == 1310)
extern long _ftol(double); /* defined by VC6 C libs */
extern long _ftol2(double dblSource) { return _ftol(dblSource); }
#endif
static const char *list_properties[] = {
BALANCE_WORKERS,
MOUNT_OF_WORKER,
USER_OF_WORKER,
GOOD_RATING_OF_WORKER,
BAD_RATING_OF_WORKER,
STATUS_FAIL_OF_WORKER,
LIST_PROPERTY_NAME,
NULL
};
static const char *unique_properties[] = {
SECRET_OF_WORKER,
REFERENCE_OF_WORKER,
HOST_OF_WORKER,
SOURCE_OF_WORKER,
PORT_OF_WORKER,
TYPE_OF_WORKER,
CACHE_OF_WORKER_DEPRECATED,
CACHE_OF_WORKER,
CACHE_OF_WORKER_MIN,
CACHE_TIMEOUT_DEPRECATED,
CACHE_TIMEOUT_OF_WORKER,
CACHE_ACQUIRE_OF_WORKER,
RECOVERY_OPTS_OF_WORKER,
CONNECT_TIMEOUT_OF_WORKER,
PREPOST_TIMEOUT_OF_WORKER,
PING_TIMEOUT_OF_WORKER,
PING_MODE_OF_WORKER,
REPLY_TIMEOUT_OF_WORKER,
SOCKET_TIMEOUT_OF_WORKER,
SOCKET_CONNECT_TIMEOUT_OF_WORKER,
SOCKET_BUFFER_OF_WORKER,
SOCKET_KEEPALIVE_OF_WORKER,
CONN_PING_INTERVAL_OF_WORKER,
RECYCLE_TIMEOUT_DEPRECATED,
LOAD_FACTOR_OF_WORKER,
STICKY_SESSION,
STICKY_SESSION_FORCE,
SESSION_COOKIE_OF_WORKER,
SESSION_PATH_OF_WORKER,
SET_SESSION_COOKIE,
SESSION_COOKIE_PATH_OF_WORKER,
LOCAL_WORKER_DEPRECATED,
LOCAL_WORKER_ONLY_DEPRECATED,
JVM_ROUTE_OF_WORKER_DEPRECATED,
ROUTE_OF_WORKER,
DOMAIN_OF_WORKER,
REDIRECT_OF_WORKER,
METHOD_OF_WORKER,
LOCK_OF_WORKER,
IS_WORKER_DISABLED_DEPRECATED,
IS_WORKER_STOPPED_DEPRECATED,
ACTIVATION_OF_WORKER,
WORKER_RECOVER_TIME,
WORKER_ERROR_ESCALATION_TIME,
MAX_REPLY_TIMEOUTS_OF_WORKER,
RETRY_INTERVAL_OF_WORKER,
BUSY_LIMIT_OF_WORKER,
WORKER_MAX_PACKET_SIZE,
STYLE_SHEET_OF_WORKER,
READ_ONLY_OF_WORKER,
RETRIES_OF_WORKER,
LB_RETRIES_OF_WORKER,
WORKER_MAINTAIN_PROPERTY_NAME,
NAMESPACE_OF_WORKER,
XML_NAMESPACE_OF_WORKER,
XML_DOCTYPE_OF_WORKER,
PROP_PREFIX_OF_WORKER,
USER_CASE_OF_WORKER,
PREFER_IPV6_ADDRESS,
NULL
};
static const char *deprecated_properties[] = {
SYSPROPS_OF_WORKER,
STDERR_OF_WORKER,
STDOUT_OF_WORKER,
MX_OF_WORKER,
MS_OF_WORKER,
CP_OF_WORKER,
BRIDGE_OF_WORKER,
JVM_OF_WORKER,
LIBPATH_OF_WORKER,
CMD_LINE_OF_WORKER,
NATIVE_LIB_OF_WORKER,
CACHE_OF_WORKER_DEPRECATED,
CACHE_TIMEOUT_DEPRECATED,
RECYCLE_TIMEOUT_DEPRECATED,
BALANCED_WORKERS_DEPRECATED,
JVM_ROUTE_OF_WORKER_DEPRECATED,
LOCAL_WORKER_DEPRECATED,
LOCAL_WORKER_ONLY_DEPRECATED,
IS_WORKER_DISABLED_DEPRECATED,
IS_WORKER_STOPPED_DEPRECATED,
NULL
};
static const char *supported_properties[] = {
SYSPROPS_OF_WORKER,
STDERR_OF_WORKER,
STDOUT_OF_WORKER,
SECRET_OF_WORKER,
MX_OF_WORKER,
MS_OF_WORKER,
CP_OF_WORKER,
BRIDGE_OF_WORKER,
JVM_OF_WORKER,
LIBPATH_OF_WORKER,
CMD_LINE_OF_WORKER,
NATIVE_LIB_OF_WORKER,
REFERENCE_OF_WORKER,
HOST_OF_WORKER,
SOURCE_OF_WORKER,
PORT_OF_WORKER,
TYPE_OF_WORKER,
CACHE_OF_WORKER_DEPRECATED,
CACHE_OF_WORKER,
CACHE_OF_WORKER_MIN,
CACHE_TIMEOUT_DEPRECATED,
CACHE_TIMEOUT_OF_WORKER,
CACHE_ACQUIRE_OF_WORKER,
RECOVERY_OPTS_OF_WORKER,
CONNECT_TIMEOUT_OF_WORKER,
PREPOST_TIMEOUT_OF_WORKER,
PING_TIMEOUT_OF_WORKER,
PING_MODE_OF_WORKER,
REPLY_TIMEOUT_OF_WORKER,
SOCKET_TIMEOUT_OF_WORKER,
SOCKET_CONNECT_TIMEOUT_OF_WORKER,
SOCKET_BUFFER_OF_WORKER,
SOCKET_KEEPALIVE_OF_WORKER,
CONN_PING_INTERVAL_OF_WORKER,
RECYCLE_TIMEOUT_DEPRECATED,
LOAD_FACTOR_OF_WORKER,
DISTANCE_OF_WORKER,
BALANCED_WORKERS_DEPRECATED,
BALANCE_WORKERS,
STICKY_SESSION,
STICKY_SESSION_FORCE,
SESSION_COOKIE_OF_WORKER,
SESSION_PATH_OF_WORKER,
SET_SESSION_COOKIE,
SESSION_COOKIE_PATH_OF_WORKER,
LOCAL_WORKER_DEPRECATED,
LOCAL_WORKER_ONLY_DEPRECATED,
JVM_ROUTE_OF_WORKER_DEPRECATED,
ROUTE_OF_WORKER,
DOMAIN_OF_WORKER,
REDIRECT_OF_WORKER,
MOUNT_OF_WORKER,
METHOD_OF_WORKER,
LOCK_OF_WORKER,
IS_WORKER_DISABLED_DEPRECATED,
IS_WORKER_STOPPED_DEPRECATED,
ACTIVATION_OF_WORKER,
WORKER_RECOVER_TIME,
WORKER_ERROR_ESCALATION_TIME,
MAX_REPLY_TIMEOUTS_OF_WORKER,
RETRY_INTERVAL_OF_WORKER,
BUSY_LIMIT_OF_WORKER,
WORKER_MAX_PACKET_SIZE,
STYLE_SHEET_OF_WORKER,
NAMESPACE_OF_WORKER,
XML_NAMESPACE_OF_WORKER,
XML_DOCTYPE_OF_WORKER,
PROP_PREFIX_OF_WORKER,
READ_ONLY_OF_WORKER,
USER_OF_WORKER,
USER_CASE_OF_WORKER,
GOOD_RATING_OF_WORKER,
BAD_RATING_OF_WORKER,
SECRET_KEY_OF_WORKER,
RETRIES_OF_WORKER,
LB_RETRIES_OF_WORKER,
STATUS_FAIL_OF_WORKER,
LIST_PROPERTY_NAME,
MAINTAIN_PROPERTY_NAME,
PREFER_IPV6_ADDRESS,
NULL
};
static const char *jk_level_verbs[] = {
"[" JK_LOG_TRACE_VERB "] ",
"[" JK_LOG_DEBUG_VERB "] ",
"[" JK_LOG_INFO_VERB "] ",
"[" JK_LOG_WARN_VERB "] ",
"[" JK_LOG_ERROR_VERB "] ",
"[" JK_LOG_EMERG_VERB "] ",
NULL
};
const char *jk_get_bool(int v)
{
if (v == 0)
return "False";
else
return "True";
}
int jk_get_bool_code(const char *v, int def)
{
if (!v) {
return def;
}
if (!strcasecmp(v, "off") ||
*v == 'F' || *v == 'f' ||
*v == 'N' || *v == 'n' ||
(*v == '0' && *(v + 1) == '\0')) {
return JK_FALSE;
}
if (!strcasecmp(v, "on") ||
*v == 'T' || *v == 't' ||
*v == 'Y' || *v == 'y' ||
(*v == '1' && *(v + 1) == '\0')) {
return JK_TRUE;
}
return def;
}
/* Sleep for 100ms */
void jk_sleep(int ms)
{
#ifdef OS2
DosSleep(ms);
#elif defined(BEOS)
snooze(ms * 1000);
#elif defined(WIN32)
Sleep(ms);
#else
struct timeval tv;
tv.tv_usec = (ms % 1000) * 1000;
tv.tv_sec = ms / 1000;
select(0, NULL, NULL, NULL, &tv);
#endif
}
/* Replace the first occurence of a sub second time format character
* by a series of zero digits with the right precision.
* We format our timestamp with strftime, but this can not handle
* sub second timestamps.
* So we first patch the milliseconds or microseconds literally into
* the format string, and then pass it on the strftime.
* In order to do that efficiently, we prepare a format string, that
* already has placeholder digits for the sub second time stamp
* and we save the position and time precision of this placeholder.
*/
void jk_set_time_fmt(jk_logger_t *l, const char *jk_log_fmt)
{
if (l) {
char *s;
if (!jk_log_fmt) {
#ifndef NO_GETTIMEOFDAY
jk_log_fmt = JK_TIME_FORMAT_MILLI;
#else
jk_log_fmt = JK_TIME_FORMAT_NONE;
#endif
}
l->log_fmt_type = JK_TIME_SUBSEC_NONE;
l->log_fmt_offset = 0;
l->log_fmt_size = 0;
l->log_fmt = jk_log_fmt;
/* Look for the first occurence of JK_TIME_CONV_MILLI */
if ((s = strstr(jk_log_fmt, JK_TIME_CONV_MILLI))) {
size_t offset = s - jk_log_fmt;
size_t len = strlen(JK_TIME_PATTERN_MILLI);
/* If we don't have enough space in our fixed-length char array,
* we simply stick to the default format, ignoring JK_TIME_CONV_MILLI.
* Otherwise we replace the first occurence of
* JK_TIME_CONV_MILLI by JK_TIME_PATTERN_MILLI.
*/
if (offset + len < JK_TIME_MAX_SIZE) {
l->log_fmt_type = JK_TIME_SUBSEC_MILLI;
l->log_fmt_offset = offset;
strncpy(l->log_fmt_subsec, jk_log_fmt, offset);
strncpy(l->log_fmt_subsec + offset, JK_TIME_PATTERN_MILLI, len);
strncpy(l->log_fmt_subsec + offset + len,
s + strlen(JK_TIME_CONV_MILLI),
JK_TIME_MAX_SIZE - offset - len - 1);
/* Now we put a stop mark into the string to make it's length
* at most JK_TIME_MAX_SIZE-1 plus terminating '\0'.
*/
l->log_fmt_subsec[JK_TIME_MAX_SIZE-1] = '\0';
l->log_fmt_size = strlen(l->log_fmt_subsec);
}
/* Look for the first occurence of JK_TIME_CONV_MICRO */
}
else if ((s = strstr(jk_log_fmt, JK_TIME_CONV_MICRO))) {
size_t offset = s - jk_log_fmt;
size_t len = strlen(JK_TIME_PATTERN_MICRO);
/* If we don't have enough space in our fixed-length char array,
* we simply stick to the default format, ignoring JK_TIME_CONV_MICRO.
* Otherwise we replace the first occurence of JK_TIME_CONV_MICRO
* by JK_TIME_PATTERN_MICRO.
*/
if (offset + len < JK_TIME_MAX_SIZE) {
l->log_fmt_type = JK_TIME_SUBSEC_MICRO;
l->log_fmt_offset = offset;
strncpy(l->log_fmt_subsec, jk_log_fmt, offset);
strncpy(l->log_fmt_subsec + offset, JK_TIME_PATTERN_MICRO, len);
strncpy(l->log_fmt_subsec + offset + len,
s + strlen(JK_TIME_CONV_MICRO),
JK_TIME_MAX_SIZE - offset - len - 1);
/* Now we put a stop mark into the string to make it's length
* at most JK_TIME_MAX_SIZE-1 plus terminating '\0'.
*/
l->log_fmt_subsec[JK_TIME_MAX_SIZE-1] = '\0';
l->log_fmt_size = strlen(l->log_fmt_subsec);
}
}
jk_log(l, JK_LOG_DEBUG, "Pre-processed log time stamp format is '%s'",
l->log_fmt_type == JK_TIME_SUBSEC_NONE ? l->log_fmt : l->log_fmt_subsec);
}
}
static int set_time_str(char *str, int len, jk_logger_t *l)
{
time_t t;
struct tm *tms;
#ifdef _MT_CODE_PTHREAD
struct tm res;
#endif
int done;
/* We want to use a fixed maximum size buffer here.
* If we would dynamically adjust it to the real format
* string length, we could support longer format strings,
* but we would have to allocate and free for each log line.
*/
char log_fmt[JK_TIME_MAX_SIZE];
if (!l || !l->log_fmt) {
return 0;
}
log_fmt[0] = '\0';
#ifndef NO_GETTIMEOFDAY
if ( l->log_fmt_type != JK_TIME_SUBSEC_NONE ) {
struct timeval tv;
int rc = 0;
#ifdef WIN32
gettimeofday(&tv, NULL);
#else
rc = gettimeofday(&tv, NULL);
#endif
if (rc == 0) {
/* We need this subsec buffer, because we convert
* the integer with sprintf(), but we don't
* want to write the terminating '\0' into our
* final log format string.
*/
char subsec[7];
t = tv.tv_sec;
strncpy(log_fmt, l->log_fmt_subsec, l->log_fmt_size + 1);
if (l->log_fmt_type == JK_TIME_SUBSEC_MILLI) {
sprintf(subsec, "%03d", (int)(tv.tv_usec/1000));
strncpy(log_fmt + l->log_fmt_offset, subsec, 3);
}
else if (l->log_fmt_type == JK_TIME_SUBSEC_MICRO) {
sprintf(subsec, "%06d", (int)(tv.tv_usec));
strncpy(log_fmt + l->log_fmt_offset, subsec, 6);
}
}
else {
t = time(NULL);
}
}
else {
t = time(NULL);
}
#else
t = time(NULL);
#endif
#ifdef _MT_CODE_PTHREAD
tms = localtime_r(&t, &res);
#else
tms = localtime(&t);
#endif
if (log_fmt[0])
done = (int)strftime(str, len, log_fmt, tms);
else
done = (int)strftime(str, len, l->log_fmt, tms);
return done;
}
static int JK_METHOD log_to_file(jk_logger_t *l, int level, int used, char *what)
{
if (l &&
(l->level <= level || level == JK_LOG_REQUEST_LEVEL) &&
l->logger_private && what) {
jk_file_logger_t *p = l->logger_private;
if (p->logfile) {
what[used++] = '\n';
what[used] = '\0';
#if defined(JK_LOG_LOCKING)
#if defined(WIN32) && defined(_MSC_VER)
LockFile((HANDLE)_get_osfhandle(_fileno(p->logfile)),
0, 0, 1, 0);
#endif
#endif
fputs(what, p->logfile);
/* [V] Flush the dam' thing! */
fflush(p->logfile);
#if defined(JK_LOG_LOCKING)
#if defined(WIN32) && defined(_MSC_VER)
UnlockFile((HANDLE)_get_osfhandle(_fileno(p->logfile)),
0, 0, 1, 0);
#endif
#endif
}
return JK_TRUE;
}
return JK_FALSE;
}
int jk_parse_log_level(const char *level)
{
if (!strcasecmp(level, JK_LOG_TRACE_VERB))
return JK_LOG_TRACE_LEVEL;
if (!strcasecmp(level, JK_LOG_DEBUG_VERB))
return JK_LOG_DEBUG_LEVEL;
if (!strcasecmp(level, JK_LOG_INFO_VERB))
return JK_LOG_INFO_LEVEL;
if (!strcasecmp(level, JK_LOG_WARN_VERB))
return JK_LOG_WARNING_LEVEL;
if (!strcasecmp(level, JK_LOG_ERROR_VERB))
return JK_LOG_ERROR_LEVEL;
if (!strcasecmp(level, JK_LOG_EMERG_VERB))
return JK_LOG_EMERG_LEVEL;
return JK_LOG_DEF_LEVEL;
}
int jk_open_file_logger(jk_logger_t **l, const char *file, int level)
{
if (l && file) {
jk_logger_t *rc = (jk_logger_t *)malloc(sizeof(jk_logger_t));
jk_file_logger_t *p = (jk_file_logger_t *) malloc(sizeof(jk_file_logger_t));
if (rc && p) {
rc->log = log_to_file;
rc->level = level;
rc->logger_private = p;
#if defined(AS400) && !defined(AS400_UTF8)
p->logfile = fopen(file, "a+, o_ccsid=0");
#elif defined(WIN32) && defined(_MSC_VER)
p->logfile = fopen(file, "a+c");
#else
p->logfile = fopen(file, "a+");
#endif
if (p->logfile) {
*l = rc;
jk_set_time_fmt(rc, NULL);
return JK_TRUE;
}
}
if (rc) {
free(rc);
}
if (p) {
free(p);
}
*l = NULL;
}
return JK_FALSE;
}
int jk_attach_file_logger(jk_logger_t **l, int fd, int level)
{
if (l && fd >= 0) {
jk_logger_t *rc = (jk_logger_t *)malloc(sizeof(jk_logger_t));
jk_file_logger_t *p = (jk_file_logger_t *) malloc(sizeof(jk_file_logger_t));
if (rc && p) {
rc->log = log_to_file;
rc->level = level;
rc->logger_private = p;
#if defined(AS400) && !defined(AS400_UTF8)
p->logfile = fdopen(fd, "a+, o_ccsid=0");
#elif defined(WIN32) && defined(_MSC_VER)
p->logfile = fdopen(fd, "a+c");
#else
p->logfile = fdopen(fd, "a+");
#endif
if (p->logfile) {
*l = rc;
jk_set_time_fmt(rc, NULL);
return JK_TRUE;
}
}
if (rc) {
free(rc);
}
if (p) {
free(p);
}
*l = NULL;
}
return JK_FALSE;
}
int jk_close_file_logger(jk_logger_t **l)
{
if (l && *l) {
jk_file_logger_t *p = (*l)->logger_private;
if (p) {
fflush(p->logfile);
fclose(p->logfile);
free(p);
}
free(*l);
*l = NULL;
return JK_TRUE;
}
return JK_FALSE;
}
int jk_log(jk_logger_t *l,
const char *file, int line, const char *funcname, int level,
const char *fmt, ...)
{
int rc = 0;
/*
* Need to reserve space for terminating zero byte
* and platform specific line endings added during the call
* to the output routing.
*/
static int usable_size = LOG_BUFFER_SIZE - 3;
if (!l || !file || !fmt) {
return -1;
}
if ((l->level <= level) || (level == JK_LOG_REQUEST_LEVEL)) {
char buf[LOG_BUFFER_SIZE];
char *f = (char *)(file + strlen(file) - 1);
va_list args;
int used = 0;
while (f != file && '\\' != *f && '/' != *f) {
f--;
}
if (f != file) {
f++;
}
used = set_time_str(buf, usable_size, l);
if (line) { /* line==0 only used for request log item */
/* Log [pid:threadid] for all levels except REQUEST.
* This information helps to correlate lines from different logs.
* Performance is no issue, because with production log levels
* we only call it often, if we have a lot of errors
*/
rc = snprintf(buf + used, usable_size - used,
"[%" JK_PID_T_FMT ":%" JK_PTHREAD_T_FMT "] ", getpid(), jk_gettid());
used += rc;
if (rc < 0 ) {
strcpy(buf, "Logging failed in pid/tid formatting");
l->log(l, level, (int)strlen(buf), buf);
return 0;
}
rc = (int)strlen(jk_level_verbs[level]);
if (usable_size - used >= rc) {
strncpy(buf + used, jk_level_verbs[level], rc);
used += rc;
}
else {
strcpy(buf, "Logging failed in log level formatting");
l->log(l, level, (int)strlen(buf), buf);
return 0; /* [V] not sure what to return... */
}
if (funcname) {
rc = (int)strlen(funcname);
if (usable_size - used >= rc + 2) {
strncpy(buf + used, funcname, rc);
used += rc;
strncpy(buf + used, "::", 2);
used += 2;
}
else {
strcpy(buf, "Logging failed in function name formatting");
l->log(l, level, (int)strlen(buf), buf);
return 0; /* [V] not sure what to return... */
}
}
rc = (int)strlen(f);
if (usable_size - used >= rc) {
strncpy(buf + used, f, rc);
used += rc;
}
else {
strcpy(buf, "Logging failed in source file name formatting");
l->log(l, level, (int)strlen(buf), buf);
return 0; /* [V] not sure what to return... */
}
rc = snprintf(buf + used, usable_size - used,
" (%d): ", line);
used += rc;
if (rc < 0 || usable_size - used < 0) {
strcpy(buf, "Logging failed in line number formatting");
l->log(l, level, (int)strlen(buf), buf);
return 0; /* [V] not sure what to return... */
}
}
va_start(args, fmt);
rc = vsnprintf(buf + used, usable_size - used, fmt, args);
va_end(args);
/* Depending on the snprintf implementation used,
* "rc == usable_size - used" can indicate not enough space in buffer */
if (rc < usable_size - used) {
used += rc;
}
else {
used = usable_size;
buf[used - 1] = '.';
buf[used - 2] = '.';
buf[used - 3] = '.';
}
l->log(l, level, used, buf);
}
return rc;
}
int jk_check_attribute_length(const char *name, const char *value,
jk_logger_t *l)
{
size_t len = strlen(value);
if (len > JK_MAX_NAME_LEN) {
jk_log(l, JK_LOG_ERROR,
"Worker %s '%s' is %d bytes too long, "
"a maximum of %d bytes is supported",
name, value, len - JK_MAX_NAME_LEN, JK_MAX_NAME_LEN);
return JK_FALSE;
}
return JK_TRUE;
}
const char *jk_get_worker_type(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return NULL;
}
MAKE_WORKER_PARAM(TYPE_OF_WORKER);
return jk_map_get_string(m, buf, DEFAULT_WORKER_TYPE);
}
const char *jk_get_worker_route(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
const char *v;
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(ROUTE_OF_WORKER);
v = jk_map_get_string(m, buf, def);
if (v) {
return v;
}
/* Try old jvm_route directive */
MAKE_WORKER_PARAM(JVM_ROUTE_OF_WORKER_DEPRECATED);
return jk_map_get_string(m, buf, def);
}
const char *jk_get_worker_domain(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(DOMAIN_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
const char *jk_get_worker_redirect(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(REDIRECT_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
const char *jk_get_worker_secret(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return NULL;
}
MAKE_WORKER_PARAM(SECRET_OF_WORKER);
return jk_map_get_string(m, buf, NULL);
}
const char *jk_get_worker_host(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return NULL;
}
MAKE_WORKER_PARAM(HOST_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
const char *jk_get_worker_source(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return NULL;
}
MAKE_WORKER_PARAM(SOURCE_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
int jk_get_worker_port(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(PORT_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_prefer_ipv6(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(PREFER_IPV6_ADDRESS);
return jk_map_get_bool(m, buf, def);
}
static int def_cache_size = -1;
int jk_get_worker_def_cache_size(int protocol)
{
if (def_cache_size < 1) {
if (protocol == AJP14_PROTO)
def_cache_size = AJP14_DEF_CACHE_SZ;
else
def_cache_size = AJP13_DEF_CACHE_SZ;
}
return def_cache_size;
}
void jk_set_worker_def_cache_size(int sz)
{
def_cache_size = sz;
}
int jk_get_worker_cache_size(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
int rv;
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(CACHE_OF_WORKER);
if ((rv = jk_map_get_int(m, buf, -1)) >= 0)
return rv;
MAKE_WORKER_PARAM(CACHE_OF_WORKER_DEPRECATED);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_cache_size_min(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(CACHE_OF_WORKER_MIN);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_cache_acquire_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(CACHE_ACQUIRE_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_socket_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(SOCKET_TIMEOUT_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_socket_connect_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(SOCKET_CONNECT_TIMEOUT_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_recover_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(WORKER_RECOVER_TIME);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_error_escalation_time(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(WORKER_ERROR_ESCALATION_TIME);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_max_reply_timeouts(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(MAX_REPLY_TIMEOUTS_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_retry_interval(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(RETRY_INTERVAL_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_busy_limit(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(BUSY_LIMIT_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_socket_buffer(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
int i;
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(SOCKET_BUFFER_OF_WORKER);
i = jk_map_get_int(m, buf, 0);
if (i > 0 && i < def)
i = def;
return i;
}
int jk_get_worker_socket_keepalive(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(SOCKET_KEEPALIVE_OF_WORKER);
return jk_map_get_bool(m, buf, def);
}
int jk_get_worker_conn_ping_interval(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(CONN_PING_INTERVAL_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_cache_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
int rv;
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(CACHE_TIMEOUT_OF_WORKER);
if ((rv = jk_map_get_int(m, buf, -1)) >= 0)
return rv;
MAKE_WORKER_PARAM(CACHE_TIMEOUT_DEPRECATED);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_connect_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(CONNECT_TIMEOUT_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_prepost_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(PREPOST_TIMEOUT_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_ping_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(PING_TIMEOUT_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_ping_mode(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
char mode[100];
const char *v;
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(PING_MODE_OF_WORKER);
jk_ajp_get_cping_text(def, mode);
v = jk_map_get_string(m, buf, mode);
return jk_ajp_get_cping_mode(v, def);
}
int jk_get_worker_reply_timeout(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(REPLY_TIMEOUT_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
int jk_get_worker_recycle_timeout(jk_map_t *m, const char *wname, int def)
{
return def;
}
int jk_get_worker_retries(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
int rv;
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(RETRIES_OF_WORKER);
rv = jk_map_get_int(m, buf, def);
if (rv < 1)
rv = 1;
return rv;
}
int jk_get_worker_lb_retries(jk_map_t *m, const char *wname, int def)
{
char buf[1024];
int rv;
if (!m || !wname) {
return -1;
}
MAKE_WORKER_PARAM(LB_RETRIES_OF_WORKER);
rv = jk_map_get_int(m, buf, def);
if (rv < 1)
rv = 1;
return rv;
}
int jk_get_worker_recovery_opts(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(RECOVERY_OPTS_OF_WORKER);
return jk_map_get_int(m, buf, def);
}
const char *jk_get_worker_secret_key(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return NULL;
}
MAKE_WORKER_PARAM(SECRET_KEY_OF_WORKER);
return jk_map_get_string(m, buf, NULL);
}
int jk_get_worker_list(jk_map_t *m, char ***list, unsigned *num_of_workers)
{
if (m && list && num_of_workers) {
char **ar = jk_map_get_string_list(m,
WORKER_LIST_PROPERTY_NAME,
num_of_workers,
DEFAULT_WORKER);
if (ar) {
*list = ar;
return JK_TRUE;
}
*list = NULL;
*num_of_workers = 0;
}
return JK_FALSE;
}
int jk_get_is_worker_disabled(jk_map_t *m, const char *wname)
{
int def = JK_FALSE;
char buf[PARAM_BUFFER_SIZE];
if (m && wname) {
MAKE_WORKER_PARAM(IS_WORKER_DISABLED_DEPRECATED);
return jk_map_get_bool(m, buf, def);
}
return JK_TRUE;
}
int jk_get_is_worker_stopped(jk_map_t *m, const char *wname)
{
int def = JK_FALSE;
char buf[PARAM_BUFFER_SIZE];
if (m && wname) {
MAKE_WORKER_PARAM(IS_WORKER_STOPPED_DEPRECATED);
return jk_map_get_bool(m, buf, def);
}
return JK_TRUE;
}
int jk_get_worker_activation(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
const char *v;
if (!m || !wname) {
return JK_LB_ACTIVATION_ACTIVE;
}
MAKE_WORKER_PARAM(ACTIVATION_OF_WORKER);
v = jk_map_get_string(m, buf, NULL);
if (v)
return jk_lb_get_activation_code(v);
if (jk_get_is_worker_stopped(m, wname))
return JK_LB_ACTIVATION_STOPPED;
if (jk_get_is_worker_disabled(m, wname))
return JK_LB_ACTIVATION_DISABLED;
return JK_LB_ACTIVATION_DEF;
}
int jk_get_lb_factor(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return DEFAULT_LB_FACTOR;
}
MAKE_WORKER_PARAM(LOAD_FACTOR_OF_WORKER);
return jk_map_get_int(m, buf, DEFAULT_LB_FACTOR);
}
int jk_get_distance(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return DEFAULT_DISTANCE;
}
MAKE_WORKER_PARAM(DISTANCE_OF_WORKER);
return jk_map_get_int(m, buf, DEFAULT_DISTANCE);
}
int jk_get_is_sticky_session(jk_map_t *m, const char *wname)
{
int def = JK_TRUE;
char buf[PARAM_BUFFER_SIZE];
if (m && wname) {
MAKE_WORKER_PARAM(STICKY_SESSION);
return jk_map_get_bool(m, buf, def);
}
return def;
}
int jk_get_is_sticky_session_force(jk_map_t *m, const char *wname)
{
int def = JK_FALSE;
char buf[PARAM_BUFFER_SIZE];
if (m && wname) {
MAKE_WORKER_PARAM(STICKY_SESSION_FORCE);
return jk_map_get_bool(m, buf, def);
}
return def;
}
int jk_get_lb_method(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
const char *v;
if (!m || !wname) {
return JK_LB_METHOD_DEF;
}
MAKE_WORKER_PARAM(METHOD_OF_WORKER);
v = jk_map_get_string(m, buf, JK_LB_METHOD_DEF);
return jk_lb_get_method_code(v);
}
int jk_get_lb_lock(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
const char *v;
if (!m || !wname) {
return JK_LB_LOCK_DEF;
}
MAKE_WORKER_PARAM(LOCK_OF_WORKER);
v = jk_map_get_string(m, buf, JK_LB_LOCK_DEF);
return jk_lb_get_lock_code(v);
}
int jk_get_max_packet_size(jk_map_t *m, const char *wname)
{
char buf[PARAM_BUFFER_SIZE];
int sz;
if (!m || !wname) {
return AJP13_DEF_PACKET_SIZE;
}
MAKE_WORKER_PARAM(WORKER_MAX_PACKET_SIZE);
sz = jk_map_get_int(m, buf, AJP13_DEF_PACKET_SIZE);
sz = JK_ALIGN(sz, AJP13_PACKET_SIZE_ALIGN);
if (sz < AJP13_DEF_PACKET_SIZE)
sz = AJP13_DEF_PACKET_SIZE;
else if (sz > AJP13_MAX_PACKET_SIZE)
sz = AJP13_MAX_PACKET_SIZE;
return sz;
}
int jk_get_worker_fail_on_status(jk_map_t *m, const char *wname,
int **list, unsigned int *list_size)
{
char buf[PARAM_BUFFER_SIZE];
int *ar;
if (!m || !wname || !list || !list_size) {
return 0;
}
MAKE_WORKER_PARAM(STATUS_FAIL_OF_WORKER);
ar = jk_map_get_int_list(m,
buf,
list_size,
NULL);
if (ar) {
*list = ar;
return JK_TRUE;
}
*list = NULL;
*list_size = 0;
return JK_FALSE;
}
int jk_get_worker_user_case_insensitive(jk_map_t *m, const char *wname)
{
int def = JK_FALSE;
char buf[PARAM_BUFFER_SIZE];
if (m && wname) {
MAKE_WORKER_PARAM(USER_CASE_OF_WORKER);
return jk_map_get_bool(m, buf, def);
}
return def;
}
const char *jk_get_worker_style_sheet(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(STYLE_SHEET_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
const char *jk_get_worker_name_space(jk_map_t *m, const char *wname, const char *def)
{
const char *rc;
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(NAMESPACE_OF_WORKER);
rc = jk_map_get_string(m, buf, def);
if (*rc == '-')
return "";
else
return rc;
}
const char *jk_get_worker_xmlns(jk_map_t *m, const char *wname, const char *def)
{
const char *rc;
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(XML_NAMESPACE_OF_WORKER);
rc = jk_map_get_string(m, buf, def);
if (*rc == '-')
return "";
else
return rc;
}
const char *jk_get_worker_xml_doctype(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(XML_DOCTYPE_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
const char *jk_get_worker_prop_prefix(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return def;
}
MAKE_WORKER_PARAM(PROP_PREFIX_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
int jk_get_is_read_only(jk_map_t *m, const char *wname)
{
int def = JK_FALSE;
char buf[PARAM_BUFFER_SIZE];
if (m && wname) {
MAKE_WORKER_PARAM(READ_ONLY_OF_WORKER);
return jk_map_get_bool(m, buf, def);
}
return def;
}
int jk_get_worker_user_list(jk_map_t *m,
const char *wname,
char ***list, unsigned int *num)
{
char buf[PARAM_BUFFER_SIZE];
if (m && list && num && wname) {
char **ar = NULL;
MAKE_WORKER_PARAM(USER_OF_WORKER);
ar = jk_map_get_string_list(m, buf, num, NULL);
if (ar) {
*list = ar;
return JK_TRUE;
}
*list = NULL;
*num = 0;
}
return JK_FALSE;
}
int jk_get_worker_good_rating(jk_map_t *m,
const char *wname,
char ***list, unsigned int *num)
{
char buf[PARAM_BUFFER_SIZE];
if (m && list && num && wname) {
char **ar = NULL;
MAKE_WORKER_PARAM(GOOD_RATING_OF_WORKER);
ar = jk_map_get_string_list(m, buf, num, NULL);
if (ar) {
*list = ar;
return JK_TRUE;
}
*list = NULL;
*num = 0;
}
return JK_FALSE;
}
int jk_get_worker_bad_rating(jk_map_t *m,
const char *wname,
char ***list, unsigned int *num)
{
char buf[PARAM_BUFFER_SIZE];
if (m && list && num && wname) {
char **ar = NULL;
MAKE_WORKER_PARAM(BAD_RATING_OF_WORKER);
ar = jk_map_get_string_list(m, buf, num, NULL);
if (ar) {
*list = ar;
return JK_TRUE;
}
*list = NULL;
*num = 0;
}
return JK_FALSE;
}
int jk_get_lb_worker_list(jk_map_t *m,
const char *wname,
char ***list, unsigned int *num_of_workers)
{
char buf[PARAM_BUFFER_SIZE];
if (m && list && num_of_workers && wname) {
char **ar = NULL;
MAKE_WORKER_PARAM(BALANCE_WORKERS);
ar = jk_map_get_string_list(m, buf, num_of_workers, NULL);
if (ar) {
*list = ar;
return JK_TRUE;
}
/* Try old balanced_workers directive */
MAKE_WORKER_PARAM(BALANCED_WORKERS_DEPRECATED);
ar = jk_map_get_string_list(m, buf, num_of_workers, NULL);
if (ar) {
*list = ar;
return JK_TRUE;
}
*list = NULL;
*num_of_workers = 0;
}
return JK_FALSE;
}
int jk_get_worker_mount_list(jk_map_t *m,
const char *wname,
char ***list, unsigned int *num_of_maps)
{
char buf[PARAM_BUFFER_SIZE];
if (m && list && num_of_maps && wname) {
char **ar = NULL;
MAKE_WORKER_PARAM(MOUNT_OF_WORKER);
ar = jk_map_get_string_list(m, buf, num_of_maps, NULL);
if (ar) {
*list = ar;
return JK_TRUE;
}
*list = NULL;
*num_of_maps = 0;
}
return JK_FALSE;
}
int jk_get_worker_maintain_time(jk_map_t *m)
{
return jk_map_get_int(m, WORKER_MAINTAIN_PROPERTY_NAME,
DEFAULT_MAINTAIN_TIME);
}
int jk_get_worker_mx(jk_map_t *m, const char *wname, unsigned *mx)
{
char buf[PARAM_BUFFER_SIZE];
if (m && mx && wname) {
int i;
MAKE_WORKER_PARAM(MX_OF_WORKER);
i = jk_map_get_int(m, buf, -1);
if (-1 != i) {
*mx = (unsigned)i;
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_get_worker_ms(jk_map_t *m, const char *wname, unsigned *ms)
{
char buf[PARAM_BUFFER_SIZE];
if (m && ms && wname) {
int i;
MAKE_WORKER_PARAM(MS_OF_WORKER);
i = jk_map_get_int(m, buf, -1);
if (-1 != i) {
*ms = (unsigned)i;
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_get_worker_classpath(jk_map_t *m, const char *wname, const char **cp)
{
char buf[PARAM_BUFFER_SIZE];
if (m && cp && wname) {
MAKE_WORKER_PARAM(CP_OF_WORKER);
*cp = jk_map_get_string(m, buf, NULL);
if (*cp) {
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_get_worker_bridge_type(jk_map_t *m, const char *wname, unsigned *bt)
{
char buf[PARAM_BUFFER_SIZE];
const char *type;
if (m && bt && wname) {
MAKE_WORKER_PARAM(BRIDGE_OF_WORKER);
type = jk_map_get_string(m, buf, NULL);
if (type) {
if (!strcasecmp(type, TOMCAT32_BRIDGE_NAME))
*bt = TC32_BRIDGE_TYPE;
else if (!strcasecmp(type, TOMCAT33_BRIDGE_NAME))
*bt = TC33_BRIDGE_TYPE;
else if (!strcasecmp(type, TOMCAT40_BRIDGE_NAME))
*bt = TC40_BRIDGE_TYPE;
else if (!strcasecmp(type, TOMCAT41_BRIDGE_NAME))
*bt = TC41_BRIDGE_TYPE;
else if (!strcasecmp(type, TOMCAT50_BRIDGE_NAME))
*bt = TC50_BRIDGE_TYPE;
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_get_worker_jvm_path(jk_map_t *m, const char *wname, const char **vm_path)
{
char buf[PARAM_BUFFER_SIZE];
if (m && vm_path && wname) {
MAKE_WORKER_PARAM(JVM_OF_WORKER);
*vm_path = jk_map_get_string(m, buf, NULL);
if (*vm_path) {
return JK_TRUE;
}
}
return JK_FALSE;
}
/* [V] This is unused. currently. */
int jk_get_worker_callback_dll(jk_map_t *m, const char *wname, const char **cb_path)
{
char buf[PARAM_BUFFER_SIZE];
if (m && cb_path && wname) {
MAKE_WORKER_PARAM(NATIVE_LIB_OF_WORKER);
*cb_path = jk_map_get_string(m, buf, NULL);
if (*cb_path) {
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_get_worker_cmd_line(jk_map_t *m, const char *wname, const char **cmd_line)
{
char buf[PARAM_BUFFER_SIZE];
if (m && cmd_line && wname) {
MAKE_WORKER_PARAM(CMD_LINE_OF_WORKER);
*cmd_line = jk_map_get_string(m, buf, NULL);
if (*cmd_line) {
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_stat(const char *f, struct stat * statbuf)
{
int rc;
/**
* i5/OS V5R4 expect filename in ASCII for fopen but required them in EBCDIC for stat()
*/
#ifdef AS400_UTF8
char *ptr;
ptr = (char *)malloc(strlen(f) + 1);
jk_ascii2ebcdic((char *)f, ptr);
rc = stat(ptr, statbuf);
free(ptr);
#else
rc = stat(f, statbuf);
#endif
return (rc);
}
int jk_file_exists(const char *f)
{
if (f) {
struct stat st;
if ((0 == jk_stat(f, &st)) && (st.st_mode & S_IFREG))
return JK_TRUE;
}
return JK_FALSE;
}
static int jk_is_some_property(const char *prp_name, const char *suffix, const char *sep)
{
if (prp_name && suffix && sep) {
size_t prp_name_len = strlen(prp_name);
size_t suffix_len = strlen(suffix);
size_t sep_len = strlen(sep);
size_t sep_off = sep_len + suffix_len;
if (prp_name_len >= sep_off) {
if (!strncmp(prp_name + prp_name_len - sep_off, sep, sep_len) &&
!strncmp(prp_name + prp_name_len - suffix_len, suffix, suffix_len)) {
return JK_TRUE;
}
}
}
return JK_FALSE;
}
int jk_is_path_property(const char *prp_name)
{
return jk_is_some_property(prp_name, "path", "_");
}
int jk_is_cmd_line_property(const char *prp_name)
{
return jk_is_some_property(prp_name, CMD_LINE_OF_WORKER, ".");
}
int jk_is_list_property(const char *prp_name)
{
const char **props = &list_properties[0];
while (*props) {
if (jk_is_some_property(prp_name, *props, "."))
return JK_TRUE;
props++;
}
return JK_FALSE;
}
int jk_is_unique_property(const char *prp_name)
{
const char **props = &unique_properties[0];
while (*props) {
if (jk_is_some_property(prp_name, *props, "."))
return JK_TRUE;
props++;
}
return JK_FALSE;
}
int jk_is_deprecated_property(const char *prp_name)
{
const char **props = &deprecated_properties[0];
while (*props) {
if (jk_is_some_property(prp_name, *props, "."))
return JK_TRUE;
props++;
}
return JK_FALSE;
}
int jk_check_buffer_size()
{
const char **props;
size_t len = 0;
size_t max_len = 0;
props = &supported_properties[0];
while (*props) {
len = strlen(*props);
if (len > max_len)
max_len = len;
props++;
}
return JK_MAX_ATTRIBUTE_NAME_LEN - (int)max_len;
}
/*
* Check that property is a valid one (to prevent user typos).
* Only property starting with worker.
*/
int jk_is_valid_property(const char *prp_name)
{
const char **props;
/* Any property not starting with "worker." is "valid".
* It is interpreted as the definition of a custom variable.
*/
if (memcmp(prp_name, "worker.", 7))
return JK_TRUE;
props = &supported_properties[0];
while (*props) {
if (jk_is_some_property(prp_name, *props, "."))
return JK_TRUE;
props++;
}
return JK_FALSE;
}
int jk_get_worker_stdout(jk_map_t *m, const char *wname, const char **stdout_name)
{
char buf[PARAM_BUFFER_SIZE];
if (m && stdout_name && wname) {
MAKE_WORKER_PARAM(STDOUT_OF_WORKER);
*stdout_name = jk_map_get_string(m, buf, NULL);
if (*stdout_name) {
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_get_worker_stderr(jk_map_t *m, const char *wname, const char **stderr_name)
{
char buf[PARAM_BUFFER_SIZE];
if (m && stderr_name && wname) {
MAKE_WORKER_PARAM(STDERR_OF_WORKER);
*stderr_name = jk_map_get_string(m, buf, NULL);
if (*stderr_name) {
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_get_worker_sysprops(jk_map_t *m, const char *wname, const char **sysprops)
{
char buf[PARAM_BUFFER_SIZE];
if (m && sysprops && wname) {
MAKE_WORKER_PARAM(SYSPROPS_OF_WORKER);
*sysprops = jk_map_get_string(m, buf, NULL);
if (*sysprops) {
return JK_TRUE;
}
}
return JK_FALSE;
}
int jk_get_worker_libpath(jk_map_t *m, const char *wname, const char **libpath)
{
char buf[PARAM_BUFFER_SIZE];
if (m && libpath && wname) {
MAKE_WORKER_PARAM(LIBPATH_OF_WORKER);
*libpath = jk_map_get_string(m, buf, NULL);
if (*libpath) {
return JK_TRUE;
}
}
return JK_FALSE;
}
const char *jk_get_lb_session_cookie(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return NULL;
}
MAKE_WORKER_PARAM(SESSION_COOKIE_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
const char *jk_get_lb_session_path(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return NULL;
}
MAKE_WORKER_PARAM(SESSION_PATH_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
int jk_get_lb_set_session_cookie(jk_map_t *m, const char *wname, int def)
{
char buf[PARAM_BUFFER_SIZE];
if (m && wname) {
MAKE_WORKER_PARAM(SET_SESSION_COOKIE);
return jk_map_get_bool(m, buf, def);
}
return def;
}
const char *jk_get_lb_session_cookie_path(jk_map_t *m, const char *wname, const char *def)
{
char buf[PARAM_BUFFER_SIZE];
if (!m || !wname) {
return NULL;
}
MAKE_WORKER_PARAM(SESSION_COOKIE_PATH_OF_WORKER);
return jk_map_get_string(m, buf, def);
}
int is_http_status_fail(unsigned int http_status_fail_num,
int *http_status_fail, int status)
{
unsigned int i;
int soft_status = -1 * status;
for (i = 0; i < http_status_fail_num; i++) {
if (http_status_fail[i] == status)
return 1;
if (http_status_fail[i] == soft_status)
return -1;
}
return 0;
}
char **jk_parse_sysprops(jk_pool_t *p, const char *sysprops)
{
char **rc = NULL;
#ifdef _MT_CODE_PTHREAD
char *lasts;
#endif
if (p && sysprops) {
char *prps = jk_pool_strdup(p, sysprops);
if (prps && strlen(prps)) {
unsigned num_of_prps;
for (num_of_prps = 1; *sysprops; sysprops++) {
if ('*' == *sysprops) {
num_of_prps++;
}
}
rc = jk_pool_alloc(p, (num_of_prps + 1) * sizeof(char *));
if (rc) {
unsigned i = 0;
#ifdef _MT_CODE_PTHREAD
char *tmp = strtok_r(prps, "*", &lasts);
#else
char *tmp = strtok(prps, "*");
#endif
while (tmp && i < num_of_prps) {
rc[i] = tmp;
#ifdef _MT_CODE_PTHREAD
tmp = strtok_r(NULL, "*", &lasts);
#else
tmp = strtok(NULL, "*");
#endif
i++;
}
rc[i] = NULL;
}
}
}
return rc;
}
void jk_append_libpath(jk_pool_t *p, const char *libpath)
{
char *env = NULL;
char *current = getenv(PATH_ENV_VARIABLE);
if (current) {
env = jk_pool_alloc(p, strlen(PATH_ENV_VARIABLE) +
strlen(current) + strlen(libpath) + 5);
if (env) {
sprintf(env, "%s=%s%c%s",
PATH_ENV_VARIABLE, libpath, PATH_SEPERATOR, current);
}
}
else {
env = jk_pool_alloc(p, strlen(PATH_ENV_VARIABLE) +
strlen(libpath) + 5);
if (env) {
sprintf(env, "%s=%s", PATH_ENV_VARIABLE, libpath);
}
}
if (env) {
putenv(env);
}
}
void jk_init_ws_service(jk_ws_service_t *s)
{
memset(s, 0, sizeof(jk_ws_service_t));
s->server_port = 80;
s->ssl_key_size = -1;
s->activation = JK_LB_ACTIVATION_TEXT_ACTIVE;
s->reco_status = RECO_NONE;
s->extension.reply_timeout = -1;
s->http_response_status = JK_HTTP_OK;
}
/* Match = 0, NoMatch = 1, Abort = -1
* Based loosely on sections of wildmat.c by Rich Salz
*/
int jk_wildchar_match(const char *str, const char *exp, int icase)
{
int x, y;
for (x = 0, y = 0; exp[y]; ++y, ++x) {
if (!str[x] && exp[y] != '*')
return -1;
if (exp[y] == '*') {
while (exp[++y] == '*');
if (!exp[y])
return 0;
while (str[x]) {
int ret;
if ((ret = jk_wildchar_match(&str[x++], &exp[y], icase)) != 1)
return ret;
}
return -1;
}
else if (exp[y] != '?') {
if (icase && (tolower(str[x]) != tolower(exp[y])))
return 1;
else if (!icase && str[x] != exp[y])
return 1;
}
}
return (str[x] != '\0');
}
int jk_servlet_normalize(char *path, jk_logger_t *logger)
{
int l, w;
if (JK_IS_DEBUG_LEVEL(logger)) {
jk_log(logger, JK_LOG_DEBUG, "URI on entering jk_servlet_normalize: [%s]", path);
}
// This test allows the loops below to start at index 1 rather than 0.
if (path[0] != '/') {
if (path[0] == '*' && path[1] == '\0') {
/* Most likely an "OPTIONS *" request */
return 0;
}
jk_log(logger, JK_LOG_WARNING, "Uri [%s] does not start with '/'.", path);
return JK_NORMALIZE_BAD_PATH;
}
/* First pass.
* Remove path parameters ;foo=bar/ from any path segment
*/
for (l = 1, w = 1; path[l] != '\0';) {
if (path[l] == ';') {
l++;
while (path[l] != '/' && path[l] != '\0') {
l++;
}
}
else
path[w++] = path[l++];
}
path[w] = '\0';
/*
* Second pass.
* Collapse ///// sequences to /
*/
for (l = 1, w = 1; path[l] != '\0';) {
if (path[w - 1] == '/' && (path[l] == '/')) {
l++;
}
else
path[w++] = path[l++];
}
path[w] = '\0';
/* Third pass.
* Remove /./ segments
* Both leading and trailing segments will be removed.
*/
for (l = 1, w = 1; path[l] != '\0';) {
if (path[l] == '.' &&
(path[l + 1] == '/' || path[l + 1] == '\0') &&
(l == 0 || path[l - 1] == '/')) {
l++;
if (path[l] == '/') {
l++;
}
}
else
path[w++] = path[l++];
}
path[w] = '\0';
/* Fourth pass.
* Remove /xx/../ segments
* Trailing segments will be removed but leading /../ segments are an error
* condition.
*/
for (l = 1, w = 1; path[l] != '\0';) {
if (path[l] == '.' && path[l + 1] == '.' &&
(path[l + 2] == '/' || path[l + 2] == '\0') &&
(l == 0 || path[l - 1] == '/')) {
// Wind w back to remove the previous segment
if (w == 1) {
jk_log(logger,
JK_LOG_EMERG,
"[%s] contains a '/../' sequence that tries to escape above the root.",
path);
return JK_NORMALIZE_TRAVERSAL;
}
do {
w--;
} while (w != 0 && path[w - 1] != '/');
// Move l forward to the next segment
l += 2;
if (path[l] == '/') {
l++;
}
}
else
path[w++] = path[l++];
}
path[w] = '\0';
if (JK_IS_DEBUG_LEVEL(logger)) {
jk_log(logger, JK_LOG_DEBUG, "URI on exiting jk_servlet_normalize: [%s]", path);
}
return 0;
}
int jk_strip_session_id(char* path, char* session_name, jk_logger_t *logger) {
char *jsessionid;
jsessionid = strstr(path, session_name);
if (jsessionid) {
int i;
int j;
if (JK_IS_DEBUG_LEVEL(logger)) {
jk_log(logger, JK_LOG_DEBUG,
"removing session identifier for non servlet uri [%s]", path);
}
// Found a session path parameter.
// Need to skip at least as many characters as there are in
// strip_session_name
i = (int) strlen(session_name);
j = 0;
// Increment i until the first character after the parameter
while (jsessionid[i] != '\0' && jsessionid[i] != ';' && jsessionid[i] != '/') {
i++;
}
// Copy until the end
while (jsessionid[i] != '\0') {
jsessionid[j++] = jsessionid[i++];
}
// Terminate
jsessionid[j] = '\0';
if (JK_IS_DEBUG_LEVEL(logger)) {
jk_log(logger, JK_LOG_DEBUG,
"result of removing session identifier for non servlet uri is [%s]", path);
}
return 1;
}
return 0;
}
#ifdef _MT_CODE_PTHREAD
jk_pthread_t jk_gettid()
{
union {
pthread_t tid;
jk_uint64_t alignme;
} u;
#ifdef AS400
/* OS400 use 64 bits ThreadId */
pthread_id_np_t tid;
#endif /* AS400 */
u.tid = pthread_self();
#ifdef AS400
/* Get only low 32 bits for now */
pthread_getunique_np(&(u.tid), &tid);
return ((jk_uint32_t)(tid.intId.lo & 0xFFFFFFFF));
#else
return ((jk_pthread_t)u.tid);
#endif /* AS400 */
}
#endif
/***
* ASCII <-> EBCDIC conversions
*
* For now usefull only in i5/OS V5R4 where UTF and EBCDIC mode are mixed
*/
#ifdef AS400_UTF8
/* EBCDIC to ASCII translation table */
static u_char ebcdic_to_ascii[256] =
{
0x00,0x01,0x02,0x03,0x20,0x09,0x20,0x7f, /* 00-07 */
0x20,0x20,0x20,0x0b,0x0c,0x0d,0x0e,0x0f, /* 08-0f */
0x10,0x11,0x12,0x13,0x20,0x0a,0x08,0x20, /* 10-17 */
0x18,0x19,0x20,0x20,0x20,0x1d,0x1e,0x1f, /* 18-1f */
0x20,0x20,0x1c,0x20,0x20,0x0a,0x17,0x1b, /* 20-27 */
0x20,0x20,0x20,0x20,0x20,0x05,0x06,0x07, /* 28-2f */
0x20,0x20,0x16,0x20,0x20,0x20,0x20,0x04, /* 30-37 */
0x20,0x20,0x20,0x20,0x14,0x15,0x20,0x1a, /* 38-3f */
0x20,0x20,0x83,0x84,0x85,0xa0,0xc6,0x86, /* 40-47 */
0x87,0xa4,0xbd,0x2e,0x3c,0x28,0x2b,0x7c, /* 48-4f */
0x26,0x82,0x88,0x89,0x8a,0xa1,0x8c,0x8b, /* 50-57 */
0x8d,0xe1,0x21,0x24,0x2a,0x29,0x3b,0xaa, /* 58-5f */
0x2d,0x2f,0xb6,0x8e,0xb7,0xb5,0xc7,0x8f, /* 60-67 */
0x80,0xa5,0xdd,0x2c,0x25,0x5f,0x3e,0x3f, /* 68-6f */
0x9b,0x90,0xd2,0xd3,0xd4,0xd6,0xd7,0xd8, /* 70-77 */
0xde,0x60,0x3a,0x23,0x40,0x27,0x3d,0x22, /* 78-7f */
0x9d,0x61,0x62,0x63,0x64,0x65,0x66,0x67, /* 80-87 */
0x68,0x69,0xae,0xaf,0xd0,0xec,0xe7,0xf1, /* 88-8f */
0xf8,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70, /* 90-97 */
0x71,0x72,0xa6,0xa7,0x91,0xf7,0x92,0xcf, /* 98-9f */
0xe6,0x7e,0x73,0x74,0x75,0x76,0x77,0x78, /* a8-a7 */
0x79,0x7a,0xad,0xa8,0xd1,0xed,0xe8,0xa9, /* a8-af */
0x5e,0x9c,0xbe,0xfa,0xb8,0x15,0x14,0xac, /* b0-b7 */
0xab,0xf3,0x5b,0x5d,0xee,0xf9,0xef,0x9e, /* b8-bf */
0x7b,0x41,0x42,0x43,0x44,0x45,0x46,0x47, /* c0-c7 */
0x48,0x49,0xf0,0x93,0x94,0x95,0xa2,0xe4, /* c8-cf */
0x7d,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50, /* d0-d7 */
0x51,0x52,0xfb,0x96,0x81,0x97,0xa3,0x98, /* d8-df */
0x5c,0xf6,0x53,0x54,0x55,0x56,0x57,0x58, /* e0-e7 */
0x59,0x5a,0xfc,0xe2,0x99,0xe3,0xe0,0xe5, /* e8-ef */
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37, /* f0-f7 */
0x38,0x39,0xfd,0xea,0x9a,0xeb,0xe9,0xff /* f8-ff */
};
/* ASCII to EBCDIC translation table */
static u_char ascii_to_ebcdic[256] =
{
0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f, /* 00-07 */
0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f, /* 08-0f */
0x10,0x11,0x12,0x13,0x3c,0x3d,0x32,0x26, /* 10-17 */
0x18,0x19,0x3f,0x27,0x22,0x1d,0x1e,0x1f, /* 18-1f */
0x40,0x5a,0x7f,0x7b,0x5b,0x6c,0x50,0x7d, /* 20-27 */
0x4d,0x5d,0x5c,0x4e,0x6b,0x60,0x4b,0x61, /* 28-2f */
0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7, /* 30-37 */
0xf8,0xf9,0x7a,0x5e,0x4c,0x7e,0x6e,0x6f, /* 38-3f */
0x7c,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7, /* 40-47 */
0xc8,0xc9,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6, /* 48-4f */
0xd7,0xd8,0xd9,0xe2,0xe3,0xe4,0xe5,0xe6, /* 50-57 */
0xe7,0xe8,0xe9,0xba,0xe0,0xbb,0xb0,0x6d, /* 58-5f */
0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, /* 60-67 */
0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, /* 68-6f */
0x97,0x98,0x99,0xa2,0xa3,0xa4,0xa5,0xa6, /* 70-77 */
0xa7,0xa8,0xa9,0xc0,0x4f,0xd0,0xa1,0x07, /* 78-7f */
0x68,0xdc,0x51,0x42,0x43,0x44,0x47,0x48, /* 80-87 */
0x52,0x53,0x54,0x57,0x56,0x58,0x63,0x67, /* 88-8f */
0x71,0x9c,0x9e,0xcb,0xcc,0xcd,0xdb,0xdd, /* 90-97 */
0xdf,0xec,0xfc,0x70,0xb1,0x80,0xbf,0x40, /* 98-9f */
0x45,0x55,0xee,0xde,0x49,0x69,0x9a,0x9b, /* a8-a7 */
0xab,0xaf,0x5f,0xb8,0xb7,0xaa,0x8a,0x8b, /* a8-af */
0x40,0x40,0x40,0x40,0x40,0x65,0x62,0x64, /* b0-b7 */
0xb4,0x40,0x40,0x40,0x40,0x4a,0xb2,0x40, /* b8-bf */
0x40,0x40,0x40,0x40,0x40,0x40,0x46,0x66, /* c0-c7 */
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x9f, /* c8-cf */
0x8c,0xac,0x72,0x73,0x74,0x89,0x75,0x76, /* d0-d7 */
0x77,0x40,0x40,0x40,0x40,0x6a,0x78,0x40, /* d8-df */
0xee,0x59,0xeb,0xed,0xcf,0xef,0xa0,0x8e, /* e0-e7 */
0xae,0xfe,0xfb,0xfd,0x8d,0xad,0xbc,0xbe, /* e8-ef */
0xca,0x8f,0x40,0xb9,0xb6,0xb5,0xe1,0x9d, /* f0-f7 */
0x90,0xbd,0xb3,0xda,0xea,0xfa,0x40,0x40 /* f8-ff */
};
void jk_ascii2ebcdic(char *src, char *dst) {
char c;
while ((c = *src++) != 0) {
*dst++ = ascii_to_ebcdic[(unsigned int)c];
}
*dst = 0;
}
void jk_ebcdic2ascii(char *src, char *dst) {
char c;
while ((c = *src++) != 0) {
*dst++ = ebcdic_to_ascii[(unsigned int)c];
}
*dst = 0;
}
#endif
#if defined (WIN32)
static PSECURITY_ATTRIBUTES pNullSA;
static SECURITY_ATTRIBUTES stEmptySA;
/* To share the objects with other processes, we need a 0 ACL
* Code from MS KB Q106387
*/
PSECURITY_ATTRIBUTES jk_get_sa_with_null_dacl()
{
DWORD rc = 0;
PSECURITY_DESCRIPTOR pSD;
if (pNullSA != NULL) {
return pNullSA;
}
else {
stEmptySA.nLength = (DWORD)sizeof(SECURITY_ATTRIBUTES);
stEmptySA.lpSecurityDescriptor = 0;
}
if (!(pNullSA = LocalAlloc(LPTR, sizeof(SECURITY_ATTRIBUTES)))) {
rc = GetLastError();
goto cleanup;
}
pNullSA->nLength = (DWORD)sizeof(SECURITY_ATTRIBUTES);
pSD = LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
if (pSD == 0) {
rc = GetLastError();
goto cleanup;
}
pNullSA->lpSecurityDescriptor = pSD;
if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)) {
rc = GetLastError();
goto cleanup;
}
if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL)0, FALSE)) {
rc = GetLastError();
goto cleanup;
}
pNullSA->lpSecurityDescriptor = pSD;
pNullSA->bInheritHandle = FALSE;
SetLastError(0);
return pNullSA;
cleanup:
if (pSD)
LocalFree(pSD);
if (pNullSA)
LocalFree(pNullSA);
pNullSA = &stEmptySA;
pNullSA->bInheritHandle = FALSE;
SetLastError(rc);
return pNullSA;
}
#endif
|